summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>2025-06-27 14:35:15 +0000
committerspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>2025-06-27 14:35:15 +0000
commitd90a97c126978b4746b6d892375d02f0acb2a8bb (patch)
treee29666cb31c4547487a3ec6f57287644f7606739
parent0326e054903018e896cf939404af2cb9f15482b9 (diff)
Replace ISINST macro by a new lineIsInst function.
git-svn-id: http://svn.code.sourceforge.net/p/sdcc/code/trunk/sdcc@15469 4a8a32a2-be11-0410-ad9d-d568d2c75423
-rw-r--r--ChangeLog9
-rw-r--r--src/SDCCpeeph.c1
-rw-r--r--src/SDCCpeeph.h51
-rw-r--r--src/f8/peep.c223
-rw-r--r--src/mos6502/peep.c96
-rw-r--r--src/pdk/peep.c222
-rw-r--r--src/stm8/peep.c447
7 files changed, 552 insertions, 497 deletions
diff --git a/ChangeLog b/ChangeLog
index 936dbfcca..61270d3f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-06-27 Philipp Klaus Krause <philipp@colecovision.eu>
+
+ * src/SDCCpeeph.h,
+ src/f8/peep.c,
+ src/mos6502/peep.c,
+ src/pdk/peep.c,
+ src/stm8/peep.c:
+ Replace ISINST macro by a new lineIsInst function.
+
2025-06-26 Philipp Klaus Krause <philipp@colecovision.eu>
* configure.ac,
diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c
index 59ea07c6e..83698b2ef 100644
--- a/src/SDCCpeeph.c
+++ b/src/SDCCpeeph.c
@@ -4042,3 +4042,4 @@ const char * StrStr (const char * str1, const char * str2)
return (NULL) ;
}
+
diff --git a/src/SDCCpeeph.h b/src/SDCCpeeph.h
index aa291cde4..18c279a9b 100644
--- a/src/SDCCpeeph.h
+++ b/src/SDCCpeeph.h
@@ -22,6 +22,8 @@
#ifndef SDCCPEEPH_H
#define SDCCPEEPH_H 1
+#include <ctype.h>
+
#include "SDCCgen.h"
#define MAX_PATTERN_LEN 256
@@ -59,4 +61,53 @@ void peepHole (lineNode **);
const char * StrStr (const char * str1, const char * str2);
+// Check if asm line pl is instruction inst (i.e. the first non-whitespace is inst).
+static inline bool lineIsInst (const lineNode *pl, const char *inst)
+{
+ return (!STRNCASECMP(pl->line, inst, strlen(inst)) && (!pl->line[strlen(inst)] || isspace((unsigned char)(pl->line[strlen(inst)]))));
+}
+
+// Get a pointer pointing just beyond the argument starting at arg (in an asxxxx syntax line).
+static inline const char *argEnd (const char *arg)
+{
+ if (!arg)
+ return (NULL);
+
+ for(unsigned int parens = 0; *arg; arg++)
+ {
+ if (*arg == '(' || *arg == '[')
+ parens++;
+ if (*arg == ')' || *arg == ']')
+ parens--;
+ if ((isspace (*arg) || *arg == ',') && !parens)
+ break;
+ }
+
+ return (arg);
+}
+
+// Get a pointer pointing to the start of argument i (in an asxxxx syntax line, numbered starting at 0).
+static inline const char *lineArg (const lineNode *pl, int i)
+{
+ const char *arg = i ? argEnd (lineArg (pl, i - 1)) : pl->line;
+
+ if (!arg)
+ return (NULL);
+
+ // Skip instruction menmonic (for argument 0) or the comma (for further arguments), and any whitespace beside it.
+ while (isspace (*arg))
+ arg++;
+ while (*arg && !isspace (*arg))
+ arg++;
+ while (isspace (*arg))
+ arg++;
+
+ // Check for comment
+ if (*arg == ';')
+ return (NULL);
+
+ return (arg);
+}
+
#endif
+
diff --git a/src/f8/peep.c b/src/f8/peep.c
index 2b76590cb..0827f2b56 100644
--- a/src/f8/peep.c
+++ b/src/f8/peep.c
@@ -11,7 +11,6 @@
// #define D(_s) { printf _s; fflush(stdout); }
#define D(_s)
-#define ISINST(l, i) (!STRNCASECMP((l), (i), sizeof(i) - 1) && (!(l)[sizeof(i) - 1] || isspace((unsigned char)((l)[sizeof(i) - 1]))))
#define STARTSINST(l, i) (!STRNCASECMP((l), (i), sizeof(i) - 1))
typedef enum
@@ -206,8 +205,8 @@ f8instructionSize (lineNode *pl)
const char *larg = leftArg (pl->line);
const char *rarg = rightArg (pl->line);
- if (ISINST (pl->line, "adc") || ISINST (pl->line, "add") || ISINST (pl->line, "and") || ISINST (pl->line, "cp") ||
- ISINST (pl->line, "or") || ISINST (pl->line, "sbc") || ISINST (pl->line, "sub") || ISINST (pl->line, "xor"))
+ if (lineIsInst (pl, "adc") || lineIsInst (pl, "add") || lineIsInst (pl, "and") || lineIsInst (pl, "cp") ||
+ lineIsInst (pl, "or") || lineIsInst (pl, "sbc") || lineIsInst (pl, "sub") || lineIsInst (pl, "xor"))
{
if (!strncmp (larg, "xl", 2) && isReg8 (rarg))
return 1;
@@ -227,10 +226,10 @@ f8instructionSize (lineNode *pl)
return 4;
}
- if (ISINST (pl->line, "bool") || ISINST (pl->line, "clr") || ISINST (pl->line, "daa") || ISINST (pl->line, "dec") ||
- ISINST (pl->line, "inc") || ISINST (pl->line, "pop") || ISINST (pl->line, "push") || ISINST (pl->line, "rlc") ||
- ISINST (pl->line, "rrc") || ISINST (pl->line, "sll") || ISINST (pl->line, "sra") || ISINST (pl->line, "srl") ||
- ISINST (pl->line, "thrd") || ISINST (pl->line, "tst"))
+ if (lineIsInst (pl, "bool") || lineIsInst (pl, "clr") || lineIsInst (pl, "daa") || lineIsInst (pl, "dec") ||
+ lineIsInst (pl, "inc") || lineIsInst (pl, "pop") || lineIsInst (pl, "push") || lineIsInst (pl, "rlc") ||
+ lineIsInst (pl, "rrc") || lineIsInst (pl, "sll") || lineIsInst (pl, "sra") || lineIsInst (pl, "srl") ||
+ lineIsInst (pl, "thrd") || lineIsInst (pl, "tst"))
{
if (!strncmp (larg, "xl", 2))
return 1;
@@ -242,11 +241,11 @@ f8instructionSize (lineNode *pl)
return 3;
}
- if ((ISINST (pl->line, "adcw") || ISINST (pl->line, "sbcw") && !rarg[0]) ||
- ISINST (pl->line, "boolw") || ISINST (pl->line, "clrw") || ISINST (pl->line, "decw") || ISINST (pl->line, "incw") ||
- ISINST (pl->line, "incnw") || ISINST (pl->line, "mul") || ISINST (pl->line, "negw") || ISINST (pl->line, "popw") ||
- ISINST (pl->line, "pushw") || ISINST (pl->line, "sllw") || ISINST (pl->line, "sraw") || ISINST (pl->line, "srlw") ||
- ISINST (pl->line, "rlcw") || ISINST (pl->line, "rrcw") || ISINST (pl->line, "tstw"))
+ if ((lineIsInst (pl, "adcw") || lineIsInst (pl, "sbcw") && !rarg[0]) ||
+ lineIsInst (pl, "boolw") || lineIsInst (pl, "clrw") || lineIsInst (pl, "decw") || lineIsInst (pl, "incw") ||
+ lineIsInst (pl, "incnw") || lineIsInst (pl, "mul") || lineIsInst (pl, "negw") || lineIsInst (pl, "popw") ||
+ lineIsInst (pl, "pushw") || lineIsInst (pl, "sllw") || lineIsInst (pl, "sraw") || lineIsInst (pl, "srlw") ||
+ lineIsInst (pl, "rlcw") || lineIsInst (pl, "rrcw") || lineIsInst (pl, "tstw"))
{
if (larg[0] == 'y')
return 1;
@@ -258,15 +257,15 @@ f8instructionSize (lineNode *pl)
return 3;
}
- if (ISINST (pl->line, "xch") && larg[0] == 'f' && isSprel (rarg))
+ if (lineIsInst (pl, "xch") && larg[0] == 'f' && isSprel (rarg))
return 1;
- else if (ISINST (pl->line, "xch"))
+ else if (lineIsInst (pl, "xch"))
return 1 + (larg[0] != 'y');
- if (ISINST (pl->line, "addw") && !strncmp (larg, "sp", 2) && rarg[0] == '#')
+ if (lineIsInst (pl, "addw") && !strncmp (larg, "sp", 2) && rarg[0] == '#')
return 2;
- if (ISINST (pl->line, "addw") && rarg[0] == '#' && isInt (rarg) && readint (rarg) <= 0xff)
+ if (lineIsInst (pl, "addw") && rarg[0] == '#' && isInt (rarg) && readint (rarg) <= 0xff)
{
if (larg[0] == 'y')
return 2;
@@ -274,8 +273,8 @@ f8instructionSize (lineNode *pl)
return 3;
}
- if (ISINST (pl->line, "addw") || ISINST (pl->line, "cpw") || ISINST (pl->line, "orw") || ISINST (pl->line, "sbcw") ||
- ISINST (pl->line, "subw") || ISINST (pl->line, "xorw"))
+ if (lineIsInst (pl, "addw") || lineIsInst (pl, "cpw") || lineIsInst (pl, "orw") || lineIsInst (pl, "sbcw") ||
+ lineIsInst (pl, "subw") || lineIsInst (pl, "xorw"))
{
if (larg[0] == 'y' && rarg[0] == 'x')
return 1;
@@ -291,7 +290,7 @@ f8instructionSize (lineNode *pl)
return 4;
}
- if (ISINST (pl->line, "ld"))
+ if (lineIsInst (pl, "ld"))
{
if (!strncmp (larg, "xl", 2) && isReg8 (rarg))
return 1;
@@ -321,10 +320,10 @@ f8instructionSize (lineNode *pl)
return 4;
}
- if ((ISINST (pl->line, "ldi") || ISINST (pl->line, "ldwi")) && isYrel (larg))
+ if ((lineIsInst (pl, "ldi") || lineIsInst (pl, "ldwi")) && isYrel (larg))
return 2;
- if (ISINST (pl->line, "ldw"))
+ if (lineIsInst (pl, "ldw"))
{
if (larg[0] == 'y' && rarg[0] == 'x')
return 1;
@@ -354,7 +353,7 @@ f8instructionSize (lineNode *pl)
return 4;
}
- if (ISINST (pl->line, "xchb"))
+ if (lineIsInst (pl, "xchb"))
{
if (!strncmp (larg, "xl", 2))
return 3;
@@ -362,7 +361,7 @@ f8instructionSize (lineNode *pl)
return 4;
}
- if (ISINST (pl->line, "rot"))
+ if (lineIsInst (pl, "rot"))
{
if (!strncmp (larg, "xl", 2))
return 2;
@@ -370,7 +369,7 @@ f8instructionSize (lineNode *pl)
return 3;
}
- if (ISINST (pl->line, "zex") || ISINST (pl->line, "sex"))
+ if (lineIsInst (pl, "zex") || lineIsInst (pl, "sex"))
{
if (!strncmp (larg, "y", 1) && !strncmp (rarg, "xl", 2))
return 1;
@@ -378,10 +377,10 @@ f8instructionSize (lineNode *pl)
return 2;
}
- if (ISINST (pl->line, "mad") || ISINST (pl->line, "nop"))
+ if (lineIsInst (pl, "mad") || lineIsInst (pl, "nop"))
return 1;
- if (ISINST (pl->line, "call") || ISINST (pl->line, "jp"))
+ if (lineIsInst (pl, "call") || lineIsInst (pl, "jp"))
{
if (larg[0] == 'y')
return 1;
@@ -392,19 +391,19 @@ f8instructionSize (lineNode *pl)
}
else if (STARTSINST (pl->line, "jr"))
{
- if (ISINST (pl->line, "jro") || ISINST (pl->line, "jrsgt") || ISINST (pl->line, "jrgt"))
+ if (lineIsInst (pl, "jro") || lineIsInst (pl, "jrsgt") || lineIsInst (pl, "jrgt"))
return 3;
else
return 2;
}
- else if (ISINST (pl->line, "dnjnz"))
+ else if (lineIsInst (pl, "dnjnz"))
{
if (!strncmp (larg, "yh", 2))
return 2;
else
return 3;
}
- else if (ISINST (pl->line, "ret") || ISINST (pl->line, "reti"))
+ else if (lineIsInst (pl, "ret") || lineIsInst (pl, "reti"))
return 1;
// If the instruction is unrecognized, we shouldn't try to optimize.
@@ -420,55 +419,55 @@ f8instructionSize (lineNode *pl)
static bool
f8MightReadFlag (const lineNode *pl, const char *what)
{
- if (ISINST (pl->line, "adc") || ISINST (pl->line, "sbc"))
+ if (lineIsInst (pl, "adc") || lineIsInst (pl, "sbc"))
return !strcmp (what, "cf");
- if (ISINST (pl->line, "adcw") || ISINST (pl->line, "sbcw"))
+ if (lineIsInst (pl, "adcw") || lineIsInst (pl, "sbcw"))
return !strcmp (what, "cf");
- if (ISINST (pl->line, "add") || ISINST (pl->line, "and") || ISINST (pl->line, "cp") || ISINST (pl->line, "or") || ISINST (pl->line, "sub") || ISINST (pl->line, "xor"))
+ if (lineIsInst (pl, "add") || lineIsInst (pl, "and") || lineIsInst (pl, "cp") || lineIsInst (pl, "or") || lineIsInst (pl, "sub") || lineIsInst (pl, "xor"))
return false;
- if (ISINST (pl->line, "sll") || ISINST (pl->line, "srl") || ISINST (pl->line, "inc") || ISINST (pl->line, "dec") || ISINST (pl->line, "clr") || ISINST (pl->line, "push") || ISINST (pl->line, "tst"))
+ if (lineIsInst (pl, "sll") || lineIsInst (pl, "srl") || lineIsInst (pl, "inc") || lineIsInst (pl, "dec") || lineIsInst (pl, "clr") || lineIsInst (pl, "push") || lineIsInst (pl, "tst"))
return false;
- if (ISINST (pl->line, "rlc") || ISINST (pl->line, "rrc"))
+ if (lineIsInst (pl, "rlc") || lineIsInst (pl, "rrc"))
return !strcmp (what, "cf");
- if (ISINST (pl->line, "addw") || ISINST (pl->line, "orw") || ISINST (pl->line, "subw"))
+ if (lineIsInst (pl, "addw") || lineIsInst (pl, "orw") || lineIsInst (pl, "subw"))
return false;
- if (ISINST (pl->line, "adcw") || ISINST (pl->line, "rlcw") || ISINST (pl->line, "rrcw") || ISINST (pl->line, "sbcw"))
+ if (lineIsInst (pl, "adcw") || lineIsInst (pl, "rlcw") || lineIsInst (pl, "rrcw") || lineIsInst (pl, "sbcw"))
return !strcmp (what, "cf");
- if (ISINST (pl->line, "clrw") || ISINST (pl->line, "incw") || ISINST (pl->line, "pushw") || ISINST (pl->line, "sraw") || ISINST (pl->line, "srlw") || ISINST (pl->line, "sllw") || ISINST (pl->line, "tstw"))
+ if (lineIsInst (pl, "clrw") || lineIsInst (pl, "incw") || lineIsInst (pl, "pushw") || lineIsInst (pl, "sraw") || lineIsInst (pl, "srlw") || lineIsInst (pl, "sllw") || lineIsInst (pl, "tstw"))
return false;
- if (ISINST (pl->line, "ld") || ISINST (pl->line, "ldw") || ISINST (pl->line, "ldi") || ISINST (pl->line, "ldwi"))
+ if (lineIsInst (pl, "ld") || lineIsInst (pl, "ldw") || lineIsInst (pl, "ldi") || lineIsInst (pl, "ldwi"))
return false;
- if (ISINST (pl->line, "bool") || ISINST (pl->line, "cax") || ISINST (pl->line, "mad") || ISINST (pl->line, "msk") || ISINST (pl->line, "pop") || ISINST (pl->line, "rot") || ISINST (pl->line, "sra") || ISINST (pl->line, "thrd"))
+ if (lineIsInst (pl, "bool") || lineIsInst (pl, "cax") || lineIsInst (pl, "mad") || lineIsInst (pl, "msk") || lineIsInst (pl, "pop") || lineIsInst (pl, "rot") || lineIsInst (pl, "sra") || lineIsInst (pl, "thrd"))
return false;
- if (ISINST (pl->line, "daa"))
+ if (lineIsInst (pl, "daa"))
return (!strcmp (what, "cf") || !strcmp (what, "hf"));
- if (ISINST (pl->line, "xch"))
+ if (lineIsInst (pl, "xch"))
return (leftArg (pl->line)[0] == 'f');
- if (ISINST (pl->line, "boolw") || ISINST (pl->line, "caxw") || ISINST (pl->line, "cpw") || ISINST (pl->line, "decw") || ISINST (pl->line, "incnw") || ISINST (pl->line, "mul") || ISINST (pl->line, "negw") || ISINST (pl->line, "popw") || ISINST (pl->line, "sex") || ISINST (pl->line, "xchw") || ISINST (pl->line, "zex"))
+ if (lineIsInst (pl, "boolw") || lineIsInst (pl, "caxw") || lineIsInst (pl, "cpw") || lineIsInst (pl, "decw") || lineIsInst (pl, "incnw") || lineIsInst (pl, "mul") || lineIsInst (pl, "negw") || lineIsInst (pl, "popw") || lineIsInst (pl, "sex") || lineIsInst (pl, "xchw") || lineIsInst (pl, "zex"))
return false;
- if (ISINST (pl->line, "xchb"))
+ if (lineIsInst (pl, "xchb"))
return false;
- if (ISINST (pl->line, "call") || ISINST (pl->line, "dnjnz") || ISINST (pl->line, "jr") || ISINST (pl->line, "jp"))
+ if (lineIsInst (pl, "call") || lineIsInst (pl, "dnjnz") || lineIsInst (pl, "jr") || lineIsInst (pl, "jp"))
return false;
- if (ISINST (pl->line, "jrc") || ISINST (pl->line, "jrnc"))
+ if (lineIsInst (pl, "jrc") || lineIsInst (pl, "jrnc"))
return !strcmp (what, "cf");
- if (ISINST (pl->line, "jrn") || ISINST (pl->line, "jrnn"))
+ if (lineIsInst (pl, "jrn") || lineIsInst (pl, "jrnn"))
return !strcmp (what, "nf");
- if (ISINST (pl->line, "jrz") || ISINST (pl->line, "jrnz"))
+ if (lineIsInst (pl, "jrz") || lineIsInst (pl, "jrnz"))
return !strcmp (what, "zf");
- if (ISINST (pl->line, "jrno") || ISINST (pl->line, "jro"))
+ if (lineIsInst (pl, "jrno") || lineIsInst (pl, "jro"))
return !strcmp (what, "of");
- if (ISINST (pl->line, "jrsle") || ISINST (pl->line, "jrsgt"))
+ if (lineIsInst (pl, "jrsle") || lineIsInst (pl, "jrsgt"))
return !strcmp (what, "zf") || !strcmp (what, "nf") || !strcmp (what, "of");
- if (ISINST (pl->line, "jrle") || ISINST (pl->line, "jrgt"))
+ if (lineIsInst (pl, "jrle") || lineIsInst (pl, "jrgt"))
return !strcmp (what, "cf") || !strcmp (what, "zf");
- if (ISINST (pl->line, "ret"))
+ if (lineIsInst (pl, "ret"))
return false;
- if (ISINST (pl->line, "reti"))
+ if (lineIsInst (pl, "reti"))
return true;
- if (ISINST (pl->line, "nop"))
+ if (lineIsInst (pl, "nop"))
return false;
if (pl->ic)
@@ -530,11 +529,11 @@ f8MightRead (const lineNode *pl, const char *what)
else
return f8MightReadFlag(pl, what);
- if (ISINST (pl->line, "jp") || ISINST (pl->line, "jr"))
+ if (lineIsInst (pl, "jp") || lineIsInst (pl, "jr"))
return false;
// 8-bit 2-op inst, and some others.
- if (ISINST (pl->line, "adc") || ISINST (pl->line, "add") || ISINST (pl->line, "and") || ISINST (pl->line, "cp") || ISINST (pl->line, "or") || ISINST (pl->line, "sbc") || ISINST (pl->line, "sub") || ISINST (pl->line, "xch") || ISINST (pl->line, "xor"))
+ if (lineIsInst (pl, "adc") || lineIsInst (pl, "add") || lineIsInst (pl, "and") || lineIsInst (pl, "cp") || lineIsInst (pl, "or") || lineIsInst (pl, "sbc") || lineIsInst (pl, "sub") || lineIsInst (pl, "xch") || lineIsInst (pl, "xor"))
{
const char *larg = leftArg (pl->line);
const char *rarg = rightArg (pl->line);
@@ -546,23 +545,23 @@ f8MightRead (const lineNode *pl, const char *what)
return false;
}
// 8-bit 1-op inst, and some others
- if (ISINST (pl->line, "pop"))
+ if (lineIsInst (pl, "pop"))
return false;
- if (ISINST (pl->line, "clr"))
+ if (lineIsInst (pl, "clr"))
{
const char *larg = leftArg (pl->line);
return (larg[0] == '(' && argCont (larg, extra));
}
- if (ISINST (pl->line, "bool") || ISINST (pl->line, "dec") || ISINST (pl->line, "inc") || ISINST (pl->line, "push") || ISINST (pl->line, "rlc") || ISINST (pl->line, "rot") || ISINST (pl->line, "rrc") || ISINST (pl->line, "sll") || ISINST (pl->line, "sra") || ISINST (pl->line, "srl") || ISINST (pl->line, "tst") || ISINST (pl->line, "xchb"))
+ if (lineIsInst (pl, "bool") || lineIsInst (pl, "dec") || lineIsInst (pl, "inc") || lineIsInst (pl, "push") || lineIsInst (pl, "rlc") || lineIsInst (pl, "rot") || lineIsInst (pl, "rrc") || lineIsInst (pl, "sll") || lineIsInst (pl, "sra") || lineIsInst (pl, "srl") || lineIsInst (pl, "tst") || lineIsInst (pl, "xchb"))
{
const char *larg = leftArg (pl->line);
return (larg[0] == what[0] && larg[1] == what[1] || argCont (larg + 1, extra));
}
// 16-bit 2/1-op inst, and some others.
- if (ISINST (pl->line, "clrw") || ISINST (pl->line, "popw"))
+ if (lineIsInst (pl, "clrw") || lineIsInst (pl, "popw"))
return false;
- if (ISINST (pl->line, "adcw") || ISINST (pl->line, "addw") || ISINST (pl->line, "boolw") || ISINST (pl->line, "cpw") || ISINST (pl->line, "decw") || ISINST (pl->line, "incw") || ISINST (pl->line, "mul") || ISINST (pl->line, "negw") || ISINST (pl->line, "orw") || ISINST (pl->line, "pushw") || ISINST (pl->line, "rlcw") || ISINST (pl->line, "rrcw") || ISINST (pl->line, "sllw") || ISINST (pl->line, "sraw") || ISINST (pl->line, "srlw") || ISINST (pl->line, "subw") || ISINST (pl->line, "sbcw") || ISINST (pl->line, "tstw") || ISINST (pl->line, "incnw") || ISINST (pl->line, "xorw"))
+ if (lineIsInst (pl, "adcw") || lineIsInst (pl, "addw") || lineIsInst (pl, "boolw") || lineIsInst (pl, "cpw") || lineIsInst (pl, "decw") || lineIsInst (pl, "incw") || lineIsInst (pl, "mul") || lineIsInst (pl, "negw") || lineIsInst (pl, "orw") || lineIsInst (pl, "pushw") || lineIsInst (pl, "rlcw") || lineIsInst (pl, "rrcw") || lineIsInst (pl, "sllw") || lineIsInst (pl, "sraw") || lineIsInst (pl, "srlw") || lineIsInst (pl, "subw") || lineIsInst (pl, "sbcw") || lineIsInst (pl, "tstw") || lineIsInst (pl, "incnw") || lineIsInst (pl, "xorw"))
{
const char *larg = leftArg (pl->line);
const char *rarg = rightArg (pl->line);
@@ -574,7 +573,7 @@ f8MightRead (const lineNode *pl, const char *what)
return false;
}
// ld
- if (ISINST (pl->line, "ld"))
+ if (lineIsInst (pl, "ld"))
{
const char *larg = leftArg (pl->line);
const char *rarg = rightArg (pl->line);
@@ -588,9 +587,9 @@ f8MightRead (const lineNode *pl, const char *what)
return false;
}
// ldw
- if (ISINST (pl->line, "ldi") || ISINST (pl->line, "ldwi"))
+ if (lineIsInst (pl, "ldi") || lineIsInst (pl, "ldwi"))
return (extra == 'y' || extra == 'z');
- if (ISINST (pl->line, "ldw"))
+ if (lineIsInst (pl, "ldw"))
{
const char *larg = leftArg (pl->line);
const char *rarg = rightArg (pl->line);
@@ -603,14 +602,14 @@ f8MightRead (const lineNode *pl, const char *what)
return true;
return false;
}
- if (ISINST (pl->line, "sex") || ISINST (pl->line, "zex"))
+ if (lineIsInst (pl, "sex") || lineIsInst (pl, "zex"))
{
const char *rarg = rightArg (pl->line);
if (rarg && (rarg[0] == what[0] && rarg[1] == what[1]))
return true;
return false;
}
- if (ISINST (pl->line, "call"))
+ if (lineIsInst (pl, "call"))
{
const char *larg = leftArg (pl->line);
if (*larg == '#')
@@ -627,9 +626,9 @@ f8MightRead (const lineNode *pl, const char *what)
}
if (STARTSINST (pl->line, "jr"))
return false;
- if (ISINST (pl->line, "ret"))
+ if (lineIsInst (pl, "ret"))
return f8IsReturned(what);
- if (ISINST (pl->line, "reti"))
+ if (lineIsInst (pl, "reti"))
return true;
if (pl->ic)
@@ -644,37 +643,37 @@ f8MightRead (const lineNode *pl, const char *what)
static bool
f8UncondJump (const lineNode *pl)
{
- return (ISINST (pl->line, "jp") || ISINST (pl->line, "jr"));
+ return (lineIsInst (pl, "jp") || lineIsInst (pl, "jr"));
}
static bool
f8CondJump (const lineNode *pl)
{
return (!f8UncondJump (pl) && STARTSINST (pl->line, "jr") ||
- ISINST (pl->line, "dnjz"));
+ lineIsInst (pl, "dnjz"));
}
static bool
f8SurelyWritesFlag (const lineNode *pl, const char *what)
{
// 8-bit 2-op inst.
- if (ISINST (pl->line, "adc") || ISINST (pl->line, "add") || ISINST (pl->line, "cp") || ISINST (pl->line, "sbc") || ISINST (pl->line, "sub"))
+ if (lineIsInst (pl, "adc") || lineIsInst (pl, "add") || lineIsInst (pl, "cp") || lineIsInst (pl, "sbc") || lineIsInst (pl, "sub"))
return true;
- if (ISINST (pl->line, "or") || ISINST (pl->line, "and") || ISINST (pl->line, "xor"))
+ if (lineIsInst (pl, "or") || lineIsInst (pl, "and") || lineIsInst (pl, "xor"))
return (!strcmp (what, "zf") || !strcmp (what, "nf"));
// 8-bit 1-op inst.
- if (ISINST (pl->line, "dec") || ISINST (pl->line, "inc"))
+ if (lineIsInst (pl, "dec") || lineIsInst (pl, "inc"))
return true;
- if (ISINST (pl->line, "clr") || ISINST (pl->line, "push"))
+ if (lineIsInst (pl, "clr") || lineIsInst (pl, "push"))
return false;
- if (ISINST (pl->line, "srl") || ISINST (pl->line, "sll") || ISINST (pl->line, "rrc") || ISINST (pl->line, "rlc"))
+ if (lineIsInst (pl, "srl") || lineIsInst (pl, "sll") || lineIsInst (pl, "rrc") || lineIsInst (pl, "rlc"))
return (!strcmp (what, "zf") || !strcmp (what, "cf"));
- if (ISINST (pl->line, "tst"))
+ if (lineIsInst (pl, "tst"))
return strcmp (what, "hf");
// 16-bit 1/2-op inst.
- if (ISINST (pl->line, "adcw") || ISINST (pl->line, "cpw") || ISINST (pl->line, "decw") || ISINST (pl->line, "incw") || ISINST (pl->line, "negw") || ISINST (pl->line, "sbcw") || ISINST (pl->line, "subw"))
+ if (lineIsInst (pl, "adcw") || lineIsInst (pl, "cpw") || lineIsInst (pl, "decw") || lineIsInst (pl, "incw") || lineIsInst (pl, "negw") || lineIsInst (pl, "sbcw") || lineIsInst (pl, "subw"))
return strcmp (what, "hf");
- if (ISINST (pl->line, "addw"))
+ if (lineIsInst (pl, "addw"))
{
const char *arg = leftArg (pl->line);
if (!strncmp (arg, "sp", 2))
@@ -682,14 +681,14 @@ f8SurelyWritesFlag (const lineNode *pl, const char *what)
else
return strcmp (what, "hf");
}
- if (ISINST (pl->line, "clrw") || ISINST (pl->line, "pushw"))
+ if (lineIsInst (pl, "clrw") || lineIsInst (pl, "pushw"))
return false;
- if (ISINST (pl->line, "orw"))
+ if (lineIsInst (pl, "orw"))
return (!strcmp (what, "of") || !strcmp (what, "zf") || !strcmp (what, "nf"));
- if (ISINST (pl->line, "tstw"))
+ if (lineIsInst (pl, "tstw"))
return strcmp (what, "hf");
// ld / ldw
- if (ISINST (pl->line, "ld") || ISINST (pl->line, "ldw"))
+ if (lineIsInst (pl, "ld") || lineIsInst (pl, "ldw"))
{
const char *rarg = rightArg (pl->line);
const char *rest = strstr (rarg, ", ");
@@ -699,31 +698,31 @@ f8SurelyWritesFlag (const lineNode *pl, const char *what)
return (!strcmp (what, "zf") || !strcmp (what, "nf"));
return false;
}
- if (ISINST (pl->line, "ldi") || ISINST (pl->line, "ldwi"))
+ if (lineIsInst (pl, "ldi") || lineIsInst (pl, "ldwi"))
return (!strcmp (what, "zf") || !strcmp (what, "nf"));
// 8-bit 0-op inst.
- if (ISINST (pl->line, "bool") || ISINST (pl->line, "cax"))
+ if (lineIsInst (pl, "bool") || lineIsInst (pl, "cax"))
return !strcmp (what, "zf");
- if (ISINST (pl->line, "daa") || ISINST (pl->line, "sra"))
+ if (lineIsInst (pl, "daa") || lineIsInst (pl, "sra"))
return (!strcmp (what, "zf") || !strcmp (what, "cf"));
- if (ISINST (pl->line, "mad"))
+ if (lineIsInst (pl, "mad"))
return (!strcmp (what, "zf") || !strcmp (what, "nf"));
- if (ISINST (pl->line, "msk") || ISINST (pl->line, "pop"))
+ if (lineIsInst (pl, "msk") || lineIsInst (pl, "pop"))
return false;
- if (ISINST (pl->line, "rot"))
+ if (lineIsInst (pl, "rot"))
return false;
- if (ISINST (pl->line, "xch"))
+ if (lineIsInst (pl, "xch"))
return leftArg (pl->line)[0] == 'f';
// 16-bit 0-op inst.
- if (ISINST (pl->line, "boolw") || ISINST (pl->line, "zex"))
+ if (lineIsInst (pl, "boolw") || lineIsInst (pl, "zex"))
return !strcmp (what, "zf");
- if (ISINST (pl->line, "incnw") || ISINST (pl->line, "popw") || ISINST (pl->line, "xchw"))
+ if (lineIsInst (pl, "incnw") || lineIsInst (pl, "popw") || lineIsInst (pl, "xchw"))
return false;
- if (ISINST (pl->line, "mul") || ISINST (pl->line, "sraw") || ISINST (pl->line, "srlw") || ISINST (pl->line, "rlcw") || ISINST (pl->line, "rrcw"))
+ if (lineIsInst (pl, "mul") || lineIsInst (pl, "sraw") || lineIsInst (pl, "srlw") || lineIsInst (pl, "rlcw") || lineIsInst (pl, "rrcw"))
return (!strcmp (what, "zf") || !strcmp (what, "nf") || !strcmp (what, "cf"));
- if (ISINST (pl->line, "sex"))
+ if (lineIsInst (pl, "sex"))
return (!strcmp (what, "zf") || !strcmp (what, "nf"));
- if (ISINST (pl->line, "sllw"))
+ if (lineIsInst (pl, "sllw"))
{
if (!strcmp (what, "zf") || !strcmp (what, "nf"))
return true;
@@ -731,20 +730,20 @@ f8SurelyWritesFlag (const lineNode *pl, const char *what)
return true;
return false;
}
- if (ISINST (pl->line, "xchb"))
+ if (lineIsInst (pl, "xchb"))
return !strcmp (what, "zf");
// jumps
if (STARTSINST (pl->line, "jr"))
return false;
- if (ISINST (pl->line, "jp")) // todo: improve accuracy by checking for function call vs. local jump.
+ if (lineIsInst (pl, "jp")) // todo: improve accuracy by checking for function call vs. local jump.
return false;
- if (ISINST (pl->line, "call"))
+ if (lineIsInst (pl, "call"))
return true;
- if (ISINST (pl->line, "ret"))
+ if (lineIsInst (pl, "ret"))
return true;
- if (ISINST (pl->line, "reti"))
+ if (lineIsInst (pl, "reti"))
return false;
- if (ISINST (pl->line, "nop"))
+ if (lineIsInst (pl, "nop"))
return false;
if (pl->ic)
@@ -771,28 +770,28 @@ f8SurelyWrites (const lineNode *pl, const char *what)
return (f8SurelyWritesFlag (pl, what));
// 8-bit 1/2-op inst, and some others.
- if (ISINST (pl->line, "push") || ISINST (pl->line, "tst"))
+ if (lineIsInst (pl, "push") || lineIsInst (pl, "tst"))
return false;
- if (ISINST (pl->line, "adc") || ISINST (pl->line, "add") || ISINST (pl->line, "and") || ISINST (pl->line, "bool") || ISINST (pl->line, "clr") || ISINST (pl->line, "dec") || ISINST (pl->line, "cp") || ISINST (pl->line, "inc") || ISINST (pl->line, "or") || ISINST (pl->line, "pop") || ISINST (pl->line, "rlc") || ISINST (pl->line, "rot") || ISINST (pl->line, "rrc") || ISINST (pl->line, "sbc") || ISINST (pl->line, "sub") || ISINST (pl->line, "sll") || ISINST (pl->line, "sra") || ISINST (pl->line, "srl") || ISINST (pl->line, "xor"))
+ if (lineIsInst (pl, "adc") || lineIsInst (pl, "add") || lineIsInst (pl, "and") || lineIsInst (pl, "bool") || lineIsInst (pl, "clr") || lineIsInst (pl, "dec") || lineIsInst (pl, "cp") || lineIsInst (pl, "inc") || lineIsInst (pl, "or") || lineIsInst (pl, "pop") || lineIsInst (pl, "rlc") || lineIsInst (pl, "rot") || lineIsInst (pl, "rrc") || lineIsInst (pl, "sbc") || lineIsInst (pl, "sub") || lineIsInst (pl, "sll") || lineIsInst (pl, "sra") || lineIsInst (pl, "srl") || lineIsInst (pl, "xor"))
{
const char *larg = leftArg (pl->line);
return (larg[0] == what[0] && larg[1] == what[1]);
}
// 16-bit 2/1-op inst, and some others.
- if (ISINST (pl->line, "pushw") || ISINST (pl->line, "tstw"))
+ if (lineIsInst (pl, "pushw") || lineIsInst (pl, "tstw"))
return false;
- if (ISINST (pl->line, "adcw") || ISINST (pl->line, "addw") || ISINST (pl->line, "boolw") || ISINST (pl->line, "clrw") || ISINST (pl->line, "cpw") || ISINST (pl->line, "decw") || ISINST (pl->line, "incw") || ISINST (pl->line, "mul") || ISINST (pl->line, "negw") || ISINST (pl->line, "orw") || ISINST (pl->line, "popw") || ISINST (pl->line, "rlcw") || ISINST (pl->line, "rrcw") || ISINST (pl->line, "sex") || ISINST (pl->line, "sllw") || ISINST (pl->line, "sraw") || ISINST (pl->line, "srlw") || ISINST (pl->line, "subw") || ISINST (pl->line, "sbcw") || ISINST (pl->line, "incnw") || ISINST (pl->line, "xorw") || ISINST (pl->line, "zex"))
+ if (lineIsInst (pl, "adcw") || lineIsInst (pl, "addw") || lineIsInst (pl, "boolw") || lineIsInst (pl, "clrw") || lineIsInst (pl, "cpw") || lineIsInst (pl, "decw") || lineIsInst (pl, "incw") || lineIsInst (pl, "mul") || lineIsInst (pl, "negw") || lineIsInst (pl, "orw") || lineIsInst (pl, "popw") || lineIsInst (pl, "rlcw") || lineIsInst (pl, "rrcw") || lineIsInst (pl, "sex") || lineIsInst (pl, "sllw") || lineIsInst (pl, "sraw") || lineIsInst (pl, "srlw") || lineIsInst (pl, "subw") || lineIsInst (pl, "sbcw") || lineIsInst (pl, "incnw") || lineIsInst (pl, "xorw") || lineIsInst (pl, "zex"))
{
const char *larg = leftArg (pl->line);
return (larg[0] == extra);
}
- if (ISINST (pl->line, "ld"))
+ if (lineIsInst (pl, "ld"))
return (pl->line[3] == what[0] && pl->line[4] == what[1]);
- if (ISINST (pl->line, "ldw"))
+ if (lineIsInst (pl, "ldw"))
return (pl->line[4] == extra);
- if (ISINST (pl->line, "ldi") || ISINST (pl->line, "ldwi"))
+ if (lineIsInst (pl, "ldi") || lineIsInst (pl, "ldwi"))
return false;
- if (ISINST (pl->line, "xch"))
+ if (lineIsInst (pl, "xch"))
{
const char *larg = leftArg (pl->line);
const char *rarg = rightArg (pl->line);
@@ -800,9 +799,9 @@ f8SurelyWrites (const lineNode *pl, const char *what)
}
if (STARTSINST (pl->line, "jr"))
return false;
- if (ISINST (pl->line, "jp") || ISINST (pl->line, "call"))
+ if (lineIsInst (pl, "jp") || lineIsInst (pl, "call"))
return false; // Todo: Improve accuracy?
- if (ISINST (pl->line, "ret") || ISINST (pl->line, "reti"))
+ if (lineIsInst (pl, "ret") || lineIsInst (pl, "reti"))
return true;
if (pl->ic)
@@ -975,11 +974,11 @@ bool
f8notUsed (const char *what, lineNode *endPl, lineNode *head)
{
lineNode *pl;
- if(!strcmp(what, "x"))
+ if (!strcmp(what, "x"))
return(f8notUsed("xl", endPl, head) && f8notUsed("xh", endPl, head));
- else if(!strcmp(what, "y"))
+ else if (!strcmp(what, "y"))
return(f8notUsed("yl", endPl, head) && f8notUsed("yh", endPl, head));
- else if(!strcmp(what, "z"))
+ else if (!strcmp(what, "z"))
return(f8notUsed("zl", endPl, head) && f8notUsed("zh", endPl, head));
// Only handle general-purpose registers and documented flags.
diff --git a/src/mos6502/peep.c b/src/mos6502/peep.c
index 0e3f0ff04..310b1b69b 100644
--- a/src/mos6502/peep.c
+++ b/src/mos6502/peep.c
@@ -8,8 +8,6 @@
// #define D(_s) { printf _s; fflush(stdout); }
#define D(_s)
-#define ISINST(l, i) (!STRNCASECMP((l), (i), sizeof(i) - 1) && (!(l)[sizeof(i) - 1] || isspace((unsigned char)((l)[sizeof(i) - 1]))))
-
typedef enum
{
S4O_CONDJMP,
@@ -95,22 +93,22 @@ findLabel (const lineNode *pl)
static bool
mos6502MightReadFlag(const lineNode *pl, const char *what)
{
- if (ISINST (pl->line, "adc") ||
- ISINST (pl->line, "rol") ||
- ISINST (pl->line, "ror") ||
- ISINST (pl->line, "sbc"))
+ if (lineIsInst (pl, "adc") ||
+ lineIsInst (pl, "rol") ||
+ lineIsInst (pl, "ror") ||
+ lineIsInst (pl, "sbc"))
return (!strcmp(what, "c"));
- if (ISINST (pl->line, "bcc") || ISINST (pl->line, "bcs"))
+ if (lineIsInst (pl, "bcc") || lineIsInst (pl, "bcs"))
return (!strcmp(what, "c"));
- if (ISINST (pl->line, "beq") || ISINST (pl->line, "bne"))
+ if (lineIsInst (pl, "beq") || lineIsInst (pl, "bne"))
return (!strcmp(what, "z"));
- if (ISINST (pl->line, "bmi") || ISINST (pl->line, "bpl"))
+ if (lineIsInst (pl, "bmi") || lineIsInst (pl, "bpl"))
return (!strcmp(what, "n"));
- if (ISINST (pl->line, "bvc") || ISINST (pl->line, "bvs"))
+ if (lineIsInst (pl, "bvc") || lineIsInst (pl, "bvs"))
return (!strcmp(what, "v"));
return false;
@@ -128,51 +126,51 @@ mos6502MightRead(const lineNode *pl, const char *what)
static bool
mos6502SurelyWritesFlag(const lineNode *pl, const char *what)
{
- if (ISINST (pl->line, "adc") ||
- ISINST (pl->line, "sbc"))
+ if (lineIsInst (pl, "adc") ||
+ lineIsInst (pl, "sbc"))
return (!strcmp(what, "n") || !strcmp(what, "z") || !strcmp(what, "c") || !strcmp(what, "v"));
- if (ISINST (pl->line, "asl") ||
- ISINST (pl->line, "cmp") ||
- ISINST (pl->line, "cpx") ||
- ISINST (pl->line, "cpy") ||
- ISINST (pl->line, "lsr") ||
- ISINST (pl->line, "rol") ||
- ISINST (pl->line, "ror"))
+ if (lineIsInst (pl, "asl") ||
+ lineIsInst (pl, "cmp") ||
+ lineIsInst (pl, "cpx") ||
+ lineIsInst (pl, "cpy") ||
+ lineIsInst (pl, "lsr") ||
+ lineIsInst (pl, "rol") ||
+ lineIsInst (pl, "ror"))
return (!strcmp(what, "n") || !strcmp(what, "z") || !strcmp(what, "c"));
- if (ISINST (pl->line, "and") ||
- ISINST (pl->line, "dec") ||
- ISINST (pl->line, "dex") ||
- ISINST (pl->line, "dey") ||
- ISINST (pl->line, "eor") ||
- ISINST (pl->line, "inc") ||
- ISINST (pl->line, "inx") ||
- ISINST (pl->line, "iny") ||
- ISINST (pl->line, "lda") ||
- ISINST (pl->line, "ldx") ||
- ISINST (pl->line, "ldy") ||
- ISINST (pl->line, "ora") ||
- ISINST (pl->line, "pla") ||
- ISINST (pl->line, "tax") ||
- ISINST (pl->line, "tay") ||
- ISINST (pl->line, "tsx") ||
- ISINST (pl->line, "tsa") ||
- ISINST (pl->line, "tya"))
+ if (lineIsInst (pl, "and") ||
+ lineIsInst (pl, "dec") ||
+ lineIsInst (pl, "dex") ||
+ lineIsInst (pl, "dey") ||
+ lineIsInst (pl, "eor") ||
+ lineIsInst (pl, "inc") ||
+ lineIsInst (pl, "inx") ||
+ lineIsInst (pl, "iny") ||
+ lineIsInst (pl, "lda") ||
+ lineIsInst (pl, "ldx") ||
+ lineIsInst (pl, "ldy") ||
+ lineIsInst (pl, "ora") ||
+ lineIsInst (pl, "pla") ||
+ lineIsInst (pl, "tax") ||
+ lineIsInst (pl, "tay") ||
+ lineIsInst (pl, "tsx") ||
+ lineIsInst (pl, "tsa") ||
+ lineIsInst (pl, "tya"))
return (!strcmp(what, "n") || !strcmp(what, "z"));
- if (ISINST (pl->line, "bit"))
+ if (lineIsInst (pl, "bit"))
return (!strcmp(what, "n") || !strcmp(what, "z") || !strcmp(what, "v"));
- if (ISINST (pl->line, "clc") ||
- ISINST (pl->line, "sec"))
+ if (lineIsInst (pl, "clc") ||
+ lineIsInst (pl, "sec"))
return (!strcmp(what, "c"));
- if (ISINST (pl->line, "clv"))
+ if (lineIsInst (pl, "clv"))
return (!strcmp(what, "v"));
- if (ISINST (pl->line, "plp") ||
- ISINST (pl->line, "rti"))
+ if (lineIsInst (pl, "plp") ||
+ lineIsInst (pl, "rti"))
return true;
return false;
@@ -191,22 +189,22 @@ mos6502SurelyWrites(const lineNode *pl, const char *what)
static bool
mos6502UncondJump (const lineNode *pl)
{
- return (ISINST (pl->line, "jmp"));
+ return (lineIsInst (pl, "jmp"));
}
static bool
mos6502CondJump (const lineNode *pl)
{
- return (ISINST (pl->line, "bpl") || ISINST (pl->line, "bmi") ||
- ISINST (pl->line, "bvc") || ISINST (pl->line, "bvs") ||
- ISINST (pl->line, "bcc") || ISINST (pl->line, "bcs") ||
- ISINST (pl->line, "bne") || ISINST (pl->line, "beq"));
+ return (lineIsInst (pl, "bpl") || lineIsInst (pl, "bmi") ||
+ lineIsInst (pl, "bvc") || lineIsInst (pl, "bvs") ||
+ lineIsInst (pl, "bcc") || lineIsInst (pl, "bcs") ||
+ lineIsInst (pl, "bne") || lineIsInst (pl, "beq"));
}
static bool
mos6502SurelyReturns (const lineNode *pl)
{
- return (ISINST (pl->line, "rts") || ISINST (pl->line, "rti") );
+ return (lineIsInst (pl, "rts") || lineIsInst (pl, "rti") );
}
/*-----------------------------------------------------------------*/
diff --git a/src/pdk/peep.c b/src/pdk/peep.c
index fe196a864..fe7a2403e 100644
--- a/src/pdk/peep.c
+++ b/src/pdk/peep.c
@@ -8,8 +8,6 @@
// #define D(_s) { printf _s; fflush(stdout); }
#define D(_s)
-#define ISINST(l, i) (!STRNCASECMP((l), (i), sizeof(i) - 1) && (!(l)[sizeof(i) - 1] || isspace((unsigned char)((l)[sizeof(i) - 1]))))
-
typedef enum
{
S4O_CONDJMP,
@@ -170,14 +168,14 @@ static bool argIs(const char *arg, const char *what)
static bool
pdkMightReadFlag(const lineNode *pl, const char *what)
{
- if (ISINST (pl->line, "push") && argIs (pl->line + 4, "af") || ISINST (pl->line, "pushaf"))
+ if (lineIsInst (pl, "push") && argIs (pl->line + 4, "af") || lineIsInst (pl, "pushaf"))
return true;
- if (ISINST (pl->line, "t0sn.io") || ISINST (pl->line, "t1sn.io"))
+ if (lineIsInst (pl, "t0sn.io") || lineIsInst (pl, "t1sn.io"))
return argIs(strchr (pl->line, ','), what);
- if(ISINST (pl->line, "addc") ||
- ISINST (pl->line, "subc"))
+ if(lineIsInst (pl, "addc") ||
+ lineIsInst (pl, "subc"))
return !strcmp(what, "c");
return false;
@@ -193,64 +191,64 @@ pdkMightRead (const lineNode *pl, const char *what)
return true;
// Instructions that never read anything.
- if (ISINST (pl->line, "clear") ||
- ISINST (pl->line, "engint") ||
- ISINST (pl->line, "disgint") ||
- ISINST (pl->line, "goto") ||
- ISINST (pl->line, "nop") ||
- ISINST (pl->line, "pop") || ISINST (pl->line, "popaf") ||
- ISINST (pl->line, "set0.io") || ISINST (pl->line, "set1.io") ||
- ISINST (pl->line, "stopsys") ||
- ISINST (pl->line, "t0sn.io") || ISINST (pl->line, "t1sn.io") || // They read I/O (maybe flags) but neither a nor p.
- ISINST (pl->line, "wdreset"))
+ if (lineIsInst (pl, "clear") ||
+ lineIsInst (pl, "engint") ||
+ lineIsInst (pl, "disgint") ||
+ lineIsInst (pl, "goto") ||
+ lineIsInst (pl, "nop") ||
+ lineIsInst (pl, "pop") || lineIsInst (pl, "popaf") ||
+ lineIsInst (pl, "set0.io") || lineIsInst (pl, "set1.io") ||
+ lineIsInst (pl, "stopsys") ||
+ lineIsInst (pl, "t0sn.io") || lineIsInst (pl, "t1sn.io") || // They read I/O (maybe flags) but neither a nor p.
+ lineIsInst (pl, "wdreset"))
return false;
- if (ISINST (pl->line, "ret") && strchr (pl->line + 2, '#') && !strcmp (what, "a"))
+ if (lineIsInst (pl, "ret") && strchr (pl->line + 2, '#') && !strcmp (what, "a"))
return false;
- if (ISINST (pl->line, "ret"))
+ if (lineIsInst (pl, "ret"))
return isReturned(what);
- if (ISINST (pl->line, "mov") ||
- ISINST (pl->line, "mov.io"))
+ if (lineIsInst (pl, "mov") ||
+ lineIsInst (pl, "mov.io"))
return argIs (strchr (pl->line, ','), what);
- if (ISINST (pl->line, "push") && argIs (pl->line + 4, "af") || ISINST (pl->line, "pushaf"))
+ if (lineIsInst (pl, "push") && argIs (pl->line + 4, "af") || lineIsInst (pl, "pushaf"))
return !strcmp(what, "a");
// Two-operand instructions that read both operands
- if (ISINST (pl->line, "add") ||
- ISINST (pl->line, "and") ||
- ISINST (pl->line, "or") ||
- ISINST (pl->line, "sub") ||
- ISINST (pl->line, "xch") ||
- ISINST (pl->line, "xor"))
+ if (lineIsInst (pl, "add") ||
+ lineIsInst (pl, "and") ||
+ lineIsInst (pl, "or") ||
+ lineIsInst (pl, "sub") ||
+ lineIsInst (pl, "xch") ||
+ lineIsInst (pl, "xor"))
return argIs (pl->line + 3, what) || argIs (strchr (pl->line, ','), what);
- if (ISINST(pl->line, "idxm"))
+ if (lineIsInst (pl, "idxm"))
return argIs (pl->line + 4, what) || argIs (strchr (pl->line, ','), what);
- if (ISINST (pl->line, "ceqsn") ||
- ISINST (pl->line, "cneqsn") ||
- ISINST (pl->line, "xor.io"))
+ if (lineIsInst (pl, "ceqsn") ||
+ lineIsInst (pl, "cneqsn") ||
+ lineIsInst (pl, "xor.io"))
return argIs (pl->line + 6, what) || argIs (strchr (pl->line, ','), what);
// One-operand instructions
- if (ISINST (pl->line, "dec") ||
- ISINST (pl->line, "inc") ||
- ISINST (pl->line, "neg") ||
- ISINST (pl->line, "not") ||
- ISINST (pl->line, "sl") ||
- ISINST (pl->line, "slc") ||
- ISINST (pl->line, "sr") ||
- ISINST (pl->line, "src"))
+ if (lineIsInst (pl, "dec") ||
+ lineIsInst (pl, "inc") ||
+ lineIsInst (pl, "neg") ||
+ lineIsInst (pl, "not") ||
+ lineIsInst (pl, "sl") ||
+ lineIsInst (pl, "slc") ||
+ lineIsInst (pl, "sr") ||
+ lineIsInst (pl, "src"))
return argIs (pl->line + 3, what);
- if (ISINST (pl->line, "addc") && !strchr (pl->line + 4, ',') || // addc a / addc M
- ISINST (pl->line, "set0") || ISINST (pl->line, "set1") || // Technically two-operand, but second operand is a literal
- ISINST (pl->line, "subc") && !strchr (pl->line + 4, ',') || // subc a / subc M)
- ISINST (pl->line, "swap"))
+ if (lineIsInst (pl, "addc") && !strchr (pl->line + 4, ',') || // addc a / addc M
+ lineIsInst (pl, "set0") || lineIsInst (pl, "set1") || // Technically two-operand, but second operand is a literal
+ lineIsInst (pl, "subc") && !strchr (pl->line + 4, ',') || // subc a / subc M)
+ lineIsInst (pl, "swap"))
return argIs (pl->line + 4, what);
- if (ISINST (pl->line, "dzsn") ||
- ISINST (pl->line, "izsn") ||
- ISINST (pl->line, "pcadd") ||
- ISINST (pl->line, "stt16"))
+ if (lineIsInst (pl, "dzsn") ||
+ lineIsInst (pl, "izsn") ||
+ lineIsInst (pl, "pcadd") ||
+ lineIsInst (pl, "stt16"))
return argIs (pl->line + 5, what);
return true; // Fail-safe: we have no idea what happens at this line, so assume it might read anything.
@@ -259,59 +257,59 @@ pdkMightRead (const lineNode *pl, const char *what)
static bool
pdkSurelyWritesFlag(const lineNode *pl, const char *what)
{
- if (ISINST (pl->line, "pop") && argIs (pl->line + 4, "af") || ISINST (pl->line, "popaf"))
+ if (lineIsInst (pl, "pop") && argIs (pl->line + 4, "af") || lineIsInst (pl, "popaf"))
return true;
// Instructions that write all flags
- if (ISINST (pl->line, "add") ||
- ISINST (pl->line, "addc") ||
- ISINST (pl->line, "ceqsn") ||
- ISINST (pl->line, "cneqsn") ||
- ISINST (pl->line, "dec") ||
- ISINST (pl->line, "dzsn") ||
- ISINST (pl->line, "inc") ||
- ISINST (pl->line, "izsn") ||
- ISINST (pl->line, "sub") ||
- ISINST (pl->line, "subc"))
+ if (lineIsInst (pl, "add") ||
+ lineIsInst (pl, "addc") ||
+ lineIsInst (pl, "ceqsn") ||
+ lineIsInst (pl, "cneqsn") ||
+ lineIsInst (pl, "dec") ||
+ lineIsInst (pl, "dzsn") ||
+ lineIsInst (pl, "inc") ||
+ lineIsInst (pl, "izsn") ||
+ lineIsInst (pl, "sub") ||
+ lineIsInst (pl, "subc"))
return true;
// Instructions that write c only
- if (ISINST (pl->line, "sl") ||
- ISINST (pl->line, "slc") ||
- ISINST (pl->line, "sr") ||
- ISINST (pl->line, "src") ||
- ISINST (pl->line, "swapc.io"))
+ if (lineIsInst (pl, "sl") ||
+ lineIsInst (pl, "slc") ||
+ lineIsInst (pl, "sr") ||
+ lineIsInst (pl, "src") ||
+ lineIsInst (pl, "swapc.io"))
return !strcmp(what, "c");
// Instructions that write z only
- if (ISINST (pl->line, "and") ||
- ISINST (pl->line, "neg") ||
- ISINST (pl->line, "not") ||
- ISINST (pl->line, "or") ||
- ISINST (pl->line, "xor") ||
- ISINST (pl->line, "xor.io"))
+ if (lineIsInst (pl, "and") ||
+ lineIsInst (pl, "neg") ||
+ lineIsInst (pl, "not") ||
+ lineIsInst (pl, "or") ||
+ lineIsInst (pl, "xor") ||
+ lineIsInst (pl, "xor.io"))
return !strcmp(what, "z");
// mov writes z iff the destination is a and the source not an immediate.
if (!strcmp(what, "z") && !strchr(pl->line, '#'))
{
- if ( (ISINST (pl->line, "mov") && pl->line[4] == 'a' && pl->line[5] == ',') ||
- (ISINST (pl->line, "mov.io") && pl->line[7] == 'a' && pl->line[8] == ','))
+ if ( (lineIsInst (pl, "mov") && pl->line[4] == 'a' && pl->line[5] == ',') ||
+ (lineIsInst (pl, "mov.io") && pl->line[7] == 'a' && pl->line[8] == ','))
return true;
}
- if (ISINST (pl->line, "mov") || ISINST (pl->line, "mov.io") ||
- ISINST (pl->line, "clear") ||
- ISINST (pl->line, "goto") ||
- ISINST (pl->line, "t0sn") || ISINST (pl->line, "t0sn.io") ||
- ISINST (pl->line, "t1sn") || ISINST (pl->line, "t1sn.io") ||
- ISINST (pl->line, "xch") ||
- ISINST (pl->line, "swap") ||
- ISINST (pl->line, "idxm"))
+ if (lineIsInst (pl, "mov") || lineIsInst (pl, "mov.io") ||
+ lineIsInst (pl, "clear") ||
+ lineIsInst (pl, "goto") ||
+ lineIsInst (pl, "t0sn") || lineIsInst (pl, "t0sn.io") ||
+ lineIsInst (pl, "t1sn") || lineIsInst (pl, "t1sn.io") ||
+ lineIsInst (pl, "xch") ||
+ lineIsInst (pl, "swap") ||
+ lineIsInst (pl, "idxm"))
return false;
// By calling convention, caller has to save flags.
- if (ISINST (pl->line, "ret") || ISINST (pl->line, "call"))
+ if (lineIsInst (pl, "ret") || lineIsInst (pl, "call"))
return true;
return false; // Fail-safe: we have no idea what happens at this line, so assume it writes nothing.
@@ -323,43 +321,43 @@ pdkSurelyWrites(const lineNode *pl, const char *what)
if (!strcmp(what, "z") || !strcmp(what, "c") || !strcmp(what, "ac") || !strcmp(what, "ov"))
return (pdkSurelyWritesFlag(pl, what));
- if (ISINST (pl->line, "mov") || ISINST (pl->line, "idxm") ||
- ISINST (pl->line, "set1") ||
- ISINST (pl->line, "set0"))
+ if (lineIsInst (pl, "mov") || lineIsInst (pl, "idxm") ||
+ lineIsInst (pl, "set1") ||
+ lineIsInst (pl, "set0"))
return argIs (pl->line + 4, what);
- if (ISINST(pl->line, "mov.io") ||
- ISINST (pl->line, "set1.io") ||
- ISINST (pl->line, "set0.io"))
+ if (lineIsInst (pl, "mov.io") ||
+ lineIsInst (pl, "set1.io") ||
+ lineIsInst (pl, "set0.io"))
return argIs (pl->line + 7, what);
- if (ISINST (pl->line, "swapc.io"))
+ if (lineIsInst (pl, "swapc.io"))
return argIs (pl->line + 9, what);
- if (ISINST (pl->line, "pop") && argIs (pl->line + 4, "af") || ISINST (pl->line, "popaf"))
+ if (lineIsInst (pl, "pop") && argIs (pl->line + 4, "af") || lineIsInst (pl, "popaf"))
return !strcmp (what, "a");
// Instructions that never write anything
- if (ISINST (pl->line, "ceqsn") || ISINST (pl->line, "cneqsn") || // Might write flags, but nothing else.
- ISINST (pl->line, "goto") ||
- ISINST (pl->line, "t0sn") || ISINST (pl->line, "t0sn.io") ||
- ISINST (pl->line, "t1sn") || ISINST (pl->line, "t1sn.io"))
+ if (lineIsInst (pl, "ceqsn") || lineIsInst (pl, "cneqsn") || // Might write flags, but nothing else.
+ lineIsInst (pl, "goto") ||
+ lineIsInst (pl, "t0sn") || lineIsInst (pl, "t0sn.io") ||
+ lineIsInst (pl, "t1sn") || lineIsInst (pl, "t1sn.io"))
return false;
// One-operand instructions that write their argument
- if (ISINST (pl->line, "neg") ||
- ISINST (pl->line, "not") ||
- ISINST (pl->line, "inc") ||
- ISINST (pl->line, "dec") ||
- ISINST (pl->line, "xch") ||
- ISINST (pl->line, "not") ||
- ISINST (pl->line, "sl") ||
- ISINST (pl->line, "slc") ||
- ISINST (pl->line, "sr") ||
- ISINST (pl->line, "src"))
+ if (lineIsInst (pl, "neg") ||
+ lineIsInst (pl, "not") ||
+ lineIsInst (pl, "inc") ||
+ lineIsInst (pl, "dec") ||
+ lineIsInst (pl, "xch") ||
+ lineIsInst (pl, "not") ||
+ lineIsInst (pl, "sl") ||
+ lineIsInst (pl, "slc") ||
+ lineIsInst (pl, "sr") ||
+ lineIsInst (pl, "src"))
return argIs (pl->line + 3, what);
- if (ISINST (pl->line, "dzsn") ||
- ISINST (pl->line, "clear") ||
- ISINST (pl->line, "izsn") ||
- ISINST (pl->line, "ldt16"))
+ if (lineIsInst (pl, "dzsn") ||
+ lineIsInst (pl, "clear") ||
+ lineIsInst (pl, "izsn") ||
+ lineIsInst (pl, "ldt16"))
return argIs (pl->line + 5, what);
return false;
@@ -369,22 +367,22 @@ pdkSurelyWrites(const lineNode *pl, const char *what)
static bool
pdkUncondJump(const lineNode *pl)
{
- return (ISINST(pl->line, "goto") || ISINST(pl->line, "pcadd"));
+ return (lineIsInst (pl, "goto") || lineIsInst (pl, "pcadd"));
}
static bool
pdkCondJump(const lineNode *pl)
{
- return (ISINST(pl->line, "ceqsn") || ISINST(pl->line, "cneqsn") ||
- ISINST(pl->line, "t0sn") || ISINST(pl->line, "t1sn") ||
- ISINST(pl->line, "t0sn.io") || ISINST(pl->line, "t1sn.io") ||
- ISINST(pl->line, "izsn") || ISINST(pl->line, "dzsn"));
+ return (lineIsInst (pl, "ceqsn") || lineIsInst (pl, "cneqsn") ||
+ lineIsInst (pl, "t0sn") || lineIsInst (pl, "t1sn") ||
+ lineIsInst (pl, "t0sn.io") || lineIsInst (pl, "t1sn.io") ||
+ lineIsInst (pl, "izsn") || lineIsInst (pl, "dzsn"));
}
static bool
pdkSurelyReturns(const lineNode *pl)
{
- return(ISINST(pl->line, "ret") || ISINST(pl->line, "reti") );
+ return(lineIsInst (pl, "ret") || lineIsInst (pl, "reti") );
}
/*-----------------------------------------------------------------*/
diff --git a/src/stm8/peep.c b/src/stm8/peep.c
index 01a951321..0bc8debcf 100644
--- a/src/stm8/peep.c
+++ b/src/stm8/peep.c
@@ -12,7 +12,6 @@
#define D(_s)
#define EQUALS(l, i) (!STRCASECMP((l), (i)))
-#define ISINST(l, i) (!STRNCASECMP((l), (i), sizeof(i) - 1) && (!(l)[sizeof(i) - 1] || isspace((unsigned char)((l)[sizeof(i) - 1]))))
#define STARTSINST(l, i) (!STRNCASECMP((l), (i), sizeof(i) - 1))
typedef enum
@@ -285,52 +284,52 @@ stm8instructionSize(lineNode *pl)
//printf("line=%s operand=%s op1start=%s op2start=%s\n", pl->line, operand, op1start, op2start);
/* Operations that always costs 1 byte */
- if (ISINST(operand, "ccf")
- || ISINST(operand, "divw")
- || ISINST(operand, "exgw")
- || ISINST(operand, "iret")
- || ISINST(operand, "nop")
- || ISINST(operand, "rcf")
- || ISINST(operand, "ret")
- || ISINST(operand, "retf")
- || ISINST(operand, "rvf")
- || ISINST(operand, "break")
- || ISINST(operand, "halt")
- || ISINST(operand, "rim")
- || ISINST(operand, "trap")
- || ISINST(operand, "wfi")
- || ISINST(operand, "sim")
- || ISINST(operand, "scf"))
+ if (lineIsInst (pl, "ccf")
+ || lineIsInst (pl, "divw")
+ || lineIsInst (pl, "exgw")
+ || lineIsInst (pl, "iret")
+ || lineIsInst (pl, "nop")
+ || lineIsInst (pl, "rcf")
+ || lineIsInst (pl, "ret")
+ || lineIsInst (pl, "retf")
+ || lineIsInst (pl, "rvf")
+ || lineIsInst (pl, "break")
+ || lineIsInst (pl, "halt")
+ || lineIsInst (pl, "rim")
+ || lineIsInst (pl, "trap")
+ || lineIsInst (pl, "wfi")
+ || lineIsInst (pl, "sim")
+ || lineIsInst (pl, "scf"))
return 1;
/* Operations that always costs 3 byte */
- if(ISINST(operand, "jrh")
- || ISINST(operand, "jrnh")
- || ISINST(operand, "jril")
- || ISINST(operand, "jrih")
- || ISINST(operand, "jrm")
- || ISINST(operand, "jrnm"))
+ if(lineIsInst (pl, "jrh")
+ || lineIsInst (pl, "jrnh")
+ || lineIsInst (pl, "jril")
+ || lineIsInst (pl, "jrih")
+ || lineIsInst (pl, "jrm")
+ || lineIsInst (pl, "jrnm"))
return 3;
/* Operations that always costs 2 byte */
if(STARTSINST(operand, "jr")
- || ISINST(operand, "callr")
- || ISINST(operand, "wfe"))
+ || lineIsInst (pl, "callr")
+ || lineIsInst (pl, "wfe"))
return 2;
/* Operations that always costs 4 byte */
- if(ISINST(operand, "bccm")
- || ISINST(operand, "bcpl")
- || ISINST(operand, "bres")
- || ISINST(operand, "bset")
- || ISINST(operand, "callf")
- || ISINST(operand, "int")
- || ISINST(operand, "jpf"))
+ if(lineIsInst (pl, "bccm")
+ || lineIsInst (pl, "bcpl")
+ || lineIsInst (pl, "bres")
+ || lineIsInst (pl, "bset")
+ || lineIsInst (pl, "callf")
+ || lineIsInst (pl, "int")
+ || lineIsInst (pl, "jpf"))
return 4;
/* Operations that always costs 5 byte */
- if(ISINST(operand, "btjf")
- || ISINST(operand, "btjt"))
+ if(lineIsInst (pl, "btjf")
+ || lineIsInst (pl, "btjt"))
return 5;
if (EQUALS(operand, "push")
@@ -375,14 +374,14 @@ stm8instructionSize(lineNode *pl)
op1start++;
if(strstr(op1start, ",y)"))
i++; // costs extra byte for operating with y
- if ((ISINST(operand, "jp") || ISINST(operand, "call")) && *op1start != '(' && *op1start != '[') // jp and call are 3 bytes for direct long addressing mode.
+ if ((lineIsInst (pl, "jp") || lineIsInst (pl, "call")) && *op1start != '(' && *op1start != '[') // jp and call are 3 bytes for direct long addressing mode.
return(3);
if(isLabel(op1start))
return(4);
if(readint(op1start) <= 0xFF)
return(2+i);
/* op1 > 0xFF */
- if((ISINST(operand, "jp") || ISINST(operand, "call")) && !strchr(op1start, 'y'))
+ if((lineIsInst (pl, "jp") || lineIsInst (pl, "call")) && !strchr(op1start, 'y'))
return(3);
return(4);
}
@@ -410,7 +409,7 @@ stm8instructionSize(lineNode *pl)
return(4);
}
- if(ISINST(operand, "cplw"))
+ if(lineIsInst (pl, "cplw"))
{
assert (op1start != NULL);
if(op1start[0] == 'y')
@@ -419,7 +418,7 @@ stm8instructionSize(lineNode *pl)
return(1);
}
- if(ISINST(operand, "ldf"))
+ if(lineIsInst (pl, "ldf"))
{
assert (op1start != NULL);
if(isRelativeAddr(op1start, "y") || isRelativeAddr(op2start, "y"))
@@ -489,7 +488,7 @@ stm8instructionSize(lineNode *pl)
}
/* mov costs 3, 4 or 5 bytes depending on its addressing mode */
- if(ISINST(operand, "mov")) {
+ if(lineIsInst (pl, "mov")) {
assert (op1start != NULL && op2start != NULL);
if(isImmediate(op2start))
return(4);
@@ -529,14 +528,14 @@ stm8instructionSize(lineNode *pl)
return(1);
}
- if(ISINST(pl->line, ".db") || ISINST(pl->line, ".byte"))
+ if(lineIsInst (pl, ".db") || lineIsInst (pl, ".byte"))
{
int i, j;
for(i = 1, j = 0; pl->line[j]; i += pl->line[j] == ',', j++);
return(i);
}
- if(ISINST(pl->line, ".dw") || ISINST(pl->line, ".word"))
+ if(lineIsInst (pl, ".dw") || lineIsInst (pl, ".word"))
{
int i, j;
for(i = 1, j = 0; pl->line[j]; i += pl->line[j] == ',', j++);
@@ -656,22 +655,22 @@ stm8MightReadFlag(const lineNode *pl, const char *what)
if (strcmp (what, "v") && strcmp (what, "c") && strcmp (what, "n") && strcmp (what, "z"))
return true;
- if (ISINST (pl->line, "push"))
+ if (lineIsInst (pl, "push"))
return (pl->line[5] == 'c');
if (!strcmp (what, "v"))
- return (ISINST (pl->line, "jrnv") || ISINST (pl->line, "jrsge") || ISINST (pl->line, "jrsgt") || ISINST (pl->line, "jrsle") || ISINST (pl->line, "jrslt") || ISINST (pl->line, "jrv"));
+ return (lineIsInst (pl, "jrnv") || lineIsInst (pl, "jrsge") || lineIsInst (pl, "jrsgt") || lineIsInst (pl, "jrsle") || lineIsInst (pl, "jrslt") || lineIsInst (pl, "jrv"));
if (!strcmp (what, "n"))
- return (ISINST (pl->line, "jrmi") || ISINST (pl->line, "jrpl") || ISINST (pl->line, "jrsge") || ISINST (pl->line, "jrsgt") || ISINST (pl->line, "jrsle") || ISINST (pl->line, "jrslt"));
+ return (lineIsInst (pl, "jrmi") || lineIsInst (pl, "jrpl") || lineIsInst (pl, "jrsge") || lineIsInst (pl, "jrsgt") || lineIsInst (pl, "jrsle") || lineIsInst (pl, "jrslt"));
if (!strcmp (what, "z"))
- return (ISINST (pl->line, "jreq") || ISINST (pl->line, "jrne") || ISINST (pl->line, "jrsgt") || ISINST (pl->line, "jrsle"));
+ return (lineIsInst (pl, "jreq") || lineIsInst (pl, "jrne") || lineIsInst (pl, "jrsgt") || lineIsInst (pl, "jrsle"));
if (!strcmp (what, "c"))
- return (ISINST (pl->line, "jrc") || ISINST (pl->line, "jrnc") || ISINST (pl->line, "jruge") || ISINST (pl->line, "jrugt") || ISINST (pl->line, "jrule") || ISINST (pl->line, "jrult") ||
- ISINST (pl->line, "adc") || ISINST (pl->line, "sbc") ||
- ISINST (pl->line, "ccf") || ISINST (pl->line, "rlc") || ISINST (pl->line, "rlcw") || ISINST (pl->line, "rrc") || ISINST (pl->line, "rrcw"));
+ return (lineIsInst (pl, "jrc") || lineIsInst (pl, "jrnc") || lineIsInst (pl, "jruge") || lineIsInst (pl, "jrugt") || lineIsInst (pl, "jrule") || lineIsInst (pl, "jrult") ||
+ lineIsInst (pl, "adc") || lineIsInst (pl, "sbc") ||
+ lineIsInst (pl, "ccf") || lineIsInst (pl, "rlc") || lineIsInst (pl, "rlcw") || lineIsInst (pl, "rrc") || lineIsInst (pl, "rrcw"));
return true;
}
@@ -728,113 +727,113 @@ stm8MightRead(const lineNode *pl, const char *what)
if (!extra)
{
- if (ISINST (pl->line, "adc")
- || ISINST (pl->line, "and")
- || ISINST (pl->line, "bcp")
- || ISINST (pl->line, "cp")
- || ISINST (pl->line, "div")
- || ISINST (pl->line, "mul")
- || ISINST (pl->line, "or")
- || ISINST (pl->line, "rlwa")
- || ISINST (pl->line, "rrwa")
- || ISINST (pl->line, "sbc")
- || ISINST (pl->line, "trap")
- || ISINST (pl->line, "xor"))
+ if (lineIsInst (pl, "adc")
+ || lineIsInst (pl, "and")
+ || lineIsInst (pl, "bcp")
+ || lineIsInst (pl, "cp")
+ || lineIsInst (pl, "div")
+ || lineIsInst (pl, "mul")
+ || lineIsInst (pl, "or")
+ || lineIsInst (pl, "rlwa")
+ || lineIsInst (pl, "rrwa")
+ || lineIsInst (pl, "sbc")
+ || lineIsInst (pl, "trap")
+ || lineIsInst (pl, "xor"))
return TRUE;
- if ((ISINST (pl->line, "add")
- || ISINST (pl->line, "cpl")
- || ISINST (pl->line, "dec")
- || ISINST (pl->line, "exg")
- || ISINST (pl->line, "inc")
- || ISINST (pl->line, "neg")
- || ISINST (pl->line, "rlc")
- || ISINST (pl->line, "rrc")
- || ISINST (pl->line, "sll")
- || ISINST (pl->line, "sla")
- || ISINST (pl->line, "sra")
- || ISINST (pl->line, "srl")
- || ISINST (pl->line, "sub")
- || ISINST (pl->line, "tnz")) &&
+ if ((lineIsInst (pl, "add")
+ || lineIsInst (pl, "cpl")
+ || lineIsInst (pl, "dec")
+ || lineIsInst (pl, "exg")
+ || lineIsInst (pl, "inc")
+ || lineIsInst (pl, "neg")
+ || lineIsInst (pl, "rlc")
+ || lineIsInst (pl, "rrc")
+ || lineIsInst (pl, "sll")
+ || lineIsInst (pl, "sla")
+ || lineIsInst (pl, "sra")
+ || lineIsInst (pl, "srl")
+ || lineIsInst (pl, "sub")
+ || lineIsInst (pl, "tnz")) &&
pl->line[4] == 'a')
return TRUE;
- if ((ISINST (pl->line, "push")
- || ISINST (pl->line, "swap")) &&
+ if ((lineIsInst (pl, "push")
+ || lineIsInst (pl, "swap")) &&
pl->line[5] == 'a')
return TRUE;
- if ((ISINST (pl->line, "ld") || ISINST (pl->line, "ldf")) && argCont (strchr (pl->line, ','), 'a'))
+ if ((lineIsInst (pl, "ld") || lineIsInst (pl, "ldf")) && argCont (strchr (pl->line, ','), 'a'))
return TRUE;
}
else
{
- if (ISINST (pl->line, "divw") || ISINST (pl->line, "exgw") || ISINST (pl->line, "trap"))
+ if (lineIsInst (pl, "divw") || lineIsInst (pl, "exgw") || lineIsInst (pl, "trap"))
return TRUE;
- if (ISINST (pl->line, "exg") && strstr (strchr(pl->line, ','), what))
+ if (lineIsInst (pl, "exg") && strstr (strchr(pl->line, ','), what))
return true;
- if ((ISINST (pl->line, "div") || ISINST (pl->line, "mul")) && pl->line[4] == extra)
+ if ((lineIsInst (pl, "div") || lineIsInst (pl, "mul")) && pl->line[4] == extra)
return true;
- if ((ISINST (pl->line, "addw")
- || ISINST (pl->line, "cplw")
- || ISINST (pl->line, "decw")
- || ISINST (pl->line, "incw")
- || ISINST (pl->line, "negw")
- || ISINST (pl->line, "rlcw")
- || ISINST (pl->line, "rlwa")
- || ISINST (pl->line, "rrcw")
- || ISINST (pl->line, "rrwa")
- || ISINST (pl->line, "sllw")
- || ISINST (pl->line, "slaw")
- || ISINST (pl->line, "sraw")
- || ISINST (pl->line, "srlw")
- || ISINST (pl->line, "subw")
- || ISINST (pl->line, "tnzw")) &&
+ if ((lineIsInst (pl, "addw")
+ || lineIsInst (pl, "cplw")
+ || lineIsInst (pl, "decw")
+ || lineIsInst (pl, "incw")
+ || lineIsInst (pl, "negw")
+ || lineIsInst (pl, "rlcw")
+ || lineIsInst (pl, "rlwa")
+ || lineIsInst (pl, "rrcw")
+ || lineIsInst (pl, "rrwa")
+ || lineIsInst (pl, "sllw")
+ || lineIsInst (pl, "slaw")
+ || lineIsInst (pl, "sraw")
+ || lineIsInst (pl, "srlw")
+ || lineIsInst (pl, "subw")
+ || lineIsInst (pl, "tnzw")) &&
pl->line[5] == extra)
return TRUE;
- if ((ISINST (pl->line, "pushw")
- || ISINST (pl->line, "swapw")) && pl->line[6] == extra)
+ if ((lineIsInst (pl, "pushw")
+ || lineIsInst (pl, "swapw")) && pl->line[6] == extra)
return TRUE;
- if (ISINST (pl->line, "cpw") && pl->line[4] == extra)
+ if (lineIsInst (pl, "cpw") && pl->line[4] == extra)
return TRUE;
if ((strchr (pl->line, ',') ? argCont (strchr (pl->line, ','), extra) : argCont (strchr (pl->line, '('), extra)) &&
- (ISINST (pl->line, "adc")
- || ISINST (pl->line, "add")
- || ISINST (pl->line, "and")
- || ISINST (pl->line, "bcp")
- || ISINST (pl->line, "call")
- || ISINST (pl->line, "clr")
- || ISINST (pl->line, "cp")
- || ISINST (pl->line, "cpl")
- || ISINST (pl->line, "dec")
- || ISINST (pl->line, "inc")
- || ISINST (pl->line, "jp")
- || ISINST (pl->line, "neg")
- || ISINST (pl->line, "or")
- || ISINST (pl->line, "rlc")
- || ISINST (pl->line, "rrc")
- || ISINST (pl->line, "sbc")
- || ISINST (pl->line, "sll")
- || ISINST (pl->line, "sla")
- || ISINST (pl->line, "sra")
- || ISINST (pl->line, "srl")
- || ISINST (pl->line, "sub")
- || ISINST (pl->line, "swap")
- || ISINST (pl->line, "tnz")
- || ISINST (pl->line, "cpw")
- || ISINST (pl->line, "ldf")
- || ISINST (pl->line, "ldw")
- || ISINST (pl->line, "ld")
- || ISINST (pl->line, "xor")))
+ (lineIsInst (pl, "adc")
+ || lineIsInst (pl, "add")
+ || lineIsInst (pl, "and")
+ || lineIsInst (pl, "bcp")
+ || lineIsInst (pl, "call")
+ || lineIsInst (pl, "clr")
+ || lineIsInst (pl, "cp")
+ || lineIsInst (pl, "cpl")
+ || lineIsInst (pl, "dec")
+ || lineIsInst (pl, "inc")
+ || lineIsInst (pl, "jp")
+ || lineIsInst (pl, "neg")
+ || lineIsInst (pl, "or")
+ || lineIsInst (pl, "rlc")
+ || lineIsInst (pl, "rrc")
+ || lineIsInst (pl, "sbc")
+ || lineIsInst (pl, "sll")
+ || lineIsInst (pl, "sla")
+ || lineIsInst (pl, "sra")
+ || lineIsInst (pl, "srl")
+ || lineIsInst (pl, "sub")
+ || lineIsInst (pl, "swap")
+ || lineIsInst (pl, "tnz")
+ || lineIsInst (pl, "cpw")
+ || lineIsInst (pl, "ldf")
+ || lineIsInst (pl, "ldw")
+ || lineIsInst (pl, "ld")
+ || lineIsInst (pl, "xor")))
return TRUE;
- if (ISINST (pl->line, "ld") || ISINST (pl->line, "ldw"))
+ if (lineIsInst (pl, "ld") || lineIsInst (pl, "ldw"))
{
char buf[128], *p;
if (strlen (pl->line) >= 128) // Avoid buffer overflow, err on safe side.
@@ -847,19 +846,19 @@ stm8MightRead(const lineNode *pl, const char *what)
}
}
- if (ISINST (pl->line, "call") || ISINST (pl->line, "callr") || ISINST (pl->line, "callf"))
+ if (lineIsInst (pl, "call") || lineIsInst (pl, "callr") || lineIsInst (pl, "callf"))
{
- const symbol *f = findSym (SymbolTab, 0, pl->line + (ISINST (pl->line, "call") ? 6 : 7));
+ const symbol *f = findSym (SymbolTab, 0, pl->line + (lineIsInst (pl, "call") ? 6 : 7));
if (f && IS_FUNC (f->type))
return stm8IsParmInCall(f->type, what);
else // Fallback needed for calls through function pointers and for calls to literal addresses.
return (stm8MightBeParmInCallFromCurrentFunction(what) || stm8MightBeParmInPCallFromCurrentFunction(what));
}
- if(ISINST(pl->line, "ret")) // IAR calling convention uses ret for some calls via pointers
+ if(lineIsInst (pl, "ret")) // IAR calling convention uses ret for some calls via pointers
return(stm8IsReturned(what) || stm8MightBeParmInPCallFromCurrentFunction(what));
- if(ISINST(pl->line, "retf")) // Large model uses retf for calls via function pointers
+ if(lineIsInst (pl, "retf")) // Large model uses retf for calls via function pointers
return(stm8IsReturned(what) || stm8MightBeParmInPCallFromCurrentFunction(what));
return FALSE;
@@ -868,72 +867,72 @@ stm8MightRead(const lineNode *pl, const char *what)
static bool
stm8UncondJump(const lineNode *pl)
{
- return (ISINST(pl->line, "jp") || ISINST(pl->line, "jra") || ISINST(pl->line, "jrt") || ISINST(pl->line, "jpf"));
+ return (lineIsInst (pl, "jp") || lineIsInst (pl, "jra") || lineIsInst (pl, "jrt") || lineIsInst (pl, "jpf"));
}
static bool
stm8CondJump(const lineNode *pl)
{
return (!stm8UncondJump(pl) && STARTSINST(pl->line, "jr") ||
- ISINST(pl->line, "btjt") || ISINST(pl->line, "btjf"));
+ lineIsInst (pl, "btjt") || lineIsInst (pl, "btjf"));
}
static bool
stm8SurelyWritesFlag(const lineNode *pl, const char *what)
{
// according to calling convention caller has to save flags
- if(ISINST(pl->line, "ret") || ISINST(pl->line, "retf") ||
- ISINST(pl->line, "call") || ISINST(pl->line, "callf") ||
- ISINST(pl->line, "jp") && findSym (SymbolTab, 0, pl->line + 4) ||
- ISINST(pl->line, "jpf") && findSym (SymbolTab, 0, pl->line + 5))
+ if(lineIsInst (pl, "ret") || lineIsInst (pl, "retf") ||
+ lineIsInst (pl, "call") || lineIsInst (pl, "callf") ||
+ lineIsInst (pl, "jp") && findSym (SymbolTab, 0, pl->line + 4) ||
+ lineIsInst (pl, "jpf") && findSym (SymbolTab, 0, pl->line + 5))
return true;
if (!strcmp (what, "v") || !strcmp (what, "c"))
{
- if (ISINST (pl->line, "addw") && !strcmp (pl->line + 5, "sp"))
+ if (lineIsInst (pl, "addw") && !strcmp (pl->line + 5, "sp"))
return false;
- if (ISINST (pl->line, "sub") && !strcmp (pl->line + 4, "sp"))
+ if (lineIsInst (pl, "sub") && !strcmp (pl->line + 4, "sp"))
return false;
- if (ISINST (pl->line, "adc") ||
+ if (lineIsInst (pl, "adc") ||
STARTSINST (pl->line, "add") || // add, addw
STARTSINST (pl->line, "cp") || // cp, cpw, cpl, cplw
STARTSINST (pl->line, "div") || // div, divw
STARTSINST (pl->line, "neg") || // neg, negw
- ISINST (pl->line, "sbc") ||
+ lineIsInst (pl, "sbc") ||
STARTSINST (pl->line, "sub")) // sub, subw
return true;
}
if (!strcmp (what, "n") || !strcmp (what, "z"))
{
- if (ISINST (pl->line, "addw") && !strcmp (pl->line + 5, "sp"))
+ if (lineIsInst (pl, "addw") && !strcmp (pl->line + 5, "sp"))
return false;
- if (ISINST (pl->line, "sub") && !strcmp (pl->line + 4, "sp"))
+ if (lineIsInst (pl, "sub") && !strcmp (pl->line + 4, "sp"))
return false;
- if (ISINST (pl->line, "ld"))
+ if (lineIsInst (pl, "ld"))
return !stm8InstIsRegToReg(pl->line, false);
- if (ISINST (pl->line, "ldw"))
+ if (lineIsInst (pl, "ldw"))
return !stm8InstIsRegToReg(pl->line, true);
- if (ISINST (pl->line, "pop"))
+ if (lineIsInst (pl, "pop"))
return (pl->line[5] == 'c');
- if (ISINST (pl->line, "bccm") || ISINST (pl->line, "bcpl") ||
- ISINST (pl->line, "break") ||
- ISINST (pl->line, "bres") || ISINST (pl->line, "bset") ||
- ISINST (pl->line, "btjf") || ISINST (pl->line, "btjt") ||
- ISINST (pl->line, "call") || ISINST (pl->line, "callf") || ISINST (pl->line, "callr") ||
- ISINST (pl->line, "ccf") ||
- ISINST (pl->line, "exg") || ISINST (pl->line, "exgw") ||
- ISINST (pl->line, "halt") || ISINST (pl->line, "int") ||
+ if (lineIsInst (pl, "bccm") || lineIsInst (pl, "bcpl") ||
+ lineIsInst (pl, "break") ||
+ lineIsInst (pl, "bres") || lineIsInst (pl, "bset") ||
+ lineIsInst (pl, "btjf") || lineIsInst (pl, "btjt") ||
+ lineIsInst (pl, "call") || lineIsInst (pl, "callf") || lineIsInst (pl, "callr") ||
+ lineIsInst (pl, "ccf") ||
+ lineIsInst (pl, "exg") || lineIsInst (pl, "exgw") ||
+ lineIsInst (pl, "halt") || lineIsInst (pl, "int") ||
STARTSINST (pl->line, "jp") ||
STARTSINST (pl->line, "jr") ||
- ISINST (pl->line, "mov") || ISINST (pl->line, "mul") ||
- ISINST (pl->line, "nop") ||
- ISINST (pl->line, "popw") || ISINST (pl->line, "push") || ISINST (pl->line, "pushw") ||
- ISINST (pl->line, "rcf") ||
- ISINST (pl->line, "ret") || ISINST (pl->line, "retf") ||
- ISINST (pl->line, "rvf") || ISINST (pl->line, "scf") ||
- ISINST (pl->line, "sim") || ISINST (pl->line, "trap") || ISINST (pl->line, "wfe") || ISINST (pl->line, "wfi"))
+ lineIsInst (pl, "mov") || lineIsInst (pl, "mul") ||
+ lineIsInst (pl, "nop") ||
+ lineIsInst (pl, "popw") || lineIsInst (pl, "push") || lineIsInst (pl, "pushw") ||
+ lineIsInst (pl, "rcf") ||
+ lineIsInst (pl, "ret") || lineIsInst (pl, "retf") ||
+ lineIsInst (pl, "rvf") || lineIsInst (pl, "scf") ||
+ lineIsInst (pl, "sim") || lineIsInst (pl, "trap") || lineIsInst (pl, "wfe") || lineIsInst (pl, "wfi"))
return false;
return true;
}
@@ -941,12 +940,12 @@ stm8SurelyWritesFlag(const lineNode *pl, const char *what)
if (!strcmp (what, "c"))
{
if (STARTSINST (pl->line, "btj") || // btjt, btjf
- ISINST (pl->line, "ccf") ||
- ISINST (pl->line, "rcf") ||
+ lineIsInst (pl, "ccf") ||
+ lineIsInst (pl, "rcf") ||
STARTSINST (pl->line, "rlc") || // rlc, rlcw
STARTSINST (pl->line, "rrc") || // rrc, rrcw
- ISINST (pl->line, "sbc") ||
- ISINST (pl->line, "scf") ||
+ lineIsInst (pl, "sbc") ||
+ lineIsInst (pl, "scf") ||
STARTSINST (pl->line, "sl") || // sll, sla, sllw, slaw
STARTSINST (pl->line, "sr") || // sra, sraw, srl, srlw
STARTSINST (pl->line, "sub")) // sub, subw
@@ -960,10 +959,10 @@ static bool
callSurelyWrites (const lineNode *pl, const char *what)
{
const symbol *f = 0;
- if ((ISINST(pl->line, "call") || ISINST(pl->line, "callf")) && !strchr(pl->line, ','))
- f = findSym (SymbolTab, 0, pl->line + 6 + ISINST(pl->line, "callf"));
- else if ((ISINST(pl->line, "jp") || ISINST(pl->line, "jr") || ISINST(pl->line, "jpf")) && !strchr(pl->line, ','))
- f = findSym (SymbolTab, 0, pl->line + 4 + ISINST(pl->line, "jpf"));
+ if ((lineIsInst (pl, "call") || lineIsInst (pl, "callf")) && !strchr(pl->line, ','))
+ f = findSym (SymbolTab, 0, pl->line + 6 + lineIsInst (pl, "callf"));
+ else if ((lineIsInst (pl, "jp") || lineIsInst (pl, "jr") || lineIsInst (pl, "jpf")) && !strchr(pl->line, ','))
+ f = findSym (SymbolTab, 0, pl->line + 4 + lineIsInst (pl, "jpf"));
const bool *preserved_regs;
@@ -999,86 +998,86 @@ stm8SurelyWrites(const lineNode *pl, const char *what)
if (!extra)
{
- if (ISINST (pl->line, "adc")
- || ISINST (pl->line, "and")
- || ISINST (pl->line, "div")
- || ISINST (pl->line, "iret")
- || ISINST (pl->line, "or")
- || ISINST (pl->line, "rlwa")
- || ISINST (pl->line, "rrwa")
- || ISINST (pl->line, "sbc")
- || ISINST (pl->line, "xor"))
+ if (lineIsInst (pl, "adc")
+ || lineIsInst (pl, "and")
+ || lineIsInst (pl, "div")
+ || lineIsInst (pl, "iret")
+ || lineIsInst (pl, "or")
+ || lineIsInst (pl, "rlwa")
+ || lineIsInst (pl, "rrwa")
+ || lineIsInst (pl, "sbc")
+ || lineIsInst (pl, "xor"))
return TRUE;
- if ((ISINST (pl->line, "add")
- || ISINST (pl->line, "clr")
- || ISINST (pl->line, "cpl")
- || ISINST (pl->line, "dec")
- || ISINST (pl->line, "exg")
- || ISINST (pl->line, "inc")
- || ISINST (pl->line, "neg")
- || ISINST (pl->line, "pop")
- || ISINST (pl->line, "rlc")
- || ISINST (pl->line, "rrc")
- || ISINST (pl->line, "sll")
- || ISINST (pl->line, "sla")
- || ISINST (pl->line, "sra")
- || ISINST (pl->line, "srl")
- || ISINST (pl->line, "ldf")
- || ISINST (pl->line, "sub")) &&
+ if ((lineIsInst (pl, "add")
+ || lineIsInst (pl, "clr")
+ || lineIsInst (pl, "cpl")
+ || lineIsInst (pl, "dec")
+ || lineIsInst (pl, "exg")
+ || lineIsInst (pl, "inc")
+ || lineIsInst (pl, "neg")
+ || lineIsInst (pl, "pop")
+ || lineIsInst (pl, "rlc")
+ || lineIsInst (pl, "rrc")
+ || lineIsInst (pl, "sll")
+ || lineIsInst (pl, "sla")
+ || lineIsInst (pl, "sra")
+ || lineIsInst (pl, "srl")
+ || lineIsInst (pl, "ldf")
+ || lineIsInst (pl, "sub")) &&
pl->line[4] == 'a')
return TRUE;
- if (ISINST (pl->line, "swap") && pl->line[5] == 'a')
+ if (lineIsInst (pl, "swap") && pl->line[5] == 'a')
return TRUE;
- if (ISINST (pl->line, "ld") && pl->line[3] == 'a')
+ if (lineIsInst (pl, "ld") && pl->line[3] == 'a')
return TRUE;
}
else
{
- if (ISINST (pl->line, "divw")
- || ISINST (pl->line, "exgw")
- || ISINST (pl->line, "iret"))
+ if (lineIsInst (pl, "divw")
+ || lineIsInst (pl, "exgw")
+ || lineIsInst (pl, "iret"))
return TRUE;
- if ((ISINST (pl->line, "div")
- || ISINST (pl->line, "ldw")
- || ISINST (pl->line, "mul"))
+ if ((lineIsInst (pl, "div")
+ || lineIsInst (pl, "ldw")
+ || lineIsInst (pl, "mul"))
&& pl->line[4] == extra)
return TRUE;
- if ((ISINST (pl->line, "addw")
- || ISINST (pl->line, "clrw")
- || ISINST (pl->line, "cplw")
- || ISINST (pl->line, "decw")
- || ISINST (pl->line, "incw")
- || ISINST (pl->line, "negw")
- || ISINST (pl->line, "popw")
- || ISINST (pl->line, "rlcw")
- || ISINST (pl->line, "rlwa")
- || ISINST (pl->line, "rrcw")
- || ISINST (pl->line, "rrwa")
- || ISINST (pl->line, "sllw")
- || ISINST (pl->line, "slaw")
- || ISINST (pl->line, "sraw")
- || ISINST (pl->line, "srlw")
- || ISINST (pl->line, "subw")) &&
+ if ((lineIsInst (pl, "addw")
+ || lineIsInst (pl, "clrw")
+ || lineIsInst (pl, "cplw")
+ || lineIsInst (pl, "decw")
+ || lineIsInst (pl, "incw")
+ || lineIsInst (pl, "negw")
+ || lineIsInst (pl, "popw")
+ || lineIsInst (pl, "rlcw")
+ || lineIsInst (pl, "rlwa")
+ || lineIsInst (pl, "rrcw")
+ || lineIsInst (pl, "rrwa")
+ || lineIsInst (pl, "sllw")
+ || lineIsInst (pl, "slaw")
+ || lineIsInst (pl, "sraw")
+ || lineIsInst (pl, "srlw")
+ || lineIsInst (pl, "subw")) &&
pl->line[5] == extra)
return TRUE;
- if (ISINST (pl->line, "swapw") && pl->line[6] == extra)
+ if (lineIsInst (pl, "swapw") && pl->line[6] == extra)
return TRUE;
- if (ISINST (pl->line, "ld")
+ if (lineIsInst (pl, "ld")
&& strncmp (pl->line + 3, what, strlen (what)) == 0)
return TRUE;
- if (ISINST (pl->line, "exg") && strstr (strstr (pl->line, ","), what))
+ if (lineIsInst (pl, "exg") && strstr (strstr (pl->line, ","), what))
return true;
}
- if (ISINST(pl->line, "call"))
+ if (lineIsInst (pl, "call"))
return (callSurelyWrites (pl, what));
return false;
@@ -1087,7 +1086,7 @@ stm8SurelyWrites(const lineNode *pl, const char *what)
static bool
stm8SurelyReturns(const lineNode *pl)
{
- return(ISINST(pl->line, "ret") || ISINST(pl->line, "retf"));
+ return(lineIsInst (pl, "ret") || lineIsInst (pl, "retf"));
}
/*-----------------------------------------------------------------*/
@@ -1169,7 +1168,7 @@ scan4op (lineNode **pl, const char *what, const char *untilOp,
lineNode *tlbl = findLabel (*pl);
if (!tlbl) // jp/jr could be a tail call.
{
- const symbol *f = findSym (SymbolTab, 0, (*pl)->line + 4 + ISINST ((*pl)->line, "jpf"));
+ const symbol *f = findSym (SymbolTab, 0, (*pl)->line + 4 + lineIsInst (*pl, "jpf"));
if (f && stm8IsParmInCall(f->type, what))
{
D (("S4O_RD_OP\n"));