comparison lwasm/pass6.c @ 369:898a41f7eb59

check for valid expressions in pass 6
author lost@starbug
date Thu, 15 Apr 2010 22:26:49 -0600
parents 34dfc9747f23
children
comparison
equal deleted inserted replaced
368:656630007668 369:898a41f7eb59
37 37
38 Observation: 38 Observation:
39 39
40 Everything should reduce as far as it is going to in a single pass 40 Everything should reduce as far as it is going to in a single pass
41 because all line addresses are now constant (or section-base offset) 41 because all line addresses are now constant (or section-base offset)
42 */
42 43
43 */ 44 static int exprok_aux(lw_expr_t e, void *priv)
45 {
46 asmstate_t *as = priv;
47
48 if (lw_expr_istype(e, lw_expr_type_int))
49 return 0;
50
51 if (as -> output_format == OUTPUT_OBJ)
52 {
53 if (lw_expr_istype(e, lw_expr_type_oper))
54 return 0;
55 if (lw_expr_istype(e, lw_expr_type_special) && as -> output_format == OUTPUT_OBJ)
56 {
57 int t;
58 t = lw_expr_specint(e);
59 if (t == lwasm_expr_secbase || t == lwasm_expr_syment || t == lwasm_expr_import)
60 return 0;
61 }
62 }
63
64 return 1;
65 }
66
67 static int exprok(asmstate_t *as, lw_expr_t e)
68 {
69 if (lw_expr_testterms(e, exprok_aux, as))
70 return 0;
71 return 1;
72 }
73
74
44 void do_pass6(asmstate_t *as) 75 void do_pass6(asmstate_t *as)
45 { 76 {
46 line_t *cl; 77 line_t *cl;
47 struct line_expr_s *le; 78 struct line_expr_s *le;
48 79
50 { 81 {
51 as -> cl = cl; 82 as -> cl = cl;
52 for (le = cl -> exprs; le; le = le -> next) 83 for (le = cl -> exprs; le; le = le -> next)
53 { 84 {
54 lwasm_reduce_expr(as, le -> expr); 85 lwasm_reduce_expr(as, le -> expr);
86 if (!exprok(as, le -> expr))
87 {
88 lwasm_register_error(as, cl, "Invalid expression");
89 }
55 } 90 }
56 } 91 }
57 } 92 }