Mercurial > hg > index.cgi
changeset 222:03f7192fcd20
Add --unicorns option for IDE integration
This version of unicorns adds RESOURCE: lines to the output which specify
files and macros discovered during the assembly process.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 15 Jul 2012 10:50:46 -0600 |
parents | 2b784a28428e |
children | 211fc8038b8d |
files | Makefile lwasm/lwasm.h lwasm/macro.c lwasm/main.c lwasm/unicorns.c |
diffstat | 5 files changed, 80 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Sun Jul 15 10:27:43 2012 -0600 +++ b/Makefile Sun Jul 15 10:50:46 2012 -0600 @@ -50,7 +50,7 @@ insn_inh.c insn_logicmem.c insn_rel.c insn_rlist.c insn_rtor.c insn_tfm.c \ instab.c list.c lwasm.c macro.c main.c os9.c output.c pass1.c pass2.c \ pass3.c pass4.c pass5.c pass6.c pass7.c pragma.c pseudo.c section.c \ - struct.c symbol.c + struct.c symbol.c unicorns.c lwasm_srcs := $(addprefix lwasm/,$(lwasm_srcs)) lwasm_objs := $(lwasm_srcs:.c=.o)
--- a/lwasm/lwasm.h Sun Jul 15 10:27:43 2012 -0600 +++ b/lwasm/lwasm.h Sun Jul 15 10:50:46 2012 -0600 @@ -68,6 +68,7 @@ FLAG_DEPEND = 0x0002, FLAG_SYMBOLS = 0x004, FLAG_DEPENDNOERR = 0x0008, + FLAG_UNICORNS = 0x0010, FLAG_NONE = 0 }; @@ -227,6 +228,7 @@ int numlines; // number lines in macro int flags; // flags for the macro macrotab_t *next; // next macro in list + line_t *definedat; // the line where the macro definition starts }; enum
--- a/lwasm/macro.c Sun Jul 15 10:27:43 2012 -0600 +++ b/lwasm/macro.c Sun Jul 15 10:50:46 2012 -0600 @@ -75,6 +75,7 @@ m -> lines = NULL; m -> numlines = 0; m -> flags = 0; + m -> definedat = l; as -> macros = m; t = *p;
--- a/lwasm/main.c Sun Jul 15 10:27:43 2012 -0600 +++ b/lwasm/main.c Sun Jul 15 10:50:46 2012 -0600 @@ -32,6 +32,8 @@ #include "lwasm.h" #include "input.h" +extern void lwasm_do_unicorns(asmstate_t *as); + extern int parse_pragma_string(asmstate_t *as, char *str, int ignoreerr); /* command line option handling */ @@ -56,6 +58,7 @@ { "includedir", 'I', "PATH", 0, "Add entry to include path" }, { "define", 'D', "SYM[=VAL]", 0, "Automatically define SYM to be VAL (or 1)"}, { "preprocess", 'P', 0, 0, "Preprocess macros and conditionals and output revised source to stdout" }, + { "unicorns", 0x4242, 0, 0, "Add sooper sekrit sauce"}, { 0 } }; @@ -137,6 +140,10 @@ case 0x102: as -> flags |= FLAG_DEPEND | FLAG_DEPENDNOERR; break; + + case 0x4242: + as -> flags |= FLAG_UNICORNS; + break; case 'f': if (!strcasecmp(arg, "decb")) @@ -284,6 +291,7 @@ // stop processing immediately break; } + lwasm_do_unicorns(&asmstate); lwasm_show_errors(&asmstate); exit(1); } @@ -291,13 +299,16 @@ if (asmstate.flags & FLAG_DEPEND) { - // output dependencies (other than "includebin") - char *n; + if ((asmstate.flags & FLAG_UNICORNS) == 0) + { + // output dependencies (other than "includebin") + char *n; - while ((n = lw_stack_pop(asmstate.includelist))) - { - fprintf(stdout, "%s\n", n); - lw_free(n); + while ((n = lw_stack_pop(asmstate.includelist))) + { + fprintf(stdout, "%s\n", n); + lw_free(n); + } } } else @@ -307,8 +318,14 @@ } debug_message(&asmstate, 50, "Done assembly"); - - do_list(&asmstate); - + + if (asmstate.flags & FLAG_UNICORNS) + { + lwasm_do_unicorns(&asmstate); + } + else + { + do_list(&asmstate); + } exit(0); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lwasm/unicorns.c Sun Jul 15 10:50:46 2012 -0600 @@ -0,0 +1,50 @@ +/* +unicorns.c + +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/>. +*/ + +/* +This adds output to lwasm that is suitable for IDEs and other tools +that are interesting in the doings of the assembler. +*/ + +#include <stdio.h> +#include <string.h> + +#include "lwasm.h" +#include "lw_alloc.h" + +void lwasm_do_unicorns(asmstate_t *as) +{ + char *n; + macrotab_t *me; + + /* output file list */ + while ((n = lw_stack_pop(as -> includelist))) + { + fprintf(stdout, "RESOURCE: file:%s\n", n); + lw_free(n); + } + + /* output macro list */ + for (me = as -> macros; me; me = me -> next) + { + fprintf(stdout, "RESOURCE: macro:%s,%d,%s\n", me -> name, me -> definedat -> lineno, me -> definedat -> linespec); + } +}