changeset 49:bd8b3fbd1e28

Added ability to flag macros as "noexpand" so they are not expanded in the listing
author lost@l-w.ca
date Tue, 05 Apr 2011 00:06:28 -0600
parents 1134255553bc
children f55650f5e9b8
files lwasm/list.c lwasm/lwasm.h lwasm/macro.c lwasm/pass1.c
diffstat 4 files changed, 100 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/list.c	Mon Apr 04 22:20:38 2011 -0600
+++ b/lwasm/list.c	Tue Apr 05 00:06:28 2011 -0600
@@ -35,10 +35,12 @@
 */
 void do_list(asmstate_t *as)
 {
-	line_t *cl;
+	line_t *cl, *nl;
 	FILE *of;
 	int i;
-
+	char *obytes = NULL;
+	int obytelen = 0;
+	
 	char *tc;
 		
 	if (!(as -> flags & FLAG_LIST))
@@ -53,9 +55,49 @@
 		fprintf(stderr, "Cannot open list file; list not generated\n");
 		return;
 	}
-	for (cl = as -> line_head; cl; cl = cl -> next)
+	for (cl = as -> line_head; cl; cl = nl)
 	{
-		if (cl -> len < 1)
+		nl = cl -> next;
+		if (cl -> noexpand_start)
+		{
+			obytelen = 0;
+			int nc = 0;
+			for (nl = cl; ; nl = nl -> next)
+			{
+				if (nl -> noexpand_start)
+					nc++;
+				if (nl -> noexpand_end)
+					nc--;
+				
+				if (nl -> outputl > 0)
+					obytelen += nl -> outputl;
+				if (nc == 0)
+					break;
+			}
+			obytes = lw_alloc(obytelen);
+			nc = 0;
+			for (nl = cl; ; nl = nl -> next)
+			{
+				int i;
+				for (i = 0; i < nl -> outputl; i++)
+				{
+					obytes[nc++] = nl -> output[i];
+				}
+				if (nc >= obytelen)
+					break;
+			}
+			nl = nl -> next;
+		}
+		else
+		{
+			obytelen = cl -> outputl;
+			if (obytelen > 0)
+			{
+				obytes = lw_alloc(obytelen);
+				memmove(obytes, cl -> output, cl -> outputl);
+			}
+		}
+		if (cl -> len < 1 && obytelen < 1)
 		{
 			if (cl -> soff >= 0)
 			{
@@ -106,9 +148,9 @@
 //			fprintf(of, "%s\n", lw_expr_print(te));
 			fprintf(of, "%04X ", lw_expr_intval(te) & 0xffff);
 			lw_expr_destroy(te);
-			for (i = 0; i < cl -> outputl && i < 8; i++)
+			for (i = 0; i < obytelen && i < 8; i++)
 			{
-				fprintf(of, "%02X", cl -> output[i]);
+				fprintf(of, "%02X", obytes[i]);
 			}
 			for (; i < 8; i++)
 			{
@@ -147,7 +189,7 @@
 		fputc('\n', of);
 		if (cl -> outputl > 8)
 		{
-			for (i = 8; i < cl -> outputl; i++)
+			for (i = 8; i < obytelen; i++)
 			{
 				if (i % 8 == 0)
 				{
@@ -156,11 +198,13 @@
 					else
 						fprintf(of, "     ");
 				}
-				fprintf(of, "%02X", cl -> output[i]);
+				fprintf(of, "%02X", obytes[i]);
 			}
 			if (i > 8)
 				fprintf(of, "\n");
 		}
+		lw_free(obytes);
+		obytes = NULL;
 	}
 	
 	if (as -> flags & FLAG_SYMBOLS)
--- a/lwasm/lwasm.h	Mon Apr 04 22:20:38 2011 -0600
+++ b/lwasm/lwasm.h	Tue Apr 05 00:06:28 2011 -0600
@@ -173,6 +173,10 @@
 	int dsize;							// set to 1 for 8 bit dshow value
 	int isbrpt;							// set to 1 if this line is a branch point
 	struct symtabe *dptr;				// symbol value to display
+
+	int noexpand_start;					// start of a no-expand block
+	int noexpand_end;					// end of a no-expand block
+	
 };
 
 enum
@@ -204,9 +208,15 @@
 	char *name;							// name of macro
 	char **lines;						// macro lines
 	int numlines;						// number lines in macro
+	int flags;							// flags for the macro
 	macrotab_t *next;					// next macro in list
 };
 
+enum
+{
+	macro_noexpand = 1					// set to not expland the macro by default in listing
+};
+
 typedef struct structtab_s structtab_t;
 typedef struct structtab_field_s structtab_field_t;
 
--- a/lwasm/macro.c	Mon Apr 04 22:20:38 2011 -0600
+++ b/lwasm/macro.c	Tue Apr 05 00:06:28 2011 -0600
@@ -35,7 +35,9 @@
 PARSEFUNC(pseudo_parse_macro)
 {
 	macrotab_t *m;
-	
+	char *t;
+	char tc;
+		
 	l -> len = 0;
 	
 	if (as -> skipcond)
@@ -72,11 +74,17 @@
 	m -> next = as -> macros;
 	m -> lines = NULL;
 	m -> numlines = 0;
+	m -> flags = 0;
 	as -> macros = m;
-	
+
+	t = *p;
 	while (**p && !isspace(**p))
 		(*p)++;
-	
+	tc = **p;
+	/* ignore unknown flags */
+	if (strcasecmp(t, "noexpand") == 0)
+		m -> flags |= macro_noexpand;
+	**p = tc;
 	as -> inmacro = 1;
 }
 
@@ -204,6 +212,16 @@
 	// and push it into the front of the input stack
 	bloc = blen = 0;
 	linebuff = NULL;
+
+	if (m -> flags & macro_noexpand)
+	{
+		char ctcbuf[100];
+		char *p;
+		snprintf(ctcbuf, 100, "\001\001SETNOEXPANDSTART\n");
+		for (p = ctcbuf; *p; p++)
+			macro_add_to_buff(&linebuff, &bloc, &blen, *p);
+	}
+
 	
 	for (lc = 0; lc < m -> numlines; lc++)
 	{
@@ -264,6 +282,15 @@
 		
 	}
 
+	if (m -> flags & macro_noexpand)
+	{
+		char ctcbuf[100];
+		char *p;
+		snprintf(ctcbuf, 100, "\001\001SETNOEXPANDEND\n");
+		for (p = ctcbuf; *p; p++)
+			macro_add_to_buff(&linebuff, &bloc, &blen, *p);
+	}
+
 	{
 		char ctcbuf[100];
 		char *p;
--- a/lwasm/pass1.c	Mon Apr 04 22:20:38 2011 -0600
+++ b/lwasm/pass1.c	Tue Apr 05 00:06:28 2011 -0600
@@ -81,6 +81,14 @@
 			{
 				lc = strtol(p1, NULL, 10);
 			}
+			else if (!strcmp(line + 2, "SETNOEXPANDSTART"))
+			{
+				as -> line_tail -> noexpand_start = 1;
+			}
+			else if (!strcmp(line + 2, "SETNOEXPANDEND"))
+			{
+				as -> line_tail -> noexpand_end = 1;
+			}
 			lw_free(line);
 			if (lc == 0)
 				lc = 1;