SmallC: minor adjustments
authorAlan Cox <alan@linux.intel.com>
Fri, 26 Aug 2016 15:05:22 +0000 (16:05 +0100)
committerAlan Cox <alan@linux.intel.com>
Fri, 26 Aug 2016 15:05:22 +0000 (16:05 +0100)
Applications/SmallC/Makefile
Applications/SmallC/TODO
Applications/SmallC/code6801.c
Applications/SmallC/code6809.c
Applications/SmallC/codez80.c
Applications/SmallC/lex.c
Applications/SmallC/prototype.h

index 37aa9b5..14870ce 100644 (file)
@@ -41,3 +41,6 @@ clean:
        $(CC) $(COPT) $(CFLAGS) -c $< -o $@
 
 $(OBJS_ALL) : $(INC)
+
+clean:
+       rm -f *~ *.rel *.asm *.lst *.sym *.o *.map *.noi *.bin *.lk
index ed06557..1f7105b 100644 (file)
@@ -1,3 +1,5 @@
+- Parse assignment to local variables
+       auto x = 4; etc
 - 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
index 2dc5ede..ff0b156 100644 (file)
@@ -2,11 +2,12 @@
 #include "defs.h"
 #include "data.h"
 
-int nextreg = 0;
-int xdirty = 0;
-int xsprel = 0;
-int xtype = 0; /* 0 = D, 1 = S */
-int regv[8];
+static int nextreg = 0;
+static int xdirty = 0;
+static int xsprel = 0;
+static int xtype = 0;  /* 0 = D, 1 = S */
+static int regv[8];
+static int indata;
 
 /*
  *      Some predefinitions:
@@ -33,6 +34,7 @@ void header (void) {
     newline ();
     output_line ("\t;program area SMALLC_GENERATED is RELOCATABLE");
     output_line ("\t.module SMALLC_GENERATED");
+    gen_code();
 }
 
 /**
@@ -52,7 +54,6 @@ void initmac(void) {
  * Output internal generated label prefix
  */
 void output_label_prefix(void) {
-    xdirty = 1;
     output_byte('$');
 }
 
@@ -61,6 +62,8 @@ void output_label_prefix(void) {
  */
 void output_label_terminator (void) {
     output_byte (':');
+    if (!indata)
+        xdirty = 1;
 }
 
 /**
@@ -902,4 +905,16 @@ void gen_multiply(int type, int size) {
 void gen_statement_end(void)
 {
     output_line(";end");
-}
\ No newline at end of file
+}
+
+void gen_data(void)
+{
+    indata = 1;
+    output_line(".data");
+}
+
+void gen_code(void)
+{
+    indata = 0;
+    output_line(".code");
+}
index 001763c..6430bdf 100644 (file)
@@ -240,9 +240,8 @@ void gen_get_indirect(char typeobj, int reg) {
             output_line("ldb ,x");
         else {
             /* TODO work out what we can damage here */
-            /* Can we avoid using ,u ?? */
-            output_line("tfr d,u");
-            output_line("ldb ,u");
+            output_line("tfr d,x");
+            output_line("ldb ,x");
         }
         if (typeobj == CCHAR)
             output_line("sex");
@@ -250,9 +249,8 @@ void gen_get_indirect(char typeobj, int reg) {
         if (reg & DE_REG)
             output_line("ldd ,x");     /* Can't happen ?? */
         else {
-            output_line("exg d,x");
-            output_line("ldx ,x");
-            output_line("exg d,x");
+            output_line("tfr d,x");
+            output_line("ldd ,x");
         }
     }
 }
@@ -310,11 +308,9 @@ void gen_pop(void) {
  * FIXME: probably want a gen_call_indirect so targets can do sane things
  */
 void gen_swap_stack(void) {
-    /* FIXME: if we can get rid of u register stuff we can get two
-       register variables */
-    output_line("ldu ,s");
+    output_line("ldx ,s");
     output_line("std ,s");
-    output_line("tfr u,d");
+    output_line("tfr x,d");
 }
 
 /**
@@ -360,12 +356,14 @@ void gen_epilogue(void)
         output_number(i);
         newline();
     }
-    /* FIXME: need to adjust the stack if there is cruft in the way */
+    /* Need to adjust the stack if there is cruft in the way */
     if (nextreg > 1) {
+        gen_modify_stack(regv[1]);
         output_line("puls y,u");
         stkp + 4;
     }
     else if (nextreg) {
+        gen_modify_stack(regv[0]);
         output_line("puls y");
         stkp += 2;
     }
@@ -517,10 +515,8 @@ void gen_jump_case(void) {
  * @param lval2
  */
 void gen_add(LVALUE *lval, LVALUE *lval2) {
-    if (dbltest (lval2, lval)) {
-        output_line("asl 1,s");
-        output_line("rol ,s");
-    }
+    if (dbltest (lval2, lval))
+        output_line("addd ,s");
     output_line ("addd ,s++");
     stkp += INTSIZE;
 }
@@ -849,11 +845,15 @@ void gen_multiply(int type, int size) {
             gen_multiply_by_two();
             break;
         case STRUCT:
+            if (nextreg > 1)
+                output_line("pshs y");
             output_with_tab("ldy ");
             output_immediate(size);
             newline();
             gen_call("__muli ");
             newline();
+            if (nextreg > 1)
+                output_line("puls y");
             break;
         default:
             break;
index 82fa342..d744796 100644 (file)
@@ -527,14 +527,11 @@ void gen_multiply_by_two(void) {
 }
 
 /**
- * divide the primary register by INTSIZE, never used
+ * divide the primary register by INTSIZE
  */
 void gen_divide_by_two(void) {
-    gen_push(HL_REG);        /* push primary in prep for gasr */
-    gen_immediate ();
-    output_number (1);
-    newline ();
-    gen_arithm_shift_right ();  /* divide by two */
+    output_line("srl h");
+    output_line("rr l");
 }
 
 /**
@@ -553,11 +550,8 @@ void gen_jump_case(void) {
  */
 void gen_add(LVALUE *lval, LVALUE *lval2) {
     gen_pop ();
-    if (dbltest (lval2, lval)) {
-        gen_swap ();
-        gen_multiply_by_two();
-        gen_swap ();
-    }
+    if (dbltest (lval2, lval))
+        output_line("add hl,de");
     output_line ("add hl,de");
 }
 
index 51e7083..a2a98d0 100644 (file)
@@ -204,6 +204,7 @@ int get_type(void) {
     if (amatch ("void", 4)) {
         return VOID;
     }
+#if 0
     if (amatch ("register", 8)) {
         if (amatch("char", 4))
             return CCHAR;
@@ -211,13 +212,15 @@ int get_type(void) {
             return CINT;
         else
             return CINT;
-    } else if(amatch("unsigned", 8)) {
+    } else
+#endif
+    if(amatch("unsigned", 8)) {
         if (amatch("char", 4)) {
             return UCHAR;
         } else if (amatch("int", 3)) {
             return UINT;
         }
-    } else if(amatch("signed", 8)) {
+    } else if(amatch("signed", 6)) {
         if (amatch("char", 4)) {
             return CCHAR;
         } else if (amatch("int", 3)) {
index b72495a..b9334d9 100644 (file)
@@ -68,6 +68,8 @@ extern void gen_prologue(void);
 extern void gen_epilogue(void);
 extern int gen_register(int vp, int size, int typ);
 extern void gen_statement_end(void);
+extern void gen_code(void);
+extern void gen_data(void);
 extern char *inclib(void);
 extern void gnargs(int d);
 extern int assemble(char *s);