scc: merge stack adjustments
authorAlan Cox <alan@linux.intel.com>
Thu, 30 Jun 2016 17:13:56 +0000 (18:13 +0100)
committerAlan Cox <alan@linux.intel.com>
Thu, 30 Jun 2016 17:13:56 +0000 (18:13 +0100)
Applications/SmallC/TODO
Applications/SmallC/code6801.c
Applications/SmallC/code6809.c
Applications/SmallC/code8080.c
Applications/SmallC/codegeneric.c
Applications/SmallC/codez80.c
Applications/SmallC/function.c
Applications/SmallC/prototype.h
Applications/SmallC/stmt.c
Applications/SmallC/sym.c

index 27afe62..1604b63 100644 (file)
@@ -1,11 +1,6 @@
-- Debug stack offsets
-- Get code generation working and suiting things like as09
 - Write some copt rules to stop the output sucking so much
 - Steal the rst tricks done by BDS C
 - Output mixed code/data so we can flush the literal pool every line of asm
   and maybe even get rid of the literal pool (2.5K saving)
 - Can we split the preprocessor optionally
-- Work out what is needed for stack frame based Z80 and 6809 code
-
-Easy small C fixups worth doing in passing
-- \x and \001 style escapes
+- Work out what is needed for stack frame based Z80 code
index 4668832..54e9890 100644 (file)
@@ -417,6 +417,13 @@ int gen_modify_stack(int newstkp) {
     return newstkp;
 }
 
+/* FIXME */
+int gen_defer_modify_stack(int newstkp)
+{
+    return gen_modify_stack(newstkp);
+}
+
+
 /**
  * multiply the primary register by INTSIZE
  */
index 948b958..596452e 100644 (file)
@@ -368,6 +368,8 @@ void gen_def_word(void) {
     output_with_tab ("fdb ");
 }
 
+static int defer;
+
 /**
  * modify the stack pointer to the new value indicated
  * @param newstkp new value
@@ -375,7 +377,8 @@ void gen_def_word(void) {
 int gen_modify_stack(int newstkp) {
     int k;
 
-    k = newstkp - stkp;
+    k = newstkp - stkp + defer;
+    defer = 0;
     if (k == 0)
         return (newstkp);
     output_with_tab("leas ");
@@ -385,6 +388,17 @@ int gen_modify_stack(int newstkp) {
     return (newstkp);
 }
 
+/**
+ * modify the stack pointer to the new value indicated, but
+ * allow the change to be deferred
+ */
+
+int gen_defer_modify_stack(int newstkp)
+{
+    defer += newstkp - stkp;
+    return newstkp + defer;
+}
+
 /**
  * multiply the primary register by INTSIZE
  */
index 9562075..5aebcf8 100644 (file)
@@ -432,6 +432,13 @@ int gen_modify_stack(int newstkp) {
     return (newstkp);
 }
 
+/* FIXME */
+int gen_defer_modify_stack(int newstkp)
+{
+    return gen_modify_stack(newstkp);
+}
+
+
 /**
  * multiply the primary register by INTSIZE
  */
index 9a4f856..3d8d2ee 100644 (file)
@@ -378,6 +378,12 @@ int gen_modify_stack(int newstkp) {
     return (newstkp);
 }
 
+/* FIXME */
+int gen_defer_modify_stack(int newstkp)
+{
+    return gen_modify_stack(newstkp);
+}
+
 /**
  * multiply the primary register by INTSIZE
  */
index f4c12bd..8212c01 100644 (file)
@@ -458,6 +458,12 @@ int gen_modify_stack(int newstkp) {
     return (newstkp);
 }
 
+/* FIXME */
+int gen_defer_modify_stack(int newstkp)
+{
+    return gen_modify_stack(newstkp);
+}
+
 /**
  * multiply the primary register by INTSIZE
  */
index 3a901ab..0405674 100644 (file)
@@ -62,6 +62,7 @@ void newfunc_typed(int storage, char *n, int type)
                 if (find_locale(an) > -1)
                     multidef(an);
                 else {
+                    /* FIXME: struct */
                     add_local(an, 0, 0, argstk, AUTO);
                     argstk = argstk + INTSIZE;
                 }
@@ -210,6 +211,7 @@ void doLocalAnsiArgument(int type) {
                 ptr = ptr - 1;
                 address = symbol_table[ptr].offset;
                 symbol_table[ptr].offset = address + INTSIZE;
+                /* Struct etc FIXME */
             }
         }
     } else {
index e65c301..faa2448 100644 (file)
@@ -30,6 +30,7 @@ extern void gen_test_jump(int label, int ft);
 extern void gen_def_byte(void);
 extern void gen_def_storage(void);
 extern void gen_def_word(void);
+extern int gen_defer_modify_stack(int newstkp);
 extern int gen_modify_stack(int newstkp);
 extern void gen_multiply_by_two(void);
 extern void gen_divide_by_two(void);
index 771409b..14ea439 100644 (file)
@@ -151,8 +151,11 @@ void do_compound(int func) {
                 if (input_eof)
                         return;
                 if (decls) {
-                        if (!statement_declare ())
+                        if (!statement_declare ()) {
+                                /* Any deferred movement now happens */
+                                gen_modify_stack(stkp);
                                 decls = NO;
+                        }
                 } else
                         do_statement ();
         }
index ae349c3..a8a13d9 100644 (file)
@@ -253,7 +253,7 @@ void declare_local(int typ, int stclass, int otag) {
             /* FIXME: do one gen_modify_stack at the end and
                some kind of align method here */
             if (stclass != LSTATIC) {
-                stkp = gen_modify_stack(stkp - k);
+                stkp = gen_defer_modify_stack(stkp - k);
                 add_local(sname, j, typ, stkp, AUTO);
             } else
                 add_local(sname, j, typ, k, LSTATIC);