Python Written in C?
grante at visi.com
Wed Jul 23 06:07:58 CEST 2008
On 2008-07-23, Larry Bates <larry.bates at websafe.com`> wrote:
>> Since you probably need an assembler anyway, generating
>> assembly-language in the compiler prevents you from having to
>> duplicate a bunch of object-code-generation code in two places.
> I'm not sure I understand what you mean here. The code
> generation phase of the top level compiler would have to
> generate assembler mnemonics instead of just generating
> machine coded directly. At that point it should be just as
> easy to generate machine code, unless you take advantage of
> macros, or other helpers provided in the assembly phase.
Generating assembly language can be a lot easier than
generating machine code. One of the big advantage if you're
generating assembly language is you don't have to handle
relocation and address fix-up issues -- you can let the
assembler and linker take care of it. Letting the linker do
the final machine-code generation step also allows certain
optimizations that can't really be done by the compiler.
> My "compiler" work was way back on mainframes and the ones I
> worked with definitely didn't produce assembler then needed to
> be run through the assembler. They created likable objects
There probably are plenty of compilers that do that. My
background is Unix and microprocessor stuff, and it could be
that for various reasons the "emit assembly" approach was more
common in that genre.
> But that was over 30 years ago!
> All this may be a moot point, because assembler is just a
> mnemonic representations of machine language anyway.
On many architectures, a particular mnemonic can end up being
translated into one of several slightly different machine
instructions -- for example a simple "jump" mnemonic might
generate any one of several instructions depending on how far
away the destination is located. If you've already got an
assembler and linker than know how to deal with that stuff,
then rather than duplicate the same functionality in the
compiler, one might just decided to emit a "jump mnemonic" and
Grant Edwards grante Yow! Wow! Look!! A stray
at meatball!! Let's interview
More information about the Python-list