void write_map_file( void ) { char *filename; FILE *file; SymbolHash *map_symtab; /* use first module filename to create global map file */ filename = get_map_filename( get_first_module( NULL )->filename ); /* set '.map' extension */ /* Create MAP file */ file = myfopen( filename, "w" ); if (file) { if (opts.verbose) puts("Creating map..."); /* BUG_0036, BUG_0051 */ map_symtab = select_symbols(cond_all_symbols); if (SymbolHash_empty(map_symtab)) { fputs("None.\n", file); } else { /* Write map symbols alphabetically */ SymbolHash_sort(map_symtab, SymbolHash_by_name); write_map_syms(file, map_symtab); fputs("\n\n", file); /* Write map symbols numerically */ SymbolHash_sort(map_symtab, SymbolHash_by_value); write_map_syms(file, map_symtab); } OBJ_DELETE(map_symtab); myfclose(file); } }
static void test_symtab( void ) { Symbol *sym; SymbolHash *symtab, *symtab2; list_open("test.lst"); opts.symtable = TRUE; opts.list = TRUE; warn("Create current module\n"); set_cur_module( new_module() ); warn("Create symbol\n"); sym = Symbol_create(S("Var1"), 123, TYPE_CONSTANT, 0, NULL, NULL); dump_Symbol(sym); OBJ_DELETE(sym); sym = Symbol_create(S("Var1"), 123, TYPE_CONSTANT, 0, CURRENTMODULE, NULL); dump_Symbol(sym); CURRENTMODULE->modname = "MODULE"; dump_Symbol(sym); warn("Delete symbol\n"); OBJ_DELETE(sym); warn("Global symtab\n"); dump_SymbolHash(global_symtab, "global"); dump_SymbolHash(static_symtab, "static"); warn("check case insensitive - CH_0024\n"); symtab = OBJ_NEW(SymbolHash); assert( symtab ); _define_sym(S("Var1"), 1, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("var1"), 2, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("VAR1"), 3, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); dump_SymbolHash(symtab, "tab1"); assert( find_symbol(S("Var1"), symtab)->value == 1 ); assert( find_symbol(S("var1"), symtab)->value == 2 ); assert( find_symbol(S("VAR1"), symtab)->value == 3 ); dump_SymbolHash(symtab, "tab1"); warn("Concat symbol tables\n"); symtab = OBJ_NEW(SymbolHash); assert( symtab ); _define_sym(S("Var1"), 1, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("Var2"), 2, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("Var3"), -3, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); dump_SymbolHash(symtab, "tab1"); symtab2 = OBJ_NEW(SymbolHash); assert( symtab2 ); _define_sym(S("Var3"), 3, TYPE_CONSTANT, 0, NULL, NULL, &symtab2); inc_page_nr(); _define_sym(S("Var4"), 4, TYPE_CONSTANT, 0, NULL, NULL, &symtab2); inc_page_nr(); _define_sym(S("Var5"), 5, TYPE_CONSTANT, 0, NULL, NULL, &symtab2); inc_page_nr(); dump_SymbolHash(symtab2, "tab2"); SymbolHash_cat( &symtab, symtab2 ); dump_SymbolHash(symtab, "merged_tab"); OBJ_DELETE( symtab ); OBJ_DELETE( symtab2 ); warn("Sort\n"); symtab = OBJ_NEW(SymbolHash); assert( symtab ); _define_sym(S("One"), 1, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("Two"), 2, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("Three"), 3, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); _define_sym(S("Four"), 4, TYPE_CONSTANT, 0, NULL, NULL, &symtab); inc_page_nr(); dump_SymbolHash(symtab, "tab"); SymbolHash_sort(symtab, SymbolHash_by_name); dump_SymbolHash(symtab, "tab by name"); SymbolHash_sort(symtab, SymbolHash_by_value); dump_SymbolHash(symtab, "tab by value"); OBJ_DELETE( symtab ); warn("Use local symbol before definition\n"); _define_sym(S("WIN32"), 1, TYPE_CONSTANT, 0, NULL, NULL, &static_symtab); inc_page_nr(); SymbolHash_cat( & CURRENTMODULE->local_symtab, static_symtab ); inc_page_nr(); _define_sym(S("PC"), 0, TYPE_CONSTANT, 0, NULL, NULL, &global_symtab); inc_page_nr(); find_symbol( S("PC"), global_symtab )->value += 3; inc_page_nr(); find_symbol( S("PC"), global_symtab )->value += 3; inc_page_nr(); sym = get_used_symbol(S("NN")); inc_page_nr(); assert( sym != NULL ); assert( ! sym->is_defined ); find_symbol( S("PC"), global_symtab )->value += 3; inc_page_nr(); sym = get_used_symbol(S("NN")); inc_page_nr(); assert( sym != NULL ); assert( ! sym->is_defined ); find_symbol( S("PC"), global_symtab )->value += 3; inc_page_nr(); sym = define_symbol(S("NN"), find_symbol( "PC", global_symtab )->value, TYPE_ADDRESS); sym->is_touched = TRUE; sym = get_used_symbol(S("NN")); inc_page_nr(); assert( sym != NULL ); dump_Symbol(sym); assert( sym->is_defined ); dump_symtab(); warn("Delete Local\n"); remove_all_local_syms(); dump_symtab(); warn("Delete Static\n"); remove_all_static_syms(); dump_symtab(); warn("Delete Global\n"); remove_all_global_syms(); dump_symtab(); warn("End\n"); }