Mercurial > repos > tabletprog
diff modules/il.tp @ 363:d949fe826e04
Unify il and backend labels
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 25 Apr 2015 20:56:02 -0700 |
parents | 06dceff348ea |
children |
line wrap: on
line diff
--- a/modules/il.tp Sat Apr 25 13:05:38 2015 -0700 +++ b/modules/il.tp Sat Apr 25 20:56:02 2015 -0700 @@ -565,11 +565,14 @@ label <- { _labelNum <- _curLabel _curLabel <- _curLabel + 1 + _offset <- option none + _forwardRefs <- #[] #{ opcode <- { _label } numops <- { 0 } name <- { _names get: opcode } string <- { name . " " . _labelNum } + length <- { 0 } reference <- { #{ isInteger? <- { false } @@ -585,6 +588,14 @@ assign:withSource <- :assignments :regSrc { self } + withOffset:else <- :fun :elsefun { + _offset value: :off { + fun: off + } none: { + _forwardRefs append: fun + elsefun: + } + } } } recordUsage:at <- :tracker :address { @@ -593,6 +604,16 @@ assignRegs:at:withSource:andUsage <- :assignments :at :regSrc :usage { self } + flattenTo:at <- :dest :idx { + if: (_offset none?) { + _offset <- option value: idx + foreach: _forwardRefs :_ fun { + fun: idx + } + _forwardRefs <- #[] + } + idx + } } } data <- :_bytes { @@ -795,15 +816,16 @@ backend adjustIL: fun } labels <- prepped map: :_ { - backend label + il label } + labelRefs <- labels map: :label { label reference } outprog <- #[] //translate main first so it's at the start of the output prepped ifget: "main" :instarr { outprog append: (labels get: "main" else: { false }) foreach: instarr :_ inst { print: "Translating: " . inst . "\n" - backend convertIL: inst to: outprog withLabels: labels + backend convertIL: inst to: outprog withLabels: labelRefs } } else: {} @@ -811,7 +833,7 @@ outprog append: (labels get: name else: { false }) foreach: instarr :_ inst { print: "Translating: " . inst . "\n" - backend convertIL: inst to: outprog withLabels: labels + backend convertIL: inst to: outprog withLabels: labelRefs } } outprog