]> git.sur5r.net Git - cc65/blobdiff - src/cc65/codegen.c
Allow any number of optional braces around all initializers as required by the standard
[cc65] / src / cc65 / codegen.c
index c4a50b139551d301bad60b8ce223ead0a9cab8d7..d3ec179c310af3779807ddfeedbbd7e26d4225b8 100644 (file)
@@ -6,9 +6,9 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2002 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
+/* (C) 1998-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
@@ -132,7 +132,7 @@ static const char* GetLabelName (unsigned Flags, unsigned long Label, long Offs)
            break;
 
        default:
-           Internal ("Invalid address flags");
+           Internal ("Invalid address flags: %04X", Flags);
     }
 
     /* Return a pointer to the static buffer */
@@ -157,16 +157,16 @@ void g_preamble (void)
     /* Identify the compiler version */
     AddTextLine (";");
     AddTextLine ("; File generated by cc65 v %u.%u.%u",
-                VER_MAJOR, VER_MINOR, VER_PATCH);
+                VER_MAJOR, VER_MINOR, VER_PATCH);
     AddTextLine (";");
 
     /* Insert some object file options */
     AddTextLine ("\t.fopt\t\tcompiler,\"cc65 v %u.%u.%u\"",
-                   VER_MAJOR, VER_MINOR, VER_PATCH);
+                   VER_MAJOR, VER_MINOR, VER_PATCH);
 
     /* If we're producing code for some other CPU, switch the command set */
     if (CPU == CPU_65C02) {
-       AddTextLine ("\t.pc02");
+       AddTextLine ("\t.pc02");
     }
 
     /* Allow auto import for runtime library routines */
@@ -189,7 +189,7 @@ void g_preamble (void)
 
 void g_fileinfo (const char* Name, unsigned long Size, unsigned long MTime)
 /* If debug info is enabled, place a file info into the source */
-{
+{   
     if (DebugInfo) {
        /* We have to place this into the global text segment, so it will
         * appear before all .dbg line statements.
@@ -387,6 +387,14 @@ void g_defimport (const char* Name, int ZP)
 
 
 
+void g_importmainargs (void)
+/* Forced import of a special symbol that handles arguments to main */
+{
+    AddTextLine ("\t.forceimport\tinitmainargs");
+}
+
+
+
 /*****************************************************************************/
 /*                          Load functions for various registers                    */
 /*****************************************************************************/
@@ -485,11 +493,51 @@ void g_leave (void)
 
 
 /*****************************************************************************/
-/*                           Register variables                             */
+/*                                   Register variables                             */
 /*****************************************************************************/
 
 
 
+void g_swap_regvars (int StackOffs, int RegOffs, unsigned Bytes)
+/* Swap a register variable with a location on the stack */
+{
+    /* Calculate the actual stack offset and check it */
+    StackOffs -= oursp;
+    CheckLocalOffs (StackOffs);
+
+    /* Generate code */
+    if (Bytes == 1) {
+
+        if (CodeSizeFactor < 165) {
+            ldyconst (StackOffs);
+            ldxconst (RegOffs);
+            AddCodeLine ("jsr regswap1");
+        } else {
+            ldyconst (StackOffs);
+            AddCodeLine ("lda (sp),y");
+            AddCodeLine ("ldx regbank%+d", RegOffs);
+            AddCodeLine ("sta regbank%+d", RegOffs);
+            AddCodeLine ("txa");
+            AddCodeLine ("sta (sp),y");
+        }
+
+    } else if (Bytes == 2) {
+
+        ldyconst (StackOffs);
+        ldxconst (RegOffs);
+        AddCodeLine ("jsr regswap2");
+
+    } else {
+
+        ldyconst (StackOffs);
+        ldxconst (RegOffs);
+        ldaconst (Bytes);
+        AddCodeLine ("jsr regswap");
+    }
+}
+
+
+
 void g_save_regvars (int RegOffs, unsigned Bytes)
 /* Save register variables */
 {
@@ -3973,10 +4021,27 @@ void g_defbytes (const void* Bytes, unsigned Count)
 
 
 
-void g_zerobytes (unsigned n)
-/* Output n bytes of data initialized with zero */
+void g_zerobytes (unsigned Count)
+/* Output Count bytes of data initialized with zero */
 {
-    AddDataLine ("\t.res\t%u,$00", n);
+    if (Count > 0) {
+        AddDataLine ("\t.res\t%u,$00", Count);
+    }
+}
+
+
+
+void g_initregister (unsigned Label, unsigned Reg, unsigned Size)
+/* Initialize a register variable from static initialization data */
+{
+    /* Register variables do always have less than 128 bytes */
+    unsigned CodeLabel = GetLocalLabel ();
+    ldxconst (Size-1);
+    g_defcodelabel (CodeLabel);
+    AddCodeLine ("lda %s,x", GetLabelName (CF_STATIC, Label, 0));
+    AddCodeLine ("sta %s,x", GetLabelName (CF_REGVAR, Reg, 0));
+    AddCodeLine ("dex");
+    AddCodeLine ("bpl %s", LocalLabelName (CodeLabel));
 }