comparison src/symbol.c @ 77:a338d496350e

Checkpointing conversion to allow object target
author lost
date Fri, 09 Jan 2009 04:23:00 +0000
parents 92eb93bffa28
children d0ce3f5f6797
comparison
equal deleted inserted replaced
76:2fe5fd7d65a3 77:a338d496350e
33 /* 33 /*
34 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
35 recognize because the expression evaluator must avoid all ambiguity in order 35 recognize because the expression evaluator must avoid all ambiguity in order
36 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.
37 */ 37 */
38
39 /*
40 NOTE: complex symbols always take their value from slot 0 on the expression placeholders
41 for a line!
42 */
38 int lwasm_register_symbol(asmstate_t *as, lwasm_line_t *l, char *sym, int val, int flags) 43 int lwasm_register_symbol(asmstate_t *as, lwasm_line_t *l, char *sym, int val, int flags)
39 { 44 {
40 lwasm_symbol_ent_t *se, *se2; 45 lwasm_symbol_ent_t *se, *se2;
41 char *p; 46 char *p;
42 47
43 int scontext = -1; 48 int scontext = -1;
44 49
45 // if the symbol is constant, fall back to simple registration! 50 // if the symbol is constant, fall back to simple registration!
46 if (flags & SYMBOL_COMPLEX) 51 if (flags & SYMBOL_COMPLEX)
47 { 52 {
48 if (lwasm_expr_is_constant(l -> expr)) 53 if (l -> exprs[0] == NULL)
49 { 54 {
50 val = lwasm_expr_get_value(l -> expr); 55 val = l -> exprvals[0];
51 flags &= ~SYMBOL_COMPLEX; 56 flags &= ~SYMBOL_COMPLEX;
52 } 57 }
53 } 58 }
54 59
55 // first check if the symbol is valid 60 // first check if the symbol is valid
96 if (se) 101 if (se)
97 { 102 {
98 se -> value = val; 103 se -> value = val;
99 if (flags & SYMBOL_COMPLEX) 104 if (flags & SYMBOL_COMPLEX)
100 { 105 {
101 se -> expr = l -> expr; 106 se -> expr = l -> exprs[0];
102 } 107 }
103 return; 108 return;
104 } 109 }
105 110
106 // if not a duplicate, register it with the value 111 // if not a duplicate, register it with the value
119 as -> symhead = se; 124 as -> symhead = se;
120 as -> symtail = se; 125 as -> symtail = se;
121 } 126 }
122 se -> value = val; 127 se -> value = val;
123 if (flags & SYMBOL_COMPLEX) 128 if (flags & SYMBOL_COMPLEX)
124 se -> expr = l -> expr; 129 se -> expr = l -> exprs[0];
125 se -> sym = lwasm_strdup(sym); 130 se -> sym = lwasm_strdup(sym);
126 se -> context = scontext; 131 se -> context = scontext;
127 se -> sect = as -> csect; 132 se -> sect = as -> csect;
128 se -> expr = NULL; 133 se -> expr = NULL;
129 se -> flags = flags; 134 se -> flags = flags;