- {
- /* allocate space */
-
- /* If this is a bit variable, then allocate storage after 8 bits have been declared */
- /* unlike the 8051, the pic does not have a separate bit area. So we emulate bit ram */
- /* by grouping the bits together into groups of 8 and storing them in the normal ram. */
- if (IS_BITVAR (sym->etype))
- {
- bitvars++;
- }
- else
- {
- fprintf (map->oFile, "\t%s\n", sym->rname);
- if ((size = (unsigned int) getSize (sym->type) & 0xffff) > 1)
- {
- for (i = 1; i < size; i++)
- fprintf (map->oFile, "\t%s_%d\n", sym->rname, i);
- }
- }
- //fprintf (map->oFile, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
- }
-
- /* if it has a initial value then do it only if
- it is a global variable */
- if (sym->ival && sym->level == 0) {
- ast *ival = NULL;
-
- if (IS_AGGREGATE (sym->type))
- ival = initAggregates (sym, sym->ival, NULL);
- else
- ival = newNode ('=', newAst_VALUE(symbolVal (sym)),
- decorateType (resolveSymbols (list2expr (sym->ival))));
- codeOutFile = statsg->oFile;
- GcurMemmap = statsg;
- eBBlockFromiCode (iCodeFromAst (ival));
- sym->ival = NULL;
- }
- }
-}
-
-
-/*-----------------------------------------------------------------*/
-/* printIvalType - generates ival for int/char */
-/*-----------------------------------------------------------------*/
-static void
-printIvalType (symbol *sym, sym_link * type, initList * ilist, pBlock *pb)
+ DCL_TYPE (val->type) = POINTER;
+
+ val->type->next = expr->left->ftype;
+ val->etype = getSpec (val->type);
+ return val;
+ }
+
+ /* if address of indexed array */
+ if (IS_AST_OP (expr->left) && expr->left->opval.op == '[')
+ return valForArray (expr->left);
+
+ /* if address of structure element then
+ case 1. a.b ; */
+ if (IS_AST_OP (expr->left) &&
+ expr->left->opval.op == '.') {
+ return valForStructElem (expr->left->left,
+ expr->left->right);
+ }
+
+ /* case 2. (&a)->b ;
+ (&some_struct)->element */
+ if (IS_AST_OP (expr->left) &&
+ expr->left->opval.op == PTR_OP &&
+ IS_ADDRESS_OF_OP (expr->left->left)) {
+ return valForStructElem (expr->left->left->left,
+ expr->left->right);
+ }
+ }
+ /* case 3. (((char *) &a) +/- constant) */
+ if (IS_AST_OP (expr) &&
+ (expr->opval.op == '+' || expr->opval.op == '-') &&
+ IS_AST_OP (expr->left) && expr->left->opval.op == CAST &&
+ IS_AST_OP (expr->left->right) &&
+ expr->left->right->opval.op == '&' &&
+ IS_AST_LIT_VALUE (expr->right)) {
+
+ return valForCastAggr (expr->left->right->left,
+ expr->left->left->opval.lnk,
+ expr->right, expr->opval.op);
+
+ }
+ /* case 4. (char *)(array type) */
+ if (IS_CAST_OP(expr) && IS_AST_SYM_VALUE (expr->right) &&
+ IS_ARRAY(expr->right->ftype)) {
+
+ val = copyValue (AST_VALUE (expr->right));
+ val->type = newLink (DECLARATOR);
+ if (SPEC_SCLS (expr->right->etype) == S_CODE) {
+ DCL_TYPE (val->type) = CPOINTER;
+ DCL_PTR_CONST (val->type) = port->mem.code_ro;
+ }
+ else if (SPEC_SCLS (expr->right->etype) == S_XDATA)
+ DCL_TYPE (val->type) = FPOINTER;
+ else if (SPEC_SCLS (expr->right->etype) == S_XSTACK)
+ DCL_TYPE (val->type) = PPOINTER;
+ else if (SPEC_SCLS (expr->right->etype) == S_IDATA)
+ DCL_TYPE (val->type) = IPOINTER;
+ else if (SPEC_SCLS (expr->right->etype) == S_EEPROM)
+ DCL_TYPE (val->type) = EEPPOINTER;
+ else
+ DCL_TYPE (val->type) = POINTER;
+ val->type->next = expr->right->ftype->next;
+ val->etype = getSpec (val->type);
+ return val;
+ }
+
+ wrong:
+ if (expr)
+ werrorfl (expr->filename, expr->lineno, E_INCOMPAT_PTYPES);
+ else
+ werror (E_INCOMPAT_PTYPES);
+ return NULL;
+
+}
+
+
+/*-----------------------------------------------------------------*/
+/* printPointerType - generates ival for pointer type */
+/*-----------------------------------------------------------------*/
+void _pic16_printPointerType (const char *name, char ptype, void *p)
+{
+ char buf[256];
+
+ sprintf (buf, "LOW(%s)", name);
+ pic16_emitDS (buf, ptype, p);
+ sprintf (buf, "HIGH(%s)", name);
+ pic16_emitDS (buf, ptype, p);
+}
+
+/*-----------------------------------------------------------------*/
+/* printPointerType - generates ival for pointer type */
+/*-----------------------------------------------------------------*/
+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,
+ char ptype, void *p)
+{
+ char buf[256];
+
+ _pic16_printPointerType (iname, ptype, p);
+
+ switch (itype)
+ {
+ case CPOINTER:
+ case FUNCTION:
+ sprintf (buf, "UPPER(%s)", iname);
+ pic16_emitDS (buf, ptype, p);
+ break;
+
+ case GPOINTER:
+ case POINTER:
+ sprintf (buf, "0x80");
+ pic16_emitDS (buf, ptype, p);
+ break;
+
+ /*
+ * FPOINTER and IPOINTER are not used in pic16 port
+ case FPOINTER:
+ case IPOINTER:
+ */
+ default:
+ debugf ("itype = %d\n", itype );
+ assert (0);
+ }
+
+ //pic16_flushDB(ptype, p); /* might break char* const arr[] = {...}; */
+}
+
+
+/* set to 0 to disable debug messages */
+#define DEBUG_PRINTIVAL 0
+
+/*-----------------------------------------------------------------*/
+/* pic16_printIvalType - generates ival for int/char */
+/*-----------------------------------------------------------------*/
+static void
+pic16_printIvalType (symbol *sym, sym_link * type, initList * ilist, char ptype, void *p)