Hello CS 524 Students, The tests for Control Structures 5a - If-then-elsif-else involve 6 files, tif0, tif1, tif2, tif3, tif4 (invalid code - has a string without the closing " which generates a scan/parse error), tif5 (undeclared variable which you should detect and turn off codegen) Your group results are summarized below (and the actual tests and their output follow): kris stewart GMCS 535 Office Hours Mon noon-1:30; Wed 1-1:30 (if ACM meeting) stewart@rohan.sdsu.edu ----------------------------------------------------------- ----------------------------------------------------------- kris stewart - student account Finger information for POC of group Login name: masc0830 In real life: Stewart as CS524 student Directory: /home/ma/524.01/masc0830 Shell: /bin/csh Last login Mon Apr 21 12:35 on pts/123 from rohan.sdsu.edu New mail received Wed Mar 26 12:00:08 2008; unread since Wed Feb 13 13:19:01 2008 No Plan. Time Stamp on simple in student account -rwxr-x--- 1 masc0830 192284 Apr 21 12:39 /home/ma/524.01/masc0830/simple* Time Stamp on executable for running tests -rwxr-xr-x 1 stewart 192284 Apr 21 12:47 simple* masc0830 simple test number tif0 CS 524 - Phase5 Control Structures / If-Tests Mon Apr 21 12:47:58 PDT 2008 package tif0 is body i : integer; begin writeln(" tif0 if then"); i:=4; if i = 4 then i:=i+2; writeln(" then - part now i=",i); else writeln(" else -part - should not see this output"); end if; writeln("completed simplest if-then-else"); end; ******** Test your compiler on the code above ******** ******** with AST and symbol table after parse ******* in simple.c Intermediate Representation - the Abstract Syntax Tree Statements Writeln parameters tif0 if then Assign i gets Immediate Value 4 If Bool Expr i equal Immediate Value 4 Then Assign i gets i add Immediate Value 2 Writeln parameters then - part now i= i ELSE Writeln parameters else -part - should not see this output End If Writeln parameters completed simplest if-then-else From codegen.c - DisplayRegs() marks used registers Register: 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - Used = x: Variable dump from GenStorage ID: i Offset: 0 Proc. Level: 0 COMPILATION COMPLETE out simple.c ******** Your compiler produces a listing ****** package tif0 is body i : integer; begin writeln( tif0 if then); i:=4; if i = 4 then i:=i+2; writeln( then - part now i=,i); else writeln( else -part - should not see this output); end if; writeln(completed simplest if-then-else); end; ******** And Source Code File *********** # Register Usage: # $s0 for global variables # .text .globl main main: la $s0, GVARS # # Start Code # Hi Kris Stewart! This is your favorite compiler team!!!!!! # Patricia, Lance, Meng, and David # # Generate Writeln statement la $a0, S4 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement li $t0,4 sw $t0,0($s0) # # Generate If Statment lw $t0,0($s0) seq $t0,$t0,4 beq $t0, 0,IF1 # # Generate Assignment Statement lw $t0,0($s0) add $t0,$t0,2 sw $t0,0($s0) # # Generate Writeln statement la $a0, S3 li $v0, 4 syscall li $v0, 1 lw $a0,0($s0) syscall la $a0, S0 li $v0, 4 syscall j IF0 IF1: # # Generate Else Statment # # Generate Writeln statement la $a0, S2 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall IF0: # # Generate Writeln statement la $a0, S1 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Halt execution li $v0 10 syscall # # Finish up by writing out constants .word 0 CONST: #Constant storage area .data S0: .asciiz "\n" .data S1: .asciiz "completed simplest if-then-else" .data S2: .asciiz " else -part - should not see this output" .data S3: .asciiz " then - part now i=" .data S4: .asciiz " tif0 if then" # # Reserve space for global variables .word 0 GVARS: # space for Global Variables .data _i: .word 0 # Offset at 0 .data Temp_Wr: .word 0 #just for alignment of write(exprtree) ******** Run through spim ********* SPIM Version 6.2 of January 11, 1999 Copyright 1990-1998 by James R. Larus (larus@cs.wisc.edu). All Rights Reserved. See the file README for a full copyright notice. Loaded: /opt/spim/bin/trap.handler tif0 if then then - part now i=6 completed simplest if-then-else masc0830 simple test number tif1 CS 524 - Phase5 Control Structures / If-Tests Mon Apr 21 12:47:58 PDT 2008 -- nested if then else package tif1 is body x,y: integer; begin writeln(" tif1 - nested if then else - no elsif "); x := 1; y := 1; if x = 1 then y := y + 1; writeln ("then part - y=",y); if y=2 then y:=y+1; writeln ("nested if-if y=",y); else writeln ("should not see this message"); end if; else x := x + 1; end if; writeln("completed tif1: nest if-then-else's"); end; ******** Test your compiler on the code above ******** ******** with AST and symbol table after parse ******* in simple.c Intermediate Representation - the Abstract Syntax Tree Statements Writeln parameters tif1 - nested if then else - no elsif Assign x gets Immediate Value 1 Assign y gets Immediate Value 1 If Bool Expr x equal Immediate Value 1 Then Assign y gets y add Immediate Value 1 Writeln parameters then part - y= y If Bool Expr y equal Immediate Value 2 Then Assign y gets y add Immediate Value 1 Writeln parameters nested if-if y= y ELSE Writeln parameters should not see this message End If ELSE Assign x gets x add Immediate Value 1 End If Writeln parameters completed tif1: nest if-then-else's From codegen.c - DisplayRegs() marks used registers Register: 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - Used = x: Variable dump from GenStorage ID: x Offset: 0 Proc. Level: 0 ID: y Offset: 4 Proc. Level: 0 COMPILATION COMPLETE out simple.c ******** Your compiler produces a listing ****** -- nested if then else package tif1 is body x,y: integer; begin writeln( tif1 - nested if then else - no elsif ); x := 1; y := 1; if x = 1 then y := y + 1; writeln (then part - y=,y); if y=2 then y:=y+1; writeln (nested if-if y=,y); else writeln (should not see this message); end if; else x := x + 1; end if; writeln(completed tif1: nest if-then-else's); end; ******** And Source Code File *********** # Register Usage: # $s0 for global variables # .text .globl main main: la $s0, GVARS # # Start Code # Hi Kris Stewart! This is your favorite compiler team!!!!!! # Patricia, Lance, Meng, and David # # Generate Writeln statement la $a0, S5 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement li $t0,1 sw $t0,0($s0) # # Generate Assignment Statement li $t0,1 sw $t0,4($s0) # # Generate If Statment lw $t0,0($s0) seq $t0,$t0,1 beq $t0, 0,IF1 # # Generate Assignment Statement lw $t0,4($s0) add $t0,$t0,1 sw $t0,4($s0) # # Generate Writeln statement la $a0, S4 li $v0, 4 syscall li $v0, 1 lw $a0,4($s0) syscall la $a0, S0 li $v0, 4 syscall # # Generate If Statment lw $t0,4($s0) seq $t0,$t0,2 beq $t0, 0,IF3 # # Generate Assignment Statement lw $t0,4($s0) add $t0,$t0,1 sw $t0,4($s0) # # Generate Writeln statement la $a0, S3 li $v0, 4 syscall li $v0, 1 lw $a0,4($s0) syscall la $a0, S0 li $v0, 4 syscall j IF2 IF3: # # Generate Else Statment # # Generate Writeln statement la $a0, S2 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall IF2: j IF0 IF1: # # Generate Else Statment # # Generate Assignment Statement lw $t0,0($s0) add $t0,$t0,1 sw $t0,0($s0) IF0: # # Generate Writeln statement la $a0, S1 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Halt execution li $v0 10 syscall # # Finish up by writing out constants .word 0 CONST: #Constant storage area .data S0: .asciiz "\n" .data S1: .asciiz "completed tif1: nest if-then-else's" .data S2: .asciiz "should not see this message" .data S3: .asciiz "nested if-if y=" .data S4: .asciiz "then part - y=" .data S5: .asciiz " tif1 - nested if then else - no elsif " # # Reserve space for global variables .word 0 GVARS: # space for Global Variables .data _x: .word 0 # Offset at 0 .data _y: .word 0 # Offset at 4 .data Temp_Wr: .word 0 #just for alignment of write(exprtree) ******** Run through spim ********* SPIM Version 6.2 of January 11, 1999 Copyright 1990-1998 by James R. Larus (larus@cs.wisc.edu). All Rights Reserved. See the file README for a full copyright notice. Loaded: /opt/spim/bin/trap.handler tif1 - nested if then else - no elsif then part - y=2 nested if-if y=3 completed tif1: nest if-then-else's masc0830 simple test number tif2 CS 524 - Phase5 Control Structures / If-Tests Mon Apr 21 12:47:58 PDT 2008 package tif2 is body i, j: integer; begin writeln("tif2- if-then-elsif - no else"); j := 0; if j=0 then writeln("then part - should see"); elsif j=0 then writeln("elsif - but should not see output"); end if; writeln("That finishes tif2 "); end; ******** Test your compiler on the code above ******** ******** with AST and symbol table after parse ******* in simple.c Intermediate Representation - the Abstract Syntax Tree Statements Writeln parameters tif2- if-then-elsif - no else Assign j gets Immediate Value 0 If Bool Expr j equal Immediate Value 0 Then Writeln parameters then part - should see ElsIf Bool Expr j equal Immediate Value 0 Then Writeln parameters elsif - but should not see output End If Writeln parameters That finishes tif2 From codegen.c - DisplayRegs() marks used registers Register: 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - Used = x: Variable dump from GenStorage ID: i Offset: 0 Proc. Level: 0 ID: j Offset: 4 Proc. Level: 0 COMPILATION COMPLETE out simple.c ******** Your compiler produces a listing ****** package tif2 is body i, j: integer; begin writeln(tif2- if-then-elsif - no else); j := 0; if j=0 then writeln(then part - should see); elsif j=0 then writeln(elsif - but should not see output); end if; writeln(That finishes tif2 ); end; ******** And Source Code File *********** # Register Usage: # $s0 for global variables # .text .globl main main: la $s0, GVARS # # Start Code # Hi Kris Stewart! This is your favorite compiler team!!!!!! # Patricia, Lance, Meng, and David # # Generate Writeln statement la $a0, S4 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement li $t0,0 sw $t0,4($s0) # # Generate If Statment lw $t0,4($s0) seq $t0,$t0,0 beq $t0, 0,IF1 # # Generate Writeln statement la $a0, S3 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j IF0 IF1: # # Generate Else If Statment lw $t0,4($s0) seq $t0,$t0,0 beq $t0, 0,IF2 # # Generate Writeln statement la $a0, S2 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j IF0 IF2: IF0: # # Generate Writeln statement la $a0, S1 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Halt execution li $v0 10 syscall # # Finish up by writing out constants .word 0 CONST: #Constant storage area .data S0: .asciiz "\n" .data S1: .asciiz "That finishes tif2 " .data S2: .asciiz "elsif - but should not see output" .data S3: .asciiz "then part - should see" .data S4: .asciiz "tif2- if-then-elsif - no else" # # Reserve space for global variables .word 0 GVARS: # space for Global Variables .data _i: .word 0 # Offset at 0 .data _j: .word 0 # Offset at 4 .data Temp_Wr: .word 0 #just for alignment of write(exprtree) ******** Run through spim ********* SPIM Version 6.2 of January 11, 1999 Copyright 1990-1998 by James R. Larus (larus@cs.wisc.edu). All Rights Reserved. See the file README for a full copyright notice. Loaded: /opt/spim/bin/trap.handler tif2- if-then-elsif - no else then part - should see That finishes tif2 masc0830 simple test number tif3 CS 524 - Phase5 Control Structures / If-Tests Mon Apr 21 12:47:58 PDT 2008 package tif3 is body i :integer; begin writeln(" tif3 - how many labels for simple if-then-endif?"); i := 6; if i=6 then writeln("simple - ifthen i=6 - correct"); end if; if i = 7 then writeln("ifthenelsifelse - then part: i = 7"); elsif i = 9 then writeln("ifthenelsifelse - elsif part: i = 9"); else writeln("else case - correct i = 6? i=",i); end if; writeln(" bye from tif3"); end; ******** Test your compiler on the code above ******** ******** with AST and symbol table after parse ******* in simple.c Intermediate Representation - the Abstract Syntax Tree Statements Writeln parameters tif3 - how many labels for simple if-then-endif? Assign i gets Immediate Value 6 If Bool Expr i equal Immediate Value 6 Then Writeln parameters simple - ifthen i=6 - correct End If If Bool Expr i equal Immediate Value 7 Then Writeln parameters ifthenelsifelse - then part: i = 7 ElsIf Bool Expr i equal Immediate Value 9 Then Writeln parameters ifthenelsifelse - elsif part: i = 9 ELSE Writeln parameters else case - correct i = 6? i= i End If Writeln parameters bye from tif3 From codegen.c - DisplayRegs() marks used registers Register: 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - Used = x: Variable dump from GenStorage ID: i Offset: 0 Proc. Level: 0 COMPILATION COMPLETE out simple.c ******** Your compiler produces a listing ****** package tif3 is body i :integer; begin writeln( tif3 - how many labels for simple if-then-endif?); i := 6; if i=6 then writeln(simple - ifthen i=6 - correct); end if; if i = 7 then writeln(ifthenelsifelse - then part: i = 7); elsif i = 9 then writeln(ifthenelsifelse - elsif part: i = 9); else writeln(else case - correct i = 6? i=,i); end if; writeln( bye from tif3); end; ******** And Source Code File *********** # Register Usage: # $s0 for global variables # .text .globl main main: la $s0, GVARS # # Start Code # Hi Kris Stewart! This is your favorite compiler team!!!!!! # Patricia, Lance, Meng, and David # # Generate Writeln statement la $a0, S6 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement li $t0,6 sw $t0,0($s0) # # Generate If Statment lw $t0,0($s0) seq $t0,$t0,6 beq $t0, 0,IF1 # # Generate Writeln statement la $a0, S5 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j IF0 IF1: IF0: # # Generate If Statment lw $t0,0($s0) seq $t0,$t0,7 beq $t0, 0,IF3 # # Generate Writeln statement la $a0, S4 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j IF2 IF3: # # Generate Else If Statment lw $t0,0($s0) seq $t0,$t0,9 beq $t0, 0,IF4 # # Generate Writeln statement la $a0, S3 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j IF2 IF4: # # Generate Else Statment # # Generate Writeln statement la $a0, S2 li $v0, 4 syscall li $v0, 1 lw $a0,0($s0) syscall la $a0, S0 li $v0, 4 syscall IF2: # # Generate Writeln statement la $a0, S1 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Halt execution li $v0 10 syscall # # Finish up by writing out constants .word 0 CONST: #Constant storage area .data S0: .asciiz "\n" .data S1: .asciiz " bye from tif3" .data S2: .asciiz "else case - correct i = 6? i=" .data S3: .asciiz "ifthenelsifelse - elsif part: i = 9" .data S4: .asciiz "ifthenelsifelse - then part: i = 7" .data S5: .asciiz "simple - ifthen i=6 - correct" .data S6: .asciiz " tif3 - how many labels for simple if-then-endif?" # # Reserve space for global variables .word 0 GVARS: # space for Global Variables .data _i: .word 0 # Offset at 0 .data Temp_Wr: .word 0 #just for alignment of write(exprtree) ******** Run through spim ********* SPIM Version 6.2 of January 11, 1999 Copyright 1990-1998 by James R. Larus (larus@cs.wisc.edu). All Rights Reserved. See the file README for a full copyright notice. Loaded: /opt/spim/bin/trap.handler tif3 - how many labels for simple if-then-endif? simple - ifthen i=6 - correct else case - correct i = 6? i=6 bye from tif3 masc0830 simple test number tif5 CS 524 - Phase5 Control Structures / If-Tests Mon Apr 21 12:47:58 PDT 2008 package tif5 is body j: integer; begin j := 0; writeln (" tif5 - ifs - undeclared var - do you exist gracefuly?"); if i = 4 then writeln ("Hello World i =", i," j=",j); end if; writeln("Thats all folks"); end; ******** Test your compiler on the code above ******** ******** with AST and symbol table after parse ******* in simple.c Error variable "i" was not declared Error the variable "i" was not initializedError the variable "i" was not initialized Intermediate Representation - the Abstract Syntax Tree Statements COMPILATION ABORTED out simple.c **** Problems ***** Only a partial compilation was produced