comparison lwasm/pseudo.c @ 349:dcd2978a7d18

More pseudo ops
author lost@starbug
date Sat, 27 Mar 2010 22:44:46 -0600
parents 11a95c6414b4
children f5666775d76f
comparison
equal deleted inserted replaced
348:11a95c6414b4 349:dcd2978a7d18
21 21
22 #include <config.h> 22 #include <config.h>
23 23
24 #include "lwasm.h" 24 #include "lwasm.h"
25 #include "instab.h" 25 #include "instab.h"
26
27 #include "lw_string.h"
26 28
27 // for "end" 29 // for "end"
28 PARSEFUNC(pseudo_parse_end) 30 PARSEFUNC(pseudo_parse_end)
29 { 31 {
30 lw_expr_t addr; 32 lw_expr_t addr;
158 { 160 {
159 e = lwasm_fetch_expr(l, i); 161 e = lwasm_fetch_expr(l, i);
160 lwasm_emitexpr(l, e, 4); 162 lwasm_emitexpr(l, e, 4);
161 } 163 }
162 } 164 }
165
166 PARSEFUNC(pseudo_parse_fcc)
167 {
168 char delim;
169 int i;
170
171 if (!**p)
172 {
173 lwasm_register_error(as, l, "Bad operand");
174 return;
175 }
176
177 delim = **p;
178 (*p)++;
179
180 for (i = 0; (*p)[i] && (*p)[i] != delim; i++)
181 /* do nothing */ ;
182
183 if ((*p)[i] != delim)
184 {
185 lwasm_register_error(as, l, "Bad operand");
186 return;
187 }
188
189 l -> lstr = lw_strndup(*p, i);
190 (*p) += i + 1;
191
192 l -> len = i;
193 }
194
195 EMITFUNC(pseudo_emit_fcc)
196 {
197 int i;
198
199 for (i = 0; i < l -> len; i++)
200 lwasm_emit(l, l -> lstr[i]);
201 }
202
203 PARSEFUNC(pseudo_parse_fcs)
204 {
205 char delim;
206 int i;
207
208 if (!**p)
209 {
210 lwasm_register_error(as, l, "Bad operand");
211 return;
212 }
213
214 delim = **p;
215 (*p)++;
216
217 for (i = 0; (*p)[i] && (*p)[i] != delim; i++)
218 /* do nothing */ ;
219
220 if ((*p)[i] != delim)
221 {
222 lwasm_register_error(as, l, "Bad operand");
223 return;
224 }
225
226 l -> lstr = lw_strndup(*p, i);
227 (*p) += i + 1;
228
229 l -> len = i;
230 }
231
232 EMITFUNC(pseudo_emit_fcs)
233 {
234 int i;
235
236 for (i = 0; i < l -> len - 1; i++)
237 lwasm_emit(l, l -> lstr[i]);
238 lwasm_emit(l, l -> lstr[i] | 0x80);
239 }
240
241 PARSEFUNC(pseudo_parse_fcn)
242 {
243 char delim;
244 int i;
245
246 if (!**p)
247 {
248 lwasm_register_error(as, l, "Bad operand");
249 return;
250 }
251
252 delim = **p;
253 (*p)++;
254
255 for (i = 0; (*p)[i] && (*p)[i] != delim; i++)
256 /* do nothing */ ;
257
258 if ((*p)[i] != delim)
259 {
260 lwasm_register_error(as, l, "Bad operand");
261 return;
262 }
263
264 l -> lstr = lw_strndup(*p, i);
265 (*p) += i + 1;
266
267 l -> len = i;
268 }
269
270 EMITFUNC(pseudo_emit_fcn)
271 {
272 int i;
273
274 for (i = 0; i < l -> len; i++)
275 lwasm_emit(l, l -> lstr[i]);
276 lwasm_emit(l, 0);
277 }
278
279 PARSEFUNC(pseudo_parse_rmb)
280 {
281 lw_expr_t expr;
282
283 expr = lwasm_parse_expr(as, p);
284 if (!expr)
285 {
286 lwasm_register_error(as, l, "Bad expression");
287 }
288
289 lwasm_save_expr(l, 0, expr);
290 }
291
292 RESOLVEFUNC(pseudo_resolve_rmb)
293 {
294 lw_expr_t expr;
295
296 if (l -> len >= 0)
297 return;
298
299 expr = lwasm_fetch_expr(l, 0);
300
301 if (lw_expr_istype(expr, lw_expr_type_int))
302 {
303 l -> len = lw_expr_intval(expr);
304 }
305 }
306
307 EMITFUNC(pseudo_emit_rmb)
308 {
309 if (l -> len < 0)
310 lwasm_register_error(as, l, "Expression not constant");
311 }
312
313 PARSEFUNC(pseudo_parse_rmd)
314 {
315 lw_expr_t expr;
316
317 expr = lwasm_parse_expr(as, p);
318 if (!expr)
319 {
320 lwasm_register_error(as, l, "Bad expression");
321 }
322
323 lwasm_save_expr(l, 0, expr);
324 }
325
326 RESOLVEFUNC(pseudo_resolve_rmd)
327 {
328 lw_expr_t expr;
329
330 if (l -> len >= 0)
331 return;
332
333 expr = lwasm_fetch_expr(l, 0);
334
335 if (lw_expr_istype(expr, lw_expr_type_int))
336 {
337 l -> len = lw_expr_intval(expr) * 2;
338 }
339 }
340
341 EMITFUNC(pseudo_emit_rmd)
342 {
343 if (l -> len < 0)
344 lwasm_register_error(as, l, "Expression not constant");
345 }
346
347
348 PARSEFUNC(pseudo_parse_rmq)
349 {
350 lw_expr_t expr;
351
352 expr = lwasm_parse_expr(as, p);
353 if (!expr)
354 {
355 lwasm_register_error(as, l, "Bad expression");
356 }
357
358 lwasm_save_expr(l, 0, expr);
359 }
360
361 RESOLVEFUNC(pseudo_resolve_rmq)
362 {
363 lw_expr_t expr;
364
365 if (l -> len >= 0)
366 return;
367
368 expr = lwasm_fetch_expr(l, 0);
369
370 if (lw_expr_istype(expr, lw_expr_type_int))
371 {
372 l -> len = lw_expr_intval(expr) * 4;
373 }
374 }
375
376 EMITFUNC(pseudo_emit_rmq)
377 {
378 if (l -> len < 0)
379 lwasm_register_error(as, l, "Expression not constant");
380 }
381
382
383 PARSEFUNC(pseudo_parse_zmq)
384 {
385 lw_expr_t expr;
386
387 expr = lwasm_parse_expr(as, p);
388 if (!expr)
389 {
390 lwasm_register_error(as, l, "Bad expression");
391 }
392
393 lwasm_save_expr(l, 0, expr);
394 }
395
396 RESOLVEFUNC(pseudo_resolve_zmq)
397 {
398 lw_expr_t expr;
399
400 if (l -> len >= 0)
401 return;
402
403 expr = lwasm_fetch_expr(l, 0);
404
405 if (lw_expr_istype(expr, lw_expr_type_int))
406 {
407 l -> len = lw_expr_intval(expr) * 4;
408 }
409 }
410
411 EMITFUNC(pseudo_emit_zmq)
412 {
413 int i;
414
415 if (l -> len < 0)
416 {
417 lwasm_register_error(as, l, "Expression not constant");
418 return;
419 }
420
421 for (i = 0; i < l -> len; i++)
422 lwasm_emit(l, 0);
423 }
424
425
426 PARSEFUNC(pseudo_parse_zmd)
427 {
428 lw_expr_t expr;
429
430 expr = lwasm_parse_expr(as, p);
431 if (!expr)
432 {
433 lwasm_register_error(as, l, "Bad expression");
434 }
435
436 lwasm_save_expr(l, 0, expr);
437 }
438
439 RESOLVEFUNC(pseudo_resolve_zmd)
440 {
441 lw_expr_t expr;
442
443 if (l -> len >= 0)
444 return;
445
446 expr = lwasm_fetch_expr(l, 0);
447
448 if (lw_expr_istype(expr, lw_expr_type_int))
449 {
450 l -> len = lw_expr_intval(expr) * 2;
451 }
452 }
453
454 EMITFUNC(pseudo_emit_zmd)
455 {
456 int i;
457
458 if (l -> len < 0)
459 {
460 lwasm_register_error(as, l, "Expression not constant");
461 return;
462 }
463
464 for (i = 0; i < l -> len; i++)
465 lwasm_emit(l, 0);
466 }
467
468 PARSEFUNC(pseudo_parse_zmb)
469 {
470 lw_expr_t expr;
471
472 expr = lwasm_parse_expr(as, p);
473 if (!expr)
474 {
475 lwasm_register_error(as, l, "Bad expression");
476 }
477
478 lwasm_save_expr(l, 0, expr);
479 }
480
481 RESOLVEFUNC(pseudo_resolve_zmb)
482 {
483 lw_expr_t expr;
484
485 if (l -> len >= 0)
486 return;
487
488 expr = lwasm_fetch_expr(l, 0);
489
490 if (lw_expr_istype(expr, lw_expr_type_int))
491 {
492 l -> len = lw_expr_intval(expr);
493 }
494 }
495
496 EMITFUNC(pseudo_emit_zmb)
497 {
498 int i;
499
500 if (l -> len < 0)
501 {
502 lwasm_register_error(as, l, "Expression not constant");
503 return;
504 }
505
506 for (i = 0; i < l -> len; i++)
507 lwasm_emit(l, 0);
508 }