367
|
1 /*
|
|
2 pass6.c
|
|
3
|
|
4 Copyright © 2010 William Astle
|
|
5
|
|
6 This file is part of LWTOOLS.
|
|
7
|
|
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
|
|
9 terms of the GNU General Public License as published by the Free Software
|
|
10 Foundation, either version 3 of the License, or (at your option) any later
|
|
11 version.
|
|
12
|
|
13 This program is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
16 more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License along with
|
|
19 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 */
|
|
21
|
|
22 #include <config.h>
|
|
23
|
|
24 #include <stdio.h>
|
|
25 #include <string.h>
|
|
26
|
|
27 #include <lw_alloc.h>
|
|
28 #include <lw_string.h>
|
|
29
|
|
30 #include "lwasm.h"
|
|
31 #include "instab.h"
|
|
32
|
|
33 /*
|
|
34 Finalize Pass
|
|
35
|
|
36 Reduce all expressions in a final pass.
|
|
37
|
|
38 Observation:
|
|
39
|
|
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)
|
369
|
42 */
|
367
|
43
|
369
|
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
|
367
|
75 void do_pass6(asmstate_t *as)
|
|
76 {
|
|
77 line_t *cl;
|
|
78 struct line_expr_s *le;
|
|
79
|
|
80 for (cl = as -> line_head; cl; cl = cl -> next)
|
|
81 {
|
|
82 as -> cl = cl;
|
|
83 for (le = cl -> exprs; le; le = le -> next)
|
|
84 {
|
|
85 lwasm_reduce_expr(as, le -> expr);
|
369
|
86 if (!exprok(as, le -> expr))
|
|
87 {
|
|
88 lwasm_register_error(as, cl, "Invalid expression");
|
|
89 }
|
367
|
90 }
|
|
91 }
|
|
92 }
|