comparison src/symbol.c @ 75:92eb93bffa28

Rejigged symbol system to be able to handle non-constant references
author lost
date Thu, 08 Jan 2009 01:32:49 +0000
parents aaddd47219b4
children a338d496350e
comparison
equal deleted inserted replaced
74:c8c772ef5df9 75:92eb93bffa28
26 26
27 #include <string.h> 27 #include <string.h>
28 28
29 #include "lwasm.h" 29 #include "lwasm.h"
30 #include "util.h" 30 #include "util.h"
31 #include "expr.h"
31 32
32 /* 33 /*
33 Note that this function may accept symbols that the expression evaluator doesn't 34 Note that this function may accept symbols that the expression evaluator doesn't
34 recognize because the expression evaluator must avoid all ambiguity in order 35 recognize because the expression evaluator must avoid all ambiguity in order
35 to achieve predictable results. The checks here are simply a fuzz check. 36 to achieve predictable results. The checks here are simply a fuzz check.
39 lwasm_symbol_ent_t *se, *se2; 40 lwasm_symbol_ent_t *se, *se2;
40 char *p; 41 char *p;
41 42
42 int scontext = -1; 43 int scontext = -1;
43 44
45 // if the symbol is constant, fall back to simple registration!
46 if (flags & SYMBOL_COMPLEX)
47 {
48 if (lwasm_expr_is_constant(l -> expr))
49 {
50 val = lwasm_expr_get_value(l -> expr);
51 flags &= ~SYMBOL_COMPLEX;
52 }
53 }
54
44 // first check if the symbol is valid 55 // first check if the symbol is valid
45 // the following characters are allowed in a symbol: 56 // the following characters are allowed in a symbol:
46 // [a-zA-Z0-9._$?@] and any byte value larger than 0x7F 57 // [a-zA-Z0-9._$?@] and any byte value larger than 0x7F
47 // although symbols should be restricted to the 7 bit range 58 // although symbols should be restricted to the 7 bit range
48 // symbols must start with [a-zA-Z._] 59 // symbols must start with [a-zA-Z._]
83 } 94 }
84 } 95 }
85 if (se) 96 if (se)
86 { 97 {
87 se -> value = val; 98 se -> value = val;
99 if (flags & SYMBOL_COMPLEX)
100 {
101 se -> expr = l -> expr;
102 }
88 return; 103 return;
89 } 104 }
90 105
91 // if not a duplicate, register it with the value 106 // if not a duplicate, register it with the value
92 se = lwasm_alloc(sizeof(lwasm_symbol_ent_t)); 107 se = lwasm_alloc(sizeof(lwasm_symbol_ent_t));
103 se -> prev = NULL; 118 se -> prev = NULL;
104 as -> symhead = se; 119 as -> symhead = se;
105 as -> symtail = se; 120 as -> symtail = se;
106 } 121 }
107 se -> value = val; 122 se -> value = val;
123 if (flags & SYMBOL_COMPLEX)
124 se -> expr = l -> expr;
108 se -> sym = lwasm_strdup(sym); 125 se -> sym = lwasm_strdup(sym);
109 se -> context = scontext; 126 se -> context = scontext;
127 se -> sect = as -> csect;
128 se -> expr = NULL;
110 se -> flags = flags; 129 se -> flags = flags;
111 130
112 return 0; 131 return 0;
113 } 132 }
114 133
145 { 164 {
146 lwasm_symbol_ent_t *se; 165 lwasm_symbol_ent_t *se;
147 166
148 for (se = as -> symhead; se; se = se -> next) 167 for (se = as -> symhead; se; se = se -> next)
149 { 168 {
150 if (se -> value > 0xffff || se -> value < -0x8000) 169 if (se -> expr)
170 {
171 fprintf(lf, "<incompl>");
172 }
173 else if (se -> value > 0xffff || se -> value < -0x8000)
151 { 174 {
152 fprintf(lf, "%08X ", se -> value); 175 fprintf(lf, "%08X ", se -> value);
153 } 176 }
154 else 177 else
155 { 178 {
168 fprintf(lf, " %s", se -> sym); 191 fprintf(lf, " %s", se -> sym);
169 192
170 if (se -> context >= 0) 193 if (se -> context >= 0)
171 fprintf(lf, " (%d)", se -> context); 194 fprintf(lf, " (%d)", se -> context);
172 195
196 if (se -> sect)
197 {
198 fprintf(lf, " [%s]", se -> sect -> name);
199 }
200
173 fputc('\n', lf); 201 fputc('\n', lf);
174 } 202 }
175 } 203 }