CSC448: Code Generation: Building an Executable [80/133] |
Corin did not show
After running ant test
, you can build a single
executable with:
LINUX $ gcc -Wa,--gstabs asmlocal/*.s output/codegenlocal/test094.s -o output/exe/test094 WINDOWS $ gcc -Wa,--gstabs asmlocal\*.s output\codegenlocal\test094.s -o output\exe\test094.exe
If you are not on Windows 95/98/ME, you can build all executables at once:
LINUX $ for i in output/codegenlocal/*.s; do gcc -Wa,--gstabs asmlocal/*.s $i -o output/exe/`basename $i .s`; done WINDOWS > for %i in (output\codegenlocal\*.s) do @gcc -Wa,--gstabs asmlocal\*.s %i -o output\exe\%~ni
Do not worry about the single example that fails to build. It is only because there is no implementation supplied for the native methods.
Be alert for missing return statements or missing variable initializations in your COOL examples. They usually cause a crash.
Interesting programs:
test085
: prints a linked list.
$ ./output/exe/test085 { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
test086
: prints "Hello World" in a loop.
$ ./output/exe/test086 Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
test087
: prints triangular numbers backwards.
$ ./output/exe/test087 Value for 10 is 55 Value for 9 is 45 Value for 8 is 36 Value for 7 is 28 Value for 6 is 21 Value for 5 is 15 Value for 4 is 10 Value for 3 is 6 Value for 2 is 3 Value for 1 is 1
test088
: prints factorials backwards.
$ ./output/exe/test088 Factorial of 10 is 3628800 Factorial of 9 is 362880 Factorial of 8 is 40320 Factorial of 7 is 5040 Factorial of 6 is 720 Factorial of 5 is 120 Factorial of 4 is 24 Factorial of 3 is 6 Factorial of 2 is 2 Factorial of 1 is 1
test090
: generates and prints linked lists in a loop, iterative version.
$ ./output/exe/test090 { 0 } { 1, 2 } { 2, 3, 4 } { 3, 4, 5, 6 } { 4, 5, 6, 7, 8 } { 5, 6, 7, 8, 9, 10 } { 6, 7, 8, 9, 10, 11, 12 } { 7, 8, 9, 10, 11, 12, 13, 14 } { 8, 9, 10, 11, 12, 13, 14, 15, 16 } { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }
test091
: generates and prints linked lists in a loop, recursive version.
$ ./output/exe/test091 { 0 } { 1, 2 } { 2, 3, 4 } { 3, 4, 5, 6 } { 4, 5, 6, 7, 8 } { 5, 6, 7, 8, 9, 10 } { 6, 7, 8, 9, 10, 11, 12 } { 7, 8, 9, 10, 11, 12, 13, 14 } { 8, 9, 10, 11, 12, 13, 14, 15, 16 } { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }
test092
: generates and prints linked lists in
a loop, recursive version, with a cons method.
$ ./output/exe/test092 { 0 } { 1, 2 } { 2, 3, 4 } { 3, 4, 5, 6 } { 4, 5, 6, 7, 8 } { 5, 6, 7, 8, 9, 10 } { 6, 7, 8, 9, 10, 11, 12 } { 7, 8, 9, 10, 11, 12, 13, 14 } { 8, 9, 10, 11, 12, 13, 14, 15, 16 } { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 }
test093
: silly program to test divisibility
by 3 (used to show need for variable renaming).
$ ./output/exe/test093 Not divisible by 3! 9 is divisible by 3 Not divisible by 3! Not divisible by 3! Not divisible by 3! 6 is divisible by 3 Not divisible by 3! Not divisible by 3! Not divisible by 3! 3 is divisible by 3 Not divisible by 3! Not divisible by 3! Not divisible by 3!
test094
: recursive factorial.
$ ./output/exe/test094 The factorial of 0 is 1 The factorial of 1 is 1 The factorial of 2 is 2 The factorial of 3 is 6 The factorial of 4 is 24 The factorial of 5 is 120 The factorial of 6 is 720 The factorial of 7 is 5040 The factorial of 8 is 40320 The factorial of 9 is 362880
test095
: prints a binary tree.
$ ./output/exe/test095 (. 7 .) 6 (((. 1 .) 3 (. 2 .)) 5 (. 4 .)) 6 7 . . 5 3 1 . . 2 . . 4 . . Sum of tree contents = 28
test096
: sorts a linked list.
$ ./output/exe/test096 Original list: { 11, 2, 1, 4, 10, 9, 4, 3, 4, 5 } Sorted list: { 1, 2, 3, 4, 5, 9, 10, 11 }
test097
: uses global variables.
$ ./output/exe/test097 john = John Doe is 50 years old. jane = Jane Doe is 52 years old. p = John Doe is 50 years old.