diff --git a/CHANGELOG.org b/CHANGELOG.org index 197efe9..e55eb38 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -24,6 +24,8 @@ Added prototype for Slow_Lisp build test Added Custom type for mes.h Added support for octal and binary numbers Added support for \0 +Added support for GET_MACHINE_FLAGS in tests +Added --architecture flag ** Changed Converted M2-Planet to use GNU style error message @@ -31,7 +33,9 @@ Seed.M1 when built will now have the same checksum as M2-Planet self-hosted Harmonized license headers Updated M1 to current version Updated hex2 to current version +Updated get_machine to current version Updated to mescc-tools 0.6.0 syntax +Changed default architecture to knight-native ** Fixed Fixed typo in file headers diff --git a/bootstrap.sh b/bootstrap.sh index 41d7b9c..9d0e472 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -28,7 +28,7 @@ then { cat <<-EOF ## This file was generated by running: -## cat functions/file.c functions/malloc.c functions/calloc.c functions/exit.c functions/match.c functions/numerate_number.c functions/file_print.c functions/string.c cc.h cc_reader.c cc_strings.c cc_types.c cc_core.c cc.c >| ../stage0/stage3/M2-Planet_x86.c +## cat functions/file.c functions/malloc.c functions/calloc.c functions/exit.c functions/match.c -f functions/in_set.c functions/numerate_number.c functions/file_print.c functions/string.c cc.h cc_reader.c cc_strings.c cc_types.c cc_core.c cc.c >| ../stage0/stage3/M2-Planet_x86.c ## inside M2-Planet's repo EOF @@ -41,6 +41,7 @@ cat header \ functions/calloc.c \ functions/exit.c \ functions/match.c \ + functions/in_set.c \ functions/numerate_number.c \ functions/file_print.c \ functions/string.c \ diff --git a/cc.c b/cc.c index 0ee1b5d..7c28b7d 100644 --- a/cc.c +++ b/cc.c @@ -35,6 +35,9 @@ int main(int argc, char** argv) int DEBUG = FALSE; FILE* in = stdin; FILE* destination_file = stdout; + Architecture = 0; /* Assume Knight-native */ + char* arch; + int i = 1; while(i <= argc) { @@ -68,6 +71,22 @@ int main(int argc, char** argv) } i = i + 2; } + else if(match(argv[i], "-A") || match(argv[i], "--architecture")) + { + arch = argv[i + 1]; + if(match("knight-native", arch)) Architecture = 0; + else if(match("knight-posix", arch)) Architecture = 1; + else if(match("x86", arch)) Architecture = 2; + else if(match("amd64", arch)) Architecture = 3; + else if(match("armv7l", arch)) Architecture = 40; + else + { + file_print("Unknown architecture: ", stderr); + file_print(arch, stderr); + file_print(" know values are: knight-native, knight-posix, x86, amd64 and armv7l", stderr); + } + i = i + 2; + } else if(match(argv[i], "-g") || match(argv[i], "--debug")) { DEBUG = TRUE; @@ -90,6 +109,13 @@ int main(int argc, char** argv) } } + /* Temp solution to aborting when an architecture isn't supported yet but is expected to be fully supported */ + if(!in_set(Architecture, "\x02")) + { + file_print("ALL IS FIRE\n\n", stderr); + exit(EXIT_FAILURE); + } + /* Deal with special case of wanting to read from standard input */ if(stdin == in) { diff --git a/cc.h b/cc.h index d0ad0be..58e5141 100644 --- a/cc.h +++ b/cc.h @@ -79,3 +79,6 @@ struct token_list* globals_list; /* Make our string collection more efficient */ char* hold_string; int string_index; + +/* Our Target Architecture */ +int Architecture; diff --git a/test/test.answers b/test/test.answers index df1f961..6b880b8 100644 --- a/test/test.answers +++ b/test/test.answers @@ -9,7 +9,7 @@ a9a3e332d13ded5f80d7431f8717f26527b3722b33ea57760a9a5723dffc099c test/results/t f1c01feb865c4d552033186d9ce50dd39468a7e8aebf762886c13ad3e03b5011 test/results/test08-binary 3b39e72f3de90ed690adfaf6145af46157cef2ec5e72867ac577fa27a0229894 test/results/test09-binary 020e86020819cc4963e6185b22e534fcf8306b6cb116f12643f254a24688ff0a test/results/test10-binary -f3377a4a6122cfa499040c1080626eb6ef60603bf6023b83090812d97857bc8c test/results/test100-binary +c84d7ca7668837bade38e6e07e018ded3e587643a0a22d513f9dc314fbf17f31 test/results/test100-binary 3fd11bad4a426ce1ff8fd9c6d7d2b943effae9f3f5740b7376e426e9b0555851 test/results/test11-binary f98ab8e4bb35580e0dde96126d7a56aff66bda208d02c8d89390b40d6cff591c test/results/test12-binary 5051ffca2615144419f8ec1a5d4999486ae81e7781428f59e47e866af97cef92 test/results/test13-binary @@ -23,5 +23,5 @@ cefc5a53513abdb9069dc8bdb7b4529307420d5dd412a10112c3253bdcd29c46 test/results/t 3c7654eb26247e5f0460dad9e539220a68078cd8c56aae8457b5a97dc6eab892 test/results/test21-binary 3d0a08c9f38b995318f459884880dbcd309930fb9f51de05c83eb1fcc3fa1825 test/results/test22-binary 3060147b0d56e30c6d9a36ed4675feed306c398df365d2c1c9e2d1c88b40cf3e test/results/test23-binary -c080413cdb713618896a73b834fb96ce8dd2c2176a226c0713d9a729bd1aa7f9 test/results/test24-binary +ff810940f7e8a9df916b20bc95d7d83a7165c57853e343417826a9f5a607c2db test/results/test24-binary 140af7fb3ef89d84b21bd3fe69f0d3260650ec0467c0ffadf9268fad573a397f test/results/test99-binary diff --git a/test/test00/hello.sh b/test/test00/hello.sh index 5a7f77d..9d22e6d 100755 --- a/test/test00/hello.sh +++ b/test/test00/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -bin/M2-Planet -f test/test00/return.c \ +bin/M2-Planet --architecture x86 -f test/test00/return.c \ -o test/test00/return.M1 || exit 1 # Macro assemble with libc written in M1-Macro @@ -32,7 +32,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test00/return.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test00-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result ./test/results/test00-binary diff --git a/test/test01/hello.sh b/test/test01/hello.sh index 208543b..805c526 100755 --- a/test/test01/hello.sh +++ b/test/test01/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f test/test01/library_call.c \ -o test/test01/library_call.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test01/library_call.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test01-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test01-binary 2>&1) diff --git a/test/test02/hello.sh b/test/test02/hello.sh index 096934f..dc6109b 100755 --- a/test/test02/hello.sh +++ b/test/test02/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f test/test02/if.c \ -o test/test02/if.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test02/if.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test02-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test02-binary 2>&1 ) diff --git a/test/test03/hello.sh b/test/test03/hello.sh index 55c29e0..0dba03a 100755 --- a/test/test03/hello.sh +++ b/test/test03/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f test/test03/constant.c \ -o test/test03/constant.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test03/constant.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test03-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test03-binary 2>&1 ) diff --git a/test/test04/hello.sh b/test/test04/hello.sh index 6c33b16..c4da7b5 100755 --- a/test/test04/hello.sh +++ b/test/test04/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f test/test04/call.c \ -o test/test04/call.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test04/call.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test04-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test04-binary 2>&1 ) diff --git a/test/test05/hello.sh b/test/test05/hello.sh index 2ccdf78..5861bbd 100755 --- a/test/test05/hello.sh +++ b/test/test05/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f test/test05/string.c \ -o test/test05/string.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test05/string.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test05-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test05-binary 2>&1 ) diff --git a/test/test06/hello.sh b/test/test06/hello.sh index 8918c1a..4f447ae 100755 --- a/test/test06/hello.sh +++ b/test/test06/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f test/test06/for.c \ -o test/test06/for.M1 || exit 1 @@ -33,7 +33,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test06/for.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test06-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works ./test/results/test06-binary >| test/test06/proof || exit 4 diff --git a/test/test07/hello.sh b/test/test07/hello.sh index b7b0109..e592161 100755 --- a/test/test07/hello.sh +++ b/test/test07/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f test/test07/do.c \ -o test/test07/do.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test07/do.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test07-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works ./test/results/test07-binary >| test/test07/proof || exit 4 diff --git a/test/test08/hello.sh b/test/test08/hello.sh index 0d6216e..209d4ce 100755 --- a/test/test08/hello.sh +++ b/test/test08/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f functions/malloc.c \ -f test/test08/struct.c \ @@ -35,7 +35,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test08/struct.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test08-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test08-binary 2>&1 ) diff --git a/test/test09/hello.sh b/test/test09/hello.sh index a4c1143..9b501bf 100755 --- a/test/test09/hello.sh +++ b/test/test09/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f test/test09/goto.c \ -o test/test09/goto.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test09/goto.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test09-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test09-binary 2>&1 ) diff --git a/test/test10/hello.sh b/test/test10/hello.sh index 9b28a2a..6d4868a 100755 --- a/test/test10/hello.sh +++ b/test/test10/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f functions/malloc.c \ -f test/test10/nested_struct.c \ @@ -35,7 +35,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test10/nested_struct.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test10-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test10-binary 2>&1 ) diff --git a/test/test100/hello.sh b/test/test100/hello.sh index c72c379..610ad6c 100755 --- a/test/test100/hello.sh +++ b/test/test100/hello.sh @@ -19,7 +19,7 @@ set -ex # Build the test if [ -f bin/M2-Planet ] then -./bin/M2-Planet -f functions/file.c \ +./bin/M2-Planet --architecture x86 -f functions/file.c \ -f functions/malloc.c \ -f functions/calloc.c \ -f functions/exit.c \ @@ -39,7 +39,7 @@ then elif [ -f bin/M2-Planet-seed ] then [ ! -f test/results ] && mkdir test/results -./bin/M2-Planet-seed -f functions/file.c \ +./bin/M2-Planet-seed --architecture x86 -f functions/file.c \ -f functions/malloc.c \ -f functions/calloc.c \ -f functions/exit.c \ @@ -75,7 +75,7 @@ ${CC} ${CFLAGS} \ gcc_req.h \ -o bin/M2-Planet-gcc -./bin/M2-Planet-gcc -f functions/file.c \ +./bin/M2-Planet-gcc --architecture x86 -f functions/file.c \ -f functions/malloc.c \ -f functions/calloc.c \ -f functions/exit.c \ @@ -116,10 +116,10 @@ hex2 -f test/common_x86/ELF-i386-debug.hex2 \ -o test/results/test100-binary --exec_enable || exit 4 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works - ./test/results/test100-binary -f functions/file.c \ + ./test/results/test100-binary --architecture x86 -f functions/file.c \ -f functions/malloc.c \ -f functions/calloc.c \ -f functions/exit.c \ @@ -140,6 +140,9 @@ then [ "$out" = "test/test100/proof: OK" ] || exit 6 [ ! -e bin/M2-Planet ] && mv test/results/test100-binary bin/M2-Planet else - cp bin/M2-Planet-gcc bin/M2-Planet + [ -e bin/M2-Planet-gcc ] && cp bin/M2-Planet-gcc bin/M2-Planet + + # Seeds only exist if you can build natively + [ -e bin/M2-Planet-seed ] && cp test/results/test100-binary bin/M2-Planet fi exit 0 diff --git a/test/test100/proof.answer b/test/test100/proof.answer index 730e6fd..dc56e33 100644 --- a/test/test100/proof.answer +++ b/test/test100/proof.answer @@ -1 +1 @@ -f1e74d13abdb3c60e531daf18b2a8d6d728c8014ed77a354ec87bf00c5cd0abd test/test100/proof +0a88d978a2e46b571d0633c09453fb8c622718b06b91ebe89b52735b68cea97d test/test100/proof diff --git a/test/test11/hello.sh b/test/test11/hello.sh index b127651..af385da 100755 --- a/test/test11/hello.sh +++ b/test/test11/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f test/test11/break-do.c \ -o test/test11/break-do.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test11/break-do.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test11-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works ./test/results/test11-binary >| test/test11/proof || exit 4 diff --git a/test/test12/hello.sh b/test/test12/hello.sh index be4a88b..523c90c 100755 --- a/test/test12/hello.sh +++ b/test/test12/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f test/test12/break-for.c \ -o test/test12/break-for.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test12/break-for.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test12-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works ./test/results/test12-binary >| test/test12/proof || exit 4 diff --git a/test/test13/hello.sh b/test/test13/hello.sh index 8747b9c..50e4726 100755 --- a/test/test13/hello.sh +++ b/test/test13/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f test/test13/break-while.c \ -o test/test13/break-while.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test13/break-while.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test13-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works ./test/results/test13-binary >| test/test13/proof || exit 4 diff --git a/test/test14/hello.sh b/test/test14/hello.sh index 0bff318..ec7315e 100755 --- a/test/test14/hello.sh +++ b/test/test14/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f test/test14/basic_args.c \ -o test/test14/basic_args.M1 || exit 1 @@ -33,7 +33,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test14/basic_args.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test14-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works ./test/results/test14-binary 314 1 5926 5 35897 932384626 43 383279 50288 419 71693 99375105 820974944 >| test/test14/proof || exit 4 diff --git a/test/test15/hello.sh b/test/test15/hello.sh index 469c822..d5528b0 100755 --- a/test/test15/hello.sh +++ b/test/test15/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/file.c \ +bin/M2-Planet --architecture x86 -f functions/file.c \ -f functions/putchar.c \ -f test/test15/file_read.c \ -o test/test15/file_read.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test15/file_read.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test15-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works ./test/results/test15-binary test/test15/file_read.c >| test/test15/proof || exit 4 diff --git a/test/test16/hello.sh b/test/test16/hello.sh index fdf95a4..1cc7524 100755 --- a/test/test16/hello.sh +++ b/test/test16/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/file.c \ +bin/M2-Planet --architecture x86 -f functions/file.c \ -f functions/putchar.c \ -f test/test16/file_write.c \ -o test/test16/file_write.M1 || exit 1 @@ -34,7 +34,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test16/file_write.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test16-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works ./test/results/test16-binary test/test16/proof || exit 4 diff --git a/test/test17/hello.sh b/test/test17/hello.sh index 152f9ce..54bca23 100755 --- a/test/test17/hello.sh +++ b/test/test17/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/malloc.c \ +bin/M2-Planet --architecture x86 -f functions/malloc.c \ -f functions/calloc.c \ -f functions/putchar.c \ -f test/test17/memset.c \ @@ -35,7 +35,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test17/memset.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test17-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works ./test/results/test17-binary >| test/test17/proof || exit 4 diff --git a/test/test18/hello.sh b/test/test18/hello.sh index 3d14b42..65f7f1a 100755 --- a/test/test18/hello.sh +++ b/test/test18/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/file.c \ +bin/M2-Planet --architecture x86 -f functions/file.c \ -f functions/malloc.c \ -f functions/calloc.c \ -f test/test18/math.c \ @@ -35,7 +35,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test18/math.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test18-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works ./test/results/test18-binary >| test/test18/proof || exit 4 diff --git a/test/test19/hello.sh b/test/test19/hello.sh index 3c7ae29..ba57534 100755 --- a/test/test19/hello.sh +++ b/test/test19/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/file.c \ +bin/M2-Planet --architecture x86 -f functions/file.c \ -f functions/malloc.c \ -f functions/calloc.c \ -f functions/exit.c \ @@ -39,7 +39,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test19/getopt.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test19-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the resulting file works ./test/results/test19-binary -f test/test19/input -o test/test19/proof || exit 4 diff --git a/test/test20/hello.sh b/test/test20/hello.sh index 059e25b..51acdf7 100755 --- a/test/test20/hello.sh +++ b/test/test20/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/exit.c \ -f functions/malloc.c \ -f test/test20/struct.c \ @@ -35,7 +35,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test20/struct.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test20-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test20-binary 2>&1 ) diff --git a/test/test21/hello.sh b/test/test21/hello.sh index 8999954..aef2a2c 100755 --- a/test/test21/hello.sh +++ b/test/test21/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -./bin/M2-Planet -f functions/exit.c \ +./bin/M2-Planet --architecture x86 -f functions/exit.c \ -f functions/file.c \ -f functions/file_print.c \ -f functions/malloc.c \ @@ -50,7 +50,7 @@ hex2 -f test/common_x86/ELF-i386-debug.hex2 \ --exec_enable || exit 4 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test21-binary --version 2>&1 ) diff --git a/test/test22/hello.sh b/test/test22/hello.sh index 2f57afd..a4fad6f 100755 --- a/test/test22/hello.sh +++ b/test/test22/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -./bin/M2-Planet -f functions/exit.c \ +./bin/M2-Planet --architecture x86 -f functions/exit.c \ -f functions/file.c \ -f functions/file_print.c \ -f functions/malloc.c \ @@ -53,7 +53,7 @@ hex2 -f test/common_x86/ELF-i386-debug.hex2 \ --exec_enable || exit 4 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test22-binary --version 2>&1 ) diff --git a/test/test23/hello.sh b/test/test23/hello.sh index 04c6dfb..a5cc05c 100755 --- a/test/test23/hello.sh +++ b/test/test23/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -./bin/M2-Planet -f functions/exit.c \ +./bin/M2-Planet --architecture x86 -f functions/exit.c \ -f functions/file.c \ -f functions/file_print.c \ -f functions/malloc.c \ @@ -53,7 +53,7 @@ hex2 -f test/common_x86/ELF-i386-debug.hex2 \ --exec_enable || exit 4 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result out=$(./test/results/test23-binary --version 2>&1 ) diff --git a/test/test24/get_machine.c b/test/test24/get_machine.c index 22b20ac..1e7c882 100644 --- a/test/test24/get_machine.c +++ b/test/test24/get_machine.c @@ -21,13 +21,63 @@ #include #include void file_print(char* s, FILE* f); +int match(char* a, char* b); + +#define TRUE 1 +//CONSTANT TRUE 1 +#define FALSE 0 +//CONSTANT FALSE 0 /* Standard C main program */ -int main() +int main(int argc, char **argv) { + int exact = FALSE; + int override = FALSE; + char* override_string; + int option_index = 1; + while(option_index <= argc) + { + if(NULL == argv[option_index]) + { + option_index = option_index + 1; + } + else if(match(argv[option_index], "--exact")) + { + exact = TRUE; + option_index = option_index + 1; + } + else if(match(argv[option_index], "--override")) + { + override = TRUE; + override_string = argv[option_index + 1]; + option_index = option_index + 2; + } + else if(match(argv[option_index], "-V") || match(argv[option_index], "--version")) + { + file_print("get_machine 0.1\n", stdout); + exit(EXIT_SUCCESS); + } + else + { + file_print("Unknown option\n", stderr); + exit(EXIT_FAILURE); + } + } + struct utsname* unameData = calloc(1, sizeof(struct utsname)); uname(unameData); - file_print(unameData->machine, stdout); + if(override) file_print(override_string, stdout); + else if(!exact) + { + if(match("i386", unameData->machine) || + match("i486", unameData->machine) || + match("i586", unameData->machine) || + match("i686", unameData->machine) || + match("i686-pae", unameData->machine)) file_print("x86", stdout); + else if(match("x86_64", unameData->machine)) file_print("amd64", stdout); + else file_print(unameData->machine, stdout); + } + else file_print(unameData->machine, stdout); file_print("\n", stdout); return EXIT_SUCCESS; } diff --git a/test/test24/hello.sh b/test/test24/hello.sh index 161335e..7b6d814 100755 --- a/test/test24/hello.sh +++ b/test/test24/hello.sh @@ -17,12 +17,13 @@ set -x # Build the test -./bin/M2-Planet -f functions/exit.c \ +./bin/M2-Planet --architecture x86 -f functions/exit.c \ -f functions/file.c \ -f functions/file_print.c \ -f functions/malloc.c \ -f functions/calloc.c \ -f functions/uname.c \ + -f functions/match.c \ -f test/test24/get_machine.c \ --debug \ -o test/test24/get_machine.M1 || exit 1 @@ -50,11 +51,11 @@ hex2 -f test/common_x86/ELF-i386-debug.hex2 \ --exec_enable || exit 4 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result - out=$(./test/results/test24-binary 2>&1 ) + out=$(./test/results/test24-binary ${GET_MACHINE_FLAGS} 2>&1 ) [ 0 = $? ] || exit 5 - [ "$out" = "x86_64" ] || exit 6 + [ "$out" = "x86" ] || exit 6 fi exit 0 diff --git a/test/test25/hello.sh b/test/test25/hello.sh index a111e92..6de4da9 100755 --- a/test/test25/hello.sh +++ b/test/test25/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -./bin/M2-Planet -f functions/exit.c \ +./bin/M2-Planet --architecture x86 -f functions/exit.c \ -f functions/file.c \ -f functions/file_print.c \ -f functions/malloc.c \ diff --git a/test/test26/hello.sh b/test/test26/hello.sh index fe30ac5..0ffe74e 100755 --- a/test/test26/hello.sh +++ b/test/test26/hello.sh @@ -17,7 +17,7 @@ set -x # Build the test -./bin/M2-Planet -f test/test26/lisp.h \ +./bin/M2-Planet --architecture x86 -f test/test26/lisp.h \ -f functions/malloc.c \ -f functions/calloc.c \ -f functions/in_set.c \ diff --git a/test/test99/hello.sh b/test/test99/hello.sh index b0512f3..913875e 100755 --- a/test/test99/hello.sh +++ b/test/test99/hello.sh @@ -17,7 +17,7 @@ set -ex # Build the test -bin/M2-Planet -f functions/putchar.c \ +bin/M2-Planet --architecture x86 -f functions/putchar.c \ -f functions/getchar.c \ -f functions/exit.c \ -f functions/malloc.c \ @@ -36,7 +36,7 @@ M1 -f test/common_x86/x86_defs.M1 \ hex2 -f test/common_x86/ELF-i386.hex2 -f test/test99/cc0.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test99-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test -if [ "$(get_machine)" = "x86_64" ] +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program can compile itself ./test/results/test99-binary < test/test99/cc500.c >| test/test99/cc1 || exit 4