Skip to content

bmansfieldRIT/mini-java-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

mini-java-compiler

This is a compiler written for the subset of the Java Language. The course, as far as I know, is still ongoing, so I will keep this repo purposefully inaccesssable to the degree I can. If you are taking this class and found your way here, congratulations. The specification this language was based off of can be found here:

http://www.cs.tufts.edu/~sguyer/classes/comp181-2006/minijava.html

How to build the compiler:

  1. cd into the mini-java-compiler directory

  2. run make

How to run the compiler

  1. Download Jasmin, the Java Bytecode Generator.

https://sourceforge.net/projects/jasmin/files/

From the Jasmin homepage: "Jasmin is an assembler for the Java Virtual Machine. It takes ASCII descriptions of Java classes, written in a simple assembler-like syntax using the Java Virtual Machine instruction set. It converts them into binary Java class files, suitable for loading by a Java runtime system.

  1. Place jasmin.jar into the src folder

Usage:

./emjc <source_file>

Optimization

The implemented optimization is a simple dead code removal. It scans the code for instances where a variable is defined, but then never used in any expression or other definition. They are optimized away, ensuring that no code is generated by those statements. It works particularly well when there is dead definitions that invoke multiple arithmetic operators.

Included is an example benchmark "TestOptimization.emj" where several variables are defined, yet go unused. They are optimized away by the compiler if the --opt option is used. Also included are two example outputs in two folders, test_unopt and test_opt. Given the same benchmark, the optimized output (PrintNums.j) is reduced by 10 bytecode instructions and returns the same output.

About

Compiler for a subset of the Java language

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published