From 5fc7f9939fbe5ce0483efa27c0e749f7991a1fcf Mon Sep 17 00:00:00 2001 From: vrokas Date: Sun, 4 Jul 2004 09:30:49 +0000 Subject: [PATCH] * src/SDCCmain.c (linkEdit): modifications only for pic16 port, add relFilesSet to $3, manipulate $2 to handle linking of object files without source files in command line, * device/include/pic16 (all headers): added ID location macros, * src/pic16/device.c (struct PIC16_device Pics16[]): added field entries for ID location bytes, * (pic16_assignIdByteValue): NEW, * src/pic16/device.h: new structures idRegInfo_t and idBytesInfo_t, added field dumpcalltree to pic16_options_t, * src/pic16/gen.c (genCmp): fixed bug case so a temporary register is used instead of pic16_Gstack_base_addr, check if (ifx) before emitting rFalseIfx label after check_carry label, * src/pic16/glue.c (PIC16_IS_IDLOC_ADDRESS, PIC16_IS_HWREG_ADDRESS, pic16_emitDIRegs), NEW * (pic16glue): dump .calltree file when option --calltree found, * src/pic16/main.c (OPTION _pic16_optionsTable): new option --calltree * (_pic16_genAssemblerPreamble): emit ID locations after configuration registers, * (pic16_linkCmd): modifications of the link command, * src/pic16/pcode.c (pic16_pciMOVFF): PCC_REGISTER replaces PCC_REGISTER2 * (pic16_pCodeInitRegisters): don't init stack registers, * (pic16_findPrevInstruction): fixed bug, * (pic16_getRegFromInstruction, pic16_getRegFromInstruction2): fixed bug with immediate registers, * (buildCallTree): traces stack push and pop, * (pct2): dump also stack usage for each function, * src/pic16/ralloc.c (dynrIdx): registers names start from 0x00 * (pic16_allocDirReg): various modifications, * (pic16_typeRegWithIdx): when searching pic16_dynProcessorRegs set fixed to 1, git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3374 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- device/include/pic16/pic18f1220.h | 11 + device/include/pic16/pic18f2220.h | 11 + device/include/pic16/pic18f242.h | 11 + device/include/pic16/pic18f248.h | 11 + device/include/pic16/pic18f252.h | 11 + device/include/pic16/pic18f258.h | 11 + device/include/pic16/pic18f442.h | 11 + device/include/pic16/pic18f448.h | 11 + device/include/pic16/pic18f452.h | 11 + device/include/pic16/pic18f458.h | 11 + device/include/pic16/pic18f6520.h | 11 + device/include/pic16/pic18f6620.h | 11 + device/include/pic16/pic18f6680.h | 11 + device/include/pic16/pic18f6720.h | 11 + device/include/pic16/pic18f8520.h | 11 + device/include/pic16/pic18f8620.h | 11 + device/include/pic16/pic18f8680.h | 11 + device/include/pic16/pic18f8720.h | 11 + device/lib/pic16/Makefile | 2 +- src/SDCCmain.c | 33 ++- src/pic16/device.c | 97 ++++++++- src/pic16/device.h | 18 +- src/pic16/gen.c | 92 ++++++-- src/pic16/glue.c | 88 ++++---- src/pic16/main.c | 24 +-- src/pic16/pcode.c | 81 +++++--- src/pic16/pcode.h | 2 + src/pic16/pcoderegs.c | 51 +++-- src/pic16/peeph.def | 334 ------------------------------ src/pic16/ralloc.c | 152 ++++++-------- 30 files changed, 608 insertions(+), 564 deletions(-) diff --git a/device/include/pic16/pic18f1220.h b/device/include/pic16/pic18f1220.h index 013a39b9..ee7f9238 100644 --- a/device/include/pic16/pic18f1220.h +++ b/device/include/pic16/pic18f1220.h @@ -784,4 +784,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f2220.h b/device/include/pic16/pic18f2220.h index d9a06f46..19b53091 100644 --- a/device/include/pic16/pic18f2220.h +++ b/device/include/pic16/pic18f2220.h @@ -976,4 +976,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f242.h b/device/include/pic16/pic18f242.h index bd94778e..6d60bfcf 100644 --- a/device/include/pic16/pic18f242.h +++ b/device/include/pic16/pic18f242.h @@ -888,4 +888,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f248.h b/device/include/pic16/pic18f248.h index 85a9d156..dc2cb4b2 100644 --- a/device/include/pic16/pic18f248.h +++ b/device/include/pic16/pic18f248.h @@ -2633,4 +2633,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f252.h b/device/include/pic16/pic18f252.h index d1815a8a..10279bd9 100644 --- a/device/include/pic16/pic18f252.h +++ b/device/include/pic16/pic18f252.h @@ -912,4 +912,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f258.h b/device/include/pic16/pic18f258.h index 7865def7..99edb0df 100644 --- a/device/include/pic16/pic18f258.h +++ b/device/include/pic16/pic18f258.h @@ -2657,4 +2657,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f442.h b/device/include/pic16/pic18f442.h index 124b9210..f05f522d 100644 --- a/device/include/pic16/pic18f442.h +++ b/device/include/pic16/pic18f442.h @@ -1017,4 +1017,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f448.h b/device/include/pic16/pic18f448.h index 78a38a47..9bdf5d52 100644 --- a/device/include/pic16/pic18f448.h +++ b/device/include/pic16/pic18f448.h @@ -2860,4 +2860,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f452.h b/device/include/pic16/pic18f452.h index c3dd631c..2ba20b7c 100644 --- a/device/include/pic16/pic18f452.h +++ b/device/include/pic16/pic18f452.h @@ -1041,4 +1041,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f458.h b/device/include/pic16/pic18f458.h index 9854327b..cdbea4c7 100644 --- a/device/include/pic16/pic18f458.h +++ b/device/include/pic16/pic18f458.h @@ -2884,4 +2884,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f6520.h b/device/include/pic16/pic18f6520.h index 245506c2..ed2e3ee2 100644 --- a/device/include/pic16/pic18f6520.h +++ b/device/include/pic16/pic18f6520.h @@ -1380,4 +1380,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f6620.h b/device/include/pic16/pic18f6620.h index 0f19ba58..b99135d6 100644 --- a/device/include/pic16/pic18f6620.h +++ b/device/include/pic16/pic18f6620.h @@ -1357,4 +1357,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f6680.h b/device/include/pic16/pic18f6680.h index 6ab0524f..810f5a79 100644 --- a/device/include/pic16/pic18f6680.h +++ b/device/include/pic16/pic18f6680.h @@ -1867,4 +1867,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f6720.h b/device/include/pic16/pic18f6720.h index 7005aa57..531f8f0e 100644 --- a/device/include/pic16/pic18f6720.h +++ b/device/include/pic16/pic18f6720.h @@ -1405,4 +1405,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f8520.h b/device/include/pic16/pic18f8520.h index 6e60b4c1..23612ea6 100644 --- a/device/include/pic16/pic18f8520.h +++ b/device/include/pic16/pic18f8520.h @@ -1482,4 +1482,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f8620.h b/device/include/pic16/pic18f8620.h index 6892b636..73424e7e 100644 --- a/device/include/pic16/pic18f8620.h +++ b/device/include/pic16/pic18f8620.h @@ -1480,4 +1480,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f8680.h b/device/include/pic16/pic18f8680.h index 1c616a10..f4b055eb 100644 --- a/device/include/pic16/pic18f8680.h +++ b/device/include/pic16/pic18f8680.h @@ -1990,4 +1990,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/include/pic16/pic18f8720.h b/device/include/pic16/pic18f8720.h index 66d7e243..6555ff1f 100644 --- a/device/include/pic16/pic18f8720.h +++ b/device/include/pic16/pic18f8720.h @@ -1528,4 +1528,15 @@ extern sfr at 0xfff TOSU; #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 diff --git a/device/lib/pic16/Makefile b/device/lib/pic16/Makefile index ee9e3f52..88c57051 100644 --- a/device/lib/pic16/Makefile +++ b/device/lib/pic16/Makefile @@ -29,7 +29,7 @@ build-all-libraries: clean: all-clean - -$(RM) -f bin/* + $(RM) -f bin/*.* diff --git a/src/SDCCmain.c b/src/SDCCmain.c index b37a9bf0..7427f555 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -1620,18 +1620,36 @@ linkEdit (char **envp) 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); } @@ -2055,6 +2073,7 @@ static void doPrintSearchDirs(void) printf("libdir:\n"); fputStrSet(stdout, libDirsSet); + fputStrSet(stdout, libPathsSet); } diff --git a/src/pic16/device.c b/src/pic16/device.c index 38e1ab6b..1126b69b 100644 --- a/src/pic16/device.c +++ b/src/pic16/device.c @@ -76,6 +76,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -94,6 +98,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -112,6 +120,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -130,6 +142,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -148,6 +164,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -166,6 +186,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -184,6 +208,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -202,6 +230,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -220,6 +252,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -238,6 +274,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -256,6 +296,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -274,6 +318,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -292,6 +340,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -310,6 +362,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -328,6 +384,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -346,6 +406,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -364,6 +428,10 @@ static PIC16_device Pics16[] = { { -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 } } } }, { @@ -382,6 +450,10 @@ static PIC16_device Pics16[] = { { -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 } } } } @@ -811,6 +883,8 @@ int checkAddReg(set **set, regs *reg) { regs *tmp; + + if(!reg)return 0; #if DEBUG_CHECK fprintf(stderr, "%s: about to insert REGister: %s ... ", __FUNCTION__, reg->name); #endif @@ -837,6 +911,7 @@ int checkAddSym(set **set, symbol *sym) { symbol *tmp; + if(!sym)return 0; #if DEBUG_CHECK fprintf(stderr, "%s: about to add SYMbol: %s ... ", __FUNCTION__, sym->name); #endif @@ -873,10 +948,13 @@ void pic16_groupRegistersInSection(set *regset) 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 */ @@ -947,3 +1025,14 @@ void pic16_assignConfigWordValue(int address, int value) } } +void pic16_assignIdByteValue(int address, char value) +{ + int i; + + for(i=0;iidInfo.idAddrEnd-pic16->idInfo.idAddrStart+1;i++) { + if(address == pic16->idInfo.idAddrStart+i) { + pic16->idInfo.irInfo[i].value = value; + pic16->idInfo.irInfo[i].emit = 1; + } + } +} diff --git a/src/pic16/device.h b/src/pic16/device.h index 54848d3f..8c387a82 100644 --- a/src/pic16/device.h +++ b/src/pic16/device.h @@ -37,6 +37,7 @@ #endif #define CONFIGURATION_WORDS 20 +#define IDLOCATION_BYTES 20 typedef struct { int sfrLoAddr; @@ -56,6 +57,17 @@ typedef struct { 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 */ @@ -68,6 +80,7 @@ typedef struct PIC16_device { 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 */ @@ -86,6 +99,7 @@ typedef struct { int stack_model; int ivt_loc; int nodefaultlibs; + int dumpcalltree; } pic16_options_t; #define STACK_MODEL_SMALL (pic16_options.stack_model == 0) @@ -99,11 +113,13 @@ extern PIC16_device *pic16; /****************************************/ 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); diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 4e60d1eb..464bab94 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -360,8 +360,10 @@ static regs *getFreePtr (iCode *ic, asmop **aopp, bool result) 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 */ @@ -540,13 +542,16 @@ static asmop *aopForSym (iCode *ic, operand *op, bool result) /* 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 */ @@ -555,9 +560,26 @@ static asmop *aopForSym (iCode *ic, operand *op, bool result) 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 */ @@ -588,6 +610,7 @@ static asmop *aopForSym (iCode *ic, operand *op, bool result) } #endif +#if 0 if (sym->onStack && options.stack10bit) { /* It's on the 10 bit stack, which is located in @@ -618,7 +641,7 @@ static asmop *aopForSym (iCode *ic, operand *op, bool result) aop->size = getSize(sym->type); return aop; } - +#endif //DEBUGpic16_emitcode(";","%d",__LINE__); /* if in bit space */ if (IN_BITSPACE(space)) { @@ -1247,8 +1270,13 @@ char *pic16_aopGet (asmop *aop, int offset, bool bit16, bool dname) 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); @@ -1283,7 +1311,7 @@ pCodeOp *pic16_popGetTempReg(void) } /*-----------------------------------------------------------------*/ -/* pic16_popGetTempReg - create a new temporary pCodeOp */ +/* pic16_popReleaseTempReg - create a new temporary pCodeOp */ /*-----------------------------------------------------------------*/ void pic16_popReleaseTempReg(pCodeOp *pcop) { @@ -1423,6 +1451,7 @@ static pCodeOp *pic16_popRegFromIdx(int rIdx) 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; @@ -1563,6 +1592,7 @@ pCodeOp *pic16_popGet (asmop *aop, int offset) //, bool bit16, bool dname) 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; @@ -3296,12 +3326,21 @@ static void genFunction (iCode *ic) 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; + } } } } @@ -3337,9 +3376,13 @@ static void genFunction (iCode *ic) 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) ); @@ -3348,6 +3391,14 @@ static void genFunction (iCode *ic) // &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; + } + } } } @@ -5084,12 +5135,16 @@ static void genCmp (operand *left,operand *right, 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 */ @@ -5148,7 +5203,8 @@ check_carry: 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 { diff --git a/src/pic16/glue.c b/src/pic16/glue.c index b0c21d45..d92db723 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -140,10 +140,6 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag) 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); @@ -189,16 +185,17 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag) #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); } } @@ -294,10 +291,12 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag) 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); @@ -1117,10 +1116,21 @@ void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptyp 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 */ /*-----------------------------------------------------------------*/ @@ -1155,6 +1165,13 @@ CODESPACE: %d\tCONST: %d\tPTRCONST: %d\tSPEC_CONST: %d\n", __FUNCTION__, 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); @@ -1291,6 +1308,17 @@ void pic16_emitConfigRegs(FILE *of) pic16->cwInfo.crInfo[i].value); } +void pic16_emitIDRegs(FILE *of) +{ + int i; + + for(i=0;iidInfo.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 () @@ -1433,6 +1461,7 @@ pic16emitOverlay (FILE * afile) 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); } @@ -1576,8 +1605,8 @@ pic16glue () pic16emitOverlay(ovrFile); pic16_AnalyzepCode('*'); -#if 0 - { +#if 1 + if(pic16_options.dumpcalltree) { FILE *cFile; sprintf(buffer, dstFileName); strcat(buffer, ".calltree"); @@ -1609,18 +1638,18 @@ pic16glue () /* 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); @@ -1631,42 +1660,11 @@ pic16glue () 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 */ diff --git a/src/pic16/main.c b/src/pic16/main.c index 36b8ef06..2cdd52ba 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -92,7 +92,7 @@ void pic16_emitDebuggerSymbol (char *); 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); @@ -112,6 +112,7 @@ _pic16_init (void) 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 @@ -289,6 +290,7 @@ OPTION pic16_optionsTable[]= { { 0, "--denable-peeps", &pic16_enable_peeps, "explicit enable of peepholes"}, { 0, IVT_LOC, NULL, " interrupt vector table location"}, + { 0, "--calltree", &pic16_options.dumpcalltree, "dump call tree in .calltree file"}, { 0, NULL, NULL, NULL} }; @@ -493,6 +495,7 @@ _pic16_setDefaultOptions (void) 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 * @@ -528,19 +531,8 @@ _pic16_genAssemblerPreamble (FILE * of) 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"); @@ -671,7 +663,7 @@ oclsExpense (struct memmap *oclass) 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... @@ -679,7 +671,7 @@ oclsExpense (struct memmap *oclass) */ const char *pic16_linkCmd[] = { - "gplink", "$3", "\"$1.o\"", "-o \"$2\"", "$l", NULL + "gplink", "$l", "-o \"$2\"", "\"$1\"","$3", NULL }; diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index cb56ead6..89491149 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -1519,7 +1519,7 @@ pCodeInstruction pic16_pciMOVFF = { // mdubuc - New 0, // second literal operand POC_NOP, PCC_REGISTER, // inCond - PCC_REGISTER2, // outCond + PCC_REGISTER, // outCond PCI_MAGIC }; @@ -2804,7 +2804,7 @@ void pic16_pCodeInitRegisters(void) 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); @@ -3506,8 +3506,9 @@ pCode *pic16_newpCodeFunction(char *mod,char *f) } else pcf->fname = NULL; - return ( (pCode *)pcf); + pcf->stackusage = 0; + return ( (pCode *)pcf); } /*-----------------------------------------------------------------*/ @@ -3857,11 +3858,10 @@ pCodeOp *pic16_newpCodeOpImmd(char *name, int offset, int index, int code_space) 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); @@ -3970,8 +3970,8 @@ pCodeOp *pic16_newpCodeOpBit(char *s, int bit, int inBitSpace, PIC_OPTYPE subt) 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; } @@ -5260,7 +5260,6 @@ pCode * pic16_findPrevInstruction(pCode *pci) pCode *pc = pci; while(pc) { - pc = pc->prev; if((pc->type == PC_OPCODE) || (pc->type == PC_WILD) @@ -5273,6 +5272,7 @@ pCode * pic16_findPrevInstruction(pCode *pci) fprintf(stderr,"pic16_findPrevInstruction: "); printpCode(stderr, pc); #endif + pc = pc->prev; } //fprintf(stderr,"Couldn't find instruction\n"); @@ -5369,9 +5369,13 @@ regs * pic16_getRegFromInstruction(pCode *pc) 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; @@ -5436,16 +5440,20 @@ regs * pic16_getRegFromInstruction2(pCode *pc) 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; @@ -5689,7 +5697,6 @@ static void dumpCond(int cond) static char *pcc_str[] = { //"PCC_NONE", "PCC_REGISTER", - "PCC_REGISTER2", "PCC_C", "PCC_Z", "PCC_DC", @@ -6008,7 +6015,7 @@ static void insertBankSwitch(int position, pCode *pc) 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); @@ -6801,7 +6808,8 @@ static void buildCallTree(void ) pBranch *pbr; pBlock *pb; pCode *pc; - + regs *r; + if(!the_pFile) return; @@ -6836,6 +6844,19 @@ static void buildCallTree(void ) 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) { @@ -7048,6 +7069,8 @@ static void pBlockStats(FILE *of, pBlock *pb) r = setNextItem(pb->tregisters); } } + + fprintf(of, "; uses %d bytes of stack\n", 1+ elementsInSet(pb->tregisters)); } /*-----------------------------------------------------------------*/ @@ -7184,7 +7207,7 @@ static set *register_usage(pBlock *pb) /* 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; @@ -7193,8 +7216,10 @@ static void pct2(FILE *of,pBlock *pb,int indent) if(!of) return; - if(indent > 10) + if(indent > 10) { + fprintf(of, "recursive function\n"); return; //recursion ? + } pc = setFirstItem(pb->function_entries); @@ -7204,12 +7229,13 @@ static void pct2(FILE *of,pBlock *pb,int indent) pb->visited = 0; for(i=0;itype == 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); @@ -7220,7 +7246,7 @@ static void pct2(FILE *of,pBlock *pb,int indent) 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__); @@ -7252,7 +7278,6 @@ void pic16_printCallTree(FILE *of) pBlockStats(of,pb); - fprintf(of,"Call Tree\n"); pbr = the_pFile->functions; while(pbr) { @@ -7277,8 +7302,8 @@ void pic16_printCallTree(FILE *of) 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) { diff --git a/src/pic16/pcode.h b/src/pic16/pcode.h index ded8c887..950251b1 100644 --- a/src/pic16/pcode.h +++ b/src/pic16/pcode.h @@ -675,6 +675,8 @@ typedef struct pCodeFunction int absblock; /* hack to emulate a block pCodes in absolute position but not inside a function */ + int stackusage; /* stack positions used in function */ + } pCodeFunction; diff --git a/src/pic16/pcoderegs.c b/src/pic16/pcoderegs.c index 2c66a552..ba0098a9 100644 --- a/src/pic16/pcoderegs.c +++ b/src/pic16/pcoderegs.c @@ -168,16 +168,16 @@ static void pCodeRegMapLiveRangesInFlow(pCodeFlow *pcfl) 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) @@ -193,18 +193,18 @@ static void pCodeRegMapLiveRangesInFlow(pCodeFlow *pcfl) 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 @@ -318,8 +318,11 @@ static void RemoveRegsFromSet(set *regset) 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 { @@ -329,11 +332,10 @@ static void RemoveRegsFromSet(set *regset) 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); @@ -355,7 +357,10 @@ static void RemoveRegsFromSet(set *regset) 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); @@ -400,6 +405,12 @@ static void Remove2pcodes(pCode *pcflow, pCode *pc1, pCode *pc2, regs *reg, int 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); @@ -733,7 +744,7 @@ static void OptimizeRegUsage(set *fregs, int optimize_multi_uses, int optimize_l 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) { @@ -835,14 +846,14 @@ void pic16_pCodeRegOptimizeRegUsage(int level) 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 } diff --git a/src/pic16/peeph.def b/src/pic16/peeph.def index 6189beb9..e69de29b 100644 --- a/src/pic16/peeph.def +++ b/src/pic16/peeph.def @@ -1,334 +0,0 @@ -// 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 -//} diff --git a/src/pic16/ralloc.c b/src/pic16/ralloc.c index 5e94acc5..991d78f1 100644 --- a/src/pic16/ralloc.c +++ b/src/pic16/ralloc.c @@ -37,6 +37,9 @@ #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 */ @@ -86,7 +89,7 @@ set *pic16_int_regs=NULL; /* internal registers placed in access bank 0 to 0x7f 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); @@ -505,7 +508,7 @@ allocReg (short type) 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); @@ -513,6 +516,7 @@ allocReg (short type) 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) { @@ -649,68 +653,60 @@ pic16_allocDirReg (operand *op ) * 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)) ) { @@ -797,7 +793,7 @@ regs *pic16_typeRegWithIdx (int idx, int type, int fixed) } 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; } @@ -826,8 +822,10 @@ pic16_regWithIdx (int idx) 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; } @@ -2140,7 +2138,7 @@ serialRegAssign (eBBlock ** ebbs, int count) /* 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); @@ -2710,36 +2708,6 @@ packRegsForAssign (iCode * ic, eBBlock * ebp) // 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))) { @@ -2884,10 +2852,12 @@ packRegsForAssign (iCode * ic, eBBlock * ebp) 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 @@ -2988,9 +2958,11 @@ findAssignToSym (operand * op, iCode * ic) 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 && -- 2.30.2