From 41eb3807f700014645eea6a34cd88827b8f92bf0 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 14 Oct 2019 20:01:06 +0200 Subject: [PATCH] op: assume aux ops are always wrapped by a macro Shaves off a length, and prepares for further simplification. Signed-off-by: Elias Naur --- internal/opconst/ops.go | 2 +- internal/ops/reader.go | 21 ++++----------------- op/op.go | 5 ----- 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/internal/opconst/ops.go b/internal/opconst/ops.go index 4f633fee..59177a28 100644 --- a/internal/opconst/ops.go +++ b/internal/opconst/ops.go @@ -44,7 +44,7 @@ const ( TypeHideInputLen = 1 TypePushLen = 1 TypePopLen = 1 - TypeAuxLen = 1 + 4 + TypeAuxLen = 1 TypeClipLen = 1 + 4*4 TypeProfileLen = 1 ) diff --git a/internal/ops/reader.go b/internal/ops/reader.go index 25f30903..15d4ce98 100644 --- a/internal/ops/reader.go +++ b/internal/ops/reader.go @@ -53,10 +53,6 @@ type opMacroDef struct { endpc pc } -type opAux struct { - len int -} - // Reset start reading from the op list. func (r *Reader) Reset(ops *op.Ops) { r.stack = r.stack[:0] @@ -93,9 +89,10 @@ func (r *Reader) Decode() (EncodedOp, bool) { refs = refs[:nrefs] switch t { case opconst.TypeAux: - var op opAux - op.decode(data) - n += op.len + // An Aux operations is always wrapped in a macro, and + // its length is the remaining space. + block := r.stack[len(r.stack)-1] + n += block.endPC.data - r.pc.data - opconst.TypeAuxLen data = data[:n] case opconst.TypeMacro: var op macroOp @@ -151,16 +148,6 @@ func (op *opMacroDef) decode(data []byte) { } } -func (op *opAux) decode(data []byte) { - if opconst.OpType(data[0]) != opconst.TypeAux { - panic("invalid op") - } - bo := binary.LittleEndian - *op = opAux{ - len: int(int32(bo.Uint32(data[1:]))), - } -} - func (m *macroOp) decode(data []byte, refs []interface{}) { if opconst.OpType(data[0]) != opconst.TypeMacro { panic("invalid op") diff --git a/op/op.go b/op/op.go index 526c229f..6ac3da1b 100644 --- a/op/op.go +++ b/op/op.go @@ -216,12 +216,7 @@ func (o *Ops) Write(op []byte, refs ...interface{}) { } func (o *Ops) endAux() { - if !o.inAux { - return - } o.inAux = false - bo := binary.LittleEndian - bo.PutUint32(o.data[o.auxOff+1:], uint32(o.auxLen)) } func (o *Ops) pc() pc {