comparison modules/il.tp @ 315:f987bb2a1911

WIP native compiler work
author Michael Pavone <pavone@retrodev.com>
date Sat, 14 Mar 2015 12:10:51 -0700
parents 2308336790d4
children a840e9a068a2
comparison
equal deleted inserted replaced
314:d4df33596e7d 315:f987bb2a1911
2 //commutative ops 2 //commutative ops
3 _add <- 0 3 _add <- 0
4 _and <- 1 4 _and <- 1
5 _or <- 2 5 _or <- 2
6 _xor <- 3 6 _xor <- 3
7 _mul <- 4 7 _muls <- 4
8 _mulu <- 5
8 //non-commutative ops 9 //non-commutative ops
9 _div <- 5 10 _divs <- 6
10 _sub <- 6 11 _divu <- 7
11 _cmp <- 7 12 _sub <- 8
12 _not <- 8 13 _cmp <- 9
13 _sl <- 9 14 _not <- 10
14 _asr <- 10 15 _sl <- 11
15 _lsr <- 11 16 _asr <- 12
16 _rol <- 12 17 _lsr <- 13
17 _ror <- 13 18 _rol <- 14
18 _mov <- 14 19 _ror <- 15
19 _call <- 15 20 _mov <- 16
20 _ret <- 16 21 _call <- 17
21 _skipif <- 17 22 _ret <- 18
22 _save <- 18 23 _skipif <- 19
23 _bool <- 19 24 _skipifelse <- 20
25 _save <- 21
26 _bool <- 22
24 27
25 _names <- #[ 28 _names <- #[
26 "add" 29 "add"
27 "and" 30 "and"
28 "or" 31 "or"
29 "xor" 32 "xor"
30 "mul" 33 "muls"
31 "div" 34 "mulu"
35 "divs"
36 "divu"
32 "sub" 37 "sub"
33 "cmp" 38 "cmp"
34 "not" 39 "not"
35 "sl" 40 "sl"
36 "asr" 41 "asr"
39 "ror" 44 "ror"
40 "mov" 45 "mov"
41 "call" 46 "call"
42 "ret" 47 "ret"
43 "skipIf" 48 "skipIf"
49 "skipIf:else"
44 "save" 50 "save"
45 "bool" 51 "bool"
46 ] 52 ]
47 53
48 op3:a:b:out:size <- :_opcode :_ina :_inb :_out :_size { 54 op3:a:b:out:size <- :_opcode :_ina :_inb :_out :_size {
49 #{ 55 #{
50 opcode <- { _opcode } 56 opcode <- { _opcode }
51 ina <- { _ina } 57 ina <- { _ina }
52 inb <- { _inb } 58 inb <- { _inb }
53 commutative? <- { _opcode < _sub } 59 commutative? <- { _opcode < _divs }
54 out <- { _out } 60 out <- { _out }
55 size <- { _size } 61 size <- { _size }
56 numops <- { 3 } 62 numops <- { 3 }
57 name <- { _names get: _opcode } 63 name <- { _names get: _opcode }
58 string <- { name . " " . (string: _ina) . " " . (string: _inb) . " " . (string: _out) . " " . (string: _size) } 64 string <- { name . " " . (string: _ina) . " " . (string: _inb) . " " . (string: _out) . " " . (string: _size) }
287 293
288 sub <- :ina inb out size { 294 sub <- :ina inb out size {
289 op3: _sub a: ina b: inb out: out size: size 295 op3: _sub a: ina b: inb out: out size: size
290 } 296 }
291 297
292 cmp <- :ina inb out size { 298 cmp <- :ina inb size {
293 op3: _cmp a: ina b: inb out: out size: size 299 op2: _cmp a: ina out: inb size: size
294 } 300 }
295 301
296 and <- :ina inb out size { 302 band <- :ina inb out size {
297 op3: _and a: ina b: inb out: out size: size 303 op3: _and a: ina b: inb out: out size: size
298 } 304 }
299 305
300 or <- :ina inb out size { 306 bor <- :ina inb out size {
301 op3: _or a: ina b: inb out: out size: size 307 op3: _or a: ina b: inb out: out size: size
302 } 308 }
303 309
304 xor <- :ina inb out size { 310 bxor <- :ina inb out size {
305 op3: _xor a: ina b: inb out: out size: size 311 op3: _xor a: ina b: inb out: out size: size
306 } 312 }
307 313
308 mul <- :ina inb out size { 314 muls <- :ina inb out size {
309 op3: _mul a: ina b: inb out: out size: size 315 op3: _muls a: ina b: inb out: out size: size
310 } 316 }
311 317
312 div <- :ina inb out size { 318 mulu <- :ina inb out size {
313 op3: _div a: ina b: inb out: out size: size 319 op3: _mulu a: ina b: inb out: out size: size
320 }
321
322 divs <- :ina inb out size {
323 op3: _divs a: ina b: inb out: out size: size
324 }
325
326 divu <- :ina inb out size {
327 op3: _divu a: ina b: inb out: out size: size
314 } 328 }
315 329
316 bnot <- :in out size { 330 bnot <- :in out size {
317 op2: _not in: in out: out size: size 331 op2: _not in: in out: out size: size
318 } 332 }
424 to2OpInst <- { 438 to2OpInst <- {
425 skipIf: _cond (to2Op: _toskip) 439 skipIf: _cond (to2Op: _toskip)
426 } 440 }
427 } 441 }
428 } 442 }
443 skipIf:else <- :_cond _toskip :_else {
444 #{
445 opcode <- { _skipif }
446 toskip <- { _toskip }
447 else <- { _else }
448 cond <- { _cond }
449 numops <- { 0 }
450 name <- { _names get: _skipifelse }
451 string <- {
452 block <- (_toskip map: :el { string: el }) join: "\n\t"
453 if: (_toskip length) > 0 {
454 block <- "\n\t" . block . "\n"
455 }
456 elseblock <- (_else map: :el { string: el }) join: "\n\t"
457 if: (_else length) > 0 {
458 elseblock <- "\n\t" . elseblock . "\n"
459 }
460 name . " " . (string: _cond) . " {" . block . "} {" . elseblock . "}"
461 }
462 recordUsage:at <- :tracker :address {
463 foreach: _toskip :idx inst {
464 inst recordUsage: tracker at: idx | address
465 }
466 foreach: _else :idx inst {
467 inst recordUsage: tracker at: idx | address
468 }
469 }
470 assignRegs:at:withSource:andUsage <- :assignments :address :regSrc :usage {
471 newskip <- #[]
472 foreach: _toskip :idx inst {
473 newskip append: (inst assignRegs: assignments at: idx | address withSource: regSrc andUsage: usage)
474 }
475 newelse <- #[]
476 foreach: _else :idx inst {
477 newelse append: (inst assignRegs: assignments at: idx | address withSource: regSrc andUsage: usage)
478 }
479 skipIf: _cond newskip else: newelse
480 }
481 to2OpInst <- {
482 skipIf: _cond (to2Op: _toskip) (to2Op: _else)
483 }
484 }
485 }
429 save <- :regs :_scope{ 486 save <- :regs :_scope{
430 #{ 487 #{
431 opcode <- { _save } 488 opcode <- { _save }
432 numops <- { 0 } 489 numops <- { 0 }
433 name <- { _names get: _save } 490 name <- { _names get: _save }
449 //produces a non-zero value or zero based on condition code flags 506 //produces a non-zero value or zero based on condition code flags
450 bool <- :_cond _out { 507 bool <- :_cond _out {
451 #{ 508 #{
452 opcode <- { _bool } 509 opcode <- { _bool }
453 cond <- { _cond } 510 cond <- { _cond }
454 out <- { _code } 511 out <- { _out }
455 name <- { _names get: _save } 512 name <- { _names get: _save }
456 numops <- { 0 } 513 numops <- { 0 }
457 514
458 } 515 }
459 } 516 }