comparison modules/il.tp @ 348:a840e9a068a2

Get sample builtin to il module working again
author Michael Pavone <pavone@retrodev.com>
date Fri, 10 Apr 2015 00:48:42 -0700
parents f987bb2a1911
children a3b06d53bcb9
comparison
equal deleted inserted replaced
347:ff7ea11b4b60 348:a840e9a068a2
372 if: (not: (_target isString?)) { 372 if: (not: (_target isString?)) {
373 //TODO: use size l for 32-bit targets or an abstract pointer size 373 //TODO: use size l for 32-bit targets or an abstract pointer size
374 _target recordUsage: tracker at: address withSize: q 374 _target recordUsage: tracker at: address withSize: q
375 } 375 }
376 foreach: _args :_ arg { 376 foreach: _args :_ arg {
377 //TODO: have some mechanism for properly expressing sizes of arguments 377 if: (not: (arg isInteger?)) {
378 arg recordUsage: tracker at: address withSize: q 378 //TODO: have some mechanism for properly expressing sizes of arguments
379 arg recordUsage: tracker at: address withSize: q
380 }
379 } 381 }
380 } 382 }
381 assignRegs:at:withSource:andUsage <- :assignments :address :regSrc :usage { 383 assignRegs:at:withSource:andUsage <- :assignments :address :regSrc :usage {
382 newtarget <- if: (_target isString?) { _target } else: { 384 newtarget <- if: (_target isString?) { _target } else: {
383 _target assign: assignments withSource: regSrc 385 _target assign: assignments withSource: regSrc
513 numops <- { 0 } 515 numops <- { 0 }
514 516
515 } 517 }
516 } 518 }
517 519
518 allocRegs:withSource <- :instarr:regSrc { 520 allocRegs:withSource <- :instarr :regSrc {
519 _regMap <- dict linear 521 _regMap <- dict linear
520 _argMap <- dict linear 522 _argMap <- dict linear
521 523
522 _usageTracker <- :_firstUsage { 524 _usageTracker <- :_firstUsage {
523 #{ 525 #{
540 542
541 _maxUses <- 0 543 _maxUses <- 0
542 liveFrom:to <- :regs :from :to { 544 liveFrom:to <- :regs :from :to {
543 live <- #[] 545 live <- #[]
544 foreach: regs :reg usage { 546 foreach: regs :reg usage {
545 if: ((usage lastUsage) addrGreatEq: from) && ((usage firstUsage) addrLessEq: to) { 547 if: (addrGreatEq: (usage lastUsage) from) && (addrLessEq: (usage firstUsage) to) {
546 live append: reg 548 live append: reg
547 } 549 }
548 } 550 }
549 live 551 live
550 } 552 }
566 } 568 }
567 usage usedAt: raddress withSize: size 569 usage usedAt: raddress withSize: size
568 } 570 }
569 571
570 liveRegsAt <- :address { 572 liveRegsAt <- :address {
571 _regMap liveFrom: address to: address 573 liveFrom: _regMap address to: address
572 } 574 }
573 liveArgsAt <- :address { 575 liveArgsAt <- :address {
574 _argMap liveFrom: address to: address 576 liveFrom: _argMap address to: address
575 } 577 }
576 578
577 print <- { 579 print <- {
578 foreach: _regMap :reg usage { 580 foreach: _regMap :reg usage {
579 print: (string: reg) . " | " . (string: usage) . "\n" 581 print: (string: reg) . " | " . (string: usage) . "\n"
625 _assignments <- dict linear 627 _assignments <- dict linear
626 curuses <- _maxUses 628 curuses <- _maxUses
627 while: { curuses > 0 && (_assignments length) < (_regMap length) } do: { 629 while: { curuses > 0 && (_assignments length) < (_regMap length) } do: {
628 foreach: _regMap :reg usage { 630 foreach: _regMap :reg usage {
629 if: (usage useCount) = curuses { 631 if: (usage useCount) = curuses {
630 liveArgs <- _argMap liveFrom: (usage firstUsage) to: (usage lastUsage) 632 liveArgs <- liveFrom: _argMap (usage firstUsage) to: (usage lastUsage)
631 foreach: liveArgs :_ arg { 633 foreach: liveArgs :_ arg {
632 regSrc allocArg: (arg num) 634 regSrc allocArg: (arg num)
633 } 635 }
634 636
635 liveRegs <- _regMap liveFrom: (usage firstUsage) to: (usage lastUsage) 637 liveRegs <- liveFrom: _regMap (usage firstUsage) to: (usage lastUsage)
636 print: (string: reg) . " | Live: " . (liveRegs join: ", ") . ", Live Args: " . (liveArgs join: ", ") . "\n" 638 print: (string: reg) . " | Live: " . (liveRegs join: ", ") . ", Live Args: " . (liveArgs join: ", ") . "\n"
637 foreach: liveRegs :_ reg { 639 foreach: liveRegs :_ reg {
638 if: (_assignments contains?: reg) { 640 if: (_assignments contains?: reg) {
639 regSrc allocSpecific: (_assignments get: reg) 641 regSrc allocSpecific: (_assignments get: reg)
640 } 642 }
703 } 705 }
704 outprog <- #[] 706 outprog <- #[]
705 foreach: prepped :name instarr { 707 foreach: prepped :name instarr {
706 outprog append: (labels get: name) 708 outprog append: (labels get: name)
707 foreach: instarr :_ inst { 709 foreach: instarr :_ inst {
710 print: "Translating: " . inst . "\n"
708 backend convertIL: inst to: outprog withLabels: labels 711 backend convertIL: inst to: outprog withLabels: labels
709 } 712 }
710 } 713 }
711 outprog 714 outprog
712 } 715 }
730 foreach: fib :idx inst { 733 foreach: fib :idx inst {
731 print: (string: inst) . "\n" 734 print: (string: inst) . "\n"
732 } 735 }
733 prog set: "fib" fib 736 prog set: "fib" fib
734 737
735 mprog <- prog toBackend: x86 738 mprog <- toBackend: prog x86
739 foreach: mprog :_ inst {
740 print: (string: inst) . "\n"
741 }
736 ba <- bytearray executableFromBytes: mprog 742 ba <- bytearray executableFromBytes: mprog
737 res <- ba runWithArg: 30u64 743 res <- if: (ba length) = 0 {
744 print: "Failed to translate code\n"
745 -1
746 } else: {
747 ba runWithArg: 30u64
748 }
738 print: (string: res) . "\n" 749 print: (string: res) . "\n"
739 0 750 0
740 } 751 }
741 } 752 }
742 } 753 }