From: tecodev Date: Mon, 19 Jun 2006 20:36:23 +0000 (+0000) Subject: * src/pic/glue.h,src/pic16/glue.h: added prototypes X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=4464999cca73961d7fd19c9d60ff1305f6ae399e;p=fw%2Fsdcc * 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 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4243 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 71f9f688..6cd9a860 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-06-19 Raphael Neider + + * 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 * src/pic/glue.h: added pic14aopLiteral prototype diff --git a/src/pic/gen.c b/src/pic/gen.c index 931f82d3..bed1cb46 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -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))); diff --git a/src/pic/glue.c b/src/pic/glue.c index f8f4a24c..c5f491e1 100644 --- a/src/pic/glue.c +++ b/src/pic/glue.c @@ -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"); diff --git a/src/pic/glue.h b/src/pic/glue.h index b5b285df..88e54429 100644 --- a/src/pic/glue.h +++ b/src/pic/glue.h @@ -25,7 +25,12 @@ #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 diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 898f4730..7dda28ae 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -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)); diff --git a/src/pic16/glue.c b/src/pic16/glue.c index 107c2e94..c2085e8b 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -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 diff --git a/src/pic16/glue.h b/src/pic16/glue.h index 2fc4da55..3c8e0478 100644 --- a/src/pic16/glue.h +++ b/src/pic16/glue.h @@ -25,7 +25,12 @@ #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 diff --git a/support/regression/ports/pic16/spec.mk b/support/regression/ports/pic16/spec.mk index b1fdcb0e..a05d2e2c 100644 --- a/support/regression/ports/pic16/spec.mk +++ b/support/regression/ports/pic16/spec.mk @@ -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 diff --git a/support/regression/tests/bug-716242.c b/support/regression/tests/bug-716242.c index d0c72a7b..604bc22b 100644 --- a/support/regression/tests/bug-716242.c +++ b/support/regression/tests/bug-716242.c @@ -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() {