From: tecodev Date: Wed, 2 Feb 2005 21:53:55 +0000 (+0000) Subject: * src/SDCCast.c (processParms): disabled W_NONRENT_ARGS for pic16 port X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=9182d601aa287fff2b037d607180a06bcf0b281b;p=fw%2Fsdcc * src/SDCCast.c (processParms): disabled W_NONRENT_ARGS for pic16 port * src/pic16/gen.c (aopForSym): reenabled special case for function pointers * (pic16_storeForReturn): fixed to allow returning function pointers * (genPackBits): improved accessing full bytes, implemented for GPOINTERs * device/include/pic16/{stddef.h,stdbool.h}: added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3669 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 12b44a83..8ec68dd6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-02-02 Raphael Neider + + * src/SDCCast.c (processParms): disabled W_NONRENT_ARGS for pic16 port + * src/pic16/gen.c (aopForSym): reenabled special case for function pointers + * (pic16_storeForReturn): fixed to allow returning function pointers + * (genPackBits): improved accessing full bytes, implemented for GPOINTERs + * device/include/pic16/{stddef.h,stdbool.h}: added + 2004-02-02 Maarten Brock * device/include/mcs51/c8051f040.h: added define CPT2_PAGE diff --git a/device/include/pic16/stdbool.h b/device/include/pic16/stdbool.h new file mode 100644 index 00000000..b4b3d424 --- /dev/null +++ b/device/include/pic16/stdbool.h @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + stdbool.h - ANSI functions forward declarations + + Ported to PIC16 port by Raphael Neider 2005 (RNeider@web.de) + + Written By - Maarten Brock, sourceforge.brock@dse.nl (2004) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------*/ + +/* +** $Id$ +*/ + +#ifndef __PIC16_STDBOOL_H +#define __PIC16_STDBOOL_H 1 + +#define _Bool unsigned char + +#define bool _Bool +#define true 1 +#define false 0 +#define __bool_true_false_are_defined 1 + +#define BOOL unsigned char + +#endif /* __PIC16_STDBOOL_H */ diff --git a/device/include/pic16/stddef.h b/device/include/pic16/stddef.h new file mode 100644 index 00000000..196fbc7f --- /dev/null +++ b/device/include/pic16/stddef.h @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + stddef.h - ANSI functions forward declarations + + Ported to PIC16 port by Raphael Neider, 2005 (rneider@web.de) + + Written By - Maarten Brock / sourceforge.brock@dse.nl (June 2004) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------*/ + +/* +** $Id$ +*/ + +#ifndef __PIC16_STDDEF_H +#define __PIC16_STDDEF_H 1 + +#ifndef NULL + #define NULL (void *)0 +#endif + +#ifndef _SIZE_T_DEFINED +#define _SIZE_T_DEFINED + typedef unsigned int size_t; +#endif + +#define offsetof(s,m) (size_t)&(((s *)0)->m) + +#endif /* __PIC16_STDDEF_H */ diff --git a/src/SDCCast.c b/src/SDCCast.c index 206e5bfe..84a6c7f1 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -693,11 +693,15 @@ processParms (ast *func, /* if the function is being called via a pointer & */ /* it has not been defined a reentrant then we cannot */ /* have parameters */ - if (func->type != EX_VALUE && !IFFUNC_ISREENT (functype) && !options.stackAuto) + /* PIC16 port can... */ + if (!TARGET_IS_PIC16) { - werror (W_NONRENT_ARGS); - fatalError++; - return 1; + if (func->type != EX_VALUE && !IFFUNC_ISREENT (functype) && !options.stackAuto) + { + werror (W_NONRENT_ARGS); + fatalError++; + return 1; + } } /* if defined parameters ended but actual parameters */ diff --git a/src/pic16/gen.c b/src/pic16/gen.c index ee85154d..0a15d8cf 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -797,7 +797,7 @@ static asmop *aopForSym (iCode *ic, operand *op, bool result) } #endif -#if 0 +#if 1 /* special case for a function */ if (IS_FUNC(sym->type)) { sym->aop = aop = newAsmop(AOP_PCODE); @@ -869,8 +869,8 @@ static asmop *aopForSym (iCode *ic, operand *op, bool result) aop->size = PTRSIZE; else if(IN_CODESPACE( space ) || IN_FARSPACE( space )) 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 if(IC_LEFT(ic) && AOP(IC_LEFT(ic))) aop->size = AOP_SIZE( IC_LEFT(ic) ); + else if(IC_RIGHT(ic) && AOP(IC_RIGHT(ic))) aop->size = AOP_SIZE( IC_RIGHT(ic) ); else if(sym->onStack) { aop->size = PTRSIZE; } else { @@ -3897,8 +3897,25 @@ static void genEndFunction (iCode *ic) void pic16_storeForReturn(operand *op, int offset, pCodeOp *dest) { - if(is_LitOp(op)) { - unsigned long lit = (unsigned long)floatFromVal(AOP(op)->aopu.aop_lit); + unsigned long lit=1; + + // this fails for is_LitOp(op) (if op is an AOP_PCODE) + if(AOP_TYPE(op) == AOP_LIT) { + if(!IS_FLOAT(operandType( op ))) { + lit = (unsigned long)floatFromVal(AOP(op)->aopu.aop_lit); + } else { + union { + unsigned long lit_int; + float lit_float; + } info; + + /* take care if literal is a float */ + info.lit_float = floatFromVal(AOP(op)->aopu.aop_lit); + lit = info.lit_int; + } + } + + if (is_LitOp(op)) { if(lit == 0) { pic16_emitpcode(POC_CLRF, dest); } else { @@ -11800,39 +11817,106 @@ static void genPackBits (sym_link *etype , operand *result, } else pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), offset++)); - /* if the bit lenth is less than or */ + /* if the bit length is less than or */ /* it exactly fits a byte then */ if((shCnt=SPEC_BSTR(etype)) || SPEC_BLEN(etype) <= 8 ) { + int fsr0_setup = 0; - pic16_emitpcode(POC_ANDLW, pic16_popGetLit((1U << blen)-1)); + if (blen != 8 || bstr != 0) { + // we need to combine the value with the old value + pic16_emitpcode(POC_ANDLW, pic16_popGetLit((1U << blen)-1)); - /* shift left acc */ - AccLsh(shCnt); + /* shift left acc */ + AccLsh(shCnt); - /* using PRODL as a temporary register here */ - pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_prodl)); + /* using PRODH as a temporary register here */ + pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_prodh)); - switch (p_type) { + /* get old value */ + switch (p_type) { case FPOINTER: case POINTER: pic16_loadFSR0( result ); + fsr0_setup = 1; pic16_emitpcode(POC_MOVFW, pic16_popCopyReg(&pic16_pc_indf0)); // pic16_emitcode ("mov","b,a"); // pic16_emitcode("mov","a,@%s",rname); break; case GPOINTER: - werror(W_POSSBUG2, __FILE__, __LINE__); + if (AOP(result)->aopu.aop_reg[2]) { + // prepare call to __gptrget1, this is actually genGenPointerGet(result, WREG, ?ic?) + 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_prodl))); + pic16_emitpcode (POC_MOVFW, pic16_popGet(AOP(result),2)); + pic16_emitpcode (POC_CALL, pic16_popGetWithString ("__gptrget1")); + { + symbol *sym; + sym = newSymbol( "__gptrget1", 0 ); + strcpy(sym->rname, "__gptrget1"); + checkAddSym(&externs, sym); + } + } else { + // data pointer (just 2 byte given) + pic16_loadFSR0( result ); + fsr0_setup = 1; + pic16_emitpcode(POC_MOVFW, pic16_popCopyReg(&pic16_pc_indf0)); + } + + // warnings will be emitted below + //pic16_emitpcomment ("; =?= genPackBits, GPOINTER..."); + //werror(W_POSSBUG2, __FILE__, __LINE__); break; - } + default: + assert (0 && "invalid pointer type specified"); + break; + } #if 1 - pic16_emitpcode(POC_ANDLW, pic16_popGetLit( + pic16_emitpcode(POC_ANDLW, pic16_popGetLit( (unsigned char)((unsigned char)(0xff << (blen+bstr)) | (unsigned char)(0xff >> (8-bstr))) )); - pic16_emitpcode(POC_IORFW, pic16_popCopyReg(&pic16_pc_prodl)); - pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_indf0)); + pic16_emitpcode(POC_IORFW, pic16_popCopyReg(&pic16_pc_prodh)); + } // if (blen != 8 || bstr != 0) + + /* write new value back */ + switch (p_type) { + case FPOINTER: + case POINTER: + if (!fsr0_setup) pic16_loadFSR0( result ); + pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_indf0)); + break; + + case GPOINTER: + if (AOP(result)->aopu.aop_reg[2]) { + // prepare call to __gptrset1, this is actually genGenPointerSet(WREG, result, ?ic?) + pic16_emitpcode (POC_MOVWF, pic16_popCopyReg (pic16_stack_postdec/*pic16_pc_postdec1*/)); + 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_prodl))); + pic16_emitpcode (POC_MOVFW, pic16_popGet(AOP(result),2)); + pic16_emitpcode (POC_CALL, pic16_popGetWithString ("__gptrput1")); + { + symbol *sym; + sym = newSymbol( "__gptrput1", 0 ); + strcpy(sym->rname, "__gptrput1"); + checkAddSym(&externs, sym); + } + } else { + // data pointer (just 2 byte given) + if (!fsr0_setup) pic16_loadFSR0( result ); + pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_indf0)); + } + + // this should work in all cases (as soon as gptrget/gptrput work on EEPROM and PROGRAM MEMORY) + //pic16_emitpcomment ("; =?= genPackBits, GPOINTER access"); + werror(W_POSSBUG2, __FILE__, __LINE__); + break; + + default: + assert (0 && "invalid pointer type specified"); + break; + } #endif return;