* src/pic16/gen.c (mov2f): New function to move an operand to
[fw/sdcc] / src / pic16 / main.c
index 727bee62c2eabb59b631b3c3c191c4b0d67a066f..8810338312cf05149f124ddc807c4d43c4917b48 100644 (file)
@@ -187,7 +187,7 @@ _process_pragma(const char *sz)
 
                if(stackLen < 1) {
                        stackLen = 64;
-                       fprintf(stderr, "%s:%d setting stack to default size 0x%x\n", __FILE__, __LINE__, stackLen);
+                       fprintf(stderr, "%s:%d setting stack to default size %d\n", __FILE__, __LINE__, stackLen);
                }
 
 //             fprintf(stderr, "Initializing stack pointer at 0x%x len 0x%x\n", stackPos, stackLen);
@@ -286,6 +286,9 @@ _process_pragma(const char *sz)
 #define NO_DEFLIBS     "--nodefaultlibs"
 #define MPLAB_COMPAT   "--mplab-comp"
 
+#define NL_OPT         "--nl="
+#define USE_CRT                "--use-crt="
+
 char *alt_asm=NULL;
 char *alt_link=NULL;
 
@@ -296,6 +299,7 @@ extern int pic16_pcode_verbose;
 
 int pic16_fstack=0;
 int pic16_enable_peeps=0;
+int pic16_nl=0;                        /* 0 for LF, 1 for CRLF */
 
 OPTION pic16_optionsTable[]= {
        { 0,    NO_DEFLIBS,             &pic16_options.nodefaultlibs,   "do not link default libraries when linking"},
@@ -304,7 +308,7 @@ OPTION pic16_optionsTable[]= {
        { 0,    "--pomit-config-words", &pic16_options.omit_configw,    "omit the generation of configuration words"},
        { 0,    "--pomit-ivt",          &pic16_options.omit_ivt,        "omit the generation of the Interrupt Vector Table"},
        { 0,    "--pleave-reset-vector",&pic16_options.leave_reset,     "when omitting IVT leave RESET vector"},
-       { 0,    STACK_MODEL,    NULL,   "use stack model 'small' (default) or 'large'"},
+       { 0,    STACK_MODEL,            NULL,                           "use stack model 'small' (default) or 'large'"},
 
        { 0,    "--debug-xtra",         &pic16_debug_verbose,   "show more debug info in assembly output"},
        { 0,    "--debug-ralloc",       &pic16_ralloc_debug,    "dump register allocator debug file *.d"},
@@ -320,6 +324,9 @@ OPTION pic16_optionsTable[]= {
        { 0,    "--calltree",           &pic16_options.dumpcalltree,    "dump call tree in .calltree file"},
        { 0,    MPLAB_COMPAT,           &pic16_mplab_comp,      "enable compatibility mode for MPLAB utilities (MPASM/MPLINK)"},
        { 0,    "--fstack",             &pic16_fstack,          "enable stack optimizations"},
+       { 0,    NL_OPT,         NULL,                           "new line, \"lf\" or \"crlf\""},
+       { 0,    USE_CRT,        NULL,   "use <crt-o> run-time initialization module"},
+       { 0,    "--no-crt",     &pic16_options.no_crt,  "do not link any default run-time initialization module"},
        { 0,    NULL,           NULL,   NULL}
        };
 
@@ -350,8 +357,8 @@ _pic16_parseOptions (int *pargc, char **argv, int *i)
 
        if(ISOPT(STACK_MODEL)) {
                stkmodel = getStringArg(STACK_MODEL, argv, i, *pargc);
-               if(STRCASECMP(stkmodel, "small"))pic16_options.stack_model = 0;
-               else if(STRCASECMP(stkmodel, "large"))pic16_options.stack_model = 1;
+               if(!STRCASECMP(stkmodel, "small"))pic16_options.stack_model = 0;
+               else if(!STRCASECMP(stkmodel, "large"))pic16_options.stack_model = 1;
                else {
                        fprintf(stderr, "Unknown stack model: %s", stkmodel);
                        exit(-1);
@@ -383,7 +390,25 @@ _pic16_parseOptions (int *pargc, char **argv, int *i)
                pic16_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc);
                return TRUE;
        }
-
+       
+       if(ISOPT(NL_OPT)) {
+          char *tmp;
+            
+            tmp = Safe_strdup( getStringArg(NL_OPT, argv, i, *pargc) );
+            if(!STRCASECMP(tmp, "lf"))pic16_nl = 0;
+            else if(!STRCASECMP(tmp, "crlf"))pic16_nl = 1;
+            else {
+                  fprintf(stderr, "invalid termination character id\n");
+                  exit(-1);
+            }
+            return TRUE;
+        }
+
+        if(ISOPT(USE_CRT)) {
+            pic16_options.no_crt = 0;
+            pic16_options.crt_name = Safe_strdup( getStringArg(USE_CRT, argv, i, *pargc) );
+        }
+        
   return FALSE;
 }
 
@@ -395,29 +420,32 @@ static void _pic16_initPaths(void)
   set *pic16libDirsSet;
   char devlib[512];
 
-       setMainValue("mcu", pic16->name[2] );
-       addSet(&preArgvSet, Safe_strdup("-D{mcu}"));
+    setMainValue("mcu", pic16->name[2] );
+    addSet(&preArgvSet, Safe_strdup("-D{mcu}"));
 
-       sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
-       sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
+    sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
+    sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
 
-       if(!options.nostdinc) {
-               /* setup pic16 include directory */
-               pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
-               mergeSets(&includeDirsSet, pic16incDirsSet);
-       }
-       
-       if(!options.nostdlib) {
-               /* setup pic16 library directory */
-               pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir);
-               mergeSets(&libDirsSet, pic16libDirsSet);
-       }
-       
-       if(!pic16_options.nodefaultlibs) {
-               /* now add the library for the device */
-               sprintf(devlib, "%s.lib", pic16->name[2]);
-               addSet(&libFilesSet, Safe_strdup(devlib));
-       }
+    if(!options.nostdinc) {
+      /* setup pic16 include directory */
+      pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
+      mergeSets(&includeDirsSet, pic16incDirsSet);
+    }
+
+    if(!options.nostdlib) {
+      /* setup pic16 library directory */
+      pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir);
+      mergeSets(&libDirsSet, pic16libDirsSet);
+    }
+
+    if(!pic16_options.nodefaultlibs) {
+      /* now add the library for the device */
+      sprintf(devlib, "%s.lib", pic16->name[2]);
+      addSet(&libFilesSet, Safe_strdup(devlib));
+
+      /* add the internal SDCC library */
+      addSet(&libFilesSet, Safe_strdup( "libsdcc.lib" ));
+    }
 }
 
 extern set *linkOptionsSet;
@@ -454,11 +482,12 @@ static void _pic16_linkEdit(void)
 
        if(fullSrcFileName) {
                sprintf(temp, "%s.o", dstFileName);
-//             shash_add(&linkValues, "srcofile", temp);
-               addSetHead(&relFilesSet, temp);
+               addSetHead(&relFilesSet, Safe_strdup(temp));
        }
 
-//     shash_add(&linkValues, "spec_ofiles", "crt0i.o");
+       if(!pic16_options.no_crt)
+          shash_add(&linkValues, "spec_ofiles", pic16_options.crt_name);
+
        shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
        shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
        
@@ -480,55 +509,35 @@ extern const char *pic16_asmCmd[];
 static void
 _pic16_finaliseOptions (void)
 {
-       port->mem.default_local_map = data;
-       port->mem.default_globl_map = data;
+    port->mem.default_local_map = data;
+    port->mem.default_globl_map = data;
 
-       /* peepholes are disabled for the time being */
-       options.nopeep = 1;
+    /* peepholes are disabled for the time being */
+    options.nopeep = 1;
 
-       /* explicit enable peepholes for testing */
-       if(pic16_enable_peeps)
-               options.nopeep = 0;
+    /* explicit enable peepholes for testing */
+    if(pic16_enable_peeps)
+      options.nopeep = 0;
 
-       options.all_callee_saves = 1;           // always callee saves
-//     options.float_rent = 1;
-//     options.intlong_rent = 1;
+    options.all_callee_saves = 1;              // always callee saves
+//    options.float_rent = 1;
+//    options.intlong_rent = 1;
        
 
-       if(alt_asm && strlen(alt_asm))
-               pic16_asmCmd[0] = alt_asm;
+    if(alt_asm && strlen(alt_asm))
+      pic16_asmCmd[0] = alt_asm;
        
-       if(alt_link && strlen(alt_link))
-               pic16_linkCmd[0] = alt_link;
+    if(alt_link && strlen(alt_link))
+      pic16_linkCmd[0] = alt_link;
+        
+    if(!pic16_options.no_crt) {
+      pic16_options.omit_ivt = 1;
+      pic16_options.leave_reset = 0;
+    }
 }
 
 
-/* all the rest is commented ifdef'd out */
 #if 0
-  /* Hack-o-matic: if we are using the flat24 model,
-   * adjust pointer sizes.
-   */
-  if (options.model == MODEL_FLAT24)
-    {
-
-      fprintf (stderr, "*** WARNING: you should use the '-mds390' option "
-              "for DS80C390 support. This code generator is "
-              "badly out of date and probably broken.\n");
-
-      port->s.fptr_size = 3;
-      port->s.gptr_size = 4;
-      port->stack.isr_overhead++;      /* Will save dpx on ISR entry. */
-#if 1
-      port->stack.call_overhead++;     /* This acounts for the extra byte 
-                                        * of return addres on the stack.
-                                        * but is ugly. There must be a 
-                                        * better way.
-                                        */
-#endif
-      fReturn = fReturn390;
-      fReturnSize = 5;
-    }
-
   if (options.model == MODEL_LARGE)
     {
       port->mem.default_local_map = xdata;
@@ -577,6 +586,8 @@ _pic16_setDefaultOptions (void)
        pic16_options.ivt_loc = 0x000000;
        pic16_options.nodefaultlibs = 0;
        pic16_options.dumpcalltree = 0;
+       pic16_options.crt_name = "crt0i.o";             /* the default crt to link */
+       pic16_options.no_crt = 0;                       /* use crt by default */
 }
 
 static const char *
@@ -665,13 +676,13 @@ static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
 #if 1
        /* multiplication is fixed */
        /* support mul for char/int/long */
-       if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) <= 4)
-               && (ic->op == '*'))return TRUE;
+       if((ic->op == '*')
+         && (getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 2))return TRUE;
 #endif
 
 #if 0
        /* support div for char/int/long */
-       if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) <= 0)
+       if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 0)
                && (ic->op == '/'))return TRUE;
 #endif
        
@@ -853,6 +864,16 @@ PORT pic16_port =
   {
     pic16_emitDebuggerSymbol
   },
+  {
+    255/3,      /* maxCount */
+    3,          /* sizeofElement */
+    /* The rest of these costs are bogus. They approximate */
+    /* the behavior of src/SDCCicode.c 1.207 and earlier.  */
+    {4,4,4},    /* sizeofMatchJump[] */
+    {0,0,0},    /* sizeofRangeCompare[] */
+    0,          /* sizeofSubtract */
+    3,          /* sizeofDispatch */
+  },
   "_",
   _pic16_init,
   _pic16_parseOptions,