From c6ac46292ffa98610b52e47b81e9ac931cc99460 Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Sun, 24 Feb 2019 09:58:47 -0500 Subject: [PATCH] Added test05 for knight-posix --- CHANGELOG.org | 1 + cc_core.c | 20 ++++++------ makefile | 20 ++++++++---- test/test.answers | 12 ++++--- test/test04/hello-knight-posix.sh | 44 ++++++++++++++++++++++++++ test/test04/{hello.sh => hello-x86.sh} | 4 +-- test/test05/hello-knight-posix.sh | 44 ++++++++++++++++++++++++++ test/test05/{hello.sh => hello-x86.sh} | 4 +-- test/test05/string.c | 4 +-- test/test100/proof.answer | 2 +- 10 files changed, 127 insertions(+), 28 deletions(-) create mode 100755 test/test04/hello-knight-posix.sh rename test/test04/{hello.sh => hello-x86.sh} (94%) create mode 100755 test/test05/hello-knight-posix.sh rename test/test05/{hello.sh => hello-x86.sh} (93%) diff --git a/CHANGELOG.org b/CHANGELOG.org index 3b2fbeb..a92ae98 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -30,6 +30,7 @@ Added first knight-posix test Added second knight-posix test Added third knight-posix test Added fourth knight-posix test +Added fifth knight-posix test ** Changed Converted M2-Planet to use GNU style error message diff --git a/cc_core.c b/cc_core.c index 918d2bf..7b531f8 100644 --- a/cc_core.c +++ b/cc_core.c @@ -216,7 +216,7 @@ void variable_load(struct token_list* a) } current_target = a->type; - if(1 == Architecture) emit_out("ADDI R0 R14 @"); + if(1 == Architecture) emit_out("ADDI R0 R14 "); else if(2 == Architecture) emit_out("LOAD_BASE_ADDRESS_eax %"); emit_out(numerate_number(a->depth)); @@ -596,12 +596,12 @@ void relational_expr_stub() { if(1 == Architecture) { - general_recursion(additive_expr, "CMPSKIP.GE R0 R1\nLOADUI R0 1\n", "<", relational_expr_stub); - general_recursion(additive_expr, "CMPSKIP.G R0 R1\nLOADUI R0 1\n", "<=", relational_expr_stub); - general_recursion(additive_expr, "CMPSKIP.L R0 R1\nLOADUI R0 1\n", ">=", relational_expr_stub); - general_recursion(additive_expr, "CMPSKIP.LE R0 R1\nLOADUI R0 1\n", ">", relational_expr_stub); - general_recursion(additive_expr, "CMPSKIP.NE R0 R1\nLOADUI R0 1\n", "==", relational_expr_stub); - general_recursion(additive_expr, "CMPSKIP.E R0 R1\nLOADUI R0 1\n", "!=", relational_expr_stub); + general_recursion(additive_expr, "CMPSKIP.GE R1 R0\nLOADUI R2 1\nMOVE R0 R2\n", "<", relational_expr_stub); + general_recursion(additive_expr, "CMPSKIP.G R1 R0\nLOADUI R2 1\nMOVE R0 R2\n", "<=", relational_expr_stub); + general_recursion(additive_expr, "CMPSKIP.L R1 R0\nLOADUI R2 1\nMOVE R0 R2\n", ">=", relational_expr_stub); + general_recursion(additive_expr, "CMPSKIP.LE R1 R0\nLOADUI R2 1\nMOVE R0 R2\n", ">", relational_expr_stub); + general_recursion(additive_expr, "CMPSKIP.NE R1 R0\nLOADUI R2 1\nMOVE R0 R2\n", "==", relational_expr_stub); + general_recursion(additive_expr, "CMPSKIP.E R1 R0\nLOADUI R2 1\nMOVE R0 R2\n", "!=", relational_expr_stub); } else if(2 == Architecture) { @@ -744,12 +744,12 @@ void collect_local() struct token_list* a = sym_declare(global_token->s, type_size, function->locals); if(match("main", function->s) && (NULL == function->locals)) { - if(1 == Architecture) a->depth = 20; + if(1 == Architecture) a->depth = 4; else if(2 == Architecture) a->depth = -20; } else if((NULL == function->arguments) && (NULL == function->locals)) { - if(1 == Architecture) a->depth = 8; + if(1 == Architecture) a->depth = 4; else if(2 == Architecture) a->depth = -8; } else if(NULL == function->locals) @@ -1168,7 +1168,7 @@ void collect_arguments() struct token_list* a = sym_declare(global_token->s, type_size, function->arguments); if(NULL == function->arguments) { - if(1 == Architecture) a->depth = 4; + if(1 == Architecture) a->depth = 0; else if(2 == Architecture) a->depth = -4; } else diff --git a/makefile b/makefile index 7ce937c..745c985 100644 --- a/makefile +++ b/makefile @@ -66,12 +66,14 @@ test: test00-knight-posix-binary \ test01-knight-posix-binary \ test02-knight-posix-binary \ test03-knight-posix-binary \ + test04-knight-posix-binary \ + test05-knight-posix-binary \ test00-x86-binary \ test01-x86-binary \ test02-x86-binary \ test03-x86-binary \ - test04-binary \ - test05-binary \ + test04-x86-binary \ + test05-x86-binary \ test06-binary \ test07-binary \ test08-binary \ @@ -107,6 +109,12 @@ test02-knight-posix-binary: M2-Planet | results test03-knight-posix-binary: M2-Planet | results test/test03/hello-knight-posix.sh +test04-knight-posix-binary: M2-Planet | results + test/test04/hello-knight-posix.sh + +test05-knight-posix-binary: M2-Planet | results + test/test05/hello-knight-posix.sh + test00-x86-binary: M2-Planet | results test/test00/hello-x86.sh @@ -119,11 +127,11 @@ test02-x86-binary: M2-Planet | results test03-x86-binary: M2-Planet | results test/test03/hello-x86.sh -test04-binary: M2-Planet | results - test/test04/hello.sh +test04-x86-binary: M2-Planet | results + test/test04/hello-x86.sh -test05-binary: M2-Planet | results - test/test05/hello.sh +test05-x86-binary: M2-Planet | results + test/test05/hello-x86.sh test06-binary: M2-Planet | results test/test06/hello.sh diff --git a/test/test.answers b/test/test.answers index 4544912..f27d701 100644 --- a/test/test.answers +++ b/test/test.answers @@ -2,18 +2,20 @@ c52562bd0aabb86ce8ca177f22f8d0455769b444df2d4d62894faab63b7151d8 test/results/test00-x86-binary fab674644b9519e8ec39e254e6b13fe5eccb9f861f7d9e7d2f736d40875b7546 test/results/test01-knight-posix-binary eae96857f2b6d8e8ba86ac06e72345ea572622b358b23978bb5f2db1baadf41c test/results/test01-x86-binary -1cd9bdf671f1b26992bb34eebb52c745a4af930b34ef0bb25348a243d0f219aa test/results/test02-knight-posix-binary +d1788ab10ad9d16488eac547664f59b1a0d4684da90240eecc1de3dceac7de78 test/results/test02-knight-posix-binary 8ead336d2f3f72d5874230492e0472edec61d355905e8636e3dfb2731695037c test/results/test02-x86-binary -25f4fcd3834351b24f76eb78571770b4afa9812970fca3000600d2e26abe35f3 test/results/test03-knight-posix-binary +e7e27666bbac654863302365ace7696b220bbb4f989eb3ee76966e09076d5fdd test/results/test03-knight-posix-binary 2313cb3f1a2b9eb6bf15f8d43418e15d6c16f7f1b5c22700fdfc2b38beb59192 test/results/test03-x86-binary -b7ddb37063c541c6a315809c4438aa235d6702f54bb64f4ffc88dbe78617de81 test/results/test04-binary -4d4ec6247a7cc9062a5b3d8adfec7199476715446723a0b882268afe6daad1f3 test/results/test05-binary +f46d7e681d9022be3e2df0063826302b708f35f682942f16fb247e22dee70137 test/results/test04-knight-posix-binary +b7ddb37063c541c6a315809c4438aa235d6702f54bb64f4ffc88dbe78617de81 test/results/test04-x86-binary +5efe707d92f6bea63be31605f38ac9caff6509b10f4461c3df9e34332dc550f7 test/results/test05-knight-posix-binary +b5b76320ccda887a30b0bbefc2a5c302c8f2aa3c398d92ef3a79526690b25d6f test/results/test05-x86-binary 663fc6eefe965f237b6bf5a211398c8ae1210f97ff39b59603677e92462c68c7 test/results/test06-binary a9a3e332d13ded5f80d7431f8717f26527b3722b33ea57760a9a5723dffc099c test/results/test07-binary f1c01feb865c4d552033186d9ce50dd39468a7e8aebf762886c13ad3e03b5011 test/results/test08-binary 3b39e72f3de90ed690adfaf6145af46157cef2ec5e72867ac577fa27a0229894 test/results/test09-binary 020e86020819cc4963e6185b22e534fcf8306b6cb116f12643f254a24688ff0a test/results/test10-binary -8bcd6f50512d0c300d2fc0939363d4dbcfc17f255e8b0f938508149097023ee7 test/results/test100-binary +70429b4c78f8a712c5bf2de9d7cbfac06fafedc0635b58f0b6319906f3549ab0 test/results/test100-binary 3fd11bad4a426ce1ff8fd9c6d7d2b943effae9f3f5740b7376e426e9b0555851 test/results/test11-binary f98ab8e4bb35580e0dde96126d7a56aff66bda208d02c8d89390b40d6cff591c test/results/test12-binary 5051ffca2615144419f8ec1a5d4999486ae81e7781428f59e47e866af97cef92 test/results/test13-binary diff --git a/test/test04/hello-knight-posix.sh b/test/test04/hello-knight-posix.sh new file mode 100755 index 0000000..1b3712e --- /dev/null +++ b/test/test04/hello-knight-posix.sh @@ -0,0 +1,44 @@ +#! /bin/sh +## Copyright (C) 2017 Jeremiah Orians +## This file is part of M2-Planet. +## +## M2-Planet is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## M2-Planet is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with M2-Planet. If not, see . + +set -x +# Build the test +bin/M2-Planet --architecture knight-posix -f test/common_knight/functions/putchar.c \ + -f test/common_knight/functions/exit.c \ + -f test/test04/call.c \ + -o test/test04/call.M1 || exit 1 + +# Macro assemble with libc written in M1-Macro +M1 -f test/common_knight/knight_defs.M1 \ + -f test/common_knight/libc-core.M1 \ + -f test/test04/call.M1 \ + --BigEndian \ + --architecture knight-posix \ + -o test/test04/call.hex2 || exit 2 + +# Resolve all linkages +hex2 -f test/common_knight/ELF-knight.hex2 -f test/test04/call.hex2 --BigEndian --architecture knight-posix --BaseAddress 0x00 -o test/results/test04-knight-posix-binary --exec_enable || exit 3 + +# Ensure binary works if host machine supports test +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "knight*" ] +then + # Verify that the compiled program returns the correct result + out=$(./test/results/test04-knight-posix-binary 2>&1 ) + [ 42 = $? ] || exit 4 + [ "$out" = "Hello mes" ] || exit 5 +fi +exit 0 diff --git a/test/test04/hello.sh b/test/test04/hello-x86.sh similarity index 94% rename from test/test04/hello.sh rename to test/test04/hello-x86.sh index b9318ce..770a9b8 100755 --- a/test/test04/hello.sh +++ b/test/test04/hello-x86.sh @@ -31,13 +31,13 @@ M1 -f test/common_x86/x86_defs.M1 \ -o test/test04/call.hex2 || exit 2 # Resolve all linkages -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 +hex2 -f test/common_x86/ELF-i386.hex2 -f test/test04/call.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test04-x86-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result - out=$(./test/results/test04-binary 2>&1 ) + out=$(./test/results/test04-x86-binary 2>&1 ) [ 42 = $? ] || exit 4 [ "$out" = "Hello mes" ] || exit 5 fi diff --git a/test/test05/hello-knight-posix.sh b/test/test05/hello-knight-posix.sh new file mode 100755 index 0000000..5debd0f --- /dev/null +++ b/test/test05/hello-knight-posix.sh @@ -0,0 +1,44 @@ +#! /bin/sh +## Copyright (C) 2017 Jeremiah Orians +## This file is part of M2-Planet. +## +## M2-Planet is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## M2-Planet is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with M2-Planet. If not, see . + +set -x +# Build the test +bin/M2-Planet --architecture knight-posix -f test/common_knight/functions/putchar.c \ + -f test/common_knight/functions/exit.c \ + -f test/test05/string.c \ + -o test/test05/string.M1 || exit 1 + +# Macro assemble with libc written in M1-Macro +M1 -f test/common_knight/knight_defs.M1 \ + -f test/common_knight/libc-core.M1 \ + -f test/test05/string.M1 \ + --BigEndian \ + --architecture knight-posix \ + -o test/test05/string.hex2 || exit 2 + +# Resolve all linkages +hex2 -f test/common_knight/ELF-knight.hex2 -f test/test05/string.hex2 --BigEndian --architecture knight-posix --BaseAddress 0x00 -o test/results/test05-knight-posix-binary --exec_enable || exit 3 + +# Ensure binary works if host machine supports test +if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "knight*" ] +then + # Verify that the compiled program returns the correct result + out=$(./test/results/test05-knight-posix-binary 2>&1 ) + [ 42 = $? ] || exit 4 + [ "$out" = "Hello mes" ] || exit 5 +fi +exit 0 diff --git a/test/test05/hello.sh b/test/test05/hello-x86.sh similarity index 93% rename from test/test05/hello.sh rename to test/test05/hello-x86.sh index 6dfe0b2..6fa9786 100755 --- a/test/test05/hello.sh +++ b/test/test05/hello-x86.sh @@ -31,13 +31,13 @@ M1 -f test/common_x86/x86_defs.M1 \ -o test/test05/string.hex2 || exit 2 # Resolve all linkages -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 +hex2 -f test/common_x86/ELF-i386.hex2 -f test/test05/string.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test05-x86-binary --exec_enable || exit 3 # Ensure binary works if host machine supports test if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ] then # Verify that the compiled program returns the correct result - out=$(./test/results/test05-binary 2>&1 ) + out=$(./test/results/test05-x86-binary 2>&1 ) [ 42 = $? ] || exit 4 [ "$out" = "Hello mes" ] || exit 5 fi diff --git a/test/test05/string.c b/test/test05/string.c index 442755d..e920ae2 100644 --- a/test/test05/string.c +++ b/test/test05/string.c @@ -28,8 +28,8 @@ void printc(char* s, int a) int main() { - char* string = "mes Hello "; + char* string = "mes\nHello "; printc(string + 4, 99); - printc(string, 3); + printc(string, 4); return 42; } diff --git a/test/test100/proof.answer b/test/test100/proof.answer index 37149c0..30c62e9 100644 --- a/test/test100/proof.answer +++ b/test/test100/proof.answer @@ -1 +1 @@ -8e3df151387b36580dfdf827ad2df237c72654ee31696f53e6961975d9baf4e3 test/test100/proof +6fdd455d135bb0d3ba048db2d9b41c469a5a8b695cf739f0916c8ec8e95dd637 test/test100/proof