CS 445 HW#5

Due: Wednesday November 27 11:59pm

Generate 3-address intermediate code for VGo. Please turnin via bblearn an electronic copy of your whole project in a hw5.zip.

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.go, 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.go the output would still just be named foo.go.

Example. Example ouput is for C, but your VGo output will be similar.

For an input file foo.go containing source code:

C Go
int main() { printf("%d\n", 10+2); return 0;}
package main
import "fmt"
func main() {
   fmt.Println(10+2)
}

your output should look something like that 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	printf,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