diff lwasm/unicorns.c @ 226:7c2c2239ec9c

Make unicorns grok errors and warnings. Added unicorn formatted error and warning output and also a framework to handle errors which know which character position in the line they occurred in.
author William Astle <lost@l-w.ca>
date Sun, 15 Jul 2012 21:19:43 -0600
parents 3864d96ee8c7
children 042c7b74faf0
line wrap: on
line diff
--- a/lwasm/unicorns.c	Sun Jul 15 21:19:04 2012 -0600
+++ b/lwasm/unicorns.c	Sun Jul 15 21:19:43 2012 -0600
@@ -46,12 +46,25 @@
 	}
 }
 
+static void show_unicorn_error(FILE *fp, line_t *l, lwasm_error_t *ee, const char *tag)
+{
+	fprintf(fp, "%s: lineno=%d,filename=", tag, l -> lineno);
+	print_urlencoding(fp, l -> linespec);
+	fputs(",message=", fp);
+	print_urlencoding(fp, ee -> mess);
+	if (ee -> charpos > 0)
+		fprintf(fp, ",col=%d", ee -> charpos);
+	fputc('\n', fp);
+}
+
 void lwasm_do_unicorns(asmstate_t *as)
 {
 	struct ifl *ifl;
 	macrotab_t *me;
 	structtab_t *se;
 	int i;
+	line_t *l;
+	lwasm_error_t *ee;
 			
 	/* output file list */	
 	for (ifl = ifl_head; ifl; ifl = ifl -> next)
@@ -86,5 +99,24 @@
 		print_urlencoding(stdout, se -> definedat -> linespec);
 		fputc('\n', stdout);
 	}
-	
+
+	/* output error and warning lists */
+	for (l = as -> line_head; l; l = l -> next)
+	{
+		if (l -> err)
+		{
+			for (ee = l -> err; ee; ee = ee -> next)
+			{
+				show_unicorn_error(stdout, l, ee, "ERROR");
+			}
+		}
+		
+		if (l -> warn)
+		{
+			for (ee = l -> warn; ee; ee = ee -> next)
+			{
+				show_unicorn_error(stdout, l, ee, "WARNING");
+			}
+		}
+	}
 }