changeset 110:38c1537857ce

Pragma stack at parse stage now works
author lost@l-w.ca
date Sun, 07 Aug 2011 10:37:22 -0600
parents 6a919c3ca0e9
children c0aedb1584af
files lwasm/debug.c lwasm/input.c lwasm/instab.c lwasm/pragma.c
diffstat 4 files changed, 23 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/debug.c	Sun Aug 07 10:23:14 2011 -0600
+++ b/lwasm/debug.c	Sun Aug 07 10:37:22 2011 -0600
@@ -44,7 +44,7 @@
 	
 	for (cl = as -> line_head; cl; cl = cl -> next)
 	{
-		debug_message(as, 100, "%p INSN %d (%s) LEN %d", cl, cl -> insn, (cl -> insn >= 0) ? instab[cl -> insn].opcode : "<none>", cl -> len);
+		debug_message(as, 100, "%p INSN %d (%s) LEN %d PRAGMA %x", cl, cl -> insn, (cl -> insn >= 0) ? instab[cl -> insn].opcode : "<none>", cl -> len, cl -> pragmas);
 		debug_message(as, 100, "    ADDR: %s", lw_expr_print(cl -> addr));
 		debug_message(as, 100, "    PB: %02X; LINT: %X; LINT2: %X", cl -> pb, cl -> lint, cl -> lint2);
 		for (le = cl -> exprs; le; le = le -> next)
--- a/lwasm/input.c	Sun Aug 07 10:23:14 2011 -0600
+++ b/lwasm/input.c	Sun Aug 07 10:37:22 2011 -0600
@@ -337,11 +337,19 @@
 				if (lbloc == 0)
 				{
 					struct input_stack *t;
+					struct input_stack_node *n;
 					if (IS -> data)
 						fclose(IS -> data);
 					lw_free(lw_stack_pop(as -> file_dir));
 					lw_free(IS -> filespec);
 					t = IS -> next;
+					while (IS -> stack)
+					{
+						n = IS -> stack;
+						IS -> stack = n -> next;
+						lw_free(n -> entry);
+						lw_free(n);
+					}
 					lw_free(IS);
 					as -> input_data = t;
 					goto nextfile;
@@ -386,9 +394,17 @@
 		if (((char *)(IS -> data))[IS -> data2] == '\0')
 		{
 			struct input_stack *t;
+			struct input_stack_node *n;
 			lw_free(IS -> data);
 			lw_free(IS -> filespec);
 			t = IS -> next;
+			while (IS -> stack)
+			{
+				n = IS -> stack;
+				IS -> stack = n -> next;
+				lw_free(n -> entry);
+				lw_free(n);
+			}
 			lw_free(IS);
 			as -> input_data = t;
 			goto nextfile;
@@ -452,6 +468,7 @@
 	n = lw_alloc(sizeof(struct input_stack_node));	
 	n -> next = IS -> stack;
 	n -> entry = e;
+	IS -> stack = n;
 }
 
 input_stack_entry *input_stack_pop(asmstate_t *as, int magic, int (*fn)(input_stack_entry *e, void *data), void *data)
--- a/lwasm/instab.c	Sun Aug 07 10:23:14 2011 -0600
+++ b/lwasm/instab.c	Sun Aug 07 10:37:22 2011 -0600
@@ -643,7 +643,7 @@
 	{ "pragma",		{	-1, 	-1, 	-1, 	-1},	pseudo_parse_pragma,	pseudo_resolve_pragma,			pseudo_emit_pragma,			lwasm_insn_normal},
 	{ "*pragma",	{	-1, 	-1, 	-1, 	-1},	pseudo_parse_starpragma,pseudo_resolve_starpragma,		pseudo_emit_starpragma,		lwasm_insn_normal},
 	{ "*pragmapush",	{	-1,	-1, 	-1,	-1},	pseudo_parse_starpragmapush, pseudo_resolve_starpragmapush, pseudo_emit_starpragmapush,	lwasm_insn_normal},
-	{ "*pragmappop",	{	-1,	-1, 	-1,	-1},	pseudo_parse_starpragmapop, pseudo_resolve_starpragmapop, pseudo_emit_starpragmapop,	lwasm_insn_normal},
+	{ "*pragmapop",	{	-1,	-1, 	-1,	-1},	pseudo_parse_starpragmapop, pseudo_resolve_starpragmapop, pseudo_emit_starpragmapop,	lwasm_insn_normal},
 	
 	
 	// for os9 target
--- a/lwasm/pragma.c	Sun Aug 07 10:23:14 2011 -0600
+++ b/lwasm/pragma.c	Sun Aug 07 10:37:22 2011 -0600
@@ -137,7 +137,7 @@
 {
 	int flag = *((int *)d);
 	struct pragma_stack_entry *pse = (struct pragma_stack_entry *)e;
-	
+
 	if (pse -> flag == flag)
 		return 1;
 	return 0;
@@ -172,6 +172,7 @@
 				pse = (struct pragma_stack_entry *)input_stack_pop(as, 0x42424242, pragma_stack_compare, (void *)&(set_pragmas[i].flag));
 				if (pse)
 				{
+					debug_message(as, 100, "Popped pragma string %s", pse->str);
 					parse_pragma_string(as, (char *)&(pse->str), 1);
 					lw_free(pse);
 				}
@@ -227,6 +228,8 @@
 				pse -> flag = set_pragmas[i].flag;
 				pse -> magic = 0x42424242;
 				strcpy((char *)&(pse -> str), t);
+				debug_message(as, 100, "Pushed pragma string %s", pse->str);
+
 				input_stack_push(as, (input_stack_entry *)pse);
 				
 				if (set_pragmas[i].flag == PRAGMA_NOLIST)