Refactoring idioms into objects with match/action methods

This commit is contained in:
Artur K 2012-02-26 23:57:33 +01:00
parent 74c5966579
commit bf2d099cd9
5 changed files with 701 additions and 888 deletions

View File

@ -36,6 +36,8 @@ src/graph.cpp
src/hlicode.cpp src/hlicode.cpp
src/icode.cpp src/icode.cpp
src/idioms.cpp src/idioms.cpp
src/idiom1.cpp
src/epilogue_idioms.cpp
src/locident.cpp src/locident.cpp
src/parser.cpp src/parser.cpp
src/perfhlib.cpp src/perfhlib.cpp
@ -57,6 +59,9 @@ set(dcc_HEADERS
include/graph.h include/graph.h
include/hlicode.h include/hlicode.h
include/icode.h include/icode.h
include/idiom.h
include/idiom1.h
include/epilogue_idioms.h
include/locident.h include/locident.h
include/perfhlib.h include/perfhlib.h
include/scanner.h include/scanner.h

View File

@ -63,32 +63,35 @@ enum eDuFlags
}; };
/* Machine registers */ /* Machine registers */
#define rAX 1 /* These are numbered relative to real 8086 */ enum eReg
#define rCX 2 {
#define rDX 3 rAX = 1, /* These are numbered relative to real 8086 */
#define rBX 4 rCX = 2,
#define rSP 5 rDX = 3,
#define rBP 6 rBX = 4,
#define rSI 7 rSP = 5,
#define rDI 8 rBP = 6,
rSI = 7,
rDI = 8,
#define rES 9 rES = 9,
#define rCS 10 rCS = 10,
#define rSS 11 rSS = 11,
#define rDS 12 rDS = 12,
#define rAL 13 rAL = 13,
#define rCL 14 rCL = 14,
#define rDL 15 rDL = 15,
#define rBL 16 rBL = 16,
#define rAH 17 rAH = 17,
#define rCH 18 rCH = 18,
#define rDH 19 rDH = 19,
#define rBH 20 rBH = 20,
#define rTMP 21 /* temp register for DIV/IDIV/MOD */ rTMP= 21 /* temp register for DIV/IDIV/MOD */
#define INDEXBASE 22 /* Indexed modes go from INDEXBASE to #define INDEXBASE 22 /* Indexed modes go from INDEXBASE to
* INDEXBASE+7 */ * INDEXBASE+7 */
};
/* Byte and Word registers */ /* Byte and Word registers */
static const char *const byteReg[9] = {"al", "cl", "dl", "bl", static const char *const byteReg[9] = {"al", "cl", "dl", "bl",
"ah", "ch", "dh", "bh", "tmp" }; "ah", "ch", "dh", "bh", "tmp" };
@ -314,6 +317,26 @@ struct LLInst : public llvm::MCInst
return (opcode >= iJB) && (opcode < iJCXZ); return (opcode >= iJB) && (opcode < iJCXZ);
} }
bool anyFlagSet(uint32_t x) const { return (flg & x)!=0;} bool anyFlagSet(uint32_t x) const { return (flg & x)!=0;}
bool match(llIcode op)
{
return (opcode==op);
}
bool match(llIcode op,eReg dest)
{
return (opcode==op)&&dst.regi==dest;
}
bool match(llIcode op,eReg dest,eReg src_reg)
{
return (opcode==op)&&(dst.regi==dest)&&(src.regi==src_reg);
}
bool match(eReg dest,eReg src_reg)
{
return (dst.regi==dest)&&(src.regi==src_reg);
}
bool match(eReg dest)
{
return (dst.regi==dest);
}
}; };
/* Icode definition: LOW_LEVEL and HIGH_LEVEL */ /* Icode definition: LOW_LEVEL and HIGH_LEVEL */
@ -338,13 +361,13 @@ struct ICODE
IC ic;/* intermediate code */ IC ic;/* intermediate code */
int loc_ip; // used by CICodeRec to number ICODEs int loc_ip; // used by CICodeRec to number ICODEs
void ClrLlFlag(dword flag) {ic.ll.flg &= ~flag;} void ClrLlFlag(dword flag) {ic.ll.flg &= ~flag;}
void SetLlFlag(dword flag) {ic.ll.flg |= flag;} void SetLlFlag(dword flag) {ic.ll.flg |= flag;}
dword GetLlFlag() {return ic.ll.flg;} dword GetLlFlag() {return ic.ll.flg;}
bool isLlFlag(dword flg) {return (ic.ll.flg&flg)!=0;} bool isLlFlag(dword flg) {return (ic.ll.flg&flg)!=0;}
llIcode GetLlOpcode() const { return ic.ll.opcode; } llIcode GetLlOpcode() const { return ic.ll.opcode; }
dword GetLlLabel() const { return ic.ll.label;} dword GetLlLabel() const { return ic.ll.label;}
void SetImmediateOp(dword dw) {ic.ll.src.SetImmediateOp(dw);} void SetImmediateOp(dword dw) {ic.ll.src.SetImmediateOp(dw);}
void writeIntComment(std::ostringstream &s); void writeIntComment(std::ostringstream &s);
void setRegDU(byte regi, operDu du_in); void setRegDU(byte regi, operDu du_in);
@ -372,6 +395,7 @@ public:
ICODE * addIcode(ICODE *pIcode); ICODE * addIcode(ICODE *pIcode);
void SetInBB(int start, int end, BB* pnewBB); void SetInBB(int start, int end, BB* pnewBB);
bool labelSrch(dword target, dword &pIndex); bool labelSrch(dword target, dword &pIndex);
iterator labelSrch(dword target);
ICODE * GetIcode(int ip); ICODE * GetIcode(int ip);
}; };
typedef CIcodeRec::iterator iICODE; typedef CIcodeRec::iterator iICODE;

View File

@ -50,7 +50,19 @@ bool CIcodeRec::labelSrch(dword target, dword &pIndex)
} }
return false; return false;
} }
CIcodeRec::iterator CIcodeRec::labelSrch(dword target)
{
Int i;
for (i = 0; i < size(); i++)
{
if (at(i).ic.ll.label == target)
{
return begin()+i;
}
}
return end();
}
ICODE * CIcodeRec::GetIcode(int ip) ICODE * CIcodeRec::GetIcode(int ip)
{ {
return &at(ip); return &at(ip);

File diff suppressed because it is too large Load Diff

View File

@ -18,16 +18,15 @@ static void displayDfs(BB * pBB);
void Function::buildCFG() void Function::buildCFG()
{ {
if(flg & PROC_ISLIB) if(flg & PROC_ISLIB)
return; /* Ignore library functions */ return; // Ignore library functions
createCFG(); createCFG();
if (option.VeryVerbose) if (option.VeryVerbose)
displayCFG(); displayCFG();
/* Remove redundancies and add in-edge information */
compressCFG();
/* Print 2nd pass assembler listing */ compressCFG(); // Remove redundancies and add in-edge information
if (option.asm2) if (option.asm2)
disassem(2, this); disassem(2, this); // Print 2nd pass assembler listing
/* Idiom analysis and propagation of long type */ /* Idiom analysis and propagation of long type */
lowLevelAnalysis(); lowLevelAnalysis();