+ FILE *asmFile;
+ struct dbuf_s ovrBuf;
+ struct dbuf_s vBuf;
+
+ dbuf_init(&ovrBuf, 4096);
+ dbuf_init(&vBuf, 4096);
+
+ pCodeInitRegisters();
+
+ /* check for main() */
+ mainf = newSymbol ("main", 0);
+ mainf->block = 0;
+ mainf = findSymWithLevel (SymbolTab, mainf);
+
+ if (!mainf || !IFFUNC_HASBODY(mainf->type))
+ {
+ /* main missing -- import stack from main module */
+ //fprintf (stderr, "main() missing -- assuming we are NOT the main module\n");
+ pic14_options.isLibrarySource = 1;
+ }
+
+#if 0
+ if (mainf && IFFUNC_HASBODY(mainf->type)) {
+
+ pBlock *pb = newpCodeChain(NULL,'X',newpCodeCharP("; Starting pCode block"));
+ addpBlock(pb);
+
+ /* entry point @ start of CSEG */
+ addpCode2pBlock(pb,newpCodeLabel("__sdcc_program_startup",-1));
+ /* put in the call to main */
+ addpCode2pBlock(pb,newpCode(POC_CALL,newpCodeOp("_main",PO_STR)));
+
+ if (options.mainreturn) {
+
+ addpCode2pBlock(pb,newpCodeCharP(";\treturn from main will return to caller\n"));
+ addpCode2pBlock(pb,newpCode(POC_RETURN,NULL));
+
+ } else {
+
+ addpCode2pBlock(pb,newpCodeCharP(";\treturn from main will lock up\n"));
+ addpCode2pBlock(pb,newpCode(POC_GOTO,newpCodeOp("$",PO_STR)));
+
+ }
+ }
+#endif
+
+ /* At this point we've got all the code in the form of pCode structures */
+ /* Now it needs to be rearranged into the order it should be placed in the */
+ /* code space */
+
+ movepBlock2Head('P'); // Last
+ movepBlock2Head(code->dbName);
+ movepBlock2Head('X');
+ movepBlock2Head(statsg->dbName); // First
+
+
+ /* print the global struct definitions */
+ if (options.debug)
+ cdbStructBlock (0);
+
+ /* emit code for the all the variables declared */
+ //pic14emitMaps ();
+ /* do the overlay segments */
+ pic14emitOverlay(&ovrBuf);
+
+ /* PENDING: this isnt the best place but it will do */
+ if (port->general.glue_up_main) {
+ /* create the interrupt vector table */
+ pic14createInterruptVect (&vBuf);
+ }
+
+ AnalyzepCode('*');
+
+ ReuseReg(); // ReuseReg where call tree permits
+
+ InlinepCode();
+
+ AnalyzepCode('*');
+
+ if (options.debug) pcode_test();
+
+
+ /* now put it all together into the assembler file */
+ /* create the assembler file name */
+
+ if ((noAssemble || options.c1mode) && fullDstFileName)
+ {
+ sprintf (buffer, fullDstFileName);
+ }
+ else
+ {
+ sprintf (buffer, dstFileName);
+ strcat (buffer, ".asm");
+ }
+
+ if (!(asmFile = fopen (buffer, "w"))) {
+ werror (E_FILE_OPEN_ERR, buffer);
+ exit (1);
+ }
+
+ /* prepare statistics */
+ resetpCodeStatistics ();
+
+ /* initial comments */
+ pic14initialComments (asmFile);
+
+ /* print module name */
+ fprintf (asmFile, "%s\t.file\t\"%s\"\n",
+ options.debug ? "" : ";", fullSrcFileName);
+
+ /* Let the port generate any global directives, etc. */
+ if (port->genAssemblerPreamble)
+ {
+ port->genAssemblerPreamble(asmFile);
+ }
+
+ /* print the global variables in this module */
+ //pic14printPublics (asmFile);
+
+ /* print the extern variables in this module */
+ //pic14printExterns (asmFile);
+
+ /* copy the sfr segment */
+#if 0
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; special function registers\n");
+ fprintf (asmFile, "%s", iComments2);
+ dbuf_write_and_destroy (&sfr->oBuf, asmFile);
+
+
+ if (udata_section_name) {
+ sprintf(udata_name,"%s",udata_section_name);
+ } else {
+ sprintf(udata_name,"data_%s",moduleName);
+ }
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; udata\n");
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "%s\tudata\n", udata_name);
+ dbuf_write_and_destroy(&data->oBuf, asmFile);
+#endif
+
+ /* Put all variables into a cblock */
+ AnalyzeBanking();
+
+ /* emit initialized data */
+ showAllMemmaps(asmFile);
+
+ /* print the locally defined variables in this module */
+ writeUsedRegs(asmFile);
+
+ /* create the overlay segments */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; overlayable items in internal ram \n");
+ fprintf (asmFile, "%s", iComments2);
+ dbuf_write_and_destroy (&ovrBuf, asmFile);
+
+#if 0
+
+ /* create the stack segment MOF */
+ if (mainf && IFFUNC_HASBODY(mainf->type)) {
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; Stack segment in internal ram \n");
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, ";\t.area\tSSEG\t(DATA)\n"
+ ";__start__stack:\n;\t.ds\t1\n\n");
+ }
+
+ /* create the idata segment */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; indirectly addressable internal ram data\n");
+ fprintf (asmFile, "%s", iComments2);
+ dbuf_write_and_destroy (&idata->oBuf, asmFile);
+
+ /* if external stack then reserve space of it */
+ if (mainf && IFFUNC_HASBODY(mainf->type) && options.useXstack ) {
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; external stack \n");
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile,";\t.area XSEG (XDATA)\n"); /* MOF */
+ fprintf (asmFile,";\t.ds 256\n");
+ }
+
+ /* copy xtern ram data */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; external ram data\n");
+ fprintf (asmFile, "%s", iComments2);
+ dbuf_write_and_destroy (&xdata->oBuf, asmFile);
+
+#endif
+
+ /* copy the bit segment */
+#if 0
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; bit data\n");
+ fprintf (asmFile, "%s", iComments2);
+ dbuf_write_and_destroy (&bit->oBuf, asmFile);
+#endif
+
+ /* copy the interrupt vector table */
+ if (mainf && IFFUNC_HASBODY(mainf->type))
+ dbuf_write_and_destroy (&vBuf, asmFile);
+ else
+ dbuf_destroy(&vBuf);
+
+ /* create interupt ventor handler */
+ pic14_emitInterruptHandler (asmFile);
+
+ /* copy over code */
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "; code\n");
+ fprintf (asmFile, "%s", iComments2);
+ fprintf (asmFile, "code_%s\t%s\n", moduleName, port->mem.code_name);
+
+ /* unknown */
+ copypCode(asmFile, 'X');
+
+ /* _main function */
+ copypCode(asmFile, 'M');
+
+ /* other functions */
+ copypCode(asmFile, code->dbName);
+
+ /* unknown */
+ copypCode(asmFile, 'P');
+
+ dumppCodeStatistics (asmFile);
+
+ fprintf (asmFile,"\tend\n");
+
+ fclose (asmFile);
+ pic14_debugLogClose();
+}
+
+/*
+ * Deal with initializers.
+ */
+#undef DEBUGprintf
+#if 0
+// debugging output
+#define DEBUGprintf printf
+#else
+// be quiet
+#define DEBUGprintf 1 ? (void)0 : (void)printf
+#endif
+
+
+void ast_print (ast * tree, FILE *outfile, int indent);
+
+#if 0
+/*
+ * Emit all memmaps.
+ */
+static void
+showInitList(initList *list, int level)
+{
+ static const char *list_type[] = { "INIT_NODE", "INIT_DEEP", "INIT_HOLE" };
+ static const char *ast_type[] = { "EX_OP", "EX_VALUE", "EX_LINK", "EX_OPERAND" };
+ struct ast *ast;
+ while (list) {
+ printf (" %d: type %u (%s), init %p, next %p\n", level, list->type, list_type[list->type], list->init.node, list->next);
+ if (list->type == INIT_DEEP) {
+ showInitList(list->init.deep, level + 1);
+ } else if (list->type == INIT_NODE) {
+ ast = list->init.node;
+ printf (" type %u (%s), level %d, block %d, seqPoint %d\n",
+ ast->type, ast_type[ast->type], ast->level, ast->block, ast->seqPoint);
+ if (ast->type == EX_VALUE) {
+ printf (" VAL %lf\n", floatFromVal(ast->opval.val));
+ } else if (ast->type == EX_LINK) {
+ printTypeChain(ast->opval.lnk, NULL);
+ } else if (ast->type == EX_OP) {
+ printf (" OP %u\n", ast->opval.op);
+ }
+ } // if
+ list = list->next;
+ } // while
+}
+#endif
+
+/*
+ * DEBUG: Print a value.
+ */
+void
+printVal(value *val)
+{
+ printf ("value %p: name %s, type %p, etype %p, sym %s, vArgs %d, lit 0x%lx/%ld\n",
+ val, val->name, val->type, val->etype,
+ val->sym ? val->sym->name : NULL, val->vArgs,
+ (long) ulFromVal (val), (long) ulFromVal (val));
+ printTypeChain(val->type, stdout);
+ printf ("\n");
+ printTypeChain(val->etype, stdout);
+ printf ("\n");
+}
+
+//prototype from ../SDCCicode.c
+operand *operandFromAst (ast * tree,int lvl);
+
+char *
+parseIvalAst (ast *node, int *inCodeSpace) {
+#define LEN 4096
+ char *buffer = NULL;
+ char *left, *right;
+
+ if (IS_AST_VALUE(node)) {
+ value *val = AST_VALUE(node);
+ symbol *sym = IS_AST_SYM_VALUE(node) ? AST_SYMBOL(node) : NULL;
+ if (inCodeSpace && val->type
+ && (IS_FUNC(val->type) || IS_CODE(getSpec(val->type))))
+ {
+ *inCodeSpace = 1;
+ }
+ if (inCodeSpace && sym
+ && (IS_FUNC(sym->type)
+ || IS_CODE(getSpec(sym->type))))
+ {
+ *inCodeSpace = 1;
+ }
+
+ DEBUGprintf ("%s: AST_VALUE\n", __FUNCTION__);
+ if (IS_AST_LIT_VALUE(node)) {
+ buffer = Safe_alloc(LEN);
+ SNPRINTF(buffer, LEN, "0x%lx", AST_ULONG_VALUE (node));
+ } else if (IS_AST_SYM_VALUE(node)) {
+ assert ( AST_SYMBOL(node) );
+ /*
+ printf ("sym %s: ", AST_SYMBOL(node)->rname);
+ printTypeChain(AST_SYMBOL(node)->type, stdout);
+ printTypeChain(AST_SYMBOL(node)->etype, stdout);
+ printf ("\n---sym %s: done\n", AST_SYMBOL(node)->rname);
+ */
+ buffer = Safe_strdup(AST_SYMBOL(node)->rname);
+ } else {
+ assert ( !"Invalid values type for initializers in AST." );
+ }
+ } else if (IS_AST_OP(node)) {
+ DEBUGprintf ("%s: AST_OP\n", __FUNCTION__);
+ switch (node->opval.op) {
+ case CAST:
+ assert (node->right);
+ buffer = parseIvalAst(node->right, inCodeSpace);
+ DEBUGprintf ("%s: %s\n", __FUNCTION__, buffer);
+ break;
+ case '&':
+ assert ( node->left && !node->right );
+ buffer = parseIvalAst(node->left, inCodeSpace);
+ DEBUGprintf ("%s: %s\n", __FUNCTION__, buffer);
+ break;
+ case '+':
+ assert (node->left && node->right );
+ left = parseIvalAst(node->left, inCodeSpace);
+ right = parseIvalAst(node->right, inCodeSpace);
+ buffer = Safe_alloc(LEN);
+ SNPRINTF(buffer, LEN, "(%s + %s)", left, right);
+ DEBUGprintf ("%s: %s\n", __FUNCTION__, buffer);
+ Safe_free(left);
+ Safe_free(right);
+ break;
+ case '[':
+ assert ( node->left && node->right );
+ assert ( IS_AST_VALUE(node->left) && AST_VALUE(node->left)->sym );
+ right = parseIvalAst(node->right, inCodeSpace);
+ buffer = Safe_alloc(LEN);
+ SNPRINTF(buffer, LEN, "(%s + %u * %s)",
+ AST_VALUE(node->left)->sym->rname, getSize(AST_VALUE(node->left)->type), right);
+ Safe_free(right);
+ DEBUGprintf ("%s: %s\n", __FUNCTION__, &buffer[0]);
+ break;
+ default:
+ assert ( !"Unhandled operation in initializer." );
+ break;
+ }
+ } else {
+ assert ( !"Invalid construct in initializer." );
+ }
+
+ return (buffer);
+}
+
+/*
+ * Emit the section preamble, absolute location (if any) and
+ * symbol name(s) for intialized data.
+ */
+static int
+emitIvalLabel(struct dbuf_s *oBuf, symbol *sym)
+{
+ char *segname;
+ static int in_code = 0;
+ static int sectionNr = 0;
+
+ if (sym) {
+ // code or data space?
+ if (IS_CODE(getSpec(sym->type))) {
+ segname = "code";
+ in_code = 1;
+ } else {
+ segname = "idata";
+ in_code = 0;
+ }
+ dbuf_printf(oBuf, "\nID_%s_%d\t%s", moduleName, sectionNr++, segname);
+ if (SPEC_ABSA(getSpec(sym->type))) {
+ // specify address for absolute symbols
+ dbuf_printf(oBuf, "\t0x%04X", SPEC_ADDR(getSpec(sym->type)));
+ } // if
+ dbuf_printf(oBuf, "\n%s\n", sym->rname);
+
+ addSet(&emitted, sym->rname);
+ }
+ return (in_code);
+}
+
+char *get_op(pCodeOp *pcop,char *buffer, size_t size);
+/*
+ * Actually emit the initial values in .asm format.
+ */
+static void
+emitIvals(struct dbuf_s *oBuf, symbol *sym, initList *list, long lit, int size)
+{
+ int i;
+ ast *node;
+ operand *op;
+ value *val = NULL;
+ int inCodeSpace = 0;
+ char *str = NULL;
+ int in_code;
+
+ assert (size <= sizeof(long));
+ assert (!list || (list->type == INIT_NODE));
+ node = list ? list->init.node : NULL;
+
+ in_code = emitIvalLabel(oBuf, sym);
+ if (!in_code) dbuf_printf (oBuf, "\tdb\t");
+
+ if (!node) {
+ // initialize as zero
+ for (i=0; i < size; i++) {
+ if (in_code) {
+ dbuf_printf (oBuf, "\tretlw 0x00");
+ } else {
+ dbuf_printf (oBuf, "%s0x00", (i == 0) ? "" : ", ");
+ }
+ } // for
+ dbuf_printf (oBuf, "\n");
+ return;
+ } // if
+
+ op = NULL;
+ if (constExprTree(node) && (val = constExprValue(node, 0))) {
+ op = operandFromValue(val);
+ DEBUGprintf ("%s: constExpr ", __FUNCTION__);
+ //printVal(val);
+ } else if (IS_AST_VALUE(node)) {
+ op = operandFromAst(node, 0);
+ } else if (IS_AST_OP(node)) {
+ str = parseIvalAst(node, &inCodeSpace);
+ DEBUGprintf("%s: AST_OP: %s\n", __FUNCTION__, str);
+ op = NULL;
+ } else {
+ assert ( !"Unhandled construct in intializer." );
+ }
+
+ if (op) {
+ aopOp(op, NULL, 1);
+ assert(AOP(op));
+ //printOperand(op, of);
+ }
+
+ for (i=0; i < size; i++) {
+ char *text;
+
+ /*
+ * FIXME: This is hacky and needs some more thought.
+ */
+ if (op && IS_SYMOP(op) && IS_FUNC(OP_SYM_TYPE(op))) {
+ /* This branch is introduced to fix #1427663. */
+ PCOI(AOP(op)->aopu.pcop)->offset+=i;
+ text = get_op(AOP(op)->aopu.pcop, NULL, 0);
+ PCOI(AOP(op)->aopu.pcop)->offset-=i;
+ } else {
+ text = op ? aopGet(AOP(op), i, 0, 0)
+ : get_op(newpCodeOpImmd(str, i, 0, inCodeSpace, 0), NULL, 0);
+ } // if
+ if (in_code) {
+ dbuf_printf (oBuf, "\tretlw %s\n", text);
+ } else {
+ dbuf_printf (oBuf, "%s%s", (i == 0) ? "" : ", ", text);
+ }
+ } // for
+ dbuf_printf (oBuf, "\n");
+}
+
+/*
+ * For UNIONs, we first have to find the correct alternative to map the
+ * initializer to. This function maps the structure of the initializer to
+ * the UNION members recursively.
+ * Returns the type of the first `fitting' member.
+ */
+static sym_link *
+matchIvalToUnion (initList *list, sym_link *type, int size)
+{
+ symbol *sym;
+
+ assert (type);
+
+ if (IS_PTR(type) || IS_CHAR(type) || IS_INT(type) || IS_LONG(type)
+ || IS_FLOAT(type))
+ {
+ if (!list || (list->type == INIT_NODE)) {
+ DEBUGprintf ("OK, simple type\n");
+ return (type);
+ } else {
+ DEBUGprintf ("ERROR, simple type\n");
+ return (NULL);
+ }
+ } else if (IS_BITFIELD(type)) {
+ if (!list || (list->type == INIT_NODE)) {
+ DEBUGprintf ("OK, bitfield\n");
+ return (type);
+ } else {
+ DEBUGprintf ("ERROR, bitfield\n");
+ return (NULL);
+ }
+ } else if (IS_STRUCT(type) && SPEC_STRUCT(getSpec(type))->type == STRUCT) {
+ if (!list || (list->type == INIT_DEEP)) {
+ if (list) list = list->init.deep;
+ sym = SPEC_STRUCT(type)->fields;
+ while (sym) {
+ DEBUGprintf ("Checking STRUCT member %s\n", sym->name);
+ if (!matchIvalToUnion(list, sym->type, 0)) {
+ DEBUGprintf ("ERROR, STRUCT member %s\n", sym->name);
+ return (NULL);
+ }
+ if (list) list = list->next;
+ sym = sym->next;
+ } // while
+
+ // excess initializers?
+ if (list) {
+ DEBUGprintf ("ERROR, excess initializers\n");
+ return (NULL);
+ }
+
+ DEBUGprintf ("OK, struct\n");
+ return (type);
+ }
+ return (NULL);
+ } else if (IS_STRUCT(type) && SPEC_STRUCT(getSpec(type))->type == UNION) {
+ if (!list || (list->type == INIT_DEEP)) {
+ if (list) list = list->init.deep;
+ sym = SPEC_STRUCT(type)->fields;
+ while (sym) {
+ DEBUGprintf ("Checking UNION member %s.\n", sym->name);
+ if (((IS_STRUCT(sym->type) || getSize(sym->type) == size))
+ && matchIvalToUnion(list, sym->type, size))
+ {
+ DEBUGprintf ("Matched UNION member %s.\n", sym->name);
+ return (sym->type);
+ }
+ sym = sym->next;
+ } // while
+ } // if
+ // no match found
+ DEBUGprintf ("ERROR, no match found.\n");
+ return (NULL);
+ } else {
+ assert ( !"Unhandled type in UNION." );
+ }
+
+ assert ( !"No match found in UNION for the given initializer structure." );
+ return (NULL);
+}
+
+/*
+ * Parse the type and its initializer and emit it (recursively).
+ */
+static void
+emitInitVal(struct dbuf_s *oBuf, symbol *topsym, sym_link *my_type, initList *list)
+{
+ symbol *sym;
+ int size, i;
+ long lit;
+ unsigned char *str;
+
+ size = getSize(my_type);
+
+ if (IS_PTR(my_type)) {
+ DEBUGprintf ("(pointer, %d byte) %p\n", size, list ? (void *)(long)list2int(list) : NULL);
+ emitIvals(oBuf, topsym, list, 0, size);
+ return;
+ }
+
+ if (IS_ARRAY(my_type) && topsym && topsym->isstrlit) {
+ str = (unsigned char *)SPEC_CVAL(topsym->etype).v_char;
+ emitIvalLabel(oBuf, topsym);
+ do {
+ dbuf_printf (oBuf, "\tretlw 0x%02x ; '%c'\n", str[0], (str[0] >= 0x20 && str[0] < 128) ? str[0] : '.');
+ } while (*(str++));
+ return;
+ }
+
+ if (IS_ARRAY(my_type) && list && list->type == INIT_NODE) {
+ fprintf (stderr, "Unhandled initialized symbol: %s\n", topsym->name);
+ assert ( !"Initialized char-arrays are not yet supported, assign at runtime instead." );
+ return;
+ }
+
+ if (IS_ARRAY(my_type)) {
+ DEBUGprintf ("(array, %d items, %d byte) below\n", DCL_ELEM(my_type), size);
+ assert (!list || list->type == INIT_DEEP);
+ if (list) list = list->init.deep;
+ for (i = 0; i < DCL_ELEM(my_type); i++) {
+ emitInitVal(oBuf, topsym, my_type->next, list);
+ topsym = NULL;
+ if (list) list = list->next;
+ } // for i
+ return;
+ }
+
+ if (IS_FLOAT(my_type)) {
+ // float, 32 bit
+ DEBUGprintf ("(float, %d byte) %lf\n", size, list ? list2int(list) : 0.0);
+ emitIvals(oBuf, topsym, list, 0, size);
+ return;
+ }
+
+ if (IS_CHAR(my_type) || IS_INT(my_type) || IS_LONG(my_type)) {
+ // integral type, 8, 16, or 32 bit
+ DEBUGprintf ("(integral, %d byte) 0x%lx/%ld\n", size, list ? (long)list2int(list) : 0, list ? (long)list2int(list) : 0);
+ emitIvals(oBuf, topsym, list, 0, size);
+ return;
+
+ } else if (IS_STRUCT(my_type) && SPEC_STRUCT(my_type)->type == STRUCT) {
+ // struct
+ DEBUGprintf ("(struct, %d byte) handled below\n", size);
+ assert (!list || (list->type == INIT_DEEP));
+
+ // iterate over struct members and initList
+ if (list) list = list->init.deep;
+ sym = SPEC_STRUCT(my_type)->fields;
+ while (sym) {
+ long bitfield = 0;
+ int len = 0;
+ if (IS_BITFIELD(sym->type)) {
+ while (sym && IS_BITFIELD(sym->type)) {
+ assert (!list || ((list->type == INIT_NODE)
+ && IS_AST_LIT_VALUE(list->init.node)));
+ lit = (long) (list ? list2int(list) : 0);
+ DEBUGprintf ( "(bitfield member) %02lx (%d bit, starting at %d, bitfield %02lx)\n",
+ lit, SPEC_BLEN(getSpec(sym->type)),
+ SPEC_BSTR(getSpec(sym->type)), bitfield);
+ bitfield |= (lit & ((1ul << SPEC_BLEN(getSpec(sym->type))) - 1)) << SPEC_BSTR(getSpec(sym->type));
+ len += SPEC_BLEN(getSpec(sym->type));
+
+ sym = sym->next;
+ if (list) list = list->next;
+ } // while
+ assert (len < sizeof (long) * 8); // did we overflow our initializer?!?
+ len = (len + 7) & ~0x07; // round up to full bytes
+ emitIvals(oBuf, topsym, NULL, bitfield, len / 8);
+ topsym = NULL;
+ } // if
+
+ if (sym) {
+ emitInitVal(oBuf, topsym, sym->type, list);
+ topsym = NULL;
+ sym = sym->next;
+ if (list) list = list->next;
+ } // if
+ } // while
+ if (list) {
+ assert ( !"Excess initializers." );
+ } // if
+ return;
+
+ } else if (IS_STRUCT(my_type) && SPEC_STRUCT(my_type)->type == UNION) {
+ // union
+ DEBUGprintf ("(union, %d byte) handled below\n", size);
+ assert (list && list->type == INIT_DEEP);
+
+ // iterate over union members and initList, try to map number and type of fields and initializers
+ my_type = matchIvalToUnion(list, my_type, size);
+ if (my_type) {
+ emitInitVal(oBuf, topsym, my_type, list->init.deep);
+ topsym = NULL;
+ size -= getSize(my_type);
+ if (size > 0) {
+ // pad with (leading) zeros
+ emitIvals(oBuf, NULL, NULL, 0, size);
+ }
+ return;
+ } // if
+
+ assert ( !"No UNION member matches the initializer structure.");
+ } else if (IS_BITFIELD(my_type)) {
+ assert ( !"bitfields should only occur in structs..." );
+
+ } else {
+ printf ("SPEC_NOUN: %d\n", SPEC_NOUN(my_type));
+ assert( !"Unhandled initialized type.");
+ }
+}
+
+/*
+ * Emit a set of symbols.
+ * type - 0: have symbol tell whether it is local, extern or global
+ * 1: assume all symbols in set to be global
+ * 2: assume all symbols in set to be extern
+ */
+static void
+emitSymbolSet(set *s, int type)
+{
+ symbol *sym;
+ initList *list;
+ unsigned sectionNr = 0;
+
+ for (sym = setFirstItem(s); sym; sym = setNextItem(s)) {