comparison src/pseudo.c @ 79:d0ce3f5f6797

Checkpointing deployment of non-constant expression handling
author lost
date Sat, 10 Jan 2009 07:09:14 +0000
parents 121bf4a588ea
children 03be43ae19cf
comparison
equal deleted inserted replaced
78:121bf4a588ea 79:d0ce3f5f6797
286 v = 0; 286 v = 0;
287 287
288 l -> symaddr = v & 0xFFFF; 288 l -> symaddr = v & 0xFFFF;
289 l -> addrset = 2; 289 l -> addrset = 2;
290 290
291 // note: we need to do this because the symbol might have resolved
292 // to a constant!
291 lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_FORCE); 293 lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_FORCE);
292 } 294 }
293 295
294 OPFUNC(pseudo_set) 296 OPFUNC(pseudo_set)
295 { 297 {
296 int rval; 298 int r, v;
297 299
298 // set MUST run on both passes as the symbol value changes! 300 // set MUST run on both passes as the symbol value changes!
299 301
300 if (l -> sym == NULL) 302 if (l -> sym == NULL)
301 { 303 {
302 register_error(as, l, 1, "No symbol specified"); 304 register_error(as, l, 1, "No symbol specified");
303 return; 305 return;
304 } 306 }
305 307
306 if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST | EXPR_PASS2CONST, &rval) < 0) 308 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
307 rval = 0; 309 if (r < 0)
308 310 v = 0;
309 l -> symaddr = rval & 0xFFFF; 311
312 l -> symaddr = v & 0xFFFF;
310 l -> addrset = 2; 313 l -> addrset = 2;
311 314
312 lwasm_register_symbol(as, l, l -> sym, rval, SYMBOL_SET); 315 lwasm_register_symbol(as, l, l -> sym, v, (r > 0 ? SYMBOL_COMPLEX: SYMBOL_NORM) | SYMBOL_SET);
313 } 316 }
314 317
315 OPFUNC(pseudo_setdp) 318 OPFUNC(pseudo_setdp)
316 { 319 {
317 int rval; 320 int r, v;
318 321
319 // setdp is needed on both passes 322 if (as -> outformat == OUTPUT_OBJ)
320 if (lwasm_expr_result(as, l, p, EXPR_PASS1CONST | EXPR_PASS2CONST | EXPR_BYTE, &rval) < 0) 323 {
321 rval = 0; 324 register_error(as, l, 1, "SETDP not permitted with OBJ target");
322 325 return;
323 l -> symaddr = rval & 0xFF; 326 }
327
328 // setdp is needed on both passes; must resolve to a constant on pass 1
329 r = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v, 0);
330 if (r != 0)
331 return;
332
333 if (v < -127 || v > 255)
334 {
335 register_error(as, l, 1, "Byte overflow");
336 return;
337 }
338
339 l -> symaddr = v & 0xFF;
324 l -> addrset = 2; 340 l -> addrset = 2;
325 341
326 as -> dpval = rval & 0xFF; 342 as -> dpval = v & 0xFF;
327 } 343 }
328 344
329 OPFUNC(pseudo_fcc) 345 OPFUNC(pseudo_fcc)
330 { 346 {
331 int delim = 0; 347 int delim = 0;
389 if (**p) 405 if (**p)
390 (*p)++; 406 (*p)++;
391 lwasm_emit(as, l, 0); 407 lwasm_emit(as, l, 0);
392 } 408 }
393 409
410 // FIXME: handle external, etc., references in a useful manner
394 OPFUNC(pseudo_fcb) 411 OPFUNC(pseudo_fcb)
395 { 412 {
396 int v1; 413 int r, v;
397 414
398 fcb_again: 415 fcb_again:
399 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST | EXPR_BYTE, &v1) < 0) 416 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
400 return; 417 if (r < 0)
401 418 return;
402 lwasm_emit(as, l, v1); 419
420 if (r > 0)
421 {
422 register_error(as, l, 2, "Illegal external or inter-segment reference");
423 v = 0;
424 }
425
426 if (v < -127 || v > 255)
427 {
428 register_error(as, l, 1, "Byte overflow");
429 }
430
431 lwasm_emit(as, l, v);
403 if (**p == ',') 432 if (**p == ',')
404 { 433 {
405 (*p)++; 434 (*p)++;
406 goto fcb_again; 435 goto fcb_again;
407 } 436 }
408 } 437 }
409 438
439 // FIXME: handle external references in an intelligent way
410 OPFUNC(pseudo_fdb) 440 OPFUNC(pseudo_fdb)
411 { 441 {
412 int v1; 442 int r, v;
413 443
414 fdb_again: 444 fdb_again:
415 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0) 445 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
416 return; 446 if (r < 0)
417 447 return;
418 lwasm_emit(as, l, v1 >> 8); 448
419 lwasm_emit(as, l, v1 & 0xff); 449 if (r > 0)
450 {
451 register_error(as, l, 2, "Illegal external or inter-segment reference");
452 v = 0;
453 }
454
455 lwasm_emit(as, l, v >> 8);
456 lwasm_emit(as, l, v & 0xff);
420 if (**p == ',') 457 if (**p == ',')
421 { 458 {
422 (*p)++; 459 (*p)++;
423 goto fdb_again; 460 goto fdb_again;
424 } 461 }
425 } 462 }
426 463
464 // FIXME: handle external references in a sensible way
427 OPFUNC(pseudo_fqb) 465 OPFUNC(pseudo_fqb)
428 { 466 {
429 int v1; 467 int r, v;
430 468
431 fqb_again: 469 fqb_again:
432 if (lwasm_expr_result(as, l, p, EXPR_PASS2CONST, &v1) < 0) 470 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
433 return; 471 if (r < 0)
434 472 return;
435 lwasm_emit(as, l, v1 >> 24); 473
436 lwasm_emit(as, l, v1 >> 16); 474 if (r > 0)
437 lwasm_emit(as, l, v1 >> 8); 475 {
438 lwasm_emit(as, l, v1 & 0xff); 476 register_error(as, l, 2, "Illegal external or inter-segment reference");
477 v = 0;
478 }
479
480 lwasm_emit(as, l, v >> 24);
481 lwasm_emit(as, l, v >> 16);
482 lwasm_emit(as, l, v >> 8);
483 lwasm_emit(as, l, v & 0xff);
439 if (**p == ',') 484 if (**p == ',')
440 { 485 {
441 (*p)++; 486 (*p)++;
442 goto fqb_again; 487 goto fqb_again;
443 } 488 }
486 { 531 {
487 as -> skipcount++; 532 as -> skipcount++;
488 return; 533 return;
489 } 534 }
490 535
491 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); 536 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
492 if (rval < 0) 537 if (rval != 0)
493 return; 538 return;
494 if (!v1) 539 if (!v1)
495 { 540 {
496 as -> skipcond = 1; 541 as -> skipcond = 1;
497 as -> skipcount = 1; 542 as -> skipcount = 1;
507 { 552 {
508 as -> skipcount++; 553 as -> skipcount++;
509 return; 554 return;
510 } 555 }
511 556
512 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); 557 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
513 if (rval < 0) 558 if (rval != 0)
514 return; 559 return;
515 if (v1) 560 if (v1)
516 { 561 {
517 as -> skipcond = 1; 562 as -> skipcond = 1;
518 as -> skipcount = 1; 563 as -> skipcount = 1;
528 { 573 {
529 as -> skipcount++; 574 as -> skipcount++;
530 return; 575 return;
531 } 576 }
532 577
533 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); 578 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
534 if (rval < 0) 579 if (rval != 0)
535 return; 580 return;
536 if (v1 >= 0) 581 if (v1 >= 0)
537 { 582 {
538 as -> skipcond = 1; 583 as -> skipcond = 1;
539 as -> skipcount = 1; 584 as -> skipcount = 1;
549 { 594 {
550 as -> skipcount++; 595 as -> skipcount++;
551 return; 596 return;
552 } 597 }
553 598
554 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); 599 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
555 if (rval < 0) 600 if (rval != 0)
556 return; 601 return;
557 if (v1 > 0) 602 if (v1 > 0)
558 { 603 {
559 as -> skipcond = 1; 604 as -> skipcond = 1;
560 as -> skipcount = 1; 605 as -> skipcount = 1;
570 { 615 {
571 as -> skipcount++; 616 as -> skipcount++;
572 return; 617 return;
573 } 618 }
574 619
575 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); 620 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
576 if (rval < 0) 621 if (rval != 0)
577 return; 622 return;
578 if (v1 <= 0) 623 if (v1 <= 0)
579 { 624 {
580 as -> skipcond = 1; 625 as -> skipcond = 1;
581 as -> skipcount = 1; 626 as -> skipcount = 1;
591 { 636 {
592 as -> skipcount++; 637 as -> skipcount++;
593 return; 638 return;
594 } 639 }
595 640
596 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1); 641 rval = lwasm_expr_result2(as, l, p, EXPR_PASS1CONST, &v1, 0);
597 if (rval < 0) 642 if (rval != 0)
598 return; 643 return;
599 if (v1 < 0) 644 if (v1 < 0)
600 { 645 {
601 as -> skipcond = 1; 646 as -> skipcond = 1;
602 as -> skipcount = 1; 647 as -> skipcount = 1;