X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fcodeinfo.c;h=cf04baf9c3a39808af1ce192f12441896b37e20c;hb=92dfde6c4e748946c5e13323bb48bf2abd72c2b3;hp=4d32972c6bf0ec35d19f9e56110d0decccc53bae;hpb=1118dd123714136c5a3389f377b0b636db2c1aae;p=cc65 diff --git a/src/cc65/codeinfo.c b/src/cc65/codeinfo.c index 4d32972c6..cf04baf9c 100644 --- a/src/cc65/codeinfo.c +++ b/src/cc65/codeinfo.c @@ -56,6 +56,11 @@ +/* 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. */ @@ -67,6 +72,8 @@ struct FuncInfo { }; 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 }, @@ -117,25 +124,50 @@ static const FuncInfo FuncInfoTable[] = { { "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 }, @@ -151,18 +183,21 @@ static const FuncInfo FuncInfoTable[] = { { "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 }, @@ -181,6 +216,7 @@ static const FuncInfo FuncInfoTable[] = { { "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])) @@ -559,6 +595,14 @@ int RegAXUsed (struct CodeSeg* S, unsigned Index) +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 @@ -566,17 +610,17 @@ unsigned GetKnownReg (unsigned Use, const RegContents* RC) */ { if ((Use & REG_A) != 0) { - return (RC && RC->RegA >= 0)? REG_A : REG_NONE; + return (RC == 0 || RC->RegA >= 0)? REG_A : REG_NONE; } else if ((Use & REG_X) != 0) { - return (RC && RC->RegX >= 0)? REG_X : REG_NONE; + return (RC == 0 || RC->RegX >= 0)? REG_X : REG_NONE; } else if ((Use & REG_Y) != 0) { - return (RC && RC->RegY >= 0)? REG_Y : REG_NONE; + return (RC == 0 || RC->RegY >= 0)? REG_Y : REG_NONE; } else if ((Use & REG_TMP1) != 0) { - return (RC && RC->Tmp1 >= 0)? REG_TMP1 : REG_NONE; + return (RC == 0 || RC->Tmp1 >= 0)? REG_TMP1 : REG_NONE; } else if ((Use & REG_SREG_LO) != 0) { - return (RC && RC->SRegLo >= 0)? REG_SREG_LO : REG_NONE; + return (RC == 0 || RC->SRegLo >= 0)? REG_SREG_LO : REG_NONE; } else if ((Use & REG_SREG_HI) != 0) { - return (RC && RC->SRegHi >= 0)? REG_SREG_HI : REG_NONE; + return (RC == 0 || RC->SRegHi >= 0)? REG_SREG_HI : REG_NONE; } else { return REG_NONE; } @@ -584,3 +628,59 @@ unsigned GetKnownReg (unsigned Use, const RegContents* RC) +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; + } +} + + +