lots of small things
This commit is contained in:
@@ -1,22 +1,24 @@
|
||||
#pragma once
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <bitset>
|
||||
#include <string>
|
||||
#include <llvm/ADT/ilist.h>
|
||||
#include <llvm/ADT/ilist_node.h>
|
||||
#include "types.h"
|
||||
#include "graph.h"
|
||||
#include "icode.h"
|
||||
//#include "icode.h"
|
||||
/* Basic block (BB) node definition */
|
||||
struct Function;
|
||||
class CIcodeRec;
|
||||
struct BB;
|
||||
struct interval;
|
||||
struct ICODE;
|
||||
|
||||
typedef std::list<ICODE>::iterator iICODE;
|
||||
typedef std::list<ICODE>::reverse_iterator riICODE;
|
||||
typedef union
|
||||
{
|
||||
dword ip; /* Out edge icode address */
|
||||
uint32_t ip; /* Out edge icode address */
|
||||
BB * BBptr; /* Out edge pointer to next BB */
|
||||
interval *intPtr; /* Out edge ptr to next interval*/
|
||||
} TYPEADR_TYPE;
|
||||
@@ -36,36 +38,36 @@ private:
|
||||
|
||||
}
|
||||
//friend class SymbolTableListTraits<BB, Function>;
|
||||
//Int numInEdges; /* Number of in edges */
|
||||
Int start; /* First instruction offset */
|
||||
Int length; /* No. of instructions this BB */
|
||||
//int numInEdges; /* Number of in edges */
|
||||
int start; /* First instruction offset */
|
||||
int length; /* No. of instructions this BB */
|
||||
|
||||
public:
|
||||
Int begin();
|
||||
int begin();
|
||||
iICODE begin2();
|
||||
iICODE end2();
|
||||
Int end();
|
||||
Int rbegin();
|
||||
Int rend();
|
||||
int end();
|
||||
int rbegin();
|
||||
int rend();
|
||||
riICODE rbegin2();
|
||||
riICODE rend2();
|
||||
ICODE &front();
|
||||
ICODE &back();
|
||||
size_t size();
|
||||
byte nodeType; /* Type of node */
|
||||
uint8_t nodeType; /* Type of node */
|
||||
int traversed; /* Boolean: traversed yet? */
|
||||
Int numHlIcodes; /* No. of high-level icodes */
|
||||
flags32 flg; /* BB flags */
|
||||
int numHlIcodes; /* No. of high-level icodes */
|
||||
uint32_t flg; /* BB flags */
|
||||
|
||||
/* In edges and out edges */
|
||||
std::vector<BB *> inEdges; // does not own held pointers
|
||||
|
||||
//Int numOutEdges; /* Number of out edges */
|
||||
//int numOutEdges; /* Number of out edges */
|
||||
std::vector<TYPEADR_TYPE> edges;/* Array of ptrs. to out edges */
|
||||
|
||||
/* For interval construction */
|
||||
Int beenOnH; /* #times been on header list H */
|
||||
Int inEdgeCount; /* #inEdges (to find intervals) */
|
||||
int beenOnH; /* #times been on header list H */
|
||||
int inEdgeCount; /* #inEdges (to find intervals) */
|
||||
BB * reachingInt; /* Reaching interval header */
|
||||
interval *inInterval; /* Node's interval */
|
||||
|
||||
@@ -81,35 +83,35 @@ public:
|
||||
std::bitset<32> liveOut; /* LiveOut(b) */
|
||||
|
||||
/* For structuring analysis */
|
||||
Int dfsFirstNum; /* DFS #: first visit of node */
|
||||
Int dfsLastNum; /* DFS #: last visit of node */
|
||||
Int immedDom; /* Immediate dominator (dfsLast
|
||||
int dfsFirstNum; /* DFS #: first visit of node */
|
||||
int dfsLastNum; /* DFS #: last visit of node */
|
||||
int immedDom; /* Immediate dominator (dfsLast
|
||||
* index) */
|
||||
Int ifFollow; /* node that ends the if */
|
||||
Int loopType; /* Type of loop (if any) */
|
||||
Int latchNode; /* latching node of the loop */
|
||||
Int numBackEdges; /* # of back edges */
|
||||
Int loopHead; /* most nested loop head to which
|
||||
int ifFollow; /* node that ends the if */
|
||||
int loopType; /* Type of loop (if any) */
|
||||
int latchNode; /* latching node of the loop */
|
||||
int numBackEdges; /* # of back edges */
|
||||
int loopHead; /* most nested loop head to which
|
||||
* thcis node belongs (dfsLast) */
|
||||
Int loopFollow; /* node that follows the loop */
|
||||
Int caseHead; /* most nested case to which this
|
||||
int loopFollow; /* node that follows the loop */
|
||||
int caseHead; /* most nested case to which this
|
||||
node belongs (dfsLast) */
|
||||
Int caseTail; /* tail node for the case */
|
||||
int caseTail; /* tail node for the case */
|
||||
|
||||
Int index; /* Index, used in several ways */
|
||||
int index; /* Index, used in several ways */
|
||||
static BB * Create(void *ctx=0,const std::string &s="",Function *parent=0,BB *insertBefore=0);
|
||||
static BB * Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function * parent);
|
||||
void writeCode(Int indLevel, Function *pProc, Int *numLoc, Int latchNode, Int ifFollow);
|
||||
static BB * Create(int start, int ip, uint8_t nodeType, int numOutEdges, Function * parent);
|
||||
void writeCode(int indLevel, Function *pProc, int *numLoc, int latchNode, int ifFollow);
|
||||
void mergeFallThrough(CIcodeRec &Icode);
|
||||
void dfsNumbering(std::vector<BB *> &dfsLast, Int *first, Int *last);
|
||||
void dfsNumbering(std::vector<BB *> &dfsLast, int *first, int *last);
|
||||
void displayDfs();
|
||||
void display();
|
||||
/// getParent - Return the enclosing method, or null if none
|
||||
///
|
||||
const Function *getParent() const { return Parent; }
|
||||
Function *getParent() { return Parent; }
|
||||
void writeBB(Int lev, Function *pProc, Int *numLoc);
|
||||
BB *rmJMP(Int marker, BB *pBB);
|
||||
void writeBB(int lev, Function *pProc, int *numLoc);
|
||||
BB *rmJMP(int marker, BB *pBB);
|
||||
void genDU1();
|
||||
private:
|
||||
Function *Parent;
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
#pragma once
|
||||
/* Machine registers */
|
||||
enum eReg
|
||||
{
|
||||
rAX = 1, /* These are numbered relative to real 8086 */
|
||||
rCX = 2,
|
||||
rDX = 3,
|
||||
rBX = 4,
|
||||
rSP = 5,
|
||||
rBP = 6,
|
||||
rSI = 7,
|
||||
rDI = 8,
|
||||
|
||||
rES = 9,
|
||||
rCS = 10,
|
||||
rSS = 11,
|
||||
rDS = 12,
|
||||
|
||||
rAL = 13,
|
||||
rCL = 14,
|
||||
rDL = 15,
|
||||
rBL = 16,
|
||||
rAH = 17,
|
||||
rCH = 18,
|
||||
rDH = 19,
|
||||
rBH = 20,
|
||||
|
||||
rTMP= 21, /* temp register for DIV/IDIV/MOD */
|
||||
INDEXBASE = 22 /* Indexed modes go from INDEXBASE to INDEXBASE+7 */
|
||||
};
|
||||
|
||||
/* Register types */
|
||||
enum regType
|
||||
{
|
||||
@@ -75,6 +105,35 @@ enum hlFirst
|
||||
HIGH_FIRST, /* High value is first */
|
||||
LOW_FIRST /* Low value is first */
|
||||
};
|
||||
/* HIGH_LEVEL icodes opcodes */
|
||||
enum hlIcode
|
||||
{
|
||||
HLI_ASSIGN, /* := */
|
||||
HLI_CALL, /* Call procedure */
|
||||
HLI_JCOND, /* Conditional jump */
|
||||
HLI_RET, /* Return from procedure */
|
||||
/* pseudo high-level icodes */
|
||||
HLI_POP, /* Pop expression */
|
||||
HLI_PUSH /* Push expression */
|
||||
} ;
|
||||
/* Type definitions used in the decompiled program */
|
||||
enum hlType
|
||||
{
|
||||
TYPE_UNKNOWN = 0, /* unknown so far */
|
||||
TYPE_BYTE_SIGN, /* signed byte (8 bits) */
|
||||
TYPE_BYTE_UNSIGN, /* unsigned byte */
|
||||
TYPE_WORD_SIGN, /* signed word (16 bits) */
|
||||
TYPE_WORD_UNSIGN, /* unsigned word (16 bits) */
|
||||
TYPE_LONG_SIGN, /* signed long (32 bits) */
|
||||
TYPE_LONG_UNSIGN, /* unsigned long (32 bits) */
|
||||
TYPE_RECORD, /* record structure */
|
||||
TYPE_PTR, /* pointer (32 bit ptr) */
|
||||
TYPE_STR, /* string */
|
||||
TYPE_CONST, /* constant (any type) */
|
||||
TYPE_FLOAT, /* floating point */
|
||||
TYPE_DOUBLE /* double precision float */
|
||||
};
|
||||
|
||||
/* Operand is defined, used or both flag */
|
||||
enum operDu
|
||||
{
|
||||
@@ -83,3 +142,4 @@ enum operDu
|
||||
USE_DEF, /* Operand is used and defined */
|
||||
NONE /* No operation is required on this operand */
|
||||
};
|
||||
|
||||
|
||||
@@ -6,26 +6,26 @@ struct IDENTTYPE
|
||||
condId idType;
|
||||
regType regiType; /* for REGISTER only */
|
||||
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 */
|
||||
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 */
|
||||
dword kte; /* value of the constant */
|
||||
byte size; /* #bytes size constant */
|
||||
uint32_t kte; /* value of the constant */
|
||||
uint8_t size; /* #bytes size constant */
|
||||
} kte;
|
||||
dword strIdx; /* idx into image, for STRING */
|
||||
Int longIdx; /* idx into LOCAL_ID table, LONG_VAR*/
|
||||
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 */
|
||||
byte seg; /* segment */
|
||||
byte regi; /* index mode */
|
||||
int16 off; /* offset */
|
||||
uint8_t seg; /* segment */
|
||||
uint8_t regi; /* index mode */
|
||||
int16_t off; /* offset */
|
||||
} other;
|
||||
} idNode;
|
||||
};
|
||||
|
||||
@@ -3,16 +3,18 @@
|
||||
#include <llvm/ADT/ilist_node.h>
|
||||
#include <bitset>
|
||||
#include "BasicBlock.h"
|
||||
#include "types.h"
|
||||
#include "ast.h"
|
||||
#include "icode.h"
|
||||
#include "locident.h"
|
||||
#include "error.h"
|
||||
#include "graph.h"
|
||||
#include "bundle.h"
|
||||
#include "state.h"
|
||||
#include "icode.h"
|
||||
//#include "types.h"
|
||||
//#include "ast.h"
|
||||
//#include "error.h"
|
||||
//#include "graph.h"
|
||||
//#include "bundle.h"
|
||||
#include "StackFrame.h"
|
||||
/* PROCEDURE NODE */
|
||||
struct CALL_GRAPH;
|
||||
struct COND_EXPR;
|
||||
namespace llvm
|
||||
{
|
||||
// Traits for intrusive list of basic blocks...
|
||||
@@ -36,6 +38,32 @@ private:
|
||||
mutable ilist_half_node<BB> Sentinel;
|
||||
};
|
||||
}
|
||||
/* Procedure FLAGS */
|
||||
enum PROC_FLAGS
|
||||
{
|
||||
PROC_BADINST=0x00000100,/* Proc contains invalid or 386 instruction */
|
||||
PROC_IJMP =0x00000200,/* Proc incomplete due to indirect jmp */
|
||||
PROC_ICALL =0x00000400, /* Proc incomplete due to indirect call */
|
||||
PROC_HLL =0x00001000, /* Proc is likely to be from a HLL */
|
||||
CALL_PASCAL =0x00002000, /* Proc uses Pascal calling convention */
|
||||
CALL_C =0x00004000, /* Proc uses C calling convention */
|
||||
CALL_UNKNOWN=0x00008000, /* Proc uses unknown calling convention */
|
||||
PROC_NEAR =0x00010000, /* Proc exits with near return */
|
||||
PROC_FAR =0x00020000, /* Proc exits with far return */
|
||||
GRAPH_IRRED =0x00100000, /* Proc generates an irreducible graph */
|
||||
SI_REGVAR =0x00200000, /* SI is used as a stack variable */
|
||||
DI_REGVAR =0x00400000, /* DI is used as a stack variable */
|
||||
PROC_IS_FUNC=0x00800000, /* Proc is a function */
|
||||
REG_ARGS =0x01000000, /* Proc has registers as arguments */
|
||||
PROC_VARARG =0x02000000, /* Proc has variable arguments */
|
||||
PROC_OUTPUT =0x04000000, /* C for this proc has been output */
|
||||
PROC_RUNTIME=0x08000000, /* Proc is part of the runtime support */
|
||||
PROC_ISLIB =0x10000000, /* Proc is a library function */
|
||||
PROC_ASM =0x20000000, /* Proc is an intrinsic assembler routine */
|
||||
PROC_IS_HLL =0x40000000 /* Proc has HLL prolog code */
|
||||
#define CALL_MASK 0xFFFF9FFF /* Masks off CALL_C and CALL_PASCAL */
|
||||
};
|
||||
|
||||
struct FunctionType
|
||||
{
|
||||
bool m_vararg;
|
||||
@@ -57,24 +85,24 @@ private:
|
||||
BasicBlockListType BasicBlocks; ///< The basic blocks
|
||||
|
||||
public:
|
||||
dword procEntry; /* label number */
|
||||
uint32_t procEntry; /* label number */
|
||||
std::string name; /* Meaningful name for this proc */
|
||||
STATE state; /* Entry state */
|
||||
Int depth; /* Depth at which we found it - for printing */
|
||||
flags32 flg; /* Combination of Icode & Proc flags */
|
||||
int16 cbParam; /* Probable no. of bytes of parameters */
|
||||
int depth; /* Depth at which we found it - for printing */
|
||||
uint32_t flg; /* Combination of Icode & Proc flags */
|
||||
int16_t cbParam; /* Probable no. of bytes of parameters */
|
||||
STKFRAME args; /* Array of arguments */
|
||||
LOCAL_ID localId; /* Local identifiers */
|
||||
ID retVal; /* Return value - identifier */
|
||||
|
||||
/* Icodes and control flow graph */
|
||||
CIcodeRec Icode; /* Object with ICODE records */
|
||||
std::vector<BB*> m_cfg; /* Ptr. to BB list/CFG */
|
||||
std::list<BB*> m_cfg; /* Ptr. to BB list/CFG */
|
||||
std::vector<BB*> m_dfsLast;
|
||||
std::vector<BB*> heldBBs;
|
||||
std::list<BB*> heldBBs;
|
||||
//BB * *dfsLast; /* Array of pointers to BBs in dfsLast
|
||||
// * (reverse postorder) order */
|
||||
Int numBBs; /* Number of BBs in the graph cfg */
|
||||
int numBBs; /* Number of BBs in the graph cfg */
|
||||
boolT hasCase; /* Procedure has a case node */
|
||||
|
||||
/* For interprocedural live analysis */
|
||||
@@ -121,9 +149,9 @@ public:
|
||||
void newRegArg(iICODE picode, iICODE ticode);
|
||||
protected:
|
||||
// TODO: replace those with friend visitor ?
|
||||
void propLongReg(Int loc_ident_idx, const ID &pLocId);
|
||||
void propLongStk(Int i, const ID &pLocId);
|
||||
void propLongGlb(Int i, const ID &pLocId);
|
||||
void propLongReg(int loc_ident_idx, const ID &pLocId);
|
||||
void propLongStk(int i, const ID &pLocId);
|
||||
void propLongGlb(int i, const ID &pLocId);
|
||||
|
||||
int findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE iter);
|
||||
int findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE beg);
|
||||
@@ -135,6 +163,6 @@ protected:
|
||||
void findIdioms();
|
||||
void propLong();
|
||||
void genLiveKtes();
|
||||
byte findDerivedSeq (derSeq *derivedGi);
|
||||
uint8_t findDerivedSeq (derSeq *derivedGi);
|
||||
bool nextOrderGraph(derSeq *derivedGi);
|
||||
};
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include "types.h"
|
||||
#include "ast.h"
|
||||
#include "icode.h"
|
||||
#include "locident.h"
|
||||
#include "error.h"
|
||||
#include "graph.h"
|
||||
#include "bundle.h"
|
||||
|
||||
#include "Enums.h"
|
||||
struct COND_EXPR;
|
||||
/* STACK FRAME */
|
||||
struct STKSYM
|
||||
{
|
||||
COND_EXPR *actual; /* Expression tree of actual parameter */
|
||||
COND_EXPR *regs; /* For register arguments only */
|
||||
int16 off; /* Immediate off from BP (+:args, -:params) */
|
||||
byte regOff; /* Offset is a register (e.g. SI, DI) */
|
||||
Int size; /* Size */
|
||||
int16_t off; /* Immediate off from BP (+:args, -:params) */
|
||||
uint8_t regOff; /* Offset is a register (e.g. SI, DI) */
|
||||
int size; /* Size */
|
||||
hlType type; /* Probable type */
|
||||
eDuVal duVal; /* DEF, USE, VAL */
|
||||
boolT hasMacro; /* This type needs a macro */
|
||||
@@ -31,14 +28,14 @@ struct STKFRAME
|
||||
{
|
||||
std::vector<STKSYM> sym;
|
||||
//STKSYM * sym; /* Symbols */
|
||||
int16 m_minOff; /* Initial offset in stack frame*/
|
||||
int16 maxOff; /* Maximum offset in stack frame*/
|
||||
Int cb; /* Number of bytes in arguments */
|
||||
Int numArgs; /* No. of arguments in the table*/
|
||||
void adjustForArgType(Int numArg_, hlType actType_);
|
||||
int16_t m_minOff; /* Initial offset in stack frame*/
|
||||
int16_t maxOff; /* Maximum offset in stack frame*/
|
||||
int cb; /* Number of bytes in arguments */
|
||||
int numArgs; /* No. of arguments in the table*/
|
||||
void adjustForArgType(int numArg_, hlType actType_);
|
||||
STKFRAME() : sym(0),m_minOff(0),maxOff(0),cb(0),numArgs(0)
|
||||
{
|
||||
|
||||
}
|
||||
Int getLocVar(Int off);
|
||||
int getLocVar(int off);
|
||||
};
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
* (C) Cristina Cifuentes
|
||||
*/
|
||||
#pragma once
|
||||
static const int operandSize=20;
|
||||
#include <cstring>
|
||||
#include <list>
|
||||
#include "Enums.h"
|
||||
#include "icode.h"
|
||||
|
||||
static const int operandSize=20;
|
||||
/* The following definitions and types define the Conditional Expression
|
||||
* attributed syntax tree, as defined by the following EBNF:
|
||||
CondExp ::= CondTerm AND CondTerm | CondTerm
|
||||
@@ -17,7 +18,6 @@ static const int operandSize=20;
|
||||
Identifier ::= globalVar | register | localVar | parameter | constant
|
||||
op ::= <= | < | = | != | > | >=
|
||||
*/
|
||||
|
||||
/* High-level BOOLEAN conditions for iJB..iJNS icodes */
|
||||
static const condOp condOpJCond[12] = {LESS, LESS_EQUAL, GREATER_EQUAL, GREATER,
|
||||
EQUAL, NOT_EQUAL, LESS, GREATER_EQUAL,
|
||||
@@ -28,10 +28,9 @@ struct STKFRAME;
|
||||
struct LOCAL_ID;
|
||||
struct ICODE;
|
||||
struct ID;
|
||||
typedef std::list<ICODE>::iterator iICODE;
|
||||
#include "IdentType.h"
|
||||
//enum opLoc;
|
||||
//enum hlFirst;
|
||||
//enum operDu;
|
||||
|
||||
/* Expression data type */
|
||||
struct COND_EXPR
|
||||
{
|
||||
@@ -47,16 +46,16 @@ struct COND_EXPR
|
||||
IDENTTYPE ident; /* for IDENTIFIER */
|
||||
} expr;
|
||||
public:
|
||||
static COND_EXPR *idGlob(int16 segValue, int16 off);
|
||||
static COND_EXPR *idRegIdx(Int idx, regType reg_type);
|
||||
static COND_EXPR *idKte(dword kte, byte size);
|
||||
static COND_EXPR *idLoc(Int off, LOCAL_ID *localId);
|
||||
static COND_EXPR *idReg(byte regi, flags32 icodeFlg, LOCAL_ID *locsym);
|
||||
static COND_EXPR *idLongIdx(Int idx);
|
||||
static COND_EXPR *idOther(byte seg, byte regi, int16 off);
|
||||
static COND_EXPR *idParam(Int off, const STKFRAME *argSymtab);
|
||||
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);
|
||||
static COND_EXPR *idReg(uint8_t regi, uint32_t icodeFlg, LOCAL_ID *locsym);
|
||||
static COND_EXPR *idLongIdx(int idx);
|
||||
static COND_EXPR *idOther(uint8_t seg, uint8_t regi, int16_t off);
|
||||
static COND_EXPR *idParam(int off, const STKFRAME *argSymtab);
|
||||
static COND_EXPR *unary(condNodeType t, COND_EXPR *sub_expr);
|
||||
static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, Int off);
|
||||
static COND_EXPR *idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, int off);
|
||||
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);
|
||||
@@ -78,12 +77,4 @@ public:
|
||||
COND_EXPR *inverse(); // return new COND_EXPR that is invarse of this
|
||||
};
|
||||
|
||||
/* Sequence of conditional expression data type */
|
||||
/*** NOTE: not used at present ****/
|
||||
//struct SEQ_COND_EXPR
|
||||
//{
|
||||
// COND_EXPR *expr;
|
||||
// struct _condExpSeq *neccxt;
|
||||
//};
|
||||
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ 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);
|
||||
int nextBundleIdx (strTable *strTab);
|
||||
void addLabelBundle (strTable &strTab, int idx, int label);
|
||||
void writeBundle (std::ostream &ios, bundle procCode);
|
||||
void freeBundle (bundle *procCode);
|
||||
|
||||
|
||||
128
include/dcc.h
128
include/dcc.h
@@ -5,7 +5,7 @@
|
||||
#pragma once
|
||||
#include <llvm/ADT/ilist.h>
|
||||
#include <bitset>
|
||||
|
||||
#include "Enums.h"
|
||||
#include "types.h"
|
||||
#include "ast.h"
|
||||
#include "icode.h"
|
||||
@@ -29,9 +29,9 @@ struct SYM
|
||||
|
||||
}
|
||||
char name[10]; /* New name for this variable */
|
||||
dword label; /* physical address (20 bit) */
|
||||
Int size; /* maximum size */
|
||||
flags32 flg; /* SEG_IMMED, IMPURE, WORD_OFF */
|
||||
uint32_t label; /* physical address (20 bit) */
|
||||
int size; /* maximum size */
|
||||
uint32_t flg; /* SEG_IMMED, IMPURE, WORD_OFF */
|
||||
hlType type; /* probable type */
|
||||
eDuVal duVal; /* DEF, USE, VAL */
|
||||
};
|
||||
@@ -48,43 +48,17 @@ public:
|
||||
{
|
||||
}
|
||||
public:
|
||||
void writeNodeCallGraph(Int indIdx);
|
||||
void writeNodeCallGraph(int indIdx);
|
||||
boolT insertCallGraph(ilFunction caller, ilFunction callee);
|
||||
boolT insertCallGraph(Function *caller, ilFunction callee);
|
||||
void insertArc(ilFunction newProc);
|
||||
};
|
||||
#define NUM_PROCS_DELTA 5 /* delta # procs a proc invokes */
|
||||
//#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 */
|
||||
|
||||
/* Procedure FLAGS */
|
||||
enum PROC_FLAGS
|
||||
{
|
||||
PROC_BADINST=0x00000100,/* Proc contains invalid or 386 instruction */
|
||||
PROC_IJMP =0x00000200,/* Proc incomplete due to indirect jmp */
|
||||
PROC_ICALL =0x00000400, /* Proc incomplete due to indirect call */
|
||||
PROC_HLL =0x00001000, /* Proc is likely to be from a HLL */
|
||||
CALL_PASCAL =0x00002000, /* Proc uses Pascal calling convention */
|
||||
CALL_C =0x00004000, /* Proc uses C calling convention */
|
||||
CALL_UNKNOWN=0x00008000, /* Proc uses unknown calling convention */
|
||||
PROC_NEAR =0x00010000, /* Proc exits with near return */
|
||||
PROC_FAR =0x00020000, /* Proc exits with far return */
|
||||
GRAPH_IRRED =0x00100000, /* Proc generates an irreducible graph */
|
||||
SI_REGVAR =0x00200000, /* SI is used as a stack variable */
|
||||
DI_REGVAR =0x00400000, /* DI is used as a stack variable */
|
||||
PROC_IS_FUNC=0x00800000, /* Proc is a function */
|
||||
REG_ARGS =0x01000000, /* Proc has registers as arguments */
|
||||
PROC_VARARG =0x02000000, /* Proc has variable arguments */
|
||||
PROC_OUTPUT =0x04000000, /* C for this proc has been output */
|
||||
PROC_RUNTIME=0x08000000, /* Proc is part of the runtime support */
|
||||
PROC_ISLIB =0x10000000, /* Proc is a library function */
|
||||
PROC_ASM =0x20000000, /* Proc is an intrinsic assembler routine */
|
||||
PROC_IS_HLL =0x40000000 /* Proc has HLL prolog code */
|
||||
};
|
||||
#define CALL_MASK 0xFFFF9FFF /* Masks off CALL_C and CALL_PASCAL */
|
||||
|
||||
/**** Global variables ****/
|
||||
|
||||
extern char *asm1_name, *asm2_name; /* Assembler output filenames */
|
||||
@@ -106,28 +80,28 @@ extern SYMTAB symtab; /* Global symbol table */
|
||||
|
||||
struct PROG /* Loaded program image parameters */
|
||||
{
|
||||
int16 initCS;
|
||||
int16 initIP; /* These are initial load values */
|
||||
int16 initSS; /* Probably not of great interest */
|
||||
int16 initSP;
|
||||
boolT fCOM; /* Flag set if COM program (else EXE)*/
|
||||
Int cReloc; /* No. of relocation table entries */
|
||||
dword *relocTable; /* Ptr. to relocation table */
|
||||
byte *map; /* Memory bitmap ptr */
|
||||
Int cProcs; /* Number of procedures so far */
|
||||
Int offMain; /* The offset of the main() proc */
|
||||
word segMain; /* The segment of the main() proc */
|
||||
boolT bSigs; /* True if signatures loaded */
|
||||
Int cbImage; /* Length of image in bytes */
|
||||
byte *Image; /* Allocated by loader to hold entire
|
||||
int16_t initCS;
|
||||
int16_t initIP; /* These are initial load values */
|
||||
int16_t initSS; /* Probably not of great interest */
|
||||
int16_t initSP;
|
||||
bool fCOM; /* Flag set if COM program (else EXE)*/
|
||||
int cReloc; /* No. of relocation table entries */
|
||||
uint32_t * relocTable; /* Ptr. to relocation table */
|
||||
uint8_t * map; /* Memory bitmap ptr */
|
||||
int cProcs; /* Number of procedures so far */
|
||||
int offMain; /* The offset of the main() proc */
|
||||
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 */
|
||||
};
|
||||
|
||||
extern PROG prog; /* Loaded program image parameters */
|
||||
extern std::bitset<32> duReg[30]; /* def/use bits for registers */
|
||||
|
||||
//extern dword duReg[30]; /* def/use bits for registers */
|
||||
extern dword maskDuReg[30]; /* masks off du bits for regs */
|
||||
//extern uint32_t duReg[30]; /* def/use bits for registers */
|
||||
extern uint32_t maskDuReg[30]; /* masks off du bits for regs */
|
||||
|
||||
/* Registers used by icode instructions */
|
||||
static constexpr const char *allRegs[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
|
||||
@@ -144,13 +118,13 @@ static constexpr const char *allRegs[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
|
||||
/* 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 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 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 */
|
||||
};
|
||||
|
||||
extern STATS stats; /* Icode statistics */
|
||||
@@ -159,19 +133,19 @@ extern STATS stats; /* Icode statistics */
|
||||
/**** Global function prototypes ****/
|
||||
|
||||
void FrontEnd(char *filename, CALL_GRAPH * *); /* frontend.c */
|
||||
void *allocMem(Int cb); /* frontend.c */
|
||||
void *allocMem(int cb); /* frontend.c */
|
||||
|
||||
void udm(void); /* udm.c */
|
||||
void freeCFG(BB * cfg); /* graph.c */
|
||||
BB * newBB(BB *, Int, Int, byte, 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(byte c); /* backend.c */
|
||||
eErrorId scan(dword 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 (byte *, char); /* parser.c */
|
||||
void disassem(Int pass, Function * pProc); /* disassem.c */
|
||||
void interactDis(Function * initProc, Int initIC); /* disassem.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 */
|
||||
|
||||
@@ -181,29 +155,29 @@ 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 allocStkArgs (ICODE *, int);
|
||||
void placeStkArg (ICODE *, COND_EXPR *, int);
|
||||
void adjustActArgType (COND_EXPR *, hlType, Function *);
|
||||
|
||||
/* Exported functions from ast.c */
|
||||
void removeRegFromLong (byte, LOCAL_ID *, COND_EXPR *);
|
||||
std::string walkCondExpr (const COND_EXPR *exp, Function * pProc, Int *);
|
||||
Int hlTypeSize (const COND_EXPR *, Function *);
|
||||
void removeRegFromLong (uint8_t, LOCAL_ID *, COND_EXPR *);
|
||||
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 **, byte, LOCAL_ID *);
|
||||
bool insertSubTreeLongReg (COND_EXPR *, COND_EXPR **, Int);
|
||||
bool insertSubTreeReg(COND_EXPR *, COND_EXPR **, uint8_t, LOCAL_ID *);
|
||||
bool insertSubTreeLongReg (COND_EXPR *, COND_EXPR **, int);
|
||||
|
||||
|
||||
/* Exported functions from hlicode.c */
|
||||
std::string writeCall (Function *, STKFRAME *, Function *, Int *);
|
||||
char *writeJcond (HLTYPE, Function *, Int *);
|
||||
char *writeJcondInv (HLTYPE, Function *, Int *);
|
||||
Int power2 (Int);
|
||||
std::string writeCall (Function *, STKFRAME *, Function *, int *);
|
||||
char *writeJcond (HLTYPE, Function *, int *);
|
||||
char *writeJcondInv (HLTYPE, Function *, int *);
|
||||
int power2 (int);
|
||||
|
||||
/* Exported funcions from locident.c */
|
||||
boolT checkLongEq (LONG_STKID_TYPE, iICODE, Int, Function *, Assignment &asgn, Int);
|
||||
boolT checkLongRegEq (LONGID_TYPE, iICODE, Int, Function *, COND_EXPR *&, COND_EXPR *&, Int);
|
||||
byte otherLongRegi (byte, Int, LOCAL_ID *);
|
||||
void insertIdx (IDX_ARRAY *, Int);
|
||||
boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, int);
|
||||
boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, COND_EXPR *&, COND_EXPR *&, int);
|
||||
uint8_t otherLongRegi (uint8_t, int, LOCAL_ID *);
|
||||
void insertIdx (IDX_ARRAY *, int);
|
||||
|
||||
|
||||
|
||||
@@ -5,34 +5,34 @@
|
||||
**************************************************************************/
|
||||
|
||||
/* Type definitions for intel 80x86 architecture */
|
||||
typedef unsigned int Word; /* 16 bits */
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
typedef unsigned int uint16_t; /* 16 bits */
|
||||
typedef unsigned char uint8_t; /* 8 bits */
|
||||
typedef union {
|
||||
unsigned long dW;
|
||||
Word wL, wH; /* 2 words */
|
||||
uint16_t wL, wH; /* 2 words */
|
||||
} Dword; /* 32 bits */
|
||||
|
||||
/* Structure to access high and low bits of a Byte or Word variable */
|
||||
/* Structure to access high and low bits of a uint8_t or uint16_t variable */
|
||||
typedef struct {
|
||||
/* low byte */
|
||||
Word lowBitWord : 1;
|
||||
Word filler1 : 6;
|
||||
Word highBitByte : 1;
|
||||
/* high byte */
|
||||
Word lowBitByte : 1;
|
||||
Word filler2 : 6;
|
||||
Word highBitWord : 1;
|
||||
/* low uint8_t */
|
||||
uint16_t lowBitWord : 1;
|
||||
uint16_t filler1 : 6;
|
||||
uint16_t highBitByte : 1;
|
||||
/* high uint8_t */
|
||||
uint16_t lowBitByte : 1;
|
||||
uint16_t filler2 : 6;
|
||||
uint16_t highBitWord : 1;
|
||||
} wordBits;
|
||||
|
||||
/* Low and high bits of a Byte or Word variable */
|
||||
/* Low and high bits of a uint8_t or uint16_t variable */
|
||||
#define lowBit(a) ((wordBits)(a).lowBitWord)
|
||||
#define highBitByte(a) ((wordBits)(a).highBitByte)
|
||||
#define lowBitByte(a) ((wordBits)(a).lowBitByte)
|
||||
#define highBit(a) (sizeof(a) == sizeof(Word) ? \
|
||||
#define highBit(a) (sizeof(a) == sizeof(uint16_t) ? \
|
||||
((wordBits)(a).highBitWord):\
|
||||
((wordBits)(a).highBitByte))
|
||||
|
||||
/* Word register variables */
|
||||
/* uint16_t register variables */
|
||||
#define ax regs.x.ax
|
||||
#define bx regs.x.bx
|
||||
#define cx regs.x.cx
|
||||
@@ -52,7 +52,7 @@ typedef struct {
|
||||
#define carry regs.x.cflags
|
||||
#define overF regs.x.flags /***** check *****/
|
||||
|
||||
/* Byte register variables */
|
||||
/* uint8_t register variables */
|
||||
#define ah regs.h.ah
|
||||
#define al regs.h.al
|
||||
#define bh regs.h.bh
|
||||
@@ -64,8 +64,8 @@ typedef struct {
|
||||
|
||||
|
||||
/* High and low words of a Dword */
|
||||
#define highWord(w) (*((Word*)&(w) + 1))
|
||||
#define lowWord(w) ((Word)(w))
|
||||
#define highWord(w) (*((uint16_t*)&(w) + 1))
|
||||
#define lowWord(w) ((uint16_t)(w))
|
||||
|
||||
#define MAXByte 0xFF
|
||||
#define MAXWord 0xFFFF
|
||||
|
||||
@@ -63,8 +63,8 @@ typedef std::list<BB *> queue;
|
||||
|
||||
struct interval
|
||||
{
|
||||
byte numInt; /* # of the interval */
|
||||
byte numOutEdges; /* Number of out edges */
|
||||
uint8_t numInt; /* # of the interval */
|
||||
uint8_t numOutEdges; /* Number of out edges */
|
||||
queue nodes; /* Nodes of the interval*/
|
||||
queue::iterator currNode; /* Current node */
|
||||
interval *next; /* Next interval */
|
||||
|
||||
186
include/icode.h
186
include/icode.h
@@ -15,13 +15,13 @@ struct LOCAL_ID;
|
||||
enum eLLFlags
|
||||
{
|
||||
|
||||
B =0x0000001, /* Byte operands (value implicitly used) */
|
||||
B =0x0000001, /* uint8_t operands (value implicitly used) */
|
||||
I =0x0000002, /* Immed. source */
|
||||
NOT_HLL =0x0000004, /* Not HLL inst. */
|
||||
FLOAT_OP =0x0000008, /* ESC or WAIT */
|
||||
SEG_IMMED =0x0000010, /* Number is relocated segment value */
|
||||
IMPURE =0x0000020, /* Instruction modifies code */
|
||||
WORD_OFF =0x0000040, /* Inst has word offset ie.could be address */
|
||||
WORD_OFF =0x0000040, /* Inst has uint16_t offset ie.could be address */
|
||||
TERMINATES =0x0000080, /* Instruction terminates program */
|
||||
CASE =0x0000100, /* Label as case part of switch */
|
||||
SWITCH =0x0000200, /* Treat indirect JMP as switch stmt */
|
||||
@@ -35,7 +35,7 @@ enum eLLFlags
|
||||
NO_SRC =0x0010000, /* Opcode takes no source */
|
||||
NO_OPS =0x0020000, /* Opcode takes no operands */
|
||||
IM_OPS =0x0040000, /* Opcode takes implicit operands */
|
||||
SRC_B =0x0080000, /* Source operand is byte (dest is word) */
|
||||
SRC_B =0x0080000, /* Source operand is uint8_t (dest is uint16_t) */
|
||||
#define NO_SRC_B 0xF7FFFF /* Masks off SRC_B */
|
||||
HLL_LABEL =0x0100000, /* Icode has a high level language label */
|
||||
IM_DST =0x0200000, /* Implicit DST for opcode (SIGNEX) */
|
||||
@@ -63,37 +63,7 @@ enum eDuFlags
|
||||
Df=8
|
||||
};
|
||||
|
||||
/* Machine registers */
|
||||
enum eReg
|
||||
{
|
||||
rAX = 1, /* These are numbered relative to real 8086 */
|
||||
rCX = 2,
|
||||
rDX = 3,
|
||||
rBX = 4,
|
||||
rSP = 5,
|
||||
rBP = 6,
|
||||
rSI = 7,
|
||||
rDI = 8,
|
||||
|
||||
rES = 9,
|
||||
rCS = 10,
|
||||
rSS = 11,
|
||||
rDS = 12,
|
||||
|
||||
rAL = 13,
|
||||
rCL = 14,
|
||||
rDL = 15,
|
||||
rBL = 16,
|
||||
rAH = 17,
|
||||
rCH = 18,
|
||||
rDH = 19,
|
||||
rBH = 20,
|
||||
|
||||
rTMP= 21 /* temp register for DIV/IDIV/MOD */
|
||||
#define INDEXBASE 22 /* Indexed modes go from INDEXBASE to
|
||||
* INDEXBASE+7 */
|
||||
};
|
||||
/* Byte and Word registers */
|
||||
/* uint8_t and uint16_t registers */
|
||||
static const char *const byteReg[9] = {"al", "cl", "dl", "bl",
|
||||
"ah", "ch", "dh", "bh", "tmp" };
|
||||
static const char *const wordReg[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
|
||||
@@ -229,22 +199,12 @@ enum llIcode
|
||||
struct BB;
|
||||
struct Function;
|
||||
struct STKFRAME;
|
||||
/* HIGH_LEVEL icodes opcodes */
|
||||
typedef enum {
|
||||
HLI_ASSIGN, /* := */
|
||||
HLI_CALL, /* Call procedure */
|
||||
HLI_JCOND, /* Conditional jump */
|
||||
HLI_RET, /* Return from procedure */
|
||||
/* pseudo high-level icodes */
|
||||
HLI_POP, /* Pop expression */
|
||||
HLI_PUSH /* Push expression */
|
||||
} hlIcode;
|
||||
|
||||
/* Def/use of flags - low 4 bits represent flags */
|
||||
struct DU
|
||||
{
|
||||
byte d;
|
||||
byte u;
|
||||
uint8_t d;
|
||||
uint8_t u;
|
||||
};
|
||||
|
||||
/* Definition-use chain for level 1 (within a basic block) */
|
||||
@@ -256,10 +216,10 @@ 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;
|
||||
virtual bool removeRegFromLong(uint8_t 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);
|
||||
void performLongRemoval (uint8_t regi, LOCAL_ID *locId, COND_EXPR *tree);
|
||||
};
|
||||
|
||||
struct CallType : public HlTypeSupport
|
||||
@@ -267,39 +227,39 @@ struct CallType : public HlTypeSupport
|
||||
//for HLI_CALL
|
||||
Function * proc;
|
||||
STKFRAME * args; // actual arguments
|
||||
void allocStkArgs (Int num);
|
||||
void allocStkArgs (int num);
|
||||
bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc);
|
||||
void placeStkArg(COND_EXPR *exp, Int pos);
|
||||
void placeStkArg(COND_EXPR *exp, int pos);
|
||||
public:
|
||||
bool removeRegFromLong(byte regi, LOCAL_ID *locId)
|
||||
bool removeRegFromLong(uint8_t regi, LOCAL_ID *locId)
|
||||
{
|
||||
printf("CallType : removeRegFromLong not supproted");
|
||||
return false;
|
||||
}
|
||||
std::string writeOut(Function *pProc, Int *numLoc);
|
||||
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)
|
||||
bool removeRegFromLong(uint8_t regi, LOCAL_ID *locId)
|
||||
{
|
||||
performLongRemoval(regi,locId,lhs);
|
||||
return true;
|
||||
}
|
||||
std::string writeOut(Function *pProc, Int *numLoc);
|
||||
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)
|
||||
bool removeRegFromLong(uint8_t regi, LOCAL_ID *locId)
|
||||
{
|
||||
performLongRemoval(regi,locId,v);
|
||||
return true;
|
||||
}
|
||||
std::string writeOut(Function *pProc, Int *numLoc);
|
||||
std::string writeOut(Function *pProc, int *numLoc);
|
||||
};
|
||||
|
||||
struct HLTYPE
|
||||
@@ -322,57 +282,65 @@ struct HLTYPE
|
||||
}
|
||||
}
|
||||
|
||||
void expr(COND_EXPR *e) { exp.v=e;}
|
||||
COND_EXPR * expr() { return exp.v;}
|
||||
void expr(COND_EXPR *e)
|
||||
{
|
||||
assert(e);
|
||||
exp.v=e;
|
||||
}
|
||||
COND_EXPR * expr() { return exp.v;}
|
||||
void set(hlIcode i,COND_EXPR *e)
|
||||
{
|
||||
if(i!=HLI_RET)
|
||||
assert(e);
|
||||
assert(exp.v==0);
|
||||
opcode=i;
|
||||
exp.v=e;
|
||||
}
|
||||
void set(COND_EXPR *l,COND_EXPR *r)
|
||||
{
|
||||
assert(l);
|
||||
assert(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);
|
||||
std::string write1HlIcode(Function *pProc, int *numLoc);
|
||||
} ;
|
||||
/* LOW_LEVEL icode operand record */
|
||||
struct LLOperand //: public llvm::MCOperand
|
||||
{
|
||||
byte seg; /* CS, DS, ES, SS */
|
||||
int16 segValue; /* Value of segment seg during analysis */
|
||||
byte segOver; /* CS, DS, ES, SS if segment override */
|
||||
byte regi; /* 0 < regs < INDEXBASE <= index modes */
|
||||
int16 off; /* memory address offset */
|
||||
dword opz; /* idx of immed src op */
|
||||
uint8_t seg; /* CS, DS, ES, SS */
|
||||
int16_t segValue; /* Value of segment seg during analysis */
|
||||
uint8_t segOver; /* CS, DS, ES, SS if segment override */
|
||||
uint8_t regi; /* 0 < regs < INDEXBASE <= index modes */
|
||||
int16_t off; /* memory address offset */
|
||||
uint32_t opz; /* idx of immed src op */
|
||||
//union {/* Source operand if (flg & I) */
|
||||
struct { /* Call & # actual arg bytes */
|
||||
Function *proc; /* pointer to target proc (for CALL(F))*/
|
||||
int cb; /* # actual arg bytes */
|
||||
} proc;
|
||||
dword op() const {return opz;}
|
||||
void SetImmediateOp(dword dw) {opz=dw;}
|
||||
uint32_t op() const {return opz;}
|
||||
void SetImmediateOp(uint32_t dw) {opz=dw;}
|
||||
|
||||
};
|
||||
struct LLInst : public llvm::MCInst
|
||||
{
|
||||
llIcode opcode; /* llIcode instruction */
|
||||
byte numBytes; /* Number of bytes this instr */
|
||||
flags32 flg; /* icode flags */
|
||||
dword label; /* offset in image (20-bit adr) */
|
||||
llIcode opcode; /* llIcode instruction */
|
||||
uint8_t numBytes; /* Number of bytes this instr */
|
||||
uint32_t flg; /* icode flags */
|
||||
uint32_t label; /* offset in image (20-bit adr) */
|
||||
LLOperand dst; /* destination operand */
|
||||
LLOperand src; /* source operand */
|
||||
DU flagDU; /* def/use of flags */
|
||||
DU flagDU; /* def/use of flags */
|
||||
struct { /* Case table if op==JMP && !I */
|
||||
Int numEntries; /* # entries in case table */
|
||||
dword *entries; /* array of offsets */
|
||||
int numEntries; /* # entries in case table */
|
||||
uint32_t *entries; /* array of offsets */
|
||||
|
||||
} caseTbl;
|
||||
Int hllLabNum; /* label # for hll codegen */
|
||||
int hllLabNum; /* label # for hll codegen */
|
||||
bool conditionalJump()
|
||||
{
|
||||
return (opcode >= iJB) && (opcode < iJCXZ);
|
||||
@@ -412,7 +380,7 @@ struct ICODE
|
||||
struct DU_ICODE
|
||||
{
|
||||
std::bitset<32> def; // For Registers: position in bitset is reg index
|
||||
std::bitset<32> use; // For Registers: position in dword is reg index
|
||||
std::bitset<32> use; // For Registers: position in uint32_t is reg index
|
||||
std::bitset<32> lastDefRegi;// Bit set if last def of this register in BB
|
||||
};
|
||||
struct DU1
|
||||
@@ -439,38 +407,38 @@ struct ICODE
|
||||
}
|
||||
|
||||
};
|
||||
Int numRegsDef; /* # registers defined by this inst */
|
||||
byte regi[MAX_REGS_DEF]; /* registers defined by this inst */
|
||||
int numRegsDef; /* # registers defined by this inst */
|
||||
uint8_t regi[MAX_REGS_DEF]; /* registers defined by this inst */
|
||||
Use idx[MAX_REGS_DEF];
|
||||
//Int idx[MAX_REGS_DEF][MAX_USES]; /* inst that uses this def */
|
||||
//int idx[MAX_REGS_DEF][MAX_USES]; /* inst that uses this def */
|
||||
bool used(int regIdx)
|
||||
{
|
||||
return not idx[regIdx].uses.empty();
|
||||
}
|
||||
{
|
||||
return not idx[regIdx].uses.empty();
|
||||
}
|
||||
int numUses(int regIdx)
|
||||
{
|
||||
return idx[regIdx].uses.size();
|
||||
}
|
||||
{
|
||||
return idx[regIdx].uses.size();
|
||||
}
|
||||
void recordUse(int regIdx,std::list<ICODE>::iterator location)
|
||||
{
|
||||
idx[regIdx].uses.push_back(location);
|
||||
}
|
||||
{
|
||||
idx[regIdx].uses.push_back(location);
|
||||
}
|
||||
void remove(int regIdx,int use_idx)
|
||||
{
|
||||
idx[regIdx].uses.erase(idx[regIdx].uses.begin()+use_idx);
|
||||
}
|
||||
{
|
||||
idx[regIdx].uses.erase(idx[regIdx].uses.begin()+use_idx);
|
||||
}
|
||||
void remove(int regIdx,std::list<ICODE>::iterator ic)
|
||||
{
|
||||
Use &u(idx[regIdx]);
|
||||
u.removeUser(ic);
|
||||
}
|
||||
{
|
||||
Use &u(idx[regIdx]);
|
||||
u.removeUser(ic);
|
||||
}
|
||||
};
|
||||
icodeType type; /* Icode type */
|
||||
bool invalid; /* Has no HIGH_LEVEL equivalent */
|
||||
BB *inBB; /* BB to which this icode belongs */
|
||||
DU_ICODE du; /* Def/use regs/vars */
|
||||
DU1 du1; /* du chain 1 */
|
||||
Int codeIdx; /* Index into cCode.code */
|
||||
int codeIdx; /* Index into cCode.code */
|
||||
struct IC { /* Different types of icodes */
|
||||
LLInst ll;
|
||||
HLTYPE hl; /* For HIGH_LEVEL icodes */
|
||||
@@ -478,29 +446,29 @@ struct ICODE
|
||||
IC ic;/* intermediate code */
|
||||
int loc_ip; // used by CICodeRec to number ICODEs
|
||||
|
||||
void ClrLlFlag(dword flag) {ic.ll.flg &= ~flag;}
|
||||
void SetLlFlag(dword flag) {ic.ll.flg |= flag;}
|
||||
dword GetLlFlag() {return ic.ll.flg;}
|
||||
bool isLlFlag(dword flg) {return (ic.ll.flg&flg)!=0;}
|
||||
void ClrLlFlag(uint32_t flag) {ic.ll.flg &= ~flag;}
|
||||
void SetLlFlag(uint32_t flag) {ic.ll.flg |= flag;}
|
||||
uint32_t GetLlFlag() {return ic.ll.flg;}
|
||||
bool isLlFlag(uint32_t flg) {return (ic.ll.flg&flg)!=0;}
|
||||
llIcode GetLlOpcode() const { return ic.ll.opcode; }
|
||||
dword GetLlLabel() const { return ic.ll.label;}
|
||||
void SetImmediateOp(dword dw) {ic.ll.src.SetImmediateOp(dw);}
|
||||
uint32_t GetLlLabel() const { return ic.ll.label;}
|
||||
void SetImmediateOp(uint32_t dw) {ic.ll.src.SetImmediateOp(dw);}
|
||||
|
||||
void writeIntComment(std::ostringstream &s);
|
||||
void setRegDU(byte regi, operDu du_in);
|
||||
void setRegDU(uint8_t regi, operDu du_in);
|
||||
void invalidate();
|
||||
void newCallHl();
|
||||
void writeDU(Int idx);
|
||||
void writeDU(int idx);
|
||||
condId idType(opLoc sd);
|
||||
// HLL setting functions
|
||||
void setAsgn(COND_EXPR *lhs, COND_EXPR *rhs); // set this icode to be an assign
|
||||
void setUnary(hlIcode op, COND_EXPR *exp);
|
||||
void setJCond(COND_EXPR *cexp);
|
||||
void emitGotoLabel(Int indLevel);
|
||||
void emitGotoLabel(int indLevel);
|
||||
void copyDU(const ICODE &duIcode, operDu _du, operDu duDu);
|
||||
bool valid() {return not invalid;}
|
||||
public:
|
||||
bool removeDefRegi(byte regi, Int thisDefIdx, LOCAL_ID *locId);
|
||||
bool removeDefRegi(uint8_t regi, int thisDefIdx, LOCAL_ID *locId);
|
||||
void checkHlCall();
|
||||
bool newStkArg(COND_EXPR *exp, llIcode opcode, Function *pproc)
|
||||
{
|
||||
@@ -516,8 +484,8 @@ public:
|
||||
|
||||
ICODE * addIcode(ICODE *pIcode);
|
||||
void SetInBB(int start, int end, BB* pnewBB);
|
||||
bool labelSrch(dword target, dword &pIndex);
|
||||
iterator labelSrch(dword target);
|
||||
bool labelSrch(uint32_t target, uint32_t &pIndex);
|
||||
iterator labelSrch(uint32_t target);
|
||||
ICODE * GetIcode(int ip);
|
||||
};
|
||||
typedef CIcodeRec::iterator iICODE;
|
||||
|
||||
@@ -5,7 +5,7 @@ struct Idiom1 : public Idiom
|
||||
protected:
|
||||
std::vector<iICODE> m_icodes;
|
||||
int m_min_off;
|
||||
Int checkStkVars (iICODE pIcode);
|
||||
int checkStkVars (iICODE pIcode);
|
||||
public:
|
||||
Idiom1(Function *f) : Idiom(f)
|
||||
{
|
||||
|
||||
@@ -8,8 +8,8 @@ struct Idiom14 : public Idiom
|
||||
{
|
||||
protected:
|
||||
iICODE m_icodes[2];
|
||||
byte m_regL;
|
||||
byte m_regH;
|
||||
uint8_t m_regL;
|
||||
uint8_t m_regH;
|
||||
public:
|
||||
virtual ~Idiom14() {}
|
||||
Idiom14(Function *f) : Idiom(f),m_regL(0),m_regH(0)
|
||||
@@ -24,7 +24,7 @@ struct Idiom13 : public Idiom
|
||||
{
|
||||
protected:
|
||||
iICODE m_icodes[2];
|
||||
byte m_loaded_reg;
|
||||
uint8_t m_loaded_reg;
|
||||
public:
|
||||
virtual ~Idiom13() {}
|
||||
Idiom13(Function *f) : Idiom(f)
|
||||
|
||||
@@ -8,7 +8,7 @@ struct Idiom8 : public Idiom
|
||||
{
|
||||
protected:
|
||||
iICODE m_icodes[2];
|
||||
byte m_loaded_reg;
|
||||
uint8_t m_loaded_reg;
|
||||
public:
|
||||
virtual ~Idiom8() {}
|
||||
Idiom8(Function *f) : Idiom(f)
|
||||
@@ -37,7 +37,7 @@ struct Idiom12 : public Idiom
|
||||
{
|
||||
protected:
|
||||
iICODE m_icodes[2];
|
||||
byte m_loaded_reg;
|
||||
uint8_t m_loaded_reg;
|
||||
public:
|
||||
virtual ~Idiom12() {}
|
||||
Idiom12(Function *f) : Idiom(f)
|
||||
@@ -53,7 +53,7 @@ struct Idiom9 : public Idiom
|
||||
{
|
||||
protected:
|
||||
iICODE m_icodes[2];
|
||||
byte m_loaded_reg;
|
||||
uint8_t m_loaded_reg;
|
||||
public:
|
||||
virtual ~Idiom9() {}
|
||||
Idiom9(Function *f) : Idiom(f)
|
||||
|
||||
@@ -6,13 +6,19 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include "icode.h"
|
||||
|
||||
#include "Enums.h"
|
||||
|
||||
/* Type definition */
|
||||
// this array has to stay in-order of addition i.e. not std::set<iICODE,std::less<iICODE> >
|
||||
// TODO: why ?
|
||||
struct ICODE;
|
||||
typedef std::list<ICODE>::iterator iICODE;
|
||||
struct IDX_ARRAY : public std::vector<iICODE>
|
||||
{
|
||||
bool inList(iICODE idx)
|
||||
@@ -20,26 +26,12 @@ struct IDX_ARRAY : public std::vector<iICODE>
|
||||
return std::find(begin(),end(),idx)!=end();
|
||||
}
|
||||
};
|
||||
/* Type definitions used in the decompiled program */
|
||||
typedef enum {
|
||||
TYPE_UNKNOWN = 0, /* unknown so far */
|
||||
TYPE_BYTE_SIGN, /* signed byte (8 bits) */
|
||||
TYPE_BYTE_UNSIGN, /* unsigned byte */
|
||||
TYPE_WORD_SIGN, /* signed word (16 bits) */
|
||||
TYPE_WORD_UNSIGN, /* unsigned word (16 bits) */
|
||||
TYPE_LONG_SIGN, /* signed long (32 bits) */
|
||||
TYPE_LONG_UNSIGN, /* unsigned long (32 bits) */
|
||||
TYPE_RECORD, /* record structure */
|
||||
TYPE_PTR, /* pointer (32 bit ptr) */
|
||||
TYPE_STR, /* string */
|
||||
TYPE_CONST, /* constant (any type) */
|
||||
TYPE_FLOAT, /* floating point */
|
||||
TYPE_DOUBLE /* double precision float */
|
||||
} hlType;
|
||||
|
||||
static constexpr const char *hlTypes[13] = {"", "char", "unsigned char", "int", "unsigned int",
|
||||
"long", "unsigned long", "record", "int *", "char *",
|
||||
"", "float", "double"};
|
||||
static constexpr const char *hlTypes[13] = {
|
||||
"", "char", "unsigned char", "int", "unsigned int",
|
||||
"long", "unsigned long", "record", "int *", "char *",
|
||||
"", "float", "double"
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -50,21 +42,21 @@ typedef enum
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int16 seg; /* segment value */
|
||||
int16 off; /* offset */
|
||||
byte regi; /* optional indexed register */
|
||||
int16_t seg; /* segment value */
|
||||
int16_t off; /* offset */
|
||||
uint8_t regi; /* optional indexed register */
|
||||
} BWGLB_TYPE;
|
||||
|
||||
|
||||
typedef struct
|
||||
{ /* For TYPE_LONG_(UN)SIGN on the stack */
|
||||
Int offH; /* high offset from BP */
|
||||
Int offL; /* low offset from BP */
|
||||
int offH; /* high offset from BP */
|
||||
int offL; /* low offset from BP */
|
||||
} LONG_STKID_TYPE;
|
||||
typedef struct
|
||||
{ /* For TYPE_LONG_(UN)SIGN registers */
|
||||
byte h; /* high register */
|
||||
byte l; /* low register */
|
||||
uint8_t h; /* high register */
|
||||
uint8_t l; /* low register */
|
||||
} LONGID_TYPE;
|
||||
|
||||
|
||||
@@ -72,46 +64,35 @@ typedef struct
|
||||
struct ID
|
||||
{
|
||||
hlType type; /* Probable type */
|
||||
boolT illegal; /* Boolean: not a valid field any more */
|
||||
bool illegal; /* Boolean: not a valid field any more */
|
||||
//std::vector<iICODE> idx;
|
||||
IDX_ARRAY idx; /* Index into icode array (REG_FRAME only) */
|
||||
frameType loc; /* Frame location */
|
||||
boolT hasMacro; /* Identifier requires a macro */
|
||||
bool hasMacro; /* Identifier requires a macro */
|
||||
char macro[10]; /* Macro for this identifier */
|
||||
char name[20]; /* Identifier's name */
|
||||
union { /* Different types of identifiers */
|
||||
byte regi; /* For TYPE_BYTE(WORD)_(UN)SIGN registers */
|
||||
struct { /* For TYPE_BYTE(WORD)_(UN)SIGN on the stack */
|
||||
byte regOff; /* register offset (if any) */
|
||||
Int off; /* offset from BP */
|
||||
uint8_t regi; /* For TYPE_BYTE(uint16_t)_(UN)SIGN registers */
|
||||
struct { /* For TYPE_BYTE(uint16_t)_(UN)SIGN on the stack */
|
||||
uint8_t regOff; /* register offset (if any) */
|
||||
int off; /* offset from BP */
|
||||
} bwId;
|
||||
BWGLB_TYPE bwGlb; /* For TYPE_BYTE(WORD)_(UN)SIGN globals */
|
||||
BWGLB_TYPE bwGlb; /* For TYPE_BYTE(uint16_t)_(UN)SIGN globals */
|
||||
LONGID_TYPE longId; /* For TYPE_LONG_(UN)SIGN registers */
|
||||
LONG_STKID_TYPE longStkId; /* For TYPE_LONG_(UN)SIGN on the stack */
|
||||
struct { /* For TYPE_LONG_(UN)SIGN globals */
|
||||
int16 seg; /* segment value */
|
||||
int16 offH; /* offset high */
|
||||
int16 offL; /* offset low */
|
||||
byte regi; /* optional indexed register */
|
||||
int16_t seg; /* segment value */
|
||||
int16_t offH; /* offset high */
|
||||
int16_t offL; /* offset low */
|
||||
uint8_t regi; /* optional indexed register */
|
||||
} longGlb;
|
||||
struct { /* For TYPE_LONG_(UN)SIGN constants */
|
||||
dword h; /* high word */
|
||||
dword l; /* low word */
|
||||
uint32_t h; /* high uint16_t */
|
||||
uint32_t l; /* low uint16_t */
|
||||
} longKte;
|
||||
} id;
|
||||
ID() : type(TYPE_UNKNOWN),illegal(false),loc(STK_FRAME),hasMacro(false)
|
||||
{
|
||||
name[0]=0;
|
||||
macro[0]=0;
|
||||
memset(&id,0,sizeof(id));
|
||||
}
|
||||
ID(hlType t, frameType f) : type(t),illegal(false),hasMacro(false)
|
||||
{
|
||||
name[0]=0;
|
||||
macro[0]=0;
|
||||
memset(&id,0,sizeof(id));
|
||||
loc=f;
|
||||
}
|
||||
ID();
|
||||
ID(hlType t, frameType f);
|
||||
bool isSigned() const { return (type==TYPE_BYTE_SIGN)||(type==TYPE_WORD_SIGN)||(type==TYPE_LONG_SIGN);}
|
||||
uint16_t typeBitsize() const
|
||||
{
|
||||
@@ -132,19 +113,19 @@ public:
|
||||
{
|
||||
id_arr.reserve(256);
|
||||
}
|
||||
Int newByteWordReg(hlType t, byte regi);
|
||||
Int newByteWordStk(hlType t, Int off, byte regOff);
|
||||
Int newIntIdx(int16 seg, int16 off, byte regi, Int ix, hlType t);
|
||||
Int newLongReg(hlType t, byte regH, byte regL, iICODE ix_);
|
||||
Int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, Int off);
|
||||
int newByteWordReg(hlType t, uint8_t regi);
|
||||
int newByteWordStk(hlType t, int off, uint8_t regOff);
|
||||
int newIntIdx(int16_t seg, int16_t off, uint8_t regi, int ix, hlType t);
|
||||
int newLongReg(hlType t, uint8_t regH, uint8_t regL, iICODE ix_);
|
||||
int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, int off);
|
||||
void newIdent(hlType t, frameType f);
|
||||
void flagByteWordId(Int off);
|
||||
void propLongId(byte regL, byte regH, const char *name);
|
||||
void flagByteWordId(int off);
|
||||
void propLongId(uint8_t regL, uint8_t regH, const char *name);
|
||||
size_t csym() const {return id_arr.size();}
|
||||
protected:
|
||||
Int newLongIdx(int16 seg, int16 offH, int16 offL, byte regi, hlType t);
|
||||
Int newLongGlb(int16 seg, int16 offH, int16 offL, hlType t);
|
||||
Int newLongStk(hlType t, Int offH, Int offL);
|
||||
int newLongIdx(int16_t seg, int16_t offH, int16_t offL, uint8_t regi, hlType t);
|
||||
int newLongGlb(int16_t seg, int16_t offH, int16_t offL, hlType t);
|
||||
int newLongStk(hlType t, int offH, int offL);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -7,19 +7,19 @@
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
//#define bool unsigned char
|
||||
#define byte unsigned char
|
||||
#define word unsigned short
|
||||
#define uint8_t unsigned char
|
||||
#define uint16_t unsigned short
|
||||
|
||||
/* Prototypes */
|
||||
void hashCleanup(void); /* Frees memory allocated by hashParams() */
|
||||
void map(void); /* Part 1 of creating the tables */
|
||||
|
||||
/* The application must provide these functions: */
|
||||
void getKey(int i, byte **pKeys);/* Set *keys to point to the i+1th key */
|
||||
void getKey(int i, uint8_t **pKeys);/* Set *keys to point to the i+1th key */
|
||||
void dispKey(int i); /* Display the key */
|
||||
class PatternHasher
|
||||
{
|
||||
word *T1base, *T2base; /* Pointers to start of T1, T2 */
|
||||
uint16_t *T1base, *T2base; /* Pointers to start of T1, T2 */
|
||||
int NumEntry; /* Number of entries in the hash table (# keys) */
|
||||
int EntryLen; /* Size (bytes) of each entry (size of keys) */
|
||||
int SetSize; /* Size of the char set */
|
||||
@@ -29,15 +29,15 @@ class PatternHasher
|
||||
int *graphNext; /* Linked list of edges */
|
||||
int *graphFirst;/* First edge at a vertex */
|
||||
public:
|
||||
word *readT1(void); /* Returns a pointer to the T1 table */
|
||||
word *readT2(void); /* Returns a pointer to the T2 table */
|
||||
word *readG(void); /* Returns a pointer to the g table */
|
||||
uint16_t *readT1(void); /* Returns a pointer to the T1 table */
|
||||
uint16_t *readT2(void); /* Returns a pointer to the T2 table */
|
||||
uint16_t *readG(void); /* Returns a pointer to the g table */
|
||||
void init(int _NumEntry, int _EntryLen, int _SetSize, char _SetMin,int _NumVert); /* Set the parameters for the hash table */
|
||||
void cleanup();
|
||||
int hash(unsigned char *string); //!< Hash the string to an int 0 .. NUMENTRY-1
|
||||
};
|
||||
extern PatternHasher g_pattern_hasher;
|
||||
/* Macro reads a LH word from the image regardless of host convention */
|
||||
/* Macro reads a LH uint16_t from the image regardless of host convention */
|
||||
#ifndef LH
|
||||
#define LH(p) ((int)((byte *)(p))[0] + ((int)((byte *)(p))[1] << 8))
|
||||
#define LH(p) ((int)((uint8_t *)(p))[0] + ((int)((uint8_t *)(p))[1] << 8))
|
||||
#endif
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
* (C) Cristina Cifuentes, Jeff Ledermann
|
||||
*/
|
||||
|
||||
#define LH(p) ((int)((byte *)(p))[0] + ((int)((byte *)(p))[1] << 8))
|
||||
/* Extracts reg bits from middle of mod-reg-rm byte */
|
||||
#define REG(x) ((byte)(x & 0x38) >> 3)
|
||||
#define LH(p) ((int)((uint8_t *)(p))[0] + ((int)((uint8_t *)(p))[1] << 8))
|
||||
/* Extracts reg bits from middle of mod-reg-rm uint8_t */
|
||||
#define REG(x) ((uint8_t)(x & 0x38) >> 3)
|
||||
|
||||
@@ -3,26 +3,27 @@
|
||||
* (C) Cristina Cifuentes, Mike van Emmerik
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
#include "types.h"
|
||||
#include "Enums.h"
|
||||
/* STATE TABLE */
|
||||
struct STATE
|
||||
{
|
||||
dword IP; /* Offset into Image */
|
||||
int16 r[INDEXBASE]; /* Value of segs and AX */
|
||||
byte f[INDEXBASE]; /* True if r[.] has a value */
|
||||
uint32_t IP; /* Offset into Image */
|
||||
int16_t r[INDEXBASE]; /* Value of segs and AX */
|
||||
uint8_t f[INDEXBASE]; /* True if r[.] has a value */
|
||||
struct
|
||||
{ /* For case stmt indexed reg */
|
||||
byte regi; /* Last conditional jump */
|
||||
int16 immed; /* Contents of the previous register */
|
||||
uint8_t regi; /* Last conditional jump */
|
||||
int16_t immed; /* Contents of the previous register */
|
||||
} JCond;
|
||||
void setState(word reg, int16 value);
|
||||
void setState(uint16_t reg, int16_t value);
|
||||
void checkStartup();
|
||||
STATE() : IP(0)
|
||||
{
|
||||
JCond.immed=0;
|
||||
memset(r,0,sizeof(int16)*INDEXBASE);
|
||||
memset(f,0,sizeof(byte)*INDEXBASE);
|
||||
memset(r,0,sizeof(int16_t)*INDEXBASE);
|
||||
memset(f,0,sizeof(uint8_t)*INDEXBASE);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ struct Function;
|
||||
struct SYMTABLE
|
||||
{
|
||||
std::string pSymName; /* Ptr to symbolic name or comment */
|
||||
dword symOff; /* Symbol image offset */
|
||||
uint32_t symOff; /* Symbol image offset */
|
||||
Function *symProc; /* Procedure pointer */
|
||||
SYMTABLE() : symOff(0),symProc(0) {}
|
||||
SYMTABLE(dword _sym,Function *_proc) : symOff(_sym),symProc(_proc)
|
||||
SYMTABLE(uint32_t _sym,Function *_proc) : symOff(_sym),symProc(_proc)
|
||||
{}
|
||||
bool operator == (const SYMTABLE &other) const
|
||||
{
|
||||
@@ -32,6 +32,6 @@ enum tableType /* The table types */
|
||||
|
||||
void createSymTables(void);
|
||||
void destroySymTables(void);
|
||||
boolT readVal (std::ostringstream &symName, dword symOff, Function *symProc);
|
||||
boolT readVal (std::ostringstream &symName, uint32_t symOff, Function *symProc);
|
||||
void selectTable(tableType); /* Select a particular table */
|
||||
|
||||
|
||||
@@ -5,17 +5,8 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
/**** Common definitions and macros ****/
|
||||
#ifdef __MSDOS__ /* Intel: 16 bit integer */
|
||||
typedef long Int; /* Int: 0x80000000..0x7FFFFFFF */
|
||||
typedef unsigned long flags32; /* 32 bits */
|
||||
typedef unsigned long dword; /* 32 bits */
|
||||
typedef unsigned int uint32_t; /* 32 bits */
|
||||
#define MAX 0x7FFFFFFF
|
||||
#else /* Unix: 32 bit integer */
|
||||
typedef int Int; /* Int: 0x80000000..0x7FFFFFFF */
|
||||
typedef unsigned int flags32; /* 32 bits */
|
||||
typedef unsigned int dword; /* 32 bits */
|
||||
#define MAX 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/* Type definitions used in the program */
|
||||
typedef unsigned char byte; /* 8 bits */
|
||||
|
||||
Reference in New Issue
Block a user