BEN KAPLAN: EECS 337, HW 4. Intermediate code generation. *** to compile the program, use the compile script in the root directory of the project. This will run the makefile in Debug/ ***to run the program, execute the command "cat input.test | Debug/CompilerDesign" ***the function declarations I used are different from the ones in the assignment. I'm actually implementing scoping here and my temp variables require it so I'm passing env_t's around instead of list_head_t. I spoke with Prof Liberatore on Tuesday and he said it was alright. *** Rather than using a flag, temporary variables are variables of the form #[0-9]+ where the number starts at 0 and increase by 1 every time a new temp is added to that symbol table ***currently, I am using both the list (for legacy reasons) and the new environments for scope. The list is basically not being used though, and the temporary variables are only put into the env_t. ***The tests for gen, sizeofidtype, widen, and newtemp are at the bottom of intcode.c. I've documented in the code what each test is doing *** The extra credit (adding type info to temp variables, is done in my types_compatible function. It's called when I go to do the assignemnt to the temp variable- it sees that there's no type info on the temp and, assuming the types of the two arguments are compatible, and creates type info for the variable Here is the output of the sample program, along with the output of all my tests. The code list for the sample program immediately follows the symbol table output (the symbol table print still uses the list): { basic id; basic id; basic id; basic id; basic[num: 100] id; while ( true ) { do id = id + num: 1 ; while( id[id] < id ); do id = id - num: 1 ; while( id[id] > id ); if (id >= id) break ; id = id[id]; id[id] = id[id]; id[id] = id; } } finished parse { i: type:0x10000b184, dimension:0, size:0, subtype: NULL, supertype: NULL j: type:0x10000b184, dimension:0, size:0, subtype: NULL, supertype: NULL v: type:0x10000b188, dimension:0, size:0, subtype: NULL, supertype: NULL x: type:0x10000b188, dimension:0, size:0, subtype: NULL, supertype: NULL a: type:0x10000b188, dimension:1, size:100, subtype: { type:0x10000b188, dimension:0, size:0, subtype: NULL, supertype: 0x100100370}, supertype: NULL } #0 = i + 1 i = #0 #2 = 8 * i #1 = a[ #2 ] #3 = j - 1 j = #3 #5 = 8 * j #4 = a[ #5 ] #7 = 8 * i #6 = a[ #7 ] x = #6 #9 = 8 * i #8 = a[ #9 ] #11 = 8 * j #10 = a[ #11 ] #8 = #10 #13 = 8 * j #12 = a[ #13 ] #12 = x -----starting gen tests--------- Test 4 : int = float + int, should fail on type check type check failed 0 should be 0 x = 1 + 3 #0 = (float) x q = #0 * 3.200000 #1 = (float) 4 r = 3.200000 / #1 -----------end gen tests--------- should be #0: #0 successfully handled null environ -------starting widen tests---------- starting widen good widen complete starting widen failing test complete -------starting sizeofidtype tests---------- sizeof {&int_var,0,0,NULL,NULL} = 4, should be 4 sizeof {&float_var,0,0,NULL,NULL} = 8 should be 8 size of {&float_var,1,10,NULL,NULL} = 80 should be 80 sizeof {&float_var, 2, 50,&{&float_var, 1, 10, NULL, &supertype}, NULL} = 4000 should be 4000 ---------finish sizeofidtype tests--------