Replaced a few places which used ICODE * in favour of ICODE &, also split HLTYPE attriubtes into 3 classes with virtual methods

This commit is contained in:
Artur K
2012-02-28 21:17:50 +01:00
parent e0503c71a3
commit 493225ad64
12 changed files with 402 additions and 401 deletions

View File

@@ -106,9 +106,9 @@ public:
void markImpure();
void findImmedDom();
void FollowCtrl(CALL_GRAPH *pcallGraph, STATE *pstate);
void process_operands(ICODE *pIcode, STATE *pstate);
boolT process_JMP(ICODE *pIcode, STATE *pstate, CALL_GRAPH *pcallGraph);
boolT process_CALL(ICODE *pIcode, CALL_GRAPH *pcallGraph, STATE *pstate);
void process_operands(ICODE &pIcode, STATE *pstate);
boolT process_JMP(ICODE &pIcode, STATE *pstate, CALL_GRAPH *pcallGraph);
boolT process_CALL(ICODE &pIcode, CALL_GRAPH *pcallGraph, STATE *pstate);
void displayCFG();
void freeCFG();
void codeGen(std::ostream &fs);

View File

@@ -23,10 +23,6 @@ static const condOp condOpJCond[12] = {LESS, LESS_EQUAL, GREATER_EQUAL, GREATER,
EQUAL, NOT_EQUAL, LESS, GREATER_EQUAL,
LESS_EQUAL, GREATER, GREATER_EQUAL, LESS};
static const condOp invCondOpJCond[12] = {GREATER_EQUAL, GREATER, LESS, LESS_EQUAL,
NOT_EQUAL, EQUAL, GREATER_EQUAL, LESS,
GREATER, LESS_EQUAL, LESS, GREATER_EQUAL};
struct Function;
struct STKFRAME;
struct LOCAL_ID;
@@ -79,6 +75,7 @@ public:
memset(&expr,0,sizeof(_exprNode));
}
public:
COND_EXPR *inverse(); // return new COND_EXPR that is invarse of this
};
/* Sequence of conditional expression data type */

View File

@@ -166,7 +166,7 @@ void freeCFG(BB * cfg); /* graph.c */
BB * newBB(BB *, Int, Int, byte, Int, Function *); /* graph.c */
void BackEnd(char *filename, CALL_GRAPH *); /* backend.c */
char *cChar(byte c); /* backend.c */
eErrorId scan(dword ip, ICODE * p); /* scanner.c */
eErrorId scan(dword ip, ICODE &p); /* scanner.c */
void parse (CALL_GRAPH * *); /* parser.c */
Int strSize (byte *, char); /* parser.c */
@@ -181,7 +181,6 @@ bool LibCheck(Function &p); /* chklib.c */
/* Exported functions from procs.c */
boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction);
boolT newStkArg (ICODE *, COND_EXPR *, llIcode, Function *);
void allocStkArgs (ICODE *, Int);
void placeStkArg (ICODE *, COND_EXPR *, Int);
void adjustActArgType (COND_EXPR *, hlType, Function *);
@@ -197,11 +196,9 @@ bool insertSubTreeLongReg (COND_EXPR *, COND_EXPR **, Int);
/* Exported functions from hlicode.c */
std::string writeCall (Function *, STKFRAME *, Function *, Int *);
char *write1HlIcode (HLTYPE, Function *, Int *);
char *writeJcond (HLTYPE, Function *, Int *);
char *writeJcondInv (HLTYPE, Function *, Int *);
Int power2 (Int);
void inverseCondOp (COND_EXPR **);
/* Exported funcions from locident.c */
boolT checkLongEq (LONG_STKID_TYPE, iICODE, Int, Function *, Assignment &asgn, Int);

View File

@@ -253,20 +253,92 @@ struct DU
struct COND_EXPR;
struct HlTypeSupport
{
//hlIcode opcode; /* hlIcode opcode */
virtual bool removeRegFromLong(byte regi, LOCAL_ID *locId)=0;
virtual std::string writeOut(Function *pProc, Int *numLoc)=0;
protected:
void performLongRemoval (byte regi, LOCAL_ID *locId, COND_EXPR *tree);
};
struct CallType : public HlTypeSupport
{
//for HLI_CALL
Function * proc;
STKFRAME * args; // actual arguments
void allocStkArgs (Int num);
bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc);
void placeStkArg(COND_EXPR *exp, Int pos);
public:
bool removeRegFromLong(byte regi, LOCAL_ID *locId)
{
printf("CallType : removeRegFromLong not supproted");
return false;
}
std::string writeOut(Function *pProc, Int *numLoc);
};
struct AssignType : public HlTypeSupport
{
/* for HLI_ASSIGN */
COND_EXPR *lhs;
COND_EXPR *rhs;
bool removeRegFromLong(byte regi, LOCAL_ID *locId)
{
performLongRemoval(regi,locId,lhs);
return true;
}
std::string writeOut(Function *pProc, Int *numLoc);
};
struct ExpType : public HlTypeSupport
{
/* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/
COND_EXPR *v;
bool removeRegFromLong(byte regi, LOCAL_ID *locId)
{
performLongRemoval(regi,locId,v);
return true;
}
std::string writeOut(Function *pProc, Int *numLoc);
};
struct HLTYPE
{
hlIcode opcode; /* hlIcode opcode */
union { /* different operands */
struct { /* for HLI_ASSIGN */
COND_EXPR *lhs;
COND_EXPR *rhs;
} asgn;
COND_EXPR *exp; /* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/
struct { /* for HLI_CALL */
Function *proc;
STKFRAME *args; /* actual arguments */
} call;
} oper; /* operand */
ExpType exp; /* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/
AssignType asgn;
CallType call;
HlTypeSupport *get()
{
switch(opcode)
{
case HLI_ASSIGN: return &asgn;
case HLI_RET:
case HLI_POP:
case HLI_PUSH: return &exp;
case HLI_CALL: return &call;
default:
return 0;
}
}
void expr(COND_EXPR *e) { exp.v=e;}
COND_EXPR * expr() { return exp.v;}
void set(hlIcode i,COND_EXPR *e)
{
assert(exp.v==0);
opcode=i;
exp.v=e;
}
void set(COND_EXPR *l,COND_EXPR *r)
{
opcode = HLI_ASSIGN;
assert((asgn.lhs==0) and (asgn.rhs==0)); //prevent memory leaks
asgn.lhs=l;
asgn.rhs=r;
}
public:
std::string write1HlIcode(Function *pProc, Int *numLoc);
} ;
/* LOW_LEVEL icode operand record */
struct LLOperand //: public llvm::MCOperand
@@ -430,6 +502,10 @@ struct ICODE
public:
bool removeDefRegi(byte regi, Int thisDefIdx, LOCAL_ID *locId);
void checkHlCall();
bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc)
{
return ic.hl.call.newStkArg(exp,opcode,pproc);
}
};
// This is the icode array object.