changeset 207:07e1fac76321

Added pragma to allow non case sensitive symbols Added "nosymbolcase" and "symbolnocase" pragmas to cause symbols defined while the pragma is in effect to be treated as case insensitive. Also documented the new pragma.
author William Astle <lost@l-w.ca>
date Sat, 09 Jun 2012 15:47:22 -0600
parents 080bb67d84f2
children fa835b780ffb
files docs/manual.docbook.sgml lwasm/lwasm.h lwasm/pragma.c lwasm/symbol.c
diffstat 4 files changed, 34 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/docs/manual.docbook.sgml	Thu May 24 17:28:15 2012 -0600
+++ b/docs/manual.docbook.sgml	Sat Jun 09 15:47:22 2012 -0600
@@ -1496,11 +1496,12 @@
 </varlistentry>
 </variablelist>
 
-<para>Each pragma supported has a positive version and a negative version.
+<para>Each pragma supported has a positive version and a negative version. 
 The positive version enables the pragma while the negative version disables
-it. The negatitve version is simply the positive version with "no" prefixed
-to it. For instance, "pragma" vs. "nopragma". Only the positive version is
-listed below.</para>
+it.  The negatitve version is simply the positive version with "no" prefixed
+to it.  For instance, "pragma" vs.  "nopragma".  When only one version is
+listed below, its opposite can be obtained by prepending "no" if it is not
+present or removing "no" from the beginning if it is present.</para>
 
 <para>Pragmas are not case sensitive.</para>
 
@@ -1657,9 +1658,20 @@
 assemblers, it is strongly recommended that it be invoked using the PRAGMA
 directive within the source code rather than on the command line or via the
 *PRAGMA directive.  This way, an error will be raised if someone tries to
-* assemble the code under a different assembler.</para>
+assemble the code under a different assembler.</para>
+
+<varlistentry>
+<term>nosymbolcase</term>
+<term>symbolnocase</term>
+<listitem>
 
+<para>Any symbol defined while this pragma is in force will be treated as
+case insensitive, regardless whether the pragma is in force when the symbol
+is referenced.</para>
 
+<para>It is important to note that this pragma will not work as expected in
+all cases when using the object file assembly target.  It is intended for
+use only when the assembler will be producing the final binary.</para>
 
 </listitem>
 </varlistentry>
--- a/lwasm/lwasm.h	Thu May 24 17:28:15 2012 -0600
+++ b/lwasm/lwasm.h	Sat Jun 09 15:47:22 2012 -0600
@@ -83,7 +83,8 @@
 	PRAGMA_SHADOW = 0x0040,				// allow macros to shadow builtin operations
 	PRAGMA_NOLIST = 0x0080,				// don't show line in listing
 	PRAGMA_AUTOBRANCHLENGTH = 0x0100,	// automatically select proper length for relative branches
-	PRAGMA_EXPORT = 0x0200				// export symbols by default, unless local
+	PRAGMA_EXPORT = 0x0200,				// export symbols by default, unless local
+	PRAGMA_SYMBOLNOCASE = 0x400			// symbols defined under this pragma are matched case insensitively
 };
 
 
@@ -194,6 +195,7 @@
 	symbol_flag_set = 1,				// symbol was used with "set"
 	symbol_flag_nocheck = 2,			// do not check symbol characters
 	symbol_flag_nolist = 4,				// no not show symbol in symbol table
+	symbol_flag_nocase = 8,				// do not match case of symbol
 	symbol_flag_none = 0				// no flags
 };
 
--- a/lwasm/pragma.c	Thu May 24 17:28:15 2012 -0600
+++ b/lwasm/pragma.c	Sat Jun 09 15:47:22 2012 -0600
@@ -57,6 +57,8 @@
 	{ "nolist", "list", PRAGMA_NOLIST },
 	{ "autobranchlength", "noautobranchlength", PRAGMA_AUTOBRANCHLENGTH },
 	{ "export", "noexport", PRAGMA_EXPORT },
+	{ "symbolnocase", "nosymbolnocase", PRAGMA_SYMBOLNOCASE },
+	{ "nosymbolcase", "symbolcase", PRAGMA_SYMBOLNOCASE },
 	{ 0, 0, 0}
 };
 
--- a/lwasm/symbol.c	Thu May 24 17:28:15 2012 -0600
+++ b/lwasm/symbol.c	Sat Jun 09 15:47:22 2012 -0600
@@ -130,7 +130,10 @@
 	{
 		int ndir;
 		debug_message(as, 300, "Symbol add lookup: %p", se);
-		ndir = strcmp(sym, se->symbol);
+		if (se -> flags & symbol_flag_nocase)
+			ndir = strcasecmp(sym, se->symbol);
+		else
+			ndir = strcmp(sym, se->symbol);
 		if (!ndir && se -> context != context)
 		{
 			ndir = (context < se -> context) ? -1 : 1;
@@ -175,6 +178,10 @@
 	{
 		nse -> flags |= symbol_flag_nolist;
 	}
+	if (CURPRAGMA(cl, PRAGMA_SYMBOLNOCASE))
+	{
+		nse -> flags |= symbol_flag_nocase;
+	}
 	nse -> value = lw_expr_copy(val);
 	nse -> symbol = lw_strdup(sym);
 	nse -> right = NULL;
@@ -251,7 +258,10 @@
 	
 	for (s = as -> symtab.head; s; )
 	{
-		cdir = strcmp(sym, s->symbol);
+		if (s->flags & symbol_flag_nocase)
+			cdir = strcasecmp(sym, s->symbol);
+		else
+			cdir = strcmp(sym, s->symbol);
 		if (!cdir)
 		{
 			if (local && s -> context != cl -> context)