The source code of the compiler is distributed across the following directories and files:
ir/
ir.sml
: Contains structure of the Intermediate Representation (IR)regAlloc.sml
: Greedy register allocationtranslate.sml
: Contains the code for translating the source of Tiger AST to the Intermediate Representation and the code for translating the Intermediate Representation to the assembly code
target/
convToMIPS.sml
: Contains helper functions to create MIPS assembly statementsmips.sig
andmips.sml
: Signature and structure of the MIPS ASTprettyMips.sml
: Contains helper functions for the pretty printing of the MIPS assembly code
tiger/
ast.sig
andast.sml
: Signature and structure of the Tiger ASTconvToTiger.sml
: Contains helper functions to create Tiger expressionsprettyTigerAST.sml
: Contains helper functions for the pretty printing of the Tiger expressionstiger.grm
: Grammar of the Tiger languagetiger.lex
: Lexical analysis file
utils/
env.sml
: Structure to create an environment from user variable to temporariestemp.sml
: Structure to create new temporary values and labelsutils.sml
: General purpose helper functions
tc.mlb
: The ML-Basis file for compilationtc.sml
: The main code where the execution begins. This uses the lexer-parser, translator and pretty printers to generate MIPS assembly from the Tiger source code
We have used the following design choices:
- Currently register allocation is implemented as a greedy register allocation and if the compiler runs out of registers just, it just flags an error
- There are built-in functions for printing expression values, they are
print
andprintln
which print the value without or with a newline respectively - The error checking mechanism is quite week as of now