cap-lab22-samy/MiniC/README-codegen.md

2.0 KiB

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

  • Number Atom
  • Boolean Atom
  • Id Atom
  • Additive expression
  • Multiplicative expression
  • UnaryMinus expression
  • Or expression
  • And expression
  • Equality expression
  • Relational expression (! many cases -> many tests)
  • Not expression

Statements

  • Prog, assignements
  • While
  • Cond Block
  • If
  • Nested ifs
  • Nested whiles

Allocation

  • Naive allocation
  • All in memory allocation
  • Massive tests of memory allocation