* src/SDCCsymt.h: removed RESULT_CHECK
[fw/sdcc] / src / pic16 / glue.c
index 2dfe5e4b8a5a189c19fc9ffb26c1f34e5a8507e8..93d4faf982947acb9663368983b9a55defa570d5 100644 (file)
@@ -135,25 +135,26 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                fprintf(stderr, "%s\t%s: sym: %s\tused: %d\textern: %d\tstatic: %d\taggregate: %d\tregister: 0x%x\tfunction: %d\n",
                        __FUNCTION__,
                        map->sname, sym->name, sym->used, IS_EXTERN(sym->etype), IS_STATIC(sym->etype),
-                       IS_AGGREGATE(sym->type), SPEC_SCLS(sym->etype), IS_FUNC(sym->type));
+                       IS_AGGREGATE(sym->type), (SPEC_SCLS(sym->etype) == S_REGISTER), IS_FUNC(sym->type));
                printTypeChain( sym->type, stderr );
                fprintf(stderr, "\n");
 #endif
 
                /* if extern then add to externs */
                if (IS_EXTERN (sym->etype)) {
-
                        /* reduce overhead while linking by not declaring
                         * extern unused external functions (usually declared
                         * in header files) */
                        if(IS_FUNC(sym->type) && !sym->used)continue;
                        
-                       checkAddSym(&externs, sym);
+                       /* make sure symbol is not in publics section */
+                       if(!checkSym(publics, sym))
+                               checkAddSym(&externs, sym);
                        continue;
                }
                
                /* if allocation required check is needed
-                *  then check if the symbol really requires
+                * then check if the symbol really requires
                 * allocation only for local variables */
                 if (arFlag && !IS_AGGREGATE (sym->type) &&
                        !(sym->_isparm && !IS_REGPARM (sym->etype)) &&
@@ -374,7 +375,7 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                                        addSet(&rel_idataSymSet, copySymbol(sym));
 
 //                                     ival = newNode ('=', newAst_VALUE(symbolVal (sym)),
-//                                             decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_CHECK));
+//                                             decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_TYPE_NONE));
                        }
 
                        if(ival) {
@@ -573,7 +574,7 @@ void pic16_printGPointerType (const char *iname, const char *oname, const unsign
 
 
 /* set to 0 to disable debug messages */
-#define DEBUG_PRINTIVAL        1
+#define DEBUG_PRINTIVAL        0
 
 /*-----------------------------------------------------------------*/
 /* pic16_printIvalType - generates ival for int/char               */
@@ -639,7 +640,7 @@ static int
 pic16_printIvalChar (sym_link * type, initList * ilist, char *s, char ptype, void *p)
 {
   value *val;
-  int remain;
+  unsigned int remain;
 
   if(!p)
     return 0;
@@ -944,6 +945,11 @@ void pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void
   value *val;
   int dLvl = 0;
 
+
+#if DEBUG_PRINTIVAL
+  fprintf(stderr, "%s\n",__FUNCTION__);
+#endif
+
   if (ilist)
     val = list2val (ilist);
   else
@@ -975,6 +981,20 @@ void pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void
       pic16_printPointerType (val->name, ptype, p);
   } else {
       pic16_printPointerType (val->sym->rname, ptype, p);
+
+      if(IS_FUNC(val->sym->type) && !val->sym->used) {
+        
+        if(!checkSym(publics, val->sym))
+         checkAddSym(&externs, val->sym);
+        
+       /* this has not been declared as extern
+        * so declare it as a 'late extern' just after the symbol */
+       if(ptype == 'f') {
+               fprintf((FILE *)p, "declare symbol as extern");
+               fprintf((FILE *)p, "\textern\t%s\n", val->sym->rname);
+               fprintf((FILE *)p, "continue variable declaration");
+       }
+      }
   }
 
   return;
@@ -1171,6 +1191,7 @@ static void
 pic16emitStaticSeg (memmap * map)
 {
   symbol *sym;
+  static int didcode=0;
 
   //fprintf(stderr, "%s\n",__FUNCTION__);
 
@@ -1299,8 +1320,12 @@ CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n", __FUNCTION__,
              pb = pic16_newpCodeChain(NULL, 'P',pic16_newpCodeCharP("; Starting pCode block for Ival"));
              pic16_addpBlock(pb);
 
-              /* make sure that 'code' directive is emitted before */
-              pic16_addpCode2pBlock(pb, pic16_newpCodeAsmDir("code", NULL));
+             if(!didcode) {
+               /* make sure that 'code' directive is emitted before, once */
+               pic16_addpCode2pBlock(pb, pic16_newpCodeAsmDir("code", NULL));
+               
+               didcode++;
+             }
                             
 //           fprintf(stderr, "%s:%d [2] generating init for label: %s\n", __FILE__, __LINE__, sym->rname);
 
@@ -1592,7 +1617,8 @@ pic16glue ()
        addSetHead(&tmpfileSet,ovrFile);
        pic16_pCodeInitRegisters();
 
-       if (mainf && IFFUNC_HASBODY(mainf->type)) {
+
+       if (pic16_options.no_crt && mainf && IFFUNC_HASBODY(mainf->type)) {
          pBlock *pb = pic16_newpCodeChain(NULL,'X',pic16_newpCodeCharP("; Starting pCode block"));
 
                pic16_addpBlock(pb);
@@ -1738,46 +1764,27 @@ pic16glue ()
 
        /* copy the interrupt vector table */
        if(mainf && IFFUNC_HASBODY(mainf->type)) {
-               fprintf (asmFile, "%s", iComments2);
+               fprintf (asmFile, "\n%s", iComments2);
                fprintf (asmFile, "; interrupt vector \n");
                fprintf (asmFile, "%s", iComments2);
                copyFile (asmFile, vFile);
        }
     
        /* copy global & static initialisations */
-       fprintf (asmFile, "%s", iComments2);
+       fprintf (asmFile, "\n%s", iComments2);
        fprintf (asmFile, "; global & static initialisations\n");
        fprintf (asmFile, "%s", iComments2);
     
-#if 0
-       /* copy over code */
-       fprintf (asmFile, "%s", iComments2);
-       fprintf (asmFile, "\tcode\n");
-       fprintf (asmFile, "%s", iComments2);
-#endif
-
        if(pic16_debug_verbose)
                fprintf(asmFile, "; A code from now on!\n");
        pic16_copypCode(asmFile, 'A');
 
 
-       if(mainf && IFFUNC_HASBODY(mainf->type)) {
-               fprintf(asmFile, "\tcode\n");
-               fprintf(asmFile,"__sdcc_gsinit_startup:\n");
-
-#if 0
-               /* FIXME 8051 legacy (?!) - VR 20-Jun-2003 */
-               /* if external stack is specified then the
-                * higher order byte of the xdatalocation is
-                * going into P2 and the lower order going into */
-       
-               if (options.useXstack) {
-                       fprintf(asmFile,";\tmov\tP2,#0x%02x\n",
-                                       (((unsigned int)options.xdata_loc) >> 8) & 0xff);
-                       fprintf(asmFile,";\tmov\t_spx,#0x%02x\n",
-                                       (unsigned int)options.xdata_loc & 0xff);
+       if(pic16_options.no_crt) {
+               if(mainf && IFFUNC_HASBODY(mainf->type)) {
+                       fprintf(asmFile, "\tcode\n");
+                       fprintf(asmFile,"__sdcc_gsinit_startup:\n");
                }
-#endif
        }
 
 //     copyFile (stderr, code->oFile);
@@ -1790,8 +1797,10 @@ pic16glue ()
        pic16_copypCode(asmFile, statsg->dbName);
 
 
-       if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type)) {
-               fprintf (asmFile,"\tgoto\t__sdcc_program_startup\n");
+       if(pic16_options.no_crt) {
+               if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type)) {
+                       fprintf (asmFile,"\tgoto\t__sdcc_program_startup\n");
+               }
        }