Java Compiler for the MiniJava language

Overview

Java Compiler for the MiniJava language

Setup

Our project requires the following tools with the specified versions.

Tool Version
Java >= 14
Maven 3

The scripts (see below) require a bash environment (in order to find the project directory).

GitHub Dependencies

Name Website Repo
Firm http://libfirm.org/ https://pp.ipd.kit.edu/git/libfirm
MJTest n/a https://git.scc.kit.edu/IPDSnelting/mjtest

Build

Execute the build script in the root directory from anywhere you like. Arguments to the build script are passed to Maven (for example -DskipTests).

./build [maven arguments]

Run

Execute the run script in the root directory from anywhere you like with the arguments for the compiler.

CLI usage:

Java Easy Compiler

usage: compiler [<action>] [<optimization-level>] [<output-verbosity>] [<debug options>]

Action
 -e --echo <path>             output file contents
 -l --lextest <path>          output the tokens from the lexer
 -p --parsetest <path>        try to parse the file contents
 -ar --print-ast-raw <path>   try to parse the file contents and output the raw AST
 -a --print-ast <path>        try to parse the file contents and output the pretty-printed AST
 -c --check <path>            try to parse the file contents and perform semantic analysis
 -f --compile-firm <path>     transform the file to Firm IR and compile it using the Firm backend
 -co --compile <path>         compile the file (default)

Optimization Level
 -O0 --optimize0              run (almost) no optimizations
 -O1 --optimize1              run standard optimizations (default)

Output Verbosity
 -v --verbose                 be more verbose
 -d --debug                   print debug information

Debug Options
 -dg --dump-graphs            dump the Firm graphs of all methods
 -ni --no-inline              disable the inline optimization

Help
 -h --help                    print command line syntax help

for more information check out: https://github.com/larsk21/compiler-minijava

Optimizations

Our compiler includes the optimizations listed below. The optimizations are assigned to two levels, enabled with -O0 and -O1, with level 1 being the default. All optimizations run in level 0 are also run in level 1.

Additionally, the compiler uses a more advanced register allocator in level 1.

Middle End Optimizations

Optimization Minimum Optimization Level
Constant Propagation 0
Arithmetic Identities 0
Trivial Jumps & Linear Blocks 1
Arithmetic Strength Reduction 1
Pure Functions 1
Inliner 1
Loop Invariant Code Motion 1
Loop Unrolling 1
Unused Arguments 1
Common Subexpression Elimination 1

Backend Optimizations

Optimization Minimum Optimization Level
Jump Inversion 1
Comments
  • Add loop invariant optimization

    Add loop invariant optimization

    Adds an optimization that moves loop-invariant nodes in front of the loop (to the deepest common dominator of the loop entry point predecessors). In nested loops, nodes are moved out as far as possible. Currently, only data nodes are moved (except Phis), but const/pure (? @g4rgoil) functions could be added, if applicable.

    enhancement 
    opened by larsk21 12
  • Proposal for logging system

    Proposal for logging system

    This PR proposes a unified logging system for our compiler. Please let me know if you would like changes to the overall design or to the API of Logger. Console output is currently structured as follows:

    error: lexer: 42,28: unexpected character '$'
    
    opened by g4rgoil 7
  • Add inlining optimization

    Add inlining optimization

    Adds an inliner to the local optimizations. Features:

    • efficient convergence by bottom-up traversal of call graph in alternation with local optimizations
    • heuristic analysis of the benefit of inlining a given call site via number of constant parameters and size of callee
    • ensures that the total code size only grows by a constant factor by tracking the size of visited functions in comparison to the first visit
    • Recursive functions usually won't be inlined; however, this is not necessarily so if some input arguments are constant. In this case, the inliner will apply up to a constant number of inlining passes in hope of eliminating the function call completely or at least partially.

    Further possible improvements:

    • add loop analysis (e.g. execfreq of libfirm) to inlining heuristics

    Furthermore, the PR adds dead code elimination based on the call graph, which is directly integrated into Optimizer. This is especially useful in combination with the inliner, which often "kills" many functions during the inlining passes.

    Note that in principal, the inliner might increase the compilation time significantly. However, based on some manual testing, the only test case that compiles much slower (about 3 times slower) at the moment seems to be the raytracer.

    opened by N-Maas 6
  • Add call graph and global optimizations

    Add call graph and global optimizations

    This PR introduces an interface for global optimizations (i.e. optimizations that work on the entire program instead of a single graph). A call graph is also implemented to query calling-realtionships between functions and to detect recursions.

    opened by g4rgoil 4
  • Remodel standard library

    Remodel standard library

    Standard library calls are now a special construct without System or System.out/System.in being defined on its own. The following code yields "System cannot be resolved":

    // inside some method
    if (System.out == null) {
      ...
    

    detailed changes:

    • remove global variable System
    • change StandardLibrary to include only names and method definitions
    • explicitly check method invocations to identify standard library calls
    • allow removing the object of a method invocation
    • add tests for standard library calls
    opened by larsk21 4
  • Benchmarks

    Benchmarks

    This branch is intended to collect some ideas for benchmarks.

    If you want to see a really huge difference between -O1 and -O0, check out the AbstractedMath benchmark :smile:

    opened by N-Maas 2
  • Add loop unrolling optimization

    Add loop unrolling optimization

    This PR implements an optimization that tries to unroll loops when the number of iterations is known at compile time. Currently loops can only be unrolled by factors that evenly divide the number of iterations.

    enhancement 
    opened by g4rgoil 2
  • Function Attributes and Pure Function Optimization

    Function Attributes and Pure Function Optimization

    This PR implements an analysis for a number of possible attributes of functions and uses the results to make some optimizations regarding calls to pure and const functions.

    • Calls to const functions are completely removed from the memory chain.
    • Unused calls to pure functions are removed from the graph (this also includes malloc-like functions).
    • Calls to pure or const functions are unpinned so that they're free to move between blocks.

    On it's own, this optimization will only have a very minor performance impact. It will however open up opportunities for improvements to other optimizations. For example, certain function calls may be optimized as part of CSE, loop-invariant code motion, or a load-store optimization.

    enhancement 
    opened by g4rgoil 2
  • Improved handling of Div and Mod

    Improved handling of Div and Mod

    This PR seeks to improve our handling of division and modulus operations. The goal is to check for the edge case of INT_MIN (/|%) -1 explicitly and to handle it separately. We will then be free to use 32-bit instead of 64-bit divisions.

    • [x] Generate the required Firm graphs during transformation
    • [x] Switch to double-word division during register allocation
    • [x] Update strength reductions to work with the new graphs
    enhancement 
    opened by g4rgoil 2
  • Use `ErrorHandler` in detailed name/type analysis

    Use `ErrorHandler` in detailed name/type analysis

    It would improve the detailed name and type analysis, if we were able to report more than one error. The necessary changes include moving from exception throwing to collecting errors (easy), as well as taking into account that reporting an error would not end the method immediately, potentialy causing follow-up errors (more complicated).

    enhancement 
    opened by larsk21 2
  • Large integer literals in Lexer

    Large integer literals in Lexer

    The value of an integer should not be restricted in the Lexer, therefore any integer (that is reasonable to store in the memory, ~1000 characters at least) should be accepted by the Lexer.

    Current behaviour: error: [...] integer literal too large

    bug 
    opened by larsk21 2
Owner
Lars
Computer science student at Karlsruhe Institute of Technology (KIT), Germany.
Lars
lazy-language-loader improves loading times when changing your language by only reloading the language instead of all the game resources!

lazy-language-loader lazy-language-loader improves loading times when changing your language by only reloading the language instead of all the game re

Shalom Ademuwagun 7 Sep 7, 2022
Compiler that compiles our language flowg to g-code (4th semester project)

flowg FlowG is a language that greatly simplifies manual g-code programming. It is a high-level language that supports functions, for loops, if statem

Mads Mogensen 4 Jun 15, 2022
Jamal is a macro language (JAmal MAcro Language)

Jamal Macro Language Jamal is a complex text processor with a wide variety of possible use. The first version of Jamal was developed 20 years ago in P

Peter Verhas 29 Dec 20, 2022
Very spicy additions to the Java programming language.

Project Lombok Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. Never write another g

Project Lombok 11.7k Dec 30, 2022
A list of direct references to classes and interfaces in the Java Language Specification (3d Ed.)

A list of direct references to classes and interfaces in the Java Language Specification (3d Ed.) and a program to compute the indirectly required classes and interfaces

Joshua Bloch 12 Jun 3, 2022
A dubbo gateway based Java language.

A dubbo gateway based Java language.

老夫正年轻 19 Sep 24, 2022
Scripting language written in, and, designed to communicate with, java

mi-lang Scripting language designed to communicate with java, to allow for easy plugins, addons, etc in any project, all without having to create an e

null 7 Dec 17, 2022
Official Java library for the DeepL language translation API.

DeepL Java Library The DeepL API is a language translation API that allows other computer programs to send texts and documents to DeepL's servers and

DeepL 26 Dec 29, 2022
Representational State Transfer + Structured Query Language(RSQL): Demo application using RSQL parser to filter records based on provided condition(s)

Representational State Transfer + Structured Query Language: RSQL Demo application using RSQL parser to filter records based on provided condition(s)

Hardik Singh Behl 9 Nov 23, 2022
MFP (Mathematic language For Parallel computing) Android library

MFPAndroLib This is MFP (Mathematic language For Parallel computing) Android library project. MFP is a novel scripting programming language designed a

Tony Cui 6 Sep 5, 2022
Metremenqeemi - Android/iOS app to teach the Coptic Language

ⲙⲉⲧⲣⲉⲙⲛ̀ⲭⲏⲙⲓ The Open Source Android/iOS app to learn how to read and understand the Coptic Language Join our Discord Channel About the Curriculum The

Mark Yacoub 8 Aug 30, 2022
Unofficial community-built app for the Japanese language learning tool jpdb.io.

jpdb-android Unofficial community-built app for the Japanese language learning tool jpdb.io. While the web app works in most scenarios, the goal with

null 3 Feb 15, 2022
JurjenLang, an interpreted programming language

JurjenLang An untyped interpreted functional programming language Getting started Follow these three steps on your computer to get started git clone h

JVerbruggen 5 May 3, 2022
Create different patterns and designs using your favorite programming language for this project.

Patterns project for Hacktoberfest Create different patterns and designs using your favourite programming language weather it be a square pattern, sta

Pulkit Handa 5 Oct 5, 2022
LaetLang is an interpreted C style language. It has file reading/writting, TCP network calls and awaitable promises.

LaetLang ?? LaetLang is an interpreted C style language built by following along Robert Nystrom's book Crafting Interpreters. This is a toy language t

Alexander Shevchenko 6 Mar 14, 2022
Code4Me provides automatic intelligent code completion based on large pre-trained language models

Code4Me Code4Me provides automatic intelligent code completion based on large pre-trained language models. Code4Me predicts statement (line) completio

Code4Me 38 Dec 5, 2022
"Some" Utilities you can use for your Java projects "freely"! Files are compiled with Java-8 and above, but mostly Java-11.

✨ Java-SomeUtils ?? "Some" Utilities you can use for your Java projects "freely"! *"Freely"* forcing you to include the license into your program. Fil

JumperBot_ 2 Jan 6, 2023
Java-Programs---For-Practice is one of the Java Programming Practice Series By Shaikh Minhaj ( minhaj-313 ). This Series will help you to level up your Programming Skills. This Java Programs are very much helpful for Beginners.

Java-Programs---For-Practice is one of the Java Programming Practice Series By Shaikh Minhaj ( minhaj-313 ). This Series will help you to level up your Programming Skills. This Java Programs are very much helpful for Beginners. If You Have any doubt or query you can ask me here or you can also ask me on My LinkedIn Profile

Shaikh Minhaj 3 Nov 8, 2022
(Java & React) Yazılım Geliştirici Yetiştirme Kampı Java kısmına ait yazılan kaynak kodlar ve ödev çalışmalarım.

JavaCamp Kamp sürecinde yazılan kaynak kodlar ve ödev çalışmalarım. Day 1 1)Intro Day 2 2)oopIntro 2.1)oopIntro ~ Homework Day 3 3)oopIntro2 3.1)inher

Melih Çelik 17 Jun 26, 2022