From 8cb5449591e671be5fcb679aaa5897e9d83a31d2 Mon Sep 17 00:00:00 2001 From: Artur K Date: Wed, 22 Feb 2012 20:56:27 +0100 Subject: [PATCH] mooing on --- CMakeLists.txt | 11 +- include/BasicBlock.h | 6 +- include/Procedure.h | 25 +- include/StackFrame.h | 3 +- include/ast.h | 3 +- include/bundle.h | 1 - include/dcc.h | 61 ++-- include/error.h | 47 +-- include/icode.h | 5 +- include/locident.h | 46 +-- include/perfhlib.h | 2 +- include/scanner.h | 31 -- src/BasicBlock.cpp | 9 +- src/ast.cpp | 793 +++++++++++++++++++++---------------------- src/backend.cpp | 17 +- src/chklib.cpp | 19 +- src/control.cpp | 30 +- src/dataflow.cpp | 637 +++++++++++++++++----------------- src/dcc.cpp | 4 +- src/disassem.cpp | 2 +- src/error.cpp | 4 +- src/frontend.cpp | 139 +++----- src/graph.cpp | 10 +- src/hlicode.cpp | 21 +- src/icode.cpp | 5 +- src/idioms.cpp | 16 +- src/parser.cpp | 16 +- src/procs.cpp | 74 ++-- src/proplong.cpp | 332 +++++++++++------- src/reducible.cpp | 31 +- src/scanner.cpp | 521 ++++++++++++++-------------- src/udm.cpp | 9 +- 32 files changed, 1481 insertions(+), 1449 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a43a47..5c81fb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,14 @@ PROJECT(dcc_original) cmake_minimum_required(VERSION 2.8) -ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D__UNIX__ -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS) +ADD_DEFINITIONS(-D__UNIX__ -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS) if(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)") ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D__UNIX__ -D_CRT_NONSTDC_NO_DEPRECATE) add_definitions(/W4) else() - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall --std=c++0x") - SET(CMAKE_CXX_FLAGS_DEBUG "-D_GLIBCXX_DEBUG --coverage ${CMAKE_CXX_FLAGS_DEBUG}" ) + #-D_GLIBCXX_DEBUG + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra --std=c++0x") + SET(CMAKE_CXX_FLAGS_DEBUG "--coverage ${CMAKE_CXX_FLAGS_DEBUG}" ) endif() FIND_PACKAGE(LLVM) @@ -63,9 +64,11 @@ set(dcc_HEADERS include/state.h include/symtab.h include/types.h + include/BasicBlock.h + include/Enums.h + include/IdentType.h include/Procedure.h include/StackFrame.h - include/BasicBlock.h ) ADD_EXECUTABLE(dcc_original ${dcc_SOURCES} ${dcc_HEADERS}) TARGET_LINK_LIBRARIES(dcc_original ${REQ_LLVM_LIBRARIES}) diff --git a/include/BasicBlock.h b/include/BasicBlock.h index c14494b..1da4373 100644 --- a/include/BasicBlock.h +++ b/include/BasicBlock.h @@ -25,7 +25,7 @@ struct BB : public llvm::ilist_node { private: BB(const BB&); - BB() : nodeType(0),traversed(0),start(0),length(0), + BB() : start(0),length(0),nodeType(0),traversed(0), numHlIcodes(0),flg(0), inEdges(0), edges(0),beenOnH(0),inEdgeCount(0),reachingInt(0), @@ -97,8 +97,8 @@ public: Int caseTail; /* tail node for the case */ Int index; /* Index, used in several ways */ - static BB *Create(void *ctx=0,const std::string &s="",Function *parent=0,BB *insertBefore=0); - static BB *Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function * parent); +static BB *Create(void *ctx=0,const std::string &s="",Function *parent=0,BB *insertBefore=0); +static BB *Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function * parent); void writeCode(Int indLevel, Function *pProc, Int *numLoc, Int latchNode, Int ifFollow); void mergeFallThrough(CIcodeRec &Icode); void dfsNumbering(std::vector &dfsLast, Int *first, Int *last); diff --git a/include/Procedure.h b/include/Procedure.h index 00f9640..cdbc076 100644 --- a/include/Procedure.h +++ b/include/Procedure.h @@ -113,20 +113,21 @@ public: void buildCFG(); void controlFlowAnalysis(); void newRegArg(ICODE *picode, ICODE *ticode); -protected: + protected: // TODO: replace those with friend visitor ? - void propLongReg(Int i, ID *pLocId); + void propLongReg(Int loc_ident_idx, ID *pLocId); void propLongStk(Int i, ID *pLocId); void propLongGlb(Int i, ID *pLocId); - void structCases(); - void findExps(); - void genDU1(); - void elimCondCodes(); - void liveRegAnalysis(dword in_liveOut); - void findIdioms(); - void propLong(); - void genLiveKtes(); - byte findDerivedSeq (derSeq *derivedGi); - bool nextOrderGraph(derSeq *derivedGi); + int checkBackwarLongDefs(int loc_ident_idx, ID *pLocId, int pLocId_idx); + void structCases(); + void findExps(); + void genDU1(); + void elimCondCodes(); + void liveRegAnalysis(dword in_liveOut); + void findIdioms(); + void propLong(); + void genLiveKtes(); + byte findDerivedSeq (derSeq *derivedGi); + bool nextOrderGraph(derSeq *derivedGi); }; diff --git a/include/StackFrame.h b/include/StackFrame.h index 316470a..66c2233 100644 --- a/include/StackFrame.h +++ b/include/StackFrame.h @@ -35,11 +35,10 @@ struct STKFRAME int16 maxOff; /* Maximum offset in stack frame*/ Int cb; /* Number of bytes in arguments */ Int numArgs; /* No. of arguments in the table*/ - void adjustForArgType(Int numArg_, hlType actType_); + void adjustForArgType(Int numArg_, hlType actType_); STKFRAME() : sym(0),minOff(0),maxOff(0),cb(0),numArgs(0) { } -public: Int getLocVar(Int off); }; diff --git a/include/ast.h b/include/ast.h index b17bf98..cd4bae8 100644 --- a/include/ast.h +++ b/include/ast.h @@ -74,9 +74,8 @@ public: type=other.type; expr=other.expr; } - COND_EXPR() + COND_EXPR(condNodeType t=UNKNOWN_OP) : type(t) { - type=UNKNOWN_OP; memset(&expr,0,sizeof(_exprNode)); } public: diff --git a/include/bundle.h b/include/bundle.h index e416335..af48ea8 100644 --- a/include/bundle.h +++ b/include/bundle.h @@ -23,7 +23,6 @@ public: #define lineSize 360 /* 3 lines in the mean time */ void newBundle (bundle *procCode); -//void appendStrTab (strTable *strTab, const char *format, ...); Int nextBundleIdx (strTable *strTab); void addLabelBundle (strTable &strTab, Int idx, Int label); void writeBundle (std::ostream &ios, bundle procCode); diff --git a/include/dcc.h b/include/dcc.h index 10dc18c..ec8219d 100644 --- a/include/dcc.h +++ b/include/dcc.h @@ -60,32 +60,29 @@ extern bundle cCode; /* Output C procedure's declaration and code */ /* Procedure FLAGS */ enum PROC_FLAGS { - PROC_BADINST=0x000100,/* Proc contains invalid or 386 instruction */ - PROC_IJMP =0x000200,/* Proc incomplete due to indirect jmp */ - PROC_ICALL =0x000400, /* Proc incomplete due to indirect call */ - PROC_HLL=0x001000, /* Proc is likely to be from a HLL */ - CALL_PASCAL=0x002000, /* Proc uses Pascal calling convention */ - CALL_C=0x004000, /* Proc uses C calling convention */ - CALL_UNKNOWN=0x008000, /* Proc uses unknown calling convention */ - PROC_NEAR=0x010000, /* Proc exits with near return */ - PROC_FAR=0x020000, /* Proc exits with far return */ - GRAPH_IRRED=0x100000, /* Proc generates an irreducible graph */ - SI_REGVAR=0x200000, /* SI is used as a stack variable */ - DI_REGVAR=0x400000, /* DI is used as a stack variable */ - PROC_IS_FUNC=0x800000, /* Proc is a function */ - REG_ARGS=0x1000000, /* Proc has registers as arguments */ - PROC_VARARG=0x2000000, /* Proc has variable arguments */ - PROC_OUTPUT=0x4000000, /* C for this proc has been output */ - PROC_RUNTIME=0x8000000, /* Proc is part of the runtime support */ - PROC_ISLIB=0x10000000, /* Proc is a library function */ - PROC_ASM=0x20000000, /* Proc is an intrinsic assembler routine */ - PROC_IS_HLL=0x40000000 /* Proc has HLL prolog code */ + PROC_BADINST=0x00000100,/* Proc contains invalid or 386 instruction */ + PROC_IJMP =0x00000200,/* Proc incomplete due to indirect jmp */ + PROC_ICALL =0x00000400, /* Proc incomplete due to indirect call */ + PROC_HLL =0x00001000, /* Proc is likely to be from a HLL */ + CALL_PASCAL =0x00002000, /* Proc uses Pascal calling convention */ + CALL_C =0x00004000, /* Proc uses C calling convention */ + CALL_UNKNOWN=0x00008000, /* Proc uses unknown calling convention */ + PROC_NEAR =0x00010000, /* Proc exits with near return */ + PROC_FAR =0x00020000, /* Proc exits with far return */ + GRAPH_IRRED =0x00100000, /* Proc generates an irreducible graph */ + SI_REGVAR =0x00200000, /* SI is used as a stack variable */ + DI_REGVAR =0x00400000, /* DI is used as a stack variable */ + PROC_IS_FUNC=0x00800000, /* Proc is a function */ + REG_ARGS =0x01000000, /* Proc has registers as arguments */ + PROC_VARARG =0x02000000, /* Proc has variable arguments */ + PROC_OUTPUT =0x04000000, /* C for this proc has been output */ + PROC_RUNTIME=0x08000000, /* Proc is part of the runtime support */ + PROC_ISLIB =0x10000000, /* Proc is a library function */ + PROC_ASM =0x20000000, /* Proc is an intrinsic assembler routine */ + PROC_IS_HLL =0x40000000 /* Proc has HLL prolog code */ }; #define CALL_MASK 0xFFFF9FFF /* Masks off CALL_C and CALL_PASCAL */ - - - /**** Global variables ****/ extern char *asm1_name, *asm2_name; /* Assembler output filenames */ @@ -125,13 +122,11 @@ struct PROG /* Loaded program image parameters */ }; extern PROG prog; /* Loaded program image parameters */ -extern char condExp[200]; /* Conditional expression buffer */ -extern char callBuf[100]; /* Function call buffer */ extern dword duReg[30]; /* def/use bits for registers */ extern dword maskDuReg[30]; /* masks off du bits for regs */ /* Registers used by icode instructions */ -static const char *allRegs[21] = {"ax", "cx", "dx", "bx", "sp", "bp", +static constexpr const char *allRegs[21] = {"ax", "cx", "dx", "bx", "sp", "bp", "si", "di", "es", "cs", "ss", "ds", "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh", "tmp"}; @@ -161,24 +156,24 @@ extern STATS stats; /* Icode statistics */ void FrontEnd(char *filename, CALL_GRAPH * *); /* frontend.c */ void *allocMem(Int cb); /* frontend.c */ -void *reallocVar(void *p, Int newsize); /* frontend.c */ + void udm(void); /* udm.c */ void freeCFG(BB * cfg); /* graph.c */ BB * newBB(BB *, Int, Int, byte, Int, Function *); /* graph.c */ void BackEnd(char *filename, CALL_GRAPH *); /* backend.c */ char *cChar(byte c); /* backend.c */ -Int scan(dword ip, ICODE * p); /* scanner.c */ +eErrorId scan(dword ip, ICODE * p); /* scanner.c */ void parse (CALL_GRAPH * *); /* parser.c */ -boolT labelSrch(CIcodeRec &pIc, Int n, dword tg, Int *pIdx); /* parser.c */ + Int strSize (byte *, char); /* parser.c */ void disassem(Int pass, Function * pProc); /* disassem.c */ void interactDis(Function * initProc, Int initIC); /* disassem.c */ -boolT JmpInst(llIcode opcode); /* idioms.c */ +bool JmpInst(llIcode opcode); /* idioms.c */ queue::iterator appendQueue(queue &Q, BB *node); /* reducible.c */ void SetupLibCheck(void); /* chklib.c */ void CleanupLibCheck(void); /* chklib.c */ -boolT LibCheck(Function &p); /* chklib.c */ +bool LibCheck(Function &p); /* chklib.c */ /* Exported functions from procs.c */ boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction); @@ -192,8 +187,8 @@ void removeRegFromLong (byte, LOCAL_ID *, COND_EXPR *); std::string walkCondExpr (const COND_EXPR *exp, Function * pProc, Int *); Int hlTypeSize (const COND_EXPR *, Function *); hlType expType (const COND_EXPR *, Function *); -boolT insertSubTreeReg (COND_EXPR *, COND_EXPR **, byte, LOCAL_ID *); -boolT insertSubTreeLongReg (COND_EXPR *, COND_EXPR **, Int); +bool insertSubTreeReg(COND_EXPR *, COND_EXPR **, byte, LOCAL_ID *); +bool insertSubTreeLongReg (COND_EXPR *, COND_EXPR **, Int); /* Exported functions from hlicode.c */ diff --git a/include/error.h b/include/error.h index e0afd90..9ffeb98 100644 --- a/include/error.h +++ b/include/error.h @@ -5,29 +5,32 @@ #pragma once /* These definitions refer to errorMessage in error.c */ +enum eErrorId +{ + NO_ERR =0, + USAGE, + INVALID_ARG, + INVALID_OPCODE, + INVALID_386OP, + FUNNY_SEGOVR, + FUNNY_REP, + CANNOT_OPEN, + CANNOT_READ, + MALLOC_FAILED, + NEWEXE_FORMAT, -#define USAGE 0 -#define INVALID_ARG 1 -#define INVALID_OPCODE 2 -#define INVALID_386OP 3 -#define FUNNY_SEGOVR 4 -#define FUNNY_REP 5 -#define CANNOT_OPEN 6 -#define CANNOT_READ 7 -#define MALLOC_FAILED 8 -#define NEWEXE_FORMAT 9 - -#define NO_BB 10 -#define INVALID_SYNTHETIC_BB 11 -#define INVALID_INT_BB 12 -#define IP_OUT_OF_RANGE 13 -#define DEF_NOT_FOUND 14 -#define JX_NOT_DEF 15 -#define NOT_DEF_USE 16 -#define REPEAT_FAIL 17 -#define WHILE_FAIL 18 + NO_BB, + INVALID_SYNTHETIC_BB, + INVALID_INT_BB, + IP_OUT_OF_RANGE, + DEF_NOT_FOUND, + JX_NOT_DEF, + NOT_DEF_USE, + REPEAT_FAIL, + WHILE_FAIL +}; -void fatalError(Int errId, ...); -void reportError(Int errId, ...); +void fatalError(eErrorId errId, ...); +void reportError(eErrorId errId, ...); diff --git a/include/icode.h b/include/icode.h index 133da30..b4a780d 100644 --- a/include/icode.h +++ b/include/icode.h @@ -294,13 +294,14 @@ struct LLTYPE dword op; /* idx of immed src op */ struct { /* Call & # actual arg bytes */ Function *proc; /* pointer to target proc (for CALL(F))*/ - int cb; /* # actual arg bytes */ + int cb; /* # actual arg bytes */ } proc; } immed; DU flagDU; /* def/use of flags */ struct { /* Case table if op==JMP && !I */ Int numEntries; /* # entries in case table */ dword *entries; /* array of offsets */ + } caseTbl; Int hllLabNum; /* label # for hll codegen */ bool conditionalJump() @@ -375,7 +376,7 @@ public: void SetLlInvalid(int ip, boolT fInv); dword GetLlLabel(int ip); llIcode GetLlOpcode(int ip); - boolT labelSrch(dword target, Int *pIndex); + bool labelSrch(dword target, dword &pIndex); ICODE * GetIcode(int ip); }; typedef CIcodeRec::iterator iICODE; diff --git a/include/locident.h b/include/locident.h index 465154a..04ee9a0 100644 --- a/include/locident.h +++ b/include/locident.h @@ -34,7 +34,7 @@ typedef enum { TYPE_DOUBLE /* double precision float */ } hlType; -static const char *hlTypes[13] = {"", "char", "unsigned char", "int", "unsigned int", +static constexpr const char *hlTypes[13] = {"", "char", "unsigned char", "int", "unsigned int", "long", "unsigned long", "record", "int *", "char *", "", "float", "double"}; @@ -68,33 +68,33 @@ typedef struct /* ID, LOCAL_ID */ struct ID { - hlType type; /* Probable type */ - boolT illegal;/* Boolean: not a valid field any more */ - IDX_ARRAY idx; /* Index into icode array (REG_FRAME only) */ - frameType loc; /* Frame location */ - boolT hasMacro;/* Identifier requires a macro */ - char macro[10];/* Macro for this identifier */ - char name[20];/* Identifier's name */ - union { /* Different types of identifiers */ - byte regi; /* For TYPE_BYTE(WORD)_(UN)SIGN registers */ - struct { /* For TYPE_BYTE(WORD)_(UN)SIGN on the stack */ - byte regOff; /* register offset (if any) */ - Int off; /* offset from BP */ - } bwId; + hlType type; /* Probable type */ + boolT illegal; /* Boolean: not a valid field any more */ + IDX_ARRAY idx; /* Index into icode array (REG_FRAME only) */ + frameType loc; /* Frame location */ + boolT hasMacro; /* Identifier requires a macro */ + char macro[10]; /* Macro for this identifier */ + char name[20]; /* Identifier's name */ + union { /* Different types of identifiers */ + byte regi; /* For TYPE_BYTE(WORD)_(UN)SIGN registers */ + struct { /* For TYPE_BYTE(WORD)_(UN)SIGN on the stack */ + byte regOff; /* register offset (if any) */ + Int off; /* offset from BP */ + } bwId; BWGLB_TYPE bwGlb; /* For TYPE_BYTE(WORD)_(UN)SIGN globals */ - LONGID_TYPE longId; /* For TYPE_LONG_(UN)SIGN registers */ - LONG_STKID_TYPE longStkId;/* For TYPE_LONG_(UN)SIGN on the stack */ + LONGID_TYPE longId; /* For TYPE_LONG_(UN)SIGN registers */ + LONG_STKID_TYPE longStkId; /* For TYPE_LONG_(UN)SIGN on the stack */ struct { /* For TYPE_LONG_(UN)SIGN globals */ - int16 seg; /* segment value */ - int16 offH; /* offset high */ - int16 offL; /* offset low */ - byte regi; /* optional indexed register */ + int16 seg; /* segment value */ + int16 offH; /* offset high */ + int16 offL; /* offset low */ + byte regi; /* optional indexed register */ } longGlb; - struct { /* For TYPE_LONG_(UN)SIGN constants */ + struct { /* For TYPE_LONG_(UN)SIGN constants */ dword h; /* high word */ dword l; /* low word */ - } longKte; - } id; + } longKte; + } id; ID() { memset(this,0,sizeof(ID)); diff --git a/include/perfhlib.h b/include/perfhlib.h index 9915514..4cd4526 100644 --- a/include/perfhlib.h +++ b/include/perfhlib.h @@ -6,7 +6,7 @@ #define TRUE 1 #define FALSE 0 -#define bool unsigned char +//#define bool unsigned char #define byte unsigned char #define word unsigned short diff --git a/include/scanner.h b/include/scanner.h index 94a8078..473a1c2 100644 --- a/include/scanner.h +++ b/include/scanner.h @@ -3,36 +3,5 @@ */ #define LH(p) ((int)((byte *)(p))[0] + ((int)((byte *)(p))[1] << 8)) - -static void rm(Int i); -static void modrm(Int i); -static void segrm(Int i); -static void data1(Int i); -static void data2(Int i); -static void regop(Int i); -static void segop(Int i); -static void strop(Int i); -static void escop(Int i); -static void axImp(Int i); -static void alImp(Int i); -static void axSrcIm(Int i); -static void memImp(Int i); -static void memReg0(Int i); -static void memOnly(Int i); -static void dispM(Int i); -static void dispS(Int i); -static void dispN(Int i); -static void dispF(Int i); -static void prefix(Int i); -static void immed(Int i); -static void shift(Int i); -static void arith(Int i); -static void trans(Int i); -static void const1(Int i); -static void const3(Int i); -static void none1(Int i); -static void none2(Int i); -static void checkInt(Int i); - /* Extracts reg bits from middle of mod-reg-rm byte */ #define REG(x) ((byte)(x & 0x38) >> 3) diff --git a/src/BasicBlock.cpp b/src/BasicBlock.cpp index 35588c8..c290d5f 100644 --- a/src/BasicBlock.cpp +++ b/src/BasicBlock.cpp @@ -101,12 +101,11 @@ void BB::displayDfs() printf("----\n"); /* Recursive call on successors of current node */ - std::for_each(edges.begin(), edges.end(), - [](TYPEADR_TYPE &pb) + for(TYPEADR_TYPE &pb : edges) { if (pb.BBptr->traversed != DFS_DISP) pb.BBptr->displayDfs(); - }); + } } /* Recursive procedure that writes the code for the given procedure, pointed * to by pBB. @@ -155,7 +154,7 @@ void BB::writeCode (Int indLevel, Function * pProc , Int *numLoc,Int latchNode, { /* Write the code for this basic block */ writeBB(&pProc->Icode.front(), indLevel, pProc, numLoc); - repCond = TRUE; + repCond = true; } /* Condition needs to be inverted if the loop body is along @@ -271,7 +270,7 @@ void BB::writeCode (Int indLevel, Function * pProc , Int *numLoc,Int latchNode, l = writeJcondInv ( back().ic.hl, pProc, numLoc); cCode.appendCode( "\n%s%s", indent(indLevel-1), l); edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, latchNode, follow); - emptyThen = TRUE; + emptyThen = true; } } else /* already visited => emit label */ diff --git a/src/ast.cpp b/src/ast.cpp index dff0c76..179d20e 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -46,24 +46,24 @@ void ICODE::setRegDU (byte regi, operDu du_in) // printf("%s %d %x\n",__FUNCTION__,regi,int(du_in)); switch (du_in) { - case eDEF: - du.def |= duReg[regi]; - du1.numRegsDef++; - printf("%s du.def |= %x\n",__FUNCTION__,duReg[regi]); - break; - case eUSE: - du.use |= duReg[regi]; - printf("%s du.use |= %x\n",__FUNCTION__,duReg[regi]); - break; - case USE_DEF: - du.def |= duReg[regi]; - du1.numRegsDef++; - printf("%s du.def |= %x\n",__FUNCTION__,duReg[regi]); - printf("%s du.use |= %x\n",__FUNCTION__,duReg[regi]); - du.use |= duReg[regi]; - break; - case NONE: /* do nothing */ - break; + case eDEF: + du.def |= duReg[regi]; + du1.numRegsDef++; + printf("%s du.def |= %x\n",__FUNCTION__,duReg[regi]); + break; + case eUSE: + du.use |= duReg[regi]; + printf("%s du.use |= %x\n",__FUNCTION__,duReg[regi]); + break; + case USE_DEF: + du.def |= duReg[regi]; + du1.numRegsDef++; + printf("%s du.def |= %x\n",__FUNCTION__,duReg[regi]); + printf("%s du.use |= %x\n",__FUNCTION__,duReg[regi]); + du.use |= duReg[regi]; + break; + case NONE: /* do nothing */ + break; } } @@ -74,50 +74,36 @@ void ICODE::copyDU(const ICODE &duIcode, operDu _du, operDu duDu) // printf("%s %d,%d from %d to %d\n",__FUNCTION__,int(du),int(duDu),duIcode->ic.ll.opcode,pIcode->ic.ll.opcode); switch (_du) { - case eDEF: - if (duDu == eDEF) - du.def=duIcode.du.def; - else - du.def=duIcode.du.use; - break; - case eUSE: - if (duDu == eDEF) - du.use=duIcode.du.def; - else - du.use =duIcode.du.use; - break; - case USE_DEF: - du = duIcode.du; - break; - case NONE: - assert(false); - break; + case eDEF: + if (duDu == eDEF) + du.def=duIcode.du.def; + else + du.def=duIcode.du.use; + break; + case eUSE: + if (duDu == eDEF) + du.use=duIcode.du.def; + else + du.use =duIcode.du.use; + break; + case USE_DEF: + du = duIcode.du; + break; + case NONE: + assert(false); + break; } printf("%s end: %x,%x\n",__FUNCTION__,du.def,du.use); } -/* Creates a newExp conditional expression node of type t and returns it */ -static COND_EXPR *newCondExp (condNodeType t) -{ - //printf("%s:%d\n",__FUNCTION__,int(t)); - - COND_EXPR *newExp; - - newExp = new COND_EXPR; - //memset(newExp, 0, sizeof(COND_EXPR)); - newExp->type = t; - return (newExp); -} - - /* Creates a conditional boolean expression and returns it */ COND_EXPR *COND_EXPR::boolOp(COND_EXPR *lhs, COND_EXPR *rhs, condOp op) { //printf("%s:%d\n",__FUNCTION__,int(op)); COND_EXPR *newExp; - newExp = newCondExp (BOOLEAN_OP); + newExp = new COND_EXPR(BOOLEAN_OP); newExp->expr.boolExpr.op = op; newExp->expr.boolExpr.lhs = lhs; newExp->expr.boolExpr.rhs = rhs; @@ -132,7 +118,7 @@ COND_EXPR *COND_EXPR::unary(condNodeType t, COND_EXPR *sub_expr) { COND_EXPR *newExp; - newExp = newCondExp (t); + newExp = new COND_EXPR(t); newExp->expr.unaryExp = sub_expr; return (newExp); } @@ -143,9 +129,9 @@ COND_EXPR *COND_EXPR::idGlob (int16 segValue, int16 off) { COND_EXPR *newExp; dword adr; - Int i; + size_t i; - newExp = newCondExp (IDENTIFIER); + newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = GLOB_VAR; adr = opAdr(segValue, off); for (i = 0; i < symtab.size(); i++) @@ -163,7 +149,7 @@ COND_EXPR *COND_EXPR::idReg(byte regi, flags32 icodeFlg, LOCAL_ID *locsym) { COND_EXPR *newExp; - newExp = newCondExp (IDENTIFIER); + newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = REGISTER; if ((icodeFlg & B) || (icodeFlg & SRC_B)) { @@ -184,7 +170,7 @@ COND_EXPR *COND_EXPR::idRegIdx(Int idx, regType reg_type) { COND_EXPR *newExp; - newExp = newCondExp (IDENTIFIER); + newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = REGISTER; newExp->expr.ident.regiType = reg_type; newExp->expr.ident.idNode.regiIdx = idx; @@ -197,11 +183,11 @@ COND_EXPR *COND_EXPR::idLoc(Int off, LOCAL_ID *localId) COND_EXPR *newExp; size_t i; - newExp = newCondExp (IDENTIFIER); + newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = LOCAL_VAR; for (i = 0; i < localId->csym(); i++) if ((localId->id_arr[i].id.bwId.off == off) && - (localId->id_arr[i].id.bwId.regOff == 0)) + (localId->id_arr[i].id.bwId.regOff == 0)) break; if (i == localId->csym()) printf ("Error, cannot find local var\n"); @@ -217,7 +203,7 @@ COND_EXPR *COND_EXPR::idParam(Int off, const STKFRAME * argSymtab) COND_EXPR *newExp; size_t i; - newExp = newCondExp (IDENTIFIER); + newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = PARAM; for (i = 0; i < argSymtab->sym.size(); i++) if (argSymtab->sym[i].off == off) @@ -235,12 +221,12 @@ COND_EXPR *idCondExpIdxGlob (int16 segValue, int16 off, byte regi, const LOCAL_I COND_EXPR *newExp; size_t i; - newExp = newCondExp (IDENTIFIER); + newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = GLOB_VAR_IDX; for (i = 0; i < locSym->csym(); i++) if ((locSym->id_arr[i].id.bwGlb.seg == segValue) && - (locSym->id_arr[i].id.bwGlb.off == off) && - (locSym->id_arr[i].id.bwGlb.regi == regi)) + (locSym->id_arr[i].id.bwGlb.off == off) && + (locSym->id_arr[i].id.bwGlb.regi == regi)) break; if (i == locSym->csym()) printf ("Error, indexed-glob var not found in local id table\n"); @@ -252,9 +238,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 *newExp; - - newExp = newCondExp (IDENTIFIER); + COND_EXPR *newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = CONSTANT; newExp->expr.ident.idNode.kte.kte = kte; newExp->expr.ident.idNode.kte.size = size; @@ -266,9 +250,7 @@ COND_EXPR *COND_EXPR::idKte(dword kte, byte size) * that points to the given index idx. */ COND_EXPR *COND_EXPR::idLongIdx (Int idx) { - COND_EXPR *newExp; - - newExp = newCondExp (IDENTIFIER); + COND_EXPR *newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = LONG_VAR; newExp->expr.ident.idNode.longIdx = idx; return (newExp); @@ -278,10 +260,8 @@ 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, Int ix, operDu du, Int off) { - COND_EXPR *newExp; Int idx; - - newExp = newCondExp (IDENTIFIER); + 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 */ @@ -289,7 +269,7 @@ COND_EXPR *COND_EXPR::idLong(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst newExp->expr.ident.idType = CONSTANT; if (f == HIGH_FIRST) newExp->expr.ident.idNode.kte.kte = (pIcode->ic.ll.immed.op << 16) + - (pIcode+off)->ic.ll.immed.op; + (pIcode+off)->ic.ll.immed.op; else /* LOW_FIRST */ newExp->expr.ident.idNode.kte.kte = ((pIcode+off)->ic.ll.immed.op << 16)+ pIcode->ic.ll.immed.op; @@ -311,7 +291,7 @@ COND_EXPR *COND_EXPR::idFunc(Function * pproc, STKFRAME * args) { COND_EXPR *newExp; - newExp = newCondExp (IDENTIFIER); + newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = FUNCTION; newExp->expr.ident.idNode.call.proc = pproc; newExp->expr.ident.idNode.call.args = args; @@ -326,7 +306,7 @@ COND_EXPR *COND_EXPR::idOther(byte seg, byte regi, int16 off) { COND_EXPR *newExp; - newExp = newCondExp (IDENTIFIER); + newExp = new COND_EXPR(IDENTIFIER); newExp->expr.ident.idType = OTHER; newExp->expr.ident.idNode.other.seg = seg; newExp->expr.ident.idNode.other.regi = regi; @@ -342,7 +322,7 @@ COND_EXPR *COND_EXPR::idID (const ID *retVal, LOCAL_ID *locsym, Int ix) COND_EXPR *newExp; Int idx; - newExp = newCondExp (IDENTIFIER); + newExp = new COND_EXPR(IDENTIFIER); if (retVal->type == TYPE_LONG_SIGN) { idx = locsym->newLongReg (TYPE_LONG_SIGN, retVal->id.longId.h,retVal->id.longId.l, ix); @@ -373,8 +353,8 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, Int i, const ICODEMEM * pm = (sd == SRC) ? &pIcode.ic.ll.src : &pIcode.ic.ll.dst; if (((sd == DST) && (pIcode.ic.ll.flg & IM_DST) == IM_DST) || - ((sd == SRC) && (pIcode.ic.ll.flg & IM_SRC)) || - (sd == LHS_OP)) /* for MUL lhs */ + ((sd == SRC) && (pIcode.ic.ll.flg & IM_SRC)) || + (sd == LHS_OP)) /* for MUL lhs */ { /* implicit dx:ax */ idx = pProc->localId.newLongReg (TYPE_LONG_SIGN, rDX, rAX, i); newExp = COND_EXPR::idLongIdx (idx); @@ -428,20 +408,20 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, Int i, if ((pm->seg == rDS) && (pm->regi > INDEXBASE + 3)) /* dereference */ { switch (pm->regi) { - case INDEXBASE + 4: newExp = COND_EXPR::idReg(rSI, 0, &pProc->localId); - duIcode.setRegDU( rSI, du); - break; - case INDEXBASE + 5: newExp = COND_EXPR::idReg(rDI, 0, &pProc->localId); - duIcode.setRegDU( rDI, du); - break; - case INDEXBASE + 6: newExp = COND_EXPR::idReg(rBP, 0, &pProc->localId); - break; - case INDEXBASE + 7: newExp = COND_EXPR::idReg(rBX, 0, &pProc->localId); - duIcode.setRegDU( rBX, du); - break; - default: - newExp = 0; - assert(false); + case INDEXBASE + 4: newExp = COND_EXPR::idReg(rSI, 0, &pProc->localId); + duIcode.setRegDU( rSI, du); + break; + case INDEXBASE + 5: newExp = COND_EXPR::idReg(rDI, 0, &pProc->localId); + duIcode.setRegDU( rDI, du); + break; + case INDEXBASE + 6: newExp = COND_EXPR::idReg(rBP, 0, &pProc->localId); + break; + case INDEXBASE + 7: newExp = COND_EXPR::idReg(rBX, 0, &pProc->localId); + duIcode.setRegDU( rBX, du); + break; + default: + newExp = 0; + assert(false); } newExp = COND_EXPR::unary (DEREFERENCE, newExp); } @@ -491,47 +471,47 @@ Int hlTypeSize (const COND_EXPR *expr, Function * pproc) return (2); /* for TYPE_UNKNOWN */ switch (expr->type) { - case BOOLEAN_OP: - first = hlTypeSize (expr->expr.boolExpr.lhs, pproc); - second = hlTypeSize (expr->expr.boolExpr.rhs, pproc); - if (first > second) - return (first); + case BOOLEAN_OP: + first = hlTypeSize (expr->expr.boolExpr.lhs, pproc); + second = hlTypeSize (expr->expr.boolExpr.rhs, pproc); + if (first > second) + return (first); + else + return (second); + + case NEGATION: case ADDRESSOF: + case POST_INC: case POST_DEC: + case PRE_INC: case PRE_DEC: + case DEREFERENCE: return (hlTypeSize (expr->expr.unaryExp, pproc)); + + case IDENTIFIER: + switch (expr->expr.ident.idType) + { + case GLOB_VAR: + return (symtab[expr->expr.ident.idNode.globIdx].size); + case REGISTER: + if (expr->expr.ident.regiType == BYTE_REG) + return (1); else - return (second); - - case NEGATION: case ADDRESSOF: - case POST_INC: case POST_DEC: - case PRE_INC: case PRE_DEC: - case DEREFERENCE: return (hlTypeSize (expr->expr.unaryExp, pproc)); - - case IDENTIFIER: - switch (expr->expr.ident.idType) - { - case GLOB_VAR: - return (symtab[expr->expr.ident.idNode.globIdx].size); - case REGISTER: - if (expr->expr.ident.regiType == BYTE_REG) - return (1); - else - return (2); - case LOCAL_VAR: - return (hlSize[pproc->localId.id_arr[expr->expr.ident.idNode.localIdx].type]); - case PARAM: - return (hlSize[pproc->args.sym[expr->expr.ident.idNode.paramIdx].type]); - case GLOB_VAR_IDX: - return (hlSize[pproc->localId.id_arr[expr->expr.ident.idNode.idxGlbIdx].type]); - case CONSTANT: - return (expr->expr.ident.idNode.kte.size); - case STRING: - return (2); - case LONG_VAR: - return (4); - case FUNCTION: - return (hlSize[expr->expr.ident.idNode.call.proc->retVal.type]); - case OTHER: - return (2); - } /* eos */ - break; + return (2); + case LOCAL_VAR: + return (hlSize[pproc->localId.id_arr[expr->expr.ident.idNode.localIdx].type]); + case PARAM: + return (hlSize[pproc->args.sym[expr->expr.ident.idNode.paramIdx].type]); + case GLOB_VAR_IDX: + return (hlSize[pproc->localId.id_arr[expr->expr.ident.idNode.idxGlbIdx].type]); + case CONSTANT: + return (expr->expr.ident.idNode.kte.size); + case STRING: + return (2); + case LONG_VAR: + return (4); + case FUNCTION: + return (hlSize[expr->expr.ident.idNode.call.proc->retVal.type]); + case OTHER: + return (2); + } /* eos */ + break; } return 2; // CC: is this correct? } @@ -547,56 +527,57 @@ hlType expType (const COND_EXPR *expr, Function * pproc) switch (expr->type) { - case BOOLEAN_OP: - first = expType (expr->expr.boolExpr.lhs, pproc); - second = expType (expr->expr.boolExpr.rhs, pproc); - if (first != second) - { - if (hlTypeSize (expr->expr.boolExpr.lhs, pproc) > + case BOOLEAN_OP: + first = expType (expr->expr.boolExpr.lhs, pproc); + second = expType (expr->expr.boolExpr.rhs, pproc); + if (first != second) + { + if (hlTypeSize (expr->expr.boolExpr.lhs, pproc) > hlTypeSize (expr->expr.boolExpr.rhs, pproc)) - return (first); - else - return (second); - } - else return (first); + else + return (second); + } + else + return (first); - case POST_INC: case POST_DEC: - case PRE_INC: case PRE_DEC: - case NEGATION: return (expType (expr->expr.unaryExp, pproc)); + case POST_INC: case POST_DEC: + case PRE_INC: case PRE_DEC: + case NEGATION: + return (expType (expr->expr.unaryExp, pproc)); - case ADDRESSOF: return (TYPE_PTR); /***????****/ - case DEREFERENCE: return (TYPE_PTR); - case IDENTIFIER: - switch (expr->expr.ident.idType) - { - case GLOB_VAR: - return (symtab[expr->expr.ident.idNode.globIdx].type); - case REGISTER: - if (expr->expr.ident.regiType == BYTE_REG) - return (TYPE_BYTE_SIGN); - else - return (TYPE_WORD_SIGN); - case LOCAL_VAR: - return (pproc->localId.id_arr[expr->expr.ident.idNode.localIdx].type); - case PARAM: - return (pproc->args.sym[expr->expr.ident.idNode.paramIdx].type); - case GLOB_VAR_IDX: - return (pproc->localId.id_arr[expr->expr.ident.idNode.idxGlbIdx].type); - case CONSTANT: - return (TYPE_CONST); - case STRING: - return (TYPE_STR); - case LONG_VAR: - return (pproc->localId.id_arr[expr->expr.ident.idNode.longIdx].type); - case FUNCTION: - return (expr->expr.ident.idNode.call.proc->retVal.type); - case OTHER: - return (TYPE_UNKNOWN); - } /* eos */ - case UNKNOWN_OP: - assert(false); + case ADDRESSOF: return (TYPE_PTR); /***????****/ + case DEREFERENCE: return (TYPE_PTR); + case IDENTIFIER: + switch (expr->expr.ident.idType) + { + case GLOB_VAR: + return (symtab[expr->expr.ident.idNode.globIdx].type); + case REGISTER: + if (expr->expr.ident.regiType == BYTE_REG) + return (TYPE_BYTE_SIGN); + else + return (TYPE_WORD_SIGN); + case LOCAL_VAR: + return (pproc->localId.id_arr[expr->expr.ident.idNode.localIdx].type); + case PARAM: + return (pproc->args.sym[expr->expr.ident.idNode.paramIdx].type); + case GLOB_VAR_IDX: + return (pproc->localId.id_arr[expr->expr.ident.idNode.idxGlbIdx].type); + case CONSTANT: + return (TYPE_CONST); + case STRING: + return (TYPE_STR); + case LONG_VAR: + return (pproc->localId.id_arr[expr->expr.ident.idNode.longIdx].type); + case FUNCTION: + return (expr->expr.ident.idNode.call.proc->retVal.type); + case OTHER: return (TYPE_UNKNOWN); + } /* eos */ + case UNKNOWN_OP: + assert(false); + return (TYPE_UNKNOWN); } return TYPE_UNKNOWN; // CC: Correct? } @@ -611,23 +592,23 @@ void removeRegFromLong (byte regi, LOCAL_ID *locId, COND_EXPR *tree) byte otherRegi; /* high or low part of long register */ switch (tree->type) { - case BOOLEAN_OP: - break; - case POST_INC: case POST_DEC: - case PRE_INC: case PRE_DEC: - case NEGATION: case ADDRESSOF: - case DEREFERENCE: - break; - case IDENTIFIER: - ident = &tree->expr.ident; - if (ident->idType == LONG_VAR) - { - otherRegi = otherLongRegi (regi, ident->idNode.longIdx, locId); - ident->idType = REGISTER; - ident->regiType = WORD_REG; - ident->idNode.regiIdx = locId->newByteWordReg(TYPE_WORD_SIGN,otherRegi); - } - break; + case BOOLEAN_OP: + break; + case POST_INC: case POST_DEC: + case PRE_INC: case PRE_DEC: + case NEGATION: case ADDRESSOF: + case DEREFERENCE: + break; + case IDENTIFIER: + ident = &tree->expr.ident; + if (ident->idType == LONG_VAR) + { + otherRegi = otherLongRegi (regi, ident->idNode.longIdx, locId); + ident->idType = REGISTER; + ident->regiType = WORD_REG; + ident->idNode.regiIdx = locId->newByteWordReg(TYPE_WORD_SIGN,otherRegi); + } + break; } } @@ -651,168 +632,168 @@ static std::string getString (Int offset) // TODO: use string stream here string walkCondExpr (const COND_EXPR* expr, Function * pProc, Int* numLoc) { - int16 off; /* temporal - for OTHER */ - ID* id; /* Pointer to local identifier table */ - char* o; /* Operand string pointer */ - boolT needBracket; /* Determine whether parenthesis is needed */ - BWGLB_TYPE* bwGlb; /* Ptr to BWGLB_TYPE (global indexed var) */ - STKSYM * psym; /* Pointer to argument in the stack */ + int16 off; /* temporal - for OTHER */ + ID* id; /* Pointer to local identifier table */ + //char* o; /* Operand string pointer */ + bool needBracket; /* Determine whether parenthesis is needed */ + BWGLB_TYPE* bwGlb; /* Ptr to BWGLB_TYPE (global indexed var) */ + STKSYM * psym; /* Pointer to argument in the stack */ std::ostringstream outStr; if (expr == NULL) return ""; - needBracket = TRUE; + needBracket = true; switch (expr->type) { - case BOOLEAN_OP: - outStr << "("; - outStr << walkCondExpr(expr->expr.boolExpr.lhs, pProc, numLoc); - outStr << condOpSym[expr->expr.boolExpr.op]; - outStr << walkCondExpr(expr->expr.boolExpr.rhs, pProc, numLoc); + case BOOLEAN_OP: + outStr << "("; + outStr << walkCondExpr(expr->expr.boolExpr.lhs, pProc, numLoc); + outStr << condOpSym[expr->expr.boolExpr.op]; + outStr << walkCondExpr(expr->expr.boolExpr.rhs, pProc, numLoc); + outStr << ")"; + break; + + case NEGATION: + if (expr->expr.unaryExp->type == IDENTIFIER) + { + needBracket = FALSE; + outStr << "!"; + } + else + outStr << "! ("; + outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc); + if (needBracket == TRUE) outStr << ")"; - break; + break; - case NEGATION: - if (expr->expr.unaryExp->type == IDENTIFIER) + case ADDRESSOF: + if (expr->expr.unaryExp->type == IDENTIFIER) + { + needBracket = FALSE; + outStr << "&"; + } + else + outStr << "&("; + outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc); + if (needBracket == TRUE) + outStr << ")"; + break; + + case DEREFERENCE: + outStr << "*"; + if (expr->expr.unaryExp->type == IDENTIFIER) + needBracket = FALSE; + else + outStr << "("; + outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc); + if (needBracket == TRUE) + outStr << ")"; + break; + + case POST_INC: + outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc) << "++"; + break; + + case POST_DEC: + outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc) << "--"; + break; + + case PRE_INC: + outStr << "++"<< walkCondExpr (expr->expr.unaryExp, pProc, numLoc); + break; + + case PRE_DEC: + outStr << "--"<< walkCondExpr (expr->expr.unaryExp, pProc, numLoc); + break; + + case IDENTIFIER: + std::ostringstream o; + switch (expr->expr.ident.idType) + { + case GLOB_VAR: + o << symtab[expr->expr.ident.idNode.globIdx].name; + break; + case REGISTER: + id = &pProc->localId.id_arr[expr->expr.ident.idNode.regiIdx]; + if (id->name[0] == '\0') /* no name */ { - needBracket = FALSE; - outStr << "!"; + sprintf (id->name, "loc%ld", ++(*numLoc)); + if (id->id.regi < rAL) + cCode.appendDecl("%s %s; /* %s */\n",hlTypes[id->type], id->name,wordReg[id->id.regi - rAX]); + else + cCode.appendDecl("%s %s; /* %s */\n",hlTypes[id->type], id->name,byteReg[id->id.regi - rAL]); } + if (id->hasMacro) + o << id->macro << "("<name<<")"; else - outStr << "! ("; - outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc); - if (needBracket == TRUE) - outStr << ")"; + o << id->name; break; - case ADDRESSOF: - if (expr->expr.unaryExp->type == IDENTIFIER) + case LOCAL_VAR: + o << pProc->localId.id_arr[expr->expr.ident.idNode.localIdx].name; + break; + + case PARAM: + psym = &pProc->args.sym[expr->expr.ident.idNode.paramIdx]; + if (psym->hasMacro) + o << psym->macro<<"("<name<< ")"; + else + o << psym->name; + break; + + case GLOB_VAR_IDX: + bwGlb = &pProc->localId.id_arr[expr->expr.ident.idNode.idxGlbIdx].id.bwGlb; + o << (bwGlb->seg << 4) + bwGlb->off << "["<regi - rAX]<<"]"; + break; + + case CONSTANT: + if (expr->expr.ident.idNode.kte.kte < 1000) + o << expr->expr.ident.idNode.kte.kte; + else + o << "0x"<expr.ident.idNode.kte.kte; + break; + + case STRING: + o << getString (expr->expr.ident.idNode.strIdx); + break; + + case LONG_VAR: + id = &pProc->localId.id_arr[expr->expr.ident.idNode.longIdx]; + if (id->name[0] != '\0') /* STK_FRAME & REG w/name*/ + o << id->name; + else if (id->loc == REG_FRAME) { - needBracket = FALSE; - outStr << "&"; + sprintf (id->name, "loc%ld", ++(*numLoc)); + cCode.appendDecl("%s %s; /* %s:%s */\n",hlTypes[id->type], id->name,wordReg[id->id.longId.h - rAX],wordReg[id->id.longId.l - rAX]); + o << id->name; + pProc->localId.propLongId (id->id.longId.l,id->id.longId.h, id->name); } - else - outStr << "&("; - outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc); - if (needBracket == TRUE) - outStr << ")"; - break; - - case DEREFERENCE: - outStr << "*"; - if (expr->expr.unaryExp->type == IDENTIFIER) - needBracket = FALSE; - else - outStr << "("; - outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc); - if (needBracket == TRUE) - outStr << ")"; - break; - - case POST_INC: - outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc) << "++"; - break; - - case POST_DEC: - outStr << walkCondExpr (expr->expr.unaryExp, pProc, numLoc) << "--"; - break; - - case PRE_INC: - outStr << "++"<< walkCondExpr (expr->expr.unaryExp, pProc, numLoc); - break; - - case PRE_DEC: - outStr << "--"<< walkCondExpr (expr->expr.unaryExp, pProc, numLoc); - break; - - case IDENTIFIER: - std::ostringstream o; - switch (expr->expr.ident.idType) + else /* GLB_FRAME */ { - case GLOB_VAR: - o << symtab[expr->expr.ident.idNode.globIdx].name; - break; - case REGISTER: - id = &pProc->localId.id_arr[expr->expr.ident.idNode.regiIdx]; - if (id->name[0] == '\0') /* no name */ - { - sprintf (id->name, "loc%ld", ++(*numLoc)); - if (id->id.regi < rAL) - cCode.appendDecl("%s %s; /* %s */\n",hlTypes[id->type], id->name,wordReg[id->id.regi - rAX]); - else - cCode.appendDecl("%s %s; /* %s */\n",hlTypes[id->type], id->name,byteReg[id->id.regi - rAL]); - } - if (id->hasMacro) - o << id->macro << "("<name<<")"; - else - o << id->name; - break; - - case LOCAL_VAR: - o << pProc->localId.id_arr[expr->expr.ident.idNode.localIdx].name; - break; - - case PARAM: - psym = &pProc->args.sym[expr->expr.ident.idNode.paramIdx]; - if (psym->hasMacro) - o << psym->macro<<"("<name<< ")"; - else - o << psym->name; - break; - - case GLOB_VAR_IDX: - bwGlb = &pProc->localId.id_arr[expr->expr.ident.idNode.idxGlbIdx].id.bwGlb; - o << (bwGlb->seg << 4) + bwGlb->off << "["<regi - rAX]<<"]"; - break; - - case CONSTANT: - if (expr->expr.ident.idNode.kte.kte < 1000) - o << expr->expr.ident.idNode.kte.kte; - else - o << "0x"<expr.ident.idNode.kte.kte; - break; - - case STRING: - o << getString (expr->expr.ident.idNode.strIdx); - break; - - case LONG_VAR: - id = &pProc->localId.id_arr[expr->expr.ident.idNode.longIdx]; - if (id->name[0] != '\0') /* STK_FRAME & REG w/name*/ - o << id->name; - else if (id->loc == REG_FRAME) - { - sprintf (id->name, "loc%ld", ++(*numLoc)); - cCode.appendDecl("%s %s; /* %s:%s */\n",hlTypes[id->type], id->name,wordReg[id->id.longId.h - rAX],wordReg[id->id.longId.l - rAX]); - o << id->name; - pProc->localId.propLongId (id->id.longId.l,id->id.longId.h, id->name); - } - else /* GLB_FRAME */ - { - if (id->id.longGlb.regi == 0) /* not indexed */ - o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"]"; - else if (id->id.longGlb.regi == rBX) - o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"][bx]"; - } - break; - - case FUNCTION: - o << writeCall (expr->expr.ident.idNode.call.proc,expr->expr.ident.idNode.call.args, pProc, numLoc); - break; - - case OTHER: - off = expr->expr.ident.idNode.other.off; - o << wordReg[expr->expr.ident.idNode.other.seg - rAX]<< "["; - o << idxReg[expr->expr.ident.idNode.other.regi - INDEXBASE]; - if (off < 0) - o << "-"<< hexStr (-off); - else if (off>0) - o << "+"<< hexStr (off); - o << "]"; - } /* eos */ - outStr << o.str(); + if (id->id.longGlb.regi == 0) /* not indexed */ + o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"]"; + else if (id->id.longGlb.regi == rBX) + o << "[" << (id->id.longGlb.seg<<4) + id->id.longGlb.offH <<"][bx]"; + } break; + + case FUNCTION: + o << writeCall (expr->expr.ident.idNode.call.proc,expr->expr.ident.idNode.call.args, pProc, numLoc); + break; + + case OTHER: + off = expr->expr.ident.idNode.other.off; + o << wordReg[expr->expr.ident.idNode.other.seg - rAX]<< "["; + o << idxReg[expr->expr.ident.idNode.other.regi - INDEXBASE]; + if (off < 0) + o << "-"<< hexStr (-off); + else if (off>0) + o << "+"<< hexStr (off); + o << "]"; + } /* eos */ + outStr << o.str(); + break; } return outStr.str(); @@ -827,21 +808,21 @@ COND_EXPR *COND_EXPR::clone() switch (type) { - case BOOLEAN_OP: - newExp = new COND_EXPR(*this); - newExp->expr.boolExpr.lhs = expr.boolExpr.lhs->clone(); - newExp->expr.boolExpr.rhs = expr.boolExpr.rhs->clone(); - break; + case BOOLEAN_OP: + newExp = new COND_EXPR(*this); + newExp->expr.boolExpr.lhs = expr.boolExpr.lhs->clone(); + newExp->expr.boolExpr.rhs = expr.boolExpr.rhs->clone(); + break; - case NEGATION: - case ADDRESSOF: - case DEREFERENCE: - newExp = new COND_EXPR(*this); - newExp->expr.unaryExp = expr.unaryExp->clone(); - break; + case NEGATION: + case ADDRESSOF: + case DEREFERENCE: + newExp = new COND_EXPR(*this); + newExp->expr.unaryExp = expr.unaryExp->clone(); + break; - case IDENTIFIER: - newExp = new COND_EXPR(*this); + case IDENTIFIER: + return new COND_EXPR(*this); } return (newExp); } @@ -856,7 +837,7 @@ void COND_EXPR::changeBoolOp (condOp newOp) /* Inserts the expression exp into the tree at the location specified by the * register regi */ -boolT insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, byte regi,LOCAL_ID *locsym) +bool insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, byte regi,LOCAL_ID *locsym) { byte treeReg; @@ -864,39 +845,39 @@ boolT insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, byte regi,LOCAL_ID *l return FALSE; switch ((*tree)->type) { - case IDENTIFIER: - if ((*tree)->expr.ident.idType == REGISTER) + case IDENTIFIER: + if ((*tree)->expr.ident.idType == REGISTER) + { + treeReg = locsym->id_arr[(*tree)->expr.ident.idNode.regiIdx].id.regi; + if (treeReg == regi) /* word reg */ { - treeReg = locsym->id_arr[(*tree)->expr.ident.idNode.regiIdx].id.regi; - if (treeReg == regi) /* word reg */ + *tree = expr; + return TRUE; + } + else if ((regi >= rAX) && (regi <= rBX)) /* word/byte reg */ + { + if ((treeReg == (regi + rAL-1)) || (treeReg == (regi + rAH-1))) { *tree = expr; return TRUE; } - else if ((regi >= rAX) && (regi <= rBX)) /* word/byte reg */ - { - if ((treeReg == (regi + rAL-1)) || (treeReg == (regi + rAH-1))) - { - *tree = expr; - return TRUE; - } - } } - return FALSE; + } + return FALSE; - case BOOLEAN_OP: - if (insertSubTreeReg (expr, &(*tree)->expr.boolExpr.lhs, regi, locsym)) - return TRUE; - if (insertSubTreeReg (expr, &(*tree)->expr.boolExpr.rhs, regi, locsym)) - return TRUE; - return FALSE; + case BOOLEAN_OP: + if (insertSubTreeReg (expr, &(*tree)->expr.boolExpr.lhs, regi, locsym)) + return TRUE; + if (insertSubTreeReg (expr, &(*tree)->expr.boolExpr.rhs, regi, locsym)) + return TRUE; + return FALSE; - case NEGATION: - case ADDRESSOF: - case DEREFERENCE: - if (insertSubTreeReg(expr, &(*tree)->expr.unaryExp,regi, locsym)) - return TRUE; - return FALSE; + case NEGATION: + case ADDRESSOF: + case DEREFERENCE: + if (insertSubTreeReg(expr, &(*tree)->expr.unaryExp,regi, locsym)) + return TRUE; + return FALSE; } return FALSE; } @@ -904,29 +885,33 @@ boolT insertSubTreeReg (COND_EXPR *expr, COND_EXPR **tree, byte regi,LOCAL_ID *l /* Inserts the expression exp into the tree at the location specified by the * long register index longIdx*/ -boolT insertSubTreeLongReg (COND_EXPR *exp, COND_EXPR **tree, Int longIdx) +bool insertSubTreeLongReg(COND_EXPR *exp, COND_EXPR **tree, Int longIdx) { - switch ((*tree)->type) { - case IDENTIFIER: if ((*tree)->expr.ident.idNode.longIdx == longIdx) - { - *tree = exp; - return TRUE; - } - return FALSE; + switch ((*tree)->type) + { + case IDENTIFIER: + if ((*tree)->expr.ident.idNode.longIdx == longIdx) + { + *tree = exp; + return true; + } + return false; - case BOOLEAN_OP: if (insertSubTreeLongReg (exp, &(*tree)->expr.boolExpr.lhs, longIdx)) - return TRUE; - if (insertSubTreeLongReg (exp, &(*tree)->expr.boolExpr.rhs, longIdx)) - return TRUE; - return FALSE; + case BOOLEAN_OP: + if (insertSubTreeLongReg (exp, &(*tree)->expr.boolExpr.lhs, longIdx)) + return true; + if (insertSubTreeLongReg (exp, &(*tree)->expr.boolExpr.rhs, longIdx)) + return true; + return false; - case NEGATION: - case ADDRESSOF: - case DEREFERENCE: if (insertSubTreeLongReg (exp, &(*tree)->expr.unaryExp, longIdx)) - return TRUE; - return FALSE; + case NEGATION: + case ADDRESSOF: + case DEREFERENCE: + if (insertSubTreeLongReg (exp, &(*tree)->expr.unaryExp, longIdx)) + return true; + return false; } - return FALSE; + return false; } @@ -935,15 +920,15 @@ void COND_EXPR::release() { switch (type) { - case BOOLEAN_OP: - expr.boolExpr.lhs->release(); - expr.boolExpr.rhs->release(); - break; - case NEGATION: - case ADDRESSOF: - case DEREFERENCE: - expr.unaryExp->release(); - break; + case BOOLEAN_OP: + expr.boolExpr.lhs->release(); + expr.boolExpr.rhs->release(); + break; + case NEGATION: + case ADDRESSOF: + case DEREFERENCE: + expr.unaryExp->release(); + break; } delete (this); } diff --git a/src/backend.cpp b/src/backend.cpp index 7e4757c..eda0c14 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -127,12 +127,14 @@ static void printGlobVar (SYM * psym) prog.Image[relocOp+1], prog.Image[relocOp+2], prog.Image[relocOp+3]); break; - default:strContents = (char *)allocMem((psym->size*2+1) *sizeof(char)); + default: + strContents = (char *)malloc((psym->size*2+1) *sizeof(char)); strContents[0] = '\0'; for (j=0; j < psym->size; j++) strcat (strContents, cChar(prog.Image[relocOp + j])); cCode.appendDecl( "char\t*%s = \"%s\";\n", psym->name, strContents); + free(strContents); } } @@ -362,20 +364,17 @@ static void backBackEnd (char *filename, CALL_GRAPH * pcallGraph, std::ostream & /* Invokes the necessary routines to produce code one procedure at a time. */ void BackEnd (char *fileName, CALL_GRAPH * pcallGraph) { - char* outName, *ext; std::ofstream fs; /* Output C file */ /* Get output file name */ - outName = strcpy ((char*)allocMem(strlen(fileName)+1), fileName); - if ((ext = strrchr (outName, '.')) != NULL) - *ext = '\0'; - strcat (outName, ".b"); /* b for beta */ + std::string outNam(fileName); + outNam = outNam.substr(0,outNam.rfind("."))+".b"; /* b for beta */ /* Open output file */ - fs.open(outName); + fs.open(outNam); if(!fs.is_open()) - fatalError (CANNOT_OPEN, outName); - printf ("dcc: Writing C beta file %s\n", outName); + fatalError (CANNOT_OPEN, outNam.c_str()); + printf ("dcc: Writing C beta file %s\n", outNam.c_str()); /* Header information */ writeHeader (fs, fileName); diff --git a/src/chklib.cpp b/src/chklib.cpp index 8526422..e793c0b 100644 --- a/src/chklib.cpp +++ b/src/chklib.cpp @@ -55,7 +55,7 @@ static word *T1base, *T2base; /* Pointers to start of T1, T2 */ static word *g; /* g[] */ static HT *ht; /* The hash table */ static PH_FUNC_STRUCT *pFunc; /* Points to the array of func names */ -static hlType *pArg; /* Points to the array of param types */ +static hlType *pArg=0; /* Points to the array of param types */ static int numFunc; /* Number of func names actually stored */ static int numArg; /* Number of param names actually stored */ #define DCCLIBS "dcclibs.dat" /* Name of the prototypes data file */ @@ -390,7 +390,8 @@ void SetupLibCheck(void) /* This is now the hash table */ /* First allocate space for the table */ - if ((ht = (HT *)allocMem(numKeys * sizeof(HT))) == 0) + ht = new HT[numKeys]; + if ( 0 == ht) { printf("Could not allocate hash table\n"); exit(1); @@ -422,19 +423,18 @@ void SetupLibCheck(void) } -void -CleanupLibCheck(void) +void CleanupLibCheck(void) { /* Deallocate all the stuff allocated in SetupLibCheck() */ - if (ht) free(ht); - if (pFunc)free(pFunc); + delete [] ht; + delete [] pFunc; } /* Check this function to see if it is a library function. Return TRUE if it is, and copy its name to pProc->name */ -boolT LibCheck(Function & pProc) +bool LibCheck(Function & pProc) { long fileOffset; int h, i, j, arg; @@ -904,7 +904,7 @@ readProtoFile(void) numFunc = readFileShort(fProto); /* Num of entries to allocate */ /* Allocate exactly correct # entries */ - pFunc = (PH_FUNC_STRUCT*) allocMem(numFunc * sizeof(PH_FUNC_STRUCT)); + pFunc = new PH_FUNC_STRUCT[numFunc]; for (i=0; i < numFunc; i++) { @@ -925,7 +925,8 @@ readProtoFile(void) numArg = readFileShort(fProto); /* Num of entries to allocate */ /* Allocate exactly correct # entries */ - pArg = (hlType*) allocMem(numArg * sizeof(hlType)); + delete [] pArg; + pArg = new hlType[numArg]; for (i=0; i < numArg; i++) { diff --git a/src/control.cpp b/src/control.cpp index 425edcc..85f58cd 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -76,10 +76,8 @@ void Function::findImmedDom () currNode = dfsLast[currIdx]; if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */ continue; - - for (j = 0; j < currNode->inEdges.size(); j++) + for (BB * inedge : currNode->inEdges) { - BB* inedge=currNode->inEdges[j]; predIdx = inedge->dfsLastNum; if (predIdx < currIdx) currNode->immedDom = commonDom (currNode->immedDom, predIdx, this); @@ -257,14 +255,12 @@ static void findNodesInInt (queue &intNodes, Int level, interval *Ii) { if (level == 1) { - std::for_each(Ii->nodes.begin(),Ii->nodes.end(),[&intNodes](BB *en)->void { - appendQueue(intNodes,en); - }); + for(BB *en : Ii->nodes) + appendQueue(intNodes,en); } else - std::for_each(Ii->nodes.begin(),Ii->nodes.end(),[&intNodes,level](BB *en)->void { - findNodesInInt(intNodes,level-1,en->correspInt); - }); + for(BB *en : Ii->nodes) + findNodesInInt(intNodes,level-1,en->correspInt); } @@ -339,10 +335,11 @@ void Function::structLoops(derSeq *derivedG) } -static boolT successor (Int s, Int h, Function * pProc) /* Returns whether the BB indexed by s is a successor of the BB indexed by * h. Note that h is a case node. */ -{ Int i; +static boolT successor (Int s, Int h, Function * pProc) +{ + Int i; BB * header; header = pProc->dfsLast[h]; @@ -406,11 +403,12 @@ void Function::structCases() * header field with caseHeader. */ insertList (caseNodes, i); dfsLast[i]->caseHead = i; - std::for_each(caseHeader->edges.begin(),caseHeader->edges.end(), - [&caseNodes, i, exitNode](TYPEADR_TYPE &pb) - {tagNodesInCase(pb.BBptr, caseNodes, i, exitNode);}); -// for (j = 0; j < caseHeader->edges[j]; j++) -// tagNodesInCase (caseHeader->edges[j].BBptr, caseNodes, i, exitNode); + for(TYPEADR_TYPE &pb : caseHeader->edges) + { + tagNodesInCase(pb.BBptr, caseNodes, i, exitNode); + } + //for (j = 0; j < caseHeader->edges[j]; j++) + // tagNodesInCase (caseHeader->edges[j].BBptr, caseNodes, i, exitNode); if (exitNode != NO_NODE) dfsLast[exitNode]->caseHead = i; } diff --git a/src/dataflow.cpp b/src/dataflow.cpp index b873e9c..e43e961 100644 --- a/src/dataflow.cpp +++ b/src/dataflow.cpp @@ -15,11 +15,11 @@ struct ExpStack typedef std::list EXP_STK; EXP_STK expStk; /* local expression stack */ - void init(); - void push(COND_EXPR *); - COND_EXPR *pop(); - Int numElem(); - boolT empty(); + void init(); + void push(COND_EXPR *); + COND_EXPR * pop(); + Int numElem(); + boolT empty(); }; /*************************************************************************** * Expression stack functions @@ -70,7 +70,8 @@ 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 i; +{ + Int i; for (i = 0; i < sym.size(); i++) if (sym[i].off == off) @@ -84,16 +85,16 @@ static COND_EXPR *srcIdent (const ICODE &Icode, Function * pProc, Int i, ICODE & { COND_EXPR *n; - if (Icode.ic.ll.flg & I) /* immediate operand */ - { - if (Icode.ic.ll.flg & B) - n = COND_EXPR::idKte (Icode.ic.ll.immed.op, 1); - else - n = COND_EXPR::idKte (Icode.ic.ll.immed.op, 2); - } - else - n = COND_EXPR::id (Icode, SRC, pProc, i, duIcode, du); - return (n); + if (Icode.ic.ll.flg & I) /* immediate operand */ + { + if (Icode.ic.ll.flg & B) + n = COND_EXPR::idKte (Icode.ic.ll.immed.op, 1); + else + n = COND_EXPR::idKte (Icode.ic.ll.immed.op, 2); + } + else + n = COND_EXPR::id (Icode, SRC, pProc, i, duIcode, du); + return (n); } @@ -145,35 +146,35 @@ void Function::elimCondCodes () { switch (defAt->GetLlOpcode()) { - case iCMP: - rhs = srcIdent (*defAt, this, defAt->loc_ip,*useAt, eUSE); - lhs = dstIdent (*defAt, this, defAt->loc_ip,*useAt, eUSE); - break; + case iCMP: + rhs = srcIdent (*defAt, this, defAt->loc_ip,*useAt, eUSE); + lhs = dstIdent (*defAt, this, defAt->loc_ip,*useAt, eUSE); + break; - case iOR: - lhs = defAt->ic.hl.oper.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.oper.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: - rhs = srcIdent (*defAt,this, defAt->loc_ip,*useAt, eUSE); - lhs = dstIdent (*defAt,this, defAt->loc_ip,*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; + case iTEST: + rhs = srcIdent (*defAt,this, defAt->loc_ip,*useAt, eUSE); + lhs = dstIdent (*defAt,this, defAt->loc_ip,*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; - default: - notSup = TRUE; - std::cout << hex<loc_ip; - reportError (JX_NOT_DEF, defAt->GetLlOpcode()); - flg |= PROC_ASM; /* generate asm */ + default: + notSup = TRUE; + std::cout << hex<loc_ip; + reportError (JX_NOT_DEF, defAt->GetLlOpcode()); + flg |= PROC_ASM; /* generate asm */ } if (! notSup) { @@ -326,7 +327,7 @@ void Function::liveRegAnalysis (dword in_liveOut) else /* library routine */ { if ((pcallee->flg & PROC_IS_FUNC) && /* returns a value */ - (pcallee->liveOut & pbb->edges[0].BBptr->liveIn)) + (pcallee->liveOut & pbb->edges[0].BBptr->liveIn)) pbb->liveOut = pcallee->liveOut; else pbb->liveOut = 0; @@ -335,13 +336,13 @@ void Function::liveRegAnalysis (dword in_liveOut) if ((! (pcallee->flg & PROC_ISLIB)) || (pbb->liveOut != 0)) { switch (pcallee->retVal.type) { - case TYPE_LONG_SIGN: case TYPE_LONG_UNSIGN: - ticode.du1.numRegsDef = 2; - break; - case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN: - case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN: - ticode.du1.numRegsDef = 1; - break; + case TYPE_LONG_SIGN: case TYPE_LONG_UNSIGN: + ticode.du1.numRegsDef = 2; + break; + case TYPE_WORD_SIGN: case TYPE_WORD_UNSIGN: + case TYPE_BYTE_SIGN: case TYPE_BYTE_UNSIGN: + ticode.du1.numRegsDef = 1; + break; } /*eos*/ /* Propagate def/use results to calling icode */ @@ -454,7 +455,7 @@ void Function::genDU1 () * next basic block (unoptimized code) or somewhere else * on optimized code. */ if ((picode->ic.hl.opcode == HLI_CALL) && - (picode->ic.hl.oper.call.proc->flg & PROC_IS_FUNC)) + (picode->ic.hl.oper.call.proc->flg & PROC_IS_FUNC)) { tbb = pbb->edges[0].BBptr; useIdx = 0; @@ -476,7 +477,7 @@ void Function::genDU1 () * register is live out, if so, make it the last * definition of this register */ if ((picode->du1.idx[defRegIdx][useIdx] == 0) && - (tbb->liveOut & duReg[regi])) + (tbb->liveOut & duReg[regi])) picode->du.lastDefRegi |= duReg[regi]; } @@ -487,11 +488,11 @@ void Function::genDU1 () * return an integer, which is normally not taken into * account by the programmer). */ if ((picode->invalid == FALSE) && - (picode->du1.idx[defRegIdx][0] == 0) && - (! (picode->du.lastDefRegi & duReg[regi])) && - // (! ((picode->ic.hl.opcode != HLI_CALL) && - (! ((picode->ic.hl.opcode == HLI_CALL) && - (picode->ic.hl.oper.call.proc->flg & PROC_ISLIB)))) + (picode->du1.idx[defRegIdx][0] == 0) && + (! (picode->du.lastDefRegi & duReg[regi])) && + // (! ((picode->ic.hl.opcode != HLI_CALL) && + (! ((picode->ic.hl.opcode == HLI_CALL) && + (picode->ic.hl.oper.call.proc->flg & PROC_ISLIB)))) { if (! (pbb->liveOut & duReg[regi])) /* not liveOut */ { @@ -525,7 +526,7 @@ void Function::genDU1 () /* Check if all defined registers have been processed */ if ((defRegIdx >= picode->du1.numRegsDef) || - (defRegIdx == MAX_REGS_DEF)) + (defRegIdx == MAX_REGS_DEF)) break; } } @@ -611,38 +612,38 @@ static boolT xClear (COND_EXPR *rhs, iICODE f, Int t, iICODE lastBBinst, Functio return false; switch (rhs->type) { - case IDENTIFIER: - if (rhs->expr.ident.idType == REGISTER) - { - picode = &pproc->Icode.front(); - regi= pproc->localId.id_arr[rhs->expr.ident.idNode.regiIdx].id.regi; - for (i = (f + 1); (i != lastBBinst) && (i->loc_ip < t); i++) - if ((i->type == HIGH_LEVEL) && (i->invalid == FALSE)) - { - if (i->du.def & duReg[regi]) - return false; - } - if (i != lastBBinst) - return true; - return false; - } - else + case IDENTIFIER: + if (rhs->expr.ident.idType == REGISTER) + { + picode = &pproc->Icode.front(); + regi= pproc->localId.id_arr[rhs->expr.ident.idNode.regiIdx].id.regi; + for (i = (f + 1); (i != lastBBinst) && (i->loc_ip < t); i++) + if ((i->type == HIGH_LEVEL) && (i->invalid == FALSE)) + { + if (i->du.def & duReg[regi]) + return false; + } + if (i != lastBBinst) return true; - /* else if (rhs->expr.ident.idType == LONG_VAR) + return false; + } + else + return true; + /* else if (rhs->expr.ident.idType == LONG_VAR) { missing all other identifiers **** } */ - case BOOLEAN_OP: - res = xClear (rhs->expr.boolExpr.rhs, f, t, lastBBinst, pproc); - if (res == FALSE) - return false; - return (xClear (rhs->expr.boolExpr.lhs, f, t, lastBBinst, pproc)); + case BOOLEAN_OP: + res = xClear (rhs->expr.boolExpr.rhs, f, t, lastBBinst, pproc); + if (res == FALSE) + return false; + return (xClear (rhs->expr.boolExpr.lhs, f, t, lastBBinst, pproc)); - case NEGATION: - case ADDRESSOF: - case DEREFERENCE: - return (xClear (rhs->expr.unaryExp, f, t, lastBBinst, pproc)); + case NEGATION: + case ADDRESSOF: + case DEREFERENCE: + return (xClear (rhs->expr.unaryExp, f, t, lastBBinst, pproc)); } /* eos */ return false; } @@ -725,7 +726,7 @@ void Function::findExps() * the last definition of the register in this BB, check * that it is not liveOut from this basic block */ if ((picode->du1.idx[0][0] != 0) && - (picode->du1.idx[0][1] == 0)) + (picode->du1.idx[0][1] == 0)) { /* Check that this register is not liveOut, if it * is the last definition of the register */ @@ -733,134 +734,134 @@ void Function::findExps() /* Check if we can forward substitute this register */ switch (picode->ic.hl.opcode) { - case HLI_ASSIGN: - /* Replace rhs of current icode into target + case HLI_ASSIGN: + /* Replace rhs of current icode into target * icode expression */ - ticode = Icode.begin()+picode->du1.idx[0][0]; - if ((picode->du.lastDefRegi & duReg[regi]) && + ticode = Icode.begin()+picode->du1.idx[0][0]; + if ((picode->du.lastDefRegi & duReg[regi]) && ((ticode->ic.hl.opcode != HLI_CALL) && (ticode->ic.hl.opcode != HLI_RET))) - continue; + continue; - if (xClear (picode->ic.hl.oper.asgn.rhs, picode, - picode->du1.idx[0][0], lastInst, this)) + if (xClear (picode->ic.hl.oper.asgn.rhs, picode, + picode->du1.idx[0][0], lastInst, this)) + { + switch (ticode->ic.hl.opcode) { + case HLI_ASSIGN: + forwardSubs (picode->ic.hl.oper.asgn.lhs, + picode->ic.hl.oper.asgn.rhs, + &(*picode), &(*ticode), &localId, + &numHlIcodes); + break; + + case HLI_JCOND: case HLI_PUSH: case HLI_RET: + res = insertSubTreeReg ( + picode->ic.hl.oper.asgn.rhs, + &ticode->ic.hl.oper.exp, + localId.id_arr[picode->ic.hl.oper.asgn.lhs->expr.ident.idNode.regiIdx].id.regi, + &localId); + if (res) + { + picode->invalidate(); + numHlIcodes--; + } + break; + + case HLI_CALL: /* register arguments */ + newRegArg (&(*picode), &(*ticode)); + picode->invalidate(); + numHlIcodes--; + break; + } /* eos */ + } + break; + + case HLI_POP: + ticode = Icode.begin()+(picode->du1.idx[0][0]); + if ((picode->du.lastDefRegi & duReg[regi]) && + ((ticode->ic.hl.opcode != HLI_CALL) && + (ticode->ic.hl.opcode != HLI_RET))) + continue; + + exp = g_exp_stk.pop(); /* pop last exp pushed */ + switch (ticode->ic.hl.opcode) { + case HLI_ASSIGN: + forwardSubs (picode->ic.hl.oper.exp, exp, + &(*picode), &(*ticode), &localId, + &numHlIcodes); + break; + + case HLI_JCOND: case HLI_PUSH: case HLI_RET: + res = insertSubTreeReg (exp, + &ticode->ic.hl.oper.exp, + localId.id_arr[picode->ic.hl.oper.exp->expr.ident.idNode.regiIdx].id.regi, + &localId); + if (res) { - switch (ticode->ic.hl.opcode) { - case HLI_ASSIGN: - forwardSubs (picode->ic.hl.oper.asgn.lhs, - picode->ic.hl.oper.asgn.rhs, - &(*picode), &(*ticode), &localId, - &numHlIcodes); - break; - - case HLI_JCOND: case HLI_PUSH: case HLI_RET: - res = insertSubTreeReg ( - picode->ic.hl.oper.asgn.rhs, - &ticode->ic.hl.oper.exp, - localId.id_arr[picode->ic.hl.oper.asgn.lhs->expr.ident.idNode.regiIdx].id.regi, - &localId); - if (res) - { - picode->invalidate(); - numHlIcodes--; - } - break; - - case HLI_CALL: /* register arguments */ - newRegArg (&(*picode), &(*ticode)); - picode->invalidate(); - numHlIcodes--; - break; - } /* eos */ + picode->invalidate(); + numHlIcodes--; } break; - case HLI_POP: - ticode = Icode.begin()+(picode->du1.idx[0][0]); - if ((picode->du.lastDefRegi & duReg[regi]) && - ((ticode->ic.hl.opcode != HLI_CALL) && - (ticode->ic.hl.opcode != HLI_RET))) - continue; - - exp = g_exp_stk.pop(); /* pop last exp pushed */ - switch (ticode->ic.hl.opcode) { - case HLI_ASSIGN: - forwardSubs (picode->ic.hl.oper.exp, exp, - &(*picode), &(*ticode), &localId, - &numHlIcodes); - break; - - case HLI_JCOND: case HLI_PUSH: case HLI_RET: - res = insertSubTreeReg (exp, - &ticode->ic.hl.oper.exp, - localId.id_arr[picode->ic.hl.oper.exp->expr.ident.idNode.regiIdx].id.regi, - &localId); - if (res) - { - picode->invalidate(); - numHlIcodes--; - } - break; - - /****case HLI_CALL: /* register arguments + /****case HLI_CALL: /* register arguments newRegArg (pProc, picode, ticode); picode->invalidate(); numHlIcodes--; break; */ - } /* eos */ + } /* eos */ + break; + + case HLI_CALL: + ticode = Icode.begin()+(picode->du1.idx[0][0]); + switch (ticode->ic.hl.opcode) { + case HLI_ASSIGN: + exp = COND_EXPR::idFunc ( + picode->ic.hl.oper.call.proc, + picode->ic.hl.oper.call.args); + res = insertSubTreeReg (exp, + &ticode->ic.hl.oper.asgn.rhs, + picode->ic.hl.oper.call.proc->retVal.id.regi, + &localId); + if (! res) + insertSubTreeReg (exp, + &ticode->ic.hl.oper.asgn.lhs, + picode->ic.hl.oper.call.proc->retVal.id.regi, + &localId); + /*** HERE missing: 2 regs ****/ + picode->invalidate(); + numHlIcodes--; break; - case HLI_CALL: - ticode = Icode.begin()+(picode->du1.idx[0][0]); - switch (ticode->ic.hl.opcode) { - case HLI_ASSIGN: - exp = COND_EXPR::idFunc ( - picode->ic.hl.oper.call.proc, - picode->ic.hl.oper.call.args); + case HLI_PUSH: case HLI_RET: + exp = COND_EXPR::idFunc ( + picode->ic.hl.oper.call.proc, + picode->ic.hl.oper.call.args); + ticode->ic.hl.oper.exp = exp; + picode->invalidate(); + numHlIcodes--; + break; + + case HLI_JCOND: + exp = COND_EXPR::idFunc ( + picode->ic.hl.oper.call.proc, + picode->ic.hl.oper.call.args); + retVal = &picode->ic.hl.oper.call.proc->retVal, res = insertSubTreeReg (exp, - &ticode->ic.hl.oper.asgn.rhs, - picode->ic.hl.oper.call.proc->retVal.id.regi, - &localId); - if (! res) - insertSubTreeReg (exp, - &ticode->ic.hl.oper.asgn.lhs, - picode->ic.hl.oper.call.proc->retVal.id.regi, - &localId); - /*** HERE missing: 2 regs ****/ - picode->invalidate(); - numHlIcodes--; - break; - - case HLI_PUSH: case HLI_RET: - exp = COND_EXPR::idFunc ( - picode->ic.hl.oper.call.proc, - picode->ic.hl.oper.call.args); - ticode->ic.hl.oper.exp = exp; - picode->invalidate(); - numHlIcodes--; - break; - - case HLI_JCOND: - exp = COND_EXPR::idFunc ( - picode->ic.hl.oper.call.proc, - picode->ic.hl.oper.call.args); - retVal = &picode->ic.hl.oper.call.proc->retVal, - res = insertSubTreeReg (exp, - &ticode->ic.hl.oper.exp, - retVal->id.regi, &localId); - if (res) /* was substituted */ - { - picode->invalidate(); - numHlIcodes--; - } - else /* cannot substitute function */ - { - lhs = COND_EXPR::idID(retVal,&localId,picode->loc_ip); - picode->setAsgn(lhs, exp); - } - break; - } /* eos */ + &ticode->ic.hl.oper.exp, + retVal->id.regi, &localId); + if (res) /* was substituted */ + { + picode->invalidate(); + numHlIcodes--; + } + else /* cannot substitute function */ + { + lhs = COND_EXPR::idID(retVal,&localId,picode->loc_ip); + picode->setAsgn(lhs, exp); + } break; + } /* eos */ + break; } /* eos */ } } @@ -869,129 +870,129 @@ void Function::findExps() { /* Check for only one use of these registers */ if ((picode->du1.idx[0][0] != 0) && - (picode->du1.idx[0][1] == 0) && - (picode->du1.idx[1][0] != 0) && - (picode->du1.idx[1][1] == 0)) + (picode->du1.idx[0][1] == 0) && + (picode->du1.idx[1][0] != 0) && + (picode->du1.idx[1][1] == 0)) { switch (picode->ic.hl.opcode) { - case HLI_ASSIGN: - /* Replace rhs of current icode into target + case HLI_ASSIGN: + /* Replace rhs of current icode into target * icode expression */ - if (picode->du1.idx[0][0] == picode->du1.idx[1][0]) - { - ticode = Icode.begin()+(picode->du1.idx[0][0]); - if ((picode->du.lastDefRegi & duReg[regi]) && - ((ticode->ic.hl.opcode != HLI_CALL) && - (ticode->ic.hl.opcode != HLI_RET))) - continue; - - switch (ticode->ic.hl.opcode) { - case HLI_ASSIGN: - forwardSubsLong (picode->ic.hl.oper.asgn.lhs->expr.ident.idNode.longIdx, - picode->ic.hl.oper.asgn.rhs, &(*picode), - &(*ticode), &numHlIcodes); - break; - - case HLI_JCOND: case HLI_PUSH: case HLI_RET: - res = insertSubTreeLongReg ( - picode->ic.hl.oper.asgn.rhs, - &ticode->ic.hl.oper.exp, - picode->ic.hl.oper.asgn.lhs->expr.ident.idNode.longIdx); - if (res) - { - picode->invalidate(); - numHlIcodes--; - } - break; - - case HLI_CALL: /* register arguments */ - newRegArg ( &(*picode), &(*ticode)); - picode->invalidate(); - numHlIcodes--; - break; - } /* eos */ - } - break; - - case HLI_POP: - if (picode->du1.idx[0][0] == picode->du1.idx[1][0]) - { - ticode = Icode.begin()+(picode->du1.idx[0][0]); - if ((picode->du.lastDefRegi & duReg[regi]) && - ((ticode->ic.hl.opcode != HLI_CALL) && - (ticode->ic.hl.opcode != HLI_RET))) - continue; - - exp = g_exp_stk.pop(); /* pop last exp pushed */ - switch (ticode->ic.hl.opcode) { - case HLI_ASSIGN: - forwardSubsLong (picode->ic.hl.oper.exp->expr.ident.idNode.longIdx, - exp, &(*picode), &(*ticode), &numHlIcodes); - break; - case HLI_JCOND: case HLI_PUSH: - res = insertSubTreeLongReg (exp, - &ticode->ic.hl.oper.exp, - picode->ic.hl.oper.asgn.lhs->expr.ident.idNode.longIdx); - if (res) - { - picode->invalidate(); - numHlIcodes--; - } - break; - case HLI_CALL: /*** missing ***/ - break; - } /* eos */ - } - break; - - case HLI_CALL: /* check for function return */ + if (picode->du1.idx[0][0] == picode->du1.idx[1][0]) + { ticode = Icode.begin()+(picode->du1.idx[0][0]); - switch (ticode->ic.hl.opcode) - { - case HLI_ASSIGN: - exp = COND_EXPR::idFunc ( - picode->ic.hl.oper.call.proc, - picode->ic.hl.oper.call.args); - ticode->ic.hl.oper.asgn.lhs = - COND_EXPR::idLong(&localId, DST, ticode, - HIGH_FIRST, picode->loc_ip, eDEF, 1); - ticode->ic.hl.oper.asgn.rhs = exp; + if ((picode->du.lastDefRegi & duReg[regi]) && + ((ticode->ic.hl.opcode != HLI_CALL) && + (ticode->ic.hl.opcode != HLI_RET))) + continue; + + switch (ticode->ic.hl.opcode) { + case HLI_ASSIGN: + forwardSubsLong (picode->ic.hl.oper.asgn.lhs->expr.ident.idNode.longIdx, + picode->ic.hl.oper.asgn.rhs, &(*picode), + &(*ticode), &numHlIcodes); + break; + + case HLI_JCOND: case HLI_PUSH: case HLI_RET: + res = insertSubTreeLongReg ( + picode->ic.hl.oper.asgn.rhs, + &ticode->ic.hl.oper.exp, + picode->ic.hl.oper.asgn.lhs->expr.ident.idNode.longIdx); + if (res) + { picode->invalidate(); numHlIcodes--; - break; + } + break; - case HLI_PUSH: case HLI_RET: - exp = COND_EXPR::idFunc ( - picode->ic.hl.oper.call.proc, - picode->ic.hl.oper.call.args); - ticode->ic.hl.oper.exp = exp; - picode->invalidate(); - numHlIcodes--; - break; - - case HLI_JCOND: - exp = COND_EXPR::idFunc ( - picode->ic.hl.oper.call.proc, - picode->ic.hl.oper.call.args); - retVal = &picode->ic.hl.oper.call.proc->retVal; - res = insertSubTreeLongReg (exp, - &ticode->ic.hl.oper.exp, - localId.newLongReg - ( - retVal->type, retVal->id.longId.h, - retVal->id.longId.l, picode->loc_ip)); - if (res) /* was substituted */ - { - picode->invalidate(); - numHlIcodes--; - } - else /* cannot substitute function */ - { - lhs = COND_EXPR::idID(retVal,&localId,picode->loc_ip); - picode->setAsgn(lhs, exp); - } - break; + case HLI_CALL: /* register arguments */ + newRegArg ( &(*picode), &(*ticode)); + picode->invalidate(); + numHlIcodes--; + break; } /* eos */ + } + break; + + case HLI_POP: + if (picode->du1.idx[0][0] == picode->du1.idx[1][0]) + { + ticode = Icode.begin()+(picode->du1.idx[0][0]); + if ((picode->du.lastDefRegi & duReg[regi]) && + ((ticode->ic.hl.opcode != HLI_CALL) && + (ticode->ic.hl.opcode != HLI_RET))) + continue; + + exp = g_exp_stk.pop(); /* pop last exp pushed */ + switch (ticode->ic.hl.opcode) { + case HLI_ASSIGN: + forwardSubsLong (picode->ic.hl.oper.exp->expr.ident.idNode.longIdx, + exp, &(*picode), &(*ticode), &numHlIcodes); + break; + case HLI_JCOND: case HLI_PUSH: + res = insertSubTreeLongReg (exp, + &ticode->ic.hl.oper.exp, + picode->ic.hl.oper.asgn.lhs->expr.ident.idNode.longIdx); + if (res) + { + picode->invalidate(); + numHlIcodes--; + } + break; + case HLI_CALL: /*** missing ***/ + break; + } /* eos */ + } + break; + + case HLI_CALL: /* check for function return */ + ticode = Icode.begin()+(picode->du1.idx[0][0]); + switch (ticode->ic.hl.opcode) + { + case HLI_ASSIGN: + exp = COND_EXPR::idFunc ( + picode->ic.hl.oper.call.proc, + picode->ic.hl.oper.call.args); + ticode->ic.hl.oper.asgn.lhs = + COND_EXPR::idLong(&localId, DST, ticode, + HIGH_FIRST, picode->loc_ip, eDEF, 1); + ticode->ic.hl.oper.asgn.rhs = exp; + picode->invalidate(); + numHlIcodes--; + break; + + case HLI_PUSH: case HLI_RET: + exp = COND_EXPR::idFunc ( + picode->ic.hl.oper.call.proc, + picode->ic.hl.oper.call.args); + ticode->ic.hl.oper.exp = exp; + picode->invalidate(); + numHlIcodes--; + break; + + case HLI_JCOND: + exp = COND_EXPR::idFunc ( + picode->ic.hl.oper.call.proc, + picode->ic.hl.oper.call.args); + retVal = &picode->ic.hl.oper.call.proc->retVal; + res = insertSubTreeLongReg (exp, + &ticode->ic.hl.oper.exp, + localId.newLongReg + ( + retVal->type, retVal->id.longId.h, + retVal->id.longId.l, picode->loc_ip)); + if (res) /* was substituted */ + { + picode->invalidate(); + numHlIcodes--; + } + else /* cannot substitute function */ + { + lhs = COND_EXPR::idID(retVal,&localId,picode->loc_ip); + picode->setAsgn(lhs, exp); + } + break; + } /* eos */ } /* eos */ } } @@ -1010,7 +1011,7 @@ void Function::findExps() * pop them from the expression stack and place them on the * procedure's argument list */ if ((picode->ic.hl.opcode == HLI_CALL) && - ! (picode->ic.hl.oper.call.proc->flg & REG_ARGS)) + ! (picode->ic.hl.oper.call.proc->flg & REG_ARGS)) { Function * pp; Int cb, numArgs; boolT res; @@ -1057,14 +1058,14 @@ void Function::findExps() /* If we could not substitute the result of a function, * assign it to the corresponding registers */ if ((picode->ic.hl.opcode == HLI_CALL) && - ((picode->ic.hl.oper.call.proc->flg & PROC_ISLIB) != - PROC_ISLIB) && (picode->du1.idx[0][0] == 0) && - (picode->du1.numRegsDef > 0)) + ((picode->ic.hl.oper.call.proc->flg & PROC_ISLIB) != + PROC_ISLIB) && (picode->du1.idx[0][0] == 0) && + (picode->du1.numRegsDef > 0)) { exp = COND_EXPR::idFunc (picode->ic.hl.oper.call.proc, - picode->ic.hl.oper.call.args); + picode->ic.hl.oper.call.args); lhs = COND_EXPR::idID (&picode->ic.hl.oper.call.proc->retVal, - &localId, picode->loc_ip); + &localId, picode->loc_ip); picode->setAsgn(lhs, exp); } } diff --git a/src/dcc.cpp b/src/dcc.cpp index 499789a..b64fe98 100644 --- a/src/dcc.cpp +++ b/src/dcc.cpp @@ -129,13 +129,13 @@ NextArg:; { if (! asm1_name) { - asm1_name = strcpy((char*)allocMem(strlen(*argv)+4), *argv); + asm1_name = strcpy((char*)malloc(strlen(*argv)+4), *argv); pc = strrchr(asm1_name, '.'); if (pc > strrchr(asm1_name, '/')) { *pc = '\0'; } - asm2_name = (char*)allocMem(strlen(asm1_name)+4) ; + asm2_name = (char*)malloc(strlen(asm1_name)+4) ; strcat(strcpy(asm2_name, asm1_name), ".a2"); unlink(asm2_name); strcat(asm1_name, ".a1"); diff --git a/src/disassem.cpp b/src/disassem.cpp index 871d074..dbdc740 100644 --- a/src/disassem.cpp +++ b/src/disassem.cpp @@ -215,7 +215,7 @@ void disassem(Int pass, Function * ppProc) JmpInst(pc[i].ic.ll.opcode)) { /* Replace the immediate operand with an icode index */ - if (labelSrch(pc,numIcode, pc[i].ic.ll.immed.op,(Int *)&pc[i].ic.ll.immed.op)) + if (pc.labelSrch(pc[i].ic.ll.immed.op,pc[i].ic.ll.immed.op)) { /* This icode is the target of a jump */ pc[pc[i].ic.ll.immed.op].ic.ll.flg |= TARGET; diff --git a/src/error.cpp b/src/error.cpp index 018a90b..037ad65 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -40,7 +40,7 @@ static const char *errorMessage[] = { /**************************************************************************** fatalError: displays error message and exits the program. ****************************************************************************/ -void fatalError(Int errId, ...) +void fatalError(eErrorId errId, ...) { va_list args; //#ifdef __UNIX__ /* ultrix */ #if 0 @@ -66,7 +66,7 @@ void fatalError(Int errId, ...) /**************************************************************************** reportError: reports the warning/error and continues with the program. ****************************************************************************/ -void reportError(Int errId, ...) +void reportError(eErrorId errId, ...) { va_list args; //#ifdef __UNIX__ /* ultrix */ #if 0 diff --git a/src/frontend.cpp b/src/frontend.cpp index bcde899..00e48d3 100644 --- a/src/frontend.cpp +++ b/src/frontend.cpp @@ -1,8 +1,8 @@ /***************************************************************************** - * dcc project Front End module - * Loads a program into simulated main memory and builds the procedure list. - * (C) Cristina Cifuentes - ****************************************************************************/ +* dcc project Front End module +* Loads a program into simulated main memory and builds the procedure list. +* (C) Cristina Cifuentes +****************************************************************************/ #include "dcc.h" #include @@ -58,9 +58,9 @@ static void displayLoadInfo(void); static void displayMemMap(void); /***************************************************************************** - * FrontEnd - invokes the loader, parser, disassembler (if asm1), icode - * rewritter, and displays any useful information. - ****************************************************************************/ +* FrontEnd - invokes the loader, parser, disassembler (if asm1), icode +* rewritter, and displays any useful information. +****************************************************************************/ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph) { /* Load program into memory */ @@ -70,7 +70,7 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph) displayLoadInfo(); /* Do depth first flow analysis building call graph and procedure list, - * and attaching the I-code to each procedure */ +* and attaching the I-code to each procedure */ parse (pcallGraph); if (option.asm1) @@ -79,29 +79,30 @@ void FrontEnd (char *filename, CALL_GRAPH * *pcallGraph) } /* Search through code looking for impure references and flag them */ - std::for_each(pProcList.begin(),pProcList.end(), - [](Function &f)->void { - f.markImpure(); - if (option.asm1) - disassem(1, &f); }); -if (option.Interact) -{ - interactDis(&pProcList.front(), 0); /* Interactive disassembler */ -} + for(Function &f : pProcList) + { + f.markImpure(); + if (option.asm1) + disassem(1, &f); + } + if (option.Interact) + { + interactDis(&pProcList.front(), 0); /* Interactive disassembler */ + } -/* Converts jump target addresses to icode offsets */ -std::for_each(pProcList.begin(),pProcList.end(), - [](Function &f)->void { f.bindIcodeOff(); }); + /* Converts jump target addresses to icode offsets */ + for(Function &f : pProcList) + f.bindIcodeOff(); -/* Print memory bitmap */ -if (option.Map) -displayMemMap(); + /* Print memory bitmap */ + if (option.Map) + displayMemMap(); } /**************************************************************************** - * displayLoadInfo - Displays low level loader type info. - ***************************************************************************/ +* displayLoadInfo - Displays low level loader type info. +***************************************************************************/ static void displayLoadInfo(void) { Int i; @@ -133,8 +134,8 @@ static void displayLoadInfo(void) /***************************************************************************** - * fill - Fills line for displayMemMap() - ****************************************************************************/ +* fill - Fills line for displayMemMap() +****************************************************************************/ static void fill(Int ip, char *bf) { static byte type[4] = {'.', 'd', 'c', 'x'}; @@ -151,8 +152,8 @@ static void fill(Int ip, char *bf) /***************************************************************************** - * displayMemMap - Displays the memory bitmap - ****************************************************************************/ +* displayMemMap - Displays the memory bitmap +****************************************************************************/ static void displayMemMap(void) { char c, b1[33], b2[33], b3[33]; @@ -187,8 +188,8 @@ static void displayMemMap(void) /***************************************************************************** - * LoadImage - ****************************************************************************/ +* LoadImage +****************************************************************************/ static void LoadImage(char *filename) { FILE *fp; @@ -222,10 +223,10 @@ 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 - */ +* 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; if (header.lastPageSize) { @@ -233,13 +234,13 @@ static void LoadImage(char *filename) } /* We quietly ignore minAlloc and maxAlloc since for our - * purposes it doesn't really matter where in real memory - * the program would end up. EXE programs can't really rely on - * their load location so setting the PSP segment to 0 is fine. - * Certainly programs that prod around in DOS or BIOS are going - * to have to load DS from a constant so it'll be pretty - * obvious. - */ +* purposes it doesn't really matter where in real memory +* the program would end up. EXE programs can't really rely on +* their load location so setting the PSP segment to 0 is fine. +* Certainly programs that prod around in DOS or BIOS are going +* 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; @@ -249,7 +250,7 @@ static void LoadImage(char *filename) /* Allocate the relocation table */ if (prog.cReloc) { - prog.relocTable = (dword*)allocMem(prog.cReloc * sizeof(Int)); + prog.relocTable = new dword [prog.cReloc]; fseek(fp, LH(&header.relocTabOffset), SEEK_SET); /* Read in seg:offset pairs and convert to Image ptrs */ @@ -265,15 +266,15 @@ static void LoadImage(char *filename) } else { /* COM file - * In this case the load module size is just the file length - */ + * In this case the load module size is just the file length + */ fseek(fp, 0, SEEK_END); cb = ftell(fp); /* COM programs start off with an ORG 100H (to leave room for a PSP) - * This is also the implied start address so if we load the image - * at offset 100H addresses should all line up properly again. - */ + * This is also the implied start address so if we load the image + * at offset 100H addresses should all line up properly again. + */ prog.initCS = 0; prog.initIP = 0x100; prog.initSS = 0; @@ -285,7 +286,7 @@ static void LoadImage(char *filename) /* Allocate a block of memory for the program. */ prog.cbImage = cb + sizeof(PSP); - prog.Image = (byte*)allocMem(prog.cbImage); + prog.Image = new byte [prog.cbImage]; prog.Image[0] = 0xCD; /* Fill in PSP Int 20h location */ prog.Image[1] = 0x20; /* for termination checking */ @@ -304,7 +305,8 @@ static void LoadImage(char *filename) /* Set up memory map */ cb = (prog.cbImage + 3) / 4; - prog.map = (byte *)memset(allocMem(cb), BM_UNKNOWN, (size_t)cb); + prog.map = (byte *)malloc(cb); + memset(prog.map, BM_UNKNOWN, (size_t)cb); /* Relocate segment constants */ if (prog.cReloc) @@ -323,8 +325,8 @@ static void LoadImage(char *filename) /***************************************************************************** - * allocMem - malloc with failure test - ****************************************************************************/ +* allocMem - malloc with failure test +****************************************************************************/ void *allocMem(Int cb) { byte *p; @@ -336,37 +338,6 @@ void *allocMem(Int cb) { fatalError(MALLOC_FAILED, cb); } - /*printf("allocMem: %p\n", p);/**/ + // printf("allocMem: %p\n", p); return p; } - - -/***************************************************************************** - * reallocVar - reallocs extra variable space - ****************************************************************************/ -void *reallocVar(void *p, Int newsize) -{ - /*printf("Attempt to reallocVar %5d bytes\n", newsize);/**/ - if (! (p = realloc((byte *)p, (size_t)newsize))) - { - fatalError(MALLOC_FAILED, newsize); - } - - /*printf("reallocVar: %p\n", p);/**/ - return p; -} - -#if 0 -void free(void *p) -{ - _ffree(p); - switch (_heapset('Z')) - { - case _HEAPBADBEGIN: printf("f: Bad heap begin\n"); getchar(); break; - case _HEAPBADNODE: printf("f: Bad heap node\n"); getchar(); break; - case _HEAPEMPTY: printf("f: Heap empty\n"); getchar(); break; - case _HEAPOK:putchar('!');break; - }/**/ -} -#endif - diff --git a/src/graph.cpp b/src/graph.cpp index 43eb41b..f5ff918 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -189,7 +189,8 @@ void Function::markImpure() ****************************************************************************/ void Function::freeCFG() { - std::for_each(heldBBs.begin(),heldBBs.end(),[](BB *p)->void {delete p;}); + for(BB *p : heldBBs) + delete p; } @@ -369,15 +370,14 @@ void BB::mergeFallThrough( CIcodeRec &Icode) void BB::dfsNumbering(std::vector &dfsLast, Int *first, Int *last) { BB * pChild; - byte i; - traversed = DFS_NUM; dfsFirstNum = (*first)++; /* index is being used as an index to inEdges[]. */ - for (i = 0; i < edges.size(); i++) +// for (i = 0; i < edges.size(); i++) + for (auto edge : edges) { - pChild = edges[i].BBptr; + pChild = edge.BBptr; pChild->inEdges[pChild->index++] = this; /* Is this the last visit? */ diff --git a/src/hlicode.cpp b/src/hlicode.cpp index d6d0b77..560bb24 100644 --- a/src/hlicode.cpp +++ b/src/hlicode.cpp @@ -157,7 +157,8 @@ void Function::highLevelGen() lhs = COND_EXPR::id (*pIcode, DST, this, i, *pIcode, NONE); } - switch (pIcode->ic.ll.opcode) { + switch (pIcode->ic.ll.opcode) + { case iADD: rhs = COND_EXPR::boolOp (lhs, rhs, ADD); pIcode->setAsgn(lhs, rhs); @@ -196,12 +197,14 @@ void Function::highLevelGen() pIcode->setAsgn(lhs, rhs); break; - case iIMUL: rhs = COND_EXPR::boolOp (lhs, rhs, MUL); + case iIMUL: + rhs = COND_EXPR::boolOp (lhs, rhs, MUL); lhs = COND_EXPR::id (*pIcode, LHS_OP, this, i, *pIcode, NONE); pIcode->setAsgn(lhs, rhs); break; - case iINC: rhs = COND_EXPR::idKte (1, 2); + case iINC: + rhs = COND_EXPR::idKte (1, 2); rhs = COND_EXPR::boolOp (lhs, rhs, ADD); pIcode->setAsgn(lhs, rhs); break; @@ -227,7 +230,8 @@ void Function::highLevelGen() case iMOV: pIcode->setAsgn(lhs, rhs); break; - case iMUL: rhs = COND_EXPR::boolOp (lhs, rhs, MUL); + case iMUL: + rhs = COND_EXPR::boolOp (lhs, rhs, MUL); lhs = COND_EXPR::id (*pIcode, LHS_OP, this, i, *pIcode, NONE); pIcode->setAsgn(lhs, rhs); break; @@ -236,11 +240,13 @@ void Function::highLevelGen() pIcode->setAsgn(lhs, rhs); break; - case iNOT: rhs = COND_EXPR::boolOp (NULL, rhs, NOT); + case iNOT: + rhs = COND_EXPR::boolOp (NULL, rhs, NOT); pIcode->setAsgn(lhs, rhs); break; - case iOR: rhs = COND_EXPR::boolOp (lhs, rhs, OR); + case iOR: + rhs = COND_EXPR::boolOp (lhs, rhs, OR); pIcode->setAsgn(lhs, rhs); break; @@ -259,7 +265,8 @@ void Function::highLevelGen() break; case iSAR: /* signed */ - case iSHR: rhs = COND_EXPR::boolOp (lhs, rhs, SHR); /* unsigned*/ + case iSHR: + rhs = COND_EXPR::boolOp (lhs, rhs, SHR); /* unsigned*/ pIcode->setAsgn(lhs, rhs); break; diff --git a/src/icode.cpp b/src/icode.cpp index 046d284..5d1d30f 100644 --- a/src/icode.cpp +++ b/src/icode.cpp @@ -15,6 +15,7 @@ CIcodeRec::CIcodeRec() { + //reserve(512); } CIcodeRec::~CIcodeRec() @@ -100,7 +101,7 @@ llIcode CIcodeRec::GetLlOpcode(int ip) /* labelSrchRepl - Searches the icodes for instruction with label = target, and replaces *pIndex with an icode index */ -boolT CIcodeRec::labelSrch(dword target, Int *pIndex) +bool CIcodeRec::labelSrch(dword target, dword &pIndex) { Int i; @@ -108,7 +109,7 @@ boolT CIcodeRec::labelSrch(dword target, Int *pIndex) { if (at(i).ic.ll.label == target) { - *pIndex = i; + pIndex = i; return TRUE; } } diff --git a/src/idioms.cpp b/src/idioms.cpp index 69bb452..f39445d 100644 --- a/src/idioms.cpp +++ b/src/idioms.cpp @@ -13,7 +13,7 @@ /***************************************************************************** * JmpInst - Returns TRUE if opcode is a conditional or unconditional jump ****************************************************************************/ -boolT JmpInst(llIcode opcode) +bool JmpInst(llIcode opcode) { switch (opcode) { case iJMP: case iJMPF: case iJCXZ: @@ -22,9 +22,9 @@ boolT JmpInst(llIcode opcode) case iJL: case iJLE: case iJGE: case iJG: case iJE: case iJNE: case iJS: case iJNS: case iJO: case iJNO: case iJP: case iJNP: - return TRUE; + return true; } - return FALSE; + return false; } @@ -1418,9 +1418,9 @@ void Function::findIdioms() * binds jump target addresses to icode offsets. */ void Function::bindIcodeOff() { - Int i, j; /* idx into icode array */ + Int i; /* idx into icode array */ iICODE pIcode; /* ptr icode array */ - dword *p; /* for case table */ + dword *p,j; /* for case table */ if (! Icode.GetNumIcodes()) /* No Icode */ return; @@ -1430,7 +1430,7 @@ void Function::bindIcodeOff() for (i = 0; i < Icode.GetNumIcodes(); i++) if ((pIcode[i].ic.ll.flg & I) && JmpInst(pIcode[i].ic.ll.opcode)) { - if (Icode.labelSrch(pIcode[i].ic.ll.immed.op, &j)) + if (Icode.labelSrch(pIcode[i].ic.ll.immed.op, j)) { pIcode[j].ic.ll.flg |= TARGET; } @@ -1445,14 +1445,14 @@ void Function::bindIcodeOff() { if (pIcode->ic.ll.flg & I) { - if (! Icode.labelSrch(pIcode->ic.ll.immed.op, (Int *)&pIcode->ic.ll.immed.op)) + if (! Icode.labelSrch(pIcode->ic.ll.immed.op, pIcode->ic.ll.immed.op)) pIcode->ic.ll.flg |= NO_LABEL; } else if (pIcode->ic.ll.flg & SWITCH) { p = pIcode->ic.ll.caseTbl.entries; for (j = 0; j < pIcode->ic.ll.caseTbl.numEntries; j++, p++) - Icode.labelSrch(*p, (Int *)p); + Icode.labelSrch(*p, *p); } } } diff --git a/src/parser.cpp b/src/parser.cpp index 9843581..83e284d 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -121,9 +121,9 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) ICODE eIcode; /* extra icodes for iDIV, iIDIV, iXCHG */ SYM * psym; dword offset; - Int err; + eErrorId err; boolT done = FALSE; - Int lab; + dword lab; if (strstr(name, "chkstk") != NULL) { @@ -151,7 +151,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) flg |= (_Icode.ic.ll.flg & (NOT_HLL | FLOAT_OP)); /* Check if this instruction has already been parsed */ - if (Icode.labelSrch(_Icode.ic.ll.label, &lab)) + if (Icode.labelSrch(_Icode.ic.ll.label, lab)) { /* Synthetic jump */ _Icode.type = LOW_LEVEL; _Icode.ic.ll.opcode = iJMP; @@ -397,7 +397,7 @@ boolT Function::process_JMP (ICODE * pIcode, STATE *pstate, CALL_GRAPH * pcallGr ICODE _Icode; dword cs, offTable, endTable; dword i, k, seg, target; - Int tmp; + dword tmp; if (pIcode->ic.ll.flg & I) { @@ -410,7 +410,7 @@ boolT Function::process_JMP (ICODE * pIcode, STATE *pstate, CALL_GRAPH * pcallGr } /* Return TRUE if jump target is already parsed */ - return Icode.labelSrch(i, &tmp); + return Icode.labelSrch(i, tmp); } /* We've got an indirect JMP - look for switch() stmt. idiom of the form @@ -854,7 +854,7 @@ void STATE::setState(word reg, int16 value) /* labelSrchRepl - Searches Icode for instruction with label = target, and replaces *pIndex with an icode index */ -boolT labelSrch(CIcodeRec &pIcode, Int numIp, dword target, Int *pIndex) +bool labelSrch(CIcodeRec &pIcode, Int numIp, dword target, Int *pIndex) { Int i; @@ -863,10 +863,10 @@ boolT labelSrch(CIcodeRec &pIcode, Int numIp, dword target, Int *pIndex) if (pIcode[i].ic.ll.label == target) { *pIndex = i; - return TRUE; + return true; } } - return FALSE; + return false; } diff --git a/src/procs.cpp b/src/procs.cpp index a243148..8049a57 100644 --- a/src/procs.cpp +++ b/src/procs.cpp @@ -30,10 +30,9 @@ void CALL_GRAPH::insertArc (ilFunction newProc) Int i; /* Check if procedure already exists */ - for (i = 0; i < outEdges.size(); i++) - if (outEdges[i]->proc == newProc) - return; - + auto res=std::find_if(outEdges.begin(),outEdges.end(),[newProc](CALL_GRAPH *e) {return e->proc==newProc;}); + if(res!=outEdges.end()) + return; /* Include new arc */ pcg = new CALL_GRAPH; pcg->proc = newProc; @@ -231,7 +230,7 @@ void allocStkArgs (ICODE *picode, Int num) * FALSE elsewhere */ boolT newStkArg (ICODE *picode, COND_EXPR *exp, llIcode opcode, Function * pproc) { - STKFRAME * ps; + STKFRAME * ps; byte regi; /* Check for far procedure call, in which case, references to segment @@ -275,52 +274,53 @@ void placeStkArg (ICODE *picode, COND_EXPR *exp, Int pos) * same type as the given type (from the procedure's formal list). If not, * the actual argument gets modified */ void adjustActArgType (COND_EXPR *exp, hlType forType, Function * pproc) -{ hlType actType; +{ + hlType actType; Int offset, offL; if (exp == NULL) return; actType = expType (exp, pproc); - if ((actType != forType) && (exp->type == IDENTIFIER)) + if (((actType == forType) || (exp->type != IDENTIFIER))) + return; + switch (forType) { - switch (forType) { - case TYPE_UNKNOWN: case TYPE_BYTE_SIGN: - case TYPE_BYTE_UNSIGN: case TYPE_WORD_SIGN: - case TYPE_WORD_UNSIGN: case TYPE_LONG_SIGN: - case TYPE_LONG_UNSIGN: case TYPE_RECORD: - break; + case TYPE_UNKNOWN: case TYPE_BYTE_SIGN: + case TYPE_BYTE_UNSIGN: case TYPE_WORD_SIGN: + case TYPE_WORD_UNSIGN: case TYPE_LONG_SIGN: + case TYPE_LONG_UNSIGN: case TYPE_RECORD: + break; - case TYPE_PTR: - case TYPE_CONST: - break; + case TYPE_PTR: + case TYPE_CONST: + break; - case TYPE_STR: - switch (actType) { - case TYPE_CONST: - /* It's an offset into image where a string is + case TYPE_STR: + switch (actType) { + case TYPE_CONST: + /* It's an offset into image where a string is * found. Point to the string. */ - offL = exp->expr.ident.idNode.kte.kte; - if (prog.fCOM) - offset = (pproc->state.r[rDS]<<4) + offL + 0x100; - else - offset = (pproc->state.r[rDS]<<4) + offL; - exp->expr.ident.idNode.strIdx = offset; - exp->expr.ident.idType = STRING; - break; + offL = exp->expr.ident.idNode.kte.kte; + if (prog.fCOM) + offset = (pproc->state.r[rDS]<<4) + offL + 0x100; + else + offset = (pproc->state.r[rDS]<<4) + offL; + exp->expr.ident.idNode.strIdx = offset; + exp->expr.ident.idType = STRING; + break; - case TYPE_PTR: - /* It's a pointer to a char rather than a pointer to + case TYPE_PTR: + /* It's a pointer to a char rather than a pointer to * an integer */ - /***HERE - modify the type ****/ - break; + /***HERE - modify the type ****/ + break; - case TYPE_WORD_SIGN: + case TYPE_WORD_SIGN: - break; - } /* eos */ - break; - } + break; + } /* eos */ + break; } } diff --git a/src/proplong.cpp b/src/proplong.cpp index 2e935a1..3ffd3e5 100644 --- a/src/proplong.cpp +++ b/src/proplong.cpp @@ -24,7 +24,7 @@ static boolT isJCond (llIcode opcode) /* Returns whether the conditions for a 2-3 long variable are satisfied */ static boolT isLong23 (Int i, BB * pbb, Int *off, Int *arc) { - BB * t, * e, * obb2; + BB * t, * e, * obb2; if (pbb->nodeType != TWO_BRANCH) return false; @@ -94,68 +94,68 @@ static void longJCond23 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, /* Modify in edges of target basic block */ auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(), [obb1,obb2](BB *b) -> bool - { - return (b==obb1) || (b==obb2); - } - ); - tbb->inEdges.erase(newlast,tbb->inEdges.end()); - tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */ - - /* Modify in edges of the ELSE basic block */ - tbb = pbb->edges[ELSE].BBptr; - auto iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb2); - assert(iter!=tbb->inEdges.end()); - tbb->inEdges.erase(iter); /* looses 1 arc */ - /* Update icode index */ - (*idx) += 5; + { + return (b==obb1) || (b==obb2); } + ); + tbb->inEdges.erase(newlast,tbb->inEdges.end()); + tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */ - else /* ELSE arc */ - { - /* Find intermediate basic blocks and target block */ - pbb = pIcode->inBB; - obb1 = pbb->edges[ELSE].BBptr; - obb2 = obb1->edges[THEN].BBptr; - tbb = obb2->edges[THEN].BBptr; + /* Modify in edges of the ELSE basic block */ + tbb = pbb->edges[ELSE].BBptr; + auto iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb2); + assert(iter!=tbb->inEdges.end()); + tbb->inEdges.erase(iter); /* looses 1 arc */ + /* Update icode index */ + (*idx) += 5; +} - /* Modify in edges of target basic block */ - auto iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb2); - assert(iter!=tbb->inEdges.end()); - tbb->inEdges.erase(iter); /* looses 1 arc */ +else /* ELSE arc */ +{ +/* Find intermediate basic blocks and target block */ +pbb = pIcode->inBB; +obb1 = pbb->edges[ELSE].BBptr; +obb2 = obb1->edges[THEN].BBptr; +tbb = obb2->edges[THEN].BBptr; - /* Modify in edges of the ELSE basic block */ - tbb = obb2->edges[ELSE].BBptr; - auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(), - [obb1,obb2](BB *b) -> bool - { - return (b==obb1) || (b==obb2); - } - ); - tbb->inEdges.erase(newlast,tbb->inEdges.end()); - tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */ +/* Modify in edges of target basic block */ +auto iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb2); +assert(iter!=tbb->inEdges.end()); +tbb->inEdges.erase(iter); /* looses 1 arc */ - /* Modify out edge of header basic block */ - pbb->edges[ELSE].BBptr = tbb; +/* Modify in edges of the ELSE basic block */ +tbb = obb2->edges[ELSE].BBptr; +auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(), + [obb1,obb2](BB *b) -> bool +{ + return (b==obb1) || (b==obb2); + } +); +tbb->inEdges.erase(newlast,tbb->inEdges.end()); +tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */ - /* Update icode index */ - (*idx) += 2; - } +/* Modify out edge of header basic block */ +pbb->edges[ELSE].BBptr = tbb; - /* Create new HLI_JCOND and condition */ - lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[(pIcode+off+1)->ic.ll.opcode-iJB]); - (pIcode+1)->setJCond(lhs); - (pIcode+1)->copyDU(*pIcode, eUSE, eUSE); - (pIcode+1)->du.use |= (pIcode+off)->du.use; +/* Update icode index */ +(*idx) += 2; +} - /* Update statistics */ - obb1->flg |= INVALID_BB; - obb2->flg |= INVALID_BB; - stats.numBBaft -= 2; +/* Create new HLI_JCOND and condition */ +lhs = COND_EXPR::boolOp (lhs, rhs, condOpJCond[(pIcode+off+1)->ic.ll.opcode-iJB]); +(pIcode+1)->setJCond(lhs); +(pIcode+1)->copyDU(*pIcode, eUSE, eUSE); +(pIcode+1)->du.use |= (pIcode+off)->du.use; - pIcode->invalidate(); - obb1->front().invalidate(); - obb2->front().invalidate(); - (obb2->begin2()+1)->invalidate(); +/* Update statistics */ +obb1->flg |= INVALID_BB; +obb2->flg |= INVALID_BB; +stats.numBBaft -= 2; + +pIcode->invalidate(); +obb1->front().invalidate(); +obb2->front().invalidate(); +(obb2->begin2()+1)->invalidate(); } @@ -201,8 +201,8 @@ static void longJCond22 (COND_EXPR *rhs, COND_EXPR *lhs, iICODE pIcode, Int *idx tbb->inEdges.erase(iter); if ((pIcode+3)->ic.ll.opcode == iJE) /* replace */ tbb->inEdges.push_back(pbb); -// else -// tbb->numInEdges--; /* iJNE => looses 1 arc */ + // else + // tbb->numInEdges--; /* iJNE => looses 1 arc */ /* Update statistics */ @@ -237,7 +237,8 @@ void Function::propLongStk (Int i, ID *pLocId) if (pIcode->ic.ll.opcode == (pIcode+1)->ic.ll.opcode) { - switch (pIcode->ic.ll.opcode) { + switch (pIcode->ic.ll.opcode) + { case iMOV: if (checkLongEq (pLocId->id.longStkId, pIcode, i, idx, this, &rhs, &lhs, 1) == TRUE) @@ -252,7 +253,8 @@ void Function::propLongStk (Int i, ID *pLocId) if (checkLongEq (pLocId->id.longStkId, pIcode, i, idx, this, &rhs, &lhs, 1) == TRUE) { - switch (pIcode->ic.ll.opcode) { + switch (pIcode->ic.ll.opcode) + { case iAND: rhs = COND_EXPR::boolOp (lhs, rhs, AND); break; case iOR: rhs = COND_EXPR::boolOp (lhs, rhs, OR); @@ -296,94 +298,172 @@ void Function::propLongStk (Int i, ID *pLocId) } } } +void checkBack(); +//int Function::checkBackwarLongDefs(int loc_ident_idx, ID *pLocId, int pLocId_idx) +//{ +// int idx; +// for (idx = pLocId_idx - 1; idx > 0 ; idx--) +// { +// pIcode = Icode.begin()+(idx-1); +// if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE)) +// continue; +// if (pIcode->ic.ll.opcode != (pIcode+1)->ic.ll.opcode) +// continue; +// switch (pIcode->ic.ll.opcode) +// { +// case iMOV: +// pmH = &pIcode->ic.ll.dst; +// pmL = &(pIcode+1)->ic.ll.dst; +// if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi)) +// { +// lhs = COND_EXPR::idLongIdx (i); +// this->localId.id_arr[i].idx.push_back(idx-1); +// pIcode->setRegDU( pmL->regi, eDEF); +// rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, HIGH_FIRST, idx, eUSE, 1); +// pIcode->setAsgn(lhs, rhs); +// (pIcode+1)->invalidate(); +// idx = 0; /* to exit the loop */ +// } +// break; + +// case iPOP: +// pmH = &(pIcode+1)->ic.ll.dst; +// pmL = &pIcode->ic.ll.dst; +// if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi)) +// { +// lhs = COND_EXPR::idLongIdx (i); +// pIcode->setRegDU( pmH->regi, eDEF); +// pIcode->setUnary(HLI_POP, lhs); +// (pIcode+1)->invalidate(); +// idx = 0; /* to exit the loop */ +// } +// break; + +// /**** others missing ***/ + +// case iAND: case iOR: case iXOR: +// pmL = &pIcode->ic.ll.dst; +// pmH = &(pIcode+1)->ic.ll.dst; +// if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi)) +// { +// lhs = COND_EXPR::idLongIdx (i); +// pIcode->setRegDU( pmH->regi, USE_DEF); +// rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, LOW_FIRST, idx, eUSE, 1); +// switch (pIcode->ic.ll.opcode) { +// case iAND: rhs = COND_EXPR::boolOp (lhs, rhs, AND); +// break; +// case iOR: +// rhs = COND_EXPR::boolOp (lhs, rhs, OR); +// break; +// case iXOR: rhs = COND_EXPR::boolOp (lhs, rhs, XOR); +// break; +// } /* eos */ +// pIcode->setAsgn(lhs, rhs); +// (pIcode+1)->invalidate(); +// idx = 0; +// } +// break; +// } /* eos */ +// } +//} /* Finds the definition of the long register pointed to by pLocId, and * transforms that instruction into a HIGH_LEVEL icode instruction. * Arguments: i : index into the local identifier table * pLocId: ptr to the long local identifier * pProc : ptr to current procedure's record. */ -void Function::propLongReg (Int i, ID *pLocId) +void Function::propLongReg (Int loc_ident_idx, ID *pLocId) { - COND_EXPR *lhs, *rhs; - Int idx, j, off, arc; - iICODE pIcode, pEnd; - ICODEMEM * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */ + Int idx; + iICODE pEnd; /* Process all definitions/uses of long registers at an icode position */ pEnd = this->Icode.end(); - for (j = 0; j < pLocId->idx.size(); j++) + // for (int pLocId_idx : pLocId->idx) + // WARNING: this loop modifies the iterated-over container. + for (int j = 0; j < pLocId->idx.size(); j++) { + int pLocId_idx=pLocId->idx[j]; /* Check backwards for a definition of this long register */ - for (idx = pLocId->idx[j] - 1; idx > 0 ; idx--) + + COND_EXPR *lhs, *rhs; + + for (idx = pLocId_idx - 1; idx > 0 ; idx--) { + iICODE pIcode; + ICODEMEM * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */ pIcode = Icode.begin()+(idx-1); if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE)) continue; - if (pIcode->ic.ll.opcode == (pIcode+1)->ic.ll.opcode) - switch (pIcode->ic.ll.opcode) - { - case iMOV: - pmH = &pIcode->ic.ll.dst; - pmL = &(pIcode+1)->ic.ll.dst; - if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi)) - { - lhs = COND_EXPR::idLongIdx (i); - this->localId.id_arr[i].idx.push_back(idx-1); - pIcode->setRegDU( pmL->regi, eDEF); - rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, HIGH_FIRST, idx, eUSE, 1); - pIcode->setAsgn(lhs, rhs); - (pIcode+1)->invalidate(); - idx = 0; /* to exit the loop */ - } - break; + if (pIcode->ic.ll.opcode != (pIcode+1)->ic.ll.opcode) + continue; + switch (pIcode->ic.ll.opcode) + { + case iMOV: + pmH = &pIcode->ic.ll.dst; + pmL = &(pIcode+1)->ic.ll.dst; + if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi)) + { + lhs = COND_EXPR::idLongIdx (loc_ident_idx); + this->localId.id_arr[loc_ident_idx].idx.push_back(idx-1); + pIcode->setRegDU( pmL->regi, eDEF); + rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, HIGH_FIRST, idx, eUSE, 1); + pIcode->setAsgn(lhs, rhs); + (pIcode+1)->invalidate(); + idx = 0; /* to exit the loop */ + } + break; - case iPOP: - pmH = &(pIcode+1)->ic.ll.dst; - pmL = &pIcode->ic.ll.dst; - if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi)) - { - lhs = COND_EXPR::idLongIdx (i); - pIcode->setRegDU( pmH->regi, eDEF); - pIcode->setUnary(HLI_POP, lhs); - (pIcode+1)->invalidate(); - idx = 0; /* to exit the loop */ - } - break; + case iPOP: + pmH = &(pIcode+1)->ic.ll.dst; + pmL = &pIcode->ic.ll.dst; + if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi)) + { + lhs = COND_EXPR::idLongIdx (loc_ident_idx); + pIcode->setRegDU( pmH->regi, eDEF); + pIcode->setUnary(HLI_POP, lhs); + (pIcode+1)->invalidate(); + idx = 0; /* to exit the loop */ + } + break; - /**** others missing ***/ + /**** others missing ***/ - case iAND: case iOR: case iXOR: - pmL = &pIcode->ic.ll.dst; - pmH = &(pIcode+1)->ic.ll.dst; - if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi)) - { - lhs = COND_EXPR::idLongIdx (i); - pIcode->setRegDU( pmH->regi, USE_DEF); - rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, LOW_FIRST, idx, eUSE, 1); - switch (pIcode->ic.ll.opcode) { - case iAND: rhs = COND_EXPR::boolOp (lhs, rhs, AND); - break; - case iOR: - rhs = COND_EXPR::boolOp (lhs, rhs, OR); - break; - case iXOR: rhs = COND_EXPR::boolOp (lhs, rhs, XOR); - break; - } /* eos */ - pIcode->setAsgn(lhs, rhs); - (pIcode+1)->invalidate(); - idx = 0; - } - break; - } /* eos */ + case iAND: case iOR: case iXOR: + pmL = &pIcode->ic.ll.dst; + pmH = &(pIcode+1)->ic.ll.dst; + if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi)) + { + lhs = COND_EXPR::idLongIdx (loc_ident_idx); + pIcode->setRegDU( pmH->regi, USE_DEF); + rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, LOW_FIRST, idx, eUSE, 1); + switch (pIcode->ic.ll.opcode) { + case iAND: rhs = COND_EXPR::boolOp (lhs, rhs, AND); + break; + case iOR: + rhs = COND_EXPR::boolOp (lhs, rhs, OR); + break; + case iXOR: + rhs = COND_EXPR::boolOp (lhs, rhs, XOR); + break; + } /* eos */ + pIcode->setAsgn(lhs, rhs); + (pIcode+1)->invalidate(); + idx = 0; + } + break; + } /* eos */ } - /* If no definition backwards, check forward for a use of this long reg */ if (idx > 0) continue; - for (idx = pLocId->idx[j] + 1; idx < Icode.size() - 1; idx++) + for (idx = pLocId_idx + 1; idx < Icode.size() - 1; idx++) { + iICODE pIcode; + ICODEMEM * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */ + int off,arc; pIcode = Icode.begin()+(idx); if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE)) continue; @@ -394,7 +474,7 @@ void Function::propLongReg (Int i, ID *pLocId) if ((pLocId->id.longId.h == pIcode->ic.ll.src.regi) && (pLocId->id.longId.l == (pIcode+1)->ic.ll.src.regi)) { - rhs = COND_EXPR::idLongIdx (i); + rhs = COND_EXPR::idLongIdx (loc_ident_idx); pIcode->setRegDU( (pIcode+1)->ic.ll.src.regi, eUSE); lhs = COND_EXPR::idLong (&this->localId, DST, pIcode, HIGH_FIRST, idx, eDEF, 1); @@ -408,7 +488,7 @@ void Function::propLongReg (Int i, ID *pLocId) if ((pLocId->id.longId.h == pIcode->ic.ll.src.regi) && (pLocId->id.longId.l == (pIcode+1)->ic.ll.src.regi)) { - rhs = COND_EXPR::idLongIdx (i); + rhs = COND_EXPR::idLongIdx (loc_ident_idx); pIcode->setRegDU( (pIcode+1)->ic.ll.src.regi, eUSE); pIcode->setUnary(HLI_PUSH, lhs); (pIcode+1)->invalidate(); @@ -424,7 +504,7 @@ void Function::propLongReg (Int i, ID *pLocId) if ((pLocId->id.longId.h == pmH->regi) && (pLocId->id.longId.l == pmL->regi)) { - lhs = COND_EXPR::idLongIdx (i); + lhs = COND_EXPR::idLongIdx (loc_ident_idx); pIcode->setRegDU( pmH->regi, USE_DEF); rhs = COND_EXPR::idLong (&this->localId, SRC, pIcode, LOW_FIRST, idx, eUSE, 1); @@ -447,7 +527,7 @@ void Function::propLongReg (Int i, ID *pLocId) else if ((pIcode->ic.ll.opcode == iCMP) && (isLong23 (idx, pIcode->inBB, &off, &arc))) { - if (checkLongRegEq (pLocId->id.longId, pIcode, i, idx, this, + if (checkLongRegEq (pLocId->id.longId, pIcode, loc_ident_idx, idx, this, &rhs, &lhs, off) == TRUE) longJCond23 (rhs, lhs, pIcode, &idx, this, arc, off); } @@ -457,7 +537,7 @@ void Function::propLongReg (Int i, ID *pLocId) else if ((pIcode->ic.ll.opcode == iCMP) && (isLong22 (pIcode, pEnd, &off))) { - if (checkLongRegEq (pLocId->id.longId, pIcode, i, idx, this, + if (checkLongRegEq (pLocId->id.longId, pIcode, loc_ident_idx, idx, this, &rhs, &lhs, off) == TRUE) longJCond22 (rhs, lhs, pIcode, &idx); } @@ -472,7 +552,7 @@ void Function::propLongReg (Int i, ID *pLocId) if ((pIcode->ic.ll.dst.regi == pLocId->id.longId.h) && (pIcode->ic.ll.src.regi == pLocId->id.longId.l)) { - lhs = COND_EXPR::idLongIdx (i); + lhs = COND_EXPR::idLongIdx (loc_ident_idx); rhs = COND_EXPR::idKte (0, 4); /* long 0 */ lhs = COND_EXPR::boolOp (lhs, rhs, diff --git a/src/reducible.cpp b/src/reducible.cpp index 19a15b5..403fe5f 100644 --- a/src/reducible.cpp +++ b/src/reducible.cpp @@ -42,12 +42,11 @@ static BB *firstOfQueue (queue &Q) queue::iterator appendQueue (queue &Q, BB *node) { auto iter=std::find(Q.begin(),Q.end(),node); - if(iter==Q.end()) - { - Q.push_back(node); - iter=Q.end(); - --iter; - } + if(iter!=Q.end()) + return iter; + Q.push_back(node); + iter=Q.end(); + --iter; return iter; } @@ -243,14 +242,14 @@ derSeq_Entry::~derSeq_Entry() * (derivedGi->Ii), and places it in derivedGi->next->Gi. */ bool Function::nextOrderGraph (derSeq *derivedGi) { - interval *Ii; /* Interval being processed */ - BB *BBnode, /* New basic block of intervals */ - *curr, /* BB being checked for out edges */ - *succ /* Successor node */ + interval *Ii; /* Interval being processed */ + BB *BBnode, /* New basic block of intervals */ + *curr, /* BB being checked for out edges */ + *succ /* Successor node */ ; - queue *listIi; /* List of intervals */ + //queue *listIi; /* List of intervals */ Int i, /* Index to outEdges array */ - j; /* Index to successors */ + j; /* Index to successors */ boolT sameGraph; /* Boolean, isomorphic graphs */ /* Process Gi's intervals */ @@ -277,9 +276,8 @@ bool Function::nextOrderGraph (derSeq *derivedGi) if (BBnode->edges.size() > 0) { - for(auto iter=listIi.begin();iter!=listIi.end(); ++iter) + for(BB *curr : listIi) { - curr = *iter; for (j = 0; j < curr->edges.size(); j++) { succ = curr->edges[j].BBptr; @@ -297,12 +295,11 @@ bool Function::nextOrderGraph (derSeq *derivedGi) * Determines the number of in edges to each new BB, and places it * in numInEdges and inEdgeCount for later interval processing. */ curr = new_entry.Gi = bbs.front(); - for(auto curr=bbs.begin(); curr!=bbs.end(); ++curr) + for(BB *curr : bbs) { - for (i = 0; i < (*curr)->edges.size(); i++) + for(TYPEADR_TYPE &edge : curr->edges) { BBnode = new_entry.Gi; /* BB of an interval */ - TYPEADR_TYPE &edge=(*curr)->edges[i]; auto iter= std::find_if(bbs.begin(),bbs.end(), [&edge](BB *node)->bool { return edge.intPtr==node->correspInt;}); if(iter==bbs.end()) diff --git a/src/scanner.cpp b/src/scanner.cpp index 779f9be..f6af201 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -5,11 +5,42 @@ * (C) Cristina Cifuentes, Jeff Ledermann ****************************************************************************/ +#include + #include "dcc.h" #include "scanner.h" -#include -#define iZERO (llIcode)0 // For neatness +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 { @@ -20,120 +51,120 @@ static struct { byte df; byte uf; } stateTable[] = { - { modrm, none2, B , iADD , Sf | Zf | Cf, }, /* 00 */ - { modrm, none2, 0 , iADD , Sf | Zf | Cf, }, /* 01 */ - { modrm, none2, TO_REG | B , iADD , Sf | Zf | Cf, }, /* 02 */ - { modrm, none2, TO_REG , iADD , Sf | Zf | Cf, }, /* 03 */ - { data1, axImp, B , iADD , Sf | Zf | Cf, }, /* 04 */ - { data2, axImp, 0 , iADD , Sf | Zf | Cf, }, /* 05 */ - { segop, none2, NO_SRC , iPUSH , 0 , }, /* 06 */ - { segop, none2, NO_SRC , iPOP , 0 , }, /* 07 */ - { modrm, none2, B , iOR , Sf | Zf | Cf, }, /* 08 */ - { modrm, none2, NSP , iOR , Sf | Zf | Cf, }, /* 09 */ - { modrm, none2, TO_REG | B , iOR , Sf | Zf | Cf, }, /* 0A */ - { modrm, none2, TO_REG | NSP , iOR , Sf | Zf | Cf, }, /* 0B */ - { data1, axImp, B , iOR , Sf | Zf | Cf, }, /* 0C */ - { data2, axImp, 0 , iOR , Sf | Zf | Cf, }, /* 0D */ - { segop, none2, NO_SRC , iPUSH , 0 , }, /* 0E */ - { none1, none2, OP386 , iZERO , 0 , }, /* 0F */ - { modrm, none2, B , iADC , Sf | Zf | Cf, Cf }, /* 10 */ - { modrm, none2, NSP , iADC , Sf | Zf | Cf, Cf }, /* 11 */ - { modrm, none2, TO_REG | B , iADC , Sf | Zf | Cf, Cf }, /* 12 */ - { modrm, none2, TO_REG | NSP , iADC , Sf | Zf | Cf, Cf }, /* 13 */ - { data1, axImp, B , iADC , Sf | Zf | Cf, Cf }, /* 14 */ - { data2, axImp, 0 , iADC , Sf | Zf | Cf, Cf }, /* 15 */ - { segop, none2, NOT_HLL | NO_SRC , iPUSH , 0 , }, /* 16 */ - { segop, none2, NOT_HLL | NO_SRC , iPOP , 0 , }, /* 17 */ - { modrm, none2, B , iSBB , Sf | Zf | Cf, Cf }, /* 18 */ - { modrm, none2, NSP , iSBB , Sf | Zf | Cf, Cf }, /* 19 */ - { modrm, none2, TO_REG | B , iSBB , Sf | Zf | Cf, Cf }, /* 1A */ - { modrm, none2, TO_REG | NSP , iSBB , Sf | Zf | Cf, Cf }, /* 1B */ - { data1, axImp, B , iSBB , Sf | Zf | Cf, Cf }, /* 1C */ - { data2, axImp, 0 , iSBB , Sf | Zf | Cf, Cf }, /* 1D */ - { segop, none2, NO_SRC , iPUSH , 0 , }, /* 1E */ - { segop, none2, NO_SRC , iPOP , 0 , }, /* 1F */ - { modrm, none2, B , iAND , Sf | Zf | Cf, }, /* 20 */ - { modrm, none2, NSP , iAND , Sf | Zf | Cf, }, /* 21 */ - { modrm, none2, TO_REG | B , iAND , Sf | Zf | Cf, }, /* 22 */ - { modrm, none2, TO_REG | NSP , iAND , Sf | Zf | Cf, }, /* 23 */ - { data1, axImp, B , iAND , Sf | Zf | Cf, }, /* 24 */ - { data2, axImp, 0 , iAND , Sf | Zf | Cf, }, /* 25 */ - { prefix, none2, 0 , (IC)rES,0 , }, /* 26 */ - { none1, axImp, NOT_HLL | B|NO_SRC , iDAA , Sf | Zf | Cf, }, /* 27 */ - { modrm, none2, B , iSUB , Sf | Zf | Cf, }, /* 28 */ - { modrm, none2, 0 , iSUB , Sf | Zf | Cf, }, /* 29 */ - { modrm, none2, TO_REG | B , iSUB , Sf | Zf | Cf, }, /* 2A */ - { modrm, none2, TO_REG , iSUB , Sf | Zf | Cf, }, /* 2B */ - { data1, axImp, B , iSUB , Sf | Zf | Cf, }, /* 2C */ - { data2, axImp, 0 , iSUB , Sf | Zf | Cf, }, /* 2D */ - { prefix, none2, 0 , (IC)rCS,0 , }, /* 2E */ - { none1, axImp, NOT_HLL | B|NO_SRC , iDAS , Sf | Zf | Cf, }, /* 2F */ - { modrm, none2, B , iXOR , Sf | Zf | Cf, }, /* 30 */ - { modrm, none2, NSP , iXOR , Sf | Zf | Cf, }, /* 31 */ - { modrm, none2, TO_REG | B , iXOR , Sf | Zf | Cf, }, /* 32 */ - { modrm, none2, TO_REG | NSP , iXOR , Sf | Zf | Cf, }, /* 33 */ - { data1, axImp, B , iXOR , Sf | Zf | Cf, }, /* 34 */ - { data2, axImp, 0 , iXOR , Sf | Zf | Cf, }, /* 35 */ - { prefix, none2, 0 , (IC)rSS,0 , }, /* 36 */ - { none1, axImp, NOT_HLL | NO_SRC , iAAA , Sf | Zf | Cf, }, /* 37 */ - { modrm, none2, B , iCMP , Sf | Zf | Cf, }, /* 38 */ - { modrm, none2, NSP , iCMP , Sf | Zf | Cf, }, /* 39 */ - { modrm, none2, TO_REG | B , iCMP , Sf | Zf | Cf, }, /* 3A */ - { modrm, none2, TO_REG | NSP , iCMP , Sf | Zf | Cf, }, /* 3B */ - { data1, axImp, B , iCMP , Sf | Zf | Cf, }, /* 3C */ - { data2, axImp, 0 , iCMP , Sf | Zf | Cf, }, /* 3D */ - { prefix, none2, 0 , (IC)rDS,0 , }, /* 3E */ - { none1, axImp, NOT_HLL | NO_SRC , iAAS , Sf | Zf | Cf, }, /* 3F */ - { regop, none2, 0 , iINC , Sf | Zf, }, /* 40 */ - { regop, none2, 0 , iINC , Sf | Zf, }, /* 41 */ - { regop, none2, 0 , iINC , Sf | Zf, }, /* 42 */ - { regop, none2, 0 , iINC , Sf | Zf, }, /* 43 */ - { regop, none2, NOT_HLL , iINC , Sf | Zf, }, /* 44 */ - { regop, none2, 0 , iINC , Sf | Zf, }, /* 45 */ - { regop, none2, 0 , iINC , Sf | Zf, }, /* 46 */ - { regop, none2, 0 , iINC , Sf | Zf, }, /* 47 */ - { regop, none2, 0 , iDEC , Sf | Zf, }, /* 48 */ - { regop, none2, 0 , iDEC , Sf | Zf, }, /* 49 */ - { regop, none2, 0 , iDEC , Sf | Zf, }, /* 4A */ - { regop, none2, 0 , iDEC , Sf | Zf, }, /* 4B */ - { regop, none2, NOT_HLL , iDEC , Sf | Zf, }, /* 4C */ - { regop, none2, 0 , iDEC , Sf | Zf, }, /* 4D */ - { regop, none2, 0 , iDEC , Sf | Zf, }, /* 4E */ - { regop, none2, 0 , iDEC , Sf | Zf, }, /* 4F */ - { regop, none2, NO_SRC , iPUSH , 0 , }, /* 50 */ - { regop, none2, NO_SRC , iPUSH , 0 , }, /* 51 */ - { regop, none2, NO_SRC , iPUSH , 0 , }, /* 52 */ - { regop, none2, NO_SRC , iPUSH , 0 , }, /* 53 */ - { regop, none2, NOT_HLL | NO_SRC , iPUSH , 0 , }, /* 54 */ - { regop, none2, NO_SRC , iPUSH , 0 , }, /* 55 */ - { regop, none2, NO_SRC , iPUSH , 0 , }, /* 56 */ - { regop, none2, NO_SRC , iPUSH , 0 , }, /* 57 */ - { regop, none2, NO_SRC , iPOP , 0 , }, /* 58 */ - { regop, none2, NO_SRC , iPOP , 0 , }, /* 59 */ - { regop, none2, NO_SRC , iPOP , 0 , }, /* 5A */ - { regop, none2, NO_SRC , iPOP , 0 , }, /* 5B */ - { regop, none2, NOT_HLL | NO_SRC , iPOP , 0 , }, /* 5C */ - { regop, none2, NO_SRC , iPOP , 0 , }, /* 5D */ - { regop, none2, NO_SRC , iPOP , 0 , }, /* 5E */ - { regop, none2, NO_SRC , iPOP , 0 , }, /* 5F */ - { none1, none2, NOT_HLL | NO_OPS , iPUSHA, 0 , }, /* 60 */ - { none1, none2, NOT_HLL | NO_OPS , iPOPA , 0 , }, /* 61 */ - { memOnly, modrm, TO_REG | NSP , iBOUND, 0 , }, /* 62 */ - { none1, none2, OP386 , iZERO , 0 , }, /* 63 */ - { none1, none2, OP386 , iZERO , 0 , }, /* 64 */ - { none1, none2, OP386 , iZERO , 0 , }, /* 65 */ - { none1, none2, OP386 , iZERO , 0 , }, /* 66 */ - { none1, none2, OP386 , iZERO , 0 , }, /* 67 */ - { data2, none2, NO_SRC , iPUSH , 0 , }, /* 68 */ - { modrm, data2, TO_REG | NSP , iIMUL , Sf | Zf | Cf, }, /* 69 */ - { data1, none2, S_EXT | NO_SRC , iPUSH , 0 , }, /* 6A */ - { modrm, data1, TO_REG | NSP | S_EXT , iIMUL , Sf | Zf | Cf, }, /* 6B */ + { modrm, none2, B , iADD , Sf | Zf | Cf , 0 }, /* 00 */ + { modrm, none2, 0 , iADD , Sf | Zf | Cf , 0 }, /* 01 */ + { modrm, none2, TO_REG | B , iADD , Sf | Zf | Cf , 0 }, /* 02 */ + { modrm, none2, TO_REG , iADD , Sf | Zf | Cf , 0 }, /* 03 */ + { data1, axImp, B , iADD , Sf | Zf | Cf , 0 }, /* 04 */ + { data2, axImp, 0 , iADD , Sf | Zf | Cf , 0 }, /* 05 */ + { segop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 06 */ + { segop, none2, NO_SRC , iPOP , 0 , 0 }, /* 07 */ + { modrm, none2, B , iOR , Sf | Zf | Cf , 0 }, /* 08 */ + { modrm, none2, NSP , iOR , Sf | Zf | Cf , 0 }, /* 09 */ + { modrm, none2, TO_REG | B , iOR , Sf | Zf | Cf , 0 }, /* 0A */ + { modrm, none2, TO_REG | NSP , iOR , Sf | Zf | Cf , 0 }, /* 0B */ + { data1, axImp, B , iOR , Sf | Zf | Cf , 0 }, /* 0C */ + { data2, axImp, 0 , iOR , Sf | Zf | Cf , 0 }, /* 0D */ + { segop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 0E */ + { none1, none2, OP386 , iZERO , 0 , 0 }, /* 0F */ + { modrm, none2, B , iADC , Sf | Zf | Cf , Cf }, /* 10 */ + { modrm, none2, NSP , iADC , Sf | Zf | Cf , Cf }, /* 11 */ + { modrm, none2, TO_REG | B , iADC , Sf | Zf | Cf , Cf }, /* 12 */ + { modrm, none2, TO_REG | NSP , iADC , Sf | Zf | Cf , Cf }, /* 13 */ + { data1, axImp, B , iADC , Sf | Zf | Cf , Cf }, /* 14 */ + { data2, axImp, 0 , iADC , Sf | Zf | Cf , Cf }, /* 15 */ + { segop, none2, NOT_HLL | NO_SRC , iPUSH , 0 , 0 }, /* 16 */ + { segop, none2, NOT_HLL | NO_SRC , iPOP , 0 , 0 }, /* 17 */ + { modrm, none2, B , iSBB , Sf | Zf | Cf , Cf }, /* 18 */ + { modrm, none2, NSP , iSBB , Sf | Zf | Cf , Cf }, /* 19 */ + { modrm, none2, TO_REG | B , iSBB , Sf | Zf | Cf , Cf }, /* 1A */ + { modrm, none2, TO_REG | NSP , iSBB , Sf | Zf | Cf , Cf }, /* 1B */ + { data1, axImp, B , iSBB , Sf | Zf | Cf , Cf }, /* 1C */ + { data2, axImp, 0 , iSBB , Sf | Zf | Cf , Cf }, /* 1D */ + { segop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 1E */ + { segop, none2, NO_SRC , iPOP , 0 , 0 }, /* 1F */ + { modrm, none2, B , iAND , Sf | Zf | Cf , 0 }, /* 20 */ + { modrm, none2, NSP , iAND , Sf | Zf | Cf , 0 }, /* 21 */ + { modrm, none2, TO_REG | B , iAND , Sf | Zf | Cf , 0 }, /* 22 */ + { modrm, none2, TO_REG | NSP , iAND , Sf | Zf | Cf , 0 }, /* 23 */ + { data1, axImp, B , iAND , Sf | Zf | Cf , 0 }, /* 24 */ + { data2, axImp, 0 , iAND , Sf | Zf | Cf , 0 }, /* 25 */ + { prefix, none2, 0 , (IC)rES,0 , 0 }, /* 26 */ + { none1, axImp, NOT_HLL | B|NO_SRC , iDAA , Sf | Zf | Cf , 0 }, /* 27 */ + { modrm, none2, B , iSUB , Sf | Zf | Cf , 0 }, /* 28 */ + { modrm, none2, 0 , iSUB , Sf | Zf | Cf , 0 }, /* 29 */ + { modrm, none2, TO_REG | B , iSUB , Sf | Zf | Cf , 0 }, /* 2A */ + { modrm, none2, TO_REG , iSUB , Sf | Zf | Cf , 0 }, /* 2B */ + { data1, axImp, B , iSUB , Sf | Zf | Cf , 0 }, /* 2C */ + { data2, axImp, 0 , iSUB , Sf | Zf | Cf , 0 }, /* 2D */ + { prefix, none2, 0 , (IC)rCS,0 , 0 }, /* 2E */ + { none1, axImp, NOT_HLL | B|NO_SRC , iDAS , Sf | Zf | Cf , 0 }, /* 2F */ + { modrm, none2, B , iXOR , Sf | Zf | Cf , 0 }, /* 30 */ + { modrm, none2, NSP , iXOR , Sf | Zf | Cf , 0 }, /* 31 */ + { modrm, none2, TO_REG | B , iXOR , Sf | Zf | Cf , 0 }, /* 32 */ + { modrm, none2, TO_REG | NSP , iXOR , Sf | Zf | Cf , 0 }, /* 33 */ + { data1, axImp, B , iXOR , Sf | Zf | Cf , 0 }, /* 34 */ + { data2, axImp, 0 , iXOR , Sf | Zf | Cf , 0 }, /* 35 */ + { prefix, none2, 0 , (IC)rSS,0 , 0 }, /* 36 */ + { none1, axImp, NOT_HLL | NO_SRC , iAAA , Sf | Zf | Cf , 0 }, /* 37 */ + { modrm, none2, B , iCMP , Sf | Zf | Cf , 0 }, /* 38 */ + { modrm, none2, NSP , iCMP , Sf | Zf | Cf , 0 }, /* 39 */ + { modrm, none2, TO_REG | B , iCMP , Sf | Zf | Cf , 0 }, /* 3A */ + { modrm, none2, TO_REG | NSP , iCMP , Sf | Zf | Cf , 0 }, /* 3B */ + { data1, axImp, B , iCMP , Sf | Zf | Cf , 0 }, /* 3C */ + { data2, axImp, 0 , iCMP , Sf | Zf | Cf , 0 }, /* 3D */ + { prefix, none2, 0 , (IC)rDS,0 , 0 }, /* 3E */ + { none1, axImp, NOT_HLL | NO_SRC , iAAS , Sf | Zf | Cf , 0 }, /* 3F */ + { regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 40 */ + { regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 41 */ + { regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 42 */ + { regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 43 */ + { regop, none2, NOT_HLL , iINC , Sf | Zf, 0 }, /* 44 */ + { regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 45 */ + { regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 46 */ + { regop, none2, 0 , iINC , Sf | Zf, 0 }, /* 47 */ + { regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 48 */ + { regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 49 */ + { regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 4A */ + { regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 4B */ + { regop, none2, NOT_HLL , iDEC , Sf | Zf, 0 }, /* 4C */ + { regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 4D */ + { regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 4E */ + { regop, none2, 0 , iDEC , Sf | Zf, 0 }, /* 4F */ + { regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 50 */ + { regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 51 */ + { regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 52 */ + { regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 53 */ + { regop, none2, NOT_HLL | NO_SRC , iPUSH , 0 , 0 }, /* 54 */ + { regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 55 */ + { regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 56 */ + { regop, none2, NO_SRC , iPUSH , 0 , 0 }, /* 57 */ + { regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 58 */ + { regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 59 */ + { regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5A */ + { regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5B */ + { regop, none2, NOT_HLL | NO_SRC , iPOP , 0 , 0 }, /* 5C */ + { regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5D */ + { regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5E */ + { regop, none2, NO_SRC , iPOP , 0 , 0 }, /* 5F */ + { none1, none2, NOT_HLL | NO_OPS , iPUSHA, 0 , 0 }, /* 60 */ + { none1, none2, NOT_HLL | NO_OPS , iPOPA , 0 , 0 }, /* 61 */ + { memOnly, modrm, TO_REG | NSP , iBOUND, 0 , 0 }, /* 62 */ + { none1, none2, OP386 , iZERO , 0 , 0 }, /* 63 */ + { none1, none2, OP386 , iZERO , 0 , 0 }, /* 64 */ + { none1, none2, OP386 , iZERO , 0 , 0 }, /* 65 */ + { none1, none2, OP386 , iZERO , 0 , 0 }, /* 66 */ + { none1, none2, OP386 , iZERO , 0 , 0 }, /* 67 */ + { data2, none2, NO_SRC , iPUSH , 0 , 0 }, /* 68 */ + { modrm, data2, TO_REG | NSP , iIMUL , Sf | Zf | Cf, 0 }, /* 69 */ + { data1, none2, S_EXT | NO_SRC , iPUSH , 0 , 0 }, /* 6A */ + { modrm, data1, TO_REG | NSP | S_EXT , iIMUL , Sf | Zf | Cf, 0 }, /* 6B */ { strop, memImp, NOT_HLL | B|IM_OPS , iINS , 0 , Df }, /* 6C */ { strop, memImp, NOT_HLL | IM_OPS , iINS , 0 , Df }, /* 6D */ { strop, memImp, NOT_HLL | B|IM_OPS , iOUTS , 0 , Df }, /* 6E */ { strop, memImp, NOT_HLL | IM_OPS , iOUTS , 0 , Df }, /* 6F */ - { dispS, none2, NOT_HLL , iJO , 0 , }, /* 70 */ - { dispS, none2, NOT_HLL , iJNO , 0 , }, /* 71 */ + { dispS, none2, NOT_HLL , iJO , 0 , 0 }, /* 70 */ + { dispS, none2, NOT_HLL , iJNO , 0 , 0 }, /* 71 */ { dispS, none2, 0 , iJB , 0 , Cf }, /* 72 */ { dispS, none2, 0 , iJAE , 0 , Cf }, /* 73 */ { dispS, none2, 0 , iJE , 0 , Zf }, /* 74 */ @@ -142,140 +173,140 @@ static struct { { dispS, none2, 0 , iJA , 0 , Zf | Cf }, /* 77 */ { dispS, none2, 0 , iJS , 0 , Sf }, /* 78 */ { dispS, none2, 0 , iJNS , 0 , Sf }, /* 79 */ - { dispS, none2, NOT_HLL , iJP , 0 , }, /* 7A */ - { dispS, none2, NOT_HLL , iJNP , 0 , }, /* 7B */ + { dispS, none2, NOT_HLL , iJP , 0 , 0 }, /* 7A */ + { dispS, none2, NOT_HLL , iJNP , 0 , 0 }, /* 7B */ { dispS, none2, 0 , iJL , 0 , Sf }, /* 7C */ { dispS, none2, 0 , iJGE , 0 , Sf }, /* 7D */ { dispS, none2, 0 , iJLE , 0 , Sf | Zf }, /* 7E */ { dispS, none2, 0 , iJG , 0 , Sf | Zf }, /* 7F */ - { immed, data1, B , iZERO , 0 , }, /* 80 */ - { immed, data2, NSP , iZERO , 0 , }, /* 81 */ - { immed, data1, B , iZERO , 0 , }, /* 82 */ /* ?? */ - { immed, data1, NSP | S_EXT , iZERO , 0 , }, /* 83 */ - { modrm, none2, TO_REG | B , iTEST , Sf | Zf | Cf, }, /* 84 */ - { modrm, none2, TO_REG | NSP , iTEST , Sf | Zf | Cf, }, /* 85 */ - { modrm, none2, TO_REG | B , iXCHG , 0 , }, /* 86 */ - { modrm, none2, TO_REG | NSP , iXCHG , 0 , }, /* 87 */ - { modrm, none2, B , iMOV , 0 , }, /* 88 */ - { modrm, none2, 0 , iMOV , 0 , }, /* 89 */ - { modrm, none2, TO_REG | B , iMOV , 0 , }, /* 8A */ - { modrm, none2, TO_REG , iMOV , 0 , }, /* 8B */ - { segrm, none2, NSP , iMOV , 0 , }, /* 8C */ - { memOnly, modrm, TO_REG | NSP , iLEA , 0 , }, /* 8D */ - { segrm, none2, TO_REG | NSP , iMOV , 0 , }, /* 8E */ - { memReg0, none2, NO_SRC , iPOP , 0 , }, /* 8F */ - { none1, none2, NO_OPS , iNOP , 0 , }, /* 90 */ - { regop, axImp, 0 , iXCHG , 0 , }, /* 91 */ - { regop, axImp, 0 , iXCHG , 0 , }, /* 92 */ - { regop, axImp, 0 , iXCHG , 0 , }, /* 93 */ - { regop, axImp, NOT_HLL , iXCHG , 0 , }, /* 94 */ - { regop, axImp, 0 , iXCHG , 0 , }, /* 95 */ - { regop, axImp, 0 , iXCHG , 0 , }, /* 96 */ - { regop, axImp, 0 , iXCHG , 0 , }, /* 97 */ - { alImp, axImp, SRC_B | S_EXT , iSIGNEX,0 , }, /* 98 */ - {axSrcIm, axImp, IM_DST | S_EXT , iSIGNEX,0 , }, /* 99 */ - { dispF, none2, 0 , iCALLF ,0 , }, /* 9A */ - { none1, none2, FLOAT_OP| NO_OPS , iWAIT , 0 , }, /* 9B */ - { none1, none2, NOT_HLL | NO_OPS , iPUSHF, 0 , }, /* 9C */ + { immed, data1, B , iZERO , 0 , 0 }, /* 80 */ + { immed, data2, NSP , iZERO , 0 , 0 }, /* 81 */ + { immed, data1, B , iZERO , 0 , 0 }, /* 82 */ /* ?? */ + { immed, data1, NSP | S_EXT , iZERO , 0 , 0 }, /* 83 */ + { modrm, none2, TO_REG | B , iTEST , Sf | Zf | Cf, 0 }, /* 84 */ + { modrm, none2, TO_REG | NSP , iTEST , Sf | Zf | Cf, 0 }, /* 85 */ + { modrm, none2, TO_REG | B , iXCHG , 0 , 0 }, /* 86 */ + { modrm, none2, TO_REG | NSP , iXCHG , 0 , 0 }, /* 87 */ + { modrm, none2, B , iMOV , 0 , 0 }, /* 88 */ + { modrm, none2, 0 , iMOV , 0 , 0 }, /* 89 */ + { modrm, none2, TO_REG | B , iMOV , 0 , 0 }, /* 8A */ + { modrm, none2, TO_REG , iMOV , 0 , 0 }, /* 8B */ + { segrm, none2, NSP , iMOV , 0 , 0 }, /* 8C */ + { memOnly, modrm, TO_REG | NSP , iLEA , 0 , 0 }, /* 8D */ + { segrm, none2, TO_REG | NSP , iMOV , 0 , 0 }, /* 8E */ + { memReg0, none2, NO_SRC , iPOP , 0 , 0 }, /* 8F */ + { none1, none2, NO_OPS , iNOP , 0 , 0 }, /* 90 */ + { regop, axImp, 0 , iXCHG , 0 , 0 }, /* 91 */ + { regop, axImp, 0 , iXCHG , 0 , 0 }, /* 92 */ + { regop, axImp, 0 , iXCHG , 0 , 0 }, /* 93 */ + { regop, axImp, NOT_HLL , iXCHG , 0 , 0 }, /* 94 */ + { regop, axImp, 0 , iXCHG , 0 , 0 }, /* 95 */ + { regop, axImp, 0 , iXCHG , 0 , 0 }, /* 96 */ + { regop, axImp, 0 , iXCHG , 0 , 0 }, /* 97 */ + { alImp, axImp, SRC_B | S_EXT , iSIGNEX,0 , 0 }, /* 98 */ + {axSrcIm, axImp, IM_DST | S_EXT , iSIGNEX,0 , 0 }, /* 99 */ + { dispF, none2, 0 , iCALLF ,0 , 0 }, /* 9A */ + { none1, none2, FLOAT_OP| NO_OPS , iWAIT , 0 , 0 }, /* 9B */ + { none1, none2, NOT_HLL | NO_OPS , iPUSHF, 0 , 0 }, /* 9C */ { none1, none2, NOT_HLL | NO_OPS , iPOPF , Sf | Zf | Cf | Df,}, /* 9D */ - { none1, none2, NOT_HLL | NO_OPS , iSAHF , Sf | Zf | Cf, }, /* 9E */ + { none1, none2, NOT_HLL | NO_OPS , iSAHF , Sf | Zf | Cf, 0 }, /* 9E */ { none1, none2, NOT_HLL | NO_OPS , iLAHF , 0 , Sf | Zf | Cf }, /* 9F */ - { dispM, axImp, B , iMOV , 0 , }, /* A0 */ - { dispM, axImp, 0 , iMOV , 0 , }, /* A1 */ - { dispM, axImp, TO_REG | B , iMOV , 0 , }, /* A2 */ - { dispM, axImp, TO_REG , iMOV , 0 , }, /* A3 */ + { dispM, axImp, B , iMOV , 0 , 0 }, /* A0 */ + { dispM, axImp, 0 , iMOV , 0 , 0 }, /* A1 */ + { dispM, axImp, TO_REG | B , iMOV , 0 , 0 }, /* A2 */ + { dispM, axImp, TO_REG , iMOV , 0 , 0 }, /* A3 */ { strop, memImp, B | IM_OPS , iMOVS , 0 , Df }, /* A4 */ { strop, memImp, IM_OPS , iMOVS , 0 , Df }, /* A5 */ { strop, memImp, B | IM_OPS , iCMPS , Sf | Zf | Cf, Df }, /* A6 */ { strop, memImp, IM_OPS , iCMPS , Sf | Zf | Cf, Df }, /* A7 */ - { data1, axImp, B , iTEST , Sf | Zf | Cf, }, /* A8 */ - { data2, axImp, 0 , iTEST , Sf | Zf | Cf, }, /* A9 */ + { data1, axImp, B , iTEST , Sf | Zf | Cf, 0 }, /* A8 */ + { data2, axImp, 0 , iTEST , Sf | Zf | Cf, 0 }, /* A9 */ { strop, memImp, B | IM_OPS , iSTOS , 0 , Df }, /* AA */ { strop, memImp, IM_OPS , iSTOS , 0 , Df }, /* AB */ { strop, memImp, B | IM_OPS , iLODS , 0 , Df }, /* AC */ { strop, memImp, IM_OPS , iLODS , 0 , Df }, /* AD */ { strop, memImp, B | IM_OPS , iSCAS , Sf | Zf | Cf, Df }, /* AE */ { strop, memImp, IM_OPS , iSCAS , Sf | Zf | Cf, Df }, /* AF */ - { regop, data1, B , iMOV , 0 , }, /* B0 */ - { regop, data1, B , iMOV , 0 , }, /* B1 */ - { regop, data1, B , iMOV , 0 , }, /* B2 */ - { regop, data1, B , iMOV , 0 , }, /* B3 */ - { regop, data1, B , iMOV , 0 , }, /* B4 */ - { regop, data1, B , iMOV , 0 , }, /* B5 */ - { regop, data1, B , iMOV , 0 , }, /* B6 */ - { regop, data1, B , iMOV , 0 , }, /* B7 */ - { regop, data2, 0 , iMOV , 0 , }, /* B8 */ - { regop, data2, 0 , iMOV , 0 , }, /* B9 */ - { regop, data2, 0 , iMOV , 0 , }, /* BA */ - { regop, data2, 0 , iMOV , 0 , }, /* BB */ - { regop, data2, NOT_HLL , iMOV , 0 , }, /* BC */ - { regop, data2, 0 , iMOV , 0 , }, /* BD */ - { regop, data2, 0 , iMOV , 0 , }, /* BE */ - { regop, data2, 0 , iMOV , 0 , }, /* BF */ - { shift, data1, B , iZERO , 0 , }, /* C0 */ - { shift, data1, NSP | SRC_B , iZERO , 0 , }, /* C1 */ - { data2, none2, 0 , iRET , 0 , }, /* C2 */ - { none1, none2, NO_OPS , iRET , 0 , }, /* C3 */ - { memOnly, modrm, TO_REG | NSP , iLES , 0 , }, /* C4 */ - { memOnly, modrm, TO_REG | NSP , iLDS , 0 , }, /* C5 */ - { memReg0, data1, B , iMOV , 0 , }, /* C6 */ - { memReg0, data2, 0 , iMOV , 0 , }, /* C7 */ - { data2, data1, 0 , iENTER, 0 , }, /* C8 */ - { none1, none2, NO_OPS , iLEAVE, 0 , }, /* C9 */ - { data2, none2, 0 , iRETF , 0 , }, /* CA */ - { none1, none2, NO_OPS , iRETF , 0 , }, /* CB */ - { const3, none2, NOT_HLL , iINT , 0 , }, /* CC */ - { data1,checkInt, NOT_HLL , iINT , 0 , }, /* CD */ - { none1, none2, NOT_HLL | NO_OPS , iINTO , 0 , }, /* CE */ - { none1, none2, NOT_HLL | NO_OPS , iIRET , 0 , }, /* Cf */ - { shift, const1, B , iZERO , 0 , }, /* D0 */ - { shift, const1, SRC_B , iZERO , 0 , }, /* D1 */ - { shift, none1, B , iZERO , 0 , }, /* D2 */ - { shift, none1, SRC_B , iZERO , 0 , }, /* D3 */ - { data1, axImp, NOT_HLL , iAAM , Sf | Zf | Cf, }, /* D4 */ - { data1, axImp, NOT_HLL , iAAD , Sf | Zf | Cf, }, /* D5 */ - { none1, none2, 0 , iZERO , 0 , }, /* D6 */ - { memImp, axImp, NOT_HLL | B| IM_OPS, iXLAT , 0 , }, /* D7 */ - { escop, none2, FLOAT_OP , iESC , 0 , }, /* D8 */ - { escop, none2, FLOAT_OP , iESC , 0 , }, /* D9 */ - { escop, none2, FLOAT_OP , iESC , 0 , }, /* DA */ - { escop, none2, FLOAT_OP , iESC , 0 , }, /* DB */ - { escop, none2, FLOAT_OP , iESC , 0 , }, /* DC */ - { escop, none2, FLOAT_OP , iESC , 0 , }, /* DD */ - { escop, none2, FLOAT_OP , iESC , 0 , }, /* DE */ - { escop, none2, FLOAT_OP , iESC , 0 , }, /* Df */ + { regop, data1, B , iMOV , 0 , 0 }, /* B0 */ + { regop, data1, B , iMOV , 0 , 0 }, /* B1 */ + { regop, data1, B , iMOV , 0 , 0 }, /* B2 */ + { regop, data1, B , iMOV , 0 , 0 }, /* B3 */ + { regop, data1, B , iMOV , 0 , 0 }, /* B4 */ + { regop, data1, B , iMOV , 0 , 0 }, /* B5 */ + { regop, data1, B , iMOV , 0 , 0 }, /* B6 */ + { regop, data1, B , iMOV , 0 , 0 }, /* B7 */ + { regop, data2, 0 , iMOV , 0 , 0 }, /* B8 */ + { regop, data2, 0 , iMOV , 0 , 0 }, /* B9 */ + { regop, data2, 0 , iMOV , 0 , 0 }, /* BA */ + { regop, data2, 0 , iMOV , 0 , 0 }, /* BB */ + { regop, data2, NOT_HLL , iMOV , 0 , 0 }, /* BC */ + { regop, data2, 0 , iMOV , 0 , 0 }, /* BD */ + { regop, data2, 0 , iMOV , 0 , 0 }, /* BE */ + { regop, data2, 0 , iMOV , 0 , 0 }, /* BF */ + { shift, data1, B , iZERO , 0 , 0 }, /* C0 */ + { shift, data1, NSP | SRC_B , iZERO , 0 , 0 }, /* C1 */ + { data2, none2, 0 , iRET , 0 , 0 }, /* C2 */ + { none1, none2, NO_OPS , iRET , 0 , 0 }, /* C3 */ + { memOnly, modrm, TO_REG | NSP , iLES , 0 , 0 }, /* C4 */ + { memOnly, modrm, TO_REG | NSP , iLDS , 0 , 0 }, /* C5 */ + { memReg0, data1, B , iMOV , 0 , 0 }, /* C6 */ + { memReg0, data2, 0 , iMOV , 0 , 0 }, /* C7 */ + { data2, data1, 0 , iENTER, 0 , 0 }, /* C8 */ + { none1, none2, NO_OPS , iLEAVE, 0 , 0 }, /* C9 */ + { data2, none2, 0 , iRETF , 0 , 0 }, /* CA */ + { none1, none2, NO_OPS , iRETF , 0 , 0 }, /* CB */ + { const3, none2, NOT_HLL , iINT , 0 , 0 }, /* CC */ + { data1,checkInt, NOT_HLL , iINT , 0 , 0 }, /* CD */ + { none1, none2, NOT_HLL | NO_OPS , iINTO , 0 , 0 }, /* CE */ + { none1, none2, NOT_HLL | NO_OPS , iIRET , 0 , 0 }, /* Cf */ + { shift, const1, B , iZERO , 0 , 0 }, /* D0 */ + { shift, const1, SRC_B , iZERO , 0 , 0 }, /* D1 */ + { shift, none1, B , iZERO , 0 , 0 }, /* D2 */ + { shift, none1, SRC_B , iZERO , 0 , 0 }, /* D3 */ + { data1, axImp, NOT_HLL , iAAM , Sf | Zf | Cf, 0 }, /* D4 */ + { data1, axImp, NOT_HLL , iAAD , Sf | Zf | Cf, 0 }, /* D5 */ + { none1, none2, 0 , iZERO , 0 , 0 }, /* D6 */ + { memImp, axImp, NOT_HLL | B| IM_OPS, iXLAT , 0 , 0 }, /* D7 */ + { escop, none2, FLOAT_OP , iESC , 0 , 0 }, /* D8 */ + { escop, none2, FLOAT_OP , iESC , 0 , 0 }, /* D9 */ + { escop, none2, FLOAT_OP , iESC , 0 , 0 }, /* DA */ + { escop, none2, FLOAT_OP , iESC , 0 , 0 }, /* DB */ + { escop, none2, FLOAT_OP , iESC , 0 , 0 }, /* DC */ + { escop, none2, FLOAT_OP , iESC , 0 , 0 }, /* DD */ + { escop, none2, FLOAT_OP , iESC , 0 , 0 }, /* DE */ + { escop, none2, FLOAT_OP , iESC , 0 , 0 }, /* Df */ { dispS, none2, 0 , iLOOPNE,0 , Zf }, /* E0 */ { dispS, none2, 0 , iLOOPE, 0 , Zf }, /* E1 */ - { dispS, none2, 0 , iLOOP , 0 , }, /* E2 */ - { dispS, none2, 0 , iJCXZ , 0 , }, /* E3 */ - { data1, axImp, NOT_HLL | B|NO_SRC , iIN , 0 , }, /* E4 */ - { data1, axImp, NOT_HLL | NO_SRC , iIN , 0 , }, /* E5 */ - { data1, axImp, NOT_HLL | B|NO_SRC , iOUT , 0 , }, /* E6 */ - { data1, axImp, NOT_HLL | NO_SRC , iOUT , 0 , }, /* E7 */ - { dispN, none2, 0 , iCALL , 0 , }, /* E8 */ - { dispN, none2, 0 , iJMP , 0 , }, /* E9 */ - { dispF, none2, 0 , iJMPF , 0 , }, /* EA */ - { dispS, none2, 0 , iJMP , 0 , }, /* EB */ - { none1, axImp, NOT_HLL | B|NO_SRC , iIN , 0 , }, /* EC */ - { none1, axImp, NOT_HLL | NO_SRC , iIN , 0 , }, /* ED */ - { none1, axImp, NOT_HLL | B|NO_SRC , iOUT , 0 , }, /* EE */ - { none1, axImp, NOT_HLL | NO_SRC , iOUT , 0 , }, /* EF */ - { none1, none2, NOT_HLL | NO_OPS , iLOCK , 0 , }, /* F0 */ - { none1, none2, 0 , iZERO , 0 , }, /* F1 */ - { prefix, none2, 0 , iREPNE, 0 , }, /* F2 */ - { prefix, none2, 0 , iREPE , 0 , }, /* F3 */ - { none1, none2, NOT_HLL | NO_OPS , iHLT , 0 , }, /* F4 */ + { dispS, none2, 0 , iLOOP , 0 , 0 }, /* E2 */ + { dispS, none2, 0 , iJCXZ , 0 , 0 }, /* E3 */ + { data1, axImp, NOT_HLL | B|NO_SRC , iIN , 0 , 0 }, /* E4 */ + { data1, axImp, NOT_HLL | NO_SRC , iIN , 0 , 0 }, /* E5 */ + { data1, axImp, NOT_HLL | B|NO_SRC , iOUT , 0 , 0 }, /* E6 */ + { data1, axImp, NOT_HLL | NO_SRC , iOUT , 0 , 0 }, /* E7 */ + { dispN, none2, 0 , iCALL , 0 , 0 }, /* E8 */ + { dispN, none2, 0 , iJMP , 0 , 0 }, /* E9 */ + { dispF, none2, 0 , iJMPF , 0 , 0 }, /* EA */ + { dispS, none2, 0 , iJMP , 0 , 0 }, /* EB */ + { none1, axImp, NOT_HLL | B|NO_SRC , iIN , 0 , 0 }, /* EC */ + { none1, axImp, NOT_HLL | NO_SRC , iIN , 0 , 0 }, /* ED */ + { none1, axImp, NOT_HLL | B|NO_SRC , iOUT , 0 , 0 }, /* EE */ + { none1, axImp, NOT_HLL | NO_SRC , iOUT , 0 , 0 }, /* EF */ + { none1, none2, NOT_HLL | NO_OPS , iLOCK , 0 , 0 }, /* F0 */ + { none1, none2, 0 , iZERO , 0 , 0 }, /* F1 */ + { prefix, none2, 0 , iREPNE, 0 , 0 }, /* F2 */ + { prefix, none2, 0 , iREPE , 0 , 0 }, /* F3 */ + { none1, none2, NOT_HLL | NO_OPS , iHLT , 0 , 0 }, /* F4 */ { none1, none2, NO_OPS , iCMC , Cf, Cf }, /* F5 */ - { arith, none1, B , iZERO , 0 , }, /* F6 */ - { arith, none1, NSP , iZERO , 0 , }, /* F7 */ - { none1, none2, NO_OPS , iCLC , Cf, }, /* F8 */ - { none1, none2, NO_OPS , iSTC , Cf, }, /* F9 */ - { none1, none2, NOT_HLL | NO_OPS , iCLI , 0 , }, /* FA */ - { none1, none2, NOT_HLL | NO_OPS , iSTI , 0 , }, /* FB */ - { none1, none2, NO_OPS , iCLD , Df, }, /* FC */ - { none1, none2, NO_OPS , iSTD , Df, }, /* FD */ - { trans, none1, B , iZERO , 0 , }, /* FE */ - { trans, none1, NSP , iZERO , 0 , } /* FF */ + { arith, none1, B , iZERO , 0 , 0 }, /* F6 */ + { arith, none1, NSP , iZERO , 0 , 0 }, /* F7 */ + { none1, none2, NO_OPS , iCLC , Cf, 0 }, /* F8 */ + { none1, none2, NO_OPS , iSTC , Cf, 0 }, /* F9 */ + { none1, none2, NOT_HLL | NO_OPS , iCLI , 0 , 0 }, /* FA */ + { none1, none2, NOT_HLL | NO_OPS , iSTI , 0 , 0 }, /* FB */ + { none1, none2, NO_OPS , iCLD , Df, 0 }, /* FC */ + { none1, none2, NO_OPS , iSTD , Df, 0 }, /* FD */ + { trans, none1, B , iZERO , 0 , 0 }, /* FE */ + { trans, none1, NSP , iZERO , 0 , 0 } /* FF */ } ; static word SegPrefix, RepPrefix; @@ -287,7 +318,7 @@ 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. ****************************************************************************/ -Int scan(dword ip, ICODE *p) +eErrorId scan(dword ip, ICODE *p) { Int op; @@ -321,7 +352,7 @@ Int scan(dword ip, ICODE *p) /* Save bytes of image used */ p->ic.ll.numBytes = (byte)((pInst - prog.Image) - ip); return ((SegPrefix)? FUNNY_SEGOVR: /* Seg. Override invalid */ - (RepPrefix ? FUNNY_REP: 0));/* REP prefix invalid */ + (RepPrefix ? FUNNY_REP: NO_ERR));/* REP prefix invalid */ } /* Else opcode error */ return ((stateTable[op].flg & OP386)? INVALID_386OP: INVALID_OPCODE); @@ -501,16 +532,14 @@ static void axImp(Int i) setAddress(i, TRUE, 0, rAX, 0); } - -static void axSrcIm (Int i) /* Implied AX source */ +static void axSrcIm (Int ) { pIcode->ic.ll.src.regi = rAX; } - -static void alImp (Int i) /* Implied AL source */ +static void alImp (Int ) { pIcode->ic.ll.src.regi = rAL; } @@ -528,7 +557,7 @@ static void memImp(Int i) /**************************************************************************** memOnly - Instruction is not valid if modrm refers to register (i.e. mod == 3) ***************************************************************************/ -static void memOnly(Int i) +static void memOnly(Int ) { if ((*pInst & 0xC0) == 0xC0) pIcode->ic.ll.opcode = (llIcode)0; @@ -665,7 +694,7 @@ static void data1(Int i) /***************************************************************************** data2 - Sets up immed from 2 byte data ****************************************************************************/ -static void data2(Int i) +static void data2(Int ) { if (relocItem(pInst)) pIcode->ic.ll.flg |= SEG_IMMED; @@ -699,10 +728,10 @@ static void dispM(Int i) /**************************************************************************** dispN - 2 byte disp as immed relative to ip ****************************************************************************/ -static void dispN(Int i) +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 */ @@ -714,7 +743,7 @@ static void dispN(Int i) /*************************************************************************** dispS - 1 byte disp as immed relative to ip ***************************************************************************/ -static void dispS(Int i) +static void dispS(Int ) { long off = signex(*pInst++); /* Signed displacement */ @@ -726,7 +755,7 @@ static void dispS(Int i) /**************************************************************************** dispF - 4 byte disp as immed 20-bit target address ***************************************************************************/ -static void dispF(Int i) +static void dispF(Int ) { dword off = (unsigned)getWord(); dword seg = (unsigned)getWord(); @@ -740,7 +769,7 @@ static void dispF(Int i) prefix - picks up prefix byte for following instruction (LOCK is ignored on purpose) ****************************************************************************/ -static void prefix(Int i) +static void prefix(Int ) { if (pIcode->ic.ll.opcode == iREPE || pIcode->ic.ll.opcode == iREPNE) RepPrefix = pIcode->ic.ll.opcode; @@ -756,7 +785,7 @@ inline void BumpOpcode(llIcode& ic) /***************************************************************************** strop - checks RepPrefix and converts string instructions accordingly *****************************************************************************/ -static void strop(Int i) +static void strop(Int ) { if (RepPrefix) { @@ -788,7 +817,7 @@ static void escop(Int i) /**************************************************************************** const1 ****************************************************************************/ -static void const1(Int i) +static void const1(Int ) { pIcode->ic.ll.immed.op = 1; pIcode->ic.ll.flg |= I; @@ -798,7 +827,7 @@ static void const1(Int i) /***************************************************************************** const3 ****************************************************************************/ -static void const3(Int i) +static void const3(Int ) { pIcode->ic.ll.immed.op = 3; pIcode->ic.ll.flg |= I; @@ -808,7 +837,7 @@ static void const3(Int i) /**************************************************************************** none1 ****************************************************************************/ -static void none1(Int i) +static void none1(Int ) { } @@ -816,7 +845,7 @@ static void none1(Int i) /**************************************************************************** none2 - Sets the NO_OPS flag if the operand is immediate ****************************************************************************/ -static void none2(Int i) +static void none2(Int ) { if (pIcode->ic.ll.flg & I) pIcode->ic.ll.flg |= NO_OPS; @@ -825,7 +854,7 @@ static void none2(Int i) /**************************************************************************** Checks for int 34 to int 3B - if so, converts to ESC nn instruction ****************************************************************************/ -static void checkInt(Int i) +static void checkInt(Int ) { word wOp = (word) pIcode->ic.ll.immed.op; if ((wOp >= 0x34) && (wOp <= 0x3B)) diff --git a/src/udm.cpp b/src/udm.cpp index 305af59..a34e57d 100644 --- a/src/udm.cpp +++ b/src/udm.cpp @@ -90,15 +90,10 @@ void udm(void) ***************************************************************************/ void Function::displayCFG() { - Int i; - BB * pBB; - printf("\nBasic Block List - Proc %s", name); - - for (auto iter = cfg.begin(); iter!=cfg.end(); ++iter) + for (BB *pBB : cfg) { - pBB = *iter; - (*iter)->display(); + pBB->display(); } }