#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
#define _EBTRB_ON_6H 0xBF /* Enabled */
+/* Device ID locations */
+#define __IDLOC0 0x200000
+#define __IDLOC1 0x200001
+#define __IDLOC2 0x200002
+#define __IDLOC3 0x200003
+#define __IDLOC4 0x200004
+#define __IDLOC5 0x200005
+#define __IDLOC6 0x200006
+#define __IDLOC7 0x200007
+
+
#endif
clean: all-clean
- -$(RM) -f bin/*
+ $(RM) -f bin/*.*
if (port->linker.cmd)
{
char buffer2[PATH_MAX];
- set *libSet=NULL;
+ char buffer3[PATH_MAX];
+ set *tempSet=NULL, *libSet=NULL;
+ strcpy(buffer3, dstFileName);
if(TARGET_IS_PIC16) {
- /* use $3 to set the linker include directories */
- libSet = appendStrSet(libDirsSet, "-I\"", "\"");
-
- /* now add the libraries from command line */
+
+ /* use $l to set the linker include directories */
+ tempSet = appendStrSet(libDirsSet, "-I\"", "\"");
+ mergeSets(&linkOptionsSet, tempSet);
+
+ tempSet = appendStrSet(libPathsSet, "-I\"", "\"");
+ mergeSets(&linkOptionsSet, tempSet);
+
+ /* use $3 for libraries from command line --> libSet */
mergeSets(&libSet, libFilesSet);
+
+ tempSet = appendStrSet(relFilesSet, "", "");
+ mergeSets(&libSet, tempSet);
+// libSet = reverseSet(libSet);
+
+ if(fullSrcFileName) {
+// strcpy(buffer3, strrchr(fullSrcFileName, DIR_SEPARATOR_CHAR)+1);
+ /* if it didn't work, revert to old behaviour */
+ if(!strlen(buffer3))strcpy(buffer3, dstFileName);
+ strcat(buffer3, port->linker.rel_ext);
+
+ } else strcpy(buffer3, "");
}
- buildCmdLine (buffer2, port->linker.cmd, dstFileName, scratchFileName, (libSet?joinStrSet(libSet):NULL), linkOptionsSet);
- if(libSet)deleteSet(&libSet);
+ buildCmdLine (buffer2, port->linker.cmd, buffer3, scratchFileName, (libSet?joinStrSet(libSet):NULL), linkOptionsSet);
buildCmdLine2 (buffer, sizeof(buffer), buffer2);
}
printf("libdir:\n");
fputStrSet(stdout, libDirsSet);
+ fputStrSet(stdout, libPathsSet);
}
{ -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
},
{
{ -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ ,
{ 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ ,
{ 0x40, 0, 0xff } /* d */ }
+ },
+ { 0x200000, 0x200007,
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+ { 0, 0 }, { 0, 0 }, { 0, 0 } }
}
}
{
regs *tmp;
+
+ if(!reg)return 0;
#if DEBUG_CHECK
fprintf(stderr, "%s: about to insert REGister: %s ... ", __FUNCTION__, reg->name);
#endif
{
symbol *tmp;
+ if(!sym)return 0;
#if DEBUG_CHECK
fprintf(stderr, "%s: about to add SYMbol: %s ... ", __FUNCTION__, sym->name);
#endif
for(reg=setFirstItem(regset); reg; reg = setNextItem(regset)) {
-// fprintf(stderr, "%s:%d group registers in section, reg: %s\n", __FILE__, __LINE__, reg->name);
-
- if(reg->wasUsed
- && !(reg->regop && SPEC_EXTR(OP_SYM_ETYPE(reg->regop)))) {
+#if 0
+ fprintf(stderr, "%s:%d group registers in section, reg: %s (used: %d, %p)\n",
+ __FILE__, __LINE__, reg->name, reg->wasUsed, reg);
+#endif
+ if((reg->wasUsed
+ && !(reg->regop && SPEC_EXTR(OP_SYM_ETYPE(reg->regop))))
+ ) {
/* avoid grouping registers that have an initial value,
* they will be added later in idataSymSet */
}
}
+void pic16_assignIdByteValue(int address, char value)
+{
+ int i;
+
+ for(i=0;i<pic16->idInfo.idAddrEnd-pic16->idInfo.idAddrStart+1;i++) {
+ if(address == pic16->idInfo.idAddrStart+i) {
+ pic16->idInfo.irInfo[i].value = value;
+ pic16->idInfo.irInfo[i].emit = 1;
+ }
+ }
+}
#endif
#define CONFIGURATION_WORDS 20
+#define IDLOCATION_BYTES 20
typedef struct {
int sfrLoAddr;
configRegInfo_t crInfo[ CONFIGURATION_WORDS ];
} configWordsInfo_t;
+typedef struct {
+ unsigned char emit;
+ unsigned char value;
+} idRegInfo_t;
+
+typedef struct {
+ int idAddrStart; /* starting ID address */
+ int idAddrEnd; /* ending ID address */
+ idRegInfo_t irInfo[ IDLOCATION_BYTES ];
+} idBytesInfo_t;
+
#define PROCESSOR_NAMES 4
/* Processor unique attributes */
int extMIface; /* device has external memory interface */
sfrRangeInfo_t sfrRange; /* SFR range */
configWordsInfo_t cwInfo; /* configuration words info */
+ idBytesInfo_t idInfo; /* ID Locations info */
} PIC16_device;
/* Given a pointer to a register, this macro returns the bank that it is in */
int stack_model;
int ivt_loc;
int nodefaultlibs;
+ int dumpcalltree;
} pic16_options_t;
#define STACK_MODEL_SMALL (pic16_options.stack_model == 0)
/****************************************/
void pic16_assignConfigWordValue(int address, int value);
-int pic16_getConfigWord(int address);
+void pic16_assignIdByteValue(int address, char value);
int pic16_isREGinBank(regs *reg, int bank);
int pic16_REGallBanks(regs *reg);
void pic16_setMaxRAM(int size);
int PIC16_IS_CONFIG_ADDRESS(int address);
+int PIC16_IS_IDLOC_ADDRESS(int address);
+int PIC16_IS_HWREG_ADDRESS(int address);
int checkAddReg(set **set, regs *reg);
int checkAddSym(set **set, symbol *reg);
bool r0iu = FALSE , r1iu = FALSE;
bool r0ou = FALSE , r1ou = FALSE;
- //fprintf(stderr, "%s:%d: getting free ptr from ic = %c\n", __FUNCTION__, __LINE__, ic->op);
+ fprintf(stderr, "%s:%d: getting free ptr from ic = %c result: %d\n", __FUNCTION__, __LINE__, ic->op, result);
+ (*aopp)->type = AOP_STK;
+ return NULL;
/* the logic: if r0 & r1 used in the instruction
then we are in trouble otherwise */
/* if symbol was initially placed onStack then we must re-place it
* to direct memory, since pic16 does not have a specific stack */
if(sym->onStack) {
-// sym->onStack = 0;
+ fprintf(stderr, "%s:%d symbol %s on stack\n", __FILE__, __LINE__, OP_SYMBOL(op)->name);
+#if 0
+ sym->onStack = 0;
SPEC_OCLS( sym->etype ) = data;
space = data;
+#endif
}
-
-#if 1
+
+#if 0
/* assign depending on the storage class */
/* if it is on the stack or indirectly addressable */
/* space we need to assign either r0 or r1 to it */
DEBUGpic16_emitcode("; ***", "%s:%d sym->onStack:%d || sym->iaccess:%d",
__FUNCTION__, __LINE__, sym->onStack, sym->iaccess);
- sym->aop = aop = newAsmop(0);
- aop->aopu.aop_ptr = getFreePtr(ic,&aop,result);
+// sym->aop = aop = newAsmop(0);
+// aop->aopu.aop_ptr = getFreePtr(ic,&aop,result);
+// aop->size = getSize(sym->type);
+
+ fprintf(stderr, "%s:%d\t%s\n", __FILE__, __LINE__, __FUNCTION__);
+
+ sym->aop = aop = newAsmop (AOP_REG);
+// aop->aopu.aop_dir = sym->name; //sym->rname ;
+ aop->aopu.aop_reg[0] = pic16_regWithIdx(IDX_PLUSW2); //pic16_pc_plusw2.r;
aop->size = getSize(sym->type);
+ DEBUGpic16_emitcode(";","%d sym->rname = %s, size = %d",__LINE__,sym->rname,aop->size);
+
+ /* initialise for stack access via frame pointer */
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(sym->stack));
+
+
+// if(IC_LEFT(ic))pic16_allocDirReg( IC_LEFT(ic) );
+// else if(IC_RIGHT(ic))pic16_allocDirReg(IC_RIGHT(ic));
+
+ return (aop);
/* now assign the address of the variable to
the pointer register */
}
#endif
+#if 0
if (sym->onStack && options.stack10bit)
{
/* It's on the 10 bit stack, which is located in
aop->size = getSize(sym->type);
return aop;
}
-
+#endif
//DEBUGpic16_emitcode(";","%d",__LINE__);
/* if in bit space */
if (IN_BITSPACE(space)) {
strcpy(rs,s);
return rs;
+ case AOP_STK:
+// pCodeOp *pcop = aop->aop
+ break;
+
}
+ fprintf(stderr, "%s:%d unsupported aop->type: %s\n", __FILE__, __LINE__, pic16_AopType(aop->type));
werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
"aopget got unsupported aop->type");
exit(0);
}
/*-----------------------------------------------------------------*/
-/* pic16_popGetTempReg - create a new temporary pCodeOp */
+/* pic16_popReleaseTempReg - create a new temporary pCodeOp */
/*-----------------------------------------------------------------*/
void pic16_popReleaseTempReg(pCodeOp *pcop)
{
pcop = Safe_calloc(1,sizeof(pCodeOpReg) );
PCOR(pcop)->rIdx = rIdx;
PCOR(pcop)->r = pic16_regWithIdx(rIdx);
+
PCOR(pcop)->r->isFree = 0;
PCOR(pcop)->r->wasUsed = 1;
DEBUGpic16_emitcode(";","%d\tAOP_REG", __LINE__);
pcop = Safe_calloc(1,sizeof(pCodeOpReg) );
+// pcop->type = PO_GPR_REGISTER;
PCOR(pcop)->rIdx = rIdx;
PCOR(pcop)->r = pic16_regWithIdx(rIdx);
PCOR(pcop)->r->wasUsed=1;
DEBUGpic16_emitcode("; **", "Saving used registers in stack");
for ( i = 0 ; i < sym->regsUsed->size ; i++) {
if (bitVectBitValue(sym->regsUsed,i)) {
-// fprintf(stderr, "%s:%d function %s uses register %s\n",
-// __FILE__, __LINE__, OP_SYMBOL(IC_LEFT(ic))->name,
-// pic16_regWithIdx(i)->name);
+#if 0
+ fprintf(stderr, "%s:%d function %s uses register %s\n",
+ __FILE__, __LINE__, OP_SYMBOL(IC_LEFT(ic))->name,
+ pic16_regWithIdx(i)->name);
+#endif
pic16_pushpCodeOp( pic16_popRegFromIdx(i) );
_G.nRegsSaved++;
+
+ if(!pic16_regWithIdx(i)->wasUsed) {
+ fprintf(stderr, "%s:%d register %s is used in function but was wasUsed = 0d\n",
+ __FILE__, __LINE__, pic16_regWithIdx(i)->name);
+
+ pic16_regWithIdx(i)->wasUsed = 1;
+ }
}
}
}
for ( i = 0 ; i < sym->regsUsed->size ; i++) {
if (bitVectBitValue(sym->regsUsed,i)) {
-// fprintf(stderr, "%s:%d function %s uses register %s\n",
-// __FILE__, __LINE__, OP_SYMBOL(IC_LEFT(ic))->name,
-// pic16_regWithIdx(i)->name);
+#if 0
+ fprintf(stderr, "%s:%d function %s uses register %s (wasUsed: %d, %p)\n",
+ __FILE__, __LINE__, OP_SYMBOL(IC_LEFT(ic))->name,
+ pic16_regWithIdx(i)->name,
+ pic16_regWithIdx(i)->wasUsed,
+ pic16_regWithIdx(i));
+#endif
pic16_pushpCodeOp( pic16_popRegFromIdx(i) );
// &pic16_pc_postdec1, 0));
_G.nRegsSaved++;
+
+ if(!pic16_regWithIdx(i)->wasUsed) {
+ fprintf(stderr, "%s:%d register %s is used in function but was wasUsed = 0d\n",
+ __FILE__, __LINE__, pic16_regWithIdx(i)->name);
+
+ pic16_regWithIdx(i)->wasUsed = 1;
+ }
+
}
}
}
if(sign) {
/* Sigh. thus sucks... */
if(size) {
+ pCodeOp *pctemp;
+
+ pctemp = pic16_popGetTempReg();
pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),size));
- pic16_emitpcode(POC_MOVWF, pic16_popRegFromIdx(pic16_Gstack_base_addr));
+ pic16_emitpcode(POC_MOVWF, pctemp); //pic16_pic16_popRegFromIdx(pic16_Gstack_base_addr));
pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
- pic16_emitpcode(POC_XORWF, pic16_popRegFromIdx(pic16_Gstack_base_addr));
+ pic16_emitpcode(POC_XORWF, pctemp); //pic16_popRegFromIdx(pic16_Gstack_base_addr));
pic16_emitpcode(POC_XORFW, pic16_popGet(AOP(right),size));
- pic16_emitpcode(POC_SUBFW, pic16_popRegFromIdx(pic16_Gstack_base_addr));
+ pic16_emitpcode(POC_SUBFW, pctemp); //pic16_popRegFromIdx(pic16_Gstack_base_addr));
+ pic16_popReleaseTempReg(pctemp);
} else {
/* Signed char comparison */
/* Special thanks to Nikolai Golovchenko for this snippet */
if ((AOP_TYPE(result) != AOP_CRY)
&& AOP_SIZE(result)) {
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
-// pic16_emitpLabel( rFalseIfx.lbl->key );
+
+ if(!ifx)pic16_emitpLabel( rFalseIfx.lbl->key );
pic16_outBitC(result);
} else {
fprintf(stderr, "\n");
#endif
-// if(PIC16_IS_CONFIG_ADDRESS(SPEC_ADDR(sym->etype)))
-// continue;
-
-
/* if extern then add to externs */
if (IS_EXTERN (sym->etype)) {
checkAddSym(&externs, sym);
#endif
reg = pic16_allocDirReg( operandFromSymbol( sym ));
-// addSet(&pic16_dynAllocRegs, reg);
{
sectSym *ssym;
int found=0;
+#if 1
for(ssym=setFirstItem(sectSyms); ssym; ssym=setNextItem(sectSyms)) {
if(!strcmp(ssym->name, reg->name))found=1;
}
-
+#endif
+
if(!found)checkAddReg(&pic16_rel_udata, reg);
}
}
sectSym *ssym;
int found=0;
+#if 1
for(ssym=setFirstItem(sectSyms); ssym; ssym=setNextItem(sectSyms)) {
if(!strcmp(ssym->name, reg->name))found=1;
}
-
+#endif
+
if(!found)
if(checkAddReg(&pic16_rel_udata, reg)) {
addSetHead(&publics, sym);
int PIC16_IS_CONFIG_ADDRESS(int address)
{
+ return ((address >= pic16->cwInfo.confAddrStart && address <= pic16->cwInfo.confAddrEnd));
+}
+
+int PIC16_IS_IDLOC_ADDRESS(int address)
+{
+ return ((address >= pic16->idInfo.idAddrStart && address <= pic16->idInfo.idAddrEnd));
+}
- return (address >= pic16->cwInfo.confAddrStart && address <= pic16->cwInfo.confAddrEnd);
+/* wrapper function for the above */
+int PIC16_IS_HWREG_ADDRESS(int address)
+{
+ return (PIC16_IS_CONFIG_ADDRESS(address) || PIC16_IS_IDLOC_ADDRESS(address));
}
+
/*-----------------------------------------------------------------*/
/* emitStaticSeg - emitcode for the static segment */
/*-----------------------------------------------------------------*/
continue;
}
+ if(SPEC_ABSA(sym->etype) && PIC16_IS_IDLOC_ADDRESS(SPEC_ADDR(sym->etype))) {
+ pic16_assignIdByteValue(SPEC_ADDR(sym->etype),
+ (char) floatFromVal(list2val(sym->ival)));
+
+ continue;
+ }
+
/* if it is "extern" then do nothing */
if (IS_EXTERN (sym->etype) && !SPEC_ABSA(sym->etype)) {
checkAddSym(&externs, sym);
pic16->cwInfo.crInfo[i].value);
}
+void pic16_emitIDRegs(FILE *of)
+{
+ int 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,
+ pic16->idInfo.irInfo[i].value);
+}
+
static void
pic16emitMaps ()
and addPublics allowed then add it to the public set */
if ((sym->_isparm && !IS_REGPARM (sym->etype))
&& !IS_STATIC (sym->etype)) {
+// fprintf(stderr, "%s:%d %s accessed\n", __FILE__, __LINE__, __FUNCTION__);
checkAddSym(&publics, sym);
// addSetHead (&publics, sym);
}
pic16emitOverlay(ovrFile);
pic16_AnalyzepCode('*');
-#if 0
- {
+#if 1
+ if(pic16_options.dumpcalltree) {
FILE *cFile;
sprintf(buffer, dstFileName);
strcat(buffer, ".calltree");
/* initial comments */
pic16initialComments (asmFile);
-
+
/* print module name */
fprintf(asmFile, "#FILE\t\"%s\"\n", fullSrcFileName);
-
+
/* Let the port generate any global directives, etc. */
if (port->genAssemblerPreamble) {
port->genAssemblerPreamble(asmFile);
}
-
+
/* print the extern variables to this module */
pic16_printExterns(asmFile);
-
+
/* print the global variables in this module */
pic16printPublics (asmFile);
fprintf (asmFile, "%s", iComments2);
copyFile (asmFile, sfr->oFile);
#endif
-
/* Put all variables into a cblock */
pic16_AnalyzeBanking();
pic16_writeUsedRegs(asmFile);
-#if 0
- /* create the overlay segments */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; overlayable items in internal ram \n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, ovrFile);
-#endif
-
-#if 0
-
- /* create the stack segment MOF */
- if (mainf && IFFUNC_HASBODY(mainf->type)) {
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; Stack segment in internal ram \n");
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, ";\t.area\tSSEG\t(DATA)\n"
- ";__start__stack:\n;\t.ds\t1\n\n");
- }
-#endif
-
-#if 0
- /* no indirect data in pic */
- /* create the idata segment */
- fprintf (asmFile, "%s", iComments2);
- fprintf (asmFile, "; indirectly addressable internal ram data\n");
- fprintf (asmFile, "%s", iComments2);
- copyFile (asmFile, idata->oFile);
-#endif
-
-
#if 0
/* no xdata in pic */
/* if external stack then reserve space of it */
extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
extern void pic16_emitConfigRegs(FILE *of);
-
+extern void pic16_emitIDRegs(FILE *of);
pic16_options.stack_model = 0; /* 0 for 'small', 1 for 'large' */
pic16_options.ivt_loc = 0x000000; /* default location of interrupt vectors */
pic16_options.nodefaultlibs = 0; /* link default libraries */
+ pic16_options.dumpcalltree = 0;
}
static void
{ 0, "--denable-peeps", &pic16_enable_peeps, "explicit enable of peepholes"},
{ 0, IVT_LOC, NULL, "<nnnn> interrupt vector table location"},
+ { 0, "--calltree", &pic16_options.dumpcalltree, "dump call tree in .calltree file"},
{ 0, NULL, NULL, NULL}
};
pic16_options.stack_model = 0; /* 0 for 'small', 1 for 'large' */
pic16_options.ivt_loc = 0x000000;
pic16_options.nodefaultlibs = 0;
+ pic16_options.dumpcalltree = 0;
}
static const char *
if(!pic16_options.omit_configw) {
pic16_emitConfigRegs(of);
-#if 0
- fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300001, pic16_getConfigWord(0x300001));
- fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300002, pic16_getConfigWord(0x300002));
- fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300003, pic16_getConfigWord(0x300003));
- fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300005, pic16_getConfigWord(0x300005));
- fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300006, pic16_getConfigWord(0x300006));
- fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300008, pic16_getConfigWord(0x300008));
- fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300009, pic16_getConfigWord(0x300009));
- fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000a, pic16_getConfigWord(0x30000a));
- fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000b, pic16_getConfigWord(0x30000b));
- fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000c, pic16_getConfigWord(0x30000c));
- fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000d, pic16_getConfigWord(0x30000d));
-#endif
+ fprintf(of, "\n");
+ pic16_emitIDRegs(of);
}
fprintf (of, "\tradix dec\n");
return 0;
}
-/** $1 is always the basename.
+/** $1 is the input object file (PIC16 specific) // >>always the basename<<.
$2 is always the output file.
$3 -L path and -l libraries
$l is the list of extra options that should be there somewhere...
*/
const char *pic16_linkCmd[] =
{
- "gplink", "$3", "\"$1.o\"", "-o \"$2\"", "$l", NULL
+ "gplink", "$l", "-o \"$2\"", "\"$1\"","$3", NULL
};
0, // second literal operand
POC_NOP,
PCC_REGISTER, // inCond
- PCC_REGISTER2, // outCond
+ PCC_REGISTER, // outCond
PCI_MAGIC
};
initialized = 1;
- pic16_initStack(0xfff, 8);
+// pic16_initStack(0xfff, 8);
pic16_init_pic(port->processor);
pic16_pc_status.r = pic16_allocProcessorRegister(IDX_STATUS,"STATUS", PO_STATUS, 0x80);
} else
pcf->fname = NULL;
- return ( (pCode *)pcf);
+ pcf->stackusage = 0;
+ return ( (pCode *)pcf);
}
/*-----------------------------------------------------------------*/
PCOI(pcop)->r = r;
if(r) {
-// fprintf(stderr, "%s:%d %s reg %s exists\n",__FILE__, __LINE__, __FUNCTION__, name);
+// fprintf(stderr, "%s:%d %s reg %s exists (r: %p)\n",__FILE__, __LINE__, __FUNCTION__, name, r);
PCOI(pcop)->rIdx = r->rIdx;
} else {
-// fprintf(stderr, "%s:%d %s reg %s doesn't exist\n",
-// __FILE__, __LINE__, __FUNCTION__, name);
+// fprintf(stderr, "%s:%d %s reg %s doesn't exist\n", __FILE__, __LINE__, __FUNCTION__, name);
PCOI(pcop)->rIdx = -1;
}
// fprintf(stderr,"%s %s %d\n",__FUNCTION__,name,offset);
PCORB(pcop)->subtype = subt;
/* pCodeOpBit is derived from pCodeOpReg. We need to init this too */
- PCOR(pcop)->r = NULL;
- PCOR(pcop)->rIdx = 0;
+ PCOR(pcop)->r = pic16_dirregWithName(s); //NULL;
+// PCOR(pcop)->rIdx = 0;
return pcop;
}
pCode *pc = pci;
while(pc) {
- pc = pc->prev;
if((pc->type == PC_OPCODE)
|| (pc->type == PC_WILD)
fprintf(stderr,"pic16_findPrevInstruction: ");
printpCode(stderr, pc);
#endif
+ pc = pc->prev;
}
//fprintf(stderr,"Couldn't find instruction\n");
return PCOR(PCI(pc)->pcop)->r;
case PO_IMMEDIATE:
+// return pic16_dirregWithName(PCOI(PCI(pc)->pcop)->r->name);
+
if(PCOI(PCI(pc)->pcop)->r)
return (PCOI(PCI(pc)->pcop)->r);
-
+ else
+ return NULL;
+
case PO_GPR_BIT:
return PCOR(PCI(pc)->pcop)->r;
return PCOR(PCOR2(PCI(pc)->pcop)->pcop2)->r;
case PO_IMMEDIATE:
-// break;
-#if 1
+#if 0
// if(PCOI(PCI(pc)->pcop)->r)
// return (PCOI(PCOR2(PCI(pc)->pcop)->pcop2)->r);
//fprintf(stderr, "pic16_getRegFromInstruction2 - immediate\n");
- return pic16_dirregWithName(PCOR(PCOR2(PCI(pc)->pcop)->pcop2)->r->name);
- //return NULL; // PCOR(PCI(pc)->pcop)->r;
+ return pic16_dirregWithName(PCOI(PCOR2(PCI(pc)->pcop)->pcop2)->r->name);
#endif
+ if(PCOI(PCOR2(PCI(pc)->pcop)->pcop2)->r)
+ return (PCOI(PCOR2(PCI(pc)->pcop)->pcop2)->r);
+ else
+ return NULL;
+
+
case PO_GPR_BIT:
break;
// return PCOR2(PCI(pc)->pcop)->r;
static char *pcc_str[] = {
//"PCC_NONE",
"PCC_REGISTER",
- "PCC_REGISTER2",
"PCC_C",
"PCC_Z",
"PCC_DC",
tlbl = newiTempLabel(NULL);
/* invert skip instruction */
- pcprev = pic16_findPrevInstruction(pc);
+ pcprev = pic16_findPrevInstruction(pc->prev);
ipci = PCI(pcprev)->inverted_op;
npci = pic16_newpCode(ipci, PCI(pcprev)->pcop);
pBranch *pbr;
pBlock *pb;
pCode *pc;
-
+ regs *r;
+
if(!the_pFile)
return;
for(pb = the_pFile->pbHead; pb; pb = pb->next) {
pCode *pc_fstart=NULL;
for(pc = pb->pcHead; pc; pc = pc->next) {
+
+ if(isPCI(pc) && pc_fstart) {
+ if(PCI(pc)->is2MemOp) {
+ r = pic16_getRegFromInstruction2(pc);
+ if(r && !strcmp(r->name, "POSTDEC1"))
+ PCF(pc_fstart)->stackusage++;
+ } else {
+ r = pic16_getRegFromInstruction(pc);
+ if(r && !strcmp(r->name, "PREINC1"))
+ PCF(pc_fstart)->stackusage--;
+ }
+ }
+
if(isPCF(pc)) {
if (PCF(pc)->fname) {
r = setNextItem(pb->tregisters);
}
}
+
+ fprintf(of, "; uses %d bytes of stack\n", 1+ elementsInSet(pb->tregisters));
}
/*-----------------------------------------------------------------*/
/* pct2 - writes the call tree to a file */
/* */
/*-----------------------------------------------------------------*/
-static void pct2(FILE *of,pBlock *pb,int indent)
+static void pct2(FILE *of,pBlock *pb,int indent,int usedstack)
{
pCode *pc,*pcn;
int i;
if(!of)
return;
- if(indent > 10)
+ if(indent > 10) {
+ fprintf(of, "recursive function\n");
return; //recursion ?
+ }
pc = setFirstItem(pb->function_entries);
pb->visited = 0;
for(i=0;i<indent;i++) // Indentation
- fputc(' ',of);
+ fputs("+ ", of);
+ fputs("+- ", of);
- if(pc->type == PC_FUNCTION)
- fprintf(of,"%s\n",PCF(pc)->fname);
- else
- return; // ???
+ if(pc->type == PC_FUNCTION) {
+ usedstack += PCF(pc)->stackusage;
+ fprintf(of,"%s (stack: %i)\n",PCF(pc)->fname, usedstack);
+ } else return; // ???
pc = setFirstItem(pb->function_calls);
pcn = findFunction(dest);
if(pcn)
- pct2(of,pcn->pb,indent+1);
+ pct2(of,pcn->pb,indent+1, usedstack); // + PCF(pcn)->stackusage);
} else
fprintf(of,"BUG? pCode isn't a POC_CALL %d\n",__LINE__);
pBlockStats(of,pb);
-
fprintf(of,"Call Tree\n");
pbr = the_pFile->functions;
while(pbr) {
fprintf(of,"\n**************\n\na better call tree\n");
for(pb = the_pFile->pbHead; pb; pb = pb->next) {
- if(pb->visited)
- pct2(of,pb,0);
+// if(pb->visited)
+ pct2(of,pb,0,0);
}
for(pb = the_pFile->pbHead; pb; pb = pb->next) {
int absblock; /* hack to emulate a block pCodes in absolute position
but not inside a function */
+ int stackusage; /* stack positions used in function */
+
} pCodeFunction;
reg = pic16_getRegFromInstruction(pc);
if(reg) {
-
#if 0
fprintf(stderr, "reg= %p\n", reg);
fprintf(stderr, "flow seq %d, inst seq %d %s ",PCODE(pcfl)->seq,pc->seq,reg->name);
- fprintf(stderr, "addr = 0x%03x, type = %d rIdx=0x%03x",
+ fprintf(stderr, "addr = 0x%03x, type = %d rIdx=0x%03x ",
reg->address,reg->type,reg->rIdx);
fprintf(stderr, "command = %s\n", PCI(pc)->mnemonic);
#endif
+// fprintf(stderr, "trying to get first operand from pCode reg= %s\n", reg->name);
addSetIfnotP(& (PCFL(pcfl)->registers), reg);
if((PCC_REGISTER | PCC_LITERAL) & PCI(pc)->inCond)
and set up the second operand too */
if(PCI(pc)->is2MemOp) {
reg = pic16_getRegFromInstruction2(pc);
-
-// fprintf(stderr, "trying to get second operand from pCode reg= %s\n", reg->name);
- addSetIfnotP(& (PCFL(pcfl)->registers), reg);
-
- if((PCC_REGISTER | PCC_LITERAL) & PCI(pc)->inCond)
- addSetIfnotP(& (reg->reglives.usedpFlows), pcfl);
-
- if(PCC_REGISTER & PCI(pc)->outCond)
- addSetIfnotP(& (reg->reglives.assignedpFlows), pcfl);
+ if(reg) {
+// fprintf(stderr, "trying to get second operand from pCode reg= %s\n", reg->name);
+ addSetIfnotP(& (PCFL(pcfl)->registers), reg);
+
+ if((PCC_REGISTER | PCC_LITERAL) & PCI(pc)->inCond)
+ addSetIfnotP(& (reg->reglives.usedpFlows), pcfl);
+
+ if((PCC_REGISTER | PCC_REGISTER2) & PCI(pc)->outCond)
+ addSetIfnotP(& (reg->reglives.assignedpFlows), pcfl);
- addSetIfnotP(& (reg->reglives.usedpCodes), pc);
-
+ addSetIfnotP(& (reg->reglives.usedpCodes), pc);
+ }
}
#endif
if(used <= 1) {
// fprintf(stderr," reg %s isfree=%d, wasused=%d\n",reg->name,reg->isFree,reg->wasUsed);
+
if(used == 0) {
-// fprintf(stderr,"%s:%d: getting rid of reg %s\n",__FILE__, __LINE__, reg->name);
+
+// fprintf(stderr,"%s:%d: getting rid of reg %s\n",__FILE__, __LINE__, reg->name);
+
reg->isFree = 1;
reg->wasUsed = 0;
} else {
pc = setFirstItem(reg->reglives.usedpCodes);
if(reg->type == REG_SFR) {
- fprintf(stderr, "not removing SFR reg %s even though used only once\n",reg->name);
+ fprintf(stderr, "not removing SFR reg %s even though used only once\n", reg->name);
continue;
}
-
if(isPCI(pc)) {
if(PCI(pc)->label) {
pCode *pcn = pic16_findNextInstruction(pc->next);
pc->print(stderr,pc);
fprintf(stderr,"reg %s, type =%d\n",r->name, r->type);
}
-// fprintf(stderr,"%s:%d: removing reg %s because it is used only once\n",__FILE__, __LINE__, reg->name);
+
+ fprintf(stderr,"%s:%d: removing reg %s because it is used only once\n",__FILE__, __LINE__, reg->name);
+
+
Remove1pcode(pc, reg);
/*
pic16_unlinkpCode(pc);
if(!reg)
return;
+#if 0
+ fprintf(stderr,"removing 2 instructions:\n");
+ pc1->print(stderr,pc1);
+ pc2->print(stderr,pc2);
+#endif
+
if(pc1)
Remove1pcode(pc1, reg);
if(used && !pcfl_used && pcfl_assigned) {
pCode *pc;
-// fprintf(stderr,"WARNING %s: reg %s assigned without being used\n",__FUNCTION__,reg->name);
+ fprintf(stderr,"WARNING %s: reg %s assigned without being used\n",__FUNCTION__,reg->name);
pc = setFirstItem(reg->reglives.usedpCodes);
while(pc) {
fprintf(stderr, "No registers saved on this pass\n");
-/*
+#if 0
fprintf(stderr,"dynamically allocated regs:\n");
dbg_regusage(pic16_dynAllocRegs);
fprintf(stderr,"stack regs:\n");
dbg_regusage(pic16_dynStackRegs);
fprintf(stderr,"direct regs:\n");
dbg_regusage(pic16_dynDirectRegs);
-*/
+#endif
}
-// PIC Port Peep rules
-//
-//
-// INTRODUCTION:
-//
-// The peep hole optimizer searchs the
-// the SDCC generated code for small snippets
-// that can be optimized. As a user, you have
-// control over this optimization process without
-// having to learn the SDCC source code. (However
-// you'll still need access to the source since
-// these rules are compiled into the source.)
-//
-// The way it works is you specify the target
-// snippet that you want replaced with a more
-// efficient snippet that you write. Wild card
-// variables allow the rules to be parameterized.
-//
-// In all of the SDCC ports, labels and operands
-// can be wild cards. However, in the PIC even the
-// instructions can be wild cards.
-//
-// EXAMPLE:
-//
-// Consider Peep Rule 1 as an example. This rule
-// replaces some code like:
-//
-// skpz ;i.e. btfss status,Z
-// goto lab1
-// clrw
-//lab1:
-//
-// with:
-//
-// skpnz ;i.e. btfsc status,Z
-// clrw
-//lab1
-//
-// However, the Rule has four wild cards.
-// The first allows the btfss instruction operator
-// be anything, not just the Z bit in status register.
-// The second wild card applies to a label.
-// The third wild card is for an instruction - any
-// single instruction can be substituted.
-// The fourth wild card is also an instruction. It's
-// just an instruction place holder associated with
-// a label (think of it as the PIC Port author's laziness
-// imposed upon the user).
-//
-//
-// CONDITIONS
-//
-// There are certain instances where a peep rule may not
-// be applicable. Consider this subtle example:
-//
-// movwf R0
-// movf R0,W
-//
-// It would seem that the second move is unnecessary. But
-// be careful! The movf instruction affects the 'Z' bit.
-// So if this sequence is followed by a btfsc status,Z, you
-// will have to leave the second move in.
-//
-// To get around this proble, the peep rule can be followed
-// by a conditon: "if NZ". Which is to say, apply the rule
-// if Z bit is not needed in the code that follows. The optimizer
-// is smart enough to look more than one instruction past the
-// target block...
-//
-// Special commands
-//
-//
-// _NOTBITSKIP_ %1 - Creates a wild card instruction that
-// will match all instructions except for
-// bit skip instructions (btfsc or btfss)
-// _BITSKIP_ %1 - Creates a wild card instruction that only
-// will match a bit skip instruction (btfsc
-// or btfss)
-// _INVERTBITSKIP_ %1 - For the wild card instruction %1, invert
-// the state of the bit skip. If %1 is not
-// a bit skip instruction, then there's an
-// error in the peep rule.
-//
-//
-//
-
-
-// Peep 1
-// Converts
-//
-// btfss reg1,bit
-// goto label
-// incf reg2,f
-//label
-//
-// Into:
-//
-// btfsc reg1,bit
-// incf reg2,f
-//label
-//
-// Notice that wild cards will allow any instruction
-// besides incf to be used in the above.
-//
-// Also, notice that this snippet is not valid if
-// it follows another skip
-
-
-replace restart {
- _NOTBITSKIP_ %1
- _BITSKIP_ %2
- goto %3
- %4
-%3: %5
-} by {
- ; peep 1 - test/jump to test/skip
- %1
- _INVERTBITSKIP_ %2
- %4
-%3: %5
-}
-
-replace restart {
- _NOTBITSKIP_ %1
- _BITSKIP_ %2
- goto %3
-%4: %5
-%3: %6
-} by {
- ; peep 1b - test/jump to test/skip
- %1
- _INVERTBITSKIP_ %2
-%4: %5
-%3: %6
-}
-
-
-//bogus test for pcode
-//replace restart {
-// movf %1,w ;comment at end
-//%4: movf %1,w
-// RETURN
-// clrf INDF0
-// movlw 0xa5
-// movf fsr0,w
-// incf indf0,f
-// %2
-//} by {
-// ; peep test remove redundant move
-//%4: movf %1,w ;another comment
-// %2
-//} if AYBABTU %3
-
-
-// peep 2
-replace restart {
- movwf %1
- movf %1,w
-} by {
- ; peep 2 - Removed redundant move
- movwf %1
-} if NZ
-
-// peep 3
-//replace restart {
-/ decf %1,f
-/// movf %1,w
-// btfss _STATUS,z
-// goto %2
-//} by {
-// ; peep 3 - decf/mov/skpz to decfsz
-// decfsz %1,f
-// goto %2
-//}
-
-
-replace restart {
- movf %1,w
- movf %1,w
-} by {
- ; peep 4 - Removed redundant move
- movf %1,w
-}
-
-
-replace restart {
- movlw %1
- movwf %2
- movlw %1
-} by {
- ; peep 5 - Removed redundant move
- movlw %1
- movwf %2
-}
-
-replace restart {
- movwf %1
- movwf %1
-} by {
- ; peep 6 - Removed redundant move
- movwf %1
-}
-
-replace restart {
- movlw 0
- iorwf %1,w
-} by {
- ; peep 7 - Removed redundant move
- movf %1,w
-}
-
-replace restart {
- movf %1,w
- movwf %2
- decf %2,f
-} by {
- ; peep 8 - Removed redundant move
- decf %1,w
- movwf %2
-}
-
-replace restart {
- movwf %1
- movf %2,w
- xorwf %1,w
-} by {
- ; peep 9a - Removed redundant move
- movwf %1
- xorwf %2,w
-}
-
-replace restart {
- movwf %1
- movf %2,w
- iorwf %1,w
-} by {
- ; peep 9b - Removed redundant move
- movwf %1
- iorwf %2,w
-}
-
-replace restart {
- movf %1,w
- movwf %2
- movf %2,w
-} by {
- ; peep 9c - Removed redundant move
- movf %1,w
- movwf %2
-}
-
-replace restart {
- movwf %1
- movf %1,w
- movwf %2
-} by {
- ; peep 9d - Removed redundant move
- movwf %1
- movwf %2
-} if NZ
-
-// From: Frieder Ferlemann
-
-replace restart {
- iorlw 0
-} by {
- ; peep 10a - Removed unnecessary iorlw
-} if NZ
-
-// From: Frieder Ferlemann
-
-replace restart {
- xorlw 0
-} by {
- ; peep 10b - Removed unnecessary xorlw
-} if NZ
-
-// From: Frieder Ferlemann
-
-replace restart {
- movf %1,w
- movwf %1
-} by {
- ; peep 11 - Removed redundant move
- movf %1,w
-}
-
-
-// From: Vangelis Rokas (vrokas AT otenet dot gr)
-// movff peeps are disabled for the moment
-// until support is added in the pcodepeeph.c
-
-//replace {
-// movf %1,w
-// movwf %2
-//} by {
-// ; peep 12 - Use movff to move source to dest
-// movff %1, %2
-//}
-
-//replace restart {
-// banksel %1
-// banksel %2
-//} by {
-// ; peep 13 - remove redudant banksel directive
-// banksel %2
-//}
-
-//replace restart {
-// movff %1,%2
-// movf %1,w
-//} by {
-// ; peep 14a - movff/movf is 6 bytes long, movfw/movwf is 4
-// movf %1,w
-// movwf %2
-//}
-
-//replace restart {
-// movff %1,%2
-// movff %1,%3
-//} by {
-// ; peep 14b - movff/movff is 8 bytes long movf/mowf/movwf is 6
-// movf %1,w
-// movwf %2
-// movwf %3
-//}
-
-//replace {
-// movff %1,%2
-//} by {
-// ; peep xxx - test peep to see if peep rules can handle movff
-// movf %1,w
-// movwf %2
-//}
#define STRCASECMP strcasecmp
#endif
+//#define USE_ONSTACK
+
+
/*-----------------------------------------------------------------*/
/* At this point we start getting processor specific although */
/* some routines are non-processor specific & can be reused when */
set *pic16_builtin_functions=NULL;
-static int dynrIdx=0x10; //0x20; // starting temporary register rIdx
+static int dynrIdx=0x00; //0x20; // starting temporary register rIdx
static int rDirectIdx=0;
int pic16_nRegs = 128; // = sizeof (regspic16) / sizeof (regs);
reg->isFree=0;
-// debugLog ("%s of type %s\n", __FUNCTION__, debugLogRegType (type));
+ debugLog ("%s of type %s for register rIdx: %d\n", __FUNCTION__, debugLogRegType (type), dynrIdx-1);
// fprintf(stderr,"%s:%d: %s\t%s addr= 0x%x\trIdx= 0x%02x isFree: %d\n",
// __FILE__, __LINE__, __FUNCTION__, reg->name, reg->address, reg->rIdx, reg->isFree);
if(reg) {
reg->accessBank = 1; /* this is a temporary register alloc in accessBank */
reg->isLocal = 1; /* this is a local frame register */
+// reg->wasUsed = 1;
}
if (currFunc) {
* a new one and put it in the hash table AND in the
* dynDirectRegNames set */
if(IN_CODESPACE( SPEC_OCLS( OP_SYM_ETYPE(op)))) {
-
-// if(pic16_debug_verbose)
-// fprintf(stderr, "%s:%d symbol %s in codespace\n", __FILE__, __LINE__,
-// OP_SYMBOL(op)->name);
-
debugLog("%s:%d sym: %s in codespace\n", __FUNCTION__, __LINE__, OP_SYMBOL(op)->name);
return NULL;
}
- if(1) { //!PIC16_IS_CONFIG_ADDRESS(address))
-// fprintf(stderr,"%s:allocating new reg %s\n",__FUNCTION__, name);
- /* this is an error, why added? -- VR */
-// if(SPEC_SCLS(OP_SYM_ETYPE(op)))regtype = REG_SFR;
+#ifndef USE_ONSTACK
+ if(OP_SYMBOL(op)->onStack) {
+ fprintf(stderr, "%s:%d onStack %s offset: %d\n", __FILE__, __LINE__,
+ OP_SYMBOL(op)->name, OP_SYMBOL(op)->stack);
+ OP_SYMBOL(op)->onStack = 0;
+ SPEC_OCLS(OP_SYM_ETYPE(op)) = data;
+ regtype = REG_GPR;
+ return (reg);
+#endif
+ }
- if(OP_SYMBOL(op)->onStack) {
- fprintf(stderr, "%s:%d onStack %s\n", __FILE__, __LINE__, OP_SYMBOL(op)->name);
-// OP_SYMBOL(op)->onStack = 0;
- SPEC_OCLS(OP_SYM_ETYPE(op)) = data;
- regtype = REG_GPR;
+ if(!IN_DIRSPACE( SPEC_OCLS( OP_SYM_ETYPE(op)))) {
+ if(pic16_debug_verbose)
+ {
+ fprintf(stderr, "dispace:%d farspace:%d codespace:%d regspace:%d stack:%d eeprom: %d\n",
+ IN_DIRSPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
+ IN_FARSPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
+ IN_CODESPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
+ IN_REGSP( SPEC_OCLS( OP_SYM_ETYPE(op))),
+ IN_STACK( OP_SYM_ETYPE(op)),
+ SPEC_OCLS(OP_SYM_ETYPE(op)) == eeprom);
+
+ fprintf(stderr, "%s:%d symbol %s NOT in dirspace\n", __FILE__, __LINE__,
+ OP_SYMBOL(op)->name);
}
+ }
- if(!IN_DIRSPACE( SPEC_OCLS( OP_SYM_ETYPE(op)))) { // patch 13
- if(pic16_debug_verbose) //
- { //
- fprintf(stderr, "dispace:%d farspace:%d codespace:%d regspace:%d stack:%d eeprom: %d\n",
- IN_DIRSPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
- IN_FARSPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
- IN_CODESPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
- IN_REGSP( SPEC_OCLS( OP_SYM_ETYPE(op))),
- IN_STACK( OP_SYM_ETYPE(op)),
- SPEC_OCLS(OP_SYM_ETYPE(op)) == eeprom);
-
- fprintf(stderr, "%s:%d symbol %s NOT in dirspace\n", __FILE__, __LINE__, //
- OP_SYMBOL(op)->name); //
- } //
- } // patch 13
-
- reg = newReg(regtype, PO_DIR, rDirectIdx++, name,getSize (OP_SYMBOL (op)->type),0, op);
- debugLog ("%d -- added %s to hash, size = %d\n", __LINE__, name,reg->size);
-
-
-// if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
-// fprintf(stderr, " ralloc.c at fixed address: %s - changing to REG_SFR\n",name);
-// reg->type = REG_SFR;
-// }
-
- if (IS_BITVAR (OP_SYM_ETYPE(op))) {
-// fprintf(stderr, "%s:%d adding %s in bit registers\n", __FILE__, __LINE__, reg->name);
- addSet(&pic16_dynDirectBitRegs, reg);
- reg->isBitField = 1;
- } else {
-// fprintf(stderr, "%s:%d adding %s in direct registers\n", __FILE__, __LINE__, reg->name);
-// addSet(&pic16_dynDirectRegs, reg);
- checkAddReg(&pic16_dynDirectRegs, reg);
- }
-
+ reg = newReg(regtype, PO_DIR, rDirectIdx++, name,getSize (OP_SYMBOL (op)->type),0, op);
+ debugLog ("%d -- added %s to hash, size = %d\n", __LINE__, name,reg->size);
+
+
+// if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
+// fprintf(stderr, " ralloc.c at fixed address: %s - changing to REG_SFR\n",name);
+// reg->type = REG_SFR;
+// }
+
+ if (IS_BITVAR (OP_SYM_ETYPE(op))) {
+// fprintf(stderr, "%s:%d adding %s in bit registers\n", __FILE__, __LINE__, reg->name);
+ addSet(&pic16_dynDirectBitRegs, reg);
+ reg->isBitField = 1;
} else {
- debugLog (" -- %s is declared at address 0x30000x\n",name);
-
- return NULL;
+// fprintf(stderr, "%s:%d adding %s in direct registers\n", __FILE__, __LINE__, reg->name);
+// addSet(&pic16_dynDirectRegs, reg);
+ checkAddReg(&pic16_dynDirectRegs, reg);
}
+
+ } else {
+// debugLog (" -- %s is declared at address 0x30000x\n",name);
+ return NULL;
}
if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
}
break;
case REG_SFR:
- if( (dReg = regWithIdx ( pic16_dynProcessorRegs, idx, fixed)) != NULL ) {
+ if( (dReg = regWithIdx ( pic16_dynProcessorRegs, idx, 1)) != NULL ) {
debugLog ("Found a Processor Register!\n");
return dReg;
}
if( (dReg = pic16_typeRegWithIdx(idx,REG_SFR,0)) != NULL)
return dReg;
+#if 0
if( (dReg = pic16_typeRegWithIdx(idx,REG_STK,0)) != NULL)
return dReg;
+#endif
return NULL;
}
/* else we assign registers to it */
_G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
- debugLog (" %d - \n", __LINE__);
+ debugLog (" %d - nRegs: %d\n", __LINE__, sym->nRegs);
if(debugF)
bitVectDebugOn(_G.regAssigned, debugF);
// fprintf(stderr, "%s:%d symbol = %s\n", __FILE__, __LINE__, OP_SYMBOL( IC_RESULT(ic))->name);
-#if 0
- /* if this is at an absolute address, then get the address. */
- if (SPEC_ABSA ( OP_SYM_ETYPE(IC_RESULT(ic))) ) {
- if(PIC16_IS_CONFIG_ADDRESS( SPEC_ADDR ( OP_SYM_ETYPE(IC_RESULT(ic))))) {
- debugLog (" %d - found config word declaration\n", __LINE__);
- if(IS_VALOP(IC_RIGHT(ic))) {
- debugLog (" setting config word to %x\n",
- (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
-
- fprintf(stderr, "%s:%d setting config word to %x\n", __FILE__, __LINE__,
- (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
-
- pic16_assignConfigWordValue( SPEC_ADDR ( OP_SYM_ETYPE(IC_RESULT(ic))),
- (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
- }
-
-
- debugLog(" %d\n", __LINE__);
-
- /* remove the assignment from the iCode chain. */
-
- remiCodeFromeBBlock (ebp, ic);
- bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
- hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
-
- return 1;
-
- }
- }
-#endif
debugLog(" %d - actuall processing\n", __LINE__ );
if (!IS_ITEMP (IC_RESULT (ic))) {
OP_SYMBOL (IC_RESULT (ic))->iaccess)
{
-#if 0
+#ifndef USE_ONSTACK
/* clear the onStack flag, the port doesn't support it yet! FIXME */
- if(OP_SYMBOL(IC_RESULT(ic))->onStack)
+ if(OP_SYMBOL(IC_RESULT(ic))->onStack) {
OP_SYMBOL(IC_RESULT(ic))->onStack = 0;
+ return 0;
+ }
#endif
OP_SYMBOL (IC_RIGHT (dic))->onStack)
{
-#if 0
- if(OP_SYMBOL(IC_RESULT(ic))->onStack)
+#if USE_ONSTACK
+ if(OP_SYMBOL(IC_RESULT(ic))->onStack) {
OP_SYMBOL(IC_RESULT(ic))->onStack = 0;
+ return NULL;
+ }
#endif
if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&