README for lab4: FIR Generation Ling Li & Xin Yu, Caltech, 02/26/2001 ---------------------------------------------------------------------- We implemented the CPS, ESC, closure conversions and the dead code elimination. All 4 tests ran perfectly. The test?.ir and test?.out files were generated at stage 7. ---------------------------------------------------------------------- Changed files (from lab3): fc_ast/fc_ast_lex.mll Lexing fc_ast/fc_ast_parse.mly Parsing fc_ir/fc_ir_ast.ml IR generation fc_fir/fc_ir_cont.ml CPS conversion fc_fir/fc_ir_esc.ml Escape analysis fc_fir/fc_ir_closure.ml Closure conversion fc_fir/fc_fir_dead.ml Dead code elimination ---------------------------------------------------------------------- Main ideas: 1. CPS: Insert continuation to all non-local function definitions. We also need to convert types (such as type in LetBinop). 2. ESC: Create frames to store local variables. Be sure to copy all arguments of a function to its frame, and convert framed variables to corresponding fields. 3. Closure: Close all functions. Every global function takes data_seg and exit as args. 4. Dead code elimination: Eliminate useless codes and types. Assignment to a non-free variable is useless. Functions never called from global functions are useless. Types never used (such as empty frames) are useless. Functions added and Bugs fixed to Lexer/Parser 1. The 3rd entry of DefFun should be return type, not the type of the whole function. 2. Support more float constant such as 3e-4. 3. Support string constant merging, such as char *s = "Hello " "World"; will be interpreted as char *s = "Hello World"; 4. Skip ^M in DOS format file. Functions added and Bugs fixed to IR generation 1. UNotOp now is transformed into IfThenElse. 2. squash_array_type added. 3. uarith of general expressions (not only AtomVar) fixed. 4. convert_args (used to be called convert_to_typelist) now uses SemException ArityMismatch instead of Invalid_argument when the two lists do not meet in length. ---------------------------------------------------------------------- To do: 1. Old problems in Lab 2 and Lab 3. 2. Other optimizations. 3. Make external functions escapable. ---------------------------------------------------------------------- This README file together with the programs can be found at http://www.cs.caltech.edu/~ling/course/cs134b/lab4/