scc: support processors that support stack relative addressing
authorAlan Cox <alan@linux.intel.com>
Thu, 30 Jun 2016 17:00:29 +0000 (18:00 +0100)
committerAlan Cox <alan@linux.intel.com>
Thu, 30 Jun 2016 17:00:29 +0000 (18:00 +0100)
Also fix LSTATIC to be more efficient

Applications/SmallC/code6801.c
Applications/SmallC/code6809.c
Applications/SmallC/code8080.c
Applications/SmallC/codegeneric.c
Applications/SmallC/codez80.c
Applications/SmallC/primary.c
Applications/SmallC/prototype.h

index eb715f6..4668832 100644 (file)
@@ -210,6 +210,16 @@ void gen_get_indirect(char typeobj, int reg) {
     }
 }
 
+/**
+ * platform level analysis of whether a symbol access needs to be
+ * direct or indirect (globals are always direct)
+ */
+int gen_indirected(SYMBOL *s)
+{
+    /* TODO */
+    return 1;
+}
+
 /**
  * swap the primary and secondary registers
  */
index f6eddb4..948b958 100644 (file)
@@ -119,6 +119,18 @@ void output_immediate(int num) {
     output_decimal(num);
 }
 
+static void describe_access(SYMBOL *sym)
+{
+    if (sym->storage == LSTATIC)
+        print_label(sym->offset);
+    else if (sym->storage == AUTO || sym->storage == DEFAUTO) {
+        output_number(sym->offset - stkp);
+        output_string(",s");
+    } else
+        output_string(sym->name);
+    newline();
+}
+
 /**
  * fetch a static memory cell into the primary register
  * @param sym
@@ -126,18 +138,15 @@ void output_immediate(int num) {
 void gen_get_memory(SYMBOL *sym) {
     if ((sym->identity != POINTER) && (sym->type == CCHAR)) {
         output_with_tab("ldb ");
-        output_string(sym->name);
-        newline ();
+        describe_access(sym);
         output_line("sex");
     } else if ((sym->identity != POINTER) && (sym->type == UCHAR)) {
         output_with_tab("ldb ");
-        output_string(sym->name);
-        newline();
+        describe_access(sym);
         output_line("clr a");
     } else {
         output_with_tab ("ldd ");
-        output_string(sym->name);
-        newline ();
+        describe_access(sym);
     }
 }
 
@@ -167,14 +176,11 @@ int gen_get_locale(SYMBOL *sym) {
  * @param sym
  */
 void gen_put_memory(SYMBOL *sym) {
-    if ((sym->identity != POINTER) && (sym->type & CCHAR)) {
+    if ((sym->identity != POINTER) && (sym->type & CCHAR))
         output_with_tab ("stb ");
-        output_string(sym->name);
-    } else {
+    else
         output_with_tab("std ");
-        output_string(sym->name);
-    }
-    newline ();
+    describe_access(sym);
 }
 
 /**
@@ -217,6 +223,16 @@ void gen_get_indirect(char typeobj, int reg) {
     }
 }
 
+/**
+ * platform level analysis of whether a symbol access needs to be
+ * direct or indirect (globals are always direct)
+ */
+int gen_indirected(SYMBOL *s)
+{
+    /* Never indirect, use s relative because our CPU rocks */
+    return 0;
+}
+
 /**
  * swap the primary and secondary registers
  */
index a603b20..9562075 100644 (file)
@@ -238,6 +238,17 @@ void gen_get_indirect(char typeobj, int reg) {
     }
 }
 
+/**
+ * platform level analysis of whether a symbol access needs to be
+ * direct or indirect (globals are always direct)
+ */
+int gen_indirected(SYMBOL *s)
+{
+    /* FIXME: TODO - we can avoid indirecting LSTATIC */
+    return 1;
+}
+
+
 /**
  * swap the primary and secondary registers
  */
index c6306e9..9a4f856 100644 (file)
@@ -128,24 +128,32 @@ static void output_bracketed(char *p)
     output_byte(')');
 }
 
+static void describe_access(SYMBOL *sym)
+{
+    output_byte('(');
+    if (sym->storage == LSTATIC) {
+        print_label(sym->offset);
+    } else if (sym->storage == AUTO || sym->storage == DEFAUTO) {
+        output_number(sym->offset);
+        output_string("+fp");
+    } else
+        output_string(sym->name);
+    output_byte(')');
+    newline();
+}
+
 /**
  * fetch a static memory cell into the primary register
  * @param sym
  */
 void gen_get_memory(SYMBOL *sym) {
-    if ((sym->identity != POINTER) && (sym->type == CCHAR)) {
+    if ((sym->identity != POINTER) && (sym->type == CCHAR))
         output_with_tab ("loadsb r1 ");
-        output_bracketed(sym->name);
-        newline ();
-    } else if ((sym->identity != POINTER) && (sym->type == UCHAR)) {
+    else if ((sym->identity != POINTER) && (sym->type == UCHAR))
         output_with_tab("loadub r1 ");
-        output_bracketed(sym->name);
-        newline();
-    } else {
+    else
         output_with_tab ("load r1 ");
-        output_bracketed(sym->name);
-        newline ();
-    }
+    describe_access(sym);
 }
 
 /**
@@ -173,14 +181,11 @@ int gen_get_locale(SYMBOL *sym) {
  * @param sym
  */
 void gen_put_memory(SYMBOL *sym) {
-    if ((sym->identity != POINTER) && (sym->type & CCHAR)) {
+    if ((sym->identity != POINTER) && (sym->type & CCHAR))
         output_with_tab ("storeb r1 ");
-        output_bracketed(sym->name);
-    } else {
+    else
         output_with_tab("store r1 ");
-        output_bracketed(sym->name);
-    }
-    newline ();
+    describe_access(sym);
 }
 
 /**
@@ -220,6 +225,15 @@ void gen_get_indirect(char typeobj, int reg) {
     }
 }
 
+/**
+ * platform level analysis of whether a symbol access needs to be
+ * direct or indirect (globals are always direct)
+ */
+int gen_indirected(SYMBOL *s)
+{
+    return 0;
+}
+
 /**
  * swap the primary and secondary registers
  */
index cb76fd2..f4c12bd 100644 (file)
@@ -115,6 +115,14 @@ void output_number(int num) {
     output_decimal(num);
 }
 
+static void output_number_signed(int num)
+{
+    if (num > 0)
+        output_byte('+');
+    else
+        output_decimal(num);
+}
+
 static void output_bracketed(char *p)
 {
     output_byte('(');
@@ -122,6 +130,22 @@ static void output_bracketed(char *p)
     output_byte(')');
 }
 
+static void describe_access(SYMBOL *sym)
+{
+    if (sym->storage == LSTATIC) {
+        output_byte('(');
+        print_label(sym->offset);
+        output_byte(')');
+    } else if (sym->storage == AUTO || sym->storage == DEFAUTO) {
+        output_string("(ix");
+        output_number_signed(sym->offset - stkp);
+        output_byte(')');
+    } else
+        output_string(sym->name);
+    newline();
+}
+
+
 /**
  * fetch a static memory cell into the primary register
  * @param sym
@@ -227,6 +251,19 @@ void gen_get_indirect(char typeobj, int reg) {
     }
 }
 
+/**
+ * platform level analysis of whether a symbol access needs to be
+ * direct or indirect (globals are always direct)
+ */
+int gen_indirected(SYMBOL *s)
+{
+    if (s->storage == LSTATIC)
+        return 0;
+/*    if (abs(s->offset) < 124 && (s->type == CCHAR || s->type == UCHAR))
+        return 0; */
+    return 1;
+}
+
 /**
  * swap the primary and secondary registers
  */
index 7f0afb2..3c802dd 100644 (file)
@@ -50,8 +50,26 @@ int primary(LVALUE *lval) {
         return(0);
     }
     if (symname (sname)) {
-        if ((symbol_table_idx = find_locale(sname)) > -1) {
-            symbol = &symbol_table[symbol_table_idx];
+        int local = 1;
+        symbol_table_idx = find_locale(sname);
+        if (symbol_table_idx == -1) {
+            local = 0;
+            symbol_table_idx = find_global(sname);
+            /* Only valid undeclared name is a function reference */
+            if (symbol_table_idx == -1) {
+                blanks();
+                if (ch() != '(')
+                    error("undeclared variable");
+                symbol_table_idx = add_global(sname, FUNCTION, CINT, 0, PUBLIC);
+                symbol = &symbol_table[symbol_table_idx];
+                lval->symbol = symbol;
+                lval->indirect = 0;
+                return 0;
+            }
+        }
+        symbol = &symbol_table[symbol_table_idx];
+
+        if (local && gen_indirected(symbol)) {
             reg = gen_get_locale(symbol);
             lval->symbol = symbol;
             lval->indirect = symbol->type;
@@ -69,37 +87,32 @@ int primary(LVALUE *lval) {
             }
             return FETCH | reg;
         }
-        if ((symbol_table_idx = find_global(sname)) > -1) {
-            symbol = &symbol_table[symbol_table_idx];
-            if (symbol->identity != FUNCTION) {
-                lval->symbol = symbol;
-                lval->indirect = 0;
-                if (symbol->type == STRUCT) {
-                    lval->tagsym = &tag_table[symbol->tagidx];
-                }
-                if (symbol->identity != ARRAY &&
-                    (symbol->identity != VARIABLE || symbol->type != STRUCT)) {
-                    if (symbol->identity == POINTER) {
-                        lval->ptr_type = symbol->type;
-                    }
-                    return FETCH | HL_REG;
+        /* Globals and anything we can directly access */
+        if (symbol->identity != FUNCTION) {
+            lval->symbol = symbol;
+            lval->indirect = 0;
+            if (symbol->type == STRUCT) {
+                lval->tagsym = &tag_table[symbol->tagidx];
+            }
+            if (symbol->identity != ARRAY &&
+                (symbol->identity != VARIABLE || symbol->type != STRUCT)) {
+                if (symbol->identity == POINTER) {
+                    lval->ptr_type = symbol->type;
                 }
+                return FETCH | HL_REG;
+            }
+
+            if (symbol->storage == LSTATIC)
+                gen_get_locale(symbol);
+            else {
                 gen_immediate();
                 output_string(symbol->name);
                 newline();
-                lval->indirect = symbol->type;
-                lval->ptr_type = symbol->type;
-                return 0;
             }
+            lval->indirect = symbol->type;
+            lval->ptr_type = symbol->type;
+            return 0;
         }
-        blanks();
-        if (ch() != '(')
-            error("undeclared variable");
-        symbol_table_idx = add_global(sname, FUNCTION, CINT, 0, PUBLIC);
-        symbol = &symbol_table[symbol_table_idx];
-        lval->symbol = symbol;
-        lval->indirect = 0;
-        return 0;
     }
     lval->symbol = 0;
     lval->indirect = 0;
index 3659188..e65c301 100644 (file)
@@ -13,6 +13,7 @@ extern void output_number(int num);
 extern void gen_get_memory(SYMBOL *sym);
 extern int gen_get_locale(SYMBOL *sym);
 extern void gen_put_memory(SYMBOL *sym);
+extern int gen_indirected(SYMBOL *sym);
 extern void gen_put_indirect(char typeobj);
 extern void gen_get_indirect(char typeobj, int reg);
 extern void gen_swap(void);