Re: C parsing + register allocation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Philip Herron <herron.philip@xxxxxxxxxxxxxx> writes:

> This a design question about the c front-end of 'a' compiler. I am
> working on a basic compiler atm. But i was wondering, should you have
> 2 parsers, it seems it may be a good idea to have a seperate parser to
> run first, to do all c-preprocessor work, then have the 2nd to do the
> actual code parsing into internal representation, then output assembly...

Yes, it's easier if the preprocessor is separate from the language
parser.  In gcc the preprocessor is a library, libcpp, which emits a
token stream.  The C or C++ parser then operates on that stream.

> I am looking through old gcc to get to grips with how its working at
> the moment, but i was also wondering for the compilation process, does
> gcc output asm then call gas from something like 'execl' or does it do
> this internaly at the moment? Its something i don't really see. It
> seems in old gcc it was called as there was direct paths hard-coded to
> the bin-utils binaries like ld,as in gcc. To call to compile. Or is it
> better to directly have some interface to an assembler. Passing a
> gimple like representation to it or somthing.

gcc has always emitted a text file and then invoked the assembler via
something like 'execl'.  gcc can literally write a text file or it can
use a pipe to the assembler.  This is all done in the gcc driver, in
gcc.c.  The gcc driver is not the compiler proper.  Use the -v option to
see the programs that are run.

It would be slightly faster to invoke the assembler as a library.
However, the time required to generate out the assembler file and the
time required for the assembler to run is normally a small fraction of
the time required to compile a file.  So there is a limit to how much
faster it would be to avoid using an external program.

> Also i was wondering is there any good documenation on how gcc or in
> general on linux or otherwise the register allocation process.

The gcc documentation is at http://gcc.gnu.org/onlinedocs/ .  You may be
interested in the internals manual which you can find at the bottom of
that page.  Unfortunately the register allocation process is not well
documented.  Also, note that the register allocator was completely
rewritten in the 4.4.0 release of gcc.

Ian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux