The src/target Directory

Namespace target, delivered for TC-7. Generation of pseudo-assembly from LIR: Low-Level Intermediate Representation.

File: local.am (src/target/)

This is a Makefile configuration relative to the src/target/ directory. It is responsible for the integration into the libtc library with everything exported from the target module.

File: libtarget.* (src/target/)

The interface of the target module. It exports the lir_to_assem, runtime_dump, instructions_dump and frame_allocate procedures. Converting tree::Fragment into assem::Fragment.

File: tasks.* (src/target/)

Tasks related to the target module (see: The src/task Directory).

File: fwd.hh (src/target/)

Forward declarations for the target module.


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.

File: cpu-limits.hh (src/target/)

Description of a set of restrictions of a CPU.

File: cpu.* (src/target/)

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

File: matcher.* (src/target/)

Implement of abstract pattern matching visitor.

File: target.* (src/target/)

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

Directories: mips, ia32 & arm (src/target/)

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

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

Strings are implemented as 4 bytes to encode the length, and then a 0-terminated C-like 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 using 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, but we do. His implementation of equality is more efficient than ours, since he can decide just by looking at the lengths of the compared strings. That could be improved in the future…

main

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.