1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 // Assemble converts insts into raw instructions suitable for loading
10 // into a BPF virtual machine.
12 // Currently, no optimization is attempted, the assembled program flow
13 // is exactly as provided.
14 func Assemble(insts []Instruction) ([]RawInstruction, error) {
15 ret := make([]RawInstruction, len(insts))
17 for i, inst := range insts {
18 ret[i], err = inst.Assemble()
20 return nil, fmt.Errorf("assembling instruction %d: %s", i+1, err)
26 // Disassemble attempts to parse raw back into
27 // Instructions. Unrecognized RawInstructions are assumed to be an
28 // extension not implemented by this package, and are passed through
29 // unchanged to the output. The allDecoded value reports whether insts
30 // contains no RawInstructions.
31 func Disassemble(raw []RawInstruction) (insts []Instruction, allDecoded bool) {
32 insts = make([]Instruction, len(raw))
34 for i, r := range raw {
35 insts[i] = r.Disassemble()
36 if _, ok := insts[i].(RawInstruction); ok {
40 return insts, allDecoded