]> git.sur5r.net Git - cc65/blobdiff - src/cc65/codeseg.c
Track usage of the sreg and several other zero page registers and remove
[cc65] / src / cc65 / codeseg.c
index 325eee20f67558d14d682df3d9a156fce59d73ab..f29c6767e3492145ec3885a8d26f46e9c8cccf21 100644 (file)
@@ -323,7 +323,7 @@ static CodeEntry* ParseInsn (CodeSeg* S, LineInfo* LI, const char* L)
                if ((OPC->Info & OF_BRA) != 0) {
                    /* Branch */
                    AM = AM65_BRA;
-               } else if (IsZPName (Arg)) {
+               } else if (IsZPName (Arg, 0)) {
                    AM = AM65_ZP;
                } else {
                    AM = AM65_ABS;
@@ -338,7 +338,7 @@ static CodeEntry* ParseInsn (CodeSeg* S, LineInfo* LI, const char* L)
                    Reg = toupper (*L);
                    L = SkipSpace (L+1);
                    if (Reg == 'X') {
-                       if (IsZPName (Arg)) {
+                       if (IsZPName (Arg, 0)) {
                            AM = AM65_ZPX;
                        } else {
                            AM = AM65_ABSX;
@@ -397,6 +397,7 @@ CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func)
 /* Create a new code segment, initialize and return it */
 {
     unsigned I;
+    const type* RetType;
 
     /* Allocate memory */
     CodeSeg* S = xmalloc (sizeof (CodeSeg));
@@ -413,8 +414,12 @@ CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func)
     /* If we have a function given, get the return type of the function.
      * Assume ANY return type besides void will use the A and X registers.
      */
-    if (S->Func && !IsTypeVoid (GetFuncReturn (Func->Type))) {
-       S->ExitRegs = REG_AX;
+    if (S->Func && !IsTypeVoid ((RetType = GetFuncReturn (Func->Type)))) {
+       if (SizeOf (RetType) == SizeOf (type_long)) {
+           S->ExitRegs = REG_EAX;
+       } else {
+           S->ExitRegs = REG_AX;
+       }
     } else {
        S->ExitRegs = REG_NONE;
     }
@@ -437,7 +442,7 @@ void CS_AddEntry (CodeSeg* S, struct CodeEntry* E)
 
 
 
-void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap)
+void CS_AddVLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap)
 /* Add a line to the given code segment */
 {
     const char* L;
@@ -482,6 +487,17 @@ void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap)
 
 
 
+void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, ...)
+/* Add a line to the given code segment */
+{
+    va_list ap;
+    va_start (ap, Format);
+    CS_AddVLine (S, LI, Format, ap);
+    va_end (ap);
+}
+
+
+
 void CS_InsertEntry (CodeSeg* S, struct CodeEntry* E, unsigned Index)
 /* Insert the code entry at the index given. Following code entries will be
  * moved to slots with higher indices.
@@ -1042,7 +1058,7 @@ void CS_GenRegInfo (CodeSeg* S)
     RC_Invalidate (&Regs);
     CurrentRegs = &Regs;
 
-    /* First pass. Walk over all insns an note just the changes from one
+    /* First pass. Walk over all insns and note just the changes from one
      * insn to the next one.
      */
     WasJump = 0;
@@ -1098,6 +1114,12 @@ void CS_GenRegInfo (CodeSeg* S)
                if (J->RI->Out2.RegY != Regs.RegY) {
                    Regs.RegY = -1;
                }
+               if (J->RI->Out2.SRegLo != Regs.SRegLo) {
+                   Regs.SRegLo = -1;
+               }
+               if (J->RI->Out2.SRegHi != Regs.SRegHi) {
+                   Regs.SRegHi = -1;
+               }
                ++Entry;
            }