# HG changeset patch # User lost # Date 1244762955 0 # Node ID 058f181190256866c44530588b80e87e1e8353f8 # Parent 2e5a32d56e603c42996c452737547c7786fe7248 Fixed filename parsing bug in include directive and added includebin directive diff -r 2e5a32d56e60 -r 058f18119025 ChangeLog --- a/ChangeLog Thu Jun 11 23:12:31 2009 +0000 +++ b/ChangeLog Thu Jun 11 23:29:15 2009 +0000 @@ -14,6 +14,9 @@ Version 2.5 [!] Fixed error in the fix for invalid operands included in 2.4 [LWASM] +[b] Fixed bug with "include" directive operand parsing [LWASM] +[+] Added includebin directive to include the literal contents of a binary + file at the current assembly address. [LWASM] Version 2.4 diff -r 2e5a32d56e60 -r 058f18119025 lwasm/instab.c --- a/lwasm/instab.c Thu Jun 11 23:12:31 2009 +0000 +++ b/lwasm/instab.c Thu Jun 11 23:29:15 2009 +0000 @@ -80,6 +80,7 @@ extern OPFUNC(pseudo_ifdef); extern OPFUNC(pseudo_ifndef); extern OPFUNC(pseudo_noop); +extern OPFUNC(pseudo_includebin); instab_t instab[] = { @@ -351,6 +352,7 @@ { "end", { -1, -1, -1, -1 }, pseudo_end }, + { "includebin", { -1, -1, -1, -1}, pseudo_includebin }, { "include", { -1, -1, -1, -1 }, pseudo_include }, { "align", { -1, -1, -1, -1 }, pseudo_align }, diff -r 2e5a32d56e60 -r 058f18119025 lwasm/pseudo.c --- a/lwasm/pseudo.c Thu Jun 11 23:12:31 2009 +0000 +++ b/lwasm/pseudo.c Thu Jun 11 23:29:15 2009 +0000 @@ -21,6 +21,8 @@ This file implements the various pseudo operations. */ #include +#include +#include #include #include #include "lwasm.h" @@ -117,6 +119,10 @@ memcpy(fn, *p, v1); fn[v1] = '\0'; + (*p) += v1; + if (**p == '"') + (*p)++; + // end local label context on include as -> context = lwasm_next_context(as); if (lwasm_read_file(as, fn) < 0) @@ -126,6 +132,75 @@ lwasm_free(fn); } +/* +The operand for includebin is a string optionally enclosed in " +*/ +OPFUNC(pseudo_includebin) +{ + int v1; + char *fn; + FILE *f; + + // only include files on pass 1 + while (**p && isspace(**p)) + (*p)++; + + if (!**p) + { + register_error(as, l, 1, "Bad file name"); + return; + } + + if (**p == '"') + { + // search for ending " + (*p)++; + for (v1 = 0; *((*p)+v1) && *((*p)+v1) != '"'; v1++) + /* do nothing */ ; + if (*((*p)+v1) != '"') + { + register_error(as, l, 1, "Bad file name"); + return; + } + } + else + { + // search for a space type character + for (v1 = 0; *((*p)+v1) && !isspace(*((*p)+v1)); v1++) + ; + } + + fn = lwasm_alloc(v1 + 1); + memcpy(fn, *p, v1); + fn[v1] = '\0'; + + (*p) += v1; + if (**p == '"') + (*p)++; + + // open the file + f = fopen(fn, "rb"); + if (!f) + { + register_error(as, l, 1, "Cannot open file: %s", strerror(errno)); + register_error(as, l, 2, "Cannot open file: %s", strerror(errno)); + } + + // don't need fn any more + lwasm_free(fn); + + // read the contents of the file and "emit()" it + while (!feof(f) && !ferror(f)) + { + v1 = fgetc(f); + if (v1 == EOF) + break; + lwasm_emit(as, l, v1); + } + // close file + fclose(f); +} + OPFUNC(pseudo_rmb) { int r, v;