From a0a6f7cc0e8b41c48369d733b08cc852a6cb07c6 Mon Sep 17 00:00:00 2001 From: Artur K Date: Wed, 29 Feb 2012 00:59:19 +0100 Subject: [PATCH] lots of small things --- include/BasicBlock.h | 68 +++++----- include/Enums.h | 60 +++++++++ include/IdentType.h | 24 ++-- include/Procedure.h | 62 ++++++--- include/StackFrame.h | 29 ++-- include/ast.h | 37 ++--- include/bundle.h | 4 +- include/dcc.h | 128 +++++++----------- include/dosdcc.h | 36 ++--- include/graph.h | 4 +- include/icode.h | 186 +++++++++++--------------- include/idioms/idiom1.h | 2 +- include/idioms/mov_idioms.h | 6 +- include/idioms/shift_idioms.h | 6 +- include/locident.h | 107 ++++++--------- include/perfhlib.h | 18 +-- include/scanner.h | 6 +- include/state.h | 19 +-- include/symtab.h | 6 +- include/types.h | 11 +- src/BasicBlock.cpp | 12 +- src/ast.cpp | 60 ++++----- src/backend.cpp | 36 ++--- src/bundle.cpp | 6 +- src/chklib.cpp | 108 +++++++-------- src/comwrite.cpp | 2 +- src/control.cpp | 42 +++--- src/dataflow.cpp | 182 +++++++++++++------------ src/disassem.cpp | 56 ++++---- src/error.cpp | 8 +- src/fixwild.cpp | 98 +++++++------- src/frontend.cpp | 128 +++++++++--------- src/graph.cpp | 30 ++--- src/hlicode.cpp | 39 +++--- src/icode.cpp | 14 +- src/idioms.cpp | 10 +- src/idioms/arith_idioms.cpp | 4 +- src/idioms/call_idioms.cpp | 6 +- src/idioms/epilogue_idioms.cpp | 4 +- src/idioms/idiom1.cpp | 6 +- src/idioms/mov_idioms.cpp | 10 +- src/idioms/neg_idioms.cpp | 2 +- src/idioms/shift_idioms.cpp | 10 +- src/locident.cpp | 67 ++++++---- src/parser.cpp | 207 ++++++++++++++-------------- src/perfhlib.cpp | 18 +-- src/procs.cpp | 22 +-- src/proplong.cpp | 18 +-- src/reducible.cpp | 18 +-- src/scanner.cpp | 238 ++++++++++++++++----------------- src/symtab.cpp | 16 +-- tests/prev_base/FIBOS.b | 3 +- 52 files changed, 1163 insertions(+), 1136 deletions(-) diff --git a/include/BasicBlock.h b/include/BasicBlock.h index f35cd5d..97e95c6 100644 --- a/include/BasicBlock.h +++ b/include/BasicBlock.h @@ -1,22 +1,24 @@ #pragma once #include #include +#include #include #include #include #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::iterator iICODE; +typedef std::list::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; - //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 inEdges; // does not own held pointers - //Int numOutEdges; /* Number of out edges */ + //int numOutEdges; /* Number of out edges */ std::vector 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 &dfsLast, Int *first, Int *last); + void dfsNumbering(std::vector &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; diff --git a/include/Enums.h b/include/Enums.h index e3bf1dd..761ac02 100644 --- a/include/Enums.h +++ b/include/Enums.h @@ -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 */ }; + diff --git a/include/IdentType.h b/include/IdentType.h index d13aca6..5a9c0ec 100644 --- a/include/IdentType.h +++ b/include/IdentType.h @@ -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; }; diff --git a/include/Procedure.h b/include/Procedure.h index ab89379..f301113 100644 --- a/include/Procedure.h +++ b/include/Procedure.h @@ -3,16 +3,18 @@ #include #include #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 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 m_cfg; /* Ptr. to BB list/CFG */ + std::list m_cfg; /* Ptr. to BB list/CFG */ std::vector m_dfsLast; - std::vector heldBBs; + std::list 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); }; diff --git a/include/StackFrame.h b/include/StackFrame.h index 6770685..89fed1b 100644 --- a/include/StackFrame.h +++ b/include/StackFrame.h @@ -1,20 +1,17 @@ #pragma once +#include +#include #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 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); }; diff --git a/include/ast.h b/include/ast.h index 6217ba2..f3b4c3f 100644 --- a/include/ast.h +++ b/include/ast.h @@ -5,10 +5,11 @@ * (C) Cristina Cifuentes */ #pragma once -static const int operandSize=20; #include +#include #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::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; -//}; - diff --git a/include/bundle.h b/include/bundle.h index af48ea8..1e74fae 100644 --- a/include/bundle.h +++ b/include/bundle.h @@ -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); diff --git a/include/dcc.h b/include/dcc.h index c659ed5..96933f0 100644 --- a/include/dcc.h +++ b/include/dcc.h @@ -5,7 +5,7 @@ #pragma once #include #include - +#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 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); diff --git a/include/dosdcc.h b/include/dosdcc.h index 84ccd96..f177938 100644 --- a/include/dosdcc.h +++ b/include/dosdcc.h @@ -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 diff --git a/include/graph.h b/include/graph.h index 9dca656..941a41e 100644 --- a/include/graph.h +++ b/include/graph.h @@ -63,8 +63,8 @@ typedef std::list 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 */ diff --git a/include/icode.h b/include/icode.h index 79feab2..70da9b9 100644 --- a/include/icode.h +++ b/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::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::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; diff --git a/include/idioms/idiom1.h b/include/idioms/idiom1.h index 5f6c543..43d3be1 100644 --- a/include/idioms/idiom1.h +++ b/include/idioms/idiom1.h @@ -5,7 +5,7 @@ struct Idiom1 : public Idiom protected: std::vector m_icodes; int m_min_off; - Int checkStkVars (iICODE pIcode); + int checkStkVars (iICODE pIcode); public: Idiom1(Function *f) : Idiom(f) { diff --git a/include/idioms/mov_idioms.h b/include/idioms/mov_idioms.h index bcdf390..3f550f7 100644 --- a/include/idioms/mov_idioms.h +++ b/include/idioms/mov_idioms.h @@ -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) diff --git a/include/idioms/shift_idioms.h b/include/idioms/shift_idioms.h index 65963bd..ac044c8 100644 --- a/include/idioms/shift_idioms.h +++ b/include/idioms/shift_idioms.h @@ -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) diff --git a/include/locident.h b/include/locident.h index 272b9fe..c3435ac 100644 --- a/include/locident.h +++ b/include/locident.h @@ -6,13 +6,19 @@ */ #pragma once +#include #include +#include #include #include -#include "icode.h" + +#include "Enums.h" + /* Type definition */ // this array has to stay in-order of addition i.e. not std::set > // TODO: why ? +struct ICODE; +typedef std::list::iterator iICODE; struct IDX_ARRAY : public std::vector { bool inList(iICODE idx) @@ -20,26 +26,12 @@ struct IDX_ARRAY : public std::vector 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 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); }; diff --git a/include/perfhlib.h b/include/perfhlib.h index 4cd4526..c5aa081 100644 --- a/include/perfhlib.h +++ b/include/perfhlib.h @@ -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 diff --git a/include/scanner.h b/include/scanner.h index 473a1c2..6cb181c 100644 --- a/include/scanner.h +++ b/include/scanner.h @@ -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) diff --git a/include/state.h b/include/state.h index 144da7b..532dfd9 100644 --- a/include/state.h +++ b/include/state.h @@ -3,26 +3,27 @@ * (C) Cristina Cifuentes, Mike van Emmerik ****************************************************************************/ #pragma once +#include #include -#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); } }; diff --git a/include/symtab.h b/include/symtab.h index 3293fad..02816dc 100644 --- a/include/symtab.h +++ b/include/symtab.h @@ -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 */ diff --git a/include/types.h b/include/types.h index f62b036..ba6dd62 100644 --- a/include/types.h +++ b/include/types.h @@ -5,17 +5,8 @@ #pragma once #include /**** 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 */ diff --git a/src/BasicBlock.cpp b/src/BasicBlock.cpp index 12995c5..f533d80 100644 --- a/src/BasicBlock.cpp +++ b/src/BasicBlock.cpp @@ -5,7 +5,7 @@ #include "Procedure.h" #include "dcc.h" using namespace std; -extern char *indent (Int indLevel); +extern char *indent (int indLevel); BB *BB::Create(void *ctx, const string &s, Function *parent, BB *insertBefore) { BB *pnewBB = new BB; @@ -13,7 +13,7 @@ BB *BB::Create(void *ctx, const string &s, Function *parent, BB *insertBefore) return pnewBB; } -BB *BB::Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function *parent) +BB *BB::Create(int start, int ip, uint8_t nodeType, int numOutEdges, Function *parent) { parent->m_cfg; BB* pnewBB; @@ -65,7 +65,7 @@ void BB::display() ****************************************************************************/ void BB::displayDfs() { - Int i; + int i; assert(this); traversed = DFS_DISP; @@ -114,9 +114,9 @@ void BB::displayDfs() * current procedure. * indLevel: indentation level - used for formatting. * numLoc: last # assigned to local variables */ -void BB::writeCode (Int indLevel, Function * pProc , Int *numLoc,Int latchNode, Int _ifFollow) +void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int latchNode, int _ifFollow) { - Int follow, /* ifFollow */ + int follow, /* ifFollow */ _loopType, /* Type of loop, if any */ _nodeType; /* Type of node */ BB * succ, *latch; /* Successor and latching node */ @@ -330,7 +330,7 @@ void BB::writeCode (Int indLevel, Function * pProc , Int *numLoc,Int latchNode, * Args: pBB: pointer to the current basic block. * Icode: pointer to the array of icodes for current procedure. * lev: indentation level - used for formatting. */ -void BB::writeBB(Int lev, Function * pProc, Int *numLoc) +void BB::writeBB(int lev, Function * pProc, int *numLoc) { /* Save the index into the code table in case there is a later goto * into this instruction (first instruction of the BB) */ diff --git a/src/ast.cpp b/src/ast.cpp index 54f6f49..b71f4dd 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -40,7 +40,7 @@ static char *hexStr (uint16_t i) /* Sets the du record for registers according to the du flag */ -void ICODE::setRegDU (byte regi, operDu du_in) +void ICODE::setRegDU (uint8_t regi, operDu du_in) { // printf("%s %d %x\n",__FUNCTION__,regi,int(du_in)); switch (du_in) @@ -120,10 +120,10 @@ COND_EXPR *COND_EXPR::unary(condNodeType t, COND_EXPR *sub_expr) /* Returns an identifier conditional expression node of type GLOB_VAR */ -COND_EXPR *COND_EXPR::idGlob (int16 segValue, int16 off) +COND_EXPR *COND_EXPR::idGlob (int16_t segValue, int16_t off) { COND_EXPR *newExp; - dword adr; + uint32_t adr; size_t i; newExp = new COND_EXPR(IDENTIFIER); @@ -140,7 +140,7 @@ COND_EXPR *COND_EXPR::idGlob (int16 segValue, int16 off) /* Returns an identifier conditional expression node of type REGISTER */ -COND_EXPR *COND_EXPR::idReg(byte regi, flags32 icodeFlg, LOCAL_ID *locsym) +COND_EXPR *COND_EXPR::idReg(uint8_t regi, uint32_t icodeFlg, LOCAL_ID *locsym) { COND_EXPR *newExp; @@ -151,7 +151,7 @@ COND_EXPR *COND_EXPR::idReg(byte regi, flags32 icodeFlg, LOCAL_ID *locsym) newExp->expr.ident.idNode.regiIdx = locsym->newByteWordReg(TYPE_BYTE_SIGN, regi); newExp->expr.ident.regiType = BYTE_REG; } - else /* word */ + else /* uint16_t */ { newExp->expr.ident.idNode.regiIdx = locsym->newByteWordReg( TYPE_WORD_SIGN, regi); newExp->expr.ident.regiType = WORD_REG; @@ -161,7 +161,7 @@ COND_EXPR *COND_EXPR::idReg(byte regi, flags32 icodeFlg, LOCAL_ID *locsym) /* Returns an identifier conditional expression node of type REGISTER */ -COND_EXPR *COND_EXPR::idRegIdx(Int idx, regType reg_type) +COND_EXPR *COND_EXPR::idRegIdx(int idx, regType reg_type) { COND_EXPR *newExp; @@ -173,7 +173,7 @@ COND_EXPR *COND_EXPR::idRegIdx(Int idx, regType reg_type) } /* Returns an identifier conditional expression node of type LOCAL_VAR */ -COND_EXPR *COND_EXPR::idLoc(Int off, LOCAL_ID *localId) +COND_EXPR *COND_EXPR::idLoc(int off, LOCAL_ID *localId) { COND_EXPR *newExp; size_t i; @@ -193,7 +193,7 @@ COND_EXPR *COND_EXPR::idLoc(Int off, LOCAL_ID *localId) /* Returns an identifier conditional expression node of type PARAM */ -COND_EXPR *COND_EXPR::idParam(Int off, const STKFRAME * argSymtab) +COND_EXPR *COND_EXPR::idParam(int off, const STKFRAME * argSymtab) { COND_EXPR *newExp; size_t i; @@ -211,7 +211,7 @@ COND_EXPR *COND_EXPR::idParam(Int off, const STKFRAME * argSymtab) /* Returns an identifier conditional expression node of type GLOB_VAR_IDX. * This global variable is indexed by regi. */ -COND_EXPR *idCondExpIdxGlob (int16 segValue, int16 off, byte regi, const LOCAL_ID *locSym) +COND_EXPR *idCondExpIdxGlob (int16_t segValue, int16_t off, uint8_t regi, const LOCAL_ID *locSym) { COND_EXPR *newExp; size_t i; @@ -231,7 +231,7 @@ COND_EXPR *idCondExpIdxGlob (int16 segValue, int16 off, byte regi, const LOCAL_I /* Returns an identifier conditional expression node of type CONSTANT */ -COND_EXPR *COND_EXPR::idKte(dword kte, byte size) +COND_EXPR *COND_EXPR::idKte(uint32_t kte, uint8_t size) { COND_EXPR *newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = CONSTANT; @@ -243,7 +243,7 @@ COND_EXPR *COND_EXPR::idKte(dword kte, byte size) /* Returns an identifier conditional expression node of type LONG_VAR, * that points to the given index idx. */ -COND_EXPR *COND_EXPR::idLongIdx (Int idx) +COND_EXPR *COND_EXPR::idLongIdx (int idx) { COND_EXPR *newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = LONG_VAR; @@ -253,9 +253,9 @@ COND_EXPR *COND_EXPR::idLongIdx (Int idx) /* Returns an identifier conditional expression node of type LONG_VAR */ -COND_EXPR *COND_EXPR::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, Int off) +COND_EXPR *COND_EXPR::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, int off) { - Int idx; + int idx; COND_EXPR *newExp = new COND_EXPR(IDENTIFIER); /* Check for long constant and save it as a constant expression */ if ((sd == SRC) && ((pIcode->ic.ll.flg & I) == I)) /* constant */ @@ -298,7 +298,7 @@ COND_EXPR *COND_EXPR::idFunc(Function * pproc, STKFRAME * args) /* Returns an identifier conditional expression node of type OTHER. * Temporary solution, should really be encoded as an indexed type (eg. * arrays). */ -COND_EXPR *COND_EXPR::idOther(byte seg, byte regi, int16 off) +COND_EXPR *COND_EXPR::idOther(uint8_t seg, uint8_t regi, int16_t off) { COND_EXPR *newExp; @@ -316,7 +316,7 @@ COND_EXPR *COND_EXPR::idOther(byte seg, byte regi, int16 off) COND_EXPR *COND_EXPR::idID (const ID *retVal, LOCAL_ID *locsym, iICODE ix_) { COND_EXPR *newExp; - Int idx; + int idx; newExp = new COND_EXPR(IDENTIFIER); if (retVal->type == TYPE_LONG_SIGN) @@ -344,7 +344,7 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, iICODE { COND_EXPR *newExp; - Int idx; /* idx into pIcode->localId table */ + int idx; /* idx into pIcode->localId table */ const LLOperand &pm((sd == SRC) ? pIcode.ic.ll.src : pIcode.ic.ll.dst); @@ -451,13 +451,13 @@ condId ICODE::idType(opLoc sd) /* Size of hl types */ -Int hlSize[] = {2, 1, 1, 2, 2, 4, 4, 4, 2, 2, 1, 4, 4}; +int hlSize[] = {2, 1, 1, 2, 2, 4, 4, 4, 2, 2, 1, 4, 4}; /* Returns the type of the expression */ -Int hlTypeSize (const COND_EXPR *expr, Function * pproc) +int hlTypeSize (const COND_EXPR *expr, Function * pproc) { - Int first, second; + int first, second; if (expr == NULL) return (2); /* for TYPE_UNKNOWN */ @@ -578,10 +578,10 @@ hlType expType (const COND_EXPR *expr, Function * pproc) /* Removes the register from the tree. If the register was part of a long * register (eg. dx:ax), the node gets transformed into an integer register * node. */ -void HlTypeSupport::performLongRemoval (byte regi, LOCAL_ID *locId, COND_EXPR *tree) +void HlTypeSupport::performLongRemoval (uint8_t regi, LOCAL_ID *locId, COND_EXPR *tree) { IDENTTYPE* ident; /* ptr to an identifier */ - byte otherRegi; /* high or low part of long register */ + uint8_t otherRegi; /* high or low part of long register */ switch (tree->type) { case BOOLEAN_OP: @@ -606,10 +606,10 @@ void HlTypeSupport::performLongRemoval (byte regi, LOCAL_ID *locId, COND_EXPR *t /* Returns the string located in image, formatted in C format. */ -static std::string getString (Int offset) +static std::string getString (int offset) { ostringstream o; - Int strLen, i; + int strLen, i; strLen = strSize (&prog.Image[offset], '\0'); o << '"'; @@ -621,9 +621,9 @@ static std::string getString (Int offset) /* Walks the conditional expression tree and returns the result on a string */ -string walkCondExpr (const COND_EXPR* expr, Function * pProc, Int* numLoc) +string walkCondExpr (const COND_EXPR* expr, Function * pProc, int* numLoc) { - int16 off; /* temporal - for OTHER */ + int16_t off; /* temporal - for OTHER */ ID* id; /* Pointer to local identifier table */ //char* o; /* Operand string pointer */ bool needBracket; /* Determine whether parenthesis is needed */ @@ -828,9 +828,9 @@ void COND_EXPR::changeBoolOp (condOp newOp) /* Inserts the expression exp into the tree at the location specified by the * register regi */ -bool insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, byte regi,LOCAL_ID *locsym) +bool insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, uint8_t regi,LOCAL_ID *locsym) { - byte treeReg; + uint8_t treeReg; if (*tree == NULL) return FALSE; @@ -840,12 +840,12 @@ bool insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, byte regi,LOCAL_ID *lo if ((*tree)->expr.ident.idType == REGISTER) { treeReg = locsym->id_arr[(*tree)->expr.ident.idNode.regiIdx].id.regi; - if (treeReg == regi) /* word reg */ + if (treeReg == regi) /* uint16_t reg */ { *tree = expr; return TRUE; } - else if ((regi >= rAX) && (regi <= rBX)) /* word/byte reg */ + else if ((regi >= rAX) && (regi <= rBX)) /* uint16_t/uint8_t reg */ { if ((treeReg == (regi + rAL-1)) || (treeReg == (regi + rAH-1))) { @@ -876,7 +876,7 @@ bool insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, byte regi,LOCAL_ID *lo /* Inserts the expression exp into the tree at the location specified by the * long register index longIdx*/ -bool insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR **tree, Int longIdx) +bool insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR **tree, int longIdx) { switch ((*tree)->type) { diff --git a/src/backend.cpp b/src/backend.cpp index f07634b..4fc468f 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -22,16 +22,16 @@ static char indentBuf[indSize] = /* Indentation according to the depth of the statement */ -char *indent (Int indLevel) +char *indent (int indLevel) { return (&indentBuf[indSize-(indLevel*4)-1]); } /* Returns a unique index to the next label */ -Int getNextLabel() +int getNextLabel() { - static Int labelIdx = 1; /* index of the next label */ + static int labelIdx = 1; /* index of the next label */ return (labelIdx++); } @@ -58,7 +58,7 @@ static void fixupLabels (PPROC pProc) * a unique label number for it. This label is placed in the associated * icode for the node (pProc->Icode). The procedure is done in sequential * order of dsfLast numbering. */ -{ Int i; /* index into the dfsLast array */ +{ int i; /* index into the dfsLast array */ PBB *dfsLast; /* pointer to the dfsLast array */ dfsLast = pProc->dfsLast; @@ -73,7 +73,7 @@ static void fixupLabels (PPROC pProc) /* Returns the corresponding C string for the given character c. Character * constants such as carriage return and line feed, require 2 C characters. */ -char *cChar (byte c) +char *cChar (uint8_t c) { static char res[3]; @@ -106,19 +106,19 @@ char *cChar (byte c) * exe file: prog.Image[operand+0x100] */ static void printGlobVar (SYM * psym) { - Int j; - dword relocOp = prog.fCOM ? psym->label : psym->label + 0x100; + int j; + uint32_t relocOp = prog.fCOM ? psym->label : psym->label + 0x100; char *strContents; /* initial contents of variable */ switch (psym->size) { - case 1: cCode.appendDecl( "byte\t%s = %ld;\n", + case 1: cCode.appendDecl( "uint8_t\t%s = %ld;\n", psym->name, prog.Image[relocOp]); break; - case 2: cCode.appendDecl( "word\t%s = %ld;\n", + case 2: cCode.appendDecl( "uint16_t\t%s = %ld;\n", psym->name, LH(prog.Image+relocOp)); break; case 4: if (psym->type == TYPE_PTR) /* pointer */ - cCode.appendDecl( "word\t*%s = %ld;\n", + cCode.appendDecl( "uint16_t\t*%s = %ld;\n", psym->name, LH(prog.Image+relocOp)); else /* char */ cCode.appendDecl( @@ -144,7 +144,7 @@ static void printGlobVar (SYM * psym) * initialization. */ static void writeGlobSymTable() { - Int idx; + int idx; char type[10]; SYM * pSym; @@ -158,7 +158,7 @@ static void writeGlobSymTable() printGlobVar (&symtab[idx]); else { /* first defined */ switch (pSym->size) { - case 1: strcpy (type, "byte\t"); break; + case 1: strcpy (type, "uint8_t\t"); break; case 2: strcpy (type, "int\t"); break; case 4: if (pSym->type == TYPE_PTR) strcpy (type, "int\t*"); @@ -195,9 +195,9 @@ static void writeHeader (std::ostream &ios, char *fileName) /* Writes the registers that are set in the bitvector */ -static void writeBitVector (dword regi) +static void writeBitVector (uint32_t regi) { - Int j; + int j; for (j = 0; j < INDEXBASE; j++) { @@ -206,7 +206,7 @@ static void writeBitVector (dword regi) } } static void writeBitVector (const std::bitset<32> ®i) -{ Int j; +{ int j; for (j = 0; j < INDEXBASE; j++) { @@ -223,7 +223,7 @@ static void writeBitVector (const std::bitset<32> ®i) * is created and a goto is also emitted. * Note: this procedure is to be used when the label is to be forward on * the code; that is, the target code has not been traversed yet. */ -static void emitFwdGotoLabel (ICODE * pt, Int indLevel) +static void emitFwdGotoLabel (ICODE * pt, int indLevel) { if (! (pt->ic.ll.flg & HLL_LABEL)) /* node hasn't got a lab */ { @@ -240,7 +240,7 @@ static void emitFwdGotoLabel (ICODE * pt, Int indLevel) * and invokes the procedure that writes the code of the given record *hli */ void Function::codeGen (std::ostream &fs) { - Int i, numLoc; + int i, numLoc; //STKFRAME * args; /* Procedure arguments */ char buf[200], /* Procedure's definition */ arg[30]; /* One argument */ @@ -339,7 +339,7 @@ void Function::codeGen (std::ostream &fs) * of the call graph. */ static void backBackEnd (char *filename, CALL_GRAPH * pcallGraph, std::ostream &ios) { - Int i; + int i; // IFace.Yield(); /* This is a good place to yield to other apps */ diff --git a/src/bundle.cpp b/src/bundle.cpp index b992057..1c03f13 100644 --- a/src/bundle.cpp +++ b/src/bundle.cpp @@ -21,7 +21,7 @@ void newBundle (bundle *) /* Returns the next available index into the table */ -Int nextBundleIdx (strTable *strTab) +int nextBundleIdx (strTable *strTab) { return (strTab->size()); } @@ -29,7 +29,7 @@ Int nextBundleIdx (strTable *strTab) /* Adds the given label to the start of the line strTab[idx]. The first * tab is removed and replaced by this label */ -void addLabelBundle (strTable &strTab, Int idx, Int label) +void addLabelBundle (strTable &strTab, int idx, int label) { char s[lineSize]; sprintf (s, "l%ld: %s", label, strTab[idx].c_str()+4); @@ -40,7 +40,7 @@ void addLabelBundle (strTable &strTab, Int idx, Int label) /* Writes the contents of the string table on the file fp. */ static void writeStrTab (std::ostream &ios, strTable &strTab) { - Int i; + int i; for (i = 0; i < strTab.size(); i++) ios << strTab[i]; diff --git a/src/chklib.cpp b/src/chklib.cpp index f5b9e74..5a18a47 100644 --- a/src/chklib.cpp +++ b/src/chklib.cpp @@ -22,7 +22,7 @@ typedef struct HT_tag { char htSym[SYMLEN]; - byte htPat[PATLEN]; + uint8_t htPat[PATLEN]; } HT; /* Structure of the prototypes table. Same as the struct in parsehdr.h, @@ -51,8 +51,8 @@ unsigned SymLen; /* Max size of the symbols, including null */ FILE *f; /* File being read */ static char sSigName[100]; /* Full path name of .sig file */ -static word *T1base, *T2base; /* Pointers to start of T1, T2 */ -static word *g; /* g[] */ +static uint16_t *T1base, *T2base; /* Pointers to start of T1, T2 */ +static uint16_t *g; /* g[] */ static HT *ht; /* The hash table */ static PH_FUNC_STRUCT *pFunc; /* Points to the array of func names */ static hlType *pArg=0; /* Points to the array of param types */ @@ -62,8 +62,8 @@ static int numArg; /* Number of param names actually stored /* prototypes */ void grab(int n, FILE *f); -word readFileShort(FILE *f); -void readFileSection(word* p, int len, FILE *f); +uint16_t readFileShort(FILE *f); +void readFileSection(uint16_t* p, int len, FILE *f); void cleanup(void); void checkStartup(STATE *state); void readProtoFile(void); @@ -71,17 +71,17 @@ void fixNewline(char *s); int searchPList(char *name); void checkHeap(char *msg); /* For debugging */ -void fixWildCards(byte pat[]); /* In fixwild.c */ +void fixWildCards(uint8_t pat[]); /* In fixwild.c */ -static boolT locatePattern(byte *source, Int iMin, Int iMax, byte *pattern, - Int iPatLen, Int *index); +static boolT locatePattern(uint8_t *source, int iMin, int iMax, uint8_t *pattern, + int iPatLen, int *index); /* * * * * * * * * * * * * * * *\ * * * S t a r t P a t t e r n s ( V e n d o r i d ) * * * \* * * * * * * * * * * * * * * */ -static byte pattMsC5Start[] = +static uint8_t pattMsC5Start[] = { 0xB4, 0x30, /* Mov ah, 30 */ 0xCD, 0x21, /* int 21 (dos version number) */ @@ -90,7 +90,7 @@ static byte pattMsC5Start[] = 0xCD, 0x20, /* int 20 (exit) */ 0xBF /* Mov di, DSEG */ }; -static byte pattMsC8Start[] = +static uint8_t pattMsC8Start[] = { 0xB4, 0x30, /* Mov ah, 30 */ 0xCD, 0x21, /* int 21 */ @@ -101,7 +101,7 @@ static byte pattMsC8Start[] = 0xCB, /* retf */ 0xBF /* mov di, DSEG */ }; -static byte pattMsC8ComStart[] = +static uint8_t pattMsC8ComStart[] = { 0xB4, 0x30, /* Mov ah, 30 */ 0xCD, 0x21, /* int 21 (dos version number) */ @@ -110,7 +110,7 @@ static byte pattMsC8ComStart[] = 0xC3, /* ret */ 0x8C, 0xDF /* Mov di, ds */ }; -static byte pattBorl2Start[] = +static uint8_t pattBorl2Start[] = { 0xBA, WILD, WILD, /* Mov dx, dseg */ 0x2E, 0x89, 0x16, /* mov cs:[], dx */ @@ -126,7 +126,7 @@ static byte pattBorl2Start[] = 0x89, 0x2E, WILD, WILD, /* mov [xx], bp */ 0xC7 /* mov [xx], -1 */ }; -static byte pattBorl3Start[] = +static uint8_t pattBorl3Start[] = { 0xBA, WILD, WILD, /* Mov dx, dseg */ 0x2E, 0x89, 0x16, /* mov cs:[], dx */ @@ -143,12 +143,12 @@ static byte pattBorl3Start[] = 0xE8 /* call ... */ }; -static byte pattBorl4on[] = +static uint8_t pattBorl4on[] = { 0x9A, 0, 0, WILD, WILD /* Call init (offset always 0) */ }; -static byte pattBorl4Init[] = +static uint8_t pattBorl4Init[] = { 0xBA, WILD, WILD, /* Mov dx, dseg */ 0x8E, 0xDA, /* mov ds, dx */ @@ -160,7 +160,7 @@ static byte pattBorl4Init[] = 0x8C, 0xD2 /* mov dx, ss */ }; -static byte pattBorl5Init[] = +static uint8_t pattBorl5Init[] = { 0xBA, WILD, WILD, /* Mov dx, dseg */ 0x8E, 0xDA, /* mov ds, dx */ @@ -173,7 +173,7 @@ static byte pattBorl5Init[] = 0x8C, 0xD2 /* mov dx, ss */ }; -static byte pattBorl7Init[] = +static uint8_t pattBorl7Init[] = { 0xBA, WILD, WILD, /* Mov dx, dseg */ 0x8E, 0xDA, /* mov ds, dx */ @@ -188,7 +188,7 @@ static byte pattBorl7Init[] = }; -static byte pattLogiStart[] = +static uint8_t pattLogiStart[] = { 0xEB, 0x04, /* jmp short $+6 */ WILD, WILD, /* Don't know what this is */ @@ -197,7 +197,7 @@ static byte pattLogiStart[] = 0x8E, 0xD8 /* mov ds, ax */ }; -static byte pattTPasStart[] = +static uint8_t pattTPasStart[] = { 0xE9, 0x79, 0x2C /* Jmp 2D7C - Turbo pascal 3.0 */ }; @@ -212,7 +212,7 @@ static byte pattTPasStart[] = /* This pattern works for MS and Borland, small and tiny model */ -static byte pattMainSmall[] = +static uint8_t pattMainSmall[] = { 0xFF, 0x36, WILD, WILD, /* Push environment pointer */ 0xFF, 0x36, WILD, WILD, /* Push argv */ @@ -225,7 +225,7 @@ static byte pattMainSmall[] = #define OFFMAINSMALL 13 /* This pattern works for MS and Borland, medium model */ -static byte pattMainMedium[] = +static uint8_t pattMainMedium[] = { 0xFF, 0x36, WILD, WILD, /* Push environment pointer */ 0xFF, 0x36, WILD, WILD, /* Push argv */ @@ -239,7 +239,7 @@ static byte pattMainMedium[] = #define OFFMAINMEDIUM 13 /* This pattern works for MS and Borland, compact model */ -static byte pattMainCompact[] = +static uint8_t pattMainCompact[] = { 0xFF, 0x36, WILD, WILD, /* Push environment pointer lo */ 0xFF, 0x36, WILD, WILD, /* Push environment pointer hi */ @@ -254,7 +254,7 @@ static byte pattMainCompact[] = #define OFFMAINCOMPACT 21 /* This pattern works for MS and Borland, large model */ -static byte pattMainLarge[] = +static uint8_t pattMainLarge[] = { 0xFF, 0x36, WILD, WILD, /* Push environment pointer lo */ 0xFF, 0x36, WILD, WILD, /* Push environment pointer hi */ @@ -277,7 +277,7 @@ static byte pattMainLarge[] = \* * * * * * * * * * * * * * * */ /* This pattern is for the stack check code in Microsoft compilers */ -static byte pattMsChkstk[] = +static uint8_t pattMsChkstk[] = { 0x59, /* pop cx */ 0x8B, 0xDC, /* mov bx, sp */ @@ -297,7 +297,7 @@ static byte pattMsChkstk[] = /* This procedure is called to initialise the library check code */ void SetupLibCheck(void) { - word w, len; + uint16_t w, len; int i; if ((f = fopen(sSigName, "rb")) == NULL) @@ -348,7 +348,7 @@ void SetupLibCheck(void) printf("Expected 'T1'\n"); exit(3); } - len = (word) (PatLen * 256 * sizeof(word)); + len = (uint16_t) (PatLen * 256 * sizeof(uint16_t)); w = readFileShort(f); if (w != len) { @@ -378,7 +378,7 @@ void SetupLibCheck(void) printf("Expected 'gg'\n"); exit(3); } - len = (word)(numVert * sizeof(word)); + len = (uint16_t)(numVert * sizeof(uint16_t)); w = readFileShort(f); if (w != len) { @@ -403,7 +403,7 @@ void SetupLibCheck(void) exit(3); } w = readFileShort(f); - if (w != numKeys * (SymLen + PatLen + sizeof(word))) + if (w != numKeys * (SymLen + PatLen + sizeof(uint16_t))) { printf("Problem with size of hash table: file %d, calc %d\n", w, len); exit(6); @@ -438,8 +438,8 @@ bool LibCheck(Function & pProc) { long fileOffset; int h, i, j, arg; - Int Idx; - byte pat[PATLEN]; + int Idx; + uint8_t pat[PATLEN]; if (prog.bSigs == FALSE) { @@ -537,10 +537,10 @@ void grab(int n, FILE *f) } } -word +uint16_t readFileShort(FILE *f) { - byte b1, b2; + uint8_t b1, b2; if (fread(&b1, 1, 1, f) != 1) { @@ -552,12 +552,12 @@ readFileShort(FILE *f) printf("Could not read short\n"); exit(11); } - return (word)(b2 << 8) + (word)b1; + return (uint16_t)(b2 << 8) + (uint16_t)b1; } // Read a section of the file, considering endian issues void -readFileSection(word* p, int len, FILE* f) +readFileSection(uint16_t* p, int len, FILE* f) { for (int i=0; i < len; i += 2) { @@ -566,7 +566,7 @@ readFileSection(word* p, int len, FILE* f) } /* The following two functions are dummies, since we don't call map() */ -void getKey(int i, byte **keys) +void getKey(int i, uint8_t **keys) { } @@ -578,16 +578,16 @@ void dispKey(int i) /* Search the source array between limits iMin and iMax for the pattern (length iPatLen). The pattern can contain wild bytes; if you really want to match - for the pattern that is used up by the WILD byte, tough - it will match with + for the pattern that is used up by the WILD uint8_t, tough - it will match with everything else as well. */ -static boolT locatePattern(byte *source, Int iMin, Int iMax, byte *pattern, Int iPatLen, - Int *index) +static boolT locatePattern(uint8_t *source, int iMin, int iMax, uint8_t *pattern, int iPatLen, + int *index) { - Int i, j; - byte *pSrc; /* Pointer to start of considered source */ - Int iLast; + int i, j; + uint8_t *pSrc; /* Pointer to start of considered source */ + int iLast; - iLast = iMax - iPatLen; /* Last source byte to consider */ + iLast = iMax - iPatLen; /* Last source uint8_t to consider */ for (i=iMin; i <= iLast; i++) { @@ -595,7 +595,7 @@ static boolT locatePattern(byte *source, Int iMin, Int iMax, byte *pattern, Int /* i is the index of the start of the moving pattern */ for (j=0; j < iPatLen; j++) { - /* j is the index of the byte being considered in the pattern. */ + /* j is the index of the uint8_t being considered in the pattern. */ if ((*pSrc != pattern[j]) && (pattern[j] != WILD)) { /* A definite mismatch */ @@ -625,15 +625,15 @@ void STATE::checkStartup() Also sets prog.offMain and prog.segMain if possible */ - Int startOff; /* Offset into the Image of the initial CS:IP */ - Int i, rel, para, init; + int startOff; /* Offset into the Image of the initial CS:IP */ + int i, rel, para, init; char chModel = 'x'; char chVendor = 'x'; char chVersion = 'x'; char *pPath; char temp[4]; - startOff = ((dword)prog.initCS << 4) + prog.initIP; + startOff = ((uint32_t)prog.initCS << 4) + prog.initIP; /* Check the Turbo Pascal signatures first, since they involve only the first 3 bytes, and false positives may be founf with the others later */ @@ -643,7 +643,7 @@ void STATE::checkStartup() determine the version from that */ rel = LH(&prog.Image[startOff+1]); /* This is abs off of init */ para= LH(&prog.Image[startOff+3]);/* This is abs seg of init */ - init = ((dword)para << 4) + rel; + init = ((uint32_t)para << 4) + rel; if (locatePattern(prog.Image, init, init+26, pattBorl4Init, sizeof(pattBorl4Init), &i)) { @@ -654,7 +654,7 @@ void STATE::checkStartup() chModel = 'p'; /* Pascal */ chVersion = '4'; /* Version 4 */ prog.offMain = startOff; /* Code starts immediately */ - prog.segMain = prog.initCS; /* At the 5 byte jump */ + prog.segMain = prog.initCS; /* At the 5 uint8_t jump */ goto gotVendor; /* Already have vendor */ } else if (locatePattern(prog.Image, init, init+26, pattBorl5Init, @@ -698,8 +698,8 @@ void STATE::checkStartup() rel = LH(&prog.Image[i+OFFMAINLARGE]); /* This is abs off of main */ para= LH(&prog.Image[i+OFFMAINLARGE+2]);/* This is abs seg of main */ /* Save absolute image offset */ - prog.offMain = ((dword)para << 4) + rel; - prog.segMain = (word)para; + prog.offMain = ((uint32_t)para << 4) + rel; + prog.segMain = (uint16_t)para; chModel = 'l'; /* Large model */ } else if (locatePattern(prog.Image, startOff, startOff+0x180, pattMainCompact, @@ -715,8 +715,8 @@ void STATE::checkStartup() { rel = LH(&prog.Image[i+OFFMAINMEDIUM]); /* This is abs off of main */ para= LH(&prog.Image[i+OFFMAINMEDIUM+2]);/* This is abs seg of main */ - prog.offMain = ((dword)para << 4) + rel; - prog.segMain = (word)para; + prog.offMain = ((uint32_t)para << 4) + rel; + prog.segMain = (uint16_t)para; chModel = 'm'; /* Medium model */ } else if (locatePattern(prog.Image, startOff, startOff+0x180, pattMainSmall, @@ -787,7 +787,7 @@ void STATE::checkStartup() else if (locatePattern(prog.Image, startOff, startOff+0x30, pattBorl2Start, sizeof(pattBorl2Start), &i)) { - /* Borland startup. DS is at the second byte (offset 1) */ + /* Borland startup. DS is at the second uint8_t (offset 1) */ setState( rDS, LH(&prog.Image[i+1])); printf("Borland v2 detected\n"); chVendor = 'b'; /* Borland compiler */ @@ -797,7 +797,7 @@ void STATE::checkStartup() else if (locatePattern(prog.Image, startOff, startOff+0x30, pattBorl3Start, sizeof(pattBorl3Start), &i)) { - /* Borland startup. DS is at the second byte (offset 1) */ + /* Borland startup. DS is at the second uint8_t (offset 1) */ setState( rDS, LH(&prog.Image[i+1])); printf("Borland v3 detected\n"); chVendor = 'b'; /* Borland compiler */ diff --git a/src/comwrite.cpp b/src/comwrite.cpp index e995be8..91584ba 100644 --- a/src/comwrite.cpp +++ b/src/comwrite.cpp @@ -113,7 +113,7 @@ static const char *int21h[] = "Reserved", "Reserved", "Get PSP address", - "Get DBCS lead byte table", + "Get DBCS lead uint8_t table", "Reserved", "Get extended country information", "Get or set code page", diff --git a/src/control.cpp b/src/control.cpp index 27b64d7..c2ca851 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -15,10 +15,10 @@ #endif //typedef struct list { -// Int nodeIdx; +// int nodeIdx; // struct list *next; //} nodeList; -typedef std::list nodeList; /* dfsLast index to the node */ +typedef std::list nodeList; /* dfsLast index to the node */ #define ancestor(a,b) ((a->dfsLastNum < b->dfsLastNum) && (a->dfsFirstNum < b->dfsFirstNum)) /* there is a path on the DFST from a to b if the a was first visited in a @@ -43,7 +43,7 @@ static boolT isBackEdge (BB * p,BB * s) /* Finds the common dominator of the current immediate dominator * currImmDom and its predecessor's immediate dominator predImmDom */ -static Int commonDom (Int currImmDom, Int predImmDom, Function * pProc) +static int commonDom (int currImmDom, int predImmDom, Function * pProc) { if (currImmDom == NO_DOM) return (predImmDom); @@ -69,7 +69,7 @@ static Int commonDom (Int currImmDom, Int predImmDom, Function * pProc) void Function::findImmedDom () { BB * currNode; - Int currIdx, j, predIdx; + int currIdx, j, predIdx; for (currIdx = 0; currIdx < numBBs; currIdx++) { @@ -87,7 +87,7 @@ void Function::findImmedDom () /* Inserts the node n to the list l. */ -static void insertList (nodeList &l, Int n) +static void insertList (nodeList &l, int n) { l.push_back(n); } @@ -95,7 +95,7 @@ static void insertList (nodeList &l, Int n) /* Returns whether or not the node n (dfsLast numbering of a basic block) * is on the list l. */ -static boolT inList (nodeList &l, Int n) +static boolT inList (nodeList &l, int n) { return std::find(l.begin(),l.end(),n)!=l.end(); } @@ -119,7 +119,7 @@ static boolT inInt(BB * n, queue &q) * The follow node is the closest node to the loop. */ static void findEndlessFollow (Function * pProc, nodeList &loopNodes, BB * head) { - Int j, succ; + int j, succ; head->loopFollow = MAX; nodeList::iterator p = loopNodes.begin(); @@ -140,9 +140,9 @@ static void findEndlessFollow (Function * pProc, nodeList &loopNodes, BB * head) * determines the type of loop. */ static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &intNodes) { - Int i, headDfsNum, intNodeType; + int i, headDfsNum, intNodeType; nodeList loopNodes; - Int immedDom, /* dfsLast index to immediate dominator */ + int immedDom, /* dfsLast index to immediate dominator */ thenDfs, elseDfs; /* dsfLast index for THEN and ELSE nodes */ BB * pbb; @@ -248,10 +248,10 @@ static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &int freeList(loopNodes); } -//static void findNodesInInt (queue **intNodes, Int level, interval *Ii) +//static void findNodesInInt (queue **intNodes, int level, interval *Ii) /* Recursive procedure to find nodes that belong to the interval (ie. nodes * from G1). */ -static void findNodesInInt (queue &intNodes, Int level, interval *Ii) +static void findNodesInInt (queue &intNodes, int level, interval *Ii) { if (level == 1) { @@ -271,7 +271,7 @@ void Function::structLoops(derSeq *derivedG) BB * intHead, /* interval header node */ * pred, /* predecessor node */ * latchNode;/* latching node (in case of loops) */ - Int i, /* counter */ + int i, /* counter */ level = 0; /* derived sequence level */ interval *initInt; /* initial interval */ queue intNodes; /* list of interval nodes */ @@ -337,9 +337,9 @@ void Function::structLoops(derSeq *derivedG) /* Returns whether the BB indexed by s is a successor of the BB indexed by * h. Note that h is a case node. */ -static boolT successor (Int s, Int h, Function * pProc) +static boolT successor (int s, int h, Function * pProc) { - Int i; + int i; BB * header; header = pProc->m_dfsLast[h]; @@ -353,8 +353,8 @@ static boolT successor (Int s, Int h, Function * pProc) /* Recursive procedure to tag nodes that belong to the case described by * the list l, head and tail (dfsLast index to first and exit node of the * case). */ -static void tagNodesInCase (BB * pBB, nodeList &l, Int head, Int tail) -{ Int current, /* index to current node */ +static void tagNodesInCase (BB * pBB, nodeList &l, int head, int tail) +{ int current, /* index to current node */ i; pBB->traversed = DFS_CASE; @@ -374,9 +374,9 @@ static void tagNodesInCase (BB * pBB, nodeList &l, Int head, Int tail) * has a case node. */ void Function::structCases() { - Int i, j; + int i, j; BB * caseHeader; /* case header node */ - Int exitNode = NO_NODE; /* case exit node */ + int exitNode = NO_NODE; /* case exit node */ nodeList caseNodes; /* temporary: list of nodes in case */ /* Linear scan of the nodes in reverse dfsLast order, searching for @@ -417,7 +417,7 @@ void Function::structCases() /* Flags all nodes in the list l as having follow node f, and deletes all * nodes from the list. */ -static void flagNodes (nodeList &l, Int f, Function * pProc) +static void flagNodes (nodeList &l, int f, Function * pProc) { nodeList::iterator p; @@ -433,7 +433,7 @@ static void flagNodes (nodeList &l, Int f, Function * pProc) /* Structures if statements */ void Function::structIfs () { - Int curr, /* Index for linear scan of nodes */ + int curr, /* Index for linear scan of nodes */ desc, /* Index for descendant */ followInEdges, /* Largest # in-edges so far */ follow; /* Possible follow node */ @@ -491,7 +491,7 @@ void Function::structIfs () * into one block with the appropriate condition */ void Function::compoundCond() { - Int i, j, k, numOutEdges; + int i, j, k, numOutEdges; BB * pbb, * t, * e, * obb,* pred; ICODE * picode, * ticode; COND_EXPR *exp; diff --git a/src/dataflow.cpp b/src/dataflow.cpp index cbe3bea..f3fcc7c 100644 --- a/src/dataflow.cpp +++ b/src/dataflow.cpp @@ -18,7 +18,7 @@ struct ExpStack void init(); void push(COND_EXPR *); COND_EXPR * pop(); - Int numElem(); + int numElem(); boolT empty(); }; /*************************************************************************** @@ -53,7 +53,7 @@ COND_EXPR *ExpStack::pop() } /* Returns the number of elements available in the expression stack */ -Int ExpStack::numElem() +int ExpStack::numElem() { return expStk.size(); } @@ -69,9 +69,9 @@ ExpStack g_exp_stk; /* Returns the index of the local variable or parameter at offset off, if it * is in the stack frame provided. */ -Int STKFRAME::getLocVar(Int off) +int STKFRAME::getLocVar(int off) { - Int i; + int i; for (i = 0; i < sym.size(); i++) if (sym[i].off == off) @@ -102,16 +102,13 @@ static COND_EXPR *dstIdent (const ICODE & Icode, Function * pProc, iICODE i, ICO /** Is it needed? (pIcode->ic.ll.flg) & NO_SRC_B **/ return (n); } - - - /* Eliminates all condition codes and generates new hlIcode instructions */ void Function::elimCondCodes () { - Int i; + int i; - byte use; /* Used flags bit vector */ - byte def; /* Defined flags bit vector */ + uint8_t use; /* Used flags bit vector */ + uint8_t def; /* Defined flags bit vector */ boolT notSup; /* Use/def combination not supported */ COND_EXPR *rhs; /* Source operand */ COND_EXPR *lhs; /* Destination operand */ @@ -127,9 +124,7 @@ void Function::elimCondCodes () for (useAt = pBB->rbegin2(); useAt != pBB->rend2(); useAt++) { - if ((useAt->type == LOW_LEVEL) && - (useAt->invalid == FALSE) && - (use = useAt->ic.ll.flagDU.u)) + if ((useAt->type == LOW_LEVEL) && (useAt->valid()) && (use = useAt->ic.ll.flagDU.u)) { /* Find definition within the same basic block */ defAt=useAt; @@ -139,66 +134,83 @@ void Function::elimCondCodes () def = defAt->ic.ll.flagDU.d; if ((use & def) != use) continue; - notSup = FALSE; - if ((useAt->GetLlOpcode() >= iJB) && (useAt->GetLlOpcode() <= iJNS)) - { + notSup = FALSE; + if ((useAt->GetLlOpcode() >= iJB) && (useAt->GetLlOpcode() <= iJNS)) + { iICODE befDefAt = (++riICODE(defAt)).base(); - switch (defAt->GetLlOpcode()) - { - case iCMP: + switch (defAt->GetLlOpcode()) + { + case iCMP: rhs = srcIdent (*defAt, this, befDefAt,*useAt, eUSE); lhs = dstIdent (*defAt, this, befDefAt,*useAt, eUSE); - break; + break; - case iOR: - lhs = defAt->ic.hl.asgn.lhs->clone(); - useAt->copyDU(*defAt, eUSE, eDEF); - if (defAt->isLlFlag(B)) - rhs = COND_EXPR::idKte (0, 1); - else - rhs = COND_EXPR::idKte (0, 2); - break; + case iOR: + lhs = defAt->ic.hl.asgn.lhs->clone(); + useAt->copyDU(*defAt, eUSE, eDEF); + if (defAt->isLlFlag(B)) + rhs = COND_EXPR::idKte (0, 1); + else + rhs = COND_EXPR::idKte (0, 2); + break; - case iTEST: + case iTEST: rhs = srcIdent (*defAt,this, befDefAt,*useAt, eUSE); lhs = dstIdent (*defAt,this, befDefAt,*useAt, eUSE); - lhs = COND_EXPR::boolOp (lhs, rhs, AND); - if (defAt->isLlFlag(B)) - rhs = COND_EXPR::idKte (0, 1); - else - rhs = COND_EXPR::idKte (0, 2); - break; + lhs = COND_EXPR::boolOp (lhs, rhs, AND); + if (defAt->isLlFlag(B)) + rhs = COND_EXPR::idKte (0, 1); + else + rhs = COND_EXPR::idKte (0, 2); + break; - default: - notSup = TRUE; - std::cout << hex<loc_ip; - reportError (JX_NOT_DEF, defAt->GetLlOpcode()); - flg |= PROC_ASM; /* generate asm */ - } - if (! notSup) - { - exp = COND_EXPR::boolOp (lhs, rhs,condOpJCond[useAt->GetLlOpcode()-iJB]); - useAt->setJCond(exp); - } - } - - else if (useAt->GetLlOpcode() == iJCXZ) - { - lhs = COND_EXPR::idReg (rCX, 0, &localId); - useAt->setRegDU (rCX, eUSE); - rhs = COND_EXPR::idKte (0, 2); - exp = COND_EXPR::boolOp (lhs, rhs, EQUAL); - useAt->setJCond(exp); - } - - else - { - reportError (NOT_DEF_USE,defAt->GetLlOpcode(),useAt->GetLlOpcode()); + default: + notSup = TRUE; + std::cout << hex<loc_ip; + reportError (JX_NOT_DEF, defAt->GetLlOpcode()); flg |= PROC_ASM; /* generate asm */ } - break; + if (! notSup) + { + exp = COND_EXPR::boolOp (lhs, rhs,condOpJCond[useAt->GetLlOpcode()-iJB]); + useAt->setJCond(exp); + } } + else if (useAt->GetLlOpcode() == iJCXZ) + { + lhs = COND_EXPR::idReg (rCX, 0, &localId); + useAt->setRegDU (rCX, eUSE); + rhs = COND_EXPR::idKte (0, 2); + exp = COND_EXPR::boolOp (lhs, rhs, EQUAL); + useAt->setJCond(exp); + } +// else if (useAt->GetLlOpcode() == iRCL) +// { +// ICODE &a(*defAt); +// ICODE &b(*useAt); +// if(a.GetLlOpcode() == iRCL) +// { +// if ((b.ic.ll.flg & NO_SRC) != NO_SRC) /* if there is src op */ +// rhs = COND_EXPR::id (*useAt, SRC, this, Icode.end(), *useAt, NONE); +// lhs = COND_EXPR::id (*useAt, DST, this, Icode.end(), *useAt, USE_DEF); + +// rhs = COND_EXPR::boolOp (lhs, rhs, SHL); +// useAt->setAsgn(lhs->clone(), rhs); +// printf("RCL\n"); +// } + +// } + else + { + ICODE &a(*defAt); + ICODE &b(*useAt); + reportError (NOT_DEF_USE,a.GetLlOpcode(),b.GetLlOpcode()); + flg |= PROC_ASM; /* generate asm */ + } + break; + } + /* Check for extended basic block */ if ((pBB->size() == 1) &&(useAt->GetLlOpcode() >= iJB) && (useAt->GetLlOpcode() <= iJNS)) { @@ -231,7 +243,7 @@ void Function::elimCondCodes () * is not really meant to be a register that is used before defined). */ void Function::genLiveKtes () { - Int i; + int i; BB * pbb; bitset<32> liveUse, def; @@ -261,11 +273,11 @@ void Function::genLiveKtes () * Propagates register usage information to the procedure call. */ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut) { - Int i, j; + int i, j; BB * pbb=0; /* pointer to current basic block */ Function * pcallee; /* invoked subroutine */ //ICODE *ticode /* icode that invokes a subroutine */ - ; + ; std::bitset<32> prevLiveOut, /* previous live out */ prevLiveIn; /* previous live in */ boolT change; /* is there change in the live sets?*/ @@ -329,7 +341,7 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut) { if ( (pcallee->flg & PROC_IS_FUNC) && /* returns a value */ (pcallee->liveOut & pbb->edges[0].BBptr->liveIn).any() - ) + ) pbb->liveOut = pcallee->liveOut; else pbb->liveOut = 0; @@ -384,8 +396,8 @@ void Function::liveRegAnalysis (std::bitset<32> &in_liveOut) void BB::genDU1() { - byte regi; /* Register that was defined */ - Int k, defRegIdx, useIdx; + uint8_t regi; /* Register that was defined */ + int k, defRegIdx, useIdx; iICODE picode, ticode,lastInst; BB *tbb; /* Target basic block */ bool res; @@ -406,7 +418,7 @@ void BB::genDU1() { if (not picode->du.def.test(k)) continue; - regi = (byte)(k + 1); /* defined register */ + regi = (uint8_t)(k + 1); /* defined register */ picode->du1.regi[defRegIdx] = regi; /* Check remaining instructions of the BB for all uses @@ -477,9 +489,9 @@ void BB::genDU1() * return an integer, which is normally not taken into * account by the programmer). */ if (picode->valid() and not picode->du1.used(defRegIdx) and - (not (picode->du.lastDefRegi & duReg[regi]).any()) && - (not ((picode->ic.hl.opcode == HLI_CALL) && - (picode->ic.hl.call.proc->flg & PROC_ISLIB)))) + (not (picode->du.lastDefRegi & duReg[regi]).any()) && + (not ((picode->ic.hl.opcode == HLI_CALL) && + (picode->ic.hl.call.proc->flg & PROC_ISLIB)))) { if (! (this->liveOut & duReg[regi]).any()) /* not liveOut */ { @@ -511,8 +523,8 @@ void BB::genDU1() /* Generates the du chain of each instruction in a basic block */ void Function::genDU1 () { - byte regi; /* Register that was defined */ - Int i, k, defRegIdx, useIdx; + uint8_t regi; /* Register that was defined */ + int i, k, defRegIdx, useIdx; iICODE picode, ticode,lastInst;/* Current and target bb */ BB * pbb, *tbb; /* Current and target basic block */ bool res; @@ -533,7 +545,7 @@ void Function::genDU1 () /* Substitutes the rhs (or lhs if rhs not possible) of ticode for the rhs * of picode. */ static void forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode, - iICODE ticode, LOCAL_ID *locsym, Int &numHlIcodes) + iICODE ticode, LOCAL_ID *locsym, int &numHlIcodes) { boolT res; @@ -566,8 +578,8 @@ static void forwardSubs (COND_EXPR *lhs, COND_EXPR *rhs, iICODE picode, /* Substitutes the rhs (or lhs if rhs not possible) of ticode for the * expression exp given */ -static void forwardSubsLong (Int longIdx, COND_EXPR *exp, iICODE picode, - iICODE ticode, Int *numHlIcodes) +static void forwardSubsLong (int longIdx, COND_EXPR *exp, iICODE picode, + iICODE ticode, int *numHlIcodes) { bool res; @@ -600,7 +612,7 @@ static boolT xClear (COND_EXPR *rhs, iICODE f, iICODE t, iICODE lastBBinst, Func { iICODE i; boolT res; - byte regi; + uint8_t regi; if (rhs == NULL) return false; @@ -646,7 +658,7 @@ static boolT xClear (COND_EXPR *rhs, iICODE f, iICODE t, iICODE lastBBinst, Func /* Checks the type of the formal argument as against to the actual argument, * whenever possible, and then places the actual argument on the procedure's * argument list. */ -static void processCArg (Function * pp, Function * pProc, ICODE * picode, Int numArgs, Int *k) +static void processCArg (Function * pp, Function * pProc, ICODE * picode, int numArgs, int *k) { COND_EXPR *exp; boolT res; @@ -685,7 +697,7 @@ static void processCArg (Function * pp, Function * pProc, ICODE * picode, Int nu * For HLI_CALL hlIcodes, places the arguments in the argument list. */ void Function::findExps() { - Int i, k, numHlIcodes; + int i, k, numHlIcodes; iICODE lastInst, picode, // Current icode */ ticode; // Target icode */ @@ -694,7 +706,7 @@ void Function::findExps() COND_EXPR *exp, // expression pointer - for HLI_POP and HLI_CALL */ *lhs; // exp ptr for return value of a HLI_CALL */ //STKFRAME * args; // pointer to arguments - for HLI_CALL */ - byte regi; // register(s) to be forward substituted */ + uint8_t regi; // register(s) to be forward substituted */ ID *retVal; // function return value /* Initialize expression stack */ @@ -714,7 +726,7 @@ void Function::findExps() if ((picode->type == HIGH_LEVEL) && (picode->invalid == FALSE)) { numHlIcodes++; - if (picode->du1.numRegsDef == 1) /* byte/word regs */ + if (picode->du1.numRegsDef == 1) /* uint8_t/uint16_t regs */ { /* Check for only one use of this register. If this is * the last definition of the register in this BB, check @@ -959,7 +971,7 @@ void Function::findExps() res = insertSubTreeLongReg (exp, &ticode->ic.hl.exp.v, localId.newLongReg ( retVal->type, retVal->id.longId.h, - retVal->id.longId.l, picode)); + retVal->id.longId.l, picode)); if (res) /* was substituted */ { picode->invalidate(); @@ -992,7 +1004,7 @@ void Function::findExps() if ((picode->ic.hl.opcode == HLI_CALL) && ! (picode->ic.hl.call.proc->flg & REG_ARGS)) { Function * pp; - Int cb, numArgs; + int cb, numArgs; boolT res; pp = picode->ic.hl.call.proc; @@ -1060,7 +1072,7 @@ void Function::findExps() void Function::dataFlow(std::bitset<32> &liveOut) { boolT isAx, isBx, isCx, isDx; - Int idx; + int idx; /* Remove references to register variables */ if (flg & SI_REGVAR) @@ -1086,7 +1098,7 @@ void Function::dataFlow(std::bitset<32> &liveOut) idx = localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, Icode.begin()/*0*/); localId.propLongId (rAX, rDX, "\0"); } - else if (isAx || isBx || isCx || isDx) /* word */ + else if (isAx || isBx || isCx || isDx) /* uint16_t */ { retVal.type = TYPE_WORD_SIGN; retVal.loc = REG_FRAME; diff --git a/src/disassem.cpp b/src/disassem.cpp index ab0fd61..554fe36 100644 --- a/src/disassem.cpp +++ b/src/disassem.cpp @@ -127,36 +127,36 @@ static const char *szWreg[12] = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di" static const char *szPtr[2] = { "word ptr ", "byte ptr " }; -static void dis1Line (ICODE &icode, Int pass); -void dis1LineOp(Int i, boolT fWin, char attr, word *len, Function * pProc); -static void formatRM(ostringstream &p, flags32 flg, const LLOperand &pm); -static ostringstream &strDst(ostringstream &os, flags32 flg, LLOperand &pm); +static void dis1Line (ICODE &icode, int pass); +void dis1LineOp(int i, boolT fWin, char attr, uint16_t *len, Function * pProc); +static void formatRM(ostringstream &p, uint32_t flg, const LLOperand &pm); +static ostringstream &strDst(ostringstream &os, uint32_t flg, LLOperand &pm); static ostringstream &strSrc(ostringstream &os,const LLInst &pc,bool skip_comma=false); -static char *strHex(dword d); -static Int checkScanned(dword pcCur); +static char *strHex(uint32_t d); +static int checkScanned(uint32_t pcCur); static void setProc(Function * proc); -static void dispData(word dataSeg); +static void dispData(uint16_t dataSeg); void flops(LLInst &pIcode, std::ostringstream &out); -boolT callArg(word off, char *temp); /* Check for procedure name */ +boolT callArg(uint16_t off, char *temp); /* Check for procedure name */ static FILE *fp; static CIcodeRec pc; static std::ostringstream buf; -static Int cb, j, numIcode, allocIcode, eop; +static int cb, j, numIcode, allocIcode, eop; static map pl; -static dword nextInst; +static uint32_t nextInst; static boolT fImpure; -static Int lab, prevPass; +static int lab, prevPass; static Function * pProc; /* Points to current proc struct */ struct POSSTACK_ENTRY { - Int ic; /* An icode offset */ + int ic; /* An icode offset */ Function * pProc; /* A pointer to a PROCEDURE structure */ } ; vector posStack; /* position stack */ -byte iPS; /* Index into the stack */ +uint8_t iPS; /* Index into the stack */ //static char cbuf[256]; /* Has to be 256 for wgetstr() to work */ @@ -174,9 +174,9 @@ byte iPS; /* Index into the stack */ * pass == 2 generates output on file .a2 * pass == 3 generates output on file .b ****************************************************************************/ -void disassem(Int pass, Function * ppProc) +void disassem(int pass, Function * ppProc) { - Int i; + int i; pProc = ppProc; /* Save the passes pProc */ if (pass != prevPass) @@ -263,7 +263,7 @@ void disassem(Int pass, Function * ppProc) * i is index into Icode for this proc * * It is assumed that icode i is already scanned * ****************************************************************************/ -static void dis1Line(ICODE &icode_iter, Int pass) +static void dis1Line(ICODE &icode_iter, int pass) { ostringstream oper_stream; ostringstream hex_bytes; @@ -298,7 +298,7 @@ static void dis1Line(ICODE &icode_iter, Int pass) nextInst = _IcLL.label; else { - cb = (dword) _IcLL.numBytes; + cb = (uint32_t) _IcLL.numBytes; nextInst = _IcLL.label + cb; /* Output hexa code in program image */ @@ -402,7 +402,7 @@ static void dis1Line(ICODE &icode_iter, Int pass) { ICODE *lab=pc.GetIcode(_IcLL.src.op()); selectTable(Label); - if ((_IcLL.src.op() < (dword)numIcode) && /* Ensure in range */ + if ((_IcLL.src.op() < (uint32_t)numIcode) && /* Ensure in range */ readVal(oper_stream, lab->ic.ll.label, 0)) { break; /* Symbolic label. Done */ @@ -528,7 +528,7 @@ static void dis1Line(ICODE &icode_iter, Int pass) } else { - for (j = _IcLL.label, fImpure = 0; j > 0 && j < (Int)nextInst; j++) + for (j = _IcLL.label, fImpure = 0; j > 0 && j < (int)nextInst; j++) { fImpure |= BITMAP(j, BM_DATA); } @@ -604,7 +604,7 @@ static void dis1Line(ICODE &icode_iter, Int pass) /**************************************************************************** * formatRM ***************************************************************************/ -static void formatRM(std::ostringstream &p, flags32 flg, const LLOperand &pm) +static void formatRM(std::ostringstream &p, uint32_t flg, const LLOperand &pm) { char seg[4]; @@ -616,7 +616,7 @@ static void formatRM(std::ostringstream &p, flags32 flg, const LLOperand &pm) if (pm.regi == 0) { - p<= PATLEN) return TRUE; /* Skip Mod/RM */ switch (op & 0xC0) { @@ -71,7 +71,7 @@ static bool ModRM(byte pat[]) /* Change the next two bytes to wild cards */ static bool -TwoWild(byte pat[]) +TwoWild(uint8_t pat[]) { pat[pc++] = WILD; if (pc >= PATLEN) return TRUE; /* Pattern exhausted */ @@ -82,7 +82,7 @@ TwoWild(byte pat[]) /* Change the next four bytes to wild cards */ static bool -FourWild(byte pat[]) +FourWild(uint8_t pat[]) { TwoWild(pat); return TwoWild(pat); @@ -91,16 +91,16 @@ FourWild(byte pat[]) /* Chop from the current point by wiping with zeroes. Can't rely on anything after this point */ static void -chop(byte pat[]) +chop(uint8_t pat[]) { if (pc >= PATLEN) return; /* Could go negative otherwise */ memset(&pat[pc], 0, PATLEN - pc); } -static bool op0F(byte pat[]) +static bool op0F(uint8_t pat[]) { - /* The two byte opcodes */ - byte op = pat[pc++]; + /* The two uint8_t opcodes */ + uint8_t op = pat[pc++]; switch (op & 0xF0) { case 0x00: /* 00 - 0F */ @@ -115,10 +115,10 @@ static bool op0F(byte pat[]) return ModRM(pat); case 0x80: - pc += 2; /* Word displacement cond jumps */ + pc += 2; /* uint16_t displacement cond jumps */ return FALSE; - case 0x90: /* Byte set on condition */ + case 0x90: /* uint8_t set on condition */ return ModRM(pat); case 0xA0: @@ -168,7 +168,7 @@ static bool op0F(byte pat[]) return FALSE; default: - return FALSE; /* Treat as double byte opcodes */ + return FALSE; /* Treat as double uint8_t opcodes */ } @@ -183,10 +183,10 @@ static bool op0F(byte pat[]) PATLEN bytes are scanned. */ void -fixWildCards(byte pat[]) +fixWildCards(uint8_t pat[]) { - byte op, quad, intArg; + uint8_t op, quad, intArg; pc=0; @@ -195,17 +195,17 @@ fixWildCards(byte pat[]) op = pat[pc++]; if (pc >= PATLEN) return; - quad = (byte) (op & 0xC0); /* Quadrant of the opcode map */ + quad = (uint8_t) (op & 0xC0); /* Quadrant of the opcode map */ if (quad == 0) { /* Arithmetic group 00-3F */ if ((op & 0xE7) == 0x26) /* First check for the odds */ { - /* Segment prefix: treat as 1 byte opcode */ + /* Segment prefix: treat as 1 uint8_t opcode */ continue; } - if (op == 0x0F) /* 386 2 byte opcodes */ + if (op == 0x0F) /* 386 2 uint8_t opcodes */ { if (op0F(pat)) return; continue; @@ -216,20 +216,20 @@ fixWildCards(byte pat[]) /* All these are constant. Work out the instr length */ if (op & 2) { - /* Push, pop, other 1 byte opcodes */ + /* Push, pop, other 1 uint8_t opcodes */ continue; } else { if (op & 1) { - /* Word immediate operands */ + /* uint16_t immediate operands */ pc += 2; continue; } else { - /* Byte immediate operands */ + /* uint8_t immediate operands */ pc++; continue; } @@ -255,7 +255,7 @@ fixWildCards(byte pat[]) /* 0x60 - 0x70 */ if (op & 0x10) { - /* 70-7F 2 byte jump opcodes */ + /* 70-7F 2 uint8_t jump opcodes */ pc++; continue; } @@ -282,11 +282,11 @@ fixWildCards(byte pat[]) if (TwoWild(pat)) return; continue; - case 0x68: /* Push byte */ - case 0x6A: /* Push byte */ + case 0x68: /* Push uint8_t */ + case 0x6A: /* Push uint8_t */ case 0x6D: /* insb port */ case 0x6F: /* outsb port */ - /* 2 byte instr, no wilds */ + /* 2 uint8_t instr, no wilds */ pc++; continue; @@ -300,14 +300,14 @@ fixWildCards(byte pat[]) switch (op & 0xF0) { case 0x80: /* 80 - 8F */ - /* All have a mod/rm byte */ + /* All have a mod/rm uint8_t */ if (ModRM(pat)) return; /* These also have immediate values */ switch (op) { case 0x80: case 0x83: - /* One byte immediate */ + /* One uint8_t immediate */ pc++; continue; @@ -326,7 +326,7 @@ fixWildCards(byte pat[]) if (FourWild(pat)) return; continue; } - /* All others are 1 byte opcodes */ + /* All others are 1 uint8_t opcodes */ continue; case 0xA0: /* A0 - AF */ if ((op & 0x0C) == 0) @@ -337,7 +337,7 @@ fixWildCards(byte pat[]) } else if ((op & 0xFE) == 0xA8) { - /* test al,#byte or test ax,#word */ + /* test al,#uint8_t or test ax,#uint16_t */ if (op & 1) pc += 2; else pc += 1; continue; @@ -366,10 +366,10 @@ fixWildCards(byte pat[]) /* In the last quadrant of the op code table */ switch (op) { - case 0xC0: /* 386: Rotate group 2 ModRM, byte, #byte */ - case 0xC1: /* 386: Rotate group 2 ModRM, word, #byte */ + case 0xC0: /* 386: Rotate group 2 ModRM, uint8_t, #uint8_t */ + case 0xC1: /* 386: Rotate group 2 ModRM, uint16_t, #uint8_t */ if (ModRM(pat)) return; - /* Byte immediate value follows ModRM */ + /* uint8_t immediate value follows ModRM */ pc++; continue; @@ -390,27 +390,27 @@ fixWildCards(byte pat[]) case 0xC6: /* Mov ModRM, #nn */ if (ModRM(pat)) return; - /* Byte immediate value follows ModRM */ + /* uint8_t immediate value follows ModRM */ pc++; continue; case 0xC7: /* Mov ModRM, #nnnn */ if (ModRM(pat)) return; - /* Word immediate value follows ModRM */ + /* uint16_t immediate value follows ModRM */ /* Immediate 16 bit values might be constant, but also might be relocatable. For now, make them wild */ if (TwoWild(pat)) return; continue; case 0xC8: /* Enter Iw, Ib */ - pc += 3; /* Constant word, byte */ + pc += 3; /* Constant uint16_t, uint8_t */ continue; case 0xC9: /* Leave */ continue; - case 0xCC: /* Int 3 */ + case 0xCC: /* int 3 */ continue; - case 0xCD: /* Int nn */ + case 0xCD: /* int nn */ intArg = pat[pc++]; if ((intArg >= 0x34) && (intArg <= 0x3B)) { @@ -425,10 +425,10 @@ fixWildCards(byte pat[]) case 0xCF: /* Iret */ continue; - case 0xD0: /* Group 2 rotate, byte, 1 bit */ - case 0xD1: /* Group 2 rotate, word, 1 bit */ - case 0xD2: /* Group 2 rotate, byte, CL bits */ - case 0xD3: /* Group 2 rotate, word, CL bits */ + case 0xD0: /* Group 2 rotate, uint8_t, 1 bit */ + case 0xD1: /* Group 2 rotate, uint16_t, 1 bit */ + case 0xD2: /* Group 2 rotate, uint8_t, CL bits */ + case 0xD3: /* Group 2 rotate, uint16_t, CL bits */ if (ModRM(pat)) return; continue; @@ -500,8 +500,8 @@ fixWildCards(byte pat[]) case 0xFD: /* Std */ continue; - case 0xF6: /* Group 3 byte test/not/mul/div */ - case 0xF7: /* Group 3 word test/not/mul/div */ + case 0xF6: /* Group 3 uint8_t test/not/mul/div */ + case 0xF7: /* Group 3 uint16_t test/not/mul/div */ case 0xFE: /* Inc/Dec group 4 */ if (ModRM(pat)) return; continue; @@ -511,7 +511,7 @@ fixWildCards(byte pat[]) if (ModRM(pat)) return; continue; - default: /* Rest are single byte opcodes */ + default: /* Rest are single uint8_t opcodes */ continue; } } diff --git a/src/frontend.cpp b/src/frontend.cpp index 8e6d8d6..d21a86c 100644 --- a/src/frontend.cpp +++ b/src/frontend.cpp @@ -11,40 +11,40 @@ #include /* For malloc, free, realloc */ typedef struct { /* PSP structure */ - word int20h; /* interrupt 20h */ - word eof; /* segment, end of allocation block */ - byte res1; /* reserved */ - byte dosDisp[5]; /* far call to DOS function dispatcher */ - byte int22h[4]; /* vector for terminate routine */ - byte int23h[4]; /* vector for ctrl+break routine */ - byte int24h[4]; /* vector for error routine */ - byte res2[22]; /* reserved */ - word segEnv; /* segment address of environment block */ - byte res3[34]; /* reserved */ - byte int21h[6]; /* opcode for int21h and far return */ - byte res4[6]; /* reserved */ - byte fcb1[16]; /* default file control block 1 */ - byte fcb2[16]; /* default file control block 2 */ - byte res5[4]; /* reserved */ - byte cmdTail[0x80]; /* command tail and disk transfer area */ + uint16_t int20h; /* interrupt 20h */ + uint16_t eof; /* segment, end of allocation block */ + uint8_t res1; /* reserved */ + uint8_t dosDisp[5]; /* far call to DOS function dispatcher */ + uint8_t int22h[4]; /* vector for terminate routine */ + uint8_t int23h[4]; /* vector for ctrl+break routine */ + uint8_t int24h[4]; /* vector for error routine */ + uint8_t res2[22]; /* reserved */ + uint16_t segEnv; /* segment address of environment block */ + uint8_t res3[34]; /* reserved */ + uint8_t int21h[6]; /* opcode for int21h and far return */ + uint8_t res4[6]; /* reserved */ + uint8_t fcb1[16]; /* default file control block 1 */ + uint8_t fcb2[16]; /* default file control block 2 */ + uint8_t res5[4]; /* reserved */ + uint8_t cmdTail[0x80]; /* command tail and disk transfer area */ } PSP; static struct { /* EXE file header */ - byte sigLo; /* .EXE signature: 0x4D 0x5A */ - byte sigHi; - word lastPageSize; /* Size of the last page */ - word numPages; /* Number of pages in the file */ - word numReloc; /* Number of relocation items */ - word numParaHeader; /* # of paragraphs in the header */ - word minAlloc; /* Minimum number of paragraphs */ - word maxAlloc; /* Maximum number of paragraphs */ - word initSS; /* Segment displacement of stack */ - word initSP; /* Contents of SP at entry */ - word checkSum; /* Complemented checksum */ - word initIP; /* Contents of IP at entry */ - word initCS; /* Segment displacement of code */ - word relocTabOffset; /* Relocation table offset */ - word overlayNum; /* Overlay number */ + uint8_t sigLo; /* .EXE signature: 0x4D 0x5A */ + uint8_t sigHi; + uint16_t lastPageSize; /* Size of the last page */ + uint16_t numPages; /* Number of pages in the file */ + uint16_t numReloc; /* Number of relocation items */ + uint16_t numParaHeader; /* # of paragraphs in the header */ + uint16_t minAlloc; /* Minimum number of paragraphs */ + uint16_t maxAlloc; /* Maximum number of paragraphs */ + uint16_t initSS; /* Segment displacement of stack */ + uint16_t initSP; /* Contents of SP at entry */ + uint16_t checkSum; /* Complemented checksum */ + uint16_t initIP; /* Contents of IP at entry */ + uint16_t initCS; /* Segment displacement of code */ + uint16_t relocTabOffset; /* Relocation table offset */ + uint16_t overlayNum; /* Overlay number */ } header; #define EXE_RELOCATION 0x10 /* EXE images rellocated to above PSP */ @@ -101,7 +101,7 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph) ***************************************************************************/ static void displayLoadInfo(void) { - Int i; + int i; printf("File type is %s\n", (prog.fCOM)?"COM":"EXE"); if (! prog.fCOM) { @@ -132,10 +132,10 @@ static void displayLoadInfo(void) /***************************************************************************** * fill - Fills line for displayMemMap() ****************************************************************************/ -static void fill(Int ip, char *bf) +static void fill(int ip, char *bf) { - static byte type[4] = {'.', 'd', 'c', 'x'}; - byte i; + static uint8_t type[4] = {'.', 'd', 'c', 'x'}; + uint8_t i; for (i = 0; i < 16; i++, ip++) { @@ -153,8 +153,8 @@ static void fill(Int ip, char *bf) static void displayMemMap(void) { char c, b1[33], b2[33], b3[33]; - byte i; - Int ip = 0; + uint8_t i; + int ip = 0; printf("\nMemory Map\n"); while (ip < prog.cbImage) @@ -189,8 +189,8 @@ static void displayMemMap(void) static void LoadImage(char *filename) { FILE *fp; - Int i, cb; - byte buf[4]; + int i, cb; + uint8_t buf[4]; /* Open the input file */ if ((fp = fopen(filename, "rb")) == NULL) @@ -219,11 +219,11 @@ static void LoadImage(char *filename) } /* Calculate the load module size. -* This is the number of pages in the file -* less the length of the header and reloc table -* less the number of bytes unused on last page -*/ - cb = (dword)LH(&header.numPages) * 512 - (dword)LH(&header.numParaHeader) * 16; + * This is the number of pages in the file + * less the length of the header and reloc table + * less the number of bytes unused on last page + */ + cb = (uint32_t)LH(&header.numPages) * 512 - (uint32_t)LH(&header.numParaHeader) * 16; if (header.lastPageSize) { cb -= 512 - LH(&header.lastPageSize); @@ -237,16 +237,16 @@ static void LoadImage(char *filename) * to have to load DS from a constant so it'll be pretty * obvious. */ - prog.initCS = (int16)LH(&header.initCS) + EXE_RELOCATION; - prog.initIP = (int16)LH(&header.initIP); - prog.initSS = (int16)LH(&header.initSS) + EXE_RELOCATION; - prog.initSP = (int16)LH(&header.initSP); - prog.cReloc = (int16)LH(&header.numReloc); + prog.initCS = (int16_t)LH(&header.initCS) + EXE_RELOCATION; + prog.initIP = (int16_t)LH(&header.initIP); + prog.initSS = (int16_t)LH(&header.initSS) + EXE_RELOCATION; + prog.initSP = (int16_t)LH(&header.initSP); + prog.cReloc = (int16_t)LH(&header.numReloc); /* Allocate the relocation table */ if (prog.cReloc) { - prog.relocTable = new dword [prog.cReloc]; + prog.relocTable = new uint32_t [prog.cReloc]; fseek(fp, LH(&header.relocTabOffset), SEEK_SET); /* Read in seg:offset pairs and convert to Image ptrs */ @@ -254,11 +254,11 @@ static void LoadImage(char *filename) { fread(buf, 1, 4, fp); prog.relocTable[i] = LH(buf) + - (((Int)LH(buf+2) + EXE_RELOCATION)<<4); + (((int)LH(buf+2) + EXE_RELOCATION)<<4); } } /* Seek to start of image */ - fseek(fp, (Int)LH(&header.numParaHeader) * 16, SEEK_SET); + fseek(fp, (int)LH(&header.numParaHeader) * 16, SEEK_SET); } else { /* COM file @@ -282,8 +282,8 @@ static void LoadImage(char *filename) /* Allocate a block of memory for the program. */ prog.cbImage = cb + sizeof(PSP); - prog.Image = new byte [prog.cbImage]; - prog.Image[0] = 0xCD; /* Fill in PSP Int 20h location */ + prog.Image = new uint8_t [prog.cbImage]; + prog.Image[0] = 0xCD; /* Fill in PSP int 20h location */ prog.Image[1] = 0x20; /* for termination checking */ /* Read in the image past where a PSP would go */ @@ -294,14 +294,14 @@ static void LoadImage(char *filename) fatalError(CANNOT_READ, filename); } #endif - if (cb != (Int)fread(prog.Image + sizeof(PSP), 1, (size_t)cb, fp)) + if (cb != (int)fread(prog.Image + sizeof(PSP), 1, (size_t)cb, fp)) { fatalError(CANNOT_READ, filename); } /* Set up memory map */ cb = (prog.cbImage + 3) / 4; - prog.map = (byte *)malloc(cb); + prog.map = (uint8_t *)malloc(cb); memset(prog.map, BM_UNKNOWN, (size_t)cb); /* Relocate segment constants */ @@ -309,10 +309,10 @@ static void LoadImage(char *filename) { for (i = 0; i < prog.cReloc; i++) { - byte *p = &prog.Image[prog.relocTable[i]]; - word w = (word)LH(p) + EXE_RELOCATION; - *p++ = (byte)(w & 0x00FF); - *p = (byte)((w & 0xFF00) >> 8); + uint8_t *p = &prog.Image[prog.relocTable[i]]; + uint16_t w = (uint16_t)LH(p) + EXE_RELOCATION; + *p++ = (uint8_t)(w & 0x00FF); + *p = (uint8_t)((w & 0xFF00) >> 8); } } @@ -323,14 +323,14 @@ static void LoadImage(char *filename) /***************************************************************************** * allocMem - malloc with failure test ****************************************************************************/ -void *allocMem(Int cb) +void *allocMem(int cb) { - byte *p; + uint8_t *p; //printf("Attempt to allocMem %5ld bytes\n", cb); - if (! (p = (byte*)malloc((size_t)cb))) - /* if (! (p = (byte*)calloc((size_t)cb, 1))) */ + if (! (p = (uint8_t*)malloc((size_t)cb))) + /* if (! (p = (uint8_t*)calloc((size_t)cb, 1))) */ { fatalError(MALLOC_FAILED, cb); } diff --git a/src/graph.cpp b/src/graph.cpp index fd97da0..83883a1 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -12,9 +12,9 @@ #endif #include "graph.h" -//static BB * rmJMP(Function * pProc, Int marker, BB * pBB); +//static BB * rmJMP(Function * pProc, int marker, BB * pBB); static void mergeFallThrough(Function * pProc, BB * pBB); -static void dfsNumbering(BB * pBB, std::vector &dfsLast, Int *first, Int *last); +static void dfsNumbering(BB * pBB, std::vector &dfsLast, int *first, int *last); /***************************************************************************** * createCFG - Create the basic control flow graph @@ -32,8 +32,8 @@ void Function::createCFG() * 5) Repeated string instructions * 6) End of procedure */ - Int i; - Int ip, start; + int i; + int ip, start; BB * psBB; BB * pBB; iICODE pIcode = Icode.begin(); @@ -63,7 +63,7 @@ void Function::createCFG() pBB = BB::Create(start, ip, TWO_BRANCH, 2, this); CondJumps: start = ip + 1; - pBB->edges[0].ip = (dword)start; + pBB->edges[0].ip = (uint32_t)start; /* This is for jumps off into nowhere */ if (pIcode->ic.ll.flg & NO_LABEL) { @@ -105,7 +105,7 @@ CondJumps: pBB = BB::Create(start, ip, CALL_NODE, i, this); start = ip + 1; if (i) - pBB->edges[0].ip = (dword)start; + pBB->edges[0].ip = (uint32_t)start; } break; @@ -130,14 +130,14 @@ CondJumps: { pBB = BB::Create(start, ip, FALL_NODE, 1, this); start = ip + 1; - pBB->edges[0].ip = (dword)start; + pBB->edges[0].ip = (uint32_t)start; } } break; } } } - std::vector::iterator iter=heldBBs.begin(); + auto iter=heldBBs.begin(); /* Convert list of BBs into a graph */ for (; iter!=heldBBs.end(); ++iter) { @@ -169,7 +169,7 @@ void Function::markImpure() if ( not icod.isLlFlag(SYM_USE | SYM_DEF)) continue; psym = &symtab[icod.ic.ll.caseTbl.numEntries]; - for (int c = (Int)psym->label; c < (Int)psym->label+psym->size; c++) + for (int c = (int)psym->label; c < (int)psym->label+psym->size; c++) { if (BITMAP(c, BM_CODE)) { @@ -204,7 +204,7 @@ void Function::freeCFG() void Function::compressCFG() { BB * pBB, *pNxt; - Int ip, first=0, last, i; + int ip, first=0, last, i; /* First pass over BB list removes redundant jumps of the form * (Un)Conditional -> Unconditional jump */ @@ -223,8 +223,8 @@ void Function::compressCFG() { pBB->edges[i].BBptr = pNxt; assert(pBB->back().loc_ip==ip); - pBB->back().SetImmediateOp((dword)pNxt->begin()); - //Icode[ip].SetImmediateOp((dword)pNxt->begin()); + pBB->back().SetImmediateOp((uint32_t)pNxt->begin()); + //Icode[ip].SetImmediateOp((uint32_t)pNxt->begin()); } } } @@ -270,7 +270,7 @@ void Function::compressCFG() /**************************************************************************** * rmJMP - If BB addressed is just a JMP it is replaced with its target ***************************************************************************/ -BB *BB::rmJMP(Int marker, BB * pBB) +BB *BB::rmJMP(int marker, BB * pBB) { marker += DFS_JMP; @@ -323,7 +323,7 @@ BB *BB::rmJMP(Int marker, BB * pBB) void BB::mergeFallThrough( CIcodeRec &Icode) { BB * pChild; - Int i; + int i; if (!this) { @@ -374,7 +374,7 @@ void BB::mergeFallThrough( CIcodeRec &Icode) * dfsNumbering - Numbers nodes during first and last visits and determine * in-edges ****************************************************************************/ -void BB::dfsNumbering(std::vector &dfsLast, Int *first, Int *last) +void BB::dfsNumbering(std::vector &dfsLast, int *first, int *last) { BB * pChild; traversed = DFS_NUM; diff --git a/src/hlicode.cpp b/src/hlicode.cpp index b6efb42..0204e92 100644 --- a/src/hlicode.cpp +++ b/src/hlicode.cpp @@ -13,11 +13,11 @@ using namespace std; #define ICODE_DELTA 25 /* Masks off bits set by duReg[] */ -dword maskDuReg[] = { 0x00, - 0xFEEFFE, 0xFDDFFD, 0xFBB00B, 0xF77007, /* word regs */ +uint32_t maskDuReg[] = { 0x00, + 0xFEEFFE, 0xFDDFFD, 0xFBB00B, 0xF77007, /* uint16_t regs */ 0xFFFFEF, 0xFFFFDF, 0xFFFFBF, 0xFFFF7F, 0xFFFEFF, 0xFFFDFF, 0xFFFBFF, 0xFFF7FF, /* seg regs */ - 0xFFEFFF, 0xFFDFFF, 0xFFBFFF, 0xFF7FFF, /* byte regs */ + 0xFFEFFF, 0xFFDFFF, 0xFFBFFF, 0xFF7FFF, /* uint8_t regs */ 0xFEFFFF, 0xFDFFFF, 0xFBFFFF, 0xF7FFFF, 0xEFFFFF, /* tmp reg */ 0xFFFFB7, 0xFFFF77, 0xFFFF9F, 0xFFFF5F, /* index regs */ @@ -87,9 +87,9 @@ void ICODE ::invalidate() * If all registers * of this instruction are unused, the instruction is invalidated (ie. removed) */ -bool ICODE::removeDefRegi (byte regi, Int thisDefIdx, LOCAL_ID *locId) +bool ICODE::removeDefRegi (uint8_t regi, int thisDefIdx, LOCAL_ID *locId) { - Int numDefs; + int numDefs; numDefs = du1.numRegsDef; // if (numDefs == thisDefIdx) @@ -130,11 +130,11 @@ bool ICODE::removeDefRegi (byte regi, Int thisDefIdx, LOCAL_ID *locId) * Note: this process should be done before data flow analysis, which * refines the HIGH_LEVEL icodes. */ void Function::highLevelGen() -{ Int i, /* idx into icode array */ +{ int i, /* idx into icode array */ numIcode; /* number of icode instructions */ iICODE pIcode; /* ptr to current icode node */ COND_EXPR *lhs, *rhs; /* left- and right-hand side of expression */ - flags32 flg; /* icode flags */ + uint32_t flg; /* icode flags */ numIcode = Icode.size(); for (iICODE i = Icode.begin(); i!=Icode.end() ; ++i) @@ -257,7 +257,8 @@ void Function::highLevelGen() case iRETF: pIcode->setUnary(HLI_RET, NULL); break; - case iSHL: rhs = COND_EXPR::boolOp (lhs, rhs, SHL); + case iSHL: + rhs = COND_EXPR::boolOp (lhs, rhs, SHL); pIcode->setAsgn(lhs, rhs); break; @@ -332,9 +333,9 @@ COND_EXPR *COND_EXPR::inverse () /* Returns the string that represents the procedure call of tproc (ie. with * actual parameters) */ -std::string writeCall (Function * tproc, STKFRAME * args, Function * pproc, Int *numLoc) +std::string writeCall (Function * tproc, STKFRAME * args, Function * pproc, int *numLoc) { - Int i; /* counter of # arguments */ + int i; /* counter of # arguments */ string condExp; ostringstream s; s<name<<" ("; @@ -350,7 +351,7 @@ std::string writeCall (Function * tproc, STKFRAME * args, Function * pproc, Int /* Displays the output of a HLI_JCOND icode. */ -char *writeJcond (HLTYPE h, Function * pProc, Int *numLoc) +char *writeJcond (HLTYPE h, Function * pProc, int *numLoc) { memset (buf, ' ', sizeof(buf)); buf[0] = '\0'; @@ -368,7 +369,7 @@ char *writeJcond (HLTYPE h, Function * pProc, Int *numLoc) /* Displays the inverse output of a HLI_JCOND icode. This is used in the case * when the THEN clause of an if..then..else is empty. The clause is * negated and the ELSE clause is used instead. */ -char *writeJcondInv (HLTYPE h, Function * pProc, Int *numLoc) +char *writeJcondInv (HLTYPE h, Function * pProc, int *numLoc) { memset (buf, ' ', sizeof(buf)); buf[0] = '\0'; @@ -379,7 +380,7 @@ char *writeJcondInv (HLTYPE h, Function * pProc, Int *numLoc) return (buf); } -string AssignType::writeOut(Function *pProc, Int *numLoc) +string AssignType::writeOut(Function *pProc, int *numLoc) { ostringstream ostr; ostr << walkCondExpr (lhs, pProc, numLoc); @@ -388,14 +389,14 @@ string AssignType::writeOut(Function *pProc, Int *numLoc) ostr << ";\n"; return ostr.str(); } -string CallType::writeOut(Function *pProc, Int *numLoc) +string CallType::writeOut(Function *pProc, int *numLoc) { ostringstream ostr; ostr << writeCall (proc, args, pProc,numLoc); ostr << ";\n"; return ostr.str(); } -string ExpType::writeOut(Function *pProc, Int *numLoc) +string ExpType::writeOut(Function *pProc, int *numLoc) { return walkCondExpr (v, pProc, numLoc); } @@ -404,7 +405,7 @@ string ExpType::writeOut(Function *pProc, Int *numLoc) * Note: this routine does not output the contens of HLI_JCOND icodes. This is * done in a separate routine to be able to support the removal of * empty THEN clauses on an if..then..else. */ -string HLTYPE::write1HlIcode (Function * pProc, Int *numLoc) +string HLTYPE::write1HlIcode (Function * pProc, int *numLoc) { string e; ostringstream ostr; @@ -435,7 +436,7 @@ string HLTYPE::write1HlIcode (Function * pProc, Int *numLoc) } -Int power2 (Int i) +int power2 (int i) /* Returns the value of 2 to the power of i */ { if (i == 0) @@ -446,10 +447,10 @@ Int power2 (Int i) /* Writes the registers/stack variables that are used and defined by this * instruction. */ -void ICODE::writeDU(Int idx) +void ICODE::writeDU(int idx) { static char buf[100]; - Int i, j; + int i, j; memset (buf, ' ', sizeof(buf)); buf[0] = '\0'; diff --git a/src/icode.cpp b/src/icode.cpp index 3864bae..1b4d536 100644 --- a/src/icode.cpp +++ b/src/icode.cpp @@ -6,7 +6,7 @@ #include #include "dcc.h" -#include "types.h" // Common types like byte, etc +#include "types.h" // Common types like uint8_t, etc #include "ast.h" // Some icode types depend on these #include "icode.h" @@ -38,18 +38,18 @@ void CIcodeRec::SetInBB(int start, int end, BB *pnewBB) /* labelSrchRepl - Searches the icodes for instruction with label = target, and replaces *pIndex with an icode index */ -bool CIcodeRec::labelSrch(dword target, dword &pIndex) +bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex) { - Int i; + int i; iICODE location=labelSrch(target); if(end()==location) return false; pIndex=location->loc_ip; return true; } -CIcodeRec::iterator CIcodeRec::labelSrch(dword target) +CIcodeRec::iterator CIcodeRec::labelSrch(uint32_t target) { - Int i; + int i; return find_if(begin(),end(),[target](ICODE &l) -> bool {return l.ic.ll.label==target;}); } ICODE * CIcodeRec::GetIcode(int ip) @@ -61,14 +61,14 @@ ICODE * CIcodeRec::GetIcode(int ip) } extern char *indent(int level); -extern Int getNextLabel(); +extern int getNextLabel(); extern bundle cCode; /* Checks the given icode to determine whether it has a label associated * to it. If so, a goto is emitted to this label; otherwise, a new label * is created and a goto is also emitted. * Note: this procedure is to be used when the label is to be backpatched * onto code in cCode.code */ -void ICODE::emitGotoLabel (Int indLevel) +void ICODE::emitGotoLabel (int indLevel) { if (! (ic.ll.flg & HLL_LABEL)) /* node hasn't got a lab */ { diff --git a/src/idioms.cpp b/src/idioms.cpp index e2605c0..9f1c305 100644 --- a/src/idioms.cpp +++ b/src/idioms.cpp @@ -38,9 +38,9 @@ bool JmpInst(llIcode opcode) ****************************************************************************/ void Function::findIdioms() { -// Int ip; /* Index to current icode */ +// int ip; /* Index to current icode */ iICODE pEnd, pIcode; /* Pointers to end of BB and current icodes */ - int16 delta; + int16_t delta; pIcode = Icode.begin(); pEnd = Icode.end(); @@ -219,9 +219,9 @@ void Function::findIdioms() * binds jump target addresses to icode offsets. */ void Function::bindIcodeOff() { - Int i; /* idx into icode array */ + int i; /* idx into icode array */ iICODE pIcode; /* ptr icode array */ - dword *p; /* for case table */ + uint32_t *p; /* for case table */ if (Icode.empty()) /* No Icode */ return; @@ -255,7 +255,7 @@ void Function::bindIcodeOff() continue; if (icode.ic.ll.flg & I) { - dword found; + uint32_t found; if (! Icode.labelSrch(icode.ic.ll.src.op(), found)) icode.ic.ll.flg |= NO_LABEL; else diff --git a/src/idioms/arith_idioms.cpp b/src/idioms/arith_idioms.cpp index f0192a6..25cfcc7 100644 --- a/src/idioms/arith_idioms.cpp +++ b/src/idioms/arith_idioms.cpp @@ -95,7 +95,7 @@ bool Idiom18::match(iICODE picode) m_is_dec = m_icodes[1]->ic.ll.match(iDEC); int type = -1; /* type of variable: 1 = reg-var, 2 = local */ - byte regi; /* register of the MOV */ + uint8_t regi; /* register of the MOV */ /* Get variable */ if (m_icodes[1]->ic.ll.dst.regi == 0) /* global variable */ @@ -238,7 +238,7 @@ int Idiom19::action() bool Idiom20::match(iICODE picode) { uint8_t type = 0; /* type of variable: 1 = reg-var, 2 = local */ - byte regi; /* register of the MOV */ + uint8_t regi; /* register of the MOV */ if(std::distance(picode,m_end)<4) return false; for(int i=0; i<4; ++i) diff --git a/src/idioms/call_idioms.cpp b/src/idioms/call_idioms.cpp index 753f646..035a94f 100644 --- a/src/idioms/call_idioms.cpp +++ b/src/idioms/call_idioms.cpp @@ -38,7 +38,7 @@ int Idiom3::action() { if (m_icodes[0]->ic.ll.flg & I) { - m_icodes[0]->ic.ll.src.proc.proc->cbParam = (int16)m_param_count; + m_icodes[0]->ic.ll.src.proc.proc->cbParam = (int16_t)m_param_count; m_icodes[0]->ic.ll.src.proc.cb = m_param_count; m_icodes[0]->ic.ll.src.proc.proc->flg |= CALL_C; } @@ -73,7 +73,7 @@ bool Idiom17::match(iICODE picode) /* Match ADD SP, immed */ for(int i=0; i<2; ++i) m_icodes.push_back(picode++); - byte regi; + uint8_t regi; /* Match POP reg */ if (m_icodes[1]->ic.ll.match(iPOP)) @@ -98,7 +98,7 @@ int Idiom17::action() { if (m_icodes[0]->isLlFlag(I)) { - m_icodes[0]->ic.ll.src.proc.proc->cbParam = (int16)m_param_count; + m_icodes[0]->ic.ll.src.proc.proc->cbParam = (int16_t)m_param_count; m_icodes[0]->ic.ll.src.proc.cb = m_param_count; m_icodes[0]->ic.ll.src.proc.proc->flg |= CALL_C; for(int idx=1; idxic.ll.flg & I) { - m_param_count = (int16)pIcode->ic.ll.src.op(); + m_param_count = (int16_t)pIcode->ic.ll.src.op(); } } int Idiom4::action() @@ -140,7 +140,7 @@ int Idiom4::action() m_icodes[idx]->invalidate(); if(m_param_count) { - m_func->cbParam = (int16)m_param_count; + m_func->cbParam = (int16_t)m_param_count; m_func->flg |= CALL_PASCAL; } return 1; diff --git a/src/idioms/idiom1.cpp b/src/idioms/idiom1.cpp index d94a32e..12539b3 100644 --- a/src/idioms/idiom1.cpp +++ b/src/idioms/idiom1.cpp @@ -8,7 +8,7 @@ * [PUSH SI] * In which case, the stack variable flags are set ****************************************************************************/ -Int Idiom1::checkStkVars (iICODE pIcode) +int Idiom1::checkStkVars (iICODE pIcode) { /* Look for PUSH SI */ int si_matched=0; @@ -51,12 +51,12 @@ Int Idiom1::checkStkVars (iICODE pIcode) bool Idiom1::match(iICODE picode) { uint8_t type = 0; /* type of variable: 1 = reg-var, 2 = local */ - byte regi; /* register of the MOV */ + uint8_t regi; /* register of the MOV */ if(m_func->flg & PROC_HLL) return false; if(picode==m_end) return false; - Int n; + int n; m_icodes.clear(); m_min_off = 0; /* PUSH BP as first instruction of procedure */ diff --git a/src/idioms/mov_idioms.cpp b/src/idioms/mov_idioms.cpp index 3194181..5f8afa1 100644 --- a/src/idioms/mov_idioms.cpp +++ b/src/idioms/mov_idioms.cpp @@ -3,7 +3,7 @@ using namespace std; /***************************************************************************** - * idiom 14 - Long word assign + * idiom 14 - Long uint16_t assign * MOV regL, mem/reg * XOR regH, regH * Eg: MOV ax, di @@ -61,14 +61,14 @@ int Idiom14::action() /***************************************************************************** - * idiom 13 - Word assign + * idiom 13 - uint16_t assign * MOV regL, mem * MOV regH, 0 * Eg: MOV al, [bp-2] * MOV ah, 0 * => MOV ax, [bp-2] * Found in Borland Turbo C, used for multiplication and division of - * byte operands (ie. they need to be extended to words). + * uint8_t operands (ie. they need to be extended to words). ****************************************************************************/ bool Idiom13::match(iICODE pIcode) { @@ -77,7 +77,7 @@ bool Idiom13::match(iICODE pIcode) m_icodes[0]=pIcode++; m_icodes[1]=pIcode++; m_loaded_reg = 0; - byte regi; + uint8_t regi; /* Check for regL */ regi = m_icodes[0]->ic.ll.dst.regi; @@ -101,7 +101,7 @@ int Idiom13::action() COND_EXPR *lhs,*rhs; lhs = COND_EXPR::idReg (m_loaded_reg, 0, &m_func->localId); m_icodes[0]->setRegDU( m_loaded_reg, eDEF); - m_icodes[0]->du1.numRegsDef--; /* prev byte reg def */ + m_icodes[0]->du1.numRegsDef--; /* prev uint8_t reg def */ rhs = COND_EXPR::id (*m_icodes[0], SRC, m_func, m_icodes[0], *m_icodes[0], NONE); m_icodes[0]->setAsgn(lhs, rhs); m_icodes[1]->invalidate(); diff --git a/src/idioms/neg_idioms.cpp b/src/idioms/neg_idioms.cpp index ace68d1..38e6967 100644 --- a/src/idioms/neg_idioms.cpp +++ b/src/idioms/neg_idioms.cpp @@ -79,7 +79,7 @@ bool Idiom16::match (iICODE picode) for(int i=0; i<3; ++i) m_icodes[i]=picode++; - byte regi = m_icodes[0]->ic.ll.dst.regi; + uint8_t regi = m_icodes[0]->ic.ll.dst.regi; if ((regi >= rAX) && (regi < INDEXBASE)) { if (m_icodes[1]->ic.ll.match(iSBB) && m_icodes[2]->ic.ll.match(iINC)) diff --git a/src/idioms/shift_idioms.cpp b/src/idioms/shift_idioms.cpp index 9d5cc04..51f7339 100644 --- a/src/idioms/shift_idioms.cpp +++ b/src/idioms/shift_idioms.cpp @@ -30,7 +30,7 @@ int Idiom8::action() { int idx; COND_EXPR *rhs,*lhs,*expr; - byte regH,regL; + uint8_t regH,regL; regH=m_icodes[0]->ic.ll.dst.regi; regL=m_icodes[1]->ic.ll.dst.regi; idx = m_func->localId.newLongReg (TYPE_LONG_SIGN, regH, regL, m_icodes[0]); @@ -58,8 +58,8 @@ int Idiom8::action() ****************************************************************************/ bool Idiom15::match(iICODE pIcode) { - Int n = 1; - byte regi; + int n = 1; + uint8_t regi; if(distance(pIcode,m_end)<2) return false; @@ -122,7 +122,7 @@ int Idiom12::action() { int idx; COND_EXPR *rhs,*lhs,*expr; - byte regH,regL; + uint8_t regH,regL; regL=m_icodes[0]->ic.ll.dst.regi; regH=m_icodes[1]->ic.ll.dst.regi; @@ -162,7 +162,7 @@ int Idiom9::action() { int idx; COND_EXPR *rhs,*lhs,*expr; - byte regH,regL; + uint8_t regH,regL; regL=m_icodes[1]->ic.ll.dst.regi; regH=m_icodes[0]->ic.ll.dst.regi; idx = m_func->localId.newLongReg (TYPE_LONG_UNSIGN,regH,regL,m_icodes[0]); diff --git a/src/locident.cpp b/src/locident.cpp index 084f851..8dd78e4 100644 --- a/src/locident.cpp +++ b/src/locident.cpp @@ -5,8 +5,23 @@ * (C) Cristina Cifuentes */ +#include +#include "locident.h" #include "dcc.h" -#include + +ID::ID() : type(TYPE_UNKNOWN),illegal(false),loc(STK_FRAME),hasMacro(false) +{ + name[0]=0; + macro[0]=0; + memset(&id,0,sizeof(id)); +} +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; +} #define LOCAL_ID_DELTA 25 @@ -26,9 +41,9 @@ void LOCAL_ID::newIdent(hlType t, frameType f) /* Creates a new register identifier node of TYPE_BYTE_(UN)SIGN or * TYPE_WORD_(UN)SIGN type. Returns the index to this new entry. */ -Int LOCAL_ID::newByteWordReg(hlType t, byte regi) +int LOCAL_ID::newByteWordReg(hlType t, uint8_t regi) { - Int idx; + int idx; /* Check for entry in the table */ auto found=std::find_if(id_arr.begin(),id_arr.end(),[t,regi](ID &el)->bool { @@ -50,9 +65,9 @@ Int LOCAL_ID::newByteWordReg(hlType t, byte regi) * the array 1 position. The problem is that indexes into this * array have already been saved in several positions; therefore, * flagging this entry as illegal is all that can be done. */ -void LOCAL_ID::flagByteWordId (Int off) +void LOCAL_ID::flagByteWordId (int off) { - Int idx; + int idx; auto found=std::find_if(id_arr.begin(),id_arr.end(),[off](ID &en)->bool { //if (((en.type == TYPE_WORD_SIGN) || (en.type == TYPE_BYTE_SIGN)) && if ((en.isSigned()) && @@ -70,9 +85,9 @@ void LOCAL_ID::flagByteWordId (Int off) /* Creates a new stack identifier node of TYPE_BYTE_(UN)SIGN or * TYPE_WORD_(UN)SIGN type. Returns the index to this new entry. */ -Int LOCAL_ID::newByteWordStk(hlType t, Int off, byte regOff) +int LOCAL_ID::newByteWordStk(hlType t, int off, uint8_t regOff) { - Int idx; + int idx; /* Check for entry in the table */ auto found=std::find_if(id_arr.begin(),id_arr.end(),[off,regOff](ID &el)->bool { @@ -101,9 +116,9 @@ Int LOCAL_ID::newByteWordStk(hlType t, Int off, byte regOff) * regi: indexed register into global variable * ix: index into icode array * t: HIGH_LEVEL type */ -Int LOCAL_ID::newIntIdx(int16 seg, int16 off, byte regi,Int ix, hlType t) +int LOCAL_ID::newIntIdx(int16_t seg, int16_t off, uint8_t regi, int ix, hlType t) { - Int idx; + int idx; /* Check for entry in the table */ for (idx = 0; idx < id_arr.size(); idx++) @@ -128,9 +143,9 @@ Int LOCAL_ID::newIntIdx(int16 seg, int16 off, byte regi,Int ix, hlType t) /* Checks if the entry exists in the locSym, if so, returns the idx to this * entry; otherwise creates a new register identifier node of type * TYPE_LONG_(UN)SIGN and returns the index to this new entry. */ -Int LOCAL_ID::newLongReg(hlType t, byte regH, byte regL, iICODE ix_) +int LOCAL_ID::newLongReg(hlType t, uint8_t regH, uint8_t regL, iICODE ix_) { - Int idx; + int idx; //iICODE ix_; /* Check for entry in the table */ for (idx = 0; idx < id_arr.size(); idx++) @@ -166,9 +181,9 @@ Int LOCAL_ID::newLongReg(hlType t, byte regH, byte regL, iICODE ix_) /* Checks if the entry exists in the locSym, if so, returns the idx to this * entry; otherwise creates a new global identifier node of type * TYPE_LONG_(UN)SIGN and returns the index to this new entry. */ -Int LOCAL_ID::newLongGlb(int16 seg, int16 offH, int16 offL,hlType t) +int LOCAL_ID::newLongGlb(int16_t seg, int16_t offH, int16_t offL,hlType t) { - Int idx; + int idx; /* Check for entry in the table */ for (idx = 0; idx < id_arr.size(); idx++) @@ -193,8 +208,8 @@ Int LOCAL_ID::newLongGlb(int16 seg, int16 offH, int16 offL,hlType t) /* Checks if the entry exists in the locSym, if so, returns the idx to this * entry; otherwise creates a new global identifier node of type * TYPE_LONG_(UN)SIGN and returns the index to this new entry. */ -Int LOCAL_ID::newLongIdx( int16 seg, int16 offH, int16 offL,byte regi, hlType t) -{ Int idx; +int LOCAL_ID::newLongIdx( int16_t seg, int16_t offH, int16_t offL,uint8_t regi, hlType t) +{ int idx; /* Check for entry in the table */ for (idx = 0; idx < id_arr.size(); idx++) @@ -220,9 +235,9 @@ Int LOCAL_ID::newLongIdx( int16 seg, int16 offH, int16 offL,byte regi, hlType t) /* Creates a new stack identifier node of type TYPE_LONG_(UN)SIGN. * Returns the index to this entry. */ -Int LOCAL_ID::newLongStk(hlType t, Int offH, Int offL) +int LOCAL_ID::newLongStk(hlType t, int offH, int offL) { - Int idx; + int idx; /* Check for entry in the table */ for (idx = 0; idx < id_arr.size(); idx++) @@ -249,9 +264,9 @@ Int LOCAL_ID::newLongStk(hlType t, Int offH, Int offL) /* Returns the index to an appropriate long identifier. * Note: long constants should be checked first and stored as a long integer * number in an expression record. */ -Int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, Int off) +int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, int off) { - Int idx; + int idx; LLOperand *pmH, *pmL; iICODE atOffset(pIcode); advance(atOffset,off); @@ -308,8 +323,8 @@ Int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, I * idx : idx into icode array * pProc : ptr to current procedure record * rhs, lhs : return expressions if successful. */ -boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, Int i, - Function * pProc, Assignment &asgn, Int off) +boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i, + Function * pProc, Assignment &asgn, int off) { LLOperand *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */ iICODE atOffset(pIcode); @@ -349,8 +364,8 @@ boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, Int i, * idx : idx into icode array * pProc : ptr to current procedure record * rhs, lhs : return expressions if successful. */ -boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, Int i, - Function * pProc, COND_EXPR *&rhs, COND_EXPR *&lhs, Int off) +boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i, + Function * pProc, COND_EXPR *&rhs, COND_EXPR *&lhs, int off) { LLOperand *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */ iICODE atOffset(pIcode); @@ -384,7 +399,7 @@ boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, Int i, /* Given an index into the local identifier table for a long register * variable, determines whether regi is the high or low part, and returns * the other part */ -byte otherLongRegi (byte regi, Int idx, LOCAL_ID *locTbl) +uint8_t otherLongRegi (uint8_t regi, int idx, LOCAL_ID *locTbl) { ID *id; @@ -405,9 +420,9 @@ byte otherLongRegi (byte regi, Int idx, LOCAL_ID *locTbl) * the local identifier table. If so, macros for these registers are * placed in the local identifier table, as these registers belong to a * long register identifier. */ -void LOCAL_ID::propLongId (byte regL, byte regH, const char *name) +void LOCAL_ID::propLongId (uint8_t regL, uint8_t regH, const char *name) { - Int i; + int i; ID *_id; for (i = 0; i < id_arr.size(); i++) diff --git a/src/parser.cpp b/src/parser.cpp index d5173be..2444faa 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -11,14 +11,14 @@ #include "dcc.h" using namespace std; -static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate); +//static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate); static boolT process_JMP (ICODE * pIcode, STATE * pstate, CALL_GRAPH * pcallGraph); -static void setBits(int16 type, dword start, dword len); -static SYM * updateGlobSym(dword operand, Int size, word duFlag); +static void setBits(int16_t type, uint32_t start, uint32_t len); +static SYM * updateGlobSym(uint32_t operand, int size, uint16_t duFlag); static void process_MOV(ICODE & pIcode, STATE * pstate); -static SYM * lookupAddr (LLOperand *pm, STATE * pstate, Int size, word duFlag); -void interactDis(Function * initProc, Int ic); -static dword SynthLab; +static SYM * lookupAddr (LLOperand *pm, STATE * pstate, int size, uint16_t duFlag); +void interactDis(Function * initProc, int ic); +static uint32_t SynthLab; /* Parses the program, builds the call graph, and returns the list of @@ -34,7 +34,7 @@ void parse (CALL_GRAPH * *pcallGraph) state.setState(rCS, prog.initCS); state.setState(rSS, prog.initSS); state.setState(rSP, prog.initSP); - state.IP = ((dword)prog.initCS << 4) + prog.initIP; + state.IP = ((uint32_t)prog.initCS << 4) + prog.initIP; SynthLab = SYNTHESIZED_MIN; // default-construct a Function object ! @@ -58,7 +58,7 @@ void parse (CALL_GRAPH * *pcallGraph) { /* Create initial procedure at program start address */ start_proc.name="start"; - start_proc.procEntry = (dword)state.IP; + start_proc.procEntry = (uint32_t)state.IP; } /* The state info is for the first procedure */ start_proc.state = state; @@ -81,8 +81,8 @@ void parse (CALL_GRAPH * *pcallGraph) /* Updates the type of the symbol in the symbol table. The size is updated * if necessary (0 means no update necessary). */ -static void updateSymType (dword symbol, hlType symType, Int size) -{ Int i; +static void updateSymType (uint32_t symbol, hlType symType, int size) +{ int i; for (i = 0; i < symtab.size(); i++) if (symtab[i].label == symbol) @@ -97,12 +97,11 @@ static void updateSymType (dword symbol, hlType symType, Int size) /* Returns the size of the string pointed by sym and delimited by delim. * Size includes delimiter. */ -Int strSize (byte *sym, char delim) +int strSize (uint8_t *sym, char delim) { - Int i; - for (i = 0; *sym++ != delim; i++) - ; - return (i+1); + int till_end = sym-prog.Image; + uint8_t *end_ptr=std::find(sym,sym+(prog.cbImage-(till_end)),delim); + return end_ptr-sym+1; } Function *fakeproc=Function::Create(0,0,"fake"); @@ -114,7 +113,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) ICODE _Icode, *pIcode; /* This gets copied to pProc->Icode[] later */ ICODE eIcode; /* extra icodes for iDIV, iIDIV, iXCHG */ SYM * psym; - dword offset; + uint32_t offset; eErrorId err; boolT done = FALSE; @@ -135,8 +134,8 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) while (! done && ! (err = scan(pstate->IP, _Icode))) { - pstate->IP += (dword)_Icode.ic.ll.numBytes; - setBits(BM_CODE, _Icode.ic.ll.label, (dword)_Icode.ic.ll.numBytes); + pstate->IP += (uint32_t)_Icode.ic.ll.numBytes; + setBits(BM_CODE, _Icode.ic.ll.label, (uint32_t)_Icode.ic.ll.numBytes); process_operands(_Icode,pstate); @@ -249,7 +248,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) */ if (ip > 0 && prev.ic.ll.opcode == iCMP && (prev.ic.ll.flg & I)) { - pstate->JCond.immed = (int16)prev.ic.ll.src.op(); + pstate->JCond.immed = (int16_t)prev.ic.ll.src.op(); if (_Icode.ic.ll.opcode == iJA || _Icode.ic.ll.opcode == iJBE) pstate->JCond.immed++; if (_Icode.ic.ll.opcode == iJAE || _Icode.ic.ll.opcode == iJA) @@ -297,12 +296,12 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) case iINT: if (_Icode.ic.ll.src.op() == 0x21 && pstate->f[rAH]) { - Int funcNum = pstate->r[rAH]; - Int operand; - Int size; + int funcNum = pstate->r[rAH]; + int operand; + int size; /* Save function number */ - Icode.back().ic.ll.dst.off = (int16)funcNum; + Icode.back().ic.ll.dst.off = (int16_t)funcNum; //Icode.GetIcode(Icode.GetNumIcodes() - 1)-> /* Program termination: int21h, fn 00h, 31h, 4Ch */ @@ -313,11 +312,11 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) if (pstate->f[rDX]) /* offset goes into DX */ if (funcNum == 0x09) { - operand = ((dword)(word)pstate->r[rDS]<<4) + - (dword)(word)pstate->r[rDX]; + operand = ((uint32_t)(uint16_t)pstate->r[rDS]<<4) + + (uint32_t)(uint16_t)pstate->r[rDX]; size = prog.fCOM ? strSize (&prog.Image[operand], '$') : - strSize (&prog.Image[operand + 0x100], '$'); + strSize (&prog.Image[operand], '$'); // + 0x100 updateSymType (operand, TYPE_STR, size); } } @@ -360,7 +359,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) offset = LH(&prog.Image[psym->label]); pstate->setState( (_Icode.ic.ll.opcode == iLDS)? rDS: rES, LH(&prog.Image[psym->label + 2])); - pstate->setState( _Icode.ic.ll.dst.regi, (int16)offset); + pstate->setState( _Icode.ic.ll.dst.regi, (int16_t)offset); psym->type = TYPE_PTR; } break; @@ -386,11 +385,11 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) /* process_JMP - Handles JMPs, returns TRUE if we should end recursion */ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGraph) { - static byte i2r[4] = {rSI, rDI, rBP, rBX}; + static uint8_t i2r[4] = {rSI, rDI, rBP, rBX}; ICODE _Icode; - dword cs, offTable, endTable; - dword i, k, seg, target; - dword tmp; + uint32_t cs, offTable, endTable; + uint32_t i, k, seg, target; + uint32_t tmp; if (pIcode.ic.ll.flg & I) { @@ -407,10 +406,10 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr } /* We've got an indirect JMP - look for switch() stmt. idiom of the form - * JMP word ptr word_offset[rBX | rSI | rDI] */ + * JMP uint16_t ptr word_offset[rBX | rSI | rDI] */ seg = (pIcode.ic.ll.src.seg)? pIcode.ic.ll.src.seg: rDS; - /* Ensure we have a word offset & valid seg */ + /* Ensure we have a uint16_t offset & valid seg */ if (pIcode.ic.ll.opcode == iJMP && (pIcode.ic.ll.flg & WORD_OFF) && pstate->f[seg] && (pIcode.ic.ll.src.regi == INDEXBASE + 4 || @@ -418,7 +417,7 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr pIcode.ic.ll.src.regi == INDEXBASE + 7)) { - offTable = ((dword)(word)pstate->r[seg] << 4) + pIcode.ic.ll.src.off; + offTable = ((uint32_t)(uint16_t)pstate->r[seg] << 4) + pIcode.ic.ll.src.off; /* Firstly look for a leading range check of the form:- * CMP {BX | SI | DI}, immed @@ -429,9 +428,9 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr if (pstate->JCond.regi == i2r[pIcode.ic.ll.src.regi-(INDEXBASE+4)]) endTable = offTable + pstate->JCond.immed; else - endTable = (dword)prog.cbImage; + endTable = (uint32_t)prog.cbImage; - /* Search for first byte flagged after start of table */ + /* Search for first uint8_t flagged after start of table */ for (i = offTable; i <= endTable; i++) if (BITMAP(i, BM_CODE | BM_DATA)) break; @@ -440,13 +439,13 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr /* Now do some heuristic pruning. Look for ptrs. into the table * and for addresses that don't appear to point to valid code. */ - cs = (dword)(word)pstate->r[rCS] << 4; + cs = (uint32_t)(uint16_t)pstate->r[rCS] << 4; for (i = offTable; i < endTable; i += 2) { target = cs + LH(&prog.Image[i]); if (target < endTable && target >= offTable) endTable = target; - else if (target >= (dword)prog.cbImage) + else if (target >= (uint32_t)prog.cbImage) endTable = i; } @@ -464,14 +463,14 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr if (offTable < endTable) { STATE StCopy; - Int ip; - dword *psw; + int ip; + uint32_t *psw; setBits(BM_DATA, offTable, endTable - offTable); pIcode.ic.ll.flg |= SWITCH; pIcode.ic.ll.caseTbl.numEntries = (endTable - offTable) / 2; - psw = (dword*)allocMem(pIcode.ic.ll.caseTbl.numEntries*sizeof(dword)); + psw = (uint32_t*)allocMem(pIcode.ic.ll.caseTbl.numEntries*sizeof(uint32_t)); pIcode.ic.ll.caseTbl.entries = psw; for (i = offTable, k = 0; i < endTable; i += 2) @@ -514,7 +513,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps { ICODE &last_insn(Icode.back()); STATE localState; /* Local copy of the machine state */ - dword off; + uint32_t off; boolT indirect; /* For Indirect Calls, find the function address */ @@ -540,16 +539,16 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps usually wrong! Consider also CALL [BP+0E] in which the segment for the pointer is in SS! - Mike */ - off = (dword)(word)pIcode.ic.ll.dst.off + - ((dword)(word)pIcode.ic.ll.dst.segValue << 4); + off = (uint32_t)(uint16_t)pIcode.ic.ll.dst.off + + ((uint32_t)(uint16_t)pIcode.ic.ll.dst.segValue << 4); /* Address of function is given by 4 (CALLF) or 2 (CALL) bytes at * previous offset into the program image */ - dword tgtAddr=0; + uint32_t tgtAddr=0; if (pIcode.ic.ll.opcode == iCALLF) - tgtAddr= LH(&prog.Image[off]) + (dword)(LH(&prog.Image[off+2])) << 4; + tgtAddr= LH(&prog.Image[off]) + (uint32_t)(LH(&prog.Image[off+2])) << 4; else - tgtAddr= LH(&prog.Image[off]) + (dword)(word)state.r[rCS] << 4; + tgtAddr= LH(&prog.Image[off]) + (uint32_t)(uint16_t)state.r[rCS] << 4; pIcode.ic.ll.src.SetImmediateOp( tgtAddr ); pIcode.ic.ll.flg |= I; indirect = TRUE; @@ -629,13 +628,13 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps static void process_MOV(ICODE & pIcode, STATE * pstate) { SYM * psym, *psym2; /* Pointer to symbol in global symbol table */ - byte dstReg = pIcode.ic.ll.dst.regi; - byte srcReg = pIcode.ic.ll.src.regi; + uint8_t dstReg = pIcode.ic.ll.dst.regi; + uint8_t srcReg = pIcode.ic.ll.src.regi; if (dstReg > 0 && dstReg < INDEXBASE) { if (pIcode.ic.ll.flg & I) - pstate->setState( dstReg, (int16)pIcode.ic.ll.src.op()); + pstate->setState( dstReg, (int16_t)pIcode.ic.ll.src.op()); else if (srcReg == 0) /* direct memory offset */ { psym = lookupAddr(&pIcode.ic.ll.src, pstate, 2, eDuVal::USE); @@ -652,28 +651,36 @@ static void process_MOV(ICODE & pIcode, STATE * pstate) } } else if (dstReg == 0) { /* direct memory offset */ - psym = lookupAddr (&pIcode.ic.ll.dst, pstate, 2, eDEF); + int size=2; + if((pIcode.ic.ll.src.regi>=rAL)&&(pIcode.ic.ll.src.regi<=rBH)) + size=1; + psym = lookupAddr (&pIcode.ic.ll.dst, pstate, size, eDEF); if (psym && ! (psym->duVal.val)) /* no initial value yet */ - if (pIcode.ic.ll.flg & I) { /* immediate */ - prog.Image[psym->label] = (byte)pIcode.ic.ll.src.op(); - prog.Image[psym->label+1] = (byte)(pIcode.ic.ll.src.op()>>8); + if (pIcode.ic.ll.flg & I) /* immediate */ + { + prog.Image[psym->label] = (uint8_t)pIcode.ic.ll.src.op(); + if(psym->size>1) + prog.Image[psym->label+1] = (uint8_t)(pIcode.ic.ll.src.op()>>8); psym->duVal.val = 1; } - else if (srcReg == 0) { /* direct mem offset */ + else if (srcReg == 0) /* direct mem offset */ + { psym2 = lookupAddr (&pIcode.ic.ll.src, pstate, 2, eDuVal::USE); if (psym2 && ((psym->flg & SEG_IMMED) || (psym->duVal.val))) { - prog.Image[psym->label] = (byte)prog.Image[psym2->label]; - prog.Image[psym->label+1] = - (byte)(prog.Image[psym2->label+1] >> 8); - psym->duVal.val=1; + prog.Image[psym->label] = (uint8_t)prog.Image[psym2->label]; + if(psym->size>1) + prog.Image[psym->label+1] = (uint8_t)(prog.Image[psym2->label+1] >> 8); + psym->duVal.setFlags(eDuVal::DEF); + psym2->duVal.setFlags(eDuVal::USE); } } else if (srcReg < INDEXBASE && pstate->f[srcReg]) /* reg */ { - prog.Image[psym->label] = (byte)pstate->r[srcReg]; - prog.Image[psym->label+1] = (byte)(pstate->r[srcReg] >> 8); - psym->duVal.val; + prog.Image[psym->label] = (uint8_t)pstate->r[srcReg]; + if(psym->size>1) + prog.Image[psym->label+1] = (uint8_t)(pstate->r[srcReg] >> 8); + psym->duVal.setFlags(eDuVal::DEF); } } } @@ -687,9 +694,9 @@ static hlType cbType[] = {TYPE_UNKNOWN, TYPE_BYTE_UNSIGN, TYPE_WORD_SIGN, * is not there yet. If it is part of the symtab, the size of the variable * is checked and updated if the old size was less than the new size (ie. * the maximum size is always saved). */ -static SYM * updateGlobSym (dword operand, Int size, word duFlag) +static SYM * updateGlobSym (uint32_t operand, int size, uint16_t duFlag) { - Int i; + int i; /* Check for symbol in symbol table */ for (i = 0; i < symtab.size(); i++) @@ -697,8 +704,8 @@ static SYM * updateGlobSym (dword operand, Int size, word duFlag) { if (symtab[i].size < size) symtab[i].size = size; - break; - } + break; + } /* New symbol, not in symbol table */ if (i == symtab.size()) @@ -725,9 +732,9 @@ static SYM * updateGlobSym (dword operand, Int size, word duFlag) /* Updates the offset entry to the stack frame table (arguments), * and returns a pointer to such entry. */ -static void updateFrameOff (STKFRAME * ps, int16 off, Int size, word duFlag) +static void updateFrameOff (STKFRAME * ps, int16_t off, int size, uint16_t duFlag) { - Int i; + int i; /* Check for symbol in stack frame table */ for (i = 0; i < ps->sym.size(); i++) @@ -764,8 +771,8 @@ static void updateFrameOff (STKFRAME * ps, int16 off, Int size, word duFlag) } /* Save maximum argument offset */ - if ((dword)ps->maxOff < (off + (dword)size)) - ps->maxOff = off + (int16)size; + if ((uint32_t)ps->maxOff < (off + (uint32_t)size)) + ps->maxOff = off + (int16_t)size; } @@ -773,11 +780,11 @@ static void updateFrameOff (STKFRAME * ps, int16 off, Int size, word duFlag) * if necessary. * Returns a pointer to the symbol in the * symbol table, or Null if it's not a direct memory offset. */ -static SYM * lookupAddr (LLOperand *pm, STATE *pstate, Int size, word duFlag) +static SYM * lookupAddr (LLOperand *pm, STATE *pstate, int size, uint16_t duFlag) { - Int i; + int i; SYM * psym; - dword operand; + uint32_t operand; if (pm->regi == 0) { /* Global var */ if (pm->segValue) { /* there is a value in the seg field */ @@ -785,7 +792,7 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, Int size, word duFlag) psym = updateGlobSym (operand, size, duFlag); /* Check for out of bounds */ - if (psym->label >= (dword)prog.cbImage) + if (psym->label >= (uint32_t)prog.cbImage) return (NULL); return (psym); } @@ -799,7 +806,7 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, Int size, word duFlag) if (symtab.size() > i) { if (size == 4) - operand += 2; /* High word */ + operand += 2; /* High uint16_t */ for (i = 0; i < prog.cReloc; i++) if (prog.relocTable[i] == operand) { psym->flg = SEG_IMMED; @@ -808,7 +815,7 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, Int size, word duFlag) } /* Check for out of bounds */ - if (psym->label >= (dword)prog.cbImage) + if (psym->label >= (uint32_t)prog.cbImage) return (NULL); return (psym); } @@ -818,7 +825,7 @@ static SYM * lookupAddr (LLOperand *pm, STATE *pstate, Int size, word duFlag) /* setState - Assigns a value to a reg. */ -void STATE::setState(word reg, int16 value) +void STATE::setState(uint16_t reg, int16_t value) { value &= 0xFFFF; r[reg] = value; @@ -854,15 +861,15 @@ void STATE::setState(word reg, int16 value) -static void setBits(int16 type, dword start, dword len) +static void setBits(int16_t type, uint32_t start, uint32_t len) /* setBits - Sets memory bitmap bits for BM_CODE or BM_DATA (additively) */ { - dword i; + uint32_t i; - if (start < (dword)prog.cbImage) + if (start < (uint32_t)prog.cbImage) { - if (start + len > (dword)prog.cbImage) - len = (dword)(prog.cbImage - start); + if (start + len > (uint32_t)prog.cbImage) + len = (uint32_t)(prog.cbImage - start); for (i = start + len - 1; i >= start; i--) { @@ -875,10 +882,10 @@ static void setBits(int16 type, dword start, dword len) /* DU bit definitions for each reg value - including index registers */ std::bitset<32> duReg[] = { 0x00, //AH AL . . AX, BH - 0x11001, 0x22002, 0x44004, 0x88008, /* word regs */ + 0x11001, 0x22002, 0x44004, 0x88008, /* uint16_t regs */ 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, /* seg regs */ - 0x1000, 0x2000, 0x4000, 0x8000, /* byte regs */ + 0x1000, 0x2000, 0x4000, 0x8000, /* uint8_t regs */ 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, /* tmp reg */ 0x48, 0x88, 0x60, 0xA0, /* index regs */ @@ -893,7 +900,7 @@ std::bitset<32> duReg[] = { 0x00, * pstate: ptr to current procedure state * size : size of the operand * ix : current index into icode array */ -static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int size, Int ix) +static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size, int ix) { LLOperand * pm = (d == SRC)? &pIcode.ic.ll.src: &pIcode.ic.ll.dst; SYM * psym; @@ -910,7 +917,7 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int else if (pm->regi == INDEXBASE + 2 || pm->regi == INDEXBASE + 3) pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off, - (byte)((pm->regi == INDEXBASE + 2) ? rSI : rDI)); + (uint8_t)((pm->regi == INDEXBASE + 2) ? rSI : rDI)); else if ((pm->regi >= INDEXBASE + 4) && (pm->regi <= INDEXBASE + 7)) { @@ -924,7 +931,7 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int else if (psym = lookupAddr(pm, pstate, size, eDuVal::USE)) { - setBits (BM_DATA, psym->label, (dword)size); + setBits (BM_DATA, psym->label, (uint32_t)size); pIcode.ic.ll.flg |= SYM_USE; pIcode.ic.ll.caseTbl.numEntries = psym - &symtab[0]; } @@ -939,8 +946,8 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int /* Checks which registers were defined (ie. got a new value) and updates the * du.d flag. * Places local variables in the local symbol table. */ -static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int size, - Int ix) +static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size, + int ix) { LLOperand *pm = (d == SRC)? &pIcode.ic.ll.src: &pIcode.ic.ll.dst; SYM * psym; @@ -958,7 +965,7 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int else if (pm->regi == INDEXBASE + 2 || pm->regi == INDEXBASE + 3) { pProc->localId.newByteWordStk(TYPE_WORD_SIGN, pm->off, - (byte)((pm->regi == INDEXBASE + 2) ? rSI : rDI)); + (uint8_t)((pm->regi == INDEXBASE + 2) ? rSI : rDI)); } else if ((pm->regi >= INDEXBASE + 4) && (pm->regi <= INDEXBASE + 7)) @@ -973,7 +980,7 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int else if (psym = lookupAddr(pm, pstate, size, eDEF)) { - setBits(BM_DATA, psym->label, (dword)size); + setBits(BM_DATA, psym->label, (uint32_t)size); pIcode.ic.ll.flg |= SYM_DEF; pIcode.ic.ll.caseTbl.numEntries = psym - &symtab[0]; } @@ -991,8 +998,8 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int /* use_def - operand is both use and def'd. * Note: the destination will always be a register, stack variable, or global * variable. */ -static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, Int cb, - Int ix) +static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int cb, + int ix) { LLOperand * pm = (d == SRC)? &pIcode.ic.ll.src: &pIcode.ic.ll.dst; @@ -1010,11 +1017,11 @@ static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, I * bitmap */ void Function::process_operands(ICODE & pIcode, STATE * pstate) { - Int ix=Icode.size(); - Int i; - Int sseg = (pIcode.ic.ll.src.seg)? pIcode.ic.ll.src.seg: rDS; - Int cb = (pIcode.ic.ll.flg & B) ? 1: 2; - flags32 Imm = (pIcode.ic.ll.flg & I); + int ix=Icode.size(); + int i; + int sseg = (pIcode.ic.ll.src.seg)? pIcode.ic.ll.src.seg: rDS; + int cb = (pIcode.ic.ll.flg & B) ? 1: 2; + uint32_t Imm = (pIcode.ic.ll.flg & I); switch (pIcode.ic.ll.opcode) { case iAND: case iOR: case iXOR: @@ -1072,13 +1079,13 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate) case iSIGNEX: cb = (pIcode.ic.ll.flg & SRC_B) ? 1 : 2; - if (cb == 1) /* byte */ + if (cb == 1) /* uint8_t */ { pIcode.du.def |= duReg[rAX]; pIcode.du1.numRegsDef++; pIcode.du.use |= duReg[rAL]; } - else /* word */ + else /* uint16_t */ { pIcode.du.def |= (duReg[rDX] | duReg[rAX]); pIcode.du1.numRegsDef += 2; diff --git a/src/perfhlib.cpp b/src/perfhlib.cpp index 73ad978..12a7a42 100644 --- a/src/perfhlib.cpp +++ b/src/perfhlib.cpp @@ -11,7 +11,7 @@ /* Private data structures */ -static word *T1, *T2; /* Pointers to T1[i], T2[i] */ +static uint16_t *T1, *T2; /* Pointers to T1[i], T2[i] */ static short *g; /* g[] */ static int numEdges; /* An edge counter */ @@ -39,8 +39,8 @@ PatternHasher::init(int _NumEntry, int _EntryLen, int _SetSize, char _SetMin, NumVert = _NumVert; /* Allocate the variable sized tables etc */ - T1base = new word [EntryLen * SetSize]; - T2base = new word [EntryLen * SetSize]; + T1base = new uint16_t [EntryLen * SetSize]; + T2base = new uint16_t [EntryLen * SetSize]; graphNode = new int [NumEntry*2 + 1]; graphNext = new int [NumEntry*2 + 1]; graphFirst = new int [NumVert + 1]; @@ -66,9 +66,9 @@ void PatternHasher::cleanup(void) // delete [] visited; } -int PatternHasher::hash(byte *string) +int PatternHasher::hash(uint8_t *string) { - word u, v; + uint16_t u, v; int j; u = 0; @@ -90,18 +90,18 @@ int PatternHasher::hash(byte *string) return (g[u] + g[v]) % NumEntry; } -word * PatternHasher::readT1(void) +uint16_t * PatternHasher::readT1(void) { return T1base; } -word *PatternHasher::readT2(void) +uint16_t *PatternHasher::readT2(void) { return T2base; } -word * PatternHasher::readG(void) +uint16_t * PatternHasher::readG(void) { - return (word *)g; + return (uint16_t *)g; } diff --git a/src/procs.cpp b/src/procs.cpp index 047708c..727a14a 100644 --- a/src/procs.cpp +++ b/src/procs.cpp @@ -15,7 +15,7 @@ static char indentBuf[indSize] = " "; -static char *indent (Int indLevel) // Indentation according to the depth of the statement +static char *indent (int indLevel) // Indentation according to the depth of the statement { return (&indentBuf[indSize-(indLevel*3)-1]); } @@ -26,7 +26,7 @@ static char *indent (Int indLevel) // Indentation according to the depth of the void CALL_GRAPH::insertArc (ilFunction newProc) { CALL_GRAPH *pcg; - Int i; + int i; /* Check if procedure already exists */ auto res=std::find_if(outEdges.begin(),outEdges.end(),[newProc](CALL_GRAPH *e) {return e->proc==newProc;}); @@ -42,7 +42,7 @@ void CALL_GRAPH::insertArc (ilFunction newProc) /* Inserts a (caller, callee) arc in the call graph tree. */ boolT CALL_GRAPH::insertCallGraph(ilFunction caller, ilFunction callee) { - Int i; + int i; if (proc == caller) { @@ -69,9 +69,9 @@ boolT CALL_GRAPH::insertCallGraph(Function *caller, ilFunction callee) /* Displays the current node of the call graph, and invokes recursively on * the nodes the procedure invokes. */ -void CALL_GRAPH::writeNodeCallGraph(Int indIdx) +void CALL_GRAPH::writeNodeCallGraph(int indIdx) { - Int i; + int i; printf ("%s%s\n", indent(indIdx), proc->name.c_str()); for (i = 0; i < outEdges.size(); i++) @@ -99,7 +99,7 @@ void Function::newRegArg(iICODE picode, iICODE ticode) COND_EXPR *lhs; STKFRAME * ps, *ts; ID *id; - Int i, tidx; + int i, tidx; boolT regExist; condId type; Function * tproc; @@ -218,7 +218,7 @@ void Function::newRegArg(iICODE picode, iICODE ticode) */ bool CallType::newStkArg(COND_EXPR *exp, llIcode opcode, Function * pproc) { - byte regi; + uint8_t regi; /* Check for far procedure call, in which case, references to segment * registers are not be considered another parameter (i.e. they are * long references to another segment) */ @@ -246,7 +246,7 @@ bool CallType::newStkArg(COND_EXPR *exp, llIcode opcode, Function * pproc) /* Places the actual argument exp in the position given by pos in the * argument list of picode. */ -void CallType::placeStkArg (COND_EXPR *exp, Int pos) +void CallType::placeStkArg (COND_EXPR *exp, int pos) { args->sym[pos].actual = exp; sprintf (args->sym[pos].name, "arg%ld", pos); @@ -259,7 +259,7 @@ void CallType::placeStkArg (COND_EXPR *exp, Int pos) void adjustActArgType (COND_EXPR *exp, hlType forType, Function * pproc) { hlType actType; - Int offset, offL; + int offset, offL; if (exp == NULL) return; @@ -311,11 +311,11 @@ void adjustActArgType (COND_EXPR *exp, hlType forType, Function * pproc) /* Determines whether the formal argument has the same type as the given * type (type of the actual argument). If not, the formal argument is * changed its type */ -void STKFRAME::adjustForArgType(Int numArg_, hlType actType_) +void STKFRAME::adjustForArgType(int numArg_, hlType actType_) { hlType forType; STKSYM * psym, * nsym; - Int off, i; + int off, i; /* Find stack offset for this argument */ off = m_minOff; diff --git a/src/proplong.cpp b/src/proplong.cpp index a2a7989..a2b0277 100644 --- a/src/proplong.cpp +++ b/src/proplong.cpp @@ -22,7 +22,7 @@ static boolT isJCond (llIcode opcode) /* Returns whether the conditions for a 2-3 long variable are satisfied */ -static boolT isLong23 (iICODE iter, BB * pbb, Int *off, Int *arc) +static boolT isLong23 (iICODE iter, BB * pbb, int *off, int *arc) { BB * t, * e, * obb2; @@ -59,7 +59,7 @@ static boolT isLong23 (iICODE iter, BB * pbb, Int *off, Int *arc) /* Returns whether the conditions for a 2-2 long variable are satisfied */ -static boolT isLong22 (iICODE pIcode, iICODE pEnd, Int *off) +static boolT isLong22 (iICODE pIcode, iICODE pEnd, int *off) { if(distance(pIcode,pEnd)<4) return false; @@ -82,7 +82,7 @@ static boolT isLong22 (iICODE pIcode, iICODE pEnd, Int *off) * @return number of ICODEs to skip */ -static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, Int arc, Int off) +static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, int arc, int off) { BB * pbb, * obb1, * obb2, * tbb; int skipped_insn=0; @@ -169,7 +169,7 @@ static int longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, Int arc, */ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEnd) { - Int j; + int j; BB * pbb, * obb1, * tbb; if(distance(pIcode,pEnd)<4) return false; @@ -227,9 +227,9 @@ static int longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode,iICODE pEn * Arguments: i : index into the local identifier table * pLocId: ptr to the long local identifier * pProc : ptr to current procedure's record. */ -void Function::propLongStk (Int i, const ID &pLocId) +void Function::propLongStk (int i, const ID &pLocId) { - Int off, arc; + int off, arc; Assignment asgn; //COND_EXPR *lhs, *rhs; /* Pointers to left and right hand expression */ iICODE next1, pEnd; @@ -502,7 +502,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be * @arg pLocId ptr to the long local identifier * */ -void Function::propLongReg (Int loc_ident_idx, const ID &pLocId) +void Function::propLongReg (int loc_ident_idx, const ID &pLocId) { /* Process all definitions/uses of long registers at an icode position */ // WARNING: this loop modifies the iterated-over container. @@ -526,7 +526,7 @@ void Function::propLongReg (Int loc_ident_idx, const ID &pLocId) /* Propagates the long global address across all LOW_LEVEL icodes. * Transforms some LOW_LEVEL icodes into HIGH_LEVEL */ -void Function::propLongGlb (Int i, const ID &pLocId) +void Function::propLongGlb (int i, const ID &pLocId) { printf("WARN: Function::propLongGlb not implemented"); } @@ -536,7 +536,7 @@ void Function::propLongGlb (Int i, const ID &pLocId) * into HIGH_LEVEL icodes. */ void Function::propLong() { - Int i; + int i; /* Pointer to current local identifier */ for (i = 0; i < localId.csym(); i++) diff --git a/src/reducible.cpp b/src/reducible.cpp index bce61f6..54e3cb7 100644 --- a/src/reducible.cpp +++ b/src/reducible.cpp @@ -10,7 +10,7 @@ #include /* For free() */ #include -static Int numInt; /* Number of intervals */ +static int numInt; /* Number of intervals */ #define nonEmpty(q) (q != NULL) @@ -84,7 +84,7 @@ static void appendNodeInt (queue &pqH, BB *node, interval *pI) auto found_iter=std::find(pqH.begin(),pqH.end(),node); if(found_iter!=pqH.end()) { - pI->numOutEdges -= (byte)(*found_iter)->inEdges.size() - 1; + pI->numOutEdges -= (uint8_t)(*found_iter)->inEdges.size() - 1; pqH.erase(found_iter); } } @@ -103,7 +103,7 @@ void derSeq_Entry::findIntervals (Function *c) BB *h, /* Node being processed */ *header, /* Current interval's header node */ *succ; /* Successor basic block */ - Int i; /* Counter */ + int i; /* Counter */ queue H; /* Queue of possible header nodes */ boolT first = TRUE; /* First pass through the loop */ @@ -116,7 +116,7 @@ void derSeq_Entry::findIntervals (Function *c) { header = firstOfQueue (H); pI = new interval; - pI->numInt = (byte)numInt++; + pI->numInt = (uint8_t)numInt++; if (first) /* ^ to first interval */ Ii = J = pI; appendNodeInt (H, header, pI); /* pI(header) = {header} */ @@ -244,7 +244,7 @@ bool Function::nextOrderGraph (derSeq *derivedGi) *succ /* Successor node */ ; //queue *listIi; /* List of intervals */ - Int i, /* Index to outEdges array */ + int i, /* Index to outEdges array */ j; /* Index to successors */ boolT sameGraph; /* Boolean, isomorphic graphs */ @@ -313,7 +313,7 @@ return (boolT)(! sameGraph); /* Finds the derived sequence of the graph derivedG->Gi (ie. cfg). * Constructs the n-th order graph and places all the intermediate graphs * in the derivedG list sequence. */ -byte Function::findDerivedSeq (derSeq *derivedGi) +uint8_t Function::findDerivedSeq (derSeq *derivedGi) { BB *Gi; /* Current derived sequence graph */ @@ -346,7 +346,7 @@ byte Function::findDerivedSeq (derSeq *derivedGi) /* Converts the irreducible graph G into an equivalent reducible one, by * means of node splitting. */ -static void nodeSplitting (std::vector &G) +static void nodeSplitting (std::list &G) { fprintf(stderr,"Attempt to perform node splitting: NOT IMPLEMENTED\n"); } @@ -354,7 +354,7 @@ static void nodeSplitting (std::vector &G) /* Displays the derived sequence and intervals of the graph G */ void derSeq::display() { - Int n = 1; /* Derived sequence number */ + int n = 1; /* Derived sequence number */ printf ("\nDerived Sequence Intervals\n"); derSeq::iterator iter=this->begin(); while (iter!=this->end()) @@ -374,7 +374,7 @@ void derSeq::display() derSeq * Function::checkReducibility() { derSeq * der_seq; - byte reducible; /* Reducible graph flag */ + uint8_t reducible; /* Reducible graph flag */ numInt = 1; /* reinitialize no. of intervals*/ stats.nOrder = 1; /* nOrder(cfg) = 1 */ diff --git a/src/scanner.cpp b/src/scanner.cpp index cb30cef..2556914 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -10,46 +10,46 @@ #include "dcc.h" #include "scanner.h" -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); +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); #define iZERO (llIcode)0 // For neatness #define IC llIcode static struct { - void (*state1)(Int); - void (*state2)(Int); - flags32 flg; + void (*state1)(int); + void (*state2)(int); + uint32_t flg; llIcode opcode; - byte df; - byte uf; + uint8_t df; + uint8_t uf; } stateTable[] = { { modrm, none2, B , iADD , Sf | Zf | Cf , 0 }, /* 00 */ { modrm, none2, 0 , iADD , Sf | Zf | Cf , 0 }, /* 01 */ @@ -309,8 +309,8 @@ static struct { { trans, none1, NSP , iZERO , 0 , 0 } /* FF */ } ; -static word SegPrefix, RepPrefix; -static byte *pInst; /* Ptr. to current byte of instruction */ +static uint16_t SegPrefix, RepPrefix; +static uint8_t *pInst; /* Ptr. to current uint8_t of instruction */ static ICODE * pIcode; /* Ptr to Icode record filled in by scan() */ @@ -318,13 +318,13 @@ static ICODE * pIcode; /* Ptr to Icode record filled in by scan() */ Scans one machine instruction at offset ip in prog.Image and returns error. At the same time, fill in low-level icode details for the scanned inst. ****************************************************************************/ -eErrorId scan(dword ip, ICODE &p) +eErrorId scan(uint32_t ip, ICODE &p) { - Int op; + int op; p = ICODE(); p.type = LOW_LEVEL; p.ic.ll.label = ip; /* ip is absolute offset into image*/ - if (ip >= (dword)prog.cbImage) + if (ip >= (uint32_t)prog.cbImage) { return (IP_OUT_OF_RANGE); } @@ -349,7 +349,7 @@ eErrorId scan(dword ip, ICODE &p) if (p.ic.ll.opcode) { /* Save bytes of image used */ - p.ic.ll.numBytes = (byte)((pInst - prog.Image) - ip); + p.ic.ll.numBytes = (uint8_t)((pInst - prog.Image) - ip); return ((SegPrefix)? FUNNY_SEGOVR: /* Seg. Override invalid */ (RepPrefix ? FUNNY_REP: NO_ERR));/* REP prefix invalid */ } @@ -359,12 +359,12 @@ eErrorId scan(dword ip, ICODE &p) /*************************************************************************** - relocItem - returns TRUE if word pointed at is in relocation table + relocItem - returns TRUE if uint16_t pointed at is in relocation table **************************************************************************/ -static boolT relocItem(byte *p) +static boolT relocItem(uint8_t *p) { - Int i; - dword off = p - prog.Image; + int i; + uint32_t off = p - prog.Image; for (i = 0; i < prog.cReloc; i++) if (prog.relocTable[i] == off) @@ -374,23 +374,23 @@ static boolT relocItem(byte *p) /*************************************************************************** - getWord - returns next word from image + getWord - returns next uint16_t from image **************************************************************************/ -static word getWord(void) +static uint16_t getWord(void) { - word w = LH(pInst); + uint16_t w = LH(pInst); pInst += 2; return w; } /**************************************************************************** - signex - returns byte sign extended to Int + signex - returns uint8_t sign extended to int ***************************************************************************/ -static Int signex(byte b) +static int signex(uint8_t b) { long s = b; - return ((b & 0x80)? (Int)(0xFFFFFF00 | s): (Int)s); + return ((b & 0x80)? (int)(0xFFFFFF00 | s): (int)s); } @@ -400,7 +400,7 @@ static Int signex(byte b) * Note: fdst == TRUE is for the r/m part of the field (dest, unless TO_REG) * fdst == FALSE is for reg part of the field ***************************************************************************/ -static void setAddress(Int i, boolT fdst, word seg, int16 reg, word off) +static void setAddress(int i, boolT fdst, uint16_t seg, int16_t reg, uint16_t off) { LLOperand *pm; @@ -413,7 +413,7 @@ static void setAddress(Int i, boolT fdst, word seg, int16 reg, word off) * provide the value of this segment in the field segValue. */ if (seg) /* segment override */ { - pm->seg = pm->segOver = (byte)seg; + pm->seg = pm->segOver = (uint8_t)seg; } else { /* no override, check indexed register */ @@ -427,8 +427,8 @@ static void setAddress(Int i, boolT fdst, word seg, int16 reg, word off) pm->seg = rDS; /* any other indexed reg */ } } - pm->regi = (byte)reg; - pm->off = (int16)off; + pm->regi = (uint8_t)reg; + pm->off = (int16_t)off; if (reg && reg < INDEXBASE && (stateTable[i].flg & B)) { pm->regi += rAL - rAX; @@ -442,12 +442,12 @@ static void setAddress(Int i, boolT fdst, word seg, int16 reg, word off) /**************************************************************************** - rm - Decodes r/m part of modrm byte for dst (unless TO_REG) part of icode + rm - Decodes r/m part of modrm uint8_t for dst (unless TO_REG) part of icode ***************************************************************************/ -static void rm(Int i) +static void rm(int i) { - byte mod = *pInst >> 6; - byte rm = *pInst++ & 7; + uint8_t mod = *pInst >> 6; + uint8_t rm = *pInst++ & 7; switch (mod) { case 0: /* No disp unless rm == 6 */ @@ -458,11 +458,11 @@ static void rm(Int i) else setAddress(i, TRUE, SegPrefix, rm + INDEXBASE, 0); break; - case 1: /* 1 byte disp */ - setAddress(i, TRUE, SegPrefix, rm+INDEXBASE, (word)signex(*pInst++)); + case 1: /* 1 uint8_t disp */ + setAddress(i, TRUE, SegPrefix, rm+INDEXBASE, (uint16_t)signex(*pInst++)); break; - case 2: /* 2 byte disp */ + case 2: /* 2 uint8_t disp */ setAddress(i, TRUE, SegPrefix, rm + INDEXBASE, getWord()); pIcode->ic.ll.flg |= WORD_OFF; break; @@ -479,9 +479,9 @@ static void rm(Int i) /**************************************************************************** - modrm - Sets up src and dst from modrm byte + modrm - Sets up src and dst from modrm uint8_t ***************************************************************************/ -static void modrm(Int i) +static void modrm(int i) { setAddress(i, FALSE, 0, REG(*pInst) + rAX, 0); rm(i); @@ -491,14 +491,14 @@ static void modrm(Int i) /**************************************************************************** segrm - seg encoded as reg of modrm ****************************************************************************/ -static void segrm(Int i) +static void segrm(int i) { - Int reg = REG(*pInst) + rES; + int reg = REG(*pInst) + rES; if (reg > rDS || (reg == rCS && (stateTable[i].flg & TO_REG))) pIcode->ic.ll.opcode = (llIcode)0; else { - setAddress(i, FALSE, 0, (int16)reg, 0); + setAddress(i, FALSE, 0, (int16_t)reg, 0); rm(i); } } @@ -507,9 +507,9 @@ static void segrm(Int i) /**************************************************************************** regop - src/dst reg encoded as low 3 bits of opcode ***************************************************************************/ -static void regop(Int i) +static void regop(int i) { - setAddress(i, FALSE, 0, ((int16)i & 7) + rAX, 0); + setAddress(i, FALSE, 0, ((int16_t)i & 7) + rAX, 0); pIcode->ic.ll.dst.regi = pIcode->ic.ll.src.regi; } @@ -517,28 +517,28 @@ static void regop(Int i) /***************************************************************************** segop - seg encoded in middle of opcode *****************************************************************************/ -static void segop(Int i) +static void segop(int i) { - setAddress(i, TRUE, 0, (((int16)i & 0x18) >> 3) + rES, 0); + setAddress(i, TRUE, 0, (((int16_t)i & 0x18) >> 3) + rES, 0); } /**************************************************************************** axImp - Plugs an implied AX dst ***************************************************************************/ -static void axImp(Int i) +static void axImp(int i) { setAddress(i, TRUE, 0, rAX, 0); } /* Implied AX source */ -static void axSrcIm (Int ) +static void axSrcIm (int ) { pIcode->ic.ll.src.regi = rAX; } /* Implied AL source */ -static void alImp (Int ) +static void alImp (int ) { pIcode->ic.ll.src.regi = rAL; } @@ -547,7 +547,7 @@ static void alImp (Int ) /***************************************************************************** memImp - Plugs implied src memory operand with any segment override ****************************************************************************/ -static void memImp(Int i) +static void memImp(int i) { setAddress(i, FALSE, SegPrefix, 0, 0); } @@ -556,7 +556,7 @@ static void memImp(Int i) /**************************************************************************** memOnly - Instruction is not valid if modrm refers to register (i.e. mod == 3) ***************************************************************************/ -static void memOnly(Int ) +static void memOnly(int ) { if ((*pInst & 0xC0) == 0xC0) pIcode->ic.ll.opcode = (llIcode)0; @@ -566,7 +566,7 @@ static void memOnly(Int ) /**************************************************************************** memReg0 - modrm for 'memOnly' and Reg field must also be 0 ****************************************************************************/ -static void memReg0(Int i) +static void memReg0(int i) { if (REG(*pInst) || (*pInst & 0xC0) == 0xC0) pIcode->ic.ll.opcode = (llIcode)0; @@ -576,12 +576,12 @@ static void memReg0(Int i) /*************************************************************************** - immed - Sets up dst and opcode from modrm byte + immed - Sets up dst and opcode from modrm uint8_t **************************************************************************/ -static void immed(Int i) +static void immed(int i) { static llIcode immedTable[8] = {iADD, iOR, iADC, iSBB, iAND, iSUB, iXOR, iCMP}; - static byte uf[8] = { 0, 0, Cf, Cf, 0, 0, 0, 0 }; + static uint8_t uf[8] = { 0, 0, Cf, Cf, 0, 0, 0, 0 }; pIcode->ic.ll.opcode = immedTable[REG(*pInst)]; pIcode->ic.ll.flagDU.u = uf[REG(*pInst)]; @@ -594,16 +594,16 @@ static void immed(Int i) /**************************************************************************** - shift - Sets up dst and opcode from modrm byte + shift - Sets up dst and opcode from modrm uint8_t ***************************************************************************/ -static void shift(Int i) +static void shift(int i) { static llIcode shiftTable[8] = { (llIcode)iROL, (llIcode)iROR, (llIcode)iRCL, (llIcode)iRCR, (llIcode)iSHL, (llIcode)iSHR, (llIcode)0, (llIcode)iSAR}; - static byte uf[8] = {0, 0, Cf, Cf, 0, 0, 0, 0 }; - static byte df[8] = {Cf, Cf, Cf, Cf, Sf | Zf | Cf, + static uint8_t uf[8] = {0, 0, Cf, Cf, 0, 0, 0, 0 }; + static uint8_t df[8] = {Cf, Cf, Cf, Cf, Sf | Zf | Cf, Sf | Zf | Cf, 0, Sf | Zf | Cf}; pIcode->ic.ll.opcode = shiftTable[REG(*pInst)]; @@ -615,18 +615,18 @@ static void shift(Int i) /**************************************************************************** - trans - Sets up dst and opcode from modrm byte + trans - Sets up dst and opcode from modrm uint8_t ***************************************************************************/ -static void trans(Int i) +static void trans(int i) { static llIcode transTable[8] = { (llIcode)iINC, (llIcode)iDEC, (llIcode)iCALL, (llIcode)iCALLF, (llIcode)iJMP, (llIcode)iJMPF,(llIcode)iPUSH, (llIcode)0 }; - static byte df[8] = {Sf | Zf, Sf | Zf, 0, 0, 0, 0, 0, 0}; + static uint8_t df[8] = {Sf | Zf, Sf | Zf, 0, 0, 0, 0, 0, 0}; - if ((byte)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */ + if ((uint8_t)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */ pIcode->ic.ll.opcode = transTable[REG(*pInst)]; /* valid on bytes */ pIcode->ic.ll.flagDU.d = df[REG(*pInst)]; rm(i); @@ -640,16 +640,16 @@ static void trans(Int i) /**************************************************************************** - arith - Sets up dst and opcode from modrm byte + arith - Sets up dst and opcode from modrm uint8_t ****************************************************************************/ -static void arith(Int i) -{ byte opcode; +static void arith(int i) +{ uint8_t opcode; static llIcode arithTable[8] = { (llIcode)iTEST, (llIcode)0, (llIcode)iNOT, (llIcode)iNEG, (llIcode)iMUL, (llIcode)iIMUL, (llIcode)iDIV, (llIcode)iIDIV }; - static byte df[8] = {Sf | Zf | Cf, 0, 0, Sf | Zf | Cf, + static uint8_t df[8] = {Sf | Zf | Cf, 0, 0, Sf | Zf | Cf, Sf | Zf | Cf, Sf | Zf | Cf, Sf | Zf | Cf, Sf | Zf | Cf}; @@ -680,9 +680,9 @@ static void arith(Int i) /***************************************************************************** - data1 - Sets up immed from 1 byte data + data1 - Sets up immed from 1 uint8_t data *****************************************************************************/ -static void data1(Int i) +static void data1(int i) { pIcode->ic.ll.src.SetImmediateOp( (stateTable[i].flg & S_EXT)? signex(*pInst++): *pInst++ ); pIcode->ic.ll.flg |= I; @@ -690,9 +690,9 @@ static void data1(Int i) /***************************************************************************** - data2 - Sets up immed from 2 byte data + data2 - Sets up immed from 2 uint8_t data ****************************************************************************/ -static void data2(Int ) +static void data2(int ) { if (relocItem(pInst)) pIcode->ic.ll.flg |= SEG_IMMED; @@ -714,60 +714,60 @@ static void data2(Int ) /**************************************************************************** - dispM - 2 byte offset without modrm (== mod 0, rm 6) (Note:TO_REG bits are + dispM - 2 uint8_t offset without modrm (== mod 0, rm 6) (Note:TO_REG bits are reversed) ****************************************************************************/ -static void dispM(Int i) +static void dispM(int i) { setAddress(i, FALSE, SegPrefix, 0, getWord()); } /**************************************************************************** - dispN - 2 byte disp as immed relative to ip + dispN - 2 uint8_t disp as immed relative to ip ****************************************************************************/ -static void dispN(Int ) +static void dispN(int ) { long off = (short)getWord(); /* Signed displacement */ /* Note: the result of the subtraction could be between 32k and 64k, and still be positive; it is an offset from prog.Image. So this must be treated as unsigned */ - pIcode->ic.ll.src.SetImmediateOp((dword)(off + (unsigned)(pInst - prog.Image))); + pIcode->ic.ll.src.SetImmediateOp((uint32_t)(off + (unsigned)(pInst - prog.Image))); pIcode->ic.ll.flg |= I; } /*************************************************************************** - dispS - 1 byte disp as immed relative to ip + dispS - 1 uint8_t disp as immed relative to ip ***************************************************************************/ -static void dispS(Int ) +static void dispS(int ) { long off = signex(*pInst++); /* Signed displacement */ - pIcode->ic.ll.src.SetImmediateOp((dword)(off + (unsigned)(pInst - prog.Image))); + pIcode->ic.ll.src.SetImmediateOp((uint32_t)(off + (unsigned)(pInst - prog.Image))); pIcode->ic.ll.flg |= I; } /**************************************************************************** - dispF - 4 byte disp as immed 20-bit target address + dispF - 4 uint8_t disp as immed 20-bit target address ***************************************************************************/ -static void dispF(Int ) +static void dispF(int ) { - dword off = (unsigned)getWord(); - dword seg = (unsigned)getWord(); + uint32_t off = (unsigned)getWord(); + uint32_t seg = (unsigned)getWord(); - pIcode->ic.ll.src.SetImmediateOp(off + ((dword)(unsigned)seg << 4)); + pIcode->ic.ll.src.SetImmediateOp(off + ((uint32_t)(unsigned)seg << 4)); pIcode->ic.ll.flg |= I; } /**************************************************************************** - prefix - picks up prefix byte for following instruction (LOCK is ignored + prefix - picks up prefix uint8_t for following instruction (LOCK is ignored on purpose) ****************************************************************************/ -static void prefix(Int ) +static void prefix(int ) { if (pIcode->ic.ll.opcode == iREPE || pIcode->ic.ll.opcode == iREPNE) RepPrefix = pIcode->ic.ll.opcode; @@ -783,7 +783,7 @@ inline void BumpOpcode(llIcode& ic) /***************************************************************************** strop - checks RepPrefix and converts string instructions accordingly *****************************************************************************/ -static void strop(Int ) +static void strop(int ) { if (RepPrefix) { @@ -804,9 +804,9 @@ static void strop(Int ) /*************************************************************************** escop - esc operands ***************************************************************************/ -static void escop(Int i) +static void escop(int i) { - pIcode->ic.ll.src.SetImmediateOp(REG(*pInst) + (dword)((i & 7) << 3)); + pIcode->ic.ll.src.SetImmediateOp(REG(*pInst) + (uint32_t)((i & 7) << 3)); pIcode->ic.ll.flg |= I; rm(i); } @@ -815,7 +815,7 @@ static void escop(Int i) /**************************************************************************** const1 ****************************************************************************/ -static void const1(Int ) +static void const1(int ) { pIcode->ic.ll.src.SetImmediateOp(1); pIcode->ic.ll.flg |= I; @@ -825,7 +825,7 @@ static void const1(Int ) /***************************************************************************** const3 ****************************************************************************/ -static void const3(Int ) +static void const3(int ) { pIcode->ic.ll.src.SetImmediateOp(3); pIcode->ic.ll.flg |= I; @@ -835,7 +835,7 @@ static void const3(Int ) /**************************************************************************** none1 ****************************************************************************/ -static void none1(Int ) +static void none1(int ) { } @@ -843,7 +843,7 @@ static void none1(Int ) /**************************************************************************** none2 - Sets the NO_OPS flag if the operand is immediate ****************************************************************************/ -static void none2(Int ) +static void none2(int ) { if (pIcode->ic.ll.flg & I) pIcode->ic.ll.flg |= NO_OPS; @@ -852,9 +852,9 @@ static void none2(Int ) /**************************************************************************** Checks for int 34 to int 3B - if so, converts to ESC nn instruction ****************************************************************************/ -static void checkInt(Int ) +static void checkInt(int ) { - word wOp = (word) pIcode->ic.ll.src.op(); + uint16_t wOp = (uint16_t) pIcode->ic.ll.src.op(); if ((wOp >= 0x34) && (wOp <= 0x3B)) { /* This is a Borland/Microsoft floating point emulation instruction. diff --git a/src/symtab.cpp b/src/symtab.cpp index 8d7a7a8..cf4d77d 100644 --- a/src/symtab.cpp +++ b/src/symtab.cpp @@ -10,7 +10,7 @@ \* * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* This file implements a symbol table with a symbolic name, a symbol value - (word), and a procedure number. Two tables are maintained, to be able to + (uint16_t), and a procedure number. Two tables are maintained, to be able to look up by name or by value. Pointers are used for the duplicated symbolic name to save space. Both tables have the same structure. The hash tables automatically expand when they get 90% full; they are @@ -30,7 +30,7 @@ #define TABLESIZE 16 /* Number of entries added each expansion */ /* Probably has to be a power of 2 */ #define STRTABSIZE 256 /* Size string table is inc'd by */ -#define NIL ((word)-1) +#define NIL ((uint16_t)-1) using namespace std; static char *pStrTab; /* Pointer to the current string table */ static int strTabNext; /* Next free index into pStrTab */ @@ -41,8 +41,8 @@ struct hash : public unary_function { size_t operator()(const SYMTABLE & key) const { - word h = 0; - h = (word)(key.symOff ^ (key.symOff >> 8)); + uint16_t h = 0; + h = (uint16_t)(key.symOff ^ (key.symOff >> 8)); return h; } @@ -55,15 +55,15 @@ struct TABLEINFO_TYPE { symTab=valTab=0; } - void deleteVal(dword symOff, Function *symProc, boolT bSymToo); + void deleteVal(uint32_t symOff, Function *symProc, boolT bSymToo); void create(tableType type); void destroy(); private: SYMTABLE *symTab; /* Pointer to the symbol hashed table */ SYMTABLE *valTab; /* Pointer to the value hashed table */ - word numEntry; /* Number of entries in this table */ - word tableSize;/* Size of the table (entries) */ + uint16_t numEntry; /* Number of entries in this table */ + uint16_t tableSize;/* Size of the table (entries) */ unordered_map z; unordered_map z2; }; @@ -133,7 +133,7 @@ void destroySymTables(void) } /* Using the value, read the symbolic name */ -boolT readVal(std::ostringstream &symName, dword symOff, Function * symProc) +boolT readVal(std::ostringstream &symName, uint32_t symOff, Function * symProc) { return false; // no symbolic names for now } diff --git a/tests/prev_base/FIBOS.b b/tests/prev_base/FIBOS.b index 41118ea..4a650fd 100644 --- a/tests/prev_base/FIBOS.b +++ b/tests/prev_base/FIBOS.b @@ -44,8 +44,7 @@ int loc4; while ((loc3 <= loc1)) { printf ("Input number: "); scanf ("%d", &loc2); - loc4 = proc_1 (loc2); - printf ("fibonacci(%d) = %u\n", loc2, loc4); + printf ("fibonacci(%d) = %u\n", loc2, proc_1 (loc2)); loc3 = (loc3 + 1); } /* end of while */ exit (0);