github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/ebpf/lsh.go (about)

     1  package ebpf
     2  
     3  import "fmt"
     4  
     5  var _ Instruction = (*Lsh32)(nil)
     6  
     7  type Lsh32 struct {
     8  	Dest  Register
     9  	Value int32
    10  }
    11  
    12  func (a *Lsh32) Raw() ([]RawInstruction, error) {
    13  	return []RawInstruction{
    14  		{Op: BPF_ALU | BPF_K | BPF_LSH, Reg: NewReg(0, a.Dest), Imm: a.Value},
    15  	}, nil
    16  }
    17  
    18  func (a *Lsh32) String() string {
    19  	return fmt.Sprintf("w%s <<= %d", a.Dest, a.Value)
    20  }
    21  
    22  var _ Instruction = (*Lsh64)(nil)
    23  
    24  type Lsh64 struct {
    25  	Dest  Register
    26  	Value int32
    27  }
    28  
    29  func (a *Lsh64) Raw() ([]RawInstruction, error) {
    30  	return []RawInstruction{
    31  		{Op: BPF_ALU64 | BPF_K | BPF_LSH, Reg: NewReg(0, a.Dest), Imm: a.Value},
    32  	}, nil
    33  }
    34  
    35  func (a *Lsh64) String() string {
    36  	return fmt.Sprintf("r%s <<= %d", a.Dest, a.Value)
    37  }
    38  
    39  var _ Instruction = (*Lsh32Register)(nil)
    40  
    41  type Lsh32Register struct {
    42  	Dest Register
    43  	Src  Register
    44  }
    45  
    46  func (a *Lsh32Register) Raw() ([]RawInstruction, error) {
    47  	return []RawInstruction{
    48  		{Op: BPF_ALU | BPF_X | BPF_LSH, Reg: NewReg(a.Src, a.Dest)},
    49  	}, nil
    50  }
    51  
    52  func (a *Lsh32Register) String() string {
    53  	return fmt.Sprintf("w%s <<= w%d", a.Dest, a.Src)
    54  }
    55  
    56  var _ Instruction = (*Lsh64Register)(nil)
    57  
    58  type Lsh64Register struct {
    59  	Dest Register
    60  	Src  Register
    61  }
    62  
    63  func (a *Lsh64Register) Raw() ([]RawInstruction, error) {
    64  	return []RawInstruction{
    65  		{Op: BPF_ALU64 | BPF_X | BPF_LSH, Reg: NewReg(a.Src, a.Dest)},
    66  	}, nil
    67  }
    68  
    69  func (a *Lsh64Register) String() string {
    70  	return fmt.Sprintf("r%s <<= r%s", a.Dest, a.Src)
    71  }