Mercurial > hg-old > index.cgi
changeset 46:b962cee20bf4
Ported output modules forward from old version
author | lost |
---|---|
date | Sun, 04 Jan 2009 07:07:00 +0000 |
parents | be459d69f481 |
children | 804d7465e0f9 |
files | src/Makefile.am src/lwasm.h src/main.c src/output.c src/pass1.c |
diffstat | 5 files changed, 27 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile.am Sun Jan 04 06:54:58 2009 +0000 +++ b/src/Makefile.am Sun Jan 04 07:07:00 2009 +0000 @@ -1,3 +1,3 @@ bin_PROGRAMS = lwasm -lwasm_SOURCES = main.c expr.c pass1.c pass2.c util.c instab.c parse.c lwasm.c insn_inh.c insn_rtor.c insn_rlist.c insn_rel.c insn_tfm.c insn_bitbit.c insn_indexed.c insn_gen.c insn_logicmem.c list.c symbol.c +lwasm_SOURCES = main.c expr.c pass1.c pass2.c util.c instab.c parse.c lwasm.c insn_inh.c insn_rtor.c insn_rlist.c insn_rel.c insn_tfm.c insn_bitbit.c insn_indexed.c insn_gen.c insn_logicmem.c list.c symbol.c output.c EXTRA_DIST = instab.h lwasm.h expr.h util.h
--- a/src/lwasm.h Sun Jan 04 06:54:58 2009 +0000 +++ b/src/lwasm.h Sun Jan 04 07:07:00 2009 +0000 @@ -29,7 +29,7 @@ #define OUTPUT_DECB 0 // DECB multirecord format #define OUTPUT_RAW 1 // raw sequence of bytes #define OUTPUT_OBJ 2 // proprietary object file format - +#define OUTPUT_RAWREL 3 // raw bytes where ORG causes a SEEK in the file // structure for tracking errors typedef struct lwasm_error_s lwasm_error_t; @@ -54,6 +54,7 @@ int codelen; // number of bytes emitted int codesize; // the size of the code buffer int codeaddr; // address the code goes at + int nocodelen; // for "RMB" type instructions }; // for keeping track of symbols
--- a/src/main.c Sun Jan 04 06:54:58 2009 +0000 +++ b/src/main.c Sun Jan 04 07:07:00 2009 +0000 @@ -37,6 +37,7 @@ extern void lwasm_pass1(asmstate_t *as); extern void lwasm_pass2(asmstate_t *as); extern void lwasm_list(asmstate_t *as); +extern void lwasm_output(asmstate_t *as); // command line option handling const char *argp_program_version = PACKAGE_STRING; @@ -174,7 +175,7 @@ lwasm_list(&asmstate); // now write the code out to the output file -// lwasm_output(&asmstate); + lwasm_output(&asmstate); if (asmstate.errorcount > 0) exit(1);
--- a/src/output.c Sun Jan 04 06:54:58 2009 +0000 +++ b/src/output.c Sun Jan 04 07:07:00 2009 +0000 @@ -1,6 +1,6 @@ /* output.c -Copyright © 2008 William Astle +Copyright © 2009 William Astle This file is part of LWASM. @@ -35,7 +35,7 @@ void write_code_decb(asmstate_t *as, FILE *of); void write_code_rawrel(asmstate_t *as, FILE *of); -void write_code(asmstate_t *as) +void lwasm_output(asmstate_t *as) { FILE *of; @@ -88,15 +88,15 @@ */ void write_code_rawrel(asmstate_t *as, FILE *of) { - sourceline_t *cl; + lwasm_line_t *cl; - for (cl = as -> source_head; cl; cl = cl -> next) + for (cl = as -> lineshead; cl; cl = cl -> next) { - if (cl -> nocode) + if (cl -> codelen == 0) continue; - fseek(of, cl -> addr, SEEK_SET); - fwrite(cl -> codebytes, cl -> numcodebytes, 1, of); + fseek(of, cl -> codeaddr, SEEK_SET); + fwrite(cl -> bytes, cl -> codelen, 1, of); } } @@ -107,41 +107,39 @@ */ void write_code_raw(asmstate_t *as, FILE *of) { - sourceline_t *cl; + lwasm_line_t *cl; - for (cl = as -> source_head; cl; cl = cl -> next) + for (cl = as -> lineshead; cl; cl = cl -> next) { - if (cl -> nocode && cl -> len > 0) + if (cl -> nocodelen) { int i; - for (i = 0; i < cl -> len; i++) + for (i = 0; i < cl -> nocodelen; i++) fwrite("\0", 1, 1, of); continue; } - if (cl -> nocode) - continue; - - fwrite(cl -> codebytes, cl -> numcodebytes, 1, of); + fwrite(cl -> bytes, cl -> codelen, 1, of); } } void write_code_decb(asmstate_t *as, FILE *of) { long preambloc; - sourceline_t *cl; + lwasm_line_t *cl; int blocklen = -1; int nextcalc = -1; unsigned char outbuf[5]; - for (cl = as -> source_head; cl; cl = cl -> next) + for (cl = as -> lineshead; cl; cl = cl -> next) { - if (cl -> nocode) + if (cl -> nocodelen) continue; - if (cl -> addr != nextcalc && cl -> numcodebytes > 0) + if (cl -> codeaddr != nextcalc && cl -> codelen > 0) { // need preamble here if (blocklen > 0) { + // update previous preamble if needed fseek(of, preambloc, SEEK_SET); outbuf[0] = (blocklen >> 8) & 0xFF; outbuf[1] = blocklen & 0xFF; @@ -149,7 +147,7 @@ fseek(of, 0, SEEK_END); } blocklen = 0; - nextcalc = cl -> addr; + nextcalc = cl -> codeaddr; outbuf[0] = 0x00; outbuf[1] = 0x00; outbuf[2] = 0x00; @@ -158,9 +156,9 @@ preambloc = ftell(of) + 1; fwrite(outbuf, 5, 1, of); } - nextcalc += cl -> numcodebytes; - fwrite(cl -> codebytes, cl -> numcodebytes, 1, of); - blocklen += cl -> numcodebytes; + nextcalc += cl -> codelen; + fwrite(cl -> bytes, cl -> codelen, 1, of); + blocklen += cl -> codelen; } if (blocklen > 0) {