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

     1  package assembler
     2  
     3  import (
     4  	"math"
     5  
     6  	"github.com/Rookout/GoSDK/pkg/services/assembler/internal/obj"
     7  	"golang.org/x/arch/arm64/arm64asm"
     8  )
     9  
    10  const NoArg = arm64asm.Reg(math.MaxInt16)
    11  
    12  const placeholderOp = ANOOP
    13  const placeholderLen = 4
    14  
    15  type Arg = arm64asm.Arg
    16  type Reg = arm64asm.Reg
    17  
    18  func Imm(imm uint64) arm64asm.Imm64 {
    19  	return arm64asm.Imm64{
    20  		Imm: imm,
    21  	}
    22  }
    23  
    24  type regReg struct {
    25  	arm64asm.Arg
    26  	reg1 arm64asm.Reg
    27  	reg2 arm64asm.Reg
    28  }
    29  
    30  func RegReg(reg1 arm64asm.Reg, reg2 arm64asm.Reg) arm64asm.Arg {
    31  	return regReg{reg1: reg1, reg2: reg2}
    32  }
    33  
    34  func argToAddr(arg arm64asm.Arg) (addr obj.Addr) {
    35  	if arg == NoArg {
    36  		return addr
    37  	}
    38  
    39  	switch t := arg.(type) {
    40  	case arm64asm.Imm64:
    41  		addr.Type = obj.TYPE_CONST
    42  		addr.Offset = int64(t.Imm)
    43  	case Reg:
    44  		addr.Type = obj.TYPE_REG
    45  		addr.Reg = AsmRegToSysReg(t)
    46  	case Mem:
    47  		addr.Type = obj.TYPE_MEM
    48  		addr.Reg = AsmRegToSysReg(t.Base)
    49  		addr.Offset = t.Disp
    50  	case regReg:
    51  		addr.Type = obj.TYPE_REGREG
    52  		addr.Reg = AsmRegToSysReg(t.reg1)
    53  		addr.Offset = int64(AsmRegToSysReg(t.reg2))
    54  	}
    55  	return addr
    56  }