annotate lwasm/pass6.c @ 439:b8549694b4c9 3.0

Fixed errors related to lw_expr_t; fixed saving expression in insn_parse_logicmem()
author lost@l-w.ca
date Sat, 30 Oct 2010 10:41:52 -0600
parents 898a41f7eb59
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
367
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
1 /*
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
2 pass6.c
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
3
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
4 Copyright © 2010 William Astle
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
5
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
6 This file is part of LWTOOLS.
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
7
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
11 version.
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
12
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
16 more details.
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
17
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
20 */
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
21
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
22 #include <config.h>
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
23
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
24 #include <stdio.h>
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
25 #include <string.h>
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
26
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
27 #include <lw_alloc.h>
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
28 #include <lw_string.h>
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
29
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
30 #include "lwasm.h"
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
31 #include "instab.h"
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
32
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
33 /*
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
34 Finalize Pass
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
35
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
36 Reduce all expressions in a final pass.
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
37
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
38 Observation:
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
39
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
40 Everything should reduce as far as it is going to in a single pass
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
41 because all line addresses are now constant (or section-base offset)
369
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
42 */
367
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
43
369
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
44 static int exprok_aux(lw_expr_t e, void *priv)
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
45 {
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
46 asmstate_t *as = priv;
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
47
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
48 if (lw_expr_istype(e, lw_expr_type_int))
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
49 return 0;
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
50
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
51 if (as -> output_format == OUTPUT_OBJ)
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
52 {
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
53 if (lw_expr_istype(e, lw_expr_type_oper))
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
54 return 0;
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
55 if (lw_expr_istype(e, lw_expr_type_special) && as -> output_format == OUTPUT_OBJ)
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
56 {
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
57 int t;
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
58 t = lw_expr_specint(e);
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
59 if (t == lwasm_expr_secbase || t == lwasm_expr_syment || t == lwasm_expr_import)
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
60 return 0;
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
61 }
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
62 }
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
63
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
64 return 1;
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
65 }
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
66
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
67 static int exprok(asmstate_t *as, lw_expr_t e)
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
68 {
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
69 if (lw_expr_testterms(e, exprok_aux, as))
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
70 return 0;
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
71 return 1;
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
72 }
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
73
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
74
367
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
75 void do_pass6(asmstate_t *as)
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
76 {
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
77 line_t *cl;
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
78 struct line_expr_s *le;
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
79
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
80 for (cl = as -> line_head; cl; cl = cl -> next)
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
81 {
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
82 as -> cl = cl;
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
83 for (le = cl -> exprs; le; le = le -> next)
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
84 {
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
85 lwasm_reduce_expr(as, le -> expr);
369
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
86 if (!exprok(as, le -> expr))
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
87 {
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
88 lwasm_register_error(as, cl, "Invalid expression");
898a41f7eb59 check for valid expressions in pass 6
lost@starbug
parents: 367
diff changeset
89 }
367
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
90 }
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
91 }
34dfc9747f23 Reduction passes complete
lost@starbug
parents:
diff changeset
92 }