For this last assignment, you will make your compiler generate i386 assembly language (32-bit mode).
As in previous assignments, you must hand in to Marmoset a .zip archive containing your source code. The .zip file must contain a file called Makefile. Marmoset will run make on this Makefile to compile your compiler. The Makefile must generate an executable (binary or shell script) called joosc. The joosc executable must accept multiple filenames as arguments. All of the files listed on the joosc command line, and only those files, are considered part of the program being compiled.
Unlike javac and unlike the dOvs version of Joos, your joosc compiler should not look for classes in .class files on the CLASSPATH; it should read only the Joos 1W source files listed on the command line. This means that all classes, including classes such as java.lang.Object, must be available in source form and must be specified on the joosc command line. Unlike javac, Joos does not care what directory a source file is in (i.e. it does not require the directory structure of the source code to match the package structure). However, the class declared in a file must still have the same name as the filename. For example, Java would require that the class java.lang.Object be declared in the file Object.java in the directory java.lang, whereas Joos only requires the file to be named Object.java, but otherwise allows it to be in any directory.
For the purposes of this course, a minimalist version of the Java standard library is provided. This library can be found in the linux.student.cs environment in the directory /u/cs444/pub/stdlib/5.0. Marmoset will include all files in this library on the joosc command line for every test, in addition to other source file(s) specific to that test. The following versioning scheme is used to make it possible to correct errors and/or to extend the library for future assignments (although we aim to minimize the number of changes that will be required). The 5 in the directory name refers to Assignment 5, and the 0 is the first version of the library. Any corrections to the Assignment 5 version of the library will appear in the directories 5.1, 5.2, etc.
As in previous assignments, joosc should process the Joos 1W files given on the command line, produce appropriate diagnostic messages on standard error, and exit with one of the following Unix return codes:
If the input program is valid Joos 1W, your compiler should output, into the subdirectory output of the current working directory, one or more files with the extension .s containing the assembly language code implementing the program. It is recommended that the code implementing each class be generated into a separate .s file. You may assume that the output directory exists before your compiler runs, and that the directory is empty. After your compiler runs, each of the .s files in the directory will be assembled with the command:
/u/cs444/bin/nasm -O1 -f elf -g -F dwarf filename.sAfter all of the files are successfully assembled, the file runtime.s from the standard library (see below for description) will also be assembled and placed in the output directory. Then, all of the .o files generated by nasm in the output directory will be linked using the command:
ld -melf_i386 -o main output/*.oFinally, the generated executable main will be executed.
Your joosc compiler, the assembler and linker, and your final main executable will be run on one of the Linux CPU servers (e.g. linux028.student.cs).
One of the generated .s files must define the global symbol _start:
global _start _start:When your program is run, execution will start from this point.
Unlike in Java, the first method that begins executing is not static void main(String), but static int test(). All of the test inputs will have such a method. The class containing the test method will be listed first on the joosc command line, before any other compilation units. The code that you generate at _start should initialize all static fields, then call this method. When the method returns with return value x, your program should exit with exit code x using the sys_exit system call. To execute this system call, load the value 1 (indicating sys_exit) into register eax, load the exit code into register ebx, then execute the instruction int 0x80.
Java specifies a very precise but complicated order in which static fields must be initialized (JLS 12.4). For Joos, the order is specified by the following rules:
The runtime.s file included with the standard library contains several utilities that are likely to be useful.
For the convenience of groups doing their development on Windows, a former student has made available a Windows translation of runtime.s. You may use this version during development. Marmoset will test your compiler on the linux.student.cs servers with the runtime.s file that is included with the Joos standard library.
Before starting to implement this assignment, it is strongly recommended that you meet with your group to design and agree on conventions for
The Marmoset tests for this assignment take several minutes to run. Do not submit more than one submission at a time to Marmoset. If Marmoset reports that your previous submission has not been tested yet, do not submit another one. Denial-of-service attacks on Marmoset will result in disciplinary action.
Submit to Marmoset a PDF document of no more than five pages explaining the design decisions you made in completing the assignment. As in previous assignments, the document should be organized to enable someone unfamiliar with your code to understand the structure of your compiler. In the document, discuss challenges that you encountered and how you tried to overcome them in your design and implementation. Also explain the testing that you did before submitting to Marmoset.
The document will be hand-marked, with 2/3 of the marks for organization, clarity, and style, and 1/3 of the marks for technical content.
According to the late policy posted on the course web page, design documents submitted after the assignment deadline will not be marked and will receive a mark of zero. If you cannot finish the assignment by the deadline, submit what you have by the deadline, and explain any unfinished parts in your design document.