Giter VIP home page Giter VIP logo

microc-comp's Introduction

MicroC Compiler

MicroC is a subset of the language C with the following simplification:

  • It supports only integers (int), characters (char) and booleans (bool) as scalar values, array and pointers as compound data types;
  • There are no structures, unions, doubles, function pointer;
  • No dynamic allocation of memory;
  • No multi-dimensional arrays;
  • No shorthand for initialize variable during declaration;
  • Functions can only return void, int, bool, char;
  • No pointer arithmetic;
  • Pointers and arrays are not interchangeable;
  • no separate compilation, all the code of a program must stay in a unique compilation unit;
  • there are only two library functions
void print(int)  // it outputs an integer to standard output
int getint()     // it inputs an integer from standard input 

As part of the exam students will be asked to implement a compiler for MicroC using the OCaml language, the tools and the techniques presented during the course. The project is made of four assignments that are released incrementally during the course, so that students can start working on the project before the end of classes (actually, the last assignment is released in the last lecture).

Setup your development environment

A description of the provided project kit is here.

MicroC assignments

The project is split in the following assignments:

  • Parsing: this assignment asks students to implement a parser for MicroC. The material is available here;

  • Semantic analysis: this assignment mainly concerns the implementation of a static analysis for check that a given program obeys the scoping rule and the type system of the language. The material is available here;

  • Code generation: this assignment asks to use the LLVM toolchain to compile a MicroC program to low level code (LLVM bitcode) and to perform some simple optimizations. The material is available here;

  • Language extensions: this assignment asks to extend the MicroC language by considering further constructs. In particular, students are required to implement at least three of the following items:

    • floating point arithmetic and strings as in C, i.e. null-terminated arrays of characters;
    • structs, sizeof, bitwise and comma operators;
    • a new semantic analysis pass to detect deadcode;
    • seperate compilation.
  • Implemented extensions:

    • pre/post increment/decrement operators, i.e., ++ and --, and abbreviation for assignment operators, i.e., +=, -=, *=, /= and %=;
    • do-while loop, variable declaration with initialization and multiple declarations, e.g., int i = 0, *j = &z;;
    • pointers, arrays & multi-dimensional arrays as in C;

To take the exam students must submit their solutions to the teacher via email by the deadline reported on the exam registration portal. The submitted solution must include the OCaml code, the documentation of the code, and a report describing the design and the implementation choices adopted.

How to run it

To compile the project remains sufficient to issue in the project root:

$ make

Two scripts are provided:

  • microcc.sh: it compiles and links (with the rt-support) a microC program provided as argument
  • run_test.sh: it runs all the test cases that are in the dir test/samples. Run it after you've already compiled the project.

Issuing the following will compile the project and execute the test script run_test.sh i.e running all the tests:

$ make test

microc-comp's People

Contributors

k4j3d3v avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.