summaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/net/bpf/asm.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-07-24 14:35:44 +0200
committerDimitri Sokolyuk <demon@dim13.org>2018-07-24 14:35:44 +0200
commit621e49bb465f500cc46d47e39e828cf76d6381d7 (patch)
treee9d6ed54cfae73209f2b0d9a016ef0b64adf45a6 /vendor/golang.org/x/net/bpf/asm.go
parent5b9a4a158b81aa6e94a5a56d0851bea938b87bef (diff)
update vendor
Diffstat (limited to 'vendor/golang.org/x/net/bpf/asm.go')
-rw-r--r--vendor/golang.org/x/net/bpf/asm.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/golang.org/x/net/bpf/asm.go b/vendor/golang.org/x/net/bpf/asm.go
new file mode 100644
index 0000000..15e21b1
--- /dev/null
+++ b/vendor/golang.org/x/net/bpf/asm.go
@@ -0,0 +1,41 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package bpf
+
+import "fmt"
+
+// Assemble converts insts into raw instructions suitable for loading
+// into a BPF virtual machine.
+//
+// Currently, no optimization is attempted, the assembled program flow
+// is exactly as provided.
+func Assemble(insts []Instruction) ([]RawInstruction, error) {
+ ret := make([]RawInstruction, len(insts))
+ var err error
+ for i, inst := range insts {
+ ret[i], err = inst.Assemble()
+ if err != nil {
+ return nil, fmt.Errorf("assembling instruction %d: %s", i+1, err)
+ }
+ }
+ return ret, nil
+}
+
+// Disassemble attempts to parse raw back into
+// Instructions. Unrecognized RawInstructions are assumed to be an
+// extension not implemented by this package, and are passed through
+// unchanged to the output. The allDecoded value reports whether insts
+// contains no RawInstructions.
+func Disassemble(raw []RawInstruction) (insts []Instruction, allDecoded bool) {
+ insts = make([]Instruction, len(raw))
+ allDecoded = true
+ for i, r := range raw {
+ insts[i] = r.Disassemble()
+ if _, ok := insts[i].(RawInstruction); ok {
+ allDecoded = false
+ }
+ }
+ return insts, allDecoded
+}