annotate lwasm/lwasm.c @ 259:c3a34f820893 2.x

Added asprintf redux
author lost
date Tue, 22 Dec 2009 05:53:25 +0000
parents 1106ec189e4f
children 97630727000e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
1 /*
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
2 lwasm.c
55
8e32696380f3 added expression evaluation and checking function
lost
parents: 52
diff changeset
3 Copyright © 2009 William Astle
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
5 This file is part of LWASM.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
6
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
8 terms of the GNU General Public License as published by the Free Software
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
10 version.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
11
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
15 more details.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
16
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
17 You should have received a copy of the GNU General Public License along with
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
19
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
20
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
21 Contains random functions used by the assembler
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
22 */
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
23
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
24 #define __lwasm_c_seen__
212
bae1e3ecdce1 More preparation for gnulib integration
lost
parents: 151
diff changeset
25 #include <config.h>
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
27 #include <stdarg.h>
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
28 #include <stdlib.h>
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
29 #include <stdio.h>
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
30
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
31 #include "lwasm.h"
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
32 #include "util.h"
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
33 #include "expr.h"
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
34
38
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
35 int debug_level = 0;
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
36
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
37 int register_error(asmstate_t *as, lwasm_line_t *l, int pass, const char *fmt, ...)
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
38 {
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
39 lwasm_error_t *e;
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
40 va_list args;
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
41 char errbuff[1024];
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
42 int r;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
43
143
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 101
diff changeset
44 if (!l)
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 101
diff changeset
45 return;
0ee5f65bccf9 Added pragma to allow all undefined symbols to be considered external and also added a --pragma command line option
lost
parents: 101
diff changeset
46
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
47 if (as -> passnum != pass)
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
48 return;
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
49
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
50 va_start(args, fmt);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
51
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
52 e = lwasm_alloc(sizeof(lwasm_error_t));
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
53
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
54 e -> next = l -> err;
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
55 l -> err = e;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
56
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
57 as -> errorcount++;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
58
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
59 r = vsnprintf(errbuff, 1024, fmt, args);
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
60 e -> mess = lwasm_strdup(errbuff);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
61
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
62 va_end(args);
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
63
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 13
diff changeset
64 return r;
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
65 }
27
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
66
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
67 void lwasm_emit(asmstate_t *as, lwasm_line_t *l, int b)
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
68 {
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
69 as -> addr += 1;
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 57
diff changeset
70 as -> addr &= 0xffff;
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 57
diff changeset
71
74
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 60
diff changeset
72 if (as -> outformat == OUTPUT_OBJ && !(as -> csect))
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 60
diff changeset
73 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 60
diff changeset
74 register_error(as, l, 1, "Output not allowed outside sections with obj target");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 60
diff changeset
75 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 60
diff changeset
76 }
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 60
diff changeset
77 if (as -> outformat == OUTPUT_OBJ && as -> csect -> flags & SECTION_BSS)
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 60
diff changeset
78 {
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 60
diff changeset
79 register_error(as, l, 1, "Output not allowed inside BSS sections");
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 60
diff changeset
80 return;
c8c772ef5df9 Checkpointing object target implementation
lost
parents: 60
diff changeset
81 }
236
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
82
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
83 if (as -> outformat == OUTPUT_OS9 && as -> inmod == 0)
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
84 {
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
85 register_error(as, l, 1, "Output not allowed outside of module in OS9 mode");
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
86 return;
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
87 }
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
88
27
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
89 if (as -> passnum == 1)
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
90 return;
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
91
42
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 39
diff changeset
92
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 39
diff changeset
93 if (l -> codelen >= l -> codesize)
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 39
diff changeset
94 {
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 39
diff changeset
95 l -> bytes = realloc(l -> bytes, l -> codesize + 16);
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 39
diff changeset
96 l -> codesize += 16;
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 39
diff changeset
97 }
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 39
diff changeset
98 l -> bytes[l -> codelen] = b & 0xff;
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 39
diff changeset
99 l -> codelen += 1;
236
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
100
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
101 if (as -> outformat == OUTPUT_OS9 && as -> inmod)
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
102 {
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
103 // calc the CRC
239
1106ec189e4f Acknowledge the source of the crc calc for os9
lost
parents: 238
diff changeset
104 // this is a direct transliteration from the nitros9 asm source
1106ec189e4f Acknowledge the source of the crc calc for os9
lost
parents: 238
diff changeset
105 // to C; it can, no doubt, be optimized for 32 bit processing
236
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
106 b &= 0xff;
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
107
238
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
108 b ^= (as -> crc)[0];
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
109 (as -> crc)[0] = (as -> crc)[1];
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
110 (as -> crc)[1] = (as -> crc)[2];
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
111 (as -> crc)[1] ^= (b >> 7);
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
112 (as -> crc)[2] = (b << 1);
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
113 (as -> crc)[1] ^= (b >> 2);
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
114 (as -> crc)[2] ^= (b << 6);
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
115 b ^= (b << 1);
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
116 b ^= (b << 2);
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
117 b ^= (b << 4);
236
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
118 if (b & 0x80)
238
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
119 {
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
120 (as -> crc)[0] ^= 0x80;
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
121 (as -> crc)[2] ^= 0x21;
a9a14e6b4bc8 Fixed os9 module CRC calculation
lost
parents: 236
diff changeset
122 }
236
a58f49a77441 Added os9 target, pragma to control whether $ localizes a symbol, and fixed some condition nesting bugs
lost
parents: 212
diff changeset
123 }
27
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
124 }
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
125
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
126 void lwasm_emitop(asmstate_t *as, lwasm_line_t *l, int o)
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
127 {
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
128 if (o >= 0x100)
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
129 lwasm_emit(as, l, o >> 8);
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
130 lwasm_emit(as, l, o & 0xff);
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
131 }
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
132
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
133 int lwasm_lookupreg2(const char *reglist, char **str)
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
134 {
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
135 int rval = 0;
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
136
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
137 while (*reglist)
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
138 {
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
139 if (toupper(**str) == *reglist)
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
140 {
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
141 // first char matches
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
142 if (reglist[1] == ' ' && !isalpha(*(*str + 1)))
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
143 break;
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
144 if (toupper(*(*str + 1)) == reglist[1])
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
145 break;
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
146 }
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
147 reglist += 2;
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
148 rval++;
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
149 }
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
150 if (!*reglist)
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
151 return -1;
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
152 if (reglist[1] == ' ')
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
153 (*str)++;
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
154 else
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
155 (*str) += 2;
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
156 return rval;
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
157 }
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
158
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
159 int lwasm_lookupreg3(const char *rlist, const char **str)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
160 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
161 int rval = 0;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
162 int f = 0;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
163 const char *reglist = rlist;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
164
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
165 while (*reglist)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
166 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
167 if (toupper(**str) == *reglist)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
168 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
169 // first char matches
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
170 if (reglist[1] == ' ')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
171 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
172 f = 1;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
173 break;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
174 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
175 if (toupper(*(*str + 1)) == reglist[1])
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
176 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
177 // second char matches
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
178 if (reglist[2] == ' ')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
179 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
180 f = 1;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
181 break;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
182 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
183 if (toupper(*(*str + 2)) == reglist[2])
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
184 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
185 f = 1;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
186 break;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
187 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
188 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
189 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
190 reglist += 3;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
191 rval++;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
192 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
193 if (f == 0)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
194 return -1;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
195
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
196
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
197 reglist = rval * 3 + rlist;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
198 if (reglist[1] == ' ')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
199 (*str) += 1;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
200 else if (reglist[2] == ' ')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
201 (*str) += 2;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
202 else
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
203 (*str)+=3;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
204 return rval;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 27
diff changeset
205 }
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
206
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
207 struct symstateinfo
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
208 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
209 asmstate_t *as;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
210 lwasm_line_t *l;
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
211 int flags;
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
212 };
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
213
76
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
214 lwasm_expr_stack_t *lwasm_expr_lookup_symbol(char *sym, void *state)
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
215 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
216 lwasm_symbol_ent_t *se;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
217 struct symstateinfo *st;
76
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
218 lwasm_expr_stack_t *rs;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
219 lwasm_expr_term_t *t;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
220 lwasm_expr_stack_node_t *n;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
221
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
222 int val;
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
223
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
224 st = state;
52
b9856da2674a Added file inclusion
lost
parents: 42
diff changeset
225 debug_message(3, "lwasm_expr_lookup_symbol(): find '%s' (context=%d)", sym, st -> as -> context);
b9856da2674a Added file inclusion
lost
parents: 42
diff changeset
226
60
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
227 // check for special symbols first...
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
228 if (sym[1] == '\0')
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
229 {
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
230 switch (sym[0])
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
231 {
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
232 // current line address
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
233 case '*':
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
234 case '.':
76
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
235 val = st -> l -> codeaddr;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
236 goto retconst;
60
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
237
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
238 case '<':
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
239 // previous branch point
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
240 // not implemented
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
241 break;
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
242 case '>':
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
243 // next branch point
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
244 // not implemented
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
245 break;
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
246 }
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
247 }
309810f39ab7 Implemented the * and . special symbols
lost
parents: 58
diff changeset
248
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
249 // look for local symbol first then global symbol
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
250 se = lwasm_find_symbol(st -> as, sym, st -> as -> context);
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
251 if (!se)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
252 se = lwasm_find_symbol(st -> as, sym, -1);
52
b9856da2674a Added file inclusion
lost
parents: 42
diff changeset
253 debug_message(3, "lwasm_expr_lookup_symbol(): got '%p'", se);
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
254 if (!se)
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
255 {
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
256 register_error(st -> as, st -> l, 2, "Undefined symbol '%s'", sym);
76
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
257 return NULL;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
258 }
92
ea2cfebef5d0 Make external symbols remain unresolved in expressions and also flag them in the symbol list
lost
parents: 84
diff changeset
259 // external reference - can not resolve it
ea2cfebef5d0 Make external symbols remain unresolved in expressions and also flag them in the symbol list
lost
parents: 84
diff changeset
260 if (se -> flags & SYMBOL_EXTERN)
ea2cfebef5d0 Make external symbols remain unresolved in expressions and also flag them in the symbol list
lost
parents: 84
diff changeset
261 {
ea2cfebef5d0 Make external symbols remain unresolved in expressions and also flag them in the symbol list
lost
parents: 84
diff changeset
262 return NULL;
ea2cfebef5d0 Make external symbols remain unresolved in expressions and also flag them in the symbol list
lost
parents: 84
diff changeset
263 }
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
264 if (st -> flags & EXPR_SECTCONST)
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
265 {
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
266 if (se -> sect == st -> l -> sect)
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
267 {
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
268 if (se -> expr)
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
269 goto retsym;
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
270 val = se -> value;
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
271 goto retconst;
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
272 }
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
273 }
93
34ca1c6e9550 Fixed symbol resolution to not resolve intra-section references to constants by default
lost
parents: 92
diff changeset
274 if (st -> as -> outformat == OUTPUT_OBJ && se -> sect != NULL)
34ca1c6e9550 Fixed symbol resolution to not resolve intra-section references to constants by default
lost
parents: 92
diff changeset
275 {
34ca1c6e9550 Fixed symbol resolution to not resolve intra-section references to constants by default
lost
parents: 92
diff changeset
276 return NULL;
34ca1c6e9550 Fixed symbol resolution to not resolve intra-section references to constants by default
lost
parents: 92
diff changeset
277 }
34ca1c6e9550 Fixed symbol resolution to not resolve intra-section references to constants by default
lost
parents: 92
diff changeset
278 if (st -> as -> outformat != OUTPUT_OBJ || se -> sect == NULL)
76
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
279 {
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
280 // global symbol, intrasegment reference, or not an object target
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
281 val = se -> value;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
282 goto retconst;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
283 }
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
284
76
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
285 // an intersegment reference will return as NULL (to be resolved at output/link time)
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
286 // if se -> expr is NULL, it has to be an intersegment reference here
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
287 if (se -> expr == NULL)
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
288 {
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
289 return NULL;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
290 }
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
291
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
292 retsym:
76
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
293 // duplicate the expression for return
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
294 rs = lwasm_expr_stack_create();
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
295 for (n = se -> expr -> head; n; n = n -> next)
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
296 {
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
297 lwasm_expr_stack_push(rs, n -> term);
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
298 }
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
299 return rs;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
300
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
301 retconst:
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
302 rs = lwasm_expr_stack_create();
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
303 t = lwasm_expr_term_create_int(val);
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
304 lwasm_expr_stack_push(rs, t);
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
305 lwasm_expr_term_free(t);
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
306 return rs;
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
307 }
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
308
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
309 lwasm_expr_stack_t *lwasm_evaluate_expr(asmstate_t *as, lwasm_line_t *l, const char *inp, const char **outp, int flags)
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
310 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
311 struct symstateinfo st;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
312
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
313 st.as = as;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
314 st.l = l;
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
315 st.flags = flags;
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
316
38
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
317 debug_message(2, "Evaluate expression: %s", inp);
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
318
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
319 return(lwasm_expr_eval(inp, outp, lwasm_expr_lookup_symbol, &st));
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
320 }
38
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
321
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
322
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
323 int lwasm_reevaluate_expr(asmstate_t *as, lwasm_line_t *l, lwasm_expr_stack_t *s, int flags)
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
324 {
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
325 struct symstateinfo st;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
326
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
327 st.as = as;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
328 st.l = l;
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
329 st.flags = flags;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
330 return(lwasm_expr_reval(s, lwasm_expr_lookup_symbol, &st));
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
331 }
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
332
76
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
333 // return 1 if no undefined symbols (externals and incompletes are okay)
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
334 // return 0 if there are undefined symbols
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
335 int lwasm_expr_result_ckconst(asmstate_t *as, lwasm_expr_stack_t *s)
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
336 {
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
337 lwasm_expr_stack_node_t *n;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
338 lwasm_symbol_ent_t *se;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
339
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
340 if (as -> outformat != OUTPUT_OBJ)
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
341 {
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
342 if (lwasm_expr_is_constant(s))
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
343 return 1;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
344 else
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
345 return 0;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
346 }
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
347
76
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
348 for (n = s -> head; n; n = n -> next)
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
349 {
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
350 if (n -> term -> term_type == LWASM_TERM_SYM)
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
351 {
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
352 se = lwasm_find_symbol(as, n -> term -> symbol, as -> context);
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
353 if (!se)
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
354 se = lwasm_find_symbol(as, n -> term -> symbol, -1);
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
355 if (!se)
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
356 return 0;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
357 }
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
358 }
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
359 return 1;
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
360 }
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
361
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
362 /*
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
363 Evaluate an expression according to the flag value. Return 0 if a constant result was
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
364 obtained, 1 if an incomplete result was obtained, and -1 if an error was flagged.
2fe5fd7d65a3 Checkpointing object target implementation
lost
parents: 74
diff changeset
365
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
366 */
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
367 int lwasm_expr_result2(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val, int slot)
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
368 {
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
369 lwasm_expr_stack_t *s = NULL;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
370 const char *ep;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
371 int rval;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
372
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
373 if ((as -> passnum == 1 && !(flag & EXPR_REEVAL)) || slot < 0)
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
374 {
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
375 s = lwasm_evaluate_expr(as, l, *inp, &ep, flag);
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
376 if (slot >= 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
377 l -> exprs[slot] = s;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
378 if (!s)
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
379 {
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
380 register_error(as, l, 1, "Bad expression");
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
381 *val = 0;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
382 return -1;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
383 }
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
384 *inp = (char *)ep;
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
385 if (slot >= 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
386 {
94
83ba34ed11b3 Fixed problem with constant expressions evaluating to 0 when they shouldn't
lost
parents: 93
diff changeset
387 l -> exprends[slot] = (char *)ep;
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
388 l -> exprvals[slot] = lwasm_expr_get_value(s);
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
389 }
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
390 }
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
391 else if (l -> exprs[slot])
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
392 {
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
393 s = l -> exprs[slot];
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 98
diff changeset
394 lwasm_reevaluate_expr(as, l, s, flag);
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
395 l -> exprvals[slot] = lwasm_expr_get_value(s);
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
396 }
84
e12edcfbebd5 Fixed problem with expression evaluation infrastructure not advancing input pointer on pass 2
lost
parents: 79
diff changeset
397 if (as -> passnum == 2 && slot >= 0)
e12edcfbebd5 Fixed problem with expression evaluation infrastructure not advancing input pointer on pass 2
lost
parents: 79
diff changeset
398 *inp = l -> exprends[slot];
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
399
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
400 if (s && lwasm_expr_is_constant(s))
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
401 {
94
83ba34ed11b3 Fixed problem with constant expressions evaluating to 0 when they shouldn't
lost
parents: 93
diff changeset
402 *val = lwasm_expr_get_value(s);
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
403 lwasm_expr_stack_free(s);
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
404 l -> exprs[slot] = NULL;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
405 s = NULL;
94
83ba34ed11b3 Fixed problem with constant expressions evaluating to 0 when they shouldn't
lost
parents: 93
diff changeset
406 return 0;
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
407 }
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
408
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
409 if (!s && slot >= 0)
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
410 {
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
411 *val = l -> exprvals[slot];
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
412 return 0;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
413 }
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
414 else if (!s)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
415 {
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
416 *val = 0;
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
417 return 0;
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
418 }
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
419
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
420 // was a constant result on pass 1 requested?
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
421 // that means we must have a constant on either pass
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
422 if (flag & EXPR_PASS1CONST)
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
423 {
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
424 *val = 0;
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
425 if (slot >= 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
426 l -> exprvals[slot] = 0;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
427 register_error(as, l, 1, "Illegal forward, external, or inter-section reference");
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
428 lwasm_expr_stack_free(s);
79
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
429 if (slot >= 0)
d0ce3f5f6797 Checkpointing deployment of non-constant expression handling
lost
parents: 78
diff changeset
430 l -> exprs[slot] = NULL;
78
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
431 return -1;
121bf4a588ea Checkpointing deployment of non-constant expression handling
lost
parents: 77
diff changeset
432 }
77
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
433
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
434 return 1;
a338d496350e Checkpointing conversion to allow object target
lost
parents: 76
diff changeset
435 }
55
8e32696380f3 added expression evaluation and checking function
lost
parents: 52
diff changeset
436
38
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
437 void debug_message(int level, const char *fmt, ...)
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
438 {
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
439 va_list args;
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
440
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
441 va_start(args, fmt);
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
442 if (debug_level >= level)
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
443 {
39
efa19ec69df9 tweaked debugging system for expression handler
lost
parents: 38
diff changeset
444 if (level > 0)
efa19ec69df9 tweaked debugging system for expression handler
lost
parents: 38
diff changeset
445 fprintf(stderr, "DEBUG %d: ", level);
38
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
446 vfprintf(stderr, fmt, args);
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
447 fputc('\n', stderr);
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
448 }
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
449 va_end(args);
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
450 }
57
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
451
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
452 int lwasm_next_context(asmstate_t *as)
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
453 {
58
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 57
diff changeset
454 int r;
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 57
diff changeset
455 r = as -> nextcontext;
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 57
diff changeset
456 as -> nextcontext += 1;
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 57
diff changeset
457 debug_message(3, "lwasm_next_context(): %d (%d) pass %d", r, as -> nextcontext, as -> passnum);
b1d81800bc91 Added symbol listing to list file; various fixes
lost
parents: 57
diff changeset
458 return r;
57
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
459 }
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
460