/*-----------------------------------------------------------------*/
/* pic16_initPointer - pointer initialization code massaging */
/*-----------------------------------------------------------------*/
-value *pic16_initPointer (initList * ilist, sym_link *toType)
+static value *
+pic16_initPointer (initList * ilist, sym_link *toType)
{
value *val;
ast *expr;
/*-----------------------------------------------------------------*/
/* printPointerType - generates ival for pointer type */
/*-----------------------------------------------------------------*/
-void _pic16_printPointerType (const char *name, char ptype, void *p)
+static void
+_pic16_printPointerType (const char *name, char ptype, void *p)
{
char buf[256];
/*-----------------------------------------------------------------*/
/* printPointerType - generates ival for pointer type */
/*-----------------------------------------------------------------*/
-void pic16_printPointerType (const char *name, char ptype, void *p)
+static void
+pic16_printPointerType (const char *name, char ptype, void *p)
{
_pic16_printPointerType (name, ptype, p);
//pic16_flushDB(ptype, p); /* breaks char* const arr[] = {&c, &c, &c}; */
/*-----------------------------------------------------------------*/
/* printGPointerType - generates ival for generic pointer type */
/*-----------------------------------------------------------------*/
-void pic16_printGPointerType (const char *iname, const unsigned int itype,
+static void
+pic16_printGPointerType (const char *iname, const unsigned int itype,
char ptype, void *p)
{
char buf[256];
switch (itype)
{
- case CPOINTER:
- case FUNCTION:
+ case CPOINTER: /* fall through */
+ case FUNCTION: /* fall through */
+ case GPOINTER:
+ /* GPTRs pointing to __data space should be reported as POINTERs */
sprintf (buf, "UPPER(%s)", iname);
pic16_emitDS (buf, ptype, p);
break;
- case GPOINTER:
- case POINTER:
- sprintf (buf, "0x80");
+ case POINTER: /* __data space */
+ sprintf (buf, "0x%02x", GPTR_TAG_DATA);
pic16_emitDS (buf, ptype, p);
break;
assert (0);
}
+ if (itype == GPOINTER) {
+ fprintf(stderr, "%s: initialized generic pointer with unknown storage class assumes object in code space\n", __func__);
+ }
+
//pic16_flushDB(ptype, p); /* might break char* const arr[] = {...}; */
}
/*-----------------------------------------------------------------*/
/* pic16_printIvalBitFields - generate initializer for bitfields */
/*-----------------------------------------------------------------*/
-void pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *p)
+static void
+pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *p)
{
value *val ;
symbol *lsym = *sym;
/*-----------------------------------------------------------------*/
/* printIvalStruct - generates initial value for structures */
/*-----------------------------------------------------------------*/
-void pic16_printIvalStruct (symbol * sym, sym_link * type,
+static void
+pic16_printIvalStruct (symbol * sym, sym_link * type,
initList * ilist, char ptype, void *p)
{
symbol *sflds;
/*-----------------------------------------------------------------*/
/* printIvalUnion - generates initial value for unions */
/*-----------------------------------------------------------------*/
-void pic16_printIvalUnion (symbol * sym, sym_link * type,
+static void
+pic16_printIvalUnion (symbol * sym, sym_link * type,
initList * ilist, char ptype, void *p)
{
//symbol *sflds;
/*--------------------------------------------------------------------------*/
/* pic16_printIvalCharPtr - generates initial values for character pointers */
/*--------------------------------------------------------------------------*/
-int pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char ptype, void *p)
+static int
+pic16_printIvalCharPtr (symbol * sym, sym_link * type, value * val, char ptype, void *p)
{
int size = 0;
else if (size == 3)
{
int type;
- if (IS_PTR (val->type)) {
- type = DCL_TYPE (val->type);
- } else {
- type = PTR_TYPE (SPEC_OCLS (val->etype));
- }
+ type = PTR_TYPE (SPEC_OCLS (val->etype));
if (val->sym && val->sym->isstrlit) {
// this is a literal string
- type=CPOINTER;
+ type = CPOINTER;
}
pic16_printGPointerType(val->name, type, ptype, p);
}
/*-----------------------------------------------------------------------*/
/* pic16_printIvalFuncPtr - generate initial value for function pointers */
/*-----------------------------------------------------------------------*/
-void pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void *p)
+static void
+pic16_printIvalFuncPtr (sym_link * type, initList * ilist, char ptype, void *p)
{
value *val;
int dLvl = 0;
}
if (IS_LITERAL(val->etype)) {
- if (compareType(type, val->etype) == 0) {
+ if (0 && compareType(type, val->etype) == 0) {
werrorfl (ilist->filename, ilist->lineno, E_INCOMPAT_TYPES);
printFromToType (val->type, type);
}
/* now generate the name */
if (!val->sym) {
- pic16_printGPointerType (val->name, DCL_TYPE(val->type), ptype, p);
+ pic16_printGPointerType (val->name, CPOINTER /*DCL_TYPE(val->type)*/, ptype, p);
} else {
- pic16_printGPointerType (val->sym->rname, DCL_TYPE(val->type), ptype, p);
+ pic16_printGPointerType (val->sym->rname, CPOINTER /*DCL_TYPE(val->type)*/, ptype, p);
if(IS_FUNC(val->sym->type) && !val->sym->used && !IS_STATIC(val->sym->etype)) {
/*-----------------------------------------------------------------*/
/* pic16_printIvalPtr - generates initial value for pointers */
/*-----------------------------------------------------------------*/
-void pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char ptype, void *p)
+static void
+pic16_printIvalPtr (symbol * sym, sym_link * type, initList * ilist, char ptype, void *p)
{
value *val;
int size;
}
else if (size == 3)
{
- pic16_printGPointerType (val->name, (IS_PTR(type)?DCL_TYPE(type):PTR_TYPE(SPEC_OCLS(sym->etype))),
- ptype, p);
+ int itype = 0;
+ itype = PTR_TYPE (SPEC_OCLS (val->etype));
+ pic16_printGPointerType (val->name, itype, ptype, p);
} else
assert(0);
return;
}
}
-int PIC16_IS_CONFIG_ADDRESS(int address)
+static int
+PIC16_IS_CONFIG_ADDRESS(int address)
{
return ((address >= pic16->cwInfo.confAddrStart && address <= pic16->cwInfo.confAddrEnd));
}
-int PIC16_IS_IDLOC_ADDRESS(int address)
+static int
+PIC16_IS_IDLOC_ADDRESS(int address)
{
return ((address >= pic16->idInfo.idAddrStart && address <= pic16->idInfo.idAddrEnd));
}
-/* wrapper function for the above */
-int PIC16_IS_HWREG_ADDRESS(int address)
-{
- return (PIC16_IS_CONFIG_ADDRESS(address) || PIC16_IS_IDLOC_ADDRESS(address));
-}
-
-
/*-----------------------------------------------------------------*/
/* emitStaticSeg - emitcode for the static segment */
/*-----------------------------------------------------------------*/
}
}
-void emitStatistics(FILE *asmFile)
+static void
+emitStatistics(FILE *asmFile)
{
unsigned long isize, udsize, ramsize;
statistics.isize = pic16_countInstructions();
if (val && oldval && (val->in_val != 0) && (val->in_val == oldval->in_val)) {
//fprintf (stderr, "MOVFW: W already set up correctly (%x) at %p\n", oldval->in_val, pc);
if (!pic16_isAlive (SPO_STATUS, pc)) pic16_safepCodeRemove (pc, "=DF= redundant MOVFW removed");
+ } else {
+ defmap_t *pred, *predpred;
+ /* Optimize MOVLW immd; MOVWF reg1; [...]; MOVFW reg1
+ * into MOVLW immd; MOVWF reg1; [...]; MOVLW immd
+ * This might allow removal of the first two assignments. */
+ pred = defmapFindDef (list, sym1, pc);
+ predpred = pred ? defmapFindDef (list, SPO_WREG, pred->pc) : NULL;
+ if (pred && predpred && (PCI(pred->pc)->op == POC_MOVWF) && (PCI(predpred->pc)->op == POC_MOVLW)
+ && !pic16_isAlive (SPO_STATUS, pc))
+ {
+ newpc = pic16_newpCode (POC_MOVLW, pic16_pCodeOpCopy (PCI(predpred->pc)->pcop));
+
+ if (pic16_debug_verbose || pic16_pcode_verbose) {
+ pic16_InsertCommentAfter (pc->prev, "=DF= MOVFW: replaced last of MOVLW;MOVWF;MOVFW by MOVLW");
+ } // if
+ pic16_pCodeReplace (pc, newpc);
+ defmapReplaceSymRef (pc, sym1, 0, 1);
+ pic16_fixDefmap (pc, newpc);
+ pc = newpc;
+
+ /* This breaks the defmap chain's references to pCodes... fix it! */
+ if (!val->prev) PCI(pc)->pcflow->defmap = val->next;
+ if (!val->acc.access.isWrite) {
+ deleteDefmap (val); // delete reference to reg1 as in value
+ val = NULL;
+ } else {
+ val->acc.access.isRead = 0; // delete reference to reg1 as in value
+ }
+ oldval = PCI(pc)->pcflow->defmap;
+ while (oldval) {
+ if (oldval->pc == pc) oldval->pc = newpc;
+ oldval = oldval->next;
+ } // while
+ } // if
}
if (val) defmapUpdate (list, SPO_WREG, pc, val->in_val);
}