#include <string.h>
-#ifdef WORDS_BIGENDIAN
- #define _ENDIAN(x) (3-x)
-#else
- #define _ENDIAN(x) (x)
-#endif
-
-#define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff)
extern symbol *interrupts[256];
void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptype, void *p);
extern unsigned long pFile_isize;
extern unsigned long pic16_countInstructions();
+set *pic16_localFunctions = NULL;
set *rel_idataSymSet=NULL;
set *fix_idataSymSet=NULL;
/*-----------------------------------------------------------------*/
/* aopLiteral - string from a literal value */
/*-----------------------------------------------------------------*/
-int pic16aopLiteral (value *val, int offset)
+unsigned int pic16aopLiteral (value *val, int offset)
{
union {
float f;
if (IS_AST_OP (expr) && expr->opval.op == '&') {
/* address of symbol */
if (IS_AST_SYM_VALUE (expr->left)) {
- val = copyValue (AST_VALUE (expr->left));
+ val = AST_VALUE (expr->left);
val->type = newLink (DECLARATOR);
if(SPEC_SCLS (expr->left->etype) == S_CODE) {
DCL_TYPE (val->type) = CPOINTER;
switch (size) {
case 1:
pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
- break;
+ break;
case 2:
pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
pic16_emitDB(BYTE_IN_LONG(ival, 1), ptype, p);
- break;
+ break;
case 4: /* EEP: why is this db and not dw? */
pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
pic16_emitDB(BYTE_IN_LONG(ival, 1), ptype, p);
pic16_emitDB(BYTE_IN_LONG(ival, 2), ptype, p);
pic16_emitDB(BYTE_IN_LONG(ival, 3), ptype, p);
- break;
+ break;
default:
/* VR - only 1,2,4 size long can be handled???? Why? */
fprintf(stderr, "%s:%d: unhandled case. Contact author.\n", __FILE__, __LINE__);
iloop = ilist->init.deep;
}
- for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
+ for (; (sflds && iloop); sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
// fprintf(stderr, "%s:%d sflds: %p\tiloop = %p\n", __FILE__, __LINE__, sflds, iloop);
if (IS_BITFIELD(sflds->type)) {
pic16_printIvalBitFields(&sflds, &iloop, ptype, p);
{
int i;
- for(i=0;i<pic16->cwInfo.confAddrEnd-pic16->cwInfo.confAddrStart;i++)
+ for(i=0;i<=(pic16->cwInfo.confAddrEnd-pic16->cwInfo.confAddrStart);i++)
if(pic16->cwInfo.crInfo[i].emit) //mask != -1)
fprintf (of, "\t__config 0x%x, 0x%hhx\n",
pic16->cwInfo.confAddrStart+i,
{
int i;
- for(i=0;i<pic16->idInfo.idAddrEnd-pic16->idInfo.idAddrStart;i++)
+ for(i=0;i<=(pic16->idInfo.idAddrEnd-pic16->idInfo.idAddrStart);i++)
if(pic16->idInfo.irInfo[i].emit)
fprintf (of, "\t__idlocs 0x%06x, 0x%hhx\n",
pic16->idInfo.idAddrStart+i,
{
initialComments (afile);
fprintf (afile, "; PIC16 port for the Microchip 16-bit core micros\n");
+ if(xinst)
+ fprintf (afile, "; * Extended Instruction Set\n");
+
if(pic16_mplab_comp)
- fprintf(afile, "; MPLAB/MPASM/MPASMWIN/MPLINK compatibility mode enabled\n");
+ fprintf(afile, "; * MPLAB/MPASM/MPASMWIN/MPLINK compatibility mode enabled\n");
fprintf (afile, iComments2);
if(options.debug) {
- fprintf (afile, "\n\t.ident \"SDCC version %s #%s [pic16 port]\"\n",
- SDCC_VERSION_STR, getBuildNumber() );
+ fprintf (afile, "\n\t.ident \"SDCC version %s #%s [pic16 port]%s\"\n",
+ SDCC_VERSION_STR, getBuildNumber(), (!xinst?"":" {extended}") );
}
}
+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 */
/*-----------------------------------------------------------------*/
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);
}
/*-----------------------------------------------------------------*/
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);
}
/*-----------------------------------------------------------------*/
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