* sim/ucsim/cmd.src/cmdutil.cc: NUL device is detected as CG_FILE type
[fw/sdcc] / src / xa51 / gen.c
index fdd1a3c249f958324b2c6fdc22d3361dca1802d6..bf86fa619ca685b20ae43a15d41d15e273f5019b 100755 (executable)
 #include "SDCCglobl.h"
 #include "newalloc.h"
 
-#ifdef HAVE_SYS_ISA_DEFS_H
-#include <sys/isa_defs.h>
-#else
-#ifdef HAVE_MACHINE_ENDIAN_H
-#include <machine/endian.h>
-#else
-#ifdef HAVE_ENDIAN_H
-#include <endian.h>
-#else
-#if !defined(__BORLANDC__) && !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__CYGWIN__)
-#warning "Cannot determine ENDIANESS of this machine assuming LITTLE_ENDIAN"
-#warning "If you running sdcc on an INTEL 80x86 Platform you are okay"
-#endif
-#endif
-#endif
-#endif
-
 #include "common.h"
 #include "SDCCpeeph.h"
 #include "ralloc.h"
 #include "gen.h"
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 extern int allocInfo;
 
 /* this is the down and dirty file with all kinds of
@@ -83,7 +60,7 @@ _G;
 
 extern int xa51_ptrRegReq;
 extern int xa51_nRegs;
-extern FILE *codeOutFile;
+extern struct dbuf_s *codeOutBuf;
 
 static lineNode *lineHead = NULL;
 static lineNode *lineCurr = NULL;
@@ -129,7 +106,7 @@ static void emitcode (char *inst, char *fmt,...) {
   else
     vsprintf (lb, fmt, ap);
 
-  while (isspace ((int)*lbp))
+  while (isspace (*lbp))
     lbp++;
 
   if (lbp && *lbp)
@@ -141,6 +118,19 @@ static void emitcode (char *inst, char *fmt,...) {
   va_end (ap);
 }
 
+/*-----------------------------------------------------------------*/
+/* xa51_emitDebuggerSymbol - associate the current code location  */
+/*   with a debugger symbol                                        */
+/*-----------------------------------------------------------------*/
+void
+xa51_emitDebuggerSymbol (char * debugSym)
+{
+  _G.debugLine = 1;
+  emitcode ("", "%s ==.", debugSym);
+  _G.debugLine = 0;
+}
+
+
 char *getStackOffset(int stack) {
   static char gsoBuf[1024];
   sprintf (gsoBuf, "r7+(%d%+d%+d)", stack,
@@ -818,7 +808,7 @@ static void genFunction (iCode * ic) {
   emitcode (";", "genFunction %s", sym->rname);
 
   /* print the allocation information */
-  printAllocInfo (currFunc, codeOutFile);
+  printAllocInfo (currFunc, codeOutBuf);
 
   emitcode ("", "%s:", sym->rname);
 
@@ -846,6 +836,8 @@ genEndFunction (iCode * ic)
 
   if (IFFUNC_ISNAKED(sym->type)) {
       emitcode(";", "naked function: no epilogue.");
+      if (options.debug && currFunc)
+       debugFile->writeEndFunction (currFunc, ic, 0);
       return;
   }
 
@@ -854,6 +846,10 @@ genEndFunction (iCode * ic)
     emitcode ("add", "r7,#%d\t; release stack space for locals", sym->stack);
   }
 
+  if (options.debug && currFunc) {
+    debugFile->writeEndFunction (currFunc, ic, 1);
+  }
+
   if (IFFUNC_ISISR(sym->type)) {
     emitcode ("reti", "");
   } else {
@@ -1205,7 +1201,7 @@ static iCode *hasInc (operand *op, iCode *ic, int osize) {
       }
     }
     /* if the operand used or deffed */
-    if (bitVectBitValue(OP_USES(op),lic->key) || (unsigned) lic->defKey == op->key) {
+    if (bitVectBitValue(OP_USES(op),lic->key) || lic->defKey == op->key) {
       return NULL;
     }
     /* if GOTO or IFX */
@@ -1906,64 +1902,67 @@ static void genReceive (iCode * ic) {
   printIc (0, "genReceive", ic, 1,0,0);
 }
 
+/*-----------------------------------------------------------------*/
+/* genDummyRead - generate code for dummy read of volatiles        */
+/*-----------------------------------------------------------------*/
+static void
+genDummyRead (iCode * ic)
+{
+  emitcode (";     genDummyRead","");
+
+  ic = ic;
+}
+
 /*-----------------------------------------------------------------*/
 /* gen51Code - generate code for 8051 based controllers            */
 /*-----------------------------------------------------------------*/
 void genXA51Code (iCode * lic) {
   iCode *ic;
   int cln = 0;
-  
+
   lineHead = lineCurr = NULL;
-  
+
   /* if debug information required */
   if (options.debug && currFunc)
     {
-      cdbSymbol (currFunc, cdbFile, FALSE, TRUE);
-      _G.debugLine = 1;
-      if (IS_STATIC (currFunc->etype))
-       emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name);
-      else
-       emitcode ("", "G$%s$0$0 ==.", currFunc->name);
-      _G.debugLine = 0;
+      debugFile->writeFunction (currFunc, lic);
     }
-  
+
   for (ic = lic; ic; ic = ic->next) {
     if (ic->lineno && cln != ic->lineno) {
       if (options.debug) {
-       _G.debugLine = 1;
-       emitcode ("", "C$%s$%d$%d$%d ==.",
-                 FileBaseName (ic->filename), ic->lineno,
-                 ic->level, ic->block);
-       _G.debugLine = 0;
+       debugFile->writeCLine (ic);
       }
       if (!options.noCcodeInAsm) {
-       emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno, 
+       emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno,
                  printCLine(ic->filename, ic->lineno));
       }
       cln = ic->lineno;
     }
     if (options.iCodeInAsm) {
-      emitcode("", ";ic:%d: %s", ic->key, printILine(ic));
+      char *iLine = printILine(ic);
+      emitcode("", ";ic:%d: %s", ic->key, iLine);
+      dbuf_free(iLine);
     }
-    
+
     /* if the result is marked as
        spilt and rematerializable or code for
        this has already been generated then
        do nothing */
     if (resultRemat (ic) || ic->generated)
       continue;
-    
+
     /* depending on the operation */
     switch (ic->op)
       {
       case '!':
        genNot (ic);
        break;
-       
+
       case '~':
        genCpl (ic);
        break;
-       
+
       case UNARYMINUS:
        genUminus (ic);
        break;
@@ -2089,7 +2088,7 @@ void genXA51Code (iCode * lic) {
       case RLC:
        genRLC (ic);
        break;
-       
+
       case GETHBIT:
        genGetHbit (ic);
        break;
@@ -2132,23 +2131,27 @@ void genXA51Code (iCode * lic) {
       case RECEIVE:
        genReceive (ic);
        break;
-       
+
       case SEND:
        addSet (&_G.sendSet, ic);
        break;
-       
+
+      case DUMMY_READ_VOLATILE:
+       genDummyRead (ic);
+       break;
+
       default:
        ic = ic;
       }
   }
-  
-  
+
+
   /* now we are ready to call the
      peep hole optimizer */
   if (!options.nopeep)
     peepHole (&lineHead);
-  
+
   /* now do the actual printing */
-  printLine (lineHead, codeOutFile);
+  printLine (lineHead, codeOutBuf);
   return;
 }