]> git.mdlowis.com Git - proto/obnc.git/commitdiff
reorganized folder strcuture to allow fo rmultipl backends
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 28 Apr 2021 15:17:52 +0000 (11:17 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 28 Apr 2021 15:17:52 +0000 (11:17 -0400)
13 files changed:
cerise/backend/test/codegen.c [new file with mode: 0644]
cerise/backend/x86_64/codegen.c [moved from cerise/codegen.c with 98% similarity]
cerise/build.sh
cerise/examples/generate.sh
cerise/examples/operators.c [new file with mode: 0644]
cerise/inc/atf.h [moved from cerise/atf.h with 100% similarity]
cerise/inc/cerise.h [moved from cerise/cerise.h with 100% similarity]
cerise/src/const_ops.c [moved from cerise/const_ops.c with 100% similarity]
cerise/src/emalloc.c [moved from cerise/emalloc.c with 100% similarity]
cerise/src/lex.c [moved from cerise/lex.c with 100% similarity]
cerise/src/main.c [moved from cerise/main.c with 100% similarity]
cerise/src/parser.c [moved from cerise/parser.c with 100% similarity]
cerise/value [deleted file]

diff --git a/cerise/backend/test/codegen.c b/cerise/backend/test/codegen.c
new file mode 100644 (file)
index 0000000..b52c404
--- /dev/null
@@ -0,0 +1,87 @@
+#include "cerise.h"
+#include <limits.h>
+#include <assert.h>
+
+Type BoolType = {
+    .form = FORM_BOOL,
+    .size = sizeof(bool)
+};
+
+Type IntType = {
+    .form = FORM_INT,
+    .size = sizeof(long)
+};
+
+Type RealType = {
+    .form = FORM_REAL,
+    .size = sizeof(double)
+};
+
+Type StringType = {
+    .form = FORM_STRING,
+    .size = -1
+};
+
+void codegen_setint(Item* item, Type* type, long long val)
+{
+    item->mode  = ITEM_CONST;
+    item->type  = type;
+    item->reg   = 0;
+    item->imm.i = val;
+}
+
+void codegen_setreal(Item* item, double val)
+{
+    item->mode  = ITEM_CONST;
+    item->type  = &RealType;
+    item->reg   = 0;
+    item->imm.f = val;
+}
+
+void codegen_setstr(Item* item, char* val)
+{
+    item->mode  = ITEM_CONST;
+    item->type  = &StringType;
+    item->reg   = 0;
+    item->imm.s = val;
+}
+
+void codegen_imports(Parser* p)
+{
+    (void)p;
+}
+
+void codegen_global(Parser* p, char* name, Type* type)
+{
+    (void)p, (void)name, (void)type;
+}
+
+void codegen_main(Parser* p)
+{
+    (void)p;
+}
+
+void codegen_startproc(Parser* p, char* name, long long localsz)
+{
+    (void)p, (void)name, (void)localsz;
+}
+
+void codegen_endproc(Parser* p)
+{
+    (void)p;
+}
+
+void codegen_unop(Parser* p, int op, Item* a)
+{
+    (void)p, (void)op, (void)a;
+}
+
+void codegen_binop(Parser* p, int op, Item* a, Item* b)
+{
+    (void)p, (void)op, (void)a, (void)b;
+}
+
+void codegen_store(Parser* p, Item* a, Item* b)
+{
+    (void)p, (void)a, (void)b;
+}
similarity index 98%
rename from cerise/codegen.c
rename to cerise/backend/x86_64/codegen.c
index 4997696d6ef70c38f742c2bd952a37a317084f73..ee68ad40e2ace8d608dac9126cfc3133f8f958b8 100644 (file)
@@ -198,10 +198,6 @@ static void load_var(Parser* p, Item* item)
             break;
 
         case ITEM_MVAR:
-//            puts("MVAR");
-//            printf("movq %s, $%lld\n", curr_regname(p), item->imm.i);
-//    item_dump(item);
-
             printf("    movq    %s_%s(%%rip), %s\n",
                 p->name,
                 item->imm.s,
index 65e385fda6c111ac4a3688ff19c739cc661e596e..55e276527d26532740dd9f20af9037d64c8a64bd 100755 (executable)
@@ -1,7 +1,12 @@
 #!/bin/sh
+
+CCCMD="cc -g -Wall -Wextra --std=c99 -Iinc/"
+BACKEND=backend/x86_64
+TEST_BACKEND=backend/test
+
 ctags -R &
-cc -g -D CERISE_TESTS -Wall -Wextra --std=c99 -o cerisec-test *.c \
-  && cc -g -Wall -Wextra --std=c99 -o cerisec *.c \
+$CCCMD -D CERISE_TESTS -o cerisec-test src/*.c "$TEST_BACKEND"/*.c \
+  && $CCCMD -o cerisec src/*.c "$BACKEND"/*.c \
   && ./cerisec-test \
   && ./cerisec tests/Module.m | tee tests/Module.s \
   && cc -o Module tests/Module.s
index bd87e1ed5e343687e6216f00b54c642ade571666..48491de02484b29ba8cbc3f1a5643a1bcba351e6 100755 (executable)
@@ -1,2 +1,2 @@
 #!/bin/sh
-cc -c -S -o - "$@" | sed -e 's/^\s*\.globl.*$/\n\n&/'
+cc -fomit-frame-pointer -c -S -o - "$@" | sed -e 's/^\s*\.globl.*$/\n\n&/' | grep -v '\.cfi' | less
diff --git a/cerise/examples/operators.c b/cerise/examples/operators.c
new file mode 100644 (file)
index 0000000..c9cdbf6
--- /dev/null
@@ -0,0 +1,29 @@
+long A, B;
+
+void pos(void)  { A = +A;  }
+void neg(void)  { A = -A; }
+
+void inc(void)  { A++; }
+void dec(void)  { A--; }
+
+void add(void)  { A = A + B; }
+void sub(void)  { A = A - B; }
+void mul(void)  { A = A * B; }
+void div(void)  { A = A / B; }
+void mod(void)  { A = A % B; }
+
+void eq(void)   { A = A == B; }
+void neq(void)  { A = A != B; }
+void lt(void)   { A = A < B;  }
+void lte(void)  { A = A <= B; }
+void gt(void)   { A = A > B;  }
+void gte(void)  { A = A >= B; }
+
+void shr(void)  { A = A >> B; }
+void shl(void)  { A = A << B; }
+
+void band(void) { A = A & B; }
+void bor(void)  { A = A | B; }
+void bnot(void) { A = ~A;    }
+void bxor(void) { A = A ^ B; }
+
similarity index 100%
rename from cerise/atf.h
rename to cerise/inc/atf.h
similarity index 100%
rename from cerise/cerise.h
rename to cerise/inc/cerise.h
similarity index 100%
rename from cerise/const_ops.c
rename to cerise/src/const_ops.c
similarity index 100%
rename from cerise/emalloc.c
rename to cerise/src/emalloc.c
similarity index 100%
rename from cerise/lex.c
rename to cerise/src/lex.c
similarity index 100%
rename from cerise/main.c
rename to cerise/src/main.c
similarity index 100%
rename from cerise/parser.c
rename to cerise/src/parser.c
diff --git a/cerise/value b/cerise/value
deleted file mode 100644 (file)
index e69de29..0000000