To build the project, run make build. To run the compiler, run make start and then supply the arguments. The compiler provides two interfaces, debug and compile mode.
When used in debug mode, only one file is processed each time the compiler is run. It is used to run each single step of the compilation process indipendently:
- Scanning (
-sdirective). - Parsing (
-p). - Type checking / Semantic Analysis (
-t). - Code generation (
-dxor-g outputfile.bc). The-goption saves the generated bytecode into the provided file, while the-doption shows the readable LLVM IR onto the standard output.
Other options:
- The
-no_tc_mainskips the check for the definition of the main function when the semantic analysis pass is executed (works for both Semantic Analysis and Code Generation). - The
-Odirective is used to optimize the generated llvm module. - The
-verifydirective is used to verify the generated llvm module.
When used in compile mode, all the provided files are compiled and evenutally linked into an executable:
- The
-rtdirective is used to specify the runtime support object file. It must be the filebin/rt-support.ccompiled for the current machine architecture. To compile it, it is possible to use clang:clang -c bin/rt-support.c -o rt-support.o. When using this option the compiler will try to link the executable. - The
-dirdirective is needed to specify the output directory for the object files. It defaults to the current directory. - The
-odirective specifies the output file for the linked executable. Its path ignores the-dirdirective. Defaults to./a.out. - The
-Odirective is used to optimize the llvm modules. - The
-verifydirective is used to verify the generated llvm modules.
There are 4 different executables used for testing:
test/parser_test.mlruns the parser on the input file.test/semant_test.mlruns parser and semantic analysis on the input file.test/codegen_test.mlruns the previous steps and code generation on the input file.test/automatic_tests.mlruns the compilation from parsing to code generation for each file provided in the given directory (-diroption), outputting if they successfully were compiled. The-extoption is used to specify which extension have the files that have to be tested, in general this should be.mc. This program splits the input files in two lists: those that start withtest-are tested for successful compilation, and those that start infail-are tested for failing compilation. The programs are not run, just tested if the compilation is successful.
The script test/testall.sh invokes the microc compiler on a series of input files, compiles them, runs them and checks if their output is the expected one.
This can be invoked automatically by running make testall.
The script firstly creates a temporary directory to place all the generated files, the compiles the runtime support as object file with clang, then proceeds to take each input file, compiles it, runs it and checks its output with the expected output files.
The script arguments are in order:
- the compiler executable.
- the directory with the test files (expectes files with starting with
test-for successful test, starting withfail-for failing tests, with.mcextension. The files with.outextension, with the same name as the input file, are used for output checking.). - the temporary output directory.
- the runtime support file (not compiled).
The command make testclean runs this script and then removes the temporary directory.