Skip to content

pcineverdies/dummy_cc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dummy_cc

Dummy C-ish Compiler for Learning Purposes, targeting RV32IM.

Structure

The file tokens.md contains the definition of the tokens currently implemented in the parser.

The file grammar.md contains the grammar of the C-like language implemented. While generating the AST, many conditions are checked for the correctness of the program. In particular, no automatic type conversion is performed (casting must always be explicit).

The file LIR.md contains the grammar the linear intermediate representation employed in the middle end. It is a stack-based lir in SSA format (although without phi functions). It can be used to obtain a CFG of the code and implement some optimizations. While the project does not focus on optimizing the result, some simple local techniques are employed.

The file Optimization.md describes the techniques adopted for different level of optimizations. Some of these techniques are implemented directly during the LIR construction, thus they can be found in lirgen.rs.

The file Backend.md describes the backend process. The one and only target of the compiler is RISC-V on 32 bits, supporting extensions I and M. The result is compliant with the RISC-V ABI.

Build

cargo build -r

Usage

The program in on a single file. It has to follow the syntax described in grammar.md. Relevant messages are shown in case of errors, with references to the input file.

Usage: dummy_cc [OPTIONS] --file-name <FILE_NAME>

Options:
  -f, --file-name <FILE_NAME>  Path of the file to compile
  -o, --o <O>                  Path of the result file [default: out.asm]
      --opt <OPT>              Required level of optimization [default: 0]
      --print-ast              Show result of parsing
      --print-lir              Show result of lirgen
  -a, --arch <ARCH>            Target architecture [default: rv32im] [possible values: rv32im]
  -h, --help                   Print help
  -V, --version                Print version

Available levels of optimization are 0, 1 and 2. Using option --print-ast you can see a printed version of the ast, highlighting the order in which expressions are evaluated. Using option --print-lir you can see a printed version of intermediate representation after it has been optimized.

Resources