Replaced memory tags #defines with eAreaType enum

Added replaceExpr, which replaces expression, and deletes the old one.
Moved subReg* family to Machine_X86, also moved there a few float op
decoding parts.
A few more usages of cCode global replaced with ostreams
Refactored compoundCond().
This commit is contained in:
Artur K
2012-03-13 22:10:07 +01:00
parent c2e5ac2694
commit a740690e04
24 changed files with 525 additions and 504 deletions

View File

@@ -105,7 +105,7 @@ static BB * Create(int start, int ip, uint8_t nodeType, int numOutEdges, Functio
///
const Function *getParent() const { return Parent; }
Function *getParent() { return Parent; }
void writeBB(int lev, Function *pProc, int *numLoc);
void writeBB(std::ostream &ostr, int lev, Function *pProc, int *numLoc);
BB *rmJMP(int marker, BB *pBB);
void genDU1();
private:

View File

@@ -151,7 +151,14 @@ public:
void controlFlowAnalysis();
void newRegArg(iICODE picode, iICODE ticode);
void writeProcComments(std::ostream &ostr);
protected:
bool Case_X_and_Y(BB* pbb, BB* thenBB, BB* elseBB);
bool Case_X_or_Y(BB* pbb, BB* thenBB, BB* elseBB);
bool Case_notX_or_Y(BB* pbb, BB* thenBB, BB* elseBB);
bool Case_notX_and_Y(BB* pbb, BB* thenBB, BB* elseBB);
void replaceInEdge(BB* where, BB* which, BB* with);
protected:
bool removeInEdge_Flag_and_ProcessLatch(BB *pbb, BB *a, BB *b);
// TODO: replace those with friend visitor ?
void propLongReg(int loc_ident_idx, const ID &pLocId);
void propLongStk(int i, const ID &pLocId);

View File

@@ -44,29 +44,29 @@ protected:
} boolExpr;
public:
condNodeType type; /* Conditional Expression Node Type */
condNodeType m_type; /* Conditional Expression Node Type */
union _exprNode { /* Different cond expr nodes */
COND_EXPR *unaryExp; /* for NEGATION,ADDRESSOF,DEREFERENCE*/
IDENTTYPE ident; /* for IDENTIFIER */
} expr;
COND_EXPR *lhs()
{
assert(type==BOOLEAN_OP);
assert(m_type==BOOLEAN_OP);
return boolExpr.lhs;
}
const COND_EXPR *lhs() const
{
assert(type==BOOLEAN_OP);
assert(m_type==BOOLEAN_OP);
return boolExpr.lhs;
}
COND_EXPR *rhs()
{
assert(type==BOOLEAN_OP);
assert(m_type==BOOLEAN_OP);
return boolExpr.rhs;
}
const COND_EXPR *rhs() const
{
assert(type==BOOLEAN_OP);
assert(m_type==BOOLEAN_OP);
return boolExpr.rhs;
}
condOp op() const { return boolExpr.op;}
@@ -92,11 +92,11 @@ public:
void changeBoolOp(condOp newOp);
COND_EXPR(const COND_EXPR &other)
{
type=other.type;
m_type=other.m_type;
expr=other.expr;
boolExpr=other.boolExpr;
}
COND_EXPR(condNodeType t=UNKNOWN_OP) : type(t)
COND_EXPR(condNodeType t=UNKNOWN_OP) : m_type(t)
{
memset(&expr,0,sizeof(_exprNode));
memset(&boolExpr,0,sizeof(boolExpr));
@@ -108,6 +108,7 @@ public:
virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *pproc);
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, LOCAL_ID *locsym);
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
virtual hlType expType(Function *pproc) const;
};
struct BinaryOperator : public COND_EXPR
{
@@ -129,22 +130,22 @@ struct BinaryOperator : public COND_EXPR
COND_EXPR *lhs()
{
assert(type==BOOLEAN_OP);
assert(m_type==BOOLEAN_OP);
return m_lhs;
}
const COND_EXPR *lhs() const
{
assert(type==BOOLEAN_OP);
assert(m_type==BOOLEAN_OP);
return m_lhs;
}
COND_EXPR *rhs()
{
assert(type==BOOLEAN_OP);
assert(m_type==BOOLEAN_OP);
return m_rhs;
}
const COND_EXPR *rhs() const
{
assert(type==BOOLEAN_OP);
assert(m_type==BOOLEAN_OP);
return m_rhs;
}
condOp op() const { return m_op;}
@@ -161,7 +162,7 @@ struct UnaryOperator : public COND_EXPR
static UnaryOperator *Create(condNodeType t, COND_EXPR *sub_expr)
{
UnaryOperator *newExp = new UnaryOperator();
newExp->type=t;
newExp->m_type=t;
newExp->unaryExp = sub_expr;
return (newExp);
}

View File

@@ -8,14 +8,26 @@
#include <stdio.h>
#include <vector>
#include <string>
typedef std::vector<std::string> strTable;
struct strTable : std::vector<std::string>
{
/* Returns the next available index into the table */
size_t nextIdx() {return size();}
public:
void addLabelBundle(int idx, int label);
};
struct bundle
{
public:
void appendCode(const char *format, ...);
void appendCode(const std::string &s);
void appendDecl(const char *format, ...);
void appendDecl(const std::string &);
void init()
{
decl.clear();
code.clear();
}
strTable decl; /* Declarations */
strTable code; /* C code */
};
@@ -23,9 +35,7 @@ public:
#define lineSize 360 /* 3 lines in the mean time */
void newBundle (bundle *procCode);
int nextBundleIdx (strTable *strTab);
void addLabelBundle (strTable &strTab, int idx, int label);
//void newBundle (bundle *procCode);
void writeBundle (std::ostream &ios, bundle procCode);
void freeBundle (bundle *procCode);

View File

@@ -39,8 +39,8 @@ public:
};
//#define NUM_PROCS_DELTA 5 /* delta # procs a proc invokes */
//extern std::list<Function> pProcList;
extern FunctionListType pProcList;
extern CALL_GRAPH * callGraph; /* Pointer to the head of the call graph */
//extern FunctionListType pProcList;
//extern CALL_GRAPH * callGraph; /* Pointer to the head of the call graph */
extern bundle cCode; /* Output C procedure's declaration and code */
/**** Global variables ****/
@@ -89,21 +89,24 @@ extern std::bitset<32> maskDuReg[30]; /* masks off du bits for regs */
/* Registers used by icode instructions */
/* Memory map states */
#define BM_UNKNOWN 0 /* Unscanned memory */
#define BM_DATA 1 /* Data */
#define BM_CODE 2 /* Code */
#define BM_IMPURE 3 /* Used as Data and Code*/
enum eAreaType
{
BM_UNKNOWN = 0, /* Unscanned memory */
BM_DATA = 1, /* Data */
BM_CODE = 2, /* Code */
BM_IMPURE = 3 /* Used as Data and Code*/
};
/* Intermediate instructions statistics */
struct STATS
{
int numBBbef; /* number of basic blocks initially */
int numBBaft; /* number of basic blocks at the end */
int nOrder; /* n-th order */
int numLLIcode; /* number of low-level Icode instructions */
int numBBbef; /* number of basic blocks initially */
int numBBaft; /* number of basic blocks at the end */
int nOrder; /* n-th order */
int numLLIcode; /* number of low-level Icode instructions */
int numHLIcode; /* number of high-level Icode instructions */
int totalLL; /* total number of low-level Icode insts */
int totalHL; /* total number of high-level Icod insts */
int totalLL; /* total number of low-level Icode insts */
int totalHL; /* total number of high-level Icod insts */
};
extern STATS stats; /* Icode statistics */
@@ -124,32 +127,30 @@ public:
void udm(void); /* udm.c */
void freeCFG(BB * cfg); /* graph.c */
BB * newBB(BB *, int, int, uint8_t, int, Function *); /* graph.c */
BB * newBB(BB *, int, int, uint8_t, int, Function *); /* graph.c */
void BackEnd(char *filename, CALL_GRAPH *); /* backend.c */
char *cChar(uint8_t c); /* backend.c */
eErrorId scan(uint32_t ip, ICODE &p); /* scanner.c */
char *cChar(uint8_t c); /* backend.c */
eErrorId scan(uint32_t ip, ICODE &p); /* scanner.c */
void parse (CALL_GRAPH * *); /* parser.c */
int strSize (uint8_t *, char); /* parser.c */
//void disassem(int pass, Function * pProc); /* disassem.c */
void interactDis(Function * initProc, int initIC); /* disassem.c */
bool JmpInst(llIcode opcode); /* idioms.c */
queue::iterator appendQueue(queue &Q, BB *node); /* reducible.c */
int strSize (uint8_t *, char); /* parser.c */
//void disassem(int pass, Function * pProc); /* disassem.c */
void interactDis(Function * initProc, int initIC); /* disassem.c */
bool JmpInst(llIcode opcode); /* idioms.c */
queue::iterator appendQueue(queue &Q, BB *node); /* reducible.c */
void SetupLibCheck(void); /* chklib.c */
void CleanupLibCheck(void); /* chklib.c */
bool LibCheck(Function &p); /* chklib.c */
bool LibCheck(Function &p); /* chklib.c */
/* Exported functions from procs.c */
boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction);
void allocStkArgs (ICODE *, int);
void placeStkArg (ICODE *, COND_EXPR *, int);
void adjustActArgType (COND_EXPR *, hlType, Function *);
/* Exported functions from ast.c */
std::string walkCondExpr (const COND_EXPR *exp, Function * pProc, int *);
int hlTypeSize (const COND_EXPR *, Function *);
hlType expType (const COND_EXPR *, Function *);
//hlType expType (const COND_EXPR *, Function *);
/* Exported functions from hlicode.c */
@@ -164,6 +165,4 @@ boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iI
eReg otherLongRegi(eReg, int, LOCAL_ID *);
extern eReg subRegH(eReg reg); //TODO: move these into machine_x86
extern eReg subRegL(eReg reg);
extern const char *indentStr(int level);

View File

@@ -120,6 +120,12 @@ public:
assert(e);
exp.v=e;
}
void replaceExpr(COND_EXPR *e)
{
assert(e);
delete exp.v;
exp.v=e;
}
COND_EXPR * expr() { return exp.v;}
const COND_EXPR * const expr() const { return exp.v;}
void set(hlIcode i,COND_EXPR *e)

View File

@@ -49,6 +49,7 @@ public:
Machine_X86();
static const std::string &regName(eReg r);
static const std::string &opcodeName(unsigned r);
static const std::string &floatOpName(unsigned r);
static bool physicalReg(eReg r);
/* Writes the registers that are set in the bitvector */
//TODO: move this into Machine_X86 ?
@@ -61,6 +62,9 @@ public:
ostr << regName(eReg(j));
}
}
static eReg subRegH(eReg reg); //TODO: move these into machine_x86
static eReg subRegL(eReg reg);
static bool isMemOff(eReg r);
static bool isSubRegisterOf(eReg reg, eReg parent);
};