CSc 453 : Programming Assignment 4 (Code Generation): Milestone 1
Start Date: Tue Nov 3, 2015
Due Date: 11:59 PM, Fri Nov. 13, 2015
1. General
This milestone involves MIPS assembly code generation for the
subset of C-- described below.
The generated code should adhere to the
operational semantics of C--.
1.1. Language Subset Considered
For this milestone, you need to handle C-- programs containing the following
language features, but not features that are excluded in the list below:
-
Variables:
-
Globals: variables of type int, char, array of int,
array of char;
-
Locals: at most one formal parameter, which is of type
int, char, array of int,
array of char (but no additional local variables).
-
Statements:
a sequence of zero or more assignments and procedure calls only (i.e., no
if, for, while statements), with these additional
restrictions:
-
Assignments are "simple", in the following sense: the
left-hand-side is a scalar variable (i.e., not an array reference) and the
right-hand-side is a scalar variable or a constant.
(This means that for this milestone we won't have
any references to array elements: the only reason for including arrays under
"Variables" (above) is to allow us to call
print_string("\n"), which makes it easier to print out
values.)
-
A procedure call takes at most one argument, which is of type
int, char, array of int, or array of char.
-
Expressions:
scalar variables, constants of type int or char, and
string constants (i.e., no operators, array references, function calls).
Note: Your compiler is not required to enforce the restrictions
described above. These restrictions given simply specify the subset of the
language you need to implement for this milestone. The test cases for this
milestone will all meet these restrictions.
1.2. The Target Architecture
The target architecture for this assignment will be the MIPS R2000
processor. The requirements in this regard are the same as for the
overall Assignment 4.
1.3. I/O Operations
Test programs will use the following two functions to print out the results
of computations:
extern void print_int(int x);
extern void print_string(char x[]);
For example, a program might look like this:
extern void print_int(int x);
extern void print_string(char x[]);
void main( void ) {
print_int(12345); print_string("\n");
}
In addition to the assembly code generated for the program, you should
generate the instruction sequence for the functions print_int()
and print_string(), as described in the document
Notes on Translating Three-Address Code to
MIPS Assembly Code.
1.4. Testing Your Programs
You can obtain the "expected output" for your test cases by
compiling them using gcc, with definitions for print_int()
and print_string() supplied in a separate file and linked in in the
obvious way.
1.5. Supporting Documents
Same as for the
overall Assignment 4.
2. Output
As before, your program will take its input from stdin and generate all
output on stdout. Error messages, if any, will be sent to stderr.
In case any errors are encountered during lexical or syntax analysis
or during type checking, you should stop generating code, but continue
to process the user program as best as possible.
The exit status of your program should be 0 if no errors are encountered during processing,
and 1 if any errors are encountered at any point.
3. Turnin
You should turn in all the sources to all the phases of your compiler.
You should also turn in a Makefile that supports at least the
following targets:
-
compile
The command "make compile" should build
your compiler from scratch, by invoking
the appropriate tools (flex, bison, etc.)
on their input specifications, and should result in the creation of an
executable file compile that implements the functionality
specified above for this assignment.
-
clean
The command "make clean" should delete
(at least) all software-generated files in the current directory,
including: C source files created by flex/bison,
e.g., y.tab.h, lex.yy.c, y.output,
etc.; object files, *.o; as well as the executable file
compile.
To turn in your program, execute the command
turnin cs453f15-assg4ms1 files.