C2 Phoenix Compiler

At a high-level, c2 compiler backend has the following control flow:

Initialization
The driver performs general component initialization, initializes the target and type system, and creates a ModuleUnit, global symbol table, and phase list.

Options
The driver reads and parses command line options.

Global symbols
The driver reads in intermediate language information provided by the language front-end. The driver reads in the global symbol table, creates, and populates symbols as necessary. The driver also reads in initial value information and associates that information with each initialized symbol.

Per-function
The driver reads in the symbol information and code expressions, again from the language front-end, for each successive function, and then invokes phases to create native code for the function.

COFF output
After emitting native code for each function, the driver creates the coff output file.

Phases in per method processing:
CIL Reader                      --> Converts CIL to Phoenix IR
MIR Lower                       --> Lowers object model instructions 
Lower                             --> Lowers most instructions to machine level
Register Allocation           --> Assigns registers to operands
Stack Allocation               --> Assigns stack locations to operands
Frame Generation            --> Determines shape of stack frame for the function
Switch Lower                    --> Lowers switch instructions
Layout                            --> Places IR in final order
Flow Optimization            --> Removes jump-to- jump and jump-to-next instructions
Encoding                        --> Produces machine encoding for IR, and debug information

The c2 compiler can run standalone. To do this you must first run the c2 compiler as part of an overall compilation to get the necessary flags from the driver, and to get the front-end to create the appropriate Compiler Intermediate Language (CIL) files. You can use the -Bz switch to show the compilation steps without executing them.

For the first run, pass the flags -Bd and -Bk to cl.exe. The following code line shows how to pass these flags for file named temp.

cl -Bktemp -Bd -c test.cpp

As this run executes, you should first see output from cl.exe invoking c1xx.dll, and then see subsequent output invoking c2.exe, such as the following example:

   \c2.exe -il temp -f test.cpp -W 1 -G6 -Gs4096 ...

When the overall compilation run completes, you can re-execute a standalone version of c2. Use the same command line to run c2 standalone as shown above.

   \c2.exe -il temp -f test.cpp -W 1 -G6 -Gs4096 ...


Some Phoenix Compiler options

This option creates a listing file that contains source code, assembler code, or machine code.
-FAstring
String Action
C Listing file contains machine code. Default file extension is .cod.
S Listing file contains source code. Default file extension is .asm.
cs or sc Listing file contains source code

This option instructs the compiler to translate C or C++ source code to assembly language.
-Fafilename
For more information about the options you can use with -Fa, see Specifying File Types.

The following example compiles the source file Qsort.c and generates an assembly-listing file named Qsort.asm in a directory named asm. The compiler will not make a directory.

CL -FAa -FaASM\QSORT QSORT.C


The option instructs the compiler to use the specified filename for COFF object file output.
-Fofilename
For more information about the options you can use with -Fo, see Specifying File Types.


Phoenix uses IR as the basis for code analysis and transformation. For a program to be rewritten, it first needs to be converted to the Phoenix IR by one of the supplied readers (native code, IL, and abstract syntax tree readers are provided with Phoenix, and others can be written for nonstandard code formats). Once the IR has been instrumented, it can be written out to an executable. From this perspective, the back-end compiler provided by Phoenix is really just an application written on top of the Phoenix framework. It uses Phoenix readers to convert input code to IR, and invokes any requested Phoenix plug-ins to transform the code; finally, it writes out the modified code in the desired format (native or IL). Phoenix programs can therefore be written either as compiler plug-ins or as meta-programming tools run post-compilation.

Share this post: | | | |
Published Saturday, August 19, 2006 5:05 AM by Risman Adnan Mattotorang

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: