Mercurial > hg-old > index.cgi
comparison lwasm/pass2.c @ 363:d96c30e60ddf
Added pass2 and various supporting logic including symbol lookups
author | lost@starbug |
---|---|
date | Tue, 06 Apr 2010 21:03:19 -0600 |
parents | |
children | d99322ef6f21 |
comparison
equal
deleted
inserted
replaced
362:4867f18c872f | 363:d96c30e60ddf |
---|---|
1 /* | |
2 pass2.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 pass 2: deal with undefined symbols and do a simplification pass | |
35 on all the expressions. Handle PRAGMA_IMPORTUNDEFEXPORT | |
36 | |
37 */ | |
38 void do_pass2(asmstate_t *as) | |
39 { | |
40 line_t *cl; | |
41 exportlist_t *ex; | |
42 struct symtabe *s; | |
43 importlist_t *im; | |
44 struct line_expr_s *le; | |
45 | |
46 // verify the export list | |
47 if (as -> output_format == OUTPUT_OBJ) | |
48 { | |
49 for (ex = as -> exportlist; ex; ex = ex -> next) | |
50 { | |
51 s = lookup_symbol(as, NULL, ex -> symbol); | |
52 if (!s) | |
53 { | |
54 if (CURPRAGMA(ex -> line, PRAGMA_IMPORTUNDEFEXPORT)) | |
55 { | |
56 for (im = as -> importlist; im; im = im -> next) | |
57 { | |
58 if (!strcmp(ex -> symbol, im -> symbol)) | |
59 break; | |
60 } | |
61 if (!im) | |
62 { | |
63 im = lw_alloc(sizeof(importlist_t)); | |
64 im -> symbol = lw_strdup(ex -> symbol); | |
65 im -> next = as -> importlist; | |
66 as -> importlist = im; | |
67 } | |
68 } | |
69 else | |
70 { | |
71 // undefined export - register error | |
72 lwasm_register_error(as, ex -> line, "Undefined exported symbol"); | |
73 } | |
74 } | |
75 } | |
76 if (as -> errorcount > 0) | |
77 return; | |
78 } | |
79 | |
80 // we want to throw errors on undefined symbols here | |
81 as -> badsymerr = 1; | |
82 | |
83 // now do some reductions on expressions | |
84 for (cl = as -> line_head; cl; cl = cl -> next) | |
85 { | |
86 as -> cl = cl; | |
87 | |
88 // simplify address | |
89 lwasm_reduce_expr(as, cl -> addr); | |
90 | |
91 // simplify each expression | |
92 for (le = cl -> exprs; le; le = le -> next) | |
93 lwasm_reduce_expr(as, le -> expr); | |
94 } | |
95 } |