Mercurial > hg > index.cgi
changeset 223:211fc8038b8d
More unicorn stuff - structs and macros
Settled on an output format for unicorn stuff and added structs and macros
to that output. Format is:
TYPE: <key>=<value>[,<key>=<value>]*
Any <value> which has special characters will use urlencoding. Values with
multiple values use a semicolon as a separator.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 15 Jul 2012 20:14:51 -0600 |
parents | 03f7192fcd20 |
children | 3864d96ee8c7 |
files | lwasm/lwasm.h lwasm/struct.c lwasm/unicorns.c |
diffstat | 3 files changed, 46 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/lwasm/lwasm.h Sun Jul 15 10:50:46 2012 -0600 +++ b/lwasm/lwasm.h Sun Jul 15 20:14:51 2012 -0600 @@ -253,6 +253,7 @@ int size; // number of bytes taken by struct structtab_field_t *fields; // fields in the structure structtab_t *next; // next structure + line_t *definedat; // line where structure is defined }; struct asmstate_s
--- a/lwasm/struct.c Sun Jul 15 10:50:46 2012 -0600 +++ b/lwasm/struct.c Sun Jul 15 20:14:51 2012 -0600 @@ -63,6 +63,7 @@ s -> next = as -> structs; s -> fields = NULL; s -> size = 0; + s -> definedat = l; as -> structs = s; as -> cstruct = s;
--- a/lwasm/unicorns.c Sun Jul 15 10:50:46 2012 -0600 +++ b/lwasm/unicorns.c Sun Jul 15 20:14:51 2012 -0600 @@ -30,21 +30,61 @@ #include "lwasm.h" #include "lw_alloc.h" +static void print_urlencoding(FILE *stream, const char *string) +{ + for ( ; *string; string++) + { + if (*string < 33 || *string > 126 || strchr("$&+,/:;=?@\"<>#%{}|\\^~[]`", *string)) + { + fprintf(stream, "%%%02X", *string); + } + else + { + fputc(*string, stream); + } + } +} + void lwasm_do_unicorns(asmstate_t *as) { char *n; macrotab_t *me; - + structtab_t *se; + int i; + /* output file list */ while ((n = lw_stack_pop(as -> includelist))) { - fprintf(stdout, "RESOURCE: file:%s\n", n); - lw_free(n); + fputs("RESOURCE: type=file,filename=", stdout); + print_urlencoding(stdout, n); + fputc('\n', stdout); + lw_free(n); } /* output macro list */ for (me = as -> macros; me; me = me -> next) { - fprintf(stdout, "RESOURCE: macro:%s,%d,%s\n", me -> name, me -> definedat -> lineno, me -> definedat -> linespec); + fprintf(stdout, "RESOURCE: type=macro,name=%s,lineno=%d,filename=", me -> name, me -> definedat -> lineno); + print_urlencoding(stdout, me -> definedat -> linespec); + fputs(",flags=", stdout); + if (me -> flags & macro_noexpand) + fputs("noexpand", stdout); + fputs(",def=", stdout); + for (i = 0; i < me -> numlines; i++) + { + if (i) + fputc(';', stdout); + print_urlencoding(stdout, me -> lines[i]); + } + fputc('\n', stdout); } + + /* output structure list */ + for (se = as -> structs; se; se = se -> next) + { + fprintf(stdout, "RESOURCE: type=struct,name=%s,lineno=%d,filename=", se -> name, se -> definedat -> lineno); + print_urlencoding(stdout, se -> definedat -> linespec); + fputc('\n', stdout); + } + }