# HG changeset patch # User lost # Date 1232161164 0 # Node ID 41ff4686b46b0fc8e429197a69a64d1f5cc1bc3a # Parent 033a328a10ae26802772053023e7dac21fc1bab9 Checkpoint: object format output diff -r 033a328a10ae -r 41ff4686b46b src/output.c --- a/src/output.c Fri Jan 16 05:33:40 2009 +0000 +++ b/src/output.c Sat Jan 17 02:59:24 2009 +0000 @@ -201,10 +201,13 @@ void write_code_obj(asmstate_t *as, FILE *of) { lwasm_line_t *l; + sectiontab_t *s; int i; + unsigned char buf[16]; // output the magic number and file header - writebytes("LWOBJ16\0", 8, 1, of); + // the 8 is NOT an error + writebytes("LWOBJ16", 8, 1, of); // run through the entire system and build the byte streams for each // section; at the same time, generate a list of "local" symbols to @@ -253,4 +256,35 @@ } } } + + // run through the sections + for (s = as -> sections; s; s = s -> next) + { + // write the name + writebytes(s -> name, strlen(s -> name) + 1, 1, of); + + // write the flags + if (s -> flags & SECTION_BSS) + writebytes("\x01", 1, 1, of); + + // indicate end of flags - the "" is NOT an error + writebytes("", 1, 1, of); + + + // now blast out the code + + // length + buf[0] = s -> oblen >> 8 & 0xff; + buf[1] = s -> oblen & 0xff; + writebytes(buf, 2, 1, of); + + if (!(s -> flags & SECTION_BSS)) + { + writebytes(s -> obytes, s -> oblen, 1, of); + } + } + + // flag no more sections + // the "" is NOT an error + writebytes("", 1, 1, of); }