changeset 58:b1d81800bc91

Added symbol listing to list file; various fixes
author lost
date Mon, 05 Jan 2009 00:20:45 +0000
parents 035b95a3690f
children 89657cb3fdf8
files src/list.c src/lwasm.c src/lwasm.h src/pass1.c src/pass2.c src/symbol.c
diffstat 6 files changed, 46 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/list.c	Mon Jan 05 00:01:21 2009 +0000
+++ b/src/list.c	Mon Jan 05 00:20:45 2009 +0000
@@ -122,6 +122,9 @@
 			fputc('\n', lf);
 		}
 	}
+	
+	lwasm_list_symbols(as, lf);
+	
 	if (lf != stdout)
 		fclose(lf);
 
--- a/src/lwasm.c	Mon Jan 05 00:01:21 2009 +0000
+++ b/src/lwasm.c	Mon Jan 05 00:20:45 2009 +0000
@@ -63,7 +63,8 @@
 void lwasm_emit(asmstate_t *as, lwasm_line_t *l, int b)
 {
 	as -> addr += 1;
-
+	as -> addr &= 0xffff;
+	
 	if (as -> passnum == 1)
 		return;
 
@@ -198,7 +199,7 @@
 int lwasm_expr_result(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val)
 {
 	lwasm_expr_stack_t *s;
-	char *ep;
+	const char *ep;
 	int rval;
 		
 	s = lwasm_evaluate_expr(as, l, *inp, &ep);
@@ -208,7 +209,7 @@
 		*val = 0;
 		return -1;
 	}
-	*inp = ep;
+	*inp = (char *)ep;
 	
 	if (flag & EXPR_PASS1CONST && as -> passnum == 1 && !lwasm_expr_is_constant(s))
 	{
@@ -258,6 +259,10 @@
 
 int lwasm_next_context(asmstate_t *as)
 {
-	return (as -> nextcontext++);
+	int r;
+	r = as -> nextcontext;
+	as -> nextcontext += 1;
+	debug_message(3, "lwasm_next_context(): %d (%d) pass %d", r, as -> nextcontext, as -> passnum);
+	return r;
 }
 
--- a/src/lwasm.h	Mon Jan 05 00:01:21 2009 +0000
+++ b/src/lwasm.h	Mon Jan 05 00:20:45 2009 +0000
@@ -24,6 +24,7 @@
 #ifndef __lwasm_h_seen__
 #define __lwasm_h_seen__
 
+#include <stdio.h>
 #include "expr.h"
 
 #define OUTPUT_DECB		0	// DECB multirecord format
@@ -159,7 +160,7 @@
 __lwasm_E__ int lwasm_register_symbol(asmstate_t *as, lwasm_line_t *l, char *sym, int val);
 __lwasm_E__ lwasm_symbol_ent_t *lwasm_find_symbol(asmstate_t *as, char *sym, int scontext);
 __lwasm_E__ int lwasm_set_symbol(asmstate_t *as, char *sym, int scontext, int val);
-
+__lwasm_E__ void lwasm_list_symbols(asmstate_t *as, FILE *f);
 #undef __lwasm_E__
 
 
--- a/src/pass1.c	Mon Jan 05 00:01:21 2009 +0000
+++ b/src/pass1.c	Mon Jan 05 00:20:45 2009 +0000
@@ -163,6 +163,7 @@
 {
 	as -> passnum = 1;
 	as -> addr = 0;
+	as -> nextcontext = 1;
 	
 	debug_message(1, "Entering pass 1");
 	if (lwasm_read_file(as, as -> infile) < 0)
--- a/src/pass2.c	Mon Jan 05 00:01:21 2009 +0000
+++ b/src/pass2.c	Mon Jan 05 00:20:45 2009 +0000
@@ -43,7 +43,7 @@
 	as -> inmacro = 0;
 	as -> nextcontext = 1;
 	as -> skiplines = 0;
-			
+
 	// iterate over all the lines and re-parse them
 	for (l = as -> lineshead; l && !(as -> endseen); l = l -> next)
 	{
--- a/src/symbol.c	Mon Jan 05 00:01:21 2009 +0000
+++ b/src/symbol.c	Mon Jan 05 00:20:45 2009 +0000
@@ -70,6 +70,8 @@
 			scontext = as -> context;
 	}
 	
+	debug_message(3, "lwasm_register_symbol(): registering '%s' (%d) at %04X", sym, scontext, val);
+	
 	// now look it for to see if it is a duplicate
 	se = lwasm_find_symbol(as, sym, scontext);
 	if (se)
@@ -129,3 +131,31 @@
 	se -> value = val;
 	return 0;
 }
+
+void lwasm_list_symbols(asmstate_t *as, FILE *lf)
+{
+	lwasm_symbol_ent_t *se;
+	
+	for (se = as -> symhead; se; se = se -> next)
+	{
+		if (se -> value > 0xffff || se -> value < -0x8000)
+		{
+			fprintf(lf, "%08X ", se -> value);
+		}
+		else
+		{
+			fprintf(lf, "    %04X ", se -> value);
+		}
+		if (se -> context < 0)
+			fputc('G', lf);
+		else
+			fputc('L', lf);
+		
+		fprintf(lf, " %s", se -> sym);
+		
+		if (se -> context >= 0)
+			fprintf(lf, " (%d)", se -> context);
+		
+		fputc('\n', lf);
+	}
+}