Mercurial > hg-old > index.cgi
changeset 370:6b33faa21a0a
Debugging output and bugfixing pass 0
author | lost@starbug |
---|---|
date | Tue, 20 Apr 2010 21:59:58 -0600 |
parents | 898a41f7eb59 |
children | 9c24d9d485b9 |
files | lwasm/Makefile.am lwasm/debug.c lwasm/main.c lwasm/pass1.c lwasm/pseudo.c lwasm/symbol.c lwlib/lw_expr.c lwlib/lw_expr.h |
diffstat | 8 files changed, 128 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/lwasm/Makefile.am Thu Apr 15 22:26:49 2010 -0600 +++ b/lwasm/Makefile.am Tue Apr 20 21:59:58 2010 -0600 @@ -4,6 +4,6 @@ instab.c symbol.c macro.c pass2.c pass3.c pass4.c pass5.c pass6.c \ insn_inh.c insn_rtor.c insn_tfm.c insn_rlist.c insn_rel.c \ insn_bitbit.c insn_indexed.c insn_gen.c insn_logicmem.c \ - pseudo.c section.c os9.c pass7.c + pseudo.c section.c os9.c pass7.c debug.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 input.h instab.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lwasm/debug.c Tue Apr 20 21:59:58 2010 -0600 @@ -0,0 +1,80 @@ +/* +debug.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 <stdio.h> +#include <string.h> + +#include "lwasm.h" +#include "instab.h" + +/* + +Various debug utilities + +*/ +void dump_state(asmstate_t *as, FILE *fp) +{ + line_t *cl; + exportlist_t *ex; + struct symtabe *s; + importlist_t *im; + struct line_expr_s *le; + lwasm_error_t *e; + + fprintf(fp, "Lines:\n"); + + for (cl = as -> line_head; cl; cl = cl -> next) + { + fprintf(fp, "%p ", cl); + if (cl -> insn >= 0) + { + fprintf(fp, "INSN %d (%s) ", cl -> insn, instab[cl -> insn].opcode); + fprintf(fp, "LEN %d ", cl -> len); + } + fprintf(fp, "\n ADDR:"); + lw_expr_print(cl -> addr, fp); + for (le = cl -> exprs; le; le = le -> next) + { + fprintf(fp, "\n EXPR %d:", le -> id); + lw_expr_print(le -> expr, fp); + } + if (cl -> outputl > 0) + { + int i; + fprintf(fp, "\n OUTPUT:"); + for (i = 0; i < cl -> outputl; i++) + { + fprintf(fp, "%02X", cl -> output[i]); + } + } + for (e = cl -> err; e; e = e -> next) + { + fprintf(fp, "\n ERR: %s", e -> mess); + } + for (e = cl -> warn; e; e = e -> next) + { + fprintf(fp, "\n WARN: %s", e -> mess); + } + fprintf(fp, "\n"); + } +}
--- a/lwasm/main.c Thu Apr 15 22:26:49 2010 -0600 +++ b/lwasm/main.c Tue Apr 20 21:59:58 2010 -0600 @@ -190,6 +190,8 @@ { NULL, NULL } }; +extern void dump_state(asmstate_t *as, FILE *fp); + int main(int argc, char **argv) { int passnum; @@ -200,6 +202,7 @@ lw_expr_set_special_handler(lwasm_evaluate_special); lw_expr_set_var_handler(lwasm_evaluate_var); + lw_expr_set_term_parser(lwasm_parse_term); /* initialize assembler state */ asmstate.include_list = lw_stringlist_create(); @@ -220,6 +223,8 @@ { fprintf(stderr, "Doing pass %d (%s)\n", passnum, passlist[passnum].passname); (passlist[passnum].fn)(&asmstate); + fprintf(stderr, "After pass %d (%s):\n", passnum, passlist[passnum].passname); + dump_state(&asmstate, stderr); if (asmstate.errorcount > 0) {
--- a/lwasm/pass1.c Thu Apr 15 22:26:49 2010 -0600 +++ b/lwasm/pass1.c Tue Apr 20 21:59:58 2010 -0600 @@ -179,8 +179,8 @@ for (tok = p1; *p1 && !isspace(*p1); p1++) /* do nothing */ ; } - - cl -> sym = sym; + if (sym) + cl -> sym = lw_strdup(sym); cl -> symset = 0; // tok points to the opcode for the line or NUL if none @@ -188,7 +188,7 @@ { // look up operation code sym = lw_strndup(tok, p1 - tok); - for (; *p1 && isspace(p1); p1++) + for (; *p1 && isspace(*p1); p1++) /* do nothing */ ; for (opnum = 0; instab[opnum].opcode; opnum++) @@ -252,19 +252,19 @@ { if (cl -> sym && cl -> symset == 0) { - printf("Register symbol %s:", sym); - lw_expr_print(cl -> addr); + printf("Register symbol %s:", cl -> sym); + lw_expr_print(cl -> addr, stderr); printf("\n"); // register symbol at line address if (!register_symbol(as, cl, cl -> sym, cl -> addr, symbol_flag_none)) { // symbol error - lwasm_register_error(as, cl, "Bad symbol '%s'", cl -> sym); + // lwasm_register_error(as, cl, "Bad symbol '%s'", cl -> sym); } } - lw_expr_print(cl -> addr); + lw_expr_print(cl -> addr, stderr); printf("\n"); }
--- a/lwasm/pseudo.c Thu Apr 15 22:26:49 2010 -0600 +++ b/lwasm/pseudo.c Tue Apr 20 21:59:58 2010 -0600 @@ -35,6 +35,7 @@ lw_expr_t addr; as -> endseen = 1; + l -> len = 0; if (as -> output_format != OUTPUT_DECB) { @@ -42,7 +43,14 @@ return; } - addr = lwasm_parse_expr(as, p); + if (!**p) + { + addr = lw_expr_build(lw_expr_type_int, 0); + } + else + { + addr = lwasm_parse_expr(as, p); + } if (!addr) { lwasm_register_error(as, l, "Bad expression");
--- a/lwasm/symbol.c Thu Apr 15 22:26:49 2010 -0600 +++ b/lwasm/symbol.c Tue Apr 20 21:59:58 2010 -0600 @@ -26,6 +26,7 @@ #include <lw_alloc.h> #include <lw_expr.h> +#include <lw_string.h> #include "lwasm.h" @@ -106,6 +107,7 @@ se -> version = version; se -> flags = flags; se -> value = lw_expr_copy(val); + se -> symbol = lw_strdup(sym); return se; }
--- a/lwlib/lw_expr.c Thu Apr 15 22:26:49 2010 -0600 +++ b/lwlib/lw_expr.c Tue Apr 20 21:59:58 2010 -0600 @@ -192,7 +192,7 @@ return r; } -void lw_expr_print(lw_expr_t E) +void lw_expr_print(lw_expr_t E, FILE *fp) { struct lw_expr_opers *o; int c = 0; @@ -200,86 +200,86 @@ for (o = E -> operands; o; o = o -> next) { c++; - lw_expr_print(o -> p); + lw_expr_print(o -> p, fp); } switch (E -> type) { case lw_expr_type_int: - printf("%d ", E -> value); + fprintf(fp, "%d ", E -> value); break; case lw_expr_type_var: - printf("V(%s) ", (char *)(E -> value2)); + fprintf(fp, "V(%s) ", (char *)(E -> value2)); break; case lw_expr_type_special: - printf("S(%d,%p) ", E -> value, E -> value2); + fprintf(fp, "S(%d,%p) ", E -> value, E -> value2); break; case lw_expr_type_oper: - printf("[%d]", c); + fprintf(fp, "[%d]", c); switch (E -> value) { case lw_expr_oper_plus: - printf("+ "); + fprintf(fp, "+ "); break; case lw_expr_oper_minus: - printf("- "); + fprintf(fp, "- "); break; case lw_expr_oper_times: - printf("* "); + fprintf(fp, "* "); break; case lw_expr_oper_divide: - printf("/ "); + fprintf(fp, "/ "); break; case lw_expr_oper_mod: - printf("%% "); + fprintf(fp, "%% "); break; case lw_expr_oper_intdiv: - printf("\\ "); + fprintf(fp, "\\ "); break; case lw_expr_oper_bwand: - printf("BWAND "); + fprintf(fp, "BWAND "); break; case lw_expr_oper_bwor: - printf("BWOR "); + fprintf(fp, "BWOR "); break; case lw_expr_oper_bwxor: - printf("BWXOR "); + fprintf(fp, "BWXOR "); break; case lw_expr_oper_and: - printf("AND "); + fprintf(fp, "AND "); break; case lw_expr_oper_or: - printf("OR "); + fprintf(fp, "OR "); break; case lw_expr_oper_neg: - printf("NEG "); + fprintf(fp, "NEG "); break; case lw_expr_oper_com: - printf("COM "); + fprintf(fp, "COM "); break; default: - printf("OPER "); + fprintf(fp, "OPER "); break; } break; default: - printf("ERR "); + fprintf(fp, "ERR "); break; } } @@ -783,7 +783,7 @@ if (!**p || isspace(**p) || **p == ')' || **p == ',' || **p == ']') return NULL; - + term1 = lw_expr_parse_term(p, priv); if (!term1) return NULL;
--- a/lwlib/lw_expr.h Thu Apr 15 22:26:49 2010 -0600 +++ b/lwlib/lw_expr.h Tue Apr 20 21:59:58 2010 -0600 @@ -22,6 +22,7 @@ #ifndef ___lw_expr_h_seen___ #define ___lw_expr_h_seen___ +#include <stdio.h> enum { @@ -81,7 +82,7 @@ extern lw_expr_t lw_expr_copy(lw_expr_t E); extern void lw_expr_add_operand(lw_expr_t E, lw_expr_t O); extern lw_expr_t lw_expr_build(int exprtype, ...); -extern void lw_expr_print(lw_expr_t E); +extern void lw_expr_print(lw_expr_t E, FILE *fp); extern int lw_expr_compare(lw_expr_t E1, lw_expr_t E2); extern void lw_expr_simplify(lw_expr_t E, void *priv);