HW 5 Notes: -- to compile, run the compile script in the main directory -- to run, including the test program, run the command "cat input.test | Debug/CompilerDesign" --Some of the structures have extra fields in them. For instance, each env keeps track of its current size. Each boolean_list_t keeps track of the quadruple of the initial instruction. --the list_merge function appears in list.c, the record size functions appear in env.c --all test cases are in test.c --the envionrment is implemented as a stack, which is clearly visible from the dump of the symbol table (inner blocks, which means top of the stack, is indented) --the location of each variable appears at the end of its printout in the environment. This location is relative to the start of the data. It doesn't include the header and list of variable locations. -- However, the locations of the second test for address generation use the locof_record function (defined in env.c), which includes the header size. -- I'm using a bunch of asserts to gracefully fail in the case of many erroneous arguments (such as passing NULL in some cases, or passing the wrong type of data in others), so I don't test those. --the code generation is addressed in both quad.c and intcode.c. For the most part, quad.c contains the control flow stuff while intcode.c contains the expression stuff. Here's the output of the program, including the sample program and all tests: { 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:int, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 0 j: type:int, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 4 v: type:float, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 8 x: type:float, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 16 a: type:float, dimension:1, size:100, subtype: { type:float, dimension:0, size:0, subtype: NULL, supertype: 0x100100800, loc: -1}, supertype: NULL, loc: 24 | | #10: type:float, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 44 | #11: type:int, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 40 | #1: type:float, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 4 | #12: type:float, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 56 | #2: type:int, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 0 | #13: type:int, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 52 | #4: type:float, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 16 | #5: type:int, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 12 | #7: type:int, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 24 | #8: type:float, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 32 | #9: type:int, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 28 | } goto (1) i = i + 1 #2 = 8 * i #1 = a[ #2 ] if #1 < v goto (1) goto (6) j = j - 1 #5 = 8 * j #4 = a[ #5 ] if #4 > v goto (6) goto (11) if i >= j goto (13) goto (14) goto (23) #7 = 8 * i x = a[ #7 ] #9 = 8 * i #11 = 8 * j #10 = a[ #11 ] a [ #9 ] = #10 #13 = 8 * j a [ #13 ] = x goto (0) ----------testing env----------- this should give an error: error: unable to create variable x at line 10. Variable already defined { x: type:float, dimension:1, size:20, subtype: { type:float, dimension:0, size:0, subtype: NULL, supertype: 0x100100540, loc: -1}, supertype: 0x2b00010000076c, loc: 4 a: type:int, dimension:0, size:0, subtype: NULL, supertype: 0x2300010000076c, loc: 0 | | abcd: type:float, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 4 | b: type:int, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 0 | | | | | x: type:int, dimension:0, size:0, subtype: NULL, supertype: NULL, loc: 0 | | } -----testing list_merge----- { a b c d } -------testing backpatch-------- goto (1) #0 = 3 + 5 if 100 > #0 goto (0) error on null: 1 -------testing activation record size----- size is 296, should be 296 size is 88, should be 88 locations of variables in second test program locations: loc of i1: 12 loc of j1: 292 loc of i2: 12 loc of j2: 16 starting my test: location of x: 16 location of y: 20 location of z: 28 size of env: 188