comparison lwasm/lwasm.c @ 433:b1adf549d181

Add some debugging instrumentation for tracking an expression bug There's no reason not to keep the instrumentation so into the repo it goes.
author William Astle <lost@l-w.ca>
date Mon, 23 Jan 2017 22:54:19 -0700
parents 58cafa61ab40
children cad5937314cb
comparison
equal deleted inserted replaced
432:58cafa61ab40 433:b1adf549d181
62 asmstate_t *as = (asmstate_t *)priv; 62 asmstate_t *as = (asmstate_t *)priv;
63 lw_expr_t e; 63 lw_expr_t e;
64 importlist_t *im; 64 importlist_t *im;
65 struct symtabe *s; 65 struct symtabe *s;
66 66
67 debug_message(as, 225, "eval var: look up %s", var);
67 s = lookup_symbol(as, as -> cl, var); 68 s = lookup_symbol(as, as -> cl, var);
68 if (s) 69 if (s)
69 { 70 {
71 debug_message(as, 225, "eval var: symbol found %s = %s (%p)", s -> symbol, lw_expr_print(s -> value), s);
70 e = lw_expr_build(lw_expr_type_special, lwasm_expr_syment, s); 72 e = lw_expr_build(lw_expr_type_special, lwasm_expr_syment, s);
71 return e; 73 return e;
72 } 74 }
73 75
74 if (as -> undefzero) 76 if (as -> undefzero)
75 { 77 {
78 debug_message(as, 225, "eval var: undefined symbol treated as 0");
76 e = lw_expr_build(lw_expr_type_int, 0); 79 e = lw_expr_build(lw_expr_type_int, 0);
77 return e; 80 return e;
78 } 81 }
79 82
80 // undefined here is undefied unless output is object 83 // undefined here is undefied unless output is object
89 } 92 }
90 93
91 // check for "undefined" to import automatically 94 // check for "undefined" to import automatically
92 if ((as -> passno != 0) && !im && CURPRAGMA(as -> cl, PRAGMA_UNDEFEXTERN)) 95 if ((as -> passno != 0) && !im && CURPRAGMA(as -> cl, PRAGMA_UNDEFEXTERN))
93 { 96 {
97 debug_message(as, 225, "eval var: importing undefined symbol");
94 im = lw_alloc(sizeof(importlist_t)); 98 im = lw_alloc(sizeof(importlist_t));
95 im -> symbol = lw_strdup(var); 99 im -> symbol = lw_strdup(var);
96 im -> next = as -> importlist; 100 im -> next = as -> importlist;
97 as -> importlist = im; 101 as -> importlist = im;
98 } 102 }
106 nomatch: 110 nomatch:
107 if (as -> badsymerr) 111 if (as -> badsymerr)
108 { 112 {
109 lwasm_register_error2(as, as -> cl, E_SYMBOL_UNDEFINED, "%s", var); 113 lwasm_register_error2(as, as -> cl, E_SYMBOL_UNDEFINED, "%s", var);
110 } 114 }
115 debug_message(as, 225, "eval var: undefined symbol - returning NULL");
111 return NULL; 116 return NULL;
112 } 117 }
113 118
114 lw_expr_t lwasm_evaluate_special(int t, void *ptr, void *priv) 119 lw_expr_t lwasm_evaluate_special(int t, void *ptr, void *priv)
115 { 120 {
1418 lwasm_reduce_expr(as, cl -> daddr); 1423 lwasm_reduce_expr(as, cl -> daddr);
1419 1424
1420 // simplify each expression 1425 // simplify each expression
1421 for (i = 0, le = cl -> exprs; le; le = le -> next, i++) 1426 for (i = 0, le = cl -> exprs; le; le = le -> next, i++)
1422 { 1427 {
1428 debug_message(as, 101, "Reduce expressions: (pre) exp[%d] = %s", i, lw_expr_print(le -> expr));
1423 lwasm_reduce_expr(as, le -> expr); 1429 lwasm_reduce_expr(as, le -> expr);
1424 debug_message(as, 100, "Reduce expressions: exp[%d] = %s", i, lw_expr_print(le -> expr)); 1430 debug_message(as, 100, "Reduce expressions: exp[%d] = %s", i, lw_expr_print(le -> expr));
1425 } 1431 }
1426 1432
1427 if (cl -> len == -1 || cl -> dlen == -1) 1433 if (cl -> len == -1 || cl -> dlen == -1)