Mercurial > hg-old > index.cgi
comparison lwasm/lwasm.c @ 347:1649bc7bda5a
Some data oriented pseudo ops added
author | lost@starbug |
---|---|
date | Sat, 27 Mar 2010 20:16:24 -0600 |
parents | a82c55070624 |
children | 11a95c6414b4 |
comparison
equal
deleted
inserted
replaced
346:a82c55070624 | 347:1649bc7bda5a |
---|---|
429 | 429 |
430 e = lw_expr_parse(p, as); | 430 e = lw_expr_parse(p, as); |
431 | 431 |
432 return e; | 432 return e; |
433 } | 433 } |
434 | |
435 void lwasm_save_expr(line_t *cl, int id, lw_expr_t expr) | |
436 { | |
437 struct line_expr_s *e; | |
438 | |
439 for (e = cl -> exprs; e; e = e -> next) | |
440 { | |
441 if (e -> id == id) | |
442 { | |
443 lw_expr_destroy(e -> expr); | |
444 e -> expr = expr; | |
445 return; | |
446 } | |
447 } | |
448 | |
449 e = lw_alloc(sizeof(struct line_expr_s)); | |
450 e -> expr = expr; | |
451 e -> id = id; | |
452 e -> next = cl -> exprs; | |
453 cl -> exprs = e; | |
454 } | |
455 | |
456 lw_expr_t lwasm_fetch_expr(line_t *cl, int id) | |
457 { | |
458 struct line_expr_s *e; | |
459 | |
460 for (e = cl -> exprs; e; e = e -> next) | |
461 { | |
462 if (e -> id == id) | |
463 { | |
464 return e -> expr; | |
465 } | |
466 } | |
467 return NULL; | |
468 } | |
469 | |
470 void skip_operand(char **p) | |
471 { | |
472 for (; **p && !isspace(**p); (*p)++) | |
473 /* do nothing */ ; | |
474 } | |
475 | |
476 int lwasm_emitexpr(line_t *l, lw_expr_t expr, int size) | |
477 { | |
478 int v; | |
479 | |
480 if (lw_expr_istype(expr, lw_expr_type_int)) | |
481 { | |
482 v = lw_expr_intval(expr); | |
483 } | |
484 else | |
485 { | |
486 lwasm_register_error(l -> as, l, "Expression not fully resolved"); | |
487 return -1; | |
488 } | |
489 | |
490 switch (size) | |
491 { | |
492 case 4: | |
493 lwasm_emit(l, v >> 24); | |
494 lwasm_emit(l, v >> 16); | |
495 /* fallthrough intended */ | |
496 | |
497 case 2: | |
498 lwasm_emit(l, v >> 8); | |
499 /* fallthrough intended */ | |
500 | |
501 case 1: | |
502 lwasm_emit(l, v); | |
503 } | |
504 | |
505 return 0; | |
506 } |