Giter Club home page Giter Club logo

mini-java-compiler's Introduction

mini-java-compiler

Mini-Java to LLVM IR compiler, a semester project for the compilers course at the University of Athens

Compilation and run

make

java Main <inputFile1> <inputFile3> <inputFile3> ...

Then the LLVM IR files are generated like <inputFile3>.ll

To run the LLVM clang needs to be installed

sudo apt update && sudo apt install clang-4.0

Then compile the .ll file with

clang-4.0 -o <executable> <inputFile3>.ll

or run the experiments with ./run.sh

About the implementation

About the Symbol Table

All the classes, variables, and methods are stored on the SumbolTable. The SymbolTable class inherits from the TreeMap data structure in java and it stores objects of the Symbol type. Symbol class is an abstract class that all the classes, variables, and methods inherit from. It shares the common information about these fields such as name, type, and offset. In SymbolCLass class are stored all the classes. There are fields for the methods and the variables of the classes. These fields are stored in a SymbolTable too. In SumbolMethods are stored all the methods of the class. This object also stores the variables and the arguments of the method. Finally SymbolVariable stores the variables. Both SYmbolClass and SymbolMethod implement setters and getters according to their needs.

About the Virtual Table

The VirtulaTable is a TreeMap data structure that holds all of a class's methods. It recursively records the parent classes' methods, and if a child class overrides one of them, the information is given to the table.

About the visitors

As for the visitors, there are 4 of them that implement different processes of semantic checking and for the LLVM IR generation. Firstly the parse tree is visited by the ClassDeclarationVisitor is responsible for adding to the SymbolTable all the class declarations. Then the parse tree is visited by the FillVisitor that fills all the classes with their variables and methods and also fills the arguments and the variables of the methods too. Then, the parse tree is visited by the CheckTypeVisitor which performs type checking of the expressions and the statements of the methods. Finally, the LLVM visitor parses the tree and creates LLVM IR based on the data in the Symbol and Virtual tables.

mini-java-compiler's People

Contributors

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