github.com/Rookout/GoSDK@v0.1.48/pkg/services/assembler/insts_arm64.go (about)

     1  package assembler
     2  
     3  import (
     4  	"github.com/Rookout/GoSDK/pkg/services/assembler/internal/obj"
     5  	"github.com/Rookout/GoSDK/pkg/services/assembler/internal/obj/arm64"
     6  )
     7  
     8  type args struct {
     9  	Dst1   Arg
    10  	Dst2   Arg
    11  	Src1   Arg
    12  	Src2   Arg
    13  	SrcReg *Reg
    14  	DstReg *Reg
    15  }
    16  
    17  
    18  func (b *Builder) instArgs(op obj.As, args args) *Instruction {
    19  	inst := b.NewInstruction()
    20  	inst.As = op
    21  	if args.Dst1 != nil {
    22  		inst.To = argToAddr(args.Dst1)
    23  	}
    24  	if args.Dst2 != nil {
    25  		inst.RestArgs = append(inst.RestArgs, obj.AddrPos{Addr: argToAddr(args.Dst2), Pos: obj.Destination})
    26  	}
    27  	if args.DstReg != nil {
    28  		inst.RegTo2 = AsmRegToSysReg(*args.DstReg)
    29  	}
    30  	if args.Src1 != nil {
    31  		inst.From = argToAddr(args.Src1)
    32  	}
    33  	if args.Src2 != nil {
    34  		inst.RestArgs = append(inst.RestArgs, obj.AddrPos{Addr: argToAddr(args.Src2), Pos: obj.Source})
    35  	}
    36  	if args.SrcReg != nil {
    37  		inst.Reg = AsmRegToSysReg(*args.SrcReg)
    38  	}
    39  	return inst
    40  }
    41  
    42  
    43  
    44  
    45  func (b *Builder) Inst(op obj.As, dst, src Arg, cond ...uint8) *Instruction {
    46  	inst := b.NewInstruction()
    47  	inst.As = op
    48  	inst.To = argToAddr(dst)
    49  	inst.From = argToAddr(src)
    50  	if len(cond) != 0 {
    51  		inst.Scond = cond[0]
    52  	}
    53  	return inst
    54  }
    55  
    56  
    57  
    58  
    59  func (b *Builder) Cmp(arg1 Reg, arg2 Arg) *Instruction {
    60  	return b.instArgs(ACMP, args{
    61  		SrcReg: &arg1,
    62  		Src1:   arg2,
    63  	})
    64  }
    65  
    66  
    67  
    68  
    69  
    70  func (b *Builder) Sub3(dst Arg, src1 Reg, src2 Arg) *Instruction {
    71  	return b.instArgs(arm64.ASUB, args{
    72  		Dst1:   dst,
    73  		SrcReg: &src1,
    74  		Src1:   src2,
    75  	})
    76  }
    77  
    78  
    79  
    80  
    81  func (b *Builder) Swpal(arg1 Arg, arg2 Reg, arg3 Arg) *Instruction {
    82  	return b.instArgs(arm64.ASWPALD, args{
    83  		Src1:   arg1,
    84  		Dst1:   arg3,
    85  		DstReg: &arg2,
    86  	})
    87  }
    88  
    89  
    90  
    91  
    92  func (b *Builder) BranchToReg(op obj.As, dst Reg) *Instruction {
    93  	var dstArg Arg = dst
    94  	
    95  	if op == AJMP {
    96  		dstArg = Mem{Base: dst}
    97  	}
    98  	return b.instArgs(op, args{
    99  		Dst1: dstArg,
   100  	})
   101  }