# HG changeset patch # User lost # Date 1231378369 0 # Node ID 92eb93bffa2810b1cd4ddf623dff428f23607482 # Parent c8c772ef5df90ce378d8b3a5b19ed9ca29ab9489 Rejigged symbol system to be able to handle non-constant references diff -r c8c772ef5df9 -r 92eb93bffa28 src/lwasm.h --- a/src/lwasm.h Thu Jan 08 01:18:40 2009 +0000 +++ b/src/lwasm.h Thu Jan 08 01:32:49 2009 +0000 @@ -85,19 +85,22 @@ // references, and intrasection relocations int relocoff; // offset into insn where relocation value goes // the incomplete reference expression - struct lwasm_expr_strack_t *expr; + lwasm_expr_stack_t *expr; }; // for keeping track of symbols -#define SYMBOL_SET 1 // the symbol was used for "SET" -#define SYMBOL_NORM 0 // no flags +#define SYMBOL_SET 1 // the symbol was used for "SET" +#define SYMBOL_COMPLEX 2 // register symbol as a complex symbol (from l -> expr) +#define SYMBOL_NORM 0 // no flags typedef struct lwasm_symbol_ent_s lwasm_symbol_ent_t; struct lwasm_symbol_ent_s { - char *sym; // the symbol - int context; // the context number of the symbol (-1 for global) - int value; // the value of the symbol - int flags; // flags for the symbol + char *sym; // the symbol + int context; // the context number of the symbol (-1 for global) + int value; // the value of the symbol + int flags; // flags for the symbol + sectiontab_t *sect; // the section the symbol exists in; NULL for none + lwasm_expr_stack_t *expr; // expression for a symbol that is not constant NULL for const lwasm_symbol_ent_t *next; // next symbol in the table lwasm_symbol_ent_t *prev; // previous symbol in the table }; diff -r c8c772ef5df9 -r 92eb93bffa28 src/symbol.c --- a/src/symbol.c Thu Jan 08 01:18:40 2009 +0000 +++ b/src/symbol.c Thu Jan 08 01:32:49 2009 +0000 @@ -28,6 +28,7 @@ #include "lwasm.h" #include "util.h" +#include "expr.h" /* Note that this function may accept symbols that the expression evaluator doesn't @@ -41,6 +42,16 @@ int scontext = -1; + // if the symbol is constant, fall back to simple registration! + if (flags & SYMBOL_COMPLEX) + { + if (lwasm_expr_is_constant(l -> expr)) + { + val = lwasm_expr_get_value(l -> expr); + flags &= ~SYMBOL_COMPLEX; + } + } + // first check if the symbol is valid // the following characters are allowed in a symbol: // [a-zA-Z0-9._$?@] and any byte value larger than 0x7F @@ -85,6 +96,10 @@ if (se) { se -> value = val; + if (flags & SYMBOL_COMPLEX) + { + se -> expr = l -> expr; + } return; } @@ -105,8 +120,12 @@ as -> symtail = se; } se -> value = val; + if (flags & SYMBOL_COMPLEX) + se -> expr = l -> expr; se -> sym = lwasm_strdup(sym); se -> context = scontext; + se -> sect = as -> csect; + se -> expr = NULL; se -> flags = flags; return 0; @@ -147,7 +166,11 @@ for (se = as -> symhead; se; se = se -> next) { - if (se -> value > 0xffff || se -> value < -0x8000) + if (se -> expr) + { + fprintf(lf, ""); + } + else if (se -> value > 0xffff || se -> value < -0x8000) { fprintf(lf, "%08X ", se -> value); } @@ -170,6 +193,11 @@ if (se -> context >= 0) fprintf(lf, " (%d)", se -> context); + if (se -> sect) + { + fprintf(lf, " [%s]", se -> sect -> name); + } + fputc('\n', lf); } }