A simple compiler for the IMP programming language
- Alecto Perez
- Jorge Loredo
- David Arredondo
- C++
- Python
- Make sure gcc-11 is installed https://www.linuxfromscratch.org/blfs/view/svn/general/gcc.html
- Make sure python 3.9 is installed
- Make sure CMake version 3.21 or above is installed (you need a version of CMake that supports CMake Presets)
Run:
cmake --preset=build && cmake --build buildThis will attempt to use system version of libraries. If the build fails, you
can alternatively have CMake download and build with the newest version of these
libraries by passing -DALWAYS_FETCH=ON:
cmake -DALWAYS_FETCH=ON --preset=build && cmake --build buildOnce the assembler is built, you can build all the programs in the programs/
directory by first compiling them to the intermediate representation, then
running the riscv compiler to convert them to riscv:
for file in programs/*.imp; do
build/assembler $file \
1> ${file%.imp}.ins \
2> ${file%.imp}.vars
riscv/print_risc.py ${file} \
--constant_folding \
--dead_code_elim \
--register_allocation > ${file%.imp}.asm
doneThis will produce a RISC-V assembly file for every program in the programs
folder. Optimizations can be enabled or disabled by adding or removing the above
flags. To see all flags, run riscv/print_risc.py.