# HG changeset patch # User Michael Pavone # Date 1430020562 25200 # Node ID d949fe826e04e84a73ffe6840aa802c9691f5382 # Parent 7101ad443081ca0952876130995fc1469aea1eb6 Unify il and backend labels diff -r 7101ad443081 -r d949fe826e04 modules/il.tp --- 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 diff -r 7101ad443081 -r d949fe826e04 modules/x86.tp --- a/modules/x86.tp Sat Apr 25 13:05:38 2015 -0700 +++ b/modules/x86.tp Sat Apr 25 20:56:02 2015 -0700 @@ -466,37 +466,7 @@ ret <- { inst: [ 0xC3u8 ] } - label <- { - _offset <- -1 - _forwardRefs <- #[] - #{ - length <- { 0 } - hasOffset? <- { _offset >= 0 } - offset <- { _offset } - isInteger? <- { false } - register? <- { false } - label? <- { true } - flattenTo:at <- :dest :idx { - if: (not: hasOffset?) { - _offset <- idx - foreach: _forwardRefs :idx fun { - fun: _offset - } - _forwardRefs <- #[] - } - idx - } - string <- { "label: " . _offset } - withOffset:else <- :fun :elsefun { - if: hasOffset? { - fun: _offset - } else: { - _forwardRefs append: fun - elsefun: - } - } - } - } + label <- { il label } jmp <- :jmpDest { if: (jmpDest label?) { @@ -887,7 +857,7 @@ { //skipIf endlab <- label: - outarr append: (jcc: (mapcond: (inst cond)) endlab) + outarr append: (jcc: (mapcond: (inst cond)) (endlab reference)) foreach: (inst toskip) :_ inst { convertIL: inst to: outarr withLabels: labels withSaved: saved } @@ -897,11 +867,11 @@ { endlab <- label: elselab <- label: - outarr append: (jcc: (mapcond: (inst cond)) elselab) + outarr append: (jcc: (mapcond: (inst cond)) (elselab reference)) foreach: (inst toskip) :_ inst { convertIL: inst to: outarr withLabels: labels withSaved: saved } - outarr append: (jmp: endlab) + outarr append: (jmp: (endlab reference)) outarr append: elselab foreach: (inst else) :_ inst { convertIL: inst to: outarr withLabels: labels withSaved: saved @@ -930,6 +900,7 @@ } //label { + outarr append: inst } //data {