Mercurial > repos > tabletprog
diff 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 |
line wrap: on
line diff
--- a/modules/il.tp Sat Mar 14 12:10:40 2015 -0700 +++ b/modules/il.tp Sat Mar 14 12:10:51 2015 -0700 @@ -4,31 +4,36 @@ _and <- 1 _or <- 2 _xor <- 3 - _mul <- 4 + _muls <- 4 + _mulu <- 5 //non-commutative ops - _div <- 5 - _sub <- 6 - _cmp <- 7 - _not <- 8 - _sl <- 9 - _asr <- 10 - _lsr <- 11 - _rol <- 12 - _ror <- 13 - _mov <- 14 - _call <- 15 - _ret <- 16 - _skipif <- 17 - _save <- 18 - _bool <- 19 + _divs <- 6 + _divu <- 7 + _sub <- 8 + _cmp <- 9 + _not <- 10 + _sl <- 11 + _asr <- 12 + _lsr <- 13 + _rol <- 14 + _ror <- 15 + _mov <- 16 + _call <- 17 + _ret <- 18 + _skipif <- 19 + _skipifelse <- 20 + _save <- 21 + _bool <- 22 _names <- #[ "add" "and" "or" "xor" - "mul" - "div" + "muls" + "mulu" + "divs" + "divu" "sub" "cmp" "not" @@ -41,6 +46,7 @@ "call" "ret" "skipIf" + "skipIf:else" "save" "bool" ] @@ -50,7 +56,7 @@ opcode <- { _opcode } ina <- { _ina } inb <- { _inb } - commutative? <- { _opcode < _sub } + commutative? <- { _opcode < _divs } out <- { _out } size <- { _size } numops <- { 3 } @@ -289,28 +295,36 @@ op3: _sub a: ina b: inb out: out size: size } - cmp <- :ina inb out size { - op3: _cmp a: ina b: inb out: out size: size + cmp <- :ina inb size { + op2: _cmp a: ina out: inb size: size } - and <- :ina inb out size { + band <- :ina inb out size { op3: _and a: ina b: inb out: out size: size } - or <- :ina inb out size { + bor <- :ina inb out size { op3: _or a: ina b: inb out: out size: size } - xor <- :ina inb out size { + bxor <- :ina inb out size { op3: _xor a: ina b: inb out: out size: size } - mul <- :ina inb out size { - op3: _mul a: ina b: inb out: out size: size + muls <- :ina inb out size { + op3: _muls a: ina b: inb out: out size: size } - div <- :ina inb out size { - op3: _div a: ina b: inb out: out size: size + mulu <- :ina inb out size { + op3: _mulu a: ina b: inb out: out size: size + } + + divs <- :ina inb out size { + op3: _divs a: ina b: inb out: out size: size + } + + divu <- :ina inb out size { + op3: _divu a: ina b: inb out: out size: size } bnot <- :in out size { @@ -426,6 +440,49 @@ } } } + skipIf:else <- :_cond _toskip :_else { + #{ + opcode <- { _skipif } + toskip <- { _toskip } + else <- { _else } + cond <- { _cond } + numops <- { 0 } + name <- { _names get: _skipifelse } + string <- { + block <- (_toskip map: :el { string: el }) join: "\n\t" + if: (_toskip length) > 0 { + block <- "\n\t" . block . "\n" + } + elseblock <- (_else map: :el { string: el }) join: "\n\t" + if: (_else length) > 0 { + elseblock <- "\n\t" . elseblock . "\n" + } + name . " " . (string: _cond) . " {" . block . "} {" . elseblock . "}" + } + recordUsage:at <- :tracker :address { + foreach: _toskip :idx inst { + inst recordUsage: tracker at: idx | address + } + foreach: _else :idx inst { + inst recordUsage: tracker at: idx | address + } + } + assignRegs:at:withSource:andUsage <- :assignments :address :regSrc :usage { + newskip <- #[] + foreach: _toskip :idx inst { + newskip append: (inst assignRegs: assignments at: idx | address withSource: regSrc andUsage: usage) + } + newelse <- #[] + foreach: _else :idx inst { + newelse append: (inst assignRegs: assignments at: idx | address withSource: regSrc andUsage: usage) + } + skipIf: _cond newskip else: newelse + } + to2OpInst <- { + skipIf: _cond (to2Op: _toskip) (to2Op: _else) + } + } + } save <- :regs :_scope{ #{ opcode <- { _save } @@ -451,7 +508,7 @@ #{ opcode <- { _bool } cond <- { _cond } - out <- { _code } + out <- { _out } name <- { _names get: _save } numops <- { 0 }