COND_EXPR splitting preparations
This commit is contained in:
@@ -52,7 +52,7 @@ enum condId
|
||||
enum condOp
|
||||
{
|
||||
/* For conditional expressions */
|
||||
LESS_EQUAL = 0, /* <= */
|
||||
LESS_EQUAL, /* <= */
|
||||
LESS, /* < */
|
||||
EQUAL, /* == */
|
||||
NOT_EQUAL, /* != */
|
||||
@@ -267,6 +267,7 @@ enum hlFirst
|
||||
/* HIGH_LEVEL icodes opcodes */
|
||||
enum hlIcode
|
||||
{
|
||||
HLI_INVALID,
|
||||
HLI_ASSIGN, /* := */
|
||||
HLI_CALL, /* Call procedure */
|
||||
HLI_JCOND, /* Conditional jump */
|
||||
|
||||
109
include/ast.h
109
include/ast.h
@@ -27,6 +27,7 @@ struct Function;
|
||||
struct STKFRAME;
|
||||
struct LOCAL_ID;
|
||||
struct ICODE;
|
||||
struct LLInst;
|
||||
struct ID;
|
||||
typedef std::list<ICODE>::iterator iICODE;
|
||||
#include "IdentType.h"
|
||||
@@ -34,19 +35,42 @@ typedef std::list<ICODE>::iterator iICODE;
|
||||
/* Expression data type */
|
||||
struct COND_EXPR
|
||||
{
|
||||
protected:
|
||||
struct /* for BOOLEAN_OP */
|
||||
{
|
||||
condOp op;
|
||||
COND_EXPR *lhs;
|
||||
COND_EXPR *rhs;
|
||||
} boolExpr;
|
||||
|
||||
public:
|
||||
condNodeType type; /* Conditional Expression Node Type */
|
||||
union _exprNode { /* Different cond expr nodes */
|
||||
struct /* for BOOLEAN_OP */
|
||||
{
|
||||
condOp op;
|
||||
COND_EXPR *lhs;
|
||||
COND_EXPR *rhs;
|
||||
} boolExpr;
|
||||
COND_EXPR *unaryExp; /* for NEGATION,ADDRESSOF,DEREFERENCE*/
|
||||
IDENTTYPE ident; /* for IDENTIFIER */
|
||||
} expr;
|
||||
COND_EXPR *lhs()
|
||||
{
|
||||
assert(type==BOOLEAN_OP);
|
||||
return boolExpr.lhs;
|
||||
}
|
||||
const COND_EXPR *lhs() const
|
||||
{
|
||||
assert(type==BOOLEAN_OP);
|
||||
return boolExpr.lhs;
|
||||
}
|
||||
COND_EXPR *rhs()
|
||||
{
|
||||
assert(type==BOOLEAN_OP);
|
||||
return boolExpr.rhs;
|
||||
}
|
||||
const COND_EXPR *rhs() const
|
||||
{
|
||||
assert(type==BOOLEAN_OP);
|
||||
return boolExpr.rhs;
|
||||
}
|
||||
condOp op() const { return boolExpr.op;}
|
||||
public:
|
||||
static COND_EXPR *idGlob(int16_t segValue, int16_t off);
|
||||
static COND_EXPR *idRegIdx(int idx, regType reg_type);
|
||||
static COND_EXPR *idKte(uint32_t kte, uint8_t size);
|
||||
static COND_EXPR *idLoc(int off, LOCAL_ID *localId);
|
||||
@@ -58,23 +82,86 @@ public:
|
||||
static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, iICODE atOffset);
|
||||
static COND_EXPR *idFunc(Function *pproc, STKFRAME *args);
|
||||
static COND_EXPR *idID(const ID *retVal, LOCAL_ID *locsym, iICODE ix_);
|
||||
static COND_EXPR *id(const ICODE &pIcode, opLoc sd, Function *pProc, iICODE ix_, ICODE &duIcode, operDu du);
|
||||
static COND_EXPR * id(const LLInst &ll_insn, opLoc sd, Function *pProc, iICODE ix_, ICODE &duIcode, operDu du);
|
||||
static COND_EXPR *boolOp(COND_EXPR *lhs, COND_EXPR *rhs, condOp op);
|
||||
static bool insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR **tree, int longIdx);
|
||||
static bool insertSubTreeReg(COND_EXPR *&tree, COND_EXPR *_expr, uint8_t regi, LOCAL_ID *locsym);
|
||||
public:
|
||||
COND_EXPR *clone();
|
||||
virtual COND_EXPR *clone();
|
||||
void release();
|
||||
void changeBoolOp(condOp newOp);
|
||||
COND_EXPR(COND_EXPR &other)
|
||||
{
|
||||
type=other.type;
|
||||
expr=other.expr;
|
||||
boolExpr=other.boolExpr;
|
||||
}
|
||||
COND_EXPR(condNodeType t=UNKNOWN_OP) : type(t)
|
||||
{
|
||||
memset(&expr,0,sizeof(_exprNode));
|
||||
memset(&boolExpr,0,sizeof(boolExpr));
|
||||
|
||||
}
|
||||
virtual ~COND_EXPR() {}
|
||||
public:
|
||||
COND_EXPR *inverse(); // return new COND_EXPR that is invarse of this
|
||||
virtual COND_EXPR *inverse(); // return new COND_EXPR that is invarse of this
|
||||
virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *pproc);
|
||||
};
|
||||
struct BinaryOperator : public COND_EXPR
|
||||
{
|
||||
condOp m_op;
|
||||
COND_EXPR *m_lhs;
|
||||
COND_EXPR *m_rhs;
|
||||
BinaryOperator()
|
||||
{
|
||||
m_op = DUMMY;
|
||||
m_lhs=m_rhs=nullptr;
|
||||
}
|
||||
static BinaryOperator *CreateAdd(COND_EXPR *l,COND_EXPR *r);
|
||||
virtual COND_EXPR *inverse();
|
||||
virtual COND_EXPR *clone();
|
||||
virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *pproc);
|
||||
COND_EXPR *lhs()
|
||||
{
|
||||
assert(type==BOOLEAN_OP);
|
||||
return m_lhs;
|
||||
}
|
||||
const COND_EXPR *lhs() const
|
||||
{
|
||||
assert(type==BOOLEAN_OP);
|
||||
return m_lhs;
|
||||
}
|
||||
COND_EXPR *rhs()
|
||||
{
|
||||
assert(type==BOOLEAN_OP);
|
||||
return m_rhs;
|
||||
}
|
||||
const COND_EXPR *rhs() const
|
||||
{
|
||||
assert(type==BOOLEAN_OP);
|
||||
return m_rhs;
|
||||
}
|
||||
condOp op() const { return m_op;}
|
||||
};
|
||||
struct UnaryOperator : public COND_EXPR
|
||||
{
|
||||
condOp op;
|
||||
COND_EXPR *unaryExp;
|
||||
virtual COND_EXPR *inverse();
|
||||
virtual COND_EXPR *clone();
|
||||
virtual bool xClear(iICODE f, iICODE t, iICODE lastBBinst, Function *pproc);
|
||||
static UnaryOperator *Create(condNodeType t, COND_EXPR *sub_expr)
|
||||
{
|
||||
UnaryOperator *newExp = new UnaryOperator();
|
||||
newExp->type=t;
|
||||
newExp->unaryExp = sub_expr;
|
||||
return (newExp);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct GlobalVariable : public COND_EXPR
|
||||
{
|
||||
static COND_EXPR *Create(int16_t segValue, int16_t off);
|
||||
};
|
||||
struct Constant : public COND_EXPR
|
||||
{};
|
||||
|
||||
@@ -163,8 +163,6 @@ void adjustActArgType (COND_EXPR *, hlType, Function *);
|
||||
std::string walkCondExpr (const COND_EXPR *exp, Function * pProc, int *);
|
||||
int hlTypeSize (const COND_EXPR *, Function *);
|
||||
hlType expType (const COND_EXPR *, Function *);
|
||||
bool insertSubTreeReg(COND_EXPR *&, COND_EXPR *, uint8_t, LOCAL_ID *);
|
||||
bool insertSubTreeLongReg (COND_EXPR *, COND_EXPR **, int);
|
||||
|
||||
|
||||
/* Exported functions from hlicode.c */
|
||||
|
||||
@@ -137,6 +137,15 @@ public:
|
||||
asgn.lhs=l;
|
||||
asgn.rhs=r;
|
||||
}
|
||||
HLTYPE(hlIcode op=HLI_INVALID) : opcode(op)
|
||||
{}
|
||||
HLTYPE & operator=(const HLTYPE &l)
|
||||
{
|
||||
exp=l.exp;
|
||||
opcode=l.opcode;
|
||||
asgn=l.asgn;
|
||||
call=l.call;
|
||||
}
|
||||
public:
|
||||
std::string write1HlIcode(Function *pProc, int *numLoc);
|
||||
void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs);
|
||||
@@ -245,6 +254,8 @@ public:
|
||||
|
||||
void flops(std::ostringstream &out);
|
||||
bool isJmpInst();
|
||||
HLTYPE toHighLevel(COND_EXPR *lhs, COND_EXPR *rhs, Function *func);
|
||||
HLTYPE createCall();
|
||||
};
|
||||
|
||||
/* Icode definition: LOW_LEVEL and HIGH_LEVEL */
|
||||
@@ -319,6 +330,7 @@ public:
|
||||
const LLInst * ll() const { return &m_ll;}
|
||||
HLTYPE * hl() { return &m_hl;}
|
||||
const HLTYPE * hl() const { return &m_hl;}
|
||||
void hl(const HLTYPE &v) { m_hl=v;}
|
||||
int loc_ip; // used by CICodeRec to number ICODEs
|
||||
|
||||
void setRegDU(uint8_t regi, operDu du_in);
|
||||
|
||||
Reference in New Issue
Block a user