scc: fixes for non ANSI headers and 6809 code gen
authorAlan Cox <alan@linux.intel.com>
Wed, 29 Jun 2016 17:58:00 +0000 (18:58 +0100)
committerAlan Cox <alan@linux.intel.com>
Wed, 29 Jun 2016 17:58:00 +0000 (18:58 +0100)
Applications/SmallC/code6809.c
Applications/SmallC/function.c
Applications/SmallC/main.c

index f7ef604..4f4127e 100644 (file)
@@ -150,7 +150,7 @@ int gen_get_locale(SYMBOL *sym) {
         newline();
         return HL_REG;
     } else {
-        output_line("leay ");
+        output_with_tab("leay ");
         output_number(sym->offset - stkp);
         output_string(",s");
         newline ();
@@ -180,8 +180,7 @@ void gen_put_memory(SYMBOL *sym) {
  * @param typeobj
  */
 void gen_put_indirect(char typeobj) {
-    /* pop ? */
-    output_line("tfr d,y");
+    output_line("puls d");
     if (typeobj & CCHAR) {
         output_line("stb ,y");
     } else {
@@ -195,19 +194,23 @@ void gen_put_indirect(char typeobj) {
  * @param typeobj object type
  */
 void gen_get_indirect(char typeobj, int reg) {
-    if (typeobj == CCHAR) {
-        if (reg & DE_REG) {
-            gen_swap();
+    if (typeobj == CCHAR || typeobj == UCHAR) {
+        if (reg & DE_REG)
+            output_line("ldb ,x");
+        else {
+            /* TODO work out what we can damage here */
+            output_line("tfr d,u");
+            output_line("ldb ,u");
         }
-        output_line("loadbs r1 (r1)");
-    } else if (typeobj == UCHAR) {
-        if (reg & DE_REG) {
-            gen_swap();
-        }
-        //gen_call("cguchar");
-        output_line("loadbu r1 (r1)");
+        if (typeobj == CCHAR)
+            output_line("sex");
     } else { // int
-         output_line("load r1 (r1)");
+        if (reg & DE_REG)
+            output_line("ldd ,x");     /* Can't happen ?? */
+        else {
+            output_line("tfr d,u");
+            output_line("ldd ,u");
+        }
     }
 }
 
index 917f58c..3a901ab 100644 (file)
@@ -31,6 +31,7 @@ void newfunc_typed(int storage, char *n, int type)
 {
     int idx;
     SYMBOL *symbol;
+    char an[NAMESIZE];
 
     fexitlab = getlabel();
 
@@ -57,11 +58,11 @@ void newfunc_typed(int storage, char *n, int type)
     } else {
         // K&R style argument declaration
         while (!match(")")) {
-            if (symname(n)) {
-                if (find_locale(n) > -1)
-                    multidef(n);
+            if (symname(an)) {
+                if (find_locale(an) > -1)
+                    multidef(an);
                 else {
-                    add_local(n, 0, 0, argstk, AUTO);
+                    add_local(an, 0, 0, argstk, AUTO);
                     argstk = argstk + INTSIZE;
                 }
             } else {
index 801e4a1..e8f1865 100644 (file)
@@ -144,20 +144,22 @@ void usage(void) {
  */
 void parse(void) {
     while (!input_eof) {
-        if (amatch("extern", 6))
+        if (match("#")) {
+            if (match("asm"))
+                doasm();
+            else if (match("include"))
+                doinclude();
+            else if (match("define"))
+                dodefine();
+            else if (match("undef"))
+                doundef();
+        }
+        else if (amatch("extern", 6))
             do_declarations(EXTERN, NULL_TAG, 0);
         else if (amatch("static", 6))
             do_declarations(STATIC, NULL_TAG, 0);
-        else if (do_declarations(PUBLIC, NULL_TAG, 0));
-        else if (match("#asm"))
-            doasm();
-        else if (match("#include"))
-            doinclude();
-        else if (match("#define")) {
-            dodefine();
-        }
-        else if (match("#undef"))
-            doundef();
+        else if (do_declarations(PUBLIC, NULL_TAG, 0))
+            ;
         else {
             newfunc();
         }