CS 423 HW#6

Due: Friday April 18 11:59pm

Generate 3-address intermediate code for k0. Please turnin via Canvas an electronic copy of your whole project in a hw6.zip. If you have a teammate, please continue to submit teammate assessments via a README or a Canvas HW text submission or both.

Output from this phase should consist of a file containing intermediate code instructions. It should contain a .string region for string constants, a .data region for global variables, and a .code region for instructions. If the input was foo.kt, the output file should be named foo.ic ("intermediate code"). Output should always be written to the current directory, so if the input was /usr/local/temp/foo.kt the output would still just be named foo.ic.

Example.

For an input file foo.kt (C provided for comparison) containing source code:

C Kotlin
#include <stdio.h>
int main() { printf("%d\n", 10+2); return 0;}
fun main() { println(10+2); }

your output should look something like that (illustration is for C version) below. loc: is the local region (offset from base pointer). const: is immediate mode (numeric constants). string: is an offset into a string constant region (global, read-only). Your output does not need to include the interpretation column, just the output column. "interpretation" here is just my explanation to you. However, if your three address code does not look something like this, I may require you to hand-annotate it with interpretation so I can read it.

output interpretation
.string	4
	%d\012\000
.code
main:
	addr	loc:0,string:0
	add	loc:8,const:10,const:2
	parm	loc:8
	parm	loc:0
	call	println,2,loc:16
	return	const:0
declare string region 4 bytes
string data, <= 16 bytes per line, non-printables given as octal escapes
code region
procedure pseudo instruction
store (address of) string region offset 0 in local offset 0
add immediates 10+2, result in local offset 8 (local 0-7 holds string addr)
push contents stored at local address offset 8 (parameter 2)
push contents of local offset 0 (parameter 1)
call printf, 2 words of parameters, result in local offset 16
return from main

Notes