GithubHelp home page GithubHelp logo

iwilare / compiler-course-unipi Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 286 KB

Project and assignments for the "Languages, Interpreters and Compilers" 2020/2021 course @ Department of Computer Science, University of Pisa https://github.com/lillo/compiler-course-unipi

License: MIT License

OCaml 85.18% Makefile 0.16% C 0.21% Shell 0.52% Standard ML 0.58% M4 8.82% Monkey C 4.53%
ocaml compiler c-compiler llvm menhir

compiler-course-unipi's Introduction

MicroC LLVM compiler

Compiler for a C-like language written in OCaml, using LLVM as compilation backend and ocamllex/Menhir as frontend. Read the report documenting the main design choices.

Features

  • do-while loops;
  • pre/post increment/decrement operators, i.e., ++ and --;
  • abbreviation for assignment operators, i.e., +=, -=, *=, /= and %=;
  • variable declaration with initialization, e.g., int i = 0;
  • multi-dimensional arrays;
  • floating point arithmetic;
  • strings as in C, i.e. null-terminated arrays of characters;
  • structs.

Files structure

Syntax

  • ast.ml : definition of the polymorphically annotated AST and its pretty-printing procedures.
  • position.ml : definition of a located AST and of positions, shared among all modules. This is separated from the generic AST module ast.ml, of which this file represents a concrete AST instance with positions as annotations.
  • symbol_table.mli: the symbol table.mli interface, specifying the procedures implemented by the Symbol table abstract data type.
  • symbol_table.ml : concrete implementation of the symbol table.mli interface, using linked lists of hash tables.

Frontend

  • scanner.mll : ocamllex specification of the Scanner module.
  • parser.mly : Menhir specification of the Parser module, and is exposed through the parser engine.ml interface.
  • parser_engine.ml: exposed interface of the Parser, leveraging the Menhir Incremental API.

Backend

  • semant.ml : Semant module, implementing the semantic checker and the semantic AST definition.
  • codegen.ml : Codegen module, interfacing the compiler with the LLVM compiler framework and transforming semantically-checked ASTs into the LLVM IR.
  • builtins.ml : name and type information of the MicroC builtin functions, so that they are logically independent from both the Semant and the Codegen module and can be separately extended with more procedures.
  • util.ml : utilities and error managing procedures.

Main

  • microcc.ml : main compiler command-line interface logic.
  • opt_pass.ml : optimization flags that can be optionally provided to LLVM to optimize the resulting bitcode.
  • rt-support.c : runtime support for MicroC programs, with primitives such as print, getint, printchar, etc.

Getting started

Ensure all requirements are installed, then simply run:

make

Requirements

  • ocamlbuild
  • menhir
  • ppx_deriving
  • llvm

compiler-course-unipi's People

Contributors

iwilare avatar

Stargazers

 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.