The src/tree Directory¶
Namespace tree, delivered for TC-5. The implementation of the
intermediate representation. The file tree/README.txt should give enough
explanations to understand how it works.
Reading the corresponding explanations in Appel’s book is mandatory.
It is worth noting that contrary to A. Appel, just as we did for ast, we
use n-ary structures. For instance, where Appel uses a binary seq, we
have an n-ary seq which allows us to put as many statements as we want.
To avoid gratuitous name clashes, what Appel denotes exp is denoted
sxp (Statement Expression), implemented in translate::Sxp.
Please, pay extra attention to the fact that there are temp::Temp used
to create unique temporaries (similar to misc::symbol), and
tree::Temp which is the intermediate representation instruction denoting
a temporary (hence a tree::Temp needs a tree::Temp). Similarly,
on the one hand, there is temp::Label which is used to create unique
labels, and on the other hand there are tree::Label which is the IR
statement to define a label, and tree::Name used to refer to a label
(typically, a tree::Jump needs a tree::Name which in turn needs
a temp::Label).
File: fragment.* (src/tree/)
It implements
tree::Fragment, an abstract class,tree::DataFragto store the literal strings, andtree::ProcFragto store the routines.
File: fragments.* (src/tree/)
Lists of
tree::Fragment.
File: visitor.* (src/tree/)
Implementation of
tree::Visitorandtree::ConstVisitorto implement function objects ontree::Fragments. In other words, these visitors implement polymorphic operations ontree::Fragment.
File: tree-variants.* (src/tree/)
misc::variantoverlay on Tree classes in order to perform pattern-matching withstd::visit, which is the basis of our implementation of IR canonicalization and instruction scheduling.