]> git.mdlowis.com Git - proto/obnc.git/commitdiff
partial fix-up of array access. Need to generate index calculations
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 28 May 2021 18:21:26 +0000 (14:21 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 28 May 2021 18:21:26 +0000 (14:21 -0400)
cerise/TODO.md
cerise/backend/c99/codegen.c
cerise/inc/cerise.h
cerise/tests/Module.m

index e7a684c617188558ccad2068b461b23ca76e8f38..ec0cbf38d05605087474eff9d3f896d6ba340886 100644 (file)
@@ -1,10 +1,10 @@
 # Doing
 
-* Cleanup the lexer
+* Fix array access in structs
 
 # Up Next
 
-* Fix array access in structs
+* Implement symbol file generation and import
 * Implement module scoped identifiers
 * Implement an SSA backend
 * Implement pointers
@@ -13,6 +13,7 @@
 
 # Backlog
 
+* Cleanup the lexer
 * Implement record extension
 * Implement logical operators: and, or, not
 * Implement string types
index 71378b153b402054f9ea665449b850593472e7c6..b16c4899e44de3f253f18e836ce2ae6b2ad4a3f6 100644 (file)
@@ -92,12 +92,13 @@ static void make_var(Parser* p, Symbol* sym, int isref)
     if (sym->type->form == FORM_ARRAY)
     {
         Type* type = sym->type;
-        for (; type->form == FORM_ARRAY; type = type->base);
-        printf("%s %s", TypeNames[type->form], name);
-        for (type = sym->type; type->form == FORM_ARRAY; type = type->base)
+        long size = 1;
+        for (; type->form == FORM_ARRAY; type = type->base)
         {
-            printf("[%d]", type->size);
+            size = size * type->size;
         }
+        size = size * type->size;
+        printf("Byte %s[%ld]", name, size);
     }
     else if (sym->type->form == FORM_RECORD)
     {
@@ -128,7 +129,7 @@ static int declare_temp(Parser* p, Type* type, int isref)
         .name = name,
         .type = type,
     };
-    if (type->form == FORM_RECORD)
+    if ((type->form == FORM_RECORD) || (type->form == FORM_ARRAY))
     {
         printf("    Byte* %s", name);
     }
@@ -440,9 +441,8 @@ void codegen_return(Parser* p, Item* item)
 
 void codegen_index(Parser* p, Item* array, Item* index)
 {
-    /* load  array and index if not already */
-    load_var(p, index);
     load_var(p, array);
+    load_var(p, index);
 
     /* perform range checking */
     if (index->mode == ITEM_CONST)
@@ -465,12 +465,13 @@ void codegen_index(Parser* p, Item* array, Item* index)
         printf("    __CHECK_RANGE(%s < %d);\n", temp(index), array->type->size);
     }
 
-    /* emit the operation */
+    /* emit the operation to calculate offset */
     array->type = array->type->base;
     array->mode = ITEM_INDEX;
-    int dest_reg = declare_temp(p, array->type, 1);
-    printf(" = &%s[%s];\n", temp(array), temp(index));
-    array->reg = dest_reg;
+
+//    int dest_reg = declare_temp(p, array->type, 1);
+//    printf(" = &%s[%s];\n", temp(array), temp(index));
+//    array->reg = dest_reg;
 }
 
 Field* get_field(Parser* p, Type* type, char* name)
index 941562ffeec443dca49971cf31ac9630327999c6..ffc7439f92eae92b4d6efd0f25eae7f05bc88305 100644 (file)
@@ -246,6 +246,11 @@ typedef struct {
     Operation** ops;
 } Block;
 
+/* <op> <reg>, <base>+<off> */
+/* <op> <base>+<off>, <reg> */
+/* <op> <reg>, <reg> */
+/* <op> <reg>, <reg>, <reg> */
+
 /*
 
 typedef struct AnfNode {
index 4421a0f6f9f1e9544f264ea58e1c3032b69c32ea..ebf4627d7b60638c1f8cf37c2c3c8c5dedee36eb 100644 (file)
@@ -27,6 +27,7 @@ var
   d : Real
   e : array 5 of array 10 of Int
   f : TypeD
+  g : array 5 of Int
 
 procedure Foo*(e : Int, z : Int, q1 : TypeD, q2 : array 5 of Int) : Int
   const FOO = 2
@@ -113,6 +114,8 @@ begin
 #    e[1][2] = 1;
 #    c = e[1][c];
 #  c = f.dim.w;
-  f.dim.h = 0;
-  f.label[0] = 42;
+#  f.dim.h = 0;
+#  f.label[0] = 42;
+
+    g[1] = 42;
 end