def BpfRaw.decode

bend-osdev-bpf@0.1.0.0 · insn.bend:241

import bend-osdev-bpf@0.1.0.0/insn.bend as Insn
import Base

241# the instruction a sock_filter holds, or None for an opcode classic BPF does
242# not define; fields the instruction does not use are ignored
243def BpfRaw.decode(r: BpfRaw) -> Maybe<&2, BpfOp>:
244  match r:
245    case BpfRaw{+code, +jt, +jf, +k}:
246      BpfRaw.decode.pick(U32.is_eq(code, 32), BpfLdAbs{BpfW{}, k},
247      BpfRaw.decode.pick(U32.is_eq(code, 40), BpfLdAbs{BpfH{}, k},
248      BpfRaw.decode.pick(U32.is_eq(code, 48), BpfLdAbs{BpfB{}, k},
249      BpfRaw.decode.pick(U32.is_eq(code, 64), BpfLdInd{BpfW{}, k},
250      BpfRaw.decode.pick(U32.is_eq(code, 72), BpfLdInd{BpfH{}, k},
251      BpfRaw.decode.pick(U32.is_eq(code, 80), BpfLdInd{BpfB{}, k},
252      BpfRaw.decode.pick(U32.is_eq(code, 0), BpfLdImm{k},
253      BpfRaw.decode.pick(U32.is_eq(code, 128), BpfLdLen{},
254      BpfRaw.decode.pick(U32.is_eq(code, 96), BpfLdMem{k},
255      BpfRaw.decode.pick(U32.is_eq(code, 1), BpfLdxImm{k},
256      BpfRaw.decode.pick(U32.is_eq(code, 97), BpfLdxMem{k},
257      BpfRaw.decode.pick(U32.is_eq(code, 129), BpfLdxLen{},
258      BpfRaw.decode.pick(U32.is_eq(code, 177), BpfLdxMsh{k},
259      BpfRaw.decode.pick(U32.is_eq(code, 2), BpfSt{k},
260      BpfRaw.decode.pick(U32.is_eq(code, 3), BpfStx{k},
261      BpfRaw.decode.pick(U32.is_eq(code, 4), BpfAlu{BpfAdd{}, BpfK{k}},
262      BpfRaw.decode.pick(U32.is_eq(code, 12), BpfAlu{BpfAdd{}, BpfX{}},
263      BpfRaw.decode.pick(U32.is_eq(code, 20), BpfAlu{BpfSub{}, BpfK{k}},
264      BpfRaw.decode.pick(U32.is_eq(code, 28), BpfAlu{BpfSub{}, BpfX{}},
265      BpfRaw.decode.pick(U32.is_eq(code, 36), BpfAlu{BpfMul{}, BpfK{k}},
266      BpfRaw.decode.pick(U32.is_eq(code, 44), BpfAlu{BpfMul{}, BpfX{}},
267      BpfRaw.decode.pick(U32.is_eq(code, 52), BpfAlu{BpfDiv{}, BpfK{k}},
268      BpfRaw.decode.pick(U32.is_eq(code, 60), BpfAlu{BpfDiv{}, BpfX{}},
269      BpfRaw.decode.pick(U32.is_eq(code, 68), BpfAlu{BpfOr{}, BpfK{k}},
270      BpfRaw.decode.pick(U32.is_eq(code, 76), BpfAlu{BpfOr{}, BpfX{}},
271      BpfRaw.decode.pick(U32.is_eq(code, 84), BpfAlu{BpfAnd{}, BpfK{k}},
272      BpfRaw.decode.pick(U32.is_eq(code, 92), BpfAlu{BpfAnd{}, BpfX{}},
273      BpfRaw.decode.pick(U32.is_eq(code, 100), BpfAlu{BpfLsh{}, BpfK{k}},
274      BpfRaw.decode.pick(U32.is_eq(code, 108), BpfAlu{BpfLsh{}, BpfX{}},
275      BpfRaw.decode.pick(U32.is_eq(code, 116), BpfAlu{BpfRsh{}, BpfK{k}},
276      BpfRaw.decode.pick(U32.is_eq(code, 124), BpfAlu{BpfRsh{}, BpfX{}},
277      BpfRaw.decode.pick(U32.is_eq(code, 148), BpfAlu{BpfMod{}, BpfK{k}},
278      BpfRaw.decode.pick(U32.is_eq(code, 156), BpfAlu{BpfMod{}, BpfX{}},
279      BpfRaw.decode.pick(U32.is_eq(code, 164), BpfAlu{BpfXor{}, BpfK{k}},
280      BpfRaw.decode.pick(U32.is_eq(code, 172), BpfAlu{BpfXor{}, BpfX{}},
281      BpfRaw.decode.pick(U32.is_eq(code, 132), BpfNeg{},
282      BpfRaw.decode.pick(U32.is_eq(code, 5), BpfJa{k},
283      BpfRaw.decode.pick(U32.is_eq(code, 21), BpfJmp{BpfJeq{}, BpfK{k}, jt, jf},
284      BpfRaw.decode.pick(U32.is_eq(code, 29), BpfJmp{BpfJeq{}, BpfX{}, jt, jf},
285      BpfRaw.decode.pick(U32.is_eq(code, 37), BpfJmp{BpfJgt{}, BpfK{k}, jt, jf},
286      BpfRaw.decode.pick(U32.is_eq(code, 45), BpfJmp{BpfJgt{}, BpfX{}, jt, jf},
287      BpfRaw.decode.pick(U32.is_eq(code, 53), BpfJmp{BpfJge{}, BpfK{k}, jt, jf},
288      BpfRaw.decode.pick(U32.is_eq(code, 61), BpfJmp{BpfJge{}, BpfX{}, jt, jf},
289      BpfRaw.decode.pick(U32.is_eq(code, 69), BpfJmp{BpfJset{}, BpfK{k}, jt, jf},
290      BpfRaw.decode.pick(U32.is_eq(code, 77), BpfJmp{BpfJset{}, BpfX{}, jt, jf},
291      BpfRaw.decode.pick(U32.is_eq(code, 6), BpfRet{BpfRetK{k}},
292      BpfRaw.decode.pick(U32.is_eq(code, 22), BpfRet{BpfRetA{}},
293      BpfRaw.decode.pick(U32.is_eq(code, 7), BpfTax{},
294      BpfRaw.decode.pick(U32.is_eq(code, 135), BpfTxa{},
295      None{})))))))))))))))))))))))))))))))))))))))))))))))))

Uses (10)

Used by (5)