+/* Table with the compare suffixes */
+static const char CmpSuffixTab [][4] = {
+ "eq", "ne", "gt", "ge", "lt", "le", "ugt", "uge", "ult", "ule"
+};
+
/* Table listing the function names and code info values for known internally
* used functions. This table should get auto-generated in the future.
*/
};
static const FuncInfo FuncInfoTable[] = {
+ { "addeq0sp", REG_AX, REG_AXY },
+ { "addeqysp", REG_AXY, REG_AXY },
{ "addysp", REG_Y, REG_NONE },
{ "aslax1", REG_AX, REG_AX | REG_TMP1 },
{ "aslax2", REG_AX, REG_AX | REG_TMP1 },
{ "laddeq", REG_EAXY|REG_PTR1_LO, REG_EAXY | REG_PTR1_HI },
{ "laddeq1", REG_Y | REG_PTR1_LO, REG_EAXY | REG_PTR1_HI },
{ "laddeqa", REG_AY | REG_PTR1_LO, REG_EAXY | REG_PTR1_HI },
+ { "laddeq0sp", REG_EAX, REG_EAXY },
+ { "laddeqysp", REG_EAXY, REG_EAXY },
{ "ldaidx", REG_AXY, REG_AX | REG_PTR1 },
{ "ldauidx", REG_AXY, REG_AX | REG_PTR1 },
- { "ldax0sp", REG_Y, REG_AX },
+ { "ldax0sp", REG_NONE, REG_AXY },
{ "ldaxi", REG_AX, REG_AXY | REG_PTR1 },
{ "ldaxidx", REG_AXY, REG_AXY | REG_PTR1 },
{ "ldaxysp", REG_Y, REG_AXY },
+ { "ldeax0sp", REG_NONE, REG_EAXY },
+ { "ldeaxi", REG_AX, REG_EAXY | REG_PTR1 },
+ { "ldeaxidx", REG_AXY, REG_EAXY | REG_PTR1 },
+ { "ldeaxysp", REG_Y, REG_EAXY },
{ "leaasp", REG_A, REG_AX },
{ "lsubeq", REG_EAXY|REG_PTR1_LO, REG_EAXY | REG_PTR1_HI },
{ "lsubeq0sp", REG_EAX, REG_EAXY },
{ "lsubeq1", REG_Y | REG_PTR1_LO, REG_EAXY | REG_PTR1_HI },
{ "lsubeqa", REG_AY | REG_PTR1_LO, REG_EAXY | REG_PTR1_HI },
{ "lsubeqysp", REG_EAXY, REG_EAXY },
+ { "lsubeq0sp", REG_EAX, REG_EAXY },
{ "negax", REG_AX, REG_AX },
+ { "push0", REG_NONE, REG_AXY },
+ { "push1", REG_NONE, REG_AXY },
+ { "push2", REG_NONE, REG_AXY },
+ { "push3", REG_NONE, REG_AXY },
+ { "push4", REG_NONE, REG_AXY },
+ { "push5", REG_NONE, REG_AXY },
+ { "push6", REG_NONE, REG_AXY },
+ { "push7", REG_NONE, REG_AXY },
{ "pusha", REG_A, REG_Y },
{ "pusha0", REG_A, REG_XY },
+ { "pusha0sp", REG_NONE, REG_AY },
{ "pushax", REG_AX, REG_Y },
+ { "pushaysp", REG_Y, REG_AY },
+ { "pushc0", REG_NONE, REG_A | REG_Y },
+ { "pushc1", REG_NONE, REG_A | REG_Y },
+ { "pushc2", REG_NONE, REG_A | REG_Y },
{ "pusheax", REG_EAX, REG_Y },
+ { "pushw", REG_AX, REG_AXY | REG_PTR1 },
{ "pushw0sp", REG_NONE, REG_AXY },
+ { "pushwidx", REG_AXY, REG_AXY | REG_PTR1 },
{ "pushwysp", REG_Y, REG_AXY },
+ { "regswap", REG_AXY, REG_AXY | REG_TMP1 },
+ { "regswap1", REG_XY, REG_A },
+ { "regswap2", REG_XY, REG_A | REG_Y },
{ "shlax1", REG_AX, REG_AX | REG_TMP1 },
{ "shlax2", REG_AX, REG_AX | REG_TMP1 },
{ "shlax3", REG_AX, REG_AX | REG_TMP1 },
{ "staspidx", REG_A | REG_Y, REG_Y | REG_TMP1 | REG_PTR1 },
{ "stax0sp", REG_AX, REG_Y },
{ "staxysp", REG_AXY, REG_Y },
+ { "steax0sp", REG_EAX, REG_Y },
+ { "steaxysp", REG_EAXY, REG_Y },
{ "subeq0sp", REG_AX, REG_AXY },
{ "subeqysp", REG_AXY, REG_AXY },
- { "tsteax", REG_EAX, REG_Y },
{ "tosadda0", REG_A, REG_AXY },
{ "tosaddax", REG_AX, REG_AXY },
- { "tosicmp", REG_AX, REG_AXY | REG_SREG },
- { "tosdiva0", REG_AX, REG_ALL },
- { "tosdivax", REG_AX, REG_ALL },
- { "tosdiveax", REG_EAX, REG_ALL },
+ { "tosanda0", REG_A, REG_AXY },
+ { "tosandax", REG_AX, REG_AXY },
+ { "tosdiva0", REG_AY, REG_ALL },
+ { "tosdivax", REG_AXY, REG_ALL },
+ { "tosdiveax", REG_EAXY, REG_ALL },
{ "toseqeax", REG_EAX, REG_AXY | REG_PTR1 },
{ "tosgeeax", REG_EAX, REG_AXY | REG_PTR1 },
{ "tosgteax", REG_EAX, REG_AXY | REG_PTR1 },
+ { "tosicmp", REG_AX, REG_AXY | REG_SREG },
{ "toslcmp", REG_EAX, REG_A | REG_Y | REG_PTR1 },
{ "tosleeax", REG_EAX, REG_AXY | REG_PTR1 },
{ "toslteax", REG_EAX, REG_AXY | REG_PTR1 },
{ "tosumula0", REG_AX, REG_ALL },
{ "tosumulax", REG_AX, REG_ALL },
{ "tosumuleax", REG_EAX, REG_ALL },
+ { "tsteax", REG_EAX, REG_Y },
{ "utsteax", REG_EAX, REG_Y },
};
#define FuncInfoCount (sizeof(FuncInfoTable) / sizeof(FuncInfoTable[0]))
+int RegEAXUsed (struct CodeSeg* S, unsigned Index)
+/* Check if any of the four bytes in EAX are used. */
+{
+ return (GetRegInfo (S, Index, REG_EAX) & REG_EAX) != 0;
+}
+
+
+
unsigned GetKnownReg (unsigned Use, const RegContents* RC)
/* Return the register or zero page location from the set in Use, thats
* contents are known. If Use does not contain any register, or if the
+static cmp_t FindCmpCond (const char* Code, unsigned CodeLen)
+/* Search for a compare condition by the given code using the given length */
+{
+ unsigned I;
+
+ /* Linear search */
+ for (I = 0; I < sizeof (CmpSuffixTab) / sizeof (CmpSuffixTab [0]); ++I) {
+ if (strncmp (Code, CmpSuffixTab [I], CodeLen) == 0) {
+ /* Found */
+ return I;
+ }
+ }
+
+ /* Not found */
+ return CMP_INV;
+}
+
+
+
+cmp_t FindBoolCmpCond (const char* Name)
+/* Check if the given string is the name of one of the boolean transformer
+ * subroutine, and if so, return the condition that is evaluated by this
+ * routine. Return CMP_INV if the condition is not recognised.
+ */
+{
+ /* Check for the correct subroutine name */
+ if (strncmp (Name, "bool", 4) == 0) {
+ /* Name is ok, search for the code in the table */
+ return FindCmpCond (Name+4, strlen(Name)-4);
+ } else {
+ /* Not found */
+ return CMP_INV;
+ }
+}
+
+
+
+cmp_t FindTosCmpCond (const char* Name)
+/* Check if this is a call to one of the TOS compare functions (tosgtax).
+ * Return the condition code or CMP_INV on failure.
+ */
+{
+ unsigned Len = strlen (Name);
+
+ /* Check for the correct subroutine name */
+ if (strncmp (Name, "tos", 3) == 0 && strcmp (Name+Len-2, "ax") == 0) {
+ /* Name is ok, search for the code in the table */
+ return FindCmpCond (Name+3, Len-3-2);
+ } else {
+ /* Not found */
+ return CMP_INV;
+ }
+}
+
+
+