]> git.mdlowis.com Git - proto/obnc.git/commitdiff
eliminated the stdlib master
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 31 Aug 2023 03:12:34 +0000 (23:12 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 31 Aug 2023 03:12:34 +0000 (23:12 -0400)
cerise/.gitignore
cerise/build.sh
cerise/inc/cerise.h
cerise/runtime/_start.c [new file with mode: 0644]
cerise/src/grammar.c
cerise/tests/A.m
cerise/tests/Module.m

index 4396af645588ae4cf722aeb74cc284e72fa02bd7..924a66b6f6281dfedb8174ac8db4a18f9f704515 100644 (file)
@@ -1,3 +1,4 @@
 *.l
 *.a
-*.o
\ No newline at end of file
+*.o
+Module
index eb6c105d3c8e4b96399d156f267abe2b6f09f68a..c84504518b84cafb1dbeb3fff7d337d803615338 100755 (executable)
@@ -17,5 +17,3 @@ ar -rc libcerise.a runtime/*.o
 $CCCMD -o cerisec src/*.c "backend/ssa"/*.c \
 && ./cerisec tests/Module.m \
 
-rm -f Module
-
index f1d62fd551481b6717b4b2be2f216a88435fd7f3..2f18c435d801d486ca9fba8e8c86416763e8e437 100644 (file)
@@ -243,6 +243,7 @@ typedef struct {
     Module* mods;
 
     bool genmain;
+    bool dirty;
 } Parser;
 
 // src/stdlib.c
diff --git a/cerise/runtime/_start.c b/cerise/runtime/_start.c
new file mode 100644 (file)
index 0000000..41a279c
--- /dev/null
@@ -0,0 +1,12 @@
+extern int main();
+
+__asm (
+    ".global _start\n"
+    "_start:\n"
+    "   movl  (%rsp), %edi\n"
+    "   lea   8(%rsp), %rsi\n"
+    "   call  main\n"
+    "   movl  %eax, %edi\n"
+    "   movl  $60, %eax\n"
+    "   syscall\n"
+);
index fde350f908035b855b6fb4870023229917581977..cf993b06468786683904dbfd2f9854458bdcec5d 100644 (file)
@@ -768,9 +768,9 @@ static void init_parser(Parser* p, char* path, bool genmain)
     symbol_new(p, 0, "String", SYM_TYPE, 0)->type = &StringType;
 }
 
-static void compile_module(Parser* p, char* path, bool genmain)
+static bool compile_module(Parser* p, char* path, bool genmain)
 {
-    /* parser the file and generate the code */
+    /* parse the file and generate the code */
     init_parser(p, path, genmain);
     codegen_init(p);
     module(p);
@@ -778,7 +778,8 @@ static void compile_module(Parser* p, char* path, bool genmain)
 
     char* asm_path = get_fpath(path, 's');
     char* obj_path = get_fpath(path, 'o');
-    if (fs_modtime(obj_path) < fs_modtime(path))
+    bool dirty = fs_modtime(obj_path) < fs_modtime(path);
+    if (p->dirty || dirty)
     {
         /* run llc to generate assembly listing */
         char* llc_cmd = strmcat("llc -opaque-pointers -o \"", asm_path , "\" \"", p->outpath, "\"", 0);
@@ -790,7 +791,7 @@ static void compile_module(Parser* p, char* path, bool genmain)
 //        remove(p->outpath);
 
         /* compile the object file now */
-        char* as_cmd = strmcat("clang -static -c -o \"", obj_path, "\" \"", asm_path, "\"", 0);
+        char* as_cmd = strmcat("clang -nostdlib -flto -static -O2 -c -o \"", obj_path, "\" \"", asm_path, "\"", 0);
         printf("%s\n", as_cmd);
         if (system(as_cmd) != 0)
         {
@@ -798,6 +799,7 @@ static void compile_module(Parser* p, char* path, bool genmain)
         }
         remove(asm_path);
     }
+    return dirty;
 }
 
 void add_module(Parser* p, char* modname, char* modpath)
@@ -832,7 +834,7 @@ static void import(Parser* curr, char* modname, char* alias)
 
     /* parse the module */
     Parser p = {0};
-    compile_module(&p, path, false);
+    curr->dirty = compile_module(&p, path, false) || curr->dirty;
     (void)alias;
 
     /* copy module references over */
@@ -869,9 +871,10 @@ void compile(char* path)
 {
     Parser p = {0};
     compile_module(&p, path, true);
-    char* link_cmd = strmcat("clang -static -g -o ", p.name, " ", 0);
+    char* link_cmd = strmcat("clang -O2 -g -nostdlib -static -flto -o ", p.name, " ", 0);
     for (size_t i = 0; i < p.nmods; i++)
     {
+        printf("%lu: %s\n", i, p.mods[i].path);
         if (!p.mods[i].path) continue;
         char* object = strdup(p.mods[i].path);
         object[strlen(object)-1] = 'o';
@@ -879,7 +882,7 @@ void compile(char* path)
     }
     char* object = strdup(p.outpath);
     object[strlen(object)-1] = 'o';
-    link_cmd = strmcat(link_cmd, "\"", object, "\" ", "-L. ", "-lm ", "-lcerise", 0);
+    link_cmd = strmcat(link_cmd, "\"", object, "\" ", "-L. ", " ", "-lcerise", 0);
     puts(link_cmd);
     if (system(link_cmd) != 0)
     {
index bc9076dadcd43fb45ad3f12e4a09766f47b9a87a..439a85210064c527ca81fd20694a5b1a9010dc25 100644 (file)
@@ -23,5 +23,5 @@ begin
 end
 
 begin
-    Baz("abc", "def");
+#    Baz("abc", "def");
 end
\ No newline at end of file
index a70872d4f108afd31e06f01f0a9f50172ecd06a3..185f4fb1c759d958f74533ea57573f78cbd4de35 100644 (file)
@@ -121,9 +121,9 @@ begin
     vReal = 1.0 / vReal;
     vReal = vReal / vReal;
 
-    vReal = vReal % 1.0;
-    vReal = 1.0 % vReal;
-    vReal = vReal % vReal;
+#    vReal = vReal % 1.0;
+#    vReal = 1.0 % vReal;
+#    vReal = vReal % vReal;
 end
 
 procedure TestRealCompOps()