changeset 367:c6d2a1f54e0c

Change processor target variations to pragmas. Add "pragma 6809" and "pragma 6309" which select the processor target rather than a global flag. The command line switches set or reset the pragma appropriately. Thanks to Erik G <erik@6809.org> for the patch.
author William Astle <lost@l-w.ca>
date Mon, 15 Jun 2015 21:21:58 -0600
parents 433dbc18fb41
children 362f8fb0695b
files lwasm/insn_indexed.c lwasm/insn_rtor.c lwasm/instab.c lwasm/instab.h lwasm/lwasm.h lwasm/main.c lwasm/pass1.c lwasm/pragma.c
diffstat 8 files changed, 15 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/insn_indexed.c	Tue Jun 02 20:58:14 2015 -0600
+++ b/lwasm/insn_indexed.c	Mon Jun 15 21:21:58 2015 -0600
@@ -99,7 +99,7 @@
 	const char *reglist;
 	lw_expr_t e;
 		
-	if (as -> target == TARGET_6809)
+	if (CURPRAGMA(l, PRAGMA_6809))
 	{
 		simples = simpleindex9;
 		reglist = regs9;
--- a/lwasm/insn_rtor.c	Tue Jun 02 20:58:14 2015 -0600
+++ b/lwasm/insn_rtor.c	Mon Jun 15 21:21:58 2015 -0600
@@ -34,7 +34,7 @@
 	// D,X,Y,U,S,PC,W,V
 	// A,B,CC,DP,0,0,E,F
 
-	r0 = lwasm_lookupreg2((as -> target == TARGET_6309) ? regs : regs9, p);
+	r0 = lwasm_lookupreg2(!CURPRAGMA(l, PRAGMA_6809) ? regs : regs9, p);
 	if (r0 < 0 || *(*p)++ != ',')
 	{
 		lwasm_register_error(as, l, "Bad operand");
@@ -42,7 +42,7 @@
 	}
 	else
 	{
-		r1 = lwasm_lookupreg2((as -> target == TARGET_6309) ? regs : regs9, p);
+		r1 = lwasm_lookupreg2(!CURPRAGMA(l, PRAGMA_6809) ? regs : regs9, p);
 		if (r1 < 0)
 		{
 			lwasm_register_error(as, l, "Bad operand");
--- a/lwasm/instab.c	Tue Jun 02 20:58:14 2015 -0600
+++ b/lwasm/instab.c	Mon Jun 15 21:21:58 2015 -0600
@@ -521,7 +521,7 @@
 	{ "pulu",		{	0x37,	-1,		-1,		-1	},	insn_parse_rlist,		insn_resolve_rlist,				insn_emit_rlist,				lwasm_insn_normal},
 	{ "puluw",		{	0x103b,	-1,		-1,		-1	},	insn_parse_inh,			insn_resolve_inh,				insn_emit_inh,				lwasm_insn_is6309},
 	
-	{ "reset",		{	0x3e,	-1,		-1,		-1	},	insn_parse_inh,			insn_resolve_inh,				insn_emit_inh,				lwasm_insn_normal},
+	{ "reset",		{	0x3e,	-1,		-1,		-1	},	insn_parse_inh,			insn_resolve_inh,				insn_emit_inh,				lwasm_insn_is6809},
 	{ "rol",		{	0x09,	0x69,	0x79,	-1	},	insn_parse_gen0,		insn_resolve_gen0,				insn_emit_gen0,				lwasm_insn_normal},
 	{ "rola",		{	0x49,	-1,		-1,		-1	},	insn_parse_inh,			insn_resolve_inh,				insn_emit_inh,				lwasm_insn_normal},
 	{ "rolb",		{	0x59,	-1,		-1,		-1	},	insn_parse_inh,			insn_resolve_inh,				insn_emit_inh,				lwasm_insn_normal},
--- a/lwasm/instab.h	Tue Jun 02 20:58:14 2015 -0600
+++ b/lwasm/instab.h	Mon Jun 15 21:21:58 2015 -0600
@@ -45,6 +45,7 @@
 	lwasm_insn_struct = 16,		/* insn allowed in a struct */
 	lwasm_insn_setdata = 32,	/* insn uses the data address for symbols */
 	lwasm_insn_is6800 = 64,		/* insn is a 6800 compatibility operation */
+	lwasm_insn_is6809 = 128,	/* insn is 6809 only */
 	lwasm_insn_normal = 0
 };
 
--- a/lwasm/lwasm.h	Tue Jun 02 20:58:14 2015 -0600
+++ b/lwasm/lwasm.h	Mon Jun 15 21:21:58 2015 -0600
@@ -63,12 +63,6 @@
 	OUTPUT_HEX			// generic hexadecimal format
 };
 
-enum lwasm_target_e
-{
-	TARGET_6309 = 0,	// target 6309 CPU
-	TARGET_6809			// target 6809 CPU (no 6309 ops)
-};
-
 enum lwasm_flags_e
 {
 	FLAG_LIST = 0x0001,
@@ -97,7 +91,8 @@
 	PRAGMA_SYMBOLNOCASE = 0x400,		// symbols defined under this pragma are matched case insensitively
 	PRAGMA_CONDUNDEFZERO = 0x800,		// treat undefined symbols as zero in conditionals during pass 1
 	PRAGMA_6800COMPAT = 0x1000,			// enable 6800 compatibility opcodes
-	PRAGMA_FORWARDREFMAX = 0x2000		// force incomplete references on pass 1 to maximum mode
+	PRAGMA_FORWARDREFMAX = 0x2000,		// force incomplete references on pass 1 to maximum mode
+	PRAGMA_6809 = 0x4000				// 6809/6309 assembly mode
 };
 
 
@@ -272,7 +267,6 @@
 struct asmstate_s
 {
 	int output_format;					// output format
-	int target;							// assembly target
 	int debug_level;					// level of debugging requested
 	FILE *debug_file;					// FILE * to output debug messages to
 	int flags;							// assembly flags
--- a/lwasm/main.c	Tue Jun 02 20:58:14 2015 -0600
+++ b/lwasm/main.c	Mon Jun 15 21:21:58 2015 -0600
@@ -202,11 +202,11 @@
 		break;
 
 	case '9':
-		as -> target = TARGET_6809;
+		as -> pragmas |= PRAGMA_6809;
 		break;
 
 	case '3':
-		as -> target = TARGET_6309;
+		as -> pragmas &= ~PRAGMA_6809;
 		break;
 
 	case 'P':
@@ -292,7 +292,6 @@
 	asmstate.include_list = lw_stringlist_create();
 	asmstate.input_files = lw_stringlist_create();
 	asmstate.nextcontext = 1;
-	asmstate.target = TARGET_6309;
 	asmstate.exprwidth = 16;
 	
 	/* parse command line arguments */	
--- a/lwasm/pass1.c	Tue Jun 02 20:58:14 2015 -0600
+++ b/lwasm/pass1.c	Mon Jun 15 21:21:58 2015 -0600
@@ -299,7 +299,7 @@
 			if (as -> skipcond && !(instab[opnum].flags & lwasm_insn_cond))
 				goto linedone;
         	
-        	if (!nomacro && ((as -> pragmas & PRAGMA_SHADOW) || ((as -> target != TARGET_6309) && (instab[opnum].flags & lwasm_insn_is6309))))
+			if (!nomacro && ((as->pragmas & PRAGMA_SHADOW) || (!CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6309))))
         	{
         		// check for macros even if they shadow real operations
         		// NOTE: "ENDM" cannot be shadowed
@@ -333,9 +333,11 @@
 				// no parse func means operand doesn't matter
 				if (instab[opnum].parse)
 				{
-					if ((as -> target != TARGET_6309) && (instab[opnum].flags & lwasm_insn_is6309))
+					if (CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6309))
 						lwasm_register_error(as, cl, "Illegal use of 6309 instruction in 6809 mode (%s)", sym);
-			
+					if (!CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6809))
+						lwasm_register_error(as, cl, "Illegal use of 6809 instruction in 6309 mode (%s)", sym);
+
 					if (as -> instruct == 0 || instab[opnum].flags & lwasm_insn_struct)
 					{
 						cl -> len = -1;
--- a/lwasm/pragma.c	Tue Jun 02 20:58:14 2015 -0600
+++ b/lwasm/pragma.c	Mon Jun 15 21:21:58 2015 -0600
@@ -60,6 +60,7 @@
 	{ "symbolnocase", "nosymbolnocase", PRAGMA_SYMBOLNOCASE },
 	{ "nosymbolcase", "symbolcase", PRAGMA_SYMBOLNOCASE },
 	{ "condundefzero", "nocondundefzero", PRAGMA_CONDUNDEFZERO },
+	{ "6809", "6309", PRAGMA_6809 },
 	{ "6800compat", "no6800compat", PRAGMA_6800COMPAT },
 	{ "forwardrefmax", "noforwardrefmax", PRAGMA_FORWARDREFMAX },
 	{ 0, 0, 0}