]> git.sur5r.net Git - cc65/blobdiff - src/cc65/codeent.c
Working on the backend
[cc65] / src / cc65 / codeent.c
index c96a95ef81b05102185bef6ef70d16f830c908ea..61b41a479a556c255125340f40a15ccb8356c120 100644 (file)
@@ -140,7 +140,7 @@ static void SetUseChgInfo (CodeEntry* E, const OPCDesc* D)
      * lookup the information about this function and use it. The jump itself
      * does not change any registers, so we don't need to use the data from D.
      */
-    if (E->OPC == OPC_JSR || ((E->Info & OF_BRA) != 0 && E->JumpTo == 0)) {
+    if ((E->Info & (OF_BRA | OF_CALL)) != 0 && E->JumpTo == 0) {
        /* A subroutine call or jump to external symbol (function exit) */
        GetFuncInfo (E->Arg, &E->Use, &E->Chg);
     } else {
@@ -160,7 +160,8 @@ static void SetUseChgInfo (CodeEntry* E, const OPCDesc* D)
 
 
 
-CodeEntry* NewCodeEntry (opc_t OPC, am_t AM, const char* Arg, CodeLabel* JumpTo)
+CodeEntry* NewCodeEntry (opc_t OPC, am_t AM, const char* Arg,
+                        CodeLabel* JumpTo, LineInfo* LI)
 /* Create a new code entry, initialize and return it */
 {
     /* Get the opcode description */
@@ -170,18 +171,14 @@ CodeEntry* NewCodeEntry (opc_t OPC, am_t AM, const char* Arg, CodeLabel* JumpTo)
     CodeEntry* E = xmalloc (sizeof (CodeEntry));
 
     /* Initialize the fields */
-    E->OPC     = D->OPC;
-    E->AM      = AM;
-    E->Size    = GetInsnSize (E->OPC, E->AM);
-    E->Hints   = 0;
-    E->Arg             = GetArgCopy (Arg);
-    if (NumArg (E->Arg, &E->Num)) {
-       E-> Flags = CEF_NUMARG;
-    } else {
-               E->Flags  = 0;
-    }
+    E->OPC    = D->OPC;
+    E->AM     = AM;
+    E->Arg    = GetArgCopy (Arg);
+    E->Flags  = NumArg (E->Arg, &E->Num)? CEF_NUMARG : 0;
     E->Info   = D->Info;
+    E->Size   = GetInsnSize (E->OPC, E->AM);
     E->JumpTo = JumpTo;
+    E->LI     = UseLineInfo (LI);
     SetUseChgInfo (E, D);
     InitCollection (&E->Labels);
 
@@ -205,6 +202,9 @@ void FreeCodeEntry (CodeEntry* E)
     /* Cleanup the collection */
     DoneCollection (&E->Labels);
 
+    /* Release the line info */
+    ReleaseLineInfo (E->LI);
+
     /* Free the entry */
     xfree (E);
 }
@@ -221,8 +221,8 @@ void ReplaceOPC (CodeEntry* E, opc_t OPC)
 
     /* Replace the opcode */
     E->OPC  = OPC;
-    E->Size = GetInsnSize (E->OPC, E->AM);
     E->Info = D->Info;
+    E->Size = GetInsnSize (E->OPC, E->AM);
     SetUseChgInfo (E, D);
 }
 
@@ -239,9 +239,6 @@ int CodeEntriesAreEqual (const CodeEntry* E1, const CodeEntry* E2)
 void AttachCodeLabel (CodeEntry* E, CodeLabel* L)
 /* Attach the label to the entry */
 {
-    /* Mark the label as defined */
-    L->Flags |= LF_DEF;
-
     /* Add it to the entries label list */
     CollAppend (&E->Labels, L);
 
@@ -299,53 +296,53 @@ void OutputCodeEntry (const CodeEntry* E, FILE* F)
     /* Print the operand */
     switch (E->AM) {
 
-       case AM_IMP:
+       case AM65_IMP:
            /* implicit */
            break;
 
-       case AM_ACC:
+       case AM65_ACC:
            /* accumulator */
            Chars += fprintf (F, "%*sa", 9-Chars, "");
            break;
 
-       case AM_IMM:
+       case AM65_IMM:
            /* immidiate */
            Chars += fprintf (F, "%*s#%s", 9-Chars, "", E->Arg);
            break;
 
-       case AM_ZP:
-       case AM_ABS:
+       case AM65_ZP:
+       case AM65_ABS:
            /* zeropage and absolute */
            Chars += fprintf (F, "%*s%s", 9-Chars, "", E->Arg);
            break;
 
-       case AM_ZPX:
-       case AM_ABSX:
+       case AM65_ZPX:
+       case AM65_ABSX:
            /* zeropage,X and absolute,X */
            Chars += fprintf (F, "%*s%s,x", 9-Chars, "", E->Arg);
            break;
 
-       case AM_ABSY:
+       case AM65_ABSY:
            /* absolute,Y */
            Chars += fprintf (F, "%*s%s,y", 9-Chars, "", E->Arg);
            break;
 
-       case AM_ZPX_IND:
+       case AM65_ZPX_IND:
            /* (zeropage,x) */
                    Chars += fprintf (F, "%*s(%s,x)", 9-Chars, "", E->Arg);
            break;
 
-       case AM_ZP_INDY:
+       case AM65_ZP_INDY:
            /* (zeropage),y */
                    Chars += fprintf (F, "%*s(%s),y", 9-Chars, "", E->Arg);
            break;
 
-       case AM_ZP_IND:
+       case AM65_ZP_IND:
            /* (zeropage) */
                    Chars += fprintf (F, "%*s(%s)", 9-Chars, "", E->Arg);
            break;
 
-       case AM_BRA:
+       case AM65_BRA:
            /* branch */
            Target = E->JumpTo? E->JumpTo->Name : E->Arg;
            Chars += fprintf (F, "%*s%s", 9-Chars, "", Target);
@@ -357,21 +354,24 @@ void OutputCodeEntry (const CodeEntry* E, FILE* F)
     }
 
     /* Print usage info if requested by the debugging flag */
-//    if (Debug) {
-       Chars += fprintf (F,
-                         "%*s; USE: %c%c%c CHG: %c%c%c SIZE: %u",
-                         30-Chars, "",
-                                 (E->Use & REG_A)? 'A' : '_',
-                                 (E->Use & REG_X)? 'X' : '_',
-                                 (E->Use & REG_Y)? 'Y' : '_',
-                                 (E->Chg & REG_A)? 'A' : '_',
-                                 (E->Chg & REG_X)? 'X' : '_',
-                                 (E->Chg & REG_Y)? 'Y' : '_',
-                         E->Size);
-//    }
-
+    if (Debug) {
+       fprintf (F,
+                "%*s; USE: %c%c%c CHG: %c%c%c SIZE: %u\n",
+                30-Chars, "",
+                (E->Use & REG_A)? 'A' : '_',
+                (E->Use & REG_X)? 'X' : '_',
+                (E->Use & REG_Y)? 'Y' : '_',
+                (E->Chg & REG_A)? 'A' : '_',
+                (E->Chg & REG_X)? 'X' : '_',
+                (E->Chg & REG_Y)? 'Y' : '_',
+                E->Size);
+    } else {
+       /* Terminate the line */
+       fprintf (F, "\n");
+    }
 }
 
 
 
 
+