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/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
|
||||||
|
|||||||
@ -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 */
|
||||||
@ -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;
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
853
src/idioms.cpp
853
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()
|
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();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user