# HG changeset patch # User lost # Date 1231049593 0 # Node ID 4bb7b723e5b795b564c93c72736521931bd8e44a # Parent 7eafdb3a8074880ac2fbf37b45283d4c65638983 Added pass2 code generation to lwasm_emit() diff -r 7eafdb3a8074 -r 4bb7b723e5b7 src/lwasm.c --- a/src/lwasm.c Sat Jan 03 19:50:30 2009 +0000 +++ b/src/lwasm.c Sun Jan 04 06:13:13 2009 +0000 @@ -67,7 +67,14 @@ if (as -> passnum == 1) return; - fprintf(stderr, "FIXME: trying to emit code in pass 2 but not implemented.\n"); + + if (l -> codelen >= l -> codesize) + { + l -> bytes = realloc(l -> bytes, l -> codesize + 16); + l -> codesize += 16; + } + l -> bytes[l -> codelen] = b & 0xff; + l -> codelen += 1; } void lwasm_emitop(asmstate_t *as, lwasm_line_t *l, int o) diff -r 7eafdb3a8074 -r 4bb7b723e5b7 src/lwasm.h --- a/src/lwasm.h Sat Jan 03 19:50:30 2009 +0000 +++ b/src/lwasm.h Sun Jan 04 06:13:13 2009 +0000 @@ -50,6 +50,9 @@ lwasm_error_t *err; // error messages int fsize; // forced size (0 = no forced size) char *sym; // scratch area to record the presence of a symbol + unsigned char *bytes; // actual bytes emitted + int codelen; // number of bytes emitted + int codesize; // the size of the code buffer }; // for keeping track of symbols diff -r 7eafdb3a8074 -r 4bb7b723e5b7 src/pass1.c --- a/src/pass1.c Sat Jan 03 19:50:30 2009 +0000 +++ b/src/pass1.c Sun Jan 04 06:13:13 2009 +0000 @@ -136,6 +136,9 @@ nl -> err = NULL; nl -> fsize = 0; nl -> sym = NULL; + nl -> bytes = NULL; + nl -> codelen = 0; + nl -> codesize = 0; if (as -> linestail) as -> linestail -> next = nl; else