* src/pic/glue.h,src/pic16/glue.h: added prototypes
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 19 Jun 2006 20:36:23 +0000 (20:36 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 19 Jun 2006 20:36:23 +0000 (20:36 +0000)
* src/pic/glue.c,src/pic16/glue.c (pic1x_stringInSet,
  pic1x_emitSymbolIfNew): NEW, check for a string in a set,
  (pic14printExterns,pic14printPublics,pic16printPublics,
  pic16_printExterns): use new functions to emit symbols
  (picglue,pic16glue): emit publics before emitting externs
* src/pic/gen.c,src/pic16/gen.c (genFunction): remember the names of
  locally defined functions to avoid bug #1443651
* support/regression/tests/bug-716242.c: removed pic16 workaround
* support/regression/ports/pic16/spec.mk: ignore errors during build

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4243 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/pic/gen.c
src/pic/glue.c
src/pic/glue.h
src/pic16/gen.c
src/pic16/glue.c
src/pic16/glue.h
support/regression/ports/pic16/spec.mk
support/regression/tests/bug-716242.c

index 71f9f688fa191868eabe825ad5b9cef9c55a055e..6cd9a8603655769725c5c16805486417ed536a0f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2006-06-19 Raphael Neider <rneider AT web.de>
+
+       * src/pic/glue.h,src/pic16/glue.h: added prototypes
+       * src/pic/glue.c,src/pic16/glue.c (pic1x_stringInSet,
+         pic1x_emitSymbolIfNew): NEW, check for a string in a set,
+         (pic14printExterns,pic14printPublics,pic16printPublics,
+         pic16_printExterns): use new functions to emit symbols
+         (picglue,pic16glue): emit publics before emitting externs
+       * src/pic/gen.c,src/pic16/gen.c (genFunction): remember the names of
+         locally defined functions to avoid bug #1443651
+       * support/regression/tests/bug-716242.c: removed pic16 workaround
+       * support/regression/ports/pic16/spec.mk: ignore errors during build
+
 2006-06-19 Raphael Neider <rneider AT web.de>
 
        * src/pic/glue.h: added pic14aopLiteral prototype
index 931f82d364af143c72046511004cb05caf370fa4..bed1cb46ace620fd0be27d8e0ae33c9f46111ef0 100644 (file)
@@ -2886,6 +2886,9 @@ static void genFunction (iCode *ic)
        pic14_emitcode(";"," function %s",(sym = OP_SYMBOL(IC_LEFT(ic)))->name);
        pic14_emitcode(";","-----------------------------------------");
        
+       /* prevent this symbol from being emitted as 'extern' */
+       pic14_stringInSet(sym->rname, &pic14_localFunctions, 1);
+
        pic14_emitcode("","%s:",sym->rname);
        addpCode2pBlock(pb,newpCodeFunction(NULL,sym->rname,!IS_STATIC (sym->etype)));
        
index f8f4a24cce6ebe1e4ebac487ccf7225a464d0a30..c5f491e146b54c2eec075a1ab1550aa00124ac62 100644 (file)
@@ -55,6 +55,7 @@ extern set *tmpfileNameSet;
 extern char *iComments1;
 extern char *iComments2;
 //extern void emitStaticSeg (memmap * map);
+set *pic14_localFunctions = NULL;
 
 extern DEFSETFUNC (closeTmpFiles);
 extern DEFSETFUNC (rmTmpFiles);
@@ -1025,6 +1026,41 @@ pic14initialComments (FILE * afile)
        
 }
 
+int
+pic14_stringInSet(const char *str, set **world, int autoAdd)
+{
+  char *s;
+
+  if (!str) return 1;
+  assert(world);
+
+  for (s = setFirstItem(*world); s; s = setNextItem(*world))
+  {
+    /* found in set */
+    if (0 == strcmp(s, str)) return 1;
+  }
+
+  /* not found */
+  if (autoAdd) addSet(world, Safe_strdup(str));
+  return 0;
+}
+
+static int
+pic14_emitSymbolIfNew(FILE *file, const char *fmt, const char *sym, int checkLocals)
+{
+  static set *emitted = NULL;
+
+  if (!pic14_stringInSet(sym, &emitted, 1)) {
+    /* sym was not in emittedSymbols */
+    if (!checkLocals || !pic14_stringInSet(sym, &pic14_localFunctions, 0)) {
+      /* sym is not a locally defined function---avoid bug #1443651 */
+      fprintf( file, fmt, sym );
+      return 0;
+    }
+  }
+  return 1;
+}
+
 /*-----------------------------------------------------------------*/
 /* printExterns - generates extern for external variables          */
 /*-----------------------------------------------------------------*/
@@ -1037,9 +1073,8 @@ pic14printExterns (FILE * afile)
        fprintf (afile, "; extern variables in this module\n");
        fprintf (afile, "%s", iComments2);
        
-       for (sym = setFirstItem (externs); sym;
-       sym = setNextItem (externs))
-               fprintf (afile, "\textern %s\n", sym->rname);
+       for (sym = setFirstItem (externs); sym; sym = setNextItem (externs))
+               pic14_emitSymbolIfNew(afile, "\textern %s\n", sym->rname, 1);
 }
 
 /*-----------------------------------------------------------------*/
@@ -1048,25 +1083,25 @@ pic14printExterns (FILE * afile)
 static void
 pic14printPublics (FILE * afile)
 {
-       symbol *sym;
-       
-       fprintf (afile, "%s", iComments2);
-       fprintf (afile, "; publics variables in this module\n");
-       fprintf (afile, "%s", iComments2);
-       
-       for (sym = setFirstItem (publics); sym;
-       sym = setNextItem (publics)) {
-               
-               if(!IS_BITFIELD(sym->type) && ((IS_FUNC(sym->type) || sym->allocreq))) {
-                       if (!IS_BITVAR(sym->type))
-                               fprintf (afile, "\tglobal %s\n", sym->rname);
-               } else {
-                       /* Absolute variables are defines in the asm file as equates and thus can not be made global. */
-                       /* Not any longer! */
-                       //if (!SPEC_ABSA (sym->etype))
-                               fprintf (afile, "\tglobal %s\n", sym->rname);
-               }
-       }
+  symbol *sym;
+
+  fprintf (afile, "%s", iComments2);
+  fprintf (afile, "; publics variables in this module\n");
+  fprintf (afile, "%s", iComments2);
+
+  for (sym = setFirstItem (publics); sym;
+      sym = setNextItem (publics)) {
+
+    if(!IS_BITFIELD(sym->type) && ((IS_FUNC(sym->type) || sym->allocreq))) {
+      if (!IS_BITVAR(sym->type))
+       pic14_emitSymbolIfNew(afile, "\tglobal %s\n", sym->rname, 0);
+    } else {
+      /* Absolute variables are defines in the asm file as equates and thus can not be made global. */
+      /* Not any longer! */
+      //if (!SPEC_ABSA (sym->etype))
+      pic14_emitSymbolIfNew(afile, "\tglobal %s\n", sym->rname, 0);
+    }
+  }
 }
 
 /*-----------------------------------------------------------------*/
@@ -1324,12 +1359,12 @@ picglue ()
        /* Emit the __config directive */
        pic14_emitConfigWord (asmFile);
        
-       /* print the extern variables in this module */
-       pic14printExterns (asmFile);
-       
        /* print the global variables in this module */
        pic14printPublics (asmFile);
        
+       /* print the extern variables in this module */
+       pic14printExterns (asmFile);
+       
        /* copy the sfr segment */
        fprintf (asmFile, "%s", iComments2);
        fprintf (asmFile, "; special function registers\n");
index b5b285dfc285bf6049d9db6166f0b26e49ffe398..88e54429babc1c46be1ac025b002188560050e4a 100644 (file)
 #ifndef PIC_GLUE_H
 #define PIC_GLUE_H
 
+#include "../SDCCset.h"
+
+extern set *pic14_localFunctions;
+
 void picglue (void);
 unsigned int pic14aopLiteral (value *val, int offset);
+int pic14_stringInSet(const char *str, set **world, int autoAdd);
 
 #endif
index 898f47302e83cacbfe09e06d7319053cd4b539b2..7dda28ae056c28530af3232e9066dfa7fa38d5f4 100644 (file)
@@ -3705,6 +3705,9 @@ static void genFunction (iCode *ic)
     pic16_emitcode(";"," function %s",sym->name);
     pic16_emitcode(";","-----------------------------------------");
 
+    /* prevent this symbol from being emitted as 'extern' */
+    pic16_stringInSet(sym->rname, &pic16_localFunctions, 1);
+
     pic16_emitcode("","%s:",sym->rname);
     pic16_addpCode2pBlock(pb,pic16_newpCodeFunction(moduleName,sym->rname));
 
index 107c2e941a645af28580278985de820363573947..c2085e8bcec8f410b957ffdb79f8a4e55d729d17 100644 (file)
@@ -55,6 +55,7 @@ extern int initsfpnt;
 extern unsigned long pFile_isize;
 
 extern unsigned long pic16_countInstructions();
+set *pic16_localFunctions = NULL;
 set *rel_idataSymSet=NULL;
 set *fix_idataSymSet=NULL;
 
@@ -1522,6 +1523,41 @@ pic16initialComments (FILE * afile)
        }
 }
 
+int
+pic16_stringInSet(const char *str, set **world, int autoAdd)
+{
+  char *s;
+
+  if (!str) return 1;
+  assert(world);
+
+  for (s = setFirstItem(*world); s; s = setNextItem(*world))
+  {
+    /* found in set */
+    if (0 == strcmp(s, str)) return 1;
+  }
+
+  /* not found */
+  if (autoAdd) addSet(world, Safe_strdup(str));
+  return 0;
+}
+
+static int
+pic16_emitSymbolIfNew(FILE *file, const char *fmt, const char *sym, int checkLocals)
+{
+  static set *emitted = NULL;
+
+  if (!pic16_stringInSet(sym, &emitted, 1)) {
+    /* sym was not in emittedSymbols */
+    if (!checkLocals || !pic16_stringInSet(sym, &pic16_localFunctions, 0)) {
+      /* sym is not a locally defined function---avoid bug #1443651 */
+      fprintf( file, fmt, sym );
+      return 0;
+    }
+  }
+  return 1;
+}
+
 /*-----------------------------------------------------------------*/
 /* printPublics - generates global declarations for publics        */
 /*-----------------------------------------------------------------*/
@@ -1537,7 +1573,7 @@ pic16printPublics (FILE *afile)
        for(sym = setFirstItem (publics); sym; sym = setNextItem (publics))
          /* sanity check */
          if(!IS_STATIC(sym->etype))
-               fprintf(afile, "\tglobal %s\n", sym->rname);
+               pic16_emitSymbolIfNew(afile, "\tglobal %s\n", sym->rname, 0);
 }
 
 /*-----------------------------------------------------------------*/
@@ -1557,10 +1593,10 @@ pic16_printExterns(FILE *afile)
        fprintf(afile, "%s", iComments2);
        
        for(sym = setFirstItem(externs); sym; sym = setNextItem(externs))
-               fprintf(afile, "\textern %s\n", sym->rname);
+               pic16_emitSymbolIfNew(afile, "\textern %s\n", sym->rname, 1);
 
        for(sym = setFirstItem(pic16_builtin_functions); sym; sym = setNextItem(pic16_builtin_functions))
-               fprintf(afile, "\textern _%s\n", sym->name);
+               pic16_emitSymbolIfNew(afile, "\textern _%s\n", sym->name, 1);
 }
 
 /*-----------------------------------------------------------------*/
@@ -1809,12 +1845,12 @@ pic16glue ()
       pic16_OptimizeJumps();
     }
 
-    /* print the extern variables to this module */
-    pic16_printExterns(asmFile);
-       
     /* print the global variables in this module */
     pic16printPublics (asmFile);
 
+    /* print the extern variables to this module */
+    pic16_printExterns(asmFile);
+       
     pic16_writeUsedRegs(asmFile);
 
 #if 0
index 2fc4da55066cdd7de6b58f7010cc36512547df8b..3c8e04786ca737b2fb2b1ba0e0268e0861d82d35 100644 (file)
 #ifndef PIC16_GLUE_H
 #define PIC16_GLUE_H
 
+#include "SDCCset.h"
+
+extern set *pic16_localFunctions;
+
 void pic16glue (void);
 unsigned int pic16aopLiteral (value *val, int offset);
+int pic16_stringInSet(const char *str, set **world, int autoAdd);
 
 #endif
index b1fdcb0e71960182ddcc0936a600e3f65c8ad704..a05d2e2c37f57895c094603e92853f135087d438 100644 (file)
@@ -19,13 +19,13 @@ EXTRAS = $(PORT_CASES_DIR)/testfwk$(OBJEXT) $(PORT_CASES_DIR)/support$(OBJEXT)
 
 # Rule to link into .ihx
 %$(EXEEXT): %$(OBJEXT) $(EXTRAS)
-       $(SDCC) $(SDCCFLAGS) $(LINKFLAGS) -L $(LIBDIR) $(EXTRAS) $< -o $@
+       -$(SDCC) $(SDCCFLAGS) $(LINKFLAGS) -L $(LIBDIR) $(EXTRAS) $< -o $@
 
 %$(OBJEXT): %.c
-       $(SDCC) $(SDCCFLAGS) -c $< -o $@
+       -$(SDCC) $(SDCCFLAGS) -c $< -o $@
 
 $(PORT_CASES_DIR)/%$(OBJEXT): $(PORTS_DIR)/$(PORT)/%.c
-       $(SDCC) $(SDCCFLAGS) -c $< -o $@
+       -$(SDCC) $(SDCCFLAGS) -c $< -o $@
 
 .PRECIOUS: gen/pic16/testfwk.o gen/pic16/support.o
 
index d0c72a7b9ba1f1b0a537a0188f7d6c450f58fc9c..604bc22b5add6689abbafdbb5b3beaf5614a85f1 100644 (file)
@@ -29,14 +29,7 @@ void f1()
 
 /****************************/
 
-#ifndef SDCC_pic16
-// Ifdefed out for PIC16 port since it generates the error:
-// Duplicate label or redefinin g symbol that cannot be redefined. (_g)
-// Submitted to the bug tracker:
-// [ 1443651 ] pic 16: redefining symbol that cannot be redefined. (_g)
-
 void g (int (*h) (int));
-#endif
 
 void f2()
 {
@@ -47,14 +40,7 @@ void f2()
 
 /****************************/
 
-#ifndef SDCC_pic16
-// Ifdefed out for PIC16 port since it generates the error:
-// Duplicate label or redefinin g symbol that cannot be redefined. (_g)
-// Submitted to the bug tracker:
-// [ 1443651 ] pic 16: redefining symbol that cannot be redefined. (_g)
-
 void g (int (*h) (int));
-#endif
 
 void f3()
 {