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