- Finish most of the machine generation coding except the whole array assignment.
- Pass all the tests except test018 which is the whole array assignment test.
- Fix bugs of code address corruption and miscalculation of jumping line count, and also add empty block deletion and block type detection for easier optimization.
- Add instruction
SG
for global variable storing.
Since there are many assertions for type checking in this project, please add -ea
argument in JVM for enabling assertions.
TestIRGenerator.java
is for generating IR dot graphs. It supports 5 types of command lines. Each type should be like
javac -sourcepath . TestIRGenerator.java <code file> (<optimization>...)
For testing results before and after SSA, use a command line
javac -sourcepath . TestIRGenerator.java <code file> SSA
For testing results before and after optimization, we define AS
as arithmetic simplification, CF
as constant folding, CSE
as common subexpression elimination, CP
as copy propagation, and constant propagation (this project does these two at the same time), and DCE
as dead line elimination. Two types of methods are defined: OneThrough
and Repeat
. OneThrough
means running the optimizations in order only one time, and the command line is like
javac -sourcepath . TestIRGenerator.java <code file> OneThrough <optimizations>
For example, we can use command line like this
javac -sourcepath . TestIRGenerator.java <code file> OneThrough AS CF CSE DCE CP
Repeat
means running the optimizations in order until convergence, it may run in order several times. For example, we can use a command line like this
javac -sourcepath . TestIRGenerator.java <code file> Repeat AS CF CSE DCE CP
For testing register allocation, we use numbers to define how many registers we use. The command line is
javac -sourcepath . TestIRGenerator.java <code file> <register number>
If we want to show the deleted line after DCE and also the store operations for global variables, we can add ShowDeleted
after other arguments, like
javac -sourcepath . TestIRGenerator.java <code file> Repeat AS CF CSE DCE CP ShowDeleted
After running TestIRGenerator.java
, pre-and post-dot graphs would be generated in /output
with the same name as the input file.
Run TestCompiler
to test this project with DLX. Usage
javac -sourcepath . TestCompiler.java <code file> <data file> <register number> [ShowProgram]
The ShowProgram
flag is to show the generated machine codes in the console. e.g.,
javac -sourcepath . TestCompiler.java ./code ./in 5 ShowProgram
- This project doesn’t propagate the optimizations through function calls. That means global variables would use index 0 in each function entry. (So this project doesn’t remove redundant load and store operations.)
- Variable with index 0 would not be shown with index, e.g., only
a
is to be shown rather thana_0
PHI
instructions are maintained in the optimization. This can be done by iteratively translating single argumentPHI
toMOVE
operation, e.g.3: PHI x_1
can be translated asMOVE x_1 x_3
. And optimizations would propagate toPHI
instructions.- This project does CP and CPP at the same time. Thus, the pre- and post-dot graphs of CP and CPP are shown together.
- Local variables are pushed to the stack before entering the first line of the main or function.
Compiler.java
is for Machine Code Generation.
IRGenerator.java
together with Package /ir
is for IR generation, IR optimization, and Register Allocation.
Parser.java
and Scanner.java
together with Package /parser
and Package /scanner
are for language parsing.