Mercurial > hg-old > index.cgi
annotate lwasm/pseudo.c @ 348:11a95c6414b4
Added third func to instab to split resolve and emit logic
author | lost@starbug |
---|---|
date | Sat, 27 Mar 2010 22:15:07 -0600 |
parents | 1649bc7bda5a |
children | dcd2978a7d18 |
rev | line source |
---|---|
347 | 1 /* |
2 pseudo.c | |
3 Copyright © 2010 William Astle | |
4 | |
5 This file is part of LWASM. | |
6 | |
7 LWASM is free software: you can redistribute it and/or modify it under the | |
8 terms of the GNU General Public License as published by the Free Software | |
9 Foundation, either version 3 of the License, or (at your option) any later | |
10 version. | |
11 | |
12 This program is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 more details. | |
16 | |
17 You should have received a copy of the GNU General Public License along with | |
18 this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 */ | |
21 | |
22 #include <config.h> | |
23 | |
24 #include "lwasm.h" | |
25 #include "instab.h" | |
26 | |
27 // for "end" | |
28 PARSEFUNC(pseudo_parse_end) | |
29 { | |
30 lw_expr_t addr; | |
31 | |
32 as -> endseen = 1; | |
33 | |
34 if (as -> output_format != OUTPUT_DECB) | |
35 { | |
36 skip_operand(p); | |
37 return; | |
38 } | |
39 | |
40 addr = lwasm_parse_expr(as, p); | |
41 if (!addr) | |
42 { | |
43 lwasm_register_error(as, l, "Bad expression"); | |
44 addr = lw_expr_build(lw_expr_type_int, 0); | |
45 } | |
46 lwasm_save_expr(l, 0, addr); | |
47 } | |
48 | |
348
11a95c6414b4
Added third func to instab to split resolve and emit logic
lost@starbug
parents:
347
diff
changeset
|
49 EMITFUNC(pseudo_emit_end) |
347 | 50 { |
51 lw_expr_t addr; | |
52 | |
53 addr = lwasm_fetch_expr(l, 0); | |
54 | |
55 if (addr) | |
56 { | |
57 if (!lw_expr_istype(addr, lw_expr_type_int)) | |
58 lwasm_register_error(as, l, "Exec address not constant!"); | |
59 else | |
60 as -> execaddr = lw_expr_intval(addr); | |
61 } | |
62 as -> endseen = 1; | |
63 } | |
64 | |
65 PARSEFUNC(pseudo_parse_fcb) | |
66 { | |
67 int i = 0; | |
68 lw_expr_t e; | |
69 | |
70 for (;;) | |
71 { | |
72 e = lwasm_parse_expr(as, p); | |
73 if (!e) | |
74 { | |
75 lwasm_register_error(as, l, "Bad expression (#%s)", i); | |
76 break; | |
77 } | |
78 lwasm_save_expr(l, i, e); | |
79 i++; | |
80 } | |
81 | |
82 l -> len = i; | |
83 } | |
84 | |
348
11a95c6414b4
Added third func to instab to split resolve and emit logic
lost@starbug
parents:
347
diff
changeset
|
85 EMITFUNC(pseudo_emit_fcb) |
347 | 86 { |
87 int i; | |
88 lw_expr_t e; | |
89 int v; | |
90 | |
91 for (i = 0; i < l -> len; i++) | |
92 { | |
93 e = lwasm_fetch_expr(l, i); | |
94 lwasm_emitexpr(l, e, 1); | |
95 } | |
96 } | |
97 | |
98 PARSEFUNC(pseudo_parse_fdb) | |
99 { | |
100 int i = 0; | |
101 lw_expr_t e; | |
102 | |
103 for (;;) | |
104 { | |
105 e = lwasm_parse_expr(as, p); | |
106 if (!e) | |
107 { | |
108 lwasm_register_error(as, l, "Bad expression (#%s)", i); | |
109 break; | |
110 } | |
111 lwasm_save_expr(l, i, e); | |
112 i++; | |
113 } | |
114 | |
115 l -> len = i * 2; | |
116 } | |
117 | |
348
11a95c6414b4
Added third func to instab to split resolve and emit logic
lost@starbug
parents:
347
diff
changeset
|
118 EMITFUNC(pseudo_emit_fdb) |
347 | 119 { |
120 int i; | |
121 lw_expr_t e; | |
122 int v; | |
123 | |
124 for (i = 0; i < (l -> len)/2; i++) | |
125 { | |
126 e = lwasm_fetch_expr(l, i); | |
127 lwasm_emitexpr(l, e, 2); | |
128 } | |
129 } | |
130 | |
131 PARSEFUNC(pseudo_parse_fqb) | |
132 { | |
133 int i = 0; | |
134 lw_expr_t e; | |
135 | |
136 for (;;) | |
137 { | |
138 e = lwasm_parse_expr(as, p); | |
139 if (!e) | |
140 { | |
141 lwasm_register_error(as, l, "Bad expression (#%s)", i); | |
142 break; | |
143 } | |
144 lwasm_save_expr(l, i, e); | |
145 i++; | |
146 } | |
147 | |
148 l -> len = i * 4; | |
149 } | |
150 | |
348
11a95c6414b4
Added third func to instab to split resolve and emit logic
lost@starbug
parents:
347
diff
changeset
|
151 EMITFUNC(pseudo_emit_fqb) |
347 | 152 { |
153 int i; | |
154 lw_expr_t e; | |
155 int v; | |
156 | |
157 for (i = 0; i < (l -> len)/4; i++) | |
158 { | |
159 e = lwasm_fetch_expr(l, i); | |
160 lwasm_emitexpr(l, e, 4); | |
161 } | |
162 } |