# MiniC Compiler LAB4 (simple code generation), MIF08 / CAP 2022-23 # Authors Samy Avrillon # Contents Same as the first lab, you did the structure, so i have litle interest in commenting it. # Test design - folder *operators* checks all operations on operators (additive, multiplicative, relations, unary minus, boolean) - *nested{While,For,Ifs}* checks with structures of nested blocks. - *forTests* and *whileClauseSyntax* tests for the well-execution of for and while loops. - *testTooManyVariables* tries initializing many variables in order to make the naive allocator fail. # Design choices Boolean Not has been implemented using an immediate 1 and the opreator xor, even though such operator exists in riscV (see Known bugs). I did implement C-like loops with the same system used in the interpreter. # Known bugs There is a lot of RiscV instruction that are not implemented in Lib, and that makes bigger and less readable code (for exemple, slt would be better than blt for integer comparison). By design, we always use a jump statement before a label. Otherwise, the CFG linearization fails. This is intended (the missing jump could be added in *prepare_chunk*). So, there is one line in *BuildCFG.c* that sould never be executed (that's why the coverage is not 100% complete), when a label is detected as a leader, as the preceding jump will always have been detected as a leader before it. # Checklists A check ([X]) means that the feature is implemented and *tested* with appropriate test cases. ## Code generation - [X] Number Atom - [X] Boolean Atom - [X] Id Atom - [X] Additive expression - [X] Multiplicative expression - [X] UnaryMinus expression - [X] Or expression - [X] And expression - [X] Equality expression - [X] Relational expression (! many cases -> many tests) - [X] Not expression ## Statements - [X] Prog, assignements - [X] While - [X] Cond Block - [X] If - [X] Nested ifs - [X] Nested whiles ## Allocation - [X] Naive allocation - [X] All in memory allocation - [X] Massive tests of memory allocation