changeset 352:f5b77989f675

Added PRAGMA and *PRAGMA
author lost@starbug
date Tue, 30 Mar 2010 20:56:54 -0600
parents 4dba8c7e242c
children faa97115952e
files lwasm/instab.c lwasm/main.c lwasm/pragma.c
diffstat 3 files changed, 52 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/instab.c	Sat Mar 27 23:37:30 2010 -0600
+++ b/lwasm/instab.c	Tue Mar 30 20:56:54 2010 -0600
@@ -161,6 +161,15 @@
 #define pseudo_resolve_else NULL
 #define pseudo_emit_else NULL
 
+extern PARSEFUNC(pseudo_parse_pragma);
+#define pseudo_resolve_pragma NULL
+#define pseudo_emit_pragma NULL
+
+extern PARSEFUNC(pseudo_parse_starpragma);
+#define pseudo_resolve_starpragma NULL
+#define pseudo_emit_starpragma NULL
+
+
 instab_t instab[] =
 {
 /*
@@ -486,10 +495,11 @@
 	{ "endsect",	{	-1, 	-1, 	-1, 	-1},	pseudo_parse_endsection,pseudo_resolve_endsection,		pseudo_emit_endsection,		lwasm_insn_normal},
 	{ "endsection",	{	-1,		-1, 	-1, 	-1},	pseudo_parse_endsection,pseudo_resolve_endsection,		pseudo_emit_endsection,		lwasm_insn_normal},
 	
+*/
 	{ "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},
 	
-	// for os9 target
+/*	// for os9 target
 	{ "os9",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_os9,		pseudo_resolve_os9,				pseudo_emit_os9,			lwasm_insn_normal},
 	{ "mod",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_mod,		pseudo_resolve_mod,				pseudo_emit_mod,			lwasm_insn_normal},
 	{ "emod",		{	-1, 	-1, 	-1, 	-1 },	pseudo_parse_emod,		pseudo_resolve_emod,			pseudo_emit_emod,			lwasm_insn_normal},
--- a/lwasm/main.c	Sat Mar 27 23:37:30 2010 -0600
+++ b/lwasm/main.c	Tue Mar 30 20:56:54 2010 -0600
@@ -33,7 +33,7 @@
 #include "lwasm.h"
 #include "input.h"
 
-extern int parse_pragma_string(asmstate_t *as, char *str);
+extern int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr);
 
 /* command line option handling */
 const char *argp_program_version = "lwasm from " PACKAGE_STRING;
@@ -124,7 +124,7 @@
 		break;
 		
 	case 'p':
-		if (parse_pragma_string(as, arg) == 0)
+		if (parse_pragma_string(as, arg, 0) == 0)
 		{
 			fprintf(stderr, "Unrecognized pragma string: %s\n", arg);
 			exit(1);
--- a/lwasm/pragma.c	Sat Mar 27 23:37:30 2010 -0600
+++ b/lwasm/pragma.c	Tue Mar 30 20:56:54 2010 -0600
@@ -24,6 +24,7 @@
 #include <lw_string.h>
 
 #include "lwasm.h"
+#include "instab.h"
 
 struct pragma_list
 {
@@ -51,7 +52,7 @@
 	{ 0, 0 }
 };
 
-int parse_pragma_string(asmstate_t *as, char *str)
+int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr)
 {
 	char *p;
 	int i;
@@ -78,12 +79,46 @@
 			}
 		}
 		/* unrecognized pragma here */
-		lw_free(p);
-		return 0;
-		
+		if (!ignoreerr)
+		{
+			lw_free(p);
+			return 0;
+		}
 	out:	
 		lw_free(p);
 	}
 	as -> pragmas = pragmas;
 	return 1;
 }
+
+PARSEFUNC(pseudo_parse_pragma)
+{
+	char *ps, *t;
+	
+	for (t = *p; *t && !isspace(*t); t++)
+		/* do nothing */ ;
+	
+	ps = lw_strndup(*p, t - *p);
+	*p = t;
+
+	if (parse_pragma_string(as, ps, 0) == 0)
+	{
+		lwasm_register_error(as, l, "Unrecognized pragma string");
+	}
+	lw_free(ps);
+}
+
+PARSEFUNC(pseudo_parse_starpragma)
+{
+	char *ps, *t;
+	
+	for (t = *p; *t && !isspace(*t); t++)
+		/* do nothing */ ;
+	
+	ps = lw_strndup(*p, t - *p);
+	*p = t;
+
+	// *pragma must NEVER throw an error
+	parse_pragma_string(as, ps, 1);
+	lw_free(ps);
+}