comparison modules/il.tp @ 195:7856f0916549

Add save il instruction to save callee saved registers in function prolog
author Mike Pavone <pavone@retrodev.com>
date Mon, 26 Aug 2013 21:04:44 -0700
parents 30bed95cbb18
children 49bca6487178
comparison
equal deleted inserted replaced
194:30bed95cbb18 195:7856f0916549
15 _ror <- 11 15 _ror <- 11
16 _mov <- 12 16 _mov <- 12
17 _call <- 13 17 _call <- 13
18 _ret <- 14 18 _ret <- 14
19 _skipif <- 15 19 _skipif <- 15
20 _save <- 16
20 21
21 _names <- #[ 22 _names <- #[
22 "add" 23 "add"
23 "and" 24 "and"
24 "or" 25 "or"
33 "ror" 34 "ror"
34 "mov" 35 "mov"
35 "call" 36 "call"
36 "ret" 37 "ret"
37 "skipIf" 38 "skipIf"
39 "save"
38 ] 40 ]
39 41
40 op3:a:b:out:size <- :_opcode :_ina :_inb :_out :_size { 42 op3:a:b:out:size <- :_opcode :_ina :_inb :_out :_size {
41 #{ 43 #{
42 opcode <- { _opcode } 44 opcode <- { _opcode }
392 } 394 }
393 skipIf: _cond newskip 395 skipIf: _cond newskip
394 } 396 }
395 } 397 }
396 } 398 }
399 save <- :regs :scope{
400 #{
401 opcode <- { _save }
402 numops <- { 0 }
403 name <- { _names get: _save }
404 string <- {
405 block <- scope join: "\n\t"
406 if: (scope length) > 0 {
407 block <- "\n\t" . block . "\n"
408 }
409 name . " " . (regs join: " ") . " {" . block . "}"
410 }
411 }
412 }
397 413
398 allocRegs:withSource <- :instarr:regSrc { 414 allocRegs:withSource <- :instarr:regSrc {
399 _regMap <- dict linear 415 _regMap <- dict linear
400 _argMap <- dict linear 416 _argMap <- dict linear
401 417
522 print: "\n\nAssignments:\n\n" 538 print: "\n\nAssignments:\n\n"
523 foreach: _assignments :reg assign { 539 foreach: _assignments :reg assign {
524 print: (string: reg) . " = " . assign . "\n" 540 print: (string: reg) . " = " . assign . "\n"
525 } 541 }
526 542
527 //TODO: Save callee saved regs 543 withassign <- map: instarr :inst {
528 map: instarr :inst {
529 inst assignRegs: _assignments withSource: regSrc 544 inst assignRegs: _assignments withSource: regSrc
530 } 545 }
546 psave <- regSrc needSaveProlog
547 print: "Regs that need saving in prolog: " . (psave join: ",") . "\n"
548 if: (psave length) > 0 {
549 withassign <- #[save: psave withassign]
550 }
551 withassign
531 } 552 }
532 553
533 //used to convert IL to a format suitable for a 2-operand architecture 554 //used to convert IL to a format suitable for a 2-operand architecture
534 //should be run after register allocation (I think....) 555 //should be run after register allocation (I think....)
535 to2Op <- :instarr { 556 to2Op <- :instarr {