comparison lwasm/symbol.c @ 365:3f8abaac214c

Add map file output and option to suppress local symbols in listings Add --map option to generate a symbol map in a regular format that can be used as an import for other tools. Also add --symbols-nolocals to suppress output of local symbols in the symbol listing. In other words, only global symbols are listed. Thanks to Erik G <erik@6809.org> for the patch.
author William Astle <lost@l-w.ca>
date Tue, 02 Jun 2015 20:08:58 -0600
parents d149e2b56981
children 8764142b3192
comparison
equal deleted inserted replaced
364:44270b66df3c 365:3f8abaac214c
339 339
340 for (s = se; s; s = s -> nextver) 340 for (s = se; s; s = s -> nextver)
341 { 341 {
342 if (s -> flags & symbol_flag_nolist) 342 if (s -> flags & symbol_flag_nolist)
343 continue; 343 continue;
344
345 if ((as -> flags & FLAG_SYMBOLS_NOLOCALS) && (s -> context >= 0))
346 continue;
347
344 lwasm_reduce_expr(as, s -> value); 348 lwasm_reduce_expr(as, s -> value);
345 fputc('[', of); 349 fputc('[', of);
346 if (s -> flags & symbol_flag_set) 350 if (s -> flags & symbol_flag_set)
347 fputc('S', of); 351 fputc('S', of);
348 else 352 else
398 void list_symbols(asmstate_t *as, FILE *of) 402 void list_symbols(asmstate_t *as, FILE *of)
399 { 403 {
400 fprintf(of, "\nSymbol Table:\n"); 404 fprintf(of, "\nSymbol Table:\n");
401 list_symbols_aux(as, of, as -> symtab.head); 405 list_symbols_aux(as, of, as -> symtab.head);
402 } 406 }
407
408 void map_symbols(asmstate_t *as, FILE *of, struct symtabe *se)
409 {
410 struct symtabe *s;
411 lw_expr_t te;
412 struct listinfo li;
413
414 li.as = as;
415
416 if (!se)
417 return;
418
419 map_symbols(as, of, se -> left);
420
421 for (s = se; s; s = s -> nextver)
422 {
423 if (s -> flags & symbol_flag_nolist)
424 continue;
425 lwasm_reduce_expr(as, s -> value);
426
427 te = lw_expr_copy(s -> value);
428 li.complex = 0;
429 li.sect = NULL;
430 lw_expr_testterms(te, list_symbols_test, &li);
431 if (li.sect)
432 {
433 as -> exportcheck = 1;
434 as -> csect = li.sect;
435 lwasm_reduce_expr(as, te);
436 as -> exportcheck = 0;
437 }
438
439 if (lw_expr_istype(te, lw_expr_type_int))
440 {
441 fprintf(of, "Symbol: %s", s -> symbol);
442 if (s -> context != -1)
443 fprintf(of, "_%04X", lw_expr_intval(te));
444 fprintf(of, " (%s) = %04X\n", as -> output_file, lw_expr_intval(te));
445
446 }
447 lw_expr_destroy(te);
448 }
449
450 map_symbols(as, of, se -> right);
451 }
452
453 void do_map(asmstate_t *as)
454 {
455 FILE *of = NULL;
456
457 if (!(as -> flags & FLAG_MAP))
458 return;
459
460 if (as -> map_file)
461 {
462 if (strcmp(as -> map_file, "-") == 0)
463 {
464 of = stdout;
465 }
466 else
467 of = fopen(as -> map_file, "w");
468 }
469 else
470 of = stdout;
471 if (!of)
472 {
473 fprintf(stderr, "Cannot open map file '%s' for output\n", as -> map_file);
474 return;
475 }
476
477 map_symbols(as, of, as -> symtab.head);
478
479 fclose(of);
480 }