Mercurial > hg-old > index.cgi
changeset 323:473ed9b353eb
Started framework for lwasm binary
author | lost |
---|---|
date | Tue, 09 Feb 2010 05:33:35 +0000 |
parents | 3ff493a445ed |
children | be63116281b0 |
files | Makefile.am configure.ac lwasm/Makefile.am lwasm/lwasm.h lwasm/main.c |
diffstat | 5 files changed, 197 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.am Tue Feb 09 04:41:08 2010 +0000 +++ b/Makefile.am Tue Feb 09 05:33:35 2010 +0000 @@ -1,4 +1,4 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = lib -DIST_SUBDIRS = lib +SUBDIRS = lib lwasm +DIST_SUBDIRS = lib lwasm EXTRA_DIST = m4/gnulib-cache.m4
--- a/configure.ac Tue Feb 09 04:41:08 2010 +0000 +++ b/configure.ac Tue Feb 09 05:33:35 2010 +0000 @@ -8,5 +8,6 @@ AC_CONFIG_FILES([ Makefile lib/Makefile + lwasm/Makefile ]) AC_OUTPUT
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lwasm/Makefile.am Tue Feb 09 05:33:35 2010 +0000 @@ -0,0 +1,5 @@ +AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib +bin_PROGRAMS = lwasm +lwasm_SOURCES = main.c +lwasm_LDADD = -L$(top_builddir)/lib -L$(top_srcdir)/lib -lgnu +EXTRA_DIST = lwasm.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lwasm/lwasm.h Tue Feb 09 05:33:35 2010 +0000 @@ -0,0 +1,47 @@ +/* +lwasm.h + +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/>. +*/ + +#ifndef ___lwasm_h_seen___ +#define ___lwasm_h_seen___ + +enum lwasm_output_e +{ + OUTPUT_DECB = 0, // DECB multirecord format + OUTPUT_RAW, // raw sequence of bytes + OUTPUT_OBJ, // proprietary object file format + OUTPUT_RAWREL, // raw bytes where ORG causes a SEEK in the file + OUTPUT_OS9 // os9 module target +}; + +enum lwasm_target_e +{ + TARGET_6309 = 0, // target 6309 CPU + TARGET_6809 // target 6809 CPU (no 6309 ops) +}; + +typedef struct +{ + int output_format; // output format + int target; // assembly target + int debug_level; // level of debugging requested +} asmstate_t; + +#endif /* ___lwasm_h_seen___ */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lwasm/main.c Tue Feb 09 05:33:35 2010 +0000 @@ -0,0 +1,142 @@ +/* +main.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 <argp.h> +#include <stdio.h> +#include <stdlib.h> + +#include "lwasm.h" + +/* command line option handling */ +const char *argp_program_version = "lwasm from " PACKAGE_STRING; +const char *argp_program_bug_address = PACKAGE_BUGREPORT; +char *program_name; + +static struct argp_option options[] = +{ + { "output", 'o', "FILE", 0, "Output to FILE"}, + { "debug", 'd', 0, 0, "Set debug mode"}, + { "format", 'f', "TYPE", 0, "Select output format: decb, raw, obj, os9"}, + { "list", 'l', "FILE", OPTION_ARG_OPTIONAL, "Generate list [to FILE]"}, + { "decb", 'b', 0, 0, "Generate DECB .bin format output, equivalent of --format=decb"}, + { "raw", 'r', 0, 0, "Generate raw binary format output, equivalent of --format=raw"}, + { "obj", 0x100, 0, 0, "Generate proprietary object file format for later linking, equivalent of --format=obj" }, + { "depend", 0x101, 0, 0, "Output a dependency list to stdout; do not do any actual output though assembly is completed as usual" }, + { "pragma", 'p', "PRAGMA", 0, "Set an assembler pragma to any value understood by the \"pragma\" pseudo op"}, + { "6809", '9', 0, 0, "Set assembler to 6809 only mode" }, + { "6309", '3', 0, 0, "Set assembler to 6309 mode (default)" }, + { "includedir", 'I', "PATH", 0, "Add entry to include path" }, + { 0 } +}; + + +static error_t parse_opts(int key, char *arg, struct argp_state *state) +{ + asmstate_t *as = state -> input; + + switch (key) + { + case 'I': + case 'o': + case 'd': + as -> debug_level++; + break; + + case 'l': + + case 'b': + as -> output_format = OUTPUT_DECB; + break; + + case 'r': + as -> output_format = OUTPUT_RAW; + break; + + case 0x100: + as -> output_format = OUTPUT_OBJ; + break; + + case 0x101: + case 'f': + if (!strcasecmp(arg, "decb")) + as -> output_format = OUTPUT_DECB; + else if (!strcasecmp(arg, "raw")) + as -> output_format = OUTPUT_RAW; + else if (!strcasecmp(arg, "obj")) + as -> output_format = OUTPUT_OBJ; + else if (!strcasecmp(arg, "os9")) + { + //as -> pragmas |= PRAGMA_DOLLARNOTLOCAL; + as -> output_format = OUTPUT_OS9; + } + else + { + fprintf(stderr, "Invalid output format: %s\n", arg); + exit(1); + } + break; + + case 'p': + case '9': + as -> target = TARGET_6809; + break; + + case '3': + as -> target = TARGET_6309; + break; + + case ARGP_KEY_END: + break; + + case ARGP_KEY_ARG: + break; + + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +static struct argp argp = +{ + options, + parse_opts, + "<input file>", + "LWASM, a HD6309 and MC6809 cross-assembler" +}; + +/* +main function; parse command line, set up assembler state, and run the +assembler on the first file +*/ +int main(int argc, char **argv) +{ + /* assembler state */ + asmstate_t asmstate = { 0 }; + + program_name = argv[0]; + + argp_parse(&argp, argc, argv, 0, 0, &asmstate); + + exit(0); +}