Translation to Intermediate Code - lgxZJ/Tiger-Compiler GitHub Wiki
Actually, a compiler is a program which translate high-level language into low-level machine language. As an practice, the compiler can be divided into two parts----the front end and back end. The front end is all about the high-level language, the back end is all about the low-level language. Then, data is transferred in what format between the two ends? The answer is IR(Intermediate Representation).
This phase is about translating the high-level language into a special data structure IR. All high-level structures have to be represented with low-level facilities.
An intermediate representation(IR) is a kind of abstract machine language that can express the target-machine operations without committing to much machine-specific detail. But it also independent of the details of the source language.
As we can see from the excerpt above, IR is translation of high-level language with enough machine abstractions. See the figure below:
A good intermediate representation has several qualities:
- It must be convenient for the semantic analysis phase to produce.
- It must be convenient to translate into real machine language, for all the desired target machines.
- Each construct must have a clear and simple meaning, so that optimizing transformations that rewrite the intermediate representation can easily be specified and implemented.
Although not very much, this compiler supports some kinds of safety confirmation:
- Bounds Checking(arrays)
- Nil Checking(records with nil value)
Support for IR:
- myIRtree.h
- myIRTree.c
Support for break(keep the break targets):
- breakGetter.h
- breakGetter.c
Support for l-value(whether remain left-values with '[reg]' format or move into a new register):
- lValueTreater.h
- lValueTreater.c