Giter VIP home page Giter VIP logo

minijava-compiler's Introduction

MiniJava Compiler

This is a MiniJava compiler that targets LLVM, written in Java with the help of JFlex, JavaCUP and JTB.

I would like to thank Stefanos Baziotis for contributing his MiniJava testsuite!

Usage

# Compile the project
make

# Run the compiler
java Main file1 [file2 [file3 ...]]

# Cleanup
make clean

Implementation

Scoping & Symbol Table

MiniJava is a simple language when it comes to scoping: all declarations precede statements. This property prevents declarations from showing up in nested compound statements such as if-else, while and block statements. Thus, the symbol table need only keep track of class declarations, class-scoped declarations (i.e. fields and methods) and method-scoped declarations (i.e. formal parameters and local variables).

Compilation Phases

We start by producing an AST for the source program with the help of JFlex, JavaCUP and JTB. Then, we check its semantics & finally generate the LLVM IR code with the help of the following visitor classes:

  1. STVisitor populates the symbol table

  2. SCVisitor type checks the program

  3. VTVisitor populates the virtual method table

  4. CGVisitor generates the resulting LLVM IR code

Notes

  • The MainClass class and its main method are not handled as special cases. The method's argument is stored in the symbol table with type String[], so, if it appears in any expression in the program, a type error will be triggered by SCVisitor inevitably.

  • Scopes are implemented by constructing strings of the form ClassID [":" [MethodID]] and passing them as arguments to children nodes as the visitors are walking the AST.

  • LLVM-IR code virtual registers are assigned names of the form %_number, where number is an auto-incrementing integer.

minijava-compiler's People

Contributors

georgesittas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.