Due on December 11th 11:59 PM (Accepted with no penalty). |
Accepted late by December 12th 11:59 PM for 1 penalty |
Not accepted after December 12th 11:59 PM |
Due on December 11th 11:59 PM (Accepted with no penalty). |
Accepted late by December 12th 11:59 PM for 1 penalty |
Not accepted after December 12th 11:59 PM |
None yet!
For this assignment you will write a code generator that generates X64 assembly code (suitable for use on the cycle servers) for A programs.
This project is intended to be an extension of the previous project code, but will be invoked via a new argument. Your code should be built and invoked via the command sequence
Where
<file.a>
is an input file
<outfile.s>
is a file containing assembly code for the input.
The only required behavior of your project is that the output file should be able to be linked, assembled, and run on the cycle servers, and that it obeys the semantics of the A language.
The code generator
will be implemented by writing codegenX64
member
functions for the various kinds of 3AC quads.
See the lecture notes for lots of useful details.
As in prior projects, you are encouraged to build the new code atop your prior implementation, but you can use the starter code here (link) to get you started. Feel free to change as much of this code as you want. Please note that this code is designed to be a starting point for working on project 7, not a complete solution to project 6.
Some additional code-generation methods can be found in the file
3ac.hpp
file, as well as stubs in the
x64_codegen.cpp
file.
In addition to the code for your compiler, one additional
object file is built by the starter code makefile, called
std_alang.o
.
This object file contains implementations of helper
functions (written in C) that are useful in programming
the intrinsics of the language
(consoleout
and consolein
).
These object files can be generated from code in the starter
files by compiling them with gcc
(gcc std_alang.c -c
).
You are not required to use these
auxiliary files, but you are welcome to do so.
The scope of this project is to generate a text file containing valid x64 assembly. In order to translate that file into an executable, there are some additional steps that you can use with existing x64 compiler toolchain tools.
Because std_alang.o
expects
to be able to call C library functions, if you use it you
should make sure that you include the object files to
initialize the C runtime. On the cycle servers, you can do
this by invoking the assembler and linker as follows:
as prog.s -o prog.o
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 \
/usr/lib/x86_64-linux-gnu/crt1.o \
/usr/lib/x86_64-linux-gnu/crti.o \
-lc \
prog.o \
std_alang.o \
/usr/lib/x86_64-linux-gnu/crtn.o \
-o prog.exe
You should make sure that your program exits gracefully. If you are using the above linker command, simply treat main like any other function with an integer return type. Code included in crt1.o (which contains the _start label), will actually invoke the exit syscall for you.
The other expectation of the C runtime objects is that
there will be a public label called simply main
that will be a jump target from crt1.o
. In your
output code make sure to include
in the .data section. Do not include a label _start,
since there already is one in
.globl main
crt1.o
.
a = false && foo()
will actually
call the function foo
Implement code generation for each of the following features; be sure to test each feature as it is implemented!
int
and bool
literals (just load
into registers), string literals, and the Syscall in it's
WRITE configuration.
SymOpd
(code that loads/stores local,
and assignments of the form id=literal and
id=id (test by assigning then writing)consoleout
works! Nearly every test program
uses it to test the semantics of your program.
As in previous projects, the oracle will serve as a reference implementation. If you are confused about how a certain operation should work, feel free to consult the oracle. If you feel that the oracle is acting in error, report the problem to Piazza ASAP.