# HG changeset patch # User William Astle # Date 1342371046 21600 # Node ID 03f7192fcd204abf96067d4d3c6cae4b8b91dc71 # Parent 2b784a28428eeb719fc1b104c0c3ab4ea842deaa 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. diff -r 2b784a28428e -r 03f7192fcd20 Makefile --- 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) diff -r 2b784a28428e -r 03f7192fcd20 lwasm/lwasm.h --- 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 diff -r 2b784a28428e -r 03f7192fcd20 lwasm/macro.c --- 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; diff -r 2b784a28428e -r 03f7192fcd20 lwasm/main.c --- 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); } diff -r 2b784a28428e -r 03f7192fcd20 lwasm/unicorns.c --- /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 . +*/ + +/* +This adds output to lwasm that is suitable for IDEs and other tools +that are interesting in the doings of the assembler. +*/ + +#include +#include + +#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); + } +}