Example #1
0
void generate_for(component init, component condition, component next,
		  component iteration, const char *continue_label,
		  bool discard, fncode fn)
{
  struct whiledata wdata;

  env_block_push(NULL); /* init may have local declarations */
  if (init)
    generate_component(init, NULL, TRUE, fn);

  start_block(NULL, FALSE, discard, fn);
  wdata.continue_label = continue_label;
  wdata.looplab = new_label(fn);
  wdata.mainlab = new_label(fn);
  wdata.endlab = new_label(fn);
  wdata.code = iteration;
  wdata.next = next;

  set_label(wdata.looplab, fn);
  if (condition)
    {
      generate_condition(condition, wdata.mainlab, wmain_code, &wdata,
			 wdata.endlab, NULL, NULL, fn);
      set_label(wdata.endlab, fn);
      if (!discard)
	generate_component(component_undefined, NULL, FALSE, fn);
    }
  else
    wmain_code(&wdata, fn);
  end_block(fn);
  env_block_pop();
}
Example #2
0
static
switch_stmt(stream, node, brk, cont, ret) {
    auto i = 0, def;
    expr_code( stream, node[3], 0 );
    def = brk = new_label();

    if (node[5][0] != 'swtb')
        int_error("No table for switch statement");

    while ( i < node[5][1] ) {
        auto c = node[5][3 + i++];

        /* Make asm labels for each case label.  We store these as integers 
         * in the unused 3rd operator slot of the case node. */
        c[5] = new_label();

        if (c[0] == 'case')
            /* Case labels have to be integers */
            branch_eq_n( stream, c[3][3], c[5] );
        else 
            def = c[5];
    }
    
    branch( stream, def ); 
    stmt_code( stream, node[4], brk, cont, ret );
    emit_label( stream, brk );
}
  //=====================================================================================================================
  void visitAnd(And *p) {

      fprintf(m_outputfile, "#### AND\n");

      // Get two label locations
      int loc1 = new_label(); int loc2 = new_label();

      // Visit the children
      p->visit_children(this);

      fprintf( m_outputfile, "  popl %%ebx\n");
      fprintf( m_outputfile, "  popl %%eax\n");
      fprintf( m_outputfile, "  cmp $0, %%eax\n");
      fprintf( m_outputfile, "  je L%i\n", loc1);
      fprintf( m_outputfile, "  cmp $0, %%ebx\n");
      fprintf( m_outputfile, "  je L%i\n", loc1);
      fprintf( m_outputfile, "  mov $1, %%eax\n");
      fprintf( m_outputfile, "  jmp L%i\n", loc2);
      fprintf( m_outputfile, "L%i:\n", loc1);
      fprintf( m_outputfile, "  mov $0, %%eax\n");
      fprintf( m_outputfile, "L%i:\n", loc2);
      fprintf( m_outputfile, "  pushl %%eax\n");
      fprintf(m_outputfile, "####\n");

  }
Example #4
0
File: cc.c Project: Fedjmike/mini-c
void while_loop () {
    int loop_to = emit_label(new_label());
    int break_to = new_label();

    bool do_while = try_match("do");

    if (do_while)
        line();

    match("while");
    match("(");
    expr(0);
    match(")");

    fprintf(output, "cmp eax, 0\n"
                    "je _%08d\n", break_to);

    if (do_while)
        match(";");

    else
        line();

    fprintf(output, "jmp _%08d\n", loop_to);
    fprintf(output, "\t_%08d:\n", break_to);
}
Example #5
0
static void create_entry(PROC_T *p){
    p->hbox=gtk_hbox_new(FALSE,0);
    char lb[12];
    char stime[80];
    snprintf(lb,12," %5d",p->pid);
    struct tm *tim=localtime(&(p->status.timstart));
    strftime(stime,80,"[%F %k:%M:%S]",tim);
    strcat(stime,lb);
    p->entry_pid=new_label(stime,WIDTH_PID,0);
    p->entry_path=new_label(p->path,WIDTH_PATH,1);
    gtk_label_set_selectable(GTK_LABEL(p->entry_path), TRUE);
    gtk_label_set_ellipsize(GTK_LABEL(p->entry_path),PANGO_ELLIPSIZE_START);
#if GTK_MAJOR_VERSION>=3 || GTK_MINOR_VERSION >= 12
    gtk_widget_set_tooltip_text(p->entry_path, p->path);
#endif
    p->entry_errlo=new_label("Lo (nm)",WIDTH_ERRLO,1);
    p->entry_errhi=new_label("Hi (nm)",WIDTH_ERRHI,1);
    p->entry_iseed=new_entry("iSEED",WIDTH_ISEED,0.5);
    p->entry_timing=new_entry("Timing",WIDTH_TIMING,1);
    /*kill_button_new(p); */
    change_button(p, GTK_STOCK_STOP, (GCallback)kill_job_event);
    int irow=nrows[p->hid];
    nrows[p->hid]++;
    gtk_table_resize(GTK_TABLE(tables[p->hid]), nrows[p->hid],ncol);
    grid_attach(tables[p->hid], p->entry_pid, 0,1,irow,irow+1,0);
    grid_attach(tables[p->hid], p->entry_path, 1,2,irow,irow+1,7);
    grid_attach(tables[p->hid], p->entry_errlo, 2,3,irow,irow+1,0);
    grid_attach(tables[p->hid], p->entry_errhi, 3,4,irow,irow+1,0);
    grid_attach(tables[p->hid], p->entry_iseed, 4,5,irow,irow+1,0);
    grid_attach(tables[p->hid], p->entry_timing, 5,6,irow,irow+1,0);
    grid_attach(tables[p->hid], p->btn, 6,7,irow,irow+1,0);
    gtk_widget_show_all(tables[p->hid]);
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook),p->hid);
}
Example #6
0
File: icode.c Project: doniexun/zcc
/*===-------------------------------------------------------------------------
expr1 * expr2 * expr3
-------------------------------------------------------------------------===*/
static symbol *equ_expr2ic(ast *root) {
	ast *t = root, *t1, *t2;
	symbol *s1, *s2, *val, *lab;
	type *dt, *ty = t->ty;
	int pre;

	if (t->node != AST_EQU && t->node != AST_UE)
		return rel_expr2ic(t);
	assert(ty == int_type);
	// s1 = expr1
	t1 = t->left;
	s1 = rel_expr2ic(t1);
	// more than one operator of equal precedence
	//ic = eval_icode_node(t->node);
	pre = t->node;
	t = t->right;
	while (t->node == AST_EQU || t->node == AST_UE) {
		t2 = t->left;
		s2 = rel_expr2ic(t2);
		dt = get_arith_type(s1->ty, s2->ty);
		emit_ic(IC_CMP + gen_post(dt->cat, dt->cat), cast(s1, dt), cast(s2, dt));
		lab = gen_label(NULL);
		emit_branch(IC_JE, lab);
		val = gen_vit_reg(ty);
		if (pre == AST_EQU)
			emit_ic(IC_MOV + i32, val, cnst_zero);
		else
			emit_ic(IC_MOV + i32, val, cnst_one);
		new_label(lab);
		if (pre == AST_EQU)
			emit_ic(IC_MOV + i32, val, cnst_one);
		else
			emit_ic(IC_MOV + i32, val, cnst_zero);
		///
		s1 = val;
		pre = t->node;
		t = t->right;
	}
	// last sub-expression or only has one operator(etc, a + b)
	s2 = rel_expr2ic(t);
	dt = get_arith_type(s1->ty, s2->ty);
	emit_ic(IC_CMP + gen_post(dt->cat, dt->cat), cast(s1, dt), cast(s2, dt));
	lab = gen_label(NULL);
	emit_branch(IC_JE, lab);
	val = gen_vit_reg(ty);
	if (pre == AST_EQU)
		emit_ic(IC_MOV + i32, val, cnst_zero);
	else
		emit_ic(IC_MOV + i32, val, cnst_one);
	new_label(lab);
	if (pre == AST_EQU)
		emit_ic(IC_MOV + i32, val, cnst_one);
	else
		emit_ic(IC_MOV + i32, val, cnst_zero);

	return val;
}
Example #7
0
File: cc.c Project: Fedjmike/mini-c
void object () {
    factor();

    while (true) {
        if (try_match("(")) {
            fputs("push eax\n", output);

            int arg_no = 0;

            if (waiting_for(")")) {
                //cdecl requires arguments to be pushed on backwards
                
                int start_label = new_label();
                int end_label = new_label();
                int prev_label = end_label;

                fprintf(output, "jmp _%08d\n", start_label);

                do {
                    int next_label = emit_label(new_label());
                    expr(0);
                    fprintf(output, "push eax\n"
                                    "jmp _%08d\n", prev_label);
                    arg_no++;

                    prev_label = next_label;
                } while (try_match(","));

                fprintf(output, "_%08d:\n", start_label);
                fprintf(output, "jmp _%08d\n", prev_label);
                fprintf(output, "_%08d:\n", end_label);
            }

            match(")");

            fprintf(output, "call dword ptr [esp+%d]\n", arg_no*word_size);
            fprintf(output, "add esp, %d\n", (arg_no+1)*word_size);

        } else if (try_match("[")) {
            fputs("push eax\n", output);

            expr(0);
            match("]");

            if (see("=") || see("++") || see("--"))
                lvalue = true;

            fprintf(output, "pop ebx\n"
                            "%s eax, [eax*%d+ebx]\n", lvalue ? "lea" : "mov", word_size);

        } else
            return;
    }
}
Example #8
0
static
while_stmt(stream, node, brk, cont, ret) {
    cont = new_label();
    emit_label( stream, cont );

    expr_code( stream, node[3], 0 );
    brk = new_label();
    branch_ifz( stream, brk );

    stmt_code( stream, node[4], brk, cont, ret );
    branch( stream, cont );
    emit_label( stream, brk );
}
intercodes translate_Cond(struct Node *node,operand label_true,operand label_false) {
	struct Node *child = node->child;
	assert(child != NULL);
	intercodes code1,code2,code3,code4;
	//Exp1 RELOP Exp2
	if (child->sibling != NULL && strcmp(child->sibling->type,"RELOP") == 0) {
		operand t1 = new_tmp();
		operand t2 = new_tmp();
		code1 = translate_Exp(child,t1);
		code2 = translate_Exp(child->sibling->sibling,t2);
		relop_type type = get_relop(child->sibling);
		code3 = gen_triop(type,t1,t2,label_true);
		code4 = gen_one(GOTO_K,label_false);
		code1 = link(code1,code2);
		code1 = link(code1,code3);
		code1 = link(code1,code4);
		return code1;
	}
	//NOT Exp1
	if (strcmp(child->type,"NOT") == 0) 
		return translate_Cond(child->sibling,label_true,label_false);
	//Exp1 AND Exp2
	if (child->sibling != NULL && strcmp(child->sibling->type,"AND") == 0) {
		operand label1 = new_label();
		code1 = translate_Cond(child,label1,label_false);
		code2 = translate_Cond(child->sibling->sibling,label_true,label_false);
		code3 = gen_one(LABEL_K,label1);
		code1 = link(code1,code3);
		code1 = link(code1,code2);
		return code1;
	}
	//Exp1 OR Exp2
	if (child->sibling != NULL && strcmp(child->sibling->type,"OR") == 0) {
		operand label1 = new_label();
		code1 = translate_Cond(child,label_true,label1);
		code2 = translate_Cond(child->sibling->sibling,label_true,label_false);
		code3 = gen_one(LABEL_K,label1);
		code1 = link(code1,code3);
		code1 = link(code1,code2);
		return code1;
	}
	//other cases
	operand t1 = new_tmp();
	code1 = translate_Exp(node,t1);
	operand c1 = new_constant(0);
	code2 = gen_triop(NE,t1,c1,label_true);
	code3 = gen_one(LABEL_K,label_false);
	code1 = link(code1,code2);
	code1 = link(code1,code3);
	return code1;
}
Example #10
0
File: icode.c Project: doniexun/zcc
/*===-------------------------------------------------------------------------
expr1 * expr2 * expr3
-------------------------------------------------------------------------===*/
static symbol *rel_expr2ic(ast *root) {
	ast *t = root, *t1, *t2;
	symbol *s1, *s2, *val, *lab;
	type *dt, *ty = t->ty;
	int ic;

	assert(t->node != AST_G && t->node != AST_GE);
	if (t->node != AST_L && t->node != AST_LE)
		return arith_expr2ic(t);
	assert(ty == int_type);
	// s1 = expr1
	t1 = t->left;
	s1 = arith_expr2ic(t1);
	// more than one operator of equal precedence
	if (t->node == AST_L)
		ic = IC_JL;
	else
		ic = IC_JLE;
	t = t->right;
	while (t->node == AST_L || t->node == AST_LE) {
		t2 = t->left;
		s2 = arith_expr2ic(t2);
		dt = get_arith_type(s1->ty, s2->ty);
		emit_ic(IC_CMP + gen_post(dt->cat, dt->cat), cast(s1, dt), cast(s2, dt));
		lab = gen_label(NULL);
		emit_branch(ic, lab);
		val = gen_vit_reg(ty);
		emit_ic(IC_MOV + i32, val, cnst_zero);
		new_label(lab);
		emit_ic(IC_MOV + i32, val, cnst_one);
		///
		s1 = val;
		if (t->node == AST_L)
			ic = IC_JL;
		else
			ic = IC_JLE;
		t = t->right;
	}
	// last sub-expression or only has one operator(etc, a + b)
	s2 = arith_expr2ic(t);
	dt = get_arith_type(s1->ty, s2->ty);
	emit_ic(IC_CMP + gen_post(dt->cat, dt->cat), cast(s1, dt), cast(s2, dt));
	lab = gen_label(NULL);
	emit_branch(ic, lab);
	val = gen_vit_reg(ty);
	emit_ic(IC_MOV + i32, val, cnst_zero);
	new_label(lab);
	emit_ic(IC_MOV + i32, val, cnst_one);

	return val;
}
Example #11
0
 void visitWhileLoop(WhileLoop * p)
 {
   fprintf(m_outputfile, "\t ## WhileLoop ##\n");
   int label_number_loop = new_label();
   int label_number_done = new_label();
   fprintf(m_outputfile, "Loop_%d:\n", label_number_loop);
   p->m_expr->accept(this);
   fprintf(m_outputfile, "\tpopl\t%%ecx\n");
   fprintf(m_outputfile, "\tjecxz\tDone_%d\n", label_number_done);
   p->m_nested_block->accept(this);
   fprintf(m_outputfile, "\tjmp\tLoop_%d\n", label_number_loop);    
   fprintf(m_outputfile, "Done_%d:\n", label_number_done);
   fprintf(m_outputfile, "\t ## END WhileLoop ##\n");
 }
Example #12
0
static
conditional(stream, node) {
    auto l1 = new_label(), l2 = new_label();

    expr_code( stream, node[3], 0 );

    branch_ifz( stream, l1 );
    expr_code( stream, node[4], 0 );
    branch( stream, l2 );
    
    emit_label( stream, l1 );
    expr_code( stream, node[5], 0 );
    emit_label( stream, l2 );
}
Example #13
0
char *code_omp_stmt(ASTNode stmt,int BASEREG){
	CODE86	*code;
	CODELIST	omplist;
	char	*lfe,*lfb,*ompf;
	omp_count+=1;
	ompf=new_label(LABEL_SYM,(void *)func_sym,omp_count);
	lfe=new_label(LABEL_LFE,NULL,0);
	lfb=new_label(LABEL_LFB,NULL,0);
	omplist.head=omplist.tail=NULL;
	code=newcode(PS_TYPE,newdessrc(IMM,1,NULL,NONE,0,0),NULL,(void *)ompf);
	code_link_one(&omplist,code);
	code=newcode(PS_LABEL,NULL,NULL,(void *)ompf);
	code_link_one(&omplist,code);
	code=newcode(PS_LABEL,NULL,NULL,(void *)lfb);
	code_link_one(&omplist,code);
/* pushl %ebp */
	code=newcode(OP_PUSHL,newdessrc(REG,0,NULL,EBP,0,0),NULL,NULL);;
	code_link_one(&omplist,code);
/* movl %esp, %ebp */
	code=newcode(OP_MOVL,newdessrc(REG,0,NULL,ESP,0,0),newdessrc(REG,0,NULL,EBP,0,0),NULL);
	code_link_one(&omplist,code);
/* pushl %esi */
	code=newcode(OP_PUSHL,newdessrc(REG,0,NULL,ESI,0,0),NULL,NULL);;
	code_link_one(&omplist,code);
/* movl 8(%ebp),%esi */
	code=newcode(OP_MOVL,newdessrc(REG_OFFSET,0,NULL,EBP,8,0),newdessrc(REG,0,NULL,ESI,0,0),NULL);
	code_link_one(&omplist,code);
/* generate function code */
	code_stmt(stmt,ESI);
	code_link(&omplist,&stmt->codes);
/* popl %esi */
	code=newcode(OP_POPL,newdessrc(REG,0,NULL,ESI,0,0),NULL,NULL);;
	code_link_one(&omplist,code);
/* leave */
	code=newcode(OP_LEAVE,NULL,NULL,NULL);;
	code_link_one(&omplist,code);
/* ret */
	code=newcode(OP_RET,NULL,NULL,NULL);
	code_link_one(&omplist,code);
/* .lfb */
	code=newcode(PS_LABEL,NULL,NULL,(void *)lfe);
	code_link_one(&omplist,code);
/* .size */
	code=newcode(PS_SIZE,NULL,newdessrc(IMM,2,NULL,NONE,0,0),ompf);
	code_link_one(&omplist,code);
	code_link(&omp_functions,&omplist);

	return ompf;
}
Example #14
0
static void create_entry(PROC_T *p){
    p->hbox=gtk_hbox_new(FALSE,0);
    char lb[12];
    snprintf(lb,12," %5d",p->pid);
    struct tm *tim=localtime(&(p->status.timstart));
    char stime[80];
    strftime(stime,80,"[%a %k:%M:%S]",tim);
    p->entry_start=new_label(stime,WIDTH_START,0.5);
    p->entry_pid=new_label(lb,WIDTH_PID,1);
    p->entry_path=new_label(p->path,WIDTH_PATH,1);
    gtk_label_set_selectable(GTK_LABEL(p->entry_path), TRUE);
    gtk_label_set_ellipsize(GTK_LABEL(p->entry_path),PANGO_ELLIPSIZE_START);
#if GTK_MAJOR_VERSION>=3 || GTK_MINOR_VERSION >= 12
    gtk_widget_set_tooltip_text(p->entry_path, p->path);
#endif
    p->entry_errlo=new_label("Lo (nm)",WIDTH_ERRLO,1);
    p->entry_errhi=new_label("Hi (nm)",WIDTH_ERRHI,1);
    gtk_label_set_max_width_chars(GTK_LABEL(p->entry_errlo),WIDTH_ERRLO);
    gtk_label_set_max_width_chars(GTK_LABEL(p->entry_errhi),WIDTH_ERRHI);
    p->entry_iseed=new_entry("seed",WIDTH_ISEED,0.5);
    p->entry_timing=new_entry("Timing",WIDTH_TIMING,1);
    gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_start,FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_pid,FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_path,TRUE,TRUE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_errlo,FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_errhi,FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_iseed,FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_timing,FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0);
    change_button(p, GTK_STOCK_PREFERENCES, (void*)kill_job_event);
    gtk_box_pack_start(GTK_BOX(p->hbox),p->btn,FALSE,FALSE,0);
    p->vbox=gtk_vbox_new(FALSE,0);
    if(nproc[p->hid]==1){
	gtk_box_pack_start(GTK_BOX(p->vbox),gtk_hseparator_new(),FALSE,FALSE,0);
    }
    gtk_box_pack_start(GTK_BOX(p->vbox),p->hbox,FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(p->vbox),gtk_hseparator_new(),FALSE,FALSE,0);
    gtk_box_pack_start(GTK_BOX(pages[p->hid]),p->vbox,FALSE,FALSE,0);
    
    /*gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook),p->hid); */
    gtk_widget_show_all(p->vbox);
}
Example #15
0
  void visitLteq(Lteq * p)
  {
	p->visit_children(this);
	int j=new_label();
	int end=new_label();
	fprintf(m_outputfile, "popl %%eax\n");
	fprintf(m_outputfile, "popl %%ebx\n");
	fprintf(m_outputfile, "cmp %%eax, %%ebx\n");
	fprintf(m_outputfile, "jle L%d\n", j);
	fprintf(m_outputfile, "pushl $0\n");
	fprintf(m_outputfile, "jmp L%d\n",end);
	fprintf(m_outputfile, "L%d:\n", j);
	fprintf(m_outputfile, "pushl $1\n");
	fprintf(m_outputfile, "L%d:\n", end);
  }
Example #16
0
static
do_stmt(stream, node, brk, cont, ret) {
    auto start = new_label();
    emit_label( stream, start );

    cont = new_label();
    brk = new_label();
    
    stmt_code( stream, node[3], brk, cont, ret );

    emit_label( stream, cont );
    expr_code( stream, node[4], 0 );
    branch_ifnz( stream, start );
    emit_label( stream, brk );
}
Example #17
0
  void visitIfWithElse(IfWithElse * p)
  {
//lattice
	p->m_expr->accept(this);
	int end=new_label();
	int b=new_label();
	fprintf(m_outputfile, "popl %%ecx\n");
	fprintf(m_outputfile, "jecxz L%d\n", b);
	p->m_nested_block_1->accept(this);
	fprintf(m_outputfile, "jmp L%d\n", end);
	fprintf(m_outputfile, "L%d:\n", b);
	p->m_nested_block_2->accept(this);
	fprintf(m_outputfile, "L%d:\n", end);

  }
Example #18
0
 void visitIfWithElse(IfWithElse * p)
 {
   fprintf(m_outputfile, "\t ## IfWithElse ##\n");
   p->m_expr->accept(this);
   int label_number_else = new_label();
   int label_number_done = new_label();
   fprintf(m_outputfile, "\tpopl\t%%ecx\n");
   fprintf(m_outputfile, "\tjecxz\tElse_%d\n", label_number_else);
   p->m_nested_block_1->accept(this);
   fprintf(m_outputfile, "\tjmp\tDone_%d\n", label_number_done);
   fprintf(m_outputfile, "Else_%d:\n", label_number_else);
   p->m_nested_block_2->accept(this);
   fprintf(m_outputfile, "Done_%d:\n", label_number_done);
   fprintf(m_outputfile, "\t ## END IfWithElse ##\n");
 }
Example #19
0
static void generate_if(component condition, component success,
			component failure, fncode fn)
{
  struct ifdata ifdata;

  ifdata.slab = new_label(fn);
  ifdata.flab = new_label(fn);
  ifdata.endlab = new_label(fn);
  ifdata.success = success;
  ifdata.failure = failure;

  generate_condition(condition, ifdata.slab, ifs_code, &ifdata,
		     ifdata.flab, iff_code, &ifdata, fn);
  set_label(ifdata.endlab, fn);
  adjust_depth(1, fn);
}
Example #20
0
 void visitProcImpl(ProcImpl * p)
 {
   int skip_label = new_label();
   fprintf(m_outputfile, "\tjmp\tskip_nested_procedure%d\n", skip_label);
   fprintf(m_outputfile, "\t ## Proc ##\n");
   fprintf(m_outputfile, "%s:\n", p->m_symname->spelling());
   fprintf(m_outputfile, "\tpushl\t%%ebp\n");
   fprintf(m_outputfile, "\tmovl\t%%esp, %%ebp\n");
   int num_args = 0;
   list<Decl_ptr>::iterator m_decl_list_iter;
   for(m_decl_list_iter = p->m_decl_list->begin();
     m_decl_list_iter != p->m_decl_list->end();
     ++m_decl_list_iter)
   {
     num_args += ((Decl *)(*m_decl_list_iter))->m_symname_list->size();
   }
   for (int i = 1; i <= num_args; i++)
   {
     int offset = 4 + (i*4);
     fprintf(m_outputfile, "\tpushl\t%d(%%ebp)\n", offset);      
   }
   p->m_function_block->accept(this);
   fprintf(m_outputfile, "\tpopl\t%%ebx\n");
   fprintf(m_outputfile, "\tmovl\t%%ebx, %%ebp\n");
   fprintf(m_outputfile, "\tret\n");
   fprintf(m_outputfile, "\t ## END Proc ##\n");
   fprintf(m_outputfile, "skip_nested_procedure%d:\n", skip_label);
 }
Example #21
0
 void visitNot(Not * p)
 {
   fprintf(m_outputfile, "\t ## Not ##\n");
   p->visit_children(this);
   int label_number_set_to_one = new_label();
   int label_number_done = new_label();
   fprintf(m_outputfile, "\tpopl\t%%ecx\n");
   fprintf(m_outputfile, "\tjecxz\tSet_To_One_%d\n", label_number_set_to_one);
   fprintf(m_outputfile, "\tmovl\t$0, %%eax\n");
   fprintf(m_outputfile, "\tjmp\tDone_%d\n", label_number_done);
   fprintf(m_outputfile, "Set_To_One_%d:\n", label_number_set_to_one);
   fprintf(m_outputfile, "\tmovl\t$1, %%eax\n");
   fprintf(m_outputfile, "Done_%d:\n", label_number_done);
   fprintf(m_outputfile, "\tpushl\t%%eax\n");
   fprintf(m_outputfile, "\t ## END Not ##\n");
 }
Example #22
0
  void visitIf(If *p) {
     fprintf( m_outputfile, "#### IF Statemet\n");

// cout<<"before IF Express"<<endl;
  if (p->m_expression != NULL) {
    p->m_expression->accept( this );
  } else {
    this->visitNullPointer();
  }
      fprintf( m_outputfile, " popl %%eax\n");
      fprintf( m_outputfile, " movl $0 , %%ebx\n");
      fprintf( m_outputfile, " cmp %%eax, %%ebx\n");
      fprintf( m_outputfile, " je skip_%d\n", new_label());
// cout<<"the label count is: "<<label_count<<endl;
// cout<<"Before IF state after express"<<endl;
  if (p->m_statement != NULL) {
    p->m_statement->accept( this );
  } else {
    this->visitNullPointer();
  }
// cout<<"After IF Statemetn"<<endl;
      fprintf( m_outputfile, " skip_%d: \n",label_count-1);

         // WRITEME

  }
Example #23
0
LABEL_INFO * new_clabel(SYM * st, SMEM_POOL * pool)
{
	LABEL_INFO * li = new_label(pool);
	LABEL_INFO_name(li) = st;
	LABEL_INFO_type(li) = L_CLABEL;
	return li;
}
Example #24
0
// for board tiles - used in order to display pieces on the board tiles
void add_label_to_button(TreeNode *button, char* pic){
	Button *btn = button->control;
	button->child_num = 1;
	button->children = malloc(sizeof(TreeNode*));
	button->children[0] = NULL;
	new_label(button, pic, btn->x, btn->y, btn->width, btn->height, 0, pic);
}
Example #25
0
inline
void If::gen(const std::uint32_t &b, const std::uint32_t &a) {
    auto label = new_label();
    expr_->jumping(0, a);
    emit_label(label);
    statement_->gen(label, a);
}
Example #26
0
static
named_label(name, is_defn) {
    if ( save_label( name, 0 ) )
        return set_label( name, new_label() );
    else
        return get_label( name );
}
Example #27
0
void generate_condition(component condition,
			label slab, gencode scode, void *sdata,
			label flab, gencode fcode, void *fdata,
			fncode fn)
{
  struct andordata data;

  switch (condition->vclass)
    {
    case c_builtin:
      switch (condition->u.builtin.fn)
	{
	case b_sc_and: case b_sc_or:
	  {
	    component arg1 = condition->u.builtin.args->c;

	    data.arg2 = condition->u.builtin.args->next->c;
	    data.lab = new_label(fn);
	    data.slab = slab; data.scode = scode; data.sdata = sdata;
	    data.flab = flab; data.fcode = fcode; data.fdata = fdata;

	    if (condition->u.builtin.fn == b_sc_and)
	      generate_condition(arg1,
				 data.lab, andorcode, &data,
				 flab, NULL, NULL,
				 fn);
	    else
	      generate_condition(arg1,
				 slab, NULL, NULL,
				 data.lab, andorcode, &data,
				 fn);
	    return;
	  }
	case b_not:
	  /* Just swap conclusions */
	  generate_condition(condition->u.builtin.args->c,
			     flab, fcode, fdata,
			     slab, scode, sdata,
			     fn);
	  return;
	}
      /* Fall through */
    default:
      generate_component(condition, NULL, FALSE, fn);
      if (scode)
	{
	  branch(OPmbf3, flab, fn);
	  scode(sdata, fn);
	  if (fcode) fcode(fdata, fn);
	}
      else
	{
	  branch(OPmbt3, slab, fn);
	  if (fcode) fcode(fdata, fn);
	  else branch(OPmba3, flab, fn);
	}
      break;
    }
}
Example #28
0
 // comparison operations
 void visitCompare(Compare * p)
 {
   p->visit_children(this);
   int label_number_true = new_label();
   int label_number_done = new_label();
   fprintf(m_outputfile, "\t ## Compare ##\n");
   fprintf(m_outputfile, "\tpopl\t%%eax\n");
   fprintf(m_outputfile, "\tpopl\t%%ecx\n");
   fprintf(m_outputfile, "\tsubl\t%%eax, %%ecx\n");
   fprintf(m_outputfile, "\tjecxz\tTrue_%d\n", label_number_true);
   fprintf(m_outputfile, "\tmovl\t$0, %%eax\n");
   fprintf(m_outputfile, "\tjmp\tDone_%d\n", label_number_done);
   fprintf(m_outputfile, "True_%d:\n", label_number_true);
   fprintf(m_outputfile, "\tmovl\t$1, %%eax\n");
   fprintf(m_outputfile, "Done_%d:\n", label_number_done);
   fprintf(m_outputfile, "\tpushl\t%%eax\n");
 }
Example #29
0
 void visitNoteq(Noteq * p)
 {
   p->visit_children(this);
   int label_number_false = new_label();
   int label_number_done = new_label();
   fprintf(m_outputfile, "\t ## Noteq ##\n");
   fprintf(m_outputfile, "\tpopl\t%%eax\n");
   fprintf(m_outputfile, "\tpopl\t%%ecx\n");
   fprintf(m_outputfile, "\tsubl\t%%eax, %%ecx\n");
   fprintf(m_outputfile, "\tjecxz\tFalse_%d\n", label_number_false);
   fprintf(m_outputfile, "\tmovl\t$1, %%eax\n");
   fprintf(m_outputfile, "\tjmp\tDone_%d\n", label_number_done);
   fprintf(m_outputfile, "False_%d:\n", label_number_false);
   fprintf(m_outputfile, "\tmovl\t$0, %%eax\n");
   fprintf(m_outputfile, "Done_%d:\n", label_number_done);
   fprintf(m_outputfile, "\tpushl\t%%eax\n");
 }
Example #30
0
static void generate_while(component condition, component iteration, fncode fn)
{
  struct whiledata wdata;

  wdata.looplab = new_label(fn);
  wdata.mainlab = new_label(fn);
  wdata.exitlab = new_label(fn);
  wdata.endlab = new_label(fn);
  wdata.code = iteration;

  env_start_loop();
  set_label(wdata.looplab, fn);
  generate_condition(condition, wdata.mainlab, wmain_code, &wdata,
		     wdata.exitlab, wexit_code, &wdata, fn);
  set_label(wdata.endlab, fn);
  env_end_loop();
  adjust_depth(1, fn);
}