changeset 35:39d750ee8d34

Added error display and fixed infinite loop in lwasm_parse_line()
author lost
date Fri, 02 Jan 2009 06:07:10 +0000
parents b29eec6f3819
children 99e3b3310bac
files src/Makefile.am src/list.c src/main.c src/pass1.c
diffstat 4 files changed, 27 insertions(+), 142 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Fri Jan 02 05:17:00 2009 +0000
+++ b/src/Makefile.am	Fri Jan 02 06:07:10 2009 +0000
@@ -1,3 +1,3 @@
 bin_PROGRAMS = lwasm
-lwasm_SOURCES = main.c expr.c pass1.c pass2.c util.c instab.c parse.c lwasm.c insn_inh.c insn_rtor.c insn_rlist.c insn_rel.c insn_tfm.c insn_bitbit.c insn_indexed.c insn_gen.c insn_logicmem.c
+lwasm_SOURCES = main.c expr.c pass1.c pass2.c util.c instab.c parse.c lwasm.c insn_inh.c insn_rtor.c insn_rlist.c insn_rel.c insn_tfm.c insn_bitbit.c insn_indexed.c insn_gen.c insn_logicmem.c list.c
 EXTRA_DIST = instab.h lwasm.h expr.h util.h
--- a/src/list.c	Fri Jan 02 05:17:00 2009 +0000
+++ b/src/list.c	Fri Jan 02 06:07:10 2009 +0000
@@ -1,6 +1,6 @@
 /*
 list.c
-Copyright © 2008 William Astle
+Copyright © 2009 William Astle
 
 This file is part of LWASM.
 
@@ -17,154 +17,35 @@
 You should have received a copy of the GNU General Public License along with
 this program. If not, see <http://www.gnu.org/licenses/>.
 
-Contains code for displaying a program listing in lwasm
+Contains code for displaying a program listings, etc.
 */
 
-//#include <ctype.h>
-#include <errno.h>
+#define __list_c_seen__
+
 #include <stdio.h>
-//#include <stdlib.h>
-#include <string.h>
-#define __list_c_seen__
-//#include "instab.h"
+#include <stdlib.h>
+
 #include "lwasm.h"
 
-const char *errlist[] =
+void lwasm_show_errors(asmstate_t *as)
 {
-	"No error",
-	"Bad opcode",
-	"Illegal Symbol",
-	"Multiply defined symbol",
-	"Symbol required but not present",
-	"Forward references not permitted",
-	"Byte overflow",
-	"Phase error",
-	"Bad operand",
-	"Symbol not permitted here",
-	"Undefined symbol",
-	"Bit number out of range",
-	"Invalid expression",
-	"Invalid register",
-	"Bad file name",
-	"ENDM without MACRO",
-	"Redefined macro",
-	"Nested namespace",
-	"Bad condition",
-	"User error",
-	"Bad pragma",
-	""
-};
-
-void list_code(asmstate_t *as)
-{
-	FILE *lf;
-	sourceline_t *cl;
-	int bn;
-	int c;
-	char *t;
+	lwasm_line_t *l;
+	lwasm_error_t *e;
 	
-	if (as -> listfile && strcmp(as -> listfile, "-"))
+	for (l = as -> lineshead; l; l = l -> next)
 	{
-		lf = fopen(as -> listfile, "w");
-		if (!lf)
+		if (l -> err)
 		{
-			perror("Cannot open list file");
-			return;
+			for (e = l -> err; e; e = e -> next)
+			{
+				fprintf(stderr, "ERROR: %s\n", e -> mess);
+			}
+			fprintf(stderr, "%s\n", l -> text);
 		}
 	}
-	else
-	{
-		lf = stdout;
-	}
-	
-	for (cl = as -> source_head; cl; cl = cl -> next)
-	{
-		bn = 0;
-		if (cl -> errors)
-		{
-			errortab_t *e;
-			for (e = cl -> errors; e; e = e -> next)
-			{
-				if (e -> errnum < ERR_MAXERR && e -> errnum != ERR_USER)
-					fprintf(lf, "*****ERROR: %s\n", errlist[e -> errnum]);
-			}
-			if (cl -> user_error)
-			{
-				fprintf(lf, "*****ERROR: %s\n", cl -> user_error);
-			}
-		}
-		if (cl -> skipped)
-		{
-			fprintf(lf, "%-15.15s", "<skipped>");
-		}
-		else if (cl -> macrodef)
-		{
-			fprintf(lf, "%-15.15s", "<macrodef>");
-		}
-		else if (cl -> opcode >= 0 && cl -> numcodebytes > 0)
-		{
-			fprintf(lf, "%04X ", cl -> addr);
-			while (bn < 5 && bn < cl -> numcodebytes)
-			{
-				fprintf(lf, "%02X", cl -> codebytes[bn]);
-				bn++;
-			}
-			while (bn < 5)
-			{
-				fprintf(lf, "  ");
-				bn++;
-			}
-		}
-		else if (cl -> addrset || (cl -> len && cl -> numcodebytes == 0))
-		{
-			fprintf(lf, "%04X %10s", cl -> addr, "");
-		}
-		else if (cl -> isequ)
-		{
-			fprintf(lf, "     %04X      ", cl -> symaddr);
-		}
-		else if (cl -> issetdp)
-		{
-			fprintf(lf, "     %02X        ", cl -> dpval);
-		}
-		else
-			fprintf(lf, "               ");
-		fprintf(lf, " %15.15s:%06d ", cl -> sourcefile, cl -> lineno);
-		// actually display the line from the file
-		for (c = 0, t = cl -> line; *t; t++)
-		{
-			if (*t == '\n' || *t == '\r')
-				break;
-			if (*t == '\t')
-			{
-				do
-				{
-					fprintf(lf, " ");
-					c++;
-				} while (c % 8);
-			}
-			else
-			{
-				c++;
-				fprintf(lf, "%c", *t);
-			}
-		}
-//		fprintf(lf, "\n");
-
-		while (bn < cl -> numcodebytes)
-		{
-			if (bn % 5 == 0)
-				fprintf(lf, "\n%04X ", (cl -> addr + bn) & 0xFFFF);
-			fprintf(lf, "%02X", cl -> codebytes[bn]);
-			bn++;
-		}
-		fprintf(lf, "\n");
-	}
-
-	fprintf(lf, "\n");
-	list_symbols(as, lf);
-	
-	if (lf != stdout)
-		fclose(lf);
 }
 
+void lwasm_list(asmstate_t *as)
+{
+	lwasm_show_errors(as);
+}
--- a/src/main.c	Fri Jan 02 05:17:00 2009 +0000
+++ b/src/main.c	Fri Jan 02 06:07:10 2009 +0000
@@ -36,7 +36,7 @@
 // external declarations
 extern void lwasm_pass1(asmstate_t *as);
 extern void lwasm_pass2(asmstate_t *as);
-
+extern void lwasm_list(asmstate_t *as);
 
 // command line option handling
 const char *argp_program_version = PACKAGE_STRING;
@@ -171,7 +171,7 @@
 	lwasm_pass2(&asmstate);
 
 	// now make a pretty listing
-//	lwasm_list(&asmstate);
+	lwasm_list(&asmstate);
 
 	// now write the code out to the output file
 //	lwasm_output(&asmstate);
--- a/src/pass1.c	Fri Jan 02 05:17:00 2009 +0000
+++ b/src/pass1.c	Fri Jan 02 06:07:10 2009 +0000
@@ -60,6 +60,9 @@
 #include "lwasm.h"
 #include "util.h"
 
+
+extern int lwasm_parse_line(asmstate_t *as, lwasm_line_t *l);
+
 // we can't use standard line inputting functions here because we have to
 // handle non-standard line terminations (CR, LF, CRLF, or LFCR)
 int lwasm_read_file(asmstate_t *as, const char *filename)
@@ -138,6 +141,7 @@
 				as -> linestail = nl;
 			if (!(as -> lineshead))
 				as -> lineshead = nl;
+			lwasm_parse_line(as, nl);
 		}
 		if (c == EOF)
 			break;