diff --git a/cc_core.c b/cc_core.c
index c2ce6b9..01bb3a9 100644
--- a/cc_core.c
+++ b/cc_core.c
@@ -124,6 +124,17 @@ void require_match(char* message, char* required)
require(NULL != global_token, "EOF after require match occurred\n");
}
+void maybe_bootstrap_error(char* feature)
+{
+ if (BOOTSTRAP_MODE)
+ {
+ line_error();
+ file_print(feature, stderr);
+ file_print(" is not supported in --bootstrap-mode\n", stderr);
+ exit(EXIT_FAILURE);
+ }
+}
+
void expression();
void function_call(char* s, int bool)
{
@@ -1813,6 +1824,7 @@ void program()
function = NULL;
Address_of = FALSE;
struct type* type_size;
+ int size;
new_type:
if (NULL == global_token) return;
@@ -1857,10 +1869,45 @@ new_type:
{
goto new_type;
}
+
+ require(NULL != global_token->next, "Unterminated global\n");
+ if(match("[", global_token->next->s))
+ {
+ maybe_bootstrap_error("global array definitions");
+ globals_list = emit(":GLOBAL_", globals_list);
+ globals_list = emit(global_token->s, globals_list);
+ globals_list = emit("\n&GLOBAL_STORAGE_", globals_list);
+ globals_list = emit(global_token->s, globals_list);
+ if (AARCH64 == Architecture || AMD64 == Architecture)
+ {
+ globals_list = emit(" %0", globals_list);
+ }
+ globals_list = emit("\n:GLOBAL_STORAGE_", globals_list);
+ globals_list = emit(global_token->s, globals_list);
+ global_symbol_list = sym_declare(global_token->s, type_size->indirect, global_symbol_list);
+
+ require(NULL != global_token->next->next, "Unterminated global\n");
+ global_token = global_token->next->next;
+
+ /* length */
+ size = numerate_string(global_token->s);
+ globals_list = emit("\n'", globals_list);
+ while (0 != size)
+ {
+ globals_list = emit(" 00", globals_list);
+ size = size - 1;
+ }
+ globals_list = emit("'\n", globals_list);
+
+ global_token = global_token->next;
+ require_match("missing close bracket\n", "]");
+ require_match("missing ;\n", ";");
+
+ goto new_type;
+ }
/* Add to global symbol table */
global_symbol_list = sym_declare(global_token->s, type_size, global_symbol_list);
global_token = global_token->next;
- require(NULL != global_token, "Unterminated global\n");
if(match(";", global_token->s))
{
/* Ensure 4 bytes are allocated for the global */
diff --git a/makefile b/makefile
index 3b7c98e..5038079 100644
--- a/makefile
+++ b/makefile
@@ -95,6 +95,7 @@ clean:
./test/test0022/cleanup.sh
./test/test0023/cleanup.sh
./test/test0024/cleanup.sh
+ ./test/test0025/cleanup.sh
./test/test0100/cleanup.sh
./test/test0101/cleanup.sh
./test/test0102/cleanup.sh
@@ -141,6 +142,7 @@ aarch64-tests: \
test0022-aarch64-binary \
test0023-aarch64-binary \
test0024-aarch64-binary \
+ test0025-aarch64-binary \
test0100-aarch64-binary \
test0101-aarch64-binary \
test0102-aarch64-binary \
@@ -176,6 +178,7 @@ amd64-tests: \
test0022-amd64-binary \
test0023-amd64-binary \
test0024-amd64-binary \
+ test0025-amd64-binary \
test0100-amd64-binary \
test0101-amd64-binary \
test0102-amd64-binary \
@@ -265,6 +268,7 @@ armv7l-tests: \
test0022-armv7l-binary \
test0023-armv7l-binary \
test0024-armv7l-binary \
+ test0025-armv7l-binary \
test0100-armv7l-binary \
test0101-armv7l-binary \
test0102-armv7l-binary \
@@ -300,6 +304,7 @@ x86-tests: \
test0022-x86-binary \
test0023-x86-binary \
test0024-x86-binary \
+ test0025-x86-binary \
test0100-x86-binary \
test0101-x86-binary \
test0102-x86-binary \
@@ -384,6 +389,9 @@ test0023-aarch64-binary: M2-Planet | results
test0024-aarch64-binary: M2-Planet | results
test/test0024/hello-aarch64.sh
+test0025-aarch64-binary: M2-Planet | results
+ test/test0025/hello-aarch64.sh
+
test0100-aarch64-binary: M2-Planet | results
test/test0100/hello-aarch64.sh
@@ -483,6 +491,9 @@ test0023-amd64-binary: M2-Planet | results
test0024-amd64-binary: M2-Planet | results
test/test0024/hello-amd64.sh
+test0025-amd64-binary: M2-Planet | results
+ test/test0025/hello-amd64.sh
+
test0100-amd64-binary: M2-Planet | results
test/test0100/hello-amd64.sh
@@ -732,6 +743,9 @@ test0023-armv7l-binary: M2-Planet | results
test0024-armv7l-binary: M2-Planet | results
test/test0024/hello-armv7l.sh
+test0025-armv7l-binary: M2-Planet | results
+ test/test0025/hello-armv7l.sh
+
test0100-armv7l-binary: M2-Planet | results
test/test0100/hello-armv7l.sh
@@ -831,6 +845,9 @@ test0023-x86-binary: M2-Planet | results
test0024-x86-binary: M2-Planet | results
test/test0024/hello-x86.sh
+test0025-x86-binary: M2-Planet | results
+ test/test0025/hello-x86.sh
+
test0100-x86-binary: M2-Planet | results
test/test0100/hello-x86.sh
diff --git a/test/test.answers b/test/test.answers
index f4fe64b..0c0ba27 100644
--- a/test/test.answers
+++ b/test/test.answers
@@ -141,6 +141,10 @@ deb80d26727f797c397b927938360f846eb982dc0722903cb07947737332c443 test/results/t
0c93110e4cf2f8f69eb3a308162478e644ee63fd4881762161be5de50fbe9f06 test/results/test0024-knight-native-binary
4862ffbb8e6265bdbf3d5fd824f7b7581206a627f5e7fe83cf5b7f4b30b8ebd4 test/results/test0024-knight-posix-binary
69c060eae9ffb12992d89eb02f066c517c5acfd1d9f80152e279fccce7b77f6a test/results/test0024-x86-binary
+6d7909095cce3d94a439a9a54c7433aa2a53abc0d703731941aa29411252788d test/results/test0025-aarch64-binary
+7b52bb0df9b63a80ee2040515c215d47fe31bc550c25feca7d0f5e2c69090070 test/results/test0025-amd64-binary
+22475767a4ecac73edfc760f770a335da62c2b3b71e591e2341d0173ff5308e1 test/results/test0025-armv7l-binary
+2b737bd6998686125c726e0fc5cd3c52ce39fbc93666772b25ec2f116c71690f test/results/test0025-x86-binary
28353f8a2c920af49a89a302d4910bd8df81a3147ca7c2c197fa5487ebb6d180 test/results/test0100-aarch64-binary
4d4d7dc249a4fc1788f4443a7a5feba51392a73dc1b80297a510cbca41afd71e test/results/test0100-amd64-binary
98ebb4ac496ed255d769383d027b0bf358f280b248a0994b30c047d2d5506ec4 test/results/test0100-armv7l-binary
@@ -175,8 +179,8 @@ a2a83f42119e646b389b98647cf6cf2aa9597185997c9453db746178c8c4c0bf test/results/t
698853b79efb30865a663c4863c050639eb21c7400008f7840830503928973d4 test/results/test0106-knight-native-binary
45c2ba61dc209d7ffa39de9ff0f0a7f8f3ea4d7e38598c72f982fcaf9a05c84a test/results/test0106-knight-posix-binary
944580ff4aae38aafac139faf6eed5bfe4ff68b01a7a3adfa346de8803101182 test/results/test0106-x86-binary
-26e9a6dd65d2cd9f7ad45b0dc145239b9317c77029c6b69faf922a9af65a0678 test/results/test1000-aarch64-binary
-421f97cb2c0ea0fbdc6ac366a340657682bf1ed9f36f7edad9972f61eb9ec2a8 test/results/test1000-amd64-binary
-7486674615d8165e5e0365070a1e20142c12d334db7393fbeafa46d14c5c74c5 test/results/test1000-armv7l-binary
-8e7f3f18441a8f5762741f1362d6789098fbb8c9f7ac722b7036416e7e602b25 test/results/test1000-knight-posix-binary
-02f26abda516b431ea6e01cfd135e45cd387fa71470495aba005bc121e23c425 test/results/test1000-x86-binary
+2acc8a2f5317cb809e0d523cb997e8ab91f90ac95881288d874ed9156a3dcfb4 test/results/test1000-aarch64-binary
+abac486fb04c067876058e16782f42e202f56cc8a013362e8a57743869f20aac test/results/test1000-amd64-binary
+e575170b6ebf2c3c2fd130943f7c3b28c52c77e9c2a65dde13b471f92286f64f test/results/test1000-armv7l-binary
+092ff610f2dc8d643545643d7d2a7423c37b8a88c4ffecd0f4df91e2210115a3 test/results/test1000-knight-posix-binary
+1893b8088334aa54a06a4c90ff384b9f499684055e6911843651c2f14d8aacb0 test/results/test1000-x86-binary
diff --git a/test/test0025/.gitignore b/test/test0025/.gitignore
new file mode 100644
index 0000000..5b7810f
--- /dev/null
+++ b/test/test0025/.gitignore
@@ -0,0 +1,23 @@
+## 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 .
+
+# Ignore the files created by script
+*.M1
+*.hex2
+proof
+
+# A place to put a good run for comparison
+actual.M1
diff --git a/test/test0025/array.c b/test/test0025/array.c
new file mode 100644
index 0000000..f417cb2
--- /dev/null
+++ b/test/test0025/array.c
@@ -0,0 +1,46 @@
+/* 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 .
+ */
+#include
+
+char global[32];
+
+void write_string(char* c, FILE* f)
+{
+ while(0 != c[0])
+ {
+ fputc(c[0], f);
+ c = c + 1;
+ }
+}
+
+void strcpy(char* a, char* b)
+{
+ while(0 != b[0])
+ {
+ a[0] = b[0];
+ a = a + 1;
+ b = b + 1;
+ }
+}
+
+int main()
+{
+ strcpy(global, "hello global\n");
+ write_string(global, stderr);
+
+ return 0;
+}
diff --git a/test/test0025/cleanup.sh b/test/test0025/cleanup.sh
new file mode 100755
index 0000000..c880eb8
--- /dev/null
+++ b/test/test0025/cleanup.sh
@@ -0,0 +1,21 @@
+#! /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 .
+
+rm -f test/test0025/array.M1
+rm -f test/test0025/array.hex2
+rm -f test/test0025/proof
+exit 0
diff --git a/test/test0025/hello-aarch64.sh b/test/test0025/hello-aarch64.sh
new file mode 100755
index 0000000..66f3e9d
--- /dev/null
+++ b/test/test0025/hello-aarch64.sh
@@ -0,0 +1,62 @@
+#! /bin/sh
+## Copyright (C) 2017 Jeremiah Orians
+## Copyright (C) 2020 deesix
+## 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 -ex
+# Build the test
+bin/M2-Planet --architecture aarch64 \
+ -f M2libc/AArch64/Linux/unistd.h \
+ -f M2libc/stdlib.c \
+ -f M2libc/AArch64/Linux/fcntl.h \
+ -f M2libc/stdio.c \
+ -f test/test0025/array.c \
+ --debug \
+ -o test/test0025/array.M1 || exit 1
+
+# Build debug footer
+blood-elf --64 -f test/test0025/array.M1 \
+ --entry _start \
+ -o test/test0025/array-footer.M1 || exit 2
+
+# Macro assemble with libc written in M1-Macro
+M1 -f M2libc/AArch64/aarch64_defs.M1 \
+ -f M2libc/AArch64/libc-full.M1 \
+ -f test/test0025/array.M1 \
+ -f test/test0025/array-footer.M1 \
+ --LittleEndian \
+ --architecture aarch64 \
+ -o test/test0025/array.hex2 || exit 2
+
+# Resolve all linkages
+hex2 -f M2libc/AArch64/ELF-aarch64-debug.hex2 \
+ -f test/test0025/array.hex2 \
+ --LittleEndian \
+ --architecture aarch64 \
+ --BaseAddress 0x400000 \
+ -o test/results/test0025-aarch64-binary \
+ --exec_enable || exit 3
+
+# Ensure binary works if host machine supports test
+if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "aarch64" ]
+then
+ . ./sha256.sh
+ # Verify that the resulting file works
+ ./test/results/test0025-aarch64-binary > test/test0025/proof || exit 4
+ out=$(sha256_check test/test0025/proof.answer)
+ [ "$out" = "test/test0025/proof: OK" ] || exit 5
+fi
+exit 0
diff --git a/test/test0025/hello-amd64.sh b/test/test0025/hello-amd64.sh
new file mode 100755
index 0000000..139c40d
--- /dev/null
+++ b/test/test0025/hello-amd64.sh
@@ -0,0 +1,60 @@
+#! /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 -ex
+bin/M2-Planet --architecture amd64 \
+ -f M2libc/amd64/Linux/unistd.h \
+ -f M2libc/stdlib.c \
+ -f M2libc/amd64/Linux/fcntl.h \
+ -f M2libc/stdio.c \
+ -f test/test0025/array.c \
+ --debug \
+ -o test/test0025/array.M1 || exit 1
+
+# Build debug footer
+blood-elf --64 -f test/test0025/array.M1 \
+ --entry _start \
+ -o test/test0025/array-footer.M1 || exit 2
+
+# Macro assemble with libc written in M1-Macro
+M1 -f M2libc/amd64/amd64_defs.M1 \
+ -f M2libc/amd64/libc-full.M1 \
+ -f test/test0025/array.M1 \
+ -f test/test0025/array-footer.M1 \
+ --LittleEndian \
+ --architecture amd64 \
+ -o test/test0025/array.hex2 || exit 2
+
+# Resolve all linkages
+hex2 -f M2libc/amd64/ELF-amd64-debug.hex2 \
+ -f test/test0025/array.hex2 \
+ --LittleEndian \
+ --architecture amd64 \
+ --BaseAddress 0x400000 \
+ -o test/results/test0025-amd64-binary \
+ --exec_enable || exit 3
+
+# Ensure binary works if host machine supports test
+if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "amd64" ]
+then
+ . ./sha256.sh
+ # Verify that the resulting file works
+ ./test/results/test0025-amd64-binary > test/test0025/proof || exit 4
+ out=$(sha256_check test/test0025/proof.answer)
+ [ "$out" = "test/test0025/proof: OK" ] || exit 5
+fi
+exit 0
diff --git a/test/test0025/hello-armv7l.sh b/test/test0025/hello-armv7l.sh
new file mode 100755
index 0000000..edce747
--- /dev/null
+++ b/test/test0025/hello-armv7l.sh
@@ -0,0 +1,61 @@
+#! /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 -ex
+# Build the test
+bin/M2-Planet --architecture armv7l \
+ -f M2libc/armv7l/Linux/unistd.h \
+ -f M2libc/stdlib.c \
+ -f M2libc/armv7l/Linux/fcntl.h \
+ -f M2libc/stdio.c \
+ -f test/test0025/array.c \
+ --debug \
+ -o test/test0025/array.M1 || exit 1
+
+# Build debug footer
+blood-elf -f test/test0025/array.M1 \
+ --entry _start \
+ -o test/test0025/array-footer.M1 || exit 2
+
+# Macro assemble with libc written in M1-Macro
+M1 -f M2libc/armv7l/armv7l_defs.M1 \
+ -f M2libc/armv7l/libc-full.M1 \
+ -f test/test0025/array.M1 \
+ -f test/test0025/array-footer.M1 \
+ --LittleEndian \
+ --architecture armv7l \
+ -o test/test0025/array.hex2 || exit 2
+
+# Resolve all linkages
+hex2 -f M2libc/armv7l/ELF-armv7l-debug.hex2 \
+ -f test/test0025/array.hex2 \
+ --LittleEndian \
+ --architecture armv7l \
+ --BaseAddress 0x400000 \
+ -o test/results/test0025-armv7l-binary \
+ --exec_enable || exit 3
+
+# Ensure binary works if host machine supports test
+if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "armv7l" ]
+then
+ . ./sha256.sh
+ # Verify that the resulting file works
+ ./test/results/test0025-armv7l-binary > test/test0025/proof || exit 4
+ out=$(sha256_check test/test0025/proof.answer)
+ [ "$out" = "test/test0025/proof: OK" ] || exit 5
+fi
+exit 0
diff --git a/test/test0025/hello-x86.sh b/test/test0025/hello-x86.sh
new file mode 100755
index 0000000..b4bbd25
--- /dev/null
+++ b/test/test0025/hello-x86.sh
@@ -0,0 +1,61 @@
+#! /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 -ex
+# Build the test
+bin/M2-Planet --architecture x86 \
+ -f M2libc/x86/Linux/unistd.h \
+ -f M2libc/stdlib.c \
+ -f M2libc/x86/Linux/fcntl.h \
+ -f M2libc/stdio.c \
+ -f test/test0025/array.c \
+ --debug \
+ -o test/test0025/array.M1 || exit 1
+
+# Build debug footer
+blood-elf --64 -f test/test0025/array.M1 \
+ --entry _start \
+ -o test/test0025/array-footer.M1 || exit 2
+
+# Macro assemble with libc written in M1-Macro
+M1 -f M2libc/x86/x86_defs.M1 \
+ -f M2libc/x86/libc-full.M1 \
+ -f test/test0025/array.M1 \
+ -f test/test0025/array-footer.M1 \
+ --LittleEndian \
+ --architecture x86 \
+ -o test/test0025/array.hex2 || exit 2
+
+# Resolve all linkages
+hex2 -f M2libc/x86/ELF-i386-debug.hex2 \
+ -f test/test0025/array.hex2 \
+ --LittleEndian \
+ --architecture x86 \
+ --BaseAddress 0x400000 \
+ -o test/results/test0025-x86-binary \
+ --exec_enable || exit 3
+
+# Ensure binary works if host machine supports test
+if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ]
+then
+ . ./sha256.sh
+ # Verify that the resulting file works
+ ./test/results/test0025-x86-binary > test/test0025/proof || exit 4
+ out=$(sha256_check test/test0025/proof.answer)
+ [ "$out" = "test/test0025/proof: OK" ] || exit 5
+fi
+exit 0
diff --git a/test/test0025/input b/test/test0025/input
new file mode 100644
index 0000000..e789cec
--- /dev/null
+++ b/test/test0025/input
@@ -0,0 +1 @@
+3.141592653589793238462643383279502884197169399375105820974944592307816406286 208998628034825342117067982148086513282306647093844609550582231725359408128481 117450284102701938521105559644622948954930381964428810975665933446128475648233 786783165271201909145648566923460348610454326648213393607260249141273724587006 606315588174881520920962829254091715364367892590360011330530548820466521384146 951941511609433057270365759591953092186117381932611793105118548074462379962749 567351885752724891227938183011949129833673362440656643086021394946395224737190 702179860943702770539217176293176752384674818467669405132000568127145263560827
diff --git a/test/test0025/proof.answer b/test/test0025/proof.answer
new file mode 100644
index 0000000..f0fd60b
--- /dev/null
+++ b/test/test0025/proof.answer
@@ -0,0 +1 @@
+e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 test/test0025/proof
diff --git a/test/test1000/proof.answer b/test/test1000/proof.answer
index cdc7f22..1030624 100644
--- a/test/test1000/proof.answer
+++ b/test/test1000/proof.answer
@@ -1 +1 @@
-61dde3b8a913296de7da40208428ff28ff741908ea9e98c7856626b19666288f test/test1000/proof
+612c951c26337ca96dfcf50ccf79b9e94e9f3b083500d5897b4b7cdc66acbb6e test/test1000/proof