]> git.sur5r.net Git - cc65/blobdiff - src/cc65/codeent.c
Fixed wrong code generation for
[cc65] / src / cc65 / codeent.c
index 5f2b3f1eef943253ec1feea688f22cb57fad58d6..13b7aed146701f961315ee240d2aa8b49bc34109 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2001-2004 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 2001-2005, Ullrich von Bassewitz                                      */
+/*                Römerstrasse 52                                            */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -144,7 +144,7 @@ static void SetUseChgInfo (CodeEntry* E, const OPCDesc* D)
      * lookup the information about this function and use it. The jump itself
      * does not change any registers, so we don't need to use the data from D.
      */
-    if ((E->Info & (OF_BRA | OF_CALL)) != 0 && E->JumpTo == 0) {
+    if ((E->Info & (OF_UBRA | OF_CALL)) != 0 && E->JumpTo == 0) {
        /* A subroutine call or jump to external symbol (function exit) */
        GetFuncInfo (E->Arg, &E->Use, &E->Chg);
     } else {
@@ -394,14 +394,26 @@ void CE_SetNumArg (CodeEntry* E, long Num)
 
 
 
-int CE_KnownImm (const CodeEntry* E)
-/* Return true if the argument of E is a known immediate value */
+int CE_IsConstImm (const CodeEntry* E)
+/* Return true if the argument of E is a constant immediate value */
 {
     return (E->AM == AM65_IMM && (E->Flags & CEF_NUMARG) != 0);
 }
 
 
 
+int CE_IsKnownImm (const CodeEntry* E, unsigned long Num)
+/* Return true if the argument of E is a constant immediate value that is
+ * equal to Num.
+ */
+{
+    return E->AM == AM65_IMM            &&
+           (E->Flags & CEF_NUMARG) != 0 &&
+           E->Num == Num;
+}
+
+
+
 int CE_UseLoadFlags (const CodeEntry* E)
 /* Return true if the instruction uses any flags that are set by a load of
  * a register (N and Z).
@@ -519,7 +531,7 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
 
        case OP65_AND:
                    if (RegValIsKnown (In->RegA)) {
-               if (CE_KnownImm (E)) {
+               if (CE_IsConstImm (E)) {
                    Out->RegA = In->RegA & (short) E->Num;
                } else if (E->AM == AM65_ZP) {
                    switch (GetKnownReg (E->Use & REG_ZP, In)) {
@@ -676,7 +688,7 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
 
        case OP65_EOR:
                    if (RegValIsKnown (In->RegA)) {
-               if (CE_KnownImm (E)) {
+               if (CE_IsConstImm (E)) {
                    Out->RegA = In->RegA ^ (short) E->Num;
                } else if (E->AM == AM65_ZP) {
                    switch (GetKnownReg (E->Use & REG_ZP, In)) {
@@ -825,7 +837,7 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
            break;
 
        case OP65_LDA:
-           if (CE_KnownImm (E)) {
+           if (CE_IsConstImm (E)) {
                Out->RegA = (unsigned char) E->Num;
            } else if (E->AM == AM65_ZP) {
                switch (GetKnownReg (E->Use & REG_ZP, In)) {
@@ -855,7 +867,7 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
            break;
 
        case OP65_LDX:
-           if (CE_KnownImm (E)) {
+           if (CE_IsConstImm (E)) {
                Out->RegX = (unsigned char) E->Num;
            } else if (E->AM == AM65_ZP) {
                switch (GetKnownReg (E->Use & REG_ZP, In)) {
@@ -885,7 +897,7 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
            break;
 
        case OP65_LDY:
-           if (CE_KnownImm (E)) {
+           if (CE_IsConstImm (E)) {
                Out->RegY = (unsigned char) E->Num;
            } else if (E->AM == AM65_ZP) {
                switch (GetKnownReg (E->Use & REG_ZP, In)) {
@@ -946,7 +958,7 @@ void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs)
 
        case OP65_ORA:
            if (RegValIsKnown (In->RegA)) {
-               if (CE_KnownImm (E)) {
+               if (CE_IsConstImm (E)) {
                    Out->RegA = In->RegA | (short) E->Num;
                } else if (E->AM == AM65_ZP) {
                    switch (GetKnownReg (E->Use & REG_ZP, In)) {