Constant Record Propagation
Pt03
Introduction
The purpose of this assignment is to become familiar with the
constant propagation implementation by extending it in
some places. In this assignment you will extend the constant
propagation with propagation of constant records and evaluation
of field access on constant records.
In the partial-eval package you will find a
Tiger-PE-ConstProp module.
This module is currently just a copy of the constant propagation
implementation in the
Tiger Compiler. You should extend the code in
this module (and maybe other modules) in this exercise.
You can use the
tiger-pe tool to test your implementation. This tool
is a source to source transformation wrapping the the
Tiger-Partial-Eval
tool. This tool currently just invokes constant propagation, but you will
change this into a partial evaluator later.
Example
Invoking your solution on the Tiger program
let type intlist = {hd: int, tl: intlist}
var tail : intlist := nil
var list : intlist :=
intlist{
hd = 12,
tl = intlist { hd = 13, tl = tail}}
in printint(list.tl.hd)
end
should for example result in
let type intlist = {hd : int, tl : intlist}
in printint(13)
end
Notice that the type declaration is no longer
required in this example, but it is included in this example because the
dead code eliminator in de
Tiger Compiler
will not remove it.
Installation
Download the package for the partial evaluator assignment:
The package should be configured, build and installed with the following commands,
which assumes that you want to install the tools in the
`pwd` :
./configure --prefix=`pwd` --with-xt=/usr --with-tiger=/usr
make bootclean
make
make install
make bootclean removes intermediate C files that are distributed
in typical
StrategoXT? packages. This is required to create new
dependecy files for
Tiger-Partial-Eval.
You should install the tools before you run them. Running on a build package will not work
or will not reflect your latest changes.
Running your tools
Run the constant propagator with:
tiger-pe -i some-test.tig
Notice that
tiger-pe has some useful switches for debugging:
--elim-dead off will ommit
the dead code elimination,
--ensugar off will not ensugar and
--pp off will
not pretty print the Tiger AST.
Tips
See the
Tiger Language topic
if you need information on Tiger.
Notice that a field access on a constant record is not allowed in Tiger. You
will have to implement the evaluation of field accesses before you can
run the output of your tool with
run-tiger .
For more information on partial evaluation in general visit the
Partial Evaluation
topic on the
Program Transformation Wiki.
--
MartinBravenboer - 06 Feb 2003