]> git.sur5r.net Git - cc65/blobdiff - src/cc65/codegen.c
Rewrote code generation for the strlen standard function. Added code for
[cc65] / src / cc65 / codegen.c
index 278ecc9b4e4fad52a7a9d01b5eb9df7e96eb4a46..5b75a764f3baee61859db853cd3438d5c6d54a4f 100644 (file)
@@ -464,21 +464,22 @@ void g_leave (void)
 /* Function epilogue */
 {
     /* How many bytes of locals do we have to drop? */
-    int k = -StackPtr;
+    unsigned k = (unsigned) -StackPtr;
 
     /* If we didn't have a variable argument list, don't call leave */
     if (funcargs >= 0) {
 
-       /* Drop stackframe if needed */
+       /* Drop stackframe if needed. We can only drop 255 bytes at a time. */
        k += funcargs;
-               if (k > 0) {
-           if (k <= 8) {
-           AddCodeLine ("jsr incsp%d", k);
+               while (k > 0) {
+            unsigned ToDrop = (k > 255)? 255 : k;
+           if (ToDrop <= 8) {
+               AddCodeLine ("jsr incsp%d", k);
            } else {
-               CheckLocalOffs (k);
-               ldyconst (k);
-               AddCodeLine ("jsr addysp");
+               ldyconst (ToDrop);
+               AddCodeLine ("jsr addysp");
            }
+            k -= ToDrop;
        }
 
     } else {
@@ -488,6 +489,11 @@ void g_leave (void)
            AddCodeLine ("jsr leave");
        } else {
            /* We've a stack frame to drop */
+            while (k > 255) {
+                ldyconst (255);
+                AddCodeLine ("jsr addysp");
+                k -= 255;
+            }
            ldyconst (k);
            AddCodeLine ("jsr leavey");
        }
@@ -4279,53 +4285,3 @@ void g_asmcode (struct StrBuf* B)
 
 
 
-/*****************************************************************************/
-/*                         Inlined known functions                          */
-/*****************************************************************************/
-
-
-
-void g_strlen (unsigned flags, unsigned long val, long offs)
-/* Inline the strlen() function */
-{
-    /* We need a label in both cases */
-    unsigned label = GetLocalLabel ();
-
-    /* Two different encodings */
-    if (flags & CF_CONST) {
-
-       /* The address of the string is constant. Create the correct label name */
-       const char* lbuf = GetLabelName (flags, val, offs);
-
-       /* Generate the strlen code */
-       AddCodeLine ("ldy #$FF");
-       g_defcodelabel (label);
-       AddCodeLine ("iny");
-       AddCodeLine ("lda %s,y", lbuf);
-       AddCodeLine ("bne %s", LocalLabelName (label));
-               AddCodeLine ("tax");
-       AddCodeLine ("tya");
-
-    } else {
-
-               /* Address not constant but in primary */
-       if (CodeSizeFactor < 400) {
-           /* This is too much code, so call strlen instead of inlining */
-           AddCodeLine ("jsr _strlen");
-       } else {
-           /* Inline the function */
-           AddCodeLine ("sta ptr1");
-           AddCodeLine ("stx ptr1+1");
-           AddCodeLine ("ldy #$FF");
-           g_defcodelabel (label);
-           AddCodeLine ("iny");
-           AddCodeLine ("lda (ptr1),y");
-           AddCodeLine ("bne %s", LocalLabelName (label));
-                   AddCodeLine ("tax");
-           AddCodeLine ("tya");
-       }
-    }
-}
-
-
-