github.com/cloudwego/iasm@v0.2.0/x86_64/eface.go (about)

     1  //
     2  // Copyright 2024 CloudWeGo Authors
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package x86_64
    18  
    19  import (
    20      `reflect`
    21      `unsafe`
    22  )
    23  
    24  type _GoType struct {
    25      size   uintptr
    26      pdata  uintptr
    27      hash   uint32
    28      flags  uint8
    29      align  uint8
    30      falign uint8
    31      kflags uint8
    32      traits unsafe.Pointer
    33      gcdata *byte
    34      str    int32
    35      ptrx   int32
    36  }
    37  
    38  const (
    39      _KindMask = (1 << 5) - 1
    40  )
    41  
    42  func (self *_GoType) kind() reflect.Kind {
    43      return reflect.Kind(self.kflags & _KindMask)
    44  }
    45  
    46  type _GoSlice struct {
    47      ptr unsafe.Pointer
    48      len int
    49      cap int
    50  }
    51  
    52  type _GoEface struct {
    53      vt  *_GoType
    54      ptr unsafe.Pointer
    55  }
    56  
    57  func (self *_GoEface) kind() reflect.Kind {
    58      if self.vt != nil {
    59          return self.vt.kind()
    60      } else {
    61          return reflect.Invalid
    62      }
    63  }
    64  
    65  func (self *_GoEface) toInt64() int64 {
    66      if self.vt.size == 8 {
    67          return *(*int64)(self.ptr)
    68      } else if self.vt.size == 4 {
    69          return int64(*(*int32)(self.ptr))
    70      } else if self.vt.size == 2 {
    71          return int64(*(*int16)(self.ptr))
    72      } else {
    73          return int64(*(*int8)(self.ptr))
    74      }
    75  }
    76  
    77  func efaceOf(v interface{}) _GoEface {
    78      return *(*_GoEface)(unsafe.Pointer(&v))
    79  }