annotate lwasm/section.c @ 423:079d43b6967b 3.0-beta2 3.0-beta2

Added missing file
author lost@l-w.ca
date Sun, 19 Sep 2010 01:44:47 -0600
parents 35a0b086bf4a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
353
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
1 /*
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
2 section.c
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
3
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
4 Copyright © 2010 William Astle
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
5
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
6 This file is part of LWTOOLS.
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
7
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
11 version.
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
12
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
16 more details.
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
17
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
20 */
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
21
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
22 #include <config.h>
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
23
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
24 #include <string.h>
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
25
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
26 #include <lw_string.h>
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
27 #include <lw_alloc.h>
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
28
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
29 #include "lwasm.h"
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
30 #include "instab.h"
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
31
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
32 PARSEFUNC(pseudo_parse_section)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
33 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
34 char *p2;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
35 char *sn;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
36 char *opts = NULL;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
37 sectiontab_t *s;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
38
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
39 if (as -> output_format != OUTPUT_OBJ)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
40 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
41 lwasm_register_error(as, l, "Cannot use sections unless using the object target");
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
42 return;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
43 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
44
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
45 if (!**p)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
46 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
47 lwasm_register_error(as, l, "Need section name");
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
48 return;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
49 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
50
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: 385
diff changeset
51 l -> len = 0;
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: 385
diff changeset
52
353
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
53 if (as -> csect)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
54 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
55 lw_expr_destroy(as -> csect -> offset);
412
35a0b086bf4a Added dummy .bank pseudo and fixed segfault in output for object target (on imported symbol)
lost@l-w.ca
parents: 387
diff changeset
56 as -> csect -> offset = lw_expr_copy(l -> addr);
353
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
57 as -> csect = NULL;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
58 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
59
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
60 for (p2 = *p; *p2 && *p2 != ',' && !isspace(*p2); p2++)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
61 /* do nothing */ ;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
62
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
63 sn = lw_strndup(*p, p2 - *p);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
64 *p = p2;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
65
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
66 if (**p == ',')
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
67 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
68 // have opts
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
69 (*p)++;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
70
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
71 for (p2 = *p; *p2 && !isspace(*p2); p2++)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
72 /* do nothing */ ;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
73
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
74 opts = lw_strndup(*p, p2 - *p);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
75 *p = p2;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
76 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
77
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
78 for (s = as -> sections; s; s = s -> next)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
79 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
80 if (!strcmp(s -> name, sn))
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
81 break;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
82 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
83 if (s && opts)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
84 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
85 lwasm_register_warning(as, l, "Section flags can only be specified the first time; ignoring duplicate definition");
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
86 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
87 if (!s)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
88 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
89 // create section data structure
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
90 s = lw_alloc(sizeof(sectiontab_t));
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: 385
diff changeset
91 s -> oblen = 0;
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: 385
diff changeset
92 s -> obsize = 0;
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: 385
diff changeset
93 s -> obytes = NULL;
353
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
94 s -> name = lw_strdup(sn);
367
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 363
diff changeset
95 s -> offset = lw_expr_build(lw_expr_type_special, lwasm_expr_secbase, s);
353
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
96 s -> flags = section_flag_none;
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: 385
diff changeset
97 s -> reloctab = NULL;
353
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
98 if (!strcasecmp(sn, "bss") || !strcasecmp(sn, ".bss"))
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
99 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
100 s -> flags |= section_flag_bss;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
101 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
102 // parse options
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
103 if (opts)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
104 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
105 // only one option ("bss" or "!bss")
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
106 if (!strcasecmp(opts, "bss"))
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
107 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
108 s -> flags |= section_flag_bss;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
109 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
110 else if (!strcasecmp(opts, "!bss"))
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
111 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
112 s -> flags &= ~section_flag_bss;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
113 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
114 else
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
115 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
116 lwasm_register_error(as, l, "Unrecognized section flag");
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
117 lw_free(sn);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
118 lw_free(opts);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
119 lw_free(s -> name);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
120 lw_expr_destroy(s -> offset);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
121 lw_free(s);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
122 return;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
123 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
124 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
125 s -> next = as -> sections;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
126 as -> sections = s;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
127 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
128
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
129 lw_expr_destroy(l -> addr);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
130 l -> addr = lw_expr_copy(s -> offset);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
131
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
132 as -> csect = s;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
133 as -> context = lwasm_next_context(as);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
134
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
135 l -> len = 0;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
136
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
137 lw_free(opts);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
138 lw_free(sn);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
139 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
140
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
141 PARSEFUNC(pseudo_parse_endsection)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
142 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
143 if (as -> output_format != OUTPUT_OBJ)
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
144 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
145 lwasm_register_error(as, l, "Cannot use sections unless using the object target");
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
146 return;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
147 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
148
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: 385
diff changeset
149 l -> len = 0;
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: 385
diff changeset
150
353
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
151 if (!(as -> csect))
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
152 {
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
153 lwasm_register_error(as, l, "ENDSECTION without SECTION");
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
154 return;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
155 }
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
156
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
157 // save offset in case another instance of the section appears
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
158 lw_expr_destroy(as -> csect -> offset);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
159 as -> csect -> offset = l -> addr;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
160
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
161 // reset address to 0
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
162 l -> addr = lw_expr_build(lw_expr_type_int, 0);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
163 as -> csect = NULL;
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
164
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
165 // end of section is a context break
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
166 as -> context = lwasm_next_context(as);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
167
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
168 skip_operand(p);
faa97115952e Added SECTION/ENDSECTION
lost@starbug
parents:
diff changeset
169 }
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
170
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
171 PARSEFUNC(pseudo_parse_export)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
172 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
173 int after = 0;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
174 char *sym = NULL;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
175 exportlist_t *e;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
176
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
177 if (as -> output_format != OUTPUT_OBJ)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
178 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
179 lwasm_register_error(as, l, "EXPORT only supported for object target");
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
180 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
181 }
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: 385
diff changeset
182
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: 385
diff changeset
183 l -> len = 0;
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
184
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
185 if (l -> sym)
385
cf8c92d70eb1 Various bugfixes
lost@starbug
parents: 380
diff changeset
186 {
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
187 sym = lw_strdup(l -> sym);
385
cf8c92d70eb1 Various bugfixes
lost@starbug
parents: 380
diff changeset
188 l -> symset = 1;
cf8c92d70eb1 Various bugfixes
lost@starbug
parents: 380
diff changeset
189 }
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
190
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
191 if (l -> sym)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
192 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
193 skip_operand(p);
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
194 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
195
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
196 again:
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
197 if (after || !sym)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
198 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
199 char *p2;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
200
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
201 after = 1;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
202 for (p2 = *p; *p2 && *p2 != ',' && !isspace(*p2); p2++)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
203 /* do nothing */ ;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
204
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
205 sym = lw_strndup(*p, p2 - *p);
385
cf8c92d70eb1 Various bugfixes
lost@starbug
parents: 380
diff changeset
206 *p = p2;
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
207 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
208 if (!sym)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
209 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
210 lwasm_register_error(as, l, "No symbol for EXPORT");
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
211 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
212 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
213
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
214 // add the symbol to the "export" list (which will be resolved
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
215 // after the parse pass is complete
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
216 e = lw_alloc(sizeof(exportlist_t));
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
217 e -> next = as -> exportlist;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
218 e -> symbol = lw_strdup(sym);
363
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 356
diff changeset
219 e -> line = l;
374
d99322ef6f21 Stage 1: actually do output
lost@starbug
parents: 367
diff changeset
220 e -> se = NULL;
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
221 as -> exportlist = e;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
222 lw_free(sym);
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
223
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
224 if (after && **p == ',')
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
225 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
226 (*p)++;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
227 for (; **p && isspace(**p); (*p)++)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
228 /* do nothing */ ;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
229 goto again;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
230 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
231 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
232
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
233 PARSEFUNC(pseudo_parse_extern)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
234 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
235 int after = 0;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
236 char *sym = NULL;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
237 importlist_t *e;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
238
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
239 if (as -> output_format != OUTPUT_OBJ)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
240 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
241 lwasm_register_error(as, l, "IMPORT only supported for object target");
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
242 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
243 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
244
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: 385
diff changeset
245 l -> len = 0;
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: 385
diff changeset
246
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
247 if (l -> sym)
385
cf8c92d70eb1 Various bugfixes
lost@starbug
parents: 380
diff changeset
248 {
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
249 sym = lw_strdup(l -> sym);
385
cf8c92d70eb1 Various bugfixes
lost@starbug
parents: 380
diff changeset
250 l -> symset = 1;
cf8c92d70eb1 Various bugfixes
lost@starbug
parents: 380
diff changeset
251 }
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
252
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
253 if (l -> sym)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
254 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
255 skip_operand(p);
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
256 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
257
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
258 again:
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
259 if (after || !sym)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
260 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
261 char *p2;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
262
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
263 after = 1;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
264 for (p2 = *p; *p2 && *p2 != ',' && !isspace(*p2); p2++)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
265 /* do nothing */ ;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
266
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
267 sym = lw_strndup(*p, p2 - *p);
385
cf8c92d70eb1 Various bugfixes
lost@starbug
parents: 380
diff changeset
268 *p = p2;
356
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
269 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
270 if (!sym)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
271 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
272 lwasm_register_error(as, l, "No symbol for IMPORT");
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
273 return;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
274 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
275
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
276 // add the symbol to the "export" list (which will be resolved
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
277 // after the parse pass is complete
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
278 e = lw_alloc(sizeof(importlist_t));
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
279 e -> next = as -> importlist;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
280 e -> symbol = lw_strdup(sym);
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
281 as -> importlist = e;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
282 lw_free(sym);
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
283
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
284 if (after && **p == ',')
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
285 {
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
286 (*p)++;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
287 for (; **p && isspace(**p); (*p)++)
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
288 /* do nothing */ ;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
289 goto again;
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
290 }
7166254491ed Finished pseudo ops
lost@starbug
parents: 353
diff changeset
291 }
380
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
292
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
293 PARSEFUNC(pseudo_parse_extdep)
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
294 {
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
295 int after = 0;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
296 char *sym = NULL;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
297 importlist_t *e;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
298
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
299 if (as -> output_format != OUTPUT_OBJ)
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
300 {
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
301 lwasm_register_error(as, l, "EXTDEP only supported for object target");
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
302 return;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
303 }
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
304
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
305 if (!as -> csect)
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
306 {
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
307 lwasm_register_error(as, l, "EXTDEP must be within a section");
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
308 return;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
309 }
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
310
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: 385
diff changeset
311 l -> len = 0;
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: 385
diff changeset
312
380
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
313 if (l -> sym)
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
314 sym = lw_strdup(l -> sym);
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
315
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
316 if (l -> sym)
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
317 {
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
318 skip_operand(p);
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
319 }
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
320
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
321 again:
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
322 if (after || !sym)
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
323 {
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
324 char *p2;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
325
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
326 after = 1;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
327 for (p2 = *p; *p2 && *p2 != ',' && !isspace(*p2); p2++)
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
328 /* do nothing */ ;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
329
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
330 sym = lw_strndup(*p, p2 - *p);
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
331 }
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
332 if (!sym)
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
333 {
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
334 lwasm_register_error(as, l, "No symbol for EXTDEP");
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
335 return;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
336 }
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
337
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
338 // create a zero-width dependency
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
339 {
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
340 lw_expr_t e;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
341 e = lw_expr_build(lw_expr_type_int, 0);
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
342 lwasm_emitexpr(l, e, 0);
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
343 lw_expr_destroy(e);
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
344 }
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
345
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
346 if (after && **p == ',')
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
347 {
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
348 (*p)++;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
349 for (; **p && isspace(**p); (*p)++)
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
350 /* do nothing */ ;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
351 goto again;
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
352 }
cc154dc614fe Added extdep pseudo back in
lost@starbug
parents: 374
diff changeset
353 }