From a51c5af87ff8a831a02db04e2605ce2a0884a61e Mon Sep 17 00:00:00 2001 From: Artur K Date: Thu, 23 Feb 2012 22:14:56 +0100 Subject: [PATCH] llvm+ --- CMakeLists.txt | 13 ++-- include/icode.h | 56 ++++++++--------- src/ast.cpp | 68 ++++++++++----------- src/comwrite.cpp | 8 +-- src/dataflow.cpp | 4 +- src/dcc.cpp | 17 +++--- src/disassem.cpp | 38 ++++++------ src/graph.cpp | 11 ++-- src/hlicode.cpp | 6 +- src/icode.cpp | 20 ------ src/idioms.cpp | 155 +++++++++++++++++++++++++---------------------- src/locident.cpp | 6 +- src/parser.cpp | 67 ++++++++++---------- src/proplong.cpp | 4 +- src/scanner.cpp | 27 ++++----- 15 files changed, 242 insertions(+), 258 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c81fb3..8e553ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,18 @@ PROJECT(dcc_original) cmake_minimum_required(VERSION 2.8) -ADD_DEFINITIONS(-D__UNIX__ -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS) +ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -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() - #-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}" ) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall --std=c++0x") + SET(CMAKE_CXX_FLAGS_DEBUG "-D_GLIBCXX_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}" ) endif() FIND_PACKAGE(LLVM) FIND_PACKAGE(Boost) -llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native) +llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native mc support) INCLUDE_DIRECTORIES( include ${Boost_INCLUDE_DIRS} @@ -64,11 +63,9 @@ 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/icode.h b/include/icode.h index efa269a..dfec0bc 100644 --- a/include/icode.h +++ b/include/icode.h @@ -4,6 +4,8 @@ ****************************************************************************/ #pragma once #include +#include +#include #include "Enums.h" //enum condId; struct LOCAL_ID; @@ -254,17 +256,6 @@ struct DU_ICODE #define MAX_USES 5 -/* LOW_LEVEL icode operand record */ -struct ICODEMEM -{ - byte seg; /* CS, DS, ES, SS */ - int16 segValue; /* Value of segment seg during analysis */ - byte segOver; /* CS, DS, ES, SS if segment override */ - byte regi; /* 0 < regs < INDEXBASE <= index modes */ - int16 off; /* memory address offset */ -} ; - - struct COND_EXPR; struct HLTYPE { @@ -281,22 +272,34 @@ struct HLTYPE } call; } oper; /* operand */ } ; +/* LOW_LEVEL icode operand record */ +struct LLOpcode : public llvm::MCOperand +{ + byte seg; /* CS, DS, ES, SS */ + int16 segValue; /* Value of segment seg during analysis */ + byte segOver; /* CS, DS, ES, SS if segment override */ + byte regi; /* 0 < regs < INDEXBASE <= index modes */ + int16 off; /* memory address offset */ + dword opz; /* idx of immed src op */ + //union {/* Source operand if (flg & I) */ + //dword opz; /* idx of immed src op */ + struct { /* Call & # actual arg bytes */ + Function *proc; /* pointer to target proc (for CALL(F))*/ + int cb; /* # actual arg bytes */ + } proc; + //} immed; + dword op() const {return opz;} + void SetImmediateOp(dword dw) {opz=dw;} -struct LLTYPE +}; +struct LLInst : public llvm::MCInst { llIcode opcode; /* llIcode instruction */ byte numBytes; /* Number of bytes this instr */ flags32 flg; /* icode flags */ dword label; /* offset in image (20-bit adr) */ - ICODEMEM dst; /* destination operand */ - ICODEMEM src; /* source operand */ - union { /* Source operand if (flg & I) */ - 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 */ - } proc; - } immed; + LLOpcode dst; /* destination operand */ + LLOpcode src; /* source operand */ DU flagDU; /* def/use of flags */ struct { /* Case table if op==JMP && !I */ Int numEntries; /* # entries in case table */ @@ -308,6 +311,7 @@ struct LLTYPE { return (opcode >= iJB) && (opcode < iJCXZ); } + bool anyFlagSet(uint32_t x) const { return (flg & x)!=0;} }; /* Icode definition: LOW_LEVEL and HIGH_LEVEL */ @@ -326,7 +330,7 @@ struct ICODE DU1 du1; /* du chain 1 */ Int codeIdx; /* Index into cCode.code */ struct IC { /* Different types of icodes */ - LLTYPE ll; + LLInst ll; HLTYPE hl; /* For HIGH_LEVEL icodes */ }; IC ic;/* intermediate code */ @@ -337,6 +341,8 @@ struct ICODE dword GetLlFlag() {return ic.ll.flg;} bool isLlFlag(dword flg) {return (ic.ll.flg&flg)!=0;} llIcode GetLlOpcode() const { return ic.ll.opcode; } + dword GetLlLabel() const { return ic.ll.label;} + void SetImmediateOp(dword dw) {ic.ll.src.SetImmediateOp(dw);} void writeIntComment(std::ostringstream &s); void setRegDU(byte regi, operDu du_in); @@ -356,19 +362,13 @@ public: }; // This is the icode array object. -// The bulk of this could well be done with a class library class CIcodeRec : public std::vector { public: CIcodeRec(); // Constructor - ~CIcodeRec(); // Destructor ICODE * addIcode(ICODE *pIcode); - // ICODE * GetNextIcode(ICODE * pCurIcode); void SetInBB(int start, int end, BB* pnewBB); - void SetImmediateOp(int ip, dword dw); - dword GetLlLabel(int ip); - llIcode GetLlOpcode(int ip); bool labelSrch(dword target, dword &pIndex); ICODE * GetIcode(int ip); }; diff --git a/src/ast.cpp b/src/ast.cpp index 179d20e..5046645 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -268,11 +268,11 @@ 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; + newExp->expr.ident.idNode.kte.kte = (pIcode->ic.ll.src.op() << 16) + + (pIcode+off)->ic.ll.src.op(); else /* LOW_FIRST */ newExp->expr.ident.idNode.kte.kte = - ((pIcode+off)->ic.ll.immed.op << 16)+ pIcode->ic.ll.immed.op; + ((pIcode+off)->ic.ll.src.op() << 16)+ pIcode->ic.ll.src.op(); newExp->expr.ident.idNode.kte.size = 4; } /* Save it as a long expression (reg, stack or glob) */ @@ -350,10 +350,10 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, Int i, Int idx; /* idx into pIcode->localId table */ - const ICODEMEM * pm = (sd == SRC) ? &pIcode.ic.ll.src : &pIcode.ic.ll.dst; + const LLOpcode &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)) || + if ( ((sd == DST) && pIcode.ic.ll.anyFlagSet(IM_DST)) or + ((sd == SRC) && pIcode.ic.ll.anyFlagSet(IM_SRC)) or (sd == LHS_OP)) /* for MUL lhs */ { /* implicit dx:ax */ idx = pProc->localId.newLongReg (TYPE_LONG_SIGN, rDX, rAX, i); @@ -362,52 +362,50 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, Int i, duIcode.setRegDU (rAX, du); } - else if ((sd == DST) && (pIcode.ic.ll.flg & IM_TMP_DST) == IM_TMP_DST) + else if ((sd == DST) && pIcode.ic.ll.anyFlagSet(IM_TMP_DST)) { /* implicit tmp */ newExp = COND_EXPR::idReg (rTMP, 0, &pProc->localId); duIcode.setRegDU(rTMP, (operDu)eUSE); } - else if ((sd == SRC) && ((pIcode.ic.ll.flg & I) == I)) /* constant */ - newExp = COND_EXPR::idKte (pIcode.ic.ll.immed.op, 2); - - else if (pm->regi == 0) /* global variable */ - newExp = COND_EXPR::idGlob(pm->segValue, pm->off); - - else if (pm->regi < INDEXBASE) /* register */ + else if ((sd == SRC) && pIcode.ic.ll.anyFlagSet(I)) /* constant */ + newExp = COND_EXPR::idKte (pIcode.ic.ll.src.op(), 2); + else if (pm.regi == 0) /* global variable */ + newExp = COND_EXPR::idGlob(pm.segValue, pm.off); + else if (pm.regi < INDEXBASE) /* register */ { - newExp = COND_EXPR::idReg (pm->regi, (sd == SRC) ? pIcode.ic.ll.flg : + newExp = COND_EXPR::idReg (pm.regi, (sd == SRC) ? pIcode.ic.ll.flg : pIcode.ic.ll.flg & NO_SRC_B, &pProc->localId); - duIcode.setRegDU( pm->regi, du); + duIcode.setRegDU( pm.regi, du); } - else if (pm->off) /* offset */ + else if (pm.off) /* offset */ { - if ((pm->seg == rSS) && (pm->regi == INDEXBASE + 6)) /* idx on bp */ + if ((pm.seg == rSS) && (pm.regi == INDEXBASE + 6)) /* idx on bp */ { - if (pm->off >= 0) /* argument */ - newExp = COND_EXPR::idParam (pm->off, &pProc->args); + if (pm.off >= 0) /* argument */ + newExp = COND_EXPR::idParam (pm.off, &pProc->args); else /* local variable */ - newExp = COND_EXPR::idLoc (pm->off, &pProc->localId); + newExp = COND_EXPR::idLoc (pm.off, &pProc->localId); } - else if ((pm->seg == rDS) && (pm->regi == INDEXBASE + 7)) /* bx */ + else if ((pm.seg == rDS) && (pm.regi == INDEXBASE + 7)) /* bx */ { - if (pm->off > 0) /* global variable */ - newExp = idCondExpIdxGlob (pm->segValue, pm->off, rBX,&pProc->localId); + if (pm.off > 0) /* global variable */ + newExp = idCondExpIdxGlob (pm.segValue, pm.off, rBX,&pProc->localId); else - newExp = COND_EXPR::idOther (pm->seg, pm->regi, pm->off); + newExp = COND_EXPR::idOther (pm.seg, pm.regi, pm.off); duIcode.setRegDU( rBX, eUSE); } else /* idx <> bp, bx */ - newExp = COND_EXPR::idOther (pm->seg, pm->regi, pm->off); + newExp = COND_EXPR::idOther (pm.seg, pm.regi, pm.off); /**** check long ops, indexed global var *****/ } else /* (pm->regi >= INDEXBASE && pm->off = 0) => indexed && no off */ { - if ((pm->seg == rDS) && (pm->regi > INDEXBASE + 3)) /* dereference */ + if ((pm.seg == rDS) && (pm.regi > INDEXBASE + 3)) /* dereference */ { - switch (pm->regi) { + switch (pm.regi) { case INDEXBASE + 4: newExp = COND_EXPR::idReg(rSI, 0, &pProc->localId); duIcode.setRegDU( rSI, du); break; @@ -426,7 +424,7 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, Int i, newExp = COND_EXPR::unary (DEREFERENCE, newExp); } else - newExp = COND_EXPR::idOther (pm->seg, pm->regi, 0); + newExp = COND_EXPR::idOther (pm.seg, pm.regi, 0); } return (newExp); @@ -436,19 +434,17 @@ COND_EXPR *COND_EXPR::id(const ICODE &pIcode, opLoc sd, Function * pProc, Int i, /* Returns the identifier type */ condId ICODE::idType(opLoc sd) { - ICODEMEM *pm; - - pm = (sd == SRC) ? &ic.ll.src : &ic.ll.dst; + LLOpcode &pm((sd == SRC) ? ic.ll.src : ic.ll.dst); if ((sd == SRC) && ((ic.ll.flg & I) == I)) return (CONSTANT); - else if (pm->regi == 0) + else if (pm.regi == 0) return (GLOB_VAR); - else if (pm->regi < INDEXBASE) + else if (pm.regi < INDEXBASE) return (REGISTER); - else if ((pm->seg == rSS) && (pm->regi == INDEXBASE)) + else if ((pm.seg == rSS) && (pm.regi == INDEXBASE)) { - if (pm->off >= 0) + if (pm.off >= 0) return (PARAM); else return (LOCAL_VAR); diff --git a/src/comwrite.cpp b/src/comwrite.cpp index 0b9eb30..e995be8 100644 --- a/src/comwrite.cpp +++ b/src/comwrite.cpp @@ -150,15 +150,15 @@ static const char *intOthers[] = { void ICODE::writeIntComment (std::ostringstream &s) { s<<"\t/* "; - if (ic.ll.immed.op == 0x21) + if (ic.ll.src.op() == 0x21) { s < 0x1F && ic.ll.immed.op < 0x2F) + else if (ic.ll.src.op() > 0x1F && ic.ll.src.op() < 0x2F) { - s < -#ifdef __UNIX__ -//#include -#else -#include -#include /* For unlink() */ -#endif - /* Global variables - extern to other modules */ char *progname; /* argv[0] - for error msgs */ @@ -28,15 +21,21 @@ CALL_GRAPH *callGraph; /* Call graph of the program */ static char *initargs(int argc, char *argv[]); static void displayTotalStats(); - +#include +#include /**************************************************************************** * main ***************************************************************************/ - +#include int main(int argc, char *argv[]) { +// llvm::MCOperand op=llvm::MCOperand::CreateImm(11); +// llvm::MCAsmInfo info; +// llvm::raw_os_ostream wrap(std::cerr); +// op.print(wrap,&info); +// wrap.flush(); /* Extract switches and filename */ strcpy(option.filename, initargs(argc, argv)); diff --git a/src/disassem.cpp b/src/disassem.cpp index 5e7dc5f..ace4318 100644 --- a/src/disassem.cpp +++ b/src/disassem.cpp @@ -129,8 +129,8 @@ static const char *szPtr[2] = { "word ptr ", "byte ptr " }; static void dis1Line (Int i, Int pass); void dis1LineOp(Int i, boolT fWin, char attr, word *len, Function * pProc); -static void formatRM(ostringstream &p, flags32 flg, ICODEMEM* pm); -static ostringstream &strDst(ostringstream &os, flags32 flg, ICODEMEM *pm); +static void formatRM(ostringstream &p, flags32 flg, LLOpcode *pm); +static ostringstream &strDst(ostringstream &os, flags32 flg, LLOpcode *pm); static ostringstream &strSrc(ostringstream &os, ICODE *pc, bool skip_comma=false); static char *strHex(dword d); static Int checkScanned(dword pcCur); @@ -215,10 +215,12 @@ void disassem(Int pass, Function * ppProc) JmpInst(pc[i].ic.ll.opcode)) { /* Replace the immediate operand with an icode index */ - if (pc.labelSrch(pc[i].ic.ll.immed.op,pc[i].ic.ll.immed.op)) + dword labTgt; + if (pc.labelSrch(pc[i].ic.ll.src.op(),labTgt)) { + pc[i].ic.ll.src.SetImmediateOp(labTgt); /* This icode is the target of a jump */ - pc[pc[i].ic.ll.immed.op].ic.ll.flg |= TARGET; + pc[labTgt].ic.ll.flg |= TARGET; pc[i].ic.ll.flg |= JMP_ICODE; /* So its not done twice */ } else @@ -362,7 +364,7 @@ static void dis1Line(Int i, Int pass) case iPUSH: if (pIcode->ic.ll.flg & I) { - oper_stream<ic.ll.immed.op); + oper_stream<ic.ll.src.op()); // strcpy(p + WID_PTR, strHex(pIcode->ic.ll.immed.op)); } else @@ -396,8 +398,8 @@ static void dis1Line(Int i, Int pass) /* Check if there is a symbol here */ selectTable(Label); - if ((pIcode->ic.ll.immed.op < (dword)numIcode) && /* Ensure in range */ - readVal(oper_stream, pc[pIcode->ic.ll.immed.op].ic.ll.label, 0)) + if ((pIcode->ic.ll.src.op() < (dword)numIcode) && /* Ensure in range */ + readVal(oper_stream, pc[pIcode->ic.ll.src.op()].ic.ll.label, 0)) { break; /* Symbolic label. Done */ } @@ -405,11 +407,11 @@ static void dis1Line(Int i, Int pass) if (pIcode->ic.ll.flg & NO_LABEL) { //strcpy(p + WID_PTR, strHex(pIcode->ic.ll.immed.op)); - oper_stream<ic.ll.immed.op); + oper_stream<ic.ll.src.op()); } else if (pIcode->ic.ll.flg & I) { - j = pIcode->ic.ll.immed.op; + j = pIcode->ic.ll.src.op(); if (! pl[j]) /* Forward jump */ { pl[j] = ++lab; @@ -438,7 +440,7 @@ static void dis1Line(Int i, Int pass) oper_stream<< "near"; else oper_stream<< " far"; - oper_stream<<" ptr "<<(pIcode->ic.ll.immed.proc.proc)->name; + oper_stream<<" ptr "<<(pIcode->ic.ll.src.proc.proc)->name; } else if (pIcode->ic.ll.opcode == iCALLF) { @@ -451,13 +453,13 @@ static void dis1Line(Int i, Int pass) case iENTER: oper_stream<ic.ll.dst.off)<<", "; - oper_stream<ic.ll.immed.op); + oper_stream<ic.ll.src.op()); break; case iRET: case iRETF: case iINT: if (pIcode->ic.ll.flg & I) { - oper_stream<ic.ll.immed.op); + oper_stream<ic.ll.src.op()); } break; @@ -502,11 +504,11 @@ static void dis1Line(Int i, Int pass) case iIN: oper_stream<<(pIcode->ic.ll.flg & B)?"al, ": "ax, "; - oper_stream<<(pIcode->ic.ll.flg & I)? strHex(pIcode->ic.ll.immed.op): "dx"; + oper_stream<<(pIcode->ic.ll.flg & I)? strHex(pIcode->ic.ll.src.op()): "dx"; break; case iOUT: - oper_stream<<(pIcode->ic.ll.flg & I)? strHex(pIcode->ic.ll.immed.op): "dx"; + oper_stream<<(pIcode->ic.ll.flg & I)? strHex(pIcode->ic.ll.src.op()): "dx"; oper_stream<<(pIcode->ic.ll.flg & B)?", al": ", ax"; break; @@ -597,7 +599,7 @@ static void dis1Line(Int i, Int pass) /**************************************************************************** * formatRM ***************************************************************************/ -static void formatRM(std::ostringstream &p, flags32 flg, ICODEMEM *pm) +static void formatRM(std::ostringstream &p, flags32 flg, LLOpcode *pm) { char seg[4]; @@ -644,7 +646,7 @@ static void formatRM(std::ostringstream &p, flags32 flg, ICODEMEM *pm) /***************************************************************************** * strDst ****************************************************************************/ -static ostringstream & strDst(ostringstream &os,flags32 flg, ICODEMEM *pm) +static ostringstream & strDst(ostringstream &os,flags32 flg, LLOpcode *pm) { /* Immediates to memory require size descriptor */ //os << setw(WID_PTR); @@ -664,7 +666,7 @@ static ostringstream &strSrc(ostringstream &os,ICODE *pc,bool skip_comma) if(false==skip_comma) os<<", "; if (pc->ic.ll.flg & I) - os<ic.ll.immed.op); + os<ic.ll.src.op()); else if (pc->ic.ll.flg & IM_SRC) /* level 2 */ os<<"dx:ax"; else @@ -699,7 +701,7 @@ void interactDis(Function * initProc, Int initIC) void flops(ICODE *pIcode,std::ostringstream &out) { char bf[30]; - byte op = (byte)pIcode->ic.ll.immed.op; + byte op = (byte)pIcode->ic.ll.src.op(); /* Note that op is set to the escape number, e.g. esc 0x38 is FILD */ diff --git a/src/graph.cpp b/src/graph.cpp index fcb3a81..0f189bd 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -70,7 +70,7 @@ CondJumps: pBB->edges.pop_back(); } else - pBB->edges[1].ip = pIcode->ic.ll.immed.op; + pBB->edges[1].ip = pIcode->ic.ll.src.op(); break; case iLOOP: case iLOOPE: case iLOOPNE: @@ -88,7 +88,7 @@ CondJumps: else if ((pIcode->ic.ll.flg & (I | NO_LABEL)) == I) { pBB = BB::Create(start, ip, ONE_BRANCH, 1, this); - pBB->edges[0].ip = pIcode->ic.ll.immed.op; + pBB->edges[0].ip = pIcode->ic.ll.src.op(); } else BB::Create(start, ip, NOWHERE_NODE, 0, this); @@ -97,7 +97,7 @@ CondJumps: case iCALLF: case iCALL: { - Function * p = pIcode->ic.ll.immed.proc.proc; + Function * p = pIcode->ic.ll.src.proc.proc; if (p) i = ((p->flg) & TERMINATES) ? 0 : 1; else @@ -217,7 +217,7 @@ void Function::compressCFG() if (not pBB->edges.empty()) /* Might have been clobbered */ { pBB->edges[i].BBptr = pNxt; - Icode.SetImmediateOp(ip, (dword)pNxt->begin()); + Icode[ip].SetImmediateOp((dword)pNxt->begin()); } } } @@ -289,7 +289,8 @@ BB *BB::rmJMP(Int marker, BB * pBB) { /* We are going around in circles */ pBB->nodeType = NOWHERE_NODE; - pBB->front().ic.ll.immed.op = pBB->front().loc_ip; + pBB->front().ic.ll.src.SetImmediateOp(pBB->front().loc_ip); + //pBB->front().ic.ll.src.immed.op = pBB->front().loc_ip; do { pBB = pBB->edges[0].BBptr; pBB->inEdges.pop_back(); // was --numInedges diff --git a/src/hlicode.cpp b/src/hlicode.cpp index 4ce29b0..ed9bc57 100644 --- a/src/hlicode.cpp +++ b/src/hlicode.cpp @@ -46,11 +46,11 @@ void ICODE::newCallHl() { type = HIGH_LEVEL; ic.hl.opcode = HLI_CALL; - ic.hl.oper.call.proc = ic.ll.immed.proc.proc; + ic.hl.oper.call.proc = ic.ll.src.proc.proc; ic.hl.oper.call.args = new STKFRAME; - if (ic.ll.immed.proc.cb != 0) - ic.hl.oper.call.args->cb = ic.ll.immed.proc.cb; + if (ic.ll.src.proc.cb != 0) + ic.hl.oper.call.args->cb = ic.ll.src.proc.cb; else if(ic.hl.oper.call.proc) ic.hl.oper.call.args->cb =ic.hl.oper.call.proc->cbParam; else diff --git a/src/icode.cpp b/src/icode.cpp index faba3fe..1dfd845 100644 --- a/src/icode.cpp +++ b/src/icode.cpp @@ -18,10 +18,6 @@ CIcodeRec::CIcodeRec() //reserve(512); } -CIcodeRec::~CIcodeRec() -{ -} - /* Copies the icode that is pointed to by pIcode to the icode array. * If there is need to allocate extra memory, it is done so, and * the alloc variable is adjusted. */ @@ -38,22 +34,6 @@ void CIcodeRec::SetInBB(int start, int end, BB *pnewBB) at(i).inBB = pnewBB; } -void CIcodeRec::SetImmediateOp(int ip, dword dw) -{ - at(ip).ic.ll.immed.op = dw; -} - -dword CIcodeRec::GetLlLabel(int ip) -{ - return at(ip).ic.ll.label; -} - -llIcode CIcodeRec::GetLlOpcode(int ip) -{ - return at(ip).ic.ll.opcode; -} - - /* labelSrchRepl - Searches the icodes for instruction with label = target, and replaces *pIndex with an icode index */ bool CIcodeRec::labelSrch(dword target, dword &pIndex) diff --git a/src/idioms.cpp b/src/idioms.cpp index da2c326..8f68fd7 100644 --- a/src/idioms.cpp +++ b/src/idioms.cpp @@ -323,7 +323,7 @@ static Int idiom3(iICODE pIcode, iICODE pEnd) ++pIcode; if ((pIcode < pEnd) && (pIcode->ic.ll.flg & I) && (pIcode->ic.ll.opcode == iADD) && (pIcode->ic.ll.dst.regi == rSP)) - return (pIcode->ic.ll.immed.op); + return (pIcode->ic.ll.src.op()); else if ((pIcode->ic.ll.opcode == iMOV) && (pIcode->ic.ll.dst.regi == rSP) && (pIcode->ic.ll.src.regi == rBP)) (pIcode-1)->ic.ll.flg |= REST_STK; @@ -404,7 +404,7 @@ static void idiom4 (iICODE pIcode, iICODE pEnd, Function * pProc) /* Check for RET(F) immed */ if (pIcode->ic.ll.flg & I) { - pProc->cbParam = (int16)pIcode->ic.ll.immed.op; + pProc->cbParam = (int16)pIcode->ic.ll.src.op(); pProc->flg |= CALL_PASCAL; } } @@ -457,7 +457,7 @@ static boolT idiom6 (iICODE pIcode, iICODE pEnd) ****************************************************************************/ static boolT idiom7 (iICODE pIcode) { - ICODEMEM *dst, *src; + LLOpcode *dst, *src; dst = &pIcode->ic.ll.dst; src = &pIcode->ic.ll.src; @@ -496,7 +496,8 @@ static boolT idiom7 (iICODE pIcode) * Found in Borland Turbo C code. ****************************************************************************/ static boolT idiom21 (iICODE picode, iICODE pend) -{ ICODEMEM *dst, *src; +{ + LLOpcode *dst, *src; dst = &picode->ic.ll.dst; src = &picode->ic.ll.src; @@ -526,14 +527,14 @@ static boolT idiom21 (iICODE picode, iICODE pend) ****************************************************************************/ static boolT idiom8 (iICODE pIcode, iICODE pEnd) { - if (pIcode < pEnd) - { - if (((pIcode->ic.ll.flg & I) == I) && (pIcode->ic.ll.immed.op == 1)) - if (((pIcode+1)->ic.ll.opcode == iRCR) && - (((pIcode+1)->ic.ll.flg & I) == I) && - ((pIcode+1)->ic.ll.immed.op == 1)) - return true; - } + iICODE next=pIcode+1; + if((pIcode>=pEnd) and (next>=pEnd)) + return false; + if (pIcode->ic.ll.anyFlagSet(I) && (pIcode->ic.ll.src.op() == 1)) + if ((next->ic.ll.opcode == iRCR) && + next->ic.ll.anyFlagSet(I) && + (next->ic.ll.src.op() == 1)) + return true; return false; } @@ -550,22 +551,22 @@ static boolT idiom8 (iICODE pIcode, iICODE pEnd) * Found in Borland Turbo C code to index an array (array multiplication) ****************************************************************************/ static Int idiom15 (iICODE picode, iICODE pend) -{ Int n = 1; +{ + Int n = 1; byte regi; if (picode < pend) { /* Match SHL reg, 1 */ - if ((picode->ic.ll.flg & I) && (picode->ic.ll.immed.op == 1)) + if ((picode->ic.ll.flg & I) && (picode->ic.ll.src.op() == 1)) { regi = picode->ic.ll.dst.regi; - while (1) + for(auto iter=picode+1;iter < pend;++iter) { - if (((picode+n) < pend) && - ((picode+n)->ic.ll.opcode == iSHL) && - ((picode+n)->ic.ll.flg & I) && - ((picode+n)->ic.ll.immed.op == 1) && - ((picode+n)->ic.ll.dst.regi == regi)) + if ((iter->ic.ll.opcode == iSHL) && + (iter->ic.ll.flg & I) && + (iter->ic.ll.src.op() == 1) && + (iter->ic.ll.dst.regi == regi)) n++; else break; @@ -590,12 +591,13 @@ static Int idiom15 (iICODE picode, iICODE pend) ****************************************************************************/ static boolT idiom12 (iICODE pIcode, iICODE pEnd) { + iICODE next=pIcode+1; if (pIcode < pEnd) { - if (((pIcode->ic.ll.flg & I) == I) && (pIcode->ic.ll.immed.op == 1)) - if (((pIcode+1)->ic.ll.opcode == iRCL) && - (((pIcode+1)->ic.ll.flg & I) == I) && - ((pIcode+1)->ic.ll.immed.op == 1)) + if (pIcode->ic.ll.anyFlagSet(I) && (pIcode->ic.ll.src.op() == 1)) + if ((next->ic.ll.opcode == iRCL) && + (next->ic.ll.anyFlagSet(I)) && + (next->ic.ll.src.op() == 1)) return true; } return false; @@ -613,12 +615,13 @@ static boolT idiom12 (iICODE pIcode, iICODE pEnd) ****************************************************************************/ static boolT idiom9 (iICODE pIcode, iICODE pEnd) { + iICODE next=pIcode+1; if (pIcode < pEnd) { - if (((pIcode->ic.ll.flg & I) == I) && (pIcode->ic.ll.immed.op == 1)) - if (((pIcode+1)->ic.ll.opcode == iRCR) && - (((pIcode+1)->ic.ll.flg & I) == I) && - ((pIcode+1)->ic.ll.immed.op == 1)) + if (((pIcode->ic.ll.flg & I) == I) && (pIcode->ic.ll.src.op() == 1)) + if ((next->ic.ll.opcode == iRCR) && + ((next->ic.ll.flg & I) == I) && + (next->ic.ll.src.op() == 1)) return true; } return false; @@ -678,22 +681,22 @@ static boolT idiom10old (iICODE pIcode, iICODE pEnd) ****************************************************************************/ static void idiom10 (iICODE pIcode, iICODE pEnd) { - if (pIcode < pEnd) - { - /* Check OR reg, reg */ - if (((pIcode->ic.ll.flg & I) != I) && - (pIcode->ic.ll.src. regi > 0) && - (pIcode->ic.ll.src.regi < INDEXBASE) && - (pIcode->ic.ll.src.regi == pIcode->ic.ll.dst.regi)) - if (((pIcode+1) < pEnd) && ((pIcode+1)->ic.ll.opcode == iJNE)) - { - pIcode->ic.ll.opcode = iCMP; - pIcode->ic.ll.flg |= I; - pIcode->ic.ll.immed.op = 0; - pIcode->du.def = 0; - pIcode->du1.numRegsDef = 0; - } - } + iICODE next=pIcode+1; + if((pIcode>=pEnd) or (next>=pEnd)) + return; + /* Check OR reg, reg */ + if (((pIcode->ic.ll.flg & I) != I) && + (pIcode->ic.ll.src.regi > 0) && + (pIcode->ic.ll.src.regi < INDEXBASE) && + (pIcode->ic.ll.src.regi == pIcode->ic.ll.dst.regi)) + if (next->ic.ll.opcode == iJNE) + { + pIcode->ic.ll.opcode = iCMP; + pIcode->ic.ll.flg |= I; + pIcode->ic.ll.src.SetImmediateOp(0); // todo check if proc should be zeroed too + pIcode->du.def = 0; + pIcode->du1.numRegsDef = 0; + } } @@ -707,23 +710,24 @@ static void idiom10 (iICODE pIcode, iICODE pEnd) * Found in Borland Turbo C, used for multiplication and division of * byte operands (ie. they need to be extended to words). ****************************************************************************/ -static byte idiom13 (iICODE picode, iICODE pend) -{ byte regi; +static byte idiom13 (iICODE pIcode, iICODE pEnd) +{ + byte regi; + iICODE next=pIcode+1; + if((pIcode>=pEnd) or (next>=pEnd)) + return 0; - if (picode < pend) + /* Check for regL */ + regi = pIcode->ic.ll.dst.regi; + if (((pIcode->ic.ll.flg & I) != I) && (regi >= rAL) && (regi <= rBH)) { - /* Check for regL */ - regi = picode->ic.ll.dst.regi; - if (((picode->ic.ll.flg & I) != I) && (regi >= rAL) && (regi <= rBH)) + /* Check for MOV regH, 0 */ + if ((next->ic.ll.opcode == iMOV) && + (next->ic.ll.flg & I) && + (next->ic.ll.src.op() == 0)) { - /* Check for MOV regH, 0 */ - if (((picode+1)->ic.ll.opcode == iMOV) && - ((picode+1)->ic.ll.flg & I) && - ((picode+1)->ic.ll.immed.op == 0)) - { - if ((picode+1)->ic.ll.dst.regi == (regi + 4)) - return (regi - rAL + rAX); - } + if (next->ic.ll.dst.regi == (regi + 4)) + return (regi - rAL + rAX); } } return (0); @@ -1175,13 +1179,12 @@ void Function::findIdioms() case iCALL: case iCALLF: /* Check for library functions that return a long register. * Propagate this result */ - if (pIcode->ic.ll.immed.proc.proc != 0) - if ((pIcode->ic.ll.immed.proc.proc->flg & PROC_ISLIB) && - (pIcode->ic.ll.immed.proc.proc->flg & PROC_IS_FUNC)) + if (pIcode->ic.ll.src.proc.proc != 0) + if ((pIcode->ic.ll.src.proc.proc->flg & PROC_ISLIB) && + (pIcode->ic.ll.src.proc.proc->flg & PROC_IS_FUNC)) { - if ((pIcode->ic.ll.immed.proc.proc->retVal.type==TYPE_LONG_SIGN) - || (pIcode->ic.ll.immed.proc.proc->retVal.type == - TYPE_LONG_UNSIGN)) + if ((pIcode->ic.ll.src.proc.proc->retVal.type==TYPE_LONG_SIGN) + || (pIcode->ic.ll.src.proc.proc->retVal.type == TYPE_LONG_UNSIGN)) localId.newLongReg(TYPE_LONG_SIGN, rDX, rAX, ip); } @@ -1190,9 +1193,9 @@ void Function::findIdioms() { if (pIcode->ic.ll.flg & I) { - (pIcode->ic.ll.immed.proc.proc)->cbParam = (int16)idx; - pIcode->ic.ll.immed.proc.cb = idx; - (pIcode->ic.ll.immed.proc.proc)->flg |= CALL_C; + (pIcode->ic.ll.src.proc.proc)->cbParam = (int16)idx; + pIcode->ic.ll.src.proc.cb = idx; + (pIcode->ic.ll.src.proc.proc)->flg |= CALL_C; pIcode++; (pIcode++)->invalidate(); ip++; @@ -1207,9 +1210,9 @@ void Function::findIdioms() { if (pIcode->isLlFlag(I)) { - (pIcode->ic.ll.immed.proc.proc)->cbParam = (int16)idx; - pIcode->ic.ll.immed.proc.cb = idx; - (pIcode->ic.ll.immed.proc.proc)->flg |= CALL_C; + (pIcode->ic.ll.src.proc.proc)->cbParam = (int16)idx; + pIcode->ic.ll.src.proc.cb = idx; + (pIcode->ic.ll.src.proc.proc)->flg |= CALL_C; ip += idx/2 - 1; pIcode++; for (idx /= 2; idx > 0; idx--) @@ -1376,7 +1379,7 @@ void Function::findIdioms() if (idiom21 (pIcode, pEnd)) { lhs = COND_EXPR::idLong (&localId, DST, pIcode,HIGH_FIRST, ip, eDEF, 1); - rhs = COND_EXPR::idKte ((pIcode+1)->ic.ll.immed.op , 4); + rhs = COND_EXPR::idKte ((pIcode+1)->ic.ll.src.op() , 4); pIcode->setAsgn(lhs, rhs); pIcode->du.use = 0; /* clear register used in iXOR */ (pIcode+1)->invalidate(); @@ -1430,7 +1433,7 @@ void Function::bindIcodeOff() for (i = 0; i < Icode.size(); 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.src.op(), j)) { pIcode[j].ic.ll.flg |= TARGET; } @@ -1445,8 +1448,14 @@ void Function::bindIcodeOff() { if (pIcode->ic.ll.flg & I) { - if (! Icode.labelSrch(pIcode->ic.ll.immed.op, pIcode->ic.ll.immed.op)) + dword found; + if (! Icode.labelSrch(pIcode->ic.ll.src.op(), found)) + { pIcode->ic.ll.flg |= NO_LABEL; + } + else + pIcode->ic.ll.src.SetImmediateOp(found); + } else if (pIcode->ic.ll.flg & SWITCH) { diff --git a/src/locident.cpp b/src/locident.cpp index d610b00..8815aab 100644 --- a/src/locident.cpp +++ b/src/locident.cpp @@ -252,7 +252,7 @@ Int LOCAL_ID::newLongStk(hlType t, Int offH, Int offL) Int LOCAL_ID::newLong(opLoc sd, ICODE *pIcode, hlFirst f, Int ix,operDu du, Int off) { Int idx; - ICODEMEM *pmH, *pmL; + LLOpcode *pmH, *pmL; if (f == LOW_FIRST) { @@ -308,7 +308,7 @@ Int LOCAL_ID::newLong(opLoc sd, ICODE *pIcode, hlFirst f, Int ix,operDu du, Int boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, Int i, Int idx, Function * pProc, COND_EXPR **rhs, COND_EXPR **lhs, Int off) { - ICODEMEM *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */ + LLOpcode *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */ pmHdst = &pIcode->ic.ll.dst; pmLdst = &(pIcode+off)->ic.ll.dst; @@ -346,7 +346,7 @@ boolT checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, Int i, Int idx, boolT checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, Int i, Int idx, Function * pProc, COND_EXPR *&rhs, COND_EXPR *&lhs, Int off) { - ICODEMEM *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */ + LLOpcode *pmHdst, *pmLdst, *pmHsrc, *pmLsrc; /* pointers to LOW_LEVEL icodes */ pmHdst = &pIcode->ic.ll.dst; pmLdst = &(pIcode+off)->ic.ll.dst; diff --git a/src/parser.cpp b/src/parser.cpp index e868ec7..99ab69d 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -21,7 +21,7 @@ static void process_operands(ICODE * pIcode, Function * pProc, STATE * pstat static void setBits(int16 type, dword start, dword len); static SYM * updateGlobSym(dword operand, Int size, word duFlag); static void process_MOV(ICODE * pIcode, STATE * pstate); -static SYM * lookupAddr (ICODEMEM *pm, STATE * pstate, Int size, word duFlag); +static SYM * lookupAddr (LLOpcode *pm, STATE * pstate, Int size, word duFlag); void interactDis(Function * initProc, Int ic); static dword SynthLab; @@ -156,7 +156,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) _Icode.type = LOW_LEVEL; _Icode.ic.ll.opcode = iJMP; _Icode.ic.ll.flg = I | SYNTHETIC | NO_OPS; - _Icode.ic.ll.immed.op = Icode.GetLlLabel(lab); + _Icode.ic.ll.src.SetImmediateOp(Icode[lab].GetLlLabel()); _Icode.ic.ll.label = SynthLab++; } @@ -184,10 +184,10 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) eIcode.ic.ll.flg |= SYNTHETIC; /* eIcode.ic.ll.label = SynthLab++; */ eIcode.ic.ll.label = _Icode.ic.ll.label; - pIcode = Icode.addIcode(&eIcode); + Icode.addIcode(&eIcode); /* iDIV, iIDIV */ - pIcode = Icode.addIcode(&_Icode); + Icode.addIcode(&_Icode); /* iMOD */ memset (&eIcode, 0, sizeof (ICODE)); @@ -212,13 +212,13 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) eIcode.ic.ll.flg |= SYNTHETIC; /* eIcode.ic.ll.label = SynthLab++; */ eIcode.ic.ll.label = _Icode.ic.ll.label; - pIcode = Icode.addIcode(&eIcode); + Icode.addIcode(&eIcode); /* MOV regDst, regSrc */ _Icode.ic.ll.opcode = iMOV; _Icode.ic.ll.flg |= SYNTHETIC; /* Icode.ic.ll.label = SynthLab++; */ - pIcode = Icode.addIcode(&_Icode); + Icode.addIcode(&_Icode); _Icode.ic.ll.opcode = iXCHG; /* for next case */ /* MOV regSrc, rTMP */ @@ -256,7 +256,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) */ if (ip > 0 && prev.ic.ll.opcode == iCMP && (prev.ic.ll.flg & I)) { - pstate->JCond.immed = (int16)prev.ic.ll.immed.op; + pstate->JCond.immed = (int16)prev.ic.ll.src.op(); if (_Icode.ic.ll.opcode == iJA || _Icode.ic.ll.opcode == iJBE) pstate->JCond.immed++; if (_Icode.ic.ll.opcode == iJAE || _Icode.ic.ll.opcode == iJA) @@ -264,8 +264,8 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) fBranch = (boolT) (_Icode.ic.ll.opcode == iJB || _Icode.ic.ll.opcode == iJBE); } - - memcpy(&StCopy, pstate, sizeof(STATE)); + StCopy = *pstate; + //memcpy(&StCopy, pstate, sizeof(STATE)); /* Straight line code */ this->FollowCtrl (pcallGraph, &StCopy); // recurrent ? @@ -302,7 +302,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) break; case iINT: - if (_Icode.ic.ll.immed.op == 0x21 && pstate->f[rAH]) + if (_Icode.ic.ll.src.op() == 0x21 && pstate->f[rAH]) { Int funcNum = pstate->r[rAH]; Int operand; @@ -328,13 +328,13 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) updateSymType (operand, TYPE_STR, size); } } - else if ((_Icode.ic.ll.immed.op == 0x2F) && (pstate->f[rAH])) + else if ((_Icode.ic.ll.src.op() == 0x2F) && (pstate->f[rAH])) { Icode.back().ic.ll.dst.off = pstate->r[rAH]; } else /* Program termination: int20h, int27h */ - done = (boolT)(_Icode.ic.ll.immed.op == 0x20 || - _Icode.ic.ll.immed.op == 0x27); + done = (boolT)(_Icode.ic.ll.src.op() == 0x20 || + _Icode.ic.ll.src.op() == 0x27); if (done) pIcode->ic.ll.flg |= TERMINATES; break; @@ -350,7 +350,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) case iSHL: if (pstate->JCond.regi == _Icode.ic.ll.dst.regi) - if ((_Icode.ic.ll.flg & I) && _Icode.ic.ll.immed.op == 1) + if ((_Icode.ic.ll.flg & I) && _Icode.ic.ll.src.op() == 1) pstate->JCond.immed *= 2; else pstate->JCond.regi = 0; @@ -403,7 +403,7 @@ boolT Function::process_JMP (ICODE * pIcode, STATE *pstate, CALL_GRAPH * pcallGr { if (pIcode->ic.ll.opcode == iJMPF) pstate->setState( rCS, LH(prog.Image + pIcode->ic.ll.label + 3)); - i = pstate->IP = pIcode->ic.ll.immed.op; + i = pstate->IP = pIcode->ic.ll.src.op(); if ((long)i < 0) { exit(1); @@ -491,7 +491,7 @@ boolT Function::process_JMP (ICODE * pIcode, STATE *pstate, CALL_GRAPH * pcallGr Icode.GetIcode(ip)->ic.ll.caseTbl.numEntries = k++; Icode.GetIcode(ip)->ic.ll.flg |= CASE; - *psw++ = Icode.GetLlLabel(ip); + *psw++ = Icode[ip].GetLlLabel(); } return TRUE; } @@ -550,11 +550,12 @@ boolT Function::process_CALL (ICODE * pIcode, CALL_GRAPH * pcallGraph, STATE *ps /* Address of function is given by 4 (CALLF) or 2 (CALL) bytes at * previous offset into the program image */ + dword tgtAddr=0; if (pIcode->ic.ll.opcode == iCALLF) - pIcode->ic.ll.immed.op = LH(&prog.Image[off]) + - ((dword)(LH(&prog.Image[off+2])) << 4); + tgtAddr= LH(&prog.Image[off]) + (dword)(LH(&prog.Image[off+2])) << 4; else - pIcode->ic.ll.immed.op = LH(&prog.Image[off]) + ((dword)(word)state.r[rCS] << 4); + tgtAddr= LH(&prog.Image[off]) + (dword)(word)state.r[rCS] << 4; + pIcode->ic.ll.src.SetImmediateOp( tgtAddr ); pIcode->ic.ll.flg |= I; indirect = TRUE; } @@ -565,7 +566,7 @@ boolT Function::process_CALL (ICODE * pIcode, CALL_GRAPH * pcallGraph, STATE *ps /* Search procedure list for one with appropriate entry point */ ilFunction iter= std::find_if(pProcList.begin(),pProcList.end(), [pIcode](const Function &f) -> - bool { return f.procEntry==pIcode->ic.ll.immed.op; }); + bool { return f.procEntry==pIcode->ic.ll.src.op(); }); /* Create a new procedure node and save copy of the state */ if (iter==pProcList.end()) @@ -573,7 +574,7 @@ boolT Function::process_CALL (ICODE * pIcode, CALL_GRAPH * pcallGraph, STATE *ps pProcList.push_back(Function::Create()); Function &x(pProcList.back()); iter = (++pProcList.rbegin()).base(); - x.procEntry = pIcode->ic.ll.immed.op; + x.procEntry = pIcode->ic.ll.src.op(); LibCheck(x); if (x.flg & PROC_ISLIB) @@ -581,7 +582,7 @@ boolT Function::process_CALL (ICODE * pIcode, CALL_GRAPH * pcallGraph, STATE *ps /* A library function. No need to do any more to it */ pcallGraph->insertCallGraph (this, iter); iter = (++pProcList.rbegin()).base(); - Icode.GetIcode(ip)->ic.ll.immed.proc.proc = &x; + Icode.GetIcode(ip)->ic.ll.src.proc.proc = &x; return false; } @@ -597,7 +598,7 @@ boolT Function::process_CALL (ICODE * pIcode, CALL_GRAPH * pcallGraph, STATE *ps /* Save machine state in localState, load up IP and CS.*/ localState = *pstate; - pstate->IP = pIcode->ic.ll.immed.op; + pstate->IP = pIcode->ic.ll.src.op(); if (pIcode->ic.ll.opcode == iCALLF) pstate->setState( rCS, LH(prog.Image + pIcode->ic.ll.label + 3)); x.state = *pstate; @@ -619,7 +620,7 @@ boolT Function::process_CALL (ICODE * pIcode, CALL_GRAPH * pcallGraph, STATE *ps else pcallGraph->insertCallGraph (this, iter); - Icode[ip].ic.ll.immed.proc.proc = &(*iter); // ^ target proc + Icode[ip].ic.ll.src.proc.proc = &(*iter); // ^ target proc /* return ((p->flg & TERMINATES) != 0); */ return FALSE; @@ -638,7 +639,7 @@ static void process_MOV(ICODE * pIcode, STATE * pstate) if (dstReg > 0 && dstReg < INDEXBASE) { if (pIcode->ic.ll.flg & I) - pstate->setState( dstReg, (int16)pIcode->ic.ll.immed.op); + pstate->setState( dstReg, (int16)pIcode->ic.ll.src.op()); else if (srcReg == 0) /* direct memory offset */ { psym = lookupAddr(&pIcode->ic.ll.src, pstate, 2, eDuVal::USE); @@ -658,8 +659,8 @@ static void process_MOV(ICODE * pIcode, STATE * pstate) psym = lookupAddr (&pIcode->ic.ll.dst, pstate, 2, eDEF); if (psym && ! (psym->duVal.val)) /* no initial value yet */ if (pIcode->ic.ll.flg & I) { /* immediate */ - prog.Image[psym->label] = (byte)pIcode->ic.ll.immed.op; - prog.Image[psym->label+1] = (byte)(pIcode->ic.ll.immed.op>>8); + prog.Image[psym->label] = (byte)pIcode->ic.ll.src.op(); + prog.Image[psym->label+1] = (byte)(pIcode->ic.ll.src.op()>>8); psym->duVal.val = 1; } else if (srcReg == 0) { /* direct mem offset */ @@ -776,7 +777,7 @@ static void updateFrameOff (STKFRAME * ps, int16 off, Int size, word duFlag) * if necessary. * Returns a pointer to the symbol in the * symbol table, or Null if it's not a direct memory offset. */ -static SYM * lookupAddr (ICODEMEM *pm, STATE *pstate, Int size, word duFlag) +static SYM * lookupAddr (LLOpcode *pm, STATE *pstate, Int size, word duFlag) { Int i; SYM * psym; @@ -911,7 +912,7 @@ dword duReg[] = { 0x00, * ix : current index into icode array */ static void use (opLoc d, ICODE * pIcode, Function * pProc, STATE * pstate, Int size, Int ix) { - ICODEMEM * pm = (d == SRC)? &pIcode->ic.ll.src: &pIcode->ic.ll.dst; + LLOpcode * pm = (d == SRC)? &pIcode->ic.ll.src: &pIcode->ic.ll.dst; SYM * psym; if (pm->regi == 0 || pm->regi >= INDEXBASE) @@ -952,13 +953,13 @@ static void use (opLoc d, ICODE * pIcode, Function * pProc, STATE * pstate, Int } -static void def (opLoc d, ICODE * pIcode, Function * pProc, STATE * pstate, Int size, - Int ix) /* Checks which registers were defined (ie. got a new value) and updates the * du.d flag. * Places local variables in the local symbol table. */ +static void def (opLoc d, ICODE * pIcode, Function * pProc, STATE * pstate, Int size, + Int ix) { - ICODEMEM *pm = (d == SRC)? &pIcode->ic.ll.src: &pIcode->ic.ll.dst; + LLOpcode *pm = (d == SRC)? &pIcode->ic.ll.src: &pIcode->ic.ll.dst; SYM * psym; if (pm->regi == 0 || pm->regi >= INDEXBASE) @@ -1010,7 +1011,7 @@ static void def (opLoc d, ICODE * pIcode, Function * pProc, STATE * pstate, Int static void use_def(opLoc d, ICODE * pIcode, Function * pProc, STATE * pstate, Int cb, Int ix) { - ICODEMEM * pm = (d == SRC)? &pIcode->ic.ll.src: &pIcode->ic.ll.dst; + LLOpcode * pm = (d == SRC)? &pIcode->ic.ll.src: &pIcode->ic.ll.dst; use (d, pIcode, pProc, pstate, cb, ix); diff --git a/src/proplong.cpp b/src/proplong.cpp index bfd058f..b78a884 100644 --- a/src/proplong.cpp +++ b/src/proplong.cpp @@ -302,7 +302,7 @@ void checkBack(); int Function::checkBackwarLongDefs(int loc_ident_idx, ID *pLocId, int pLocId_idx,Assignment &asgn) { int idx; - ICODEMEM * pmH,* pmL; + LLOpcode * pmH,* pmL; iICODE pIcode; for (idx = pLocId_idx - 1; idx > 0 ; idx--) { @@ -397,7 +397,7 @@ void Function::propLongReg (Int loc_ident_idx, ID *pLocId) for (idx = pLocId_idx + 1; idx < Icode.size() - 1; idx++) { iICODE pIcode; - ICODEMEM * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */ + LLOpcode * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */ int off,arc; pIcode = Icode.begin()+(idx); if ((pIcode->type == HIGH_LEVEL) || (pIcode->invalid == TRUE)) diff --git a/src/scanner.cpp b/src/scanner.cpp index f6af201..a44c4e5 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -403,7 +403,7 @@ static Int signex(byte b) ***************************************************************************/ static void setAddress(Int i, boolT fdst, word seg, int16 reg, word off) { - ICODEMEM *pm; + LLOpcode *pm; /* If not to register (i.e. to r/m), and talking about r/m, then this is dest */ @@ -631,7 +631,7 @@ static void trans(Int i) pIcode->ic.ll.opcode = transTable[REG(*pInst)]; /* valid on bytes */ pIcode->ic.ll.flagDU.d = df[REG(*pInst)]; rm(i); - memcpy(&pIcode->ic.ll.src, &pIcode->ic.ll.dst, sizeof(ICODEMEM)); + pIcode->ic.ll.src = pIcode->ic.ll.dst; if (pIcode->ic.ll.opcode == iJMP || pIcode->ic.ll.opcode == iCALL || pIcode->ic.ll.opcode == iCALLF) pIcode->ic.ll.flg |= NO_OPS; else if (pIcode->ic.ll.opcode == iINC || pIcode->ic.ll.opcode == iPUSH || pIcode->ic.ll.opcode == iDEC) @@ -666,7 +666,7 @@ static void arith(Int i) } else if (!(opcode == iNOT || opcode == iNEG)) { - memcpy(&pIcode->ic.ll.src, &pIcode->ic.ll.dst, sizeof(ICODEMEM)); + pIcode->ic.ll.src = pIcode->ic.ll.dst; setAddress(i, TRUE, 0, rAX, 0); /* dst = AX */ } else if (opcode == iNEG || opcode == iNOT) @@ -685,8 +685,7 @@ static void arith(Int i) *****************************************************************************/ static void data1(Int i) { - pIcode->ic.ll.immed.op = (stateTable[i].flg & S_EXT)? signex(*pInst++): - *pInst++; + pIcode->ic.ll.src.SetImmediateOp( (stateTable[i].flg & S_EXT)? signex(*pInst++): *pInst++ ); pIcode->ic.ll.flg |= I; } @@ -710,7 +709,7 @@ static void data2(Int ) pIcode->ic.ll.flg |= NO_OPS; } else - pIcode->ic.ll.immed.op = getWord(); + pIcode->ic.ll.src.SetImmediateOp(getWord()); pIcode->ic.ll.flg |= I; } @@ -735,7 +734,7 @@ static void dispN(Int ) /* Note: the result of the subtraction could be between 32k and 64k, and still be positive; it is an offset from prog.Image. So this must be treated as unsigned */ - pIcode->ic.ll.immed.op = (dword)(off + (unsigned)(pInst - prog.Image)); + pIcode->ic.ll.src.SetImmediateOp((dword)(off + (unsigned)(pInst - prog.Image))); pIcode->ic.ll.flg |= I; } @@ -747,7 +746,7 @@ static void dispS(Int ) { long off = signex(*pInst++); /* Signed displacement */ - pIcode->ic.ll.immed.op = (dword)(off + (unsigned)(pInst - prog.Image)); + pIcode->ic.ll.src.SetImmediateOp((dword)(off + (unsigned)(pInst - prog.Image))); pIcode->ic.ll.flg |= I; } @@ -760,7 +759,7 @@ static void dispF(Int ) dword off = (unsigned)getWord(); dword seg = (unsigned)getWord(); - pIcode->ic.ll.immed.op = off + ((dword)(unsigned)seg << 4); + pIcode->ic.ll.src.SetImmediateOp(off + ((dword)(unsigned)seg << 4)); pIcode->ic.ll.flg |= I; } @@ -808,7 +807,7 @@ static void strop(Int ) ***************************************************************************/ static void escop(Int i) { - pIcode->ic.ll.immed.op = REG(*pInst) + (dword)((i & 7) << 3); + pIcode->ic.ll.src.SetImmediateOp(REG(*pInst) + (dword)((i & 7) << 3)); pIcode->ic.ll.flg |= I; rm(i); } @@ -819,7 +818,7 @@ static void escop(Int i) ****************************************************************************/ static void const1(Int ) { - pIcode->ic.ll.immed.op = 1; + pIcode->ic.ll.src.SetImmediateOp(1); pIcode->ic.ll.flg |= I; } @@ -829,7 +828,7 @@ static void const1(Int ) ****************************************************************************/ static void const3(Int ) { - pIcode->ic.ll.immed.op = 3; + pIcode->ic.ll.src.SetImmediateOp(3); pIcode->ic.ll.flg |= I; } @@ -856,12 +855,12 @@ static void none2(Int ) ****************************************************************************/ static void checkInt(Int ) { - word wOp = (word) pIcode->ic.ll.immed.op; + word wOp = (word) pIcode->ic.ll.src.op(); if ((wOp >= 0x34) && (wOp <= 0x3B)) { /* This is a Borland/Microsoft floating point emulation instruction. Treat as if it is an ESC opcode */ - pIcode->ic.ll.immed.op = wOp - 0x34; + pIcode->ic.ll.src.SetImmediateOp(wOp - 0x34); pIcode->ic.ll.opcode = iESC; pIcode->ic.ll.flg |= FLOAT_OP;