diff --git a/common/perfhlib.cpp b/common/perfhlib.cpp index 332ba1a..9b7da05 100644 --- a/common/perfhlib.cpp +++ b/common/perfhlib.cpp @@ -333,7 +333,7 @@ void PerfectHash::traverse(int u) while (e) { w = graphNode[NumEntry+e]-1; - if (!visited[w]) + if (not visited[w]) { g[w] = (abs(e)-1 - g[u]) % NumEntry; if (g[w] < 0) g[w] += NumEntry; /* Keep these positive */ @@ -357,7 +357,7 @@ void PerfectHash::assign(void) for (v=0; v < NumVert; v++) { - if (!visited[v]) + if (not visited[v]) { g[v] = 0; traverse(v); diff --git a/include/BasicBlock.h b/include/BasicBlock.h index 6896faa..8fc02ff 100644 --- a/include/BasicBlock.h +++ b/include/BasicBlock.h @@ -111,7 +111,7 @@ public: /// const Function *getParent() const { return Parent; } Function *getParent() { return Parent; } - void writeBB(std::ostream &ostr, int lev, Function *pProc, int *numLoc); + void writeBB(QTextStream & ostr, int lev, Function *pProc, int *numLoc); BB * rmJMP(int marker, BB *pBB); void genDU1(); void findBBExps(LOCAL_ID &locals, Function *f); diff --git a/include/CallConvention.h b/include/CallConvention.h index b46b2c3..4c41633 100644 --- a/include/CallConvention.h +++ b/include/CallConvention.h @@ -1,6 +1,8 @@ #pragma once #include "ast.h" +class QTextStream; + struct CConv { enum Type { UNKNOWN=0, @@ -8,7 +10,7 @@ struct CConv { PASCAL }; virtual void processHLI(Function *func, Expr *_exp, iICODE picode)=0; - virtual void writeComments(std::ostream &)=0; + virtual void writeComments(QTextStream &)=0; static CConv * create(Type v); protected: @@ -16,16 +18,16 @@ protected: struct C_CallingConvention : public CConv { virtual void processHLI(Function *func, Expr *_exp, iICODE picode); - virtual void writeComments(std::ostream &); + virtual void writeComments(QTextStream &); private: int processCArg(Function *callee, Function *pProc, ICODE *picode, size_t numArgs); }; struct Pascal_CallingConvention : public CConv { virtual void processHLI(Function *func, Expr *_exp, iICODE picode); - virtual void writeComments(std::ostream &); + virtual void writeComments(QTextStream &); }; struct Unknown_CallingConvention : public CConv { void processHLI(Function *func, Expr *_exp, iICODE picode) {} - virtual void writeComments(std::ostream &); + virtual void writeComments(QTextStream &); }; diff --git a/include/Procedure.h b/include/Procedure.h index f5330f7..af7396a 100644 --- a/include/Procedure.h +++ b/include/Procedure.h @@ -1,14 +1,20 @@ #pragma once -#include -//#include -#include -#include #include "BasicBlock.h" #include "locident.h" #include "state.h" #include "icode.h" #include "StackFrame.h" #include "CallConvention.h" + +#include +//#include +#include +#include +#include + +class QIODevice; +class QTextStream; + /* PROCEDURE NODE */ struct CALL_GRAPH; struct Expr; @@ -126,8 +132,8 @@ public: FunctionType * type; CConv * m_call_conv; uint32_t procEntry; /* label number */ - std::string name; /* Meaningful name for this proc */ - STATE state; /* Entry state */ + QString name; /* Meaningful name for this proc */ + STATE state; /* Entry state */ int depth; /* Depth at which we found it - for printing */ uint32_t flg; /* Combination of Icode & Proc flags */ int16_t cbParam; /* Probable no. of bytes of parameters */ @@ -153,7 +159,7 @@ public: delete type; } public: - static Function *Create(FunctionType *ty=0,int /*Linkage*/=0,const std::string &nm="",void */*module*/=0) + static Function *Create(FunctionType *ty=0,int /*Linkage*/=0,const QString &nm="",void */*module*/=0) { Function *r=new Function(ty); r->name = nm; @@ -185,14 +191,14 @@ public: bool process_JMP(ICODE &pIcode, STATE *pstate, CALL_GRAPH *pcallGraph); bool process_CALL(ICODE &pIcode, CALL_GRAPH *pcallGraph, STATE *pstate); void freeCFG(); - void codeGen(std::ostream &fs); + void codeGen(QIODevice & fs); void mergeFallThrough(BB *pBB); void structIfs(); void structLoops(derSeq *derivedG); void buildCFG(Disassembler &ds); void controlFlowAnalysis(); void newRegArg(iICODE picode, iICODE ticode); - void writeProcComments(std::ostream &ostr); + void writeProcComments(QTextStream & ostr); void displayCFG(); void displayStats(); @@ -200,7 +206,7 @@ public: void preprocessReturnDU(LivenessSet &_liveOut); Expr * adjustActArgType(Expr *_exp, hlType forType); - std::string writeCall(Function *tproc, STKFRAME &args, int *numLoc); + QString writeCall(Function *tproc, STKFRAME &args, int *numLoc); void processDosInt(STATE *pstate, PROG &prog, bool done); ICODE *translate_DIV(LLInst *ll, ICODE &_Icode); ICODE *translate_XCHG(LLInst *ll, ICODE &_Icode); diff --git a/include/ast.h b/include/ast.h index f97a515..e9a912d 100644 --- a/include/ast.h +++ b/include/ast.h @@ -58,7 +58,7 @@ public: /** Recursively deallocates the abstract syntax tree rooted at *exp */ virtual ~Expr() {} public: - virtual std::string walkCondExpr (Function * pProc, int* numLoc) const=0; + virtual QString walkCondExpr (Function * pProc, int* numLoc) const=0; virtual Expr *inverse() const=0; // return new COND_EXPR that is invarse of this virtual bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId)=0; virtual Expr *insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym)=0; @@ -100,10 +100,12 @@ struct UnaryOperator : public Expr } public: int hlTypeSize(Function *pproc) const; - virtual std::string walkCondExpr(Function *pProc, int *numLoc) const; + virtual QString walkCondExpr(Function *pProc, int *numLoc) const; virtual Expr *insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym); virtual hlType expType(Function *pproc) const; virtual Expr *insertSubTreeLongReg(Expr *_expr, int longIdx); +private: + QString wrapUnary(Function *pProc, int *numLoc, QChar op) const; }; struct BinaryOperator : public Expr @@ -188,7 +190,7 @@ struct BinaryOperator : public Expr condOp op() const { return m_op;} /* Changes the boolean conditional operator at the root of this expression */ void op(condOp o) { m_op=o;} - std::string walkCondExpr (Function * pProc, int* numLoc) const; + QString walkCondExpr(Function * pProc, int* numLoc) const; public: hlType expType(Function *pproc) const; int hlTypeSize(Function *pproc) const; @@ -215,7 +217,7 @@ struct AstIdent : public UnaryOperator virtual int hlTypeSize(Function *pproc) const; virtual hlType expType(Function *pproc) const; virtual Expr * performLongRemoval(eReg regi, LOCAL_ID *locId); - virtual std::string walkCondExpr(Function *pProc, int *numLoc) const; + virtual QString walkCondExpr(Function *pProc, int *numLoc) const; virtual Expr *insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym); virtual Expr *insertSubTreeLongReg(Expr *_expr, int longIdx); virtual bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId); @@ -232,7 +234,7 @@ struct GlobalVariable : public AstIdent return new GlobalVariable(*this); } GlobalVariable(int16_t segValue, int16_t off); - std::string walkCondExpr(Function *pProc, int *numLoc) const; + QString walkCondExpr(Function *pProc, int *numLoc) const; int hlTypeSize(Function *pproc) const; hlType expType(Function *pproc) const; }; @@ -246,7 +248,7 @@ struct GlobalVariableIdx : public AstIdent return new GlobalVariableIdx(*this); } GlobalVariableIdx(int16_t segValue, int16_t off, uint8_t regi, const LOCAL_ID *locSym); - std::string walkCondExpr(Function *pProc, int *numLoc) const; + QString walkCondExpr(Function *pProc, int *numLoc) const; int hlTypeSize(Function *pproc) const; hlType expType(Function *pproc) const; }; @@ -268,7 +270,7 @@ struct Constant : public AstIdent { return new Constant(*this); } - std::string walkCondExpr(Function *pProc, int *numLoc) const; + QString walkCondExpr(Function *pProc, int *numLoc) const; int hlTypeSize(Function *pproc) const; hlType expType(Function *pproc) const; }; @@ -288,7 +290,7 @@ struct FuncNode : public AstIdent { return new FuncNode(*this); } - std::string walkCondExpr(Function *pProc, int *numLoc) const; + QString walkCondExpr(Function *pProc, int *numLoc) const; int hlTypeSize(Function *pproc) const; hlType expType(Function *pproc) const; }; @@ -314,7 +316,7 @@ struct RegisterNode : public AstIdent { return new RegisterNode(*this); } - std::string walkCondExpr(Function *pProc, int *numLoc) const; + QString walkCondExpr(Function *pProc, int *numLoc) const; int hlTypeSize(Function *) const; hlType expType(Function *pproc) const; bool xClear(rICODE range_to_check, iICODE lastBBinst, const LOCAL_ID &locId); diff --git a/include/bundle.h b/include/bundle.h index 4c866db..fd5d234 100644 --- a/include/bundle.h +++ b/include/bundle.h @@ -7,8 +7,10 @@ #pragma once #include #include -#include -struct strTable : std::vector +#include +#include + +struct strTable : std::vector { /* Returns the next available index into the table */ size_t nextIdx() {return size();} @@ -20,9 +22,9 @@ struct bundle { public: void appendCode(const char *format, ...); - void appendCode(const std::string &s); + void appendCode(const QString &s); void appendDecl(const char *format, ...); - void appendDecl(const std::string &); + void appendDecl(const QString &); void init() { decl.clear(); @@ -37,6 +39,6 @@ extern bundle cCode; #define lineSize 360 /* 3 lines in the mean time */ //void newBundle (bundle *procCode); -void writeBundle (std::ostream &ios, bundle procCode); +void writeBundle (QIODevice & ios, bundle procCode); void freeBundle (bundle *procCode); diff --git a/include/dcc.h b/include/dcc.h index 3fc0f25..18e2481 100644 --- a/include/dcc.h +++ b/include/dcc.h @@ -93,8 +93,8 @@ bool LibCheck(Function &p); /* chklib.c */ /* Exported functions from hlicode.c */ -const char *writeJcond(const HLTYPE &, Function *, int *); -const char *writeJcondInv (HLTYPE, Function *, int *); +QString writeJcond(const HLTYPE &, Function *, int *); +QString writeJcondInv(HLTYPE, Function *, int *); /* Exported funcions from locident.c */ diff --git a/include/disassem.h b/include/disassem.h index f1ac699..37fe06c 100644 --- a/include/disassem.h +++ b/include/disassem.h @@ -5,9 +5,12 @@ *************************************************************************** */ #pragma once +#include "bundle.h" + #include #include -#include "bundle.h" +#include +#include struct LLInst; struct Function; struct Disassembler @@ -16,7 +19,8 @@ protected: int pass; int g_lab; //bundle &cCode; - std::ofstream m_fp; + QIODevice *m_disassembly_target; + QTextStream m_fp; std::vector m_decls; std::vector m_code; diff --git a/include/icode.h b/include/icode.h index 808d2a4..964f75f 100644 --- a/include/icode.h +++ b/include/icode.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -145,8 +146,8 @@ struct UnaryOperator; struct HlTypeSupport { //hlIcode opcode; /* hlIcode opcode */ - virtual bool removeRegFromLong(eReg regi, LOCAL_ID *locId)=0; - virtual std::string writeOut(Function *pProc, int *numLoc) const=0; + virtual bool removeRegFromLong(eReg regi, LOCAL_ID *locId)=0; + virtual QString writeOut(Function *pProc, int *numLoc) const=0; protected: Expr * performLongRemoval (eReg regi, LOCAL_ID *locId, Expr *tree); }; @@ -166,7 +167,7 @@ public: printf("CallType : removeRegFromLong not supproted"); return false; } - std::string writeOut(Function *pProc, int *numLoc) const; + QString writeOut(Function *pProc, int *numLoc) const; }; struct AssignType : public HlTypeSupport { @@ -179,7 +180,7 @@ public: Expr *lhs() const {return m_lhs;} void lhs(Expr *l); bool removeRegFromLong(eReg regi, LOCAL_ID *locId); - std::string writeOut(Function *pProc, int *numLoc) const; + QString writeOut(Function *pProc, int *numLoc) const; }; struct ExpType : public HlTypeSupport { @@ -191,7 +192,7 @@ struct ExpType : public HlTypeSupport v=performLongRemoval(regi,locId,v); return true; } - std::string writeOut(Function *pProc, int *numLoc) const; + QString writeOut(Function *pProc, int *numLoc) const; }; struct HLTYPE @@ -245,7 +246,7 @@ public: return *this; } public: - std::string write1HlIcode(Function *pProc, int *numLoc) const; + QString write1HlIcode(Function *pProc, int *numLoc) const; void setAsgn(Expr *lhs, Expr *rhs); } ; /* LOW_LEVEL icode operand record */ @@ -404,11 +405,11 @@ public: } void emitGotoLabel(int indLevel); void findJumpTargets(CIcodeRec &_pc); - void writeIntComment(std::ostringstream &s); + void writeIntComment(QTextStream & s); void dis1Line(int loc_ip, int pass); - std::ostringstream &strSrc(std::ostringstream &os,bool skip_comma=false); + QTextStream & strSrc(QTextStream & os, bool skip_comma=false); - void flops(std::ostringstream &out); + void flops(QTextStream & out); bool isJmpInst(); HLTYPE createCall(); LLInst(ICODE *container) : flg(0),codeIdx(0),numBytes(0),m_link(container) diff --git a/include/locident.h b/include/locident.h index f7bfd43..8b72881 100644 --- a/include/locident.h +++ b/include/locident.h @@ -11,6 +11,7 @@ #include "Enums.h" #include "machine_x86.h" +#include #include #include #include @@ -101,7 +102,7 @@ public: frameType loc; /* Frame location */ bool hasMacro; /* Identifier requires a macro */ char macro[10]; /* Macro for this identifier */ - std::string name; /* Identifier's name */ + QString name; /* Identifier's name */ union ID_UNION { /* Different types of identifiers */ friend struct ID; protected: @@ -167,7 +168,7 @@ public: int newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix, operDu du, LLInst &atOffset); void newIdent(hlType t, frameType f); void flagByteWordId(int off); - void propLongId(uint8_t regL, uint8_t regH, const char *name); + void propLongId(uint8_t regL, uint8_t regH, const QString & name); size_t csym() const {return id_arr.size();} void newRegArg(iICODE picode, iICODE ticode) const; void processTargetIcode(iICODE picode, int &numHlIcodes, iICODE ticode, bool isLong) const; diff --git a/include/machine_x86.h b/include/machine_x86.h index c876568..9f542f4 100644 --- a/include/machine_x86.h +++ b/include/machine_x86.h @@ -1,9 +1,11 @@ #pragma once + +#include #include -#include -#include #include +class QTextStream; + struct LivenessSet; /* Machine registers */ enum eReg @@ -60,13 +62,13 @@ class Machine_X86 : public SourceMachine public: Machine_X86(); virtual ~Machine_X86() {} - static const std::string ®Name(eReg r); - static const std::string &opcodeName(unsigned r); - static const std::string &floatOpName(unsigned r); + static const QString & regName(eReg r); + static const QString & opcodeName(unsigned r); + static const QString & floatOpName(unsigned r); bool physicalReg(eReg r); /* Writes the registers that are set in the bitvector */ //TODO: move this into Machine_X86 ? - static void writeRegVector (std::ostream &ostr,const LivenessSet ®i); + static void writeRegVector (QTextStream & ostr, const LivenessSet ®i); static eReg subRegH(eReg reg); static eReg subRegL(eReg reg); static bool isMemOff(eReg r); diff --git a/include/project.h b/include/project.h index 61b8296..32762e0 100644 --- a/include/project.h +++ b/include/project.h @@ -52,14 +52,14 @@ public: QString output_name(const char *ext); ilFunction funcIter(Function *to_find); ilFunction findByEntry(uint32_t entry); - ilFunction createFunction(FunctionType *f,const std::string &name); + ilFunction createFunction(FunctionType *f, const QString & name); bool valid(ilFunction iter); int getSymIdxByAdd(uint32_t adr); bool validSymIdx(size_t idx); size_t symbolSize(size_t idx); hlType symbolType(size_t idx); - const std::string &symbolName(size_t idx); + const QString & symbolName(size_t idx); const SYM &getSymByIdx(size_t idx) const; static Project *get(); diff --git a/include/symtab.h b/include/symtab.h index b38582d..fad1e8a 100644 --- a/include/symtab.h +++ b/include/symtab.h @@ -7,6 +7,7 @@ #include "types.h" #include "msvc_fixes.h" +#include #include #include struct Expr; @@ -17,7 +18,7 @@ struct TypeContainer; /* * * * * * * * * * * * * * * * * */ struct SymbolCommon { - std::string name; /* New name for this variable/symbol/argument */ + QString name; /* New name for this variable/symbol/argument */ int size; /* Size/maximum size */ hlType type; /* probable type */ eDuVal duVal; /* DEF, USE, VAL */ @@ -38,12 +39,12 @@ struct SYM : public SymbolCommon struct STKSYM : public SymbolCommon { typedef int16_t tLabel; - Expr *actual=0; /* Expression tree of actual parameter */ - AstIdent *regs=0; /* For register arguments only */ + Expr * actual=0; /* Expression tree of actual parameter */ + AstIdent * regs=0; /* For register arguments only */ tLabel label=0; /* Immediate off from BP (+:args, -:params) */ - uint8_t regOff=0; /* Offset is a register (e.g. SI, DI) */ + uint8_t regOff=0; /* Offset is a register (e.g. SI, DI) */ bool hasMacro=false; /* This type needs a macro */ - std::string macro; /* Macro name */ + QString macro; /* Macro name */ bool invalid=false; /* Boolean: invalid entry in formal arg list*/ void setArgName(int i) { @@ -106,6 +107,6 @@ constexpr int NUM_TABLE_TYPES = int(Comment)+1; /* Number of entries: must be la void createSymTables(void); void destroySymTables(void); -bool readVal (std::ostringstream &symName, uint32_t symOff, Function *symProc); +bool readVal (QTextStream & symName, uint32_t symOff, Function *symProc); void selectTable(tableType); /* Select a particular table */ diff --git a/src/BasicBlock.cpp b/src/BasicBlock.cpp index d0cc769..6bedcb0 100644 --- a/src/BasicBlock.cpp +++ b/src/BasicBlock.cpp @@ -5,6 +5,7 @@ #include "dcc.h" #include "msvc_fixes.h" +#include #include #include #include @@ -143,7 +144,8 @@ ICODE* BB::writeLoopHeader(int &indLevel, Function* pProc, int *numLoc, BB *&lat if(loopType == eNodeHeaderType::NO_TYPE) return nullptr; latch = pProc->m_dfsLast[this->latchNode]; - std::ostringstream ostr; + QString ostr_contents; + QTextStream ostr(&ostr_contents); ICODE* picode; switch (loopType) { @@ -169,7 +171,7 @@ ICODE* BB::writeLoopHeader(int &indLevel, Function* pProc, int *numLoc, BB *&lat picode->hlU()->replaceExpr(picode->hl()->expr()->inverse()); } { - string e=picode->hl()->expr()->walkCondExpr (pProc, numLoc); + QString e=picode->hl()->expr()->walkCondExpr (pProc, numLoc); ostr << "\n"<invalidate(); @@ -186,7 +188,8 @@ ICODE* BB::writeLoopHeader(int &indLevel, Function* pProc, int *numLoc, BB *&lat picode = &latch->back(); break; } - cCode.appendCode(ostr.str()); + ostr.flush(); + cCode.appendCode(ostr_contents); stats.numHLIcode += 1; indLevel++; return picode; @@ -199,11 +202,11 @@ bool BB::isEndOfPath(int latch_node_idx) const void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, int _ifFollow) { int follow; /* ifFollow */ - BB * succ, *latch; /* Successor and latching node */ + BB * succ, *latch; /* Successor and latching node */ ICODE * picode; /* Pointer to HLI_JCOND instruction */ - std::string l; /* Pointer to HLI_JCOND expression */ + QString l; /* Pointer to HLI_JCOND expression */ bool emptyThen, /* THEN clause is empty */ - repCond; /* Repeat condition for while() */ + repCond; /* Repeat condition for while() */ /* Check if this basic block should be analysed */ if ((_ifFollow != UN_INIT) and (this == pProc->m_dfsLast[_ifFollow])) @@ -221,9 +224,11 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, /* Write the code for this basic block */ if (repCond == false) { - std::ostringstream ostr; + QString ostr_contents; + QTextStream ostr(&ostr_contents); writeBB(ostr,indLevel, pProc, numLoc); - cCode.appendCode(ostr.str()); + ostr.flush(); + cCode.appendCode(ostr_contents); } /* Check for end of path */ @@ -254,7 +259,8 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, indLevel--; if (loopType == eNodeHeaderType::WHILE_TYPE) { - std::ostringstream ostr; + QString ostr_contents; + QTextStream ostr(&ostr_contents); /* Check if there is need to repeat other statements involved * in while condition, then, emit the loop trailer */ if (repCond) @@ -262,13 +268,14 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, writeBB(ostr,indLevel+1, pProc, numLoc); } ostr <hl()->opcode != HLI_JCOND) { reportError (REPEAT_FAIL); @@ -277,7 +284,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, { e=picode->hl()->expr()->walkCondExpr (pProc, numLoc); } - cCode.appendCode( "%s} while (%s);\n", indentStr(indLevel),e.c_str()); + cCode.appendCode( "%s} while (%s);\n", indentStr(indLevel),qPrintable(e)); } /* Recurse on the loop follow */ @@ -309,13 +316,13 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, if (succ->dfsLastNum != follow) /* THEN part */ { l = writeJcond ( *back().hl(), pProc, numLoc); - cCode.appendCode( "\n%s%s", indentStr(indLevel-1), l.c_str()); + cCode.appendCode( "\n%s%s", indentStr(indLevel-1), qPrintable(l)); succ->writeCode (indLevel, pProc, numLoc, _latchNode,follow); } else /* empty THEN part => negate ELSE part */ { l = writeJcondInv ( *back().hl(), pProc, numLoc); - cCode.appendCode( "\n%s%s", indentStr(indLevel-1), l.c_str()); + cCode.appendCode( "\n%s%s", indentStr(indLevel-1), qPrintable(l)); edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, follow); emptyThen = true; } @@ -335,7 +342,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, } /* else (empty ELSE part) */ } - else if (! emptyThen) /* already visited => emit label */ + else if (not emptyThen) /* already visited => emit label */ { cCode.appendCode( "%s}\n%selse {\n", indentStr(indLevel-1), indentStr(indLevel - 1)); @@ -351,7 +358,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, else /* no follow => if..then..else */ { l = writeJcond ( *back().hl(), pProc, numLoc); - cCode.appendCode( "%s%s", indentStr(indLevel-1), l.c_str()); + cCode.appendCode( "%s%s", indentStr(indLevel-1), qPrintable(l)); edges[THEN].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, _ifFollow); cCode.appendCode( "%s}\n%selse {\n", indentStr(indLevel-1), indentStr(indLevel - 1)); edges[ELSE].BBptr->writeCode (indLevel, pProc, numLoc, _latchNode, _ifFollow); @@ -374,7 +381,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, * Args: pBB: pointer to the current basic block. * Icode: pointer to the array of icodes for current procedure. * lev: indentation level - used for formatting. */ -void BB::writeBB(std::ostream &ostr,int lev, Function * pProc, int *numLoc) +void BB::writeBB(QTextStream &ostr,int lev, Function * pProc, int *numLoc) { /* Save the index into the code table in case there is a later goto * into this instruction (first instruction of the BB) */ @@ -386,8 +393,8 @@ void BB::writeBB(std::ostream &ostr,int lev, Function * pProc, int *numLoc) { if ((pHli.type == HIGH_LEVEL) and ( pHli.valid() )) //TODO: use filtering range here. { - std::string line = pHli.hl()->write1HlIcode(pProc, numLoc); - if (!line.empty()) + QString line = pHli.hl()->write1HlIcode(pProc, numLoc); + if (not line.isEmpty()) { ostr< #include #include "CallConvention.h" +#include CConv *CConv::create(Type v) { @@ -22,15 +23,15 @@ CConv *CConv::create(Type v) return nullptr; } -void C_CallingConvention::writeComments(std::ostream &ostr) +void C_CallingConvention::writeComments(QTextStream & ostr) { ostr << " * C calling convention.\n"; } -void Pascal_CallingConvention::writeComments(std::ostream &ostr) +void Pascal_CallingConvention::writeComments(QTextStream & ostr) { ostr << " * Pascal calling convention.\n"; } -void Unknown_CallingConvention::writeComments(std::ostream &ostr) +void Unknown_CallingConvention::writeComments(QTextStream & ostr) { ostr << " * Unknown calling convention.\n"; } diff --git a/src/DccFrontend.cpp b/src/DccFrontend.cpp index 19a53e4..0a2d635 100644 --- a/src/DccFrontend.cpp +++ b/src/DccFrontend.cpp @@ -332,7 +332,7 @@ bool Project::load() const char *fname = binary_path().toLocal8Bit().data(); QFile finfo(binary_path()); /* Open the input file */ - if(!finfo.open(QFile::ReadOnly)) { + if(not finfo.open(QFile::ReadOnly)) { fatalError(CANNOT_OPEN, fname); } /* Read in first 2 bytes to check EXE signature */ diff --git a/src/Procedure.cpp b/src/Procedure.cpp index 57a04f7..62f445c 100644 --- a/src/Procedure.cpp +++ b/src/Procedure.cpp @@ -28,7 +28,7 @@ void JumpTable::pruneEntries(uint16_t cs) { uint32_t target = cs + LH(&prg->image()[i]); /* Be wary of 00 00 as code - it's probably data */ - if (! (prg->image()[target] or prg->image()[target+1]) or scan(target, _Icode)) + if (not (prg->image()[target] or prg->image()[target+1]) or scan(target, _Icode)) finish = i; } diff --git a/src/RegisterNode.cpp b/src/RegisterNode.cpp index b27d20c..fc5e4bb 100644 --- a/src/RegisterNode.cpp +++ b/src/RegisterNode.cpp @@ -56,26 +56,26 @@ RegisterNode::RegisterNode(const LLOperand &op, LOCAL_ID *locsym) // regiType = reg_type; //} -string RegisterNode::walkCondExpr(Function *pProc, int *numLoc) const +QString RegisterNode::walkCondExpr(Function *pProc, int *numLoc) const { - std::ostringstream codeOut; + QString codeOut; - std::ostringstream o; + QString o; assert(&pProc->localId==m_syms); ID *id = &pProc->localId.id_arr[regiIdx]; if (id->name[0] == '\0') /* no name */ { id->setLocalName(++(*numLoc)); - codeOut <type)<< " "<name<<"; "; - codeOut <<"/* "<id.regi)<<" */\n"; + codeOut += QString("%1 %2; ").arg(TypeContainer::typeName(id->type)).arg(id->name); + codeOut += QString("/* %1 */\n").arg(Machine_X86::regName(id->id.regi)); } if (id->hasMacro) - o << id->macro << "("<name<<")"; + o += QString("%1(%2)").arg(id->macro).arg(id->name); else - o << id->name; + o += id->name; - cCode.appendDecl(codeOut.str()); - return o.str(); + cCode.appendDecl(codeOut); + return o; } int RegisterNode::hlTypeSize(Function *) const diff --git a/src/ast.cpp b/src/ast.cpp index be951b0..5c83a03 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -12,6 +12,7 @@ #include "machine_x86.h" #include "project.h" +#include #include #include #include @@ -61,19 +62,19 @@ void ICODE::setRegDU (eReg regi, operDu du_in) } switch (du_in) { - case eDEF: - du.def.addReg(regi); - du1.addDef(regi); - break; - case eUSE: - du.use.addReg(regi); - break; - case USE_DEF: - du.addDefinedAndUsed(regi); - du1.addDef(regi); - break; - case NONE: /* do nothing */ - break; + case eDEF: + du.def.addReg(regi); + du1.addDef(regi); + break; + case eUSE: + du.use.addReg(regi); + break; + case USE_DEF: + du.addDefinedAndUsed(regi); + du1.addDef(regi); + break; + case NONE: /* do nothing */ + break; } } @@ -83,24 +84,24 @@ void ICODE::copyDU(const ICODE &duIcode, operDu _du, operDu duDu) { 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; } } @@ -132,7 +133,7 @@ GlobalVariable::GlobalVariable(int16_t segValue, int16_t off) globIdx = i; } -string GlobalVariable::walkCondExpr(Function *, int *) const +QString GlobalVariable::walkCondExpr(Function *, int *) const { if(valid) return Project::get()->symtab[globIdx].name; @@ -190,12 +191,10 @@ GlobalVariableIdx::GlobalVariableIdx (int16_t segValue, int16_t off, uint8_t reg printf ("Error, indexed-glob var not found in local id table\n"); idxGlbIdx = i; } -string GlobalVariableIdx::walkCondExpr(Function *pProc, int *) const +QString GlobalVariableIdx::walkCondExpr(Function *pProc, int *) const { - ostringstream o; auto bwGlb = &pProc->localId.id_arr[idxGlbIdx].id.bwGlb; - o << (bwGlb->seg << 4) + bwGlb->off << "["<regi)<<"]"; - return o.str(); + return QString("%1[%2]").arg((bwGlb->seg << 4) + bwGlb->off).arg(Machine_X86::regName(bwGlb->regi)); } @@ -264,22 +263,22 @@ AstIdent *AstIdent::idID (const ID *retVal, LOCAL_ID *locsym, iICODE ix_) AstIdent *newExp=nullptr; switch(retVal->type) { - case TYPE_LONG_SIGN: - { - newExp = new AstIdent(); - idx = locsym->newLongReg (TYPE_LONG_SIGN, retVal->longId(), ix_); - newExp->ident.idType = LONG_VAR; - newExp->ident.idNode.longIdx = idx; - break; - } - case TYPE_WORD_SIGN: - newExp = new RegisterNode(locsym->newByteWordReg(retVal->type, retVal->id.regi),WORD_REG,locsym); - break; - case TYPE_BYTE_SIGN: - newExp = new RegisterNode(locsym->newByteWordReg(retVal->type, retVal->id.regi),BYTE_REG,locsym); - break; - default: - fprintf(stderr,"AstIdent::idID unhandled type %d\n",retVal->type); + case TYPE_LONG_SIGN: + { + newExp = new AstIdent(); + idx = locsym->newLongReg (TYPE_LONG_SIGN, retVal->longId(), ix_); + newExp->ident.idType = LONG_VAR; + newExp->ident.idNode.longIdx = idx; + break; + } + case TYPE_WORD_SIGN: + newExp = new RegisterNode(locsym->newByteWordReg(retVal->type, retVal->id.regi),WORD_REG,locsym); + break; + case TYPE_BYTE_SIGN: + newExp = new RegisterNode(locsym->newByteWordReg(retVal->type, retVal->id.regi),BYTE_REG,locsym); + break; + default: + fprintf(stderr,"AstIdent::idID unhandled type %d\n",retVal->type); } return (newExp); } @@ -353,13 +352,13 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_ { eReg selected; switch (pm.regi) { - case INDEX_SI: selected = rSI; break; - case INDEX_DI: selected = rDI; break; - case INDEX_BP: selected = rBP; break; - case INDEX_BX: selected = rBX; break; - default: - newExp = nullptr; - assert(false); + case INDEX_SI: selected = rSI; break; + case INDEX_DI: selected = rDI; break; + case INDEX_BP: selected = rBP; break; + case INDEX_BX: selected = rBX; break; + default: + newExp = nullptr; + assert(false); } //NOTICE: was selected, 0 newExp = new RegisterNode(LLOperand(selected, 0), &pProc->localId); @@ -430,22 +429,22 @@ int AstIdent::hlTypeSize(Function *pproc) const { switch (ident.idType) { - case GLOB_VAR: - assert(false); - return 1; - case LOCAL_VAR: - return (hlSize[pproc->localId.id_arr[ident.idNode.localIdx].type]); - case PARAM: - return (hlSize[pproc->args[ident.idNode.paramIdx].type]); - case STRING: - return (2); - case LONG_VAR: - return (4); - case OTHER: - return (2); - default: - assert(false); - return -1; + case GLOB_VAR: + assert(false); + return 1; + case LOCAL_VAR: + return (hlSize[pproc->localId.id_arr[ident.idNode.localIdx].type]); + case PARAM: + return (hlSize[pproc->args[ident.idNode.paramIdx].type]); + case STRING: + return (2); + case LONG_VAR: + return (4); + case OTHER: + return (2); + default: + assert(false); + return -1; } /* eos */ } hlType BinaryOperator::expType(Function *pproc) const @@ -479,24 +478,24 @@ hlType AstIdent::expType(Function *pproc) const { switch (ident.idType) { - case UNDEF: - case CONSTANT: - case FUNCTION: - case REGISTER: - case GLOB_VAR: - case GLOB_VAR_IDX: - assert(false); - return TYPE_UNKNOWN; - case LOCAL_VAR: - return (pproc->localId.id_arr[ident.idNode.localIdx].type); - case PARAM: - return (pproc->args[ident.idNode.paramIdx].type); - case STRING: - return (TYPE_STR); - case LONG_VAR: - return (pproc->localId.id_arr[ident.idNode.longIdx].type); - default: - return (TYPE_UNKNOWN); + case UNDEF: + case CONSTANT: + case FUNCTION: + case REGISTER: + case GLOB_VAR: + case GLOB_VAR_IDX: + assert(false); + return TYPE_UNKNOWN; + case LOCAL_VAR: + return (pproc->localId.id_arr[ident.idNode.localIdx].type); + case PARAM: + return (pproc->args[ident.idNode.paramIdx].type); + case STRING: + return (TYPE_STR); + case LONG_VAR: + return (pproc->localId.id_arr[ident.idNode.longIdx].type); + default: + return (TYPE_UNKNOWN); } /* eos */ return (TYPE_UNKNOWN); } @@ -509,177 +508,159 @@ hlType AstIdent::expType(Function *pproc) const Expr * HlTypeSupport::performLongRemoval (eReg regi, LOCAL_ID *locId, Expr *tree) { switch (tree->m_type) { - case BOOLEAN_OP: - case POST_INC: case POST_DEC: - case PRE_INC: case PRE_DEC: - case NEGATION: case ADDRESSOF: - case DEREFERENCE: - case IDENTIFIER: - return tree->performLongRemoval(regi,locId); - break; - default: - fprintf(stderr,"performLongRemoval attemped on %d\n",tree->m_type); - break; + case BOOLEAN_OP: + case POST_INC: case POST_DEC: + case PRE_INC: case PRE_DEC: + case NEGATION: case ADDRESSOF: + case DEREFERENCE: + case IDENTIFIER: + return tree->performLongRemoval(regi,locId); + break; + default: + fprintf(stderr,"performLongRemoval attemped on %d\n",tree->m_type); + break; } return tree; } /* Returns the string located in image, formatted in C format. */ -static std::string getString (int offset) +static QString getString (int offset) { PROG &prog(Project::get()->prog); - ostringstream o; + QString o; int strLen, i; strLen = strSize (&prog.image()[offset], '\0'); - o << '"'; + o += '"'; for (i = 0; i < strLen; i++) - o<walkCondExpr(pProc, numLoc); - } assert(rhs()); - outStr << condOpSym[m_op]; - outStr << rhs()->walkCondExpr(pProc, numLoc); - outStr << ")"; - return outStr.str(); + + return QString("(%1%2%3)") + .arg((m_op!=NOT) ? lhs()->walkCondExpr(pProc, numLoc) : "") + .arg(condOpSym[m_op]) + .arg(rhs()->walkCondExpr(pProc, numLoc)); } -string AstIdent::walkCondExpr(Function *pProc, int *numLoc) const +QString AstIdent::walkCondExpr(Function *pProc, int *numLoc) const { int16_t off; /* temporal - for OTHER */ ID* id; /* Pointer to local identifier table */ BWGLB_TYPE* bwGlb; /* Ptr to BWGLB_TYPE (global indexed var) */ STKSYM * psym; /* Pointer to argument in the stack */ - std::ostringstream outStr,codeOut; + QString codeContents; + QString collectedContents; + + QTextStream codeOut(&codeContents); + QTextStream o(&collectedContents); - std::ostringstream o; switch (ident.idType) { - case LOCAL_VAR: - o << pProc->localId.id_arr[ident.idNode.localIdx].name; - break; + case LOCAL_VAR: + o << pProc->localId.id_arr[ident.idNode.localIdx].name; + break; - case PARAM: - psym = &pProc->args[ident.idNode.paramIdx]; - if (psym->hasMacro) - o << psym->macro<<"("<name<< ")"; - else - o << psym->name; - break; - case STRING: - o << getString (ident.idNode.strIdx); - break; + case PARAM: + psym = &pProc->args[ident.idNode.paramIdx]; + if (psym->hasMacro) + o << psym->macro<<"("<name<< ")"; + else + o << psym->name; + break; + case STRING: + o << getString (ident.idNode.strIdx); + break; - case LONG_VAR: - id = &pProc->localId.id_arr[ident.idNode.longIdx]; - if (id->name[0] != '\0') /* STK_FRAME & REG w/name*/ - o << id->name; - else if (id->loc == REG_FRAME) - { - id->setLocalName(++(*numLoc)); - codeOut <type)<< " "<name<<"; "; - codeOut <<"/* "<longId().h()) << ":" << - Machine_X86::regName(id->longId().l()) << " */\n"; - o << id->name; - pProc->localId.propLongId (id->longId().l(),id->longId().h(), id->name.c_str()); - } - 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 OTHER: - off = ident.idNode.other.off; - o << Machine_X86::regName(ident.idNode.other.seg)<< "["; - o << Machine_X86::regName(ident.idNode.other.regi); - if (off < 0) - o << "-"<< hexStr (-off); - else if (off>0) - o << "+"<< hexStr (off); - o << "]"; - break; - default: - assert(false); - return ""; + case LONG_VAR: + id = &pProc->localId.id_arr[ident.idNode.longIdx]; + if (id->name[0] != '\0') /* STK_FRAME & REG w/name*/ + o << id->name; + else if (id->loc == REG_FRAME) + { + id->setLocalName(++(*numLoc)); + codeOut <type)<< " "<name<<"; "; + codeOut <<"/* "<longId().h()) << ":" << + Machine_X86::regName(id->longId().l()) << " */\n"; + o << id->name; + pProc->localId.propLongId (id->longId().l(),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 OTHER: + off = ident.idNode.other.off; + o << Machine_X86::regName(ident.idNode.other.seg)<< "["; + o << Machine_X86::regName(ident.idNode.other.regi); + if (off < 0) + o << "-"<< hexStr (-off); + else if (off>0) + o << "+"<< hexStr (off); + o << "]"; + break; + default: + assert(false); + return ""; } /* eos */ - outStr << o.str(); - cCode.appendDecl(codeOut.str()); - return outStr.str(); + cCode.appendDecl(codeContents); + return collectedContents; } -string UnaryOperator::walkCondExpr(Function *pProc, int *numLoc) const +QString UnaryOperator::wrapUnary(Function *pProc, int *numLoc,QChar op) const { - std::ostringstream outStr; - bool needBracket=true; + QString outStr = op; + QString inner = unaryExp->walkCondExpr (pProc, numLoc); + if (unaryExp->m_type == IDENTIFIER) + outStr += inner; + else + outStr += "("+inner+')'; + return outStr; +} + +QString UnaryOperator::walkCondExpr(Function *pProc, int *numLoc) const +{ + QString outStr; switch(m_type) { - case NEGATION: - if (unaryExp->m_type == IDENTIFIER) - { - needBracket = false; - outStr << "!"; - } - else - outStr << "! ("; - outStr << unaryExp->walkCondExpr (pProc, numLoc); - if (needBracket == true) - outStr << ")"; - break; + case NEGATION: + outStr+=wrapUnary(pProc,numLoc,'!'); + break; - case ADDRESSOF: - if (unaryExp->m_type == IDENTIFIER) - { - needBracket = false; - outStr << "&"; - } - else - outStr << "&("; - outStr << unaryExp->walkCondExpr (pProc, numLoc); - if (needBracket == true) - outStr << ")"; - break; + case ADDRESSOF: + outStr+=wrapUnary(pProc,numLoc,'&'); + break; - case DEREFERENCE: - outStr << "*"; - if (unaryExp->m_type == IDENTIFIER) - needBracket = false; - else - outStr << "("; - outStr << unaryExp->walkCondExpr (pProc, numLoc); - if (needBracket == true) - outStr << ")"; - break; + case DEREFERENCE: + outStr+=wrapUnary(pProc,numLoc,'*'); + break; - case POST_INC: - outStr << unaryExp->walkCondExpr (pProc, numLoc) << "++"; - break; + case POST_INC: + outStr += unaryExp->walkCondExpr (pProc, numLoc) + "++"; + break; - case POST_DEC: - outStr << unaryExp->walkCondExpr (pProc, numLoc) << "--"; - break; + case POST_DEC: + outStr += unaryExp->walkCondExpr (pProc, numLoc) + "--"; + break; - case PRE_INC: - outStr << "++"<< unaryExp->walkCondExpr (pProc, numLoc); - break; + case PRE_INC: + outStr += "++" + unaryExp->walkCondExpr (pProc, numLoc); + break; - case PRE_DEC: - outStr << "--"<< unaryExp->walkCondExpr (pProc, numLoc); - break; + case PRE_DEC: + outStr += "--" + unaryExp->walkCondExpr (pProc, numLoc); + break; } - return outStr.str(); + return outStr; } /* Walks the conditional expression tree and returns the result on a string */ @@ -726,18 +707,18 @@ Expr *UnaryOperator::insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *lo Expr *temp; switch (m_type) { - case NEGATION: - case ADDRESSOF: - case DEREFERENCE: - temp = unaryExp->insertSubTreeReg( _expr, regi, locsym); - if (nullptr!=temp) - { - unaryExp = temp; - return this; - } - return nullptr; - default: - fprintf(stderr,"insertSubTreeReg attempt on unhandled type %d\n",m_type); + case NEGATION: + case ADDRESSOF: + case DEREFERENCE: + temp = unaryExp->insertSubTreeReg( _expr, regi, locsym); + if (nullptr!=temp) + { + unaryExp = temp; + return this; + } + return nullptr; + default: + fprintf(stderr,"insertSubTreeReg attempt on unhandled type %d\n",m_type); } return nullptr; } @@ -843,22 +824,22 @@ Expr *BinaryOperator::inverse() const BinaryOperator *res=reinterpret_cast(this->clone()); switch (m_op) { - case LESS_EQUAL: case LESS: case EQUAL: - case NOT_EQUAL: case GREATER: case GREATER_EQUAL: - res->m_op = invCondOp[m_op]; - return res; + case LESS_EQUAL: case LESS: case EQUAL: + case NOT_EQUAL: case GREATER: case GREATER_EQUAL: + res->m_op = invCondOp[m_op]; + return res; - case AND: case OR: case XOR: case NOT: case ADD: - case SUB: case MUL: case DIV: case SHR: case SHL: case MOD: - return UnaryOperator::Create(NEGATION, res); + case AND: case OR: case XOR: case NOT: case ADD: + case SUB: case MUL: case DIV: case SHR: case SHL: case MOD: + return UnaryOperator::Create(NEGATION, res); - case DBL_AND: case DBL_OR: - res->m_op = invCondOp[m_op]; - res->m_lhs=m_lhs->inverse (); - res->m_rhs=m_rhs->inverse (); - return res; - default: - fprintf(stderr,"BinaryOperator::inverse attempt on unhandled op %d\n",m_op); + case DBL_AND: case DBL_OR: + res->m_op = invCondOp[m_op]; + res->m_lhs=m_lhs->inverse (); + res->m_rhs=m_rhs->inverse (); + return res; + default: + fprintf(stderr,"BinaryOperator::inverse attempt on unhandled op %d\n",m_op); } /* eos */ assert(false); return res; @@ -880,7 +861,7 @@ eReg AstIdent::otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl) { ID *id = &locTbl->id_arr[idx]; if ((id->loc == REG_FRAME) and ((id->type == TYPE_LONG_SIGN) or - (id->type == TYPE_LONG_UNSIGN))) + (id->type == TYPE_LONG_UNSIGN))) { if (id->longId().h() == regi) return (id->longId().l()); @@ -891,14 +872,12 @@ eReg AstIdent::otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl) } -string Constant::walkCondExpr(Function *, int *) const +QString Constant::walkCondExpr(Function *, int *) const { - ostringstream o; if (kte.kte < 1000) - o << kte.kte; + return QString::number(kte.kte); else - o << "0x"<writeCall(call.proc,*call.args, numLoc); } diff --git a/src/backend.cpp b/src/backend.cpp index 9e9ca6b..5781ce5 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -10,8 +10,10 @@ #include "project.h" #include "CallGraph.h" -#include -#include +#include +#include +#include +#include #include #include #include @@ -41,14 +43,14 @@ int getNextLabel() /* displays statistics on the subroutine */ void Function::displayStats () { - printf("\nStatistics - Subroutine %s\n", name.c_str()); - printf ("Number of Icode instructions:\n"); - printf (" Low-level : %4d\n", stats.numLLIcode); - if (! (flg & PROC_ASM)) + qDebug() << "\nStatistics - Subroutine" << name; + qDebug() << "Number of Icode instructions:"; + qDebug() << " Low-level :" << stats.numLLIcode; + if (not (flg & PROC_ASM)) { - printf (" High-level: %4d\n", stats.numHLIcode); - printf (" Percentage reduction: %2.2f%%\n", 100.0 - (stats.numHLIcode * - 100.0) / stats.numLLIcode); + qDebug() << " High-level:"<prog); @@ -129,10 +131,10 @@ static void printGlobVar (std::ostream &ostr,SYM * psym) break; default: { - ostringstream strContents; + QString strContents; for (j=0; j < psym->size; j++) - strContents << cChar(prog.image()[relocOp + j]); - ostr << "char\t*"<name<<" = \""<name<<" = \""<prog); /* Write header information */ @@ -210,10 +214,11 @@ static void emitFwdGotoLabel (ICODE * pt, int indLevel) /* Writes the procedure's declaration (including arguments), local variables, * and invokes the procedure that writes the code of the given record *hli */ -void Function::codeGen (std::ostream &fs) +void Function::codeGen (QIODevice &fs) { int numLoc; - ostringstream ostr; + QString ostr_contents; + QTextStream ostr(&ostr_contents); //STKFRAME * args; /* Procedure arguments */ //char buf[200], /* Procedure's definition */ // arg[30]; /* One argument */ @@ -222,30 +227,27 @@ void Function::codeGen (std::ostream &fs) /* Write procedure/function header */ cCode.init(); if (flg & PROC_IS_FUNC) /* Function */ - ostr<< "\n"<flg & INVALID_BB) continue; /* skip invalid BBs */ - cout << "BB "<proc->displayStats (); - if (! (pcallGraph->proc->flg & PROC_ASM)) + if (not (pcallGraph->proc->flg & PROC_ASM)) { stats.totalLL += stats.numLLIcode; stats.totalHL += stats.numHLIcode; @@ -349,16 +358,15 @@ static void backBackEnd (CALL_GRAPH * pcallGraph, std::ostream &_ios) /* Invokes the necessary routines to produce code one procedure at a time. */ void BackEnd(CALL_GRAPH * pcallGraph) { - std::ofstream fs; /* Output C file */ - /* Get output file name */ QString outNam(Project::get()->output_name("b")); /* b for beta */ + QFile fs(outNam); /* Output C file */ /* Open output file */ - fs.open(outNam.toStdString()); - if(!fs.is_open()) + if(not fs.open(QFile::WriteOnly|QFile::Text)) fatalError (CANNOT_OPEN, outNam.toStdString().c_str()); - std::cout<<"dcc: Writing C beta file "< #include #include - +#include #define deltaProcLines 20 using namespace std; @@ -21,26 +21,26 @@ using namespace std; * tab is removed and replaced by this label */ void strTable::addLabelBundle (int idx, int label) { - char s[16]; - sprintf (s, "l%d: ", label); - if(at(idx).size()<4) - at(idx)=s; + QString &processedLine(at(idx)); + QString s = QString("l%1: ").arg(label); + if(processedLine.size()<4) + processedLine = s; else - at(idx) = string(s)+at(idx).substr(4); + processedLine = s+processedLine.mid(4); } /* Writes the contents of the string table on the file fp. */ -static void writeStrTab (std::ostream &ios, strTable &strTab) +static void writeStrTab (QIODevice &ios, strTable &strTab) { for (size_t i = 0; i < strTab.size(); i++) - ios << strTab[i]; + ios.write(strTab[i].toLatin1()); } /* Writes the contents of the bundle (procedure code and declaration) to * a file. */ -void writeBundle (std::ostream &ios, bundle procCode) +void writeBundle (QIODevice &ios, bundle procCode) { writeStrTab (ios, procCode.decl); writeStrTab (ios, procCode.code); @@ -70,7 +70,7 @@ void bundle::appendCode(const char *format,...) code.push_back(buf); va_end (args); } -void bundle::appendCode(const std::string &s) +void bundle::appendCode(const QString & s) { code.push_back(s); } @@ -85,7 +85,7 @@ void bundle::appendDecl(const char *format,...) va_end (args); } -void bundle::appendDecl(const std::string &v) +void bundle::appendDecl(const QString &v) { decl.push_back(v); } diff --git a/src/chklib.cpp b/src/chklib.cpp index 4a9f62f..efb4f6d 100644 --- a/src/chklib.cpp +++ b/src/chklib.cpp @@ -11,7 +11,9 @@ #include "perfhlib.h" #include "dcc_interface.h" -#include +#include +#include +#include #include #include #include @@ -468,7 +470,7 @@ bool LibCheck(Function & pProc) if (memcmp(ht[h].htPat, pat, PATLEN) == 0) { /* We have a match. Save the name, if not already set */ - if (pProc.name.empty() ) /* Don't overwrite existing name */ + if (pProc.name.isEmpty() ) /* Don't overwrite existing name */ { /* Give proc the new name */ pProc.name = ht[h].htSym; @@ -510,7 +512,8 @@ bool LibCheck(Function & pProc) pProc.liveOut.setReg(rAX).addReg(rDS); break; default: - fprintf(stderr,"Unknown retval type %d for %s in LibCheck\n",pProc.retVal.type,pProc.name.c_str()); + qCritical() << QString("Unknown retval type %1 for %2 in LibCheck") + .arg(pProc.retVal.type).arg(pProc.name); /*** other types are not considered yet ***/ } } diff --git a/src/comwrite.cpp b/src/comwrite.cpp index f3044f0..fd71cd5 100644 --- a/src/comwrite.cpp +++ b/src/comwrite.cpp @@ -12,6 +12,7 @@ #include #include +#include using namespace std; #define intSize 40 @@ -150,7 +151,7 @@ static const char *intOthers[] = { /* Writes the description of the current interrupt. Appends it to the * string s. */ -void LLInst::writeIntComment (std::ostringstream &s) +void LLInst::writeIntComment (QTextStream &s) { uint32_t src_immed=src().getImm2(); s<<"\t/* "; @@ -188,12 +189,15 @@ void LLInst::writeIntComment (std::ostringstream &s) //, &cCode.decl void Function::writeProcComments() { - std::ostringstream ostr; - writeProcComments(ostr); - cCode.appendDecl(ostr.str()); + QString dest_str; + { + QTextStream ostr(&dest_str); + writeProcComments(ostr); + } + cCode.appendDecl(dest_str); } -void Function::writeProcComments(std::ostream &ostr) +void Function::writeProcComments(QTextStream &ostr) { int i; ID *id; /* Pointer to register argument identifier */ diff --git a/src/control.cpp b/src/control.cpp index cae3078..27c0e71 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -470,7 +470,7 @@ void Function::structIfs () if ((follow != 0) and (followInEdges > 1)) { currNode->ifFollow = follow; - if (!unresolved.empty()) + if (not unresolved.empty()) flagNodes (unresolved, follow, this); } else @@ -624,7 +624,7 @@ void Function::compoundCond() --i; } - /* Check (!X and Y) case */ + /* Check (not X and Y) case */ else if ((thenBB->nodeType == TWO_BRANCH) and (thenBB->numHlIcodes == 1) and (thenBB->inEdges.size() == 1) and (thenBB->edges[THEN].BBptr == elseBB)) { @@ -640,7 +640,7 @@ void Function::compoundCond() --i; } - /* Check (!X or Y) case */ + /* Check (not X or Y) case */ else if ((elseBB->nodeType == TWO_BRANCH) and (elseBB->numHlIcodes == 1) and (elseBB->inEdges.size() == 1) and (elseBB->edges[ELSE].BBptr == thenBB)) { diff --git a/src/dataflow.cpp b/src/dataflow.cpp index 72a7fec..f12b5ca 100644 --- a/src/dataflow.cpp +++ b/src/dataflow.cpp @@ -222,7 +222,7 @@ void Function::elimCondCodes () { ICODE &a(*defAt); ICODE &b(*useAt); - reportError (NOT_DEF_USE,a.ll()->getOpcode(),b.ll()->getOpcode()); + reportError (NOT_DEF_USE,a.ll()->label,a.ll()->getOpcode(),b.ll()->getOpcode()); flg |= PROC_ASM; /* generate asm */ } break; @@ -364,7 +364,8 @@ void Function::liveRegAnalysis (LivenessSet &in_liveOut) if ((not (pcallee->flg & PROC_ISLIB)) or ( pbb->liveOut.any() )) { switch (pcallee->retVal.type) { - case TYPE_LONG_SIGN: case TYPE_LONG_UNSIGN: + case TYPE_LONG_SIGN: + case TYPE_LONG_UNSIGN: ticode.du1.setDef(rAX).addDef(rDX); //TODO: use Calling convention to properly set regs here break; @@ -977,7 +978,7 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc) assert(ti_hl->asgn.rhs); _exp = _icHl.call.toAst(); res = Expr::insertSubTreeReg (ti_hl->asgn.rhs,_exp, _retVal->id.regi, &locals); - if (! res) + if (not res) Expr::insertSubTreeReg (ti_hl->asgn.m_lhs, _exp,_retVal->id.regi, &locals); //TODO: HERE missing: 2 regs picode->invalidate(); @@ -1225,7 +1226,7 @@ void Function::preprocessReturnDU(LivenessSet &_liveOut) retVal.loc = REG_FRAME; retVal.longId() = LONGID_TYPE(rDX,rAX); /*idx = */localId.newLongReg(TYPE_LONG_SIGN, LONGID_TYPE(rDX,rAX), Icode.begin()); - localId.propLongId (rAX, rDX, "\0"); + localId.propLongId (rAX, rDX, ""); } else if (isAx or isBx or isCx or isDx) /* uint16_t */ { @@ -1291,7 +1292,7 @@ void Function::dataFlow(LivenessSet &_liveOut) elimCondCodes(); genLiveKtes(); liveRegAnalysis (_liveOut); /* calls dataFlow() recursively */ - if (! (flg & PROC_ASM)) /* can generate C for pProc */ + if (not (flg & PROC_ASM)) /* can generate C for pProc */ { genDU1 (); /* generate def/use level 1 chain */ findExps (); /* forward substitution algorithm */ diff --git a/src/dcc.cpp b/src/dcc.cpp index 4c0f899..5be65ff 100644 --- a/src/dcc.cpp +++ b/src/dcc.cpp @@ -188,7 +188,7 @@ int main(int argc, char **argv) Project::get()->create(option.filename); DccFrontend fe(&app); - if(!Project::get()->load()) { + if(not Project::get()->load()) { return -1; } if (option.verbose) diff --git a/src/disassem.cpp b/src/disassem.cpp index b5a12ad..f8aa954 100644 --- a/src/disassem.cpp +++ b/src/disassem.cpp @@ -9,6 +9,8 @@ #include "symtab.h" #include "project.h" +#include +#include #include #include #include @@ -16,6 +18,7 @@ #include #include #include + // Note: for the time being, there is no interactive disassembler // for unix @@ -72,8 +75,8 @@ static const char *szFlops3C[] = static const char *szPtr[2] = { "word ptr ", "byte ptr " }; -static void formatRM(ostringstream &p, const LLOperand &pm); -static ostringstream &strDst(ostringstream &os, uint32_t flg, const LLOperand &pm); +static void formatRM(QTextStream & p, const LLOperand &pm); +static QTextStream & strDst(QTextStream & os, uint32_t flg, const LLOperand &pm); static char *strHex(uint32_t d); //static int checkScanned(uint32_t pcCur); @@ -152,11 +155,11 @@ void Disassembler::disassem(Function * ppProc) if (pass != 3) { auto p = (pass == 1)? asm1_name: asm2_name; - m_fp.open(p.toStdString(),ios_base::app); - if (!m_fp.is_open()) - { + m_disassembly_target = new QFile(p); + if(!m_disassembly_target->open(QFile::WriteOnly|QFile::Text|QFile::Append)) { fatalError(CANNOT_OPEN, p.toStdString().c_str()); } + m_fp.setDevice(m_disassembly_target); } /* Create temporary code array */ // Mike: needs objectising! @@ -179,7 +182,7 @@ void Disassembler::disassem(Function * ppProc) /* Write procedure header */ if (pass != 3) { - std::string near_far=(pProc->flg & PROC_FAR)? "FAR": "NEAR"; + const char * near_far=(pProc->flg & PROC_FAR)? "FAR": "NEAR"; m_fp << "\t\t"<name<<" PROC "<< near_far<<"\n"; } @@ -194,7 +197,10 @@ void Disassembler::disassem(Function * ppProc) if (pass != 3) { m_fp << "\n\t\t"<name<<" ENDP\n\n"; - m_fp.close(); + m_fp.setDevice(nullptr); + m_disassembly_target->close(); + delete m_disassembly_target; + } pc.clear(); @@ -208,16 +214,20 @@ void Disassembler::disassem(Function * ppProc) void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass) { PROG &prog(Project::get()->prog); - ostringstream oper_stream; - ostringstream hex_bytes; - ostringstream result_stream; - ostringstream opcode_with_mods; - ostringstream operands_s; - oper_stream << uppercase; - hex_bytes << uppercase; + QString oper_contents; + QTextStream oper_stream(&oper_contents); + QString hex_bytes; + QString result_contents; + QTextStream result_stream(&result_contents); + QString opcode_with_mods; + + QString operands_contents; + QTextStream operands_s(&operands_contents); + oper_stream.setNumberFlags(QTextStream::UppercaseBase|QTextStream::UppercaseDigits); + /* Disassembly stage 1 -- - * Do not try to display NO_CODE entries or synthetic instructions, - * other than JMPs, that have been introduced for def/use analysis. */ + * Do not try to display NO_CODE entries or synthetic instructions, + * other than JMPs, that have been introduced for def/use analysis. */ if ((option.asm1) and ( inst.testFlags(NO_CODE) or (inst.testFlags(SYNTHETIC) and (inst.getOpcode() != iJMP)))) @@ -244,25 +254,28 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass) cb = (uint32_t) inst.numBytes; nextInst = inst.label + cb; - /* Output hexa code in program image */ + /* Output hex code in program image */ if (pass != 3) { for (j = 0; j < cb; j++) { - hex_bytes << hex << setw(2) << setfill('0') << uint16_t(prog.image()[inst.label + j]); + hex_bytes += QString("%1").arg(uint16_t(prog.image()[inst.label + j]),2,16,QChar('0')).toUpper(); } - hex_bytes << ' '; + hex_bytes += ' '; } } - oper_stream << setw(POS_LAB) << left<< hex_bytes.str(); + oper_stream.setFieldWidth(POS_LAB); + oper_stream.setFieldAlignment(QTextStream::AlignLeft); + oper_stream << hex_bytes; /* Check if there is a symbol here */ selectTable(Label); - oper_stream << setw(5)<name; + QString oper = QString("%1 ptr %2") + .arg((inst.getOpcode() == iCALL) ? "near" : "far") + .arg((inst.src().proc.proc)->name); + operands_s<< qPrintable(oper); } else if (inst.getOpcode() == iCALLF) { @@ -438,7 +452,10 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass) } else { - (inst.getFlag() & B)? opcode_with_mods<< "B": opcode_with_mods<< "W"; + if(inst.getFlag() & B) + opcode_with_mods+='B'; + else + opcode_with_mods+='W'; } break; @@ -457,8 +474,8 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass) case iOUT: { - std::string d1=((inst.testFlags(I))? strHex(inst.src().getImm2()): "dx"); - std::string d2=((inst.getFlag() & B) ? ", al": ", ax"); + QString d1=((inst.testFlags(I))? strHex(inst.src().getImm2()): "dx"); + QString d2=((inst.getFlag() & B) ? ", al": ", ax"); operands_s<name.c_str(); + procname = initProc->name; - printf("Wanted to start interactive disasassembler for %s:%d\n",procname,initIC); + qDebug() << "Wanted to start interactive disasassembler for "<second; elem.BBptr = psBB; psBB->inEdges.push_back((BB *)nullptr); diff --git a/src/hlicode.cpp b/src/hlicode.cpp index 4ff5c68..68e32c3 100644 --- a/src/hlicode.cpp +++ b/src/hlicode.cpp @@ -4,17 +4,17 @@ * Date: September-October 1993 * (C) Cristina Cifuentes */ +#include "dcc.h" + +#include +#include + #include #include #include #include -#include "dcc.h" using namespace std; -static char buf[lineSize]; /* Line buffer for hl icode output */ - - - /* Places the new HLI_ASSIGN high-level operand in the high-level icode array */ void HLTYPE::setAsgn(Expr *lhs, Expr *rhs) { @@ -477,82 +477,68 @@ void Function::highLevelGen() /* Returns the string that represents the procedure call of tproc (ie. with * actual parameters) */ -std::string Function::writeCall (Function * tproc, STKFRAME & args, int *numLoc) +QString Function::writeCall (Function * tproc, STKFRAME & args, int *numLoc) { //string condExp; - ostringstream ostr; - ostr<name<<" ("; + QString ostr; + ostr+=tproc->name+" ("; for(const STKSYM &sym : args) { if(sym.actual) - ostr << sym.actual->walkCondExpr (this, numLoc); + ostr += sym.actual->walkCondExpr(this, numLoc); else - ostr << ""; + ostr += ""; if((&sym)!=&(args.back())) - ostr << ", "; + ostr += ", "; } - ostr << ")"; - return ostr.str(); + ostr += ")"; + return ostr; } /* Displays the output of a HLI_JCOND icode. */ -const char *writeJcond (const HLTYPE &h, Function * pProc, int *numLoc) +QString writeJcond (const HLTYPE &h, Function * pProc, int *numLoc) { - memset (buf, ' ', sizeof(buf)); - buf[0] = '\0'; - strcat (buf, "if "); if(h.opcode==HLI_INVALID) { return "if (*HLI_INVALID*) {\n"; } + assert(h.expr()); Expr *inverted=h.expr()->inverse(); //inverseCondOp (&h.exp); - std::string e = inverted->walkCondExpr (pProc, numLoc); + QString inverted_form = inverted->walkCondExpr (pProc, numLoc); delete inverted; - strcat (buf, e.c_str()); - strcat (buf, " {\n"); - return (buf); + + return QString("if %1 {\n").arg(inverted_form); } /* Displays the inverse output of a HLI_JCOND icode. This is used in the case * when the THEN clause of an if..then..else is empty. The clause is * negated and the ELSE clause is used instead. */ -const char *writeJcondInv(HLTYPE h, Function * pProc, int *numLoc) +QString writeJcondInv(HLTYPE h, Function * pProc, int *numLoc) { - memset (buf, ' ', sizeof(buf)); - buf[0] = '\0'; - strcat (buf, "if "); - std::string e; + QString _form; + if(h.expr()==nullptr) - e = "( *failed condition recovery* )"; + _form = "( *failed condition recovery* )"; else - e = h.expr()->walkCondExpr (pProc, numLoc); - - strcat (buf, e.c_str()); - strcat (buf, " {\n"); - return (buf); + _form = h.expr()->walkCondExpr (pProc, numLoc); + return QString("if %1 {\n").arg(_form); } -string AssignType::writeOut(Function *pProc, int *numLoc) const +QString AssignType::writeOut(Function *pProc, int *numLoc) const { - ostringstream ostr; - ostr << m_lhs->walkCondExpr (pProc, numLoc); - ostr << " = "; - ostr << rhs->walkCondExpr (pProc, numLoc); - ostr << ";\n"; - return ostr.str(); + return QString("%1 = %2;\n") + .arg(m_lhs->walkCondExpr (pProc, numLoc)) + .arg(rhs->walkCondExpr (pProc, numLoc)); } -string CallType::writeOut(Function *pProc, int *numLoc) const +QString CallType::writeOut(Function *pProc, int *numLoc) const { - ostringstream ostr; - ostr << pProc->writeCall (proc, *args, numLoc); - ostr << ";\n"; - return ostr.str(); + return pProc->writeCall (proc, *args, numLoc) + ";\n"; } -string ExpType::writeOut(Function *pProc, int *numLoc) const +QString ExpType::writeOut(Function *pProc, int *numLoc) const { if(v==nullptr) return ""; @@ -573,38 +559,33 @@ void HLTYPE::set(Expr *l, Expr *r) * Note: this routine does not output the contens of HLI_JCOND icodes. This is * done in a separate routine to be able to support the removal of * empty THEN clauses on an if..then..else. */ -string HLTYPE::write1HlIcode (Function * pProc, int *numLoc) const +QString HLTYPE::write1HlIcode (Function * pProc, int *numLoc) const { - string e; - ostringstream ostr; const HlTypeSupport *p = get(); switch (opcode) { - case HLI_ASSIGN: - return p->writeOut(pProc,numLoc); - case HLI_CALL: - return p->writeOut(pProc,numLoc); - case HLI_RET: - e = p->writeOut(pProc,numLoc); - if (! e.empty()) - ostr << "return (" << e << ");\n"; - break; - case HLI_POP: - ostr << "HLI_POP "; - ostr << p->writeOut(pProc,numLoc); - ostr << "\n"; - break; - case HLI_PUSH: - ostr << "HLI_PUSH "; - ostr << p->writeOut(pProc,numLoc); - ostr << "\n"; - break; - case HLI_JCOND: //Handled elsewhere - break; - default: - fprintf(stderr," HLTYPE::write1HlIcode - Unhandled opcode %d\n",opcode); + case HLI_ASSIGN: + return p->writeOut(pProc,numLoc); + case HLI_CALL: + return p->writeOut(pProc,numLoc); + case HLI_RET: + { + QString e; + e = p->writeOut(pProc,numLoc); + if (not e.isEmpty()) + return QString("return (%1);\n").arg(e); + break; } - return ostr.str(); + case HLI_POP: + return QString("HLI_POP %1\n").arg(p->writeOut(pProc,numLoc)); + case HLI_PUSH: + return QString("HLI_PUSH %1\n").arg(p->writeOut(pProc,numLoc)); + case HLI_JCOND: //Handled elsewhere + break; + default: + qCritical() << " HLTYPE::write1HlIcode - Unhandled opcode" << opcode; + } + return ""; } @@ -619,16 +600,22 @@ void ICODE::writeDU() { int my_idx = loc_ip; { - ostringstream ostr; - Machine_X86::writeRegVector(ostr,du.def); - if (!ostr.str().empty()) - printf ("Def (reg) = %s\n", ostr.str().c_str()); + QString ostr_contents; + { + QTextStream ostr(&ostr_contents); + Machine_X86::writeRegVector(ostr,du.def); + } + if (not ostr_contents.isEmpty()) + qDebug() << QString("Def (reg) = %1\n").arg(ostr_contents); } { - ostringstream ostr; - Machine_X86::writeRegVector(ostr,du.use); - if (!ostr.str().empty()) - printf ("Use (reg) = %s\n", ostr.str().c_str()); + QString ostr_contents; + { + QTextStream ostr(&ostr_contents); + Machine_X86::writeRegVector(ostr,du.use); + } + if (not ostr_contents.isEmpty()) + qDebug() << QString("Use (reg) = %1\n").arg(ostr_contents); } /* Print du1 chain */ diff --git a/src/idioms.cpp b/src/idioms.cpp index 44fe2ee..f4990a3 100644 --- a/src/idioms.cpp +++ b/src/idioms.cpp @@ -211,7 +211,7 @@ void Function::findIdioms() } /* Check if number of parameter bytes match their calling convention */ - if ((flg & PROC_HLL) and (!args.empty())) + if ((flg & PROC_HLL) and (not args.empty())) { args.m_minOff += (flg & PROC_FAR ? 4 : 2); delta = args.maxOff - args.m_minOff; @@ -258,7 +258,7 @@ void Function::bindIcodeOff() if (ll->testFlags(I) ) { uint32_t found; - if (! Icode.labelSrch(ll->src().getImm2(), found)) + if (not Icode.labelSrch(ll->src().getImm2(), found)) ll->setFlags( NO_LABEL ); else ll->replaceSrc(LLOperand::CreateImm2(found)); diff --git a/src/idioms/arith_idioms.cpp b/src/idioms/arith_idioms.cpp index 9204e7e..010a5ae 100644 --- a/src/idioms/arith_idioms.cpp +++ b/src/idioms/arith_idioms.cpp @@ -3,6 +3,8 @@ #include "dcc.h" #include "msvc_fixes.h" +#include + using namespace std; /***************************************************************************** @@ -134,7 +136,8 @@ bool Idiom18::match(iICODE picode) /* not supported yet */ ICODE &ic(*picode); const Function *my_proc(ic.getParent()->getParent()); - printf("Unsupported idiom18 type at %x in %s:%x : indexed\n",ic.loc_ip,my_proc->name.c_str(),my_proc->procEntry); + qWarning() << "Unsupported idiom18 type at"<< QString::number(ic.loc_ip,16) + << "in"<< my_proc->name <<':'<< QString::number(my_proc->procEntry,16) << "- indexed"; } switch(m_idiom_type) diff --git a/src/idioms/epilogue_idioms.cpp b/src/idioms/epilogue_idioms.cpp index 5b9f0da..e867e30 100644 --- a/src/idioms/epilogue_idioms.cpp +++ b/src/idioms/epilogue_idioms.cpp @@ -64,13 +64,13 @@ bool Idiom2::match(iICODE pIcode) if(nicode == m_end) return false; - if (nicode->ll()->match(iPOP,rBP) and ! (nicode->ll()->testFlags(I | TARGET | CASE)) ) + if (nicode->ll()->match(iPOP,rBP) and not (nicode->ll()->testFlags(I | TARGET | CASE)) ) { m_icodes.push_back(nicode++); // Matched POP BP /* Match RET(F) */ if ( nicode != m_end and - !(nicode->ll()->testFlags(I | TARGET | CASE)) and + not (nicode->ll()->testFlags(I | TARGET | CASE)) and (nicode->ll()->match(iRET) or nicode->ll()->match(iRETF)) ) { @@ -140,7 +140,7 @@ bool Idiom4::match(iICODE pIcode) } int Idiom4::action() { - if( ! m_icodes.empty()) // if not an empty RET[F] N + if( not m_icodes.empty()) // if not an empty RET[F] N { for(size_t idx=0; idxinvalidate(); diff --git a/src/idioms/idiom1.cpp b/src/idioms/idiom1.cpp index db8a2a1..7b5c30e 100644 --- a/src/idioms/idiom1.cpp +++ b/src/idioms/idiom1.cpp @@ -122,7 +122,7 @@ bool Idiom1::match(iICODE picode) m_icodes.push_back(picode++); } - return !m_icodes.empty(); + return not m_icodes.empty(); } int Idiom1::action() { diff --git a/src/locident.cpp b/src/locident.cpp index 4597397..98a373e 100644 --- a/src/locident.cpp +++ b/src/locident.cpp @@ -181,7 +181,7 @@ int LOCAL_ID::newLongReg(hlType t, const LONGID_TYPE &longT, iICODE ix_) for (idx = 0; idx < id_arr.size(); idx++) { ID &entry(id_arr[idx]); - if(!entry.isLong() or (entry.loc != REG_FRAME)) + if(not entry.isLong() or (entry.loc != REG_FRAME)) continue; if (/*(locSym->id[idx].type == t) and Not checking type */ (entry.longId().h() == regH) and @@ -461,7 +461,7 @@ eReg otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl) * the local identifier table. If so, macros for these registers are * placed in the local identifier table, as these registers belong to a * long register identifier. */ -void LOCAL_ID::propLongId (uint8_t regL, uint8_t regH, const char *name) +void LOCAL_ID::propLongId (uint8_t regL, uint8_t regH, const QString &name) { for (ID &rid : id_arr) { diff --git a/src/machine_x86.cpp b/src/machine_x86.cpp index 16eb0e7..ad9fbf7 100644 --- a/src/machine_x86.cpp +++ b/src/machine_x86.cpp @@ -3,10 +3,11 @@ #include "msvc_fixes.h" #include "icode.h" +#include #include // Index registers **** temp solution -static const std::string regNames[] = { +static const QString regNames[] = { "undef", "ax", "cx", "dx", "bx", "sp", "bp", "si", "di", @@ -21,17 +22,17 @@ static const std::string regNames[] = { /* uint8_t and uint16_t registers */ Machine_X86::Machine_X86() { - static_assert((sizeof(regNames)/sizeof(std::string))==LAST_REG, + static_assert((sizeof(regNames)/sizeof(QString))==LAST_REG, "Reg count not equal number of strings"); } -const std::string &Machine_X86::regName(eReg r) +const QString &Machine_X86::regName(eReg r) { - assert(r<(sizeof(regNames)/sizeof(std::string))); + assert(r<(sizeof(regNames)/sizeof(QString))); return regNames[r]; } -static const std::string szOps[] = +static const QString szOps[] = { "CBW", "AAA", "AAD", "AAM", "AAS", "ADC", "ADD", "AND", "BOUND","CALL", "CALL", "CLC", "CLD", "CLI", "CMC", "CMP", @@ -49,7 +50,7 @@ static const std::string szOps[] = "XLAT", "XOR", "INTO", "NOP", "REPNE", "REPE", "MOD" }; /* The following opcodes are for mod != 3 */ -static std::string szFlops1[] = +static const QString szFlops1[] = { /* 0 1 2 3 4 5 6 7 */ "FADD", "FMUL", "FCOM", "FCOMP", "FSUB", "FSUBR", "FDIV", "FDIVR", /* 00 */ @@ -62,7 +63,7 @@ static std::string szFlops1[] = "FILD", "???", "FIST", "FISTP", "FBLD", "???", "FBSTP", "FISTP" /* 38 */ }; /* The following opcodes are for mod == 3 */ -static std::string szFlops2[] = +static const QString szFlops2[] = { /* 0 1 2 3 4 5 6 7 */ "FADD", "FMUL", "FCOM", "FCOMP", "FSUB", "FSUBR", "FDIV", "FDIVR", /* 00 */ @@ -75,17 +76,17 @@ static std::string szFlops2[] = "FILD", "???", "FIST", "FISTP", "", "???", "FBSTP", "FISTP" /* 38 */ }; -const std::string &Machine_X86::opcodeName(unsigned r) +const QString &Machine_X86::opcodeName(unsigned r) { - assert(r<(sizeof(szOps)/sizeof(std::string))); + assert(r<(sizeof(szOps)/sizeof(QString))); return szOps[r]; } -const std::string &Machine_X86::floatOpName(unsigned r) +const QString &Machine_X86::floatOpName(unsigned r) { - if(r>=(sizeof(szFlops1)/sizeof(std::string))) + if(r>=(sizeof(szFlops1)/sizeof(QString))) { - r-= (sizeof(szFlops1)/sizeof(std::string)); - assert(r<(sizeof(szFlops2)/sizeof(std::string))); + r-= (sizeof(szFlops1)/sizeof(QString)); + assert(r<(sizeof(szFlops2)/sizeof(QString))); return szFlops2[r]; } return szFlops1[r]; @@ -137,7 +138,7 @@ eReg Machine_X86::compositeParent(eReg reg) } return rUNDEF; } -void Machine_X86::writeRegVector (std::ostream &ostr,const LivenessSet ®i) +void Machine_X86::writeRegVector (QTextStream &ostr,const LivenessSet ®i) { int j; for (j = rAX; j < INDEX_BX_SI; j++) diff --git a/src/parser.cpp b/src/parser.cpp index a6a5766..4426a1a 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -124,7 +124,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) eErrorId err; bool done = false; SYMTAB &global_symbol_table(Project::get()->symtab); - if (name.find("chkstk") != string::npos) + if (name.contains("chkstk")) { // Danger! Dcc will likely fall over in this code. // So we act as though we have done with this proc @@ -136,7 +136,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate) } if (option.VeryVerbose) { - printf("Parsing proc %s at %X\n", name.c_str(), pstate->IP); + qDebug() << "Parsing proc" << name << "at"<< QString::number(pstate->IP,16).toUpper(); } while (not done ) @@ -759,11 +759,9 @@ bool Function::process_CALL(ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *psta if (indirect) x.flg |= PROC_ICALL; - if (x.name.empty()) /* Don't overwrite existing name */ + if (x.name.isEmpty()) /* Don't overwrite existing name */ { - ostringstream os; - os<<"proc_"<< ++prog.cProcs; - x.name = os.str(); + x.name = QString("proc_%1").arg(++prog.cProcs); } x.depth = x.depth + 1; x.flg |= TERMINATES; @@ -1194,7 +1192,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate) case iMUL: case iIMUL: use(SRC, pIcode, this, pstate, cb); - if (! Imm) + if (not Imm) { use (DST, pIcode, this, pstate, cb); if (cb == 1) @@ -1231,7 +1229,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate) case iCALLF: /* Ignore def's on CS for now */ cb = 4; case iCALL: case iPUSH: case iPOP: - if (! Imm) { + if (not Imm) { if (pIcode.ll()->getOpcode() == iPOP) def(DST, pIcode, this, pstate, cb); else @@ -1269,7 +1267,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate) case iJMPF: cb = 4; case iJMP: - if (! Imm) + if (not Imm) use(SRC, pIcode, this, pstate, cb); break; @@ -1330,7 +1328,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate) case iIN: case iOUT: def(DST, pIcode, this, pstate, cb); - if (! Imm) + if (not Imm) { pIcode.du.use.addReg(rDX); } diff --git a/src/procs.cpp b/src/procs.cpp index ae9b1e8..9c07520 100644 --- a/src/procs.cpp +++ b/src/procs.cpp @@ -10,6 +10,7 @@ #include "project.h" #include "CallGraph.h" +#include #include #include @@ -66,7 +67,7 @@ bool CALL_GRAPH::insertCallGraph(Function *caller, ilFunction callee) * the nodes the procedure invokes. */ void CALL_GRAPH::writeNodeCallGraph(int indIdx) { - printf ("%s%s\n", indentStr(indIdx), proc->name.c_str()); + qDebug() << indentStr(indIdx)+proc->name; for (CALL_GRAPH *cg : outEdges) cg->writeNodeCallGraph (indIdx + 1); } @@ -178,7 +179,7 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const newsym.type = TYPE_LONG_SIGN; assert(regL!=rUNDEF); tproc->localId.id_arr[tidx].name = newsym.name; - tproc->localId.propLongId (regL, regH, tproc->localId.id_arr[tidx].name.c_str()); + tproc->localId.propLongId (regL, regH, tproc->localId.id_arr[tidx].name); } target_stackframe->push_back(newsym); target_stackframe->numArgs++; diff --git a/src/project.cpp b/src/project.cpp index 3ca433a..d60a031 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -54,7 +54,7 @@ ilFunction Project::findByEntry(uint32_t entry) return iter; } -ilFunction Project::createFunction(FunctionType *f,const std::string &name) +ilFunction Project::createFunction(FunctionType *f,const QString &name) { pProcList.push_back(Function::Create(f,0,name,0)); return (++pProcList.rbegin()).base(); @@ -87,7 +87,7 @@ hlType Project::symbolType(size_t idx) return symtab[idx].type; } -const std::string &Project::symbolName(size_t idx) +const QString &Project::symbolName(size_t idx) { assert(validSymIdx(idx)); return symtab[idx].name; diff --git a/src/reducible.cpp b/src/reducible.cpp index 08a484f..e3c3970 100644 --- a/src/reducible.cpp +++ b/src/reducible.cpp @@ -28,7 +28,7 @@ bool trivialGraph(BB *G) * from the list. Q is not an empty queue. */ static BB *firstOfQueue (queue &Q) { - assert(!Q.empty()); + assert(not Q.empty()); BB *res=Q.front(); Q.pop_front(); return res; @@ -81,7 +81,7 @@ void interval::appendNodeInt(queue &pqH, BB *node) /* Check header list for occurrence of node, if found, remove it * and decrement number of out-edges from this interval. */ - if (node->beenOnH and !pqH.empty()) + if (node->beenOnH and not pqH.empty()) { auto found_iter=std::find(pqH.begin(),pqH.end(),node); if(found_iter!=pqH.end()) @@ -113,7 +113,7 @@ void derSeq_Entry::findIntervals (Function *c) Gi->reachingInt = BB::Create(nullptr,"",c); /* ^ empty BB */ /* Process header nodes list H */ - while (!H.empty()) + while (not H.empty()) { header = firstOfQueue (H); pI = new interval; @@ -139,7 +139,7 @@ void derSeq_Entry::findIntervals (Function *c) succ->reachingInt = header; if (succ->inEdgeCount == 0) pI->appendNodeInt (H, succ); - else if (! succ->beenOnH) /* out edge */ + else if (not succ->beenOnH) /* out edge */ { appendQueue (H, succ); succ->beenOnH = true; @@ -163,7 +163,7 @@ void derSeq_Entry::findIntervals (Function *c) } /* Link interval I to list of intervals */ - if (! first) + if (not first) { m_intervals.push_back(pI); J->next = pI; @@ -311,20 +311,20 @@ bool Function::findDerivedSeq (derSeq &derivedGi) derSeq::iterator iter=derivedGi.begin(); assert(iter!=derivedGi.end()); BB *Gi = iter->Gi; /* Current derived sequence graph */ - while (! trivialGraph (Gi)) + while (not trivialGraph (Gi)) { /* Find the intervals of Gi and place them in derivedGi->Ii */ iter->findIntervals(this); /* Create Gi+1 and check if it is equivalent to Gi */ - if (! nextOrderGraph (derivedGi)) + if (not nextOrderGraph (derivedGi)) break; ++iter; Gi = iter->Gi; stats.nOrder++; } - if (! trivialGraph (Gi)) + if (not trivialGraph (Gi)) { ++iter; derivedGi.erase(iter,derivedGi.end()); /* remove Gi+1 */ @@ -368,7 +368,7 @@ derSeq * Function::checkReducibility() der_seq->back().Gi = *m_actual_cfg.begin(); /*m_cfg.front()*/; reducible = findDerivedSeq(*der_seq); - if (! reducible) + if (not reducible) { flg |= GRAPH_IRRED; m_actual_cfg.nodeSplitting(); diff --git a/src/scanner.cpp b/src/scanner.cpp index 4938ffa..374bb0f 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -214,7 +214,7 @@ static struct { { regop, axImp, 0 , iXCHG }, /* 97 */ { alImp, axImp, SRC_B | S_EXT , iSIGNEX}, /* 98 */ {axSrcIm, axImp, IM_DST | S_EXT , iSIGNEX}, /* 99 */ - { dispF, none2, 0 , iCALLF }, /* 9A */ + { dispF, none2, TO_REG , iCALLF }, /* 9A */ // TO_REG set to use SRC when processing setAddress { none1, none2, FLOAT_OP| NO_OPS , iWAIT }, /* 9B */ { none1, none2, NOT_HLL | NO_OPS , iPUSHF}, /* 9C */ { none1, none2, NOT_HLL | NO_OPS , iPOPF }, /* 9D */ @@ -508,7 +508,7 @@ LLOperand convertOperand(const x86_op_t &from) case op_register: res.regi = convertRegister(from.data.reg); break; case op_immediate: - res.opz = from.data.sdword; + res.opz = from.data.sdword; break; case op_expression: res = convertExpression(from.data.expression); break; case op_offset: @@ -630,7 +630,7 @@ static int signex(uint8_t b) static void setAddress(int i, bool fdst, uint16_t seg, int16_t reg, uint16_t off) { /* If not to register (i.e. to r/m), and talking about r/m, then this is dest */ - LLOperand *pm = ((stateTable[i].flg & TO_REG) != fdst) ? &pIcode->ll()->m_dst : &pIcode->ll()->src(); + LLOperand *pm = (! (stateTable[i].flg & TO_REG) == fdst) ? &pIcode->ll()->m_dst : &pIcode->ll()->src(); /* Set segment. A later procedure (lookupAddr in proclist.c) will * provide the value of this segment in the field segValue. @@ -973,6 +973,7 @@ static void dispF(int i) { uint16_t off = (unsigned)getWord(); uint16_t seg = (unsigned)getWord(); + // FIXME: this is wrong since seg here is seg value, but setAddress treats it as register id setAddress(i, true, seg, 0, off); // decodeBranchTgt(); } diff --git a/src/symtab.cpp b/src/symtab.cpp index 089a744..096ec58 100644 --- a/src/symtab.cpp +++ b/src/symtab.cpp @@ -133,7 +133,7 @@ void destroySymTables(void) } /* Using the value, read the symbolic name */ -bool readVal(std::ostringstream &/*symName*/, uint32_t /*symOff*/, Function * /*symProc*/) +bool readVal(QTextStream &/*symName*/, uint32_t /*symOff*/, Function * /*symProc*/) { return false; // no symbolic names for now } diff --git a/src/udm.cpp b/src/udm.cpp index bf119d1..12c8fec 100644 --- a/src/udm.cpp +++ b/src/udm.cpp @@ -4,13 +4,14 @@ * that just plays with abstract cfg's and intervals and such like. * (C) Cristina Cifuentes ****************************************************************************/ -#include -#include -#include #include "dcc.h" #include "disassem.h" #include "project.h" +#include +#include +#include +#include extern Project g_proj; //static void displayCFG(Function * pProc); //static void displayDfs(BB * pBB); @@ -60,7 +61,7 @@ void Function::controlFlowAnalysis() if (option.verbose) { - printf("\nDepth first traversal - Proc %s\n", name.c_str()); + qDebug() <<"\nDepth first traversal - Proc" <displayDfs(); //m_cfg.front()->displayDfs(); } @@ -101,7 +102,7 @@ void udm(void) ***************************************************************************/ void Function::displayCFG() { - printf("\nBasic Block List - Proc %s", name.c_str()); + qDebug() << "\nBasic Block List - Proc"<display(); diff --git a/tools/makedsig/LIB_PatternCollector.cpp b/tools/makedsig/LIB_PatternCollector.cpp index b8f93a7..bb3cddb 100644 --- a/tools/makedsig/LIB_PatternCollector.cpp +++ b/tools/makedsig/LIB_PatternCollector.cpp @@ -52,7 +52,7 @@ int LIB_PatternCollector::readSyms(FILE *fl) exit(10); } - while (!feof(fl)) + while (not feof(fl)) { type = readByte(fl); len = readWord(fl);