github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/func.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 Function struct {
    11  	*ccall.Function
    12  }
    13  
    14  func toFunction(c *ccall.Function) *Function {
    15  	return &Function{c}
    16  }
    17  
    18  func (f *Function) Label(label *Label) bool {
    19  	return f.Function.Label(label.Label)
    20  }
    21  
    22  func (f *Function) LabelRight(label *Label) bool {
    23  	return f.Function.LabelRight(label.Label)
    24  }
    25  
    26  func (f *Function) NewBlock(label *Label) bool {
    27  	return f.Function.NewBlock(label.Label)
    28  }
    29  
    30  func (f *Function) Load(value *Value) *Value {
    31  	return toValue(f.Function.Load(value.Value))
    32  }
    33  
    34  func (f *Function) Dup(value *Value) *Value {
    35  	return toValue(f.Function.Dup(value.Value))
    36  }
    37  
    38  func (f *Function) Store(dest, value *Value) bool {
    39  	return f.Function.Store(dest.Value, value.Value)
    40  }
    41  
    42  func (f *Function) LoadRelative(value *Value, offset int, typ *Type) *Value {
    43  	return toValue(f.Function.LoadRelative(value.Value, offset, typ.Type))
    44  }
    45  
    46  func (f *Function) StoreRelative(dest *Value, offset int, value *Value) bool {
    47  	return f.Function.StoreRelative(dest.Value, offset, value.Value)
    48  }
    49  
    50  func (f *Function) AddRelative(value *Value, offset int) *Value {
    51  	return toValue(f.Function.AddRelative(value.Value, offset))
    52  }
    53  
    54  func (f *Function) LoadElem(baseAddr, index *Value, elemType *Type) *Value {
    55  	return toValue(f.Function.LoadElem(baseAddr.Value, index.Value, elemType.Type))
    56  }
    57  
    58  func (f *Function) LoadElemAddress(baseAddr, index *Value, elemType *Type) *Value {
    59  	return toValue(f.Function.LoadElemAddress(baseAddr.Value, index.Value, elemType.Type))
    60  }
    61  
    62  func (f *Function) StoreElem(baseAddr, index, value *Value) bool {
    63  	return f.Function.StoreElem(baseAddr.Value, index.Value, value.Value)
    64  }
    65  
    66  func (f *Function) CheckNull(value *Value) bool {
    67  	return f.Function.CheckNull(value.Value)
    68  }
    69  
    70  func (f *Function) Nop() bool {
    71  	return f.Function.Nop()
    72  }
    73  
    74  func (f *Function) Add(value1, value2 *Value) *Value {
    75  	return toValue(f.Function.Add(value1.Value, value2.Value))
    76  }
    77  
    78  func (f *Function) AddOvf(value1, value2 *Value) *Value {
    79  	return toValue(f.Function.AddOvf(value1.Value, value2.Value))
    80  }
    81  
    82  func (f *Function) Sub(value1, value2 *Value) *Value {
    83  	return toValue(f.Function.Sub(value1.Value, value2.Value))
    84  }
    85  
    86  func (f *Function) SubOvf(value1, value2 *Value) *Value {
    87  	return toValue(f.Function.SubOvf(value1.Value, value2.Value))
    88  }
    89  
    90  func (f *Function) Mul(value1, value2 *Value) *Value {
    91  	return toValue(f.Function.Mul(value1.Value, value2.Value))
    92  }
    93  
    94  func (f *Function) MulOvf(value1, value2 *Value) *Value {
    95  	return toValue(f.Function.MulOvf(value1.Value, value2.Value))
    96  }
    97  
    98  func (f *Function) Div(value1, value2 *Value) *Value {
    99  	return toValue(f.Function.Div(value2.Value, value2.Value))
   100  }
   101  
   102  func (f *Function) Rem(value1, value2 *Value) *Value {
   103  	return toValue(f.Function.Rem(value1.Value, value2.Value))
   104  }
   105  
   106  func (f *Function) RemIEEE(value1, value2 *Value) *Value {
   107  	return toValue(f.Function.RemIEEE(value1.Value, value2.Value))
   108  }
   109  
   110  func (f *Function) Neg(value1 *Value) *Value {
   111  	return toValue(f.Function.Neg(value1.Value))
   112  }
   113  
   114  func (f *Function) And(value1, value2 *Value) *Value {
   115  	return toValue(f.Function.And(value1.Value, value2.Value))
   116  }
   117  
   118  func (f *Function) Or(value1, value2 *Value) *Value {
   119  	return toValue(f.Function.Or(value1.Value, value2.Value))
   120  }
   121  
   122  func (f *Function) Xor(value1, value2 *Value) *Value {
   123  	return toValue(f.Function.Xor(value1.Value, value2.Value))
   124  }
   125  
   126  func (f *Function) Not(value1 *Value) *Value {
   127  	return toValue(f.Function.Not(value1.Value))
   128  }
   129  
   130  func (f *Function) Shl(value1, value2 *Value) *Value {
   131  	return toValue(f.Function.Shl(value1.Value, value2.Value))
   132  }
   133  
   134  func (f *Function) Shr(value1, value2 *Value) *Value {
   135  	return toValue(f.Function.Shr(value1.Value, value2.Value))
   136  }
   137  
   138  func (f *Function) Ushr(value1, value2 *Value) *Value {
   139  	return toValue(f.Function.Ushr(value1.Value, value2.Value))
   140  }
   141  
   142  func (f *Function) Sshr(value1, value2 *Value) *Value {
   143  	return toValue(f.Function.Sshr(value1.Value, value2.Value))
   144  }
   145  
   146  func (f *Function) Eq(value1, value2 *Value) *Value {
   147  	return toValue(f.Function.Eq(value1.Value, value2.Value))
   148  }
   149  
   150  func (f *Function) Ne(value1, value2 *Value) *Value {
   151  	return toValue(f.Function.Ne(value1.Value, value2.Value))
   152  }
   153  
   154  func (f *Function) Lt(value1, value2 *Value) *Value {
   155  	return toValue(f.Function.Lt(value1.Value, value2.Value))
   156  }
   157  
   158  func (f *Function) Le(value1, value2 *Value) *Value {
   159  	return toValue(f.Function.Le(value1.Value, value2.Value))
   160  }
   161  
   162  func (f *Function) Gt(value1, value2 *Value) *Value {
   163  	return toValue(f.Function.Gt(value1.Value, value2.Value))
   164  }
   165  
   166  func (f *Function) Ge(value1, value2 *Value) *Value {
   167  	return toValue(f.Function.Ge(value1.Value, value2.Value))
   168  }
   169  
   170  func (f *Function) Cmpl(value1, value2 *Value) *Value {
   171  	return toValue(f.Function.Cmpl(value1.Value, value2.Value))
   172  }
   173  
   174  func (f *Function) Cmpg(value1, value2 *Value) *Value {
   175  	return toValue(f.Function.Cmpg(value1.Value, value2.Value))
   176  }
   177  
   178  func (f *Function) ToBool(value1 *Value) *Value {
   179  	return toValue(f.Function.ToBool(value1.Value))
   180  }
   181  
   182  func (f *Function) ToNotBool(value1 *Value) *Value {
   183  	return toValue(f.Function.ToNotBool(value1.Value))
   184  }
   185  
   186  func (f *Function) Acos(value1 *Value) *Value {
   187  	return toValue(f.Function.Acos(value1.Value))
   188  }
   189  
   190  func (f *Function) Asin(value1 *Value) *Value {
   191  	return toValue(f.Function.Asin(value1.Value))
   192  }
   193  
   194  func (f *Function) Atan(value1 *Value) *Value {
   195  	return toValue(f.Function.Atan(value1.Value))
   196  }
   197  
   198  func (f *Function) Atan2(value1, value2 *Value) *Value {
   199  	return toValue(f.Function.Atan2(value1.Value, value2.Value))
   200  }
   201  
   202  func (f *Function) Ceil(value1 *Value) *Value {
   203  	return toValue(f.Function.Ceil(value1.Value))
   204  }
   205  
   206  func (f *Function) Cos(value1 *Value) *Value {
   207  	return toValue(f.Function.Cos(value1.Value))
   208  }
   209  
   210  func (f *Function) Cosh(value1 *Value) *Value {
   211  	return toValue(f.Function.Cosh(value1.Value))
   212  }
   213  
   214  func (f *Function) Exp(value1 *Value) *Value {
   215  	return toValue(f.Function.Exp(value1.Value))
   216  }
   217  
   218  func (f *Function) Floor(value1 *Value) *Value {
   219  	return toValue(f.Function.Floor(value1.Value))
   220  }
   221  
   222  func (f *Function) Log(value1 *Value) *Value {
   223  	return toValue(f.Function.Log(value1.Value))
   224  }
   225  
   226  func (f *Function) Log10(value1 *Value) *Value {
   227  	return toValue(f.Function.Log10(value1.Value))
   228  }
   229  
   230  func (f *Function) Pow(value1, value2 *Value) *Value {
   231  	return toValue(f.Function.Pow(value1.Value, value2.Value))
   232  }
   233  
   234  func (f *Function) Rint(value1 *Value) *Value {
   235  	return toValue(f.Function.Rint(value1.Value))
   236  }
   237  
   238  func (f *Function) Round(value1 *Value) *Value {
   239  	return toValue(f.Function.Round(value1.Value))
   240  }
   241  
   242  func (f *Function) Sin(value1 *Value) *Value {
   243  	return toValue(f.Function.Sin(value1.Value))
   244  }
   245  
   246  func (f *Function) Sinh(value1 *Value) *Value {
   247  	return toValue(f.Function.Sinh(value1.Value))
   248  }
   249  
   250  func (f *Function) Sqrt(value1 *Value) *Value {
   251  	return toValue(f.Function.Sqrt(value1.Value))
   252  }
   253  
   254  func (f *Function) Tan(value1 *Value) *Value {
   255  	return toValue(f.Function.Tan(value1.Value))
   256  }
   257  
   258  func (f *Function) Tanh(value1 *Value) *Value {
   259  	return toValue(f.Function.Tanh(value1.Value))
   260  }
   261  
   262  func (f *Function) Trunc(value1 *Value) *Value {
   263  	return toValue(f.Function.Trunc(value1.Value))
   264  }
   265  
   266  func (f *Function) IsNan(value1 *Value) *Value {
   267  	return toValue(f.Function.IsNan(value1.Value))
   268  }
   269  
   270  func (f *Function) IsFinite(value1 *Value) *Value {
   271  	return toValue(f.Function.IsFinite(value1.Value))
   272  }
   273  
   274  func (f *Function) IsInf(value1 *Value) *Value {
   275  	return toValue(f.Function.IsInf(value1.Value))
   276  }
   277  
   278  func (f *Function) Abs(value1 *Value) *Value {
   279  	return toValue(f.Function.Abs(value1.Value))
   280  }
   281  
   282  func (f *Function) Min(value1, value2 *Value) *Value {
   283  	return toValue(f.Function.Min(value1.Value, value2.Value))
   284  }
   285  
   286  func (f *Function) Max(value1, value2 *Value) *Value {
   287  	return toValue(f.Function.Max(value1.Value, value2.Value))
   288  }
   289  
   290  func (f *Function) Sign(value1 *Value) *Value {
   291  	return toValue(f.Function.Sign(value1.Value))
   292  }
   293  
   294  func (f *Function) Branch(label *Label) bool {
   295  	return f.Function.Branch(label.Label)
   296  }
   297  
   298  func (f *Function) BranchIf(value *Value, label *Label) bool {
   299  	return f.Function.BranchIf(value.Value, label.Label)
   300  }
   301  
   302  func (f *Function) BranchIfNot(value *Value, label *Label) bool {
   303  	return f.Function.BranchIfNot(value.Value, label.Label)
   304  }
   305  
   306  func (f *Function) JumpTable(value *Value, labels Labels) bool {
   307  	return f.Function.JumpTable(value.Value, labels.raw())
   308  }
   309  
   310  func (f *Function) AddressOf(value1 *Value) *Value {
   311  	return toValue(f.Function.AddressOf(value1.Value))
   312  }
   313  
   314  func (f *Function) AddressOfLabel(label *Label) *Value {
   315  	return toValue(f.Function.AddressOfLabel(label.Label))
   316  }
   317  
   318  func (f *Function) Convert(value *Value, typ *Type, overflowCheck int) *Value {
   319  	return toValue(f.Function.Convert(value.Value, typ.Type, overflowCheck))
   320  }
   321  
   322  func (f *Function) Call(name string, fn *Function, args Values) *Value {
   323  	return toValue(f.Function.Call(name, fn.Function, args.raw()))
   324  }
   325  
   326  func (f *Function) CallIndirect(fn *Function, value *Value, signature *Type, args Values) *Value {
   327  	return toValue(f.Function.CallIndirect(fn.Function, value.Value, signature.Type, args.raw()))
   328  }
   329  
   330  func (f *Function) CallNestedIndirect(fn *Function, value *Value, parentFrame *Value, signature *Type, args Values) *Value {
   331  	return toValue(f.Function.CallNestedIndirect(fn.Function, value.Value, parentFrame.Value, signature.Type, args.raw()))
   332  }
   333  
   334  func (f *Function) CallIndirectVtable(fn *Function, value *Value, signature *Type, args Values) *Value {
   335  	return toValue(f.Function.CallIndirectVtable(fn.Function, value.Value, signature.Type, args.raw()))
   336  }
   337  
   338  func (f *Function) CallNative(fn *Function, name string, nativeFunc unsafe.Pointer, signature *Type, args Values) *Value {
   339  	return toValue(f.Function.CallNative(fn.Function, name, nativeFunc, signature.Type, args.raw()))
   340  }
   341  
   342  //func (f *Function) CallIntrinsic(fn *Function, name string, intrinsicFunc unsafe.Pointer, desc *IntrinsicDescriptor, arg1, arg2 *Value) *Value {
   343  //	return toValue(C.jit_insn_call_intrinsic(f.c, C.CString(name), intrinsicFunc, desc.c, arg1.c, arg2.c))
   344  //}
   345  
   346  func (f *Function) IncomingReg(value *Value, reg int) int {
   347  	return f.Function.IncomingReg(value.Value, reg)
   348  }
   349  
   350  func (f *Function) Return(value *Value) int {
   351  	return f.Function.Return(value.Value)
   352  }
   353  
   354  func (f *Function) ReturnPtr(value *Value, typ *Type) int {
   355  	return f.Function.ReturnPtr(value.Value, typ.Type)
   356  }
   357  
   358  func (f *Function) DefaultReturn() int {
   359  	return f.Function.DefaultReturn()
   360  }
   361  
   362  func (f *Function) Memcpy(dest, src, size *Value) int {
   363  	return f.Function.Memcpy(dest.Value, src.Value, size.Value)
   364  }
   365  
   366  func (f *Function) Memmove(dest, src, size *Value) int {
   367  	return f.Function.Memmove(dest.Value, src.Value, size.Value)
   368  }
   369  
   370  func (f *Function) Memset(dest, src, size *Value) int {
   371  	return f.Function.Memset(dest.Value, src.Value, size.Value)
   372  }
   373  
   374  func (f *Function) Alloca(size *Value) *Value {
   375  	return toValue(f.Function.Alloca(size.Value))
   376  }
   377  
   378  func (f *Function) MoveBlocksToStart(fromLabel *Label, toLabel *Label) int {
   379  	return f.Function.MoveBlocksToStart(fromLabel.Label, toLabel.Label)
   380  }
   381  
   382  func (f *Function) MoveBlocksToEnd(fromLabel *Label, toLabel *Label) int {
   383  	return f.Function.MoveBlocksToEnd(fromLabel.Label, toLabel.Label)
   384  }
   385  
   386  func (f *Function) MarkOffset(offset int) int {
   387  	return f.Function.MarkOffset(offset)
   388  }
   389  
   390  func (f *Function) MarkBreakpoint(data1, data2 int) int {
   391  	return f.Function.MarkBreakpoint(data1, data2)
   392  }
   393  
   394  func (f *Function) MarkBreakpointVariable(data1, data2 *Value) int {
   395  	return f.Function.MarkBreakpointVariable(data1.Value, data2.Value)
   396  }
   397  
   398  func (f *Function) Abandon() {
   399  	f.Function.Abandon()
   400  }
   401  
   402  func (f *Function) Context() *Context {
   403  	return toContext(f.Function.Context())
   404  }
   405  
   406  func (f *Function) Signature() *Type {
   407  	return toType(f.Function.Signature())
   408  }
   409  
   410  func (f *Function) Meta(typ int) unsafe.Pointer {
   411  	return f.Function.Meta(typ)
   412  }
   413  
   414  func (f *Function) FreeMeta(typ int) {
   415  	f.Function.FreeMeta(typ)
   416  }
   417  
   418  func (f *Function) Entry() *Block {
   419  	return toBlock(f.Function.Entry())
   420  }
   421  
   422  func (f *Function) Current() *Block {
   423  	return toBlock(f.Function.Current())
   424  }
   425  
   426  func (f *Function) NestedParent() *Function {
   427  	return toFunction(f.Function.NestedParent())
   428  }
   429  
   430  func (f *Function) SetParentFrame(parentFrame *Value) {
   431  	f.Function.SetParentFrame(parentFrame.Value)
   432  }
   433  
   434  func (f *Function) Compile() bool {
   435  	return f.Function.Compile()
   436  }
   437  
   438  func (f *Function) IsCompiled() bool {
   439  	return f.Function.IsCompiled()
   440  }
   441  
   442  func (f *Function) SetRecompilable() {
   443  	f.Function.SetRecompilable()
   444  }
   445  
   446  func (f *Function) ClearRecompilable() {
   447  	f.Function.ClearRecompilable()
   448  }
   449  
   450  func (f *Function) IsRecompilable() bool {
   451  	return f.Function.IsRecompilable()
   452  }
   453  
   454  func (f *Function) SetupEntry(entryPoint unsafe.Pointer) {
   455  	f.Function.SetupEntry(entryPoint)
   456  }
   457  
   458  func (f *Function) ToClosure() unsafe.Pointer {
   459  	return f.Function.ToClosure()
   460  }
   461  
   462  func (f *Function) ToVtablePointer() unsafe.Pointer {
   463  	return f.Function.ToVtablePointer()
   464  }
   465  
   466  func (f *Function) Run(args ...interface{}) interface{} {
   467  	return f.Function.Apply(args)
   468  }
   469  
   470  func (f *Function) SetOptimizationLevel(level uint) {
   471  	f.Function.SetOptimizationLevel(level)
   472  }
   473  
   474  func (f *Function) OptimizationLevel() uint {
   475  	return f.Function.OptimizationLevel()
   476  }
   477  
   478  func MaxOptimizationLevel() uint {
   479  	return ccall.MaxOptimizationLevel()
   480  }
   481  
   482  func (f *Function) ReserveLabel() *Label {
   483  	return toLabel(f.Function.ReserveLabel())
   484  }
   485  
   486  func (f *Function) LabelsEqual(label *Label, label2 *Label) bool {
   487  	return f.Function.LabelsEqual(label.Label, label2.Label)
   488  }
   489  
   490  func (f *Function) Optimize() bool {
   491  	return f.Function.Optimize()
   492  }
   493  
   494  func (f *Function) CreateValue(typ *Type) *Value {
   495  	return toValue(f.Function.CreateValue(typ.Type))
   496  }
   497  
   498  func (f *Function) CreatePtrValue(ptr unsafe.Pointer) *Value {
   499  	return toValue(f.Function.CreatePtrValue(ptr))
   500  }
   501  
   502  func (f *Function) CreateIntValue(value int) *Value {
   503  	return toValue(f.Function.CreateNintConstant(ccall.TypeGoInt, value))
   504  }
   505  
   506  func (f *Function) CreateFloat32Value(constValue float32) *Value {
   507  	return toValue(f.Function.CreateFloat32Constant(ccall.TypeFloat32, constValue))
   508  }
   509  
   510  func (f *Function) CreateFloat64Value(constValue float64) *Value {
   511  	return toValue(f.Function.CreateFloat64Constant(ccall.TypeFloat64, constValue))
   512  }
   513  
   514  func (f *Function) Param(param uint) *Value {
   515  	return toValue(f.Function.Param(param))
   516  }
   517  
   518  func (f *Function) StructPointer() *Value {
   519  	return toValue(f.Function.StructPointer())
   520  }
   521  
   522  func (f *Function) ValueRef(value *Value) {
   523  	f.Function.ValueRef(value.Value)
   524  }
   525  
   526  func (f *Function) NextBlock(block *Block) *Block {
   527  	return toBlock(f.Function.NextBlock(block.Block))
   528  }
   529  
   530  func (f *Function) PreviousBlock(block *Block) *Block {
   531  	return toBlock(f.Function.PreviousBlock(block.Block))
   532  }
   533  
   534  func (f *Function) BlockFromLabel(label *Label) *Block {
   535  	return toBlock(f.Function.BlockFromLabel(label.Label))
   536  }
   537  
   538  func (f *Function) IsDeadCurrentBlock() bool {
   539  	return f.Function.IsDeadCurrentBlock()
   540  }
   541  
   542  func (f *Function) Dump(name string, w io.Writer) error {
   543  	return f.Function.Dump(name, w)
   544  }
   545  
   546  func (f *Function) DumpValue(value *Value, prefix string, w io.Writer) error {
   547  	return f.Function.DumpValue(value.Value, prefix, w)
   548  }
   549  
   550  func (f *Function) DumpInstruction(insn *Instruction, w io.Writer) error {
   551  	return f.Function.DumpInstruction(insn.Instruction, w)
   552  }
   553  
   554  func (f *Function) GoCall(fn interface{}, args Values) ([]*Value, error) {
   555  	values, err := f.Function.GoCall(fn, args.raw())
   556  	if err != nil {
   557  		return nil, err
   558  	}
   559  	return toValues(values), nil
   560  }