Next: , Previous: , Up: Project Layout   [Contents][Index]

3.2.23 The src/target Directory

Namespace target, delivered for TC-7. Some data on the back end.

File: cpu.* (src/target/)

Description of a CPU: everything about its registers, and its word size.

File: target.* (src/target/)

Description of a target (language): its CPU, its assembly (target::Assembly), and it translator (target::Codegen).

File: assembly.* (src/target/)

The abstract class target::Assembly, the interface for elementary assembly instructions generation.

File: codegen.* (src/target/)

The abstract class target::Codegen, the interface for all our back ends.

Directory: mips (src/target/)
Directory: ia32 (src/target/)
Directory: arm (src/target/)

The instruction selection per se split into a generic part, and a target specific (MIPS, IA-32 and ARM) part. See src/target/mips, src/target/ia32 and src/target/arm.

File: libtarget.* (src/target/)

Converting tree::Fragments into assem::Fragments.

File: tiger-runtime.c (src/target/)

This is the Tiger runtime, written in C, based on Andrew Appel’s runtime.c. The actual runtime.s file for MIPS was written by hand, but the IA-32 was a compiled version of this file. It should be noted that:


Strings are implemented as 4 bytes to encode the length, and then a 0-terminated à la C string. The length part is due to conformance to the Tiger Reference Manual, which specifies that 0 is a regular character that can be part of the strings, but it is nevertheless terminated by 0 to be compliant with SPIM/Nolimips’ print syscall. This might change in the future.

Special Strings

There are some special strings: 0 and 1 character long strings are all implemented via a singleton. That is to say there is only one allocated string ‘""’, a single ‘"1"’ etc. These singletons are allocated by main. It is essential to preserve this invariant/convention in the whole runtime.

strcmp vs. stringEqual

We don’t know how Appel wants to support ‘"bar" < "foo"’ since he doesn’t provide strcmp. We do. His implementation of equality is more efficient than ours though, since he can decide just be looking at the lengths. That could be improved in the future...


The runtime has some initializations to make, such as strings singletons, and then calls the compiled program. This is why the runtime provides main, and calls tc_main, which is the “main” that your compiler should provide.

Next: , Previous: , Up: Project Layout   [Contents][Index]