diff lwasm/list.c @ 384:38b50ce6967a

Made --list and --depend work
author lost@starbug
date Sat, 15 May 2010 20:46:04 -0600
parents
children a741d2e4869f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lwasm/list.c	Sat May 15 20:46:04 2010 -0600
@@ -0,0 +1,89 @@
+/*
+list.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 <lw_alloc.h>
+#include <lw_string.h>
+
+#include "lwasm.h"
+#include "instab.h"
+
+/*
+Do listing
+*/
+void do_list(asmstate_t *as)
+{
+	line_t *cl;
+	FILE *of;
+	int i;
+	
+	if (!(as -> flags & FLAG_LIST))
+		return;
+
+	if (as -> list_file)
+		of = fopen(as -> list_file, "w");
+	else
+		of = stdout;
+	if (!of)
+	{
+		fprintf(stderr, "Cannot open list file; list not generated\n");
+		return;
+	}
+	for (cl = as -> line_head; cl; cl = cl -> next)
+	{
+		if (cl -> len < 1)
+		{
+			fprintf(of, "                      ");
+		}
+		else
+		{
+			fprintf(of, "%04X ", lw_expr_intval(cl -> addr));
+			for (i = 0; i < cl -> outputl && i < 8; i++)
+			{
+				fprintf(of, "%02X", cl -> output[i]);
+			}
+			for (; i < 8; i++)
+			{
+				fprintf(of, "  ");
+			}
+			fprintf(of, " ");
+		}
+		fprintf(of, "%15s:%05d %s\n", cl -> linespec, cl -> lineno, cl -> ltext);
+		if (cl -> outputl > 8)
+		{
+			for (i = 8; i < cl -> outputl; i++)
+			{
+				if (i % 8 == 0)
+				{
+					if (i != 8)
+						fprintf(of, "\n     ");
+					else
+						fprintf(of, "     ");
+				}
+				fprintf(of, "%02X", cl -> output[i]);
+			}
+		}
+	}
+}