github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/type.go (about)

     1  package jit
     2  
     3  import (
     4  	"io"
     5  	"unsafe"
     6  
     7  	"github.com/goccy/go-jit/internal/ccall"
     8  )
     9  
    10  type Type struct {
    11  	*ccall.Type
    12  }
    13  
    14  type Types []*Type
    15  
    16  func (t Types) raw() ccall.Types {
    17  	types := ccall.Types{}
    18  	for _, tt := range t {
    19  		types = append(types, tt.Type)
    20  	}
    21  	return types
    22  }
    23  
    24  func toType(raw *ccall.Type) *Type {
    25  	return &Type{raw}
    26  }
    27  
    28  func CreateStruct(fields Types, incref int) *Type {
    29  	return toType(ccall.CreateStruct(fields.raw(), incref))
    30  }
    31  
    32  func CreateUnion(fields Types, incref int) *Type {
    33  	return toType(ccall.CreateUnion(fields.raw(), incref))
    34  }
    35  
    36  func CreateSignature(args Types, rtype *Type) *Type {
    37  	return toType(ccall.CreateSignature(args.raw(), rtype.Type))
    38  }
    39  
    40  func BestAlignment() uint {
    41  	return ccall.BestAlignment()
    42  }
    43  
    44  func (t *Type) Copy() *Type {
    45  	return toType(t.Type.Copy())
    46  }
    47  
    48  func (t *Type) Free() {
    49  	t.Type.Free()
    50  }
    51  
    52  func (t *Type) CreatePointer(incref int) *Type {
    53  	return toType(t.Type.CreatePointer(incref))
    54  }
    55  
    56  func (t *Type) SetSizeAndAlignment(size, alignment int) {
    57  	t.Type.SetSizeAndAlignment(size, alignment)
    58  }
    59  
    60  func (t *Type) SetOffset(fieldIndex, offset uint) {
    61  	t.Type.SetOffset(fieldIndex, offset)
    62  }
    63  
    64  func (t *Type) Kind() int {
    65  	return t.Type.Kind()
    66  }
    67  
    68  func (t *Type) Size() uint {
    69  	return t.Type.Size()
    70  }
    71  
    72  func (t *Type) Alignment() uint {
    73  	return t.Type.Alignment()
    74  }
    75  
    76  func (t *Type) NumFields() uint {
    77  	return t.Type.NumFields()
    78  }
    79  
    80  func (t *Type) Field(index uint) *Type {
    81  	return toType(t.Type.Field(index))
    82  }
    83  
    84  func (t *Type) Offset(index uint) uint {
    85  	return t.Type.Offset(index)
    86  }
    87  
    88  func (t *Type) Name(index uint) string {
    89  	return t.Type.Name(index)
    90  }
    91  
    92  func (t *Type) FindName(name string) uint {
    93  	return t.Type.FindName(name)
    94  }
    95  
    96  func (t *Type) NumParams() uint {
    97  	return t.Type.NumParams()
    98  }
    99  
   100  func (t *Type) Return() *Type {
   101  	return toType(t.Type.Return())
   102  }
   103  
   104  func (t *Type) Param(index uint) *Type {
   105  	return toType(t.Type.Param(index))
   106  }
   107  
   108  func (t *Type) Ref() *Type {
   109  	return toType(t.Type.Ref())
   110  }
   111  
   112  func (t *Type) TaggedType() *Type {
   113  	return toType(t.Type.TaggedType())
   114  }
   115  
   116  func (t *Type) SetTaggedType(underlying *Type, incref int) {
   117  	t.Type.SetTaggedType(underlying.Type, incref)
   118  }
   119  
   120  func (t *Type) TaggedKind() int {
   121  	return t.Type.TaggedKind()
   122  }
   123  
   124  func (t *Type) TaggedData() unsafe.Pointer {
   125  	return t.Type.TaggedData()
   126  }
   127  
   128  func (t *Type) IsPrimitive() bool {
   129  	return t.Type.IsPrimitive()
   130  }
   131  
   132  func (t *Type) IsStruct() bool {
   133  	return t.Type.IsStruct()
   134  }
   135  
   136  func (t *Type) IsUnion() bool {
   137  	return t.Type.IsUnion()
   138  }
   139  
   140  func (t *Type) IsSignature() bool {
   141  	return t.Type.IsSignature()
   142  }
   143  
   144  func (t *Type) IsPointer() bool {
   145  	return t.Type.IsPointer()
   146  }
   147  
   148  func (t *Type) IsTagged() bool {
   149  	return t.Type.IsTagged()
   150  }
   151  
   152  func (t *Type) RemoveTags() *Type {
   153  	return toType(t.Type.RemoveTags())
   154  }
   155  
   156  func (t *Type) Normalize() *Type {
   157  	return toType(t.Type.Normalize())
   158  }
   159  
   160  func (t *Type) PromoteInt() *Type {
   161  	return toType(t.Type.PromoteInt())
   162  }
   163  
   164  func (t *Type) ReturnViaPointer() int {
   165  	return t.Type.ReturnViaPointer()
   166  }
   167  
   168  func (t *Type) HasTag(kind int) bool {
   169  	return t.Type.HasTag(kind)
   170  }
   171  
   172  func (t *Type) Dump(w io.Writer) error {
   173  	return t.Type.Dump(w)
   174  }