示例#1
0
static void print_block_stmt(int indent, struct stmts *block)
{
	print_indent(indent);
	printf("BLOCK\n");
	int i;
	for (i = 0; i < block->v_n; i++) {
		struct stmt *s = block->v[i];
		print_stmt(indent+1, s);
	}
}
/* 
    Print all statements
*/
void print_stmts(Stmts stmts, char* proc_id) {
    Stmt first = stmts->first;
    Stmts rest = stmts->rest;

    if (first) {
        print_stmt(first, proc_id);
    }
    if (rest) {
        print_stmts(rest, proc_id);
    }
}
示例#3
0
void print_stmt(stmt *t)
{
	idt_printf("statement: %s\n", t->f_str());

	if(t->flow){
		gen_str_indent++;
		print_stmt_flow(t->flow);
		gen_str_indent--;
	}

	PRINT_IF(t, expr, print_expr);
	PRINT_IF(t, lhs,  print_stmt);
	PRINT_IF(t, rhs,  print_stmt);
	PRINT_IF(t, rhs,  print_stmt);

	if(stmt_kind(t, code)){
		idt_printf("structs/unions/enums:\n");
		gen_str_indent++;
		print_sues_static_asserts(t->symtab);
		gen_str_indent--;

		if(t->symtab){
			decl **iter;

			idt_printf("stack space %d\n", t->symtab->auto_total_size);
			idt_printf("decls:\n");

			for(iter = t->symtab->decls; iter && *iter; iter++){
				decl *d = *iter;

				gen_str_indent++;
				print_decl(d, PDECL_INDENT
						| PDECL_NEWLINE
						| PDECL_SYM_OFFSET
						| PDECL_ATTR
						| PDECL_PINIT);
				gen_str_indent--;
			}
		}

		if(t->bits.code.stmts){
			stmt **iter;

			idt_printf("code:\n");

			for(iter = t->bits.code.stmts; *iter; iter++){
				gen_str_indent++;
				print_stmt(*iter);
				gen_str_indent--;
			}
		}
	}
}
示例#4
0
void print_decl(decl *d, enum pdeclargs mode)
{
	if(mode & PDECL_INDENT)
		idt_print();

	if(d->store)
		fprintf(cc1_out, "%s ", decl_store_to_str(d->store));

	if(fopt_mode & FOPT_ENGLISH){
		print_decl_eng(d);
	}else{
		print_type(d->ref, d);
	}

	if(mode & PDECL_SYM_OFFSET){
		if(d->sym){
			const int off = d->sym->type == sym_arg
				? d->sym->loc.arg_offset
				: (int)d->sym->loc.stack_pos;

			fprintf(cc1_out, " (sym %s, pos = %d)",
					sym_to_str(d->sym->type), off);
		}else{
			fprintf(cc1_out, " (no sym)");
		}
	}

	if(mode & PDECL_SIZE && !type_is(d->ref, type_func)){
		if(type_is_complete(d->ref)){
			const unsigned sz = decl_size(d);
			const unsigned align = decl_align(d);

			fprintf(cc1_out, " size %u, align %u", sz, align);
		}else{
			fprintf(cc1_out, " incomplete decl");
		}
	}

	if(mode & PDECL_NEWLINE)
		fputc('\n', cc1_out);

	if(!type_is(d->ref, type_func)
	&& d->bits.var.init.dinit
	&& mode & PDECL_PINIT)
	{
		gen_str_indent++;
		print_decl_init(d->bits.var.init.dinit);
		gen_str_indent--;
	}

	if(mode & PDECL_ATTR){
		gen_str_indent++;
		if(!type_is(d->ref, type_func) && d->bits.var.align)
			idt_printf("[align={as_int=%d, resolved=%d}]\n",
					d->bits.var.align->as_int, d->bits.var.align->resolved);
		print_attribute(d->attr);
		print_type_attr(d->ref);
		gen_str_indent--;
	}

	if((mode & PDECL_FUNC_DESCEND) && DECL_HAS_FUNC_CODE(d)){
		decl **iter;

		gen_str_indent++;

		for(iter = d->bits.func.code->symtab->decls; iter && *iter; iter++){
			sym *s = (*iter)->sym;
			if(s)
				idt_printf("offset of %s = %d\n", (*iter)->spel, s->loc.stack_pos);
		}

		idt_printf("function stack space %d\n",
				d->bits.func.code->symtab->auto_total_size);

		print_stmt(d->bits.func.code);

		gen_str_indent--;
	}
}