Coder Social home page Coder Social logo

feup-comp's Introduction

Compilers Project

For this project, you need to install Java, Gradle, and Git (and optionally, a Git GUI client, such as TortoiseGit or GitHub Desktop). Please check the compatibility matrix for Java and Gradle versions.

Project setup

There are some import folders in the repository. Your development source code is inside the subfolder named src/main. Specifically, your initially application is in the folder src/main/pt/up/fe/comp2023, and the grammar is in the subfolder src/main/antlr/comp2023/grammar. Finally, the subfolder named test contains your unit tests.

Compile and Running

To compile and install the program, run gradle installDist. This will compile your classes and create a launcher script in the folder ./build/install/jmm/bin. For convenience, there are two script files in the root folder, one for Windows (jmm.bat) and another for Linux (jmm), that call this launcher script.

After compilation, a series of tests will be automatically executed. The build will stop if any test fails. Whenever you want to ignore the tests and build the program anyway, you can call Gradle with the flag -x test.

Tests

The base repository comes with two classes that contains unitary tests in the package pt.up.fe.comp, TutorialTest and GrammarTest. The tests in TutorialTest should all pass just using the provided code. GrammarTest contains tests for the complete Java-- grammar, and most should fail. By the end of Checkpoint 1, all tests should pass.

The class GrammarTest contains several static String variables at the beginning of the class where you should put the name of your rules for each type of rule that appears there. You have to set these variables to pass all tests.

To test the program, run gradle test. This will execute the build, and run the JUnit tests in the test folder. If you want to see output printed during the tests, use the flag -i (i.e., gradle test -i).

You can also see a test report by opening the file ./build/reports/tests/test/index.html.

Reports

We also included in this project the class pt.up.fe.comp.jmm.report.Report. This class is used to generate important reports, including error and warning messages, but also can be used to include debugging and logging information. E.g. When you want to generate an error, create a new Report with the Error type and provide the stage in which the error occurred.

Parser Interface

We have included the interface pt.up.fe.comp.jmm.parser.JmmParser, for which we already provide an example implementation in the file src/main/pt/up/fe/comp2023/SimpleParser.java.

To configure the name of the class of the JmmParser implementation that should be automatically used for tests, use the file config.properties (more details below).

Compilation Stages

The project is divided in four compilation stages, that you will be developing during the semester. The stages are Parser, Analysis, Optimization and Backend, and for each of these stages there is a corresponding Java interface that you will have to implement (e.g. for the Parser stage, you have to implement the interface JmmParser).

config.properties

The testing framework, which uses the class pt.up.fe.comp.TestUtils, has methods to test each of the four compilation stages (e.g., TestUtils.parse() for testing the Parser stage).

In order for the test class to find your implementations for the stages, it uses the file config.properties that is in root of your repository. It has four fields, one for each stage (i.e. ParserClass, AnalysisClass, OptimizationClass, BackendClass), and initially it only has one value, pt.up.fe.comp2023.SimpleParser, associated with the first stage.

During the development of your compiler you will update this file in order to setup the classes that implement each of the compilation stages.

Self-Assessment

We consider our project deserves a grade of 20 out of 20.

Extras

Syntax and semantics

  • Support for more Java syntax, including for loops, switch statements, and all java operators.

Ollir

  • Ollir generation for all additional supported syntax, excluding the modulo operator, as it is not supported by ollir.

Optimizations

  • Some dead code removal, like removal of code after returns, breaks and continues, and in unvisited branches in if statements.
  • Removal of redundant JVM instructions (stores after loads of the same register, removal of redundant gotos).

feup-comp's People

Contributors

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