diff lwasm/debug.c @ 370:6b33faa21a0a

Debugging output and bugfixing pass 0
author lost@starbug
date Tue, 20 Apr 2010 21:59:58 -0600
parents
children 90de73ba0cac
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lwasm/debug.c	Tue Apr 20 21:59:58 2010 -0600
@@ -0,0 +1,80 @@
+/*
+debug.c
+
+Copyright © 2010 William Astle
+
+This file is part of LWTOOLS.
+
+LWTOOLS is free software: you can redistribute it and/or modify it under the
+terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <config.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include "lwasm.h"
+#include "instab.h"
+
+/*
+
+Various debug utilities
+
+*/
+void dump_state(asmstate_t *as, FILE *fp)
+{
+	line_t *cl;
+	exportlist_t *ex;
+	struct symtabe *s;
+	importlist_t *im;
+	struct line_expr_s *le;
+	lwasm_error_t *e;
+	
+	fprintf(fp, "Lines:\n");
+	
+	for (cl = as -> line_head; cl; cl = cl -> next)
+	{
+		fprintf(fp, "%p ", cl);
+		if (cl -> insn >= 0)
+		{
+			fprintf(fp, "INSN %d (%s) ", cl -> insn, instab[cl -> insn].opcode);
+			fprintf(fp, "LEN %d ", cl -> len);
+		}
+		fprintf(fp, "\n    ADDR:");
+		lw_expr_print(cl -> addr, fp);
+		for (le = cl -> exprs; le; le = le -> next)
+		{
+			fprintf(fp, "\n    EXPR %d:", le -> id);
+			lw_expr_print(le -> expr, fp);
+		}
+		if (cl -> outputl > 0)
+		{
+			int i;
+			fprintf(fp, "\n    OUTPUT:");
+			for (i = 0; i < cl -> outputl; i++)
+			{
+				fprintf(fp, "%02X", cl -> output[i]);
+			}
+		}
+		for (e = cl -> err; e; e = e -> next)
+		{
+			fprintf(fp, "\n    ERR: %s", e -> mess);
+		}
+		for (e = cl -> warn; e; e = e -> next)
+		{
+			fprintf(fp, "\n    WARN: %s", e -> mess);
+		}
+		fprintf(fp, "\n");
+	}
+}