mooing on
This commit is contained in:
@@ -25,7 +25,7 @@ struct BB : public llvm::ilist_node<BB>
|
||||
{
|
||||
private:
|
||||
BB(const BB&);
|
||||
BB() : nodeType(0),traversed(0),start(0),length(0),
|
||||
BB() : start(0),length(0),nodeType(0),traversed(0),
|
||||
numHlIcodes(0),flg(0),
|
||||
inEdges(0),
|
||||
edges(0),beenOnH(0),inEdgeCount(0),reachingInt(0),
|
||||
@@ -97,8 +97,8 @@ public:
|
||||
Int caseTail; /* tail node for the case */
|
||||
|
||||
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);
|
||||
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);
|
||||
void mergeFallThrough(CIcodeRec &Icode);
|
||||
void dfsNumbering(std::vector<BB *> &dfsLast, Int *first, Int *last);
|
||||
|
||||
@@ -113,20 +113,21 @@ public:
|
||||
void buildCFG();
|
||||
void controlFlowAnalysis();
|
||||
void newRegArg(ICODE *picode, ICODE *ticode);
|
||||
protected:
|
||||
protected:
|
||||
// TODO: replace those with friend visitor ?
|
||||
void propLongReg(Int i, ID *pLocId);
|
||||
void propLongReg(Int loc_ident_idx, ID *pLocId);
|
||||
void propLongStk(Int i, ID *pLocId);
|
||||
void propLongGlb(Int i, ID *pLocId);
|
||||
|
||||
void structCases();
|
||||
void findExps();
|
||||
void genDU1();
|
||||
void elimCondCodes();
|
||||
void liveRegAnalysis(dword in_liveOut);
|
||||
void findIdioms();
|
||||
void propLong();
|
||||
void genLiveKtes();
|
||||
byte findDerivedSeq (derSeq *derivedGi);
|
||||
bool nextOrderGraph(derSeq *derivedGi);
|
||||
int checkBackwarLongDefs(int loc_ident_idx, ID *pLocId, int pLocId_idx);
|
||||
void structCases();
|
||||
void findExps();
|
||||
void genDU1();
|
||||
void elimCondCodes();
|
||||
void liveRegAnalysis(dword in_liveOut);
|
||||
void findIdioms();
|
||||
void propLong();
|
||||
void genLiveKtes();
|
||||
byte findDerivedSeq (derSeq *derivedGi);
|
||||
bool nextOrderGraph(derSeq *derivedGi);
|
||||
};
|
||||
|
||||
@@ -35,11 +35,10 @@ struct STKFRAME
|
||||
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_);
|
||||
void adjustForArgType(Int numArg_, hlType actType_);
|
||||
STKFRAME() : sym(0),minOff(0),maxOff(0),cb(0),numArgs(0)
|
||||
{
|
||||
|
||||
}
|
||||
public:
|
||||
Int getLocVar(Int off);
|
||||
};
|
||||
|
||||
@@ -74,9 +74,8 @@ public:
|
||||
type=other.type;
|
||||
expr=other.expr;
|
||||
}
|
||||
COND_EXPR()
|
||||
COND_EXPR(condNodeType t=UNKNOWN_OP) : type(t)
|
||||
{
|
||||
type=UNKNOWN_OP;
|
||||
memset(&expr,0,sizeof(_exprNode));
|
||||
}
|
||||
public:
|
||||
|
||||
@@ -23,7 +23,6 @@ public:
|
||||
#define lineSize 360 /* 3 lines in the mean time */
|
||||
|
||||
void newBundle (bundle *procCode);
|
||||
//void appendStrTab (strTable *strTab, const char *format, ...);
|
||||
Int nextBundleIdx (strTable *strTab);
|
||||
void addLabelBundle (strTable &strTab, Int idx, Int label);
|
||||
void writeBundle (std::ostream &ios, bundle procCode);
|
||||
|
||||
@@ -60,32 +60,29 @@ extern bundle cCode; /* Output C procedure's declaration and code */
|
||||
/* Procedure FLAGS */
|
||||
enum PROC_FLAGS
|
||||
{
|
||||
PROC_BADINST=0x000100,/* Proc contains invalid or 386 instruction */
|
||||
PROC_IJMP =0x000200,/* Proc incomplete due to indirect jmp */
|
||||
PROC_ICALL =0x000400, /* Proc incomplete due to indirect call */
|
||||
PROC_HLL=0x001000, /* Proc is likely to be from a HLL */
|
||||
CALL_PASCAL=0x002000, /* Proc uses Pascal calling convention */
|
||||
CALL_C=0x004000, /* Proc uses C calling convention */
|
||||
CALL_UNKNOWN=0x008000, /* Proc uses unknown calling convention */
|
||||
PROC_NEAR=0x010000, /* Proc exits with near return */
|
||||
PROC_FAR=0x020000, /* Proc exits with far return */
|
||||
GRAPH_IRRED=0x100000, /* Proc generates an irreducible graph */
|
||||
SI_REGVAR=0x200000, /* SI is used as a stack variable */
|
||||
DI_REGVAR=0x400000, /* DI is used as a stack variable */
|
||||
PROC_IS_FUNC=0x800000, /* Proc is a function */
|
||||
REG_ARGS=0x1000000, /* Proc has registers as arguments */
|
||||
PROC_VARARG=0x2000000, /* Proc has variable arguments */
|
||||
PROC_OUTPUT=0x4000000, /* C for this proc has been output */
|
||||
PROC_RUNTIME=0x8000000, /* 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 */
|
||||
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 */
|
||||
@@ -125,13 +122,11 @@ struct PROG /* Loaded program image parameters */
|
||||
};
|
||||
|
||||
extern PROG prog; /* Loaded program image parameters */
|
||||
extern char condExp[200]; /* Conditional expression buffer */
|
||||
extern char callBuf[100]; /* Function call buffer */
|
||||
extern dword duReg[30]; /* def/use bits for registers */
|
||||
extern dword maskDuReg[30]; /* masks off du bits for regs */
|
||||
|
||||
/* Registers used by icode instructions */
|
||||
static const char *allRegs[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
|
||||
static constexpr const char *allRegs[21] = {"ax", "cx", "dx", "bx", "sp", "bp",
|
||||
"si", "di", "es", "cs", "ss", "ds",
|
||||
"al", "cl", "dl", "bl", "ah", "ch", "dh", "bh",
|
||||
"tmp"};
|
||||
@@ -161,24 +156,24 @@ extern STATS stats; /* Icode statistics */
|
||||
|
||||
void FrontEnd(char *filename, CALL_GRAPH * *); /* frontend.c */
|
||||
void *allocMem(Int cb); /* frontend.c */
|
||||
void *reallocVar(void *p, Int newsize); /* frontend.c */
|
||||
|
||||
void udm(void); /* udm.c */
|
||||
void freeCFG(BB * cfg); /* graph.c */
|
||||
BB * newBB(BB *, Int, Int, byte, Int, Function *); /* graph.c */
|
||||
void BackEnd(char *filename, CALL_GRAPH *); /* backend.c */
|
||||
char *cChar(byte c); /* backend.c */
|
||||
Int scan(dword ip, ICODE * p); /* scanner.c */
|
||||
eErrorId scan(dword ip, ICODE * p); /* scanner.c */
|
||||
void parse (CALL_GRAPH * *); /* parser.c */
|
||||
boolT labelSrch(CIcodeRec &pIc, Int n, dword tg, Int *pIdx); /* parser.c */
|
||||
|
||||
Int strSize (byte *, char); /* parser.c */
|
||||
void disassem(Int pass, Function * pProc); /* disassem.c */
|
||||
void interactDis(Function * initProc, Int initIC); /* disassem.c */
|
||||
boolT JmpInst(llIcode opcode); /* idioms.c */
|
||||
bool JmpInst(llIcode opcode); /* idioms.c */
|
||||
queue::iterator appendQueue(queue &Q, BB *node); /* reducible.c */
|
||||
|
||||
void SetupLibCheck(void); /* chklib.c */
|
||||
void CleanupLibCheck(void); /* chklib.c */
|
||||
boolT LibCheck(Function &p); /* chklib.c */
|
||||
bool LibCheck(Function &p); /* chklib.c */
|
||||
|
||||
/* Exported functions from procs.c */
|
||||
boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction);
|
||||
@@ -192,8 +187,8 @@ void removeRegFromLong (byte, 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 *);
|
||||
boolT insertSubTreeReg (COND_EXPR *, COND_EXPR **, byte, LOCAL_ID *);
|
||||
boolT insertSubTreeLongReg (COND_EXPR *, COND_EXPR **, Int);
|
||||
bool insertSubTreeReg(COND_EXPR *, COND_EXPR **, byte, LOCAL_ID *);
|
||||
bool insertSubTreeLongReg (COND_EXPR *, COND_EXPR **, Int);
|
||||
|
||||
|
||||
/* Exported functions from hlicode.c */
|
||||
|
||||
@@ -5,29 +5,32 @@
|
||||
#pragma once
|
||||
|
||||
/* These definitions refer to errorMessage in error.c */
|
||||
enum eErrorId
|
||||
{
|
||||
NO_ERR =0,
|
||||
USAGE,
|
||||
INVALID_ARG,
|
||||
INVALID_OPCODE,
|
||||
INVALID_386OP,
|
||||
FUNNY_SEGOVR,
|
||||
FUNNY_REP,
|
||||
CANNOT_OPEN,
|
||||
CANNOT_READ,
|
||||
MALLOC_FAILED,
|
||||
NEWEXE_FORMAT,
|
||||
|
||||
#define USAGE 0
|
||||
#define INVALID_ARG 1
|
||||
#define INVALID_OPCODE 2
|
||||
#define INVALID_386OP 3
|
||||
#define FUNNY_SEGOVR 4
|
||||
#define FUNNY_REP 5
|
||||
#define CANNOT_OPEN 6
|
||||
#define CANNOT_READ 7
|
||||
#define MALLOC_FAILED 8
|
||||
#define NEWEXE_FORMAT 9
|
||||
|
||||
#define NO_BB 10
|
||||
#define INVALID_SYNTHETIC_BB 11
|
||||
#define INVALID_INT_BB 12
|
||||
#define IP_OUT_OF_RANGE 13
|
||||
#define DEF_NOT_FOUND 14
|
||||
#define JX_NOT_DEF 15
|
||||
#define NOT_DEF_USE 16
|
||||
#define REPEAT_FAIL 17
|
||||
#define WHILE_FAIL 18
|
||||
NO_BB,
|
||||
INVALID_SYNTHETIC_BB,
|
||||
INVALID_INT_BB,
|
||||
IP_OUT_OF_RANGE,
|
||||
DEF_NOT_FOUND,
|
||||
JX_NOT_DEF,
|
||||
NOT_DEF_USE,
|
||||
REPEAT_FAIL,
|
||||
WHILE_FAIL
|
||||
};
|
||||
|
||||
|
||||
void fatalError(Int errId, ...);
|
||||
void reportError(Int errId, ...);
|
||||
void fatalError(eErrorId errId, ...);
|
||||
void reportError(eErrorId errId, ...);
|
||||
|
||||
|
||||
@@ -294,13 +294,14 @@ struct LLTYPE
|
||||
dword op; /* idx of immed src op */
|
||||
struct { /* Call & # actual arg bytes */
|
||||
Function *proc; /* pointer to target proc (for CALL(F))*/
|
||||
int cb; /* # actual arg bytes */
|
||||
int cb; /* # actual arg bytes */
|
||||
} proc;
|
||||
} immed;
|
||||
DU flagDU; /* def/use of flags */
|
||||
struct { /* Case table if op==JMP && !I */
|
||||
Int numEntries; /* # entries in case table */
|
||||
dword *entries; /* array of offsets */
|
||||
|
||||
} caseTbl;
|
||||
Int hllLabNum; /* label # for hll codegen */
|
||||
bool conditionalJump()
|
||||
@@ -375,7 +376,7 @@ public:
|
||||
void SetLlInvalid(int ip, boolT fInv);
|
||||
dword GetLlLabel(int ip);
|
||||
llIcode GetLlOpcode(int ip);
|
||||
boolT labelSrch(dword target, Int *pIndex);
|
||||
bool labelSrch(dword target, dword &pIndex);
|
||||
ICODE * GetIcode(int ip);
|
||||
};
|
||||
typedef CIcodeRec::iterator iICODE;
|
||||
|
||||
@@ -34,7 +34,7 @@ typedef enum {
|
||||
TYPE_DOUBLE /* double precision float */
|
||||
} hlType;
|
||||
|
||||
static const char *hlTypes[13] = {"", "char", "unsigned char", "int", "unsigned int",
|
||||
static constexpr const char *hlTypes[13] = {"", "char", "unsigned char", "int", "unsigned int",
|
||||
"long", "unsigned long", "record", "int *", "char *",
|
||||
"", "float", "double"};
|
||||
|
||||
@@ -68,33 +68,33 @@ typedef struct
|
||||
/* ID, LOCAL_ID */
|
||||
struct ID
|
||||
{
|
||||
hlType type; /* Probable type */
|
||||
boolT illegal;/* Boolean: not a valid field any more */
|
||||
IDX_ARRAY idx; /* Index into icode array (REG_FRAME only) */
|
||||
frameType loc; /* Frame location */
|
||||
boolT 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 */
|
||||
} bwId;
|
||||
hlType type; /* Probable type */
|
||||
boolT illegal; /* Boolean: not a valid field any more */
|
||||
IDX_ARRAY idx; /* Index into icode array (REG_FRAME only) */
|
||||
frameType loc; /* Frame location */
|
||||
boolT 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 */
|
||||
} bwId;
|
||||
BWGLB_TYPE bwGlb; /* For TYPE_BYTE(WORD)_(UN)SIGN globals */
|
||||
LONGID_TYPE longId; /* For TYPE_LONG_(UN)SIGN registers */
|
||||
LONG_STKID_TYPE longStkId;/* For TYPE_LONG_(UN)SIGN on the stack */
|
||||
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 seg; /* segment value */
|
||||
int16 offH; /* offset high */
|
||||
int16 offL; /* offset low */
|
||||
byte regi; /* optional indexed register */
|
||||
} longGlb;
|
||||
struct { /* For TYPE_LONG_(UN)SIGN constants */
|
||||
struct { /* For TYPE_LONG_(UN)SIGN constants */
|
||||
dword h; /* high word */
|
||||
dword l; /* low word */
|
||||
} longKte;
|
||||
} id;
|
||||
} longKte;
|
||||
} id;
|
||||
ID()
|
||||
{
|
||||
memset(this,0,sizeof(ID));
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define bool unsigned char
|
||||
//#define bool unsigned char
|
||||
#define byte unsigned char
|
||||
#define word unsigned short
|
||||
|
||||
|
||||
@@ -3,36 +3,5 @@
|
||||
*/
|
||||
|
||||
#define LH(p) ((int)((byte *)(p))[0] + ((int)((byte *)(p))[1] << 8))
|
||||
|
||||
static void rm(Int i);
|
||||
static void modrm(Int i);
|
||||
static void segrm(Int i);
|
||||
static void data1(Int i);
|
||||
static void data2(Int i);
|
||||
static void regop(Int i);
|
||||
static void segop(Int i);
|
||||
static void strop(Int i);
|
||||
static void escop(Int i);
|
||||
static void axImp(Int i);
|
||||
static void alImp(Int i);
|
||||
static void axSrcIm(Int i);
|
||||
static void memImp(Int i);
|
||||
static void memReg0(Int i);
|
||||
static void memOnly(Int i);
|
||||
static void dispM(Int i);
|
||||
static void dispS(Int i);
|
||||
static void dispN(Int i);
|
||||
static void dispF(Int i);
|
||||
static void prefix(Int i);
|
||||
static void immed(Int i);
|
||||
static void shift(Int i);
|
||||
static void arith(Int i);
|
||||
static void trans(Int i);
|
||||
static void const1(Int i);
|
||||
static void const3(Int i);
|
||||
static void none1(Int i);
|
||||
static void none2(Int i);
|
||||
static void checkInt(Int i);
|
||||
|
||||
/* Extracts reg bits from middle of mod-reg-rm byte */
|
||||
#define REG(x) ((byte)(x & 0x38) >> 3)
|
||||
|
||||
Reference in New Issue
Block a user