Removed lints
This commit is contained in:
parent
eb6c1ac939
commit
3bcbb7a2cf
@ -40,6 +40,7 @@ private:
|
|||||||
//friend class SymbolTableListTraits<BB, Function>;
|
//friend class SymbolTableListTraits<BB, Function>;
|
||||||
iICODE range_start;
|
iICODE range_start;
|
||||||
iICODE range_end;
|
iICODE range_end;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
iICODE begin();
|
iICODE begin();
|
||||||
iICODE end() const;
|
iICODE end() const;
|
||||||
|
|||||||
@ -15,6 +15,7 @@ struct bundle
|
|||||||
public:
|
public:
|
||||||
void appendCode(const char *format, ...);
|
void appendCode(const char *format, ...);
|
||||||
void appendDecl(const char *format, ...);
|
void appendDecl(const char *format, ...);
|
||||||
|
void appendDecl(const std::string &);
|
||||||
strTable decl; /* Declarations */
|
strTable decl; /* Declarations */
|
||||||
strTable code; /* C code */
|
strTable code; /* C code */
|
||||||
};
|
};
|
||||||
|
|||||||
@ -104,10 +104,6 @@ extern std::bitset<32> duReg[30]; /* def/use bits for registers */
|
|||||||
extern std::bitset<32> maskDuReg[30]; /* masks off du bits for regs */
|
extern std::bitset<32> maskDuReg[30]; /* masks off du bits for regs */
|
||||||
|
|
||||||
/* Registers used by icode instructions */
|
/* Registers used by icode instructions */
|
||||||
static constexpr const char *allRegs[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
|
|
||||||
"si", "di", "es", "cs", "ss", "ds",
|
|
||||||
"al", "cl", "dl", "bl", "ah", "ch", "dh", "bh",
|
|
||||||
"tmp"};
|
|
||||||
|
|
||||||
/* Memory map states */
|
/* Memory map states */
|
||||||
#define BM_UNKNOWN 0 /* Unscanned memory */
|
#define BM_UNKNOWN 0 /* Unscanned memory */
|
||||||
@ -169,7 +165,7 @@ hlType expType (const COND_EXPR *, Function *);
|
|||||||
std::string writeCall (Function *, STKFRAME *, Function *, int *);
|
std::string writeCall (Function *, STKFRAME *, Function *, int *);
|
||||||
char *writeJcond (const HLTYPE &, Function *, int *);
|
char *writeJcond (const HLTYPE &, Function *, int *);
|
||||||
char *writeJcondInv (HLTYPE, Function *, int *);
|
char *writeJcondInv (HLTYPE, Function *, int *);
|
||||||
int power2 (int);
|
|
||||||
|
|
||||||
/* Exported funcions from locident.c */
|
/* Exported funcions from locident.c */
|
||||||
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
|
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
|
||||||
@ -177,6 +173,6 @@ boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iI
|
|||||||
eReg otherLongRegi(eReg, int, LOCAL_ID *);
|
eReg otherLongRegi(eReg, int, LOCAL_ID *);
|
||||||
|
|
||||||
|
|
||||||
extern eReg subRegH(eReg reg);
|
extern eReg subRegH(eReg reg); //TODO: move these into machine_x86
|
||||||
extern eReg subRegL(eReg reg);
|
extern eReg subRegL(eReg reg);
|
||||||
extern const char *indentStr(int level);
|
extern const char *indentStr(int level);
|
||||||
|
|||||||
@ -2,6 +2,11 @@
|
|||||||
* dcc project disassembler header
|
* dcc project disassembler header
|
||||||
* (C) Mike van Emmerik
|
* (C) Mike van Emmerik
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
#include "bundle.h"
|
||||||
|
struct LLInst;
|
||||||
|
|
||||||
/* Definitions for extended keys (first key is zero) */
|
/* Definitions for extended keys (first key is zero) */
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@ enum eErrorId
|
|||||||
WHILE_FAIL
|
WHILE_FAIL
|
||||||
};
|
};
|
||||||
|
|
||||||
//lint -function(exit,fatalError)
|
|
||||||
void fatalError(eErrorId errId, ...);
|
void fatalError(eErrorId errId, ...);
|
||||||
void reportError(eErrorId errId, ...);
|
void reportError(eErrorId errId, ...);
|
||||||
|
|
||||||
|
|||||||
@ -3,11 +3,13 @@
|
|||||||
* (C) Cristina Cifuentes
|
* (C) Cristina Cifuentes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <llvm/ADT/ilist.h>
|
#include <llvm/ADT/ilist.h>
|
||||||
#include <llvm/ADT/ilist_node.h>
|
#include <llvm/ADT/ilist_node.h>
|
||||||
|
#include <llvm/CodeGen/MachineInstr.h>
|
||||||
#include <llvm/MC/MCInst.h>
|
#include <llvm/MC/MCInst.h>
|
||||||
#include <llvm/MC/MCAsmInfo.h>
|
#include <llvm/MC/MCAsmInfo.h>
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
@ -20,9 +22,12 @@ struct Function;
|
|||||||
struct STKFRAME;
|
struct STKFRAME;
|
||||||
struct CIcodeRec;
|
struct CIcodeRec;
|
||||||
struct ICODE;
|
struct ICODE;
|
||||||
|
struct bundle;
|
||||||
typedef std::list<ICODE>::iterator iICODE;
|
typedef std::list<ICODE>::iterator iICODE;
|
||||||
typedef std::list<ICODE>::reverse_iterator riICODE;
|
typedef std::list<ICODE>::reverse_iterator riICODE;
|
||||||
|
|
||||||
|
/* uint8_t and uint16_t registers */
|
||||||
|
|
||||||
/* Def/use of flags - low 4 bits represent flags */
|
/* Def/use of flags - low 4 bits represent flags */
|
||||||
struct DU
|
struct DU
|
||||||
{
|
{
|
||||||
@ -65,19 +70,19 @@ struct AssignType : public HlTypeSupport
|
|||||||
/* for HLI_ASSIGN */
|
/* for HLI_ASSIGN */
|
||||||
COND_EXPR *lhs;
|
COND_EXPR *lhs;
|
||||||
COND_EXPR *rhs;
|
COND_EXPR *rhs;
|
||||||
|
AssignType() : lhs(0),rhs(0) {}
|
||||||
bool removeRegFromLong(eReg regi, LOCAL_ID *locId)
|
bool removeRegFromLong(eReg regi, LOCAL_ID *locId)
|
||||||
{
|
{
|
||||||
performLongRemoval(regi,locId,lhs);
|
performLongRemoval(regi,locId,lhs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string writeOut(Function *pProc, int *numLoc);
|
std::string writeOut(Function *pProc, int *numLoc);
|
||||||
AssignType() : lhs(0),rhs(0)
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
struct ExpType : public HlTypeSupport
|
struct ExpType : public HlTypeSupport
|
||||||
{
|
{
|
||||||
/* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/
|
/* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/
|
||||||
COND_EXPR *v;
|
COND_EXPR *v;
|
||||||
|
ExpType() : v(0) {}
|
||||||
bool removeRegFromLong(eReg regi, LOCAL_ID *locId)
|
bool removeRegFromLong(eReg regi, LOCAL_ID *locId)
|
||||||
{
|
{
|
||||||
performLongRemoval(regi,locId,v);
|
performLongRemoval(regi,locId,v);
|
||||||
@ -148,7 +153,7 @@ public:
|
|||||||
void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs);
|
void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs);
|
||||||
} ;
|
} ;
|
||||||
/* LOW_LEVEL icode operand record */
|
/* LOW_LEVEL icode operand record */
|
||||||
struct LLOperand //: public llvm::MCOperand
|
struct LLOperand : public llvm::MCOperand
|
||||||
{
|
{
|
||||||
eReg seg; /* CS, DS, ES, SS */
|
eReg seg; /* CS, DS, ES, SS */
|
||||||
int16_t segValue; /* Value of segment seg during analysis */
|
int16_t segValue; /* Value of segment seg during analysis */
|
||||||
@ -161,15 +166,22 @@ struct LLOperand //: public llvm::MCOperand
|
|||||||
Function *proc; /* pointer to target proc (for CALL(F))*/
|
Function *proc; /* pointer to target proc (for CALL(F))*/
|
||||||
int cb; /* # actual arg bytes */
|
int cb; /* # actual arg bytes */
|
||||||
} proc;
|
} proc;
|
||||||
|
LLOperand() : seg(rUNDEF),segValue(0),segOver(rUNDEF),regi(rUNDEF),off(0),opz(0)
|
||||||
|
{
|
||||||
|
proc.proc=0;
|
||||||
|
proc.cb=0;
|
||||||
|
}
|
||||||
uint32_t op() const {return opz;}
|
uint32_t op() const {return opz;}
|
||||||
void SetImmediateOp(uint32_t dw) {opz=dw;}
|
void SetImmediateOp(uint32_t dw) {opz=dw;}
|
||||||
|
bool isReg() const;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
struct LLInst : public llvm::ilist_node<LLInst>
|
struct LLInst : public llvm::MCInst //: public llvm::ilist_node<LLInst>
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
uint32_t flg; /* icode flags */
|
uint32_t flg; /* icode flags */
|
||||||
llIcode opcode; /* llIcode instruction */
|
// llIcode opcode; /* llIcode instruction */
|
||||||
public:
|
public:
|
||||||
int codeIdx; /* Index into cCode.code */
|
int codeIdx; /* Index into cCode.code */
|
||||||
uint8_t numBytes; /* Number of bytes this instr */
|
uint8_t numBytes; /* Number of bytes this instr */
|
||||||
@ -185,13 +197,13 @@ public:
|
|||||||
int hllLabNum; /* label # for hll codegen */
|
int hllLabNum; /* label # for hll codegen */
|
||||||
bool conditionalJump()
|
bool conditionalJump()
|
||||||
{
|
{
|
||||||
return (opcode >= iJB) && (opcode < iJCXZ);
|
return (getOpcode() >= iJB) && (getOpcode() < iJCXZ);
|
||||||
}
|
}
|
||||||
bool testFlags(uint32_t x) const { return (flg & x)!=0;}
|
bool testFlags(uint32_t x) const { return (flg & x)!=0;}
|
||||||
void setFlags(uint32_t flag) {flg |= flag;}
|
void setFlags(uint32_t flag) {flg |= flag;}
|
||||||
void clrFlags(uint32_t flag)
|
void clrFlags(uint32_t flag)
|
||||||
{
|
{
|
||||||
if(opcode==iMOD)
|
if(getOpcode()==iMOD)
|
||||||
{
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
@ -199,7 +211,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getFlag() const {return flg;}
|
uint32_t getFlag() const {return flg;}
|
||||||
llIcode getOpcode() const { return opcode; }
|
//llIcode getOpcode() const { return opcode; }
|
||||||
|
|
||||||
uint32_t GetLlLabel() const { return label;}
|
uint32_t GetLlLabel() const { return label;}
|
||||||
|
|
||||||
@ -208,19 +220,19 @@ public:
|
|||||||
|
|
||||||
bool match(llIcode op)
|
bool match(llIcode op)
|
||||||
{
|
{
|
||||||
return (opcode==op);
|
return (getOpcode()==op);
|
||||||
}
|
}
|
||||||
bool match(llIcode op,eReg dest)
|
bool match(llIcode op,eReg dest)
|
||||||
{
|
{
|
||||||
return (opcode==op)&&dst.regi==dest;
|
return (getOpcode()==op)&&dst.regi==dest;
|
||||||
}
|
}
|
||||||
bool match(llIcode op,eReg dest,uint32_t flgs)
|
bool match(llIcode op,eReg dest,uint32_t flgs)
|
||||||
{
|
{
|
||||||
return (opcode==op) and (dst.regi==dest) and testFlags(flgs);
|
return (getOpcode()==op) and (dst.regi==dest) and testFlags(flgs);
|
||||||
}
|
}
|
||||||
bool match(llIcode op,eReg dest,eReg src_reg)
|
bool match(llIcode op,eReg dest,eReg src_reg)
|
||||||
{
|
{
|
||||||
return (opcode==op)&&(dst.regi==dest)&&(src.regi==src_reg);
|
return (getOpcode()==op)&&(dst.regi==dest)&&(src.regi==src_reg);
|
||||||
}
|
}
|
||||||
bool match(eReg dest,eReg src_reg)
|
bool match(eReg dest,eReg src_reg)
|
||||||
{
|
{
|
||||||
@ -232,17 +244,13 @@ public:
|
|||||||
}
|
}
|
||||||
bool match(llIcode op,uint32_t flgs)
|
bool match(llIcode op,uint32_t flgs)
|
||||||
{
|
{
|
||||||
return (opcode==op) and testFlags(flgs);
|
return (getOpcode()==op) and testFlags(flgs);
|
||||||
}
|
}
|
||||||
void set(llIcode op,uint32_t flags)
|
void set(llIcode op,uint32_t flags)
|
||||||
{
|
{
|
||||||
opcode = op;
|
setOpcode(op);
|
||||||
flg =flags;
|
flg =flags;
|
||||||
}
|
}
|
||||||
void setOpcode(llIcode op)
|
|
||||||
{
|
|
||||||
opcode = op;
|
|
||||||
}
|
|
||||||
void emitGotoLabel(int indLevel);
|
void emitGotoLabel(int indLevel);
|
||||||
void findJumpTargets(CIcodeRec &_pc);
|
void findJumpTargets(CIcodeRec &_pc);
|
||||||
void writeIntComment(std::ostringstream &s);
|
void writeIntComment(std::ostringstream &s);
|
||||||
@ -253,6 +261,11 @@ public:
|
|||||||
bool isJmpInst();
|
bool isJmpInst();
|
||||||
HLTYPE toHighLevel(COND_EXPR *lhs, COND_EXPR *rhs, Function *func);
|
HLTYPE toHighLevel(COND_EXPR *lhs, COND_EXPR *rhs, Function *func);
|
||||||
HLTYPE createCall();
|
HLTYPE createCall();
|
||||||
|
LLInst(ICODE *container) : m_link(container),flg(0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
ICODE *m_link;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Icode definition: LOW_LEVEL and HIGH_LEVEL */
|
/* Icode definition: LOW_LEVEL and HIGH_LEVEL */
|
||||||
@ -261,6 +274,7 @@ struct ICODE
|
|||||||
protected:
|
protected:
|
||||||
LLInst m_ll;
|
LLInst m_ll;
|
||||||
HLTYPE m_hl;
|
HLTYPE m_hl;
|
||||||
|
bool invalid; /* Has no HIGH_LEVEL equivalent */
|
||||||
public:
|
public:
|
||||||
/* Def/Use of registers and stack variables */
|
/* Def/Use of registers and stack variables */
|
||||||
struct DU_ICODE
|
struct DU_ICODE
|
||||||
@ -317,18 +331,20 @@ public:
|
|||||||
Use &u(idx[regIdx]);
|
Use &u(idx[regIdx]);
|
||||||
u.removeUser(ic);
|
u.removeUser(ic);
|
||||||
}
|
}
|
||||||
|
DU1() : numRegsDef(0) {}
|
||||||
};
|
};
|
||||||
icodeType type; /* Icode type */
|
icodeType type; /* Icode type */
|
||||||
bool invalid; /* Has no HIGH_LEVEL equivalent */
|
|
||||||
BB *inBB; /* BB to which this icode belongs */
|
BB *inBB; /* BB to which this icode belongs */
|
||||||
DU_ICODE du; /* Def/use regs/vars */
|
DU_ICODE du; /* Def/use regs/vars */
|
||||||
DU1 du1; /* du chain 1 */
|
DU1 du1; /* du chain 1 */
|
||||||
|
int loc_ip; // used by CICodeRec to number ICODEs
|
||||||
|
|
||||||
LLInst * ll() { return &m_ll;}
|
LLInst * ll() { return &m_ll;}
|
||||||
const LLInst * ll() const { return &m_ll;}
|
const LLInst * ll() const { return &m_ll;}
|
||||||
|
|
||||||
HLTYPE * hl() { return &m_hl;}
|
HLTYPE * hl() { return &m_hl;}
|
||||||
const HLTYPE * hl() const { return &m_hl;}
|
const HLTYPE * hl() const { return &m_hl;}
|
||||||
void hl(const HLTYPE &v) { m_hl=v;}
|
void hl(const HLTYPE &v) { m_hl=v;}
|
||||||
int loc_ip; // used by CICodeRec to number ICODEs
|
|
||||||
|
|
||||||
void setRegDU(eReg regi, operDu du_in);
|
void setRegDU(eReg regi, operDu du_in);
|
||||||
void invalidate();
|
void invalidate();
|
||||||
@ -355,8 +371,15 @@ public:
|
|||||||
{
|
{
|
||||||
return hl()->call.newStkArg(exp,opcode,pproc);
|
return hl()->call.newStkArg(exp,opcode,pproc);
|
||||||
}
|
}
|
||||||
|
ICODE() : m_ll(this),type(NOT_SCANNED),inBB(0),loc_ip(0),invalid(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
struct MappingLLtoML
|
||||||
|
{
|
||||||
|
std::list<std::shared_ptr<LLInst> > m_low_level;
|
||||||
|
std::list<std::shared_ptr<HLTYPE> > m_middle_level;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is the icode array object.
|
// This is the icode array object.
|
||||||
class CIcodeRec : public std::list<ICODE>
|
class CIcodeRec : public std::list<ICODE>
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <bitset>
|
||||||
/* Machine registers */
|
/* Machine registers */
|
||||||
enum eReg
|
enum eReg
|
||||||
{
|
{
|
||||||
@ -45,4 +48,18 @@ class Machine_X86
|
|||||||
public:
|
public:
|
||||||
Machine_X86();
|
Machine_X86();
|
||||||
static const std::string ®Name(eReg r);
|
static const std::string ®Name(eReg r);
|
||||||
|
static const std::string &opcodeName(unsigned r);
|
||||||
|
static bool physicalReg(eReg r);
|
||||||
|
/* Writes the registers that are set in the bitvector */
|
||||||
|
//TODO: move this into Machine_X86 ?
|
||||||
|
static void writeBitVector (std::ostream &ostr,const std::bitset<32> ®i)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
for (j = rAX; j < INDEX_BX_SI; j++)
|
||||||
|
{
|
||||||
|
if (regi.test(j-1))
|
||||||
|
ostr << regName(eReg(j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -25,7 +25,7 @@ struct STATE
|
|||||||
JCond.regi=0;
|
JCond.regi=0;
|
||||||
JCond.immed=0;
|
JCond.immed=0;
|
||||||
|
|
||||||
memset(r,0,sizeof(int16_t)*INDEX_BX_SI);
|
memset(r,0,sizeof(int16_t)*INDEX_BX_SI); //TODO: move this to machine_x86
|
||||||
memset(f,0,sizeof(uint8_t)*INDEX_BX_SI);
|
memset(f,0,sizeof(uint8_t)*INDEX_BX_SI);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -15,7 +15,6 @@ BB *BB::Create(void *ctx, const string &s, Function *parent, BB *insertBefore)
|
|||||||
|
|
||||||
BB *BB::Create(int start, int ip, uint8_t _nodeType, int numOutEdges, Function *parent)
|
BB *BB::Create(int start, int ip, uint8_t _nodeType, int numOutEdges, Function *parent)
|
||||||
{
|
{
|
||||||
//parent->m_cfg;
|
|
||||||
BB* pnewBB;
|
BB* pnewBB;
|
||||||
|
|
||||||
pnewBB = new BB;
|
pnewBB = new BB;
|
||||||
@ -36,7 +35,6 @@ BB *BB::Create(int start, int ip, uint8_t _nodeType, int numOutEdges, Function *
|
|||||||
pnewBB->range_end = parent->Icode.end();
|
pnewBB->range_end = parent->Icode.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
// pnewBB->range_start = parent->Icode.begin();
|
|
||||||
if (numOutEdges)
|
if (numOutEdges)
|
||||||
pnewBB->edges.resize(numOutEdges);
|
pnewBB->edges.resize(numOutEdges);
|
||||||
|
|
||||||
@ -101,28 +99,15 @@ void BB::displayDfs()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int edge_idx=0;
|
int edge_idx=0;
|
||||||
#ifdef _lint
|
|
||||||
for(auto iter=inEdges.begin(); iter!=inEdges.end(); ++iter)
|
|
||||||
{
|
|
||||||
BB *node(*iter);
|
|
||||||
#else
|
|
||||||
for(BB *node : inEdges)
|
for(BB *node : inEdges)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
printf (" inEdge[%ld] = %ld\n", edge_idx, node->begin()->loc_ip);
|
printf (" inEdge[%ld] = %ld\n", edge_idx, node->begin()->loc_ip);
|
||||||
edge_idx++;
|
edge_idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Display out edges information */
|
/* Display out edges information */
|
||||||
#ifdef _lint
|
|
||||||
for(auto iter=edges.begin(); iter!=edges.end(); ++iter)
|
|
||||||
{
|
|
||||||
TYPEADR_TYPE &edg(*iter);
|
|
||||||
#else
|
|
||||||
for(TYPEADR_TYPE &edg : edges)
|
for(TYPEADR_TYPE &edg : edges)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
if (nodeType == INTERVAL_NODE)
|
if (nodeType == INTERVAL_NODE)
|
||||||
printf(" outEdge[%ld] = %ld\n", i, edg.BBptr->correspInt->numInt);
|
printf(" outEdge[%ld] = %ld\n", i, edg.BBptr->correspInt->numInt);
|
||||||
else
|
else
|
||||||
@ -131,14 +116,8 @@ void BB::displayDfs()
|
|||||||
printf("----\n");
|
printf("----\n");
|
||||||
|
|
||||||
/* Recursive call on successors of current node */
|
/* Recursive call on successors of current node */
|
||||||
#ifdef _lint
|
|
||||||
for (auto ik=edges.begin(); ik!=edges.end(); ++ik)
|
|
||||||
{
|
|
||||||
TYPEADR_TYPE &pb(*ik);
|
|
||||||
#else
|
|
||||||
for(TYPEADR_TYPE &pb : edges)
|
for(TYPEADR_TYPE &pb : edges)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
if (pb.BBptr->traversed != DFS_DISP)
|
if (pb.BBptr->traversed != DFS_DISP)
|
||||||
pb.BBptr->displayDfs();
|
pb.BBptr->displayDfs();
|
||||||
}
|
}
|
||||||
@ -374,15 +353,9 @@ void BB::writeBB(int lev, Function * pProc, int *numLoc)
|
|||||||
//for (i = start, last = i + length; i < last; i++)
|
//for (i = start, last = i + length; i < last; i++)
|
||||||
|
|
||||||
/* Generate code for each hlicode that is not a HLI_JCOND */
|
/* Generate code for each hlicode that is not a HLI_JCOND */
|
||||||
//for();
|
|
||||||
#ifdef _lint
|
|
||||||
for(iICODE hli=begin(); hli!=end(); ++hli)
|
|
||||||
{
|
|
||||||
ICODE &pHli(*hli);
|
|
||||||
#else
|
|
||||||
for(ICODE &pHli : *this)
|
for(ICODE &pHli : *this)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
if ((pHli.type == HIGH_LEVEL) && ( pHli.valid() )) //TODO: use filtering range here.
|
if ((pHli.type == HIGH_LEVEL) && ( pHli.valid() )) //TODO: use filtering range here.
|
||||||
{
|
{
|
||||||
std::string line = pHli.hl()->write1HlIcode(pProc, numLoc);
|
std::string line = pHli.hl()->write1HlIcode(pProc, numLoc);
|
||||||
@ -396,10 +369,6 @@ void BB::writeBB(int lev, Function * pProc, int *numLoc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//int BB::beginIdx()
|
|
||||||
//{
|
|
||||||
// return start;
|
|
||||||
//}
|
|
||||||
|
|
||||||
iICODE BB::begin()
|
iICODE BB::begin()
|
||||||
{
|
{
|
||||||
|
|||||||
21
src/ast.cpp
21
src/ast.cpp
@ -5,7 +5,6 @@
|
|||||||
* (C) Cristina Cifuentes
|
* (C) Cristina Cifuentes
|
||||||
*/
|
*/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
//#include <malloc.h> // For free()
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -20,7 +19,6 @@ static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ",
|
|||||||
" + ", " - ", " * ", " / ",
|
" + ", " - ", " * ", " / ",
|
||||||
" >> ", " << ", " % ", " && ", " || " };
|
" >> ", " << ", " % ", " && ", " || " };
|
||||||
|
|
||||||
//#define EXP_SIZE 200 /* Size of the expression buffer */
|
|
||||||
|
|
||||||
/* Local expression stack */
|
/* Local expression stack */
|
||||||
//typedef struct _EXP_STK {
|
//typedef struct _EXP_STK {
|
||||||
@ -64,7 +62,6 @@ void ICODE::setRegDU (eReg regi, operDu du_in)
|
|||||||
/* Copies the def, use, or def and use fields of duIcode into pIcode */
|
/* Copies the def, use, or def and use fields of duIcode into pIcode */
|
||||||
void ICODE::copyDU(const ICODE &duIcode, operDu _du, operDu duDu)
|
void ICODE::copyDU(const ICODE &duIcode, operDu _du, operDu duDu)
|
||||||
{
|
{
|
||||||
// printf("%s %d,%d from %d to %d\n",__FUNCTION__,int(du),int(duDu),duIcode->ll()->getOpcode(),pIcode->ll()->getOpcode());
|
|
||||||
switch (_du)
|
switch (_du)
|
||||||
{
|
{
|
||||||
case eDEF:
|
case eDEF:
|
||||||
@ -363,9 +360,9 @@ COND_EXPR *COND_EXPR::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICO
|
|||||||
|
|
||||||
else if ((sd == SRC) && ll_insn.testFlags(I)) /* constant */
|
else if ((sd == SRC) && ll_insn.testFlags(I)) /* constant */
|
||||||
newExp = COND_EXPR::idKte (ll_insn.src.op(), 2);
|
newExp = COND_EXPR::idKte (ll_insn.src.op(), 2);
|
||||||
else if (pm.regi == 0) /* global variable */
|
else if (pm.regi == rUNDEF) /* global variable */
|
||||||
newExp = GlobalVariable::Create(pm.segValue, pm.off);
|
newExp = GlobalVariable::Create(pm.segValue, pm.off);
|
||||||
else if (pm.regi < INDEX_BX_SI) /* register */
|
else if ( pm.isReg() ) /* register */
|
||||||
{
|
{
|
||||||
newExp = COND_EXPR::idReg (pm.regi, (sd == SRC) ? ll_insn.getFlag() :
|
newExp = COND_EXPR::idReg (pm.regi, (sd == SRC) ? ll_insn.getFlag() :
|
||||||
ll_insn.getFlag() & NO_SRC_B,
|
ll_insn.getFlag() & NO_SRC_B,
|
||||||
@ -438,10 +435,11 @@ condId ICODE::idType(opLoc sd)
|
|||||||
return (CONSTANT);
|
return (CONSTANT);
|
||||||
else if (pm.regi == 0)
|
else if (pm.regi == 0)
|
||||||
return (GLOB_VAR);
|
return (GLOB_VAR);
|
||||||
else if (pm.regi < INDEX_BX_SI)
|
else if ( pm.isReg() )
|
||||||
return (REGISTER);
|
return (REGISTER);
|
||||||
else if ((pm.seg == rSS) && (pm.regi == INDEX_BX_SI))
|
else if ((pm.seg == rSS) && (pm.regi == INDEX_BP))
|
||||||
{
|
{
|
||||||
|
//TODO: which pm.seg/pm.regi pairs should produce PARAM/LOCAL_VAR ?
|
||||||
if (pm.off >= 0)
|
if (pm.off >= 0)
|
||||||
return (PARAM);
|
return (PARAM);
|
||||||
else
|
else
|
||||||
@ -793,7 +791,6 @@ string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc)
|
|||||||
|
|
||||||
/* Makes a copy of the given expression. Allocates newExp storage for each
|
/* Makes a copy of the given expression. Allocates newExp storage for each
|
||||||
* node. Returns the copy. */
|
* node. Returns the copy. */
|
||||||
//lint -sem(COND_EXPR::clone, @p!=0)
|
|
||||||
COND_EXPR *COND_EXPR::clone() const
|
COND_EXPR *COND_EXPR::clone() const
|
||||||
{
|
{
|
||||||
COND_EXPR* newExp=0; /* Expression node copy */
|
COND_EXPR* newExp=0; /* Expression node copy */
|
||||||
@ -830,6 +827,7 @@ void COND_EXPR::changeBoolOp (condOp newOp)
|
|||||||
* register regi */
|
* register regi */
|
||||||
bool COND_EXPR::insertSubTreeReg (COND_EXPR *&tree, COND_EXPR *_expr, eReg regi,LOCAL_ID *locsym)
|
bool COND_EXPR::insertSubTreeReg (COND_EXPR *&tree, COND_EXPR *_expr, eReg regi,LOCAL_ID *locsym)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (tree == NULL)
|
if (tree == NULL)
|
||||||
return false;
|
return false;
|
||||||
COND_EXPR *temp=tree->insertSubTreeReg(_expr,regi,locsym);
|
COND_EXPR *temp=tree->insertSubTreeReg(_expr,regi,locsym);
|
||||||
@ -848,7 +846,7 @@ bool isSubRegisterOf(eReg reg,eReg parent)
|
|||||||
}
|
}
|
||||||
COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, eReg regi,LOCAL_ID *locsym)
|
COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, eReg regi,LOCAL_ID *locsym)
|
||||||
{
|
{
|
||||||
//HlTypeSupport *set_val;
|
|
||||||
eReg treeReg;
|
eReg treeReg;
|
||||||
COND_EXPR *temp;
|
COND_EXPR *temp;
|
||||||
|
|
||||||
@ -894,6 +892,7 @@ COND_EXPR *COND_EXPR::insertSubTreeReg (COND_EXPR *_expr, eReg regi,LOCAL_ID *lo
|
|||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
COND_EXPR *BinaryOperator::insertSubTreeReg(COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym)
|
COND_EXPR *BinaryOperator::insertSubTreeReg(COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym)
|
||||||
@ -984,7 +983,6 @@ COND_EXPR *BinaryOperator::insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1007,7 +1005,7 @@ void COND_EXPR::release()
|
|||||||
}
|
}
|
||||||
/* Makes a copy of the given expression. Allocates newExp storage for each
|
/* Makes a copy of the given expression. Allocates newExp storage for each
|
||||||
* node. Returns the copy. */
|
* node. Returns the copy. */
|
||||||
//lint -sem(BinaryOperator::clone, @p!=0)
|
|
||||||
COND_EXPR *BinaryOperator::clone()
|
COND_EXPR *BinaryOperator::clone()
|
||||||
{
|
{
|
||||||
BinaryOperator* newExp=new BinaryOperator(m_op); /* Expression node copy */
|
BinaryOperator* newExp=new BinaryOperator(m_op); /* Expression node copy */
|
||||||
@ -1042,4 +1040,5 @@ COND_EXPR *BinaryOperator::inverse()
|
|||||||
} /* eos */
|
} /* eos */
|
||||||
assert(false);
|
assert(false);
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "dcc.h"
|
#include "dcc.h"
|
||||||
|
#include "disassem.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -136,15 +138,8 @@ static void writeGlobSymTable()
|
|||||||
if (not symtab.empty())
|
if (not symtab.empty())
|
||||||
{
|
{
|
||||||
cCode.appendDecl( "/* Global variables */\n");
|
cCode.appendDecl( "/* Global variables */\n");
|
||||||
#ifdef _lint
|
|
||||||
for (auto iter=symtab.begin(); iter!=symtab.end(); ++iter)
|
|
||||||
{
|
|
||||||
SYM &sym(*iter);
|
|
||||||
#else
|
|
||||||
for (SYM &sym : symtab)
|
for (SYM &sym : symtab)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
// pSym = &symtab[idx];
|
|
||||||
if (sym.duVal.isUSE_VAL()) /* first used */
|
if (sym.duVal.isUSE_VAL()) /* first used */
|
||||||
printGlobVar (&sym);
|
printGlobVar (&sym);
|
||||||
else { /* first defined */
|
else { /* first defined */
|
||||||
@ -184,19 +179,6 @@ static void writeHeader (std::ostream &_ios, char *fileName)
|
|||||||
freeBundle (&cCode);
|
freeBundle (&cCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Writes the registers that are set in the bitvector */
|
|
||||||
static void writeBitVector (const std::bitset<32> ®i)
|
|
||||||
{
|
|
||||||
int j;
|
|
||||||
|
|
||||||
for (j = rAX; j < INDEX_BX_SI; j++)
|
|
||||||
{
|
|
||||||
if (regi.test(j))
|
|
||||||
printf ("%s ", allRegs[j-1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: Not currently called!
|
// Note: Not currently called!
|
||||||
/* Checks the given icode to determine whether it has a label associated
|
/* Checks the given icode to determine whether it has a label associated
|
||||||
* to it. If so, a goto is emitted to this label; otherwise, a new label
|
* to it. If so, a goto is emitted to this label; otherwise, a new label
|
||||||
@ -205,7 +187,7 @@ static void writeBitVector (const std::bitset<32> ®i)
|
|||||||
* the code; that is, the target code has not been traversed yet. */
|
* the code; that is, the target code has not been traversed yet. */
|
||||||
static void emitFwdGotoLabel (ICODE * pt, int indLevel)
|
static void emitFwdGotoLabel (ICODE * pt, int indLevel)
|
||||||
{
|
{
|
||||||
if ( ! pt->ll()->testFlags(HLL_LABEL) ) /* node hasn't got a lab */
|
if ( not pt->ll()->testFlags(HLL_LABEL)) /* node hasn't got a lab */
|
||||||
{
|
{
|
||||||
/* Generate new label */
|
/* Generate new label */
|
||||||
pt->ll()->hllLabNum = getNextLabel();
|
pt->ll()->hllLabNum = getNextLabel();
|
||||||
@ -220,8 +202,10 @@ static void emitFwdGotoLabel (ICODE * pt, int indLevel)
|
|||||||
void Function::codeGen (std::ostream &fs)
|
void Function::codeGen (std::ostream &fs)
|
||||||
{
|
{
|
||||||
int numLoc;
|
int numLoc;
|
||||||
char buf[200], /* Procedure's definition */
|
ostringstream buf;
|
||||||
arg[30]; /* One argument */
|
//STKFRAME * args; /* Procedure arguments */
|
||||||
|
//char buf[200], /* Procedure's definition */
|
||||||
|
// arg[30]; /* One argument */
|
||||||
BB *pBB; /* Pointer to basic block */
|
BB *pBB; /* Pointer to basic block */
|
||||||
|
|
||||||
/* Write procedure/function header */
|
/* Write procedure/function header */
|
||||||
@ -232,19 +216,17 @@ void Function::codeGen (std::ostream &fs)
|
|||||||
cCode.appendDecl( "\nvoid %s (", name.c_str());
|
cCode.appendDecl( "\nvoid %s (", name.c_str());
|
||||||
|
|
||||||
/* Write arguments */
|
/* Write arguments */
|
||||||
memset (buf, 0, sizeof(buf));
|
|
||||||
for (size_t i = 0; i < args.sym.size(); i++)
|
for (size_t i = 0; i < args.sym.size(); i++)
|
||||||
{
|
{
|
||||||
if (args.sym[i].invalid == FALSE)
|
if (args.sym[i].invalid == FALSE)
|
||||||
{
|
{
|
||||||
sprintf (arg,"%s %s",hlTypes[args.sym[i].type], args.sym[i].name);
|
buf<<hlTypes[args.sym[i].type]<<" "<<args.sym[i].name;
|
||||||
strcat (buf, arg);
|
|
||||||
if (i < (args.sym.size() - 1))
|
if (i < (args.sym.size() - 1))
|
||||||
strcat (buf, ", ");
|
buf<<", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strcat (buf, ")\n");
|
buf<<")\n";
|
||||||
cCode.appendDecl( "%s", buf);
|
cCode.appendDecl( buf.str() );
|
||||||
|
|
||||||
/* Write comments */
|
/* Write comments */
|
||||||
writeProcComments();
|
writeProcComments();
|
||||||
@ -253,14 +235,8 @@ void Function::codeGen (std::ostream &fs)
|
|||||||
if (! (flg & PROC_ASM))
|
if (! (flg & PROC_ASM))
|
||||||
{
|
{
|
||||||
numLoc = 0;
|
numLoc = 0;
|
||||||
#ifdef _lint
|
|
||||||
for (size_t i = 0; i < localId.csym(); i++)
|
|
||||||
{
|
|
||||||
ID &refId(localId.id_arr[i]);
|
|
||||||
#else
|
|
||||||
for (ID &refId : localId )
|
for (ID &refId : localId )
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
/* Output only non-invalidated entries */
|
/* Output only non-invalidated entries */
|
||||||
if (refId.illegal == FALSE)
|
if (refId.illegal == FALSE)
|
||||||
{
|
{
|
||||||
@ -290,7 +266,9 @@ void Function::codeGen (std::ostream &fs)
|
|||||||
if (flg & PROC_ASM) /* generate assembler */
|
if (flg & PROC_ASM) /* generate assembler */
|
||||||
disassem (3, this);
|
disassem (3, this);
|
||||||
else /* generate C */
|
else /* generate C */
|
||||||
|
{
|
||||||
m_cfg.front()->writeCode (1, this, &numLoc, MAX, UN_INIT);
|
m_cfg.front()->writeCode (1, this, &numLoc, MAX, UN_INIT);
|
||||||
|
}
|
||||||
|
|
||||||
cCode.appendCode( "}\n\n");
|
cCode.appendCode( "}\n\n");
|
||||||
writeBundle (fs, cCode);
|
writeBundle (fs, cCode);
|
||||||
@ -302,17 +280,18 @@ void Function::codeGen (std::ostream &fs)
|
|||||||
{
|
{
|
||||||
pBB = m_dfsLast[i];
|
pBB = m_dfsLast[i];
|
||||||
if (pBB->flg & INVALID_BB) continue; /* skip invalid BBs */
|
if (pBB->flg & INVALID_BB) continue; /* skip invalid BBs */
|
||||||
printf ("BB %d\n", i);
|
cout << "BB "<<i<<"\n";
|
||||||
printf (" Start = %d, end = %d\n", pBB->begin()->loc_ip, pBB->begin()->loc_ip+pBB->size());
|
cout << " Start = "<<pBB->begin()->loc_ip;
|
||||||
printf (" LiveUse = ");
|
cout << ", end = "<<pBB->begin()->loc_ip+pBB->size()<<"\n";
|
||||||
writeBitVector (pBB->liveUse);
|
cout << " LiveUse = ";
|
||||||
printf ("\n Def = ");
|
Machine_X86::writeBitVector(cout,pBB->liveUse);
|
||||||
writeBitVector (pBB->def);
|
cout << "\n Def = ";
|
||||||
printf ("\n LiveOut = ");
|
Machine_X86::writeBitVector(cout,pBB->def);
|
||||||
writeBitVector (pBB->liveOut);
|
cout << "\n LiveOut = ";
|
||||||
printf ("\n LiveIn = ");
|
Machine_X86::writeBitVector(cout,pBB->liveOut);
|
||||||
writeBitVector (pBB->liveIn);
|
cout << "\n LiveIn = ";
|
||||||
printf ("\n\n");
|
Machine_X86::writeBitVector(cout,pBB->liveIn);
|
||||||
|
cout <<"\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,6 +300,7 @@ void Function::codeGen (std::ostream &fs)
|
|||||||
* of the call graph. */
|
* of the call graph. */
|
||||||
static void backBackEnd (char *filename, CALL_GRAPH * pcallGraph, std::ostream &_ios)
|
static void backBackEnd (char *filename, CALL_GRAPH * pcallGraph, std::ostream &_ios)
|
||||||
{
|
{
|
||||||
|
|
||||||
// IFace.Yield(); /* This is a good place to yield to other apps */
|
// IFace.Yield(); /* This is a good place to yield to other apps */
|
||||||
|
|
||||||
/* Check if this procedure has been processed already */
|
/* Check if this procedure has been processed already */
|
||||||
|
|||||||
@ -63,8 +63,8 @@ static void freeStrTab (strTable &strTab)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void freeBundle (bundle *procCode)
|
|
||||||
/* Deallocates the space taken by the bundle procCode */
|
/* Deallocates the space taken by the bundle procCode */
|
||||||
|
void freeBundle (bundle *procCode)
|
||||||
{
|
{
|
||||||
freeStrTab (procCode->decl);
|
freeStrTab (procCode->decl);
|
||||||
freeStrTab (procCode->code);
|
freeStrTab (procCode->code);
|
||||||
@ -90,4 +90,10 @@ void bundle::appendDecl(const char *format,...)
|
|||||||
va_end (args);
|
va_end (args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bundle::appendDecl(const std::string &v)
|
||||||
|
{
|
||||||
|
decl.push_back(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -62,8 +62,8 @@ static int numArg; /* Number of param names actually stored
|
|||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
void grab(int n, FILE *_file);
|
void grab(int n, FILE *_file);
|
||||||
uint16_t readFileShort(FILE *g_file);
|
uint16_t readFileShort(FILE *_file);
|
||||||
void readFileSection(uint16_t* p, int len, FILE *g_file);
|
void readFileSection(uint16_t* p, int len, FILE *_file);
|
||||||
void cleanup(void);
|
void cleanup(void);
|
||||||
void checkStartup(STATE *state);
|
void checkStartup(STATE *state);
|
||||||
void readProtoFile(void);
|
void readProtoFile(void);
|
||||||
@ -908,11 +908,17 @@ readProtoFile(void)
|
|||||||
|
|
||||||
for (i=0; i < numFunc; i++)
|
for (i=0; i < numFunc; i++)
|
||||||
{
|
{
|
||||||
fread(&pFunc[i], 1, SYMLEN, fProto);
|
size_t read_size=fread(&pFunc[i], 1, SYMLEN, fProto);
|
||||||
|
assert(read_size==SYMLEN);
|
||||||
|
if(read_size!=SYMLEN)
|
||||||
|
break;
|
||||||
pFunc[i].typ = (hlType)readFileShort(fProto);
|
pFunc[i].typ = (hlType)readFileShort(fProto);
|
||||||
pFunc[i].numArg = readFileShort(fProto);
|
pFunc[i].numArg = readFileShort(fProto);
|
||||||
pFunc[i].firstArg = readFileShort(fProto);
|
pFunc[i].firstArg = readFileShort(fProto);
|
||||||
fread(&pFunc[i].bVararg, 1, 1, fProto);
|
if(feof(fProto))
|
||||||
|
break;
|
||||||
|
int c = fgetc(fProto);
|
||||||
|
pFunc[i].bVararg = (c!=0); //fread(&pFunc[i].bVararg, 1, 1, fProto);
|
||||||
}
|
}
|
||||||
|
|
||||||
grab(2, fProto);
|
grab(2, fProto);
|
||||||
|
|||||||
@ -65,24 +65,14 @@ static int commonDom (int currImmDom, int predImmDom, Function * pProc)
|
|||||||
void Function::findImmedDom ()
|
void Function::findImmedDom ()
|
||||||
{
|
{
|
||||||
BB * currNode;
|
BB * currNode;
|
||||||
int currIdx, predIdx;
|
for (size_t currIdx = 0; currIdx < numBBs; currIdx++)
|
||||||
|
|
||||||
for (currIdx = 0; currIdx < numBBs; currIdx++)
|
|
||||||
{
|
{
|
||||||
currNode = m_dfsLast[currIdx];
|
currNode = m_dfsLast[currIdx];
|
||||||
if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */
|
if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */
|
||||||
continue;
|
continue;
|
||||||
#ifdef _lint
|
|
||||||
BB * inedge=0;
|
|
||||||
for (auto i=currNode->inEdges.begin(); i!=currNode->inEdges.end(); ++i)
|
|
||||||
{
|
|
||||||
inedge=*i;
|
|
||||||
|
|
||||||
#else
|
|
||||||
for (BB * inedge : currNode->inEdges)
|
for (BB * inedge : currNode->inEdges)
|
||||||
{
|
{
|
||||||
#endif
|
size_t predIdx = inedge->dfsLastNum;
|
||||||
predIdx = inedge->dfsLastNum;
|
|
||||||
if (predIdx < currIdx)
|
if (predIdx < currIdx)
|
||||||
currNode->immedDom = commonDom (currNode->immedDom, predIdx, this);
|
currNode->immedDom = commonDom (currNode->immedDom, predIdx, this);
|
||||||
}
|
}
|
||||||
@ -259,30 +249,15 @@ static void findNodesInInt (queue &intNodes, int level, interval *Ii)
|
|||||||
{
|
{
|
||||||
if (level == 1)
|
if (level == 1)
|
||||||
{
|
{
|
||||||
#ifdef _lint
|
|
||||||
BB * en=0;
|
|
||||||
for (auto i=Ii->nodes.begin(); i!=Ii->nodes.end(); ++i)
|
|
||||||
{
|
|
||||||
en=*i;
|
|
||||||
#else
|
|
||||||
for(BB *en : Ii->nodes)
|
for(BB *en : Ii->nodes)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
appendQueue(intNodes,en);
|
appendQueue(intNodes,en);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef _lint
|
|
||||||
BB * en=0;
|
|
||||||
for (auto i=Ii->nodes.begin(); i!=Ii->nodes.end(); ++i)
|
|
||||||
{
|
|
||||||
en=*i;
|
|
||||||
|
|
||||||
#else
|
|
||||||
for(BB *en : Ii->nodes)
|
for(BB *en : Ii->nodes)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
findNodesInInt(intNodes,level-1,en->correspInt);
|
findNodesInInt(intNodes,level-1,en->correspInt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,8 +271,7 @@ void Function::structLoops(derSeq *derivedG)
|
|||||||
BB * intHead, /* interval header node */
|
BB * intHead, /* interval header node */
|
||||||
* pred, /* predecessor node */
|
* pred, /* predecessor node */
|
||||||
* latchNode;/* latching node (in case of loops) */
|
* latchNode;/* latching node (in case of loops) */
|
||||||
int
|
size_t level = 0; /* derived sequence level */
|
||||||
level = 0; /* derived sequence level */
|
|
||||||
interval *initInt; /* initial interval */
|
interval *initInt; /* initial interval */
|
||||||
queue intNodes; /* list of interval nodes */
|
queue intNodes; /* list of interval nodes */
|
||||||
|
|
||||||
@ -362,16 +336,15 @@ void Function::structLoops(derSeq *derivedG)
|
|||||||
|
|
||||||
/* Returns whether the BB indexed by s is a successor of the BB indexed by
|
/* Returns whether the BB indexed by s is a successor of the BB indexed by
|
||||||
* h. Note that h is a case node. */
|
* h. Note that h is a case node. */
|
||||||
static boolT successor (int s, int h, Function * pProc)
|
static bool successor (int s, int h, Function * pProc)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
BB * header;
|
BB * header;
|
||||||
|
|
||||||
header = pProc->m_dfsLast[h];
|
header = pProc->m_dfsLast[h];
|
||||||
for (i = 0; i < header->edges.size(); i++)
|
auto iter = std::find_if(header->edges.begin(),
|
||||||
if (header->edges[i].BBptr->dfsLastNum == s)
|
header->edges.end(),
|
||||||
return true;
|
[s](const TYPEADR_TYPE &te)->bool{ return te.BBptr->dfsLastNum == s;});
|
||||||
return false;
|
return iter!=header->edges.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -428,14 +401,8 @@ void Function::structCases()
|
|||||||
* header field with caseHeader. */
|
* header field with caseHeader. */
|
||||||
insertList (caseNodes, i);
|
insertList (caseNodes, i);
|
||||||
m_dfsLast[i]->caseHead = i;
|
m_dfsLast[i]->caseHead = i;
|
||||||
#ifdef _lint
|
|
||||||
for (auto ki=caseHeader->edges.begin(); ki!=caseHeader->edges.end(); ++ki)
|
|
||||||
{
|
|
||||||
TYPEADR_TYPE &pb(*ki);
|
|
||||||
#else
|
|
||||||
for(TYPEADR_TYPE &pb : caseHeader->edges)
|
for(TYPEADR_TYPE &pb : caseHeader->edges)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
tagNodesInCase(pb.BBptr, caseNodes, i, exitNode);
|
tagNodesInCase(pb.BBptr, caseNodes, i, exitNode);
|
||||||
}
|
}
|
||||||
//for (j = 0; j < caseHeader->edges[j]; j++)
|
//for (j = 0; j < caseHeader->edges[j]; j++)
|
||||||
@ -525,8 +492,6 @@ void Function::compoundCond()
|
|||||||
int i; //j, k, numOutEdges
|
int i; //j, k, numOutEdges
|
||||||
BB * pbb, * t, * e, * obb;//,* pred;
|
BB * pbb, * t, * e, * obb;//,* pred;
|
||||||
ICODE * picode, * ticode;
|
ICODE * picode, * ticode;
|
||||||
//COND_EXPR *exp;
|
|
||||||
//TYPEADR_TYPE *edges;
|
|
||||||
boolT change;
|
boolT change;
|
||||||
|
|
||||||
change = TRUE;
|
change = TRUE;
|
||||||
|
|||||||
@ -6,14 +6,14 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "dcc.h"
|
#include "dcc.h"
|
||||||
//#include <boost/range.hpp>
|
#include <boost/range.hpp>
|
||||||
//#include <boost/range/adaptors.hpp>
|
#include <boost/range/adaptors.hpp>
|
||||||
//#include <boost/range/algorithm.hpp>
|
#include <boost/range/algorithm.hpp>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
//using namespace boost;
|
using namespace boost;
|
||||||
struct ExpStack
|
struct ExpStack
|
||||||
{
|
{
|
||||||
typedef std::list<COND_EXPR *> EXP_STK;
|
typedef std::list<COND_EXPR *> EXP_STK;
|
||||||
@ -120,7 +120,7 @@ void Function::elimCondCodes ()
|
|||||||
BB * pBB; /* Pointer to BBs in dfs last ordering */
|
BB * pBB; /* Pointer to BBs in dfs last ordering */
|
||||||
riICODE useAt; /* Instruction that used flag */
|
riICODE useAt; /* Instruction that used flag */
|
||||||
riICODE defAt; /* Instruction that defined flag */
|
riICODE defAt; /* Instruction that defined flag */
|
||||||
lhs=rhs=_expr=0;
|
//lhs=rhs=_expr=0;
|
||||||
for (i = 0; i < numBBs; i++)
|
for (i = 0; i < numBBs; i++)
|
||||||
{
|
{
|
||||||
pBB = m_dfsLast[i];
|
pBB = m_dfsLast[i];
|
||||||
@ -129,10 +129,9 @@ void Function::elimCondCodes ()
|
|||||||
// auto v(pBB | boost::adaptors::reversed);
|
// auto v(pBB | boost::adaptors::reversed);
|
||||||
// for (const ICODE &useAt : v)
|
// for (const ICODE &useAt : v)
|
||||||
// {}
|
// {}
|
||||||
assert(distance(pBB->rbegin(),pBB->rend())==pBB->size());
|
|
||||||
for (useAt = pBB->rbegin(); useAt != pBB->rend(); useAt++)
|
for (useAt = pBB->rbegin(); useAt != pBB->rend(); useAt++)
|
||||||
{
|
{
|
||||||
llIcode useAtOp = useAt->ll()->getOpcode();
|
llIcode useAtOp = llIcode(useAt->ll()->getOpcode());
|
||||||
use = useAt->ll()->flagDU.u;
|
use = useAt->ll()->flagDU.u;
|
||||||
if ((useAt->type != LOW_LEVEL) || ( ! useAt->valid() ) || ( 0 == use ))
|
if ((useAt->type != LOW_LEVEL) || ( ! useAt->valid() ) || ( 0 == use ))
|
||||||
continue;
|
continue;
|
||||||
@ -252,14 +251,8 @@ void Function::genLiveKtes ()
|
|||||||
pbb = m_dfsLast[i];
|
pbb = m_dfsLast[i];
|
||||||
if (pbb->flg & INVALID_BB)
|
if (pbb->flg & INVALID_BB)
|
||||||
continue; // skip invalid BBs
|
continue; // skip invalid BBs
|
||||||
#ifdef _lint
|
|
||||||
for (auto j = pbb->begin(); j != pbb->end(); j++)
|
|
||||||
{
|
|
||||||
ICODE &insn(*j);
|
|
||||||
#else
|
|
||||||
for(ICODE &insn : *pbb)
|
for(ICODE &insn : *pbb)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
if ((insn.type == HIGH_LEVEL) && ( insn.valid() ))
|
if ((insn.type == HIGH_LEVEL) && ( insn.valid() ))
|
||||||
{
|
{
|
||||||
liveUse |= (insn.du.use & ~def);
|
liveUse |= (insn.du.use & ~def);
|
||||||
@ -326,14 +319,8 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
|
|||||||
}
|
}
|
||||||
else /* Check successors */
|
else /* Check successors */
|
||||||
{
|
{
|
||||||
#ifdef _lint
|
|
||||||
for (auto i=pbb->edges.begin(); i!=pbb->edges.end(); ++i)
|
|
||||||
{
|
|
||||||
TYPEADR_TYPE &e(*i);
|
|
||||||
#else
|
|
||||||
for(TYPEADR_TYPE &e : pbb->edges)
|
for(TYPEADR_TYPE &e : pbb->edges)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
pbb->liveOut |= e.BBptr->liveIn;
|
pbb->liveOut |= e.BBptr->liveIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,7 +398,6 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut)
|
|||||||
void BB::genDU1()
|
void BB::genDU1()
|
||||||
{
|
{
|
||||||
eReg regi; /* Register that was defined */
|
eReg regi; /* Register that was defined */
|
||||||
|
|
||||||
int k, defRegIdx, useIdx;
|
int k, defRegIdx, useIdx;
|
||||||
iICODE picode, ticode,lastInst;
|
iICODE picode, ticode,lastInst;
|
||||||
BB *tbb; /* Target basic block */
|
BB *tbb; /* Target basic block */
|
||||||
@ -505,9 +491,9 @@ void BB::genDU1()
|
|||||||
* from a library function (routines such as printf
|
* from a library function (routines such as printf
|
||||||
* return an integer, which is normally not taken into
|
* return an integer, which is normally not taken into
|
||||||
* account by the programmer). */
|
* account by the programmer). */
|
||||||
if (picode->valid() && ! picode->du1.used(defRegIdx) &&
|
if (picode->valid() and not picode->du1.used(defRegIdx) and
|
||||||
( ! (picode->du.lastDefRegi & duReg[regi]).any()) &&
|
(not (picode->du.lastDefRegi & duReg[regi]).any()) &&
|
||||||
( ! ((picode->hl()->opcode == HLI_CALL) &&
|
(not ((picode->hl()->opcode == HLI_CALL) &&
|
||||||
(picode->hl()->call.proc->flg & PROC_ISLIB))))
|
(picode->hl()->call.proc->flg & PROC_ISLIB))))
|
||||||
{
|
{
|
||||||
if (! (this->liveOut & duReg[regi]).any()) /* not liveOut */
|
if (! (this->liveOut & duReg[regi]).any()) /* not liveOut */
|
||||||
@ -542,14 +528,8 @@ void Function::genDU1 ()
|
|||||||
{
|
{
|
||||||
/* Traverse tree in dfsLast order */
|
/* Traverse tree in dfsLast order */
|
||||||
assert(m_dfsLast.size()==numBBs);
|
assert(m_dfsLast.size()==numBBs);
|
||||||
#ifdef _lint
|
|
||||||
for (auto i=m_dfsLast.begin(); i!=m_dfsLast.end(); ++i)
|
|
||||||
{
|
|
||||||
BB *pbb(*i);
|
|
||||||
#else
|
|
||||||
for(BB *pbb : m_dfsLast)
|
for(BB *pbb : m_dfsLast)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
if (pbb->flg & INVALID_BB)
|
if (pbb->flg & INVALID_BB)
|
||||||
continue;
|
continue;
|
||||||
pbb->genDU1();
|
pbb->genDU1();
|
||||||
@ -636,7 +616,7 @@ bool COND_EXPR::xClear (iICODE f, iICODE t, iICODE lastBBinst, Function * pproc)
|
|||||||
{
|
{
|
||||||
regi= pproc->localId.id_arr[expr.ident.idNode.regiIdx].id.regi;
|
regi= pproc->localId.id_arr[expr.ident.idNode.regiIdx].id.regi;
|
||||||
for (i = ++iICODE(f); (i != lastBBinst) && (i!=t); i++)
|
for (i = ++iICODE(f); (i != lastBBinst) && (i!=t); i++)
|
||||||
if ((i->type == HIGH_LEVEL) && ( not i->invalid ))
|
if ((i->type == HIGH_LEVEL) && ( i->valid() ))
|
||||||
{
|
{
|
||||||
if ((i->du.def & duReg[regi]).any())
|
if ((i->du.def & duReg[regi]).any())
|
||||||
return false;
|
return false;
|
||||||
@ -711,13 +691,13 @@ static int processCArg (Function * pp, Function * pProc, ICODE * picode, int num
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
adjustActArgType (_exp, pp->args.sym[numArgs].type, pProc);
|
adjustActArgType (_exp, pp->args.sym[numArgs].type, pProc);
|
||||||
res = picode->newStkArg (_exp, picode->ll()->getOpcode(), pProc);
|
res = picode->newStkArg (_exp, (llIcode)picode->ll()->getOpcode(), pProc);
|
||||||
}
|
}
|
||||||
else /* user function */
|
else /* user function */
|
||||||
{
|
{
|
||||||
if (pp->args.numArgs > 0)
|
if (pp->args.numArgs > 0)
|
||||||
pp->args.adjustForArgType (numArgs, expType (_exp, pProc));
|
pp->args.adjustForArgType (numArgs, expType (_exp, pProc));
|
||||||
res = picode->newStkArg (_exp, picode->ll()->getOpcode(), pProc);
|
res = picode->newStkArg (_exp, (llIcode)picode->ll()->getOpcode(), pProc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do not update the size of k if the expression was a segment register
|
/* Do not update the size of k if the expression was a segment register
|
||||||
@ -796,13 +776,13 @@ void Function::processHliCall1(COND_EXPR *_exp, iICODE picode)
|
|||||||
{
|
{
|
||||||
if (pp->args.numArgs > 0)
|
if (pp->args.numArgs > 0)
|
||||||
adjustActArgType(_exp, pp->args.sym[numArgs].type, this);
|
adjustActArgType(_exp, pp->args.sym[numArgs].type, this);
|
||||||
res = picode->newStkArg (_exp, picode->ll()->getOpcode(), this);
|
res = picode->newStkArg (_exp, (llIcode)picode->ll()->getOpcode(), this);
|
||||||
}
|
}
|
||||||
else /* user function */
|
else /* user function */
|
||||||
{
|
{
|
||||||
if (pp->args.numArgs >0)
|
if (pp->args.numArgs >0)
|
||||||
pp->args.adjustForArgType (numArgs,expType (_exp, this));
|
pp->args.adjustForArgType (numArgs,expType (_exp, this));
|
||||||
res = picode->newStkArg (_exp,picode->ll()->getOpcode(), this);
|
res = picode->newStkArg (_exp,(llIcode)picode->ll()->getOpcode(), this);
|
||||||
}
|
}
|
||||||
if (res == FALSE)
|
if (res == FALSE)
|
||||||
k += hlTypeSize (_exp, this);
|
k += hlTypeSize (_exp, this);
|
||||||
@ -849,6 +829,7 @@ void Function::findExps()
|
|||||||
|
|
||||||
/* Initialize expression stack */
|
/* Initialize expression stack */
|
||||||
g_exp_stk.init();
|
g_exp_stk.init();
|
||||||
|
|
||||||
_exp = 0;
|
_exp = 0;
|
||||||
/* Traverse tree in dfsLast order */
|
/* Traverse tree in dfsLast order */
|
||||||
for (i = 0; i < numBBs; i++)
|
for (i = 0; i < numBBs; i++)
|
||||||
@ -1125,9 +1106,11 @@ void Function::dataFlow(std::bitset<32> &_liveOut)
|
|||||||
isCx = _liveOut.test(rCX - rAX);
|
isCx = _liveOut.test(rCX - rAX);
|
||||||
isDx = _liveOut.test(rDX - rAX);
|
isDx = _liveOut.test(rDX - rAX);
|
||||||
bool isAL = !isAx && _liveOut.test(rAL - rAX);
|
bool isAL = !isAx && _liveOut.test(rAL - rAX);
|
||||||
bool isBL = !isBx && _liveOut.test(rBL - rAX);
|
|
||||||
bool isCL = !isCx && _liveOut.test(rCL - rAX);
|
|
||||||
bool isAH = !isAx && _liveOut.test(rAH - rAX);
|
bool isAH = !isAx && _liveOut.test(rAH - rAX);
|
||||||
|
bool isBL = !isBx && _liveOut.test(rBL - rAX);
|
||||||
|
bool isBH = !isBx && _liveOut.test(rBH - rAX);
|
||||||
|
bool isCL = !isCx && _liveOut.test(rCL - rAX);
|
||||||
|
bool isCH = !isCx && _liveOut.test(rCH - rAX);
|
||||||
bool isDL = !isDx && _liveOut.test(rDL - rAX);
|
bool isDL = !isDx && _liveOut.test(rDL - rAX);
|
||||||
bool isDH = !isDx && _liveOut.test(rDH - rAX);
|
bool isDH = !isDx && _liveOut.test(rDH - rAX);
|
||||||
if(isAL && isAH)
|
if(isAL && isAH)
|
||||||
@ -1142,6 +1125,19 @@ void Function::dataFlow(std::bitset<32> &_liveOut)
|
|||||||
printf("**************************************************************************** dataFlow Join discovered Dx\n");
|
printf("**************************************************************************** dataFlow Join discovered Dx\n");
|
||||||
isDH=isDL=false;
|
isDH=isDL=false;
|
||||||
}
|
}
|
||||||
|
if(isBL && isBH)
|
||||||
|
{
|
||||||
|
isBx = true;
|
||||||
|
printf("**************************************************************************** dataFlow Join discovered Dx\n");
|
||||||
|
isBH=isBL=false;
|
||||||
|
}
|
||||||
|
if(isCL && isCH)
|
||||||
|
{
|
||||||
|
isCx = true;
|
||||||
|
printf("**************************************************************************** dataFlow Join discovered Dx\n");
|
||||||
|
isCH=isCL=false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isAx && isDx) /* long or pointer */
|
if (isAx && isDx) /* long or pointer */
|
||||||
{
|
{
|
||||||
retVal.type = TYPE_LONG_SIGN;
|
retVal.type = TYPE_LONG_SIGN;
|
||||||
|
|||||||
@ -8,7 +8,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* Global variables - extern to other modules */
|
/* Global variables - extern to other modules */
|
||||||
//char *progname; /* argv[0] - for error msgs */
|
|
||||||
char *asm1_name, *asm2_name; /* Assembler output filenames */
|
char *asm1_name, *asm2_name; /* Assembler output filenames */
|
||||||
SYMTAB symtab; /* Global symbol table */
|
SYMTAB symtab; /* Global symbol table */
|
||||||
STATS stats; /* cfg statistics */
|
STATS stats; /* cfg statistics */
|
||||||
@ -73,7 +72,6 @@ int main(int argc, char *argv[])
|
|||||||
static char *initargs(int argc, char *argv[])
|
static char *initargs(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *pc;
|
char *pc;
|
||||||
//progname = *argv; /* Save invocation name for error messages */
|
|
||||||
|
|
||||||
while (--argc > 0 && (*++argv)[0] == '-')
|
while (--argc > 0 && (*++argv)[0] == '-')
|
||||||
{
|
{
|
||||||
@ -102,7 +100,6 @@ static char *initargs(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'V': /* Very verbose => verbose */
|
case 'V': /* Very verbose => verbose */
|
||||||
option.VeryVerbose = true;
|
option.VeryVerbose = true;
|
||||||
//lint -fallthrough
|
|
||||||
case 'v':
|
case 'v':
|
||||||
option.verbose = true; /* Make everything verbose */
|
option.verbose = true; /* Make everything verbose */
|
||||||
break;
|
break;
|
||||||
@ -115,10 +112,9 @@ static char *initargs(int argc, char *argv[])
|
|||||||
asm1_name = asm2_name = *++argv;
|
asm1_name = asm2_name = *++argv;
|
||||||
goto NextArg;
|
goto NextArg;
|
||||||
}
|
}
|
||||||
//lint -fallthrough
|
|
||||||
default:
|
default:
|
||||||
fatalError(INVALID_ARG, *pc); // does not return
|
fatalError(INVALID_ARG, *pc);
|
||||||
|
return *argv;
|
||||||
}
|
}
|
||||||
NextArg:;
|
NextArg:;
|
||||||
}
|
}
|
||||||
|
|||||||
136
src/disassem.cpp
136
src/disassem.cpp
@ -33,24 +33,6 @@ using namespace std;
|
|||||||
|
|
||||||
#define DELTA_ICODE 16 /* Number of icodes to realloc by each time */
|
#define DELTA_ICODE 16 /* Number of icodes to realloc by each time */
|
||||||
|
|
||||||
static const char *szOps[] =
|
|
||||||
{
|
|
||||||
"CBW", "AAA", "AAD", "AAM", "AAS", "ADC", "ADD", "AND",
|
|
||||||
"BOUND","CALL", "CALL", "CLC", "CLD", "CLI", "CMC", "CMP",
|
|
||||||
"CMPS", "REPNE CMPS","REPE CMPS","DAA", "DAS", "DEC", "DIV", "ENTER",
|
|
||||||
"ESC", "HLT", "IDIV", "IMUL", "IN", "INC", "INS", "REP INS",
|
|
||||||
"INT", "IRET", "JB", "JBE", "JAE", "JA", "JE", "JNE",
|
|
||||||
"JL", "JGE", "JLE", "JG", "JS", "JNS", "JO", "JNO",
|
|
||||||
"JP", "JNP", "JCXZ", "JMP", "JMP", "LAHF", "LDS", "LEA",
|
|
||||||
"LEAVE","LES", "LOCK", "LODS", "REP LODS", "LOOP", "LOOPE","LOOPNE",
|
|
||||||
"MOV", "MOVS", "REP MOVS", "MUL", "NEG", "NOT", "OR", "OUT",
|
|
||||||
"OUTS", "REP OUTS", "POP", "POPA", "POPF", "PUSH", "PUSHA","PUSHF",
|
|
||||||
"RCL", "RCR", "ROL", "ROR", "RET", "RETF", "SAHF", "SAR",
|
|
||||||
"SHL", "SHR", "SBB", "SCAS", "REPNE SCAS","REPE SCAS", "CWD", "STC",
|
|
||||||
"STD", "STI", "STOS", "REP STOS", "SUB", "TEST", "WAIT", "XCHG",
|
|
||||||
"XLAT", "XOR", "INTO", "NOP", "REPNE", "REPE", "MOD"
|
|
||||||
};
|
|
||||||
|
|
||||||
/* The following opcodes are for mod != 3 */
|
/* The following opcodes are for mod != 3 */
|
||||||
static const char *szFlops1[] =
|
static const char *szFlops1[] =
|
||||||
{
|
{
|
||||||
@ -120,10 +102,10 @@ static const char *szFlops3C[] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const char *szIndex[8] = {"bx+si", "bx+di", "bp+si", "bp+di", "si", "di","bp","bx" };
|
//static const char *szIndex[8] = {"bx+si", "bx+di", "bp+si", "bp+di", "si", "di","bp","bx" };
|
||||||
static const char *szBreg[8] = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh" };
|
//static const char *szBreg[8] = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh" };
|
||||||
static const char *szWreg[12] = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
|
//static const char *szWreg[12] = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
|
||||||
"es", "cs", "ss", "ds" };
|
// "es", "cs", "ss", "ds" };
|
||||||
static const char *szPtr[2] = { "word ptr ", "byte ptr " };
|
static const char *szPtr[2] = { "word ptr ", "byte ptr " };
|
||||||
|
|
||||||
|
|
||||||
@ -139,7 +121,6 @@ boolT callArg(uint16_t off, char *temp); /* Check for procedure name */
|
|||||||
|
|
||||||
static FILE *fp;
|
static FILE *fp;
|
||||||
static CIcodeRec pc;
|
static CIcodeRec pc;
|
||||||
|
|
||||||
static int cb, j, numIcode, allocIcode;
|
static int cb, j, numIcode, allocIcode;
|
||||||
static map<int,int> pl;
|
static map<int,int> pl;
|
||||||
static uint32_t nextInst;
|
static uint32_t nextInst;
|
||||||
@ -229,14 +210,8 @@ void disassem(int pass, Function * ppProc)
|
|||||||
{
|
{
|
||||||
/* Bind jump offsets to labels */
|
/* Bind jump offsets to labels */
|
||||||
//for (i = 0; i < numIcode; i++)
|
//for (i = 0; i < numIcode; i++)
|
||||||
#ifdef _lint
|
|
||||||
for (auto i=pc.begin(); i!=pc.end(); ++i)
|
|
||||||
{
|
|
||||||
ICODE &icode(*i);
|
|
||||||
#else
|
|
||||||
for( ICODE &icode : pc)
|
for( ICODE &icode : pc)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
LLInst *ll=icode.ll();
|
LLInst *ll=icode.ll();
|
||||||
ll->findJumpTargets(pc);
|
ll->findJumpTargets(pc);
|
||||||
}
|
}
|
||||||
@ -251,14 +226,8 @@ void disassem(int pass, Function * ppProc)
|
|||||||
|
|
||||||
/* Loop over array printing each record */
|
/* Loop over array printing each record */
|
||||||
nextInst = 0;
|
nextInst = 0;
|
||||||
#ifdef _lint
|
|
||||||
for (auto i=pc.begin(); i!=pc.end(); ++i)
|
|
||||||
{
|
|
||||||
ICODE &icode(*i);
|
|
||||||
#else
|
|
||||||
for( ICODE &icode : pc)
|
for( ICODE &icode : pc)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
icode.ll()->dis1Line(icode.loc_ip,pass);
|
icode.ll()->dis1Line(icode.loc_ip,pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +241,6 @@ void disassem(int pass, Function * ppProc)
|
|||||||
pc.clear();
|
pc.clear();
|
||||||
destroySymTables();
|
destroySymTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* dis1Line() - disassemble one line to stream fp * *
|
* dis1Line() - disassemble one line to stream fp * *
|
||||||
* i is index into Icode for this proc *
|
* i is index into Icode for this proc *
|
||||||
@ -292,16 +260,16 @@ void LLInst::dis1Line(int loc_ip, int pass)
|
|||||||
* Do not try to display NO_CODE entries or synthetic instructions,
|
* Do not try to display NO_CODE entries or synthetic instructions,
|
||||||
* other than JMPs, that have been introduced for def/use analysis. */
|
* other than JMPs, that have been introduced for def/use analysis. */
|
||||||
if ((option.asm1) &&
|
if ((option.asm1) &&
|
||||||
( testFlags(NO_CODE) ||
|
( this->testFlags(NO_CODE) ||
|
||||||
(testFlags(SYNTHETIC) && (opcode != iJMP))))
|
(this->testFlags(SYNTHETIC) && (this->getOpcode() != iJMP))))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (testFlags(NO_CODE))
|
else if (this->testFlags(NO_CODE))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (testFlags(TARGET | CASE))
|
if (this->testFlags(TARGET | CASE))
|
||||||
{
|
{
|
||||||
if (pass == 3)
|
if (pass == 3)
|
||||||
cCode.appendCode("\n"); /* Print to c code buffer */
|
cCode.appendCode("\n"); /* Print to c code buffer */
|
||||||
@ -310,19 +278,19 @@ void LLInst::dis1Line(int loc_ip, int pass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Find next instruction label and print hex bytes */
|
/* Find next instruction label and print hex bytes */
|
||||||
if (testFlags(SYNTHETIC))
|
if (this->testFlags(SYNTHETIC))
|
||||||
nextInst = label;
|
nextInst = this->label;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cb = (uint32_t) numBytes;
|
cb = (uint32_t) this->numBytes;
|
||||||
nextInst = label + cb;
|
nextInst = this->label + cb;
|
||||||
|
|
||||||
/* Output hexa code in program image */
|
/* Output hexa code in program image */
|
||||||
if (pass != 3)
|
if (pass != 3)
|
||||||
{
|
{
|
||||||
for (j = 0; j < cb; j++)
|
for (j = 0; j < cb; j++)
|
||||||
{
|
{
|
||||||
hex_bytes << hex << setw(2) << setfill('0') << uint16_t(prog.Image[label + j]);
|
hex_bytes << hex << setw(2) << setfill('0') << uint16_t(prog.Image[this->label + j]);
|
||||||
}
|
}
|
||||||
hex_bytes << ' ';
|
hex_bytes << ' ';
|
||||||
}
|
}
|
||||||
@ -333,11 +301,11 @@ void LLInst::dis1Line(int loc_ip, int pass)
|
|||||||
oper_stream << setw(5)<<left; // align for the labels
|
oper_stream << setw(5)<<left; // align for the labels
|
||||||
{
|
{
|
||||||
ostringstream lab_contents;
|
ostringstream lab_contents;
|
||||||
if (readVal(lab_contents, label, 0))
|
if (readVal(lab_contents, this->label, 0))
|
||||||
{
|
{
|
||||||
lab_contents << ':'; /* Also removes the null */
|
lab_contents << ':'; /* Also removes the null */
|
||||||
}
|
}
|
||||||
else if (testFlags(TARGET)) /* Symbols override Lnn labels */
|
else if (this->testFlags(TARGET)) /* Symbols override Lnn labels */
|
||||||
{
|
{
|
||||||
/* Print label */
|
/* Print label */
|
||||||
if (pl.count(loc_ip)==0)
|
if (pl.count(loc_ip)==0)
|
||||||
@ -348,13 +316,13 @@ void LLInst::dis1Line(int loc_ip, int pass)
|
|||||||
}
|
}
|
||||||
oper_stream<< lab_contents.str();
|
oper_stream<< lab_contents.str();
|
||||||
}
|
}
|
||||||
if (opcode == iSIGNEX && testFlags(B))
|
if ((this->getOpcode()==iSIGNEX )&& this->testFlags(B))
|
||||||
{
|
{
|
||||||
opcode = iCBW;
|
setOpcode(iCBW);
|
||||||
}
|
}
|
||||||
opcode_with_mods<<szOps[opcode];
|
opcode_with_mods<<Machine_X86::opcodeName(this->getOpcode());
|
||||||
|
|
||||||
switch (opcode)
|
switch ( this->getOpcode() )
|
||||||
{
|
{
|
||||||
case iADD: case iADC: case iSUB: case iSBB: case iAND: case iOR:
|
case iADD: case iADC: case iSUB: case iSBB: case iAND: case iOR:
|
||||||
case iXOR: case iTEST: case iCMP: case iMOV: case iLEA: case iXCHG:
|
case iXOR: case iTEST: case iCMP: case iMOV: case iLEA: case iXCHG:
|
||||||
@ -383,7 +351,6 @@ void LLInst::dis1Line(int loc_ip, int pass)
|
|||||||
if (testFlags(I))
|
if (testFlags(I))
|
||||||
{
|
{
|
||||||
operands_s<<strHex(src.op());
|
operands_s<<strHex(src.op());
|
||||||
// strcpy(p + WID_PTR, strHex(pIcode->ll()->immed.op));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -437,13 +404,13 @@ void LLInst::dis1Line(int loc_ip, int pass)
|
|||||||
{
|
{
|
||||||
pl[j] = ++g_lab;
|
pl[j] = ++g_lab;
|
||||||
}
|
}
|
||||||
if (opcode == iJMPF)
|
if (getOpcode() == iJMPF)
|
||||||
{
|
{
|
||||||
operands_s<<" far ptr ";
|
operands_s<<" far ptr ";
|
||||||
}
|
}
|
||||||
operands_s<<"L"<<pl[j];
|
operands_s<<"L"<<pl[j];
|
||||||
}
|
}
|
||||||
else if (opcode == iJMPF)
|
else if (getOpcode() == iJMPF)
|
||||||
{
|
{
|
||||||
operands_s<<"dword ptr";
|
operands_s<<"dword ptr";
|
||||||
strSrc(operands_s,true);
|
strSrc(operands_s,true);
|
||||||
@ -457,13 +424,13 @@ void LLInst::dis1Line(int loc_ip, int pass)
|
|||||||
case iCALL: case iCALLF:
|
case iCALL: case iCALLF:
|
||||||
if (testFlags(I))
|
if (testFlags(I))
|
||||||
{
|
{
|
||||||
if((opcode == iCALL))
|
if((getOpcode() == iCALL))
|
||||||
operands_s<< "near";
|
operands_s<< "near";
|
||||||
else
|
else
|
||||||
operands_s<< " far";
|
operands_s<< " far";
|
||||||
operands_s<<" ptr "<<(src.proc.proc)->name;
|
operands_s<<" ptr "<<(src.proc.proc)->name;
|
||||||
}
|
}
|
||||||
else if (opcode == iCALLF)
|
else if (getOpcode() == iCALLF)
|
||||||
{
|
{
|
||||||
operands_s<<"dword ptr ";
|
operands_s<<"dword ptr ";
|
||||||
strSrc(operands_s,true);
|
strSrc(operands_s,true);
|
||||||
@ -493,21 +460,21 @@ void LLInst::dis1Line(int loc_ip, int pass)
|
|||||||
case iOUTS: case iREP_OUTS:
|
case iOUTS: case iREP_OUTS:
|
||||||
if (src.segOver)
|
if (src.segOver)
|
||||||
{
|
{
|
||||||
bool is_dx_src=(opcode == iOUTS || opcode == iREP_OUTS);
|
bool is_dx_src=(getOpcode() == iOUTS || getOpcode() == iREP_OUTS);
|
||||||
if(is_dx_src)
|
if(is_dx_src)
|
||||||
operands_s<<"dx, "<<szPtr[getFlag() & B];
|
operands_s<<"dx, "<<szPtr[getFlag() & B];
|
||||||
else
|
else
|
||||||
operands_s<<szPtr[getFlag() & B];
|
operands_s<<szPtr[getFlag() & B];
|
||||||
if (opcode == iLODS ||
|
if (getOpcode() == iLODS ||
|
||||||
opcode == iREP_LODS ||
|
getOpcode() == iREP_LODS ||
|
||||||
opcode == iOUTS ||
|
getOpcode() == iOUTS ||
|
||||||
opcode == iREP_OUTS)
|
getOpcode() == iREP_OUTS)
|
||||||
{
|
{
|
||||||
operands_s<<szWreg[src.segOver-rAX];
|
operands_s<<Machine_X86::regName(src.segOver); // szWreg[src.segOver-rAX]
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
operands_s<<"es:[di], "<<szWreg[src.segOver - rAX];
|
operands_s<<"es:[di], "<<Machine_X86::regName(src.segOver);
|
||||||
}
|
}
|
||||||
operands_s<<":[si]";
|
operands_s<<":[si]";
|
||||||
}
|
}
|
||||||
@ -521,7 +488,7 @@ void LLInst::dis1Line(int loc_ip, int pass)
|
|||||||
if (src.segOver)
|
if (src.segOver)
|
||||||
{
|
{
|
||||||
operands_s<<" "<<szPtr[1];
|
operands_s<<" "<<szPtr[1];
|
||||||
operands_s<<szWreg[src.segOver-rAX]<<":[bx]";
|
operands_s<<Machine_X86::regName(src.segOver)<<":[bx]";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -593,7 +560,7 @@ void LLInst::dis1Line(int loc_ip, int pass)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Comment on iINT icodes */
|
/* Comment on iINT icodes */
|
||||||
if (opcode == iINT)
|
if (getOpcode() == iINT)
|
||||||
writeIntComment(result_stream);
|
writeIntComment(result_stream);
|
||||||
|
|
||||||
/* Display output line */
|
/* Display output line */
|
||||||
@ -628,45 +595,41 @@ void LLInst::dis1Line(int loc_ip, int pass)
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void formatRM(std::ostringstream &p, uint32_t flg, const LLOperand &pm)
|
static void formatRM(std::ostringstream &p, uint32_t flg, const LLOperand &pm)
|
||||||
{
|
{
|
||||||
char seg[4];
|
//char seg[4];
|
||||||
|
|
||||||
if (pm.segOver)
|
if (pm.segOver)
|
||||||
{
|
{
|
||||||
strcat(strcpy(seg, szWreg[pm.segOver - rAX]), ":");
|
p <<Machine_X86::regName(pm.segOver)<<':';
|
||||||
|
//strcat(strcpy(seg, szWreg[pm.segOver - rAX]), ":");
|
||||||
}
|
}
|
||||||
else *seg = '\0';
|
//else *seg = '\0';
|
||||||
|
|
||||||
if (pm.regi == 0)
|
if (pm.regi == rUNDEF)
|
||||||
{
|
{
|
||||||
p<<seg<<"["<<strHex((uint32_t)pm.off)<<"]";
|
p<<"["<<strHex((uint32_t)pm.off)<<"]";
|
||||||
}
|
}
|
||||||
|
else if (pm.isReg())
|
||||||
else if (pm.regi == (INDEX_BX_SI - 1))
|
|
||||||
{
|
{
|
||||||
p<<"tmp";
|
p<<Machine_X86::regName(pm.regi);
|
||||||
}
|
// if(flg & B)
|
||||||
|
// p << szBreg[pm.regi - rAL];
|
||||||
else if (pm.regi < INDEX_BX_SI)
|
// else
|
||||||
{
|
// p << szWreg[pm.regi - rAX];
|
||||||
if(flg & B)
|
|
||||||
p << szBreg[pm.regi - rAL];
|
|
||||||
else
|
|
||||||
p << szWreg[pm.regi - rAX];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (pm.off)
|
else if (pm.off)
|
||||||
{
|
{
|
||||||
if (pm.off < 0)
|
if (pm.off < 0)
|
||||||
{
|
{
|
||||||
p <<seg<<"["<<szIndex[pm.regi - INDEX_BX_SI]<<"-"<<strHex((uint32_t)(- pm.off))<<"]";
|
p <<"["<<Machine_X86::regName(pm.regi)<<"-"<<strHex((uint32_t)(- pm.off))<<"]";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
p <<seg<<"["<<szIndex[pm.regi - INDEX_BX_SI]<<"+"<<strHex((uint32_t)(pm.off))<<"]";
|
p <<"["<<Machine_X86::regName(pm.regi)<<"+"<<strHex((uint32_t)(pm.off))<<"]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
p <<seg<<"["<<szIndex[pm.regi - INDEX_BX_SI]<<"]";
|
p <<"["<<Machine_X86::regName(pm.regi)<<"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -677,7 +640,7 @@ static ostringstream & strDst(ostringstream &os,uint32_t flg, LLOperand &pm)
|
|||||||
{
|
{
|
||||||
/* Immediates to memory require size descriptor */
|
/* Immediates to memory require size descriptor */
|
||||||
//os << setw(WID_PTR);
|
//os << setw(WID_PTR);
|
||||||
if ((flg & I) && (pm.regi == 0 || pm.regi >= INDEX_BX_SI))
|
if ((flg & I) and not pm.isReg())
|
||||||
os << szPtr[flg & B];
|
os << szPtr[flg & B];
|
||||||
formatRM(os, flg, pm);
|
formatRM(os, flg, pm);
|
||||||
return os;
|
return os;
|
||||||
@ -689,7 +652,6 @@ static ostringstream & strDst(ostringstream &os,uint32_t flg, LLOperand &pm)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
ostringstream &LLInst::strSrc(ostringstream &os,bool skip_comma)
|
ostringstream &LLInst::strSrc(ostringstream &os,bool skip_comma)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(false==skip_comma)
|
if(false==skip_comma)
|
||||||
os<<", ";
|
os<<", ";
|
||||||
if (testFlags(I))
|
if (testFlags(I))
|
||||||
@ -734,7 +696,7 @@ void LLInst::flops(std::ostringstream &out)
|
|||||||
/* Note that op is set to the escape number, e.g.
|
/* Note that op is set to the escape number, e.g.
|
||||||
esc 0x38 is FILD */
|
esc 0x38 is FILD */
|
||||||
|
|
||||||
if ((dst.regi == 0) || (dst.regi >= INDEX_BX_SI))
|
if ( not dst.isReg() )
|
||||||
{
|
{
|
||||||
/* The mod/rm mod bits are not set to 11 (i.e. register). This is the normal floating point opcode */
|
/* The mod/rm mod bits are not set to 11 (i.e. register). This is the normal floating point opcode */
|
||||||
out<<szFlops1[op]<<' ';
|
out<<szFlops1[op]<<' ';
|
||||||
|
|||||||
@ -10,9 +10,7 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "dcc.h"
|
#include "dcc.h"
|
||||||
#ifdef _lint
|
|
||||||
static std::map<eErrorId,std::string> errorMessage;
|
|
||||||
#else
|
|
||||||
static std::map<eErrorId,std::string> errorMessage =
|
static std::map<eErrorId,std::string> errorMessage =
|
||||||
{
|
{
|
||||||
{INVALID_ARG ,"Invalid option -%c\n"},
|
{INVALID_ARG ,"Invalid option -%c\n"},
|
||||||
@ -34,8 +32,6 @@
|
|||||||
{REPEAT_FAIL ,"Failed to construct repeat..until() condition.\n"},
|
{REPEAT_FAIL ,"Failed to construct repeat..until() condition.\n"},
|
||||||
{WHILE_FAIL ,"Failed to construct while() condition.\n"},
|
{WHILE_FAIL ,"Failed to construct while() condition.\n"},
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
fatalError: displays error message and exits the program.
|
fatalError: displays error message and exits the program.
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "dcc.h"
|
#include "dcc.h"
|
||||||
|
#include "disassem.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -75,14 +76,8 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Search through code looking for impure references and flag them */
|
/* Search through code looking for impure references and flag them */
|
||||||
#ifdef _lint
|
|
||||||
for (auto i=pProcList.begin(); i!=pProcList.end(); ++i)
|
|
||||||
{
|
|
||||||
Function &f(*i);
|
|
||||||
#else
|
|
||||||
for(Function &f : pProcList)
|
for(Function &f : pProcList)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
f.markImpure();
|
f.markImpure();
|
||||||
if (option.asm1)
|
if (option.asm1)
|
||||||
disassem(1, &f);
|
disassem(1, &f);
|
||||||
@ -93,14 +88,8 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Converts jump target addresses to icode offsets */
|
/* Converts jump target addresses to icode offsets */
|
||||||
#ifdef _lint
|
|
||||||
for (auto i=pProcList.begin(); i!=pProcList.end(); ++i)
|
|
||||||
{
|
|
||||||
Function &f(*i);
|
|
||||||
#else
|
|
||||||
for(Function &f : pProcList)
|
for(Function &f : pProcList)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
f.bindIcodeOff();
|
f.bindIcodeOff();
|
||||||
}
|
}
|
||||||
/* Print memory bitmap */
|
/* Print memory bitmap */
|
||||||
|
|||||||
@ -161,14 +161,8 @@ CondJumps:
|
|||||||
void Function::markImpure()
|
void Function::markImpure()
|
||||||
{
|
{
|
||||||
SYM * psym;
|
SYM * psym;
|
||||||
#ifdef _lint
|
|
||||||
for (auto i=Icode.begin(); i!=Icode.end(); ++i)
|
|
||||||
{
|
|
||||||
ICODE &icod(*i);
|
|
||||||
#else
|
|
||||||
for(ICODE &icod : Icode)
|
for(ICODE &icod : Icode)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
if ( not icod.ll()->testFlags(SYM_USE | SYM_DEF))
|
if ( not icod.ll()->testFlags(SYM_USE | SYM_DEF))
|
||||||
continue;
|
continue;
|
||||||
psym = &symtab[icod.ll()->caseTbl.numEntries];
|
psym = &symtab[icod.ll()->caseTbl.numEntries];
|
||||||
@ -196,14 +190,8 @@ void Function::markImpure()
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
void Function::freeCFG()
|
void Function::freeCFG()
|
||||||
{
|
{
|
||||||
#ifdef _lint
|
|
||||||
for (auto i=heldBBs.begin(); i!=heldBBs.end(); ++i)
|
|
||||||
{
|
|
||||||
BB *p(*i);
|
|
||||||
#else
|
|
||||||
for(BB *p : heldBBs)
|
for(BB *p : heldBBs)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
delete p;
|
delete p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,25 +207,12 @@ void Function::compressCFG()
|
|||||||
|
|
||||||
/* First pass over BB list removes redundant jumps of the form
|
/* First pass over BB list removes redundant jumps of the form
|
||||||
* (Un)Conditional -> Unconditional jump */
|
* (Un)Conditional -> Unconditional jump */
|
||||||
#ifdef _lint
|
|
||||||
|
|
||||||
for (auto iter=m_cfg.begin(); iter!=m_cfg.end(); ++iter)
|
|
||||||
{
|
|
||||||
BB *pBB(*iter);
|
|
||||||
#else
|
|
||||||
for (BB *pBB : m_cfg)
|
for (BB *pBB : m_cfg)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
if(pBB->inEdges.empty() || (pBB->nodeType != ONE_BRANCH && pBB->nodeType != TWO_BRANCH))
|
if(pBB->inEdges.empty() || (pBB->nodeType != ONE_BRANCH && pBB->nodeType != TWO_BRANCH))
|
||||||
continue;
|
continue;
|
||||||
#ifdef _lint
|
|
||||||
for (auto iter2=pBB->edges.begin(); iter2!=pBB->edges.end(); ++iter2)
|
|
||||||
{
|
|
||||||
TYPEADR_TYPE &edgeRef(*iter2);
|
|
||||||
#else
|
|
||||||
for (TYPEADR_TYPE &edgeRef : pBB->edges)
|
for (TYPEADR_TYPE &edgeRef : pBB->edges)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
ip = pBB->rbegin()->loc_ip;
|
ip = pBB->rbegin()->loc_ip;
|
||||||
pNxt = edgeRef.BBptr->rmJMP(ip, edgeRef.BBptr);
|
pNxt = edgeRef.BBptr->rmJMP(ip, edgeRef.BBptr);
|
||||||
|
|
||||||
@ -246,6 +221,7 @@ void Function::compressCFG()
|
|||||||
edgeRef.BBptr = pNxt;
|
edgeRef.BBptr = pNxt;
|
||||||
assert(pBB->back().loc_ip==ip);
|
assert(pBB->back().loc_ip==ip);
|
||||||
pBB->back().ll()->SetImmediateOp((uint32_t)pNxt->begin()->loc_ip);
|
pBB->back().ll()->SetImmediateOp((uint32_t)pNxt->begin()->loc_ip);
|
||||||
|
//Icode[ip].SetImmediateOp((uint32_t)pNxt->begin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -403,14 +379,8 @@ void BB::dfsNumbering(std::vector<BB *> &dfsLast, int *first, int *last)
|
|||||||
|
|
||||||
/* index is being used as an index to inEdges[]. */
|
/* index is being used as an index to inEdges[]. */
|
||||||
// for (i = 0; i < edges.size(); i++)
|
// for (i = 0; i < edges.size(); i++)
|
||||||
#ifdef _lint
|
|
||||||
for (auto i=edges.begin(); i!=edges.end(); ++i)
|
|
||||||
{
|
|
||||||
auto edge(*i);
|
|
||||||
#else
|
|
||||||
for(auto edge : edges)
|
for(auto edge : edges)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
pChild = edge.BBptr;
|
pChild = edge.BBptr;
|
||||||
pChild->inEdges[pChild->index++] = this;
|
pChild->inEdges[pChild->index++] = this;
|
||||||
|
|
||||||
|
|||||||
@ -78,7 +78,7 @@ void ICODE::setJCond(COND_EXPR *cexp)
|
|||||||
* it has been replaced by a high-level icode. */
|
* it has been replaced by a high-level icode. */
|
||||||
void ICODE ::invalidate()
|
void ICODE ::invalidate()
|
||||||
{
|
{
|
||||||
invalid = TRUE;
|
invalid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -287,7 +287,6 @@ void Function::highLevelGen()
|
|||||||
COND_EXPR *lhs, *rhs; /* left- and right-hand side of expression */
|
COND_EXPR *lhs, *rhs; /* left- and right-hand side of expression */
|
||||||
uint32_t _flg; /* icode flags */
|
uint32_t _flg; /* icode flags */
|
||||||
numIcode = Icode.size();
|
numIcode = Icode.size();
|
||||||
lhs=rhs=0;
|
|
||||||
for (iICODE i = Icode.begin(); i!=Icode.end() ; ++i)
|
for (iICODE i = Icode.begin(); i!=Icode.end() ; ++i)
|
||||||
{
|
{
|
||||||
assert(numIcode==Icode.size());
|
assert(numIcode==Icode.size());
|
||||||
@ -469,6 +468,7 @@ COND_EXPR *COND_EXPR::inverse () const
|
|||||||
return COND_EXPR::unary (NEGATION, this->clone());
|
return COND_EXPR::unary (NEGATION, this->clone());
|
||||||
|
|
||||||
case DBL_AND: case DBL_OR:
|
case DBL_AND: case DBL_OR:
|
||||||
|
// Binary::Create(invertop,lhs->inverse(),rhs->inverse());
|
||||||
res = this->clone();
|
res = this->clone();
|
||||||
res->boolExpr.op = invCondOp[op()];
|
res->boolExpr.op = invCondOp[op()];
|
||||||
res->boolExpr.lhs=lhs()->inverse ();
|
res->boolExpr.lhs=lhs()->inverse ();
|
||||||
@ -591,13 +591,9 @@ string HLTYPE::write1HlIcode (Function * pProc, int *numLoc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int power2 (int i)
|
//TODO: replace all "< (INDEX_BX_SI-1)" with machine_x86::lastReg
|
||||||
/* Returns the value of 2 to the power of i */
|
|
||||||
{
|
//TODO: replace all >= INDEX_BX_SI with machine_x86::isRegExpression
|
||||||
if (i == 0)
|
|
||||||
return (1);
|
|
||||||
return (2 << (i-1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Writes the registers/stack variables that are used and defined by this
|
/* Writes the registers/stack variables that are used and defined by this
|
||||||
@ -607,48 +603,29 @@ void ICODE::writeDU()
|
|||||||
int my_idx = loc_ip;
|
int my_idx = loc_ip;
|
||||||
{
|
{
|
||||||
ostringstream ostr;
|
ostringstream ostr;
|
||||||
for (int i = 0; i < (INDEX_BX_SI-1); i++)
|
Machine_X86::writeBitVector(ostr,du.def);
|
||||||
if (du.def[i])
|
|
||||||
ostr << allRegs[i] << " ";
|
|
||||||
if (!ostr.str().empty())
|
if (!ostr.str().empty())
|
||||||
printf ("Def (reg) = %s\n", ostr.str().c_str());
|
printf ("Def (reg) = %s\n", ostr.str().c_str());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ostringstream ostr;
|
ostringstream ostr;
|
||||||
for (int i = 0; i < (INDEX_BX_SI-1); i++)
|
Machine_X86::writeBitVector(ostr,du.use);
|
||||||
if (du.def[i])
|
|
||||||
ostr << allRegs[i] << " ";
|
|
||||||
if (!ostr.str().empty())
|
|
||||||
printf ("Def (reg) = %s\n", ostr.str().c_str());
|
|
||||||
for (int i = 0; i < INDEX_BX_SI; i++)
|
|
||||||
{
|
|
||||||
if (du.use[i])
|
|
||||||
ostr << allRegs[i] << " ";
|
|
||||||
}
|
|
||||||
if (!ostr.str().empty())
|
if (!ostr.str().empty())
|
||||||
printf ("Use (reg) = %s\n", ostr.str().c_str());
|
printf ("Use (reg) = %s\n", ostr.str().c_str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print du1 chain */
|
/* Print du1 chain */
|
||||||
printf ("# regs defined = %d\n", du1.numRegsDef);
|
printf ("# regs defined = %d\n", du1.numRegsDef);
|
||||||
for (int i = 0; i < MAX_REGS_DEF; i++)
|
for (int i = 0; i < MAX_REGS_DEF; i++)
|
||||||
{
|
{
|
||||||
if (du1.used(i))
|
if (not du1.used(i))
|
||||||
{
|
continue;
|
||||||
printf ("%d: du1[%d][] = ", my_idx, i);
|
printf ("%d: du1[%d][] = ", my_idx, i);
|
||||||
#ifdef _lint
|
|
||||||
for (auto ik=du1.idx[i].uses.begin(); ik!=du1.idx[i].uses.end(); ++ik)
|
|
||||||
{
|
|
||||||
auto j(*ik);
|
|
||||||
#else
|
|
||||||
for(auto j : du1.idx[i].uses)
|
for(auto j : du1.idx[i].uses)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
printf ("%d ", j->loc_ip);
|
printf ("%d ", j->loc_ip);
|
||||||
}
|
}
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For HLI_CALL, print # parameter bytes */
|
/* For HLI_CALL, print # parameter bytes */
|
||||||
@ -656,7 +633,3 @@ void ICODE::writeDU()
|
|||||||
printf ("# param bytes = %d\n", hl()->call.args->cb);
|
printf ("# param bytes = %d\n", hl()->call.args->cb);
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -29,14 +29,8 @@ ICODE * CIcodeRec::addIcode(ICODE *pIcode)
|
|||||||
|
|
||||||
void CIcodeRec::SetInBB(int start, int _end, BB *pnewBB)
|
void CIcodeRec::SetInBB(int start, int _end, BB *pnewBB)
|
||||||
{
|
{
|
||||||
#ifdef _lint
|
|
||||||
for (auto ik=this->begin(); ik!=this->end(); ++ik)
|
|
||||||
{
|
|
||||||
ICODE &icode(*ik);
|
|
||||||
#else
|
|
||||||
for(ICODE &icode : *this)
|
for(ICODE &icode : *this)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
if((icode.loc_ip>=start) and (icode.loc_ip<=_end))
|
if((icode.loc_ip>=start) and (icode.loc_ip<=_end))
|
||||||
icode.inBB = pnewBB;
|
icode.inBB = pnewBB;
|
||||||
}
|
}
|
||||||
@ -46,7 +40,6 @@ void CIcodeRec::SetInBB(int start, int _end, BB *pnewBB)
|
|||||||
replaces *pIndex with an icode index */
|
replaces *pIndex with an icode index */
|
||||||
bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex)
|
bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex)
|
||||||
{
|
{
|
||||||
|
|
||||||
iICODE location=labelSrch(target);
|
iICODE location=labelSrch(target);
|
||||||
if(end()==location)
|
if(end()==location)
|
||||||
return false;
|
return false;
|
||||||
@ -55,7 +48,6 @@ bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex)
|
|||||||
}
|
}
|
||||||
CIcodeRec::iterator CIcodeRec::labelSrch(uint32_t target)
|
CIcodeRec::iterator CIcodeRec::labelSrch(uint32_t target)
|
||||||
{
|
{
|
||||||
|
|
||||||
return find_if(begin(),end(),[target](ICODE &l) -> bool {return l.ll()->label==target;});
|
return find_if(begin(),end(),[target](ICODE &l) -> bool {return l.ll()->label==target;});
|
||||||
}
|
}
|
||||||
ICODE * CIcodeRec::GetIcode(int ip)
|
ICODE * CIcodeRec::GetIcode(int ip)
|
||||||
@ -66,7 +58,6 @@ ICODE * CIcodeRec::GetIcode(int ip)
|
|||||||
return &(*res);
|
return &(*res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern int getNextLabel();
|
extern int getNextLabel();
|
||||||
extern bundle cCode;
|
extern bundle cCode;
|
||||||
/* Checks the given icode to determine whether it has a label associated
|
/* Checks the given icode to determine whether it has a label associated
|
||||||
@ -90,3 +81,9 @@ void LLInst::emitGotoLabel (int indLevel)
|
|||||||
stats.numHLIcode++;
|
stats.numHLIcode++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool LLOperand::isReg() const
|
||||||
|
{
|
||||||
|
return (regi>=rAX) && (regi<=rTMP);
|
||||||
|
}
|
||||||
|
|||||||
@ -16,13 +16,13 @@
|
|||||||
#include "arith_idioms.h"
|
#include "arith_idioms.h"
|
||||||
#include "dcc.h"
|
#include "dcc.h"
|
||||||
#include <llvm/Support/PatternMatch.h>
|
#include <llvm/Support/PatternMatch.h>
|
||||||
//#include <boost/iterator/filter_iterator.hpp>
|
#include <boost/iterator/filter_iterator.hpp>
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* JmpInst - Returns TRUE if opcode is a conditional or unconditional jump
|
* JmpInst - Returns TRUE if opcode is a conditional or unconditional jump
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
bool LLInst::isJmpInst()
|
bool LLInst::isJmpInst()
|
||||||
{
|
{
|
||||||
switch (opcode)
|
switch (getOpcode())
|
||||||
{
|
{
|
||||||
case iJMP: case iJMPF: case iJCXZ:
|
case iJMP: case iJMPF: case iJCXZ:
|
||||||
case iLOOP: case iLOOPE:case iLOOPNE:
|
case iLOOP: case iLOOPE:case iLOOPNE:
|
||||||
@ -74,9 +74,9 @@ void Function::findIdioms()
|
|||||||
Idiom20 i20(this);
|
Idiom20 i20(this);
|
||||||
struct is_valid
|
struct is_valid
|
||||||
{
|
{
|
||||||
bool operator()(ICODE &z) { return not z.invalid;}
|
bool operator()(ICODE &z) { return z.valid();}
|
||||||
};
|
};
|
||||||
//typedef boost::filter_iterator<is_valid,iICODE> ifICODE;
|
typedef boost::filter_iterator<is_valid,iICODE> ifICODE;
|
||||||
while (pIcode != pEnd)
|
while (pIcode != pEnd)
|
||||||
{
|
{
|
||||||
switch (pIcode->ll()->getOpcode())
|
switch (pIcode->ll()->getOpcode())
|
||||||
@ -230,14 +230,8 @@ void Function::bindIcodeOff()
|
|||||||
pIcode = Icode.begin();
|
pIcode = Icode.begin();
|
||||||
|
|
||||||
/* Flag all jump targets for BB construction and disassembly stage 2 */
|
/* Flag all jump targets for BB construction and disassembly stage 2 */
|
||||||
#ifdef _lint
|
|
||||||
for (auto ik=Icode.begin(); ik!=Icode.end(); ++ik)
|
|
||||||
{
|
|
||||||
ICODE &c(*ik);
|
|
||||||
#else
|
|
||||||
for(ICODE &c : Icode)
|
for(ICODE &c : Icode)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
LLInst *ll=c.ll();
|
LLInst *ll=c.ll();
|
||||||
if (ll->testFlags(I) && ll->isJmpInst())
|
if (ll->testFlags(I) && ll->isJmpInst())
|
||||||
{
|
{
|
||||||
@ -251,14 +245,8 @@ void Function::bindIcodeOff()
|
|||||||
* is found (no code at dest. of jump) are simply left unlinked and
|
* is found (no code at dest. of jump) are simply left unlinked and
|
||||||
* flagged as going nowhere. */
|
* flagged as going nowhere. */
|
||||||
//for (pIcode = Icode.begin(); pIcode!= Icode.end(); pIcode++)
|
//for (pIcode = Icode.begin(); pIcode!= Icode.end(); pIcode++)
|
||||||
#ifdef _lint
|
|
||||||
for (auto ik=Icode.begin(); ik!=Icode.end(); ++ik)
|
|
||||||
{
|
|
||||||
ICODE &icode(*ik);
|
|
||||||
#else
|
|
||||||
for(ICODE &icode : Icode)
|
for(ICODE &icode : Icode)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
LLInst *ll=icode.ll();
|
LLInst *ll=icode.ll();
|
||||||
if (not ll->isJmpInst())
|
if (not ll->isJmpInst())
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@ -105,7 +105,7 @@ bool Idiom18::match(iICODE picode)
|
|||||||
/* not supported yet */
|
/* not supported yet */
|
||||||
type = 0;
|
type = 0;
|
||||||
}
|
}
|
||||||
else if (m_icodes[1]->ll()->dst.regi < INDEX_BX_SI) /* register */
|
else if ( m_icodes[1]->ll()->dst.isReg() ) /* register */
|
||||||
{
|
{
|
||||||
if ((m_icodes[1]->ll()->dst.regi == rSI) && (m_func->flg & SI_REGVAR))
|
if ((m_icodes[1]->ll()->dst.regi == rSI) && (m_func->flg & SI_REGVAR))
|
||||||
type = 1;
|
type = 1;
|
||||||
@ -131,7 +131,7 @@ bool Idiom18::match(iICODE picode)
|
|||||||
if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src.regi == m_icodes[1]->ll()->dst.regi))
|
if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src.regi == m_icodes[1]->ll()->dst.regi))
|
||||||
{
|
{
|
||||||
regi = m_icodes[0]->ll()->dst.regi;
|
regi = m_icodes[0]->ll()->dst.regi;
|
||||||
if ((regi > 0) && (regi < INDEX_BX_SI))
|
if ( m_icodes[0]->ll()->dst.isReg() )
|
||||||
{
|
{
|
||||||
if ( m_icodes[2]->ll()->match(iCMP) && (m_icodes[2]->ll()->dst.regi == regi) &&
|
if ( m_icodes[2]->ll()->match(iCMP) && (m_icodes[2]->ll()->dst.regi == regi) &&
|
||||||
m_icodes[3]->ll()->conditionalJump() )
|
m_icodes[3]->ll()->conditionalJump() )
|
||||||
@ -143,7 +143,7 @@ bool Idiom18::match(iICODE picode)
|
|||||||
if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src.off == m_icodes[1]->ll()->dst.off))
|
if (m_icodes[0]->ll()->match(iMOV) && (m_icodes[0]->ll()->src.off == m_icodes[1]->ll()->dst.off))
|
||||||
{
|
{
|
||||||
regi = m_icodes[0]->ll()->dst.regi;
|
regi = m_icodes[0]->ll()->dst.regi;
|
||||||
if ((regi > 0) && (regi < INDEX_BX_SI))
|
if ( m_icodes[0]->ll()->dst.isReg() )
|
||||||
{
|
{
|
||||||
if ( m_icodes[2]->ll()->match(iCMP) && (m_icodes[2]->ll()->dst.regi == regi) &&
|
if ( m_icodes[2]->ll()->match(iCMP) && (m_icodes[2]->ll()->dst.regi == regi) &&
|
||||||
m_icodes[3]->ll()->conditionalJump() )
|
m_icodes[3]->ll()->conditionalJump() )
|
||||||
@ -194,7 +194,7 @@ bool Idiom19::match(iICODE picode)
|
|||||||
m_is_dec = m_icodes[0]->ll()->match(iDEC);
|
m_is_dec = m_icodes[0]->ll()->match(iDEC);
|
||||||
if (m_icodes[0]->ll()->dst.regi == 0) /* global variable */
|
if (m_icodes[0]->ll()->dst.regi == 0) /* global variable */
|
||||||
/* not supported yet */ ;
|
/* not supported yet */ ;
|
||||||
else if (m_icodes[0]->ll()->dst.regi < INDEX_BX_SI) /* register */
|
else if ( m_icodes[0]->ll()->dst.isReg() ) /* register */
|
||||||
{
|
{
|
||||||
// if (((picode->ll()->dst.regi == rSI) && (pproc->flg & SI_REGVAR)) ||
|
// if (((picode->ll()->dst.regi == rSI) && (pproc->flg & SI_REGVAR)) ||
|
||||||
// ((picode->ll()->dst.regi == rDI) && (pproc->flg & DI_REGVAR)))
|
// ((picode->ll()->dst.regi == rDI) && (pproc->flg & DI_REGVAR)))
|
||||||
@ -248,23 +248,24 @@ bool Idiom20::match(iICODE picode)
|
|||||||
|
|
||||||
m_is_dec = m_icodes[0]->ll()->match(iDEC);
|
m_is_dec = m_icodes[0]->ll()->match(iDEC);
|
||||||
|
|
||||||
|
LLOperand &ll_dest(m_icodes[0]->ll()->dst);
|
||||||
/* Get variable */
|
/* Get variable */
|
||||||
if (m_icodes[0]->ll()->dst.regi == 0) /* global variable */
|
if (ll_dest.regi == 0) /* global variable */
|
||||||
{
|
{
|
||||||
/* not supported yet */ ;
|
/* not supported yet */ ;
|
||||||
}
|
}
|
||||||
else if (m_icodes[0]->ll()->dst.regi < INDEX_BX_SI) /* register */
|
else if ( ll_dest.isReg() ) /* register */
|
||||||
{
|
{
|
||||||
if ((m_icodes[0]->ll()->dst.regi == rSI) && (m_func->flg & SI_REGVAR))
|
if ((ll_dest.regi == rSI) && (m_func->flg & SI_REGVAR))
|
||||||
type = 1;
|
type = 1;
|
||||||
else if ((m_icodes[0]->ll()->dst.regi == rDI) && (m_func->flg & DI_REGVAR))
|
else if ((ll_dest.regi == rDI) && (m_func->flg & DI_REGVAR))
|
||||||
type = 1;
|
type = 1;
|
||||||
}
|
}
|
||||||
else if (m_icodes[0]->ll()->dst.off) /* local variable */
|
else if (ll_dest.off) /* local variable */
|
||||||
type = 2;
|
type = 2;
|
||||||
else /* indexed */
|
else /* indexed */
|
||||||
{
|
{
|
||||||
printf("idiom20 : Unsupported type\n");
|
printf("idiom20 : Unsupported type [indexed]\n");
|
||||||
/* not supported yet */ ;
|
/* not supported yet */ ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,10 +273,10 @@ bool Idiom20::match(iICODE picode)
|
|||||||
if (type == 1) /* register variable */
|
if (type == 1) /* register variable */
|
||||||
{
|
{
|
||||||
if (m_icodes[1]->ll()->match(iMOV) &&
|
if (m_icodes[1]->ll()->match(iMOV) &&
|
||||||
(m_icodes[1]->ll()->src.regi == m_icodes[0]->ll()->dst.regi))
|
(m_icodes[1]->ll()->src.regi == ll_dest.regi))
|
||||||
{
|
{
|
||||||
regi = m_icodes[1]->ll()->dst.regi;
|
regi = m_icodes[1]->ll()->dst.regi;
|
||||||
if ((regi > 0) && (regi < INDEX_BX_SI))
|
if ( m_icodes[1]->ll()->dst.isReg() )
|
||||||
{
|
{
|
||||||
if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) &&
|
if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) &&
|
||||||
m_icodes[3]->ll()->conditionalJump())
|
m_icodes[3]->ll()->conditionalJump())
|
||||||
@ -286,10 +287,10 @@ bool Idiom20::match(iICODE picode)
|
|||||||
else if (type == 2) /* local */
|
else if (type == 2) /* local */
|
||||||
{
|
{
|
||||||
if ( m_icodes[0]->ll()->match(iMOV) &&
|
if ( m_icodes[0]->ll()->match(iMOV) &&
|
||||||
(m_icodes[1]->ll()->src.off == m_icodes[0]->ll()->dst.off))
|
(m_icodes[1]->ll()->src.off == ll_dest.off))
|
||||||
{
|
{
|
||||||
regi = m_icodes[1]->ll()->dst.regi;
|
regi = m_icodes[1]->ll()->dst.regi;
|
||||||
if ((regi > 0) && (regi < INDEX_BX_SI))
|
if ( m_icodes[1]->ll()->dst.isReg() )
|
||||||
{
|
{
|
||||||
if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) &&
|
if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) &&
|
||||||
m_icodes[3]->ll()->conditionalJump())
|
m_icodes[3]->ll()->conditionalJump())
|
||||||
|
|||||||
@ -140,7 +140,7 @@ int Idiom4::action()
|
|||||||
{
|
{
|
||||||
if( ! m_icodes.empty()) // if not an empty RET[F] N
|
if( ! m_icodes.empty()) // if not an empty RET[F] N
|
||||||
{
|
{
|
||||||
for(size_t idx=0; idx<m_icodes.size()-1; ++idx) // invalidate all but the RET
|
for(size_t idx=0; idx<m_icodes.size()-1; ++idx) // don't invalidate last entry
|
||||||
m_icodes[idx]->invalidate();
|
m_icodes[idx]->invalidate();
|
||||||
}
|
}
|
||||||
if(m_param_count)
|
if(m_param_count)
|
||||||
|
|||||||
@ -123,14 +123,8 @@ bool Idiom1::match(iICODE picode)
|
|||||||
}
|
}
|
||||||
int Idiom1::action()
|
int Idiom1::action()
|
||||||
{
|
{
|
||||||
#ifdef _lint
|
|
||||||
for (auto ik=m_icodes.begin(); ik!=m_icodes.end(); ++ik)
|
|
||||||
{
|
|
||||||
iICODE ic(*ik);
|
|
||||||
#else
|
|
||||||
for(iICODE ic : m_icodes)
|
for(iICODE ic : m_icodes)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
ic->invalidate();
|
ic->invalidate();
|
||||||
}
|
}
|
||||||
m_func->flg |= PROC_HLL;
|
m_func->flg |= PROC_HLL;
|
||||||
|
|||||||
@ -57,7 +57,6 @@ int Idiom8::action()
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
bool Idiom15::match(iICODE pIcode)
|
bool Idiom15::match(iICODE pIcode)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint8_t regi;
|
uint8_t regi;
|
||||||
|
|
||||||
if(distance(pIcode,m_end)<2)
|
if(distance(pIcode,m_end)<2)
|
||||||
@ -72,7 +71,6 @@ bool Idiom15::match(iICODE pIcode)
|
|||||||
pIcode->ll()->match(iSHL,(eReg)regi,I) and
|
pIcode->ll()->match(iSHL,(eReg)regi,I) and
|
||||||
(pIcode->ll()->src.op() == 1) )
|
(pIcode->ll()->src.op() == 1) )
|
||||||
{
|
{
|
||||||
|
|
||||||
m_icodes.push_back(pIcode++);
|
m_icodes.push_back(pIcode++);
|
||||||
}
|
}
|
||||||
return m_icodes.size()>1;
|
return m_icodes.size()>1;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
|
#include <cassert>
|
||||||
#include "machine_x86.h"
|
#include "machine_x86.h"
|
||||||
// Index registers **** temp solution
|
// Index registers **** temp solution
|
||||||
static const std::string regNames[] = {
|
static const std::string regNames[] = {
|
||||||
@ -22,5 +22,35 @@ Machine_X86::Machine_X86()
|
|||||||
|
|
||||||
const std::string &Machine_X86::regName(eReg r)
|
const std::string &Machine_X86::regName(eReg r)
|
||||||
{
|
{
|
||||||
|
assert(r<(sizeof(regNames)/sizeof(std::string)));
|
||||||
return regNames[r];
|
return regNames[r];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const std::string szOps[] =
|
||||||
|
{
|
||||||
|
"CBW", "AAA", "AAD", "AAM", "AAS", "ADC", "ADD", "AND",
|
||||||
|
"BOUND","CALL", "CALL", "CLC", "CLD", "CLI", "CMC", "CMP",
|
||||||
|
"CMPS", "REPNE CMPS","REPE CMPS","DAA", "DAS", "DEC", "DIV", "ENTER",
|
||||||
|
"ESC", "HLT", "IDIV", "IMUL", "IN", "INC", "INS", "REP INS",
|
||||||
|
"INT", "IRET", "JB", "JBE", "JAE", "JA", "JE", "JNE",
|
||||||
|
"JL", "JGE", "JLE", "JG", "JS", "JNS", "JO", "JNO",
|
||||||
|
"JP", "JNP", "JCXZ", "JMP", "JMP", "LAHF", "LDS", "LEA",
|
||||||
|
"LEAVE","LES", "LOCK", "LODS", "REP LODS", "LOOP", "LOOPE","LOOPNE",
|
||||||
|
"MOV", "MOVS", "REP MOVS", "MUL", "NEG", "NOT", "OR", "OUT",
|
||||||
|
"OUTS", "REP OUTS", "POP", "POPA", "POPF", "PUSH", "PUSHA","PUSHF",
|
||||||
|
"RCL", "RCR", "ROL", "ROR", "RET", "RETF", "SAHF", "SAR",
|
||||||
|
"SHL", "SHR", "SBB", "SCAS", "REPNE SCAS","REPE SCAS", "CWD", "STC",
|
||||||
|
"STD", "STI", "STOS", "REP STOS", "SUB", "TEST", "WAIT", "XCHG",
|
||||||
|
"XLAT", "XOR", "INTO", "NOP", "REPNE", "REPE", "MOD"
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::string &Machine_X86::opcodeName(unsigned r)
|
||||||
|
{
|
||||||
|
assert(r<(sizeof(szOps)/sizeof(std::string)));
|
||||||
|
return szOps[r];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Machine_X86::physicalReg(eReg r)
|
||||||
|
{
|
||||||
|
return (r>=rAX) && (r<rTMP);
|
||||||
|
}
|
||||||
|
|||||||
@ -19,7 +19,7 @@ static void process_MOV(LLInst &ll, STATE * pstate);
|
|||||||
static SYM * lookupAddr (LLOperand *pm, STATE * pstate, int size, uint16_t duFlag);
|
static SYM * lookupAddr (LLOperand *pm, STATE * pstate, int size, uint16_t duFlag);
|
||||||
void interactDis(Function * initProc, int ic);
|
void interactDis(Function * initProc, int ic);
|
||||||
static uint32_t SynthLab;
|
static uint32_t SynthLab;
|
||||||
|
//TODO: Move these to Machine_X86
|
||||||
/*constexpr */eReg subRegH(eReg reg)
|
/*constexpr */eReg subRegH(eReg reg)
|
||||||
{
|
{
|
||||||
return eReg((int)reg + (int)rAH-(int)rAX);
|
return eReg((int)reg + (int)rAH-(int)rAX);
|
||||||
@ -798,7 +798,9 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, int size, uint16_t duFlag
|
|||||||
SYM * psym;
|
SYM * psym;
|
||||||
uint32_t operand;
|
uint32_t operand;
|
||||||
|
|
||||||
if (pm->regi == 0) { /* Global var */
|
if (pm->regi == 0)
|
||||||
|
{
|
||||||
|
/* Global var */
|
||||||
if (pm->segValue) { /* there is a value in the seg field */
|
if (pm->segValue) { /* there is a value in the seg field */
|
||||||
operand = opAdr (pm->segValue, pm->off);
|
operand = opAdr (pm->segValue, pm->off);
|
||||||
psym = updateGlobSym (operand, size, duFlag);
|
psym = updateGlobSym (operand, size, duFlag);
|
||||||
@ -1043,7 +1045,6 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
|
|||||||
if (! Imm) {
|
if (! Imm) {
|
||||||
use(SRC, pIcode, this, pstate, cb, ix);
|
use(SRC, pIcode, this, pstate, cb, ix);
|
||||||
}
|
}
|
||||||
//lint -fallthrough
|
|
||||||
case iINC: case iDEC: case iNEG: case iNOT:
|
case iINC: case iDEC: case iNEG: case iNOT:
|
||||||
case iAAA: case iAAD: case iAAM: case iAAS:
|
case iAAA: case iAAD: case iAAM: case iAAS:
|
||||||
case iDAA: case iDAS:
|
case iDAA: case iDAS:
|
||||||
|
|||||||
@ -47,6 +47,7 @@ PatternHasher::init(int _NumEntry, int _EntryLen, int _SetSize, char _SetMin,
|
|||||||
g = new short [NumVert + 1];
|
g = new short [NumVert + 1];
|
||||||
// visited = new bool [NumVert + 1];
|
// visited = new bool [NumVert + 1];
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PatternHasher::cleanup(void)
|
void PatternHasher::cleanup(void)
|
||||||
|
|||||||
@ -23,7 +23,6 @@ const char *indentStr(int indLevel) // Indentation according to the depth of the
|
|||||||
|
|
||||||
/* Inserts an outEdge at the current callGraph pointer if the newProc does
|
/* Inserts an outEdge at the current callGraph pointer if the newProc does
|
||||||
* not exist. */
|
* not exist. */
|
||||||
//lint -sem(vector<CALL_GRAPH *>::push,custodial(1))
|
|
||||||
void CALL_GRAPH::insertArc (ilFunction newProc)
|
void CALL_GRAPH::insertArc (ilFunction newProc)
|
||||||
{
|
{
|
||||||
CALL_GRAPH *pcg;
|
CALL_GRAPH *pcg;
|
||||||
@ -109,7 +108,7 @@ void Function::newRegArg(iICODE picode, iICODE ticode)
|
|||||||
/* Flag ticode as having register arguments */
|
/* Flag ticode as having register arguments */
|
||||||
tproc = ticode->hl()->call.proc;
|
tproc = ticode->hl()->call.proc;
|
||||||
tproc->flg |= REG_ARGS;
|
tproc->flg |= REG_ARGS;
|
||||||
tidx = 0;
|
|
||||||
/* Get registers and index into target procedure's local list */
|
/* Get registers and index into target procedure's local list */
|
||||||
ps = ticode->hl()->call.args;
|
ps = ticode->hl()->call.args;
|
||||||
ts = &tproc->args;
|
ts = &tproc->args;
|
||||||
|
|||||||
@ -67,8 +67,8 @@ static boolT isLong22 (iICODE pIcode, iICODE pEnd, iICODE &off)
|
|||||||
// preincrement because pIcode is not checked here
|
// preincrement because pIcode is not checked here
|
||||||
iICODE icodes[] = { ++pIcode,++pIcode,++pIcode };
|
iICODE icodes[] = { ++pIcode,++pIcode,++pIcode };
|
||||||
if ( icodes[1]->ll()->match(iCMP) &&
|
if ( icodes[1]->ll()->match(iCMP) &&
|
||||||
(isJCond (icodes[0]->ll()->getOpcode())) &&
|
(isJCond ((llIcode)icodes[0]->ll()->getOpcode())) &&
|
||||||
(isJCond (icodes[2]->ll()->getOpcode())))
|
(isJCond ((llIcode)icodes[2]->ll()->getOpcode())))
|
||||||
{
|
{
|
||||||
off = initial_icode;
|
off = initial_icode;
|
||||||
advance(off,2);
|
advance(off,2);
|
||||||
@ -244,7 +244,7 @@ void Function::propLongStk (int i, const ID &pLocId)
|
|||||||
next1 = ++iICODE(pIcode);
|
next1 = ++iICODE(pIcode);
|
||||||
if(next1==pEnd)
|
if(next1==pEnd)
|
||||||
break;
|
break;
|
||||||
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
|
if ((pIcode->type == HIGH_LEVEL) || ( not pIcode->valid() ))
|
||||||
continue;
|
continue;
|
||||||
if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode())
|
if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode())
|
||||||
{
|
{
|
||||||
@ -312,7 +312,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
ICODE &icode(*pIcode);
|
ICODE &icode(*pIcode);
|
||||||
|
|
||||||
|
|
||||||
if ((icode.type == HIGH_LEVEL) || (icode.invalid == TRUE))
|
if ((icode.type == HIGH_LEVEL) || ( not icode.valid() ))
|
||||||
continue;
|
continue;
|
||||||
if (icode.ll()->getOpcode() != next1->ll()->getOpcode())
|
if (icode.ll()->getOpcode() != next1->ll()->getOpcode())
|
||||||
continue;
|
continue;
|
||||||
@ -391,7 +391,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
LLOperand * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */
|
LLOperand * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */
|
||||||
int arc;
|
int arc;
|
||||||
|
|
||||||
if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE))
|
if ((pIcode->type == HIGH_LEVEL) || ( not pIcode->valid() ))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode())
|
if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode())
|
||||||
@ -478,7 +478,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
|
|||||||
* JX lab
|
* JX lab
|
||||||
* => HLI_JCOND (regH:regL X 0) lab
|
* => HLI_JCOND (regH:regL X 0) lab
|
||||||
* This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */
|
* This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */
|
||||||
else if (pIcode->ll()->match(iOR) && (next1 != pEnd) && (isJCond (next1->ll()->getOpcode())))
|
else if (pIcode->ll()->match(iOR) && (next1 != pEnd) && (isJCond ((llIcode)next1->ll()->getOpcode())))
|
||||||
{
|
{
|
||||||
if ((pIcode->ll()->dst.regi == pLocId.id.longId.h) && (pIcode->ll()->src.regi == pLocId.id.longId.l))
|
if ((pIcode->ll()->dst.regi == pLocId.id.longId.h) && (pIcode->ll()->src.regi == pLocId.id.longId.l))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -35,7 +35,6 @@ static BB *firstOfQueue (queue &Q)
|
|||||||
|
|
||||||
/* Appends pointer to node at the end of the queue Q if node is not present
|
/* Appends pointer to node at the end of the queue Q if node is not present
|
||||||
* in this queue. Returns the queue node just appended. */
|
* in this queue. Returns the queue node just appended. */
|
||||||
//lint -sem(appendQueue,custodial(1))
|
|
||||||
queue::iterator appendQueue (queue &Q, BB *node)
|
queue::iterator appendQueue (queue &Q, BB *node)
|
||||||
{
|
{
|
||||||
auto iter=std::find(Q.begin(),Q.end(),node);
|
auto iter=std::find(Q.begin(),Q.end(),node);
|
||||||
@ -100,7 +99,7 @@ static void appendNodeInt (queue &pqH, BB *node, interval *pI)
|
|||||||
void derSeq_Entry::findIntervals (Function *c)
|
void derSeq_Entry::findIntervals (Function *c)
|
||||||
{
|
{
|
||||||
interval *pI, /* Interval being processed */
|
interval *pI, /* Interval being processed */
|
||||||
*J=0; /* ^ last interval in derivedGi->Ii */
|
*J; /* ^ last interval in derivedGi->Ii */
|
||||||
BB *h, /* Node being processed */
|
BB *h, /* Node being processed */
|
||||||
*header, /* Current interval's header node */
|
*header, /* Current interval's header node */
|
||||||
*succ; /* Successor basic block */
|
*succ; /* Successor basic block */
|
||||||
@ -174,17 +173,12 @@ void derSeq_Entry::findIntervals (Function *c)
|
|||||||
/* Displays the intervals of the graph Gi. */
|
/* Displays the intervals of the graph Gi. */
|
||||||
static void displayIntervals (interval *pI)
|
static void displayIntervals (interval *pI)
|
||||||
{
|
{
|
||||||
|
|
||||||
while (pI)
|
while (pI)
|
||||||
{
|
{
|
||||||
printf (" Interval #: %ld\t#OutEdges: %ld\n", pI->numInt, pI->numOutEdges);
|
printf (" Interval #: %ld\t#OutEdges: %ld\n", pI->numInt, pI->numOutEdges);
|
||||||
#ifdef _lint
|
|
||||||
for(auto iter=pI->nodes.begin(); iter!=pI->nodes.end(); ++iter)
|
|
||||||
{
|
|
||||||
BB *node(*iter);
|
|
||||||
#else
|
|
||||||
for(BB *node : pI->nodes)
|
for(BB *node : pI->nodes)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
if (node->correspInt == NULL) /* real BBs */
|
if (node->correspInt == NULL) /* real BBs */
|
||||||
printf (" Node: %ld\n", node->begin()->loc_ip);
|
printf (" Node: %ld\n", node->begin()->loc_ip);
|
||||||
else // BBs represent intervals
|
else // BBs represent intervals
|
||||||
@ -275,14 +269,8 @@ bool Function::nextOrderGraph (derSeq &derivedGi)
|
|||||||
|
|
||||||
if (BBnode->edges.size() > 0)
|
if (BBnode->edges.size() > 0)
|
||||||
{
|
{
|
||||||
#ifdef _lint
|
|
||||||
for (auto ik=listIi.begin(); ik!=listIi.end(); ++ik)
|
|
||||||
{
|
|
||||||
BB *curr(*ik);
|
|
||||||
#else
|
|
||||||
for(BB *curr : listIi)
|
for(BB *curr : listIi)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
for (j = 0; j < curr->edges.size(); j++)
|
for (j = 0; j < curr->edges.size(); j++)
|
||||||
{
|
{
|
||||||
succ = curr->edges[j].BBptr;
|
succ = curr->edges[j].BBptr;
|
||||||
@ -300,22 +288,10 @@ bool Function::nextOrderGraph (derSeq &derivedGi)
|
|||||||
* Determines the number of in edges to each new BB, and places it
|
* Determines the number of in edges to each new BB, and places it
|
||||||
* in numInEdges and inEdgeCount for later interval processing. */
|
* in numInEdges and inEdgeCount for later interval processing. */
|
||||||
curr = new_entry.Gi = bbs.front();
|
curr = new_entry.Gi = bbs.front();
|
||||||
#ifdef _lint
|
|
||||||
for (auto ik=bbs.begin(); ik!=bbs.end(); ++ik)
|
|
||||||
{
|
|
||||||
BB *curr(*ik);
|
|
||||||
#else
|
|
||||||
for(BB *curr : bbs)
|
for(BB *curr : bbs)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
#ifdef _lint
|
|
||||||
for (auto il=curr->edges.begin(); il!=curr->edges.end(); ++il)
|
|
||||||
{
|
|
||||||
TYPEADR_TYPE &edge(*il);
|
|
||||||
#else
|
|
||||||
for(TYPEADR_TYPE &edge : curr->edges)
|
for(TYPEADR_TYPE &edge : curr->edges)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
BBnode = new_entry.Gi; /* BB of an interval */
|
BBnode = new_entry.Gi; /* BB of an interval */
|
||||||
auto iter= std::find_if(bbs.begin(),bbs.end(),
|
auto iter= std::find_if(bbs.begin(),bbs.end(),
|
||||||
[&edge](BB *node)->bool { return edge.intPtr==node->correspInt;});
|
[&edge](BB *node)->bool { return edge.intPtr==node->correspInt;});
|
||||||
|
|||||||
@ -785,7 +785,7 @@ static void prefix(int )
|
|||||||
|
|
||||||
inline void BumpOpcode(LLInst &ll)
|
inline void BumpOpcode(LLInst &ll)
|
||||||
{
|
{
|
||||||
llIcode ic = ll.getOpcode();
|
llIcode ic((llIcode)ll.getOpcode());
|
||||||
ic = (llIcode)(((int)ic)+1); // Bump this icode via the int type
|
ic = (llIcode)(((int)ic)+1); // Bump this icode via the int type
|
||||||
ll.setOpcode(ic);
|
ll.setOpcode(ic);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,14 +91,8 @@ void udm(void)
|
|||||||
void Function::displayCFG()
|
void Function::displayCFG()
|
||||||
{
|
{
|
||||||
printf("\nBasic Block List - Proc %s", name.c_str());
|
printf("\nBasic Block List - Proc %s", name.c_str());
|
||||||
#ifdef _lint
|
|
||||||
for (auto ik=m_cfg.begin(); ik!=m_cfg.end(); ++ik)
|
|
||||||
{
|
|
||||||
BB *pBB(*ik);
|
|
||||||
#else
|
|
||||||
for (BB *pBB : m_cfg)
|
for (BB *pBB : m_cfg)
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
pBB->display();
|
pBB->display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user