changeset 193:68f41eaf44f2

Added lwcc, lwcpp stubs
author lost@l-w.ca
date Fri, 13 Jan 2012 22:32:15 -0700
parents 8ae2670377ca
children f8b33b3a45ac
files .hgignore Makefile lwcc/cpp/lwcpp.c lwcc/lwcc.c
diffstat 4 files changed, 184 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Jan 13 21:33:55 2012 -0700
+++ b/.hgignore	Fri Jan 13 22:32:15 2012 -0700
@@ -9,3 +9,5 @@
 /lwobjdump$
 /lwar$
 /lwasm$
+/lwcc/lwcc$
+/lwcc/lwcpp$
--- a/Makefile	Fri Jan 13 21:33:55 2012 -0700
+++ b/Makefile	Fri Jan 13 22:32:15 2012 -0700
@@ -43,6 +43,8 @@
 
 lwcc_srcs :=  lwcc.c
 lwcc_srcs := $(addprefix lwcc/,$(lwcc_srcs))
+lwcpp_srcs := lwcpp.c
+lwcpp_srcs := $(addprefix lwcc/cpp/,$(lwcpp_srcs))
 
 lwasm_srcs :=  debug.c input.c insn_bitbit.c insn_gen.c insn_indexed.c \
 	insn_inh.c insn_logicmem.c insn_rel.c insn_rlist.c insn_rtor.c insn_tfm.c \
@@ -57,6 +59,7 @@
 lwlib_objs := $(lwlib_srcs:.c=.o)
 lwobjdump_objs := $(lwobjdump_srcs:.c=.o)
 lwcc_objs := $(lwcc_srcs:.c=.o)
+lwcpp_objs := $(lwcpp_srcs:.c=.o)
 
 lwasm_deps := $(lwasm_srcs:.c=.d)
 lwlink_deps := $(lwlink_srcs:.c=.d)
@@ -64,13 +67,15 @@
 lwlib_deps := $(lwlib_srcs:.c=.d)
 lwobjdump_deps := $(lwobjdump_srcs:.c=.d)
 lwcc_deps := $(lwcc_srcs:.c=.d)
+lwcpp_deps := $(lwcpp_srcs:.c=.d)
 
-.PHONY: lwlink lwasm lwar lwobjdump lwcc
+.PHONY: lwlink lwasm lwar lwobjdump lwcc lwcpp
 lwlink: lwlink/lwlink$(PROGSUFFIX)
 lwasm: lwasm/lwasm$(PROGSUFFIX)
 lwar: lwar/lwar$(PROGSUFFIX)
 lwobjdump: lwlink/lwobjdump$(PROGSUFFIX)
 lwcc: lwcc/lwcc$(PROGSUFFIX)
+lwcpp: lwcc/lwcpp$(PROGSUFFIX)
 
 .PHONY: lwbasic
 lwbasic: lwbasic/lwbasic$(PROGSUFFIX)
@@ -95,6 +100,11 @@
 	@echo Linking $@
 	@$(CC) -o $@ $(lwcc_objs) $(LDFLAGS)
 
+lwcc/lwcpp$(PROGSUFFIX): $(lwcpp_objs) lwlib
+	@echo Linking $@
+	@$(CC) -o $@ $(lwcpp_objs) $(LDFLAGS)
+
+
 #.PHONY: lwlib
 .INTERMEDIATE: lwlib
 lwlib: lwlib/liblw.a
@@ -125,14 +135,14 @@
 clean: $(cleantargs)
 	@echo "Cleaning up"
 	@rm -f lwlib/liblw.a lwasm/lwasm$(PROGSUFFIX) lwlink/lwlink$(PROGSUFFIX) lwlink/lwobjdump$(PROGSUFFIX) lwar/lwar$(PROGSUFFIX) lwcc/lwcc$(PROGSUFFIX)
-	@rm -f $(lwasm_objs) $(lwlink_objs) $(lwar_objs) $(lwlib_objs) $(lwobjdump_objs) $(lwcc_objs)
+	@rm -f $(lwasm_objs) $(lwlink_objs) $(lwar_objs) $(lwlib_objs) $(lwobjdump_objs) $(lwcc_objs) $(lwcpp_objs)
 	@rm -f $(extra_clean)
 	@rm -f */*.exe
 
 .PHONY: realclean
 realclean: clean $(realcleantargs)
 	@echo "Cleaning up even more"
-	@rm -f $(lwasm_deps) $(lwlink_deps) $(lwar_deps) $(lwlib_deps) $(lwobjdump_deps)
+	@rm -f $(lwasm_deps) $(lwlink_deps) $(lwar_deps) $(lwlib_deps) $(lwobjdump_deps) $(lwcc_deps) $(lwcpp_deps)
 	@rm -f docs/manual/*.html docs/manual/*.pdf
 
 print-%:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lwcc/cpp/lwcpp.c	Fri Jan 13 22:32:15 2012 -0700
@@ -0,0 +1,168 @@
+/*
+
+This is the main source for lwcpp, the C preprocessor
+
+Copyright © 2012 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <lw_alloc.h>
+#include <lw_string.h>
+
+/* command line option handling */
+#define PROGVER "lwcpp from " PACKAGE_STRING
+char *program_name;
+
+/* global state */
+char *output_file = NULL;
+int debug_level = 0;
+
+static void do_help(void);
+static void do_usage(void);
+
+/*
+NOTE:
+
+We can't actually use a standard option parser here due to a raft of weird
+command line syntax and we want to be somewhat compatible with various
+other tools. That means we have a built-in help text that is preformatted.
+
+*/
+
+#define OPTARG(dest,src)	do { char *___s = (src); if (!*___s) { if (i < argc) ___s = argv[i++]; else { fprintf(stderr, "Option %s requires an argument\n", arg); } } (dest) = ___s; } while (0)
+static void parse_cmdline(int argc, char **argv)
+{
+	int i = 1;
+	int eargs = 0;
+	char *arg;
+	
+	while (i < argc)
+	{
+		arg = argv[i++];
+		if (!eargs && arg[0] == '-' && arg[1] != 0)
+		{
+			/* we have an option here */
+			if (arg[1] == '-' && arg[2] == 0)
+			{
+				eargs = 1;
+				continue;
+			}
+			
+			/* consume the '-' */
+			arg++;
+			if (!strcmp(arg, "-help") || !strcmp(arg, "?"))
+			{
+				/* --help */
+				do_help();
+				exit(0);
+			}
+			else if (!strcmp(arg, "-usage"))
+			{
+				/* --usage */
+				do_usage();
+				exit(0);
+			}
+			else if (!strcmp(arg, "version") || !strcmp(arg, "-version"))
+			{
+				/* --version */
+				printf("%s\n", PROGVER);
+				exit(0);
+			}
+			
+			switch (*arg)
+			{
+			case 'o':
+				if (output_file)
+					lw_free(output_file);
+				OPTARG(output_file, arg + 1);
+				continue;
+			
+			case 'd':
+				if (!arg[1])
+					debug_level = 50;
+				else
+					debug_level = atoi(arg + 1);
+				continue;
+			}
+			
+			fprintf(stderr, "Unknown option: %s\n", arg);
+		}
+		else
+		{
+			/* we have an input file here */
+			printf("Input file: %s\n", arg);
+		}
+	}
+}
+
+/*
+static struct lw_cmdline_parser cmdline_parser =
+{
+	options,
+	parse_opts,
+	"INPUTFILE",
+	"lwcc, a HD6309 and MC6809 cross-compiler\vPlease report bugs to lost@l-w.ca.",
+	PROGVER
+};
+*/
+int main(int argc, char **argv)
+{
+	program_name = argv[0];
+
+	parse_cmdline(argc, argv);
+
+	if (!output_file)
+	{
+		output_file = lw_strdup("a.out");
+	}
+
+	exit(0);
+}
+
+void do_usage(void)
+{
+	printf(
+		"Usage: %1$s [options] <input file>\n"
+		"       %1$s --help\n"
+		"       %1$s --version\n"
+		"       %1$s --usage\n",
+		program_name
+	);
+}
+
+void do_help(void)
+{
+	printf(
+		"Usage: %s [options] <input file>\n"
+		"lwcpp, the lwtools C preprocessor\n"
+		"\n"
+		"  -d[LEVEL]                   enable debug output, optionally set verbosity\n"
+		"                              level to LEVEL\n"
+		"  -o FILE                     specify the output file name\n"
+		"  -?, --help                  give this help message\n"
+		"  --usage                     print a short usage message\n"
+		"  -version, --version         print program version\n"
+		"\n"
+		"Please report bugs to lost@l-w.ca.\n",
+		program_name
+	);
+}
--- a/lwcc/lwcc.c	Fri Jan 13 21:33:55 2012 -0700
+++ b/lwcc/lwcc.c	Fri Jan 13 22:32:15 2012 -0700
@@ -2,7 +2,7 @@
 
 This is the front-end program for the C compiler.
 
-Copyright © 2011 William Astle
+Copyright © 2012 William Astle
 
 This file is part of LWTOOLS.