annotate lwasm/pass3.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 6a98cc90c14f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
364
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
1 /*
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
2 pass3.c
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
3
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
4 Copyright © 2010 William Astle
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
5
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
6 This file is part of LWTOOLS.
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
7
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
11 version.
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
12
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
16 more details.
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
17
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
20 */
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
21
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
22 #include <config.h>
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
23
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
24 #include <stdio.h>
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
25 #include <string.h>
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
26
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
27 #include <lw_alloc.h>
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
28 #include <lw_string.h>
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
29
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
30 #include "lwasm.h"
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
31 #include "instab.h"
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
32
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
33 /*
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
34 Resolve1 Pass
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
35
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
36 repeatedly resolve instruction sizes and line addresses
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
37 until nothing more reduces
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
38
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
39 */
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
40 void do_pass3(asmstate_t *as)
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
41 {
365
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
42 int rc;
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
43 line_t *cl;
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
44 struct line_expr_s *le;
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
45
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
46 do
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
47 {
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
48 rc = 0;
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
49 for (cl = as -> line_head; cl; cl = cl -> next)
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
50 {
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
51 as -> cl = cl;
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
52
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
53 // simplify address
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
54 lwasm_reduce_expr(as, cl -> addr);
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
55
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
56 // simplify each expression
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
57 for (le = cl -> exprs; le; le = le -> next)
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
58 lwasm_reduce_expr(as, le -> expr);
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
59
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
60 if (cl -> len == -1)
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
61 {
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
62 // try resolving the instruction length
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
63 // but don't force resolution
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
64 if (cl -> insn >= 0 && instab[cl -> insn].resolve)
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
65 {
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
66 (instab[cl -> insn].resolve)(as, cl, 0);
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
67 if (cl -> len != -1)
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
68 rc++;
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
69 }
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
70 }
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
71 }
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
72 if (as -> errorcount > 0)
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
73 return;
6a98cc90c14f Added resolve passes
lost@starbug
parents: 364
diff changeset
74 } while (rc > 0);
364
0b5a26bedbe1 Pass framework simplified; skeleton pass 3
lost@starbug
parents:
diff changeset
75 }