From: Mike Lowis Date: Wed, 30 Aug 2023 16:36:07 +0000 (-0400) Subject: added runtime stubs and added it to the link step. The link step is silently failing... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=a244903fa6285622267827203b680670bddde421;p=proto%2Fobnc.git added runtime stubs and added it to the link step. The link step is silently failing and needs to be debugged... --- diff --git a/cerise/.gitignore b/cerise/.gitignore new file mode 100644 index 0000000..4396af6 --- /dev/null +++ b/cerise/.gitignore @@ -0,0 +1,3 @@ +*.l +*.a +*.o \ No newline at end of file diff --git a/cerise/backend/ssa/codegen.c b/cerise/backend/ssa/codegen.c index ba0df9b..6230d40 100644 --- a/cerise/backend/ssa/codegen.c +++ b/cerise/backend/ssa/codegen.c @@ -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) diff --git a/cerise/build.sh b/cerise/build.sh index 5f25435..eb6c105 100755 --- a/cerise/build.sh +++ b/cerise/build.sh @@ -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 index 0000000..b350fb2 --- /dev/null +++ b/cerise/runtime/addref.c @@ -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 index 0000000..d23f6b0 --- /dev/null +++ b/cerise/runtime/allocate.c @@ -0,0 +1,7 @@ +#include + +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 index 0000000..626de3d --- /dev/null +++ b/cerise/runtime/deallocate.c @@ -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 index 0000000..fc7dd42 --- /dev/null +++ b/cerise/runtime/delref.c @@ -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 index 0000000..c3ef9c9 --- /dev/null +++ b/cerise/runtime/retref.c @@ -0,0 +1,4 @@ +void retref(void* ptr) +{ + (void)ptr; +} diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index 77da701..fde350f 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -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) {