* .version: bumped version number to 2.4.5
authorvrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 1 Oct 2004 14:49:51 +0000 (14:49 +0000)
committervrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 1 Oct 2004 14:49:51 +0000 (14:49 +0000)
* support/Util/SDCCerr.h: added warning W_POSSBUG2.
* support/Util/SDCCerr.c (messages structure): added entry for
W_POSSBUG2
Large cumulative patch for pic16 port and libraries.
* device/include/pic16/sdcc-lib.h,
* device/include/asm/pic16/features.h: NEW,
* device/include/pic16/float.h: changes reentrant keyword with
_FS_REENTRANT, added prototype for __fsneq, included sdcc-lib.h
* device/lib/pic16/libsdcc/Makefile: added target directory gptr,
updated target build-libraries to include objects from gptr,
* device/lib/pic16/libsdcc/{char,int,long}/*.c: added macro
_IL_REENTRANT to all function headings, included sdcc-lib.h header,
* device/lib/pic16/libsdcc/float/*.c: added macro _FS_REENTRANT to
all function headings,
* src/SDCCmain.c: added global parameter userIncDirsSet,
* (parseCmdLine): when option -I is encountered add directory to
userIncDirsSet too,
* src/version.awk: added space between control and long,
* src/pic16/NOTES: added some notes for the port,
* src/pic16/gen.c: added prototype for mov2fp function,
* (fReturnpic16[]): properly named return value registers,
* (_G structure): added fields stackRegSet, fregsUsed, stack_lat,
* (aopForSym): added code to handle symbols with onStack flag set,
symbols onStack are allocated PTRSIZE bytes,
* (aopFreeAsmop): handles special case where asmops are stack objects,
* (aopGet, pic16_popGet): adde cod to handle new asmop AOP_STA,
* (pic16_popGetTempReg, pic16_popGetTempRegCond, pic16_popReleaseTempReg):
added argument lock to trace flaws in allocating temporary registers
when developing port,
* (pic16_popGetLit, pic16_popGetLit2): changed lit from unsigned to signed
* (pic16_popRegFromString): reenabled allocating a direct register
from string,
* (assignResultValue): various beautifications,
* fixed bug #1037717 (patch from R. Neider & D. Wrinkler) with mistaken
referenced function argument,
* (genIpush): reenabled to allow stacked arguments, handles only
ic->parmPush iCodes,
* (genCall, genPcall): major changes to allow for variable argument
functions, fixed a bug with falsely restoring stack pointer after
returning from call,
* (genFunction): pending code for critical function,
* (shiftR1Left2ResultSigned, shiftR1Left2Result, shiftL2Left2Result,
* (shiftR2Left2Result, shiftLLong) applied patch #1032155 from R.Neider,
* (genNearPointerGet): fixed bug with indirect reading, was always
reading from INDF0
* (genGenPointerGet, genGenPointerSet): rewrote to support generic
pointers,
* (genAddrOf): rewrote code to take address of a stacked function parameter
* (genCast): fixed casting to generic pointer type,
* src/pic16/gen.h: added AOP_STA,
* (struct asmop): added field stk,
* src/pic16/genarith.c (pic16_AopType): handle AOP_STA,
* (pic16_genPlusIncr): changed emitSKPNZ to emitSKPNZ,
* (pic16_genAddLit, pic16_genPlus): applied patch #1034042 by tecodev,
* (pic16_genMinus): fixed bug #1035119 with patch submitted by tecodev,
* src/pic16/genutils.c (pic16_genNot): removed symbol *tlbl,
* src/pic16/glue.c (pic16_printGPPointerType): fixed to support new
generic pointers,
* src/pic16/main.c (_pic16_initPaths): ignores default SDCC include
and library paths,
* (pic16_port structure): generic pointer size is set to 3,
* src/pic16/pcode.c (pic16_newpCodeOpLit): correctly print literal integer,
* (insertBankSwitch): cast to (char *) to prevent 64bit CPUs'
compiler warning,
* src/pic16/ralloc.c (allocReg): prevent allocating register when
operand is an iTemp,

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

57 files changed:
.version
ChangeLog
device/include/pic16/stdarg.h [new file with mode: 0644]
device/lib/pic16/Makefile
device/lib/pic16/libsdcc/Makefile
device/lib/pic16/libsdcc/char/divschar.c
device/lib/pic16/libsdcc/char/divuchar.c
device/lib/pic16/libsdcc/char/modschar.c
device/lib/pic16/libsdcc/char/moduchar.c
device/lib/pic16/libsdcc/float/fs2schar.c
device/lib/pic16/libsdcc/float/fs2sint.c
device/lib/pic16/libsdcc/float/fs2slong.c
device/lib/pic16/libsdcc/float/fs2uchar.c
device/lib/pic16/libsdcc/float/fs2uint.c
device/lib/pic16/libsdcc/float/fs2ulong.c
device/lib/pic16/libsdcc/float/fsadd.c
device/lib/pic16/libsdcc/float/fsdiv.c
device/lib/pic16/libsdcc/float/fseq.c
device/lib/pic16/libsdcc/float/fsgt.c
device/lib/pic16/libsdcc/float/fslt.c
device/lib/pic16/libsdcc/float/fsmul.c
device/lib/pic16/libsdcc/float/fsneq.c
device/lib/pic16/libsdcc/float/fssub.c
device/lib/pic16/libsdcc/float/schar2fs.c
device/lib/pic16/libsdcc/float/sint2fs.c
device/lib/pic16/libsdcc/float/slong2fs.c
device/lib/pic16/libsdcc/float/uchar2fs.c
device/lib/pic16/libsdcc/float/uint2fs.c
device/lib/pic16/libsdcc/float/ulong2fs.c
device/lib/pic16/libsdcc/int/divsint.c
device/lib/pic16/libsdcc/int/divuint.c
device/lib/pic16/libsdcc/int/modsint.c
device/lib/pic16/libsdcc/int/moduint.c
device/lib/pic16/libsdcc/int/mulint.c
device/lib/pic16/libsdcc/long/divslong.c
device/lib/pic16/libsdcc/long/divulong.c
device/lib/pic16/libsdcc/long/modslong.c
device/lib/pic16/libsdcc/long/modulong.c
device/lib/pic16/libsdcc/long/mullong.c
doc/sdccman.lyx
src/SDCCmain.c
src/SDCCsymt.c
src/pic16/NOTES
src/pic16/device.h
src/pic16/gen.c
src/pic16/gen.h
src/pic16/genarith.c
src/pic16/genutils.c
src/pic16/glue.c
src/pic16/main.c
src/pic16/pcode.c
src/pic16/pcodepeep.c
src/pic16/peeph.def
src/pic16/ralloc.c
src/version.awk
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index 79a614418f747a2c5e6c8a8a4c42d12e16b06607..59aa62c1fa4c234af19118ff8d8572c1d50437fd 100644 (file)
--- a/.version
+++ b/.version
@@ -1 +1 @@
-2.4.4
+2.4.5
index 758084440e30ebc562bf607c3f169ddc73d4aa93..ac46903f8289d4fe6b0472fac40a4365a41b01b9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,75 @@
+2004-10-01 Vangelis Rokas <vrokas AT otenet.gr>
+
+       * .version: bumped version number to 2.4.5
+       * support/Util/SDCCerr.h: added warning W_POSSBUG2.
+       * support/Util/SDCCerr.c (messages structure): added entry for
+       W_POSSBUG2
+       
+       Large cumulative patch for pic16 port and libraries.
+       * device/include/pic16/sdcc-lib.h,
+       * device/include/pic16/stdarg.h,
+       * device/include/asm/pic16/features.h: NEW,
+       * device/include/pic16/float.h: changes reentrant keyword with
+       _FS_REENTRANT, added prototype for __fsneq, included sdcc-lib.h
+       * device/lib/pic16/libsdcc/Makefile: added target directory gptr,
+       updated target build-libraries to include objects from gptr,
+       * device/lib/pic16/libsdcc/{char,int,long}/*.c: added macro
+       _IL_REENTRANT to all function headings, included sdcc-lib.h header,
+       * device/lib/pic16/libsdcc/float/*.c: added macro _FS_REENTRANT to
+       all function headings,
+       * src/SDCCmain.c: added global parameter userIncDirsSet,
+       * (parseCmdLine): when option -I is encountered add directory to
+       userIncDirsSet too,
+       * src/version.awk: added space between control and long,
+       * src/pic16/NOTES: added some notes for the port,
+       * src/pic16/gen.c: added prototype for mov2fp function,
+       * (fReturnpic16[]): properly named return value registers,
+       * (_G structure): added fields stackRegSet, fregsUsed, stack_lat,
+       * (aopForSym): added code to handle symbols with onStack flag set,
+       symbols onStack are allocated PTRSIZE bytes,
+       * (aopFreeAsmop): handles special case where asmops are stack objects,
+       * (aopGet, pic16_popGet): adde cod to handle new asmop AOP_STA,
+       * (pic16_popGetTempReg, pic16_popGetTempRegCond, pic16_popReleaseTempReg):
+       added argument lock to trace flaws in allocating temporary registers
+       when developing port,
+       * (pic16_popGetLit, pic16_popGetLit2): changed lit from unsigned to signed
+       * (pic16_popRegFromString): reenabled allocating a direct register
+       from string,
+       * (assignResultValue): various beautifications,
+       * fixed bug #1037717 (patch from R. Neider & D. Wrinkler) with mistaken
+       referenced function argument,
+       * (genIpush): reenabled to allow stacked arguments, handles only
+       ic->parmPush iCodes,
+       * (genCall, genPcall): major changes to allow for variable argument
+       functions, fixed a bug with falsely restoring stack pointer after
+       returning from call,
+       * (genFunction): pending code for critical function,
+       * (shiftR1Left2ResultSigned, shiftR1Left2Result, shiftL2Left2Result,
+       * (shiftR2Left2Result, shiftLLong) applied patch #1032155 from R.Neider,
+       * (genNearPointerGet): fixed bug with indirect reading, was always
+       reading from INDF0
+       * (genGenPointerGet, genGenPointerSet): rewrote to support generic
+       pointers,
+       * (genAddrOf): rewrote code to take address of a stacked function parameter
+       * (genCast): fixed casting to generic pointer type,
+       * src/pic16/gen.h: added AOP_STA,
+       * (struct asmop): added field stk,
+       * src/pic16/genarith.c (pic16_AopType): handle AOP_STA,
+       * (pic16_genPlusIncr): changed emitSKPNZ to emitSKPNZ,
+       * (pic16_genAddLit, pic16_genPlus): applied patch #1034042 by tecodev,
+       * (pic16_genMinus): fixed bug #1035119 with patch submitted by tecodev,
+       * src/pic16/genutils.c (pic16_genNot): removed symbol *tlbl,
+       * src/pic16/glue.c (pic16_printGPPointerType): fixed to support new
+       generic pointers,
+       * src/pic16/main.c (_pic16_initPaths): ignores default SDCC include
+       and library paths,
+       * (pic16_port structure): generic pointer size is set to 3,
+       * src/pic16/pcode.c (pic16_newpCodeOpLit): correctly print literal integer,
+       * (insertBankSwitch): cast to (char *) to prevent 64bit CPUs'
+       compiler warning,
+       * src/pic16/ralloc.c (allocReg): prevent allocating register when
+       operand is an iTemp,
+
 2004-09-24 Martin Helmling <mh AT octo-soft.de>
 
        * debugger/mcs51/cmd.c: set PC if a symbol at pc reg is set
diff --git a/device/include/pic16/stdarg.h b/device/include/pic16/stdarg.h
new file mode 100644 (file)
index 0000000..6e0f468
--- /dev/null
@@ -0,0 +1,13 @@
+/*-----------------------------------------------------------------------------------*/
+/* stdarg.h - ANSI macros for variable parameter list                               */
+/*-----------------------------------------------------------------------------------*/
+
+#ifndef __STDARG_H
+#define __STDARG_H 1
+
+typedef        unsigned char data * va_list ;
+#define va_arg(marker,type) *((data type * )(marker += sizeof(type)))
+#define        va_start(marker,first) { marker = (va_list) ((char data * )&first); }
+#define va_end(marker) marker = (va_list) 0;
+
+#endif
index 88c57051ad8c6aabdabb8c204dac8df8fb37e8dc..35ecb4dea23e78c4226e13665bbddf3e03f15708 100644 (file)
@@ -50,4 +50,3 @@ all-dep:
        for temp in $(DIRS) ; do \
                $(MAKE) -C $$temp dep ; \
        done
-       
\ No newline at end of file
index 8882141d1d6241a1575c9bec9f616efde9a82f98..bd6b60d36dceabed1acd0d996c65ea82670aaa71 100644 (file)
@@ -15,7 +15,8 @@
 DIRS   =       char \
                int \
                long \
-               float
+               float \
+               gptr
 
 
 LIB    = libsdcc.lib
@@ -28,7 +29,7 @@ build-libraries:
        for dir in $(DIRS) ; do  \
                $(MAKE) -C $$dir ; \
        done;
-       gplib -c $(LIB) char/*.o int/*.o long/*.o float/*.o
+       gplib -c $(LIB) char/*.o int/*.o long/*.o float/*.o gptr/*.o
        mv -v $(LIB) ../bin
        
 
index 4fe34f73a6e4f084d1216ef2e83e8dfd09dabbd7..57e0b7e10aa9247d8faaeaec12be012392a5fdba 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
 
 unsigned char _divuchar (unsigned char a, unsigned char b);
 
-char _divschar (char a, char b)
+char _divschar (char a, char b) _IL_REENTRANT
 {
   register char r;
   char ta, tb;
index 0b99c5d8aaa062fd975ed80534dea286d59842f3..6c99d1e803cd3e63a8627f082fe641342ac3a14b 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
 
 #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1)
 
-unsigned char _divuchar (unsigned char a, unsigned char b)
+unsigned char _divuchar (unsigned char a, unsigned char b) _IL_REENTRANT
 {
   unsigned char reste = 0;
   unsigned char count = 8;
index a61c036717c27928fbd717cd93cbdefe182b6014..116ecd1876fd6e1d40497b098ddb550a041404b0 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
+
 unsigned char _moduchar (unsigned char a, unsigned char b);
 
-char _modschar (char a, char b)
+char _modschar (char a, char b) _IL_REENTRANT
 {
   register char r;
   register char ta, tb;
index 70f162a2f0c84fbaa0beabe07ab3f79b26a23f93..c627ccc91c9b48da04bd06f807ca630c22f29ab6 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
 
 #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1) 
 
-unsigned char _moduchar (unsigned char a, unsigned char b)
+unsigned char _moduchar (unsigned char a, unsigned char b) _IL_REENTRANT
 {
   unsigned char count = 0;
     
index 17e5ea0d8bd7b6f7da234c2fdd781613272c56d8..a482b2d805613ec3794386d9bc1a75ff0b96ede4 100644 (file)
@@ -33,8 +33,7 @@
 #include <float.h>
 
 /* convert float to signed char */
-signed char __fs2schar (float f)
-// reentrant
+signed char __fs2schar (float f) _FS_REENTRANT
 {
   signed long sl=__fs2slong(f);
   if (sl>=CHAR_MAX)
index bcf7703076a98a58b741a6bfb92f39cceef03720..82265249d1462615fc8e0a65c971a91887955511 100644 (file)
@@ -34,8 +34,7 @@
 #include <float.h>
 
 /* convert float to signed int */
-signed int __fs2sint (float f)
-// reentrant
+signed int __fs2sint (float f) _FS_REENTRANT
 {
   signed long sl=__fs2slong(f);
   if (sl>=INT_MAX)
index dc57c2d7c0621c2cf103cecefd0ec167bdc20305..6f9d61dae0f8be5933782ea2364507aa5573043d 100644 (file)
@@ -32,8 +32,7 @@
 #include <float.h>
 
 /* convert float to signed long */
-signed long __fs2slong (float f)
-// reentrant
+signed long __fs2slong (float f) _FS_REENTRANT
 {
 
   if (!f)
index 3d422e1d03a38b75fd7be8235328b8b3e1674965..6d8d431e29e894be0f9f4026e8a8cd12d7ba8fbe 100644 (file)
@@ -32,8 +32,7 @@
 #include <float.h>
 
 /* convert float to unsigned char */
-unsigned char __fs2uchar (float f)
-// reentrant
+unsigned char __fs2uchar (float f) _FS_REENTRANT
 {
   unsigned long ul=__fs2ulong(f);
   if (ul>=UCHAR_MAX) return UCHAR_MAX;
index ac4742d11b8cb62d79de4a71a84d340bee6f18c9..0313c68d7c14a1cf6a2b4c04d6c2712f98515b2f 100644 (file)
@@ -34,8 +34,7 @@
 unsigned long __fs2ulong (float a1);
 
 /* convert float to unsigned int */
-unsigned int __fs2uint (float f)
-// reentrant
+unsigned int __fs2uint (float f) _FS_REENTRANT
 {
   unsigned long ul=__fs2ulong(f);
   if (ul>=UINT_MAX) return UINT_MAX;
index 8d290b18302a00d68bf4c46ceddbe045be9f4587..ccb200dd1ae9a4efea1796c78bc042734f3bf2bf 100644 (file)
@@ -29,8 +29,7 @@ union float_long
 };
 
 /* convert float to unsigned long */
-unsigned long __fs2ulong (float a1)
-// reentrant
+unsigned long __fs2ulong (float a1) _FS_REENTRANT
 {
   volatile union float_long fl1;
   volatile int exp;
index 3b07ce92d61bc0474ef3d2df845c0ea8471913d4..aaf9f60ecdc164905b2331bc8f420ebf83caaade 100644 (file)
@@ -27,8 +27,7 @@ union float_long
   };
 
 /* add two floats */
-float __fsadd (float a1, float a2)
-// reentrant
+float __fsadd (float a1, float a2) _FS_REENTRANT
 {
   volatile long mant1, mant2;
   volatile union float_long fl1, fl2;
index 7126216a228a6b278da154c642465e90ed89033c..e438a577dc11d4164ee4eaf297e945d5c2c8c8e2 100644 (file)
@@ -29,8 +29,7 @@ union float_long
   };
 
 /* divide two floats */
-float __fsdiv (float a1, float a2)
-// reentrant
+float __fsdiv (float a1, float a2) _FS_REENTRANT
 {
   volatile union float_long fl1, fl2;
   volatile long result;
index d8ba933301145cd4b34528557c2c747e383c24f8..4446fc594de9f04cb7cadc85d8e7023165d3fe62 100644 (file)
@@ -29,8 +29,7 @@ union float_long
   };
 
 /* compare two floats */
-char __fseq (float a1, float a2)
-// reentrant
+char __fseq (float a1, float a2) _FS_REENTRANT
 {
   volatile union float_long fl1, fl2;
 
index 574898c271a4315699110b37291802705fb7d15c..04dcdde50f0a460ea14d161fd9cc8d8ca57f68c0 100644 (file)
@@ -29,8 +29,7 @@ union float_long
   };
 
 /* compare two floats */
-char __fsgt (float a1, float a2)
-//reentrant
+char __fsgt (float a1, float a2) _FS_REENTRANT
 {
   volatile union float_long fl1, fl2;
 
index 45eadf8aaadd816db7abb11078ce05714dd01cde..4cf5c087904a8955538608e3c25c153d33957969 100644 (file)
@@ -29,8 +29,7 @@ union float_long
   };
 
 /* compare two floats */
-char __fslt (float a1, float a2)
-// reentrant
+char __fslt (float a1, float a2) _FS_REENTRANT
 {
   volatile union float_long fl1, fl2;
 
index 315a04d618b85ecd3ae6cb213194ab6b0fb825c3..0e7fc27ef06ed921f9235e6fd850bd31f3f57e16 100644 (file)
@@ -29,8 +29,7 @@ union float_long
   };
 
 /* multiply two floats */
-float __fsmul (float a1, float a2)
-// reentrant
+float __fsmul (float a1, float a2) _FS_REENTRANT
 {
   volatile union float_long fl1, fl2;
   volatile unsigned long result;
index 2ed1b1ec38c7a8511c508a711b55705bdc5d60d1..338aa2360580d7177c7be9126835ea13b657cc2f 100644 (file)
@@ -29,8 +29,7 @@ union float_long
   };
 
 /* compare two floats */
-char __fsneq (float a1, float a2)
-// reentrant
+char __fsneq (float a1, float a2) _FS_REENTRANT
 {
   volatile union float_long fl1, fl2;
 
index 54770b591a11fe7ad52fa216d23b40c6a8d6b362..a69e33269e1134d9f60f28193880cd8d40d927a9 100644 (file)
@@ -29,8 +29,7 @@ union float_long
   };
 
 /* subtract two floats */
-float __fssub (float a1, float a2)
-// reentrant
+float __fssub (float a1, float a2) _FS_REENTRANT
 {
   volatile union float_long fl1, fl2;
 
index d0028f68fe4291d816c77accc52793d1e9ae838b..9fc7bdf6cc3826472dc9669de0e127878ab634b2 100644 (file)
@@ -32,8 +32,7 @@
 #include <float.h>
 
 /* convert signed char to float */
-float __schar2fs (signed char sc)
-// reentrant
+float __schar2fs (signed char sc) _FS_REENTRANT
 {
   return __slong2fs(sc);
 }
index 4c3d65d745f36ae00f075129593d109bfddb776a..ce53b355d11ba949b2d0708002dfde2bd66d7f1d 100644 (file)
@@ -32,8 +32,7 @@
 #include <float.h>
 
 /* convert signed int to float */
-float __sint2fs (signed int si)
-// reentrant
+float __sint2fs (signed int si) _FS_REENTRANT
 {
   return __slong2fs(si);
 }
index 11d38920dd0b420c33f552027e58349bebb9da93..fb9a8ab63e347ed6f285abbc6c76cbdd172db601 100644 (file)
@@ -32,8 +32,7 @@
 #include <float.h>
 
 /* convert signed long to float */
-float __slong2fs (signed long sl)
-//reentrant
+float __slong2fs (signed long sl) _FS_REENTRANT
 {
   if (sl<0) 
     return -__ulong2fs(-sl);
index 536cf674c985c6abc902ddc9fe0e866c47725f1a..d68eb8665b47777968a50e86ca982bb0cd6cb37d 100644 (file)
@@ -32,8 +32,7 @@
 #include <float.h>
 
 /* convert unsigned char to float */
-float __uchar2fs (unsigned char uc)
-// reentrant
+float __uchar2fs (unsigned char uc) _FS_REENTRANT
 {
   return __ulong2fs(uc);
 }
index 2a846d7553df5fa8e9ec5ba8b2daace3369aab72..6930296cc6260b08052d89556497b074faaa1c17 100644 (file)
@@ -32,8 +32,7 @@
 #include <float.h>
 
 /* convert unsigned int to float */
-float __uint2fs (unsigned int ui)
-//reentrant
+float __uint2fs (unsigned int ui) _FS_REENTRANT
 {
   return __ulong2fs(ui);
 }
index 23123339a3a80f41db5be05724ae356e78d9e24b..90322f28fc454c969872e5321baf7a8638a8023a 100644 (file)
@@ -28,8 +28,7 @@ union float_long
     long l;
   };
 
-float __ulong2fs (unsigned long a )
-// reentrant
+float __ulong2fs (unsigned long a ) _FS_REENTRANT
 {
   int exp = 24 + EXCESS;
   volatile union float_long fl;
index 2db46c13159f2b22803b4276c8ed572e3c17b836..21ba08e577a9447f3bad48d77ac8cf378b21d4c9 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
 
 unsigned unsigned _divuint (unsigned a, unsigned b);
 
-int _divsint (int a, int b)
+int _divsint (int a, int b) _IL_REENTRANT
 {
   register int r;
 
index 1c54fd49e16c108eb05adfe0348c42f1332c4108..59a4cb7c0e518184f6727645440f396f65f8c743 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
 
 #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1)
 
-unsigned int _divuint (unsigned int a, unsigned int b)
+unsigned int _divuint (unsigned int a, unsigned int b) _IL_REENTRANT
 {
   unsigned int reste = 0;
   unsigned char count = 16;
index 4ed9a78f8d0651e5ec20e2f621582072ad9de945..f326a4dd30276092e86d1995e47812fefe4ff084 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
+
 unsigned unsigned _moduint (unsigned a, unsigned b);
 
-int _modsint (int a, int b)
+int _modsint (int a, int b) _IL_REENTRANT
 {
        register int r;
        
index f0235be3b63ce3ccaf251ad990310cf8350a74bb..0006c9e4bc60914e0959e794c2e695bd9ead94a1 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
 
 #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1) 
 
-unsigned int _moduint (unsigned int a, unsigned int b)
+unsigned int _moduint (unsigned int a, unsigned int b) _IL_REENTRANT
 {
   unsigned char count = 0;
     
index f024fe73124b9cd88ed34a67214c38164bf15c3f..5979fe6c0637a90c636214b57a7c816dec796381 100644 (file)
    has the same precision as the input.
 */
 
+#include <sdcc-lib.h>
+
 union uu {
        struct { unsigned char lo,hi ;} s;
         unsigned int t;
 } ;
 
-int _mulint (int a, int b)
+int _mulint (int a, int b) _IL_REENTRANT
 {
-#if 0
-  register union uu *x;
-  register union uu *y;
-  union uu t;
-
-       x = (union uu *)&a;
-       y = (union uu *)&b;
-
-        t.t = x->s.lo * y->s.lo;
-        t.s.hi += (x->s.lo * y->s.hi) + (x->s.hi * y->s.lo);
-
-       return t.t;
-#else
   union uu x;
   union uu y;
   union uu t;
 
-        x.t = a;
-        y.t = b;
-        t.t = x.s.lo * y.s.lo;
-        t.s.hi += (x.s.lo * y.s.hi) + (x.s.hi * y.s.lo);
+    x.t = a;
+    y.t = b;
+    t.t = x.s.lo * y.s.lo;
+    t.s.hi += (x.s.lo * y.s.hi) + (x.s.hi * y.s.lo);
 
   return t.t;
-#endif
 }
index 12cc54384b73ae3ac433ffb39cc198b01192e185..bd99d08f5ec6367642d49d54c8a981a2a89ff568 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
+
 unsigned long _divulong(unsigned long a, unsigned long b);
 
-long _divslong (long a, long b)
+long _divslong (long a, long b) _IL_REENTRANT
 {
   long r;
 
index 867964136733365f08c858901f3b0d1a925eba35..2e7d7961485812e0695e7329dfc60d358d5b44eb 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
+
 #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1)
 
-unsigned long _divulong (unsigned long a, unsigned long b)
+unsigned long _divulong (unsigned long a, unsigned long b) _IL_REENTRANT
 {
   unsigned long reste = 0L;
   unsigned char count = 32;
index ee875f9325f2bf156046888d2c27847bad7b48a9..d5459d7080f0f09c432158676b4ebcb20e02b8a0 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
+
 unsigned long _modulong (unsigned long a, unsigned long b);
 
-long _modslong (long a, long b)
+long _modslong (long a, long b) _IL_REENTRANT
 {
   long r;
 
index 628c980ce28ebff4eaf844696805c8f18f5b08a6..0d137454b487a09b813fb2cde05a2e53d1641e5a 100644 (file)
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
+
 #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1)
 
-unsigned long _modulong (unsigned long a, unsigned long b)
+unsigned long _modulong (unsigned long a, unsigned long b) _IL_REENTRANT
 {
   unsigned char count = 0;
 
index ae9764c483f0e554d2004793e8588ae9c474cbdf..ad14020e1a6d78133d93bde19cc42a70bab93841 100644 (file)
@@ -24,6 +24,8 @@
    what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+#include <sdcc-lib.h>
+
 union bil {
         struct {unsigned char b0,b1,b2,b3 ;} b;
         struct {unsigned short lo,hi ;} i;
@@ -52,7 +54,7 @@ union bil {
                           |-------> only this side 32 x 32 -> 32
 */
 
-long _mullong (long a, long b)
+long _mullong (long a, long b) _IL_REENTRANT
 {
 #if 0
         union bil t;
index cc0b7b8d1bf013dfe6e1b73d7374229c63b68466..ae5c8cae4da7094caf504d06930682019fee4dab 100644 (file)
@@ -82,7 +82,7 @@ SDCC Compiler User Guide
 
 
 \size normal 
-SDCC 2.4.4
+SDCC 2.4.5
 \size footnotesize 
 
 \newline 
index 7503d9f9c971ccb9e833d595db069f0cab2a1f11..c9668217224c09fff33b3021b65efcbcb282c4e8 100644 (file)
@@ -76,6 +76,7 @@ set *libPathsSet = NULL;
 set *relFilesSet = NULL;
 set *dataDirsSet = NULL;        /* list of data search directories */
 set *includeDirsSet = NULL;     /* list of include search directories */
+set *userIncDirsSet = NULL;    /* list of user include directories */
 set *libDirsSet = NULL;         /* list of lib search directories */
 
 /* uncomment JAMIN_DS390 to always override and use ds390 port
@@ -1234,7 +1235,10 @@ parseCmdLine (int argc, char **argv)
                 SNPRINTF (buffer, sizeof(buffer),
                   ((sOpt == 'I') ? "-%c\"%s\"": "-%c%s"), sOpt, rest);
                 addSet(&preArgvSet, Safe_strdup(buffer));
-                if(sOpt == 'I')addSet(&includeDirsSet, Safe_strdup(rest));
+                if(sOpt == 'I') {
+                  addSet(&includeDirsSet, Safe_strdup(rest));
+                  addSet(&userIncDirsSet, Safe_strdup(rest));
+                }
               }
               break;
 
@@ -2224,6 +2228,7 @@ main (int argc, char **argv, char **envp)
   parseCmdLine (argc, argv);
 
   initValues ();
+
   setBinPaths(argv[0]);
   setDataPaths(argv[0]);
 
index 6b856b4380f5c2798910bf4eb8dcdf58cabeb813..2b39b153e9054a3622716090650a8adba568692e 100644 (file)
@@ -2470,7 +2470,7 @@ processFuncArgs (symbol * func)
     }
 
   /* reset regparm for the port */
-  (*port->reset_regparms) ();
+  (*port->reset_regparms) ( func );
   /* if any of the arguments is an aggregate */
   /* change it to pointer to the same type */
   while (val)
index 67cb9eacf8da03a24e7b0dbbca27668ac36a9ea9..33ec60ea97b52ca700fa48e8280a3500535b2baa 100644 (file)
@@ -18,6 +18,34 @@ Scott Dattalo        <scott AT dattalo.com>
 
 ======================================================================
 ======================================================================
+2004-Sep-27 Vangelis Rokas
+1. Function parameters have been extended to cover functions with
+variable arguments. Now function parameters follow the rules below:
+
+  a) void foo(long a, int b, char c)
+     void foo(long a, int b, char c) reentrant
+
+Stack layout: c, b+1, b, a+3, a+2, a+1 and WREG = a
+
+  b) prototype: void foo(long a, int b, ...)
+
+       example: foo(0xaaffeedd, 0xbbcc, 0x4455, 0x7788);
+
+Stack layout: 0x77, 0x88, 0x44, 0x55, 0xbb, 0xcc, 0xaa, 0xff, 0xee, 0xdd
+
+WREG is not used in functions with variable arguments so that the address
+of the first parameter can be taken.
+
+
+
+
+2004-Sep-24 Vangelis Rokas
+1. Began implementation of generic pointers, current specs are:
+       0x0 xxxxxxx -> code pointer
+       0x8 xxxxxxx -> data pointer
+       0x4 xxxxxxx -> eeprom pointer (currently unimplemented)
+
+
 2004-Aug-30 Vangelis Rokas
 1. A few months ago Hans Dorn had the idea to support general pointer
 for accessing all code, eeprom data and data ram memory. These pointers
index 0b378b991781d9bc2348b804e88130d6f0276641..f25163331f7cb69712928763ccab8264bde0776a 100644 (file)
@@ -85,23 +85,21 @@ typedef struct PIC16_device {
 
 /* Given a pointer to a register, this macro returns the bank that it is in */
 #define REG_ADDR(r)        ((r)->isBitField ? (((r)->address)>>3) : (r)->address)
-//#define REG_BANK(r)        (pic16_finalMapping[REG_ADDR(r)].bank)
-//#define REG_isALIASED(r)   (pic16_finalMapping[REG_ADDR(r)].alias != 0)
-//#define REG_isVALID(r)     (pic16_finalMapping[REG_ADDR(r)].isValid)
 
 
 typedef struct {
-       int no_banksel;
-       int opt_banksel;
-       int omit_configw;
-       int omit_ivt;
-       int leave_reset;
-       int stack_model;
-       int ivt_loc;
-       int nodefaultlibs;
-       int dumpcalltree;
-       char *crt_name;
-       int no_crt;
+  int no_banksel;
+  int opt_banksel;
+  int omit_configw;
+  int omit_ivt;
+  int leave_reset;
+  int stack_model;
+  int ivt_loc;
+  int nodefaultlibs;
+  int dumpcalltree;
+  char *crt_name;
+  int no_crt;
+  int ip_stack;
 } pic16_options_t;
 
 #define STACK_MODEL_SMALL      (pic16_options.stack_model == 0)
index 5c67e4dcb70e9a5a392e6be21256feb02fb923f1..9a09ef0b891063c594ff9914f17864e1f7aa82ab 100644 (file)
@@ -58,7 +58,8 @@ static asmop *newAsmop (short type);
 static pCodeOp *pic16_popRegFromString(char *str, int size, int offset, operand *op);
 extern pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...);
 static void mov2w (asmop *aop, int offset);
-static void mov2f(asmop *dsr, asmop *src, int offset);
+static void mov2f(asmop *dst, asmop *src, int offset);
+static void mov2fp(pCodeOp *dst, asmop *src, int offset);
 //static int aopIdx (asmop *aop, int offset);
 
 int pic16_labelOffset=0;
@@ -99,7 +100,7 @@ static bool is_LitAOp(asmop *aop);
 
 static char *zero = "#0x00";
 static char *one  = "#0x01";
-static char *spname = "sp";
+//static char *spname = "sp";
 
 
 /*
@@ -113,8 +114,7 @@ static char *spname = "sp";
  */
  
 
-char *fReturnpic16[] = {"temp1","temp2","temp3","temp4" };
-//char *fReturn390[] = {"dpl","dph","dpx", "b","a" };
+char *fReturnpic16[] = {"WREG", "PRODL", "PRODH", "FSR0L" };
 unsigned pic16_fReturnSizePic = 4; /* shared with ralloc.c */
 static char **fReturn = fReturnpic16;
 
@@ -132,8 +132,11 @@ static struct {
     short nRegsSaved;
     short ipushRegs;
     set *sendSet;
+    set *stackRegSet;
     int interruptvector;
     int usefastretfie;
+    bitVect *fregsUsed;
+    int stack_lat;                     /* stack offset latency */
 } _G;
 
 /* Resolved ifx structure. This structure stores information
@@ -149,7 +152,7 @@ typedef struct resolvedIfx {
 extern int pic16_ptrRegReq ;
 extern int pic16_nRegs;
 extern FILE *codeOutFile;
-static void saverbank (int, iCode *,bool);
+//static void saverbank (int, iCode *,bool);
 
 static lineNode *lineHead = NULL;
 static lineNode *lineCurr = NULL;
@@ -382,6 +385,16 @@ static regs *getFreePtr (iCode *ic, asmop **aopp, bool result)
        DEBUGpic16_emitcode("%s:%d WREG is used by this ic", __FILE__, __LINE__);
     }
 
+    if(!fsr0iu && !fsr0ou) {
+       ic->rUsed = bitVectSetBit(ic->rUsed, IDX_FSR0);
+       (*aopp)->type = AOP_FSR0;
+
+       fprintf(stderr, "%s:%d returning plain FSR0\n", __FILE__, __LINE__);
+       
+      return ((*aopp)->aopu.aop_ptr = pic16_regWithIdx(IDX_FSR0));
+    }
+
+#if 0
     /* no usage of FSR2 */
     if(!fsr2iu && !fsr2ou) {
        ic->rUsed = bitVectSetBit(ic->rUsed, IDX_FSR2);
@@ -389,14 +402,8 @@ static regs *getFreePtr (iCode *ic, asmop **aopp, bool result)
 
       return (*aopp)->aopu.aop_ptr = pic16_regWithIdx(IDX_FSR2);
     }
+#endif
        
-    if(!fsr0iu && !fsr0ou) {
-       ic->rUsed = bitVectSetBit(ic->rUsed, IDX_FSR0);
-       (*aopp)->type = AOP_FSR0;
-       
-      return ((*aopp)->aopu.aop_ptr = pic16_regWithIdx(IDX_FSR0));
-    }
-
     /* now we know they both have usage */
     /* if fsr0 not used in this instruction */
     if (!fsr0iu) {
@@ -409,6 +416,8 @@ static regs *getFreePtr (iCode *ic, asmop **aopp, bool result)
        ic->rUsed = bitVectSetBit (ic->rUsed, IDX_FSR0);
        (*aopp)->type = AOP_FSR0;
 
+//     fprintf(stderr, "%s:%d returning FSR0 after pushing value to stack\n", __FILE__, __LINE__);
+
       return (*aopp)->aopu.aop_ptr = pic16_regWithIdx (IDX_FSR0);
     }
        
@@ -435,7 +444,7 @@ static regs *getFreePtr (iCode *ic, asmop **aopp, bool result)
     /* if no usage of r0 then return it */
     if (!r0iu && !r0ou) {
         ic->rUsed = bitVectSetBit(ic->rUsed,R0_IDX);
-        (*aopp)->type = AOP_R0;
+        (*aopp)->type = AOP_R0; 
         
         return (*aopp)->aopu.aop_ptr = pic16_regWithIdx(R0_IDX);
     }
@@ -594,52 +603,57 @@ static asmop *aopForSym (iCode *ic, operand *op, bool result)
         return sym->aop;
     }
 
+#if 0
     /* 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) {
        fprintf(stderr, "%s:%d symbol %s on stack\n", __FILE__, __LINE__, OP_SYMBOL(op)->name);
     }
-
+#endif
 
 #if 1
     /* 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   */    
-    if ((sym->onStack && !options.stack10bit) || sym->iaccess) {
-
+    if (sym->onStack || sym->iaccess) {
+      pCodeOp *pcop[4];
+      int i;
+      
        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);
+        /* acquire a temporary register -- it is saved in function */
+
+        sym->aop = aop = newAsmop(AOP_STA);
+        aop->aopu.stk.stk = sym->stack;
         aop->size = getSize(sym->type);
 
-        fprintf(stderr, "%s:%d\t%s\n", __FILE__, __LINE__, __FUNCTION__);
+        for(i=0;i<aop->size;i++) {
+          aop->aopu.stk.pop[i] = pcop[i] = pic16_popGetTempRegCond( _G.fregsUsed, 0 );
+          _G.fregsUsed = bitVectSetBit(_G.fregsUsed, PCOR(pcop[i])->r->rIdx);
+        }
+
+//        fprintf(stderr, "%s:%d\t%s\tsym size %d\n", __FILE__, __LINE__, __FUNCTION__, aop->size);
 
 #if 1
-//        sym->aop = aop = newAsmop (AOP_REG);
-//        aop->aopu.aop_dir = sym->name;       //sym->rname ;
-//     aop->aopu.aop_reg[0] = pic16_regWithIdx(IDX_PLUSW0);    //pic16_pc_plusw2.r;
-//        aop->size = getSize(sym->type);
-       DEBUGpic16_emitcode(";","%d sym->rname = %s, size = %d",__LINE__,sym->rname,aop->size);
-       
-//     if(_G.accInUse) {
-//             pic16_pushpCodeOp( pic16_popCopyReg(&pic16_pc_wreg) );
-//     }
-       
-//     pic16_emitpcode(POC_MOVFF, pic16_popGet2p( pic16_popCopyReg(&pic16_pc_fsr2l), pic16_popCopyReg(&pic16_pc_fsr0l)));
-//     pic16_emitpcode(POC_MOVFF, pic16_popGet2p( pic16_popCopyReg(&pic16_pc_fsr2h), pic16_popCopyReg(&pic16_pc_fsr0h)));
+       DEBUGpic16_emitcode(";","%d sym->rname = %s, size = %d stack = %d",__LINE__,sym->rname,aop->size, sym->stack);
        
+       if(_G.accInUse) {
+               pic16_pushpCodeOp( pic16_popCopyReg(&pic16_pc_wreg) );
+       }
        
-       /* initialise for stack access via frame pointer */
-       pic16_emitpcode(POC_MOVLW, pic16_popGetLit(sym->stack));
+       for(i=0;i<aop->size;i++) {
 
-//     pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
-//             pic16_popCopyReg(&pic16_pc_plusw2), pic16_popCopyReg(&pic16_pc_kzero)));
+         /* initialise for stack access via frame pointer */
+         pic16_emitpcode(POC_MOVLW, pic16_popGetLit(sym->stack + i + _G.stack_lat));
+
+         pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
+                         pic16_popCopyReg(&pic16_pc_plusw2), pcop[i]));
+        }
        
-//     if(_G.accInUse) {
-//             pic16_poppCodeOp( pic16_popCopyReg(&pic16_pc_wreg) );
-//     }
+       if(_G.accInUse) {
+               pic16_poppCodeOp( pic16_popCopyReg(&pic16_pc_wreg) );
+       }
        
        return (aop);
 #endif
@@ -779,7 +793,9 @@ static asmop *aopForSym (iCode *ic, operand *op, bool result)
                aop->size = FPTRSIZE;
        else if(IC_LEFT(ic)) aop->size = AOP_SIZE( IC_LEFT(ic) );
        else if(IC_RIGHT(ic)) aop->size = AOP_SIZE( IC_RIGHT(ic) );
-       else {
+       else if(sym->onStack) {
+               aop->size = PTRSIZE;
+        } else {
                assert( 0 );
        }
 
@@ -1221,6 +1237,20 @@ void pic16_freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop)
             bitVectUnSetBit(ic->rUsed,R1_IDX);          
             break;
 
+        case AOP_STA:
+          {
+            int i;
+
+              for(i=0;i<aop->size;i++)
+#if 1
+                PCOR(aop->aopu.stk.pop[i] )->r->isFree = 1;
+#else
+                pic16_popReleaseTempReg( aop->aopu.stk.pop[i], 0 );
+                bitVectUnSetBit(_G.fregsUsed, PCOR(aop->aopu.stk.pop[i])->r->rIdx );
+#endif
+          }
+          break;
+#if 0
         case AOP_STK :
         {
             int sz = aop->size;    
@@ -1265,6 +1295,8 @@ void pic16_freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop)
                 _G.r1Pushed--;
             }       
         }
+#endif
+
     }
 #endif
 
@@ -1409,7 +1441,11 @@ char *pic16_aopGet (asmop *aop, int offset, bool bit16, bool dname)
       strcpy(rs,s);   
       return rs;
 
-      case AOP_STK:
+    case AOP_STA:
+        rs = Safe_strdup(PCOR(aop->aopu.stk.pop[offset])->r->name);
+        return (rs);
+        
+    case AOP_STK:
 //        pCodeOp *pcop = aop->aop
        break;
 
@@ -1422,45 +1458,102 @@ char *pic16_aopGet (asmop *aop, int offset, bool bit16, bool dname)
 }
 
 
+
+/* lock has the following meaning: When allocating temporary registers
+ * for stack variables storage, the value of the temporary register is
+ * saved on stack. Its value is restored at the end. This procedure is
+ * done via calls to pic16_aopOp and pic16_freeAsmop functions. There is
+ * a possibility that before a call to pic16_aopOp, a temporary register
+ * is allocated for a while and it is freed after some time, this will
+ * mess the stack and values will not be restored properly. So use lock=1
+ * to allocate temporary registers used internally by the programmer, and
+ * lock=0 to allocate registers for stack use. lock=1 will emit a warning
+ * to inform the compiler developer about a possible bug. This is an internal
+ * feature for developing the compiler -- VR */
+int _TempReg_lock = 0;
 /*-----------------------------------------------------------------*/
 /* pic16_popGetTempReg - create a new temporary pCodeOp                  */
 /*-----------------------------------------------------------------*/
-pCodeOp *pic16_popGetTempReg(void)
+pCodeOp *pic16_popGetTempReg(int lock)
 {
   pCodeOp *pcop;
   symbol *cfunc;
 
-//     DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+//    DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+    if(_TempReg_lock) {
+      werror(W_POSSBUG2, __FILE__, __LINE__);
+    }
+    
+    _TempReg_lock += lock;
+    
+    cfunc = currFunc;
+    currFunc = NULL;
 
-       cfunc = currFunc;
-       currFunc = NULL;
+    pcop = pic16_newpCodeOp(NULL, PO_GPR_TEMP);
+    if(pcop && pcop->type == PO_GPR_TEMP && PCOR(pcop)->r) {
+      PCOR(pcop)->r->wasUsed=1;
+      PCOR(pcop)->r->isFree=0;
 
-       pcop = pic16_newpCodeOp(NULL, PO_GPR_TEMP);
-       if(pcop && pcop->type == PO_GPR_TEMP && PCOR(pcop)->r) {
-               PCOR(pcop)->r->wasUsed=1;
-               PCOR(pcop)->r->isFree=0;
+      /* push value on stack */
+      pic16_pushpCodeOp( pic16_pCodeOpCopy(pcop) );
+    }
 
-               /* push value on stack */
-               pic16_pushpCodeOp( pic16_pCodeOpCopy(pcop) );
-       }
+    currFunc = cfunc;
+
+  return pcop;
+}
+
+/*-----------------------------------------------------------------*/
+/* pic16_popGetTempRegCond - create a new temporary pCodeOp, but   */
+/*                            don't save if inside v               */
+/*-----------------------------------------------------------------*/
+pCodeOp *pic16_popGetTempRegCond(bitVect *v, int lock)
+{
+  pCodeOp *pcop;
+  symbol *cfunc;
+
+//    DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+
+    if(_TempReg_lock) {
+      werror(W_POSSBUG2, __FILE__, __LINE__);
+    }
+
+    _TempReg_lock += lock;
 
-       currFunc = cfunc;
+    cfunc = currFunc;
+    currFunc = NULL;
+
+    pcop = pic16_newpCodeOp(NULL, PO_GPR_TEMP);
+    if(pcop && pcop->type == PO_GPR_TEMP && PCOR(pcop)->r) {
+      PCOR(pcop)->r->wasUsed=1;
+      PCOR(pcop)->r->isFree=0;
+
+      if(!bitVectBitValue(v, PCOR(pcop)->r->rIdx)) {
+      /* push value on stack */
+        pic16_pushpCodeOp( pic16_pCodeOpCopy(pcop) );
+      }
+    }
+
+    currFunc = cfunc;
 
   return pcop;
 }
 
+
 /*-----------------------------------------------------------------*/
 /* pic16_popReleaseTempReg - create a new temporary pCodeOp                  */
 /*-----------------------------------------------------------------*/
-void pic16_popReleaseTempReg(pCodeOp *pcop)
+void pic16_popReleaseTempReg(pCodeOp *pcop, int lock)
 {
-       DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
-       if(pcop && pcop->type == PO_GPR_TEMP && PCOR(pcop)->r) {
-               PCOR(pcop)->r->isFree = 1;
-               
-               pic16_poppCodeOp( pic16_pCodeOpCopy(pcop) );
-       }
+  _TempReg_lock -= lock;
+
+  if(pcop && pcop->type == PO_GPR_TEMP && PCOR(pcop)->r) {
+    PCOR(pcop)->r->isFree = 1;
+    pic16_poppCodeOp( pic16_pCodeOpCopy(pcop) );
+  }
 }
 /*-----------------------------------------------------------------*/
 /* pic16_popGetLabel - create a new pCodeOp of type PO_LABEL             */
@@ -1503,7 +1596,7 @@ pCodeOp *pic16_popCopyReg(pCodeOpReg *pc)
 /*-----------------------------------------------------------------*/
 /* pic16_popGetLit - asm operator to pcode operator conversion     */
 /*-----------------------------------------------------------------*/
-pCodeOp *pic16_popGetLit(unsigned int lit)
+pCodeOp *pic16_popGetLit(int lit)
 {
   return pic16_newpCodeOpLit(lit);
 }
@@ -1511,7 +1604,7 @@ pCodeOp *pic16_popGetLit(unsigned int lit)
 /*-----------------------------------------------------------------*/
 /* pic16_popGetLit2 - asm operator to pcode operator conversion    */
 /*-----------------------------------------------------------------*/
-pCodeOp *pic16_popGetLit2(unsigned int lit, pCodeOp *arg2)
+pCodeOp *pic16_popGetLit2(int lit, pCodeOp *arg2)
 {
   return pic16_newpCodeOpLit2(lit, arg2);
 }
@@ -1565,17 +1658,17 @@ static pCodeOp *pic16_popRegFromString(char *str, int size, int offset, operand
   //pcop->name = Safe_strdup( ( (str) ? str : "BAD STRING"));
 
   PCOR(pcop)->r = pic16_dirregWithName(pcop->name);
-  if(PCOR(pcop)->r == NULL) {
+
+  /* make sure that register doesn't exist,
+   * and operand isn't NULL */
+  if((PCOR(pcop)->r == NULL) 
+    && (op)) {
 //     fprintf(stderr, "%s:%d - couldn't find %s in allocated regsters, size= %d ofs= %d\n",
 //             __FUNCTION__, __LINE__, str, size, offset);
 
+    PCOR(pcop)->r = pic16_allocRegByName (pcop->name,size, op);
+    fprintf(stderr, "%s:%d: WARNING: need to allocate new register by name -> %s\n", __FILE__, __LINE__, str);
 
-//    PCOR(pcop)->r = pic16_allocRegByName (pcop->name,size, op);
-       fprintf(stderr, "%s:%d: WARNING: need to allocate new register by name -> %s\n", __FILE__, __LINE__, str);
-
-//    DEBUGpic16_emitcode(";","%d  %s   size= %d offset=%d - had to alloc by reg name",__LINE__,pcop->name,size,offset);
-  } else {
-//    DEBUGpic16_emitcode(";","%d  %s   size= %d offset=%d",__LINE__,pcop->name,size,offset);
   }
   PCOR(pcop)->instance = offset;
 
@@ -1705,6 +1798,13 @@ pCodeOp *pic16_popGet (asmop *aop, int offset) //, bool bit16, bool dname)
       DEBUGpic16_emitcode(";","%d\tAOP_IMMD",__LINE__);
       return pic16_popGetImmd(aop->aopu.aop_immd,offset,0);
 
+    case AOP_STA:
+      /* pCodeOp is already allocated from aopForSym */
+        DEBUGpic16_emitcode(";---", "%d getting stack + offset %d\n", __LINE__, offset);
+        pcop = pic16_pCodeOpCopy(aop->aopu.stk.pop[offset]);
+          
+      return (pcop);
+      
     case AOP_ACC:
       {
        int rIdx = IDX_WREG;            //aop->aopu.aop_reg[offset]->rIdx;
@@ -1813,6 +1913,8 @@ void pic16_aopPut (asmop *aop, char *s, int offset)
     char *d = buffer ;
     symbol *lbl ;
 
+    return;
+
     DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
     if (aop->size && offset > ( aop->size - 1)) {
@@ -2029,9 +2131,10 @@ void pic16_aopPut (asmop *aop, char *s, int offset)
        break;
 
     default :
-       werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
-              "pic16_aopPut got unsupported aop->type");
-       exit(0);    
+        fprintf(stderr, "%s:%d: unknown aop->type = 0x%x\n", __FILE__, __LINE__, aop->type);
+//     werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
+//            "pic16_aopPut got unsupported aop->type");
+//     exit(0);    
     }    
 
 }
@@ -2041,28 +2144,33 @@ void pic16_aopPut (asmop *aop, char *s, int offset)
 /*-----------------------------------------------------------------*/
 static void mov2w (asmop *aop, int offset)
 {
+  DEBUGpic16_emitcode ("; ***","%s  %d  offset=%d",__FUNCTION__,__LINE__,offset);
 
-//  if(!aop)
-//    return;
-
-       DEBUGpic16_emitcode ("; ***","%s  %d  offset=%d",__FUNCTION__,__LINE__,offset);
-
-       if(is_LitAOp(aop))
-               pic16_emitpcode(POC_MOVLW,pic16_popGet(aop,offset));
-       else
-               pic16_emitpcode(POC_MOVFW,pic16_popGet(aop,offset));
-
+  if(is_LitAOp(aop))
+    pic16_emitpcode(POC_MOVLW,pic16_popGet(aop,offset));
+  else
+    pic16_emitpcode(POC_MOVFW,pic16_popGet(aop,offset));
 }
 
 static void mov2f(asmop *dst, asmop *src, int offset)
 {
   if(is_LitAOp(src)) {
-          pic16_emitpcode(POC_MOVLW, pic16_popGet(src, offset));
-          pic16_emitpcode(POC_MOVWF, pic16_popGet(dst, offset));
-        } else {
-          pic16_emitpcode(POC_MOVFF, pic16_popGet2p( pic16_popGet(src, offset),
-                                    pic16_popGet(dst, offset)));
-        }
+    pic16_emitpcode(POC_MOVLW, pic16_popGet(src, offset));
+    pic16_emitpcode(POC_MOVWF, pic16_popGet(dst, offset));
+  } else {
+    pic16_emitpcode(POC_MOVFF, pic16_popGet2p( pic16_popGet(src, offset),
+                      pic16_popGet(dst, offset)));
+  }
+}
+
+static void mov2fp(pCodeOp *dst, asmop *src, int offset)
+{
+  if(is_LitAOp(src)) {
+    pic16_emitpcode(POC_MOVLW, pic16_popGet(src, offset));
+    pic16_emitpcode(POC_MOVWF, dst);
+  } else {
+    pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(src, offset), dst));
+  }
 }
 
 
@@ -2466,6 +2574,7 @@ release:
        pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);    
 }
 
+#if 0
 /*-----------------------------------------------------------------*/
 /* saveRegisters - will look for a call and save the registers     */
 /*-----------------------------------------------------------------*/
@@ -2567,6 +2676,7 @@ static void unsaveRegisters (iCode *ic)
     //}
 
 }  
+#endif
 
 #if 0  // patch 14
 /*-----------------------------------------------------------------*/
@@ -2591,15 +2701,13 @@ static void pushSide(operand * oper, int size)
 
 void pic16_loadFromReturn(operand *op, int offset, pCodeOp *src)
 {
-//             (AOP(left)->aopu.pcop->type == PO_DIR)?
-
-       if(AOP(op)->aopu.pcop->type == PO_IMMEDIATE) {
-               pic16_emitpcode(POC_MOVFW, src);
-               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(op), offset));
-       } else {
-               pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
-                       src, pic16_popGet(AOP(op), offset)));
-       }
+  if(AOP(op)->aopu.pcop->type == PO_IMMEDIATE) {
+    pic16_emitpcode(POC_MOVFW, src);
+    pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(op), offset));
+  } else {
+    pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
+        src, pic16_popGet(AOP(op), offset)));
+  }
 }
 
 
@@ -2610,82 +2718,84 @@ void pic16_loadFromReturn(operand *op, int offset, pCodeOp *src)
 static void assignResultValue(operand * oper, int rescall)
 {
   int size = AOP_SIZE(oper);
+  int offset=0;
+  
+    DEBUGpic16_emitcode ("; ***","%s  %d rescall:%d size:%d",__FUNCTION__,__LINE__,rescall,size); // patch 14
+    DEBUGpic16_pic16_AopType(__LINE__,oper,NULL,NULL);
 
-       DEBUGpic16_emitcode ("; ***","%s  %d rescall:%d size:%d",__FUNCTION__,__LINE__,rescall,size); // patch 14
-       DEBUGpic16_pic16_AopType(__LINE__,oper,NULL,NULL);
-
-       if(rescall) {
-               /* assign result from a call/pcall function() */
+    if(rescall) {
+      /* assign result from a call/pcall function() */
                
-               /* function results are stored in a special order,
-                * see top of file with Function return policy, or manual */
+      /* function results are stored in a special order,
+       * see top of file with Function return policy, or manual */
 
-               if(size <= 4) {
-                       /* 8-bits, result in WREG */
-                       pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(oper), 0));
+      if(size <= 4) {
+        /* 8-bits, result in WREG */
+        pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(oper), 0));
                        
-                       if(size>1) {
-                               /* 16-bits, result in PRODL:WREG */
-                               pic16_loadFromReturn(oper, 1, pic16_popCopyReg(&pic16_pc_prodl));
-                       }
+        if(size>1) {
+         /* 16-bits, result in PRODL:WREG */
+         pic16_loadFromReturn(oper, 1, pic16_popCopyReg(&pic16_pc_prodl));
+       }
                        
-                       if(size>2) {
-                               /* 24-bits, result in PRODH:PRODL:WREG */
-                               pic16_loadFromReturn(oper, 2, pic16_popCopyReg(&pic16_pc_prodh)); // patch 14
-                       }
+       if(size>2) {
+         /* 24-bits, result in PRODH:PRODL:WREG */
+         pic16_loadFromReturn(oper, 2, pic16_popCopyReg(&pic16_pc_prodh)); // patch 14
+       }
                        
-                       if(size>3) {
-                               /* 32-bits, result in FSR0L:PRODH:PRODL:WREG */
-                               pic16_loadFromReturn(oper, 3, pic16_popCopyReg(&pic16_pc_fsr0l)); // patch14
-                       }
-               } else {
-                       /* >32-bits, result on stack, and FSR0 points to beginning.
-                        * Fix stack when done */
-                        /* FIXME FIXME */
-                       while (size--) {
-//                             DEBUGpic16_emitcode("; ", "POC_MOVLW %d", GpsuedoStkPtr);
-//                             DEBUGpic16_emitcode("; ", "POC_MOVFW PLUSW2");
+       if(size>3) {
+         /* 32-bits, result in FSR0L:PRODH:PRODL:WREG */
+         pic16_loadFromReturn(oper, 3, pic16_popCopyReg(&pic16_pc_fsr0l)); // patch14
+       }
+      
+      } else {
+        /* >32-bits, result on stack, and FSR0 points to beginning.
+        * Fix stack when done */
+       /* FIXME FIXME */
+       while (size--) {
+//         DEBUGpic16_emitcode("; ", "POC_MOVLW %d", GpsuedoStkPtr);
+//          DEBUGpic16_emitcode("; ", "POC_MOVFW PLUSW2");
                
-                               popaopidx(AOP(oper), size, GpsuedoStkPtr);
-                               GpsuedoStkPtr++;
-                       }
+          popaopidx(AOP(oper), size, GpsuedoStkPtr);
+          GpsuedoStkPtr++;
+       }
                        
-                       /* fix stack */
-                       pic16_emitpcode(POC_MOVLW, pic16_popGetLit( AOP_SIZE(oper) ));
-                       pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( &pic16_pc_fsr1l ));
-                       if(STACK_MODEL_LARGE) {
-                               emitSKPNC;
-                               pic16_emitpcode(POC_INCF, pic16_popCopyReg( &pic16_pc_fsr1h ));
-                       }
-               }                       
-       } else {        
-               if(!GpsuedoStkPtr) {
-//                     DEBUGpic16_emitcode("; ", "pop %d", GpsuedoStkPtr);
-                       /* The last byte in the assignment is in W */
-                       size--;
-                       pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(oper),size));
-                       GpsuedoStkPtr++;
-               }
-
-               while (size--) {
-//                     DEBUGpic16_emitcode("; ", "POC_MOVLW %d", GpsuedoStkPtr);
-//                     DEBUGpic16_emitcode("; ", "POC_MOVFW PLUSW2");
-               
-                       popaopidx(AOP(oper), size, GpsuedoStkPtr);
-                       GpsuedoStkPtr++;
-
-#if 0
-#if STACK_SUPPORT
-               if(!USE_STACK)
-                       pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(oper),size));
-#else
-               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(oper),size));
-#endif
-#endif
-
-               }
+       /* fix stack */
+       pic16_emitpcode(POC_MOVLW, pic16_popGetLit( AOP_SIZE(oper) ));
+       pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( &pic16_pc_fsr1l ));
+       if(STACK_MODEL_LARGE) {
+         emitSKPNC;
+         pic16_emitpcode(POC_INCF, pic16_popCopyReg( &pic16_pc_fsr1h ));
        }
-               
+      }                        
+    } else {
+      int areg = 0;            /* matching argument register */
+      
+      areg = SPEC_ARGREG( OP_SYM_ETYPE( oper ) ) - 1;
+      /* its called from genReceive (probably) */
+      if(!GpsuedoStkPtr) {
+//        DEBUGpic16_emitcode("; ", "pop %d", GpsuedoStkPtr);
+        /* The last byte in the assignment is in W */
+        if(areg <= GpsuedoStkPtr) {
+          size--;
+          pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(oper), offset /*size*/));
+          offset++;
+        }
+       GpsuedoStkPtr++;
+       _G.stack_lat = AOP_SIZE(oper)-1;
+      }
+
+      while (size) {
+//        DEBUGpic16_emitcode("; ", "POC_MOVLW %d", GpsuedoStkPtr);
+//        DEBUGpic16_emitcode("; ", "POC_MOVFW PLUSW2");
+        if(areg <= GpsuedoStkPtr) {
+          size--;
+          popaopidx(AOP(oper), offset, GpsuedoStkPtr);
+          offset++;
+        }
+       GpsuedoStkPtr++;
+      }
+    }
 }
 
 
@@ -2694,21 +2804,20 @@ static void assignResultValue(operand * oper, int rescall)
 /*-----------------------------------------------------------------*/
 static void genIpush (iCode *ic)
 {
-  int size, offset=0;
+//  int size, offset=0;
 
   DEBUGpic16_emitcode ("; ***","%s  %d - WARNING no code generated",__FUNCTION__,__LINE__);
 
 
-       pic16_aopOp(IC_LEFT(ic), ic, FALSE);
-       
+  if(ic->parmPush) {
+    pic16_aopOp(IC_LEFT(ic), ic, FALSE );
+
+    /* send to stack as normal */
+    addSet(&_G.sendSet,ic);
+//    addSetHead(&_G.sendSet,ic);
+    pic16_freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
+  }
 
-       size = AOP_SIZE( IC_LEFT(ic) );
-       
-       while(size--) {
-               mov2w( AOP(IC_LEFT(ic)), offset );
-               pushw();
-               offset++;
-       }
        
 #if 0
     int size, offset = 0 ;
@@ -2737,29 +2846,6 @@ static void genIpush (iCode *ic)
         return ;        
     }
 
-    /* this is a paramter push: in this case we call
-    the routine to find the call and save those
-    registers that need to be saved */   
-    saveRegisters(ic);
-
-    /* then do the push */
-    pic16_aopOp(IC_LEFT(ic),ic,FALSE);
-
-
-       // pushSide(IC_LEFT(ic), AOP_SIZE(IC_LEFT(ic)));
-    size = AOP_SIZE(IC_LEFT(ic));
-
-    while (size--) {
-        l = pic16_aopGet(AOP(IC_LEFT(ic)),offset++,FALSE,TRUE);
-        if (AOP_TYPE(IC_LEFT(ic)) != AOP_REG && 
-            AOP_TYPE(IC_LEFT(ic)) != AOP_DIR &&
-            strcmp(l,"a") ) {
-            pic16_emitcode("mov","a,%s",l);
-            pic16_emitcode("push","acc");
-        } else
-            pic16_emitcode("push","%s",l);
-    }       
-
     pic16_freeAsmop(IC_LEFT(ic),NULL,ic,TRUE);
 #endif
 }
@@ -2789,6 +2875,7 @@ static void genIpop (iCode *ic)
 #endif
 }
 
+#if 0
 /*-----------------------------------------------------------------*/
 /* unsaverbank - restores the resgister bank from stack            */
 /*-----------------------------------------------------------------*/
@@ -2884,7 +2971,7 @@ static void saverbank (int bank, iCode *ic, bool pushPsw)
     ic->bankSaved = 1;
 #endif
 }
-
+#endif /* 0 */
 
 
 /*-----------------------------------------------------------------*/
@@ -2892,437 +2979,291 @@ static void saverbank (int bank, iCode *ic, bool pushPsw)
 /*-----------------------------------------------------------------*/
 static void genCall (iCode *ic)
 {
-  sym_link *dtype;   
+  sym_link *ftype;   
   int stackParms=0;
+  int use_wreg=0;
   
-       DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-
-       /* if caller saves & we have not saved then */
-       if (!ic->regsSaved)
-               saveRegisters(ic);
-
-       /* if we are calling a function that is not using
-        * the same register bank then we need to save the
-        * destination registers on the stack */
-       dtype = operandType(IC_LEFT(ic));
-       if (currFunc && dtype && 
-               (FUNC_REGBANK(currFunc->type) != FUNC_REGBANK(dtype)) &&
-               IFFUNC_ISISR(currFunc->type) &&
-               !ic->bankSaved) 
-
-                       saverbank(FUNC_REGBANK(dtype),ic,TRUE);
+    DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
+    ftype = OP_SYM_TYPE(IC_LEFT(ic));
+    /* if caller saves & we have not saved then */
+//    if (!ic->regsSaved)
+//      saveRegisters(ic);
 
        /* initialise stackParms for IPUSH pushes */
 //     stackParms = psuedoStkPtr;
 //     fprintf(stderr, "%s:%d ic parmBytes = %d\n", __FILE__, __LINE__, ic->parmBytes);
 
-       /* if send set is not empty the assign */
-       if (_G.sendSet) {
-         iCode *sic;
+    /* if send set is not empty the assign */
+    if (_G.sendSet) {
+      iCode *sic;
+      int psuedoStkPtr=-1; 
+      int firstTimeThruLoop = 1;
 
-               /* For the Pic port, there is no data stack.
-                * So parameters passed to functions are stored
-                * in registers. (The pCode optimizer will get
-                * rid of most of these :). */
 
-         int psuedoStkPtr=-1; 
-         int firstTimeThruLoop = 1;
+#if 1
+        /* reverse sendSet if function is not reentrant */
+        if(!IFFUNC_ISREENT(ftype))
+          _G.sendSet = reverseSet(_G.sendSet);
+#endif
 
-               _G.sendSet = reverseSet(_G.sendSet);
+       /* First figure how many parameters are getting passed */
 
-               /* First figure how many parameters are getting passed */
-               for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
-                       pic16_aopOp(IC_LEFT(sic),sic,FALSE);
-                       psuedoStkPtr += AOP_SIZE(IC_LEFT(sic));
-                       pic16_freeAsmop (IC_LEFT(sic),NULL,sic,FALSE);
-               }
+/*     do we really need to know this ? -- VR 
+       for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
+         pic16_aopOp(IC_LEFT(sic),sic,FALSE);
+          psuedoStkPtr += AOP_SIZE(IC_LEFT(sic));
+          pic16_freeAsmop (IC_LEFT(sic),NULL,sic,FALSE);
+        }
+*/
 
-               stackParms = psuedoStkPtr;
+//        stackParms = psuedoStkPtr;
+        stackParms = 0;
 
-               for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
-                 int size, offset = 0;
+        for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
+          int size, offset = 0;
 
-                       pic16_aopOp(IC_LEFT(sic),sic,FALSE);
-                       size = AOP_SIZE(IC_LEFT(sic));
+            pic16_aopOp(IC_LEFT(sic),sic,FALSE);
+            size = AOP_SIZE(IC_LEFT(sic));
 
-                       while (size--) {
-                               DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
-                                       pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
-                               DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
-
-                               if(!firstTimeThruLoop) {
-                                       /* If this is not the first time we've been through the loop
-                                        * then we need to save the parameter in a temporary
-                                        * register. The last byte of the last parameter is
-                                        * passed in W. */
-
-                                       pushw();
-                                       --psuedoStkPtr;         // sanity check
-                               }
-                       
-                               firstTimeThruLoop=0;
+            stackParms += size;
 
-                               mov2w (AOP(IC_LEFT(sic)),  offset);
-                               offset++;
-                       }
-                       pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
-               }
-               _G.sendSet = NULL;
-       }
+            while (size--) {
+              DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
+                    pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
+              DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
 
-       /* make the call */
-       pic16_emitpcode(POC_CALL,pic16_popGetWithString(OP_SYMBOL(IC_LEFT(ic))->rname[0] ?
-                       OP_SYMBOL(IC_LEFT(ic))->rname :
-                       OP_SYMBOL(IC_LEFT(ic))->name));
+              if(!firstTimeThruLoop) {
+                /* If this is not the first time we've been through the loop
+                 * then we need to save the parameter in a temporary
+                 * register. The last byte of the last parameter is
+                 * passed in W. */
 
-       GpsuedoStkPtr=0;
-       /* if we need assign a result value */
-       if ((IS_ITEMP(IC_RESULT(ic)) && 
-               (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
-               OP_SYMBOL(IC_RESULT(ic))->spildir )) ||
-               IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
+                pushw();
+//                --psuedoStkPtr;              // sanity check
+              }
+                
+              firstTimeThruLoop=0;
 
-               _G.accInUse++;
-               pic16_aopOp(IC_RESULT(ic),ic,FALSE);
-               _G.accInUse--;
+              mov2w (AOP(IC_LEFT(sic)), size);
 
-               assignResultValue(IC_RESULT(ic), 1);
+              offset++;
+            }
+            pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
+          }
 
-               DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
-                        pic16_AopType(AOP_TYPE(IC_RESULT(ic))));
-               
-               pic16_freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
-       }
+          /* save last parameter to stack if functions has varargs */
+          if(IFFUNC_HASVARARGS(ftype))
+                  pushw();
+          else
+            use_wreg = 1;              /* last parameter in WREG */
+          
+          _G.stackRegSet = _G.sendSet;
+          _G.sendSet = NULL;
+      }
 
-       if(!stackParms && ic->parmBytes) {
-               stackParms = ic->parmBytes;
-       }
-       
-       if(stackParms>0) {
-               pic16_emitpcode(POC_MOVLW, pic16_popGetLit(stackParms));
-               pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( &pic16_pc_fsr1l ));
-               if(STACK_MODEL_LARGE) {
-                       emitSKPNC;
-                       pic16_emitpcode(POC_INCF, pic16_popCopyReg( &pic16_pc_fsr1h ));
-               }
-       }
+      /* make the call */
+      pic16_emitpcode(POC_CALL,pic16_popGetWithString(OP_SYMBOL(IC_LEFT(ic))->rname[0] ?
+                      OP_SYMBOL(IC_LEFT(ic))->rname :
+                      OP_SYMBOL(IC_LEFT(ic))->name));
 
-       /* adjust the stack for parameters if required */
-//     fprintf(stderr, "%s:%d: %s ic->parmBytes= %d\n", __FILE__, __LINE__, OP_SYMBOL(IC_LEFT(ic))->name, ic->parmBytes);
-#if 0
-       if (ic->parmBytes) {
-         int i;
+      GpsuedoStkPtr=0;
+      /* if we need to assign a result value */
+      if ((IS_ITEMP(IC_RESULT(ic))
+            && (OP_SYMBOL(IC_RESULT(ic))->nRegs
+                || OP_SYMBOL(IC_RESULT(ic))->spildir ))
+          || IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
 
-               if (ic->parmBytes > 3) {
-                       pic16_emitcode("mov","a,%s",spname);
-                       pic16_emitcode("add","a,#0x%02x", (- ic->parmBytes) & 0xff);
-                       pic16_emitcode("mov","%s,a",spname);
-               } else 
-                       for ( i = 0 ; i <  ic->parmBytes ;i++)
-                               pic16_emitcode("dec","%s",spname);
-       }
-#endif
+        _G.accInUse++;
+        pic16_aopOp(IC_RESULT(ic),ic,FALSE);
+        _G.accInUse--;
+
+        assignResultValue(IC_RESULT(ic), 1);
+
+        DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
+                  pic16_AopType(AOP_TYPE(IC_RESULT(ic))));
+               
+        pic16_freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
+      }
+
+      if(!stackParms && ic->parmBytes) {
+        stackParms = ic->parmBytes;
+      }
+      
+      stackParms -= use_wreg;
+      
+      if(stackParms>0) {
+        pic16_emitpcode(POC_MOVLW, pic16_popGetLit(stackParms));
+        pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( &pic16_pc_fsr1l ));
+        if(STACK_MODEL_LARGE) {
+          emitSKPNC;
+          pic16_emitpcode(POC_INCF, pic16_popCopyReg( &pic16_pc_fsr1h ));
+        }
+      }
+
+      /* adjust the stack for parameters if required */
+//      fprintf(stderr, "%s:%d: %s ic->parmBytes= %d\n", __FILE__, __LINE__, OP_SYMBOL(IC_LEFT(ic))->name, ic->parmBytes);
 
 #if 0
-       /* if register bank was saved then pop them */
-       if (ic->bankSaved)
-               unsaverbank(FUNC_REGBANK(dtype),ic,TRUE);
+      /* if register bank was saved then pop them */
+      if (ic->bankSaved)
+        unsaverbank(FUNC_REGBANK(dtype),ic,TRUE);
 
-       /* if we hade saved some registers then unsave them */
-       if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype))
-               unsaveRegisters (ic);
+      /* if we hade saved some registers then unsave them */
+      if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype))
+        unsaveRegisters (ic);
 #endif
 }
 
 
 
-/*-----------------------------------------------------------------*/  // patch 14
+/*-----------------------------------------------------------------*/
 /* genPcall - generates a call by pointer statement                */
+/*            new version, created from genCall - HJD              */
 /*-----------------------------------------------------------------*/
-
-// new version, created from genCall
-
 static void genPcall (iCode *ic)
 {
-  sym_link *dtype;   
+  sym_link *ftype;
   int stackParms=0;
   symbol *retlbl = newiTempLabel(NULL);
   pCodeOp *pcop_lbl = pic16_popGetLabel(retlbl->key);
+  int use_wreg=0;
   
-       DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-
-       /* if caller saves & we have not saved then */
-       if (!ic->regsSaved)
-               saveRegisters(ic);
+    DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
-       /* if we are calling a function that is not using
-        * the same register bank then we need to save the
-        * destination registers on the stack */
-       dtype = operandType(IC_LEFT(ic));
-       if (currFunc && dtype && 
-               (FUNC_REGBANK(currFunc->type) != FUNC_REGBANK(dtype)) &&
-               IFFUNC_ISISR(currFunc->type) &&
-               !ic->bankSaved) 
+    ftype = OP_SYM_TYPE(IC_LEFT(ic));
+    
+    /* if send set is not empty the assign */
+    if (_G.sendSet) {
+      iCode *sic;
+      int psuedoStkPtr=-1; 
+      int firstTimeThruLoop = 1;
 
-                       saverbank(FUNC_REGBANK(dtype),ic,TRUE);
+      /* For the Pic port, there is no data stack.
+       * So parameters passed to functions are stored
+       * in registers. (The pCode optimizer will get
+       * rid of most of these :). */
 
-       /* if send set is not empty the assign */
-       if (_G.sendSet) {
-         iCode *sic;
 
-               /* For the Pic port, there is no data stack.
-                * So parameters passed to functions are stored
-                * in registers. (The pCode optimizer will get
-                * rid of most of these :). */
+#if 1
+      /* reverse sendSet if function is not reentrant */
+      if(!IFFUNC_ISREENT(ftype))
+        _G.sendSet = reverseSet(_G.sendSet);
+#endif
 
-         int psuedoStkPtr=-1; 
-         int firstTimeThruLoop = 1;
+      /* First figure how many parameters are getting passed */
+#if 0
+      for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
+        pic16_aopOp(IC_LEFT(sic),sic,FALSE);
+        psuedoStkPtr += AOP_SIZE(IC_LEFT(sic));
+        pic16_freeAsmop (IC_LEFT(sic),NULL,sic,FALSE);
+      }
+#endif
 
-               _G.sendSet = reverseSet(_G.sendSet);
+//      stackParms = psuedoStkPtr;
+      stackParms = 0;
 
-               /* First figure how many parameters are getting passed */
-               for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
-                       pic16_aopOp(IC_LEFT(sic),sic,FALSE);
-                       psuedoStkPtr += AOP_SIZE(IC_LEFT(sic));
-                       pic16_freeAsmop (IC_LEFT(sic),NULL,sic,FALSE);
-               }
+      for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
+        int size, offset = 0;
 
-               stackParms = psuedoStkPtr;
+          pic16_aopOp(IC_LEFT(sic),sic,FALSE);
+          size = AOP_SIZE(IC_LEFT(sic));
+          stackParms += size;
 
-               for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) {
-                 int size, offset = 0;
+          while (size--) {
+            DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
+            pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
+            DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
 
-                       pic16_aopOp(IC_LEFT(sic),sic,FALSE);
-                       size = AOP_SIZE(IC_LEFT(sic));
+            if(!firstTimeThruLoop) {
+              /* If this is not the first time we've been through the loop
+               * then we need to save the parameter in a temporary
+               * register. The last byte of the last parameter is
+               * passed in W. */
 
-                       while (size--) {
-                               DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
-                                       pic16_AopType(AOP_TYPE(IC_LEFT(sic))));
-                               DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1);
-
-                               if(!firstTimeThruLoop) {
-                                       /* If this is not the first time we've been through the loop
-                                        * then we need to save the parameter in a temporary
-                                        * register. The last byte of the last parameter is
-                                        * passed in W. */
-
-                                       pushw();
-                                       --psuedoStkPtr;         // sanity check
-                               }
+              pushw();
+              --psuedoStkPtr;          // sanity check
+            }
                        
-                               firstTimeThruLoop=0;
+            firstTimeThruLoop=0;
 
-                               mov2w (AOP(IC_LEFT(sic)),  offset);
-                               offset++;
-                       }
-                       pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
-               }
-               _G.sendSet = NULL;
-       }
-
-       pic16_aopOp(IC_LEFT(ic),ic,FALSE);
-
-       // push return address
-       // push $ on return stack, then replace with retlbl
-
-       pic16_emitpcodeNULLop(POC_PUSH);
-
-       pic16_emitpcode(POC_MOVLW, pic16_popGetImmd(pcop_lbl->name, 0, 0));
-       pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_tosl));
-       pic16_emitpcode(POC_MOVLW, pic16_popGetImmd(pcop_lbl->name, 1, 0));
-       pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_tosh));
-       pic16_emitpcode(POC_MOVLW, pic16_popGetImmd(pcop_lbl->name, 2, 0));
-       pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_tosu));
-
-       /* make the call by writing the pointer into pc */
-       pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)),2), pic16_popCopyReg(&pic16_pc_pclatu)));
-       pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)),1), pic16_popCopyReg(&pic16_pc_pclath)));
-
-       // note: MOVFF to PCL not allowed
-       pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(IC_LEFT(ic)),0));
-       pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_pcl));
-
-
-//     pic16_emitpcode(POC_GOTO, pic16_popGetLabel(retlbl->key));
-//     pic16_emitpcodeNULLop(POC_NOP);
-//     pic16_emitpcodeNULLop(POC_NOP);
-
-       /* return address is here: (X) */
-       pic16_emitpLabelFORCE(retlbl->key);
-
-//     pic16_emitpcodeNULLop(POC_NOP);
-
-       pic16_freeAsmop (IC_LEFT(ic),NULL,ic,TRUE);
-
-       GpsuedoStkPtr=0;
-       /* if we need assign a result value */
-       if ((IS_ITEMP(IC_RESULT(ic)) && 
-               (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
-               OP_SYMBOL(IC_RESULT(ic))->spildir )) ||
-               IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
-
-               _G.accInUse++;
-               pic16_aopOp(IC_RESULT(ic),ic,FALSE);
-               _G.accInUse--;
-
-               assignResultValue(IC_RESULT(ic), 1);
-
-               DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
-                        pic16_AopType(AOP_TYPE(IC_RESULT(ic))));
-               
-               pic16_freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
-       }
-
-       if(stackParms>0) {
-               pic16_emitpcode(POC_MOVLW, pic16_popGetLit(stackParms));
-               pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( &pic16_pc_fsr1l ));
-               if(STACK_MODEL_LARGE) {
-                       emitSKPNC;
-                       pic16_emitpcode(POC_INCF, pic16_popCopyReg( &pic16_pc_fsr1h ));
-               }
-       }
-
-       /* adjust the stack for parameters if required */
-//     fprintf(stderr, "%s:%d: %s ic->parmBytes= %d\n", __FILE__, __LINE__, OP_SYMBOL(IC_LEFT(ic))->name, ic->parmBytes);
-
-       if (ic->parmBytes) {
-         int i;
-
-               if (ic->parmBytes > 3) {
-                       pic16_emitcode("mov","a,%s",spname);
-                       pic16_emitcode("add","a,#0x%02x", (- ic->parmBytes) & 0xff);
-                       pic16_emitcode("mov","%s,a",spname);
-               } else 
-                       for ( i = 0 ; i <  ic->parmBytes ;i++)
-                               pic16_emitcode("dec","%s",spname);
-       }
-
-       /* if register bank was saved then pop them */
-       if (ic->bankSaved)
-               unsaverbank(FUNC_REGBANK(dtype),ic,TRUE);
-
-       /* if we hade saved some registers then unsave them */
-       if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype))
-               unsaveRegisters (ic);
-}
-
-
-#if 0                                                                          // patch 14
-// old version, kept for reference
-
-/*-----------------------------------------------------------------*/
-/* genPcall - generates a call by pointer statement                */
-/*-----------------------------------------------------------------*/
-static void genPcall (iCode *ic)
-{
-    sym_link *dtype;
-    symbol *rlbl = newiTempLabel(NULL);
+            mov2w (AOP(IC_LEFT(sic)), size);
 
+            offset++;
+          }
 
-    DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    /* if caller saves & we have not saved then */
-    if (!ic->regsSaved)
-        saveRegisters(ic);
 
-    /* if we are calling a function that is not using
-    the same register bank then we need to save the
-    destination registers on the stack */
-    dtype = operandType(IC_LEFT(ic));
-    if (currFunc && dtype && 
-       IFFUNC_ISISR(currFunc->type) &&
-        (FUNC_REGBANK(currFunc->type) != FUNC_REGBANK(dtype)))
-        saverbank(FUNC_REGBANK(dtype),ic,TRUE);
+          pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
+      }
 
+      if(IFFUNC_HASVARARGS(ftype))
+        pushw();
+      else
+        use_wreg = 1;          /* last parameter in WREG */
 
-    /* push the return address on to the stack */
-    pic16_emitcode("mov","a,#%05d_DS_",(rlbl->key+100));
-    pic16_emitcode("push","acc");    
-    pic16_emitcode("mov","a,#(%05d_DS_ >> 8)",(rlbl->key+100));
-    pic16_emitcode("push","acc");
-    
-    if (options.model == MODEL_FLAT24)
-    {
-       pic16_emitcode("mov","a,#(%05d_DS_ >> 16)",(rlbl->key+100));
-       pic16_emitcode("push","acc");    
+      _G.stackRegSet = _G.sendSet;
+      _G.sendSet = NULL;
     }
 
-    /* now push the calling address */
     pic16_aopOp(IC_LEFT(ic),ic,FALSE);
 
-    pushSide(IC_LEFT(ic), FPTRSIZE);
+    // push return address
+    // push $ on return stack, then replace with retlbl
 
-    pic16_freeAsmop(IC_LEFT(ic),NULL,ic,TRUE); 
+    pic16_emitpcodeNULLop(POC_PUSH);
 
-    /* if send set is not empty the assign */
-    if (_G.sendSet) {
-       iCode *sic ;
+    pic16_emitpcode(POC_MOVLW, pic16_popGetImmd(pcop_lbl->name, 0, 0));
+    pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_tosl));
+    pic16_emitpcode(POC_MOVLW, pic16_popGetImmd(pcop_lbl->name, 1, 0));
+    pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_tosh));
+    pic16_emitpcode(POC_MOVLW, pic16_popGetImmd(pcop_lbl->name, 2, 0));
+    pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_tosu));
+  
+    /* make the call by writing the pointer into pc */
+    pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)),2), pic16_popCopyReg(&pic16_pc_pclatu)));
+    pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)),1), pic16_popCopyReg(&pic16_pc_pclath)));
 
-       for (sic = setFirstItem(_G.sendSet) ; sic ; 
-            sic = setNextItem(_G.sendSet)) {
-           int size, offset = 0;
-           pic16_aopOp(IC_LEFT(sic),sic,FALSE);
-           size = AOP_SIZE(IC_LEFT(sic));
-           while (size--) {
-               char *l = pic16_aopGet(AOP(IC_LEFT(sic)),offset,
-                               FALSE,FALSE);
-               if (strcmp(l,fReturn[offset]))
-                   pic16_emitcode("mov","%s,%s",
-                            fReturn[offset],
-                            l);
-               offset++;
-           }
-           pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
-       }
-       _G.sendSet = NULL;
-    }
+    // note: MOVFF to PCL not allowed
+    pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(IC_LEFT(ic)),0));
+    pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_pcl));
 
-    pic16_emitcode("ret","");
-    pic16_emitcode("","%05d_DS_:",(rlbl->key+100));
 
+    /* return address is here: (X) */
+    pic16_emitpLabelFORCE(retlbl->key);
 
-    /* if we need assign a result value */
-    if ((IS_ITEMP(IC_RESULT(ic)) &&
-         (OP_SYMBOL(IC_RESULT(ic))->nRegs ||
-          OP_SYMBOL(IC_RESULT(ic))->spildir)) ||
-        IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
+    pic16_freeAsmop (IC_LEFT(ic),NULL,ic,TRUE);
 
-        _G.accInUse++;
-        pic16_aopOp(IC_RESULT(ic),ic,FALSE);
-        _G.accInUse--;
-       
-       assignResultValue(IC_RESULT(ic), 1);
+    GpsuedoStkPtr=0;
+    /* if we need assign a result value */
+    if ((IS_ITEMP(IC_RESULT(ic))
+          && (OP_SYMBOL(IC_RESULT(ic))->nRegs
+              || OP_SYMBOL(IC_RESULT(ic))->spildir ))
+        || IS_TRUE_SYMOP(IC_RESULT(ic)) ) {
 
-        pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
-    }
+      _G.accInUse++;
+      pic16_aopOp(IC_RESULT(ic),ic,FALSE);
+      _G.accInUse--;
 
-    /* adjust the stack for parameters if 
-    required */
-    if (ic->parmBytes) {
-        int i;
-        if (ic->parmBytes > 3) {
-            pic16_emitcode("mov","a,%s",spname);
-            pic16_emitcode("add","a,#0x%02x", (- ic->parmBytes) & 0xff);
-            pic16_emitcode("mov","%s,a",spname);
-        } else 
-            for ( i = 0 ; i <  ic->parmBytes ;i++)
-                pic16_emitcode("dec","%s",spname);
+      assignResultValue(IC_RESULT(ic), 1);
 
+      DEBUGpic16_emitcode ("; ","%d left %s",__LINE__,
+              pic16_AopType(AOP_TYPE(IC_RESULT(ic))));
+               
+      pic16_freeAsmop(IC_RESULT(ic),NULL, ic,TRUE);
     }
 
-    /* if register bank was saved then unsave them */
-    if (currFunc && dtype && 
-        (FUNC_REGBANK(currFunc->type) != FUNC_REGBANK(dtype)))
-        unsaverbank(FUNC_REGBANK(dtype),ic,TRUE);
-
-    /* if we hade saved some registers then
-    unsave them */
-    if (ic->regsSaved)
-        unsaveRegisters (ic);
-
+    stackParms -= use_wreg;
+    
+    if(stackParms>0) {
+      pic16_emitpcode(POC_MOVLW, pic16_popGetLit(stackParms));
+      pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( &pic16_pc_fsr1l ));
+      if(STACK_MODEL_LARGE) {
+        /* this implies that stackParms < 256 !!! -- VR */
+        emitSKPNC;
+        pic16_emitpcode(POC_INCF, pic16_popCopyReg( &pic16_pc_fsr1h ));
+      }
+    }
 }
-#endif                                                                         // patch 14
-
 
 /*-----------------------------------------------------------------*/
 /* resultRemat - result  is rematerializable                       */
@@ -3385,7 +3326,7 @@ static void genFunction (iCode *ic)
        max_key=0;
        GpsuedoStkPtr=0;
        _G.nRegsSaved = 0;
-
+       
        ftype = operandType(IC_LEFT(ic));
        sym = OP_SYMBOL(IC_LEFT(ic));
 
@@ -3481,8 +3422,11 @@ static void genFunction (iCode *ic)
        }
        
        /* if critical function then turn interrupts off */
-       if (IFFUNC_ISCRITICAL(ftype))
-               pic16_emitcode("clr","ea");
+       if (IFFUNC_ISCRITICAL(ftype)) {
+         //pic16_emitcode("clr","ea");
+        }
+
+        _G.fregsUsed = sym->regsUsed;
 
        /* if this is an interrupt service routine then
         * save acc, b, dpl, dph  */
@@ -3541,7 +3485,7 @@ static void genFunction (iCode *ic)
         
 //             fprintf(stderr, "function name: %s\n", sym->name);
                if(strcmp(sym->name, "main")) {
-                       if(/*!options.ommitFramePtr || */sym->regsUsed) {
+                       if(/*!options.ommitFramePtr || sym->regsUsed*/1) {
                        /* setup the stack frame */
                                pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_fsr2l, &pic16_pc_postdec1, 0));
                                pic16_emitpcode(POC_MOVFF, pic16_popCombine2( &pic16_pc_fsr1l, &pic16_pc_fsr2l, 0));
@@ -3655,7 +3599,15 @@ static void genEndFunction (iCode *ic)
        return;
     }
 
+    _G.stack_lat = 0;
+
     /* add code for ISCRITICAL */
+    if(IFFUNC_ISCRITICAL(sym->type)) {
+      /* if critical function, turn on interrupts */
+      
+      /* TODO: add code here -- VR */
+    }
+    
 
 #if 0
     if (IFFUNC_ISREENT(sym->type) || options.stackAuto)
@@ -4222,9 +4174,9 @@ static void genDivOneByte (operand *left,
 
         /* unsigned is easy */
 
-       pct1 = pic16_popGetTempReg();
-       pct2 = pic16_popGetTempReg();
-       pct3 = pic16_popGetTempReg();
+       pct1 = pic16_popGetTempReg(1);
+       pct2 = pic16_popGetTempReg(1);
+       pct3 = pic16_popGetTempReg(1);
        
        label1 = newiTempLabel(NULL);
        label2 = newiTempLabel(NULL);
@@ -4274,9 +4226,9 @@ static void genDivOneByte (operand *left,
        if(AOP_TYPE(result) != AOP_ACC)
                pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 0));
 
-       pic16_popReleaseTempReg( pct3 );
-       pic16_popReleaseTempReg( pct2 );
-       pic16_popReleaseTempReg( pct1 );
+       pic16_popReleaseTempReg( pct3, 1);
+       pic16_popReleaseTempReg( pct2, 1);
+       pic16_popReleaseTempReg( pct1, 1);
 
         return ;
     }
@@ -5333,14 +5285,14 @@ static void genCmp (operand *left,operand *right,
       if(size) {
        pCodeOp *pctemp;
        
-       pctemp = pic16_popGetTempReg();
+       pctemp = pic16_popGetTempReg(1);
        pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),size));
        pic16_emitpcode(POC_MOVWF, pctemp);             //pic16_pic16_popRegFromIdx(pic16_Gstack_base_addr));
        pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
        pic16_emitpcode(POC_XORWF, pctemp);             //pic16_popRegFromIdx(pic16_Gstack_base_addr));
        pic16_emitpcode(POC_XORFW, pic16_popGet(AOP(right),size));
        pic16_emitpcode(POC_SUBFW, pctemp);             //pic16_popRegFromIdx(pic16_Gstack_base_addr));
-       pic16_popReleaseTempReg(pctemp);
+       pic16_popReleaseTempReg(pctemp, 1);
       } else {
        /* Signed char comparison */
        /* Special thanks to Nikolai Golovchenko for this snippet */
@@ -7679,6 +7631,7 @@ static void AccSRsh (int shCount)
     }
 }
 #endif
+
 /*-----------------------------------------------------------------*/
 /* shiftR1Left2Result - shift right one byte from left to result   */
 /*-----------------------------------------------------------------*/
@@ -7725,8 +7678,8 @@ static void shiftR1Left2ResultSigned (operand *left, int offl,
       pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offr));
     }
 
-    pic16_emitpcode(POC_RLCFW,  pic16_popGet(AOP(result),offr));
-    pic16_emitpcode(POC_RLCFW,  pic16_popGet(AOP(result),offr));
+    pic16_emitpcode(POC_RLNCFW,  pic16_popGet(AOP(result),offr));
+    //pic16_emitpcode(POC_RLCFW,  pic16_popGet(AOP(result),offr));
     pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0x1f));
 
     pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(result),offr,FALSE,FALSE),3,0, PO_GPR_REGISTER));
@@ -7841,8 +7794,8 @@ static void shiftR1Left2Result (operand *left, int offl,
       pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offr));
     }
 
-    pic16_emitpcode(POC_RLCFW,  pic16_popGet(AOP(result),offr));
-    pic16_emitpcode(POC_RLCFW,  pic16_popGet(AOP(result),offr));
+    pic16_emitpcode(POC_RLNCFW,  pic16_popGet(AOP(result),offr));
+    //pic16_emitpcode(POC_RLCFW,  pic16_popGet(AOP(result),offr));
     pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0x1f));
     pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offr));
     break;
@@ -7855,19 +7808,19 @@ static void shiftR1Left2Result (operand *left, int offl,
 
   case 5:
     pic16_emitpcode(POC_SWAPFW, pic16_popGet(AOP(left),offl));
-    pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0x0f));
+    pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0x0e));
     pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offr));
-    emitCLRC;
-    pic16_emitpcode(POC_RRCF, pic16_popGet(AOP(result),offr));
+    //emitCLRC;
+    pic16_emitpcode(POC_RRNCF, pic16_popGet(AOP(result),offr));
 
     break;
   case 6:
 
-    pic16_emitpcode(POC_RLCFW,  pic16_popGet(AOP(left),offl));
-    pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0x80));
+    pic16_emitpcode(POC_RLNCFW,  pic16_popGet(AOP(left),offl));
+    pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0x81));
     pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offr));
-    pic16_emitpcode(POC_RLCF,   pic16_popGet(AOP(result),offr));
-    pic16_emitpcode(POC_RLCF,   pic16_popGet(AOP(result),offr));
+    //pic16_emitpcode(POC_RLCF,   pic16_popGet(AOP(result),offr));
+    pic16_emitpcode(POC_RLNCF,   pic16_popGet(AOP(result),offr));
     break;
 
   case 7:
@@ -8081,7 +8034,7 @@ static void shiftL2Left2Result (operand *left, int offl,
       pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offr+MSB16));
       pic16_emitpcode(POC_SWAPFW,pic16_popGet(AOP(left),offl));
       pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offr));
-      pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0xF0));
+      pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0x0F));
       pic16_emitpcode(POC_XORWF, pic16_popGet(AOP(result),offr));
       pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(result),offr+MSB16));
 
@@ -8218,7 +8171,7 @@ static void shiftR2Left2Result (operand *left, int offl,
       pic16_emitpcode(POC_ANDLW,pic16_popGetLit(0x03));
       if(sign) {
        pic16_emitpcode(POC_BTFSC, 
-                 pic16_newpCodeOpBit(pic16_aopGet(AOP(result),offr+MSB16,FALSE,FALSE),1,0, PO_GPR_REGISTER));
+                 pic16_newpCodeOpBit(pic16_aopGet(AOP(result),offr,FALSE,FALSE),0,0, PO_GPR_REGISTER));
        pic16_emitpcode(POC_IORLW,pic16_popGetLit(0xfc));
       }
       pic16_emitpcode(POC_XORFW,pic16_popGet(AOP(result),offr+MSB16));
@@ -8354,7 +8307,7 @@ static void shiftLLong (operand *left, operand *result, int offr )
                pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),LSB+offr));
        }
        
-    if (size >= LSB+offr ){
+    if (size > LSB+offr ){
                if (same) {
                        pic16_emitpcode(POC_ADDWF,pic16_popGet(AOP(left),LSB+offr));
                } else {
@@ -8363,7 +8316,7 @@ static void shiftLLong (operand *left, operand *result, int offr )
                }
         }
 
-    if(size >= MSB16+offr){
+    if(size > MSB16+offr){
                if (same) {
                        pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(left),MSB16+offr));
                } else {
@@ -8372,7 +8325,7 @@ static void shiftLLong (operand *left, operand *result, int offr )
                }
     }
 
-    if(size >= MSB24+offr){
+    if(size > MSB24+offr){
                if (same) {
                        pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(left),MSB24+offr));
                } else {
@@ -8711,7 +8664,7 @@ static void genLeftShift (iCode *ic)
   size = AOP_SIZE(result);
   offset = 1;
 
-  pctemp = pic16_popGetTempReg();  /* grab a temporary working register. */
+  pctemp = pic16_popGetTempReg(1);  /* grab a temporary working register. */
 
   pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
 
@@ -8735,7 +8688,7 @@ static void genLeftShift (iCode *ic)
   pic16_emitpcode(POC_GOTO,pic16_popGetLabel(tlbl->key));
   pic16_emitpLabel(tlbl1->key);
 
-  pic16_popReleaseTempReg(pctemp);
+  pic16_popReleaseTempReg(pctemp,1);
 
 
  release:
@@ -8893,7 +8846,7 @@ static void genLeftShift (iCode *ic)
   size = AOP_SIZE(result);
   offset = 1;
 
-  pctemp = pic16_popGetTempReg();  /* grab a temporary working register. */
+  pctemp = pic16_popGetTempReg(1);  /* grab a temporary working register. */
 
   pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
 
@@ -8917,7 +8870,7 @@ static void genLeftShift (iCode *ic)
   pic16_emitpcode(POC_GOTO,pic16_popGetLabel(tlbl->key));
   pic16_emitpLabel(tlbl1->key);
 
-  pic16_popReleaseTempReg(pctemp);
+  pic16_popReleaseTempReg(pctemp,1);
 
 
  release:
@@ -9240,7 +9193,7 @@ static void genSignedRightShift (iCode *ic)
   size = AOP_SIZE(result);
   offset = size - 1;
 
-  pctemp = pic16_popGetTempReg();  /* grab a temporary working register. */
+  pctemp = pic16_popGetTempReg(1);  /* grab a temporary working register. */
 
   pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
 
@@ -9265,7 +9218,7 @@ static void genSignedRightShift (iCode *ic)
   pic16_emitpcode(POC_GOTO,pic16_popGetLabel(tlbl->key));
   pic16_emitpLabel(tlbl1->key);
 
-  pic16_popReleaseTempReg(pctemp);
+  pic16_popReleaseTempReg(pctemp,1);
 #if 0
   size = AOP_SIZE(result);
   offset = size - 1;
@@ -9706,11 +9659,11 @@ static void genNearPointerGet (operand *left,
 
        if(size) {
                pic16_emitpcode(POC_MOVFF,
-                       pic16_popGet2p(pic16_popCopyReg(&pic16_pc_indf0),
+                       pic16_popGet2p(pic16_popCopyReg(&pic16_pc_postinc0),
                                pic16_popGet(AOP(result), offset++)));
        } else {
                pic16_emitpcode(POC_MOVFF,
-                       pic16_popGet2p(pic16_popCopyReg(&pic16_pc_postinc0),
+                       pic16_popGet2p(pic16_popCopyReg(&pic16_pc_indf0),
                                pic16_popGet(AOP(result), offset++)));
        }
       }
@@ -9947,6 +9900,7 @@ static void genCodePointerGet (operand *left,
     pic16_freeAsmop(result,NULL,ic,TRUE);
 }
 #endif
+#if 0
 /*-----------------------------------------------------------------*/
 /* genGenPointerGet - gget value from generic pointer space        */
 /*-----------------------------------------------------------------*/
@@ -10010,6 +9964,88 @@ static void genGenPointerGet (operand *left,
        pic16_freeAsmop(result,NULL,ic,TRUE);
 
 }
+#endif
+
+extern set *externs;
+
+/*-----------------------------------------------------------------*/
+/* genGenPointerGet - gget value from generic pointer space        */
+/*-----------------------------------------------------------------*/
+static void genGenPointerGet (operand *left,
+                              operand *result, iCode *ic)
+{
+  int size, offset, lit;
+  sym_link *retype = getSpec(operandType(result));
+  char fgptrget[32];
+
+    DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+    pic16_aopOp(left,ic,FALSE);
+    pic16_aopOp(result,ic,FALSE);
+    size = AOP_SIZE(result);
+
+    DEBUGpic16_pic16_AopType(__LINE__,left,NULL,result);
+
+    if (AOP_TYPE(left) == AOP_IMMD) { // do we ever get here? (untested!)
+
+      lit = (unsigned)floatFromVal(AOP(left)->aopu.aop_lit);
+      // load FSR0 from immediate
+      pic16_emitpcode(POC_LFSR,pic16_popGetLit2(0,pic16_popGetLit(lit)));
+
+      werror(W_POSSBUG2, __FILE__, __LINE__);
+
+      offset = 0;
+      while(size--) {
+        if(size) {
+         pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_postinc0), pic16_popGet(AOP(result),offset)));
+       } else {
+          pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_indf0), pic16_popGet(AOP(result),offset)));
+        }
+        offset++;
+      }
+
+      goto release;
+
+    } else { /* we need to get it byte by byte */
+
+      /* set up WREG:FSR0H:FSR0L with address from left */
+      pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),0), pic16_popCopyReg(&pic16_pc_fsr0l)));
+      pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),1), pic16_popCopyReg(&pic16_pc_fsr0h)));
+      pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), 2));
+      
+      switch( size ) {
+        case 1: strcpy(fgptrget, "__gptrget1"); break;
+        case 2: strcpy(fgptrget, "__gptrget2"); break;
+        case 3: strcpy(fgptrget, "__gptrget3"); break;
+        case 4: strcpy(fgptrget, "__gptrget4"); break;
+        default:
+          werror(W_POSSBUG2, __FILE__, __LINE__);
+          abort();
+      }
+      
+      pic16_emitpcode(POC_CALL, pic16_popGetWithString( fgptrget ));
+      
+      assignResultValue(result, 1);
+      
+      {
+        symbol *sym;
+
+          sym = newSymbol( fgptrget, 0 );
+          strcpy(sym->rname, fgptrget);
+          checkAddSym(&externs, sym);
+//          fprintf(stderr, "%s:%d adding extern symbol %s in externs\n", __FILE__, __LINE__, fgptrget);
+      }
+              
+      goto release;
+    }
+
+  /* if bit then unpack */
+    if (IS_BITFIELD(retype)) 
+      genUnpackBits(result,left,"BAD",GPOINTER);
+
+release:
+  pic16_freeAsmop(left,NULL,ic,TRUE);
+  pic16_freeAsmop(result,NULL,ic,TRUE);
+}
 
 /*-----------------------------------------------------------------*/
 /* genConstPointerGet - get value from const generic pointer space */
@@ -10038,7 +10074,7 @@ static void genConstPointerGet (operand *left,
   pic16_emitpLabel(albl->key);
 
   poc = ( (AOP_TYPE(left) == AOP_PCODE) ? POC_MOVLW : POC_MOVFW);
-    
+  
   /* this performs a goto to the specified address -- Why not to use pointer? -- VR */
   pic16_emitpcode(poc,pic16_popGet(AOP(left),1));
   pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_pclath));
@@ -10677,6 +10713,7 @@ static void genFarPointerSet (operand *right,
 /*-----------------------------------------------------------------*/
 /* genGenPointerSet - set value from generic pointer space         */
 /*-----------------------------------------------------------------*/
+#if 0
 static void genGenPointerSet (operand *right,
                               operand *result, iCode *ic)
 {
@@ -10798,6 +10835,75 @@ static void genGenPointerSet (operand *right,
        pic16_freeAsmop(right,NULL,ic,TRUE);
        pic16_freeAsmop(result,NULL,ic,TRUE);
 }
+#endif
+
+static void genGenPointerSet (operand *right,
+                              operand *result, iCode *ic)
+{
+  int size;
+  sym_link *retype = getSpec(operandType(right));
+  char fgptrput[32];
+
+    DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+
+    pic16_aopOp(result,ic,FALSE);
+    pic16_aopOp(right,ic,FALSE);
+    size = AOP_SIZE(right);
+
+    DEBUGpic16_pic16_AopType(__LINE__,NULL,right,result);
+
+
+    /* if bit then unpack */
+    if (IS_BITFIELD(retype)) {
+//      pic16_emitpcode(POC_LFSR,pic16_popGetLit2(0,pic16_popGetLit(lit)));
+      genPackBits(retype,result,right,"dptr",GPOINTER);
+      goto release;
+    }
+
+    size = AOP_SIZE(right);
+
+    DEBUGpic16_emitcode ("; ***","%s  %d size=%d",__FUNCTION__,__LINE__,size);
+
+
+    /* load value to write in TBLPTRH:TBLPTRL:PRODH:PRODL */
+    mov2fp(pic16_popCopyReg(&pic16_pc_prodl), AOP(right), 0);
+    if(size>1)mov2fp(pic16_popCopyReg(&pic16_pc_prodh), AOP(right), 1);
+    if(size>2)mov2fp(pic16_popCopyReg(&pic16_pc_tblptrl), AOP(right), 2);
+    if(size>3)mov2fp(pic16_popCopyReg(&pic16_pc_tblptrh), AOP(right), 3);
+    
+    /* load address to write to in WREG:FSR0H:FSR0L */
+    pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(result), 0),
+                                pic16_popCopyReg(&pic16_pc_fsr0l)));
+    pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(result), 1),
+                                pic16_popCopyReg(&pic16_pc_fsr0h)));
+    pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(result), 2));
+    
+
+    /* put code here */
+    switch (size) {
+      case 1: strcpy(fgptrput, "__gptrput1"); break;
+      case 2: strcpy(fgptrput, "__gptrput2"); break;
+      case 4: strcpy(fgptrput, "__gptrput4"); break;
+      default:
+        werror(W_POSSBUG2, __FILE__, __LINE__);
+        abort();
+    }
+    
+    pic16_emitpcode(POC_CALL, pic16_popGetWithString( fgptrput ));
+    
+    {
+      symbol *sym;
+                  
+        sym = newSymbol( fgptrput, 0 );
+        strcpy(sym->rname, fgptrput);
+        checkAddSym(&externs, sym);
+//          fprintf(stderr, "%s:%d adding extern symbol %s in externs\n", __FILE__, __LINE__, fgptrget);
+    }
+
+release:
+    pic16_freeAsmop(right,NULL,ic,TRUE);
+    pic16_freeAsmop(result,NULL,ic,TRUE);
+}
 
 /*-----------------------------------------------------------------*/
 /* genPointerSet - stores the value into a pointer location        */
@@ -10918,59 +11024,72 @@ static void genAddrOf (iCode *ic)
   symbol *sym; // = OP_SYMBOL(IC_LEFT(ic));
   pCodeOp *pcop0, *pcop1, *pcop2;
 
-       DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-
-       pic16_aopOp((left=IC_LEFT(ic)), ic, FALSE);
-       pic16_aopOp((result=IC_RESULT(ic)),ic,TRUE);
+    DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
-       sym = OP_SYMBOL( left );
+    pic16_aopOp((result=IC_RESULT(ic)),ic,TRUE);
 
-       size = AOP_SIZE(IC_RESULT(ic));
+    sym = OP_SYMBOL( IC_LEFT(ic) );
+    
+    if(sym->onStack) {
+      /* get address of symbol on stack */
+      DEBUGpic16_emitcode(";    ", "%s symbol %s on stack", __FUNCTION__, sym->name);
+#if 0
+      fprintf(stderr, "%s:%d symbol %s on stack offset %d\n", __FILE__, __LINE__,
+                  OP_SYMBOL(left)->name, OP_SYMBOL(left)->stack);
+#endif
 
+      pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
+                      pic16_popCopyReg(&pic16_pc_fsr2l),
+                      pic16_popGet(AOP(result), 0)));
+      pic16_emitpcode(POC_MOVFF, pic16_popGet2p(
+                      pic16_popCopyReg(&pic16_pc_fsr2h),
+                      pic16_popGet(AOP(result), 1)));
+      
+      pic16_emitpcode(POC_MOVLW, pic16_popGetLit( OP_SYMBOL( IC_LEFT(ic))->stack ) /*+ _G.stack_lat*/);
+      pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(result), 0));
+      emitSKPNC;
+      pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result), 1));
 
-       if(sym->onStack) {
-               DEBUGpic16_emitcode(";    ", "%s symbol %s on stack", __FUNCTION__, sym->name);
-       
-               return;
-       }
+      goto release;
+    }
        
 //     if(pic16_debug_verbose) {
 //             fprintf(stderr, "%s:%d %s symbol %s , codespace=%d\n",
 //                     __FILE__, __LINE__, __FUNCTION__, sym->name, IN_CODESPACE( SPEC_OCLS(sym->etype)));
 //     }
        
-       /* Assume that what we want the address of is in data space
-        * since there is no stack on the PIC, yet! -- VR */
-       /* low */
-       pcop0 = PCOP(pic16_newpCodeOpImmd(sym->rname, 0, 0, IN_CODESPACE( SPEC_OCLS(sym->etype))));
+    pic16_aopOp((left=IC_LEFT(ic)), ic, FALSE);
+    size = AOP_SIZE(IC_RESULT(ic));
 
-       /* high */
-       pcop1 = PCOP(pic16_newpCodeOpImmd(sym->rname, 1, 0, IN_CODESPACE( SPEC_OCLS(sym->etype))));
-       
-       /* upper */
-       pcop2 = PCOP(pic16_newpCodeOpImmd(sym->rname, 2, 0, IN_CODESPACE( SPEC_OCLS(sym->etype))));
-       
 
-       if (size == 3) {
-               pic16_emitpcode(POC_MOVLW, pcop0);
-               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 0));
-               pic16_emitpcode(POC_MOVLW, pcop1);
-               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 1));
-               pic16_emitpcode(POC_MOVLW, pcop2);
-               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 2));
-       } else
-       if (size == 2) {
-               pic16_emitpcode(POC_MOVLW, pcop0);
-               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),0));
-               pic16_emitpcode(POC_MOVLW, pcop1);
-               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),1));
-       } else {
-               pic16_emitpcode(POC_MOVLW, pcop0);
-               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),0));
-       }
+    /* Assume that what we want the address of is in data space
+     * since there is no stack on the PIC, yet! -- VR */
+  
+    pcop0 = PCOP(pic16_newpCodeOpImmd(sym->rname, 0, 0, IN_CODESPACE( SPEC_OCLS(sym->etype))));
+    pcop1 = PCOP(pic16_newpCodeOpImmd(sym->rname, 1, 0, IN_CODESPACE( SPEC_OCLS(sym->etype))));
+    pcop2 = PCOP(pic16_newpCodeOpImmd(sym->rname, 2, 0, IN_CODESPACE( SPEC_OCLS(sym->etype))));
+       
+    if (size == 3) {
+      pic16_emitpcode(POC_MOVLW, pcop0);
+      pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 0));
+      pic16_emitpcode(POC_MOVLW, pcop1);
+      pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 1));
+      pic16_emitpcode(POC_MOVLW, pcop2);
+      pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 2));
+    } else
+    if (size == 2) {
+      pic16_emitpcode(POC_MOVLW, pcop0);
+      pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),0));
+      pic16_emitpcode(POC_MOVLW, pcop1);
+    pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),1));
+    } else {
+      pic16_emitpcode(POC_MOVLW, pcop0);
+      pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),0));
+    }
 
-       pic16_freeAsmop(result,NULL,ic,TRUE);
-       pic16_freeAsmop(left, NULL, ic, FALSE);
+    pic16_freeAsmop(left, NULL, ic, FALSE);
+release:
+    pic16_freeAsmop(result,NULL,ic,TRUE);
 }
 
 
@@ -11167,7 +11286,7 @@ static void genAssign (iCode *ic)
 
   know_W=-1;
   while (size--) {
-  DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  DEBUGpic16_emitcode ("; ***","%s  %d size %d",__FUNCTION__,__LINE__, size);
     if(AOP_TYPE(right) == AOP_LIT) {
       if(lit&0xff) {
        if(know_W != (lit&0xff))
@@ -11590,16 +11709,20 @@ static void genCast (iCode *ic)
            offset = 0 ;
            while (size--) {
              if(offset < AOP_SIZE(right)) {
-      DEBUGpic16_emitcode("; ***","%s  %d - pointer cast3",__FUNCTION__,__LINE__);
+                DEBUGpic16_emitcode("; ***","%s  %d - pointer cast3 ptype = 0x%x",__FUNCTION__,__LINE__, p_type);
+                mov2f(AOP(result), AOP(right), offset);
+/*
                if ((AOP_TYPE(right) == AOP_PCODE) && 
                    AOP(right)->aopu.pcop->type == PO_IMMEDIATE) {
                  pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(right),offset));
                  pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset));
                } else { 
+                 
                  pic16_aopPut(AOP(result),
                         pic16_aopGet(AOP(right),offset,FALSE,FALSE),
                         offset);
                }
+*/
              } else 
                pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),offset));
              offset++;
@@ -11608,21 +11731,28 @@ static void genCast (iCode *ic)
            switch (p_type) {
            case IPOINTER:
            case POINTER:
-               pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),GPTRSIZE - 1));
+               pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
+               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), GPTRSIZE - 1));
+//             pic16_emitpcode(POC_CLRF,pic16_popGet(AOP(result),GPTRSIZE - 1));
                break;
+
+           case CPOINTER:
+               pic16_emitpcode(POC_MOVFF, pic16_popGet2(AOP(right), AOP(result), GPTRSIZE-1));
+               break;
+
            case FPOINTER:
              pic16_emitcode(";BUG!? ","%d",__LINE__);
                l = one;
                break;
-           case CPOINTER:
-             pic16_emitcode(";BUG!? ","%d",__LINE__);
-               l = "#0x02";
-               break;                          
            case PPOINTER:
              pic16_emitcode(";BUG!? ","%d",__LINE__);
                l = "#0x03";
                break;
-               
+
+            case GPOINTER:
+              pic16_emitpcode(POC_MOVFF, pic16_popGet2(AOP(right), AOP(result), GPTRSIZE-1));
+              break;
+              
            default:
                /* this should never happen */
                werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
@@ -11753,11 +11883,6 @@ static int genDjnz (iCode *ic, iCode *ifx)
       pic16_emitcode ("goto","_%05d_DS_",IC_TRUE(ifx)->key+100 + pic16_labelOffset);
 
     }
-/*     pic16_emitcode ("sjmp","%05d_DS_",lbl1->key+100); */
-/*     pic16_emitcode ("","%05d_DS_:",lbl->key+100); */
-/*     pic16_emitcode ("ljmp","%05d_DS_",IC_TRUE(ifx)->key+100); */
-/*     pic16_emitcode ("","%05d_DS_:",lbl1->key+100); */
-
     
     pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
     ifx->generated = 1;
@@ -11769,47 +11894,47 @@ static int genDjnz (iCode *ic, iCode *ifx)
 /*-----------------------------------------------------------------*/
 static void genReceive (iCode *ic)
 {    
-       DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
 #if 0
-       fprintf(stderr, "%s:%d %s for symbol %s\tonStack: %d\n", __FILE__, __LINE__, __FUNCTION__,
-               OP_SYMBOL( IC_RESULT(ic) )->rname, OP_SYMBOL( IC_RESULT(ic) )->onStack);
+  fprintf(stderr, "%s:%d %s for symbol %s\tonStack: %d\n", __FILE__, __LINE__, __FUNCTION__,
+        OP_SYMBOL( IC_RESULT(ic) )->rname, OP_SYMBOL( IC_RESULT(ic) )->onStack);
 #endif
-//     pic16_DumpOp(__FUNCTION__, IC_RESULT(ic));
+//  pic16_DumpOp(__FUNCTION__, IC_RESULT(ic));
 
-       if (isOperandInFarSpace(IC_RESULT(ic)) &&
-               ( OP_SYMBOL(IC_RESULT(ic))->isspilt ||
-               IS_TRUE_SYMOP(IC_RESULT(ic))) ) {
+  if (isOperandInFarSpace(IC_RESULT(ic))
+      && ( OP_SYMBOL(IC_RESULT(ic))->isspilt
+          || IS_TRUE_SYMOP(IC_RESULT(ic))) ) {
 
-         int size = getSize(operandType(IC_RESULT(ic)));
-         int offset =  pic16_fReturnSizePic - size;
+    int size = getSize(operandType(IC_RESULT(ic)));
+    int offset =  pic16_fReturnSizePic - size;
 
-               assert( 0 );
-               while (size--) {
-                       pic16_emitcode ("push","%s", (strcmp(fReturn[pic16_fReturnSizePic - offset - 1],"a") ?
-                                       fReturn[pic16_fReturnSizePic - offset - 1] : "acc"));
-                       offset++;
-               }
+      assert( 0 );
+      while (size--) {
+        pic16_emitcode ("push","%s", (strcmp(fReturn[pic16_fReturnSizePic - offset - 1],"a") ?
+                      fReturn[pic16_fReturnSizePic - offset - 1] : "acc"));
+                      offset++;
+        }
 
-               DEBUGpic16_emitcode ("; ***","1 %s  %d",__FUNCTION__,__LINE__);
+      DEBUGpic16_emitcode ("; ***","1 %s  %d",__FUNCTION__,__LINE__);
 
-               pic16_aopOp(IC_RESULT(ic),ic,FALSE);  
-               size = AOP_SIZE(IC_RESULT(ic));
-               offset = 0;
-               while (size--) {
-                       pic16_emitcode ("pop","acc");
-                       pic16_aopPut (AOP(IC_RESULT(ic)),"a",offset++);
-               }
-       } else {
-               DEBUGpic16_emitcode ("; ***","2 %s  %d",__FUNCTION__,__LINE__);
+      pic16_aopOp(IC_RESULT(ic),ic,FALSE);  
+      size = AOP_SIZE(IC_RESULT(ic));
+      offset = 0;
+      while (size--) {
+        pic16_emitcode ("pop","acc");
+        pic16_aopPut (AOP(IC_RESULT(ic)),"a",offset++);
+      }
+  } else {
+    DEBUGpic16_emitcode ("; ***","2 %s  %d argreg = %d",__FUNCTION__,__LINE__, SPEC_ARGREG(OP_SYM_ETYPE(IC_RESULT(ic)) ));
 
-               _G.accInUse++;
-               pic16_aopOp(IC_RESULT(ic),ic,FALSE);  
-               _G.accInUse--;
-               assignResultValue(IC_RESULT(ic), 0);
-       }
+    _G.accInUse++;
+    pic16_aopOp(IC_RESULT(ic),ic,FALSE);  
+    _G.accInUse--;
+    assignResultValue(IC_RESULT(ic), 0);
+  }
 
-       pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
+  pic16_freeAsmop(IC_RESULT(ic),NULL,ic,TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -12067,6 +12192,8 @@ void genpic16Code (iCode *lic)
            
        case SEND:
            addSet(&_G.sendSet,ic);
+            /* create a reversed list of SEND iCodes */
+//            addSetHead(&_G.sendSet, ic);
            break;
 
        case DUMMY_READ_VOLATILE:
@@ -12085,7 +12212,7 @@ void genpic16Code (iCode *lic)
       peepHole (&lineHead);
     }
     /* now do the actual printing */
-    printLine (lineHead,codeOutFile);
+    printLine (lineHead, codeOutFile);
 
 #ifdef PCODE_DEBUG
     DFPRINTF((stderr,"printing pBlock\n\n"));
index 33c0fa87277046a7918f3409e92cf014d4f212bf..50d83bb8a1b3b100191efa1646248632d5200728 100644 (file)
@@ -46,7 +46,8 @@ enum
     AOP_FSR0,
     AOP_FSR1,
     AOP_FSR2,
-    AOP_PCODE
+    AOP_PCODE,
+    AOP_STA            // asmop on stack
   };
 
 /* type asmop : a homogenised type for 
@@ -85,6 +86,10 @@ typedef struct asmop
        char *aop_str[4];       /* just a string array containing the location */
 /*     regs *aop_alloc_reg;     * points to a dynamically allocated register */
        pCodeOp *pcop;
+       struct {
+         int stk;
+         pCodeOp *pop[4];
+        } stk;
       }
     aopu;
   }
@@ -173,12 +178,13 @@ void pic16_genMinus (iCode *ic);
 pCodeOp *pic16_popGetLabel(unsigned int key);
 pCodeOp *pic16_popCopyReg(pCodeOpReg *pc);
 pCodeOp *pic16_popCopyGPR2Bit(pCodeOp *pc, int bitval);
-pCodeOp *pic16_popGetLit(unsigned int lit);
-pCodeOp *pic16_popGetLit2(unsigned int lit, pCodeOp *arg2);
+pCodeOp *pic16_popGetLit(int lit);
+pCodeOp *pic16_popGetLit2(int lit, pCodeOp *arg2);
 pCodeOp *popGetWithString(char *str);
 pCodeOp *pic16_popGet (asmop *aop, int offset);//, bool bit16, bool dname);
-pCodeOp *pic16_popGetTempReg(void);
-void pic16_popReleaseTempReg(pCodeOp *pcop);
+pCodeOp *pic16_popGetTempReg(int lock);
+pCodeOp *pic16_popGetTempRegCond(bitVect *, int lock);
+void pic16_popReleaseTempReg(pCodeOp *pcop, int lock);
 
 pCodeOp *pic16_popCombine2(pCodeOpReg *src, pCodeOpReg *dst, int noalloc);
 
index 0fad965e1ac49c7d29f4c84ede4629f958ab5024..81ef668107f2113b171fb7fc35890e9ad3eba339 100644 (file)
 #include "pcode.h"
 #include "gen.h"
 
+//#define D_POS(txt) DEBUGpic16_emitcode ("; TECODEV::: " txt, " (%s:%d (%s))", __FILE__, __LINE__, __FUNCTION__)
+
+#define D_POS(msg)     DEBUGpic16_emitcode("; ", msg, "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__)
+
 #if 1
 #define pic16_emitcode DEBUGpic16_emitcode
 #endif
@@ -74,6 +78,7 @@ const char *pic16_AopType(short type)
   case AOP_CRY:                return "AOP_CRY";
   case AOP_ACC:                return "AOP_ACC";
   case AOP_PCODE:      return "AOP_PCODE";
+  case AOP_STA:                return "AOP_STA";
   }
 
   return "BAD TYPE";
@@ -193,7 +198,7 @@ bool pic16_genPlusIncr (iCode *ic)
       //pic16_emitcode("incf","%s,f",pic16_aopGet(AOP(IC_RESULT(ic)),LSB,FALSE,FALSE));
 
       while(--size) {
-       emitSKPNZ;
+       emitSKPNC;
        pic16_emitpcode(POC_INCF, pic16_popGet(AOP(IC_RESULT(ic)),offset++));
        //pic16_emitcode(" incf","%s,f",pic16_aopGet(AOP(IC_RESULT(ic)),offset++,FALSE,FALSE));
       }
@@ -257,6 +262,8 @@ void pic16_outBitAcc(operand *result)
     /* if the result is a bit */
     DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
+    assert(0); // not implemented for PIC16?
+
     if (AOP_TYPE(result) == AOP_CRY){
         pic16_aopPut(AOP(result),"a",0);
     }
@@ -523,6 +530,14 @@ static void genAddLit (iCode *ic, int lit)
          pic16_emitpcode(POC_INCFSZW, pic16_popGet(AOP(result),0));
          pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),MSB16));
          pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),MSB16));
+         break;
+       default: /* 0x01LL */
+         D_POS("FIXED: added default case for adding 0x01??");
+         pic16_emitpcode(POC_MOVLW,pic16_popGetLit(lo));
+         pic16_emitpcode(POC_ADDWF,pic16_popGet(AOP(result),0));
+         emitSKPNC;
+         pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),MSB16));
+         pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),MSB16));
        }         
        break;
 
@@ -562,10 +577,11 @@ static void genAddLit (iCode *ic, int lit)
          genAddLit2byte (result, MSB16, hi);
          break;
        case 1:  /* 0xHH01 */
-         pic16_emitpcode(POC_MOVLW,pic16_popGetLit((hi+1)&0xff));
-         pic16_emitpcode(POC_INCFSZ, pic16_popGet(AOP(result),0));
+         D_POS(">>> IMPROVED");
+         pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),0));
          pic16_emitpcode(POC_MOVLW,pic16_popGetLit(hi));
-         pic16_emitpcode(POC_ADDWF,pic16_popGet(AOP(result),MSB16));
+         pic16_emitpcode(POC_ADDWFC,pic16_popGet(AOP(result),MSB16));
+         D_POS("<<< IMPROVED");
          break;
 /*     case 0xff: * 0xHHff *
          pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(result),0,FALSE,FALSE));
@@ -577,9 +593,9 @@ static void genAddLit (iCode *ic, int lit)
          pic16_emitpcode(POC_MOVLW,pic16_popGetLit(lo));
          pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(result),0));
          pic16_emitpcode(POC_MOVLW,pic16_popGetLit(hi));
-         emitSKPNC;
-         pic16_emitpcode(POC_MOVLW,pic16_popGetLit((hi+1) & 0xff));
-         pic16_emitpcode(POC_ADDWF,pic16_popGet(AOP(result),MSB16));
+         D_POS(">>> IMPROVED");
+         pic16_emitpcode(POC_ADDWFC,pic16_popGet(AOP(result),MSB16));
+         D_POS("<<< IMPROVED");
          break;
        }
 
@@ -596,40 +612,22 @@ static void genAddLit (iCode *ic, int lit)
        if(carry_info) {
          switch(lo) {
          case 0:
-           switch(carry_info) {
-           case 1:
-             emitSKPNZ;
-             pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),offset));
-             break;
-           case 2:
-             pic16_emitpcode(POC_RLCFW, pic16_popGet(AOP(result),offset));
-             pic16_emitpcode(POC_ANDLW, pic16_popGetLit(1));
-             pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(result),offset));
-             break;
-           default: /* carry_info = 3  */
-             emitSKPNC;
-             pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),offset));
-             carry_info = 1;
-             break;
-           }
+           D_POS(">>> IMPROVED and compacted");
+           emitSKPNC;
+           pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),offset));
+           D_POS("<<< IMPROVED and compacted");
            break;
          case 0xff:
            pic16_emitpcode(POC_MOVLW,pic16_popGetLit(lo));
-           if(carry_info==1) 
-             emitSKPZ;
-           else
-             emitSKPC;
+           D_POS(">>> Changed from SKPZ/SKPC to always SKPC");
+           emitSKPC;
            pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(result),offset));
            break;
          default:
+           D_POS(">>> IMPROVED and compacted");
            pic16_emitpcode(POC_MOVLW,pic16_popGetLit(lo));
-           if(carry_info==1) 
-             emitSKPNZ;
-           else
-             emitSKPNC;
-           pic16_emitpcode(POC_MOVLW,pic16_popGetLit(lo+1));
-           pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(result),offset));
-           carry_info=2;
+           pic16_emitpcode(POC_ADDWFC, pic16_popGet(AOP(result),offset));
+           D_POS("<<< IMPROVED and compacted");
            break;
          }
        }else {
@@ -705,8 +703,7 @@ static void genAddLit (iCode *ic, int lit)
        case 0:
          pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
          emitMOVWF(result, 0);
-         //pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),0,FALSE,FALSE));
-         emitMOVWF(result,0);
+         D_POS(">>> REMOVED double assignment");
          break;
        case 1:
          pic16_emitpcode(POC_INCFW, pic16_popGet(AOP(left),0));
@@ -750,25 +747,26 @@ static void genAddLit (iCode *ic, int lit)
 
            pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit & 0xff));
            pic16_emitpcode(POC_ADDFW,  pic16_popGet(AOP(left),offset));
-           pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(left),offset));
+           D_POS(">>> FIXED from left to result");
+           pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset));
+           D_POS("<<< FIXED from left to result");
 
            clear_carry = 0;
 
          } else {
+           D_POS(">>> FIXED");
            pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit & 0xff));
-           //pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset,FALSE,FALSE));
-           emitMOVWF(result,offset);
-           pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),offset));
-           emitSKPNC;
-           pic16_emitpcode(POC_INCFSZW,pic16_popGet(AOP(left),offset));
-           pic16_emitpcode(POC_ADDWF,  pic16_popGet(AOP(result),offset));
+           pic16_emitpcode(POC_ADDFWC, pic16_popGet(AOP(left),offset));
+           pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset));
+           D_POS("<<< FIXED");
          }
 
        } else {
+         D_POS(">>> IMPROVED");
          pic16_emitpcode(POC_CLRF,  pic16_popGet(AOP(result),offset));
-         pic16_emitpcode(POC_RLCF,  pic16_popGet(AOP(result),offset));
          pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),offset));
-         pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(result),offset));
+         pic16_emitpcode(POC_ADDWFC, pic16_popGet(AOP(result),offset));
+         D_POS("<<< IMPROVED");
        }
        offset++;
       }
@@ -924,7 +922,7 @@ void pic16_genPlus (iCode *ic)
                                pic16_emitcode(" incf","%s,f", pic16_aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
 
                        } else {
-
+                               emitCLRZ; // needed here as well: INCFW is not always executed, Z is undefined then
                                pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(IC_LEFT(ic)),0));
                                pic16_emitpcode(POC_BTFSC, pic16_popGet(AOP(IC_RIGHT(ic)),0));
                                pic16_emitpcode(POC_INCFW, pic16_popGet(AOP(IC_LEFT(ic)),0));
@@ -1014,7 +1012,9 @@ void pic16_genPlus (iCode *ic)
                                // right is signed, oh dear ...
                                for(i=size; i< AOP_SIZE(result); i++) {
                                        pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),i));
-                                       pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(result),size-1,FALSE,FALSE),7,0, PO_GPR_REGISTER));
+                                       D_POS(">>> FIXED sign test from result to right");
+                                       pic16_emitpcode(POC_BTFSC, pic16_newpCodeOpBit(pic16_aopGet(AOP(right),size-1,FALSE,FALSE),7,0, PO_GPR_REGISTER));
+                                       D_POS("<<< FIXED sign test from result to right");
                                        pic16_emitpcode(POC_COMF, pic16_popGet(AOP(result),i));
                                        pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(left),i));
                                        pic16_emitpcode(POC_ADDWFC, pic16_popGet(AOP(result),i));
@@ -1056,8 +1056,11 @@ void pic16_genPlus (iCode *ic)
                                                pic16_emitpcode(POC_CLRF, pic16_popCopyReg(&pic16_pc_wreg));
                                                pic16_emitpcode(POC_ADDWFC, pic16_popGet(AOP(left),i));
                                        } else { // not same
-                                               pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),i));
-                                               pic16_emitpcode(POC_ADDWFC, pic16_popGet(AOP(result),i));
+                                               D_POS (">>> FIXED added to uninitialized result");
+                                               pic16_emitpcode(POC_CLRF, pic16_popCopyReg(&pic16_pc_wreg));
+                                               pic16_emitpcode(POC_ADDFWC, pic16_popGet(AOP(left),i));
+                                               pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),i));
+                                               D_POS ("<<< FIXED");
                                        }
                                }
                        } else {
@@ -1417,7 +1420,8 @@ void pic16_genMinus (iCode *ic)
          if(AOP_TYPE(IC_RESULT(ic)) == AOP_CRY) {
            if (pic16_sameRegs(AOP(IC_RIGHT(ic)), AOP(IC_RESULT(ic))) ) {
              if(lit & 1) {
-               pic16_emitpcode(POC_MOVLW , pic16_popGet(AOP(IC_RIGHT(ic)),0));
+               D_POS(">>> FIXED from MOVLW right(=result) to MOVLW left(=literal,left&1==1)");
+               pic16_emitpcode(POC_MOVLW , pic16_popGetLit(1));
                pic16_emitpcode(POC_XORWF , pic16_popGet(AOP(IC_RIGHT(ic)),0));
              }
            }else{
@@ -1433,7 +1437,8 @@ void pic16_genMinus (iCode *ic)
            pic16_emitpcode(POC_MOVLW , pic16_popGetLit(lit & 0xff));
            pic16_emitpcode(POC_BTFSC , pic16_popGet(AOP(IC_RIGHT(ic)),0));
            pic16_emitpcode(POC_MOVLW , pic16_popGetLit((lit-1) & 0xff));
-           pic16_emitpcode(POC_MOVWF , pic16_popGet(AOP(IC_RESULT(ic)),0));
+           D_POS(">>> IMPROVED removed following assignment W-->result");
+           //pic16_emitpcode(POC_MOVWF , pic16_popGet(AOP(IC_RESULT(ic)),0));
 
          }
 
@@ -1473,8 +1478,9 @@ void pic16_genMinus (iCode *ic)
     if( (size == 1) && ((lit & 0xff) == 0) ) {
       /* res = 0 - right */
       if (pic16_sameRegs(AOP(IC_RIGHT(ic)), AOP(IC_RESULT(ic))) ) {
-       pic16_emitpcode(POC_COMF,  pic16_popGet(AOP(IC_RIGHT(ic)),0));
-       pic16_emitpcode(POC_INCF,  pic16_popGet(AOP(IC_RIGHT(ic)),0));
+       D_POS(">>> IMPROVED changed comf,incf to negf");
+       pic16_emitpcode(POC_NEGF,  pic16_popGet(AOP(IC_RIGHT(ic)),0));
+       D_POS("<<< IMPROVED changed comf,incf to negf");
       } else { 
        pic16_emitpcode(POC_COMFW,  pic16_popGet(AOP(IC_RIGHT(ic)),0));
        pic16_emitpcode(POC_MOVWF,  pic16_popGet(AOP(IC_RESULT(ic)),0));
@@ -1488,62 +1494,21 @@ void pic16_genMinus (iCode *ic)
     pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(IC_RESULT(ic)),0));
 
 
-    offset = 1;
+    offset = 0;
     while(--size) {
       lit >>= 8;
-
-      if(size == 1) {
-       /* This is the last byte in a multibyte subtraction 
-        * There are a couple of tricks we can do by not worrying about 
-        * propogating the carry */
-       if(lit == 0xff) {
-         /* 0xff - x == ~x */
-         if(same) {
-           pic16_emitpcode(POC_COMF,  pic16_popGet(AOP(IC_RESULT(ic)),offset));
-           emitSKPC;
-           pic16_emitpcode(POC_DECF,  pic16_popGet(AOP(IC_RESULT(ic)),offset));
-         } else {
-           pic16_emitpcode(POC_COMFW, pic16_popGet(AOP(IC_RIGHT(ic)),offset));
-           pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(IC_RESULT(ic)),offset));
-           emitSKPC;
-           pic16_emitpcode(POC_DECF,  pic16_popGet(AOP(IC_RESULT(ic)),offset));
-         }
-       } else {
-           pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(IC_RIGHT(ic)),offset));
-           emitSKPC;
-           pic16_emitpcode(POC_INCFW, pic16_popGet(AOP(IC_RIGHT(ic)),offset));
-           pic16_emitpcode(POC_SUBLW, pic16_popGetLit(lit & 0xff));
-           pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(IC_RESULT(ic)),offset));
-       }
-
-       goto release;
-      }
-
+      offset++;
+      D_POS(">>> FIXED and compacted");
       if(same) {
-
-       if(lit & 0xff) {
-         pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit & 0xff));
-         emitSKPC;
-         pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lit & 0xff)-1));
-         pic16_emitpcode(POC_SUBWF,  pic16_popGet(AOP(IC_RESULT(ic)),offset));
-       } else {
-         emitSKPNC;
-         pic16_emitpcode(POC_SUBWF,  pic16_popGet(AOP(IC_RESULT(ic)),offset));
-
-       }
+       // here we have x = lit - x   for sizeof(x)>1
+       pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit & 0xff));
+       pic16_emitpcode(POC_SUBFWB_D1,  pic16_popGet(AOP(IC_RESULT(ic)),offset));
       } else {
-
-       if(lit & 0xff) {
-         pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit & 0xff));
-         pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(IC_RESULT(ic)),offset));
-       } else
-         pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(IC_RESULT(ic)),offset));
-
-       pic16_emitpcode(POC_MOVFW,  pic16_popGet(AOP(IC_RIGHT(ic)),offset));
-       emitSKPC;
-       pic16_emitpcode(POC_INCFSZW,pic16_popGet(AOP(IC_RIGHT(ic)),offset));
-       pic16_emitpcode(POC_SUBWF,  pic16_popGet(AOP(IC_RESULT(ic)),offset));
+       pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit & 0xff));
+       pic16_emitpcode(POC_SUBFWB_D0,  pic16_popGet(AOP(IC_RIGHT(ic)),offset));
+       pic16_emitpcode(POC_MOVWF,  pic16_popGet(AOP(IC_RESULT(ic)),offset));
       }
+      D_POS("<<< FIXED and compacted");
     }
   
 
@@ -1558,16 +1523,10 @@ void pic16_genMinus (iCode *ic)
       DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
       pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(IC_RIGHT(ic)),0));
       pic16_emitpcode(POC_SUBLW, pic16_popGetLit(0));
-      pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(IC_RESULT(ic)),0));
+      if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
+       pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(IC_RESULT(ic)),0));
     } else {
 
-      if ( AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) {
-       pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(IC_RIGHT(ic)),0));
-       pic16_emitpcode(POC_SUBLW, pic16_popGetLit(0));
-       if ( AOP_TYPE(IC_RESULT(ic)) != AOP_ACC)
-         pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(IC_RESULT(ic)),0));
-      } else {
-
        DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
        if(AOP_TYPE(IC_RIGHT(ic)) != AOP_ACC) 
          pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(IC_RIGHT(ic)),0));
@@ -1590,7 +1549,6 @@ void pic16_genMinus (iCode *ic)
              pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(IC_RESULT(ic)),0));
          }
        }
-      }
     }
 
     /*
@@ -1607,15 +1565,17 @@ void pic16_genMinus (iCode *ic)
     size--;
 
     while(size--){
-      if (!pic16_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
-       pic16_emitpcode(POC_MOVFW,  pic16_popGet(AOP(IC_LEFT(ic)),offset));
+      if (pic16_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic)))) {
+       pic16_emitpcode(POC_MOVFW,  pic16_popGet(AOP(IC_RIGHT(ic)),offset));
+       D_POS(">>> IMPROVED by replacing emitSKPC, incfszw by subwfb");
+       pic16_emitpcode(POC_SUBWFB_D1,  pic16_popGet(AOP(IC_RESULT(ic)),offset));
+       D_POS("<<< IMPROVED by replacing emitSKPC, incfszw by subwfb");
+      } else {
+       D_POS(">>> FIXED for same regs right and result");
+       pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(IC_RIGHT(ic)),offset));
+       pic16_emitpcode(POC_SUBWFB_D0,  pic16_popGet(AOP(IC_LEFT(ic)),offset));
        pic16_emitpcode(POC_MOVWF,  pic16_popGet(AOP(IC_RESULT(ic)),offset));
-      }
-      pic16_emitpcode(POC_MOVFW,  pic16_popGet(AOP(IC_RIGHT(ic)),offset));
-      emitSKPC;
-      pic16_emitpcode(POC_INCFSZW,pic16_popGet(AOP(IC_RIGHT(ic)),offset));
-      pic16_emitpcode(POC_SUBWF,  pic16_popGet(AOP(IC_RESULT(ic)),offset));
-
+      }        
       offset++;
     }
 
@@ -1738,10 +1698,10 @@ void pic16_genUMult16XLit_16 (operand *left,
                        default: {
                                DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
-                               pct1 = pic16_popGetTempReg();
-                               pct2 = pic16_popGetTempReg();
-                               pct3 = pic16_popGetTempReg();
-                               pct4 = pic16_popGetTempReg();
+                               pct1 = pic16_popGetTempReg(1);
+                               pct2 = pic16_popGetTempReg(1);
+                               pct3 = pic16_popGetTempReg(1);
+                               pct4 = pic16_popGetTempReg(1);
 
                                pic16_emitpcode(POC_MOVLW, pic16_popGetLit( lit & 0xff));
                                pic16_emitpcode(POC_MULWF, pic16_popGet(AOP(left), 0));
@@ -1768,10 +1728,10 @@ void pic16_genUMult16XLit_16 (operand *left,
                                pic16_emitpcode(POC_ADDFWC, pic16_pCodeOpCopy(pct4));
                                pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 1));
 
-                               pic16_popReleaseTempReg( pct4 );
-                               pic16_popReleaseTempReg( pct3 );
-                               pic16_popReleaseTempReg( pct2 );
-                               pic16_popReleaseTempReg( pct1 );
+                               pic16_popReleaseTempReg(pct4,1);
+                               pic16_popReleaseTempReg(pct3,1);
+                               pic16_popReleaseTempReg(pct2,1);
+                               pic16_popReleaseTempReg(pct1,1);
                        }; return;
                }
        } else {
@@ -1911,10 +1871,10 @@ void pic16_genUMult16X16_16 (operand *left,
 
        if(pic16_sameRegs(AOP(result), AOP(left))) {
 
-               pct1 = pic16_popGetTempReg();
-               pct2 = pic16_popGetTempReg();
-               pct3 = pic16_popGetTempReg();
-               pct4 = pic16_popGetTempReg();
+               pct1 = pic16_popGetTempReg(1);
+               pct2 = pic16_popGetTempReg(1);
+               pct3 = pic16_popGetTempReg(1);
+               pct4 = pic16_popGetTempReg(1);
 
                pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), 0));
                pic16_emitpcode(POC_MULWF, pic16_popGet(AOP(right), 0));
@@ -1941,10 +1901,10 @@ void pic16_genUMult16X16_16 (operand *left,
                pic16_emitpcode(POC_ADDFWC, pic16_pCodeOpCopy(pct4));
                pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 1));
 
-               pic16_popReleaseTempReg( pct4 );
-               pic16_popReleaseTempReg( pct3 );
-               pic16_popReleaseTempReg( pct2 );
-               pic16_popReleaseTempReg( pct1 );
+               pic16_popReleaseTempReg( pct4, 1 );
+               pic16_popReleaseTempReg( pct3, 1 );
+               pic16_popReleaseTempReg( pct2, 1 );
+               pic16_popReleaseTempReg( pct1, 1 );
 
        } else {
 
@@ -2082,10 +2042,10 @@ void pic16_genUMult32XLit_32 (operand *left,
                        default: {
                                DEBUGpic16_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
-                               pct1 = pic16_popGetTempReg();
-                               pct2 = pic16_popGetTempReg();
-                               pct3 = pic16_popGetTempReg();
-                               pct4 = pic16_popGetTempReg();
+                               pct1 = pic16_popGetTempReg(1);
+                               pct2 = pic16_popGetTempReg(1);
+                               pct3 = pic16_popGetTempReg(1);
+                               pct4 = pic16_popGetTempReg(1);
 
                                pic16_emitpcode(POC_MOVLW, pic16_popGetLit( lit & 0xff));
                                pic16_emitpcode(POC_MULWF, pic16_popGet(AOP(left), 0));
@@ -2112,10 +2072,10 @@ void pic16_genUMult32XLit_32 (operand *left,
                                pic16_emitpcode(POC_ADDFWC, pic16_pCodeOpCopy(pct4));
                                pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 1));
 
-                               pic16_popReleaseTempReg( pct4 );
-                               pic16_popReleaseTempReg( pct3 );
-                               pic16_popReleaseTempReg( pct2 );
-                               pic16_popReleaseTempReg( pct1 );
+                               pic16_popReleaseTempReg( pct4, 1 );
+                               pic16_popReleaseTempReg( pct3, 1 );
+                               pic16_popReleaseTempReg( pct2, 1 );
+                               pic16_popReleaseTempReg( pct1, 1 );
                        }; return;
                }
        } else {
@@ -2190,10 +2150,10 @@ void pic16_genUMult32X32_32 (operand *left,
 
        if(pic16_sameRegs(AOP(result), AOP(left))) {
 
-               pct1 = pic16_popGetTempReg();
-               pct2 = pic16_popGetTempReg();
-               pct3 = pic16_popGetTempReg();
-               pct4 = pic16_popGetTempReg();
+               pct1 = pic16_popGetTempReg(1);
+               pct2 = pic16_popGetTempReg(1);
+               pct3 = pic16_popGetTempReg(1);
+               pct4 = pic16_popGetTempReg(1);
 
                pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), 0));
                pic16_emitpcode(POC_MULWF, pic16_popGet(AOP(right), 0));
@@ -2220,10 +2180,10 @@ void pic16_genUMult32X32_32 (operand *left,
                pic16_emitpcode(POC_ADDFWC, pic16_pCodeOpCopy(pct4));
                pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), 1));
 
-               pic16_popReleaseTempReg( pct4 );
-               pic16_popReleaseTempReg( pct3 );
-               pic16_popReleaseTempReg( pct2 );
-               pic16_popReleaseTempReg( pct1 );
+               pic16_popReleaseTempReg( pct4, 1 );
+               pic16_popReleaseTempReg( pct3, 1 );
+               pic16_popReleaseTempReg( pct2, 1 );
+               pic16_popReleaseTempReg( pct1, 1 );
 
        } else {
 
index 8992fe0bdcb561b34549f72dde99cf6380e775c0..ab5f75be5a57e5d2bfe6f5eb5c0ccdcf5ef499a8 100644 (file)
@@ -69,7 +69,7 @@
 void pic16_genNot (iCode *ic)
 {
   int size;
-  symbol *tlbl;
+//  symbol *tlbl;
 
 /*
  * result[AOP_CRY,AOP_REG]  = ! left[AOP_CRY, AOP_REG]
@@ -106,8 +106,6 @@ void pic16_genNot (iCode *ic)
 #endif
 
        pic16_toBoolean( IC_LEFT(ic) );
-       
-       tlbl = newiTempLabel(NULL);
        emitSETC;
        pic16_emitpcode(POC_TSTFSZ, pic16_popCopyReg( &pic16_pc_wreg ));
        emitCLRC;
@@ -299,6 +297,8 @@ void pic16_DumpAop(char *prefix, asmop *aop)
                DEBUGpic16_emitcode (";", " %s type:AOP_R1",prefix);
        if (aop->type == AOP_STK)
                DEBUGpic16_emitcode (";", " %s type:AOP_STK",prefix);
+       if (aop->type == AOP_STA)
+               DEBUGpic16_emitcode (";", " %s type:AOP_STA",prefix);
        if (aop->type == AOP_IMMD)
        {
                DEBUGpic16_emitcode (";", " %s type:AOP_IMMD",prefix);
index 93d4faf982947acb9663368983b9a55defa570d5..5e2ddab73c551e194966c434efab8b3d06a8a22d 100644 (file)
@@ -76,8 +76,6 @@ extern void initialComments (FILE * afile);
 extern void printPublics (FILE * afile);
 
 void  pic16_pCodeInitRegisters(void);
-pCodeOp *pic16_popGetLit(unsigned int lit);
-pCodeOp *pic16_popGetLit2(unsigned int lit, pCodeOp *arg2);
 pCodeOp *pic16_popCopyReg(pCodeOpReg *pc);
 extern void pic16_pCodeConstString(char *name, char *value);
 
@@ -298,8 +296,11 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                                          sectSym *ssym;
                                          int found=0;
                                  
+#if 0
                                                fprintf(stderr, "%s:%d sym->rname: %s reg: %p reg->name: %s\n", __FILE__, __LINE__,
                                                        sym->rname, reg, (reg?reg->name:"<<NULL>>"));
+#endif
+
 #if 1
                                                for(ssym=setFirstItem(sectSyms); ssym; ssym=setNextItem(sectSyms)) {
                                                        if(!strcmp(ssym->name, reg->name))found=1;
@@ -558,18 +559,27 @@ void pic16_printPointerType (const char *name, char ptype, void *p)
 /* printGPointerType - generates ival for generic pointer type     */
 /*-----------------------------------------------------------------*/
 void pic16_printGPointerType (const char *iname, const char *oname, const unsigned int itype,
-                   const unsigned int type, char ptype, void *p)
+  const unsigned int type, char ptype, void *p)
 {
-  _pic16_printPointerType (iname, ptype, p);
-
-  if(itype == FPOINTER || itype == CPOINTER) { // || itype == GPOINTER) {
-    char buf[256];
+  char buf[256];
+  
+    _pic16_printPointerType (iname, ptype, p);
 
-       sprintf(buf, "UPPER(%s)", iname);
-       pic16_emitDS(buf, ptype, p);
-  }
+    switch( itype ) {
+      case FPOINTER:
+      case CPOINTER:
+        {
+          sprintf(buf, "UPPER(%s)", iname);
+          pic16_emitDS(buf, ptype, p);
+        }; break;
+      case POINTER:
+      case IPOINTER:
+        sprintf(buf, "0x80");
+        pic16_emitDS(buf, ptype, p);
+        break;
+    }
 
-  pic16_flushDB(ptype, p);
+    pic16_flushDB(ptype, p);
 }
 
 
@@ -1055,7 +1065,9 @@ void pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char p
             pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
             pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
             pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
+            break;
         default:
+               fprintf(stderr, "%s:%d size = %d\n", __FILE__, __LINE__, getSize(type));
                assert(0);
         }
       return;
index 8810338312cf05149f124ddc807c4d43c4917b48..82904a1e5572351972719f6fe4a4fd17cbddb166 100644 (file)
@@ -100,41 +100,32 @@ extern void pic16_emitIDRegs(FILE *of);
 static void
 _pic16_init (void)
 {
-       asm_addTree (&asm_asxxxx_mapping);
-       pic16_pCodeInitRegisters();
-       maxInterrupts = 2;
-
-       /* set pic16 port options to defaults */
-       pic16_options.no_banksel = 0;
-       pic16_options.opt_banksel = 0;
-       pic16_options.omit_configw = 0;
-       pic16_options.omit_ivt = 0;
-       pic16_options.leave_reset = 0;
-       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;
+  asm_addTree (&asm_asxxxx_mapping);
+  pic16_pCodeInitRegisters();
+  maxInterrupts = 2;
 }
 
 static void
-_pic16_reset_regparm ()
+_pic16_reset_regparm (void)
 {
-       regParmFlg = 0;
+  regParmFlg = 0;
 }
 
 static int
 _pic16_regparm (sym_link * l)
 {
-       /* for this processor it is simple
-        * can pass only the first parameter in a register */
-       if(pic16_fstack) {
-               if(regParmFlg)return 0;
-               regParmFlg = 1;
-         return 1;
-       } else {
-               regParmFlg++;// = 1;
-         return 1;
-       }
+  /* force all parameters via SEND/RECEIVE */
+  if(0 /*pic16_options.ip_stack*/) {
+    /* for this processor it is simple
+     * can pass only the first parameter in a register */
+    if(regParmFlg)return 0;
+      regParmFlg++;
+      return 1;        //regParmFlg;
+  } else {
+    /* otherwise pass all arguments in registers via SEND/RECEIVE */
+    regParmFlg++;// = 1;
+    return regParmFlg;
+  }
 }
 
 
@@ -412,12 +403,14 @@ _pic16_parseOptions (int *pargc, char **argv, int *i)
   return FALSE;
 }
 
+extern set *userIncDirsSet;
+
 static void _pic16_initPaths(void)
 {
   char pic16incDir[512];
   char pic16libDir[512];
-  set *pic16incDirsSet;
-  set *pic16libDirsSet;
+  set *pic16incDirsSet=NULL;
+  set *pic16libDirsSet=NULL;
   char devlib[512];
 
     setMainValue("mcu", pic16->name[2] );
@@ -426,16 +419,22 @@ static void _pic16_initPaths(void)
     sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
     sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
 
+
     if(!options.nostdinc) {
       /* setup pic16 include directory */
       pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
-      mergeSets(&includeDirsSet, pic16incDirsSet);
+      includeDirsSet = pic16incDirsSet;
+//      mergeSets(&includeDirsSet, pic16incDirsSet);
     }
+    /* pic16 port should not search to the SDCC standard include directories,
+     * so add here the deleted include dirs that user has issued in command line */
+    mergeSets(&pic16incDirsSet, userIncDirsSet);
 
     if(!options.nostdlib) {
       /* setup pic16 library directory */
       pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir);
-      mergeSets(&libDirsSet, pic16libDirsSet);
+      libDirsSet = pic16libDirsSet;
+//      mergeSets(&libDirsSet, pic16libDirsSet);
     }
 
     if(!pic16_options.nodefaultlibs) {
@@ -520,8 +519,11 @@ _pic16_finaliseOptions (void)
       options.nopeep = 0;
 
     options.all_callee_saves = 1;              // always callee saves
-//    options.float_rent = 1;
-//    options.intlong_rent = 1;
+
+#if 0
+    options.float_rent = 1;
+    options.intlong_rent = 1;
+#endif
        
 
     if(alt_asm && strlen(alt_asm))
@@ -573,21 +575,26 @@ _pic16_finaliseOptions (void)
 static void
 _pic16_setDefaultOptions (void)
 {
-       /* initialize to defaults section locations, names and addresses */
-       pic16_sectioninfo.at_udata      = "udata";
-
-       /* set pic16 port options to defaults */
-       pic16_options.no_banksel = 0;
-       pic16_options.opt_banksel = 0;
-       pic16_options.omit_configw = 0;
-       pic16_options.omit_ivt = 0;
-       pic16_options.leave_reset = 0;
-       pic16_options.stack_model = 0;                  /* 0 for 'small', 1 for 'large' */
-       pic16_options.ivt_loc = 0x000000;
-       pic16_options.nodefaultlibs = 0;
-       pic16_options.dumpcalltree = 0;
-       pic16_options.crt_name = "crt0i.o";             /* the default crt to link */
-       pic16_options.no_crt = 0;                       /* use crt by default */
+  options.stackAuto = 0;               /* implicit declaration */
+  /* port is not capable yet to allocate separate registers 
+   * dedicated for passing certain parameters */
+  
+  /* initialize to defaults section locations, names and addresses */
+  pic16_sectioninfo.at_udata   = "udata";
+
+  /* set pic16 port options to defaults */
+  pic16_options.no_banksel = 0;
+  pic16_options.opt_banksel = 0;
+  pic16_options.omit_configw = 0;
+  pic16_options.omit_ivt = 0;
+  pic16_options.leave_reset = 0;
+  pic16_options.stack_model = 0;                       /* 0 for 'small', 1 for 'large' */
+  pic16_options.ivt_loc = 0x000000;
+  pic16_options.nodefaultlibs = 0;
+  pic16_options.dumpcalltree = 0;
+  pic16_options.crt_name = "crt0i.o";          /* the default crt to link */
+  pic16_options.no_crt = 0;                    /* use crt by default */
+  pic16_options.ip_stack = 1;          /* set to 1 to enable ipop/ipush for stack */
 }
 
 static const char *
@@ -820,7 +827,7 @@ PORT pic16_port =
     4,         /* long */
     2,         /* ptr */
     3,         /* fptr, far pointers (see Microchip) */
-    2,         /* gptr */
+    3,         /* gptr */
     1,         /* bit */
     4,         /* float */
     4          /* max */
index cb0b8c43bb318a242612f0bf133de60d50288828..d4324d2dd3b4a8e68430ee2be9ddf832eefbe9de 100644 (file)
@@ -3863,11 +3863,13 @@ pCodeOp *pic16_newpCodeOpLit(int lit)
   pcop->type = PO_LITERAL;
 
   pcop->name = NULL;
-  if(lit>=0) {
-    sprintf(s,"0x%02x",lit);
-    if(s)
-      pcop->name = Safe_strdup(s);
-  }
+//  if(lit>=0)
+    sprintf(s,"0x%02hhx",(char)(lit));
+//  else
+//    sprintf(s, "%i", lit);
+  
+  if(s)
+    pcop->name = Safe_strdup(s);
 
   ((pCodeOpLit *)pcop)->lit = lit;
 
@@ -4707,7 +4709,7 @@ char *pic16_pCode2str(char *str, size_t size, pCode *pc)
        if(isPCI(pc) && (PCI(pc)->pci_magic != PCI_MAGIC)) {
                fprintf(stderr, "%s:%d: pCodeInstruction initialization error in instruction %s, magic is %x (defaut: %x)\n",
                        __FILE__, __LINE__, PCI(pc)->mnemonic, PCI(pc)->pci_magic, PCI_MAGIC);
-               exit(-1);
+//             exit(-1);
        }
 #endif
 
@@ -6107,7 +6109,7 @@ static void insertBankSwitch(unsigned char position, pCode *pc)
                                len = sizeof(pCodeInstruction) - ofs1 - sizeof( char const * const *);
                                ofs1 += strlen( PCI(pcprev)->mnemonic) + 1;
                                ofs2 += strlen( PCI(npci)->mnemonic) + 1;
-                               memcpy(&PCI(npci)->from, &PCI(pcprev)->from, (unsigned int)(&(PCI(npci)->pci_magic)) - (unsigned int)(&(PCI(npci)->from)));
+                               memcpy(&PCI(npci)->from, &PCI(pcprev)->from, (char *)(&(PCI(npci)->pci_magic)) - (char *)(&(PCI(npci)->from)));
                                PCI(npci)->op = PCI(pcprev)->inverted_op;
                                
                                /* unlink old pCode */
@@ -6118,7 +6120,7 @@ static void insertBankSwitch(unsigned char position, pCode *pc)
                                
                                /* extra instructions to handle invertion */
                                pcnext = pic16_newpCode(POC_GOTO, pic16_popGetLabel(tlbl->key));
-                               pic16_pCodeInsertAfter(pc->prev, pcnext);
+                               pic16_pCodeInsertAfter(npci, pcnext);
                                pic16_pCodeInsertAfter(pc->prev, new_pc);
                                
                                pcnext = pic16_newpCodeLabel(NULL,tlbl->key+100+pic16_labelOffset);
index e60068b8b808652ea3cba8ae688f586e74b2db76..7be49b9add1cc4dfa78a036667f4bd2b46ff437e 100644 (file)
@@ -1907,7 +1907,8 @@ static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 
       /* Compare the operands */
       if(PCI(pcd)->pcop) {
-       if (PCI(pcd)->pcop->type == PO_WILD) {
+       /* assert that optimizations do not touch operations that work on SFRs or INDF registers */
+       if ((PCI(pcd)->pcop->type == PO_WILD) && (!(PCI(pcs)->pcop) || ((PCI(pcs)->pcop->type != PO_SFR_REGISTER) && (PCI(pcs)->pcop->type != PO_INDF0)))) {
          index = PCOW(PCI(pcd)->pcop)->id;
          //DFPRINTF((stderr,"destination is wild\n"));
 #ifdef DEBUG_PCODEPEEP
@@ -1961,9 +1962,10 @@ static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 //           return 1;
            }
          }
-  
+
          /* now check whether the second operand matches */
-         if(PCOW2(PCI(pcd)->pcop) && (PCOR2(PCI(pcd)->pcop)->pcop2->type == PO_WILD)) {
+         /* assert that optimizations do not touch operations that work on SFRs or INDF registers */
+         if(PCOW2(PCI(pcd)->pcop) && (PCOR2(PCI(pcd)->pcop)->pcop2->type == PO_WILD) && (!(PCOR2(PCI(pcs)->pcop)->pcop2) || ((PCOR2(PCI(pcs)->pcop)->pcop2->type != PO_SFR_REGISTER) && (PCOR2(PCI(pcs)->pcop)->pcop2) && (PCOR2(PCI(pcs)->pcop)->pcop2->type != PO_INDF0)))) {
        
 //             fprintf(stderr, "%s:%d %s second operand is wild\n", __FILE__, __LINE__, __FUNCTION__);
        
@@ -2018,11 +2020,16 @@ static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
                        }
                }
          
-       } else return (havematch);
+         } else if (PCOW2(PCI(pcd)->pcop) && (PCOR2(PCI(pcd)->pcop)->pcop2->type == PO_WILD) && PCOR2(PCI(pcs)->pcop)->pcop2)
+           {
+             return 0;
+           } else {
+             return havematch;
+           }
 #if 0
         else if (PCI(pcd)->pcop->type == PO_LITERAL) {
          return (havematch &&
-               pCodeOpCompare(PCOR2(PCI(pcs)->pcop)->pcop2, PCOR2(PCI(pcd)->pcop)->pcop2);
+               pCodeOpCompare(PCOR2(PCI(pcs)->pcop)->pcop2, PCOR2(PCI(pcd)->pcop)->pcop2));
 
        }
 #endif
index 511e2efb5c557b5bd1fb5eb7109f6cf4e6b523a1..e904c3c4d804b5d0b9437d3c274801e3b19945a5 100644 (file)
@@ -285,3 +285,9 @@ replace restart {
         movf    %1,w
 }
 
+replace restart {
+        movff   %1,%1
+} by {
+        ;     peep 12 - Removed redundant move
+}
+
index 3e6c3f03a28a04749418e26b194c3db6bfcf797d..0fec45041ddb85bb4eeb038038336b8081022444 100644 (file)
@@ -516,7 +516,7 @@ allocReg (short type)
 
        reg->isFree=0;
 
-//     debugLog ("%s of type %s for register rIdx: %d\n", __FUNCTION__, debugLogRegType (type), dynrIdx-1);
+       debugLog ("%s of type %s for register rIdx: %d (0x%x)\n", __FUNCTION__, debugLogRegType (type), dynrIdx-1, 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);
@@ -752,7 +752,8 @@ pic16_allocDirReg (operand *op )
                return NULL;
        }
 
-
+       if(IS_ITEMP(op))return NULL;
+       
        debugLog ("%s:%d symbol name %s\n", __FUNCTION__, __LINE__, name);
 //     fprintf(stderr, "%s symbol name %s\n", __FUNCTION__,name);
 
@@ -803,10 +804,12 @@ pic16_allocDirReg (operand *op )
                }
 
 
+#if 0
                if(OP_SYMBOL(op)->onStack) {
                        fprintf(stderr, "%s:%d onStack %s offset: %d\n", __FILE__, __LINE__,
                                OP_SYMBOL(op)->name, OP_SYMBOL(op)->stack);
                }
+#endif
 
                if(!IN_DIRSPACE( SPEC_OCLS( OP_SYM_ETYPE(op)))
                        || !IN_FARSPACE(SPEC_OCLS( OP_SYM_ETYPE(op))) ) {
@@ -4147,9 +4150,10 @@ pic16_assignRegisters (eBBlock ** ebbs, int count)
   /* and serially allocate registers */
   serialRegAssign (ebbs, count);
 
-//  debugLog ("ebbs after serialRegAssign:\n");
-//  dumpEbbsToDebug (ebbs, count);
-
+#if 0
+  debugLog ("ebbs after serialRegAssign:\n");
+  dumpEbbsToDebug (ebbs, count);
+#endif
 
   //pic16_freeAllRegs();
 
index b7a1d06d1dc95008a77d8ea3337dbbe6b3550dc9..3d21e903976f3463e909c8dbb28f0052df7bd53e 100644 (file)
@@ -1,7 +1,7 @@
 BEGIN {
 print "/*"
 print " * version.h"
-print " * controllong build version number"
+print " * control long build version number"
 print " *"
 print " * Created automatically with version.awk script"
 print " *"
index cc3e98a4279a5b461b149e43bbce40f860f47192..2bdf092de38011faf3fb423db623f9e3f48ee9b3 100644 (file)
@@ -414,6 +414,9 @@ struct
    "previously defined here" },
 { W_SIZEOF_VOID, ERROR_LEVEL_WARNING,
    "size of void is zero" },
+{ W_POSSBUG2, ERROR_LEVEL_WARNING,
+   "possible code generation error at %s line %d,\n"
+   " please report problem and send source code at SDCC-USER list on SF.Net"},
 };
 
 /*
index 1233f5a824c32632a85dcf4b91463122a86df3ba..92abb906069363fe2b71d58d7d8fdf21472f7864 100644 (file)
@@ -194,6 +194,7 @@ SDCCERR - SDCC Standard error handler
 #define E_SIZEOF_INCOMPLETE_TYPE      176 /* sizeof applied to an incomplete type */
 #define E_PREVIOUS_DEF                177 /* previously defined here */
 #define W_SIZEOF_VOID                 178 /* size of void is zero */
+#define W_POSSBUG2                    179 /* possible bug, new format */
 
 #define MAX_ERROR_WARNING             256 /* size of disable warnings array */