Example #1
0
void dumpLabel(LabelInfo const* li)
{
    if (g_tfile == NULL) return;
    if (LABEL_INFO_type(li) == L_ILABEL) {
        fprintf(g_tfile, "\nilabel(" ILABEL_STR_FORMAT ")",
                ILABEL_CONT(li));
    } else if (LABEL_INFO_type(li) == L_CLABEL) {
        fprintf(g_tfile, "\nclabel(" CLABEL_STR_FORMAT ")",
                CLABEL_CONT(li));
    } else if (LABEL_INFO_type(li) == L_PRAGMA) {
        ASSERT0(LABEL_INFO_pragma(li));
        fprintf(g_tfile, "\npragms(%s)",
                SYM_name(LABEL_INFO_pragma(li)));
    } else { UNREACH(); }

    if (LABEL_INFO_b1(li) != 0) {
        fprintf(g_tfile, "(");
    }
    if (LABEL_INFO_is_try_start(li)) {
        fprintf(g_tfile, "try_start ");
    }
    if (LABEL_INFO_is_try_end(li)) {
        fprintf(g_tfile, "try_end ");
    }
    if (LABEL_INFO_is_catch_start(li)) {
        fprintf(g_tfile, "catch_start ");
    }
    if (LABEL_INFO_b1(li) != 0) {
        fprintf(g_tfile, ")");
    }
    fflush(g_tfile);
}
Example #2
0
/*
Return VAR if there is already related to 's',
otherwise create a new VAR.
'var_name': name of the variable, it is optional.
's': string's content.
*/
VAR * VAR_MGR::register_str(CHAR const* var_name, SYM * s, UINT align)
{
	IS_TRUE0(s != NULL);
	VAR * v;
	if ((v = m_str_tab.get(s)) != NULL) {
		return v;
	}
	v = new_var();
	CHAR buf[64];
	if (var_name == NULL) {
		sprintf(buf, ".rodata_%zu", m_str_count++);
		VAR_name(v) = m_ru_mgr->add_to_symtab(buf);
	} else {
		VAR_name(v) = m_ru_mgr->add_to_symtab(var_name);
	}
	VAR_str(v) = s;
	VAR_data_type(v) = D_STR;
	VAR_elem_type(v) = D_UNDEF;
	IS_TRUE0(sizeof(CHAR) == 1);
	VAR_data_size(v) = xstrlen(SYM_name(s)) + 1;
	VAR_align(v) = align;
	VAR_is_global(v) = 1; //store in .data or .rodata

	assign_var_id(v);
	m_str_tab.set(s, v);
	return v;
}
Example #3
0
void dump_lab(LABEL_INFO const* li)
{
	if (g_tfile == NULL) return;
	if (LABEL_INFO_type(li) == L_ILABEL) {
		fprintf(g_tfile, "\nilabel(" ILABEL_STR_FORMAT ")",
				ILABEL_CONT(li));
	} else if (LABEL_INFO_type(li) == L_CLABEL) {
		fprintf(g_tfile, "\nclabel(" CLABEL_STR_FORMAT ")",
				CLABEL_CONT(li));
	} else if (LABEL_INFO_type(li) == L_PRAGMA) {
		fprintf(g_tfile, "\npragms(%s)",
				SYM_name(LABEL_INFO_pragma(li)));
	} else { IS_TRUE0(0); }

	if (LABEL_INFO_b1(li) != 0) {
		fprintf(g_tfile, "(");
	}
	if (LABEL_INFO_is_try_start(li)) {
		fprintf(g_tfile, "try_start ");
	}
	if (LABEL_INFO_is_try_end(li)) {
		fprintf(g_tfile, "try_end ");
	}
	if (LABEL_INFO_is_catch_start(li)) {
		fprintf(g_tfile, "catch_start ");
	}
	if (LABEL_INFO_is_used(li)) {
		fprintf(g_tfile, "used ");
	}
	if (LABEL_INFO_b1(li) != 0) {
		fprintf(g_tfile, ")");
	}
	fflush(g_tfile);
}
Example #4
0
void dumpBBLabel(List<LabelInfo const*> & lablist, FILE * h)
{
    ASSERT0(h);
    C<LabelInfo const*> * ct;
    for (lablist.get_head(&ct); ct != lablist.end(); ct = lablist.get_next(ct)) {
        LabelInfo const* li = ct->val();
        switch (LABEL_INFO_type(li)) {
        case L_CLABEL:
            fprintf(h, CLABEL_STR_FORMAT, CLABEL_CONT(li));
            break;
        case L_ILABEL:
            fprintf(h, ILABEL_STR_FORMAT, ILABEL_CONT(li));
            break;
        case L_PRAGMA:
            ASSERT0(LABEL_INFO_pragma(li));
            fprintf(h, "%s", SYM_name(LABEL_INFO_pragma(li)));
            break;
        default: UNREACH();
        }

        if (LABEL_INFO_is_try_start(li) ||
            LABEL_INFO_is_try_end(li) ||
            LABEL_INFO_is_catch_start(li)) {
            fprintf(g_tfile, "(");
            if (LABEL_INFO_is_try_start(li)) {
                fprintf(g_tfile, "try_start,");
            }
            if (LABEL_INFO_is_try_end(li)) {
                fprintf(g_tfile, "try_end,");
            }
            if (LABEL_INFO_is_catch_start(li)) {
                fprintf(g_tfile, "catch_start");
            }
            fprintf(g_tfile, ")");
        }
        fprintf(g_tfile, " ");
    }
}
Example #5
0
//Recusively dumping SCOPE trees.
void dump_scope(SCOPE * s, UINT flag)
{
	if (g_tfile == NULL) return;
	static CHAR buf[8192];
	buf[0] = 0;
	note("\nSCOPE(id:%d, level:%d)", SCOPE_id(s), SCOPE_level(s));
	g_indent++;
	
	//symbols
	SYM_LIST * sym_list = SCOPE_sym_tab_list(s);
	if (sym_list != NULL) {
		note("\nSYMBAL:");
		g_indent++;
		note("\n");
		while (sym_list != NULL) {
			note("%s\n", SYM_name(SYM_LIST_sym(sym_list)));
			sym_list = SYM_LIST_next(sym_list);
		}
		g_indent--;
	}

	//all of defined customer label in code
	LABEL_INFO * li = SCOPE_label_list(s).get_head(); 
	if (li != NULL) {
		note("\nDEFINED LABEL:");		
		g_indent++;
		note("\n");
		for (; li != NULL; li = SCOPE_label_list(s).get_next()) { 
			IS_TRUE0(map_lab2lineno(li) != 0);
			note("%s (def in line:%d)\n",
				 SYM_name(LABEL_INFO_name(li)),
				 map_lab2lineno(li));
		}
		g_indent--;
	}

	//refered customer label in code
	li = SCOPE_ref_label_list(s).get_head(); 
	if (li != NULL) {
		note("\nREFED LABEL:");
		g_indent++;		
		note("\n");
		for (; li != NULL; li = SCOPE_ref_label_list(s).get_next()) { 
			note("%s (use in line:%d)\n", 
				 SYM_name(LABEL_INFO_name(li)),
				 map_lab2lineno(li));
		}
		g_indent--;
	}

	//enums
	ENUM_LIST * el = SCOPE_enum_list(s);
	if (el != NULL) {
		note("\nENUM LIST:");
		g_indent++;
		note("\n");
		while (el != NULL) {
			buf[0] = 0;
			format_enum_complete(buf, ENUM_LIST_enum(el));
			note("%s\n", buf);
			el = ENUM_LIST_next(el);
		}
		g_indent--;
	}

	//user defined type, by 'typedef'
	USER_TYPE_LIST * utl = SCOPE_user_type_list(s);
	if (utl != NULL) {
		note("\nUSER TYPE:");
		g_indent++;	
		note("\n");
		while (utl != NULL) {
			buf[0] = 0;
			format_user_type_spec(buf, USER_TYPE_LIST_utype(utl));
			note("%s\n", buf);
			utl = USER_TYPE_LIST_next(utl);
		}
		g_indent--;
	}

	//structs
	STRUCT * st = SCOPE_struct_list(s);
	if (st != NULL) {
		note("\nSTRUCT:");
		g_indent++;	
		note("\n");
		while (st != NULL) {
			buf[0] = 0;
			format_struct_complete(buf, st);
			note("%s\n", buf);
			st = USER_TYPE_LIST_next(st);
		}
		g_indent--;
	}

	//unions
	UNION * un = SCOPE_union_list(s);
	if (un != NULL) {
		note("\nUNION:");
		g_indent++;
		note("\n");
		while (un != NULL) {
			buf[0] = 0;
			format_union_complete(buf, un);
			note("%s\n", buf);
			un = USER_TYPE_LIST_next(un);
		}
		g_indent--;
	}

	//declarations
	DECL * dcl = SCOPE_decl_list(s);
	if (dcl != NULL) {
		note("\nDECLARATIONS:");
		note("\n");
		g_indent++;
		while (dcl != NULL) {
			buf[0] = 0;
			format_declaration(buf, dcl);
			note("%s", buf);
			dump_decl(dcl);

			//Dump function body
			if (DECL_is_fun_def(dcl) && HAVE_FLAG(flag, DUMP_SCOPE_FUNC_BODY)) {
				g_indent += 2;
				dump_scope(DECL_fun_body(dcl), flag);
				g_indent -= 2;
			}

			//Dump initializing value/expression.
			if (DECL_is_init(DECL_decl_list(dcl))) {
				note("= ");
				g_indent += 2;
				dump_tree(DECL_init_tree(DECL_decl_list(dcl)));
				g_indent -= 2;
			}
			
			note("\n");
			dcl = DECL_next(dcl);
		}
		g_indent--;
	}
	fflush(g_tfile);

	if (HAVE_FLAG(flag, DUMP_SCOPE_STMT_TREE)) {
		TREE * t = SCOPE_stmt_list(s);
		if (t != NULL) {
			note("\nSTATEMENT:");
			g_indent++;	
			note("\n");
			dump_trees(t);	
			g_indent--;
		}
	}
	g_indent--;
}
Example #6
0
CHAR * VAR::dump(CHAR * buf)
{
	CHAR * tb = buf;
	CHAR * name = SYM_name(VAR_name(this));
	CHAR tt[43];
	if (xstrlen(name) > 43) {
		memcpy(tt, name, 43);
		tt[39] = '.';
		tt[40] = '.';
		tt[41] = '.';
		tt[42] = 0;
		name = tt;
	}
	buf += sprintf(buf, "VAR%d(%s):", VAR_id(this), name);
	if (HAVE_FLAG(VAR_flag(this), VAR_GLOBAL)) {
		strcat(buf, "global");
	} else if (HAVE_FLAG(VAR_flag(this), VAR_LOCAL)) {
		strcat(buf, "local");
	} else {
		IS_TRUE0(0);
	}

	if (HAVE_FLAG(VAR_flag(this), VAR_STATIC)) {
		strcat(buf, ",static");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_READONLY)) {
		strcat(buf, ",const");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_VOLATILE)) {
		strcat(buf, ",volatile");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_IS_RESTRICT)) {
		strcat(buf, ",restrict");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_HAS_INIT_VAL)) {
		strcat(buf, ",has_init_val");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_FUNC_UNIT)) {
		strcat(buf, ",func_unit");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_FUNC_DECL)) {
		strcat(buf, ",func_decl");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_FAKE)) {
		strcat(buf, ",fake");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_IS_FORMAL_PARAM)) {
		strcat(buf, ",formal_param");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_IS_SPILL)) {
		strcat(buf, ",spill_loc");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_ADDR_TAKEN)) {
		strcat(buf, ",addr_taken");
	}
	if (VAR_is_str(this)) {
		strcat(buf, ",str");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_IS_ARRAY)) {
		strcat(buf, ",array");
	}
	if (HAVE_FLAG(VAR_flag(this), VAR_IS_ALLOCABLE)) {
		strcat(buf, ",allocable");
	}
	if (VAR_is_pointer(this)) {
		buf += strlen(buf);
		sprintf(buf, ",pointer,pt_base_sz:%d", VAR_pointer_base_size(this));
	}
	buf += strlen(buf);

	sprintf(buf, ",%s", DTDES_name(&g_dtype_desc[VAR_data_type(this)]));
	if (VAR_data_type(this) > D_F128) {
		buf += strlen(buf);
		sprintf(buf, ",mem_size:%d", VAR_data_size(this));
	}

	if (VAR_align(this) != 0) {
		buf += strlen(buf);
		sprintf(buf, ",align:%d", VAR_align(this));
	}

	strcat(buf, ",decl:'");
	buf += strlen(buf);
	dump_var_decl(buf, 40);
	strcat(buf, "'");

	#ifdef _DEBUG_
	UINT tmpf = VAR_flag(this);
	REMOVE_FLAG(tmpf, VAR_GLOBAL);
	REMOVE_FLAG(tmpf, VAR_LOCAL);
	REMOVE_FLAG(tmpf, VAR_STATIC);
	REMOVE_FLAG(tmpf, VAR_READONLY);
	REMOVE_FLAG(tmpf, VAR_VOLATILE);
	REMOVE_FLAG(tmpf, VAR_HAS_INIT_VAL);
	REMOVE_FLAG(tmpf, VAR_FUNC_UNIT);
	REMOVE_FLAG(tmpf, VAR_FUNC_DECL);
	REMOVE_FLAG(tmpf, VAR_FAKE);
	REMOVE_FLAG(tmpf, VAR_IS_ARRAY);
	REMOVE_FLAG(tmpf, VAR_IS_FORMAL_PARAM);
	REMOVE_FLAG(tmpf, VAR_IS_SPILL);
	REMOVE_FLAG(tmpf, VAR_ADDR_TAKEN);
	REMOVE_FLAG(tmpf, VAR_IS_PR);
	REMOVE_FLAG(tmpf, VAR_IS_RESTRICT);
	REMOVE_FLAG(tmpf, VAR_IS_ALLOCABLE);
	IS_TRUE0(tmpf == 0);
	#endif
	return tb;
}