diff --git a/CMakeLists.txt b/CMakeLists.txt index 49a8838..345ded9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.1) #SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D__UNIX__ -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS) -IF(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)") +IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D__UNIX__ -D_CRT_NONSTDC_NO_DEPRECATE -DNOMINMAX) ADD_DEFINITIONS(/W4) ELSE() @@ -11,7 +11,7 @@ ELSE() SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} " ) #--coverage ENDIF() - +SET(CMAKE_CXX_STANDARD 11) SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeScripts;${CMAKE_MODULE_PATH}) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) @@ -30,17 +30,12 @@ enable_testing() ENDIF() - -find_package(LLVM REQUIRED CONFIG) -llvm_map_components_to_libnames(REQ_LLVM_LIBRARIES native mc support tablegen) - INCLUDE_DIRECTORIES( 3rd_party/libdisasm include include/idioms common ${Boost_INCLUDE_DIRS} - ${LLVM_INCLUDE_DIRS} ) @@ -125,6 +120,7 @@ set(dcc_HEADERS include/bundle.h include/BinaryImage.h include/DccFrontend.h + include/Enums.h include/dcc.h include/disassem.h include/dosdcc.h @@ -165,8 +161,10 @@ qt5_use_modules(dcc_lib Core) ADD_EXECUTABLE(dcc_original ${dcc_SOURCES} ${dcc_UI_SOURCES}) ADD_DEPENDENCIES(dcc_original dcc_lib) -TARGET_LINK_LIBRARIES(dcc_original dcc_lib dcc_hash disasm_s ${REQ_LLVM_LIBRARIES} LLVMSupport) +TARGET_LINK_LIBRARIES(dcc_original dcc_lib dcc_hash disasm_s) qt5_use_modules(dcc_original Core Widgets) +SET_PROPERTY(TARGET dcc_original PROPERTY CXX_STANDARD 11) +SET_PROPERTY(TARGET dcc_original PROPERTY CXX_STANDARD_REQUIRED ON) #ADD_SUBDIRECTORY(gui) if(dcc_build_tests) ADD_SUBDIRECTORY(src) diff --git a/include/BasicBlock.h b/include/BasicBlock.h index 8fc02ff..6609ccb 100644 --- a/include/BasicBlock.h +++ b/include/BasicBlock.h @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include #include "icode.h" #include "types.h" @@ -27,7 +25,7 @@ struct TYPEADR_TYPE TYPEADR_TYPE(interval *v) : ip(0),BBptr(nullptr),intPtr(v) {} }; -struct BB : public llvm::ilist_node +struct BB { friend struct Function; private: diff --git a/include/CallConvention.h b/include/CallConvention.h index 71a828f..cd728b7 100644 --- a/include/CallConvention.h +++ b/include/CallConvention.h @@ -1,6 +1,9 @@ #pragma once #include "ast.h" +#ifdef PASCAL +#undef PASCAL +#endif class QTextStream; struct CConv { diff --git a/include/Enums.h b/include/Enums.h index 28c0e7c..4a749c6 100644 --- a/include/Enums.h +++ b/include/Enums.h @@ -90,9 +90,9 @@ enum eLLFlags /* Types of icodes */ enum icodeType { - NOT_SCANNED = 0, // not even scanned yet - LOW_LEVEL, // low-level icode - HIGH_LEVEL // high-level icode + NOT_SCANNED_ICODE = 0, // not even scanned yet + LOW_LEVEL_ICODE, // low-level icode + HIGH_LEVEL_ICODE // high-level icode }; diff --git a/include/Procedure.h b/include/Procedure.h index 503ef51..0328736 100644 --- a/include/Procedure.h +++ b/include/Procedure.h @@ -6,7 +6,6 @@ #include "StackFrame.h" #include "CallConvention.h" -#include #include #include #include @@ -26,29 +25,6 @@ struct PROG; struct IStructuredTextTarget; struct Function; -namespace llvm -{ -// Traits for intrusive list of basic blocks... -template<> -struct ilist_traits : public ilist_default_traits -{ - - // createSentinel is used to get hold of the node that marks the end of the - // list... (same trick used here as in ilist_traits) - BB *createSentinel() const { - return static_cast(&Sentinel); - } - static void destroySentinel(BB*) {} - - BB *provideInitialHead() const { return createSentinel(); } - BB *ensureHead(BB*) const { return createSentinel(); } - static void noteHead(BB*, BB*) {} - - //static ValueSymbolTable *getSymTab(Function *ItemParent); -private: - mutable ilist_half_node Sentinel; -}; -} /* Procedure FLAGS */ enum PROC_FLAGS { @@ -155,7 +131,7 @@ enum DecompilationStep : uint32_t { class Function : public std::enable_shared_from_this { - typedef llvm::iplist BasicBlockListType; + typedef std::list BasicBlockListType; // BasicBlock iterators... typedef BasicBlockListType::iterator iterator; typedef BasicBlockListType::const_iterator const_iterator; @@ -284,7 +260,6 @@ protected: bool nextOrderGraph(derSeq &derivedGi); void addOutEdgesForConditionalJump(BB *pBB, int next_ip, LLInst *ll); }; - typedef std::list FunctionListType; typedef FunctionListType lFunction; typedef lFunction::iterator ilFunction; diff --git a/include/dcc.h b/include/dcc.h index 5c1f6f1..b05c52a 100644 --- a/include/dcc.h +++ b/include/dcc.h @@ -5,7 +5,6 @@ #pragma once //TODO: Remove boolT -#include #include #include #include diff --git a/include/dcc_interface.h b/include/dcc_interface.h index b2448d1..11af805 100644 --- a/include/dcc_interface.h +++ b/include/dcc_interface.h @@ -3,7 +3,6 @@ #include #include -#include class IStructuredTextTarget; diff --git a/include/icode.h b/include/icode.h index b9302bd..62178d4 100644 --- a/include/icode.h +++ b/include/icode.h @@ -10,10 +10,6 @@ #include "state.h" // State depends on INDEXBASE, but later need STATE #include "CallConvention.h" -#include -#include -#include -#include #include #include @@ -63,12 +59,7 @@ public: } friend void swap(LivenessSet& first, LivenessSet& second) // nothrow { - // enable ADL (not necessary in our case, but good practice) - using std::swap; - - // by swapping the members of two classes, - // the two classes are effectively swapped - swap(first.registers, second.registers); + std::swap(first.registers, second.registers); } LivenessSet &operator|=(const LivenessSet &other) { @@ -319,9 +310,10 @@ struct LLOperand bool compound() const {return is_compound;} // dx:ax pair size_t byteWidth() const { assert(width<=4); return width;} }; -struct LLInst : public llvm::MCInst //: public llvm::ilist_node +struct LLInst { protected: + uint32_t m_opcode; // Low level opcode identifier uint32_t flg; /* icode flags */ LLOperand m_src; /* source operand */ public: @@ -333,6 +325,9 @@ public: int caseEntry; std::vector caseTbl2; int hllLabNum; /* label # for hll codegen */ + + uint32_t getOpcode() const { return m_opcode;} + void setOpcode(uint32_t op) { m_opcode=op; } bool conditionalJump() { return (getOpcode() >= iJB) and (getOpcode() < iJCXZ); @@ -469,8 +464,8 @@ public: bool operator()(ICODE *ic) {return (ic->type==TYPE) and (ic->valid());} bool operator()(ICODE &ic) {return (ic.type==TYPE) and ic.valid();} }; - static TypeFilter select_high_level; - static TypeAndValidFilter select_valid_high_level; + static TypeFilter select_high_level; + static TypeAndValidFilter select_valid_high_level; /* Def/Use of registers and stack variables */ struct DU_ICODE { @@ -572,7 +567,7 @@ public: // set this icode to be an assign void setAsgn(Expr *lhs, Expr *rhs) { - type=HIGH_LEVEL; + type=HIGH_LEVEL_ICODE; hlU()->setAsgn(lhs,rhs); } void setUnary(hlIcode op, Expr *_exp); @@ -589,7 +584,7 @@ public: { return hlU()->call.newStkArg(exp,opcode,pproc); } - ICODE() :Parent(0),invalid(false),type(NOT_SCANNED),loc_ip(0) + ICODE() :Parent(0),invalid(false),type(NOT_SCANNED_ICODE),loc_ip(0) { m_ll = new LLInst(this); } @@ -638,14 +633,13 @@ public: }; /** Map n low level instructions to m high level instructions */ -struct MappingLLtoML -{ - typedef llvm::iplist InstListType; - typedef boost::iterator_range rSourceRange; - typedef boost::iterator_range rTargetRange; - rSourceRange m_low_level; - rTargetRange m_middle_level; -}; +//struct MappingLLtoML +//{ +// typedef boost::iterator_range rSourceRange; +// typedef boost::iterator_range rTargetRange; +// rSourceRange m_low_level; +// rTargetRange m_middle_level; +//}; // This is the icode array object. class CIcodeRec : public std::list { diff --git a/include/project.h b/include/project.h index cdff231..a58194c 100644 --- a/include/project.h +++ b/include/project.h @@ -6,7 +6,6 @@ #include "state.h" #include "src/Command.h" -#include #include #include #include diff --git a/src/BasicBlock.cpp b/src/BasicBlock.cpp index 25183e6..7246b6b 100644 --- a/src/BasicBlock.cpp +++ b/src/BasicBlock.cpp @@ -10,7 +10,7 @@ #include #include #include -#include + using namespace std; using namespace boost; @@ -391,7 +391,7 @@ void BB::writeBB(QTextStream &ostr,int lev, Function * pProc, int *numLoc) for(ICODE &pHli : instructions) { - if ((pHli.type == HIGH_LEVEL) and ( pHli.valid() )) //TODO: use filtering range here. + if ((pHli.type == HIGH_LEVEL_ICODE) and ( pHli.valid() )) //TODO: use filtering range here. { QString line = pHli.hl()->write1HlIcode(pProc, numLoc); if (not line.isEmpty()) diff --git a/src/DccFrontend.cpp b/src/DccFrontend.cpp index a7cae0e..1ca6c45 100644 --- a/src/DccFrontend.cpp +++ b/src/DccFrontend.cpp @@ -33,7 +33,7 @@ void PROG::displayLoadInfo(void) // printf("Minimum allocation = %04X paras\n", LH(&header.minAlloc)); // printf("Maximum allocation = %04X paras\n", LH(&header.maxAlloc)); // } - printf("Load image size = %04" PRIiPTR "\n", cbImage); + printf("Load image size = %08lX\n", cbImage); // - sizeof(PSP) printf("Initial SS:SP = %04X:%04X\n", initSS, initSP); printf("Initial CS:IP = %04X:%04X\n", initCS, initIP); diff --git a/src/RegisterNode.cpp b/src/RegisterNode.cpp index 3a36a18..d34eccc 100644 --- a/src/RegisterNode.cpp +++ b/src/RegisterNode.cpp @@ -10,8 +10,8 @@ #include #include #include +#include #include -#include //#include //#include diff --git a/src/ast.cpp b/src/ast.cpp index ef4d0b0..7c7a8a3 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/backend.cpp b/src/backend.cpp index 079dbc1..9870e83 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/dataflow.cpp b/src/dataflow.cpp index 0f6470a..7ea09ec 100644 --- a/src/dataflow.cpp +++ b/src/dataflow.cpp @@ -10,7 +10,8 @@ #include "msvc_fixes.h" #include -#include +#include +#include #include #include #include @@ -148,7 +149,7 @@ void Function::elimCondCodes () { llIcode useAtOp = llIcode(useAt->ll()->getOpcode()); use = useAt->ll()->flagDU.u; - if ((useAt->type != LOW_LEVEL) or ( not useAt->valid() ) or ( 0 == use )) + if ((useAt->type != LOW_LEVEL_ICODE) or ( not useAt->valid() ) or ( 0 == use )) continue; /* Find definition within the same basic block */ defAt=useAt; @@ -271,7 +272,7 @@ void Function::genLiveKtes () continue; // skip invalid BBs for(ICODE &insn : *pbb) { - if ((insn.type == HIGH_LEVEL) and ( insn.valid() )) + if ((insn.type == HIGH_LEVEL_ICODE) and ( insn.valid() )) { liveUse |= (insn.du.use - def); def |= insn.du.def; @@ -884,7 +885,7 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc) numHlIcodes = 0; assert(&fnc->localId==&locals); // register(s) to be forward substituted - auto valid_and_highlevel = instructions | filtered(ICODE::TypeAndValidFilter()); + auto valid_and_highlevel = instructions | filtered(ICODE::TypeAndValidFilter()); for (auto picode = valid_and_highlevel.begin(); picode != valid_and_highlevel.end(); picode++) { ICODE &_ic(*picode); diff --git a/src/graph.cpp b/src/graph.cpp index 3cb7153..ecb649c 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -11,7 +11,6 @@ #include #include -#include #include using namespace std; diff --git a/src/hlicode.cpp b/src/hlicode.cpp index 591bdba..3e75748 100644 --- a/src/hlicode.cpp +++ b/src/hlicode.cpp @@ -29,7 +29,7 @@ void ICODE::checkHlCall() /* Places the new HLI_CALL high-level operand in the high-level icode array */ void ICODE::newCallHl() { - type = HIGH_LEVEL; + type = HIGH_LEVEL_ICODE; hlU()->setCall(ll()->src().proc.proc); if (ll()->src().proc.cb != 0) @@ -48,7 +48,7 @@ void ICODE::newCallHl() * array */ void ICODE::setUnary(hlIcode op, Expr *_exp) { - type = HIGH_LEVEL; + type = HIGH_LEVEL_ICODE; hlU()->set(op,_exp); } @@ -56,7 +56,7 @@ void ICODE::setUnary(hlIcode op, Expr *_exp) /* Places the new HLI_JCOND high-level operand in the high-level icode array */ void ICODE::setJCond(Expr *cexp) { - type = HIGH_LEVEL; + type = HIGH_LEVEL_ICODE; hlU()->set(HLI_JCOND,cexp); } @@ -320,7 +320,7 @@ void Function::highLevelGen() LLOperand *src_ll = ll->get(SRC); if ( ll->testFlags(NOT_HLL) ) pIcode->invalidate(); - if ((pIcode->type != LOW_LEVEL) or not pIcode->valid() ) + if ((pIcode->type != LOW_LEVEL_ICODE) or not pIcode->valid() ) continue; _flg = ll->getFlag(); if (not ll->testFlags(IM_OPS)) /* not processing IM_OPS yet */ @@ -353,7 +353,7 @@ void Function::highLevelGen() case iCALL: case iCALLF: - pIcode->type = HIGH_LEVEL; + pIcode->type = HIGH_LEVEL_ICODE; pIcode->hl( ll->createCall() ); break; diff --git a/src/icode.cpp b/src/icode.cpp index 8632104..fa23510 100644 --- a/src/icode.cpp +++ b/src/icode.cpp @@ -9,8 +9,8 @@ #include -ICODE::TypeFilter ICODE::select_high_level; -ICODE::TypeAndValidFilter ICODE::select_valid_high_level; +ICODE::TypeFilter ICODE::select_high_level; +ICODE::TypeAndValidFilter ICODE::select_valid_high_level; CIcodeRec::CIcodeRec() { } diff --git a/src/parser.cpp b/src/parser.cpp index eb3fc2c..23a6260 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -52,7 +52,7 @@ static std::vector rewrite_DIV(LLInst *ll, ICODE &_Icode) ICODE synth_mov = ICODE(); // MOV rTMP, reg ICODE synth_mod = ICODE(); // MOD - synth_mov.type = LOW_LEVEL; + synth_mov.type = LOW_LEVEL_ICODE; synth_mov.ll()->set(iMOV,0,rTMP); if (ll->testFlags(B) ) { @@ -71,7 +71,7 @@ static std::vector rewrite_DIV(LLInst *ll, ICODE &_Icode) synth_mov.ll()->label = _Icode.ll()->label; /* iMOD */ - synth_mod.type = LOW_LEVEL; + synth_mod.type = LOW_LEVEL_ICODE; synth_mod.ll()->set(iMOD,ll->getFlag() | SYNTHETIC | IM_TMP_DST); synth_mod.ll()->replaceSrc(_Icode.ll()->src()); synth_mod.du = _Icode.du; @@ -86,7 +86,7 @@ static std::vector rewrite_XCHG(LLInst *ll,ICODE &_Icode) { /* MOV rTMP, regDst */ ICODE mov_tmp_dst; - mov_tmp_dst.type = LOW_LEVEL; + mov_tmp_dst.type = LOW_LEVEL_ICODE; mov_tmp_dst.ll()->set(iMOV,SYNTHETIC,rTMP,ll->m_dst); mov_tmp_dst.setRegDU( rTMP, eDEF); if(mov_tmp_dst.ll()->src().getReg2()) @@ -104,7 +104,7 @@ static std::vector rewrite_XCHG(LLInst *ll,ICODE &_Icode) /* MOV regSrc, rTMP */ ICODE mov_src_tmp; - mov_src_tmp.type = LOW_LEVEL; + mov_src_tmp.type = LOW_LEVEL_ICODE; mov_src_tmp.ll()->set(iMOV,SYNTHETIC); mov_src_tmp.ll()->replaceDst(ll->src()); if(mov_src_tmp.ll()->m_dst.regi) @@ -218,7 +218,7 @@ void FollowCtrl(Function &func,CALL_GRAPH * pcallGraph, STATE *pstate) iICODE labLoc = func.Icode.labelSrch(ll->label); if (func.Icode.end()!=labLoc) { /* Synthetic jump */ - _Icode.type = LOW_LEVEL; + _Icode.type = LOW_LEVEL_ICODE; ll->set(iJMP,I | SYNTHETIC | NO_OPS); ll->replaceSrc(LLOperand::CreateImm2(labLoc->ll()->GetLlLabel())); ll->label = Project::get()->SynthLab++; diff --git a/src/proplong.cpp b/src/proplong.cpp index 026e37b..779f1ad 100644 --- a/src/proplong.cpp +++ b/src/proplong.cpp @@ -248,7 +248,7 @@ void Function::propLongStk (int i, const ID &pLocId) next1 = ++iICODE(pIcode); if(next1==pEnd) break; - if ((pIcode->type == HIGH_LEVEL) or ( not pIcode->valid() )) + if ((pIcode->type == HIGH_LEVEL_ICODE) or ( not pIcode->valid() )) continue; if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode()) { @@ -323,7 +323,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be ICODE &icode(*pIcode); - if ((icode.type == HIGH_LEVEL) or ( not icode.valid() )) + if ((icode.type == HIGH_LEVEL_ICODE) or ( not icode.valid() )) continue; if (icode.ll()->getOpcode() != next1->ll()->getOpcode()) continue; @@ -401,7 +401,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be LLOperand * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */ int arc; - if ((pIcode->type == HIGH_LEVEL) or ( not pIcode->valid() )) + if ((pIcode->type == HIGH_LEVEL_ICODE) or ( not pIcode->valid() )) continue; if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode()) diff --git a/src/scanner.cpp b/src/scanner.cpp index c17d167..4a83b61 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -537,7 +537,7 @@ eErrorId scan(uint32_t ip, ICODE &p) PROG &prog(Project::get()->prog); int op; p = ICODE(); - p.type = LOW_LEVEL; + p.type = LOW_LEVEL_ICODE; p.ll()->label = ip; /* ip is absolute offset into image*/ if (ip >= (uint32_t)prog.cbImage) {