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,12 +1,13 @@
#include "dcc.h"
#include "DccFrontend.h" #include "DccFrontend.h"
#include "dcc.h"
#include "msvc_fixes.h"
#include "project.h" #include "project.h"
#include "disassem.h" #include "disassem.h"
#include "CallGraph.h" #include "CallGraph.h"
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <cstdio> #include <cstdio>
@ -64,7 +65,7 @@ void PROG::displayLoadInfo(void)
int i; int i;
printf("File type is %s\n", (fCOM)?"COM":"EXE"); printf("File type is %s\n", (fCOM)?"COM":"EXE");
if (! fCOM) { if (not fCOM) {
printf("Signature = %02X%02X\n", header.sigLo, header.sigHi); printf("Signature = %02X%02X\n", header.sigLo, header.sigHi);
printf("File size %% 512 = %04X\n", LH(&header.lastPageSize)); printf("File size %% 512 = %04X\n", LH(&header.lastPageSize));
printf("File size / 512 = %04X pages\n", LH(&header.numPages)); printf("File size / 512 = %04X pages\n", LH(&header.numPages));
@ -77,7 +78,7 @@ void PROG::displayLoadInfo(void)
printf("Initial SS:SP = %04X:%04X\n", initSS, initSP); printf("Initial SS:SP = %04X:%04X\n", initSS, initSP);
printf("Initial CS:IP = %04X:%04X\n", initCS, initIP); printf("Initial CS:IP = %04X:%04X\n", initCS, initIP);
if (option.VeryVerbose && cReloc) if (option.VeryVerbose and cReloc)
{ {
printf("\nRelocation Table\n"); printf("\nRelocation Table\n");
for (i = 0; i < cReloc; i++) for (i = 0; i < cReloc; i++)
@ -123,20 +124,20 @@ static void displayMemMap(void)
fill(ip, b1); fill(ip, b1);
printf("%06X %s\n", ip, b1); printf("%06X %s\n", ip, b1);
ip += 16; ip += 16;
for (i = 3, c = b1[1]; i < 32 && c == b1[i]; i += 2) for (i = 3, c = b1[1]; i < 32 and c == b1[i]; i += 2)
; /* Check if all same */ ; /* Check if all same */
if (i > 32) if (i > 32)
{ {
fill(ip, b2); /* Skip until next two are not same */ fill(ip, b2); /* Skip until next two are not same */
fill(ip+16, b3); fill(ip+16, b3);
if (! (strcmp(b1, b2) || strcmp(b1, b3))) if (not (strcmp(b1, b2) || strcmp(b1, b3)))
{ {
printf(" :\n"); printf(" :\n");
do do
{ {
ip += 16; ip += 16;
fill(ip+16, b1); fill(ip+16, b1);
} while (! strcmp(b1, b2)); } while (0==strcmp(b1, b2));
} }
} }
} }
@ -206,7 +207,7 @@ struct ComLoader : public DosLoader {
fp.seek(0); fp.seek(0);
char sig[2]; char sig[2];
if(2==fp.read(sig,2)) { if(2==fp.read(sig,2)) {
return not (sig[0] == 0x4D && sig[1] == 0x5A); return not (sig[0] == 0x4D and sig[1] == 0x5A);
} }
return false; return false;
} }
@ -244,7 +245,7 @@ struct ExeLoader : public DosLoader {
MZHeader tmp_header; MZHeader tmp_header;
fp.seek(0); fp.seek(0);
fp.read((char *)&tmp_header, sizeof(header)); fp.read((char *)&tmp_header, sizeof(header));
if(not (tmp_header.sigLo == 0x4D && tmp_header.sigHi == 0x5A)) if(not (tmp_header.sigLo == 0x4D and tmp_header.sigHi == 0x5A))
return false; return false;
/* This is a typical DOS kludge! */ /* This is a typical DOS kludge! */

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

@ -3,14 +3,16 @@
* (C) Cristina Cifuentes * (C) Cristina Cifuentes
****************************************************************************/ ****************************************************************************/
#include <string.h> #include "graph.h"
#include "msvc_fixes.h"
#include "dcc.h"
#include "project.h"
#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 <string.h>
#include "dcc.h"
#include "graph.h"
#include "project.h"
using namespace std; using namespace std;
using namespace boost; using namespace boost;
@ -105,7 +107,7 @@ void Function::createCFG()
{ {
Function * p = ll->src().proc.proc; Function * p = ll->src().proc.proc;
pBB = BB::Create(current_range, CALL_NODE, this); pBB = BB::Create(current_range, CALL_NODE, this);
if (p && not ((p->flg) & TERMINATES) ) if (p and not ((p->flg) & TERMINATES) )
pBB->addOutEdge(nextIcode->loc_ip); pBB->addOutEdge(nextIcode->loc_ip);
break; break;
} }
@ -210,7 +212,7 @@ void Function::compressCFG()
* (Un)Conditional -> Unconditional jump */ * (Un)Conditional -> Unconditional jump */
for (BB *pBB : m_actual_cfg) //m_cfg for (BB *pBB : m_actual_cfg) //m_cfg
{ {
if(pBB->inEdges.empty() || (pBB->nodeType != ONE_BRANCH && pBB->nodeType != TWO_BRANCH)) if(pBB->inEdges.empty() or (pBB->nodeType != ONE_BRANCH and pBB->nodeType != TWO_BRANCH))
continue; continue;
for (TYPEADR_TYPE &edgeRef : pBB->edges) for (TYPEADR_TYPE &edgeRef : pBB->edges)
{ {
@ -272,7 +274,7 @@ BB *BB::rmJMP(int marker, BB * pBB)
{ {
marker += (int)DFS_JMP; marker += (int)DFS_JMP;
while (pBB->nodeType == ONE_BRANCH && pBB->size() == 1) while (pBB->nodeType == ONE_BRANCH and pBB->size() == 1)
{ {
if (pBB->traversed != marker) if (pBB->traversed != marker)
{ {
@ -299,7 +301,7 @@ BB *BB::rmJMP(int marker, BB * pBB)
do { do {
pBB = pBB->edges[0].BBptr; pBB = pBB->edges[0].BBptr;
pBB->inEdges.pop_back(); // was --numInedges pBB->inEdges.pop_back(); // was --numInedges
if (! pBB->inEdges.empty()) if (not pBB->inEdges.empty())
{ {
pBB->front().ll()->setFlags(NO_CODE); pBB->front().ll()->setFlags(NO_CODE);
pBB->front().invalidate(); pBB->front().invalidate();
@ -321,11 +323,11 @@ BB *BB::rmJMP(int marker, BB * pBB)
void BB::mergeFallThrough( CIcodeRec &Icode) void BB::mergeFallThrough( CIcodeRec &Icode)
{ {
BB * pChild; BB * pChild;
if (!this) if (nullptr==this)
{ {
printf("mergeFallThrough on empty BB!\n"); printf("mergeFallThrough on empty BB!\n");
} }
while (nodeType == FALL_NODE || nodeType == ONE_BRANCH) while (nodeType == FALL_NODE or nodeType == ONE_BRANCH)
{ {
pChild = edges[0].BBptr; pChild = edges[0].BBptr;
/* Jump to next instruction can always be removed */ /* Jump to next instruction can always be removed */

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)

View File

@ -2,6 +2,10 @@
* dcc project procedure list builder * dcc project procedure list builder
* (C) Cristina Cifuentes, Mike van Emmerik, Jeff Ledermann * (C) Cristina Cifuentes, Mike van Emmerik, Jeff Ledermann
****************************************************************************/ ****************************************************************************/
#include "dcc.h"
#include "project.h"
#include "CallGraph.h"
#include "msvc_fixes.h"
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
@ -13,9 +17,6 @@
#include <QMap> #include <QMap>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include "dcc.h"
#include "project.h"
#include "CallGraph.h"
using namespace std; using namespace std;
//static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate); //static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate);
@ -83,7 +84,7 @@ ICODE *Function::translate_XCHG(LLInst *ll,ICODE &_Icode)
{ {
eReg srcreg=eIcode.ll()->src().getReg2(); eReg srcreg=eIcode.ll()->src().getReg2();
eIcode.setRegDU( srcreg, eUSE); eIcode.setRegDU( srcreg, eUSE);
if((srcreg>=rAL) && (srcreg<=rBH)) if((srcreg>=rAL) and (srcreg<=rBH))
eIcode.ll()->setFlags( B ); eIcode.ll()->setFlags( B );
} }
eIcode.ll()->label = ll->label; eIcode.ll()->label = ll->label;
@ -101,7 +102,7 @@ ICODE *Function::translate_XCHG(LLInst *ll,ICODE &_Icode)
eIcode.ll()->replaceDst(ll->src()); eIcode.ll()->replaceDst(ll->src());
if(eIcode.ll()->m_dst.regi) if(eIcode.ll()->m_dst.regi)
{ {
if((eIcode.ll()->m_dst.regi>=rAL) && (eIcode.ll()->m_dst.regi<=rBH)) if((eIcode.ll()->m_dst.regi>=rAL) and (eIcode.ll()->m_dst.regi<=rBH))
eIcode.ll()->setFlags( B ); eIcode.ll()->setFlags( B );
eIcode.setRegDU( eIcode.ll()->m_dst.regi, eDEF); eIcode.setRegDU( eIcode.ll()->m_dst.regi, eDEF);
} }
@ -138,7 +139,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
printf("Parsing proc %s at %X\n", name.c_str(), pstate->IP); printf("Parsing proc %s at %X\n", name.c_str(), pstate->IP);
} }
while (! done ) while (not done )
{ {
err = scan(pstate->IP, _Icode); err = scan(pstate->IP, _Icode);
if(err) if(err)
@ -163,7 +164,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
} }
/* Copy Icode to Proc */ /* Copy Icode to Proc */
if ((ll->getOpcode() == iDIV) || (ll->getOpcode() == iIDIV)) if ((ll->getOpcode() == iDIV) or (ll->getOpcode() == iIDIV))
pIcode = translate_DIV(ll, _Icode); pIcode = translate_DIV(ll, _Icode);
else if (_Icode.ll()->getOpcode() == iXCHG) else if (_Icode.ll()->getOpcode() == iXCHG)
pIcode = translate_XCHG(ll, _Icode); pIcode = translate_XCHG(ll, _Icode);
@ -189,14 +190,14 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
/* This sets up range check for indexed JMPs hopefully /* This sets up range check for indexed JMPs hopefully
* Handles JA/JAE for fall through and JB/JBE on branch * Handles JA/JAE for fall through and JB/JBE on branch
*/ */
if (ip > 0 && prev.ll()->getOpcode() == iCMP && (prev.ll()->testFlags(I))) if (ip > 0 and prev.ll()->getOpcode() == iCMP and (prev.ll()->testFlags(I)))
{ {
pstate->JCond.immed = (int16_t)prev.ll()->src().getImm2(); pstate->JCond.immed = (int16_t)prev.ll()->src().getImm2();
if (ll->match(iJA) || ll->match(iJBE) ) if (ll->match(iJA) or ll->match(iJBE) )
pstate->JCond.immed++; pstate->JCond.immed++;
if (ll->getOpcode() == iJAE || ll->getOpcode() == iJA) if (ll->getOpcode() == iJAE or ll->getOpcode() == iJA)
pstate->JCond.regi = prev.ll()->m_dst.regi; pstate->JCond.regi = prev.ll()->m_dst.regi;
fBranch = (bool) (ll->getOpcode() == iJB || ll->getOpcode() == iJBE); fBranch = (bool) (ll->getOpcode() == iJB or ll->getOpcode() == iJBE);
} }
StCopy = *pstate; StCopy = *pstate;
@ -237,7 +238,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
break; break;
case iINT: case iINT:
if (ll->src().getImm2() == 0x21 && pstate->f[rAH]) if (ll->src().getImm2() == 0x21 and pstate->f[rAH])
{ {
int funcNum = pstate->r[rAH]; int funcNum = pstate->r[rAH];
int operand; int operand;
@ -248,7 +249,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
//Icode.GetIcode(Icode.GetNumIcodes() - 1)-> //Icode.GetIcode(Icode.GetNumIcodes() - 1)->
/* Program termination: int21h, fn 00h, 31h, 4Ch */ /* Program termination: int21h, fn 00h, 31h, 4Ch */
done = (bool)(funcNum == 0x00 || funcNum == 0x31 || done = (bool)(funcNum == 0x00 or funcNum == 0x31 or
funcNum == 0x4C); funcNum == 0x4C);
/* String functions: int21h, fn 09h */ /* String functions: int21h, fn 09h */
@ -263,12 +264,12 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
global_symbol_table.updateSymType (operand, TypeContainer(TYPE_STR, size)); global_symbol_table.updateSymType (operand, TypeContainer(TYPE_STR, size));
} }
} }
else if ((ll->src().getImm2() == 0x2F) && (pstate->f[rAH])) else if ((ll->src().getImm2() == 0x2F) and (pstate->f[rAH]))
{ {
Icode.back().ll()->m_dst.off = pstate->r[rAH]; Icode.back().ll()->m_dst.off = pstate->r[rAH];
} }
else /* Program termination: int20h, int27h */ else /* Program termination: int20h, int27h */
done = (ll->src().getImm2() == 0x20 || ll->src().getImm2() == 0x27); done = (ll->src().getImm2() == 0x20 or ll->src().getImm2() == 0x27);
if (done) if (done)
pIcode->ll()->setFlags(TERMINATES); pIcode->ll()->setFlags(TERMINATES);
break; break;
@ -285,7 +286,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
case iSHL: case iSHL:
if (pstate->JCond.regi == ll->m_dst.regi) if (pstate->JCond.regi == ll->m_dst.regi)
{ {
if ((ll->testFlags(I)) && ll->src().getImm2() == 1) if ((ll->testFlags(I)) and ll->src().getImm2() == 1)
pstate->JCond.immed *= 2; pstate->JCond.immed *= 2;
else else
pstate->JCond.regi = 0; pstate->JCond.regi = 0;
@ -299,7 +300,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
case iLDS: case iLES: case iLDS: case iLES:
if ((psym = lookupAddr(&ll->src(), pstate, 4, eDuVal::USE)) if ((psym = lookupAddr(&ll->src(), pstate, 4, eDuVal::USE))
/* && (Icode.ll()->flg & SEG_IMMED) */ ) /* and (Icode.ll()->flg & SEG_IMMED) */ )
{ {
offset = LH(&prog.image()[psym->label]); offset = LH(&prog.image()[psym->label]);
pstate->setState( (ll->getOpcode() == iLDS)? rDS: rES, pstate->setState( (ll->getOpcode() == iLDS)? rDS: rES,
@ -314,7 +315,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
if (err) { if (err) {
this->flg &= ~TERMINATES; this->flg &= ~TERMINATES;
if (err == INVALID_386OP || err == INVALID_OPCODE) if (err == INVALID_386OP or err == INVALID_OPCODE)
{ {
fatalError(err, prog.image()[_Icode.ll()->label], _Icode.ll()->label); fatalError(err, prog.image()[_Icode.ll()->label], _Icode.ll()->label);
this->flg |= PROC_BADINST; this->flg |= PROC_BADINST;
@ -433,7 +434,7 @@ bool Function::decodeIndirectJMP(ICODE & pIcode, STATE *pstate, CALL_GRAPH * pca
const LLOperand &op = last_jmp->ll()->src(); const LLOperand &op = last_jmp->ll()->src();
if(op.regi != INDEX_BX) if(op.regi != INDEX_BX)
return false; return false;
if(!load_jump_table_addr->ll()->src().isImmediate()) if(not load_jump_table_addr->ll()->src().isImmediate())
return false; return false;
uint32_t cs = (uint32_t)(uint16_t)pstate->r[rCS] << 4; uint32_t cs = (uint32_t)(uint16_t)pstate->r[rCS] << 4;
uint32_t table_addr = cs + load_jump_table_addr->ll()->src().getImm2(); uint32_t table_addr = cs + load_jump_table_addr->ll()->src().getImm2();
@ -477,7 +478,7 @@ bool Function::decodeIndirectJMP2(ICODE & pIcode, STATE *pstate, CALL_GRAPH * pc
if(Icode.size()<12) if(Icode.size()<12)
return false; return false;
if(&Icode.back()!=&pIcode) // not the last insn in the list skip it if(&Icode.back() != &pIcode) // not the last insn in the list skip it
return false; return false;
if(pIcode.ll()->src().regi != INDEX_BX) { if(pIcode.ll()->src().regi != INDEX_BX) {
return false; return false;
@ -519,7 +520,7 @@ bool Function::decodeIndirectJMP2(ICODE & pIcode, STATE *pstate, CALL_GRAPH * pc
const LLOperand &op = last_jmp->ll()->src(); const LLOperand &op = last_jmp->ll()->src();
if(op.regi != INDEX_BX) if(op.regi != INDEX_BX)
return false; return false;
if(!load_jump_table_addr->ll()->src().isImmediate()) if(not load_jump_table_addr->ll()->src().isImmediate())
return false; return false;
uint32_t cs = (uint32_t)(uint16_t)pstate->r[rCS] << 4; uint32_t cs = (uint32_t)(uint16_t)pstate->r[rCS] << 4;
uint32_t table_addr = cs + load_jump_table_addr->ll()->src().getImm2(); uint32_t table_addr = cs + load_jump_table_addr->ll()->src().getImm2();
@ -570,8 +571,8 @@ bool Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGra
/* Ensure we have a uint16_t offset & valid seg */ /* Ensure we have a uint16_t offset & valid seg */
if (pIcode.ll()->match(iJMP) and (pIcode.ll()->testFlags(WORD_OFF)) and if (pIcode.ll()->match(iJMP) and (pIcode.ll()->testFlags(WORD_OFF)) and
pstate->f[seg] and pstate->f[seg] and
(pIcode.ll()->src().regi == INDEX_SI || (pIcode.ll()->src().regi == INDEX_SI or
pIcode.ll()->src().regi == INDEX_DI || /* Idx reg. BX, SI, DI */ pIcode.ll()->src().regi == INDEX_DI or /* Idx reg. BX, SI, DI */
pIcode.ll()->src().regi == INDEX_BX)) pIcode.ll()->src().regi == INDEX_BX))
{ {
@ -601,7 +602,7 @@ bool Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGra
for (i = offTable; i < endTable; i += 2) for (i = offTable; i < endTable; i += 2)
{ {
target = cs + LH(&prog.image()[i]); target = cs + LH(&prog.image()[i]);
if (target < endTable && target >= offTable) if (target < endTable and target >= offTable)
endTable = target; endTable = target;
else if (target >= (uint32_t)prog.cbImage) else if (target >= (uint32_t)prog.cbImage)
endTable = i; endTable = i;
@ -611,7 +612,7 @@ bool Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGra
{ {
target = cs + LH(&prog.image()[i]); target = cs + LH(&prog.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 (! (prog.image()[target] || prog.image()[target+1]) || if (not (prog.image()[target] or prog.image()[target+1]) or
scan(target, _Icode)) scan(target, _Icode))
endTable = i; endTable = i;
} }
@ -685,13 +686,12 @@ bool Function::process_CALL(ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *psta
{ {
/* Not immediate, i.e. indirect call */ /* Not immediate, i.e. indirect call */
if (pIcode.ll()->m_dst.regi && (!option.Calls)) if (pIcode.ll()->m_dst.regi and (not option.Calls))
{ {
/* We have not set the brave option to attempt to follow /* We have not set the brave option to attempt to follow
the execution path through register indirect calls. the execution path through register indirect calls.
So we just exit this function, and ignore the call. So we just exit this function, and ignore the call.
We probably should not have parsed this deep, anyway. We probably should not have parsed this deep, anyway. */
*/
return false; return false;
} }
@ -807,17 +807,17 @@ static void process_MOV(LLInst & ll, STATE * pstate)
SYM * psym, *psym2; /* Pointer to symbol in global symbol table */ SYM * psym, *psym2; /* Pointer to symbol in global symbol table */
uint8_t dstReg = ll.m_dst.regi; uint8_t dstReg = ll.m_dst.regi;
uint8_t srcReg = ll.src().regi; uint8_t srcReg = ll.src().regi;
if (dstReg > 0 && dstReg < INDEX_BX_SI) if (dstReg > 0 and dstReg < INDEX_BX_SI)
{ {
if (ll.testFlags(I)) if (ll.testFlags(I))
pstate->setState( dstReg, (int16_t)ll.src().getImm2()); pstate->setState( dstReg, (int16_t)ll.src().getImm2());
else if (srcReg == 0) /* direct memory offset */ else if (srcReg == 0) /* direct memory offset */
{ {
psym = lookupAddr(&ll.src(), pstate, 2, eDuVal::USE); psym = lookupAddr(&ll.src(), pstate, 2, eDuVal::USE);
if (psym && ((psym->flg & SEG_IMMED) || psym->duVal.val)) if (psym and ((psym->flg & SEG_IMMED) or psym->duVal.val))
pstate->setState( dstReg, LH(&prog.image()[psym->label])); pstate->setState( dstReg, LH(&prog.image()[psym->label]));
} }
else if (srcReg < INDEX_BX_SI && pstate->f[srcReg]) /* reg */ else if (srcReg < INDEX_BX_SI and pstate->f[srcReg]) /* reg */
{ {
pstate->setState( dstReg, pstate->r[srcReg]); pstate->setState( dstReg, pstate->r[srcReg]);
@ -828,10 +828,10 @@ static void process_MOV(LLInst & ll, STATE * pstate)
} }
else if (dstReg == 0) { /* direct memory offset */ else if (dstReg == 0) { /* direct memory offset */
int size=2; int size=2;
if((ll.src().regi>=rAL)&&(ll.src().regi<=rBH)) if((ll.src().regi>=rAL)and(ll.src().regi<=rBH))
size=1; size=1;
psym = lookupAddr (&ll.m_dst, pstate, size, eDEF); psym = lookupAddr (&ll.m_dst, pstate, size, eDEF);
if (psym && ! (psym->duVal.val)) /* no initial value yet */ if (psym and not (psym->duVal.val)) /* no initial value yet */
{ {
if (ll.testFlags(I)) /* immediate */ if (ll.testFlags(I)) /* immediate */
{ {
@ -847,7 +847,7 @@ static void process_MOV(LLInst & ll, STATE * pstate)
else if (srcReg == 0) /* direct mem offset */ else if (srcReg == 0) /* direct mem offset */
{ {
psym2 = lookupAddr (&ll.src(), pstate, 2, eDuVal::USE); psym2 = lookupAddr (&ll.src(), pstate, 2, eDuVal::USE);
if (psym2 && ((psym->flg & SEG_IMMED) || (psym->duVal.val))) if (psym2 and ((psym->flg & SEG_IMMED) or (psym->duVal.val)))
{ {
//prog.image()[psym->label] = (uint8_t)prog.image()[psym2->label]; //prog.image()[psym->label] = (uint8_t)prog.image()[psym2->label];
pstate->setMemoryByte(psym->label,(uint8_t)prog.image()[psym2->label]); pstate->setMemoryByte(psym->label,(uint8_t)prog.image()[psym2->label]);
@ -860,7 +860,7 @@ static void process_MOV(LLInst & ll, STATE * pstate)
psym2->duVal.setFlags(eDuVal::USE); psym2->duVal.setFlags(eDuVal::USE);
} }
} }
else if (srcReg < INDEX_BX_SI && pstate->f[srcReg]) /* reg */ else if (srcReg < INDEX_BX_SI and pstate->f[srcReg]) /* reg */
{ {
//prog.image()[psym->label] = (uint8_t)pstate->r[srcReg]; //prog.image()[psym->label] = (uint8_t)pstate->r[srcReg];
pstate->setMemoryByte(psym->label,(uint8_t)pstate->r[srcReg]); pstate->setMemoryByte(psym->label,(uint8_t)pstate->r[srcReg]);
@ -1042,13 +1042,13 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off, 0); pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off, 0);
} }
else if (pm->regi == INDEX_BP_SI || pm->regi == INDEX_BP_DI) else if (pm->regi == INDEX_BP_SI or pm->regi == INDEX_BP_DI)
pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off, pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off,
(uint8_t)((pm->regi == INDEX_BP_SI) ? rSI : rDI)); (uint8_t)((pm->regi == INDEX_BP_SI) ? rSI : rDI));
else if ((pm->regi >= INDEX_SI) && (pm->regi <= INDEX_BX)) else if ((pm->regi >= INDEX_SI) and (pm->regi <= INDEX_BX))
{ {
if ((pm->seg == rDS) && (pm->regi == INDEX_BX)) /* bx */ if ((pm->seg == rDS) and (pm->regi == INDEX_BX)) /* bx */
{ {
if (pm->off > 0) /* global indexed variable */ if (pm->off > 0) /* global indexed variable */
pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,TYPE_WORD_SIGN); pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,TYPE_WORD_SIGN);
@ -1070,7 +1070,7 @@ static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
} }
/* Use of register */ /* Use of register */
else if ((d == DST) || ((d == SRC) && (not pIcode.ll()->testFlags(I)))) else if ((d == DST) or ((d == SRC) and (not pIcode.ll()->testFlags(I))))
pIcode.du.use.addReg(pm->regi); pIcode.du.use.addReg(pm->regi);
} }
@ -1102,15 +1102,15 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off, 0); pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off, 0);
} }
else if (pm->regi == INDEX_BP_SI || pm->regi == INDEX_BP_DI) else if (pm->regi == INDEX_BP_SI or pm->regi == INDEX_BP_DI)
{ {
pProc->localId.newByteWordStk(TYPE_WORD_SIGN, pm->off, pProc->localId.newByteWordStk(TYPE_WORD_SIGN, pm->off,
(uint8_t)((pm->regi == INDEX_BP_SI) ? rSI : rDI)); (uint8_t)((pm->regi == INDEX_BP_SI) ? rSI : rDI));
} }
else if ((pm->regi >= INDEX_SI) && (pm->regi <= INDEX_BX)) else if ((pm->regi >= INDEX_SI) and (pm->regi <= INDEX_BX))
{ {
if ((pm->seg == rDS) && (pm->regi == INDEX_BX)) /* bx */ if ((pm->seg == rDS) and (pm->regi == INDEX_BX)) /* bx */
{ {
if (pm->off > 0) /* global var */ if (pm->off > 0) /* global var */
pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,TYPE_WORD_SIGN); pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,TYPE_WORD_SIGN);
@ -1119,7 +1119,7 @@ static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int
} }
} }
/* Definition of register */ /* Definition of register */
else if ((d == DST) || ((d == SRC) && (not pIcode.ll()->testFlags(I)))) else if ((d == DST) or ((d == SRC) and (not pIcode.ll()->testFlags(I))))
{ {
assert(not pIcode.ll()->match(iPUSH)); assert(not pIcode.ll()->match(iPUSH));
pIcode.du1.addDef(pm->regi); pIcode.du1.addDef(pm->regi);
@ -1163,7 +1163,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
case iSAR: case iSHL: case iSHR: case iSAR: case iSHL: case iSHR:
case iRCL: case iRCR: case iROL: case iROR: case iRCL: case iRCR: case iROL: case iROR:
case iADD: case iADC: case iSUB: case iSBB: case iADD: case iADC: case iSUB: case iSBB:
if (! Imm) { if (not Imm) {
use(SRC, pIcode, this, pstate, cb); use(SRC, pIcode, this, pstate, cb);
} }
case iINC: case iDEC: case iNEG: case iNOT: case iINC: case iDEC: case iNEG: case iNOT:
@ -1181,7 +1181,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
break; break;
case iTEST: case iCMP: case iTEST: case iCMP:
if (! Imm) if (not Imm)
use(SRC, pIcode, this, pstate, cb); use(SRC, pIcode, this, pstate, cb);
use(DST, pIcode, this, pstate, cb); use(DST, pIcode, this, pstate, cb);
break; break;
@ -1296,7 +1296,7 @@ void Function::process_operands(ICODE & pIcode, STATE * pstate)
case iSCAS: case iSTOS: case iINS: case iSCAS: case iSTOS: case iINS:
pIcode.du.def.addReg(rDI); pIcode.du.def.addReg(rDI);
pIcode.du1.addDef(rDI); pIcode.du1.addDef(rDI);
if (pIcode.ll()->getOpcode() == iREP_INS || pIcode.ll()->getOpcode()== iINS) if (pIcode.ll()->getOpcode() == iREP_INS or pIcode.ll()->getOpcode()== iINS)
{ {
pIcode.du.use.addReg(rDI).addReg(rES).addReg(rDX); pIcode.du.use.addReg(rDI).addReg(rES).addReg(rDX);
} }

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;