Normalize logic operation keywords and add use msvc fix

Logical or should be only 'or','and','not', and not error prone
'||','&&','!'
This commit is contained in:
nemerle 2016-04-25 11:39:07 +02:00
parent 3f217e83da
commit 9cd3226536
45 changed files with 2670 additions and 2568 deletions

View File

@ -12,6 +12,7 @@
*/ */
#include "perfhlib.h" #include "perfhlib.h"
#include "PatternCollector.h" #include "PatternCollector.h"
#include "msvc_fixes.h"
#include <stdio.h> #include <stdio.h>
#include <cassert> #include <cassert>
@ -38,9 +39,6 @@ static bool *visited; /* Array of bools: whether visited */
static bool *deleted; /* Array of bools: whether deleted */ static bool *deleted; /* Array of bools: whether deleted */
/* Private prototypes */ /* Private prototypes */
static void initGraph(void);
static void addToGraph(int e, int v1, int v2);
static bool isCycle(void);
static void duplicateKeys(int v1, int v2); static void duplicateKeys(int v1, int v2);
void PerfectHash::setHashParams(int _NumEntry, int _EntryLen, int _SetSize, char _SetMin, void PerfectHash::setHashParams(int _NumEntry, int _EntryLen, int _SetSize, char _SetMin,
@ -157,7 +155,7 @@ void PerfectHash::map(PatternCollector *collector)
} }
addToGraph(numEdges++, f1, f2); addToGraph(numEdges++, f1, f2);
} }
if (cycle || (cycle = isCycle())) /* OK - is there a cycle? */ if (cycle or (cycle = isCycle())) /* OK - is there a cycle? */
{ {
printf("Iteration %d\n", ++c); printf("Iteration %d\n", ++c);
} }
@ -314,7 +312,7 @@ bool PerfectHash::isCycle(void)
} }
for (v=1; v <= NumVert; v++) for (v=1; v <= NumVert; v++)
{ {
if (!visited[v]) if (not visited[v])
{ {
if (DFS(-32767, v)) if (DFS(-32767, v))
{ {
@ -415,7 +413,7 @@ duplicateKeys(int v1, int v2)
u += T1[keys[j] - SetMin]; u += T1[keys[j] - SetMin];
} }
u %= NumVert; u %= NumVert;
if ((u != v1) && (u != v2)) continue; if ((u != v1) and (u != v2)) continue;
v = 0; v = 0;
for (j=0; j < EntryLen; j++) for (j=0; j < EntryLen; j++)
@ -425,7 +423,7 @@ duplicateKeys(int v1, int v2)
} }
v %= NumVert; v %= NumVert;
if ((v == v2) || (v == v1)) if ((v == v2) or (v == v1))
{ {
printf("Entry #%d key: ", i+1); printf("Entry #%d key: ", i+1);
for (j=0; j < EntryLen; j++) printf("%02X ", keys[j]); for (j=0; j < EntryLen; j++) printf("%02X ", keys[j]);

View File

@ -5,11 +5,15 @@
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
*/ */
#pragma once #pragma once
#include "Enums.h"
#include "msvc_fixes.h"
#include <boost/range/iterator_range.hpp>
#include <stdint.h> #include <stdint.h>
#include <cstring> #include <cstring>
#include <list> #include <list>
#include <boost/range/iterator_range.hpp>
#include "Enums.h"
static const int operandSize=20; static const int operandSize=20;
/* The following definitions and types define the Conditional Expression /* The following definitions and types define the Conditional Expression
* attributed syntax tree, as defined by the following EBNF: * attributed syntax tree, as defined by the following EBNF:
@ -120,7 +124,7 @@ struct BinaryOperator : public Expr
} }
~BinaryOperator() ~BinaryOperator()
{ {
assert(m_lhs!=m_rhs || m_lhs==nullptr); assert(m_lhs!=m_rhs or m_lhs==nullptr);
delete m_lhs; delete m_lhs;
delete m_rhs; delete m_rhs;
m_lhs=m_rhs=nullptr; m_lhs=m_rhs=nullptr;

View File

@ -9,6 +9,7 @@
#include <vector> #include <vector>
#include "bundle.h" #include "bundle.h"
struct LLInst; struct LLInst;
struct Function;
struct Disassembler struct Disassembler
{ {
protected: protected:

View File

@ -3,6 +3,19 @@
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
#include "msvc_fixes.h"
#include "BinaryImage.h"
#include "libdis.h"
#include "Enums.h"
#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 <memory> #include <memory>
#include <vector> #include <vector>
#include <list> #include <list>
@ -10,15 +23,6 @@
#include <set> #include <set>
#include <algorithm> #include <algorithm>
#include <initializer_list> #include <initializer_list>
#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 "libdis.h"
#include "Enums.h"
#include "state.h" // State depends on INDEXBASE, but later need STATE
#include "CallConvention.h"
//enum condId; //enum condId;
@ -275,12 +279,12 @@ struct LLOperand
} }
bool operator==(const LLOperand &with) const bool operator==(const LLOperand &with) const
{ {
return (seg==with.seg) && return (seg==with.seg) and
(segOver==with.segOver) && (segOver==with.segOver) and
(segValue==with.segValue) && (segValue==with.segValue) and
(regi == with.regi) && (regi == with.regi) and
(off == with.off) && (off == with.off) and
(opz==with.opz) && (opz==with.opz) and
(proc.proc==with.proc.proc); (proc.proc==with.proc.proc);
} }
int64_t getImm2() const {return opz;} int64_t getImm2() const {return opz;}
@ -330,7 +334,7 @@ public:
int hllLabNum; /* label # for hll codegen */ int hllLabNum; /* label # for hll codegen */
bool conditionalJump() bool conditionalJump()
{ {
return (getOpcode() >= iJB) && (getOpcode() < iJCXZ); return (getOpcode() >= iJB) and (getOpcode() < iJCXZ);
} }
bool testFlags(uint32_t x) const { return (flg & x)!=0;} bool testFlags(uint32_t x) const { return (flg & x)!=0;}
void setFlags(uint32_t flag) {flg |= flag;} void setFlags(uint32_t flag) {flg |= flag;}
@ -366,11 +370,11 @@ public:
} }
bool match(llIcode op,eReg dest,eReg src_reg) bool match(llIcode op,eReg dest,eReg src_reg)
{ {
return (getOpcode()==op)&&(m_dst.regi==dest)&&(m_src.regi==src_reg); return (getOpcode()==op) and (m_dst.regi==dest) and (m_src.regi==src_reg);
} }
bool match(eReg dest,eReg src_reg) bool match(eReg dest,eReg src_reg)
{ {
return (m_dst.regi==dest)&&(m_src.regi==src_reg); return (m_dst.regi==dest) and (m_src.regi==src_reg);
} }
bool match(eReg dest) bool match(eReg dest)
{ {
@ -460,14 +464,14 @@ public:
template<int TYPE> template<int TYPE>
struct TypeFilter struct TypeFilter
{ {
bool operator()(ICODE *ic) {return ic->type==HIGH_LEVEL;} bool operator()(ICODE *ic) {return ic->type==TYPE;}
bool operator()(ICODE &ic) {return ic.type==HIGH_LEVEL;} bool operator()(ICODE &ic) {return ic.type==TYPE;}
}; };
template<int TYPE> template<int TYPE>
struct TypeAndValidFilter struct TypeAndValidFilter
{ {
bool operator()(ICODE *ic) {return (ic->type==HIGH_LEVEL)&&(ic->valid());} bool operator()(ICODE *ic) {return (ic->type==TYPE) and (ic->valid());}
bool operator()(ICODE &ic) {return (ic.type==HIGH_LEVEL)&&ic.valid();} bool operator()(ICODE &ic) {return (ic.type==TYPE) and ic.valid();}
}; };
static TypeFilter<HIGH_LEVEL> select_high_level; static TypeFilter<HIGH_LEVEL> select_high_level;
static TypeAndValidFilter<HIGH_LEVEL> select_valid_high_level; static TypeAndValidFilter<HIGH_LEVEL> select_valid_high_level;
@ -506,7 +510,7 @@ public:
if(iter==uses.end()) if(iter==uses.end())
return; return;
uses.erase(iter); uses.erase(iter);
assert("Same user more then once!" && uses.end()==std::find(uses.begin(),uses.end(),us)); assert("Same user more then once!" and uses.end()==std::find(uses.begin(),uses.end(),us));
} }
}; };

View File

@ -6,14 +6,16 @@
*/ */
#pragma once #pragma once
#include "msvc_fixes.h"
#include "types.h"
#include "Enums.h"
#include "machine_x86.h"
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
#include <list> #include <list>
#include <set> #include <set>
#include <algorithm> #include <algorithm>
#include "types.h"
#include "Enums.h"
#include "machine_x86.h"
/* Type definition */ /* Type definition */
// this array has to stay in-order of addition i.e. not std::set<iICODE,std::less<iICODE> > // this array has to stay in-order of addition i.e. not std::set<iICODE,std::less<iICODE> >
@ -105,11 +107,11 @@ public:
protected: protected:
LONG_STKID_TYPE longStkId; /* For TYPE_LONG_(UN)SIGN on the stack */ LONG_STKID_TYPE longStkId; /* For TYPE_LONG_(UN)SIGN on the stack */
public: public:
eReg regi; /* For TYPE_BYTE(uint16_t)_(UN)SIGN registers */ eReg regi; /* For TYPE_BYTE(WORD)_(UN)SIGN registers */
struct { /* For TYPE_BYTE(uint16_t)_(UN)SIGN on the stack */ struct { /* For TYPE_BYTE(WORD)_(UN)SIGN on the stack */
uint8_t regOff; /* register offset (if any) */ uint8_t regOff; /* register offset (if any) */
int off; /* offset from BP */ int off; /* offset from BP */
} bwId; } bwId;
BWGLB_TYPE bwGlb; /* For TYPE_BYTE(uint16_t)_(UN)SIGN globals */ BWGLB_TYPE bwGlb; /* For TYPE_BYTE(uint16_t)_(UN)SIGN globals */
LONGGLB_TYPE longGlb; LONGGLB_TYPE longGlb;
struct { /* For TYPE_LONG_(UN)SIGN constants */ struct { /* For TYPE_LONG_(UN)SIGN constants */
@ -118,21 +120,22 @@ public:
} longKte; } longKte;
ID_UNION() { /*new (&longStkId) LONG_STKID_TYPE();*/} ID_UNION() { /*new (&longStkId) LONG_STKID_TYPE();*/}
} id; } id;
LONGID_TYPE & longId() {assert(isLong() && loc==REG_FRAME); return m_longId;}
const LONGID_TYPE & longId() const {assert(isLong() && loc==REG_FRAME); return m_longId;} LONGID_TYPE & longId() {assert(isLong() and loc==REG_FRAME); return m_longId;}
LONG_STKID_TYPE & longStkId() {assert(isLong() && loc==STK_FRAME); return id.longStkId;} const LONGID_TYPE & longId() const {assert(isLong() and loc==REG_FRAME); return m_longId;}
const LONG_STKID_TYPE & longStkId() const {assert(isLong() && loc==STK_FRAME); return id.longStkId;} LONG_STKID_TYPE & longStkId() {assert(isLong() and loc==STK_FRAME); return id.longStkId;}
const LONG_STKID_TYPE & longStkId() const {assert(isLong() and loc==STK_FRAME); return id.longStkId;}
ID(); ID();
ID(hlType t, frameType f); ID(hlType t, frameType f);
ID(hlType t, const LONGID_TYPE &s); ID(hlType t, const LONGID_TYPE &s);
ID(hlType t, const LONG_STKID_TYPE &s); ID(hlType t, const LONG_STKID_TYPE &s);
ID(hlType t, const LONGGLB_TYPE &s); ID(hlType t, const LONGGLB_TYPE &s);
bool isSigned() const { return (type==TYPE_BYTE_SIGN)||(type==TYPE_WORD_SIGN)||(type==TYPE_LONG_SIGN);} bool isSigned() const { return (type==TYPE_BYTE_SIGN) or (type==TYPE_WORD_SIGN) or (type==TYPE_LONG_SIGN);}
uint16_t typeBitsize() const uint16_t typeBitsize() const
{ {
return TypeContainer::typeSize(type)*8; return TypeContainer::typeSize(type)*8;
} }
bool isLong() const { return (type==TYPE_LONG_UNSIGN)||(type==TYPE_LONG_SIGN); } bool isLong() const { return (type==TYPE_LONG_UNSIGN) or (type==TYPE_LONG_SIGN); }
void setLocalName(int i) void setLocalName(int i)
{ {
char buf[32]; char buf[32];

View File

@ -3,10 +3,12 @@
* (C) Mike van Emmerik * (C) Mike van Emmerik
*/ */
#pragma once #pragma once
#include <string>
#include <stdint.h>
#include "Enums.h" #include "Enums.h"
#include "types.h" #include "types.h"
#include "msvc_fixes.h"
#include <string>
#include <stdint.h>
struct Expr; struct Expr;
struct AstIdent; struct AstIdent;
struct TypeContainer; struct TypeContainer;
@ -91,7 +93,7 @@ struct SYMTABLE
{ {
// does not yse pSymName, to ease finding by symOff/symProc combo // does not yse pSymName, to ease finding by symOff/symProc combo
// in map<SYMTABLE,X> // in map<SYMTABLE,X>
return (symOff==other.symOff) && symProc==(other.symProc); return (symOff==other.symOff) and symProc==(other.symProc);
} }
}; };

View File

@ -5,9 +5,13 @@
*************************************************************************** ***************************************************************************
*/ */
#pragma once #pragma once
#include "Enums.h"
#include "msvc_fixes.h"
#include <cassert> #include <cassert>
#include <stdint.h> #include <stdint.h>
#include "Enums.h" #include <stdlib.h>
/**** Common definitions and macros ****/ /**** Common definitions and macros ****/
#define MAX 0x7FFFFFFF #define MAX 0x7FFFFFFF
@ -25,7 +29,7 @@
// Macro reads a LH word from the image regardless of host convention // Macro reads a LH word from the image regardless of host convention
// Returns a 16 bit quantity, e.g. C000 is read into an Int as C000 // Returns a 16 bit quantity, e.g. C000 is read into an Int as C000
//#define LH(p) ((int16)((byte *)(p))[0] + ((int16)((byte *)(p))[1] << 8)) //#define LH(p) ((int16)((byte *)(p))[0] + ((int16)((byte *)(p))[1] << 8))
#define LH(p) ((uint16_t)((uint8_t *)(p))[0] + ((uint16_t)((uint8_t *)(p))[1] << 8)) #define LH(p) ((uint16_t)((uint8_t *)(p))[0] + ((uint16_t)((uint8_t *)(p))[1] << 8))
/* Macro reads a LH word from the image regardless of host convention */ /* Macro reads a LH word from the image regardless of host convention */
@ -64,12 +68,22 @@ struct eDuVal
use = x&USE; use = x&USE;
val = x&VAL; val = x&VAL;
} }
bool isUSE_VAL() {return use&&val;} //Use and Val bool isUSE_VAL() {return use and val;} //Use and Val
}; };
static constexpr const char * hlTypes[13] = { static constexpr const char * hlTypes[13] = {
"", "char", "unsigned char", "int", "unsigned int", "",
"long", "unsigned long", "record", "int *", "char *", "char",
"", "float", "double" "unsigned char",
"int",
"unsigned int",
"long",
"unsigned long",
"record",
"int *",
"char *",
"",
"float",
"double"
}; };
struct TypeContainer struct TypeContainer

View File

@ -1,11 +1,15 @@
#include "BasicBlock.h"
#include "msvc_fixes.h"
#include "Procedure.h"
#include "dcc.h"
#include "msvc_fixes.h"
#include <cassert> #include <cassert>
#include <string> #include <string>
#include <boost/range/rbegin.hpp> #include <boost/range/rbegin.hpp>
#include <boost/range/rend.hpp> #include <boost/range/rend.hpp>
#include <boost/range/adaptors.hpp> #include <boost/range/adaptors.hpp>
#include "BasicBlock.h"
#include "Procedure.h"
#include "dcc.h"
using namespace std; using namespace std;
using namespace boost; using namespace boost;
@ -189,8 +193,8 @@ ICODE* BB::writeLoopHeader(int &indLevel, Function* pProc, int *numLoc, BB *&lat
} }
bool BB::isEndOfPath(int latch_node_idx) const bool BB::isEndOfPath(int latch_node_idx) const
{ {
return nodeType == RETURN_NODE || nodeType == TERMINATE_NODE || return nodeType == RETURN_NODE or nodeType == TERMINATE_NODE or
nodeType == NOWHERE_NODE || (dfsLastNum == latch_node_idx); nodeType == NOWHERE_NODE or dfsLastNum == latch_node_idx;
} }
void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, int _ifFollow) void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode, int _ifFollow)
{ {
@ -202,7 +206,7 @@ void BB::writeCode (int indLevel, Function * pProc , int *numLoc,int _latchNode,
repCond; /* Repeat condition for while() */ repCond; /* Repeat condition for while() */
/* Check if this basic block should be analysed */ /* Check if this basic block should be analysed */
if ((_ifFollow != UN_INIT) && (this == pProc->m_dfsLast[_ifFollow])) if ((_ifFollow != UN_INIT) and (this == pProc->m_dfsLast[_ifFollow]))
return; return;
if (wasTraversedAtLevel(DFS_ALPHA)) if (wasTraversedAtLevel(DFS_ALPHA))
@ -380,7 +384,7 @@ void BB::writeBB(std::ostream &ostr,int lev, Function * pProc, int *numLoc)
for(ICODE &pHli : instructions) for(ICODE &pHli : instructions)
{ {
if ((pHli.type == HIGH_LEVEL) && ( pHli.valid() )) //TODO: use filtering range here. if ((pHli.type == HIGH_LEVEL) and ( pHli.valid() )) //TODO: use filtering range here.
{ {
std::string line = pHli.hl()->write1HlIcode(pProc, numLoc); std::string line = pHli.hl()->write1HlIcode(pProc, numLoc);
if (!line.empty()) if (!line.empty())

View File

@ -7,11 +7,11 @@ CConv *CConv::create(Type v)
static C_CallingConvention *c_call = nullptr; static C_CallingConvention *c_call = nullptr;
static Pascal_CallingConvention *p_call = nullptr; static Pascal_CallingConvention *p_call = nullptr;
static Unknown_CallingConvention *u_call= nullptr; static Unknown_CallingConvention *u_call= nullptr;
if(!c_call) if(nullptr==c_call)
c_call = new C_CallingConvention; c_call = new C_CallingConvention;
if(!p_call) if(nullptr==p_call)
p_call = new Pascal_CallingConvention; p_call = new Pascal_CallingConvention;
if(!u_call) if(nullptr==u_call)
u_call = new Unknown_CallingConvention; u_call = new Unknown_CallingConvention;
switch(v) { switch(v) {
case UNKNOWN: return u_call; case UNKNOWN: return u_call;

View File

@ -1,413 +1,414 @@
#include "dcc.h" #include "DccFrontend.h"
#include "DccFrontend.h"
#include "project.h" #include "dcc.h"
#include "disassem.h" #include "msvc_fixes.h"
#include "CallGraph.h" #include "project.h"
#include "disassem.h"
#include <QtCore/QFileInfo> #include "CallGraph.h"
#include <QtCore/QDebug>
#include <QtCore/QFileInfo>
#include <cstdio> #include <QtCore/QDebug>
#include <cstdio>
class Loader
{ class Loader
bool loadIntoProject(IProject *); {
}; bool loadIntoProject(IProject *);
};
struct PSP { /* PSP structure */
uint16_t int20h; /* interrupt 20h */ struct PSP { /* PSP structure */
uint16_t eof; /* segment, end of allocation block */ uint16_t int20h; /* interrupt 20h */
uint8_t res1; /* reserved */ uint16_t eof; /* segment, end of allocation block */
uint8_t dosDisp[5]; /* far call to DOS function dispatcher */ uint8_t res1; /* reserved */
uint8_t int22h[4]; /* vector for terminate routine */ uint8_t dosDisp[5]; /* far call to DOS function dispatcher */
uint8_t int23h[4]; /* vector for ctrl+break routine */ uint8_t int22h[4]; /* vector for terminate routine */
uint8_t int24h[4]; /* vector for error routine */ uint8_t int23h[4]; /* vector for ctrl+break routine */
uint8_t res2[22]; /* reserved */ uint8_t int24h[4]; /* vector for error routine */
uint16_t segEnv; /* segment address of environment block */ uint8_t res2[22]; /* reserved */
uint8_t res3[34]; /* reserved */ uint16_t segEnv; /* segment address of environment block */
uint8_t int21h[6]; /* opcode for int21h and far return */ uint8_t res3[34]; /* reserved */
uint8_t res4[6]; /* reserved */ uint8_t int21h[6]; /* opcode for int21h and far return */
uint8_t fcb1[16]; /* default file control block 1 */ uint8_t res4[6]; /* reserved */
uint8_t fcb2[16]; /* default file control block 2 */ uint8_t fcb1[16]; /* default file control block 1 */
uint8_t res5[4]; /* reserved */ uint8_t fcb2[16]; /* default file control block 2 */
uint8_t cmdTail[0x80]; /* command tail and disk transfer area */ uint8_t res5[4]; /* reserved */
}; uint8_t cmdTail[0x80]; /* command tail and disk transfer area */
};
static struct MZHeader { /* EXE file header */
uint8_t sigLo; /* .EXE signature: 0x4D 0x5A */ static struct MZHeader { /* EXE file header */
uint8_t sigHi; uint8_t sigLo; /* .EXE signature: 0x4D 0x5A */
uint16_t lastPageSize; /* Size of the last page */ uint8_t sigHi;
uint16_t numPages; /* Number of pages in the file */ uint16_t lastPageSize; /* Size of the last page */
uint16_t numReloc; /* Number of relocation items */ uint16_t numPages; /* Number of pages in the file */
uint16_t numParaHeader; /* # of paragraphs in the header */ uint16_t numReloc; /* Number of relocation items */
uint16_t minAlloc; /* Minimum number of paragraphs */ uint16_t numParaHeader; /* # of paragraphs in the header */
uint16_t maxAlloc; /* Maximum number of paragraphs */ uint16_t minAlloc; /* Minimum number of paragraphs */
uint16_t initSS; /* Segment displacement of stack */ uint16_t maxAlloc; /* Maximum number of paragraphs */
uint16_t initSP; /* Contents of SP at entry */ uint16_t initSS; /* Segment displacement of stack */
uint16_t checkSum; /* Complemented checksum */ uint16_t initSP; /* Contents of SP at entry */
uint16_t initIP; /* Contents of IP at entry */ uint16_t checkSum; /* Complemented checksum */
uint16_t initCS; /* Segment displacement of code */ uint16_t initIP; /* Contents of IP at entry */
uint16_t relocTabOffset; /* Relocation table offset */ uint16_t initCS; /* Segment displacement of code */
uint16_t overlayNum; /* Overlay number */ uint16_t relocTabOffset; /* Relocation table offset */
} header; uint16_t overlayNum; /* Overlay number */
} header;
#define EXE_RELOCATION 0x10 /* EXE images rellocated to above PSP */
#define EXE_RELOCATION 0x10 /* EXE images rellocated to above PSP */
//static void LoadImage(char *filename);
static void displayMemMap(void); //static void LoadImage(char *filename);
/**************************************************************************** static void displayMemMap(void);
* displayLoadInfo - Displays low level loader type info. /****************************************************************************
***************************************************************************/ * displayLoadInfo - Displays low level loader type info.
void PROG::displayLoadInfo(void) ***************************************************************************/
{ void PROG::displayLoadInfo(void)
int i; {
int i;
printf("File type is %s\n", (fCOM)?"COM":"EXE");
if (! fCOM) { printf("File type is %s\n", (fCOM)?"COM":"EXE");
printf("Signature = %02X%02X\n", header.sigLo, header.sigHi); if (not fCOM) {
printf("File size %% 512 = %04X\n", LH(&header.lastPageSize)); printf("Signature = %02X%02X\n", header.sigLo, header.sigHi);
printf("File size / 512 = %04X pages\n", LH(&header.numPages)); printf("File size %% 512 = %04X\n", LH(&header.lastPageSize));
printf("# relocation items = %04X\n", LH(&header.numReloc)); printf("File size / 512 = %04X pages\n", LH(&header.numPages));
printf("Offset to load image = %04X paras\n", LH(&header.numParaHeader)); printf("# relocation items = %04X\n", LH(&header.numReloc));
printf("Minimum allocation = %04X paras\n", LH(&header.minAlloc)); printf("Offset to load image = %04X paras\n", LH(&header.numParaHeader));
printf("Maximum allocation = %04X paras\n", LH(&header.maxAlloc)); 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 - sizeof(PSP)); }
printf("Initial SS:SP = %04X:%04X\n", initSS, initSP); printf("Load image size = %04" PRIiPTR "\n", cbImage - sizeof(PSP));
printf("Initial CS:IP = %04X:%04X\n", initCS, initIP); printf("Initial SS:SP = %04X:%04X\n", initSS, initSP);
printf("Initial CS:IP = %04X:%04X\n", initCS, initIP);
if (option.VeryVerbose && cReloc)
{ if (option.VeryVerbose and cReloc)
printf("\nRelocation Table\n"); {
for (i = 0; i < cReloc; i++) printf("\nRelocation Table\n");
{ for (i = 0; i < cReloc; i++)
printf("%06X -> [%04X]\n", relocTable[i],LH(image() + relocTable[i])); {
} printf("%06X -> [%04X]\n", relocTable[i],LH(image() + relocTable[i]));
} }
printf("\n"); }
} printf("\n");
}
/*****************************************************************************
* fill - Fills line for displayMemMap() /*****************************************************************************
****************************************************************************/ * fill - Fills line for displayMemMap()
static void fill(int ip, char *bf) ****************************************************************************/
{ static void fill(int ip, char *bf)
PROG &prog(Project::get()->prog); {
static uint8_t type[4] = {'.', 'd', 'c', 'x'}; PROG &prog(Project::get()->prog);
uint8_t i; static uint8_t type[4] = {'.', 'd', 'c', 'x'};
uint8_t i;
for (i = 0; i < 16; i++, ip++)
{ for (i = 0; i < 16; i++, ip++)
*bf++ = ' '; {
*bf++ = (ip < prog.cbImage)? type[(prog.map[ip >> 2] >> ((ip & 3) * 2)) & 3]: ' '; *bf++ = ' ';
} *bf++ = (ip < prog.cbImage)? type[(prog.map[ip >> 2] >> ((ip & 3) * 2)) & 3]: ' ';
*bf = '\0'; }
} *bf = '\0';
}
/*****************************************************************************
* displayMemMap - Displays the memory bitmap /*****************************************************************************
****************************************************************************/ * displayMemMap - Displays the memory bitmap
static void displayMemMap(void) ****************************************************************************/
{ static void displayMemMap(void)
PROG &prog(Project::get()->prog); {
PROG &prog(Project::get()->prog);
char c, b1[33], b2[33], b3[33];
uint8_t i; char c, b1[33], b2[33], b3[33];
int ip = 0; uint8_t i;
int ip = 0;
printf("\nMemory Map\n");
while (ip < prog.cbImage) printf("\nMemory Map\n");
{ while (ip < prog.cbImage)
fill(ip, b1); {
printf("%06X %s\n", ip, b1); fill(ip, b1);
ip += 16; printf("%06X %s\n", ip, b1);
for (i = 3, c = b1[1]; i < 32 && c == b1[i]; i += 2) ip += 16;
; /* Check if all same */ for (i = 3, c = b1[1]; i < 32 and c == b1[i]; i += 2)
if (i > 32) ; /* Check if all same */
{ if (i > 32)
fill(ip, b2); /* Skip until next two are not same */ {
fill(ip+16, b3); fill(ip, b2); /* Skip until next two are not same */
if (! (strcmp(b1, b2) || strcmp(b1, b3))) fill(ip+16, b3);
{ if (not (strcmp(b1, b2) || strcmp(b1, b3)))
printf(" :\n"); {
do printf(" :\n");
{ do
ip += 16; {
fill(ip+16, b1); ip += 16;
} while (! strcmp(b1, b2)); fill(ip+16, b1);
} } while (0==strcmp(b1, b2));
} }
} }
printf("\n"); }
} printf("\n");
DccFrontend::DccFrontend(QObject *parent) : }
QObject(parent) DccFrontend::DccFrontend(QObject *parent) :
{ QObject(parent)
} {
}
/*****************************************************************************
* FrontEnd - invokes the loader, parser, disassembler (if asm1), icode /*****************************************************************************
* rewritter, and displays any useful information. * FrontEnd - invokes the loader, parser, disassembler (if asm1), icode
****************************************************************************/ * rewritter, and displays any useful information.
bool DccFrontend::FrontEnd () ****************************************************************************/
{ bool DccFrontend::FrontEnd ()
{
/* Do depth first flow analysis building call graph and procedure list,
* and attaching the I-code to each procedure */ /* Do depth first flow analysis building call graph and procedure list,
parse (*Project::get()); * and attaching the I-code to each procedure */
parse (*Project::get());
if (option.asm1)
{ if (option.asm1)
qWarning() << "dcc: writing assembler file "<<asm1_name<<'\n'; {
} qWarning() << "dcc: writing assembler file "<<asm1_name<<'\n';
}
/* Search through code looking for impure references and flag them */
Disassembler ds(1); /* Search through code looking for impure references and flag them */
for(Function &f : Project::get()->pProcList) Disassembler ds(1);
{ for(Function &f : Project::get()->pProcList)
f.markImpure(); {
if (option.asm1) f.markImpure();
{ if (option.asm1)
ds.disassem(&f); {
} ds.disassem(&f);
} }
if (option.Interact) }
{ if (option.Interact)
interactDis(&Project::get()->pProcList.front(), 0); /* Interactive disassembler */ {
} interactDis(&Project::get()->pProcList.front(), 0); /* Interactive disassembler */
}
/* Converts jump target addresses to icode offsets */
for(Function &f : Project::get()->pProcList) /* Converts jump target addresses to icode offsets */
{ for(Function &f : Project::get()->pProcList)
f.bindIcodeOff(); {
} f.bindIcodeOff();
/* Print memory bitmap */ }
if (option.Map) /* Print memory bitmap */
displayMemMap(); if (option.Map)
return(true); // we no longer own proj ! displayMemMap();
} return(true); // we no longer own proj !
struct DosLoader { }
protected: struct DosLoader {
void prepareImage(PROG &prog,size_t sz,QFile &fp) { protected:
/* Allocate a block of memory for the program. */ void prepareImage(PROG &prog,size_t sz,QFile &fp) {
prog.cbImage = sz + sizeof(PSP); /* Allocate a block of memory for the program. */
prog.Imagez = new uint8_t [prog.cbImage]; prog.cbImage = sz + sizeof(PSP);
prog.Imagez[0] = 0xCD; /* Fill in PSP int 20h location */ prog.Imagez = new uint8_t [prog.cbImage];
prog.Imagez[1] = 0x20; /* for termination checking */ prog.Imagez[0] = 0xCD; /* Fill in PSP int 20h location */
/* Read in the image past where a PSP would go */ prog.Imagez[1] = 0x20; /* for termination checking */
if (sz != fp.read((char *)prog.Imagez + sizeof(PSP),sz)) /* Read in the image past where a PSP would go */
fatalError(CANNOT_READ, fp.fileName().toLocal8Bit().data()); if (sz != fp.read((char *)prog.Imagez + sizeof(PSP),sz))
} fatalError(CANNOT_READ, fp.fileName().toLocal8Bit().data());
}; }
struct ComLoader : public DosLoader { };
bool canLoad(QFile &fp) { struct ComLoader : public DosLoader {
fp.seek(0); bool canLoad(QFile &fp) {
char sig[2]; fp.seek(0);
if(2==fp.read(sig,2)) { char sig[2];
return not (sig[0] == 0x4D && sig[1] == 0x5A); if(2==fp.read(sig,2)) {
} return not (sig[0] == 0x4D and sig[1] == 0x5A);
return false; }
} return false;
bool load(PROG &prog,QFile &fp) { }
fp.seek(0); bool load(PROG &prog,QFile &fp) {
/* COM file fp.seek(0);
* In this case the load module size is just the file length /* COM file
*/ * In this case the load module size is just the file length
auto cb = fp.size(); */
auto cb = fp.size();
/* COM programs start off with an ORG 100H (to leave room for a PSP)
* This is also the implied start address so if we load the image /* COM programs start off with an ORG 100H (to leave room for a PSP)
* at offset 100H addresses should all line up properly again. * This is also the implied start address so if we load the image
*/ * at offset 100H addresses should all line up properly again.
prog.initCS = 0; */
prog.initIP = 0x100; prog.initCS = 0;
prog.initSS = 0; prog.initIP = 0x100;
prog.initSP = 0xFFFE; prog.initSS = 0;
prog.cReloc = 0; prog.initSP = 0xFFFE;
prog.cReloc = 0;
prepareImage(prog,cb,fp);
prepareImage(prog,cb,fp);
/* Set up memory map */
cb = (prog.cbImage + 3) / 4; /* Set up memory map */
prog.map = (uint8_t *)malloc(cb); cb = (prog.cbImage + 3) / 4;
memset(prog.map, BM_UNKNOWN, (size_t)cb); prog.map = (uint8_t *)malloc(cb);
return true; memset(prog.map, BM_UNKNOWN, (size_t)cb);
} return true;
}; }
struct ExeLoader : public DosLoader { };
bool canLoad(QFile &fp) { struct ExeLoader : public DosLoader {
if(fp.size()<sizeof(header)) bool canLoad(QFile &fp) {
return false; if(fp.size()<sizeof(header))
MZHeader tmp_header; return false;
fp.seek(0); MZHeader tmp_header;
fp.read((char *)&tmp_header, sizeof(header)); fp.seek(0);
if(not (tmp_header.sigLo == 0x4D && tmp_header.sigHi == 0x5A)) fp.read((char *)&tmp_header, sizeof(header));
return false; if(not (tmp_header.sigLo == 0x4D and tmp_header.sigHi == 0x5A))
return false;
/* This is a typical DOS kludge! */
if (LH(&header.relocTabOffset) == 0x40) /* This is a typical DOS kludge! */
{ if (LH(&header.relocTabOffset) == 0x40)
qDebug() << "Don't understand new EXE format"; {
return false; qDebug() << "Don't understand new EXE format";
} return false;
return true; }
} return true;
bool load(PROG &prog,QFile &fp) { }
/* Read rest of header */ bool load(PROG &prog,QFile &fp) {
fp.seek(0); /* Read rest of header */
if (fp.read((char *)&header, sizeof(header)) != sizeof(header)) fp.seek(0);
return false; if (fp.read((char *)&header, sizeof(header)) != sizeof(header))
return false;
/* Calculate the load module size.
* This is the number of pages in the file /* Calculate the load module size.
* less the length of the header and reloc table * This is the number of pages in the file
* less the number of bytes unused on last page * less the length of the header and reloc table
*/ * less the number of bytes unused on last page
uint32_t cb = (uint32_t)LH(&header.numPages) * 512 - (uint32_t)LH(&header.numParaHeader) * 16; */
if (header.lastPageSize) uint32_t cb = (uint32_t)LH(&header.numPages) * 512 - (uint32_t)LH(&header.numParaHeader) * 16;
{ if (header.lastPageSize)
cb -= 512 - LH(&header.lastPageSize); {
} cb -= 512 - LH(&header.lastPageSize);
}
/* We quietly ignore minAlloc and maxAlloc since for our
* purposes it doesn't really matter where in real memory /* We quietly ignore minAlloc and maxAlloc since for our
* the program would end up. EXE programs can't really rely on * purposes it doesn't really matter where in real memory
* their load location so setting the PSP segment to 0 is fine. * the program would end up. EXE programs can't really rely on
* Certainly programs that prod around in DOS or BIOS are going * their load location so setting the PSP segment to 0 is fine.
* to have to load DS from a constant so it'll be pretty * Certainly programs that prod around in DOS or BIOS are going
* obvious. * to have to load DS from a constant so it'll be pretty
*/ * obvious.
prog.initCS = (int16_t)LH(&header.initCS) + EXE_RELOCATION; */
prog.initIP = (int16_t)LH(&header.initIP); prog.initCS = (int16_t)LH(&header.initCS) + EXE_RELOCATION;
prog.initSS = (int16_t)LH(&header.initSS) + EXE_RELOCATION; prog.initIP = (int16_t)LH(&header.initIP);
prog.initSP = (int16_t)LH(&header.initSP); prog.initSS = (int16_t)LH(&header.initSS) + EXE_RELOCATION;
prog.cReloc = (int16_t)LH(&header.numReloc); prog.initSP = (int16_t)LH(&header.initSP);
prog.cReloc = (int16_t)LH(&header.numReloc);
/* Allocate the relocation table */
if (prog.cReloc) /* Allocate the relocation table */
{ if (prog.cReloc)
prog.relocTable.resize(prog.cReloc); {
fp.seek(LH(&header.relocTabOffset)); prog.relocTable.resize(prog.cReloc);
fp.seek(LH(&header.relocTabOffset));
/* Read in seg:offset pairs and convert to Image ptrs */
uint8_t buf[4]; /* Read in seg:offset pairs and convert to Image ptrs */
for (int i = 0; i < prog.cReloc; i++) uint8_t buf[4];
{ for (int i = 0; i < prog.cReloc; i++)
fp.read((char *)buf,4); {
prog.relocTable[i] = LH(buf) + (((int)LH(buf+2) + EXE_RELOCATION)<<4); fp.read((char *)buf,4);
} prog.relocTable[i] = LH(buf) + (((int)LH(buf+2) + EXE_RELOCATION)<<4);
} }
/* Seek to start of image */ }
uint32_t start_of_image= LH(&header.numParaHeader) * 16; /* Seek to start of image */
fp.seek(start_of_image); uint32_t start_of_image= LH(&header.numParaHeader) * 16;
/* Allocate a block of memory for the program. */ fp.seek(start_of_image);
prepareImage(prog,cb,fp); /* Allocate a block of memory for the program. */
prepareImage(prog,cb,fp);
/* Set up memory map */
cb = (prog.cbImage + 3) / 4; /* Set up memory map */
prog.map = (uint8_t *)malloc(cb); cb = (prog.cbImage + 3) / 4;
memset(prog.map, BM_UNKNOWN, (size_t)cb); prog.map = (uint8_t *)malloc(cb);
memset(prog.map, BM_UNKNOWN, (size_t)cb);
/* Relocate segment constants */
for(uint32_t v : prog.relocTable) { /* Relocate segment constants */
uint8_t *p = &prog.Imagez[v]; for(uint32_t v : prog.relocTable) {
uint16_t w = (uint16_t)LH(p) + EXE_RELOCATION; uint8_t *p = &prog.Imagez[v];
*p++ = (uint8_t)(w & 0x00FF); uint16_t w = (uint16_t)LH(p) + EXE_RELOCATION;
*p = (uint8_t)((w & 0xFF00) >> 8); *p++ = (uint8_t)(w & 0x00FF);
} *p = (uint8_t)((w & 0xFF00) >> 8);
return true; }
} return true;
}; }
/***************************************************************************** };
* LoadImage /*****************************************************************************
****************************************************************************/ * LoadImage
bool Project::load() ****************************************************************************/
{ bool Project::load()
// addTask(loaderSelection,PreCond(BinaryImage)) {
// addTask(applyLoader,PreCond(Loader)) // addTask(loaderSelection,PreCond(BinaryImage))
const char *fname = binary_path().toLocal8Bit().data(); // addTask(applyLoader,PreCond(Loader))
QFile finfo(binary_path()); const char *fname = binary_path().toLocal8Bit().data();
/* Open the input file */ QFile finfo(binary_path());
if(!finfo.open(QFile::ReadOnly)) { /* Open the input file */
fatalError(CANNOT_OPEN, fname); if(!finfo.open(QFile::ReadOnly)) {
} fatalError(CANNOT_OPEN, fname);
/* Read in first 2 bytes to check EXE signature */ }
if (finfo.size()<=2) /* Read in first 2 bytes to check EXE signature */
{ if (finfo.size()<=2)
fatalError(CANNOT_READ, fname); {
} fatalError(CANNOT_READ, fname);
ComLoader com_loader; }
ExeLoader exe_loader; ComLoader com_loader;
if(exe_loader.canLoad(finfo)) { ExeLoader exe_loader;
prog.fCOM = false; if(exe_loader.canLoad(finfo)) {
return exe_loader.load(prog,finfo); prog.fCOM = false;
} return exe_loader.load(prog,finfo);
if(com_loader.canLoad(finfo)) { }
prog.fCOM = true; if(com_loader.canLoad(finfo)) {
return com_loader.load(prog,finfo); prog.fCOM = true;
} return com_loader.load(prog,finfo);
return false; }
} return false;
uint32_t SynthLab; }
/* Parses the program, builds the call graph, and returns the list of uint32_t SynthLab;
* procedures found */ /* Parses the program, builds the call graph, and returns the list of
void DccFrontend::parse(Project &proj) * procedures found */
{ void DccFrontend::parse(Project &proj)
PROG &prog(proj.prog); {
STATE state; PROG &prog(proj.prog);
STATE state;
/* Set initial state */
state.setState(rES, 0); /* PSP segment */ /* Set initial state */
state.setState(rDS, 0); state.setState(rES, 0); /* PSP segment */
state.setState(rCS, prog.initCS); state.setState(rDS, 0);
state.setState(rSS, prog.initSS); state.setState(rCS, prog.initCS);
state.setState(rSP, prog.initSP); state.setState(rSS, prog.initSS);
state.IP = ((uint32_t)prog.initCS << 4) + prog.initIP; state.setState(rSP, prog.initSP);
SynthLab = SYNTHESIZED_MIN; state.IP = ((uint32_t)prog.initCS << 4) + prog.initIP;
SynthLab = SYNTHESIZED_MIN;
/* Check for special settings of initial state, based on idioms of the
startup code */ /* Check for special settings of initial state, based on idioms of the
state.checkStartup(); startup code */
ilFunction start_proc; state.checkStartup();
/* Make a struct for the initial procedure */ ilFunction start_proc;
if (prog.offMain != -1) /* Make a struct for the initial procedure */
{ if (prog.offMain != -1)
start_proc = proj.createFunction(0,"main"); {
start_proc->retVal.loc = REG_FRAME; start_proc = proj.createFunction(0,"main");
start_proc->retVal.type = TYPE_WORD_SIGN; start_proc->retVal.loc = REG_FRAME;
start_proc->retVal.id.regi = rAX; start_proc->retVal.type = TYPE_WORD_SIGN;
/* We know where main() is. Start the flow of control from there */ start_proc->retVal.id.regi = rAX;
start_proc->procEntry = prog.offMain; /* We know where main() is. Start the flow of control from there */
/* In medium and large models, the segment of main may (will?) not be start_proc->procEntry = prog.offMain;
the same as the initial CS segment (of the startup code) */ /* In medium and large models, the segment of main may (will?) not be
state.setState(rCS, prog.segMain); the same as the initial CS segment (of the startup code) */
state.IP = prog.offMain; state.setState(rCS, prog.segMain);
} state.IP = prog.offMain;
else }
{ else
start_proc = proj.createFunction(0,"start"); {
/* Create initial procedure at program start address */ start_proc = proj.createFunction(0,"start");
start_proc->procEntry = (uint32_t)state.IP; /* Create initial procedure at program start address */
} start_proc->procEntry = (uint32_t)state.IP;
}
/* The state info is for the first procedure */
start_proc->state = state; /* The state info is for the first procedure */
start_proc->state = state;
/* Set up call graph initial node */
proj.callGraph = new CALL_GRAPH; /* Set up call graph initial node */
proj.callGraph->proc = start_proc; proj.callGraph = new CALL_GRAPH;
proj.callGraph->proc = start_proc;
/* This proc needs to be called to set things up for LibCheck(), which
checks a proc to see if it is a know C (etc) library */ /* This proc needs to be called to set things up for LibCheck(), which
SetupLibCheck(); checks a proc to see if it is a know C (etc) library */
//BUG: proj and g_proj are 'live' at this point ! SetupLibCheck();
//BUG: proj and g_proj are 'live' at this point !
/* Recursively build entire procedure list */
start_proc->FollowCtrl(proj.callGraph, &state); /* Recursively build entire procedure list */
start_proc->FollowCtrl(proj.callGraph, &state);
/* This proc needs to be called to clean things up from SetupLibCheck() */
CleanupLibCheck(); /* This proc needs to be called to clean things up from SetupLibCheck() */
} CleanupLibCheck();
}

View File

@ -1,6 +1,9 @@
#include "Procedure.h" #include "Procedure.h"
#include "msvc_fixes.h"
#include "project.h" #include "project.h"
#include "scanner.h" #include "scanner.h"
//FunctionType *Function::getFunctionType() const //FunctionType *Function::getFunctionType() const
//{ //{
// return &m_type; // return &m_type;
@ -15,7 +18,7 @@ void JumpTable::pruneEntries(uint16_t cs)
for (uint32_t i = start; i < finish; i += 2) for (uint32_t i = start; i < finish; i += 2)
{ {
uint32_t target = cs + LH(&prg->image()[i]); uint32_t target = cs + LH(&prg->image()[i]);
if (target < finish && target >= start) if (target < finish and target >= start)
finish = target; finish = target;
else if (target >= (uint32_t)prg->cbImage) else if (target >= (uint32_t)prg->cbImage)
finish = i; finish = i;
@ -25,7 +28,7 @@ void JumpTable::pruneEntries(uint16_t cs)
{ {
uint32_t target = cs + LH(&prg->image()[i]); uint32_t target = cs + LH(&prg->image()[i]);
/* Be wary of 00 00 as code - it's probably data */ /* Be wary of 00 00 as code - it's probably data */
if (! (prg->image()[target] || prg->image()[target+1]) || scan(target, _Icode)) if (! (prg->image()[target] or prg->image()[target+1]) or scan(target, _Icode))
finish = i; finish = i;
} }

View File

@ -1,3 +1,10 @@
#include "types.h"
#include "msvc_fixes.h"
#include "ast.h"
#include "bundle.h"
#include "machine_x86.h"
#include "project.h"
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <sstream> #include <sstream>
@ -8,12 +15,6 @@
//#include <boost/range/algorithm.hpp> //#include <boost/range/algorithm.hpp>
//#include <boost/assign.hpp> //#include <boost/assign.hpp>
#include "types.h"
#include "ast.h"
#include "bundle.h"
#include "machine_x86.h"
#include "project.h"
using namespace std; using namespace std;
using namespace boost::adaptors; using namespace boost::adaptors;
RegisterNode::RegisterNode(const LLOperand &op, LOCAL_ID *locsym) RegisterNode::RegisterNode(const LLOperand &op, LOCAL_ID *locsym)
@ -41,7 +42,7 @@ RegisterNode::RegisterNode(const LLOperand &op, LOCAL_ID *locsym)
// ident.type(REGISTER); // ident.type(REGISTER);
// hlType type_sel; // hlType type_sel;
// regType reg_type; // regType reg_type;
// if ((icodeFlg & B) || (icodeFlg & SRC_B)) // if ((icodeFlg & B) or (icodeFlg & SRC_B))
// { // {
// type_sel = TYPE_BYTE_SIGN; // type_sel = TYPE_BYTE_SIGN;
// reg_type = BYTE_REG; // reg_type = BYTE_REG;
@ -80,17 +81,17 @@ string RegisterNode::walkCondExpr(Function *pProc, int *numLoc) const
int RegisterNode::hlTypeSize(Function *) const int RegisterNode::hlTypeSize(Function *) const
{ {
if (regiType == BYTE_REG) if (regiType == BYTE_REG)
return (1); return 1;
else else
return (2); return 2;
} }
hlType RegisterNode::expType(Function *pproc) const hlType RegisterNode::expType(Function *pproc) const
{ {
if (regiType == BYTE_REG) if (regiType == BYTE_REG)
return (TYPE_BYTE_SIGN); return TYPE_BYTE_SIGN;
else else
return (TYPE_WORD_SIGN); return TYPE_WORD_SIGN;
} }
Expr *RegisterNode::insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym) Expr *RegisterNode::insertSubTreeReg(Expr *_expr, eReg regi, const LOCAL_ID *locsym)

View File

@ -4,29 +4,31 @@
* Date: September 1993 * Date: September 1993
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
*/ */
#include "ast.h"
#include "msvc_fixes.h"
#include "types.h"
#include "bundle.h"
#include "machine_x86.h"
#include "project.h"
#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/assign.hpp>
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#include <cassert> #include <cassert>
#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/assign.hpp>
#include "types.h"
#include "ast.h"
#include "bundle.h"
#include "machine_x86.h"
#include "project.h"
using namespace std; using namespace std;
using namespace boost; using namespace boost;
using namespace boost::adaptors; using namespace boost::adaptors;
extern int strSize (const uint8_t *, char); extern int strSize (const uint8_t *, char);
extern char *cChar(uint8_t c); extern char *cChar(uint8_t c);
// Conditional operator symbols in C. Index by condOp enumeration type // Conditional operator symbols in C. Index by condOp enumeration type
static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ", static const char * const condOpSym[] = { " <= ", " < ", " == ", " != ", " > ", " >= ",
" & ", " | ", " ^ ", " ~ ", " & ", " | ", " ^ ", " ~ ",
@ -146,7 +148,7 @@ AstIdent *AstIdent::Loc(int off, LOCAL_ID *localId)
for (i = 0; i < localId->csym(); i++) for (i = 0; i < localId->csym(); i++)
{ {
const ID &lID(localId->id_arr[i]); const ID &lID(localId->id_arr[i]);
if ((lID.id.bwId.off == off) && (lID.id.bwId.regOff == 0)) if ((lID.id.bwId.off == off) and (lID.id.bwId.regOff == 0))
break; break;
} }
if (i == localId->csym()) if (i == localId->csym())
@ -181,7 +183,7 @@ GlobalVariableIdx::GlobalVariableIdx (int16_t segValue, int16_t off, uint8_t reg
for (i = 0; i < locSym->csym(); i++) for (i = 0; i < locSym->csym(); i++)
{ {
const BWGLB_TYPE &lID(locSym->id_arr[i].id.bwGlb); const BWGLB_TYPE &lID(locSym->id_arr[i].id.bwGlb);
if ((lID.seg == segValue) && (lID.off == off) && (lID.regi == regi)) if ((lID.seg == segValue) and (lID.off == off) and (lID.regi == regi))
break; break;
} }
if (i == locSym->csym()) if (i == locSym->csym())
@ -221,7 +223,7 @@ AstIdent *AstIdent::Long(LOCAL_ID *localId, opLoc sd, iICODE pIcode, hlFirst f,
{ {
AstIdent *newExp; AstIdent *newExp;
/* Check for long constant and save it as a constant expression */ /* Check for long constant and save it as a constant expression */
if ((sd == SRC) && pIcode->ll()->testFlags(I)) /* constant */ if ((sd == SRC) and pIcode->ll()->testFlags(I)) /* constant */
{ {
int value; int value;
if (f == HIGH_FIRST) if (f == HIGH_FIRST)
@ -296,8 +298,8 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_
const LLOperand &pm(*ll_insn.get(sd)); const LLOperand &pm(*ll_insn.get(sd));
if ( ((sd == DST) && ll_insn.testFlags(IM_DST)) or if ( ((sd == DST) and ll_insn.testFlags(IM_DST)) or
((sd == SRC) && ll_insn.testFlags(IM_SRC)) or ((sd == SRC) and ll_insn.testFlags(IM_SRC)) or
(sd == LHS_OP)) /* for MUL lhs */ (sd == LHS_OP)) /* for MUL lhs */
{ /* implicit dx:ax */ { /* implicit dx:ax */
idx = pProc->localId.newLongReg (TYPE_LONG_SIGN, LONGID_TYPE(rDX, rAX), ix_); idx = pProc->localId.newLongReg (TYPE_LONG_SIGN, LONGID_TYPE(rDX, rAX), ix_);
@ -306,13 +308,13 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_
duIcode.setRegDU (rAX, du); duIcode.setRegDU (rAX, du);
} }
else if ((sd == DST) && ll_insn.testFlags(IM_TMP_DST)) else if ((sd == DST) and ll_insn.testFlags(IM_TMP_DST))
{ /* implicit tmp */ { /* implicit tmp */
newExp = new RegisterNode(LLOperand(rTMP,2), &pProc->localId); newExp = new RegisterNode(LLOperand(rTMP,2), &pProc->localId);
duIcode.setRegDU(rTMP, (operDu)eUSE); duIcode.setRegDU(rTMP, (operDu)eUSE);
} }
else if ((sd == SRC) && ll_insn.testFlags(I)) /* constant */ else if ((sd == SRC) and ll_insn.testFlags(I)) /* constant */
newExp = new Constant(ll_insn.src().getImm2(), 2); newExp = new Constant(ll_insn.src().getImm2(), 2);
else if (pm.regi == rUNDEF) /* global variable */ else if (pm.regi == rUNDEF) /* global variable */
newExp = new GlobalVariable(pm.segValue, pm.off); newExp = new GlobalVariable(pm.segValue, pm.off);
@ -325,14 +327,14 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_
else if (pm.off) /* offset */ else if (pm.off) /* offset */
{ // TODO: this is ABI specific, should be actually based on Function calling conv { // TODO: this is ABI specific, should be actually based on Function calling conv
if ((pm.seg == rSS) && (pm.regi == INDEX_BP)) /* idx on bp */ if ((pm.seg == rSS) and (pm.regi == INDEX_BP)) /* idx on bp */
{ {
if (pm.off >= 0) /* argument */ if (pm.off >= 0) /* argument */
newExp = AstIdent::Param (pm.off, &pProc->args); newExp = AstIdent::Param (pm.off, &pProc->args);
else /* local variable */ else /* local variable */
newExp = AstIdent::Loc (pm.off, &pProc->localId); newExp = AstIdent::Loc (pm.off, &pProc->localId);
} }
else if ((pm.seg == rDS) && (pm.regi == INDEX_BX)) /* bx */ else if ((pm.seg == rDS) and (pm.regi == INDEX_BX)) /* bx */
{ {
if (pm.off > 0) /* global variable */ if (pm.off > 0) /* global variable */
newExp = new GlobalVariableIdx(pm.segValue, pm.off, rBX,&pProc->localId); newExp = new GlobalVariableIdx(pm.segValue, pm.off, rBX,&pProc->localId);
@ -345,9 +347,9 @@ Expr *AstIdent::id(const LLInst &ll_insn, opLoc sd, Function * pProc, iICODE ix_
/**** check long ops, indexed global var *****/ /**** check long ops, indexed global var *****/
} }
else /* (pm->regi >= INDEXBASE && pm->off = 0) => indexed && no off */ else /* (pm->regi >= INDEXBASE and pm->off = 0) => indexed and no off */
{ {
if ((pm.seg == rDS) && (pm.regi > INDEX_BP_DI)) /* dereference */ if ((pm.seg == rDS) and (pm.regi > INDEX_BP_DI)) /* dereference */
{ {
eReg selected; eReg selected;
switch (pm.regi) { switch (pm.regi) {
@ -376,13 +378,13 @@ condId LLInst::idType(opLoc sd) const
{ {
const LLOperand &pm((sd == SRC) ? src() : m_dst); const LLOperand &pm((sd == SRC) ? src() : m_dst);
if ((sd == SRC) && testFlags(I)) if ((sd == SRC) and testFlags(I))
return (CONSTANT); return (CONSTANT);
else if (pm.regi == 0) else if (pm.regi == 0)
return (GLOB_VAR); return (GLOB_VAR);
else if ( pm.isReg() ) else if ( pm.isReg() )
return (REGISTER); return (REGISTER);
else if ((pm.seg == rSS) && (pm.regi == INDEX_BP)) else if ((pm.seg == rSS) and (pm.regi == INDEX_BP))
{ {
//TODO: which pm.seg/pm.regi pairs should produce PARAM/LOCAL_VAR ? //TODO: which pm.seg/pm.regi pairs should produce PARAM/LOCAL_VAR ?
if (pm.off >= 0) if (pm.off >= 0)
@ -877,7 +879,7 @@ Expr *AstIdent::performLongRemoval(eReg regi, LOCAL_ID *locId)
eReg AstIdent::otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl) eReg AstIdent::otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl)
{ {
ID *id = &locTbl->id_arr[idx]; ID *id = &locTbl->id_arr[idx];
if ((id->loc == REG_FRAME) && ((id->type == TYPE_LONG_SIGN) || 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) if (id->longId().h() == regi)

View File

@ -4,6 +4,12 @@
* Purpose: Back-end module. Generates C code for each procedure. * Purpose: Back-end module. Generates C code for each procedure.
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
****************************************************************************/ ****************************************************************************/
#include "dcc.h"
#include "msvc_fixes.h"
#include "disassem.h"
#include "project.h"
#include "CallGraph.h"
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <cassert> #include <cassert>
@ -17,15 +23,13 @@
#include <sstream> #include <sstream>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "dcc.h"
#include "disassem.h"
#include "project.h"
#include "CallGraph.h"
using namespace boost; using namespace boost;
using namespace boost::adaptors; using namespace boost::adaptors;
bundle cCode; /* Procedure declaration and code */
using namespace std; using namespace std;
bundle cCode; /* Procedure declaration and code */
/* Returns a unique index to the next label */ /* Returns a unique index to the next label */
int getNextLabel() int getNextLabel()
{ {
@ -252,8 +256,8 @@ void Function::codeGen (std::ostream &fs)
if (refId.loc == REG_FRAME) if (refId.loc == REG_FRAME)
{ {
/* Register variables are assigned to a local variable */ /* Register variables are assigned to a local variable */
if (((flg & SI_REGVAR) && (refId.id.regi == rSI)) || if (((flg & SI_REGVAR) and (refId.id.regi == rSI)) or
((flg & DI_REGVAR) && (refId.id.regi == rDI))) ((flg & DI_REGVAR) and (refId.id.regi == rDI)))
{ {
refId.setLocalName(++numLoc); refId.setLocalName(++numLoc);
ostr << "int "<<refId.name<<";\n"; ostr << "int "<<refId.name<<";\n";
@ -315,7 +319,7 @@ static void backBackEnd (CALL_GRAPH * pcallGraph, std::ostream &_ios)
// IFace.Yield(); /* This is a good place to yield to other apps */ // IFace.Yield(); /* This is a good place to yield to other apps */
/* Check if this procedure has been processed already */ /* Check if this procedure has been processed already */
if ((pcallGraph->proc->flg & PROC_OUTPUT) || if ((pcallGraph->proc->flg & PROC_OUTPUT) or
(pcallGraph->proc->flg & PROC_ISLIB)) (pcallGraph->proc->flg & PROC_ISLIB))
return; return;
pcallGraph->proc->flg |= PROC_OUTPUT; pcallGraph->proc->flg |= PROC_OUTPUT;

View File

@ -6,6 +6,7 @@
*/ */
#include "dcc.h" #include "dcc.h"
#include "msvc_fixes.h"
#include "project.h" #include "project.h"
#include "perfhlib.h" #include "perfhlib.h"
#include "dcc_interface.h" #include "dcc_interface.h"
@ -15,6 +16,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <memory.h> #include <memory.h>
#include <string.h> #include <string.h>
PerfectHash g_pattern_hasher; PerfectHash g_pattern_hasher;
#define NIL -1 /* Used like NULL, but 0 is valid */ #define NIL -1 /* Used like NULL, but 0 is valid */
@ -322,7 +324,7 @@ void SetupLibCheck(void)
numVert = readFileShort(g_file); numVert = readFileShort(g_file);
PatLen = readFileShort(g_file); PatLen = readFileShort(g_file);
SymLen = readFileShort(g_file); SymLen = readFileShort(g_file);
if ((PatLen != PATLEN) || (SymLen != SYMLEN)) if ((PatLen != PATLEN) or (SymLen != SYMLEN))
{ {
printf("Sorry! Compiled for sym and pattern lengths of %d and %d\n", printf("Sorry! Compiled for sym and pattern lengths of %d and %d\n",
SYMLEN, PATLEN); SYMLEN, PATLEN);
@ -473,7 +475,7 @@ bool LibCheck(Function & pProc)
} }
/* But is it a real library function? */ /* But is it a real library function? */
i = NIL; i = NIL;
if ((numFunc == 0) || (i=searchPList(ht[h].htSym)) != NIL) if ((numFunc == 0) or (i=searchPList(ht[h].htSym)) != NIL)
{ {
pProc.flg |= PROC_ISLIB; /* It's a lib function */ pProc.flg |= PROC_ISLIB; /* It's a lib function */
pProc.callingConv(CConv::C); pProc.callingConv(CConv::C);
@ -604,7 +606,7 @@ static bool locatePattern(const uint8_t *source, int iMin, int iMax, uint8_t *pa
for (j=0; j < iPatLen; j++) for (j=0; j < iPatLen; j++)
{ {
/* j is the index of the uint8_t being considered in the pattern. */ /* j is the index of the uint8_t being considered in the pattern. */
if ((*pSrc != pattern[j]) && (pattern[j] != WILD)) if ((*pSrc != pattern[j]) and (pattern[j] != WILD))
{ {
/* A definite mismatch */ /* A definite mismatch */
break; /* Break to outer loop */ break; /* Break to outer loop */

View File

@ -7,7 +7,9 @@
****************************************************************************/ ****************************************************************************/
#include "dcc.h" #include "dcc.h"
#include "msvc_fixes.h"
#include "machine_x86.h" #include "machine_x86.h"
#include <string.h> #include <string.h>
#include <sstream> #include <sstream>
using namespace std; using namespace std;
@ -156,7 +158,7 @@ void LLInst::writeIntComment (std::ostringstream &s)
{ {
s <<int21h[m_dst.off]; s <<int21h[m_dst.off];
} }
else if (src_immed > 0x1F && src_immed < 0x2F) else if (src_immed > 0x1F and src_immed < 0x2F)
{ {
s <<intOthers[src_immed - 0x20]; s <<intOthers[src_immed - 0x20];
} }

View File

@ -2,6 +2,10 @@
* Description : Performs control flow analysis on the CFG * Description : Performs control flow analysis on the CFG
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
********************************************************************/ ********************************************************************/
#include "dcc.h"
#include "msvc_fixes.h"
#include <boost/range/algorithm.hpp> #include <boost/range/algorithm.hpp>
#include <algorithm> #include <algorithm>
#include <list> #include <list>
@ -10,15 +14,10 @@
#include <string.h> #include <string.h>
#include <malloc.h> #include <malloc.h>
#include "dcc.h"
//typedef struct list {
// int nodeIdx;
// struct list *next;
//} nodeList;
typedef std::list<int> nodeList; /* dfsLast index to the node */ typedef std::list<int> nodeList; /* dfsLast index to the node */
#define ancestor(a,b) ((a->dfsLastNum < b->dfsLastNum) && (a->dfsFirstNum < b->dfsFirstNum)) #define ancestor(a,b) ((a->dfsLastNum < b->dfsLastNum) and (a->dfsFirstNum < b->dfsFirstNum))
/* there is a path on the DFST from a to b if the a was first visited in a /* there is a path on the DFST from a to b if the a was first visited in a
* dfs, and a was later visited than b when doing the last visit of each * dfs, and a was later visited than b when doing the last visit of each
* node. */ * node. */
@ -48,7 +47,7 @@ static int commonDom (int currImmDom, int predImmDom, Function * pProc)
if (predImmDom == NO_DOM) /* predecessor is the root */ if (predImmDom == NO_DOM) /* predecessor is the root */
return (currImmDom); return (currImmDom);
while ((currImmDom != NO_DOM) && (predImmDom != NO_DOM) && while ((currImmDom != NO_DOM) and (predImmDom != NO_DOM) and
(currImmDom != predImmDom)) (currImmDom != predImmDom))
{ {
if (currImmDom < predImmDom) if (currImmDom < predImmDom)
@ -121,7 +120,7 @@ static void findEndlessFollow (Function * pProc, nodeList &loopNodes, BB * head)
for (TYPEADR_TYPE &typeaddr: pProc->m_dfsLast[loop_node]->edges) for (TYPEADR_TYPE &typeaddr: pProc->m_dfsLast[loop_node]->edges)
{ {
int succ = typeaddr.BBptr->dfsLastNum; int succ = typeaddr.BBptr->dfsLastNum;
if ((! inList(loopNodes, succ)) && (succ < head->loopFollow)) if ((not inList(loopNodes, succ)) and (succ < head->loopFollow))
head->loopFollow = succ; head->loopFollow = succ;
} }
} }
@ -149,7 +148,7 @@ static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &int
continue; continue;
immedDom = pProc->m_dfsLast[i]->immedDom; immedDom = pProc->m_dfsLast[i]->immedDom;
if (inList (loopNodes, immedDom) && inInt(pProc->m_dfsLast[i], intNodes)) if (inList (loopNodes, immedDom) and inInt(pProc->m_dfsLast[i], intNodes))
{ {
insertList (loopNodes, i); insertList (loopNodes, i);
if (pProc->m_dfsLast[i]->loopHead == NO_NODE)/*not in other loop*/ if (pProc->m_dfsLast[i]->loopHead == NO_NODE)/*not in other loop*/
@ -163,9 +162,9 @@ static void findNodesInLoop(BB * latchNode,BB * head,Function * pProc,queue &int
/* Determine type of loop and follow node */ /* Determine type of loop and follow node */
intNodeType = head->nodeType; intNodeType = head->nodeType;
if (latchNode->nodeType == TWO_BRANCH) if (latchNode->nodeType == TWO_BRANCH)
if ((intNodeType == TWO_BRANCH) || (latchNode == head)) if ((intNodeType == TWO_BRANCH) or (latchNode == head))
if ((latchNode == head) || if ((latchNode == head) or
(inList (loopNodes, head->edges[THEN].BBptr->dfsLastNum) && (inList (loopNodes, head->edges[THEN].BBptr->dfsLastNum) and
inList (loopNodes, head->edges[ELSE].BBptr->dfsLastNum))) inList (loopNodes, head->edges[ELSE].BBptr->dfsLastNum)))
{ {
head->loopType = eNodeHeaderType::REPEAT_TYPE; head->loopType = eNodeHeaderType::REPEAT_TYPE;
@ -299,9 +298,9 @@ void Function::structLoops(derSeq *derivedG)
for (size_t i = 0; i < intHead->inEdges.size(); i++) for (size_t i = 0; i < intHead->inEdges.size(); i++)
{ {
pred = intHead->inEdges[i]; pred = intHead->inEdges[i];
if (inInt(pred, intNodes) && isBackEdge(pred, intHead)) if (inInt(pred, intNodes) and isBackEdge(pred, intHead))
{ {
if (! latchNode) if (nullptr == latchNode)
latchNode = pred; latchNode = pred;
else if (pred->dfsLastNum > latchNode->dfsLastNum) else if (pred->dfsLastNum > latchNode->dfsLastNum)
latchNode = pred; latchNode = pred;
@ -314,7 +313,7 @@ void Function::structLoops(derSeq *derivedG)
/* Check latching node is at the same nesting level of case /* Check latching node is at the same nesting level of case
* statements (if any) and that the node doesn't belong to * statements (if any) and that the node doesn't belong to
* another loop. */ * another loop. */
if ((latchNode->caseHead == intHead->caseHead) && if ((latchNode->caseHead == intHead->caseHead) and
(latchNode->loopHead == NO_NODE)) (latchNode->loopHead == NO_NODE))
{ {
intHead->latchNode = latchNode->dfsLastNum; intHead->latchNode = latchNode->dfsLastNum;
@ -353,7 +352,7 @@ static void tagNodesInCase (BB * pBB, nodeList &l, int head, int tail)
pBB->traversed = DFS_CASE; pBB->traversed = DFS_CASE;
current = pBB->dfsLastNum; current = pBB->dfsLastNum;
if ((current != tail) && (pBB->nodeType != MULTI_BRANCH) && (inList (l, pBB->immedDom))) if ((current != tail) and (pBB->nodeType != MULTI_BRANCH) and (inList (l, pBB->immedDom)))
{ {
insertList (l, current); insertList (l, current);
pBB->caseHead = head; pBB->caseHead = head;
@ -385,7 +384,7 @@ void Function::structCases()
* the current header node, and is not a successor. */ * the current header node, and is not a successor. */
for (size_t j = i + 2; j < numBBs; j++) for (size_t j = i + 2; j < numBBs; j++)
{ {
if ((!successor(j, i, this)) && (m_dfsLast[j]->immedDom == i)) if ((not successor(j, i, this)) and (m_dfsLast[j]->immedDom == i))
{ {
if (exitNode == NO_NODE) if (exitNode == NO_NODE)
{ {
@ -446,7 +445,7 @@ void Function::structIfs ()
if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */ if (currNode->flg & INVALID_BB) /* Do not process invalid BBs */
continue; continue;
if ((currNode->nodeType == TWO_BRANCH) && (!currNode->back().ll()->testFlags(JX_LOOP))) if ((currNode->nodeType == TWO_BRANCH) and (not currNode->back().ll()->testFlags(JX_LOOP)))
{ {
followInEdges = 0; followInEdges = 0;
follow = 0; follow = 0;
@ -468,7 +467,7 @@ void Function::structIfs ()
/* Determine follow according to number of descendants /* Determine follow according to number of descendants
* immediately dominated by this node */ * immediately dominated by this node */
if ((follow != 0) && (followInEdges > 1)) if ((follow != 0) and (followInEdges > 1))
{ {
currNode->ifFollow = follow; currNode->ifFollow = follow;
if (!unresolved.empty()) if (!unresolved.empty())
@ -617,33 +616,33 @@ void Function::compoundCond()
change = true; //assume change change = true; //assume change
/* Check (X || Y) case */ /* Check (X or Y) case */
if ((thenBB->nodeType == TWO_BRANCH) && (thenBB->numHlIcodes == 1) && if ((thenBB->nodeType == TWO_BRANCH) and (thenBB->numHlIcodes == 1) and
(thenBB->inEdges.size() == 1) && (thenBB->edges[ELSE].BBptr == elseBB)) (thenBB->inEdges.size() == 1) and (thenBB->edges[ELSE].BBptr == elseBB))
{ {
if(Case_X_or_Y(pbb, thenBB, elseBB)) if(Case_X_or_Y(pbb, thenBB, elseBB))
--i; --i;
} }
/* Check (!X && Y) case */ /* Check (!X and Y) case */
else if ((thenBB->nodeType == TWO_BRANCH) && (thenBB->numHlIcodes == 1) && else if ((thenBB->nodeType == TWO_BRANCH) and (thenBB->numHlIcodes == 1) and
(thenBB->inEdges.size() == 1) && (thenBB->edges[THEN].BBptr == elseBB)) (thenBB->inEdges.size() == 1) and (thenBB->edges[THEN].BBptr == elseBB))
{ {
if(Case_notX_and_Y(pbb, thenBB, elseBB)) if(Case_notX_and_Y(pbb, thenBB, elseBB))
--i; --i;
} }
/* Check (X && Y) case */ /* Check (X and Y) case */
else if ((elseBB->nodeType == TWO_BRANCH) && (elseBB->numHlIcodes == 1) && else if ((elseBB->nodeType == TWO_BRANCH) and (elseBB->numHlIcodes == 1) and
(elseBB->inEdges.size()==1) && (elseBB->edges[THEN].BBptr == thenBB)) (elseBB->inEdges.size()==1) and (elseBB->edges[THEN].BBptr == thenBB))
{ {
if(Case_X_and_Y(pbb, thenBB, elseBB )) if(Case_X_and_Y(pbb, thenBB, elseBB ))
--i; --i;
} }
/* Check (!X || Y) case */ /* Check (!X or Y) case */
else if ((elseBB->nodeType == TWO_BRANCH) && (elseBB->numHlIcodes == 1) && else if ((elseBB->nodeType == TWO_BRANCH) and (elseBB->numHlIcodes == 1) and
(elseBB->inEdges.size() == 1) && (elseBB->edges[ELSE].BBptr == thenBB)) (elseBB->inEdges.size() == 1) and (elseBB->edges[ELSE].BBptr == thenBB))
{ {
if(Case_notX_or_Y(pbb, thenBB, elseBB )) if(Case_notX_or_Y(pbb, thenBB, elseBB ))
--i; --i;

View File

@ -4,18 +4,21 @@
* Purpose: Data flow analysis module. * Purpose: Data flow analysis module.
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
****************************************************************************/ ****************************************************************************/
#include "dcc.h"
#include "project.h"
#include "msvc_fixes.h"
#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/assign.hpp>
#include <stdint.h> #include <stdint.h>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <cstdio> #include <cstdio>
#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/assign.hpp>
#include "dcc.h"
#include "project.h"
using namespace boost; using namespace boost;
using namespace boost::adaptors; using namespace boost::adaptors;
struct ExpStack struct ExpStack
@ -28,7 +31,7 @@ struct ExpStack
void push(Expr *); void push(Expr *);
Expr * pop(); Expr * pop();
Expr * top() const { Expr * top() const {
if(!expStk.empty()) if(not expStk.empty())
return expStk.back(); return expStk.back();
return nullptr; return nullptr;
} }
@ -145,7 +148,7 @@ void Function::elimCondCodes ()
{ {
llIcode useAtOp = llIcode(useAt->ll()->getOpcode()); llIcode useAtOp = llIcode(useAt->ll()->getOpcode());
use = useAt->ll()->flagDU.u; use = useAt->ll()->flagDU.u;
if ((useAt->type != LOW_LEVEL) || ( ! useAt->valid() ) || ( 0 == use )) if ((useAt->type != LOW_LEVEL) or ( not useAt->valid() ) or ( 0 == use ))
continue; continue;
/* Find definition within the same basic block */ /* Find definition within the same basic block */
defAt=useAt; defAt=useAt;
@ -158,7 +161,7 @@ void Function::elimCondCodes ()
continue; continue;
notSup = false; notSup = false;
LLOperand *dest_ll = defIcode.ll()->get(DST); LLOperand *dest_ll = defIcode.ll()->get(DST);
if ((useAtOp >= iJB) && (useAtOp <= iJNS)) if ((useAtOp >= iJB) and (useAtOp <= iJNS))
{ {
iICODE befDefAt = (++riICODE(defAt)).base(); iICODE befDefAt = (++riICODE(defAt)).base();
switch (defIcode.ll()->getOpcode()) switch (defIcode.ll()->getOpcode())
@ -194,7 +197,7 @@ void Function::elimCondCodes ()
reportError (JX_NOT_DEF, defIcode.ll()->getOpcode()); reportError (JX_NOT_DEF, defIcode.ll()->getOpcode());
flg |= PROC_ASM; /* generate asm */ flg |= PROC_ASM; /* generate asm */
} }
if (! notSup) if (not notSup)
{ {
assert(lhs); assert(lhs);
assert(rhs); assert(rhs);
@ -226,7 +229,7 @@ void Function::elimCondCodes ()
} }
/* Check for extended basic block */ /* Check for extended basic block */
if ((pBB->size() == 1) &&(useAtOp >= iJB) && (useAtOp <= iJNS)) if ((pBB->size() == 1) and(useAtOp >= iJB) and (useAtOp <= iJNS))
{ {
ICODE & _prev(pBB->back()); /* For extended basic blocks - previous icode inst */ ICODE & _prev(pBB->back()); /* For extended basic blocks - previous icode inst */
if (_prev.hl()->opcode == HLI_JCOND) if (_prev.hl()->opcode == HLI_JCOND)
@ -268,7 +271,7 @@ void Function::genLiveKtes ()
continue; // skip invalid BBs continue; // skip invalid BBs
for(ICODE &insn : *pbb) for(ICODE &insn : *pbb)
{ {
if ((insn.type == HIGH_LEVEL) && ( insn.valid() )) if ((insn.type == HIGH_LEVEL) and ( insn.valid() ))
{ {
liveUse |= (insn.du.use - def); liveUse |= (insn.du.use - def);
def |= insn.du.def; def |= insn.du.def;
@ -342,7 +345,7 @@ void Function::liveRegAnalysis (LivenessSet &in_liveOut)
pcallee = ticode.hl()->call.proc; pcallee = ticode.hl()->call.proc;
/* user/runtime routine */ /* user/runtime routine */
if (! (pcallee->flg & PROC_ISLIB)) if (not (pcallee->flg & PROC_ISLIB))
{ {
if (pcallee->liveAnal == false) /* hasn't been processed */ if (pcallee->liveAnal == false) /* hasn't been processed */
pcallee->dataFlow (pbb->liveOut); pcallee->dataFlow (pbb->liveOut);
@ -350,7 +353,7 @@ void Function::liveRegAnalysis (LivenessSet &in_liveOut)
} }
else /* library routine */ else /* library routine */
{ {
if ( (pcallee->flg & PROC_IS_FUNC) && /* returns a value */ if ( (pcallee->flg & PROC_IS_FUNC) and /* returns a value */
(pcallee->liveOut & pbb->edges[0].BBptr->liveIn).any() (pcallee->liveOut & pbb->edges[0].BBptr->liveIn).any()
) )
pbb->liveOut = pcallee->liveOut; pbb->liveOut = pcallee->liveOut;
@ -358,7 +361,7 @@ void Function::liveRegAnalysis (LivenessSet &in_liveOut)
pbb->liveOut.reset(); pbb->liveOut.reset();
} }
if ((! (pcallee->flg & PROC_ISLIB)) || ( pbb->liveOut.any() )) if ((not (pcallee->flg & PROC_ISLIB)) or ( pbb->liveOut.any() ))
{ {
switch (pcallee->retVal.type) { switch (pcallee->retVal.type) {
case TYPE_LONG_SIGN: case TYPE_LONG_UNSIGN: case TYPE_LONG_SIGN: case TYPE_LONG_UNSIGN:
@ -385,7 +388,7 @@ void Function::liveRegAnalysis (LivenessSet &in_liveOut)
pbb->liveIn = LivenessSet(pbb->liveUse + (pbb->liveOut - pbb->def)); pbb->liveIn = LivenessSet(pbb->liveUse + (pbb->liveOut - pbb->def));
/* Check if live sets have been modified */ /* Check if live sets have been modified */
if ((prevLiveIn != pbb->liveIn) || (prevLiveOut != pbb->liveOut)) if ((prevLiveIn != pbb->liveIn) or (prevLiveOut != pbb->liveOut))
change = true; change = true;
} }
} }
@ -412,9 +415,9 @@ void Function::liveRegAnalysis (LivenessSet &in_liveOut)
* register */ * register */
bool BB::FindUseBeforeDef(eReg regi, int defRegIdx, iICODE start_at) bool BB::FindUseBeforeDef(eReg regi, int defRegIdx, iICODE start_at)
{ {
if ((regi == rDI) && (flg & DI_REGVAR)) if ((regi == rDI) and (flg & DI_REGVAR))
return true; return true;
if ((regi == rSI) && (flg & SI_REGVAR)) if ((regi == rSI) and (flg & SI_REGVAR))
return true; return true;
if (distance(start_at,end())>1) /* several instructions */ if (distance(start_at,end())>1) /* several instructions */
{ {
@ -457,7 +460,7 @@ bool BB::FindUseBeforeDef(eReg regi, int defRegIdx, iICODE start_at)
* on optimized code. */ * on optimized code. */
void BB::ProcessUseDefForFunc(eReg regi, int defRegIdx, ICODE &picode) void BB::ProcessUseDefForFunc(eReg regi, int defRegIdx, ICODE &picode)
{ {
if (!((picode.hl()->opcode == HLI_CALL) && (picode.hl()->call.proc->flg & PROC_IS_FUNC))) if (not ((picode.hl()->opcode == HLI_CALL) and (picode.hl()->call.proc->flg & PROC_IS_FUNC)))
return; return;
BB *tbb = this->edges[0].BBptr; BB *tbb = this->edges[0].BBptr;
@ -475,7 +478,7 @@ void BB::ProcessUseDefForFunc(eReg regi, int defRegIdx, ICODE &picode)
/* if not used in this basic block, check if the /* if not used in this basic block, check if the
* register is live out, if so, make it the last * register is live out, if so, make it the last
* definition of this register */ * definition of this register */
if ( picode.du1.used(defRegIdx) && tbb->liveOut.testRegAndSubregs(regi)) if ( picode.du1.used(defRegIdx) and tbb->liveOut.testRegAndSubregs(regi))
picode.du.lastDefRegi.addReg(regi); picode.du.lastDefRegi.addReg(regi);
} }
@ -488,11 +491,11 @@ void BB::ProcessUseDefForFunc(eReg regi, int defRegIdx, ICODE &picode)
void BB::RemoveUnusedDefs(eReg regi, int defRegIdx, iICODE picode) void BB::RemoveUnusedDefs(eReg regi, int defRegIdx, iICODE picode)
{ {
if (picode->valid() and not picode->du1.used(defRegIdx) and if (picode->valid() and not picode->du1.used(defRegIdx) and
(not picode->du.lastDefRegi.testRegAndSubregs(regi)) && (not picode->du.lastDefRegi.testRegAndSubregs(regi)) and
(not ((picode->hl()->opcode == HLI_CALL) && (not ((picode->hl()->opcode == HLI_CALL) and
(picode->hl()->call.proc->flg & PROC_ISLIB)))) (picode->hl()->call.proc->flg & PROC_ISLIB))))
{ {
if (! (this->liveOut.testRegAndSubregs(regi))) /* not liveOut */ if (not (this->liveOut.testRegAndSubregs(regi))) /* not liveOut */
{ {
bool res = picode->removeDefRegi (regi, defRegIdx+1,&Parent->localId); bool res = picode->removeDefRegi (regi, defRegIdx+1,&Parent->localId);
if (res == true) if (res == true)
@ -540,7 +543,7 @@ void BB::genDU1()
defRegIdx++; defRegIdx++;
/* Check if all defined registers have been processed */ /* Check if all defined registers have been processed */
if ((defRegIdx >= picode->du1.getNumRegsDef()) || (defRegIdx == MAX_REGS_DEF)) if ((defRegIdx >= picode->du1.getNumRegsDef()) or (defRegIdx == MAX_REGS_DEF))
break; break;
} }
} }
@ -588,7 +591,7 @@ void LOCAL_ID::forwardSubs (Expr *lhs, Expr *rhs, iICODE picode, iICODE ticode,
{ {
eReg inserted = id_arr[lhs_reg->regiIdx].id.regi; eReg inserted = id_arr[lhs_reg->regiIdx].id.regi;
eReg lhsReg = id_arr[op->regiIdx].id.regi; eReg lhsReg = id_arr[op->regiIdx].id.regi;
if((lhsReg==inserted)||Machine_X86::isSubRegisterOf(lhsReg,inserted)) if((lhsReg==inserted) or Machine_X86::isSubRegisterOf(lhsReg,inserted))
{ {
// Do not replace ax = XYZ; given ax = H << P; with H << P = // Do not replace ax = XYZ; given ax = H << P; with H << P =
return; return;
@ -644,7 +647,7 @@ bool BinaryOperator::xClear(rICODE range_to_check, iICODE lastBBinst, const LOCA
{ {
if(nullptr==m_rhs) if(nullptr==m_rhs)
return false; return false;
if ( ! m_rhs->xClear (range_to_check, lastBBinst, locs) ) if ( not m_rhs->xClear (range_to_check, lastBBinst, locs) )
return false; return false;
if(nullptr==m_lhs) if(nullptr==m_lhs)
return false; return false;
@ -690,7 +693,7 @@ int C_CallingConvention::processCArg (Function * callee, Function * pProc, ICODE
else { else {
if(numArgs<callee->args.size()) { if(numArgs<callee->args.size()) {
if(prog.addressingMode=='l') { if(prog.addressingMode=='l') {
if((callee->args[numArgs].type==TYPE_STR)||(callee->args[numArgs].type==TYPE_PTR)) { if((callee->args[numArgs].type==TYPE_STR) or (callee->args[numArgs].type==TYPE_PTR)) {
RegisterNode *rn = dynamic_cast<RegisterNode *>(g_exp_stk.top()); RegisterNode *rn = dynamic_cast<RegisterNode *>(g_exp_stk.top());
AstIdent *idn = dynamic_cast<AstIdent *>(g_exp_stk.top()); AstIdent *idn = dynamic_cast<AstIdent *>(g_exp_stk.top());
if(rn) { if(rn) {
@ -815,9 +818,9 @@ void C_CallingConvention::processHLI(Function *func,Expr *_exp, iICODE picode) {
numArgs++; numArgs++;
} }
} }
else if ((cb == 0) && picode->ll()->testFlags(REST_STK)) else if ((cb == 0) and picode->ll()->testFlags(REST_STK))
{ {
while (! g_exp_stk.empty()) while (not g_exp_stk.empty())
{ {
k+=processCArg (pp, func, &(*picode), numArgs); k+=processCArg (pp, func, &(*picode), numArgs);
numArgs++; numArgs++;
@ -907,8 +910,8 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
* icode expression */ * icode expression */
ticode = picode->du1.idx[0].uses.front(); ticode = picode->du1.idx[0].uses.front();
if ((picode->du.lastDefRegi.testRegAndSubregs(regi)) && if ((picode->du.lastDefRegi.testRegAndSubregs(regi)) and
((ticode->hl()->opcode != HLI_CALL) && ((ticode->hl()->opcode != HLI_CALL) and
(ticode->hl()->opcode != HLI_RET))) (ticode->hl()->opcode != HLI_RET)))
continue; continue;
@ -926,8 +929,8 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
// call F() <- somehow this is marked as user of POP ? // call F() <- somehow this is marked as user of POP ?
ticode = picode->du1.idx[0].uses.front(); ticode = picode->du1.idx[0].uses.front();
ti_hl = ticode->hlU(); ti_hl = ticode->hlU();
if ((picode->du.lastDefRegi.testRegAndSubregs(regi)) && if ((picode->du.lastDefRegi.testRegAndSubregs(regi)) and
((ti_hl->opcode != HLI_CALL) && ((ti_hl->opcode != HLI_CALL) and
(ti_hl->opcode != HLI_RET))) (ti_hl->opcode != HLI_RET)))
continue; continue;
@ -1026,8 +1029,8 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
if (picode->du1.idx[0].uses[0] == picode->du1.idx[1].uses[0]) if (picode->du1.idx[0].uses[0] == picode->du1.idx[1].uses[0])
{ {
ticode = picode->du1.idx[0].uses.front(); ticode = picode->du1.idx[0].uses.front();
if ((picode->du.lastDefRegi.testRegAndSubregs(regi)) && if ((picode->du.lastDefRegi.testRegAndSubregs(regi)) and
((ticode->hl()->opcode != HLI_CALL) && ((ticode->hl()->opcode != HLI_CALL) and
(ticode->hl()->opcode != HLI_RET))) (ticode->hl()->opcode != HLI_RET)))
continue; continue;
locals.processTargetIcode(picode.base(), numHlIcodes, ticode,true); locals.processTargetIcode(picode.base(), numHlIcodes, ticode,true);
@ -1038,8 +1041,8 @@ void BB::findBBExps(LOCAL_ID &locals,Function *fnc)
if (picode->du1.idx[0].uses[0] == picode->du1.idx[1].uses[0]) if (picode->du1.idx[0].uses[0] == picode->du1.idx[1].uses[0])
{ {
ticode = picode->du1.idx[0].uses.front(); ticode = picode->du1.idx[0].uses.front();
if ((picode->du.lastDefRegi.testRegAndSubregs(regi)) && if ((picode->du.lastDefRegi.testRegAndSubregs(regi)) and
((ticode->hl()->opcode != HLI_CALL) && ((ticode->hl()->opcode != HLI_CALL) and
(ticode->hl()->opcode != HLI_RET))) (ticode->hl()->opcode != HLI_RET)))
continue; continue;
@ -1187,36 +1190,36 @@ void Function::preprocessReturnDU(LivenessSet &_liveOut)
isBx = _liveOut.testReg(rBX); isBx = _liveOut.testReg(rBX);
isCx = _liveOut.testReg(rCX); isCx = _liveOut.testReg(rCX);
isDx = _liveOut.testReg(rDX); isDx = _liveOut.testReg(rDX);
bool isAL = !isAx && _liveOut.testReg(rAL); bool isAL = not isAx and _liveOut.testReg(rAL);
bool isAH = !isAx && _liveOut.testReg(rAH); bool isAH = not isAx and _liveOut.testReg(rAH);
bool isBL = !isBx && _liveOut.testReg(rBL); bool isBL = not isBx and _liveOut.testReg(rBL);
bool isBH = !isBx && _liveOut.testReg(rBH); bool isBH = not isBx and _liveOut.testReg(rBH);
bool isCL = !isCx && _liveOut.testReg(rCL); bool isCL = not isCx and _liveOut.testReg(rCL);
bool isCH = !isCx && _liveOut.testReg(rCH); bool isCH = not isCx and _liveOut.testReg(rCH);
bool isDL = !isDx && _liveOut.testReg(rDL); bool isDL = not isDx and _liveOut.testReg(rDL);
bool isDH = !isDx && _liveOut.testReg(rDH); bool isDH = not isDx and _liveOut.testReg(rDH);
if(isAL && isAH) if(isAL and isAH)
{ {
isAx = true; isAx = true;
isAH=isAL=false; isAH=isAL=false;
} }
if(isDL && isDH) if(isDL and isDH)
{ {
isDx = true; isDx = true;
isDH=isDL=false; isDH=isDL=false;
} }
if(isBL && isBH) if(isBL and isBH)
{ {
isBx = true; isBx = true;
isBH=isBL=false; isBH=isBL=false;
} }
if(isCL && isCH) if(isCL and isCH)
{ {
isCx = true; isCx = true;
isCH=isCL=false; isCH=isCL=false;
} }
if (isAx && isDx) /* long or pointer */ if (isAx and isDx) /* long or pointer */
{ {
retVal.type = TYPE_LONG_SIGN; retVal.type = TYPE_LONG_SIGN;
retVal.loc = REG_FRAME; retVal.loc = REG_FRAME;
@ -1224,7 +1227,7 @@ void Function::preprocessReturnDU(LivenessSet &_liveOut)
/*idx = */localId.newLongReg(TYPE_LONG_SIGN, LONGID_TYPE(rDX,rAX), Icode.begin()); /*idx = */localId.newLongReg(TYPE_LONG_SIGN, LONGID_TYPE(rDX,rAX), Icode.begin());
localId.propLongId (rAX, rDX, "\0"); localId.propLongId (rAX, rDX, "\0");
} }
else if (isAx || isBx || isCx || isDx) /* uint16_t */ else if (isAx or isBx or isCx or isDx) /* uint16_t */
{ {
retVal.type = TYPE_WORD_SIGN; retVal.type = TYPE_WORD_SIGN;
retVal.loc = REG_FRAME; retVal.loc = REG_FRAME;
@ -1238,7 +1241,7 @@ void Function::preprocessReturnDU(LivenessSet &_liveOut)
retVal.id.regi = rDX; retVal.id.regi = rDX;
/*idx = */localId.newByteWordReg(TYPE_WORD_SIGN,retVal.id.regi); /*idx = */localId.newByteWordReg(TYPE_WORD_SIGN,retVal.id.regi);
} }
else if(isAL||isBL||isCL||isDL) else if(isAL or isBL or isCL or isDL)
{ {
retVal.type = TYPE_BYTE_SIGN; retVal.type = TYPE_BYTE_SIGN;
retVal.loc = REG_FRAME; retVal.loc = REG_FRAME;
@ -1252,7 +1255,7 @@ void Function::preprocessReturnDU(LivenessSet &_liveOut)
retVal.id.regi = rDL; retVal.id.regi = rDL;
/*idx = */localId.newByteWordReg(TYPE_BYTE_SIGN,retVal.id.regi); /*idx = */localId.newByteWordReg(TYPE_BYTE_SIGN,retVal.id.regi);
} }
else if(isAH||isBH||isCH||isDH) else if(isAH or isBH or isCH or isDH)
{ {
retVal.type = TYPE_BYTE_SIGN; retVal.type = TYPE_BYTE_SIGN;
retVal.loc = REG_FRAME; retVal.loc = REG_FRAME;

View File

@ -4,10 +4,18 @@
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
****************************************************************************/ ****************************************************************************/
#include "dcc.h"
#include "msvc_fixes.h"
#include "project.h"
#include "CallGraph.h"
#include "DccFrontend.h"
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
#ifdef LLVM_EXPERIMENTAL #ifdef LLVM_EXPERIMENTAL
#include <llvm/Support/raw_os_ostream.h> #include <llvm/Support/raw_os_ostream.h>
#include <llvm/Support/CommandLine.h> #include <llvm/Support/CommandLine.h>
@ -26,10 +34,6 @@
#endif #endif
#include <QtCore/QFile> #include <QtCore/QFile>
#include "dcc.h"
#include "project.h"
#include "CallGraph.h"
#include "DccFrontend.h"
/* Global variables - extern to other modules */ /* Global variables - extern to other modules */
extern QString asm1_name, asm2_name; /* Assembler output filenames */ extern QString asm1_name, asm2_name; /* Assembler output filenames */
@ -164,7 +168,7 @@ void setupOptions(QCoreApplication &app) {
option.filename = args.first(); option.filename = args.first();
if(parser.isSet(targetFileOption)) if(parser.isSet(targetFileOption))
asm1_name = asm2_name = parser.value(targetFileOption); asm1_name = asm2_name = parser.value(targetFileOption);
else if(option.asm1 || option.asm2) { else if(option.asm1 or option.asm2) {
asm1_name = option.filename+".a1"; asm1_name = option.filename+".a1";
asm2_name = option.filename+".a2"; asm2_name = option.filename+".a2";
} }

View File

@ -54,8 +54,7 @@ public:
IDcc* IDcc::get() { IDcc* IDcc::get() {
static IDcc *v=0; static IDcc *v=0;
if(!v) if(nullptr == v)
v = new DccImpl; v = new DccImpl;
return v; return v;
} }

View File

@ -2,6 +2,13 @@
* dcc project disassembler * dcc project disassembler
* (C) Cristina Cifuentes, Mike van Emmerik, Jeff Ledermann * (C) Cristina Cifuentes, Mike van Emmerik, Jeff Ledermann
****************************************************************************/ ****************************************************************************/
#include "disassem.h"
#include "dcc.h"
#include "msvc_fixes.h"
#include "symtab.h"
#include "project.h"
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
#include <map> #include <map>
@ -9,11 +16,6 @@
#include <iomanip> #include <iomanip>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "dcc.h"
#include "symtab.h"
#include "disassem.h"
#include "project.h"
// Note: for the time being, there is no interactive disassembler // Note: for the time being, there is no interactive disassembler
// for unix // for unix
@ -107,7 +109,7 @@ static vector<POSSTACK_ENTRY> posStack; /* position stack */
void LLInst::findJumpTargets(CIcodeRec &_pc) void LLInst::findJumpTargets(CIcodeRec &_pc)
{ {
if (testFlags(I) && ! testFlags(JMP_ICODE) && isJmpInst()) if (testFlags(I) and not testFlags(JMP_ICODE) and isJmpInst())
{ {
/* Replace the immediate operand with an icode index */ /* Replace the immediate operand with an icode index */
iICODE labTgt=_pc.labelSrch(src().getImm2()); iICODE labTgt=_pc.labelSrch(src().getImm2());
@ -216,9 +218,9 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
/* Disassembly stage 1 -- /* Disassembly stage 1 --
* Do not try to display NO_CODE entries or synthetic instructions, * Do not try to display NO_CODE entries or synthetic instructions,
* other than JMPs, that have been introduced for def/use analysis. */ * other than JMPs, that have been introduced for def/use analysis. */
if ((option.asm1) && if ((option.asm1) and
( inst.testFlags(NO_CODE) || ( inst.testFlags(NO_CODE) or
(inst.testFlags(SYNTHETIC) && (inst.getOpcode() != iJMP)))) (inst.testFlags(SYNTHETIC) and (inst.getOpcode() != iJMP))))
{ {
return; return;
} }
@ -273,7 +275,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
} }
oper_stream<< lab_contents.str(); oper_stream<< lab_contents.str();
} }
if ((inst.getOpcode()==iSIGNEX )&& inst.testFlags(B)) if ((inst.getOpcode()==iSIGNEX )and inst.testFlags(B))
{ {
inst.setOpcode(iCBW); inst.setOpcode(iCBW);
} }
@ -342,7 +344,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
{ {
ICODE *lab=pc.GetIcode(inst.src().getImm2()); ICODE *lab=pc.GetIcode(inst.src().getImm2());
selectTable(Label); selectTable(Label);
if ((inst.src().getImm2() < (uint32_t)numIcode) && /* Ensure in range */ if ((inst.src().getImm2() < (uint32_t)numIcode) and /* Ensure in range */
readVal(operands_s, lab->ll()->label, nullptr)) readVal(operands_s, lab->ll()->label, nullptr))
{ {
break; /* Symbolic label. Done */ break; /* Symbolic label. Done */
@ -416,14 +418,14 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
case iOUTS: case iREP_OUTS: case iOUTS: case iREP_OUTS:
if (inst.src().segOver) if (inst.src().segOver)
{ {
bool is_dx_src=(inst.getOpcode() == iOUTS || inst.getOpcode() == iREP_OUTS); bool is_dx_src=(inst.getOpcode() == iOUTS or inst.getOpcode() == iREP_OUTS);
if(is_dx_src) if(is_dx_src)
operands_s<<"dx, "<<szPtr[inst.getFlag() & B]; operands_s<<"dx, "<<szPtr[inst.getFlag() & B];
else else
operands_s<<szPtr[inst.getFlag() & B]; operands_s<<szPtr[inst.getFlag() & B];
if (inst.getOpcode() == iLODS || if (inst.getOpcode() == iLODS or
inst.getOpcode() == iREP_LODS || inst.getOpcode() == iREP_LODS or
inst.getOpcode() == iOUTS || inst.getOpcode() == iOUTS or
inst.getOpcode() == iREP_OUTS) inst.getOpcode() == iREP_OUTS)
{ {
operands_s<<Machine_X86::regName(inst.src().segOver); // szWreg[src.segOver-rAX] operands_s<<Machine_X86::regName(inst.src().segOver); // szWreg[src.segOver-rAX]
@ -473,7 +475,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
} }
else else
{ {
for (j = inst.label, fImpure = 0; j > 0 && j < (int)nextInst; j++) for (j = inst.label, fImpure = 0; j > 0 and j < (int)nextInst; j++)
{ {
fImpure |= BITMAP(j, BM_DATA); fImpure |= BITMAP(j, BM_DATA);
} }
@ -487,7 +489,7 @@ void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
{ {
result_stream <<"; "<<cbuf.str(); result_stream <<"; "<<cbuf.str();
} }
else if (fImpure || (inst.testFlags(SWITCH | CASE | SEG_IMMED | IMPURE | SYNTHETIC | TERMINATES))) else if (fImpure or (inst.testFlags(SWITCH | CASE | SEG_IMMED | IMPURE | SYNTHETIC | TERMINATES)))
{ {
if (inst.testFlags(CASE)) if (inst.testFlags(CASE))
{ {
@ -657,7 +659,7 @@ void LLInst::flops(std::ostringstream &out)
/* The mod/rm mod bits are not set to 11 (i.e. register). This is the normal floating point opcode */ /* The mod/rm mod bits are not set to 11 (i.e. register). This is the normal floating point opcode */
out<<Machine_X86::floatOpName(op)<<' '; out<<Machine_X86::floatOpName(op)<<' ';
out <<setw(10); out <<setw(10);
if ((op == 0x29) || (op == 0x1F)) if ((op == 0x29) or (op == 0x1F))
{ {
out << "tbyte ptr "; out << "tbyte ptr ";
} }
@ -726,7 +728,7 @@ void LLInst::flops(std::ostringstream &out)
break; break;
default: default:
out << Machine_X86::floatOpName(0x40+op); out << Machine_X86::floatOpName(0x40+op);
if ((op >= 0x20) && (op <= 0x27)) if ((op >= 0x20) and (op <= 0x27))
{ {
/* This is the ST(i), ST form. */ /* This is the ST(i), ST form. */
out << "ST("<<destRegIdx - rAX<<"),ST"; out << "ST("<<destRegIdx - rAX<<"),ST";

View File

@ -9,18 +9,15 @@
* * * *
\* * * * * * * * * * * * */ \* * * * * * * * * * * * */
#include "msvc_fixes.h"
#include <memory.h> #include <memory.h>
#include <stdint.h>
#ifndef PATLEN #ifndef PATLEN
#define PATLEN 23 #define PATLEN 23
#define WILD 0xF4 #define WILD 0xF4
#endif #endif
#ifndef bool
#define bool unsigned char
#define uint8_t unsigned char
#endif
static int pc; /* Indexes into pat[] */ static int pc; /* Indexes into pat[] */
/* prototypes */ /* prototypes */
@ -410,7 +407,7 @@ void fixWildCards(uint8_t pat[])
case 0xCD: /* int nn */ case 0xCD: /* int nn */
intArg = pat[pc++]; intArg = pat[pc++];
if ((intArg >= 0x34) && (intArg <= 0x3B)) if ((intArg >= 0x34) and (intArg <= 0x3B))
{ {
/* Borland/Microsoft FP emulations */ /* Borland/Microsoft FP emulations */
if (ModRM(pat)) return; if (ModRM(pat)) return;

View File

@ -1,396 +1,398 @@
/***************************************************************************** /*****************************************************************************
* dcc project CFG related functions * dcc project CFG related functions
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
****************************************************************************/ ****************************************************************************/
#include <string.h> #include "graph.h"
#include <boost/range/rbegin.hpp>
#include <boost/range/rend.hpp> #include "msvc_fixes.h"
#include <boost/range/adaptors.hpp> #include "dcc.h"
#include "project.h"
#include "dcc.h"
#include "graph.h" #include <boost/range/rbegin.hpp>
#include "project.h" #include <boost/range/rend.hpp>
#include <boost/range/adaptors.hpp>
using namespace std; #include <string.h>
using namespace boost;
extern Project g_proj; using namespace std;
//static BB * rmJMP(Function * pProc, int marker, BB * pBB); using namespace boost;
//static void mergeFallThrough(Function * pProc, BB * pBB); extern Project g_proj;
//static void dfsNumbering(BB * pBB, std::vector<BB*> &dfsLast, int *first, int *last); //static BB * rmJMP(Function * pProc, int marker, BB * pBB);
//static void mergeFallThrough(Function * pProc, BB * pBB);
void Function::addOutEdgesForConditionalJump(BB * pBB,int next_ip, LLInst *ll) //static void dfsNumbering(BB * pBB, std::vector<BB*> &dfsLast, int *first, int *last);
{
pBB->addOutEdge(next_ip); void Function::addOutEdgesForConditionalJump(BB * pBB,int next_ip, LLInst *ll)
/* This is checking for jumps off into nowhere */ {
if ( not ll->testFlags(NO_LABEL) ) pBB->addOutEdge(next_ip);
pBB->addOutEdge(ll->src().getImm2()); /* This is checking for jumps off into nowhere */
} if ( not ll->testFlags(NO_LABEL) )
pBB->addOutEdge(ll->src().getImm2());
/***************************************************************************** }
* createCFG - Create the basic control flow graph
****************************************************************************/ /*****************************************************************************
void Function::createCFG() * createCFG - Create the basic control flow graph
{ ****************************************************************************/
/* Splits Icode associated with the procedure into Basic Blocks. void Function::createCFG()
* The links between BBs represent the control flow graph of the {
* procedure. /* Splits Icode associated with the procedure into Basic Blocks.
* A Basic Block is defined to end on one of the following instructions: * The links between BBs represent the control flow graph of the
* 1) Conditional and unconditional jumps * procedure.
* 2) CALL(F) * A Basic Block is defined to end on one of the following instructions:
* 3) RET(F) * 1) Conditional and unconditional jumps
* 4) On the instruction before a join (a flagged TARGET) * 2) CALL(F)
* 5) Repeated string instructions * 3) RET(F)
* 6) End of procedure * 4) On the instruction before a join (a flagged TARGET)
*/ * 5) Repeated string instructions
* 6) End of procedure
BB * psBB; */
BB * pBB;
iICODE pIcode = Icode.begin(); BB * psBB;
BB * pBB;
stats.numBBbef = stats.numBBaft = 0; iICODE pIcode = Icode.begin();
rICODE current_range=make_iterator_range(pIcode,++iICODE(pIcode));
for (; pIcode!=Icode.end(); ++pIcode,current_range.advance_end(1)) stats.numBBbef = stats.numBBaft = 0;
{ rICODE current_range=make_iterator_range(pIcode,++iICODE(pIcode));
iICODE nextIcode = ++iICODE(pIcode); for (; pIcode!=Icode.end(); ++pIcode,current_range.advance_end(1))
pBB = nullptr; {
iICODE nextIcode = ++iICODE(pIcode);
LLInst *ll = pIcode->ll(); pBB = nullptr;
/* Only process icodes that have valid instructions */
if(ll->testFlags(NO_CODE)) LLInst *ll = pIcode->ll();
continue; /* Only process icodes that have valid instructions */
/* Stick a NOWHERE_NODE on the end if we terminate if(ll->testFlags(NO_CODE))
* with anything other than a ret, jump or terminate */ continue;
if (nextIcode == Icode.end() and /* Stick a NOWHERE_NODE on the end if we terminate
(not ll->testFlags(TERMINATES)) and * with anything other than a ret, jump or terminate */
(not ll->match(iJMP)) and (not ll->match(iJMPF)) and if (nextIcode == Icode.end() and
(not ll->match(iRET)) and (not ll->match(iRETF))) (not ll->testFlags(TERMINATES)) and
{ (not ll->match(iJMP)) and (not ll->match(iJMPF)) and
pBB=BB::Create(current_range, NOWHERE_NODE, this); (not ll->match(iRET)) and (not ll->match(iRETF)))
} {
else pBB=BB::Create(current_range, NOWHERE_NODE, this);
switch (ll->getOpcode()) { }
case iJB: case iJBE: case iJAE: case iJA: else
case iJL: case iJLE: case iJGE: case iJG: switch (ll->getOpcode()) {
case iJE: case iJNE: case iJS: case iJNS: case iJB: case iJBE: case iJAE: case iJA:
case iJO: case iJNO: case iJP: case iJNP: case iJL: case iJLE: case iJGE: case iJG:
case iJCXZ: case iJE: case iJNE: case iJS: case iJNS:
pBB = BB::Create(current_range, TWO_BRANCH, this); case iJO: case iJNO: case iJP: case iJNP:
addOutEdgesForConditionalJump(pBB,nextIcode->loc_ip, ll); case iJCXZ:
break; pBB = BB::Create(current_range, TWO_BRANCH, this);
addOutEdgesForConditionalJump(pBB,nextIcode->loc_ip, ll);
case iLOOP: case iLOOPE: case iLOOPNE: break;
pBB = BB::Create(current_range, LOOP_NODE, this);
addOutEdgesForConditionalJump(pBB,nextIcode->loc_ip, ll); case iLOOP: case iLOOPE: case iLOOPNE:
break; pBB = BB::Create(current_range, LOOP_NODE, this);
addOutEdgesForConditionalJump(pBB,nextIcode->loc_ip, ll);
case iJMPF: case iJMP: break;
if (ll->testFlags(SWITCH))
{ case iJMPF: case iJMP:
pBB = BB::Create(current_range, MULTI_BRANCH, this); if (ll->testFlags(SWITCH))
for (auto & elem : ll->caseTbl2) {
pBB->addOutEdge(elem); pBB = BB::Create(current_range, MULTI_BRANCH, this);
hasCase = true; for (auto & elem : ll->caseTbl2)
} pBB->addOutEdge(elem);
else if ((ll->getFlag() & (I | NO_LABEL)) == I) //TODO: WHY NO_LABEL TESTIT hasCase = true;
{ }
pBB = BB::Create(current_range, ONE_BRANCH, this); else if ((ll->getFlag() & (I | NO_LABEL)) == I) //TODO: WHY NO_LABEL TESTIT
pBB->addOutEdge(ll->src().getImm2()); {
} pBB = BB::Create(current_range, ONE_BRANCH, this);
else pBB->addOutEdge(ll->src().getImm2());
pBB = BB::Create(current_range, NOWHERE_NODE, this); }
break; else
pBB = BB::Create(current_range, NOWHERE_NODE, this);
case iCALLF: case iCALL: break;
{
Function * p = ll->src().proc.proc; case iCALLF: case iCALL:
pBB = BB::Create(current_range, CALL_NODE, this); {
if (p && not ((p->flg) & TERMINATES) ) Function * p = ll->src().proc.proc;
pBB->addOutEdge(nextIcode->loc_ip); pBB = BB::Create(current_range, CALL_NODE, this);
break; if (p and not ((p->flg) & TERMINATES) )
} pBB->addOutEdge(nextIcode->loc_ip);
break;
case iRET: case iRETF: }
pBB = BB::Create(current_range, RETURN_NODE, this);
break; case iRET: case iRETF:
pBB = BB::Create(current_range, RETURN_NODE, this);
default: break;
/* Check for exit to DOS */
if ( ll->testFlags(TERMINATES) ) default:
{ /* Check for exit to DOS */
pBB = BB::Create(current_range, TERMINATE_NODE, this); if ( ll->testFlags(TERMINATES) )
} {
/* Check for a fall through */ pBB = BB::Create(current_range, TERMINATE_NODE, this);
else if (nextIcode != Icode.end()) }
{ /* Check for a fall through */
if (nextIcode->ll()->testFlags(TARGET | CASE)) else if (nextIcode != Icode.end())
{ {
pBB = BB::Create(current_range, FALL_NODE, this); if (nextIcode->ll()->testFlags(TARGET | CASE))
pBB->addOutEdge(nextIcode->loc_ip); {
} pBB = BB::Create(current_range, FALL_NODE, this);
} pBB->addOutEdge(nextIcode->loc_ip);
break; }
} }
if(pBB!=nullptr) // created a new Basic block break;
{ }
// restart the range if(pBB!=nullptr) // created a new Basic block
// end iterator will be updated by expression in for statement {
current_range=make_iterator_range(nextIcode,nextIcode); // restart the range
} // end iterator will be updated by expression in for statement
if (nextIcode == Icode.end()) current_range=make_iterator_range(nextIcode,nextIcode);
break; }
} if (nextIcode == Icode.end())
for (auto pr : m_ip_to_bb) break;
{ }
BB* pBB=pr.second; for (auto pr : m_ip_to_bb)
for (auto & elem : pBB->edges) {
{ BB* pBB=pr.second;
int32_t ip = elem.ip; for (auto & elem : pBB->edges)
if (ip >= SYNTHESIZED_MIN) {
{ int32_t ip = elem.ip;
fatalError (INVALID_SYNTHETIC_BB); if (ip >= SYNTHESIZED_MIN)
return; {
} fatalError (INVALID_SYNTHETIC_BB);
auto iter2=m_ip_to_bb.find(ip); return;
if(iter2==m_ip_to_bb.end()) }
fatalError(NO_BB, ip, name.c_str()); auto iter2=m_ip_to_bb.find(ip);
psBB = iter2->second; if(iter2==m_ip_to_bb.end())
elem.BBptr = psBB; fatalError(NO_BB, ip, name.c_str());
psBB->inEdges.push_back((BB *)nullptr); psBB = iter2->second;
} elem.BBptr = psBB;
} psBB->inEdges.push_back((BB *)nullptr);
} }
}
void Function::markImpure() }
{
PROG &prog(Project::get()->prog); void Function::markImpure()
for(ICODE &icod : Icode) {
{ PROG &prog(Project::get()->prog);
if ( not icod.ll()->testFlags(SYM_USE | SYM_DEF)) for(ICODE &icod : Icode)
continue; {
//assert that case tbl has less entries then symbol table ???? if ( not icod.ll()->testFlags(SYM_USE | SYM_DEF))
//WARNING: Case entries are held in symbol table ! continue;
assert(Project::get()->validSymIdx(icod.ll()->caseEntry)); //assert that case tbl has less entries then symbol table ????
const SYM &psym(Project::get()->getSymByIdx(icod.ll()->caseEntry)); //WARNING: Case entries are held in symbol table !
for (int c = (int)psym.label; c < (int)psym.label+psym.size; c++) assert(Project::get()->validSymIdx(icod.ll()->caseEntry));
{ const SYM &psym(Project::get()->getSymByIdx(icod.ll()->caseEntry));
if (BITMAP(c, BM_CODE)) for (int c = (int)psym.label; c < (int)psym.label+psym.size; c++)
{ {
icod.ll()->setFlags(IMPURE); if (BITMAP(c, BM_CODE))
flg |= IMPURE; {
break; icod.ll()->setFlags(IMPURE);
} flg |= IMPURE;
} break;
} }
}
} }
/***************************************************************************** }
* freeCFG - Deallocates a cfg
****************************************************************************/ /*****************************************************************************
void Function::freeCFG() * freeCFG - Deallocates a cfg
{ ****************************************************************************/
for(auto p : m_ip_to_bb) void Function::freeCFG()
{ {
delete p.second; for(auto p : m_ip_to_bb)
} {
m_ip_to_bb.clear(); delete p.second;
} }
m_ip_to_bb.clear();
}
/*****************************************************************************
* compressCFG - Remove redundancies and add in-edge information
****************************************************************************/ /*****************************************************************************
void Function::compressCFG() * compressCFG - Remove redundancies and add in-edge information
{ ****************************************************************************/
BB *pNxt; void Function::compressCFG()
int ip, first=0, last; {
BB *pNxt;
/* First pass over BB list removes redundant jumps of the form int ip, first=0, last;
* (Un)Conditional -> Unconditional jump */
for (BB *pBB : m_actual_cfg) //m_cfg /* First pass over BB list removes redundant jumps of the form
{ * (Un)Conditional -> Unconditional jump */
if(pBB->inEdges.empty() || (pBB->nodeType != ONE_BRANCH && pBB->nodeType != TWO_BRANCH)) for (BB *pBB : m_actual_cfg) //m_cfg
continue; {
for (TYPEADR_TYPE &edgeRef : pBB->edges) if(pBB->inEdges.empty() or (pBB->nodeType != ONE_BRANCH and pBB->nodeType != TWO_BRANCH))
{ continue;
ip = pBB->rbegin()->loc_ip; for (TYPEADR_TYPE &edgeRef : pBB->edges)
pNxt = edgeRef.BBptr->rmJMP(ip, edgeRef.BBptr); {
ip = pBB->rbegin()->loc_ip;
if (not pBB->edges.empty()) /* Might have been clobbered */ pNxt = edgeRef.BBptr->rmJMP(ip, edgeRef.BBptr);
{
edgeRef.BBptr = pNxt; if (not pBB->edges.empty()) /* Might have been clobbered */
assert(pBB->back().loc_ip==ip); {
pBB->back().ll()->SetImmediateOp((uint32_t)pNxt->begin()->loc_ip); edgeRef.BBptr = pNxt;
//Icode[ip].SetImmediateOp((uint32_t)pNxt->begin()); assert(pBB->back().loc_ip==ip);
} pBB->back().ll()->SetImmediateOp((uint32_t)pNxt->begin()->loc_ip);
} //Icode[ip].SetImmediateOp((uint32_t)pNxt->begin());
} }
}
/* Next is a depth-first traversal merging any FALL_NODE or }
* ONE_BRANCH that fall through to a node with that as their only
* in-edge. */ /* Next is a depth-first traversal merging any FALL_NODE or
m_actual_cfg.front()->mergeFallThrough(Icode); * ONE_BRANCH that fall through to a node with that as their only
* in-edge. */
/* Remove redundant BBs created by the above compressions m_actual_cfg.front()->mergeFallThrough(Icode);
* and allocate in-edge arrays as required. */
stats.numBBaft = stats.numBBbef; /* Remove redundant BBs created by the above compressions
bool entry_node=true; * and allocate in-edge arrays as required. */
for(BB *pBB : m_actual_cfg) stats.numBBaft = stats.numBBbef;
{ bool entry_node=true;
if (pBB->inEdges.empty()) for(BB *pBB : m_actual_cfg)
{ {
if (entry_node) /* Init it misses out on */ if (pBB->inEdges.empty())
pBB->index = UN_INIT; {
else if (entry_node) /* Init it misses out on */
{ pBB->index = UN_INIT;
delete pBB; else
stats.numBBaft--; {
} delete pBB;
} stats.numBBaft--;
else }
{ }
pBB->inEdgeCount = pBB->inEdges.size(); else
} {
entry_node=false; pBB->inEdgeCount = pBB->inEdges.size();
} }
entry_node=false;
/* Allocate storage for dfsLast[] array */ }
numBBs = stats.numBBaft;
m_dfsLast.resize(numBBs,nullptr); // = (BB **)allocMem(numBBs * sizeof(BB *)) /* Allocate storage for dfsLast[] array */
numBBs = stats.numBBaft;
/* Now do a dfs numbering traversal and fill in the inEdges[] array */ m_dfsLast.resize(numBBs,nullptr); // = (BB **)allocMem(numBBs * sizeof(BB *))
last = numBBs - 1;
m_actual_cfg.front()->dfsNumbering(m_dfsLast, &first, &last); /* Now do a dfs numbering traversal and fill in the inEdges[] array */
} last = numBBs - 1;
m_actual_cfg.front()->dfsNumbering(m_dfsLast, &first, &last);
}
/****************************************************************************
* rmJMP - If BB addressed is just a JMP it is replaced with its target
***************************************************************************/ /****************************************************************************
BB *BB::rmJMP(int marker, BB * pBB) * rmJMP - If BB addressed is just a JMP it is replaced with its target
{ ***************************************************************************/
marker += (int)DFS_JMP; BB *BB::rmJMP(int marker, BB * pBB)
{
while (pBB->nodeType == ONE_BRANCH && pBB->size() == 1) marker += (int)DFS_JMP;
{
if (pBB->traversed != marker) while (pBB->nodeType == ONE_BRANCH and pBB->size() == 1)
{ {
pBB->traversed = (eDFS)marker; if (pBB->traversed != marker)
pBB->inEdges.pop_back(); {
if (not pBB->inEdges.empty()) pBB->traversed = (eDFS)marker;
{ pBB->inEdges.pop_back();
pBB->edges[0].BBptr->inEdges.push_back((BB *)nullptr); if (not pBB->inEdges.empty())
} {
else pBB->edges[0].BBptr->inEdges.push_back((BB *)nullptr);
{ }
pBB->front().ll()->setFlags(NO_CODE); else
pBB->front().invalidate(); //pProc->Icode.SetLlInvalid(pBB->begin(), true); {
} pBB->front().ll()->setFlags(NO_CODE);
pBB->front().invalidate(); //pProc->Icode.SetLlInvalid(pBB->begin(), true);
pBB = pBB->edges[0].BBptr; }
}
else pBB = pBB->edges[0].BBptr;
{ }
/* We are going around in circles */ else
pBB->nodeType = NOWHERE_NODE; {
pBB->front().ll()->replaceSrc(LLOperand::CreateImm2(pBB->front().loc_ip)); /* We are going around in circles */
//pBB->front().ll()->src.immed.op = pBB->front().loc_ip; pBB->nodeType = NOWHERE_NODE;
do { pBB->front().ll()->replaceSrc(LLOperand::CreateImm2(pBB->front().loc_ip));
pBB = pBB->edges[0].BBptr; //pBB->front().ll()->src.immed.op = pBB->front().loc_ip;
pBB->inEdges.pop_back(); // was --numInedges do {
if (! pBB->inEdges.empty()) pBB = pBB->edges[0].BBptr;
{ pBB->inEdges.pop_back(); // was --numInedges
pBB->front().ll()->setFlags(NO_CODE); if (not pBB->inEdges.empty())
pBB->front().invalidate(); {
// pProc->Icode.setFlags(pBB->start, NO_CODE); pBB->front().ll()->setFlags(NO_CODE);
// pProc->Icode.SetLlInvalid(pBB->start, true); pBB->front().invalidate();
} // pProc->Icode.setFlags(pBB->start, NO_CODE);
} while (pBB->nodeType != NOWHERE_NODE); // pProc->Icode.SetLlInvalid(pBB->start, true);
}
pBB->edges.clear(); } while (pBB->nodeType != NOWHERE_NODE);
}
} pBB->edges.clear();
return pBB; }
} }
return pBB;
}
/*****************************************************************************
* mergeFallThrough
****************************************************************************/ /*****************************************************************************
void BB::mergeFallThrough( CIcodeRec &Icode) * mergeFallThrough
{ ****************************************************************************/
BB * pChild; void BB::mergeFallThrough( CIcodeRec &Icode)
if (!this) {
{ BB * pChild;
printf("mergeFallThrough on empty BB!\n"); if (nullptr==this)
} {
while (nodeType == FALL_NODE || nodeType == ONE_BRANCH) printf("mergeFallThrough on empty BB!\n");
{ }
pChild = edges[0].BBptr; while (nodeType == FALL_NODE or nodeType == ONE_BRANCH)
/* Jump to next instruction can always be removed */ {
if (nodeType == ONE_BRANCH) pChild = edges[0].BBptr;
{ /* Jump to next instruction can always be removed */
assert(Parent==pChild->Parent); if (nodeType == ONE_BRANCH)
if(back().loc_ip>pChild->front().loc_ip) // back edege {
break; assert(Parent==pChild->Parent);
auto iter=std::find_if(this->end(),pChild->begin(),[](ICODE &c) if(back().loc_ip>pChild->front().loc_ip) // back edege
{return not c.ll()->testFlags(NO_CODE);}); break;
auto iter=std::find_if(this->end(),pChild->begin(),[](ICODE &c)
if (iter != pChild->begin()) {return not c.ll()->testFlags(NO_CODE);});
break;
back().ll()->setFlags(NO_CODE); if (iter != pChild->begin())
back().invalidate(); break;
nodeType = FALL_NODE; back().ll()->setFlags(NO_CODE);
//instructions.advance_end(-1); //TODO: causes creation of empty BB back().invalidate();
} nodeType = FALL_NODE;
/* If there's no other edges into child can merge */ //instructions.advance_end(-1); //TODO: causes creation of empty BB
if (pChild->inEdges.size() != 1) }
break; /* If there's no other edges into child can merge */
if (pChild->inEdges.size() != 1)
nodeType = pChild->nodeType; break;
instructions = boost::make_iterator_range(begin(),pChild->end());
pChild->front().ll()->clrFlags(TARGET); nodeType = pChild->nodeType;
edges.swap(pChild->edges); instructions = boost::make_iterator_range(begin(),pChild->end());
pChild->front().ll()->clrFlags(TARGET);
pChild->inEdges.clear(); edges.swap(pChild->edges);
pChild->edges.clear();
} pChild->inEdges.clear();
traversed = DFS_MERGE; pChild->edges.clear();
}
/* Process all out edges recursively */ traversed = DFS_MERGE;
for (auto & elem : edges)
{ /* Process all out edges recursively */
if (elem.BBptr->traversed != DFS_MERGE) for (auto & elem : edges)
elem.BBptr->mergeFallThrough(Icode); {
} if (elem.BBptr->traversed != DFS_MERGE)
} elem.BBptr->mergeFallThrough(Icode);
}
}
/*****************************************************************************
* dfsNumbering - Numbers nodes during first and last visits and determine
* in-edges /*****************************************************************************
****************************************************************************/ * dfsNumbering - Numbers nodes during first and last visits and determine
void BB::dfsNumbering(std::vector<BB *> &dfsLast, int *first, int *last) * in-edges
{ ****************************************************************************/
BB * pChild; void BB::dfsNumbering(std::vector<BB *> &dfsLast, int *first, int *last)
traversed = DFS_NUM; {
dfsFirstNum = (*first)++; BB * pChild;
traversed = DFS_NUM;
/* index is being used as an index to inEdges[]. */ dfsFirstNum = (*first)++;
// for (i = 0; i < edges.size(); i++)
for(auto edge : edges) /* index is being used as an index to inEdges[]. */
{ // for (i = 0; i < edges.size(); i++)
pChild = edge.BBptr; for(auto edge : edges)
pChild->inEdges[pChild->index++] = this; {
pChild = edge.BBptr;
/* Is this the last visit? */ pChild->inEdges[pChild->index++] = this;
if (pChild->index == int(pChild->inEdges.size()))
pChild->index = UN_INIT; /* Is this the last visit? */
if (pChild->index == int(pChild->inEdges.size()))
if (pChild->traversed != DFS_NUM) pChild->index = UN_INIT;
pChild->dfsNumbering(dfsLast, first, last);
} if (pChild->traversed != DFS_NUM)
dfsLastNum = *last; pChild->dfsNumbering(dfsLast, first, last);
dfsLast[(*last)--] = this; }
} dfsLastNum = *last;
dfsLast[(*last)--] = this;
}

View File

@ -24,7 +24,7 @@ void HLTYPE::setAsgn(Expr *lhs, Expr *rhs)
} }
void ICODE::checkHlCall() void ICODE::checkHlCall()
{ {
//assert((ll()->immed.proc.cb != 0)||ll()->immed.proc.proc!=0); //assert((ll()->immed.proc.cb != 0) or ll()->immed.proc.proc!=0);
} }
/* Places the new HLI_CALL high-level operand in the high-level icode array */ /* Places the new HLI_CALL high-level operand in the high-level icode array */
void ICODE::newCallHl() void ICODE::newCallHl()
@ -83,7 +83,7 @@ bool ICODE::removeDefRegi (eReg regi, int thisDefIdx, LOCAL_ID *locId)
for ( ; numDefs > 0; numDefs--) for ( ; numDefs > 0; numDefs--)
{ {
if (du1.used(numDefs-1)||(du.lastDefRegi.testReg(regi))) if (du1.used(numDefs-1) or (du.lastDefRegi.testReg(regi)))
break; break;
} }
} }
@ -328,7 +328,7 @@ void Function::highLevelGen()
{ {
if ( not ll->testFlags(NO_SRC) ) /* if there is src op */ if ( not ll->testFlags(NO_SRC) ) /* if there is src op */
rhs = AstIdent::id (*pIcode->ll(), SRC, this, i, *pIcode, NONE); rhs = AstIdent::id (*pIcode->ll(), SRC, this, i, *pIcode, NONE);
if(ll->m_dst.isSet() || (ll->getOpcode()==iMOD)) if(ll->m_dst.isSet() or (ll->getOpcode()==iMOD))
lhs = AstIdent::id (*pIcode->ll(), DST, this, i, *pIcode, NONE); lhs = AstIdent::id (*pIcode->ll(), DST, this, i, *pIcode, NONE);
} }
if(ll->getOpcode()==iPUSH) { if(ll->getOpcode()==iPUSH) {

View File

@ -1,13 +1,13 @@
// Object oriented icode code for dcc // Object oriented icode code for dcc
// (C) 1997 Mike Van Emmerik // (C) 1997 Mike Van Emmerik
#include "icode.h"
#include <stdlib.h> #include "msvc_fixes.h"
#include "dcc.h" #include "dcc.h"
#include "types.h" // Common types like uint8_t, etc #include "types.h" // Common types like uint8_t, etc
#include "ast.h" // Some icode types depend on these #include "ast.h" // Some icode types depend on these
#include "icode.h"
#include <stdlib.h>
ICODE::TypeFilter<HIGH_LEVEL> ICODE::select_high_level; ICODE::TypeFilter<HIGH_LEVEL> ICODE::select_high_level;
ICODE::TypeAndValidFilter<HIGH_LEVEL> ICODE::select_valid_high_level; ICODE::TypeAndValidFilter<HIGH_LEVEL> ICODE::select_valid_high_level;
@ -87,7 +87,7 @@ void LLInst::emitGotoLabel (int indLevel)
bool LLOperand::isReg() const bool LLOperand::isReg() const
{ {
return (regi>=rAX) && (regi<=rTMP); return (regi>=rAX) and (regi<=rTMP);
} }
void LLOperand::addProcInformation(int param_count, CConv::Type call_conv) void LLOperand::addProcInformation(int param_count, CConv::Type call_conv)
{ {

View File

@ -4,14 +4,11 @@
****************************************************************************/ ****************************************************************************/
//#include <llvm/Config/llvm-config.h> //#include <llvm/Config/llvm-config.h>
//#if( (LLVM_VERSION_MAJOR==3 ) && (LLVM_VERSION_MINOR>3) ) //#if( (LLVM_VERSION_MAJOR==3 ) and (LLVM_VERSION_MINOR>3) )
//#include <llvm/IR/PatternMatch.h> //#include <llvm/IR/PatternMatch.h>
//#else //#else
//#include <llvm/Support/PatternMatch.h> //#include <llvm/Support/PatternMatch.h>
//#endif //#endif
#include <boost/iterator/filter_iterator.hpp>
#include <cstring>
#include <deque>
#include "idiom.h" #include "idiom.h"
#include "idiom1.h" #include "idiom1.h"
#include "epilogue_idioms.h" #include "epilogue_idioms.h"
@ -22,6 +19,11 @@
#include "shift_idioms.h" #include "shift_idioms.h"
#include "arith_idioms.h" #include "arith_idioms.h"
#include "dcc.h" #include "dcc.h"
#include "msvc_fixes.h"
#include <boost/iterator/filter_iterator.hpp>
#include <cstring>
#include <deque>
/***************************************************************************** /*****************************************************************************
* JmpInst - Returns true if opcode is a conditional or unconditional jump * JmpInst - Returns true if opcode is a conditional or unconditional jump
****************************************************************************/ ****************************************************************************/
@ -122,11 +124,11 @@ void Function::findIdioms()
/* Check for library functions that return a long register. /* Check for library functions that return a long register.
* Propagate this result */ * Propagate this result */
if (pIcode->ll()->src().proc.proc != nullptr) if (pIcode->ll()->src().proc.proc != nullptr)
if ((pIcode->ll()->src().proc.proc->flg & PROC_ISLIB) && if ((pIcode->ll()->src().proc.proc->flg & PROC_ISLIB) and
(pIcode->ll()->src().proc.proc->flg & PROC_IS_FUNC)) (pIcode->ll()->src().proc.proc->flg & PROC_IS_FUNC))
{ {
if ((pIcode->ll()->src().proc.proc->retVal.type==TYPE_LONG_SIGN) if ((pIcode->ll()->src().proc.proc->retVal.type==TYPE_LONG_SIGN)
|| (pIcode->ll()->src().proc.proc->retVal.type == TYPE_LONG_UNSIGN)) or (pIcode->ll()->src().proc.proc->retVal.type == TYPE_LONG_UNSIGN))
localId.newLongReg(TYPE_LONG_SIGN, LONGID_TYPE(rDX,rAX), pIcode/*ip*/); localId.newLongReg(TYPE_LONG_SIGN, LONGID_TYPE(rDX,rAX), pIcode/*ip*/);
} }
@ -209,7 +211,7 @@ void Function::findIdioms()
} }
/* Check if number of parameter bytes match their calling convention */ /* Check if number of parameter bytes match their calling convention */
if ((flg & PROC_HLL) && (!args.empty())) if ((flg & PROC_HLL) and (!args.empty()))
{ {
args.m_minOff += (flg & PROC_FAR ? 4 : 2); args.m_minOff += (flg & PROC_FAR ? 4 : 2);
delta = args.maxOff - args.m_minOff; delta = args.maxOff - args.m_minOff;
@ -236,7 +238,7 @@ void Function::bindIcodeOff()
for(ICODE &c : Icode) // TODO: use filtered here for(ICODE &c : Icode) // TODO: use filtered here
{ {
LLInst *ll=c.ll(); LLInst *ll=c.ll();
if (ll->testFlags(I) && ll->isJmpInst()) if (ll->testFlags(I) and ll->isJmpInst())
{ {
iICODE loc=Icode.labelSrch(ll->src().getImm2()); iICODE loc=Icode.labelSrch(ll->src().getImm2());
if (loc!=Icode.end()) if (loc!=Icode.end())

View File

@ -1,5 +1,8 @@
#include "dcc.h"
#include "arith_idioms.h" #include "arith_idioms.h"
#include "dcc.h"
#include "msvc_fixes.h"
using namespace std; using namespace std;
/***************************************************************************** /*****************************************************************************
@ -105,7 +108,7 @@ bool Idiom18::match(iICODE picode)
if(not m_icodes[0]->ll()->matchWithRegDst(iMOV) ) if(not m_icodes[0]->ll()->matchWithRegDst(iMOV) )
return false; return false;
regi = m_icodes[0]->ll()->m_dst.regi; regi = m_icodes[0]->ll()->m_dst.regi;
if( not ( m_icodes[2]->ll()->match(iCMP,regi) && if( not ( m_icodes[2]->ll()->match(iCMP,regi) and
m_icodes[3]->ll()->conditionalJump() ) ) m_icodes[3]->ll()->conditionalJump() ) )
return false; return false;
// Simple matching finished, select apropriate matcher based on dst type // Simple matching finished, select apropriate matcher based on dst type
@ -118,9 +121,9 @@ bool Idiom18::match(iICODE picode)
else if ( m_icodes[1]->ll()->m_dst.isReg() ) /* register */ else if ( m_icodes[1]->ll()->m_dst.isReg() ) /* register */
{ {
m_idiom_type = 1; m_idiom_type = 1;
// if ((m_icodes[1]->ll()->dst.regi == rSI) && (m_func->flg & SI_REGVAR)) // if ((m_icodes[1]->ll()->dst.regi == rSI) and (m_func->flg & SI_REGVAR))
// m_idiom_type = 1; // m_idiom_type = 1;
// else if ((m_icodes[1]->ll()->dst.regi == rDI) && (m_func->flg & DI_REGVAR)) // else if ((m_icodes[1]->ll()->dst.regi == rDI) and (m_func->flg & DI_REGVAR))
// m_idiom_type = 1; // m_idiom_type = 1;
} }
else if (m_icodes[1]->ll()->m_dst.off) /* local variable */ else if (m_icodes[1]->ll()->m_dst.off) /* local variable */
@ -204,8 +207,8 @@ bool Idiom19::match(iICODE picode)
/* not supported yet */ ; /* not supported yet */ ;
else if ( m_icodes[0]->ll()->m_dst.isReg() ) /* register */ else if ( m_icodes[0]->ll()->m_dst.isReg() ) /* register */
{ {
// if (((picode->ll()->dst.regi == rSI) && (pproc->flg & SI_REGVAR)) || // if (((picode->ll()->dst.regi == rSI) and (pproc->flg & SI_REGVAR)) or
// ((picode->ll()->dst.regi == rDI) && (pproc->flg & DI_REGVAR))) // ((picode->ll()->dst.regi == rDI) and (pproc->flg & DI_REGVAR)))
return true; return true;
} }
else if (m_icodes[0]->ll()->m_dst.off) /* stack variable */ else if (m_icodes[0]->ll()->m_dst.off) /* stack variable */
@ -271,9 +274,9 @@ bool Idiom20::match(iICODE picode)
else if ( ll_dest.isReg() ) /* register */ else if ( ll_dest.isReg() ) /* register */
{ {
type = 1; type = 1;
// if ((ll_dest.regi == rSI) && (m_func->flg & SI_REGVAR)) // if ((ll_dest.regi == rSI) and (m_func->flg & SI_REGVAR))
// type = 1; // type = 1;
// else if ((ll_dest.regi == rDI) && (m_func->flg & DI_REGVAR)) // else if ((ll_dest.regi == rDI) and (m_func->flg & DI_REGVAR))
// type = 1; // type = 1;
} }
else if (ll_dest.off) /* local variable */ else if (ll_dest.off) /* local variable */
@ -286,7 +289,7 @@ bool Idiom20::match(iICODE picode)
} }
regi = m_icodes[1]->ll()->m_dst.regi; regi = m_icodes[1]->ll()->m_dst.regi;
const LLOperand &mov_src(m_icodes[1]->ll()->src()); const LLOperand &mov_src(m_icodes[1]->ll()->src());
if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) && m_icodes[3]->ll()->conditionalJump()) if (m_icodes[2]->ll()->match(iCMP,(eReg)regi) and m_icodes[3]->ll()->conditionalJump())
{ {
switch(type) switch(type)
{ {

View File

@ -1,5 +1,8 @@
#include "dcc.h"
#include "call_idioms.h" #include "call_idioms.h"
#include "dcc.h"
#include "msvc_fixes.h"
using namespace std; using namespace std;
/***************************************************************************** /*****************************************************************************
* idiom3 - C calling convention. * idiom3 - C calling convention.
@ -22,7 +25,7 @@ bool Idiom3::match(iICODE picode)
/* Match ADD SP, immed */ /* Match ADD SP, immed */
for(int i=0; i<2; ++i) for(int i=0; i<2; ++i)
m_icodes[i] = picode++; m_icodes[i] = picode++;
if ( m_icodes[1]->ll()->testFlags(I) && m_icodes[1]->ll()->match(iADD,rSP)) if ( m_icodes[1]->ll()->testFlags(I) and m_icodes[1]->ll()->match(iADD,rSP))
{ {
m_param_count = m_icodes[1]->ll()->src().getImm2(); m_param_count = m_icodes[1]->ll()->src().getImm2();
return true; return true;
@ -78,10 +81,10 @@ bool Idiom17::match(iICODE picode)
{ {
int i=0; int i=0;
regi = m_icodes[1]->ll()->m_dst.regi; regi = m_icodes[1]->ll()->m_dst.regi;
if ((regi >= rAX) && (regi <= rBX)) if ((regi >= rAX) and (regi <= rBX))
i++; i++;
while (picode != m_end && picode->ll()->match(iPOP)) while (picode != m_end and picode->ll()->match(iPOP))
{ {
if (picode->ll()->m_dst.regi != regi) if (picode->ll()->m_dst.regi != regi)
break; break;

View File

@ -1,6 +1,8 @@
#include "dcc.h"
#include "epilogue_idioms.h" #include "epilogue_idioms.h"
#include "dcc.h"
#include "msvc_fixes.h"
/***************************************************************************** /*****************************************************************************
* popStkVars - checks for * popStkVars - checks for
* [POP DI] * [POP DI]
@ -14,9 +16,9 @@ void EpilogIdiom::popStkVars(iICODE pIcode)
/* Match [POP DI] */ /* Match [POP DI] */
if (pIcode->ll()->match(iPOP)) if (pIcode->ll()->match(iPOP))
{ {
if ((m_func->flg & DI_REGVAR) && pIcode->ll()->match(rDI)) if ((m_func->flg & DI_REGVAR) and pIcode->ll()->match(rDI))
m_icodes.push_front(pIcode); m_icodes.push_front(pIcode);
else if ((m_func->flg & SI_REGVAR) && pIcode->ll()->match(rSI)) else if ((m_func->flg & SI_REGVAR) and pIcode->ll()->match(rSI))
m_icodes.push_front(pIcode); m_icodes.push_front(pIcode);
} }
++pIcode; ++pIcode;
@ -25,9 +27,9 @@ void EpilogIdiom::popStkVars(iICODE pIcode)
/* Match [POP SI] */ /* Match [POP SI] */
if (pIcode->ll()->match(iPOP)) if (pIcode->ll()->match(iPOP))
{ {
if ((m_func->flg & SI_REGVAR) && pIcode->ll()->match(rSI)) if ((m_func->flg & SI_REGVAR) and pIcode->ll()->match(rSI))
m_icodes.push_front(pIcode); m_icodes.push_front(pIcode);
else if ((m_func->flg & DI_REGVAR) && pIcode->ll()->match(rDI)) else if ((m_func->flg & DI_REGVAR) and pIcode->ll()->match(rDI))
m_icodes.push_front(pIcode); m_icodes.push_front(pIcode);
} }
} }
@ -46,7 +48,7 @@ bool Idiom2::match(iICODE pIcode)
iICODE nicode; iICODE nicode;
if(pIcode==m_func->Icode.begin()) // pIcode->loc_ip == 0 if(pIcode==m_func->Icode.begin()) // pIcode->loc_ip == 0
return false; return false;
if ( pIcode->ll()->testFlags(I) || (not pIcode->ll()->match(rSP,rBP)) ) if ( pIcode->ll()->testFlags(I) or (not pIcode->ll()->match(rSP,rBP)) )
return false; return false;
if(distance(pIcode,m_end)<3) if(distance(pIcode,m_end)<3)
return false; return false;
@ -55,21 +57,21 @@ bool Idiom2::match(iICODE pIcode)
m_icodes.push_back(pIcode); m_icodes.push_back(pIcode);
/* Get next icode, skip over holes in the icode array */ /* Get next icode, skip over holes in the icode array */
nicode = ++iICODE(pIcode); nicode = ++iICODE(pIcode);
while (nicode->ll()->testFlags(NO_CODE) && (nicode != m_end)) while (nicode->ll()->testFlags(NO_CODE) and (nicode != m_end))
{ {
nicode++; nicode++;
} }
if(nicode == m_end) if(nicode == m_end)
return false; return false;
if (nicode->ll()->match(iPOP,rBP) && ! (nicode->ll()->testFlags(I | TARGET | CASE)) ) if (nicode->ll()->match(iPOP,rBP) and ! (nicode->ll()->testFlags(I | TARGET | CASE)) )
{ {
m_icodes.push_back(nicode++); // Matched POP BP m_icodes.push_back(nicode++); // Matched POP BP
/* Match RET(F) */ /* Match RET(F) */
if ( nicode != m_end && if ( nicode != m_end and
!(nicode->ll()->testFlags(I | TARGET | CASE)) && !(nicode->ll()->testFlags(I | TARGET | CASE)) and
(nicode->ll()->match(iRET) || nicode->ll()->match(iRETF)) (nicode->ll()->match(iRET) or nicode->ll()->match(iRETF))
) )
{ {
m_icodes.push_back(nicode); // Matched RET m_icodes.push_back(nicode); // Matched RET
@ -118,7 +120,7 @@ bool Idiom4::match(iICODE pIcode)
{ {
iICODE prev1 = --iICODE(pIcode); iICODE prev1 = --iICODE(pIcode);
/* Check for POP BP */ /* Check for POP BP */
if (prev1->ll()->match(iPOP,rBP) && not prev1->ll()->testFlags(I) ) if (prev1->ll()->match(iPOP,rBP) and not prev1->ll()->testFlags(I) )
m_icodes.push_back(prev1); m_icodes.push_back(prev1);
else if(prev1!=m_func->Icode.begin()) else if(prev1!=m_func->Icode.begin())
{ {

View File

@ -1,5 +1,8 @@
#include "idiom1.h" #include "idiom1.h"
#include "dcc.h" #include "dcc.h"
#include "msvc_fixes.h"
/***************************************************************************** /*****************************************************************************
* checkStkVars - Checks for PUSH SI * checkStkVars - Checks for PUSH SI
@ -19,14 +22,14 @@ int Idiom1::checkStkVars (iICODE pIcode)
{ {
si_matched = 1; si_matched = 1;
++pIcode; ++pIcode;
if ((pIcode != m_end) && pIcode->ll()->match(iPUSH,rDI)) // Look for PUSH DI if ((pIcode != m_end) and pIcode->ll()->match(iPUSH,rDI)) // Look for PUSH DI
di_matched = 1; di_matched = 1;
} }
else if (pIcode->ll()->match(iPUSH,rDI)) else if (pIcode->ll()->match(iPUSH,rDI))
{ {
di_matched = 1; di_matched = 1;
++pIcode; ++pIcode;
if ((pIcode != m_end) && pIcode->ll()->match(iPUSH,rSI)) // Look for PUSH SI if ((pIcode != m_end) and pIcode->ll()->match(iPUSH,rSI)) // Look for PUSH SI
si_matched = 1; si_matched = 1;
} }
m_func->flg |= (si_matched ? SI_REGVAR : 0) | (di_matched ? DI_REGVAR : 0); m_func->flg |= (si_matched ? SI_REGVAR : 0) | (di_matched ? DI_REGVAR : 0);
@ -60,13 +63,13 @@ bool Idiom1::match(iICODE picode)
m_icodes.clear(); m_icodes.clear();
m_min_off = 0; m_min_off = 0;
/* PUSH BP as first instruction of procedure */ /* PUSH BP as first instruction of procedure */
if ( (not picode->ll()->testFlags(I)) && picode->ll()->src().regi == rBP) if ( (not picode->ll()->testFlags(I)) and picode->ll()->src().regi == rBP)
{ {
m_icodes.push_back( picode++ ); // insert iPUSH m_icodes.push_back( picode++ ); // insert iPUSH
if(picode==m_end) if(picode==m_end)
return false; return false;
/* MOV BP, SP as next instruction */ /* MOV BP, SP as next instruction */
if ( !picode->ll()->testFlags(I | TARGET | CASE) && picode->ll()->match(iMOV ,rBP,rSP) ) if ( not picode->ll()->testFlags(I | TARGET | CASE) and picode->ll()->match(iMOV ,rBP,rSP) )
{ {
m_icodes.push_back( picode++ ); // insert iMOV m_icodes.push_back( picode++ ); // insert iMOV
if(picode==m_end) if(picode==m_end)
@ -75,7 +78,7 @@ bool Idiom1::match(iICODE picode)
/* Look for SUB SP, immed */ /* Look for SUB SP, immed */
if ( if (
picode->ll()->testFlags(I | TARGET | CASE) && picode->ll()->match(iSUB,rSP) picode->ll()->testFlags(I | TARGET | CASE) and picode->ll()->match(iSUB,rSP)
) )
{ {
m_icodes.push_back( picode++ ); // insert iSUB m_icodes.push_back( picode++ ); // insert iSUB
@ -98,8 +101,8 @@ bool Idiom1::match(iICODE picode)
if(picode == m_end) if(picode == m_end)
return false; return false;
/* Look for MOV BP, SP */ /* Look for MOV BP, SP */
if ( picode != m_end && if ( picode != m_end and
!picode->ll()->testFlags(I | TARGET | CASE) && not picode->ll()->testFlags(I | TARGET | CASE) and
picode->ll()->match(iMOV,rBP,rSP)) picode->ll()->match(iMOV,rBP,rSP))
{ {
m_icodes.push_back(picode); m_icodes.push_back(picode);

View File

@ -1,5 +1,8 @@
#include "dcc.h"
#include "mov_idioms.h" #include "mov_idioms.h"
#include "dcc.h"
#include "msvc_fixes.h"
using namespace std; using namespace std;
/***************************************************************************** /*****************************************************************************
@ -30,17 +33,17 @@ bool Idiom14::match(iICODE pIcode)
LLInst * matched [] {m_icodes[0]->ll(),m_icodes[1]->ll()}; LLInst * matched [] {m_icodes[0]->ll(),m_icodes[1]->ll()};
/* Check for regL */ /* Check for regL */
m_regL = matched[0]->m_dst.regi; m_regL = matched[0]->m_dst.regi;
if (not matched[0]->testFlags(I) && ((m_regL == rAX) || (m_regL ==rBX))) if (not matched[0]->testFlags(I) and ((m_regL == rAX) or (m_regL ==rBX)))
{ {
/* Check for XOR regH, regH */ /* Check for XOR regH, regH */
if (matched[1]->match(iXOR) && not matched[1]->testFlags(I)) if (matched[1]->match(iXOR) and not matched[1]->testFlags(I))
{ {
m_regH = matched[1]->m_dst.regi; m_regH = matched[1]->m_dst.regi;
if (m_regH == matched[1]->src().getReg2()) if (m_regH == matched[1]->src().getReg2())
{ {
if ((m_regL == rAX) && (m_regH == rDX)) if ((m_regL == rAX) and (m_regH == rDX))
return true; return true;
if ((m_regL == rBX) && (m_regH == rCX)) if ((m_regL == rBX) and (m_regH == rCX))
return true; return true;
} }
} }
@ -81,10 +84,10 @@ bool Idiom13::match(iICODE pIcode)
/* Check for regL */ /* Check for regL */
regi = m_icodes[0]->ll()->m_dst.regi; regi = m_icodes[0]->ll()->m_dst.regi;
if (not m_icodes[0]->ll()->testFlags(I) && (regi >= rAL) && (regi <= rBH)) if (not m_icodes[0]->ll()->testFlags(I) and (regi >= rAL) and (regi <= rBH))
{ {
/* Check for MOV regH, 0 */ /* Check for MOV regH, 0 */
if (m_icodes[1]->ll()->match(iMOV,I) && (m_icodes[1]->ll()->src().getImm2() == 0)) if (m_icodes[1]->ll()->match(iMOV,I) and (m_icodes[1]->ll()->src().getImm2() == 0))
{ {
if (m_icodes[1]->ll()->m_dst.regi == (regi + 4)) //WARNING: based on distance between AH-AL,BH-BL etc. if (m_icodes[1]->ll()->m_dst.regi == (regi + 4)) //WARNING: based on distance between AH-AL,BH-BL etc.
{ {

View File

@ -1,5 +1,8 @@
#include "dcc.h"
#include "neg_idioms.h" #include "neg_idioms.h"
#include "dcc.h"
#include "msvc_fixes.h"
using namespace std; using namespace std;
@ -23,7 +26,7 @@ bool Idiom11::match (iICODE picode)
for(int i=0; i<3; ++i) for(int i=0; i<3; ++i)
m_icodes[i]=picode++; m_icodes[i]=picode++;
type = m_icodes[0]->ll()->idType(DST); type = m_icodes[0]->ll()->idType(DST);
if(type==CONSTANT || type == OTHER) if(type==CONSTANT or type == OTHER)
return false; return false;
/* Check NEG reg/mem /* Check NEG reg/mem
* SBB reg/mem, 0*/ * SBB reg/mem, 0*/
@ -32,7 +35,7 @@ bool Idiom11::match (iICODE picode)
switch (type) switch (type)
{ {
case GLOB_VAR: case GLOB_VAR:
if ((m_icodes[2]->ll()->m_dst.segValue == m_icodes[0]->ll()->m_dst.segValue) && if ((m_icodes[2]->ll()->m_dst.segValue == m_icodes[0]->ll()->m_dst.segValue) and
(m_icodes[2]->ll()->m_dst.off == m_icodes[0]->ll()->m_dst.off)) (m_icodes[2]->ll()->m_dst.off == m_icodes[0]->ll()->m_dst.off))
return true; return true;
break; break;
@ -83,11 +86,11 @@ bool Idiom16::match (iICODE picode)
m_icodes[i]=picode++; m_icodes[i]=picode++;
uint8_t regi = m_icodes[0]->ll()->m_dst.regi; uint8_t regi = m_icodes[0]->ll()->m_dst.regi;
if ((regi >= rAX) && (regi < INDEX_BX_SI)) if ((regi >= rAX) and (regi < INDEX_BX_SI))
{ {
if (m_icodes[1]->ll()->match(iSBB) && m_icodes[2]->ll()->match(iINC)) if (m_icodes[1]->ll()->match(iSBB) and m_icodes[2]->ll()->match(iINC))
if ((m_icodes[1]->ll()->m_dst.regi == (m_icodes[1]->ll()->src().getReg2())) && if ((m_icodes[1]->ll()->m_dst.regi == (m_icodes[1]->ll()->src().getReg2())) and
m_icodes[1]->ll()->match((eReg)regi) && m_icodes[1]->ll()->match((eReg)regi) and
m_icodes[2]->ll()->match((eReg)regi)) m_icodes[2]->ll()->match((eReg)regi))
return true; return true;
} }

View File

@ -1,5 +1,8 @@
#include "dcc.h"
#include "shift_idioms.h" #include "shift_idioms.h"
#include "dcc.h"
#include "msvc_fixes.h"
using namespace std; using namespace std;
@ -18,8 +21,8 @@ bool Idiom8::match(iICODE pIcode)
return false; return false;
m_icodes[0]=pIcode++; m_icodes[0]=pIcode++;
m_icodes[1]=pIcode++; m_icodes[1]=pIcode++;
if (m_icodes[0]->ll()->testFlags(I) && (m_icodes[0]->ll()->src().getImm2() == 1)) if (m_icodes[0]->ll()->testFlags(I) and (m_icodes[0]->ll()->src().getImm2() == 1))
if ( m_icodes[1]->ll()->match(iRCR,I) && if ( m_icodes[1]->ll()->match(iRCR,I) and
(m_icodes[1]->ll()->src().getImm2() == 1)) (m_icodes[1]->ll()->src().getImm2() == 1))
return true; return true;
return false; return false;
@ -107,8 +110,8 @@ bool Idiom12::match(iICODE pIcode)
return false; return false;
m_icodes[0]=pIcode++; m_icodes[0]=pIcode++;
m_icodes[1]=pIcode++; m_icodes[1]=pIcode++;
if (m_icodes[0]->ll()->testFlags(I) && (m_icodes[0]->ll()->src().getImm2() == 1)) if (m_icodes[0]->ll()->testFlags(I) and (m_icodes[0]->ll()->src().getImm2() == 1))
if (m_icodes[1]->ll()->match(iRCL,I) && (m_icodes[1]->ll()->src().getImm2() == 1)) if (m_icodes[1]->ll()->match(iRCL,I) and (m_icodes[1]->ll()->src().getImm2() == 1))
return true; return true;
return false; return false;
} }
@ -147,8 +150,8 @@ bool Idiom9::match(iICODE pIcode)
return false; return false;
m_icodes[0]=pIcode++; m_icodes[0]=pIcode++;
m_icodes[1]=pIcode++; m_icodes[1]=pIcode++;
if (m_icodes[0]->ll()->testFlags(I) && (m_icodes[0]->ll()->src().getImm2() == 1)) if (m_icodes[0]->ll()->testFlags(I) and (m_icodes[0]->ll()->src().getImm2() == 1))
if (m_icodes[1]->ll()->match(iRCR,I) && (m_icodes[1]->ll()->src().getImm2() == 1)) if (m_icodes[1]->ll()->match(iRCR,I) and (m_icodes[1]->ll()->src().getImm2() == 1))
return true; return true;
return false; return false;
} }

View File

@ -1,5 +1,8 @@
#include "dcc.h"
#include "xor_idioms.h" #include "xor_idioms.h"
#include "dcc.h"
#include "msvc_fixes.h"
using namespace std; using namespace std;
/***************************************************************************** /*****************************************************************************
@ -28,11 +31,11 @@ bool Idiom21::match (iICODE picode)
dst = &m_icodes[0]->ll()->m_dst; dst = &m_icodes[0]->ll()->m_dst;
src = &m_icodes[0]->ll()->src(); src = &m_icodes[0]->ll()->src();
if ((dst->regi == src->getReg2()) && (dst->getReg2() > 0) && (dst->getReg2() < INDEX_BX_SI)) if ((dst->regi == src->getReg2()) and (dst->getReg2() > 0) and (dst->getReg2() < INDEX_BX_SI))
{ {
if ((dst->getReg2() == rDX) && m_icodes[1]->ll()->match(rAX)) if ((dst->getReg2() == rDX) and m_icodes[1]->ll()->match(rAX))
return true; return true;
if ((dst->getReg2() == rCX) && m_icodes[1]->ll()->match(rBX)) if ((dst->getReg2() == rCX) and m_icodes[1]->ll()->match(rBX))
return true; return true;
} }
return false; return false;
@ -67,7 +70,7 @@ bool Idiom7::match(iICODE picode)
src = &picode->ll()->src(); src = &picode->ll()->src();
if (dst->regi == 0) /* global variable */ if (dst->regi == 0) /* global variable */
{ {
if ((dst->segValue == src->segValue) && (dst->off == src->off)) if ((dst->segValue == src->segValue) and (dst->off == src->off))
return true; return true;
} }
else if (dst->regi < INDEX_BX_SI) /* register */ else if (dst->regi < INDEX_BX_SI) /* register */
@ -75,9 +78,9 @@ bool Idiom7::match(iICODE picode)
if (dst->regi == src->regi) if (dst->regi == src->regi)
return true; return true;
} }
else if ((dst->off) && (dst->seg == rSS) && (dst->regi == INDEX_BP)) /* offset from BP */ else if ((dst->off) and (dst->seg == rSS) and (dst->regi == INDEX_BP)) /* offset from BP */
{ {
if ((dst->off == src->off) && (dst->seg == src->seg) && (dst->regi == src->regi)) if ((dst->off == src->off) and (dst->seg == src->seg) and (dst->regi == src->regi))
return true; return true;
} }
return false; return false;
@ -114,8 +117,8 @@ bool Idiom10::match(iICODE pIcode)
m_icodes[0]=pIcode++; m_icodes[0]=pIcode++;
m_icodes[1]=pIcode++; m_icodes[1]=pIcode++;
/* Check OR reg, reg */ /* Check OR reg, reg */
if (not m_icodes[0]->ll()->testFlags(I) && if (not m_icodes[0]->ll()->testFlags(I) and
m_icodes[0]->ll()->src().isReg() && m_icodes[0]->ll()->src().isReg() and
(m_icodes[0]->ll()->src().getReg2() == m_icodes[0]->ll()->m_dst.getReg2())) (m_icodes[0]->ll()->src().getReg2() == m_icodes[0]->ll()->m_dst.getReg2()))
if (m_icodes[1]->ll()->match(iJNE)) //.conditionalJump() if (m_icodes[1]->ll()->match(iJNE)) //.conditionalJump()
{ {

View File

@ -4,10 +4,13 @@
* Date: October 1993 * Date: October 1993
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
*/ */
#include "locident.h"
#include "dcc.h"
#include "msvc_fixes.h"
#include <cstring> #include <cstring>
#include "locident.h"
#include "dcc.h"
bool LONGID_TYPE::srcDstRegMatch(iICODE a, iICODE b) const bool LONGID_TYPE::srcDstRegMatch(iICODE a, iICODE b) const
{ {
return (a->ll()->src().getReg2()==m_l) and (b->ll()->m_dst.getReg2()==m_h); return (a->ll()->src().getReg2()==m_l) and (b->ll()->m_dst.getReg2()==m_h);
@ -23,7 +26,7 @@ ID::ID(hlType t, frameType f) : type(t),illegal(false),hasMacro(false)
macro[0]=0; macro[0]=0;
memset(&id,0,sizeof(id)); memset(&id,0,sizeof(id));
loc=f; loc=f;
assert(not ((t==TYPE_LONG_SIGN)||(t==TYPE_LONG_UNSIGN))); assert(not ((t==TYPE_LONG_SIGN) or (t==TYPE_LONG_UNSIGN)));
} }
ID::ID(hlType t,const LONGID_TYPE &s) : type(t),illegal(false),hasMacro(false) ID::ID(hlType t,const LONGID_TYPE &s) : type(t),illegal(false),hasMacro(false)
{ {
@ -31,7 +34,7 @@ ID::ID(hlType t,const LONGID_TYPE &s) : type(t),illegal(false),hasMacro(false)
memset(&id,0,sizeof(id)); memset(&id,0,sizeof(id));
loc=REG_FRAME; loc=REG_FRAME;
m_longId = s; m_longId = s;
assert((t==TYPE_LONG_SIGN)||(t==TYPE_LONG_UNSIGN)); assert((t==TYPE_LONG_SIGN) or (t==TYPE_LONG_UNSIGN));
} }
ID::ID(hlType t,const LONG_STKID_TYPE &s) : type(t),illegal(false),hasMacro(false) ID::ID(hlType t,const LONG_STKID_TYPE &s) : type(t),illegal(false),hasMacro(false)
{ {
@ -39,7 +42,7 @@ ID::ID(hlType t,const LONG_STKID_TYPE &s) : type(t),illegal(false),hasMacro(fals
memset(&id,0,sizeof(id)); memset(&id,0,sizeof(id));
loc=STK_FRAME; loc=STK_FRAME;
id.longStkId = s; id.longStkId = s;
assert((t==TYPE_LONG_SIGN)||(t==TYPE_LONG_UNSIGN)); assert((t==TYPE_LONG_SIGN) or (t==TYPE_LONG_UNSIGN));
} }
ID::ID(hlType t, const LONGGLB_TYPE &s) : type(t),illegal(false) ID::ID(hlType t, const LONGGLB_TYPE &s) : type(t),illegal(false)
@ -48,7 +51,7 @@ ID::ID(hlType t, const LONGGLB_TYPE &s) : type(t),illegal(false)
memset(&id,0,sizeof(id)); memset(&id,0,sizeof(id));
loc=GLB_FRAME; loc=GLB_FRAME;
id.longGlb = s; id.longGlb = s;
assert((t==TYPE_LONG_SIGN)||(t==TYPE_LONG_UNSIGN)); assert((t==TYPE_LONG_SIGN) or (t==TYPE_LONG_UNSIGN));
} }
@ -75,7 +78,7 @@ int LOCAL_ID::newByteWordReg(hlType t, eReg regi)
/* Check for entry in the table */ /* Check for entry in the table */
auto found=std::find_if(id_arr.begin(),id_arr.end(),[t,regi](ID &el)->bool { auto found=std::find_if(id_arr.begin(),id_arr.end(),[t,regi](ID &el)->bool {
return ((el.type == t) && (el.id.regi == regi)); return ((el.type == t) and (el.id.regi == regi));
}); });
if(found!=id_arr.end()) if(found!=id_arr.end())
return found-id_arr.begin(); return found-id_arr.begin();
@ -96,9 +99,9 @@ int LOCAL_ID::newByteWordReg(hlType t, eReg regi)
void LOCAL_ID::flagByteWordId (int off) void LOCAL_ID::flagByteWordId (int off)
{ {
auto found=std::find_if(id_arr.begin(),id_arr.end(),[off](ID &en)->bool { auto found=std::find_if(id_arr.begin(),id_arr.end(),[off](ID &en)->bool {
//if (((en.type == TYPE_WORD_SIGN) || (en.type == TYPE_BYTE_SIGN)) && //if (((en.type == TYPE_WORD_SIGN) or (en.type == TYPE_BYTE_SIGN)) and
if ((en.typeBitsize()<=16) && if ((en.typeBitsize()<=16) and
(en.id.bwId.off == off) && (en.id.bwId.regOff == 0)) (en.id.bwId.off == off) and (en.id.bwId.regOff == 0))
return true; return true;
return false; return false;
}); });
@ -118,7 +121,7 @@ int LOCAL_ID::newByteWordStk(hlType t, int off, uint8_t regOff)
/* Check for entry in the table */ /* Check for entry in the table */
auto found=std::find_if(id_arr.begin(),id_arr.end(),[off,regOff](ID &el)->bool { auto found=std::find_if(id_arr.begin(),id_arr.end(),[off,regOff](ID &el)->bool {
if ((el.id.bwId.off == off) && (el.id.bwId.regOff == regOff)) if ((el.id.bwId.off == off) and (el.id.bwId.regOff == regOff))
return true; return true;
return false; return false;
}); });
@ -148,9 +151,9 @@ int LOCAL_ID::newIntIdx(int16_t seg, int16_t off, eReg regi, hlType t)
/* Check for entry in the table */ /* Check for entry in the table */
for (size_t idx = 0; idx < id_arr.size(); idx++) for (size_t idx = 0; idx < id_arr.size(); idx++)
{ {
if (/*(locSym->id[idx].type == t) && Not checking type */ if (/*(locSym->id[idx].type == t) and Not checking type */
(id_arr[idx].id.bwGlb.seg == seg) && (id_arr[idx].id.bwGlb.seg == seg) and
(id_arr[idx].id.bwGlb.off == off) && (id_arr[idx].id.bwGlb.off == off) and
(id_arr[idx].id.bwGlb.regi == regi)) (id_arr[idx].id.bwGlb.regi == regi))
return (idx); return (idx);
} }
@ -178,10 +181,10 @@ int LOCAL_ID::newLongReg(hlType t, const LONGID_TYPE &longT, iICODE ix_)
for (idx = 0; idx < id_arr.size(); idx++) for (idx = 0; idx < id_arr.size(); idx++)
{ {
ID &entry(id_arr[idx]); ID &entry(id_arr[idx]);
if(!entry.isLong() || (entry.loc != REG_FRAME)) if(!entry.isLong() or (entry.loc != REG_FRAME))
continue; continue;
if (/*(locSym->id[idx].type == t) && Not checking type */ if (/*(locSym->id[idx].type == t) and Not checking type */
(entry.longId().h() == regH) && (entry.longId().h() == regH) and
(entry.longId().l() == regL)) (entry.longId().l() == regL))
{ {
/* Check for occurrence in the list */ /* Check for occurrence in the list */
@ -218,9 +221,9 @@ int LOCAL_ID::newLongGlb(int16_t seg, int16_t offH, int16_t offL,hlType t)
/* Check for entry in the table */ /* Check for entry in the table */
for (idx = 0; idx < id_arr.size(); idx++) for (idx = 0; idx < id_arr.size(); idx++)
{ {
if (/*(locSym->id[idx].type == t) && Not checking type */ if (/*(locSym->id[idx].type == t) and Not checking type */
(id_arr[idx].id.longGlb.seg == seg) && (id_arr[idx].id.longGlb.seg == seg) and
(id_arr[idx].id.longGlb.offH == offH) && (id_arr[idx].id.longGlb.offH == offH) and
(id_arr[idx].id.longGlb.offL == offL)) (id_arr[idx].id.longGlb.offL == offL))
return (idx); return (idx);
} }
@ -242,10 +245,10 @@ int LOCAL_ID::newLongIdx( int16_t seg, int16_t offH, int16_t offL,uint8_t regi,
/* Check for entry in the table */ /* Check for entry in the table */
for (idx = 0; idx < id_arr.size(); idx++) for (idx = 0; idx < id_arr.size(); idx++)
{ {
if (/*(locSym->id[idx].type == t) && Not checking type */ if (/*(locSym->id[idx].type == t) and Not checking type */
(id_arr[idx].id.longGlb.seg == seg) && (id_arr[idx].id.longGlb.seg == seg) and
(id_arr[idx].id.longGlb.offH == offH) && (id_arr[idx].id.longGlb.offH == offH) and
(id_arr[idx].id.longGlb.offL == offL) && (id_arr[idx].id.longGlb.offL == offL) and
(id_arr[idx].id.longGlb.regi == regi)) (id_arr[idx].id.longGlb.regi == regi))
return (idx); return (idx);
} }
@ -272,8 +275,8 @@ int LOCAL_ID::newLongStk(hlType t, int offH, int offL)
{ {
if(id_arr[idx].loc!=STK_FRAME) if(id_arr[idx].loc!=STK_FRAME)
continue; continue;
if ((id_arr[idx].type == t) && if ((id_arr[idx].type == t) and
(id_arr[idx].longStkId().offH == offH) && (id_arr[idx].longStkId().offH == offH) and
(id_arr[idx].longStkId().offL == offL)) (id_arr[idx].longStkId().offL == offL))
return (idx); return (idx);
} }
@ -320,9 +323,9 @@ int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, L
} }
else if (pmL->off) { /* offset */ else if (pmL->off) { /* offset */
if ((pmL->seg == rSS) && (pmL->regi == INDEX_BP)) /* idx on bp */ if ((pmL->seg == rSS) and (pmL->regi == INDEX_BP)) /* idx on bp */
idx = newLongStk(TYPE_LONG_SIGN, pmH->off, pmL->off); idx = newLongStk(TYPE_LONG_SIGN, pmH->off, pmL->off);
else if ((pmL->seg == rDS) && (pmL->regi == INDEX_BX)) /* bx */ else if ((pmL->seg == rDS) and (pmL->regi == INDEX_BX)) /* bx */
{ /* glb var indexed on bx */ { /* glb var indexed on bx */
printf("Bx indexed global, BX is an unused parameter to newLongIdx\n"); printf("Bx indexed global, BX is an unused parameter to newLongIdx\n");
idx = newLongIdx(pmH->segValue, pmH->off, pmL->off,rBX,TYPE_LONG_SIGN); idx = newLongIdx(pmH->segValue, pmH->off, pmL->off,rBX,TYPE_LONG_SIGN);
@ -332,8 +335,8 @@ int LOCAL_ID::newLong(opLoc sd, iICODE pIcode, hlFirst f, iICODE ix,operDu du, L
printf ("long not supported, idx <> bp\n"); printf ("long not supported, idx <> bp\n");
} }
else /* (pm->regi >= INDEXBASE && pm->off = 0) => indexed && no off */ else /* (pm->regi >= INDEXBASE and pm->off = 0) => indexed and no off */
printf ("long not supported, idx && no off\n"); printf ("long not supported, idx and no off\n");
return (idx); return (idx);
} }
@ -357,7 +360,7 @@ bool checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i, Function * pProc
pmLdst = &atOffset.m_dst; pmLdst = &atOffset.m_dst;
pmHsrc = &pIcode->ll()->src(); pmHsrc = &pIcode->ll()->src();
pmLsrc = &atOffset.src(); pmLsrc = &atOffset.src();
// if ((longId.offH == pmHsrc->off) && (longId.offL == pmLsrc->off)) // if ((longId.offH == pmHsrc->off) and (longId.offL == pmLsrc->off))
// { // {
// asgn.lhs = AstIdent::LongIdx (i); // asgn.lhs = AstIdent::LongIdx (i);
@ -367,14 +370,14 @@ bool checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i, Function * pProc
// } // }
// return true; // return true;
// } // }
// else if ((longId.offH == pmHdst->off) && (longId.offL == pmLdst->off)) // else if ((longId.offH == pmHdst->off) and (longId.offL == pmLdst->off))
// { // {
// asgn.lhs = AstIdent::Long (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode,eDEF, atOffset); // asgn.lhs = AstIdent::Long (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode,eDEF, atOffset);
// asgn.rhs = AstIdent::LongIdx (i); // asgn.rhs = AstIdent::LongIdx (i);
// return true; // return true;
// } // }
if ((longId.offH == pmHdst->off) && (longId.offL == pmLdst->off)) if ((longId.offH == pmHdst->off) and (longId.offL == pmLdst->off))
{ {
asgn.lhs = AstIdent::LongIdx (i); asgn.lhs = AstIdent::LongIdx (i);
@ -384,7 +387,7 @@ bool checkLongEq (LONG_STKID_TYPE longId, iICODE pIcode, int i, Function * pProc
} }
return true; return true;
} }
else if ((longId.offH == pmHsrc->off) && (longId.offL == pmLsrc->off)) else if ((longId.offH == pmHsrc->off) and (longId.offL == pmLsrc->off))
{ {
asgn.lhs = AstIdent::Long (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode,eDEF, atOffset); asgn.lhs = AstIdent::Long (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode,eDEF, atOffset);
asgn.rhs = AstIdent::LongIdx (i); asgn.rhs = AstIdent::LongIdx (i);
@ -414,7 +417,7 @@ bool checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
pmHsrc = &pIcode->ll()->src(); pmHsrc = &pIcode->ll()->src();
pmLsrc = &atOffset.src(); pmLsrc = &atOffset.src();
if ((longId.h() == pmHdst->regi) && (longId.l() == pmLdst->regi)) if ((longId.h() == pmHdst->regi) and (longId.l() == pmLdst->regi))
{ {
asgn.lhs = AstIdent::LongIdx (i); asgn.lhs = AstIdent::LongIdx (i);
if ( not pIcode->ll()->testFlags(NO_SRC) ) if ( not pIcode->ll()->testFlags(NO_SRC) )
@ -423,7 +426,7 @@ bool checkLongRegEq (LONGID_TYPE longId, iICODE pIcode, int i,
} }
return true; return true;
} }
else if ((longId.h() == pmHsrc->regi) && (longId.l() == pmLsrc->regi)) else if ((longId.h() == pmHsrc->regi) and (longId.l() == pmLsrc->regi))
{ {
asgn.lhs = AstIdent::Long (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode, eDEF, atOffset); asgn.lhs = AstIdent::Long (&pProc->localId, DST, pIcode, HIGH_FIRST, pIcode, eDEF, atOffset);
asgn.rhs = AstIdent::LongIdx (i); asgn.rhs = AstIdent::LongIdx (i);
@ -442,7 +445,7 @@ eReg otherLongRegi (eReg regi, int idx, LOCAL_ID *locTbl)
ID *id; ID *id;
id = &locTbl->id_arr[idx]; id = &locTbl->id_arr[idx];
if ((id->loc == REG_FRAME) && ((id->type == TYPE_LONG_SIGN) || 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) if (id->longId().h() == regi)

View File

@ -1,6 +1,10 @@
#include <cassert>
#include "machine_x86.h" #include "machine_x86.h"
#include "msvc_fixes.h"
#include "icode.h" #include "icode.h"
#include <cassert>
// Index registers **** temp solution // Index registers **** temp solution
static const std::string regNames[] = { static const std::string regNames[] = {
"undef", "undef",
@ -89,11 +93,11 @@ const std::string &Machine_X86::floatOpName(unsigned r)
bool Machine_X86::physicalReg(eReg r) bool Machine_X86::physicalReg(eReg r)
{ {
return (r>=rAX) && (r<rTMP); return (r>=rAX) and (r<rTMP);
} }
bool Machine_X86::isMemOff(eReg r) bool Machine_X86::isMemOff(eReg r)
{ {
return r == 0 || r >= INDEX_BX_SI; return r == 0 or r >= INDEX_BX_SI;
} }
//TODO: Move these to Machine_X86 //TODO: Move these to Machine_X86
eReg Machine_X86::subRegH(eReg reg) eReg Machine_X86::subRegH(eReg reg)
@ -106,18 +110,18 @@ eReg Machine_X86::subRegL(eReg reg)
} }
bool Machine_X86::isSubRegisterOf(eReg reg,eReg parent) bool Machine_X86::isSubRegisterOf(eReg reg,eReg parent)
{ {
if ((parent < rAX) || (parent > rBX)) if ((parent < rAX) or (parent > rBX))
return false; // only AX -> BX are coverede by subregisters return false; // only AX -> BX are coverede by subregisters
return ((reg==subRegH(parent)) || (reg == subRegL(parent))); return ((reg==subRegH(parent)) or (reg == subRegL(parent)));
} }
bool Machine_X86::hasSubregisters(eReg reg) bool Machine_X86::hasSubregisters(eReg reg)
{ {
return ((reg >= rAX) && (reg <= rBX)); return ((reg >= rAX) and (reg <= rBX));
} }
bool Machine_X86::isPartOfComposite(eReg reg) bool Machine_X86::isPartOfComposite(eReg reg)
{ {
return ((reg >= rAL) && (reg <= rBH)); return ((reg >= rAL) and (reg <= rBH));
} }
eReg Machine_X86::compositeParent(eReg reg) eReg Machine_X86::compositeParent(eReg reg)

File diff suppressed because it is too large Load Diff

View File

@ -5,12 +5,14 @@
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
*/ */
#include <cstring>
#include <cassert>
#include "dcc.h" #include "dcc.h"
#include "msvc_fixes.h"
#include "project.h" #include "project.h"
#include "CallGraph.h" #include "CallGraph.h"
#include <cstring>
#include <cassert>
extern Project g_proj; extern Project g_proj;
/* Static indentation buffer */ /* Static indentation buffer */
static constexpr int indSize=81; /* size of indentation buffer; max 20 */ static constexpr int indSize=81; /* size of indentation buffer; max 20 */
@ -111,7 +113,7 @@ void LOCAL_ID::newRegArg(iICODE picode, iICODE ticode) const
if(type==REGISTER) if(type==REGISTER)
assert(lhs_reg); assert(lhs_reg);
if(type==LONG_VAR) if(type==LONG_VAR)
assert(!lhs_reg); assert(nullptr==lhs_reg);
if (lhs_reg) if (lhs_reg)
{ {
regL = id_arr[lhs_reg->regiIdx].id.regi; regL = id_arr[lhs_reg->regiIdx].id.regi;
@ -227,7 +229,7 @@ bool CallType::newStkArg(Expr *exp, llIcode opcode, Function * pproc)
if (expr) if (expr)
{ {
regi = pproc->localId.id_arr[expr->regiIdx].id.regi; regi = pproc->localId.id_arr[expr->regiIdx].id.regi;
if ((regi >= rES) && (regi <= rDS)) if ((regi >= rES) and (regi <= rDS))
{ {
return (opcode == iCALLF) ? false : true; return (opcode == iCALLF) ? false : true;
} }
@ -365,8 +367,8 @@ void STKFRAME::adjustForArgType(size_t numArg_, hlType actType_)
case TYPE_LONG_UNSIGN: case TYPE_LONG_UNSIGN:
case TYPE_LONG_SIGN: case TYPE_LONG_SIGN:
if ((forType == TYPE_WORD_UNSIGN) || if ((forType == TYPE_WORD_UNSIGN) or
(forType == TYPE_WORD_SIGN) || (forType == TYPE_WORD_SIGN) or
(forType == TYPE_UNKNOWN)) (forType == TYPE_UNKNOWN))
{ {
/* Merge low and high */ /* Merge low and high */

View File

@ -4,18 +4,20 @@
* registers) along the graph. Structure the graph in this way. * registers) along the graph. Structure the graph in this way.
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
**************************************************************************/ **************************************************************************/
#include "dcc.h"
#include "msvc_fixes.h"
#include <string.h> #include <string.h>
#include <memory.h> #include <memory.h>
#include <cassert> #include <cassert>
#include <algorithm> #include <algorithm>
#include "dcc.h"
/* Returns whether the given icode opcode is within the range of valid /* Returns whether the given icode opcode is within the range of valid
* high-level conditional jump icodes (iJB..iJG) */ * high-level conditional jump icodes (iJB..iJG) */
static bool isJCond (llIcode opcode) static bool isJCond (llIcode opcode)
{ {
if ((opcode >= iJB) && (opcode <= iJG)) if ((opcode >= iJB) and (opcode <= iJG))
return true; return true;
return false; return false;
} }
@ -32,10 +34,10 @@ static bool isLong23 (BB * pbb, iICODE &off, int *arc)
e = pbb->edges[ELSE].BBptr; e = pbb->edges[ELSE].BBptr;
/* Check along the THEN path */ /* Check along the THEN path */
if ((t->size() == 1) && (t->nodeType == TWO_BRANCH) && (t->inEdges.size() == 1)) if ((t->size() == 1) and (t->nodeType == TWO_BRANCH) and (t->inEdges.size() == 1))
{ {
obb2 = t->edges[THEN].BBptr; obb2 = t->edges[THEN].BBptr;
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->getOpcode() == iCMP)) if ((obb2->size() == 2) and (obb2->nodeType == TWO_BRANCH) and (obb2->front().ll()->getOpcode() == iCMP))
{ {
off = obb2->begin();//std::distance(iter,obb2->begin2()); off = obb2->begin();//std::distance(iter,obb2->begin2());
*arc = THEN; *arc = THEN;
@ -44,10 +46,10 @@ static bool isLong23 (BB * pbb, iICODE &off, int *arc)
} }
/* Check along the ELSE path */ /* Check along the ELSE path */
else if ((e->size() == 1) && (e->nodeType == TWO_BRANCH) && (e->inEdges.size() == 1)) else if ((e->size() == 1) and (e->nodeType == TWO_BRANCH) and (e->inEdges.size() == 1))
{ {
obb2 = e->edges[THEN].BBptr; obb2 = e->edges[THEN].BBptr;
if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->getOpcode() == iCMP)) if ((obb2->size() == 2) and (obb2->nodeType == TWO_BRANCH) and (obb2->front().ll()->getOpcode() == iCMP))
{ {
off = obb2->begin();//std::distance(iter,obb2->begin2());//obb2->front().loc_ip - i; off = obb2->begin();//std::distance(iter,obb2->begin2());//obb2->front().loc_ip - i;
*arc = ELSE; *arc = ELSE;
@ -66,8 +68,8 @@ static bool isLong22 (iICODE pIcode, iICODE pEnd, iICODE &off)
return false; return false;
// preincrement because pIcode is not checked here // preincrement because pIcode is not checked here
iICODE icodes[] = { ++pIcode,++pIcode,++pIcode }; iICODE icodes[] = { ++pIcode,++pIcode,++pIcode };
if ( icodes[1]->ll()->match(iCMP) && if ( icodes[1]->ll()->match(iCMP) and
(isJCond ((llIcode)icodes[0]->ll()->getOpcode())) && (isJCond ((llIcode)icodes[0]->ll()->getOpcode())) and
(isJCond ((llIcode)icodes[2]->ll()->getOpcode()))) (isJCond ((llIcode)icodes[2]->ll()->getOpcode())))
{ {
off = initial_icode; off = initial_icode;
@ -101,7 +103,7 @@ static int longJCond23 (Assignment &asgn, iICODE pIcode, int arc, iICODE atOffse
/* Modify in edges of target basic block */ /* Modify in edges of target basic block */
auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(), auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(),
[obb1,obb2](BB *b) -> bool { [obb1,obb2](BB *b) -> bool {
return (b==obb1) || (b==obb2); }); return (b==obb1) or (b==obb2); });
tbb->inEdges.erase(newlast,tbb->inEdges.end()); tbb->inEdges.erase(newlast,tbb->inEdges.end());
tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */ tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */
@ -129,7 +131,7 @@ static int longJCond23 (Assignment &asgn, iICODE pIcode, int arc, iICODE atOffse
/* Modify in edges of the ELSE basic block */ /* Modify in edges of the ELSE basic block */
tbb = obb2->edges[ELSE].BBptr; tbb = obb2->edges[ELSE].BBptr;
auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(), auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(),
[obb1,obb2](BB *b) -> bool { return (b==obb1) || (b==obb2); }); [obb1,obb2](BB *b) -> bool { return (b==obb1) or (b==obb2); });
tbb->inEdges.erase(newlast,tbb->inEdges.end()); tbb->inEdges.erase(newlast,tbb->inEdges.end());
tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */ tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */
@ -246,7 +248,7 @@ void Function::propLongStk (int i, const ID &pLocId)
next1 = ++iICODE(pIcode); next1 = ++iICODE(pIcode);
if(next1==pEnd) if(next1==pEnd)
break; break;
if ((pIcode->type == HIGH_LEVEL) || ( not pIcode->valid() )) if ((pIcode->type == HIGH_LEVEL) or ( not pIcode->valid() ))
continue; continue;
if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode()) if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode())
{ {
@ -288,7 +290,7 @@ void Function::propLongStk (int i, const ID &pLocId)
} }
//TODO: Simplify this! //TODO: Simplify this!
/* Check long conditional (i.e. 2 CMPs and 3 branches */ /* Check long conditional (i.e. 2 CMPs and 3 branches */
else if ((pIcode->ll()->getOpcode() == iCMP) && (isLong23 (pIcode->getParent(), l23, &arc))) else if ((pIcode->ll()->getOpcode() == iCMP) and (isLong23 (pIcode->getParent(), l23, &arc)))
{ {
if ( checkLongEq (pLocId.longStkId(), pIcode, i, this, asgn, *l23->ll()) ) if ( checkLongEq (pLocId.longStkId(), pIcode, i, this, asgn, *l23->ll()) )
{ {
@ -298,7 +300,7 @@ void Function::propLongStk (int i, const ID &pLocId)
/* Check for long conditional equality or inequality. This requires /* Check for long conditional equality or inequality. This requires
* 2 CMPs and 2 branches */ * 2 CMPs and 2 branches */
else if ((pIcode->ll()->getOpcode() == iCMP) && isLong22 (pIcode, pEnd, l23)) else if ((pIcode->ll()->getOpcode() == iCMP) and isLong22 (pIcode, pEnd, l23))
{ {
if ( checkLongEq (pLocId.longStkId(), pIcode, i, this,asgn, *l23->ll()) ) if ( checkLongEq (pLocId.longStkId(), pIcode, i, this,asgn, *l23->ll()) )
{ {
@ -321,7 +323,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
ICODE &icode(*pIcode); ICODE &icode(*pIcode);
if ((icode.type == HIGH_LEVEL) || ( not icode.valid() )) if ((icode.type == HIGH_LEVEL) or ( not icode.valid() ))
continue; continue;
if (icode.ll()->getOpcode() != next1->ll()->getOpcode()) if (icode.ll()->getOpcode() != next1->ll()->getOpcode())
continue; continue;
@ -331,7 +333,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
case iMOV: case iMOV:
pmH = &icode.ll()->m_dst; pmH = &icode.ll()->m_dst;
pmL = &next1->ll()->m_dst; pmL = &next1->ll()->m_dst;
if ((pLocId.longId().h() == pmH->regi) && (pLocId.longId().l() == pmL->regi)) if ((pLocId.longId().h() == pmH->regi) and (pLocId.longId().l() == pmL->regi))
{ {
localId.id_arr[loc_ident_idx].idx.push_back(pIcode);//idx-1//insert localId.id_arr[loc_ident_idx].idx.push_back(pIcode);//idx-1//insert
icode.setRegDU( pmL->regi, eDEF); icode.setRegDU( pmL->regi, eDEF);
@ -346,7 +348,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
case iPOP: case iPOP:
pmH = &next1->ll()->m_dst; pmH = &next1->ll()->m_dst;
pmL = &icode.ll()->m_dst; pmL = &icode.ll()->m_dst;
if ((pLocId.longId().h() == pmH->regi) && (pLocId.longId().l() == pmL->regi)) if ((pLocId.longId().h() == pmH->regi) and (pLocId.longId().l() == pmL->regi))
{ {
asgn.lhs = AstIdent::LongIdx (loc_ident_idx); asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
icode.setRegDU( pmH->regi, eDEF); icode.setRegDU( pmH->regi, eDEF);
@ -362,7 +364,7 @@ int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE be
case iAND: case iOR: case iXOR: case iAND: case iOR: case iXOR:
pmL = &icode.ll()->m_dst; pmL = &icode.ll()->m_dst;
pmH = &next1->ll()->m_dst; pmH = &next1->ll()->m_dst;
if ((pLocId.longId().h() == pmH->regi) && (pLocId.longId().l() == pmL->regi)) if ((pLocId.longId().h() == pmH->regi) and (pLocId.longId().l() == pmL->regi))
{ {
asgn.lhs = AstIdent::LongIdx (loc_ident_idx); asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
asgn.rhs = AstIdent::Long (&this->localId, SRC, pIcode, LOW_FIRST, pIcode, eUSE, *next1->ll()); asgn.rhs = AstIdent::Long (&this->localId, SRC, pIcode, LOW_FIRST, pIcode, eUSE, *next1->ll());
@ -399,7 +401,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
LLOperand * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */ LLOperand * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */
int arc; int arc;
if ((pIcode->type == HIGH_LEVEL) || ( not pIcode->valid() )) if ((pIcode->type == HIGH_LEVEL) or ( not pIcode->valid() ))
continue; continue;
if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode()) if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode())
@ -412,7 +414,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
const LLOperand &src_op2(next1->ll()->src()); const LLOperand &src_op2(next1->ll()->src());
eReg srcReg1=src_op1.getReg2(); eReg srcReg1=src_op1.getReg2();
eReg nextReg2=src_op2.getReg2(); eReg nextReg2=src_op2.getReg2();
if ((ref_long.h() == srcReg1) && (ref_long.l() == nextReg2)) if ((ref_long.h() == srcReg1) and (ref_long.l() == nextReg2))
{ {
pIcode->setRegDU( nextReg2, eUSE); pIcode->setRegDU( nextReg2, eUSE);
@ -431,7 +433,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
const LONGID_TYPE &ref_long(pLocId.longId()); const LONGID_TYPE &ref_long(pLocId.longId());
const LLOperand &src_op1(pIcode->ll()->src()); const LLOperand &src_op1(pIcode->ll()->src());
const LLOperand &src_op2(next1->ll()->src()); const LLOperand &src_op2(next1->ll()->src());
if ((ref_long.h() == src_op1.getReg2()) && (ref_long.l() == src_op2.getReg2())) if ((ref_long.h() == src_op1.getReg2()) and (ref_long.l() == src_op2.getReg2()))
{ {
asgn.rhs = AstIdent::LongIdx (loc_ident_idx); asgn.rhs = AstIdent::LongIdx (loc_ident_idx);
pIcode->setRegDU( next1->ll()->src().getReg2(), eUSE); pIcode->setRegDU( next1->ll()->src().getReg2(), eUSE);
@ -447,7 +449,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
case iAND: case iOR: case iXOR: case iAND: case iOR: case iXOR:
pmL = &pIcode->ll()->m_dst; pmL = &pIcode->ll()->m_dst;
pmH = &next1->ll()->m_dst; pmH = &next1->ll()->m_dst;
if ((pLocId.longId().h() == pmH->regi) && (pLocId.longId().l() == pmL->regi)) if ((pLocId.longId().h() == pmH->regi) and (pLocId.longId().l() == pmL->regi))
{ {
asgn.lhs = AstIdent::LongIdx (loc_ident_idx); asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
pIcode->setRegDU( pmH->regi, USE_DEF); pIcode->setRegDU( pmH->regi, USE_DEF);
@ -474,7 +476,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
} /* eos */ } /* eos */
/* Check long conditional (i.e. 2 CMPs and 3 branches */ /* Check long conditional (i.e. 2 CMPs and 3 branches */
else if ((pIcode->ll()->getOpcode() == iCMP) && (isLong23 (pIcode->getParent(), long_loc, &arc))) else if ((pIcode->ll()->getOpcode() == iCMP) and (isLong23 (pIcode->getParent(), long_loc, &arc)))
{ {
if (checkLongRegEq (pLocId.longId(), pIcode, loc_ident_idx, this, asgn, *long_loc->ll())) if (checkLongRegEq (pLocId.longId(), pIcode, loc_ident_idx, this, asgn, *long_loc->ll()))
{ {
@ -485,7 +487,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
/* Check for long conditional equality or inequality. This requires /* Check for long conditional equality or inequality. This requires
* 2 CMPs and 2 branches */ * 2 CMPs and 2 branches */
else if (pIcode->ll()->match(iCMP) && (isLong22 (pIcode, pEnd, long_loc))) else if (pIcode->ll()->match(iCMP) and (isLong22 (pIcode, pEnd, long_loc)))
{ {
if (checkLongRegEq (pLocId.longId(), pIcode, loc_ident_idx, this, asgn, *long_loc->ll()) ) if (checkLongRegEq (pLocId.longId(), pIcode, loc_ident_idx, this, asgn, *long_loc->ll()) )
{ {
@ -498,7 +500,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
* JX lab * JX lab
* => HLI_JCOND (regH:regL X 0) lab * => HLI_JCOND (regH:regL X 0) lab
* This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */ * This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */
else if (pIcode->ll()->match(iOR) && (next1 != pEnd) && (isJCond ((llIcode)next1->ll()->getOpcode()))) else if (pIcode->ll()->match(iOR) and (next1 != pEnd) and (isJCond ((llIcode)next1->ll()->getOpcode())))
{ {
if (pLocId.longId().srcDstRegMatch(pIcode,pIcode)) if (pLocId.longId().srcDstRegMatch(pIcode,pIcode))
{ {

View File

@ -3,12 +3,14 @@
* constructs an equivalent reducible graph if one is not found. * constructs an equivalent reducible graph if one is not found.
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
********************************************************************/ ********************************************************************/
#include "dcc.h"
#include "msvc_fixes.h"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <stdint.h> #include <stdint.h>
#include "dcc.h"
static int numInt; /* Number of intervals */ static int numInt; /* Number of intervals */
@ -79,7 +81,7 @@ void interval::appendNodeInt(queue &pqH, BB *node)
/* Check header list for occurrence of node, if found, remove it /* Check header list for occurrence of node, if found, remove it
* and decrement number of out-edges from this interval. */ * and decrement number of out-edges from this interval. */
if (node->beenOnH && !pqH.empty()) if (node->beenOnH and !pqH.empty())
{ {
auto found_iter=std::find(pqH.begin(),pqH.end(),node); auto found_iter=std::find(pqH.begin(),pqH.end(),node);
if(found_iter!=pqH.end()) if(found_iter!=pqH.end())
@ -147,7 +149,7 @@ void derSeq_Entry::findIntervals (Function *c)
else /* node has been visited before */ else /* node has been visited before */
if (succ->inEdgeCount == 0) if (succ->inEdgeCount == 0)
{ {
if (succ->reachingInt == header || succ->inInterval == pI) /* same interval */ if (succ->reachingInt == header or succ->inInterval == pI) /* same interval */
{ {
if (succ != header) if (succ != header)
pI->appendNodeInt (H, succ); pI->appendNodeInt (H, succ);
@ -155,7 +157,7 @@ void derSeq_Entry::findIntervals (Function *c)
else /* out edge */ else /* out edge */
pI->numOutEdges++; pI->numOutEdges++;
} }
else if (succ != header && succ->beenOnH) else if (succ != header and succ->beenOnH)
pI->numOutEdges++; pI->numOutEdges++;
} }
} }
@ -230,7 +232,7 @@ void freeDerivedSeq(derSeq &derivedG)
derSeq_Entry::~derSeq_Entry() derSeq_Entry::~derSeq_Entry()
{ {
freeInterval (&Ii); freeInterval (&Ii);
// if(Gi && Gi->nodeType == INTERVAL_NODE) // if(Gi and Gi->nodeType == INTERVAL_NODE)
// freeCFG (Gi); // freeCFG (Gi);
} }
@ -259,7 +261,7 @@ bool Function::nextOrderGraph (derSeq &derivedGi)
const queue &listIi(Ii->nodes); const queue &listIi(Ii->nodes);
/* Check for more than 1 interval */ /* Check for more than 1 interval */
if (sameGraph && (listIi.size()>1)) if (sameGraph and (listIi.size()>1))
sameGraph = false; sameGraph = false;
/* Find out edges */ /* Find out edges */

View File

@ -4,13 +4,16 @@
* I-code * I-code
* (C) Cristina Cifuentes, Jeff Ledermann * (C) Cristina Cifuentes, Jeff Ledermann
****************************************************************************/ ****************************************************************************/
#include "scanner.h"
#include "msvc_fixes.h"
#include "dcc.h"
#include "project.h"
#include <cstring> #include <cstring>
#include <map> #include <map>
#include <string> #include <string>
#include "dcc.h"
#include "scanner.h"
#include "project.h"
/* Parser flags */ /* Parser flags */
#define TO_REG 0x000100 /* rm is source */ #define TO_REG 0x000100 /* rm is source */
#define S_EXT 0x000200 /* sign extend */ #define S_EXT 0x000200 /* sign extend */
@ -380,7 +383,7 @@ static void fixFloatEmulation(x86_insn_t &insn)
return; return;
PROG &prog(Project::get()->prog); PROG &prog(Project::get()->prog);
uint16_t wOp=insn.x86_get_imm()->data.word; uint16_t wOp=insn.x86_get_imm()->data.word;
if ((wOp < 0x34) || (wOp > 0x3B)) if ((wOp < 0x34) or (wOp > 0x3B))
return; return;
uint8_t buf[16]; uint8_t buf[16];
/* This is a Borland/Microsoft floating point emulation instruction. Treat as if it is an ESC opcode */ /* This is a Borland/Microsoft floating point emulation instruction. Treat as if it is an ESC opcode */
@ -403,7 +406,7 @@ int disassembleOneLibDisasm(uint32_t ip,x86_insn_t &l)
PROG &prog(Project::get()->prog); PROG &prog(Project::get()->prog);
X86_Disasm ds(opt_16_bit); X86_Disasm ds(opt_16_bit);
int cnt=ds.x86_disasm(prog.image(),prog.cbImage,0,ip,&l); int cnt=ds.x86_disasm(prog.image(),prog.cbImage,0,ip,&l);
if(cnt && l.is_valid()) if(cnt and l.is_valid())
{ {
fixFloatEmulation(l); //can change 'l' fixFloatEmulation(l); //can change 'l'
} }
@ -413,7 +416,7 @@ int disassembleOneLibDisasm(uint32_t ip,x86_insn_t &l)
} }
eReg convertRegister(const x86_reg_t &reg) eReg convertRegister(const x86_reg_t &reg)
{ {
if( (reg_pc==reg.type) || (0==reg.id)) if( (reg_pc==reg.type) or (0==reg.id))
return rUNDEF; return rUNDEF;
eReg regmap[]={ rUNDEF, eReg regmap[]={ rUNDEF,
@ -518,7 +521,7 @@ LLOperand convertOperand(const x86_op_t &from)
default: default:
fprintf(stderr,"convertOperand does not know how to convert %d\n",from.type); fprintf(stderr,"convertOperand does not know how to convert %d\n",from.type);
} }
if(res.isSet() && (res.seg == rUNDEF)) if(res.isSet() and (res.seg == rUNDEF))
{ {
res.seg = rDS; res.seg = rDS;
} }
@ -627,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) 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 */ /* 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 /* Set segment. A later procedure (lookupAddr in proclist.c) will
* provide the value of this segment in the field segValue. * provide the value of this segment in the field segValue.
@ -638,7 +641,7 @@ static void setAddress(int i, bool fdst, uint16_t seg, int16_t reg, uint16_t off
} }
else else
{ /* no override, check indexed register */ { /* no override, check indexed register */
if ((reg >= INDEX_BX_SI) && (reg == INDEX_BP_SI || reg == INDEX_BP_DI || reg == INDEX_BP)) if ((reg >= INDEX_BX_SI) and (reg == INDEX_BP_SI or reg == INDEX_BP_DI or reg == INDEX_BP))
{ {
pm->seg = rSS; /* indexed on bp */ pm->seg = rSS; /* indexed on bp */
} }
@ -650,7 +653,7 @@ static void setAddress(int i, bool fdst, uint16_t seg, int16_t reg, uint16_t off
pm->regi = (eReg)reg; pm->regi = (eReg)reg;
pm->off = (int16_t)off; pm->off = (int16_t)off;
if (reg && reg < INDEX_BX_SI && (stateTable[i].flg & B)) if (reg and (reg < INDEX_BX_SI) and (stateTable[i].flg & B))
{ {
pm->regi = Machine_X86::subRegL(pm->regi); pm->regi = Machine_X86::subRegL(pm->regi);
} }
@ -694,7 +697,7 @@ static void rm(int i)
break; break;
} }
//pIcode->insn.get_dest()-> //pIcode->insn.get_dest()->
if ((stateTable[i].flg & NSP) && (pIcode->ll()->src().getReg2()==rSP || if ((stateTable[i].flg & NSP) and (pIcode->ll()->src().getReg2()==rSP or
pIcode->ll()->m_dst.getReg2()==rSP)) pIcode->ll()->m_dst.getReg2()==rSP))
pIcode->ll()->setFlags(NOT_HLL); pIcode->ll()->setFlags(NOT_HLL);
} }
@ -717,7 +720,7 @@ static void segrm(int i)
{ {
int reg = REG(*pInst) + rES; int reg = REG(*pInst) + rES;
if (reg > rDS || (reg == rCS && (stateTable[i].flg & TO_REG))) if (reg > rDS or (reg == rCS and (stateTable[i].flg & TO_REG)))
pIcode->ll()->setOpcode((llIcode)0); // setCBW because it has that index pIcode->ll()->setOpcode((llIcode)0); // setCBW because it has that index
else { else {
setAddress(i, false, 0, (int16_t)reg, 0); setAddress(i, false, 0, (int16_t)reg, 0);
@ -793,7 +796,7 @@ static void memOnly(int )
****************************************************************************/ ****************************************************************************/
static void memReg0(int i) static void memReg0(int i)
{ {
if (REG(*pInst) || (*pInst & 0xC0) == 0xC0) if (REG(*pInst) or (*pInst & 0xC0) == 0xC0)
pIcode->ll()->setOpcode((llIcode)0); pIcode->ll()->setOpcode((llIcode)0);
else else
rm(i); rm(i);
@ -810,7 +813,7 @@ static void immed(int i)
pIcode->ll()->setOpcode(immedTable[REG(*pInst)]) ; pIcode->ll()->setOpcode(immedTable[REG(*pInst)]) ;
rm(i); rm(i);
if (pIcode->ll()->getOpcode() == iADD || pIcode->ll()->getOpcode() == iSUB) if (pIcode->ll()->getOpcode() == iADD or pIcode->ll()->getOpcode() == iSUB)
pIcode->ll()->clrFlags(NOT_HLL); /* Allow ADD/SUB SP, immed */ pIcode->ll()->clrFlags(NOT_HLL); /* Allow ADD/SUB SP, immed */
} }
@ -845,13 +848,13 @@ static void trans(int i)
// if(transTable[REG(*pInst)]==iPUSH) { // if(transTable[REG(*pInst)]==iPUSH) {
// printf("es"); // printf("es");
// } // }
if ((uint8_t)REG(*pInst) < 2 || !(stateTable[i].flg & B)) { /* INC & DEC */ if ((uint8_t)REG(*pInst) < 2 or not (stateTable[i].flg & B)) { /* INC & DEC */
ll->setOpcode(transTable[REG(*pInst)]); /* valid on bytes */ ll->setOpcode(transTable[REG(*pInst)]); /* valid on bytes */
rm(i); rm(i);
ll->replaceSrc( pIcode->ll()->m_dst ); ll->replaceSrc( pIcode->ll()->m_dst );
if (ll->match(iJMP) || ll->match(iCALL) || ll->match(iCALLF)) if (ll->match(iJMP) or ll->match(iCALL) or ll->match(iCALLF))
ll->setFlags(NO_OPS); ll->setFlags(NO_OPS);
else if (ll->match(iINC) || ll->match(iPUSH) || ll->match(iDEC)) else if (ll->match(iINC) or ll->match(iPUSH) or ll->match(iDEC))
ll->setFlags(NO_SRC); ll->setFlags(NO_SRC);
} }
} }
@ -878,15 +881,15 @@ static void arith(int i)
else else
data2(i); data2(i);
} }
else if (!(opcode == iNOT || opcode == iNEG)) else if (not (opcode == iNOT or opcode == iNEG))
{ {
pIcode->ll()->replaceSrc( pIcode->ll()->m_dst ); pIcode->ll()->replaceSrc( pIcode->ll()->m_dst );
setAddress(i, true, 0, rAX, 0); /* dst = AX */ setAddress(i, true, 0, rAX, 0); /* dst = AX */
} }
else if (opcode == iNEG || opcode == iNOT) else if (opcode == iNEG or opcode == iNOT)
pIcode->ll()->setFlags(NO_SRC); pIcode->ll()->setFlags(NO_SRC);
if ((opcode == iDIV) || (opcode == iIDIV)) if ((opcode == iDIV) or (opcode == iIDIV))
{ {
if ( not pIcode->ll()->testFlags(B) ) if ( not pIcode->ll()->testFlags(B) )
pIcode->ll()->setFlags(IM_TMP_DST); pIcode->ll()->setFlags(IM_TMP_DST);
@ -981,7 +984,7 @@ static void dispF(int i)
****************************************************************************/ ****************************************************************************/
static void prefix(int ) static void prefix(int )
{ {
if (pIcode->ll()->getOpcode() == iREPE || pIcode->ll()->getOpcode() == iREPNE) if (pIcode->ll()->getOpcode() == iREPE or pIcode->ll()->getOpcode() == iREPNE)
RepPrefix = pIcode->ll()->getOpcode(); RepPrefix = pIcode->ll()->getOpcode();
else else
SegPrefix = pIcode->ll()->getOpcode(); SegPrefix = pIcode->ll()->getOpcode();
@ -1001,7 +1004,7 @@ static void strop(int )
{ {
if (RepPrefix) if (RepPrefix)
{ {
if ( pIcode->ll()->match(iCMPS) || pIcode->ll()->match(iSCAS) ) if ( pIcode->ll()->match(iCMPS) or pIcode->ll()->match(iSCAS) )
{ {
if(pIcode->insn.prefix & insn_rep_zero) if(pIcode->insn.prefix & insn_rep_zero)
{ {
@ -1075,7 +1078,7 @@ static void none2(int )
static void checkInt(int ) static void checkInt(int )
{ {
uint16_t wOp = (uint16_t) pIcode->ll()->src().getImm2(); uint16_t wOp = (uint16_t) pIcode->ll()->src().getImm2();
if ((wOp >= 0x34) && (wOp <= 0x3B)) if ((wOp >= 0x34) and (wOp <= 0x3B))
{ {
/* This is a Borland/Microsoft floating point emulation instruction. /* This is a Borland/Microsoft floating point emulation instruction.
Treat as if it is an ESC opcode */ Treat as if it is an ESC opcode */

View File

@ -1,4 +1,7 @@
#include "LIB_PatternCollector.h" #include "LIB_PatternCollector.h"
#include "msvc_fixes.h"
#include <cstring> #include <cstring>
#include <cstring> #include <cstring>
/** \note there is an untested assumption that the *first* segment definition /** \note there is an untested assumption that the *first* segment definition
@ -88,7 +91,7 @@ int LIB_PatternCollector::readSyms(FILE *fl)
++segnum; ++segnum;
b = readByte(fl); /* Class name index */ b = readByte(fl); /* Class name index */
if ((b == codeLNAMES) && (codeSEGDEF == NONE)) if ((b == codeLNAMES) and (codeSEGDEF == NONE))
{ {
/* This is the segment defining the code class */ /* This is the segment defining the code class */
codeSEGDEF = segnum; codeSEGDEF = segnum;

View File

@ -1,4 +1,7 @@
#include "TPL_PatternCollector.h" #include "TPL_PatternCollector.h"
#include "msvc_fixes.h"
#include <cstring> #include <cstring>
/** \note Fundamental problem: there seems to be no information linking the names /** \note Fundamental problem: there seems to be no information linking the names
@ -255,7 +258,7 @@ void TPL_PatternCollector::enterUnitProcs(FILE *f)
readString(f); readString(f);
strcpy(name, (char *)buf); strcpy(name, (char *)buf);
cat = readByte(f); cat = readByte(f);
if ((cat == charProc) || (cat == charFunc)) if ((cat == charProc) or (cat == charFunc))
{ {
grab(f,skipPmap); /* Skip to the pmap */ grab(f,skipPmap); /* Skip to the pmap */
pmapOff = readShort(f); /* pmap offset */ pmapOff = readShort(f); /* pmap offset */
@ -278,7 +281,7 @@ void TPL_PatternCollector::enterUnitProcs(FILE *f)
int TPL_PatternCollector::readSyms(FILE *f) int TPL_PatternCollector::readSyms(FILE *f)
{ {
grab(f,4); grab(f,4);
if ((strncmp((char *)buf, "TPU0", 4) != 0) && ((strncmp((char *)buf, "TPU5", 4) != 0))) if ((strncmp((char *)buf, "TPU0", 4) != 0) and ((strncmp((char *)buf, "TPU5", 4) != 0)))
{ {
printf("Not a Turbo Pascal version 4 or 5 library file\n"); printf("Not a Turbo Pascal version 4 or 5 library file\n");
fclose(f); fclose(f);

View File

@ -25,8 +25,11 @@
* * * *
\* * * * * * * * * * * * */ \* * * * * * * * * * * * */
#include "msvc_fixes.h"
#include <memory.h> #include <memory.h>
#include <stdint.h> #include <stdint.h>
#ifndef PATLEN #ifndef PATLEN
#define PATLEN 23 #define PATLEN 23
#define WILD 0xF4 #define WILD 0xF4
@ -417,7 +420,7 @@ void fixWildCards(uint8_t pat[])
case 0xCD: /* Int nn */ case 0xCD: /* Int nn */
intArg = pat[pc++]; intArg = pat[pc++];
if ((intArg >= 0x34) && (intArg <= 0x3B)) if ((intArg >= 0x34) and (intArg <= 0x3B))
{ {
/* Borland/Microsoft FP emulations */ /* Borland/Microsoft FP emulations */
if (ModRM(pat)) return; if (ModRM(pat)) return;

View File

@ -3,6 +3,7 @@
#include "LIB_PatternCollector.h" #include "LIB_PatternCollector.h"
#include "TPL_PatternCollector.h" #include "TPL_PatternCollector.h"
#include "perfhlib.h" /* Symbol table prototypes */ #include "perfhlib.h" /* Symbol table prototypes */
#include "msvc_fixes.h"
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QtCore/QStringList> #include <QtCore/QStringList>
@ -48,7 +49,7 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
QString arg2 = app.arguments()[1]; QString arg2 = app.arguments()[1];
if (arg2.startsWith("-h") || arg2.startsWith("-?")) if (arg2.startsWith("-h") or arg2.startsWith("-?"))
{ {
printUsage(true); printUsage(true);
return 0; return 0;