Fixes to libdisasm, also use it a bit more
This commit is contained in:
@@ -15,6 +15,7 @@ struct PROG /* Loaded program image parameters */
|
||||
uint16_t segMain; /* The segment of the main() proc */
|
||||
bool bSigs; /* True if signatures loaded */
|
||||
int cbImage; /* Length of image in bytes */
|
||||
uint8_t * Image; /* Allocated by loader to hold entire program image */
|
||||
const uint8_t *image() const {return Imagez;}
|
||||
uint8_t * Imagez; /* Allocated by loader to hold entire program image */
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ enum regType
|
||||
};
|
||||
enum condId
|
||||
{
|
||||
UNDEF=0,
|
||||
GLOB_VAR, /* global variable */
|
||||
REGISTER, /* register */
|
||||
LOCAL_VAR, /* negative disp */
|
||||
|
||||
@@ -2,32 +2,29 @@
|
||||
#include "ast.h"
|
||||
#include "types.h"
|
||||
#include "machine_x86.h"
|
||||
|
||||
struct GlobalVariable;
|
||||
struct AstIdent;
|
||||
struct IDENTTYPE
|
||||
{
|
||||
friend struct GlobalVariable;
|
||||
friend struct Constant;
|
||||
friend struct AstIdent;
|
||||
protected:
|
||||
condId idType;
|
||||
regType regiType; /* for REGISTER only */
|
||||
public:
|
||||
condId type() {return idType;}
|
||||
void type(condId t) {idType=t;}
|
||||
union _idNode {
|
||||
int regiIdx; /* index into localId, REGISTER */
|
||||
int globIdx; /* index into symtab for GLOB_VAR */
|
||||
int localIdx; /* idx into localId, LOCAL_VAR */
|
||||
int paramIdx; /* idx into args symtab, PARAMS */
|
||||
int idxGlbIdx; /* idx into localId, GLOB_VAR_IDX */
|
||||
struct _kte
|
||||
{ /* for CONSTANT only */
|
||||
uint32_t kte; /* value of the constant */
|
||||
uint8_t size; /* #bytes size constant */
|
||||
} kte;
|
||||
uint32_t strIdx; /* idx into image, for STRING */
|
||||
int longIdx; /* idx into LOCAL_ID table, LONG_VAR*/
|
||||
struct _call { /* for FUNCTION only */
|
||||
Function *proc;
|
||||
STKFRAME *args;
|
||||
} call;
|
||||
struct { /* for OTHER; tmp struct */
|
||||
eReg seg; /* segment */
|
||||
eReg regi; /* index mode */
|
||||
int16_t off; /* offset */
|
||||
} other;
|
||||
} idNode;
|
||||
IDENTTYPE() : idType(UNDEF)
|
||||
{}
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "StackFrame.h"
|
||||
/* PROCEDURE NODE */
|
||||
struct CALL_GRAPH;
|
||||
struct COND_EXPR;
|
||||
struct Expr;
|
||||
struct Disassembler;
|
||||
struct Function;
|
||||
struct CALL_GRAPH;
|
||||
@@ -74,8 +74,8 @@ struct FunctionType
|
||||
};
|
||||
struct Assignment
|
||||
{
|
||||
COND_EXPR *lhs;
|
||||
COND_EXPR *rhs;
|
||||
Expr *lhs;
|
||||
Expr *rhs;
|
||||
};
|
||||
struct JumpTable
|
||||
{
|
||||
@@ -184,9 +184,11 @@ public:
|
||||
|
||||
void displayCFG();
|
||||
void displayStats();
|
||||
void processHliCall(COND_EXPR *exp, iICODE picode);
|
||||
void processHliCall(Expr *exp, iICODE picode);
|
||||
|
||||
void preprocessReturnDU(LivenessSet &_liveOut);
|
||||
Expr * adjustActArgType(Expr *_exp, hlType forType);
|
||||
std::string writeCall(Function *tproc, STKFRAME &args, int *numLoc);
|
||||
protected:
|
||||
void extractJumpTableRange(ICODE& pIcode, STATE *pstate, JumpTable &table);
|
||||
bool followAllTableEntries(JumpTable &table, uint32_t cs, ICODE &pIcode, CALL_GRAPH *pcallGraph, STATE *pstate);
|
||||
|
||||
210
include/ast.h
210
include/ast.h
@@ -5,6 +5,7 @@
|
||||
* (C) Cristina Cifuentes
|
||||
*/
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
#include <list>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
@@ -34,37 +35,37 @@ typedef boost::iterator_range<iICODE> rICODE;
|
||||
#include "IdentType.h"
|
||||
|
||||
/* Expression data type */
|
||||
struct COND_EXPR
|
||||
struct Expr
|
||||
{
|
||||
public:
|
||||
condNodeType m_type; /* Conditional Expression Node Type */
|
||||
public:
|
||||
static bool insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR *&tree, int longIdx);
|
||||
static bool insertSubTreeReg(COND_EXPR *&tree, COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||
static bool insertSubTreeReg(AstIdent *&tree, COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||
static bool insertSubTreeLongReg(Expr *exp, Expr *&tree, int longIdx);
|
||||
static bool insertSubTreeReg(Expr *&tree, Expr *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||
static bool insertSubTreeReg(AstIdent *&tree, Expr *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||
public:
|
||||
virtual COND_EXPR *clone() const;
|
||||
void release();
|
||||
COND_EXPR(condNodeType t=UNKNOWN_OP) : m_type(t)
|
||||
|
||||
virtual Expr *clone() const=0; //!< Makes a deep copy of the given expression
|
||||
Expr(condNodeType t=UNKNOWN_OP) : m_type(t)
|
||||
{
|
||||
|
||||
}
|
||||
virtual ~COND_EXPR();
|
||||
virtual ~Expr();
|
||||
public:
|
||||
virtual std::string walkCondExpr (Function * pProc, int* numLoc) const=0;
|
||||
virtual COND_EXPR *inverse() const=0; // return new COND_EXPR that is invarse of this
|
||||
virtual Expr *inverse() const=0; // return new COND_EXPR that is invarse of this
|
||||
virtual bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId)=0;
|
||||
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym)=0;
|
||||
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx)=0;
|
||||
virtual hlType expType(Function *pproc) const;
|
||||
virtual Expr *insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym)=0;
|
||||
virtual Expr *insertSubTreeLongReg(Expr *_expr, int longIdx)=0;
|
||||
virtual hlType expType(Function *pproc) const=0;
|
||||
virtual int hlTypeSize(Function *pproc) const=0;
|
||||
virtual void performLongRemoval(eReg regi, LOCAL_ID *locId) {}
|
||||
virtual Expr * performLongRemoval(eReg regi, LOCAL_ID *locId) { return this; }
|
||||
};
|
||||
struct UnaryOperator : public COND_EXPR
|
||||
struct UnaryOperator : public Expr
|
||||
{
|
||||
UnaryOperator(condNodeType t=UNKNOWN_OP) : COND_EXPR(t),unaryExp(nullptr) {}
|
||||
COND_EXPR *unaryExp;
|
||||
virtual COND_EXPR *inverse() const
|
||||
UnaryOperator(condNodeType t=UNKNOWN_OP) : Expr(t),unaryExp(nullptr) {}
|
||||
Expr *unaryExp;
|
||||
virtual Expr *inverse() const
|
||||
{
|
||||
if (m_type == NEGATION) //TODO: memleak here
|
||||
{
|
||||
@@ -72,14 +73,14 @@ struct UnaryOperator : public COND_EXPR
|
||||
}
|
||||
return this->clone();
|
||||
}
|
||||
virtual COND_EXPR *clone() const
|
||||
virtual Expr *clone() const
|
||||
{
|
||||
UnaryOperator *newExp = new UnaryOperator(*this);
|
||||
newExp->unaryExp = unaryExp->clone();
|
||||
return newExp;
|
||||
}
|
||||
virtual bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs);
|
||||
static UnaryOperator *Create(condNodeType t, COND_EXPR *sub_expr)
|
||||
static UnaryOperator *Create(condNodeType t, Expr *sub_expr)
|
||||
{
|
||||
UnaryOperator *newExp = new UnaryOperator();
|
||||
newExp->m_type = t;
|
||||
@@ -94,22 +95,22 @@ struct UnaryOperator : public COND_EXPR
|
||||
public:
|
||||
int hlTypeSize(Function *pproc) const;
|
||||
virtual std::string walkCondExpr(Function *pProc, int *numLoc) const;
|
||||
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||
virtual Expr *insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||
virtual hlType expType(Function *pproc) const;
|
||||
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
|
||||
virtual Expr *insertSubTreeLongReg(Expr *_expr, int longIdx);
|
||||
};
|
||||
|
||||
struct BinaryOperator : public COND_EXPR
|
||||
struct BinaryOperator : public Expr
|
||||
{
|
||||
condOp m_op;
|
||||
COND_EXPR *m_lhs;
|
||||
COND_EXPR *m_rhs;
|
||||
BinaryOperator(condOp o) : COND_EXPR(BOOLEAN_OP)
|
||||
Expr *m_lhs;
|
||||
Expr *m_rhs;
|
||||
BinaryOperator(condOp o) : Expr(BOOLEAN_OP)
|
||||
{
|
||||
m_op = o;
|
||||
m_lhs=m_rhs=nullptr;
|
||||
}
|
||||
BinaryOperator(condOp o,COND_EXPR *l,COND_EXPR *r) : COND_EXPR(BOOLEAN_OP)
|
||||
BinaryOperator(condOp o,Expr *l,Expr *r) : Expr(BOOLEAN_OP)
|
||||
{
|
||||
m_op = o;
|
||||
m_lhs=l;
|
||||
@@ -121,51 +122,51 @@ struct BinaryOperator : public COND_EXPR
|
||||
delete m_lhs;
|
||||
delete m_rhs;
|
||||
}
|
||||
static BinaryOperator *Create(condOp o,COND_EXPR *l,COND_EXPR *r)
|
||||
static BinaryOperator *Create(condOp o,Expr *l,Expr *r)
|
||||
{
|
||||
BinaryOperator *res = new BinaryOperator(o);
|
||||
res->m_lhs = l;
|
||||
res->m_rhs = r;
|
||||
return res;
|
||||
}
|
||||
static BinaryOperator *LogicAnd(COND_EXPR *l,COND_EXPR *r)
|
||||
static BinaryOperator *LogicAnd(Expr *l,Expr *r)
|
||||
{
|
||||
return new BinaryOperator(DBL_AND,l,r);
|
||||
}
|
||||
static BinaryOperator *And(COND_EXPR *l,COND_EXPR *r)
|
||||
static BinaryOperator *And(Expr *l,Expr *r)
|
||||
{
|
||||
return new BinaryOperator(AND,l,r);
|
||||
}
|
||||
static BinaryOperator *Or(COND_EXPR *l,COND_EXPR *r)
|
||||
static BinaryOperator *Or(Expr *l,Expr *r)
|
||||
{
|
||||
return new BinaryOperator(OR,l,r);
|
||||
}
|
||||
static BinaryOperator *LogicOr(COND_EXPR *l,COND_EXPR *r)
|
||||
static BinaryOperator *LogicOr(Expr *l,Expr *r)
|
||||
{
|
||||
return new BinaryOperator(DBL_OR,l,r);
|
||||
}
|
||||
static BinaryOperator *CreateAdd(COND_EXPR *l,COND_EXPR *r);
|
||||
static BinaryOperator *CreateAdd(Expr *l,Expr *r);
|
||||
void changeBoolOp(condOp newOp);
|
||||
virtual COND_EXPR *inverse() const;
|
||||
virtual COND_EXPR *clone() const;
|
||||
virtual Expr *inverse() const;
|
||||
virtual Expr *clone() const;
|
||||
virtual bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locs);
|
||||
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
|
||||
const COND_EXPR *lhs() const
|
||||
virtual Expr *insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||
virtual Expr *insertSubTreeLongReg(Expr *_expr, int longIdx);
|
||||
const Expr *lhs() const
|
||||
{
|
||||
return const_cast<const COND_EXPR *>(const_cast<BinaryOperator *>(this)->lhs());
|
||||
return const_cast<const Expr *>(const_cast<BinaryOperator *>(this)->lhs());
|
||||
}
|
||||
const COND_EXPR *rhs() const
|
||||
const Expr *rhs() const
|
||||
{
|
||||
return const_cast<const COND_EXPR *>(const_cast<BinaryOperator *>(this)->rhs());
|
||||
return const_cast<const Expr *>(const_cast<BinaryOperator *>(this)->rhs());
|
||||
}
|
||||
|
||||
COND_EXPR *lhs()
|
||||
Expr *lhs()
|
||||
{
|
||||
assert(m_type==BOOLEAN_OP);
|
||||
return m_lhs;
|
||||
}
|
||||
COND_EXPR *rhs()
|
||||
Expr *rhs()
|
||||
{
|
||||
assert(m_type==BOOLEAN_OP);
|
||||
return m_rhs;
|
||||
@@ -182,31 +183,27 @@ struct AstIdent : public UnaryOperator
|
||||
{
|
||||
AstIdent() : UnaryOperator(IDENTIFIER)
|
||||
{
|
||||
memset(&ident,0,sizeof(ident));
|
||||
}
|
||||
virtual COND_EXPR *clone() const
|
||||
IDENTTYPE ident; /* for IDENTIFIER */
|
||||
static AstIdent * Loc(int off, LOCAL_ID *localId);
|
||||
static AstIdent * LongIdx(int idx);
|
||||
static AstIdent * String(uint32_t idx);
|
||||
static AstIdent * Other(eReg seg, eReg regi, int16_t off);
|
||||
static AstIdent * Param(int off, const STKFRAME *argSymtab);
|
||||
static AstIdent * Long(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, LLInst &atOffset);
|
||||
static AstIdent * idID(const ID *retVal, LOCAL_ID *locsym, iICODE ix_);
|
||||
static Expr * id(const LLInst &ll_insn, opLoc sd, Function *pProc, iICODE ix_, ICODE &duIcode, operDu du);
|
||||
|
||||
virtual Expr *clone() const
|
||||
{
|
||||
return new AstIdent(*this);
|
||||
}
|
||||
IDENTTYPE ident; /* for IDENTIFIER */
|
||||
static AstIdent * RegIdx(int idx, regType reg_type);
|
||||
static AstIdent * Kte(uint32_t kte, uint8_t size);
|
||||
static AstIdent * Loc(int off, LOCAL_ID *localId);
|
||||
static AstIdent * Reg(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym);
|
||||
static AstIdent * LongIdx(int idx);
|
||||
static AstIdent * Other(eReg seg, eReg regi, int16_t off);
|
||||
static AstIdent * idParam(int off, const STKFRAME *argSymtab);
|
||||
static AstIdent * idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, LLInst &atOffset);
|
||||
static AstIdent * idFunc(Function *pproc, STKFRAME *args);
|
||||
static AstIdent * idID(const ID *retVal, LOCAL_ID *locsym, iICODE ix_);
|
||||
static COND_EXPR * id(const LLInst &ll_insn, opLoc sd, Function *pProc, iICODE ix_, ICODE &duIcode, operDu du);
|
||||
|
||||
virtual int hlTypeSize(Function *pproc) const;
|
||||
virtual hlType expType(Function *pproc) const;
|
||||
virtual void performLongRemoval(eReg regi, LOCAL_ID *locId);
|
||||
virtual Expr * performLongRemoval(eReg regi, LOCAL_ID *locId);
|
||||
virtual std::string walkCondExpr(Function *pProc, int *numLoc) const;
|
||||
virtual COND_EXPR *insertSubTreeReg(COND_EXPR *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||
virtual COND_EXPR *insertSubTreeLongReg(COND_EXPR *_expr, int longIdx);
|
||||
virtual Expr *insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||
virtual Expr *insertSubTreeLongReg(Expr *_expr, int longIdx);
|
||||
virtual bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId);
|
||||
protected:
|
||||
eReg otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl);
|
||||
@@ -214,7 +211,94 @@ protected:
|
||||
};
|
||||
struct GlobalVariable : public AstIdent
|
||||
{
|
||||
static AstIdent *Create(int16_t segValue, int16_t off);
|
||||
bool valid;
|
||||
int globIdx;
|
||||
virtual Expr *clone() const
|
||||
{
|
||||
return new GlobalVariable(*this);
|
||||
}
|
||||
GlobalVariable(int16_t segValue, int16_t off);
|
||||
std::string walkCondExpr(Function *pProc, int *numLoc) const;
|
||||
int hlTypeSize(Function *pproc) const;
|
||||
hlType expType(Function *pproc) const;
|
||||
};
|
||||
struct GlobalVariableIdx : public AstIdent
|
||||
{
|
||||
bool valid;
|
||||
int idxGlbIdx; /* idx into localId, GLOB_VAR_IDX */
|
||||
|
||||
virtual Expr *clone() const
|
||||
{
|
||||
return new GlobalVariableIdx(*this);
|
||||
}
|
||||
GlobalVariableIdx(int16_t segValue, int16_t off, uint8_t regi, const LOCAL_ID *locSym);
|
||||
std::string walkCondExpr(Function *pProc, int *numLoc) const;
|
||||
int hlTypeSize(Function *pproc) const;
|
||||
hlType expType(Function *pproc) const;
|
||||
};
|
||||
struct Constant : public AstIdent
|
||||
{
|
||||
struct _kte
|
||||
{ /* for CONSTANT only */
|
||||
uint32_t kte; /* value of the constant */
|
||||
uint8_t size; /* #bytes size constant */
|
||||
} kte;
|
||||
|
||||
Constant(uint32_t _kte, uint8_t size)
|
||||
{
|
||||
ident.idType = CONSTANT;
|
||||
kte.kte = _kte;
|
||||
kte.size = size;
|
||||
}
|
||||
virtual Expr *clone() const
|
||||
{
|
||||
return new Constant(*this);
|
||||
}
|
||||
std::string walkCondExpr(Function *pProc, int *numLoc) const;
|
||||
int hlTypeSize(Function *pproc) const;
|
||||
hlType expType(Function *pproc) const;
|
||||
};
|
||||
struct FuncNode : public AstIdent
|
||||
{
|
||||
struct _call { /* for FUNCTION only */
|
||||
Function *proc;
|
||||
STKFRAME *args;
|
||||
} call;
|
||||
|
||||
FuncNode(Function *pproc, STKFRAME *args)
|
||||
{
|
||||
call.proc = pproc;
|
||||
call.args = args;
|
||||
}
|
||||
virtual Expr *clone() const
|
||||
{
|
||||
return new FuncNode(*this);
|
||||
}
|
||||
std::string walkCondExpr(Function *pProc, int *numLoc) const;
|
||||
int hlTypeSize(Function *pproc) const;
|
||||
hlType expType(Function *pproc) const;
|
||||
};
|
||||
struct RegisterNode : public AstIdent
|
||||
{
|
||||
regType regiType; /* for REGISTER only */
|
||||
int regiIdx; /* index into localId, REGISTER */
|
||||
|
||||
virtual Expr *insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym);
|
||||
|
||||
RegisterNode(int idx, regType reg_type)
|
||||
{
|
||||
ident.type(REGISTER);
|
||||
regiType = reg_type;
|
||||
regiIdx = idx;
|
||||
}
|
||||
|
||||
RegisterNode(eReg regi, uint32_t icodeFlg, LOCAL_ID *locsym);
|
||||
virtual Expr *clone() const
|
||||
{
|
||||
return new RegisterNode(*this);
|
||||
}
|
||||
std::string walkCondExpr(Function *pProc, int *numLoc) const;
|
||||
int hlTypeSize(Function *) const;
|
||||
hlType expType(Function *pproc) const;
|
||||
bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId);
|
||||
};
|
||||
struct Constant : public COND_EXPR
|
||||
{};
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
int current_indent;
|
||||
};
|
||||
|
||||
|
||||
extern bundle cCode;
|
||||
#define lineSize 360 /* 3 lines in the mean time */
|
||||
|
||||
//void newBundle (bundle *procCode);
|
||||
|
||||
@@ -37,9 +37,6 @@ public:
|
||||
bool insertCallGraph(Function *caller, ilFunction callee);
|
||||
void insertArc(ilFunction newProc);
|
||||
};
|
||||
//#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 bundle cCode; /* Output C procedure's declaration and code */
|
||||
|
||||
@@ -110,11 +107,11 @@ void udm(void); /* udm.c */
|
||||
void freeCFG(BB * cfg); /* 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 */
|
||||
extern 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 */
|
||||
extern int strSize (const uint8_t *, char); /* parser.c */
|
||||
//void disassem(int pass, Function * pProc); /* disassem.c */
|
||||
void interactDis(Function *, int initIC); /* disassem.c */
|
||||
bool JmpInst(llIcode opcode); /* idioms.c */
|
||||
@@ -126,10 +123,8 @@ bool LibCheck(Function &p); /* chklib.c */
|
||||
|
||||
/* Exported functions from procs.c */
|
||||
boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction);
|
||||
void adjustActArgType (COND_EXPR *, hlType, Function *);
|
||||
|
||||
/* Exported functions from hlicode.c */
|
||||
std::string writeCall (Function *, STKFRAME &, Function *, int *);
|
||||
char *writeJcond (const HLTYPE &, Function *, int *);
|
||||
char *writeJcondInv (HLTYPE, Function *, int *);
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
/*****************************************************************************
|
||||
/*
|
||||
|
||||
****************************************************************************
|
||||
* Error codes
|
||||
* (C) Cristina Cifuentes
|
||||
****************************************************************************/
|
||||
***************************************************************************
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/* These definitions refer to errorMessage in error.c */
|
||||
|
||||
@@ -65,6 +65,8 @@ struct LivenessSet : public std::bitset<32>
|
||||
{
|
||||
return test(r-rAX);
|
||||
}
|
||||
public:
|
||||
LivenessSet &clrReg(int r);
|
||||
private:
|
||||
void postProcessCompositeRegs();
|
||||
};
|
||||
@@ -83,15 +85,16 @@ struct DU
|
||||
#define MAX_REGS_DEF 4 /* 2 regs def'd for long-reg vars */
|
||||
|
||||
|
||||
struct COND_EXPR;
|
||||
struct Expr;
|
||||
struct AstIdent;
|
||||
struct UnaryOperator;
|
||||
struct HlTypeSupport
|
||||
{
|
||||
//hlIcode opcode; /* hlIcode opcode */
|
||||
virtual bool removeRegFromLong(eReg regi, LOCAL_ID *locId)=0;
|
||||
virtual std::string writeOut(Function *pProc, int *numLoc) const=0;
|
||||
protected:
|
||||
void performLongRemoval (eReg regi, LOCAL_ID *locId, COND_EXPR *tree);
|
||||
Expr * performLongRemoval (eReg regi, LOCAL_ID *locId, Expr *tree);
|
||||
};
|
||||
|
||||
struct CallType : public HlTypeSupport
|
||||
@@ -100,9 +103,9 @@ struct CallType : public HlTypeSupport
|
||||
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);
|
||||
virtual COND_EXPR * toId();
|
||||
bool newStkArg(Expr *exp, llIcode opcode, Function *pproc);
|
||||
void placeStkArg(Expr *exp, int pos);
|
||||
virtual Expr * toAst();
|
||||
public:
|
||||
bool removeRegFromLong(eReg /*regi*/, LOCAL_ID */*locId*/)
|
||||
{
|
||||
@@ -114,20 +117,24 @@ public:
|
||||
struct AssignType : public HlTypeSupport
|
||||
{
|
||||
/* for HLI_ASSIGN */
|
||||
COND_EXPR *lhs;
|
||||
COND_EXPR *rhs;
|
||||
AssignType() : lhs(0),rhs(0) {}
|
||||
protected:
|
||||
public:
|
||||
Expr *m_lhs;
|
||||
Expr *rhs;
|
||||
AssignType() {}
|
||||
Expr *lhs() const {return m_lhs;}
|
||||
void lhs(Expr *l);
|
||||
bool removeRegFromLong(eReg regi, LOCAL_ID *locId);
|
||||
std::string writeOut(Function *pProc, int *numLoc) const;
|
||||
};
|
||||
struct ExpType : public HlTypeSupport
|
||||
{
|
||||
/* for HLI_JCOND, HLI_RET, HLI_PUSH, HLI_POP*/
|
||||
COND_EXPR *v;
|
||||
Expr *v;
|
||||
ExpType() : v(0) {}
|
||||
bool removeRegFromLong(eReg regi, LOCAL_ID *locId)
|
||||
{
|
||||
performLongRemoval(regi,locId,v);
|
||||
v=performLongRemoval(regi,locId,v);
|
||||
return true;
|
||||
}
|
||||
std::string writeOut(Function *pProc, int *numLoc) const;
|
||||
@@ -147,15 +154,21 @@ public:
|
||||
return const_cast<const HlTypeSupport *>(const_cast<HLTYPE*>(this)->get());
|
||||
}
|
||||
|
||||
void expr(COND_EXPR *e)
|
||||
void expr(Expr *e)
|
||||
{
|
||||
assert(e);
|
||||
exp.v=e;
|
||||
}
|
||||
void replaceExpr(COND_EXPR *e);
|
||||
COND_EXPR * expr() { return exp.v;}
|
||||
const COND_EXPR * expr() const { return exp.v;}
|
||||
void set(hlIcode i,COND_EXPR *e)
|
||||
Expr *getMyExpr()
|
||||
{
|
||||
if(opcode==HLI_CALL)
|
||||
return call.toAst();
|
||||
return expr();
|
||||
}
|
||||
void replaceExpr(Expr *e);
|
||||
Expr * expr() { return exp.v;}
|
||||
const Expr * expr() const { return exp.v;}
|
||||
void set(hlIcode i,Expr *e)
|
||||
{
|
||||
if(i!=HLI_RET)
|
||||
assert(e);
|
||||
@@ -163,7 +176,7 @@ public:
|
||||
opcode=i;
|
||||
exp.v=e;
|
||||
}
|
||||
void set(COND_EXPR *l,COND_EXPR *r);
|
||||
void set(Expr *l,Expr *r);
|
||||
void setCall(Function *proc);
|
||||
HLTYPE(hlIcode op=HLI_INVALID) : opcode(op)
|
||||
{}
|
||||
@@ -179,7 +192,7 @@ public:
|
||||
}
|
||||
public:
|
||||
std::string write1HlIcode(Function *pProc, int *numLoc) const;
|
||||
void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs);
|
||||
void setAsgn(Expr *lhs, Expr *rhs);
|
||||
} ;
|
||||
/* LOW_LEVEL icode operand record */
|
||||
struct LLOperand
|
||||
@@ -201,6 +214,16 @@ struct LLOperand
|
||||
proc.proc=0;
|
||||
proc.cb=0;
|
||||
}
|
||||
bool operator==(const LLOperand &with) const
|
||||
{
|
||||
return (seg==with.seg) &&
|
||||
(segOver==with.segOver) &&
|
||||
(segValue==with.segValue) &&
|
||||
(regi == with.regi) &&
|
||||
(off == with.off) &&
|
||||
(opz==with.opz) &&
|
||||
(proc.proc==with.proc.proc);
|
||||
}
|
||||
int64_t getImm2() const {return opz;}
|
||||
void SetImmediateOp(uint32_t dw)
|
||||
{
|
||||
@@ -219,8 +242,6 @@ struct LLOperand
|
||||
static LLOperand CreateReg2(unsigned Val)
|
||||
{
|
||||
LLOperand Op;
|
||||
// Op.Kind = kRegister;
|
||||
// Op.RegVal = Reg;
|
||||
Op.regi = (eReg)Val;
|
||||
return Op;
|
||||
}
|
||||
@@ -229,20 +250,15 @@ struct LLOperand
|
||||
struct LLInst : public llvm::MCInst //: public llvm::ilist_node<LLInst>
|
||||
{
|
||||
protected:
|
||||
uint32_t flg; /* icode flags */
|
||||
// LLOperand &get(int idx)
|
||||
// {
|
||||
// assert(idx<size());
|
||||
// return getOperand(idx);
|
||||
// }
|
||||
LLOperand m_src; /* source operand */
|
||||
uint32_t flg; /* icode flags */
|
||||
LLOperand m_src; /* source operand */
|
||||
public:
|
||||
int codeIdx; /* Index into cCode.code */
|
||||
uint8_t numBytes; /* Number of bytes this instr */
|
||||
uint32_t label; /* offset in image (20-bit adr) */
|
||||
LLOperand dst; /* destination operand */
|
||||
DU flagDU; /* def/use of flags */
|
||||
int caseEntry;
|
||||
int codeIdx; /* Index into cCode.code */
|
||||
uint8_t numBytes; /* Number of bytes this instr */
|
||||
uint32_t label; /* offset in image (20-bit adr) */
|
||||
LLOperand dst; /* destination operand */
|
||||
DU flagDU; /* def/use of flags */
|
||||
int caseEntry;
|
||||
std::vector<uint32_t> caseTbl2;
|
||||
int hllLabNum; /* label # for hll codegen */
|
||||
bool conditionalJump()
|
||||
@@ -260,9 +276,7 @@ public:
|
||||
flg &= ~flag;
|
||||
}
|
||||
uint32_t getFlag() const {return flg;}
|
||||
//llIcode getOpcode() const { return opcode; }
|
||||
|
||||
uint32_t GetLlLabel() const { return label;}
|
||||
uint32_t GetLlLabel() const { return label;}
|
||||
|
||||
void SetImmediateOp(uint32_t dw) {m_src.SetImmediateOp(dw);}
|
||||
|
||||
@@ -308,7 +322,6 @@ public:
|
||||
|
||||
void flops(std::ostringstream &out);
|
||||
bool isJmpInst();
|
||||
//HLTYPE toHighLevel(COND_EXPR *lhs, COND_EXPR *rhs, Function *func);
|
||||
HLTYPE createCall();
|
||||
LLInst(ICODE *container) : flg(0),codeIdx(0),numBytes(0),m_link(container)
|
||||
{
|
||||
@@ -465,13 +478,13 @@ public:
|
||||
condId idType(opLoc sd);
|
||||
// HLL setting functions
|
||||
// set this icode to be an assign
|
||||
void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs)
|
||||
void setAsgn(Expr *lhs, Expr *rhs)
|
||||
{
|
||||
type=HIGH_LEVEL;
|
||||
hlU()->setAsgn(lhs,rhs);
|
||||
}
|
||||
void setUnary(hlIcode op, COND_EXPR *_exp);
|
||||
void setJCond(COND_EXPR *cexp);
|
||||
void setUnary(hlIcode op, Expr *_exp);
|
||||
void setJCond(Expr *cexp);
|
||||
|
||||
void emitGotoLabel(int indLevel);
|
||||
void copyDU(const ICODE &duIcode, operDu _du, operDu duDu);
|
||||
@@ -480,7 +493,7 @@ public:
|
||||
public:
|
||||
bool removeDefRegi(eReg regi, int thisDefIdx, LOCAL_ID *locId);
|
||||
void checkHlCall();
|
||||
bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc)
|
||||
bool newStkArg(Expr *exp, llIcode opcode, Function *pproc)
|
||||
{
|
||||
return hlU()->call.newStkArg(exp,opcode,pproc);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
/* Type definition */
|
||||
// this array has to stay in-order of addition i.e. not std::set<iICODE,std::less<iICODE> >
|
||||
// TODO: why ?
|
||||
struct COND_EXPR;
|
||||
struct Expr;
|
||||
struct AstIdent;
|
||||
struct ICODE;
|
||||
struct LLInst;
|
||||
@@ -132,7 +132,7 @@ public:
|
||||
size_t csym() const {return id_arr.size();}
|
||||
void newRegArg(iICODE picode, iICODE ticode) const;
|
||||
void processTargetIcode(iICODE picode, int &numHlIcodes, iICODE ticode, bool isLong) const;
|
||||
void forwardSubs(COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode, iICODE ticode, int &numHlIcodes) const;
|
||||
void forwardSubs(Expr *lhs, Expr *rhs, iICODE picode, iICODE ticode, int &numHlIcodes) const;
|
||||
AstIdent *createId(const ID *retVal, iICODE ix_);
|
||||
};
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@ struct STATE
|
||||
memset(r,0,sizeof(int16_t)*INDEX_BX_SI); //TODO: move this to machine_x86
|
||||
memset(f,0,sizeof(uint8_t)*INDEX_BX_SI);
|
||||
}
|
||||
void setMemoryByte(uint32_t addr,uint8_t val)
|
||||
{
|
||||
//TODO: make this into a full scale value tracking class !
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <stdint.h>
|
||||
#include "Enums.h"
|
||||
#include "types.h"
|
||||
struct COND_EXPR;
|
||||
struct Expr;
|
||||
struct AstIdent;
|
||||
struct TypeContainer;
|
||||
/* * * * * * * * * * * * * * * * * */
|
||||
@@ -36,7 +36,7 @@ struct SYM : public SymbolCommon
|
||||
struct STKSYM : public SymbolCommon
|
||||
{
|
||||
typedef int16_t tLabel;
|
||||
COND_EXPR *actual; /* Expression tree of actual parameter */
|
||||
Expr *actual; /* Expression tree of actual parameter */
|
||||
AstIdent *regs; /* For register arguments only */
|
||||
tLabel label; /* Immediate off from BP (+:args, -:params) */
|
||||
uint8_t regOff; /* Offset is a register (e.g. SI, DI) */
|
||||
|
||||
Reference in New Issue
Block a user