CS 553 Compiler Construction Fall 2007 Project #1 Adding floats to MiniJava Due August 31, 2005

Similar documents
CS 553 Compiler Construction Fall 2009 Project #1 Adding doubles to MiniJava Due September 8, 2009

CS 553 Compiler Construction Fall 2006 Project #4 Garbage Collection Due November 27, 2005

LECTURE 3. Compiler Phases

Compilers. Computer Science 431

Question Points Score

CS 415 Midterm Exam Spring 2002

CSE P 501 Exam 8/5/04

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

ECE251 Midterm practice questions, Fall 2010

Programming Project 4: COOL Code Generation

Introduction to Programming Using Java (98-388)

Software Concepts. 2-8 Explain the process of translating and executing a Java program. How might the World Wide Web be involved?

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

CS453 Compiler Construction

General Course Information. Catalogue Description. Objectives

CPSC 411, Fall 2010 Midterm Examination

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division

CS/SE 153 Concepts of Compiler Design

CS/SE 153 Concepts of Compiler Design

ECE573 Introduction to Compilers & Translators

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

Compiler Construction

CPSC 411: Introduction to Compiler Construction

Announcements. 1. Forms to return today after class:

Introduction to Programming Languages and Compilers. CS164 11:00-12:30 TT 10 Evans. UPRM ICOM 4029 (Adapted from: Prof. Necula UCB CS 164)

Chapter 4. Abstract Syntax

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment

Programming Assignment IV Due Thursday, November 18th, 2010 at 11:59 PM

CMPE 152 Compiler Design

UNIVERSITY OF CALIFORNIA

CS143 Handout 25 Summer 2012 August 6 th, 2011 Programming Project 4: TAC Generation

Important Project Dates

Introduction to Compiler Design

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

CS202 Compiler Construction. Christian Skalka. Course prerequisites. Solid programming skills a must.

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

CSE 401 Final Exam. March 14, 2017 Happy π Day! (3/14) This exam is closed book, closed notes, closed electronics, closed neighbors, open mind,...

CPS 506 Comparative Programming Languages. Syntax Specification

CMPE 152 Compiler Design

Compilers. Lecture 2 Overview. (original slides by Sam

Who are we? Andre Platzer Out of town the first week GHC TAs Alex Crichton, senior in CS and ECE Ian Gillis, senior in CS

CS153: Compilers Lecture 1: Introduction

Final Examination. Preliminaries. Compilers (CS F) Due: 11 a.m., Friday, 20 December 2002

Assignment Tutorial.

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

Project Compiler. CS031 TA Help Session November 28, 2011

Syntax-Directed Translation. Lecture 14

ECE Introduction to Compilers and Translation Engineering

COMP 412, Fall 2018 Lab 1: A Front End for ILOC

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

Java Bytecode (binary file)

CS 4120 and 5120 are really the same course. CS 4121 (5121) is required! Outline CS 4120 / 4121 CS 5120/ = 5 & 0 = 1. Course Information

Introduction to Programming (Java) 2/12

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

CPSC 411, 2015W Term 2 Midterm Exam Date: February 25, 2016; Instructor: Ron Garcia

CSE 401 Final Exam. December 16, 2010

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

CSE 401 Midterm Exam Sample Solution 11/4/11

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

CS111: PROGRAMMING LANGUAGE II

CS 432 Fall Mike Lam, Professor. Code Generation

COMP 202 Java in one week

CS 6371: Advanced Programming Languages

Syntax and Grammars 1 / 21

CS 116. Lab Assignment # 1 1

CS111: PROGRAMMING LANGUAGE II

Compilers and Interpreters

WACC Report. Zeshan Amjad, Rohan Padmanabhan, Rohan Pritchard, & Edward Stow

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 4

Programming Assignment IV Due Thursday, June 1, 2017 at 11:59pm

The Structure of a Syntax-Directed Compiler

CS 101 Fall 2005 Midterm 2 Name: ID:

CS 231 Data Structures and Algorithms, Fall 2016

Compiling Techniques

KU Compilerbau - Programming Assignment

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

CS /534 Compiler Construction University of Massachusetts Lowell

CSCE-608 Database Systems. COURSE PROJECT #2 (Due December 5, 2018)

Crafting a Compiler with C (II) Compiler V. S. Interpreter

CS 553: Algorithmic Language Compilers (PLDI) Graduate Students and Super Undergraduates... Logistics. Plan for Today

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

CS 241 Data Organization using C

Important Project Dates

Fundamentals of Compilation

Lab 2. Lexing and Parsing with ANTLR4

CSE 504: Compiler Design

Syntax Errors; Static Semantics

Programming Assignment I Due Thursday, October 9, 2008 at 11:59pm

PP6: Register Allocation - Optimization

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002

Programming Assignment I Due Thursday, October 7, 2010 at 11:59pm

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Transcription:

CS 553 Compiler Construction Fall 2007 Project #1 Adding floats to MiniJava Due August 31, 2005 In this assignment you will extend the MiniJava language and compiler to enable the float data type. The report is a crucial part of this project and all other projects in this course. You should proof read your report and rewrite it a couple of times. ANY spelling errors will result in 50% off the grade for this project. If the same grammar errors appear in more than two reports, the resulting penalty will increase. This assignment should be done in groups of two. Please speak to me at least a week before the assignment is due if you cannot find a partner. 1 Motivation The MiniJava compiler will be used throughout this course for hands-on projects such as implementing a garbage collector and implementing data-flow based code optimizations. By extending the MiniJava language and compiler to include the float data type, you will review all of the phases of a typical compiler and become comfortable with the MiniJava compiler. 2 The Assignment Your assignment is to extend the MiniJava language (see http://www.cs.tufts.edu/~sguyer/ classes/comp181-2006/minijava.html) and compiler to include the float data type. Float- Test1.java is a simple example of a MiniJava program that uses a float data type. /* FloatTest1.java A program that prints a constant float. MMS Aug 07 */ class FloatTest1 { public static void main(string[] a){ System.out.println(1.1); } } Your group will need to create MiniJava programs that use floats and compare the output of those test programs when compiled with javac and run with java versus when compiled with the MiniJava compiler and run with spim. For example, 1

% java -jar mjc.jar FloatTest1.java % spim FloatTest1.java.s > spim.output % javac FloatTest1.java % java FloatTest1 > sun.output % diff sun.output spim.output 0a1,5 > SPIM Version 7.2.1 of August 28, 2005 > Copyright 1990-2004 by James R. Larus (larus@cs.wisc.edu). > All Rights Reserved. > See the file README for a full copyright notice. > Loaded: /usr/local/share/xspim/cpu/exceptions.s The MiniJava-float compiler should be able to handle the following: float constants of the form digit* dot digit+ declarations of a float scalar usage of a float in an expression System.out.println() should accept an int or a float. For type rules, assume that floats can only be in arithmetic and comparison operations with other floats. Feel free to share such test cases with other groups in the class, but each group must submit their own test cases. 3 Getting Started The course mailing list will be sent a starting MiniJavaCompiler, a new version of Mips/SpillAllRegAlloc.java, and a file called float.s, which contains example float MIPS instructions. For further MIPS information, you should use the Appendix A from Hennessy and Patterson, for which a link can be found at http://pages.cs.wisc.edu/~larus/spim.html. 1. Untar the the MiniJavaCompiler-start.tar file. It will expand into MiniJavaCompiler-float/. 2. Run the CodeGenAssem main on a test input. > cd src > javac CodeGenAssem.java > java CodeGenAssem../TestCases/And.java 3. Look at the output from various phases of the compiler. The output is in the../testcases/ subdirectory and files And.java.ast.dot, And.java.ST.dot, And.java.IRT, And.java.IRT.dot, And.java.MIPSnoreg, and And.java.s. Use the graphviz dot program to create a graphic from the dot files (see Project 0). 2

4. To add more tokens and modify the concrete syntax and abstract syntax grammars, edit the ast.scc file. 5. Run SableCC to regenerate the lexer, parser, and AST data structures. (see Project 0) > sablecc ast.scc 6. Recompile CodeGenAssem.java. Step through the compiler by starting in CodeGenAssem.java and using the Eclipse debugger. You are responsible for understanding how the provided MiniJava compiler works and you will be using it in all the projects in this course. Learning someone else s code is not easy, but it is a task that you will find yourself doing quite often in industry and/or academia. I am open to any ideas you might have about modifying the compiler. You can modify your own copy as much as you want as long as the intermediate outputs remain the same. Modifications needed to lex, parse, and generate the AST: Modify ast.scc to include new tokens like float literals and the float keyword. Modify ast.scc to include grammar rules to parse declarations of float variables and parameters. Modify ast.scc to add new AST nodes for float literals and the float type. Modify the rules in ast.scc that convert the concrete syntax into abstract syntax to handle the new grammar rules and new AST nodes. Building the symbol table and performing semantic type analysis: ast visitors/buildsymtable.java, have gettype() handle the float type. ast visitors/checktypes.java, floats should only be in arithmetic and comparison operations with other floats and/or as an input to println(). SymTable/Type.java needs a FLOAT type. Translating the AST to the IR Tree representation: You will need to generate new classes called Tree/ExpFLOATCONST, Tree/ExpFLOATMEM, and Temp/FloatTemp (recommend that FloatTemp extends Temp). Tree/ExpCALL needs a flag to indicate if the call returns a float or not. Tree/TreeVisitor.java needs visit(expfloatconst e) and visit(expfloatmem). Tree/Print.java and Tree/PrintDot.java need to implement visit(expfloatconst e) and visit(expfloatmem). 3

Temp/Temp.java, make num protected instead of private. ast visitors/translate.java should generate an ExpFLOATCONST when it visits a float expression in the AST and an ExpFLOATMEM when it visits float id expressions. outaprintstatement should be modified to differentiate between int and float arguments (HINT: map relevant expression nodes in the AST to their Type in out methods). outacallexp should pass a flag into ExpCALL to indicate whether the call returns a float or not. outamethoddecl should put the return value into the floating point return address if the method returns a float. Generating MIPS assembly from the IR Tree representation Mips/CodeGen.java Add munchexpfloatconst and munchexpfloatmem. Generate floating point MIPS operations for arithmetic and comparison operators involving floats. Modify munchexpcall to return the float return register if the call returns a float. Modify munchstmmove methods to handle ExpFLOATMEM targets and float expressions as sources. Modify munchstmcjump to handle less than comparisons between floats. Frame/Frame.java, include a floatregset() method and a FRV() method. CodeGenAssem.java, call the spillall that is capable of spilling floating point registers. Put the floating point return register (FRV()) in the nospillset. Mips/MipsFrame.java Add static final Temp s for each of the floating point registers ($f0 thru $f31). Put the corresponding string for each floating point register in the tempmap. Create a method FRV() that returns the Temp that should hold the floating point return value ($f0). Create a floatregset() method that returns a set of at least three FloatTemps, but not $f0. Add printfloat MIPS code to programtail() SymTable/MemberSTE.java and Mips/InFrame.java, edit exp method so that it generates an ExpFLOATMEM if the id is a float variable. I recommend a test-driven approach. Write a test for each feature the extended compiler must handle and then make each test work. Also, make sure you understand how integers and integer operations are implemented in the current MiniJava compiler. Floats will be implemented very much like integers. 4

4 Your Report The report is an essential part of your completed assignment. Use it to describe the phases of the MiniJava compilers and how you implemented the float data type. Organize and present your document as if it were the only basis for your assignment s grade. The format of your writeup is up to you, but it should minimally include the following: Introduce the main goals of the project and in a couple of sentences summarize what you have accomplished. Briefly describe how you augmented each phase of the MiniJava compiler. Indicate any new tokens and grammar rules added to the MiniJava language. What new semantic type checking rules were needed? What new MIPS instructions are generated? How did you test your MiniJava extensions? What problems did you encounter while implementing the float data type. If you knew someone who was just about to start work on this assignment, what advice would you give them? What, if any, outside sources did you use (e.g., articles, books, other students)? This is particularly important. It s OK to look at books and articles and speak with your professor and fellow students (although sharing code and working with another group is strictly forbidden), but as with any scientific document, you should always cite your references and collaborations. You can either cite collaborations in footnotes or in a separate Acknowledgment section. There s no exact number of pages you should write, but if you ve got between two and three then you re in the right ballpark. 5 Hints for doing the assignment You should start this assignment right now!! You only have 11 days to complete this assignment. I recommend spending a couple hours a day on the project starting now. Start writing your report as you are planning the implementation. A well-written report with some missing implementation guarantees a much higher grade than a poorly written report with all the implementation. I can look at your code and help point you in the right direction, but the amount of help I can give may be inversely proportional to the amount of time until the due date. By no means should you spend several hours trying to figure out a weird bug; consult me for help. When e-mailing me about the project, send a copy of the relevant section of your code (not as an attachment; send it as text pasted into your message). Give a good description of the problem including information about the stack in a debugger. Also, indicate possible solutions you are considering. 5

6 What to turn in Turn in a hard copy of the report and email a copy in pdf format to mstrout@cs.colostate.edu. Create a jar file that includes all of the bytecode files and the source files. Submit a README file, the jar file, and two test cases via email to mstrout@cs.colostate.edu. The README should include specific command-lines for running the jar file on your provided test cases. 7 Due date This assignment is due Friday August 31st, at 2:10pm and is worth 10% of your final grade. Late assignments will be penalized 10% per day. 6