Example #1
0
static sblock_t *
flow_generate (flowgraph_t *graph)
{
	int         i;
	sblock_t   *code = 0;
	sblock_t  **tail = &code;

	for (i = 0; i < graph->num_nodes; i++) {
		ex_label_t *label;
		sblock_t   *block;

		flownode_t *node = graph->nodes[i];
		*tail = block = new_sblock ();
		tail = &(*tail)->next;
		// first, transfer any labels on the old node to the new
		while ((label = node->sblock->labels)) {
			node->sblock->labels = label->next;
			label->next = block->labels;
			block->labels = label;
			label->dest = block;
		}
		// generate new statements from the dag;
		dag_generate (node->dag, block);
	}
	if (options.block_dot.post)
		dump_dot ("post", code, dump_dot_sblock);
	return code;
}
Example #2
0
File: vasm.c Project: ezrec/vasm
static void assemble(void)
{
    section *sec;
    atom *p;
    char *attr;
    int bss;

    final_pass=1;
    for(sec=first_section; sec; sec=sec->next) {
        source *lasterrsrc=NULL;
        int lasterrline=0;
        sec->pc=sec->org;
        attr=sec->attr;
        bss=0;
        while(*attr) {
            if(*attr++=='u') {
                bss=1;
                break;
            }
        }
        for(p=sec->first; p; p=p->next) {
            sec->pc=(sec->pc+p->align-1)/p->align*p->align;
            cur_src=p->src;
            cur_src->line=p->line;
            if(p->list&&p->list->atom==p) {
                p->list->sec=sec;
                p->list->pc=sec->pc;
            }
            if(p->type==INSTRUCTION) {
                dblock *db;
                cur_listing=p->list;
                db=eval_instruction(p->content.inst,sec,sec->pc);
                if(pic_check)
                    do_pic_check(db->relocs);
                cur_listing=0;
                if(DEBUG) {
                    if(db->size!=instruction_size(p->content.inst,sec,sec->pc))
                        ierror(0);
                }
                /*FIXME: sauber freigeben */
                myfree(p->content.inst);
                p->content.db=db;
                p->type=DATA;
            }
            else if(p->type==DATADEF) {
                dblock *db;
                cur_listing=p->list;
                db=eval_data(p->content.defb->op,p->content.defb->bitsize,sec,sec->pc);
                if(pic_check)
                    do_pic_check(db->relocs);
                cur_listing=0;
                /*FIXME: sauber freigeben */
                myfree(p->content.defb);
                p->content.db=db;
                p->type=DATA;
            }
            else if(p->type==RORG) {
                sblock *sb;
                taddr space;
                if(eval_expr(p->content.roffs,&space,sec,sec->pc)) {
                    space=sec->org+space-sec->pc;
                    if (space>=0) {
                        sb=new_sblock(number_expr(space),1,0);
                        p->content.sb=sb;
                        p->type=SPACE;
                    }
                    else
                        general_error(20);  /* rorg is lower than current pc */
                }
                else
                    general_error(30);  /* expression must be constant */
            }
            else if(p->type==DATA&&bss) {
                if(lasterrsrc!=p->src||lasterrline!=p->line) {
                    general_error(31);  /* initialized data in bss */
                    lasterrsrc=p->src;
                    lasterrline=p->line;
                }
            }
#ifdef HAVE_CPU_OPTS
            else if(p->type==OPTS)
                cpu_opts(p->content.opts);
#endif
            else if(p->type==PRINTTEXT)
                printf("%s\n",p->content.ptext);
            else if (p->type==PRINTEXPR) {
                taddr val;
                eval_expr(p->content.pexpr,&val,sec,sec->pc);
                printf("%ld (0x%lx)\n",(long)val,(unsigned long)val);
            }
            sec->pc+=atom_size(p,sec,sec->pc);
        }
    }
}