From abd216098cbe5b77a209f6935822ab0237cf500a Mon Sep 17 00:00:00 2001 From: tecodev Date: Mon, 1 Sep 2008 17:02:23 +0000 Subject: [PATCH] * src/pic16/gen.c (pic16_derefPtr): handle CPOINTERs as well * (genConstPointerGet): fix reading bitfields from __code space * src/pic16/glue.c (pic16_printIvalBitFields): correctly mask bitfield initializers (fix regression test bug1856409.c) * (pic16_printIvalCharPtr,pic16_printIvalPtr): generalized to support arbitrary sizes git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5228 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 9 ++++++++ src/pic16/gen.c | 34 +++++++++++++++++++++++++++- src/pic16/glue.c | 59 ++++++++++++++---------------------------------- 3 files changed, 59 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6fb756ed..894ad907 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-09-01 Raphael Neider + + * src/pic16/gen.c (pic16_derefPtr): handle CPOINTERs as well + * (genConstPointerGet): fix reading bitfields from __code space + * src/pic16/glue.c (pic16_printIvalBitFields): correctly mask + bitfield initializers (fix regression test bug1856409.c) + * (pic16_printIvalCharPtr,pic16_printIvalPtr): generalized to support + arbitrary sizes + 2008-08-31 Raphael Neider * src/pic16/gen.c (genAssign): removed useless compiler output diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 1786aa49..7edff7f4 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -7928,8 +7928,10 @@ static void pic16_derefPtr (operand *ptr, int p_type, int doWrite, int *fsr0_set p_type = DCL_TYPE(operandType(ptr)); switch (p_type) { - case FPOINTER: case POINTER: + case FPOINTER: + case IPOINTER: + case PPOINTER: if (!fsr0_setup || !*fsr0_setup) { pic16_loadFSR0( ptr, 0 ); @@ -7963,6 +7965,29 @@ static void pic16_derefPtr (operand *ptr, int p_type, int doWrite, int *fsr0_set } break; + case CPOINTER: + /* XXX: Writing to CPOINTERs not (yet) implemented. */ + assert ( !doWrite && "Cannot write into __code space!" ); + if( (AOP_TYPE(ptr) == AOP_PCODE) + && ((AOP(ptr)->aopu.pcop->type == PO_IMMEDIATE) + || (AOP(ptr)->aopu.pcop->type == PO_DIR))) + { + pic16_emitpcode(POC_MOVLW, pic16_popGet (AOP (ptr), 0)); + pic16_emitpcode(POC_MOVWF, pic16_popCopyReg (&pic16_pc_tblptrl)); + pic16_emitpcode(POC_MOVLW, pic16_popGet (AOP (ptr), 1)); + pic16_emitpcode(POC_MOVWF, pic16_popCopyReg (&pic16_pc_tblptrh)); + pic16_emitpcode(POC_MOVLW, pic16_popGet (AOP (ptr), 2)); + pic16_emitpcode(POC_MOVWF, pic16_popCopyReg (&pic16_pc_tblptru)); + } else { + mov2fp(pic16_popCopyReg(&pic16_pc_tblptrl), AOP(ptr), 0); + mov2fp(pic16_popCopyReg(&pic16_pc_tblptrh), AOP(ptr), 1); + mov2fp(pic16_popCopyReg(&pic16_pc_tblptru), AOP(ptr), 2); + } // if + + pic16_emitpcodeNULLop (POC_TBLRD_POSTINC); + pic16_emitpcode (POC_MOVFW, pic16_popCopyReg (&pic16_pc_tablat)); + break; + default: assert (0 && "invalid pointer type specified"); break; @@ -8318,6 +8343,12 @@ static void genConstPointerGet (operand *left, pic16_aopOp(result,ic,TRUE); size = AOP_SIZE(result); + /* if bit then unpack */ + if (IS_BITFIELD(getSpec (operandType (left)))) { + genUnpackBits(result,left,"BAD",GPOINTER); + goto release; + } // if + DEBUGpic16_pic16_AopType(__LINE__,left,NULL,result); DEBUGpic16_emitcode ("; "," %d getting const pointer",__LINE__); @@ -8345,6 +8376,7 @@ static void genConstPointerGet (operand *left, offset++; } +release: pic16_freeAsmop(left,NULL,ic,TRUE); pic16_freeAsmop(result,NULL,ic,TRUE); } diff --git a/src/pic16/glue.c b/src/pic16/glue.c index 1a7adf3b..d75dd6d6 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -802,7 +802,7 @@ pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *p) size = ((SPEC_BLEN (lsym->etype) / 8) + (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0)); } - i = ulFromVal (val); + i = (ulFromVal (val) & ((1ul << SPEC_BLEN (lsym->etype)) - 1ul)); i <<= SPEC_BSTR (lsym->etype); ival |= i; if (! ( lsym->next && @@ -916,6 +916,7 @@ static int pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char ptype, void *p) { int size = 0; + int i; /* PENDING: this is _very_ mcs51 specific, including a magic number... @@ -961,24 +962,10 @@ pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char ptype, else { // these are literals assigned to pointers - switch (size) + for (i = 0; i < size; i++) { - case 1: - pic16_emitDB(pic16aopLiteral(val, 0), ptype, p); - break; - case 2: - pic16_emitDB(pic16aopLiteral(val, 0), ptype, p); - pic16_emitDB(pic16aopLiteral(val, 1), ptype, p); - break; - case 3: - pic16_emitDB(pic16aopLiteral(val, 0), ptype, p); - pic16_emitDB(pic16aopLiteral(val, 1), ptype, p); - pic16_emitDB(pic16aopLiteral(val, 2), ptype, p); - break; - - default: - assert (0); - } + pic16_emitDB(pic16aopLiteral(val, i), ptype, p); + } // for } if (val->sym && val->sym->isstrlit) { // && !isinSet(statsg->syms, val->sym)) { @@ -1060,6 +1047,7 @@ pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char ptype, { value *val; int size; + int i; #if 0 fprintf(stderr, "%s:%d initialising pointer: %s size: %d\n", __FILE__, __LINE__, @@ -1091,49 +1079,36 @@ pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char ptype, printFromToType (val->type, type); } + size = getSize (type); + /* if val is literal */ if (IS_LITERAL (val->etype)) { - switch (getSize (type)) + for (i = 0; i < size; i++) { - case 1: - pic16_emitDB((unsigned int) ulFromVal (val) & 0xff, ptype, p); - break; - case 2: - pic16_emitDB(pic16aopLiteral(val, 0), ptype, p); - pic16_emitDB(pic16aopLiteral(val, 1), ptype, p); - break; - case 3: - 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); - } + pic16_emitDB(pic16aopLiteral(val, i), ptype, p); + } // for return; } - - size = getSize (type); - if (size == 1) /* Z80 specific?? */ { pic16_emitDS(val->name, ptype, p); } else if (size == 2) { - pic16_printPointerType (val->name, ptype, p); + pic16_printPointerType (val->name, ptype, p); } else if (size == 3) { int itype = 0; itype = PTR_TYPE (SPEC_OCLS (val->etype)); pic16_printGPointerType (val->name, itype, ptype, p); - } else - assert(0); - return; + } + else + { + assert(0); + } } -- 2.30.2