changeset 325:619fd6ad4ab9

Completed command line parsing
author lost
date Sat, 13 Feb 2010 05:20:55 +0000
parents be63116281b0
children 2eb058346cad
files lwasm/Makefile.am lwasm/lwasm.h lwasm/main.c lwasm/pragma.c
diffstat 4 files changed, 153 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/Makefile.am	Tue Feb 09 05:59:56 2010 +0000
+++ b/lwasm/Makefile.am	Sat Feb 13 05:20:55 2010 +0000
@@ -1,5 +1,5 @@
 AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_builddir)/lwlib -I$(top_srcdir)/lwlib
 bin_PROGRAMS = lwasm
-lwasm_SOURCES = main.c
+lwasm_SOURCES = main.c pragma.c
 lwasm_LDADD = -L$(top_builddir)/lib -L$(top_srcdir)/lib -L$(top_builddir)/lwlib -L$(top_srcdir)/lwlib -lgnu -llw
 EXTRA_DIST =  lwasm.h
--- a/lwasm/lwasm.h	Tue Feb 09 05:59:56 2010 +0000
+++ b/lwasm/lwasm.h	Sat Feb 13 05:20:55 2010 +0000
@@ -39,13 +39,35 @@
 	TARGET_6809			// target 6809 CPU (no 6309 ops)
 };
 
+enum lwasm_flags_e
+{
+	FLAG_NONE = 0,
+	FLAG_LIST = 0x0001,
+	FLAG_DEPEND = 0x0002
+};
+
+enum lwasm_pragmas_e
+{
+	PRAGMA_NONE = 0,					// no pragmas in effect
+	PRAGMA_DOLLARNOTLOCAL = 0x0001,		// dollar sign does not make a symbol local
+	PRAGMA_NOINDEX0TONONE = 0x0002,		// do not change implicit 0,R to ,R
+	PRAGMA_UNDEFEXTERN = 0x0004,		// undefined symbols are considered to be external
+	PRAGMA_CESCAPES = 0x0008,			// allow C style escapes in fcc, fcs, fcn, etc.
+	PRAGMA_IMPORTUNDEFEXPORT = 0x0010	// imports symbol if undefined upon export
+};
+
 typedef struct
 {
 	int output_format;					// output format
 	int target;							// assembly target
 	int debug_level;					// level of debugging requested
-	
+	int flags;							// assembly flags
+	int pragmas;						// pragmas currently in effect
+
+	char *list_file;					// name of file to list to
+	char *output_file;					// output file name	
 	lw_stringlist_t input_files;		// files to assemble
+	lw_stringlist_t include_list;		// include paths
 } asmstate_t;
 
 #endif /* ___lwasm_h_seen___ */
--- a/lwasm/main.c	Tue Feb 09 05:59:56 2010 +0000
+++ b/lwasm/main.c	Sat Feb 13 05:20:55 2010 +0000
@@ -25,8 +25,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <lw_string.h>
+#include <lw_stringlist.h>
+
 #include "lwasm.h"
 
+extern int parse_pragma_string(asmstate_t *as, char *str);
+
 /* command line option handling */
 const char *argp_program_version = "lwasm from " PACKAGE_STRING;
 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
@@ -57,13 +62,29 @@
 	switch (key)
 	{
 	case 'I':
+		lw_stringlist_addstring(as -> include_list, arg);
+		break;
+
 	case 'o':
+		if (as -> output_file)
+			lw_free(as -> output_file);
+		as -> output_file = lw_strdup(arg);
+		break;
+
 	case 'd':
 		as -> debug_level++;
 		break;
 
 	case 'l':
-
+		if (as -> list_file)
+			lw_free(as -> list_file);
+		if (!arg)
+			as -> list_file = NULL;
+		else
+			as -> list_file = lw_strdup(arg);
+		as -> flags |= FLAG_LIST;
+		break;
+		
 	case 'b':
 		as -> output_format = OUTPUT_DECB;
 		break;
@@ -77,6 +98,9 @@
 		break;
 
 	case 0x101:
+		as -> flags |= FLAG_DEPEND;
+		break;
+
 	case 'f':
 		if (!strcasecmp(arg, "decb"))
 			as -> output_format = OUTPUT_DECB;
@@ -86,7 +110,7 @@
 			as -> output_format = OUTPUT_OBJ;
 		else if (!strcasecmp(arg, "os9"))
 		{
-			//as -> pragmas |= PRAGMA_DOLLARNOTLOCAL;
+			as -> pragmas |= PRAGMA_DOLLARNOTLOCAL;
 			as -> output_format = OUTPUT_OS9;
 		}
 		else
@@ -97,6 +121,13 @@
 		break;
 		
 	case 'p':
+		if (parse_pragma_string(as, arg) == 0)
+		{
+			fprintf(stderr, "Unrecognized pragma string: %s\n", arg);
+			exit(1);
+		}
+		break;
+
 	case '9':
 		as -> target = TARGET_6809;
 		break;
@@ -109,6 +140,7 @@
 		break;
 	
 	case ARGP_KEY_ARG:
+		lw_stringlist_addstring(as -> input_files, arg);
 		break;
 		
 	default:
@@ -133,9 +165,13 @@
 {
 	/* assembler state */
 	asmstate_t asmstate = { 0 };
+	program_name = argv[0];
 
-	program_name = argv[0];
-	
+	/* initialize assembler state */
+	asmstate.input_files = lw_stringlist_create();
+	asmstate.include_list = lw_stringlist_create();
+
+	/* parse command line arguments */	
 	argp_parse(&argp, argc, argv, 0, 0, &asmstate);
 
 	exit(0);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lwasm/pragma.c	Sat Feb 13 05:20:55 2010 +0000
@@ -0,0 +1,89 @@
+/*
+pragma.c
+
+Copyright © 2010 William Astle
+
+This file is part of LWTOOLS.
+
+LWTOOLS is free software: you can redistribute it and/or modify it under the
+terms of the GNU General Public License as published by the Free Software
+Foundation, either version 3 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+more details.
+
+You should have received a copy of the GNU General Public License along with
+this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <config.h>
+
+#include <lw_string.h>
+
+#include "lwasm.h"
+
+struct pragma_list
+{
+	const char *str;
+	int flag;
+};
+
+static const struct pragma_list set_pragmas[] =
+{
+	{ "dollarnotlocal", PRAGMA_DOLLARNOTLOCAL },
+	{ "noindex0tonone", PRAGMA_NOINDEX0TONONE },
+	{ "undefextern", PRAGMA_UNDEFEXTERN },
+	{ "cescapes", PRAGMA_CESCAPES },
+	{ "importundefexport", PRAGMA_IMPORTUNDEFEXPORT },
+	{ 0, 0 }
+};
+
+static const struct pragma_list reset_pragmas[] =
+{
+	{ "nodollarnotlocal", PRAGMA_DOLLARNOTLOCAL },
+	{ "index0tonone", PRAGMA_NOINDEX0TONONE },
+	{ "noundefextern", PRAGMA_UNDEFEXTERN },
+	{ "nocescapes", PRAGMA_CESCAPES },
+	{ "noimportundefexport", PRAGMA_IMPORTUNDEFEXPORT },
+	{ 0, 0 }
+};
+
+int parse_pragma_string(asmstate_t *as, char *str)
+{
+	char *p;
+	int i;
+	const char *np = str;
+	int pragmas = as -> pragmas;
+
+	while (np)
+	{
+		p = lw_token(np, ',', &np);
+		for (i = 0; set_pragmas[i].str; i++)
+		{
+			if (!strcasecmp(p, set_pragmas[i].str))
+			{
+				pragmas |= set_pragmas[i].flag;
+				goto out;
+			}
+		}
+		for (i = 0; reset_pragmas[i].str; i++)
+		{
+			if (!strcasecmp(p, reset_pragmas[i].str))
+			{
+				pragmas &= ~(reset_pragmas[i].flag);
+				goto out;
+			}
+		}
+		/* unrecognized pragma here */
+		lw_free(p);
+		return 0;
+		
+	out:	
+		lw_free(p);
+	}
+	as -> pragmas = pragmas;
+	return 1;
+}