]> git.sur5r.net Git - cc65/blobdiff - src/cc65/coptadd.c
Comment and indentation changes
[cc65] / src / cc65 / coptadd.c
index 31beea9cfc2d7e31253145e22cd8a75a1918e874..d490574d9cdff5dd96091097d4d017bf41945c22 100644 (file)
@@ -33,6 +33,9 @@
 
 
 
+/* common */
+#include "chartype.h"
+
 /* cc65 */
 #include "codeent.h"
 #include "codeinfo.h"
@@ -373,6 +376,59 @@ unsigned OptAdd3 (CodeSeg* S)
 
 
 unsigned OptAdd4 (CodeSeg* S)
+/* Search for a call to incaxn and replace it by an 8 bit add if the X register
+ * is not used later.
+ */
+{
+    unsigned Changes = 0;
+
+    /* Walk over the entries */
+    unsigned I = 0;
+    while (I < CS_GetEntryCount (S)) {
+
+       CodeEntry* E;
+
+       /* Get next entry */
+               E = CS_GetEntry (S, I);
+
+       /* Check for the sequence */
+        if (E->OPC == OP65_JSR                          &&
+            strncmp (E->Arg, "incax", 5) == 0           &&
+            IsDigit (E->Arg[5])                         &&
+            E->Arg[6] == '\0'                           &&
+            !RegXUsed (S, I+1)) {
+
+            CodeEntry* X;
+            const char* Arg;
+
+            /* Insert new code behind the sequence */
+           X = NewCodeEntry (OP65_CLC, AM65_IMP, 0, 0, E->LI);
+           CS_InsertEntry (S, X, I+1);
+
+           Arg = MakeHexArg (E->Arg[5] - '0');
+                   X = NewCodeEntry (OP65_ADC, AM65_IMM, Arg, 0, E->LI);
+           CS_InsertEntry (S, X, I+2);
+
+                   /* Delete the old code */
+           CS_DelEntry (S, I);
+
+           /* Remember, we had changes */
+           ++Changes;
+
+       }
+
+       /* Next entry */
+       ++I;
+
+    }
+
+    /* Return the number of changes made */
+    return Changes;
+}
+
+
+
+unsigned OptAdd5 (CodeSeg* S)
 /* Search for the sequence
  *
  *     adc     ...