]> git.mdlowis.com Git - proto/obnc.git/commitdiff
added runtime stubs and added it to the link step. The link step is silently failing...
authorMike Lowis <mike.lowis@gentex.com>
Wed, 30 Aug 2023 16:36:07 +0000 (12:36 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Wed, 30 Aug 2023 16:36:07 +0000 (12:36 -0400)
cerise/.gitignore [new file with mode: 0644]
cerise/backend/ssa/codegen.c
cerise/build.sh
cerise/runtime/addref.c [new file with mode: 0644]
cerise/runtime/allocate.c [new file with mode: 0644]
cerise/runtime/deallocate.c [new file with mode: 0644]
cerise/runtime/delref.c [new file with mode: 0644]
cerise/runtime/retref.c [new file with mode: 0644]
cerise/src/grammar.c

diff --git a/cerise/.gitignore b/cerise/.gitignore
new file mode 100644 (file)
index 0000000..4396af6
--- /dev/null
@@ -0,0 +1,3 @@
+*.l
+*.a
+*.o
\ No newline at end of file
index ba0df9ba0ee4ea3c011ed1e2c66a9601f09fef89..6230d40883bee7d22db3fc45f2823e57689ec9e5 100644 (file)
@@ -119,52 +119,9 @@ void codegen_init(Parser* p)
     fout(p, "%%String = type i8*\n");
     fout(p, "declare ptr @allocate(i64)\n");
     fout(p, "declare void @deallocate(ptr)\n");
-    fout(p,
-        "%%obj.header.t = type { i64 }"
-        "\n"
-        "define private void @addref(ptr %%0) {\n"
-        "  %%2 = icmp eq ptr %%0, null\n"
-        "  br i1 %%2, label %%7, label %%3\n"
-        "3:\n"
-        "  %%4 = getelementptr inbounds %%obj.header.t, ptr %%0, i64 -1\n"
-        "  %%5 = load i64, ptr %%4, align 8\n"
-        "  %%6 = add nsw i64 %%5, 1\n"
-        "  store i64 %%6, ptr %%4, align 8\n"
-        "  br label %%7\n"
-        "7:\n"
-        "  ret void\n"
-        "}\n"
-        "\n"
-        "define private void @delref(ptr %%0) {\n"
-        "  %%2 = icmp eq ptr %%0, null\n"
-        "  br i1 %%2, label %%9, label %%3\n"
-        "3:\n"
-        "  %%4 = getelementptr inbounds %%obj.header.t, ptr %%0, i64 -1\n"
-        "  %%5 = load i64, ptr %%4, align 8\n"
-        "  %%6 = add nsw i64 %%5, -1\n"
-        "  store i64 %%6, ptr %%4, align 8\n"
-        "  %%7 = icmp eq i64 %%6, 0\n"
-        "  br i1 %%7, label %%8, label %%9\n"
-        "8:\n"
-        "  tail call void @deallocate(ptr %%0) #4\n"
-        "  br label %%9\n"
-        "9:\n"
-        "  ret void\n"
-        "}\n"
-        "\n"
-        "define private void @retref(ptr %%0) {\n"
-        "  %%2 = icmp eq ptr %%0, null\n"
-        "  br i1 %%2, label %%7, label %%3\n"
-        "3:\n"
-        "  %%4 = getelementptr inbounds %%obj.header.t, ptr %%0, i64 -1\n"
-        "  %%5 = load i64, ptr %%4, align 8\n"
-        "  %%6 = add nsw i64 %%5, -1\n"
-        "  store i64 %%6, ptr %%4, align 8\n"
-        "  br label %%7\n"
-        "7:\n"
-        "  ret void\n"
-        "}\n"
-    );
+    fout(p, "declare void @addref(ptr %%0);\n");
+    fout(p, "declare void @delref(ptr %%0);\n");
+    fout(p, "declare void @retref(ptr %%0);\n");
 }
 
 void codegen_symbol(Parser* p, Symbol* sym)
index 5f2543504347bf5a70695eb05bb704075a1c0a73..eb6c105d3c8e4b96399d156f267abe2b6f09f68a 100755 (executable)
@@ -7,6 +7,12 @@ TEST_BACKEND=backend/test
 ctags -R &
 grep -rh TODO src/*.* backend/*/*.* | sed -E -e 's/ *\/\/ *//' -e 's/ *\/\* *(.*) *\*\//\1/'
 
+# Build the runtime library
+for src in runtime/*.c; do
+  clang -c -Wall -Werror -Wextra -o "${src%.c}.o" "$src"
+done
+ar -rc libcerise.a runtime/*.o
+
 # Now build and test it
 $CCCMD -o cerisec src/*.c "backend/ssa"/*.c \
 && ./cerisec tests/Module.m \
diff --git a/cerise/runtime/addref.c b/cerise/runtime/addref.c
new file mode 100644 (file)
index 0000000..b350fb2
--- /dev/null
@@ -0,0 +1,4 @@
+void addref(void* ptr)
+{
+    (void)ptr;
+}
diff --git a/cerise/runtime/allocate.c b/cerise/runtime/allocate.c
new file mode 100644 (file)
index 0000000..d23f6b0
--- /dev/null
@@ -0,0 +1,7 @@
+#include <stdint.h>
+
+void* allocate(int64_t sz)
+{
+    (void)sz;
+    return (void*)0;
+}
\ No newline at end of file
diff --git a/cerise/runtime/deallocate.c b/cerise/runtime/deallocate.c
new file mode 100644 (file)
index 0000000..626de3d
--- /dev/null
@@ -0,0 +1,4 @@
+void deallocate(void* ptr)
+{
+    (void)ptr;
+}
diff --git a/cerise/runtime/delref.c b/cerise/runtime/delref.c
new file mode 100644 (file)
index 0000000..fc7dd42
--- /dev/null
@@ -0,0 +1,4 @@
+void delref(void* ptr)
+{
+    (void)ptr;
+}
diff --git a/cerise/runtime/retref.c b/cerise/runtime/retref.c
new file mode 100644 (file)
index 0000000..c3ef9c9
--- /dev/null
@@ -0,0 +1,4 @@
+void retref(void* ptr)
+{
+    (void)ptr;
+}
index 77da701876332b6439c07f27044967d1e1739a67..fde350f908035b855b6fb4870023229917581977 100644 (file)
@@ -869,7 +869,7 @@ void compile(char* path)
 {
     Parser p = {0};
     compile_module(&p, path, true);
-    char* link_cmd = strmcat("clang -static -o ", p.name, " ", 0);
+    char* link_cmd = strmcat("clang -static -g -o ", p.name, " ", 0);
     for (size_t i = 0; i < p.nmods; i++)
     {
         if (!p.mods[i].path) continue;
@@ -879,7 +879,7 @@ void compile(char* path)
     }
     char* object = strdup(p.outpath);
     object[strlen(object)-1] = 'o';
-    link_cmd = strmcat(link_cmd, "\"", object, "\" ", "-lm", 0);
+    link_cmd = strmcat(link_cmd, "\"", object, "\" ", "-L. ", "-lm ", "-lcerise", 0);
     puts(link_cmd);
     if (system(link_cmd) != 0)
     {