SOURCE PROGRAM: class Short { public static void main() { int i = 0; int f0 = 1; int f1 = 1; while (i < 10) { int f2 = f0 + f1; f0 = f1; f1 = f2; i = i+1; } IO.putInt(f1); IO.putString("\n"); } } ========================================================================== LEXEMES: class Short { public static void main ( ) { int i = 0 ; int f0 = 1 ; int f1 = 1 ; while ( i < 10 ) { int f2 = f0 + f1 ; f0 = f1 ; f1 = f2 ; i = i + 1 ; } IO . putInt ( f1 ) ; IO . putString ( "\n" ) ; } } ========================================================================== INITIAL ABSTRACT SYNTAX TREE: OuterScope (2) FILE='' ClassList (1) Class (112) ID='Short' MODS='' KIND='CLASS' SuperClass (51) ClassType (3) NAME='Object' LENGTH='0' VTABLE='0' ------ SuperClass MemberList (52) Method (111) ID='main' MODS='' KIND='METHOD' VTABLE='0' VoidType (24) NAME='void' MethodBody (110) FormalList (53) StatementList (54) DeclStatement (59) IntType (30) NAME='int' Local (58) ID='i' TYPE='int' MODS='' KIND='VAR' OFFSET='0' IntType (30) NAME='int' AssignExpression (57) FILE='short.decaf' LINE='4' OP='=' TARGETOP='ERROR' Name (56) LINE='4' ID='i' CALL='false' LiteralInt (55) LINE='4' VALUE='0' ------ AssignExpression ------ Local ------ DeclStatement DeclStatement (64) IntType (30) NAME='int' Local (63) ID='f0' TYPE='int' MODS='' KIND='VAR' OFFSET='0' IntType (30) NAME='int' AssignExpression (62) FILE='short.decaf' LINE='5' OP='=' TARGETOP='ERROR' Name (61) LINE='5' ID='f0' CALL='false' LiteralInt (60) LINE='5' VALUE='1' ------ AssignExpression ------ Local ------ DeclStatement DeclStatement (69) IntType (30) NAME='int' Local (68) ID='f1' TYPE='int' MODS='' KIND='VAR' OFFSET='0' IntType (30) NAME='int' AssignExpression (67) FILE='short.decaf' LINE='6' OP='=' TARGETOP='ERROR' Name (66) LINE='6' ID='f1' CALL='false' LiteralInt (65) LINE='6' VALUE='1' ------ AssignExpression ------ Local ------ DeclStatement WhileStatement (97) CompareExpression (72) FILE='short.decaf' LINE='8' OP='<' TARGETOP='ERROR' Name (70) LINE='8' ID='i' CALL='false' LiteralInt (71) LINE='8' VALUE='10' ------ CompareExpression BlockStatement (96) FILE='' StmtBlock (95) StatementList (73) DeclStatement (80) IntType (30) NAME='int' Local (79) ID='f2' TYPE='int' MODS='' KIND='VAR' OFFSET='0' IntType (30) NAME='int' AssignExpression (78) FILE='short.decaf' LINE='9' OP='=' TARGETOP='ERROR' Name (77) LINE='9' ID='f2' CALL='false' ArithExpression (76) LINE='9' OP='+' TARGETOP='ERROR' Name (74) LINE='9' ID='f0' CALL='false' Name (75) LINE='9' ID='f1' CALL='false' ------ ArithExpression ------ AssignExpression ------ Local ------ DeclStatement ExpressionStatement (84) FILE='short.decaf' LINE='10' AssignExpression (83) LINE='10' OP='=' TARGETOP='ERROR' Name (81) LINE='10' ID='f0' CALL='false' Name (82) LINE='10' ID='f1' CALL='false' ------ AssignExpression ------ ExpressionStatement ExpressionStatement (88) FILE='short.decaf' LINE='11' AssignExpression (87) LINE='11' OP='=' TARGETOP='ERROR' Name (85) LINE='11' ID='f1' CALL='false' Name (86) LINE='11' ID='f2' CALL='false' ------ AssignExpression ------ ExpressionStatement ExpressionStatement (94) FILE='short.decaf' LINE='12' AssignExpression (93) LINE='12' OP='=' TARGETOP='ERROR' Name (89) LINE='12' ID='i' CALL='false' ArithExpression (92) LINE='12' OP='+' TARGETOP='ERROR' Name (90) LINE='12' ID='i' CALL='false' LiteralInt (91) LINE='12' VALUE='1' ------ ArithExpression ------ AssignExpression ------ ExpressionStatement ------ StatementList ------ StmtBlock ------ BlockStatement ------ WhileStatement ExpressionStatement (103) FILE='short.decaf' LINE='15' Call (102) LINE='15' Name (101) LINE='15' ID='putInt' CALL='true' Name (98) LINE='15' ID='IO' CALL='false' ------ Name ExpressionList (100) LINE='15' Name (99) LINE='15' ID='f1' CALL='false' ------ ExpressionList ------ Call ------ ExpressionStatement ExpressionStatement (109) FILE='short.decaf' LINE='16' Call (108) LINE='16' Name (107) LINE='16' ID='putString' CALL='true' Name (104) LINE='16' ID='IO' CALL='false' ------ Name ExpressionList (106) LINE='16' LiteralString (105) LINE='16' VALUE='\n' ------ ExpressionList ------ Call ------ ExpressionStatement ------ StatementList ------ MethodBody ------ Method ------ MemberList ClassType (113) NAME='Short' LENGTH='0' VTABLE='0' ------ Class ------ ClassList ------ OuterScope ========================================================================== RESOLVED ABSTRACT SYNTAX TREE: OuterScope (2) FILE='' ClassList (1) Class (112) ID='Short' MODS='' KIND='CLASS' SuperClass (51) ClassType (3) NAME='Object' LENGTH='4' VTABLE='4' ------ SuperClass MemberList (52) Method (111) ID='main' MODS='' KIND='METHOD' VTABLE='0' VoidType (24) NAME='void' MethodBody (110) FormalList (53) StatementList (54) DeclStatement (59) IntType (30) NAME='int' Local (58) ID='i' TYPE='int' MODS='' KIND='VAR' OFFSET='0' IntType (30) NAME='int' AssignExpression (57) FILE='short.decaf' LINE='4' OP='=' TARGETOP='iASG' TYPE='int' Name (56) LINE='4' ID='i' SYM='58' TYPE='int' CALL='false' LiteralInt (55) LINE='4' VALUE='0' TYPE='int' ------ AssignExpression ------ Local ------ DeclStatement DeclStatement (64) IntType (30) NAME='int' Local (63) ID='f0' TYPE='int' MODS='' KIND='VAR' OFFSET='0' IntType (30) NAME='int' AssignExpression (62) FILE='short.decaf' LINE='5' OP='=' TARGETOP='iASG' TYPE='int' Name (61) LINE='5' ID='f0' SYM='63' TYPE='int' CALL='false' LiteralInt (60) LINE='5' VALUE='1' TYPE='int' ------ AssignExpression ------ Local ------ DeclStatement DeclStatement (69) IntType (30) NAME='int' Local (68) ID='f1' TYPE='int' MODS='' KIND='VAR' OFFSET='0' IntType (30) NAME='int' AssignExpression (67) FILE='short.decaf' LINE='6' OP='=' TARGETOP='iASG' TYPE='int' Name (66) LINE='6' ID='f1' SYM='68' TYPE='int' CALL='false' LiteralInt (65) LINE='6' VALUE='1' TYPE='int' ------ AssignExpression ------ Local ------ DeclStatement WhileStatement (97) CompareExpression (72) FILE='short.decaf' LINE='8' OP='<' TARGETOP='iLSS' TYPE='boolean' Name (70) LINE='8' ID='i' SYM='58' TYPE='int' CALL='false' LiteralInt (71) LINE='8' VALUE='10' TYPE='int' ------ CompareExpression BlockStatement (96) FILE='' StmtBlock (95) StatementList (73) DeclStatement (80) IntType (30) NAME='int' Local (79) ID='f2' TYPE='int' MODS='' KIND='VAR' OFFSET='0' IntType (30) NAME='int' AssignExpression (78) FILE='short.decaf' LINE='9' OP='=' TARGETOP='iASG' TYPE='int' Name (77) LINE='9' ID='f2' SYM='79' TYPE='int' CALL='false' ArithExpression (76) LINE='9' OP='+' TARGETOP='iADD' TYPE='int' Name (74) LINE='9' ID='f0' SYM='63' TYPE='int' CALL='false' Name (75) LINE='9' ID='f1' SYM='68' TYPE='int' CALL='false' ------ ArithExpression ------ AssignExpression ------ Local ------ DeclStatement ExpressionStatement (84) FILE='short.decaf' LINE='10' AssignExpression (83) LINE='10' OP='=' TARGETOP='iASG' TYPE='int' Name (81) LINE='10' ID='f0' SYM='63' TYPE='int' CALL='false' Name (82) LINE='10' ID='f1' SYM='68' TYPE='int' CALL='false' ------ AssignExpression ------ ExpressionStatement ExpressionStatement (88) FILE='short.decaf' LINE='11' AssignExpression (87) LINE='11' OP='=' TARGETOP='iASG' TYPE='int' Name (85) LINE='11' ID='f1' SYM='68' TYPE='int' CALL='false' Name (86) LINE='11' ID='f2' SYM='79' TYPE='int' CALL='false' ------ AssignExpression ------ ExpressionStatement ExpressionStatement (94) FILE='short.decaf' LINE='12' AssignExpression (93) LINE='12' OP='=' TARGETOP='iASG' TYPE='int' Name (89) LINE='12' ID='i' SYM='58' TYPE='int' CALL='false' ArithExpression (92) LINE='12' OP='+' TARGETOP='iADD' TYPE='int' Name (90) LINE='12' ID='i' SYM='58' TYPE='int' CALL='false' LiteralInt (91) LINE='12' VALUE='1' TYPE='int' ------ ArithExpression ------ AssignExpression ------ ExpressionStatement ------ StatementList ------ StmtBlock ------ BlockStatement ------ WhileStatement ExpressionStatement (103) FILE='short.decaf' LINE='15' Call (102) LINE='15' TYPE='void' Name (101) LINE='15' ID='putInt' SYM='34' TYPE='(int):void' CALL='true' ExpressionList (100) LINE='15' Name (99) LINE='15' ID='f1' SYM='68' TYPE='int' CALL='false' ------ ExpressionList ------ Call ------ ExpressionStatement ExpressionStatement (109) FILE='short.decaf' LINE='16' Call (108) LINE='16' TYPE='void' Name (107) LINE='16' ID='putString' SYM='38' TYPE='(String):void' CALL='true' ExpressionList (106) LINE='16' LiteralString (105) LINE='16' VALUE='\n' TYPE='String' ------ ExpressionList ------ Call ------ ExpressionStatement ------ StatementList ------ MethodBody MethodType (136) NAME='():void' STATIC='true' VoidType (24) NAME='void' ------ MethodType ------ Method Constructor (122) ID='$init$' MODS='' KIND='CTOR' VTABLE='0' ClassType (113) NAME='Short' LENGTH='4' VTABLE='4' MethodBody (121) FormalList (119) Formal (137) ID='this' TYPE='Short' MODS='' KIND='ARG' OFFSET='8' ClassType (113) NAME='Short' LENGTH='4' VTABLE='4' ------ Formal ------ FormalList StatementList (120) SuperStatement (118) Call (117) TYPE='Object' Name (115) ID='$init$' SYM='6' TYPE='Object*():Object' CALL='true' Name (141) ID='this' SYM='137' TYPE='Short' CALL='false' ------ Name ExpressionList (116) ------ Call ------ SuperStatement ------ StatementList ------ MethodBody MethodType (138) NAME='Short*():Short' STATIC='false' ClassType (113) NAME='Short' LENGTH='4' VTABLE='4' ClassType (113) NAME='Short' LENGTH='4' VTABLE='4' ------ MethodType ------ Constructor ------ MemberList ClassType (113) NAME='Short' LENGTH='4' VTABLE='4' ------ Class ------ ClassList ------ OuterScope ========================================================================== INTERMEDIATE CODE: Code for routine Short$main(0) : Block_ 1: ENTER #0 Block_ 2: LDC #0,T2 MOVE T2,T1 LDC #1,T4 MOVE T4,T3 LDC #1,T4 MOVE T4,T5 Block_ 3: LDC #10,T6 CMP T1,T6,T7 BCOND[LT] T7,Block_5,Block_4 Block_ 4: CALL #"IO$putInt",T5 STRING #"\n",T11 CALL #"IO$putString",T11 BRANCH Block_6 Block_ 5: iADD T3,T5,T9 MOVE T9,T8 MOVE T5,T3 MOVE T8,T5 LDC #1,T4 iADD T1,T4,T10 MOVE T10,T1 BRANCH Block_3 Block_ 6: EXIT Code for routine Short$$init$(0) : Block_ 1: ENTER #0 PARAM #0,T2 Block_ 2: CALLR #"Object$$init$",T2,T3 Block_ 3: MOVE T2,T1 RETVAL T1 EXIT ========================================================================== x86 ASSEMBLER CODE: # File short.decaf .file "short.decaf" .version "01.01" .text .align 4 .globl _$DecafMain .type _$DecafMain,@function _$DecafMain: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax pushl %eax call Short$main addl $4,%esp leave ret .size main,(.-main) # Routine main .align 4 .type Short$main,@function Short$main: .L1: pushl %ebp movl %esp,%ebp subl $28,%esp pushl %esi pushl %edi pushl %ebx .L2: movl $0,-4(%ebp) movl $1,-12(%ebp) movl $1,-8(%ebp) .L3: cmpl $10,-4(%ebp) jl .L5 .L4: movl -8(%ebp),%eax pushl %eax call IO$putInt addl $4,%esp pushl $.LC1 call IO$putString addl $4,%esp jmp .L6 .L5: movl -12(%ebp),%eax addl -8(%ebp),%eax movl -8(%ebp),%ebx movl %ebx,-12(%ebp) movl %eax,-8(%ebp) movl -4(%ebp),%ebx addl $1,%ebx movl %ebx,-4(%ebp) jmp .L3 .L6: leal -40(%ebp),%esp popl %ebx popl %edi popl %esi leave ret .size Short$main,(.-Short$main) # Routine $init$ .align 4 .type Short$$init$,@function Short$$init$: .L7: pushl %ebp movl %esp,%ebp subl $8,%esp pushl %esi pushl %edi pushl %ebx .L8: movl 8(%ebp),%edi pushl %edi call Object$$init$ addl $4,%esp .L9: movl 8(%ebp),%eax leal -20(%ebp),%esp popl %ebx popl %edi popl %esi leave ret .size Short$$init$,(.-Short$$init$) .section .rodata .section .rodata .align 8 .globl _V$Object _V$Object: .long Object$$init$ .type _V$Object,@object .size _V$Object,(.-_V$Object) .section .rodata .align 8 .globl _V$String _V$String: .long String$$init$ .type _V$String,@object .size _V$String,(.-_V$String) .section .rodata .align 8 .globl _V$IO _V$IO: .long IO$$init$ .type _V$IO,@object .size _V$IO,(.-_V$IO) .section .rodata .align 8 .globl _V$Short _V$Short: .long Short$$init$ .type _V$Short,@object .size _V$Short,(.-_V$Short) .section .rodata .align 4 .LC1: .long _V$String .string "\n"