Mercurial > hg-old > index.cgi
annotate lwasm/pass4.c @ 388:8991eb507d2d
Added missing arg-nonnull.h ??? file to repo
author | lost@l-w.ca |
---|---|
date | Wed, 14 Jul 2010 20:17:57 -0600 |
parents | a741d2e4869f |
children |
rev | line source |
---|---|
365 | 1 /* |
2 pass4.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 Resolve2 Pass | |
35 | |
36 Force resolution of instruction sizes. | |
37 | |
38 */ | |
387
a741d2e4869f
Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents:
371
diff
changeset
|
39 void do_pass4_aux(asmstate_t *as, int force) |
365 | 40 { |
41 int rc; | |
42 int cnt; | |
43 line_t *cl, *sl; | |
44 struct line_expr_s *le; | |
45 | |
46 // first, count the number of unresolved instructions | |
47 for (cnt = 0, cl = as -> line_head; cl; cl = cl -> next) | |
48 { | |
49 if (cl -> len == -1) | |
50 cnt++; | |
51 } | |
52 | |
53 sl = as -> line_head; | |
54 while (cnt > 0) | |
55 { | |
56 // find an unresolved instruction | |
57 for ( ; sl && sl -> len != -1; sl = sl -> next) | |
366 | 58 { |
59 as -> cl = sl; | |
60 lwasm_reduce_expr(as, sl -> addr); | |
365 | 61 |
366 | 62 // simplify each expression |
63 for (le = sl -> exprs; le; le = le -> next) | |
64 lwasm_reduce_expr(as, le -> expr); | |
65 } | |
66 | |
365 | 67 // simplify address |
68 as -> cl = sl; | |
69 lwasm_reduce_expr(as, sl -> addr); | |
70 | |
71 // simplify each expression | |
72 for (le = sl -> exprs; le; le = le -> next) | |
73 lwasm_reduce_expr(as, le -> expr); | |
74 | |
75 | |
371 | 76 if (sl -> len == -1 && sl -> insn >= 0 && instab[sl -> insn].resolve) |
365 | 77 { |
371 | 78 (instab[sl -> insn].resolve)(as, sl, 1); |
387
a741d2e4869f
Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents:
371
diff
changeset
|
79 if (force && sl -> len == -1) |
365 | 80 { |
81 lwasm_register_error(as, sl, "Instruction failed to resolve."); | |
82 return; | |
83 } | |
84 } | |
85 cnt--; | |
86 if (cnt == 0) | |
87 return; | |
88 | |
89 do | |
90 { | |
91 rc = 0; | |
92 for (cl = sl; cl; cl = cl -> next) | |
93 { | |
94 as -> cl = cl; | |
95 | |
96 // simplify address | |
97 lwasm_reduce_expr(as, cl -> addr); | |
98 | |
99 // simplify each expression | |
100 for (le = cl -> exprs; le; le = le -> next) | |
101 lwasm_reduce_expr(as, le -> expr); | |
102 | |
103 if (cl -> len == -1) | |
104 { | |
105 // try resolving the instruction length | |
106 // but don't force resolution | |
107 if (cl -> insn >= 0 && instab[cl -> insn].resolve) | |
108 { | |
109 (instab[cl -> insn].resolve)(as, cl, 0); | |
110 if (cl -> len != -1) | |
111 { | |
112 rc++; | |
113 cnt--; | |
114 if (cnt == 0) | |
115 return; | |
116 } | |
117 } | |
118 } | |
119 } | |
120 if (as -> errorcount > 0) | |
121 return; | |
122 } while (rc > 0); | |
123 } | |
124 } | |
387
a741d2e4869f
Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents:
371
diff
changeset
|
125 |
a741d2e4869f
Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents:
371
diff
changeset
|
126 void do_pass4(asmstate_t *as) |
a741d2e4869f
Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents:
371
diff
changeset
|
127 { |
a741d2e4869f
Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents:
371
diff
changeset
|
128 do_pass4_aux(as, 1); |
a741d2e4869f
Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents:
371
diff
changeset
|
129 } |