* sim/ucsim/cmd.src/cmdutil.cc: NUL device is detected as CG_FILE type
[fw/sdcc] / src / pic16 / main.c
index 2a6e06784e1faffa6a125a2342dd8a432612e110..ee7b4b4f4fd8848b66367b86cb07602fffaf97fd 100644 (file)
@@ -31,6 +31,7 @@
 #include "SDCCutil.h"
 #include "glue.h"
 #include "pcode.h"
+#include "dbuf_string.h"
 
 
 static char _defaultRules[] =
@@ -335,68 +336,79 @@ do_pragma(int id, const char *name, const char *cp)
         int found = 0;
 
         cp = get_pragma_token(cp, &token);
-        if (TOKEN_EOL == token.type)
-          goto udata_err;
-
-        sectname = Safe_strdup(get_pragma_string(&token));
-
-        cp = get_pragma_token(cp, &token);
-        if (TOKEN_EOL == token.type)
+        if (TOKEN_STR == token.type)
+          sectname = Safe_strdup(get_pragma_string(&token));
+        else
           {
-          udata_err:
-            //fprintf (stderr, "%s:%d: #pragma udata [section-name] [symbol] -- section-name or symbol missing!\n", filename, lineno);
             err = 1;
             break;
           }
-        symname = get_pragma_string(&token);
 
         cp = get_pragma_token(cp, &token);
-        if (TOKEN_EOL != token.type)
+        if (TOKEN_STR == token.type)
+          symname = get_pragma_string(&token);
+        else
           {
+            //fprintf (stderr, "%s:%d: #pragma udata [section-name] [symbol] -- section-name or symbol missing!\n", filename, lineno);
             err = 1;
-            break;
+            symname = NULL;
           }
 
-        while (symname) {
-          ssym = Safe_calloc(1, sizeof(sectSym));
-          ssym->name = Safe_calloc(1, strlen(symname) + 2);
-          sprintf(ssym->name, "%s%s", port->fun_prefix, symname);
-          ssym->reg = NULL;
+        while (symname)
+          {
+            ssym = Safe_calloc(1, sizeof(sectSym));
+            ssym->name = Safe_calloc(1, strlen(symname) + 2);
+            sprintf(ssym->name, "%s%s", port->fun_prefix, symname);
+            ssym->reg = NULL;
 
-          addSet(&sectSyms, ssym);
+            addSet(&sectSyms, ssym);
 
-          nsym = newSymbol((char *)symname, 0);
-          strcpy(nsym->rname, ssym->name);
+            nsym = newSymbol((char *)symname, 0);
+            strcpy(nsym->rname, ssym->name);
 
 #if 0
-          checkAddSym(&publics, nsym);
+            checkAddSym(&publics, nsym);
 #endif
 
-          found = 0;
-          for (snam = setFirstItem(sectNames);snam;snam=setNextItem(sectNames)) {
-            if (!strcmp(sectname, snam->name)){ found=1; break; }
-          }
+            found = 0;
+            for (snam = setFirstItem(sectNames);snam;snam=setNextItem(sectNames))
+              {
+                if (!strcmp(sectname, snam->name))
+                  {
+                    found=1;
+                    break;
+                  }
+              }
 
-          if(!found) {
-            snam = Safe_calloc(1, sizeof(sectName));
-            snam->name = Safe_strdup(sectname);
-            snam->regsSet = NULL;
+            if(!found)
+              {
+                snam = Safe_calloc(1, sizeof(sectName));
+                snam->name = Safe_strdup(sectname);
+                snam->regsSet = NULL;
 
-            addSet(&sectNames, snam);
-          }
+                addSet(&sectNames, snam);
+              }
 
-          ssym->section = snam;
+            ssym->section = snam;
 
 #if 0
-          fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
-             ssym->name, snam->name, snam);
+            fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
+               ssym->name, snam->name, snam);
 #endif
 
-          cp = get_pragma_token(cp, &token);
-          symname = (TOKEN_EOL != token.type) ? get_pragma_string(&token) : NULL;
-        }
+            cp = get_pragma_token(cp, &token);
+            if (TOKEN_STR == token.type)
+              symname = get_pragma_string(&token);
+            else if (TOKEN_EOL == token.type)
+              symname = NULL;
+            else
+              {
+                err = 1;
+                symname = NULL;
+              }
+          }
 
-        Safe_free(sectname);
+          Safe_free(sectname);
       }
       break;
 
@@ -686,8 +698,6 @@ extern set *userIncDirsSet;
 
 static void _pic16_initPaths(void)
 {
-  char pic16incDir[512];
-  char pic16libDir[512];
   set *pic16incDirsSet=NULL;
   set *pic16libDirsSet=NULL;
   char devlib[512];
@@ -698,13 +708,15 @@ static void _pic16_initPaths(void)
     setMainValue("mcu1", pic16->name[1] );
     addSet(&preArgvSet, Safe_strdup("-D__{mcu1}"));
 
-    sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
-    sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
+    if(!options.nostdinc) {
+      struct dbuf_s pic16incDir;
 
+      dbuf_init(&pic16incDir, 128);
+      dbuf_makePath(&pic16incDir, INCLUDE_DIR_SUFFIX, "pic16");
 
-    if(!options.nostdinc) {
       /* setup pic16 include directory */
-      pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
+      pic16incDirsSet = appendStrSet(dataDirsSet, NULL, dbuf_c_str(&pic16incDir));
+      dbuf_destroy(&pic16incDir);
       includeDirsSet = pic16incDirsSet;
 //      mergeSets(&includeDirsSet, pic16incDirsSet);
     }
@@ -713,8 +725,13 @@ static void _pic16_initPaths(void)
     mergeSets(&pic16incDirsSet, userIncDirsSet);
 
     if(!options.nostdlib) {
+      struct dbuf_s pic16libDir;
+
+      dbuf_init(&pic16libDir, 128);
+      dbuf_makePath(&pic16libDir, INCLUDE_DIR_SUFFIX, "pic16");
       /* setup pic16 library directory */
-      pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir);
+      pic16libDirsSet = appendStrSet(dataDirsSet, NULL, dbuf_c_str(&pic16libDir));
+      dbuf_destroy(&pic16libDir);
       libDirsSet = pic16libDirsSet;
 //      mergeSets(&libDirsSet, pic16libDirsSet);
     }
@@ -968,35 +985,35 @@ _pic16_genAssemblerPreamble (FILE * of)
 
 /* Generate interrupt vector table. */
 static int
-_pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
+_pic16_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
 {
 #if 1
        /* PIC18F family has only two interrupts, the high and the low
         * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */
 
        if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) {
-               fprintf(of, "; RESET vector\n");
-               fprintf(of, "\tgoto\t__sdcc_gsinit_startup\n");
+               dbuf_printf(oBuf, "; RESET vector\n");
+               dbuf_printf(oBuf, "\tgoto\t__sdcc_gsinit_startup\n");
        }
        
        if(!pic16_options.omit_ivt) {
-               fprintf(of, "\tres 4\n");
+               dbuf_printf(oBuf, "\tres 4\n");
 
 
-               fprintf(of, "; High priority interrupt vector 0x0008\n");
+               dbuf_printf(oBuf, "; High priority interrupt vector 0x0008\n");
                if(interrupts[1]) {
-                       fprintf(of, "\tgoto\t%s\n", interrupts[1]->rname);
-                       fprintf(of, "\tres\t12\n"); 
+                       dbuf_printf(oBuf, "\tgoto\t%s\n", interrupts[1]->rname);
+                       dbuf_printf(oBuf, "\tres\t12\n"); 
                } else {
-                       fprintf(of, "\tretfie\n");
-                       fprintf(of, "\tres\t14\n");
+                       dbuf_printf(oBuf, "\tretfie\n");
+                       dbuf_printf(oBuf, "\tres\t14\n");
                }
 
-               fprintf(of, "; Low priority interrupt vector 0x0018\n");
+               dbuf_printf(oBuf, "; Low priority interrupt vector 0x0018\n");
                if(interrupts[2]) {
-                       fprintf(of, "\tgoto\t%s\n", interrupts[2]->rname);
+                       dbuf_printf(oBuf, "\tgoto\t%s\n", interrupts[2]->rname);
                } else {
-                       fprintf(of, "\tretfie\n");
+                       dbuf_printf(oBuf, "\tretfie\n");
                }
        }
 #endif
@@ -1281,6 +1298,8 @@ PORT pic16_port =
     NULL,                      // xinit
     "CONST   (CODE)",          // const_name - const data (code or not)
     "CABS    (ABS,CODE)",      // cabs_name - const absolute data (code or not)
+    "XABS    (ABS,XDATA)",     // xabs_name - absolute xdata
+    "IABS    (ABS,DATA)",      // iabs_name - absolute data
     NULL,                      // default location for auto vars
     NULL,                      // default location for global vars
     1                          // code is read only 1=yes