Skip to content

lamdang2k/ifcc-2023

Repository files navigation

IFCC - Compilation Project

About The Project

The goal of this project is to develop an end-to-end compiler of C language. This involves implementing a complete chain to analyze and transform a language.

Build With

  • C++11
  • ANTLR 4.12.0

Getting Started

Below are some instructions on setting up this project locally.

Prerequisites

Install antlr using your distribution's package manager, or run the provided shell script:

./install-antlr.sh

Installation

  1. Clone the repo
    git clone https://github.com/lamdang2k/ifcc-2023
  2. Execute the script *_runmake.sh
  3. Run the executable file ifcc in the folder compiler/build

Test Execution

  • Execute run_test.sh to run all the tests
  • Enter -h option to see available commands
  • Enter -c option to clean the tests results directory

Usage

Features Implemented

✔️ Variables
✔️ Integer and character constants (with simple quote)
✔️ Basic arithmetic operations: +,-, *
✔️ bitwise logical operations: |, &,ˆ
✔️ Comparison operations: ==, !=, <, >
✔️ Unary operations: ! and -
✔️ Declaration of variables anywhere
✔️ Assignment (which, in C, also returns a value)
✔️ Ability to initialise a variable when declaring it
✔️ Use of the standard putchar and getchar functions for input/output
✔️ Definition of functions with parameters, and return type int, char or void
✔️ Check the consistency of function calls and their parameters
✔️ Block structure using { and }
✔️ Support for variable scoping and shadowing
✔️ if, else, while control structures
✔️ Support for return expression anywhere
✔️ Check that a variable used in an expression has been declared
✔️ Check that a variable is not declared more than once
✔️ Check that a declared variable is used at least once
✔️ Division and modulo
✔️ Arrays (one-dimensional)

Features Currently Being Implemented

✏️ Basic data types char(32bits) and int(32bits) [char must change to 8 bits].
✏️ Retargeting to several architectures: x86, MSP430, ARM [IR achieved].
✏️ Character strings represented by arrays of char [no assignment of a character string with a string].
✏️ Propagation of simple constants
✏️ Propagation of constant variables (with data-flow analysis)

Features Not Supported

❌ Assignment operators +=, -= etc., increment ++ and decrement --.
❌ Pointers
❌ break and continue
❌ switch...case
❌ Lazy logical operators ||, &&
❌ Propagation of simple constants
❌ Propagation of constant variables (with data-flow analysis)
❌ Global variables
❌ Other control structures: for, do...while
❌ Detailed support for all other arithmetic and logical operators: <=, >=, << and >> etc.
❌ Other basic types such as inttypes.h, float, double, etc.

Source Files Information

  • ifcc.g4 contains the grammar in antlr4 format

  • main.cpp contains the C++ code to call the antlr4-generated parser on the file name provided in the command line.

  • CodeGenVisitor.h produces the actual assembly-language output

  • Makefile contains the actual build logic. The Makefile uses 3 variables (ANTLRJAR, ANTLRINC and ANTLRLIB) indicating the location of various parts of the Antlr suite. You can (should) change those values to suit your installation, either by editing the Makefile and/or on the command line, as illustrated by the *_runmake scripts.

  • fedora_runmake.sh is an example of such a script. it shows how makefile variables can be overriden from the command-line.

License

Distributed under the BSD 2-Clause "Simplified" License.

Authors

Thanh Lam DANG
Maud ANDRUSZAK
Jorge KORGUT
Florian PAUTRAT
Quoc Viet PHAM
Mohamed Khalil LOUKHNATI
Taha ISMAILI
Anass AMMARI
Contact us by email: [email protected]

Acknowledgments

This project is a part of the Compilation course at INSA Lyon.

About

A C language subset compiler written in C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published