Refactoring idioms into objects with match/action methods
This commit is contained in:
parent
74c5966579
commit
bf2d099cd9
@ -36,6 +36,8 @@ src/graph.cpp
|
||||
src/hlicode.cpp
|
||||
src/icode.cpp
|
||||
src/idioms.cpp
|
||||
src/idiom1.cpp
|
||||
src/epilogue_idioms.cpp
|
||||
src/locident.cpp
|
||||
src/parser.cpp
|
||||
src/perfhlib.cpp
|
||||
@ -57,6 +59,9 @@ set(dcc_HEADERS
|
||||
include/graph.h
|
||||
include/hlicode.h
|
||||
include/icode.h
|
||||
include/idiom.h
|
||||
include/idiom1.h
|
||||
include/epilogue_idioms.h
|
||||
include/locident.h
|
||||
include/perfhlib.h
|
||||
include/scanner.h
|
||||
|
||||
@ -63,32 +63,35 @@ enum eDuFlags
|
||||
};
|
||||
|
||||
/* Machine registers */
|
||||
#define rAX 1 /* These are numbered relative to real 8086 */
|
||||
#define rCX 2
|
||||
#define rDX 3
|
||||
#define rBX 4
|
||||
#define rSP 5
|
||||
#define rBP 6
|
||||
#define rSI 7
|
||||
#define rDI 8
|
||||
enum eReg
|
||||
{
|
||||
rAX = 1, /* These are numbered relative to real 8086 */
|
||||
rCX = 2,
|
||||
rDX = 3,
|
||||
rBX = 4,
|
||||
rSP = 5,
|
||||
rBP = 6,
|
||||
rSI = 7,
|
||||
rDI = 8,
|
||||
|
||||
#define rES 9
|
||||
#define rCS 10
|
||||
#define rSS 11
|
||||
#define rDS 12
|
||||
rES = 9,
|
||||
rCS = 10,
|
||||
rSS = 11,
|
||||
rDS = 12,
|
||||
|
||||
#define rAL 13
|
||||
#define rCL 14
|
||||
#define rDL 15
|
||||
#define rBL 16
|
||||
#define rAH 17
|
||||
#define rCH 18
|
||||
#define rDH 19
|
||||
#define rBH 20
|
||||
rAL = 13,
|
||||
rCL = 14,
|
||||
rDL = 15,
|
||||
rBL = 16,
|
||||
rAH = 17,
|
||||
rCH = 18,
|
||||
rDH = 19,
|
||||
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
|
||||
* INDEXBASE+7 */
|
||||
* INDEXBASE+7 */
|
||||
};
|
||||
/* Byte and Word registers */
|
||||
static const char *const byteReg[9] = {"al", "cl", "dl", "bl",
|
||||
"ah", "ch", "dh", "bh", "tmp" };
|
||||
@ -314,6 +317,26 @@ struct LLInst : public llvm::MCInst
|
||||
return (opcode >= iJB) && (opcode < iJCXZ);
|
||||
}
|
||||
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 */
|
||||
@ -338,13 +361,13 @@ struct ICODE
|
||||
IC ic;/* intermediate code */
|
||||
int loc_ip; // used by CICodeRec to number ICODEs
|
||||
|
||||
void ClrLlFlag(dword flag) {ic.ll.flg &= ~flag;}
|
||||
void SetLlFlag(dword flag) {ic.ll.flg |= flag;}
|
||||
dword GetLlFlag() {return ic.ll.flg;}
|
||||
bool isLlFlag(dword flg) {return (ic.ll.flg&flg)!=0;}
|
||||
void ClrLlFlag(dword flag) {ic.ll.flg &= ~flag;}
|
||||
void SetLlFlag(dword flag) {ic.ll.flg |= flag;}
|
||||
dword GetLlFlag() {return ic.ll.flg;}
|
||||
bool isLlFlag(dword flg) {return (ic.ll.flg&flg)!=0;}
|
||||
llIcode GetLlOpcode() const { return ic.ll.opcode; }
|
||||
dword GetLlLabel() const { return ic.ll.label;}
|
||||
void SetImmediateOp(dword dw) {ic.ll.src.SetImmediateOp(dw);}
|
||||
dword GetLlLabel() const { return ic.ll.label;}
|
||||
void SetImmediateOp(dword dw) {ic.ll.src.SetImmediateOp(dw);}
|
||||
|
||||
void writeIntComment(std::ostringstream &s);
|
||||
void setRegDU(byte regi, operDu du_in);
|
||||
@ -372,6 +395,7 @@ public:
|
||||
ICODE * addIcode(ICODE *pIcode);
|
||||
void SetInBB(int start, int end, BB* pnewBB);
|
||||
bool labelSrch(dword target, dword &pIndex);
|
||||
iterator labelSrch(dword target);
|
||||
ICODE * GetIcode(int ip);
|
||||
};
|
||||
typedef CIcodeRec::iterator iICODE;
|
||||
|
||||
@ -50,7 +50,19 @@ bool CIcodeRec::labelSrch(dword target, dword &pIndex)
|
||||
}
|
||||
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)
|
||||
{
|
||||
return &at(ip);
|
||||
|
||||
1483
src/idioms.cpp
1483
src/idioms.cpp
File diff suppressed because it is too large
Load Diff
@ -18,16 +18,15 @@ static void displayDfs(BB * pBB);
|
||||
void Function::buildCFG()
|
||||
{
|
||||
if(flg & PROC_ISLIB)
|
||||
return; /* Ignore library functions */
|
||||
return; // Ignore library functions
|
||||
createCFG();
|
||||
if (option.VeryVerbose)
|
||||
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)
|
||||
disassem(2, this);
|
||||
disassem(2, this); // Print 2nd pass assembler listing
|
||||
|
||||
/* Idiom analysis and propagation of long type */
|
||||
lowLevelAnalysis();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user