Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

lsaos/pld-comp

Repository files navigation

PLD-COMP

PLD Compilateur By the super hexanome whatever its number is (kidding, its 4404).

How to build the compiler ?

Setup the makefile

You will first need to make sure that the Makefile is actually referencing your antlr-cpp runtime. Therefore, you will have to open the Makefile, and take a look at lines 36 through 39 :

ANTLR=/shares/public/tp/ANTLR4-CPP/bin/antlr4#The path to your antlr4 executable
ANTLRRUNTIME=/shares/public/tp/ANTLR4-CPP#Main folder of antlrcpp
ANTLRSRC=$(ANTLRRUNTIME)/antlr4-runtime#Same, but here the runtime is located
LDFLAGS=$(ANTLRRUNTIME)/lib/libantlr4-runtime.a

You may have to change ANTLR, ANTLRRUNTIME, ANTLRSRC and LDFLAGS such that they all point to your personnal antlr files or installation directories.

Remark : The current Makefile is already adapted to the INSA IT department's computers.

You will also need to create the build/ folder at the root of the project, among src/ and tests/. Otherwise, the Makefile won't be correctly executed.

Build the executable

First of all, make sure the grammar is up to date by running :

make Grammaire

Now, just run :

make

in order to build the whole executable. It will be named "./compiler"

Last but not least, if you want to run tests, you can either write :

make test

or

cd tests && bash mktest.sh && cd ..

Which is basically the content of the test target.

Run the compiler

Just type :

./compiler

The compiler may take a few options to produce other outputs. Here follows the list of allowed options and their goal :

  • -c : Produce assembly (.s) file
  • -o : Proceed optimisation
  • -a : Proceed static analysis
  • -t : View the Tree structure of the Program
  • -m : Produce assembly for MSP_430 target
## What can I find in this folder ?

Here's a description of the folder hierarchy :

  • src : Source code
    • parser : Every bit of code dealing with the antlr lexers and parsers. You'll find there the grammar (expr.g4) and the visitors' implementation (visitor.cpp)
    • ast : You will find here every class modelling what our C program consists of, i.e. AST...
    • ir : You will find every item about IR.
    • main : This folder name is perhaps obvious about its content.
  • tests : You will find here a list of tests that can be run with the command *make test*. Every category of test is arranged in subfolders.
    • ValidPrograms : programs that should normally compile with our executable.
    • LexError : Program generating a Lexer Error.
    • SyntaxError : Same, with syntax.
    • SemanticError : Same, with semantics.
    • Moodle : All the tests that were downloaded from Moodle
      • Front
      • Back
  • build : It's useless to take a look at it, unless you know how to read .o files.

Is there anything to sum up what the compiler does ?

Sure ! Please check tests/DemonstrationPrograms and run the compiler executable on every .c file !

About

Basic Handmade C Compiler

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5