Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Latest commit

 

History

40 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MicroC Compiler Instructions

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.

Compiler Modes

*** Debug 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 (-s directive).
  • Parsing (-p).
  • Type checking / Semantic Analysis (-t).
  • Code generation (-d xor -g outputfile.bc). The -g option saves the generated bytecode into the provided file, while the -d option shows the readable LLVM IR onto the standard output.

Other options:

  • The -no_tc_main skips 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 -O directive is used to optimize the generated llvm module.
  • The -verify directive is used to verify the generated llvm module.

*** Compile mode ***

When used in compile mode, all the provided files are compiled and evenutally linked into an executable:

  • The -rt directive is used to specify the runtime support object file. It must be the file bin/rt-support.c compiled 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 -dir directive is needed to specify the output directory for the object files. It defaults to the current directory.
  • The -o directive specifies the output file for the linked executable. Its path ignores the -dir directive. Defaults to ./a.out.
  • The -O directive is used to optimize the llvm modules.
  • The -verify directive is used to verify the generated llvm modules.

Test Executables

There are 4 different executables used for testing:

  • test/parser_test.ml runs the parser on the input file.
  • test/semant_test.ml runs parser and semantic analysis on the input file.
  • test/codegen_test.ml runs the previous steps and code generation on the input file.
  • test/automatic_tests.ml runs the compilation from parsing to code generation for each file provided in the given directory (-dir option), outputting if they successfully were compiled. The -ext option 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 with test- are tested for successful compilation, and those that start in fail- are tested for failing compilation. The programs are not run, just tested if the compilation is successful.

Testall Script

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 with fail- for failing tests, with .mc extension. The files with .out extension, 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages