comparison lwasm/pass6.c @ 0:2c24602be78f

Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
author lost@l-w.ca
date Wed, 19 Jan 2011 22:27:17 -0700
parents
children 02804b7c051c
comparison
equal deleted inserted replaced
-1:000000000000 0:2c24602be78f
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 <stdio.h>
23 #include <string.h>
24
25 #include <lw_alloc.h>
26 #include <lw_string.h>
27
28 #include "lwasm.h"
29 #include "instab.h"
30
31 /*
32 Finalize Pass
33
34 Reduce all expressions in a final pass.
35
36 Observation:
37
38 Everything should reduce as far as it is going to in a single pass
39 because all line addresses are now constant (or section-base offset)
40 */
41
42 static int exprok_aux(lw_expr_t e, void *priv)
43 {
44 asmstate_t *as = priv;
45
46 if (lw_expr_istype(e, lw_expr_type_int))
47 return 0;
48
49 if (as -> output_format == OUTPUT_OBJ)
50 {
51 if (lw_expr_istype(e, lw_expr_type_oper))
52 return 0;
53 if (lw_expr_istype(e, lw_expr_type_special) && as -> output_format == OUTPUT_OBJ)
54 {
55 int t;
56 t = lw_expr_specint(e);
57 if (t == lwasm_expr_secbase || t == lwasm_expr_syment || t == lwasm_expr_import)
58 return 0;
59 }
60 }
61
62 return 1;
63 }
64
65 static int exprok(asmstate_t *as, lw_expr_t e)
66 {
67 if (lw_expr_testterms(e, exprok_aux, as))
68 return 0;
69 return 1;
70 }
71
72
73 void do_pass6(asmstate_t *as)
74 {
75 line_t *cl;
76 struct line_expr_s *le;
77
78 for (cl = as -> line_head; cl; cl = cl -> next)
79 {
80 as -> cl = cl;
81 for (le = cl -> exprs; le; le = le -> next)
82 {
83 lwasm_reduce_expr(as, le -> expr);
84 if (!exprok(as, le -> expr))
85 {
86 lwasm_register_error(as, cl, "Invalid expression");
87 }
88 }
89 }
90 }