UP | HOME

Intermediate code generation
Lecture 15

Table of Contents

Intermediate code generation

Compiler project

Implement the code generator for SimpleC according to the operational semantics and informal language semantics discussed in class.

You may use the starter code for this project and intermediate code helper classes (TAC.java and TACFunction.java). Please develop and use your own test cases. Ask any questions about semantic decisions or details of the intermediate representation in class or in chat.

To get the repo ready, uncomment the CodeGen phase in the main driver and Makefile:

diff --git a/Compiler.java b/Compiler.java
index 8ae0512..8b75d09 100644
--- a/Compiler.java
+++ b/Compiler.java
@@ -26,9 +26,10 @@ public class Compiler {
     TypeChecker typechecker = new TypeChecker();
     typechecker.visit(tree);

-    // // Phase 3: Intermediate code gen.
-    // CodeGen codegen = new CodeGen();
-    // codegen.visit(tree);
+    // Phase 3: Intermediate code gen.
+    CodeGen codegen = new CodeGen();
+    codegen.visit(tree);
+    System.err.println(codegen.functionlist);

     // // Phase 4: Machine-independent optimization.

diff --git a/Makefile b/Makefile
index bb418b2..4b4bdab 100644
--- a/Makefile
+++ b/Makefile
@@ -2,9 +2,9 @@ SOURCE := \
        SimpleCParser.java \
        Compiler.java \
        TypeChecker.java \
-       # TAC.java \
-       # TACFunction.java \
-       # CodeGen.java \
+       TAC.java \
+       TACFunction.java \
+       CodeGen.java \
        # ASMGen.java

Submission

Push the complete code generator to the main branch of your github repository. Be sure that it builds with make from the root directory and can be run with java Compiler program.simplec.

Grading

The intermediate code is written by the driver to stderr, which will be used to evaluate your code gen output, e.g., the input program

main() {
return 1;
}

should, somewhere in the output (other output is okay, as long as the intermediate code is there), be

[main
CONST _t0 1
ASSIGN true _t0
CONST _t1 0
ASSIGN false _t1
CONST _t2 1
RETURN _t2
]

Grading will use several new programs to ensure that the code generator is handling all SimpleC constructs.

Author: Paul Gazzillo

Created: 2022-03-14 Mon 14:30