changeset 382:80d615a6642c

Add REORG pseudo op For Macro-80C compatibility, add REORG pseudo op. It has some utility so this one is not protected by a pragma. Thanks to Erik G <erik@6809.org> for the patch.
author William Astle <lost@l-w.ca>
date Mon, 13 Jul 2015 21:18:02 -0600
parents e3f4aaa2a4e8
children 04e11f6faead
files lwasm/instab.c lwasm/lwasm.c lwasm/lwasm.h lwasm/pass1.c lwasm/pseudo.c
diffstat 5 files changed, 46 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/instab.c	Mon Jul 13 21:11:12 2015 -0600
+++ b/lwasm/instab.c	Mon Jul 13 21:18:02 2015 -0600
@@ -188,6 +188,10 @@
 #define pseudo_resolve_org NULL
 #define pseudo_emit_org NULL
 
+PARSEFUNC(pseudo_parse_reorg);
+#define pseudo_resolve_reorg NULL
+#define pseudo_emit_reorg NULL
+
 PARSEFUNC(pseudo_parse_equ);
 #define pseudo_resolve_equ NULL
 #define pseudo_emit_equ NULL
@@ -594,6 +598,7 @@
 	{ "tstw",		{	0x105d,	-1,		-1,		-1	},	insn_parse_inh,			insn_resolve_inh,				insn_emit_inh,				lwasm_insn_is6309},
 
 	{ "org",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_org,		pseudo_resolve_org,				pseudo_emit_org,			lwasm_insn_normal},
+	{ "reorg",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_reorg,		pseudo_resolve_reorg,			pseudo_emit_reorg,			lwasm_insn_normal},
 	{ "equ",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_equ,		pseudo_resolve_equ,				pseudo_emit_equ,			lwasm_insn_setsym},
 	{ "=",			{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_equ,		pseudo_resolve_equ,				pseudo_emit_equ,			lwasm_insn_setsym},
 
--- a/lwasm/lwasm.c	Mon Jul 13 21:11:12 2015 -0600
+++ b/lwasm/lwasm.c	Mon Jul 13 21:18:02 2015 -0600
@@ -261,6 +261,7 @@
 		case E_STRUCT_RECURSE:			return "Attempt to define a structure inside a structure";
 		case E_SYMBOL_DUPE:				return "Multiply defined symbol";
 		case E_UNKNOWN_OPERATION:		return "Unknown operation";
+		case E_ORG_NOT_FOUND:			return "Previous ORG not found";
 
 		case W_ENDSTRUCT_WITHOUT:		return "ENDSTRUCT without STRUCT";
 		case W_DUPLICATE_SECTION:		return "Section flags can only be specified the first time; ignoring duplicate definition";
--- a/lwasm/lwasm.h	Mon Jul 13 21:11:12 2015 -0600
+++ b/lwasm/lwasm.h	Mon Jul 13 21:18:02 2015 -0600
@@ -195,6 +195,7 @@
 	E_SYMBOL_UNDEFINED_EXPORT	= 54,
 	E_UNKNOWN_OPERATION			= 55,
 	E_USER_SPECIFIED			= 56,
+	E_ORG_NOT_FOUND				= 57,
 
 	/* warnings must be 1000 or greater */
 
--- a/lwasm/pass1.c	Mon Jul 13 21:11:12 2015 -0600
+++ b/lwasm/pass1.c	Mon Jul 13 21:18:02 2015 -0600
@@ -352,6 +352,7 @@
 						// call parse function
 						debug_message(as, 100, "len = %d, dlen = %d", cl -> len, cl -> dlen);
 						(instab[opnum].parse)(as, cl, &p1);
+
 						// if we're forcing address modes on pass 1, force a resolution
 						if (CURPRAGMA(cl, PRAGMA_FORWARDREFMAX) && instab[opnum].resolve)
 						{
@@ -364,7 +365,6 @@
 							else
 								cl -> dlen = cl -> len;
 						}
-					
 						if (*p1 && !isspace(*p1) && !(cl -> err))
 						{
 							// flag bad operand error
--- a/lwasm/pseudo.c	Mon Jul 13 21:11:12 2015 -0600
+++ b/lwasm/pseudo.c	Mon Jul 13 21:18:02 2015 -0600
@@ -965,6 +965,44 @@
 	l -> len = 0;
 }
 
+PARSEFUNC(pseudo_parse_reorg)
+{
+	lw_expr_t e = NULL;
+
+	l -> len = 0;
+
+	line_t *cl = l;
+	for (cl = cl -> prev; cl; cl = cl -> prev)
+	{
+		if (cl -> insn == -1) continue;
+
+		if (!strcmp("org", instab[cl -> insn].opcode))
+		{
+			if (cl -> prev)
+			{
+				e = lw_expr_copy(cl -> prev -> daddr);
+				break;
+			}
+		}
+	}
+
+	if (!e)
+	{
+		lwasm_register_error(as, l, E_ORG_NOT_FOUND);
+		return;
+	}
+
+	lw_expr_destroy(l -> daddr);
+	l -> daddr = e;
+
+	if (l -> inmod == 0)
+	{
+		lw_expr_destroy(l -> addr);
+		l -> addr = e;
+	}
+	l -> len = 0;
+}
+
 PARSEFUNC(pseudo_parse_equ)
 {
 	lw_expr_t e;