CSCE 425/825 - Compiler Construction


CSCE 425/825
Course Home Page
Course Description
Calendar
Project Upload
Resources
Project
Java
ANTLR
JVM and ASM
Eclipse and Plugins
  Getting Started
The project for this course is designed to work in the Eclipse environment.   It is possible to develop a solution to this project outside of Eclipse but relatively littl support will be provided for students who choose to do so.  In the following the bold arrow separated text indicates a series of menu selections in Eclipse, e.g., X->Y->Z means select X from the tool bar, then menu selection Y and sub-menu selection Z.

   Running Eclipse
The StaticJava compiler is implemented using a few Java 1.5 generics.  For this reason, you must build it using an appropriate SDK and using Eclipse 3.2.   If you have your own machine it is best to download Eclipse 3.2 and install it yourself.   If you use CSCE computing labs you can use the installed version of Eclipse 3.2.  

Note that you can always navigate to the actual files in your Eclipse workspace via the command line.   This is useful for launching tools, such as Acrobat, that Eclipse is not configured to launch.

   Setting Up Eclipse
  • Make sure that Project->Build Automatically menu item is checked.
  • Change your Java compiler to 5.0: Window->Preferences...->Java->Compiler, set Compiler Compliance Setting to 5.0
   Accessing the Compiler Source
We are distributing the source to the compiler via a SVN site that is shared by students taking the course at UNL and KSU.  To access the source files and other course materials you will need to use an SVN plugin for Eclipse; we prefer the Subversive plugin. You can install it in Eclipse by selecting Help->Software Updates->Find and Install and then selecting Search for new features to install. At that point you should add a New Remote Site with the address:
   http://www.polarion.org/projects/subversive/download/1.1/update-site/
and then proceed with the instructions. If you are using a non-Windows system, you need to additionally set the Subversive Preferences to use SVN Kit 1.1.4 (see the bottom of this page).

If you have not used an SVN plugin you can start by read the CVS Eclipse tutorial (see Help->Help Contents->Workbench User Guide->Getting started->Team CVS tutorial). More specific documentation is available at the Subversive project home, but the concepts are very similar to CVS. If you have never used SVN or CVS before see the Gentoo Linux CVS Tutorial linked off of the CourseResources page for a brief CVS tutorial.

You can access the compiler project using the SVN repository available at:
    https://robby.user.cis.ksu.edu/courses/compiler

Note that while you can browse the sources at that URL, but you'll want to use Subversive to get a copy of the sources.

The repository has three modules and you should checkout each of them; to do that you highlight the module name, right click, and select checkout. The names of the modules are:
  • sjc -- contains the source for the StaticJava Compiler
  • slides -- contains the .pdf slides for the course lectures
  • examples -- contains the examples used in the lectures
You can then enter the java Eclipse view Window->Show View->Other...->Java to work with the compiler source code. 

   Installing Plugins
There are a number of plugins that you will need to work with the compiler; some of the plugins you will use later in the course.  See the documentation given at collected resources for the URLs of plugin download sites.   One of the easy ways to install plugins is to use the Help->Software Updates->Find and Install feature; many of the plugins have step by step directions on how to perform an install.

   JDT AST Viewer Plugin
To view the JDT AST representation of a Java file, you need to open the file in Eclipse, and open the AST view: Window->Show View->Other...->Java->ASTView

   Bytecode Outline Plugin
To view the bytecode representation of a Java file, you need to open the file in Eclipse, and open the Bytecode view: Window->Show View->Bytecode

   Running the sjc Compiler
So now you have the source folder compiler-sjc module visible in your Java view.  Open the source folder src-sjc which contains the SJC.java file -- the main class for running sjc.   To run sjc, right click on SJC.java, then Run As->Run.... It should open up the Eclipse launcher dialog.   Highlight Java Application and then click the New button. Select the Arguments tab, and fill in the full path of the StaticJava file that you want to compile (e.g., /home/dwyer/workspace/compiler-sjc/src-examples/Factorial.java), and put -ea in the VM arguments to enable Java assertion checking. Click run. The generated class file will be written in the same directory as the Java file. Note that, if the Java file is in an Eclipse Java source folder, Eclipse will not show the class file in the Package Explorer unless you use the refresh right-click selection. To run the program, go to the directory in the command shell, and type:

java -classpath .:$PATH_TO_STATIC_LIB_CLASS <classname> <program arguments>

For example, by default the libraries are in the bin directory of the compiler module in your installation:

java -classpath .:/home/dwyer/workspace/compiler-sjc/bin Factorial 3

    Running sjc test cases in Eclipse
The source folder src-sjc-test in the compiler-sjc module containts some JUnit test cases to run sjc. For example, if you want to run the test cases in ByteCodeGeneratorTest.java, right click on the file, then select Run As->JUnit Test.