# Copyright (C) Mohammad Hasanzadeh Mofrad - All Rights Reserved # Course: CS 2210 - Compiler Design (Spring 2016) # Project: Mini Java - part 4 - Code Generation # File: Readme # Author: Mohammad Hasanzadeh Mofrad # Email: hasanzadeh@cs.pitt.edu # Date: April 2016; Last revision 04-30-2016 # Mini Java - Code Generation ## Compatible GCC version # gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ## Compatible file character encoding # text/x-c; charset=us-ascii ## Successful run on arsenic.cs.pitt.edu ## Project structure This project consists of the following key files: * run.sh assign necessary permissions and compile the program * Makefile that build the program * parser.y contains grammars for YACC tool * driver.c runs the parser and code generator * lexer.l contains regular expressions for LEX tool * proj2.c and proj2.h contain procedures to print syntax tree * proj3.c and proj3.h contain procedures to print semantic tree * proj4.c and proj4.h contain procedures to generate codes * traverstree.c contains procedures to perform semantic checks * tokens.h contains token numbers of reserved words for lexical analyser * spim.linux is the SPIM MIPS SIMULATOR * trap.handler is the trap handler for SPIM # Build ## Building the project using run.sh (easy way) Give the execute permission and run it * chmod +x run.sh * ./run.sh PATH_TO_TEST_FILE/TEST_FILE ## Building the project using makefile (hard way) For help building the parser: * make help For building the parser: * make parser For using the parser: * ./parser PATH_TO_TEST_FILE/TEST_FILE For generating the code: * chmod +x spim.linux * chmod +x trap.handler * ./spim.linux -file TEST_FILE.s # Project Description ## Code generation features Proj4.c contains the libraries developed for code generation. driver.c is the main file invoke the proj.c for starting the code generation. The following is the list of implemented features: 1. Jump to main label (emit_init) 2. system.println and system.readln syscalls (emit_init) 3. Create procedure declaration (emit_decl + emit_data) 4. Memory allocation and array allocation (emit_data + calc_dim) 5. Procedure call with passing arguments (emit_func + emit_code) 6. If statement (emit_ifstmt) 7. while statement (emit_whilestmt)