op: assume aux ops are always wrapped by a macro

Shaves off a length, and prepares for further simplification.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-10-14 20:01:06 +02:00
parent f5e93206f6
commit 41eb3807f7
3 changed files with 5 additions and 23 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ const (
TypeHideInputLen = 1
TypePushLen = 1
TypePopLen = 1
TypeAuxLen = 1 + 4
TypeAuxLen = 1
TypeClipLen = 1 + 4*4
TypeProfileLen = 1
)
+4 -17
View File
@@ -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")
-5
View File
@@ -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 {