Merge branch 'qt5' into experimental_command_streams

This commit is contained in:
nemerle 2016-05-19 15:57:52 +02:00
commit 5f68987001
21 changed files with 58 additions and 93 deletions

View File

@ -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)

View File

@ -3,8 +3,6 @@
#include <vector>
#include <bitset>
#include <string>
#include <llvm/ADT/ilist.h>
#include <llvm/ADT/ilist_node.h>
#include <boost/range/iterator_range.hpp>
#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<BB>
struct BB
{
friend struct Function;
private:

View File

@ -1,6 +1,9 @@
#pragma once
#include "ast.h"
#ifdef PASCAL
#undef PASCAL
#endif
class QTextStream;
struct CConv {

View File

@ -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
};

View File

@ -6,7 +6,6 @@
#include "StackFrame.h"
#include "CallConvention.h"
#include <llvm/ADT/ilist.h>
#include <memory>
#include <stdint.h>
#include <QtCore/QString>
@ -26,29 +25,6 @@ struct PROG;
struct IStructuredTextTarget;
struct Function;
namespace llvm
{
// Traits for intrusive list of basic blocks...
template<>
struct ilist_traits<BB> : public ilist_default_traits<BB>
{
// createSentinel is used to get hold of the node that marks the end of the
// list... (same trick used here as in ilist_traits<Instruction>)
BB *createSentinel() const {
return static_cast<BB*>(&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<BB> Sentinel;
};
}
/* Procedure FLAGS */
enum PROC_FLAGS
{
@ -155,7 +131,7 @@ enum DecompilationStep : uint32_t {
class Function : public std::enable_shared_from_this<Function>
{
typedef llvm::iplist<BB> BasicBlockListType;
typedef std::list<BB *> 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<PtrFunction> FunctionListType;
typedef FunctionListType lFunction;
typedef lFunction::iterator ilFunction;

View File

@ -5,7 +5,6 @@
#pragma once
//TODO: Remove boolT
#include <llvm/ADT/ilist.h>
#include <utility>
#include <algorithm>
#include <bitset>

View File

@ -3,7 +3,6 @@
#include <QtCore/QObject>
#include <QtCore/QDir>
#include <llvm/ADT/ilist.h>
class IStructuredTextTarget;

View File

@ -10,10 +10,6 @@
#include "state.h" // State depends on INDEXBASE, but later need STATE
#include "CallConvention.h"
#include <llvm/ADT/ilist.h>
#include <llvm/ADT/ilist_node.h>
#include <llvm/MC/MCInst.h>
#include <llvm/IR/Instruction.h>
#include <boost/range/iterator_range.hpp>
#include <QtCore/QString>
@ -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<LLInst>
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<uint32_t> 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<HIGH_LEVEL> select_high_level;
static TypeAndValidFilter<HIGH_LEVEL> select_valid_high_level;
static TypeFilter<HIGH_LEVEL_ICODE> select_high_level;
static TypeAndValidFilter<HIGH_LEVEL_ICODE> 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<llvm::Instruction> InstListType;
typedef boost::iterator_range<iICODE> rSourceRange;
typedef boost::iterator_range<InstListType::iterator> rTargetRange;
rSourceRange m_low_level;
rTargetRange m_middle_level;
};
//struct MappingLLtoML
//{
// typedef boost::iterator_range<iICODE> rSourceRange;
// typedef boost::iterator_range<InstListType::iterator> rTargetRange;
// rSourceRange m_low_level;
// rTargetRange m_middle_level;
//};
// This is the icode array object.
class CIcodeRec : public std::list<ICODE>
{

View File

@ -6,7 +6,6 @@
#include "state.h"
#include "src/Command.h"
#include <llvm/ADT/ilist.h>
#include <boost/icl/interval.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/icl/split_interval_map.hpp>

View File

@ -10,7 +10,7 @@
#include <string>
#include <boost/range/rbegin.hpp>
#include <boost/range/rend.hpp>
#include <boost/range/adaptors.hpp>
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())

View File

@ -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);

View File

@ -10,8 +10,8 @@
#include <sstream>
#include <iostream>
#include <cassert>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/assign.hpp>

View File

@ -14,7 +14,7 @@
#include <QtCore/QTextStream>
#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/assign.hpp>
#include <stdint.h>

View File

@ -17,7 +17,7 @@
#include <cassert>
#include <string>
#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/algorithm.hpp>
#include <fstream>

View File

@ -10,7 +10,8 @@
#include "msvc_fixes.h"
#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/assign.hpp>
#include <stdint.h>
@ -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<HIGH_LEVEL>());
auto valid_and_highlevel = instructions | filtered(ICODE::TypeAndValidFilter<HIGH_LEVEL_ICODE>());
for (auto picode = valid_and_highlevel.begin(); picode != valid_and_highlevel.end(); picode++)
{
ICODE &_ic(*picode);

View File

@ -11,7 +11,6 @@
#include <boost/range/rbegin.hpp>
#include <boost/range/rend.hpp>
#include <boost/range/adaptors.hpp>
#include <string.h>
using namespace std;

View File

@ -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;

View File

@ -9,8 +9,8 @@
#include <stdlib.h>
ICODE::TypeFilter<HIGH_LEVEL> ICODE::select_high_level;
ICODE::TypeAndValidFilter<HIGH_LEVEL> ICODE::select_valid_high_level;
ICODE::TypeFilter<HIGH_LEVEL_ICODE> ICODE::select_high_level;
ICODE::TypeAndValidFilter<HIGH_LEVEL_ICODE> ICODE::select_valid_high_level;
CIcodeRec::CIcodeRec()
{
}

View File

@ -52,7 +52,7 @@ static std::vector<ICODE> 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<ICODE> 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<ICODE> 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<ICODE> 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++;

View File

@ -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())

View File

@ -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)
{