return valCastLiteral(toType, 0.0);
}
- expr = list2expr (ilist);
+ expr = decorateType(resolveSymbols( list2expr (ilist) ), FALSE);
+// expr = list2expr( ilist );
if (!expr)
goto wrong;
if (IS_AST_SYM_VALUE (expr->left)) {
val = copyValue (AST_VALUE (expr->left));
val->type = newLink (DECLARATOR);
- if (SPEC_SCLS (expr->left->etype) == S_CODE) {
+ if(SPEC_SCLS (expr->left->etype) == S_CODE) {
DCL_TYPE (val->type) = CPOINTER;
DCL_PTR_CONST (val->type) = port->mem.code_ro;
}
DCL_TYPE (val->type) = EEPPOINTER;
else
DCL_TYPE (val->type) = POINTER;
+
val->type->next = expr->left->ftype;
val->etype = getSpec (val->type);
return val;
val->etype = getSpec (val->type);
return val;
}
+
wrong:
if (expr)
werrorfl (expr->filename, expr->lineno, E_INCOMPAT_PTYPES);
}
-/*-----------------------------------------------------------------*/
-/* return the generic pointer high byte for a given pointer type. */
-/*-----------------------------------------------------------------*/
-int pic16_pointerTypeToGPByte (const int p_type, const char *iname, const char *oname)
-{
- switch (p_type)
- {
- case IPOINTER:
- case POINTER:
- fprintf(stderr, "%s:%d pointer is IPOINTER/POINTER\n", __FILE__, __LINE__);
- return GPTYPE_NEAR;
- case GPOINTER:
- fprintf(stderr, "%s:%d pointer is GPOINTER\n", __FILE__, __LINE__);
- werror (E_CANNOT_USE_GENERIC_POINTER,
- iname ? iname : "<null>",
- oname ? oname : "<null>");
- exit (1);
- case FPOINTER:
- fprintf(stderr, "%s:%d pointer is FPOINTER\n", __FILE__, __LINE__);
- return GPTYPE_FAR;
- case CPOINTER:
- fprintf(stderr, "%s:%d pointer is CPOINTER\n", __FILE__, __LINE__);
- return GPTYPE_CODE;
- case PPOINTER:
- fprintf(stderr, "%s:%d pointer is PPOINTER\n", __FILE__, __LINE__);
- return GPTYPE_XSTACK;
- default:
- fprintf (stderr, "*** internal error: unknown pointer type %d in GPByte.\n",
- p_type);
- break;
- }
- return -1;
-}
-
-
/*-----------------------------------------------------------------*/
/* printPointerType - generates ival for pointer type */
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/* printGPointerType - generates ival for generic pointer type */
/*-----------------------------------------------------------------*/
-void pic16_printGPointerType (const char *iname, const char *oname,
+void pic16_printGPointerType (const char *iname, const char *oname, const unsigned int itype,
const unsigned int type, char ptype, void *p)
{
_pic16_printPointerType (iname, ptype, p);
- pic16_emitDB(pic16_pointerTypeToGPByte(type, iname, oname), ptype, p);
+
+ if(itype == FPOINTER || itype == CPOINTER) { // || itype == GPOINTER) {
+ char buf[256];
+
+ sprintf(buf, "UPPER(%s)", iname);
+ pic16_emitDS(buf, ptype, p);
+ }
+
pic16_flushDB(ptype, p);
}
value *val;
unsigned long ulval;
- //fprintf(stderr, "%s\n",__FUNCTION__);
+// fprintf(stderr, "%s for symbol %s\n",__FUNCTION__, sym->rname);
/* if initList is deep */
if (ilist && ilist->type == INIT_DEEP)
default:
/* VR - only 1,2,4 size long can be handled???? Why? */
fprintf(stderr, "%s:%d: unhandled case. Contact author.\n", __FILE__, __LINE__);
+ assert(0);
}
*sym = lsym;
*ilist = lilist;
VR - Attempting to port this function to pic16 port - 8-Jun-2004
*/
- fprintf(stderr, "%s\n",__FUNCTION__);
+// fprintf(stderr, "%s\n",__FUNCTION__);
size = getSize (type);
{
pic16_emitDS(val->name, ptype, p);
}
- else if (size == FPTRSIZE)
+ else if (size == 2)
{
pic16_printPointerType (val->name, ptype, p);
}
- else if (size == GPTRSIZE)
+ else if (size == 3)
{
int type;
if (IS_PTR (val->type)) {
// this is a literal string
type=CPOINTER;
}
- pic16_printGPointerType(val->name, sym->name, type, ptype, p);
+ pic16_printGPointerType(val->name, sym->name, type, type, ptype, p);
}
else
{
switch (size)
{
case 1:
- pic16_emitDS(aopLiteral(val, 0), ptype, p);
-// tfprintf (oFile, "\t!dbs\n", aopLiteral (val, 0));
+ pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
break;
case 2:
- pic16_emitDS(aopLiteral(val, 0), ptype, p);
- pic16_emitDS(aopLiteral(val, 1), ptype, p);
-// tfprintf (oFile, "\t.byte %s,%s\n",
-// aopLiteral (val, 0), aopLiteral (val, 1));
+ pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
+ pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
break;
case 3:
- if (IS_GENPTR(type) && floatFromVal(val)!=0) {
- // non-zero mcs51 generic pointer
- werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
- }
-
- pic16_emitDS(aopLiteral(val, 0), ptype, p);
- pic16_emitDS(aopLiteral(val, 1), ptype, p);
- pic16_emitDS(aopLiteral(val, 2), ptype, p);
+ pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
+ pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
+ pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
-// fprintf (oFile, "\t.byte %s,%s,%s\n",
-// aopLiteral (val, 0),
-// aopLiteral (val, 1),
-// aopLiteral (val, 2));
break;
-
-/* no 4 bytes size long for pic16 port */
- case 4:
- if (IS_GENPTR(type) && floatFromVal(val)!=0) {
- // non-zero ds390 generic pointer
- werrorfl (sym->fileDef, sym->lineDef, E_LITERAL_GENERIC);
- }
-
-// fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
-// aopLiteral (val, 0),
-// aopLiteral (val, 1),
-// aopLiteral (val, 2),
-// aopLiteral (val, 3));
- break;
default:
assert (0);
}
}
/* now generate the name */
- if (!val->sym)
- {
+ if (!val->sym) {
pic16_printPointerType (val->name, ptype, p);
- }
- else
- {
+ } else {
pic16_printPointerType (val->sym->rname, ptype, p);
- }
+ }
return;
}
value *val;
int size;
+
+#if 0
+ fprintf(stderr, "%s:%d initialising pointer: %s size: %d\n", __FILE__, __LINE__,
+ sym->rname, getSize(sym->type));
+#endif
+
/* if deep then */
if (ilist && (ilist->type == INIT_DEEP))
ilist = ilist->init.deep;
{
case 1:
pic16_emitDB((unsigned int)floatFromVal(val) & 0xff, ptype, p);
-// tfprintf (oFile, "\t!db !constbyte\n", (unsigned int) floatFromVal (val) & 0xff);
break;
case 2:
pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
-// tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
break;
case 3:
pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
-
- if (IS_GENPTR (val->type))
- pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
- else if (IS_PTR (val->type))
- pic16_emitDB(pic16_pointerTypeToGPByte(DCL_TYPE(val->type), NULL, NULL), ptype, p);
- else
pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
}
return;
{
pic16_emitDS(val->name, ptype, p);
}
- else if (size == FPTRSIZE)
+ else if (size == 2)
{
pic16_printPointerType (val->name, ptype, p);
}
- else if (size == GPTRSIZE)
+ else if (size == 3)
{
- pic16_printGPointerType (val->name, sym->name,
+ pic16_printGPointerType (val->name, sym->name, (IS_PTR(type)?DCL_TYPE(type):PTR_TYPE(SPEC_OCLS(sym->etype))),
(IS_PTR (val->type) ? DCL_TYPE (val->type) :
PTR_TYPE (SPEC_OCLS (val->etype))), ptype, p);
}
// fprintf(stderr, "%s:%d generating init for %s\n", __FILE__, __LINE__, sym->name);
- /* if structure then */
+ /* if structure then */
if (IS_STRUCT (type))
{
- fprintf(stderr,"%s struct\n",__FUNCTION__);
+// fprintf(stderr,"%s struct\n",__FUNCTION__);
pic16_printIvalStruct (sym, type, ilist, ptype, p);
return;
}
- /* if this is an array */
+ /* if this is an array */
if (IS_ARRAY (type))
{
// fprintf(stderr,"%s array\n",__FUNCTION__);
}
}
-#if 1
+#if 0
// and the type must match
itype=ilist->init.node->ftype;
/* if this is a pointer */
if (IS_PTR (type))
{
- fprintf(stderr,"%s pointer\n",__FUNCTION__);
+// fprintf(stderr,"%s pointer\n",__FUNCTION__);
pic16_printIvalPtr (sym, type, ilist, ptype, p);
return;
}
#endif
if(SPEC_ABSA(sym->etype) && PIC16_IS_CONFIG_ADDRESS(SPEC_ADDR(sym->etype))) {
-
pic16_assignConfigWordValue(SPEC_ADDR(sym->etype),
(int) floatFromVal(list2val(sym->ival)));
}
/* if it is "extern" then do nothing */
- if (IS_EXTERN (sym->etype)) {
-
- /* do not emit if it is a config word declaration */
- if(!SPEC_ABSA(sym->etype)
- || (SPEC_ABSA(sym->etype) && !PIC16_IS_CONFIG_ADDRESS(SPEC_ADDR(sym->etype))))
- checkAddSym(&externs, sym);
+ if (IS_EXTERN (sym->etype) && !SPEC_ABSA(sym->etype)) {
+ checkAddSym(&externs, sym);
continue;
}
checkAddSym(&publics, sym);
}
-#if 0
/* print extra debug info if required */
- if (options.debug || sym->level == 0)
- {
+ if (options.debug || sym->level == 0) {
/* NOTE to me - cdbFile may be null in which case,
* the sym name will be printed to stdout. oh well */
- if(cdbFile)
- cdbSymbol (sym, cdbFile, FALSE, FALSE);
-
- if (!sym->level)
- { /* global */
- if (IS_STATIC (sym->etype))
- fprintf (code->oFile, "F%s_", moduleName); /* scope is file */
- else
- fprintf (code->oFile, "G_"); /* scope is global */
- }
- else
- /* symbol is local */
- fprintf (code->oFile, "L%s_",
- (sym->localof ? sym->localof->name : "-null-"));
- fprintf (code->oFile, "%s_%d_%d", sym->name, sym->level, sym->block);
-
- }
-#endif
-
+ debugFile->writeSymbol(sym);
+ }
+
/* if it has an absolute address */
- if (SPEC_ABSA (sym->etype))
- {
- fprintf(stderr, "%s:%d spec_absa is true for symbol: %s\n",
- __FILE__, __LINE__, sym->name);
+ if (SPEC_ABSA (sym->etype)) {
+// fprintf(stderr, "%s:%d spec_absa is true for symbol: %s\n",
+// __FILE__, __LINE__, sym->name);
- if (options.debug || sym->level == 0)
- fprintf (code->oFile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
-
- fprintf (code->oFile, "%s\t=\t0x%04x\n",
- sym->rname,
- SPEC_ADDR (sym->etype));
-
/* if it has an initial value */
if (sym->ival)
{
absSym *abSym;
pCode *pcf;
+ /* symbol has absolute address and initial value */
noAlloc++;
resolveIvalSym (sym->ival, sym->type);
asym = newSymbol(sym->rname, 0);
else
{
+ /* symbol has absolute address but no initial value */
+
/* allocate space */
fprintf (code->oFile, "%s:\n", sym->rname);
+
/* special case for character strings */
if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
SPEC_CVAL (sym->etype).v_char)
pic16_pCodeConstString(sym->rname , SPEC_CVAL (sym->etype).v_char);
- /*printChar (code->oFile,
- SPEC_CVAL (sym->etype).v_char,
- strlen (SPEC_CVAL (sym->etype).v_char) + 1);*/
- else
+ else {
+ assert(0);
fprintf (code->oFile, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
+ }
}
} else {
// fprintf(stderr, "%s:%d spec_absa is false for symbol: %s\n",
// __FILE__, __LINE__, sym->name);
- if (options.debug || sym->level == 0)
- fprintf (code->oFile, " == .\n");
-
/* if it has an initial value */
- if (sym->ival)
- {
+ if (sym->ival) {
pBlock *pb;
+ /* symbol doesn't have absolute address but has initial value */
fprintf (code->oFile, "%s:\n", sym->rname);
noAlloc++;
resolveIvalSym (sym->ival, sym->type);
pic16_printIval(sym, sym->type, sym->ival, 'p', (void *)pb);
pic16_flushDB('p', (void *)pb);
noAlloc--;
- }
- else
- {
+ } else {
+ /* symbol doesn't have absolute address and no initial value */
/* allocate space */
fprintf (code->oFile, "%s:\n", sym->rname);
/* special case for character strings */
if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
SPEC_CVAL (sym->etype).v_char)
pic16_pCodeConstString(sym->rname , SPEC_CVAL (sym->etype).v_char);
- /*printChar (code->oFile,
- SPEC_CVAL (sym->etype).v_char,
- strlen (SPEC_CVAL (sym->etype).v_char) + 1);*/
- else
+ else {
+ assert(0);
fprintf (code->oFile, "\t.ds\t0x%04x\n", (unsigned int) getSize (sym->type) & 0xffff);
+ }
}
}
}
pCodeOpReg pic16_pc_prodl = {{PO_PRODL, "PRODL"}, -1, NULL, 0, NULL};
pCodeOpReg pic16_pc_prodh = {{PO_PRODH, "PRODH"}, -1, NULL, 0, NULL};
+/* EEPROM registers */
+pCodeOpReg pic16_pc_eecon1 = {{PO_SFR_REGISTER, "EECON1"}, -1, NULL, 0, NULL};
+pCodeOpReg pic16_pc_eecon2 = {{PO_SFR_REGISTER, "EECON2"}, -1, NULL, 0, NULL};
+pCodeOpReg pic16_pc_eedata = {{PO_SFR_REGISTER, "EEDATA"}, -1, NULL, 0, NULL};
+pCodeOpReg pic16_pc_eeadr = {{PO_SFR_REGISTER, "EEADR"}, -1, NULL, 0, NULL};
+
+
+
pCodeOpReg pic16_pc_kzero = {{PO_GPR_REGISTER, "KZ"}, -1, NULL,0,NULL};
pCodeOpReg pic16_pc_wsave = {{PO_GPR_REGISTER, "WSAVE"}, -1, NULL,0,NULL};
pCodeOpReg pic16_pc_ssave = {{PO_GPR_REGISTER, "SSAVE"}, -1, NULL,0,NULL};
pic16_pc_tosh.r = pic16_allocProcessorRegister(IDX_TOSH,"TOSH", PO_SFR_REGISTER, 0x80);
pic16_pc_tosu.r = pic16_allocProcessorRegister(IDX_TOSU,"TOSU", PO_SFR_REGISTER, 0x80);
- pic16_pc_tblptrl.r = pic16_allocProcessorRegister(IDX_TBLPTRL,"TBLPTRL", PO_SFR_REGISTER, 0x80); // patch 15
- pic16_pc_tblptrh.r = pic16_allocProcessorRegister(IDX_TBLPTRH,"TBLPTRH", PO_SFR_REGISTER, 0x80); // patch 15
- pic16_pc_tblptru.r = pic16_allocProcessorRegister(IDX_TBLPTRU,"TBLPTRU", PO_SFR_REGISTER, 0x80); // patch 15
- pic16_pc_tablat.r = pic16_allocProcessorRegister(IDX_TABLAT,"TABLAT", PO_SFR_REGISTER, 0x80); // patch 15
-
-
-// pic16_pc_fsr0.r = pic16_allocProcessorRegister(IDX_FSR0,"FSR0", PO_FSR0, 0x80); // deprecated !
+ pic16_pc_tblptrl.r = pic16_allocProcessorRegister(IDX_TBLPTRL,"TBLPTRL", PO_SFR_REGISTER, 0x80);
+ pic16_pc_tblptrh.r = pic16_allocProcessorRegister(IDX_TBLPTRH,"TBLPTRH", PO_SFR_REGISTER, 0x80);
+ pic16_pc_tblptru.r = pic16_allocProcessorRegister(IDX_TBLPTRU,"TBLPTRU", PO_SFR_REGISTER, 0x80);
+ pic16_pc_tablat.r = pic16_allocProcessorRegister(IDX_TABLAT,"TABLAT", PO_SFR_REGISTER, 0x80);
pic16_pc_fsr0l.r = pic16_allocProcessorRegister(IDX_FSR0L, "FSR0L", PO_FSR0, 0x80);
pic16_pc_fsr0h.r = pic16_allocProcessorRegister(IDX_FSR0H, "FSR0H", PO_FSR0, 0x80);
pic16_pc_prodl.r = pic16_allocProcessorRegister(IDX_PRODL, "PRODL", PO_PRODL, 0x80);
pic16_pc_prodh.r = pic16_allocProcessorRegister(IDX_PRODH, "PRODH", PO_PRODH, 0x80);
+
+
+ pic16_pc_eecon1.r = pic16_allocProcessorRegister(IDX_EECON1, "EECON1", PO_SFR_REGISTER, 0x80);
+ pic16_pc_eecon2.r = pic16_allocProcessorRegister(IDX_EECON2, "EECON2", PO_SFR_REGISTER, 0x80);
+ pic16_pc_eedata.r = pic16_allocProcessorRegister(IDX_EEDATA, "EEDATA", PO_SFR_REGISTER, 0x80);
+ pic16_pc_eeadr.r = pic16_allocProcessorRegister(IDX_EEADR, "EEADR", PO_SFR_REGISTER, 0x80);
+
pic16_pc_status.rIdx = IDX_STATUS;
pic16_pc_intcon.rIdx = IDX_INTCON;
pic16_pc_wsave.rIdx = IDX_WSAVE;
pic16_pc_ssave.rIdx = IDX_SSAVE;
+ pic16_pc_eecon1.rIdx = IDX_EECON1;
+ pic16_pc_eecon2.rIdx = IDX_EECON2;
+ pic16_pc_eedata.rIdx = IDX_EEDATA;
+ pic16_pc_eeadr.rIdx = IDX_EEADR;
+
+
/* probably should put this in a separate initialization routine */
pb_dead_pcodes = newpBlock();
return pcop;
}
+#define DB_ITEMS_PER_LINE 8
typedef struct DBdata
{
sprintf(DBd.buffer+l,"%s0x%02x", (DBd.count>0?", ":""), c & 0xff);
DBd.count++;
- if (DBd.count>=16)
+ if (DBd.count>= DB_ITEMS_PER_LINE)
pic16_flushDB(ptype, p);
}
prevreg = reg;
if(!pic16_options.no_banksel)
insertBankSwitch(0, pc);
+ } else {
+// if(pcprev && isPCI_SKIP(pcprev))assert(0);
}
}
return NULL;
}
- if(1) { //!PIC16_IS_CONFIG_ADDRESS(address)) {
+ if(1) { //!PIC16_IS_CONFIG_ADDRESS(address))
// fprintf(stderr,"%s:allocating new reg %s\n",__FUNCTION__, name);
/* this is an error, why added? -- VR */
if(!IN_DIRSPACE( SPEC_OCLS( OP_SYM_ETYPE(op)))) { // patch 13
if(pic16_debug_verbose) //
{ //
- fprintf(stderr, "dispace:%d farspace:%d codespace:%d regspace:%d stack:%d\n",
+ fprintf(stderr, "dispace:%d farspace:%d codespace:%d regspace:%d stack:%d eeprom: %d\n",
IN_DIRSPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
IN_FARSPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
IN_CODESPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
IN_REGSP( SPEC_OCLS( OP_SYM_ETYPE(op))),
- IN_STACK( OP_SYM_ETYPE(op)));
+ IN_STACK( OP_SYM_ETYPE(op)),
+ SPEC_OCLS(OP_SYM_ETYPE(op)) == eeprom);
fprintf(stderr, "%s:%d symbol %s NOT in dirspace\n", __FILE__, __LINE__, //
OP_SYMBOL(op)->name); //
} //
-// return NULL; //
} // patch 13
reg = newReg(regtype, PO_DIR, rDirectIdx++, name,getSize (OP_SYMBOL (op)->type),0, op);
debugLog ("%d -- added %s to hash, size = %d\n", __LINE__, name,reg->size);
-// hTabAddItem(&dynDirectRegNames, regname2key(name), reg); /* commented out */
// if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
// fprintf(stderr, " ralloc.c at fixed address: %s - changing to REG_SFR\n",name);
} else {
debugLog (" -- %s is declared at address 0x30000x\n",name);
-// fprintf(stderr, " -- %s is declared at address 0x30000x\n",name);
return NULL;
}
pic16_groupRegistersInSection(pic16_dynProcessorRegs);
-#if 0
- pic16_assignFixedRegisters(pic16_dynAllocRegs);
- pic16_assignFixedRegisters(pic16_dynStackRegs);
- pic16_assignFixedRegisters(pic16_dynDirectRegs);
- pic16_assignFixedRegisters(pic16_dynProcessorRegs);
-
- pic16_assignRelocatableRegisters(pic16_dynDirectBitRegs, 0);
- pic16_assignRelocatableRegisters(pic16_dynInternalRegs,0);
- pic16_assignRelocatableRegisters(pic16_dynAllocRegs,0);
- pic16_assignRelocatableRegisters(pic16_dynStackRegs,0);
- pic16_assignRelocatableRegisters(pic16_dynDirectRegs,0);
-#endif
-
-// pic16_dump_map();
-// pic16_dump_cblock(of);
-
/* dump equates */
pic16_dump_equates(of, pic16_equ_data);
+// pic16_dump_esection(of, pic16_rel_eedata, 0);
+// pic16_dump_esection(of, pic16_fix_eedata, 0);
+
/* dump initialised data */
pic16_dump_isection(of, rel_idataSymSet, 0);
pic16_dump_isection(of, fix_idataSymSet, 1);
-// pic16_dump_idata(of, idataSymSet);
-
/* dump internal registers */
pic16_dump_int_registers(of, pic16_int_regs);