Mercurial > hg-old > index.cgi
comparison src/pseudo.c @ 56:55260a178667
Added from f* pseudo ops
author | lost |
---|---|
date | Sun, 04 Jan 2009 21:43:05 +0000 |
parents | 360d53062bb9 |
children | 035b95a3690f |
comparison
equal
deleted
inserted
replaced
55:8e32696380f3 | 56:55260a178667 |
---|---|
306 l -> symaddr = rval; | 306 l -> symaddr = rval; |
307 l -> addrset = 2; | 307 l -> addrset = 2; |
308 } | 308 } |
309 } | 309 } |
310 | 310 |
311 /* | 311 |
312 void pseudo_align(asmstate_t *as, sourceline_t *cl, char **optr) | 312 OPFUNC(pseudo_align) |
313 { | 313 { |
314 int rval, v1; | 314 int rval; |
315 lwasm_expr_stack_t *s; | |
315 int cn; | 316 int cn; |
316 | 317 |
317 rval = eval_expr(as, cl, optr, &v1); | 318 if (as -> passnum == 2) |
318 if (rval < 0) | 319 { |
319 { | 320 while (as -> addr < l -> symaddr) |
320 errorp1(ERR_FORWARD); | 321 lwasm_emit(as, l, 0); |
321 return; | 322 return; |
322 } | 323 } |
323 cn = cl -> addr % v1; | 324 |
325 s = lwasm_evaluate_expr(as, l, *p, NULL); | |
326 if (!s) | |
327 { | |
328 register_error(as, l, 1, "Bad expression"); | |
329 return; | |
330 } | |
331 if (!lwasm_expr_is_constant(s)) | |
332 { | |
333 register_error(as, l, 1, "Illegal incomplete reference (pass 1)"); | |
334 } | |
335 rval = lwasm_expr_get_value(s); | |
336 lwasm_expr_stack_free(s); | |
337 | |
338 if (rval < 1) | |
339 { | |
340 register_error(as, l, 1, "Illegal alignment %d", rval); | |
341 return; | |
342 } | |
343 | |
344 cn = l -> codeaddr % rval; | |
324 if (cn) | 345 if (cn) |
325 cn = v1 - cn; | 346 cn = rval - cn; |
326 | 347 |
327 while (cn) | 348 while (cn--) |
328 { | 349 { |
329 emit(0); | 350 lwasm_emit(as, l, 0); |
330 cn--; | 351 } |
331 } | 352 l -> symaddr = as -> addr; |
332 } | 353 } |
333 */ | 354 |
334 OPFUNC(pseudo_equ) | 355 OPFUNC(pseudo_equ) |
335 { | 356 { |
336 lwasm_expr_stack_t *s; | 357 lwasm_expr_stack_t *s; |
337 int rval; | 358 int rval; |
338 | 359 |
431 cl -> dpval = v1 & 0xff; | 452 cl -> dpval = v1 & 0xff; |
432 cl -> issetdp = 1; | 453 cl -> issetdp = 1; |
433 cl -> numcodebytes = 0; | 454 cl -> numcodebytes = 0; |
434 //printf("%s\n", "SETDP2"); | 455 //printf("%s\n", "SETDP2"); |
435 } | 456 } |
436 | 457 */ |
437 void pseudo_fcc(asmstate_t *as, sourceline_t *cl, char **optr) | 458 |
438 { | 459 OPFUNC(pseudo_fcc) |
439 int cn = 0; | 460 { |
440 int delim = 0; | 461 int delim = 0; |
441 | 462 |
442 delim = *(*optr)++; | 463 delim = **p; |
443 if (!delim) | 464 if (!delim) |
444 { | 465 { |
445 errorp1(ERR_BADOPER); | 466 register_error(as, l, 1, "Bad operand"); |
446 } | 467 return; |
447 else | 468 } |
448 { | 469 *p += 1; |
449 while (**optr && **optr != delim) | 470 while (**p && **p != delim) |
450 { | 471 { |
451 emit(**optr); | 472 lwasm_emit(as, l, **p); |
452 (*optr)++; | 473 (*p)++; |
453 cn += 1; | 474 } |
454 } | 475 if (**p) |
455 } | 476 (*p)++; |
456 cl -> len = cn; | |
457 } | 477 } |
458 | 478 |
459 void pseudo_fcs(asmstate_t *as, sourceline_t *cl, char **optr) | 479 |
460 { | 480 OPFUNC(pseudo_fcs) |
461 int cn = 0; | 481 { |
482 int delim = 0; | |
483 | |
484 delim = **p; | |
485 if (!delim) | |
486 { | |
487 register_error(as, l, 1, "Bad operand"); | |
488 return; | |
489 } | |
490 *p += 1; | |
491 while (**p && **p != delim) | |
492 { | |
493 if (!*((*p) + 1) || *((*p) + 1) == delim) | |
494 lwasm_emit(as, l, **p | 0x80); | |
495 else | |
496 lwasm_emit(as, l, **p); | |
497 (*p)++; | |
498 } | |
499 if (**p) | |
500 (*p)++; | |
501 } | |
502 | |
503 OPFUNC(pseudo_fcn) | |
504 { | |
462 int delim = 0; | 505 int delim = 0; |
463 | 506 |
464 delim = *(*optr)++; | 507 delim = **p; |
465 if (!delim) | 508 if (!delim) |
466 { | 509 { |
467 errorp1(ERR_BADOPER); | 510 register_error(as, l, 1, "Bad operand"); |
468 } | 511 return; |
469 else | 512 } |
470 { | 513 *p += 1; |
471 while (**optr && **optr != delim) | 514 while (**p && **p != delim) |
472 { | 515 { |
473 if (!*((*optr) + 1) || *((*optr) + 1) == delim) | 516 lwasm_emit(as, l, **p); |
474 emit((**optr) | 0x80); | 517 (*p)++; |
475 else | 518 } |
476 emit(**optr); | 519 if (**p) |
477 (*optr)++; | 520 (*p)++; |
478 cn += 1; | 521 lwasm_emit(as, l, 0); |
479 } | 522 } |
480 } | 523 |
481 cl -> len = cn; | 524 OPFUNC(pseudo_fcb) |
482 } | 525 { |
483 | 526 int v1; |
484 void pseudo_fcn(asmstate_t *as, sourceline_t *cl, char **optr) | |
485 { | |
486 int cn = 0; | |
487 int delim = 0; | |
488 | |
489 delim = *(*optr)++; | |
490 if (!delim) | |
491 { | |
492 errorp1(ERR_BADOPER); | |
493 } | |
494 else | |
495 { | |
496 while (**optr && **optr != delim) | |
497 { | |
498 emit(**optr); | |
499 (*optr)++; | |
500 cn += 1; | |
501 } | |
502 } | |
503 emit(0); | |
504 cl -> len = cn + 1; | |
505 } | |
506 | |
507 void pseudo_fcb(asmstate_t *as, sourceline_t *cl, char **optr) | |
508 { | |
509 int rval, v1; | |
510 | 527 |
511 fcb_again: | 528 fcb_again: |
512 rval = eval_expr(as, cl, optr, &v1); | 529 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST | EXPR_BYTE, &v1) < 0) |
513 if (v1 < -127 || v1 > 0xff) | 530 return; |
514 errorp2(ERR_OVERFLOW); | 531 |
515 emit(v1 & 0xff); | 532 lwasm_emit(as, l, v1); |
516 if (**optr == ',') | 533 if (**p == ',') |
517 { | 534 { |
518 (*optr)++; | 535 (*p)++; |
519 goto fcb_again; | 536 goto fcb_again; |
520 } | 537 } |
521 } | 538 } |
522 | 539 |
523 void pseudo_fdb(asmstate_t *as, sourceline_t *cl, char **optr) | 540 OPFUNC(pseudo_fdb) |
524 { | 541 { |
525 int rval, v1; | 542 int v1; |
526 | 543 |
527 fdb_again: | 544 fdb_again: |
528 rval = eval_expr(as, cl, optr, &v1); | 545 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0) |
529 emit((v1 >> 8) & 0xff); | 546 return; |
530 emit(v1 & 0xff); | 547 |
531 if (**optr == ',') | 548 lwasm_emit(as, l, v1 >> 8); |
532 { | 549 lwasm_emit(as, l, v1 & 0xff); |
533 (*optr)++; | 550 if (**p == ',') |
551 { | |
552 (*p)++; | |
534 goto fdb_again; | 553 goto fdb_again; |
535 } | 554 } |
536 } | 555 } |
537 | 556 |
538 void pseudo_fqb(asmstate_t *as, sourceline_t *cl, char **optr) | 557 OPFUNC(pseudo_fqb) |
539 { | 558 { |
540 int rval, v1; | 559 int v1; |
541 | 560 |
542 fqb_again: | 561 fqb_again: |
543 rval = eval_expr(as, cl, optr, &v1); | 562 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0) |
544 emit((v1 >> 24) & 0xff); | 563 return; |
545 emit((v1 >> 16) & 0xff); | 564 |
546 emit((v1 >> 8) & 0xff); | 565 lwasm_emit(as, l, v1 >> 24); |
547 emit(v1 & 0xff); | 566 lwasm_emit(as, l, v1 >> 16); |
548 if (**optr == ',') | 567 lwasm_emit(as, l, v1 >> 8); |
549 { | 568 lwasm_emit(as, l, v1 & 0xff); |
550 (*optr)++; | 569 if (**p == ',') |
570 { | |
571 (*p)++; | |
551 goto fqb_again; | 572 goto fqb_again; |
552 } | 573 } |
553 } | 574 } |
554 | 575 |
576 /* | |
555 // don't need to do anything if we are executing one of these | 577 // don't need to do anything if we are executing one of these |
556 void pseudo_endc(asmstate_t *as, sourceline_t *cl, char **optr) | 578 void pseudo_endc(asmstate_t *as, sourceline_t *cl, char **optr) |
557 { | 579 { |
558 return; | 580 return; |
559 } | 581 } |
679 as -> skipcond = 1; | 701 as -> skipcond = 1; |
680 as -> skipcount = 1; | 702 as -> skipcount = 1; |
681 } | 703 } |
682 } | 704 } |
683 } | 705 } |
684 | |
685 void pseudo_error(asmstate_t *as, sourceline_t *cl, char **optr) | |
686 { | |
687 cl -> user_error = strdup(*optr); | |
688 errorp1(ERR_USER); | |
689 } | |
690 */ | 706 */ |
707 | |
708 OPFUNC(pseudo_error) | |
709 { | |
710 register_error(as, l, 1, "User error: %s", *p); | |
711 } | |
712 |