Compiler construction (MRJP) lab project
Laboratory grade is based on a project involving the implementation of a compiler for a simple imperative language Latte.
The project consits of three stages:
Your lab supervisor can set slightly different deadline, in particular require project presentation in person.
- Front-end: syntactic and semantic analysis. Deadline Nov. 18.
- JVM back-end. Deadline Dec 16.
- LLVM or x86 back-end, extensions. Deadline Jan. 20.
At most 30 points in total, counting towards final course mark.
To pass the lab and qualify to sit an exam, it is required to submit satisfactory solutions for all stages and get a total of at least 15 points.
Points are awarded for:
A more precise specification of extensions is contained in the language description.
- front-end (4);
- additionally up to 2 points if the parser is written without using a parser generator;
- JVM back-end JVM (5)
- back-end for LLVM (8) or (exclusive) x86 (10)
- LLVM code in SSA form - additional 1p
- register allocation for x86 - additional (up to) 3p
- optimisations - up to 3p
- Extension (x/y denotes points for LLVM/x86 respectively)
- arrays (2)
- structures (2)
- objects (attributes, methods, inheritance without method override)
- (3/4) extra
- virtual methods (3/4) extra (in total 8/10 can be awarded for objects with virtual methods)
- garbage collection (2)
Late submissions are subject to penalty of 2p for each week started; however no submissions will be accepted after February 22.
The project must be original work, developed independently by the student submitting it.
- you must not look at other students' code, show or share your code in any manner.
- any foreign code (e.g. from books, tutorial, or other sources) must be clearly marked and attributed.
- The project must be submitted as a packed TAR archive (.tar.gz, .tgz, tar.bz2 or .tbz)
- The project root must contain at least:
- Text file README describing how to compile and run the project, used tools and libraries, implemented extensions, structure of the project, pointers to more detailed documentation.
- Makefile allowing to build the program
- A directory src containing only source files of the project (possibly including Latte.cf, makefiles etc.); auxiliary files such as libraries, etc should be placed in other directories.
- The project must be buildable on lab computers by running make in the project root.
- All necessary libraries (except standard library of the programming language used) must be described in README.
- After the build, project root must contain an executable file latc (may be a shell script calling other programs)
- The compiler must accept all test programs from the directory good
and reject (with appropriate error messages) all programs from the directory bad. For the extensions, the compiler must accept all programs from the respective subdirectories in extension. Execution of a correct test program must give output exactly the same as in the corresponding .output file
(given input in the corresponding .input file, if any).
- For an accepted program, the compiler must output OK ("OK\n") and exit with code 0.
- For a rejected program, the first line of stderr must be ERROR ("ERROR\n"). Further linses should contain appropriate error messages. The compiler must then exit with a non-zero exit code.
Stage II - JVM backend
The project must fulfill all the conditions above, moreover:
- Executing latc foo/bar/baz.lat for a correct program
baz.lat should create file baz.j (Jasmin code)
and baz.class in the directory foo/bar
(passing option -d to Jasmin may be helpful here).
- The file jasmin.jar should be placed in lib
- Helper methods (printInt etc.) should be placed in the class Runtime.class in the lib directory.
Stage III - LLVM backend
- After running make the project root should contain executable latc_llvm
- Running latc_llvm foo/bar/baz.lat for a correct program
baz.lat should create files baz.ll (readable LLVM code) and executtable a.out in the directory foo/bar.
- Helper functions (printInt etc.) should be placed in the file runtime.bc in the lib directory (with sources in runtime.ll).
Stage III - x86 backend
- After running make the project root should contain executable latc_ARCH where ARCH is x86 or x86_64
- Running latc_ARCH foo/bar/baz.lat for a correct program
baz.latshould create files baz.s (assembly) and executtable a.out in the directory foo/bar.
- Helper functions (printInt etc.) should be placed in the file runtime.o in the lib directory (with sources in runtime.s).
Test programs archive: