changeset 405:7bcc50e828ff

Fixed up symbol table list to be more clear
author lost@l-w.ca
date Fri, 23 Jul 2010 18:58:20 -0600
parents 0324fd09c7ac
children 502fbc37ff4e
files lwasm/symbol.c
diffstat 1 files changed, 74 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/symbol.c	Fri Jul 23 18:31:33 2010 -0600
+++ b/lwasm/symbol.c	Fri Jul 23 18:58:20 2010 -0600
@@ -168,29 +168,97 @@
 	return s;
 }
 
+struct listinfo
+{
+	sectiontab_t *sect;
+	asmstate_t *as;
+	int complex;
+};
+
+int list_symbols_test(lw_expr_t e, void *p)
+{
+	struct listinfo *li = p;
+	
+	if (li -> complex)
+		return 0;
+	
+	if (lw_expr_istype(e, lw_expr_type_special))
+	{
+		if (lw_expr_specint(e) == lwasm_expr_secbase)
+		{
+			if (li -> sect)
+			{
+				li -> complex = 1;
+			}
+			else
+			{
+				li -> sect = lw_expr_specptr(e);
+			}
+		}
+	}
+	return 0;
+}
+
 void list_symbols(asmstate_t *as, FILE *of)
 {
 	struct symtabe *s;
-	
+	lw_expr_t te;
+	struct listinfo li;
+
+	li.as = as;
+		
 	fprintf(of, "\nSymbol Table:\n");
 	
 	for (s = as -> symtab.head; s; s = s -> next)
 	{
+		lwasm_reduce_expr(as, s -> value);
 		fputc('[', of);
 		if (s -> flags & symbol_flag_set)
 			fputc('S', of);
 		else
 			fputc(' ', of);
-		if (lw_expr_istype(s -> value, lw_expr_type_int))
+		if (as -> output_format == OUTPUT_OBJ)
+		{
+			if (lw_expr_istype(s -> value, lw_expr_type_int))
+				fputc('c', of);
+			else
+				fputc('s', of);
+		}
+		if (s -> context < 0)
 			fputc('G', of);
 		else
-			fputc(' ', of);
+			fputc('L', of);
+
 		fputc(']', of);
 		fputc(' ', of);
 		fprintf(of, "%-32s ", s -> symbol);
-		if (lw_expr_istype(s -> value, lw_expr_type_int))
-			fprintf(of, "%04X\n", lw_expr_intval(s -> value));
+		
+		te = lw_expr_copy(s -> value);
+		li.complex = 0;
+		li.sect = NULL;
+		lw_expr_testterms(te, list_symbols_test, &li);
+		if (li.sect)
+		{
+			as -> exportcheck = 1;
+			as -> csect = li.sect;
+			lwasm_reduce_expr(as, te);
+			as -> exportcheck = 0;
+		}
+		
+		if (lw_expr_istype(te, lw_expr_type_int))
+		{
+			fprintf(of, "%04X", lw_expr_intval(te));
+			if (li.sect)
+			{
+				fprintf(of, " (%s)", li.sect -> name);
+			}
+			fprintf(of, "\n");
+		}
 		else
-			fprintf(of, "%s\n", lw_expr_print(s -> value));
+		{
+			fprintf(of, "<<incomplete>>\n");
+//			fprintf(of, "%s\n", lw_expr_print(s -> value));
+		}
+		lw_expr_destroy(te);
 	}
 }