diff --git a/cc_core.c b/cc_core.c index 8526f8e..929c022 100644 --- a/cc_core.c +++ b/cc_core.c @@ -46,7 +46,8 @@ char* parse_string(char* string); int escape_lookup(char* c); int numerate_string(char *a); void require(int bool, char* error); - +/* Host touchy function will need custom on 64bit systems*/ +int fixup_int32(int a); struct token_list* emit(char *s, struct token_list* head) { @@ -446,7 +447,7 @@ void primary_expr_number() { if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) { - int size = numerate_string(global_token->s); + int size = fixup_int32(numerate_string(global_token->s)); if((32767 > size) && (size > -32768)) { emit_out("LOADI R0 "); diff --git a/functions/fixup.c b/functions/fixup.c new file mode 100644 index 0000000..45b438b --- /dev/null +++ b/functions/fixup.c @@ -0,0 +1,22 @@ +/* Copyright (C) 2016 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 . + */ + +/* This only works for 32bit architectures */ +int fixup_int32(int a) +{ + return a; +} diff --git a/makefile b/makefile index 96036ce..17b6559 100644 --- a/makefile +++ b/makefile @@ -34,6 +34,7 @@ M2-Planet: bin results cc.h cc_reader.c cc_strings.c cc_types.c cc_core.c cc.c functions/number_pack.c \ functions/string.c \ functions/require.c \ + functions/fixup.c \ cc_reader.c \ cc_strings.c \ cc_types.c \ @@ -52,6 +53,7 @@ M2-minimal: bin results cc.h cc_reader.c cc_strings.c cc_types.c cc_core.c cc-mi functions/number_pack.c \ functions/string.c \ functions/require.c \ + functions/fixup.c \ cc_reader.c \ cc_strings.c \ cc_types.c \ diff --git a/test/common_aarch64/functions/fixup.c b/test/common_aarch64/functions/fixup.c new file mode 100644 index 0000000..f77a472 --- /dev/null +++ b/test/common_aarch64/functions/fixup.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2016 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 . + */ + + +int fixup_int32(int a) +{ + if(0 != (0x80000000 & a)) + { + a = a << 32; + a = a >> 32; + } + + return a; +} diff --git a/test/common_amd64/functions/fixup.c b/test/common_amd64/functions/fixup.c new file mode 100644 index 0000000..f62d8eb --- /dev/null +++ b/test/common_amd64/functions/fixup.c @@ -0,0 +1,24 @@ +/* Copyright (C) 2016 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 . + */ + +/* Only works for AMD64 with the value in RAX */ +int fixup_int32(int a) +{ + asm("LOAD_EFFECTIVE_ADDRESS_rax %8" + "LOAD_INTEGER" + "MOVESX"); +} diff --git a/test/test.answers b/test/test.answers index bc2c930..b2e19e8 100644 --- a/test/test.answers +++ b/test/test.answers @@ -169,8 +169,8 @@ c22dabd4d371e23ed10389080eaa241f31a3822f08c64c934776c80b2e376a51 test/results/t 6eb826151abe3ea2d7c1f16079e61f1b80d651a20f8341fbb77574f7b5c41fb3 test/results/test0106-knight-native-binary 61cdce452cb287467efbf315da67f3d107f5d3a9c3cf5b086bf51dcc67d78971 test/results/test0106-knight-posix-binary 55804110c3b2d5a5e5130a8ed11f0888f4460ee32ad6a86fde877ec914624a6d test/results/test0106-x86-binary -33408d9b3370af357dd4cbdbbe8afaa8ef2b3d178dd889bb18b4d332ea073e5c test/results/test1000-aarch64-binary -20c40ff607486a267e7d97efb3b085ada3ab047d7275d2cce3bab1e5fbfeceb7 test/results/test1000-amd64-binary -79aa352c954cbf5a8ad97a2065114342acd20ae71ee33af1adb73eedb380557f test/results/test1000-armv7l-binary -4b513e582ab3686c996052930a6af88d2ad176a81223f8d3d99e6617ba501277 test/results/test1000-knight-posix-binary -8f89602bc7e66f4c228f97c04054b2d8613b81dabed3796bd9486f98756de806 test/results/test1000-x86-binary +b952f44841f440020baa6ef5243ec223fb85f7a1f2326c0b40ee16b65dbebe49 test/results/test1000-aarch64-binary +23875877e8721ed56c3e0ef625ac264bd39d9ed594905adebf1c2e933e33cca5 test/results/test1000-amd64-binary +ef705712c741acb90464ab58154c16832658a980bc7a55c48aea64e59ea93ebc test/results/test1000-armv7l-binary +7d7b4dbeea3aac3a91fb093ddd4b37baf8898ddf5f8f2af8006529f737b75a93 test/results/test1000-knight-posix-binary +3b8bec2a562ac0a5c6a623563ad7622a987b24e47937885d1f21d2ea17871e34 test/results/test1000-x86-binary diff --git a/test/test1000/hello-aarch64.sh b/test/test1000/hello-aarch64.sh index 57f1c28..7da9f9c 100755 --- a/test/test1000/hello-aarch64.sh +++ b/test/test1000/hello-aarch64.sh @@ -30,6 +30,7 @@ set -ex -f functions/number_pack.c \ -f functions/string.c \ -f functions/require.c \ + -f test/common_aarch64/functions/fixup.c \ -f cc.h \ -f cc_reader.c \ -f cc_strings.c \ diff --git a/test/test1000/hello-amd64.sh b/test/test1000/hello-amd64.sh index 3806f10..ef01538 100755 --- a/test/test1000/hello-amd64.sh +++ b/test/test1000/hello-amd64.sh @@ -29,6 +29,7 @@ set -ex -f functions/number_pack.c \ -f functions/string.c \ -f functions/require.c \ + -f test/common_amd64/functions/fixup.c \ -f cc.h \ -f cc_reader.c \ -f cc_strings.c \ diff --git a/test/test1000/hello-armv7l.sh b/test/test1000/hello-armv7l.sh index 7efc8d1..5a4fba0 100755 --- a/test/test1000/hello-armv7l.sh +++ b/test/test1000/hello-armv7l.sh @@ -29,6 +29,7 @@ set -ex -f functions/number_pack.c \ -f functions/string.c \ -f functions/require.c \ + -f functions/fixup.c \ -f cc.h \ -f cc_reader.c \ -f cc_strings.c \ diff --git a/test/test1000/hello-knight-posix.sh b/test/test1000/hello-knight-posix.sh index f69f2f6..5b5be11 100755 --- a/test/test1000/hello-knight-posix.sh +++ b/test/test1000/hello-knight-posix.sh @@ -29,6 +29,7 @@ set -ex -f functions/number_pack.c \ -f functions/string.c \ -f functions/require.c \ + -f functions/fixup.c \ -f cc.h \ -f cc_reader.c \ -f cc_strings.c \ diff --git a/test/test1000/hello-x86.sh b/test/test1000/hello-x86.sh index 0466f7e..8ed431b 100755 --- a/test/test1000/hello-x86.sh +++ b/test/test1000/hello-x86.sh @@ -29,6 +29,7 @@ set -ex -f functions/number_pack.c \ -f functions/string.c \ -f functions/require.c \ + -f functions/fixup.c \ -f cc.h \ -f cc_reader.c \ -f cc_strings.c \ diff --git a/test/test1000/proof.answer b/test/test1000/proof.answer index 329d6c5..5057833 100644 --- a/test/test1000/proof.answer +++ b/test/test1000/proof.answer @@ -1 +1 @@ -c3442a08ff63c1520c84e6f4cc3e97e379e0d87fedd300b14c5f38f0fce65e55 test/test1000/proof +df2c542a46a5367f62b3a573256942bc139fdcd5cd49547b43257ab889c50bad test/test1000/proof