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