Browse Source

Added setters/creation methods to LLOperand
Moved PROG global into Project instance. Still need to refactor all
usages of prog.
Split fseek offset calculation in frontend.cpp to allow for easier
debugging.
Added alreadyDecoded method to CIcodeRec
LONGID_TYPE now has a method matching srcDstRegMatch icode's src a dst
regs

Artur K 12 years ago
parent
commit
26b9ab1e00
16 changed files with 89 additions and 16 deletions
  1. 1 1
      include/dcc.h
  2. 32 4
      include/icode.h
  3. 1 0
      src/ast.cpp
  4. 2 0
      src/backend.cpp
  5. 4 0
      src/chklib.cpp
  6. 1 1
      src/dcc.cpp
  7. 2 1
      src/disassem.cpp
  8. 8 3
      src/frontend.cpp
  9. 1 0
      src/graph.cpp
  10. 7 0
      src/icode.cpp
  11. 5 0
      src/locident.cpp
  12. 10 3
      src/parser.cpp
  13. 1 0
      src/procs.cpp
  14. 7 1
      src/project.cpp
  15. 1 1
      src/proplong.cpp
  16. 6 1
      src/scanner.cpp

+ 1 - 1
include/dcc.h

@@ -63,7 +63,7 @@ extern OPTION option;       /* Command line options             */
 
 #include "BinaryImage.h"
 
-extern PROG prog;   		/* Loaded program image parameters  */
+//extern PROG prog;   		/* Loaded program image parameters  */
 extern std::bitset<32> duReg[30];   /* def/use bits for registers		*/
 
 //extern uint32_t duReg[30];		/* def/use bits for registers		*/

+ 32 - 4
include/icode.h

@@ -186,10 +186,30 @@ struct LLOperand
         proc.cb=0;
     }
     uint32_t op() const {return opz;}
-    void SetImmediateOp(uint32_t dw) {opz=dw;}
+    int64_t getImm2() const {return opz;}
+    void SetImmediateOp(uint32_t dw)
+    {
+        opz=dw;
+    }
+    eReg getReg2() {return regi;}
     bool isReg() const;
-
-
+    static LLOperand CreateImm2(int64_t Val)
+    {
+        LLOperand Op;
+        //Op.Kind = kImmediate;
+        //Op.ImmVal = Val;
+        Op.opz = Val;
+        return Op;
+    }
+    static LLOperand CreateReg2(unsigned Val)
+    {
+        LLOperand Op;
+//        Op.Kind = kRegister;
+//        Op.RegVal = Reg;
+        Op.regi = (eReg)Val;
+        return Op;
+    }
+    void addProcInformation(int param_count,uint32_t call_conv);
 };
 struct LLInst : public llvm::MCInst //: public llvm::ilist_node<LLInst>
 {
@@ -280,6 +300,14 @@ public:
         caseTbl.numEntries=0;
         setOpcode(0);
     }
+    void replaceDst(const LLOperand &with)
+    {
+        dst = with;
+    }
+    void replaceDst(eReg r)
+    {
+        dst = LLOperand::CreateReg2(r);
+    }
     ICODE *m_link;
 };
 
@@ -438,9 +466,9 @@ public:
     CIcodeRec();	// Constructor
 
     ICODE *	addIcode(ICODE *pIcode);
-    void	SetInBB(int start, int end, BB* pnewBB);
     void	SetInBB(rCODE &rang, BB* pnewBB);
     bool	labelSrch(uint32_t target, uint32_t &pIndex);
     iterator    labelSrch(uint32_t target);
     ICODE *	GetIcode(int ip);
+    bool        alreadyDecoded(uint32_t target);
 };

+ 1 - 0
src/ast.cpp

@@ -604,6 +604,7 @@ void HlTypeSupport::performLongRemoval (eReg regi, LOCAL_ID *locId, COND_EXPR *t
 /* Returns the string located in image, formatted in C format. */
 static std::string getString (int offset)
 {
+    PROG &prog(Project::get()->prog);
     ostringstream o;
     int strLen, i;
 

+ 2 - 0
src/backend.cpp

@@ -97,6 +97,7 @@ char *cChar (uint8_t c)
 static void printGlobVar (std::ostream &ostr,SYM * psym)
 {
     int j;
+    PROG &prog(Project::get()->prog);
     uint32_t relocOp = prog.fCOM ? psym->label : psym->label + 0x100;
 
     switch (psym->size)
@@ -162,6 +163,7 @@ void Project::writeGlobSymTable()
  * fp. */
 static void writeHeader (std::ostream &_ios, char *fileName)
 {
+    PROG &prog(Project::get()->prog);
     /* Write header information */
     cCode.init();
     cCode.appendDecl( "/*\n");

+ 4 - 0
src/chklib.cpp

@@ -14,6 +14,7 @@
 #endif
 #include <string.h>
 #include "dcc.h"
+#include "project.h"
 #include "perfhlib.h"
 
 #define  NIL   -1                   /* Used like NULL, but 0 is valid */
@@ -297,6 +298,7 @@ static uint8_t pattMsChkstk[] =
 /* This procedure is called to initialise the library check code */
 void SetupLibCheck(void)
 {
+    PROG &prog(Project::get()->prog);
     uint16_t w, len;
     int i;
 
@@ -436,6 +438,7 @@ void CleanupLibCheck(void)
 */
 bool LibCheck(Function & pProc)
 {
+    PROG &prog(Project::get()->prog);
     long fileOffset;
     int h, i, j, arg;
     int Idx;
@@ -619,6 +622,7 @@ static boolT locatePattern(uint8_t *source, int iMin, int iMax, uint8_t *pattern
 
 void STATE::checkStartup()
 {
+    PROG &prog(Project::get()->prog);
     /* This function checks the startup code for various compilers' way of
     loading DS. If found, it sets DS. This may not be needed in the future if
     pushing and popping of registers is implemented.

+ 1 - 1
src/dcc.cpp

@@ -12,7 +12,7 @@
 char    *asm1_name, *asm2_name;     /* Assembler output filenames     */
 SYMTAB  symtab;             /* Global symbol table      			  */
 STATS   stats;              /* cfg statistics       				  */
-PROG    prog;               /* programs fields      				  */
+//PROG    prog;               /* programs fields      				  */
 OPTION  option;             /* Command line options     			  */
 //Function *   pProcList;			/* List of procedures, topologically sort */
 //Function *	pLastProc;			/* Pointer to last node in procedure list */

+ 2 - 1
src/disassem.cpp

@@ -13,7 +13,7 @@
 #include "dcc.h"
 #include "symtab.h"
 #include "disassem.h"
-
+#include "project.h"
 // Note: for the time being, there is no interactive disassembler
 // for unix
 
@@ -205,6 +205,7 @@ void Disassembler::disassem(Function * ppProc)
  ****************************************************************************/
 void Disassembler::dis1Line(LLInst &inst,int loc_ip, int pass)
 {
+    PROG &prog(Project::get()->prog);
     ostringstream oper_stream;
     ostringstream hex_bytes;
     ostringstream result_stream;

+ 8 - 3
src/frontend.cpp

@@ -112,6 +112,7 @@ bool DccFrontend::FrontEnd ()
 ***************************************************************************/
 static void displayLoadInfo(void)
 {
+    PROG &prog(Project::get()->prog);
     int	i;
 
     printf("File type is %s\n", (prog.fCOM)?"COM":"EXE");
@@ -145,14 +146,14 @@ static void displayLoadInfo(void)
 ****************************************************************************/
 static void fill(int ip, char *bf)
 {
+    PROG &prog(Project::get()->prog);
     static uint8_t type[4] = {'.', 'd', 'c', 'x'};
     uint8_t	i;
 
     for (i = 0; i < 16; i++, ip++)
     {
         *bf++ = ' ';
-        *bf++ = (ip < prog.cbImage)?
-                    type[(prog.map[ip >> 2] >> ((ip & 3) * 2)) & 3]: ' ';
+        *bf++ = (ip < prog.cbImage)? type[(prog.map[ip >> 2] >> ((ip & 3) * 2)) & 3]: ' ';
     }
     *bf = '\0';
 }
@@ -163,6 +164,8 @@ static void fill(int ip, char *bf)
 ****************************************************************************/
 static void displayMemMap(void)
 {
+    PROG &prog(Project::get()->prog);
+
     char	c, b1[33], b2[33], b3[33];
     uint8_t i;
     int ip = 0;
@@ -199,6 +202,7 @@ static void displayMemMap(void)
 ****************************************************************************/
 void DccFrontend::LoadImage(Project &proj)
 {
+    PROG &prog(Project::get()->prog);
     FILE   *fp;
     int		i, cb;
     uint8_t	buf[4];
@@ -269,7 +273,8 @@ void DccFrontend::LoadImage(Project &proj)
             }
         }
         /* Seek to start of image */
-        fseek(fp, (int)LH(&header.numParaHeader) * 16, SEEK_SET);
+        uint32_t start_of_image= LH(&header.numParaHeader) * 16;
+        fseek(fp, start_of_image, SEEK_SET);
     }
     else
     {	/* COM file

+ 1 - 0
src/graph.cpp

@@ -172,6 +172,7 @@ CondJumps:
 
 void Function::markImpure()
 {
+    PROG &prog(Project::get()->prog);
     SYM * psym;
     for(ICODE &icod : Icode)
     {

+ 7 - 0
src/icode.cpp

@@ -46,6 +46,13 @@ bool CIcodeRec::labelSrch(uint32_t target, uint32_t &pIndex)
     pIndex=location->loc_ip;
     return true;
 }
+bool CIcodeRec::alreadyDecoded(uint32_t target)
+{
+    iICODE location=labelSrch(target);
+    if(end()==location)
+            return false;
+    return true;
+}
 CIcodeRec::iterator CIcodeRec::labelSrch(uint32_t target)
 {
     return find_if(begin(),end(),[target](ICODE &l) -> bool {return l.ll()->label==target;});

+ 5 - 0
src/locident.cpp

@@ -8,6 +8,11 @@
 #include <cstring>
 #include "locident.h"
 #include "dcc.h"
+bool LONGID_TYPE::srcDstRegMatch(iICODE a, iICODE b) const
+{
+    return (a->ll()->src.getReg2()==l) and (b->ll()->dst.getReg2()==h);
+}
+
 
 ID::ID() : type(TYPE_UNKNOWN),illegal(false),loc(STK_FRAME),hasMacro(false)
 {

+ 10 - 3
src/parser.cpp

@@ -25,6 +25,7 @@ static uint32_t    SynthLab;
  * procedures found     */
 void DccFrontend::parse(Project &proj)
 {
+    PROG &prog(proj.prog);
     STATE state;
 
     /* Set initial state */
@@ -82,6 +83,7 @@ void DccFrontend::parse(Project &proj)
  * Size includes delimiter.     */
 int strSize (uint8_t *sym, char delim)
 {
+    PROG &prog(Project::get()->prog);
     int till_end = sym-prog.Image;
     uint8_t *end_ptr=std::find(sym,sym+(prog.cbImage-(till_end)),delim);
     return end_ptr-sym+1;
@@ -93,12 +95,13 @@ Function *fakeproc=Function::Create(0,0,"fake");
  * using a depth first search.     */
 void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
 {
+    PROG &prog(Project::get()->prog);
     ICODE   _Icode, *pIcode;     /* This gets copied to pProc->Icode[] later */
     ICODE   eIcode;             /* extra icodes for iDIV, iIDIV, iXCHG */
     SYM *    psym;
     uint32_t   offset;
     eErrorId err;
-    boolT   done = false;
+    bool   done = false;
     SYMTAB &global_symbol_table(g_proj.symtab);
     if (name.find("chkstk") != string::npos)
     {
@@ -376,6 +379,7 @@ void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
 /* process_JMP - Handles JMPs, returns true if we should end recursion  */
 boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGraph)
 {
+    PROG &prog(Project::get()->prog);
     static uint8_t i2r[4] = {rSI, rDI, rBP, rBX};
     ICODE       _Icode;
     uint32_t       cs, offTable, endTable;
@@ -503,6 +507,7 @@ boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGr
 
 boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *pstate)
 {
+    PROG &prog(Project::get()->prog);
     ICODE &last_insn(Icode.back());
     STATE localState;     /* Local copy of the machine state */
     uint32_t off;
@@ -633,6 +638,7 @@ boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *ps
 /* process_MOV - Handles state changes due to simple assignments    */
 static void process_MOV(LLInst & ll, STATE * pstate)
 {
+    PROG &prog(Project::get()->prog);
     SYM *  psym, *psym2;        /* Pointer to symbol in global symbol table */
     uint8_t  dstReg = ll.dst.regi;
     uint8_t  srcReg = ll.src.regi;
@@ -742,6 +748,7 @@ void STKFRAME::updateFrameOff ( int16_t off, int _size, uint16_t duFlag)
  *      symbol table, or Null if it's not a direct memory offset.  */
 static SYM * lookupAddr (LLOperand *pm, STATE *pstate, int size, uint16_t duFlag)
 {
+    PROG &prog(Project::get()->prog);
     int     i;
     SYM *    psym=nullptr;
     uint32_t   operand;
@@ -816,10 +823,10 @@ void STATE::setState(uint16_t reg, int16_t value)
     replaces *pIndex with an icode index */
 
 
-
-static void setBits(int16_t type, uint32_t start, uint32_t len)
 /* setBits - Sets memory bitmap bits for BM_CODE or BM_DATA (additively) */
+static void setBits(int16_t type, uint32_t start, uint32_t len)
 {
+    PROG &prog(Project::get()->prog);
     uint32_t   i;
 
     if (start < (uint32_t)prog.cbImage)

+ 1 - 0
src/procs.cpp

@@ -263,6 +263,7 @@ COND_EXPR *CallType::toId()
  * the actual argument gets modified */
 void adjustActArgType (COND_EXPR *exp, hlType forType, Function * pproc)
 {
+    PROG &prog(Project::get()->prog);
     hlType actType;
     int offset, offL;
 

+ 7 - 1
src/project.cpp

@@ -61,7 +61,13 @@ const std::string &Project::symbolName(size_t idx)
     assert(validSymIdx(idx));
     return symtab[idx].name;
 }
-Project *get()
+Project *Project::get()
 {
     return &g_proj;
 }
+
+
+SourceMachine *Project::machine()
+{
+    return nullptr;
+}

+ 1 - 1
src/proplong.cpp

@@ -480,7 +480,7 @@ int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE be
              * 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())))
         {
-            if ((pIcode->ll()->dst.regi == pLocId.id.longId.h) && (pIcode->ll()->src.regi == pLocId.id.longId.l))
+            if (pLocId.id.longId.srcDstRegMatch(pIcode,pIcode))
             {
                 asgn.lhs = COND_EXPR::idLongIdx (loc_ident_idx);
                 asgn.rhs = COND_EXPR::idKte (0, 4);	/* long 0 */

+ 6 - 1
src/scanner.cpp

@@ -9,6 +9,7 @@
 
 #include "dcc.h"
 #include "scanner.h"
+#include "project.h"
 /*  Parser flags  */
 #define TO_REG      0x000100    /* rm is source  */
 #define S_EXT       0x000200    /* sign extend   */
@@ -326,6 +327,7 @@ static ICODE * pIcode;		/* Ptr to Icode record filled in by scan() */
  ****************************************************************************/
 eErrorId scan(uint32_t ip, ICODE &p)
 {
+    PROG &prog(Project::get()->prog);
     int  op;
     p = ICODE();
     p.type = LOW_LEVEL;
@@ -367,8 +369,9 @@ eErrorId scan(uint32_t ip, ICODE &p)
 /***************************************************************************
  relocItem - returns true if uint16_t pointed at is in relocation table
  **************************************************************************/
-static boolT relocItem(uint8_t *p)
+static bool relocItem(uint8_t *p)
 {
+    PROG &prog(Project::get()->prog);
     int		i;
     uint32_t	off = p - prog.Image;
 
@@ -736,6 +739,7 @@ static void dispM(int i)
  ****************************************************************************/
 static void dispN(int )
 {
+    PROG &prog(Project::get()->prog);
     long off = (short)getWord();	/* Signed displacement */
 
     /* Note: the result of the subtraction could be between 32k and 64k, and
@@ -751,6 +755,7 @@ static void dispN(int )
  ***************************************************************************/
 static void dispS(int )
 {
+    PROG &prog(Project::get()->prog);
     long off = signex(*pInst++); 	/* Signed displacement */
 
     pIcode->ll()->src.SetImmediateOp((uint32_t)(off + (unsigned)(pInst - prog.Image)));