jit

package module
v0.0.0-...-ff78d45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2020 License: MIT Imports: 3 Imported by: 3

README

go-jit

GoDoc

JIT compile library for Go

Status

WIP

Synopsis

Basic Operation

package main

import (
  "fmt"

  "github.com/goccy/go-jit"
)

// func f(x, y, z int) int {
//   temp1 := x * y
//   temp2 := temp1 + z
//   return temp2
// }

func main() {
  ctx := jit.NewContext()
  defer ctx.Close()
  f, err := ctx.Build(func(ctx *jit.Context) (*jit.Function, error) {
    f := ctx.CreateFunction([]*jit.Type{jit.TypeInt, jit.TypeInt, jit.TypeInt}, jit.TypeInt)
    x := f.Param(0)
    y := f.Param(1)
    z := f.Param(2)
    temp1 := f.Mul(x, y)
    temp2 := f.Add(temp1, z)
    f.Return(temp2)
    f.Compile()
    return f, nil
  })
  if err != nil {
    panic(err)
  }
  fmt.Println("result = ", f.Run(2, 3, 4))
}

Call defined Go function during JIT runtime

package main

import (
  "fmt"

  "github.com/goccy/go-jit"
)

// func f() int {
//   return callback(7, 8)
// }

func callback(i, j int) int {
  fmt.Printf("callback: i = %d j = %d\n", i, j)
  return i * j
}

func main() {
  ctx := jit.NewContext()
  defer ctx.Close()
  f, err := ctx.Build(func(ctx *jit.Context) (*jit.Function, error) {
    f := ctx.CreateFunction(nil, jit.TypeInt)
    rvalues, err := f.GoCall(callback, []*jit.Value{
      f.CreateIntValue(7), f.CreateIntValue(8),
    })
    if err != nil {
      return nil, err
    }
    f.Return(rvalues[0])
    f.Compile()
    return f, nil
  })
  if err != nil {
    panic(err)
  }
  fmt.Println("result = ", f.Run(nil))
}

Installation

go get github.com/goccy/go-jit

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TypeInt = &Type{ccall.TypeGoInt}
)

Functions

func BestAlignment

func BestAlignment() uint

func MaxOptimizationLevel

func MaxOptimizationLevel() uint

Types

type Block

type Block struct {
	*ccall.Block
}

func (*Block) Context

func (b *Block) Context() *Context

func (*Block) EndsInDead

func (b *Block) EndsInDead() bool

func (*Block) Function

func (b *Block) Function() *Function

func (*Block) IsReachable

func (b *Block) IsReachable() bool

func (*Block) Label

func (b *Block) Label() *Label

func (*Block) NextLabel

func (b *Block) NextLabel(label *Label) *Label

type Context

type Context struct {
	*ccall.Context
}

func NewContext

func NewContext() *Context

func (*Context) Build

func (c *Context) Build(cb func(*Context) (*Function, error)) (*Function, error)

func (*Context) Close

func (c *Context) Close()

func (*Context) CreateFunction

func (c *Context) CreateFunction(argtypes Types, rtype *Type) *Function

func (*Context) CreateNestedFunction

func (c *Context) CreateNestedFunction(signature *Type, parent *Function) *Function

type Function

type Function struct {
	*ccall.Function
}

func (*Function) Abandon

func (f *Function) Abandon()

func (*Function) Abs

func (f *Function) Abs(value1 *Value) *Value

func (*Function) Acos

func (f *Function) Acos(value1 *Value) *Value

func (*Function) Add

func (f *Function) Add(value1, value2 *Value) *Value

func (*Function) AddOvf

func (f *Function) AddOvf(value1, value2 *Value) *Value

func (*Function) AddRelative

func (f *Function) AddRelative(value *Value, offset int) *Value

func (*Function) AddressOf

func (f *Function) AddressOf(value1 *Value) *Value

func (*Function) AddressOfLabel

func (f *Function) AddressOfLabel(label *Label) *Value

func (*Function) Alloca

func (f *Function) Alloca(size *Value) *Value

func (*Function) And

func (f *Function) And(value1, value2 *Value) *Value

func (*Function) Asin

func (f *Function) Asin(value1 *Value) *Value

func (*Function) Atan

func (f *Function) Atan(value1 *Value) *Value

func (*Function) Atan2

func (f *Function) Atan2(value1, value2 *Value) *Value

func (*Function) BlockFromLabel

func (f *Function) BlockFromLabel(label *Label) *Block

func (*Function) Branch

func (f *Function) Branch(label *Label) bool

func (*Function) BranchIf

func (f *Function) BranchIf(value *Value, label *Label) bool

func (*Function) BranchIfNot

func (f *Function) BranchIfNot(value *Value, label *Label) bool

func (*Function) Call

func (f *Function) Call(name string, fn *Function, args Values) *Value

func (*Function) CallIndirect

func (f *Function) CallIndirect(fn *Function, value *Value, signature *Type, args Values) *Value

func (*Function) CallIndirectVtable

func (f *Function) CallIndirectVtable(fn *Function, value *Value, signature *Type, args Values) *Value

func (*Function) CallNative

func (f *Function) CallNative(fn *Function, name string, nativeFunc unsafe.Pointer, signature *Type, args Values) *Value

func (*Function) CallNestedIndirect

func (f *Function) CallNestedIndirect(fn *Function, value *Value, parentFrame *Value, signature *Type, args Values) *Value

func (*Function) Ceil

func (f *Function) Ceil(value1 *Value) *Value

func (*Function) CheckNull

func (f *Function) CheckNull(value *Value) bool

func (*Function) ClearRecompilable

func (f *Function) ClearRecompilable()

func (*Function) Cmpg

func (f *Function) Cmpg(value1, value2 *Value) *Value

func (*Function) Cmpl

func (f *Function) Cmpl(value1, value2 *Value) *Value

func (*Function) Compile

func (f *Function) Compile() bool

func (*Function) Context

func (f *Function) Context() *Context

func (*Function) Convert

func (f *Function) Convert(value *Value, typ *Type, overflowCheck int) *Value

func (*Function) Cos

func (f *Function) Cos(value1 *Value) *Value

func (*Function) Cosh

func (f *Function) Cosh(value1 *Value) *Value

func (*Function) CreateFloat32Value

func (f *Function) CreateFloat32Value(constValue float32) *Value

func (*Function) CreateFloat64Value

func (f *Function) CreateFloat64Value(constValue float64) *Value

func (*Function) CreateIntValue

func (f *Function) CreateIntValue(value int) *Value

func (*Function) CreatePtrValue

func (f *Function) CreatePtrValue(ptr unsafe.Pointer) *Value

func (*Function) CreateValue

func (f *Function) CreateValue(typ *Type) *Value

func (*Function) Current

func (f *Function) Current() *Block

func (*Function) DefaultReturn

func (f *Function) DefaultReturn() int

func (*Function) Div

func (f *Function) Div(value1, value2 *Value) *Value

func (*Function) Dump

func (f *Function) Dump(name string, w io.Writer) error

func (*Function) DumpInstruction

func (f *Function) DumpInstruction(insn *Instruction, w io.Writer) error

func (*Function) DumpValue

func (f *Function) DumpValue(value *Value, prefix string, w io.Writer) error

func (*Function) Dup

func (f *Function) Dup(value *Value) *Value

func (*Function) Entry

func (f *Function) Entry() *Block

func (*Function) Eq

func (f *Function) Eq(value1, value2 *Value) *Value

func (*Function) Exp

func (f *Function) Exp(value1 *Value) *Value

func (*Function) Floor

func (f *Function) Floor(value1 *Value) *Value

func (*Function) FreeMeta

func (f *Function) FreeMeta(typ int)

func (*Function) Ge

func (f *Function) Ge(value1, value2 *Value) *Value

func (*Function) GoCall

func (f *Function) GoCall(fn interface{}, args Values) ([]*Value, error)

func (*Function) Gt

func (f *Function) Gt(value1, value2 *Value) *Value

func (*Function) IncomingReg

func (f *Function) IncomingReg(value *Value, reg int) int

func (*Function) IsCompiled

func (f *Function) IsCompiled() bool

func (*Function) IsDeadCurrentBlock

func (f *Function) IsDeadCurrentBlock() bool

func (*Function) IsFinite

func (f *Function) IsFinite(value1 *Value) *Value

func (*Function) IsInf

func (f *Function) IsInf(value1 *Value) *Value

func (*Function) IsNan

func (f *Function) IsNan(value1 *Value) *Value

func (*Function) IsRecompilable

func (f *Function) IsRecompilable() bool

func (*Function) JumpTable

func (f *Function) JumpTable(value *Value, labels Labels) bool

func (*Function) Label

func (f *Function) Label(label *Label) bool

func (*Function) LabelRight

func (f *Function) LabelRight(label *Label) bool

func (*Function) LabelsEqual

func (f *Function) LabelsEqual(label *Label, label2 *Label) bool

func (*Function) Le

func (f *Function) Le(value1, value2 *Value) *Value

func (*Function) Load

func (f *Function) Load(value *Value) *Value

func (*Function) LoadElem

func (f *Function) LoadElem(baseAddr, index *Value, elemType *Type) *Value

func (*Function) LoadElemAddress

func (f *Function) LoadElemAddress(baseAddr, index *Value, elemType *Type) *Value

func (*Function) LoadRelative

func (f *Function) LoadRelative(value *Value, offset int, typ *Type) *Value

func (*Function) Log

func (f *Function) Log(value1 *Value) *Value

func (*Function) Log10

func (f *Function) Log10(value1 *Value) *Value

func (*Function) Lt

func (f *Function) Lt(value1, value2 *Value) *Value

func (*Function) MarkBreakpoint

func (f *Function) MarkBreakpoint(data1, data2 int) int

func (*Function) MarkBreakpointVariable

func (f *Function) MarkBreakpointVariable(data1, data2 *Value) int

func (*Function) MarkOffset

func (f *Function) MarkOffset(offset int) int

func (*Function) Max

func (f *Function) Max(value1, value2 *Value) *Value

func (*Function) Memcpy

func (f *Function) Memcpy(dest, src, size *Value) int

func (*Function) Memmove

func (f *Function) Memmove(dest, src, size *Value) int

func (*Function) Memset

func (f *Function) Memset(dest, src, size *Value) int

func (*Function) Meta

func (f *Function) Meta(typ int) unsafe.Pointer

func (*Function) Min

func (f *Function) Min(value1, value2 *Value) *Value

func (*Function) MoveBlocksToEnd

func (f *Function) MoveBlocksToEnd(fromLabel *Label, toLabel *Label) int

func (*Function) MoveBlocksToStart

func (f *Function) MoveBlocksToStart(fromLabel *Label, toLabel *Label) int

func (*Function) Mul

func (f *Function) Mul(value1, value2 *Value) *Value

func (*Function) MulOvf

func (f *Function) MulOvf(value1, value2 *Value) *Value

func (*Function) Ne

func (f *Function) Ne(value1, value2 *Value) *Value

func (*Function) Neg

func (f *Function) Neg(value1 *Value) *Value

func (*Function) NestedParent

func (f *Function) NestedParent() *Function

func (*Function) NewBlock

func (f *Function) NewBlock(label *Label) bool

func (*Function) NextBlock

func (f *Function) NextBlock(block *Block) *Block

func (*Function) Nop

func (f *Function) Nop() bool

func (*Function) Not

func (f *Function) Not(value1 *Value) *Value

func (*Function) OptimizationLevel

func (f *Function) OptimizationLevel() uint

func (*Function) Optimize

func (f *Function) Optimize() bool

func (*Function) Or

func (f *Function) Or(value1, value2 *Value) *Value

func (*Function) Param

func (f *Function) Param(param uint) *Value

func (*Function) Pow

func (f *Function) Pow(value1, value2 *Value) *Value

func (*Function) PreviousBlock

func (f *Function) PreviousBlock(block *Block) *Block

func (*Function) Rem

func (f *Function) Rem(value1, value2 *Value) *Value

func (*Function) RemIEEE

func (f *Function) RemIEEE(value1, value2 *Value) *Value

func (*Function) ReserveLabel

func (f *Function) ReserveLabel() *Label

func (*Function) Return

func (f *Function) Return(value *Value) int

func (*Function) ReturnPtr

func (f *Function) ReturnPtr(value *Value, typ *Type) int

func (*Function) Rint

func (f *Function) Rint(value1 *Value) *Value

func (*Function) Round

func (f *Function) Round(value1 *Value) *Value

func (*Function) Run

func (f *Function) Run(args ...interface{}) interface{}

func (*Function) SetOptimizationLevel

func (f *Function) SetOptimizationLevel(level uint)

func (*Function) SetParentFrame

func (f *Function) SetParentFrame(parentFrame *Value)

func (*Function) SetRecompilable

func (f *Function) SetRecompilable()

func (*Function) SetupEntry

func (f *Function) SetupEntry(entryPoint unsafe.Pointer)

func (*Function) Shl

func (f *Function) Shl(value1, value2 *Value) *Value

func (*Function) Shr

func (f *Function) Shr(value1, value2 *Value) *Value

func (*Function) Sign

func (f *Function) Sign(value1 *Value) *Value

func (*Function) Signature

func (f *Function) Signature() *Type

func (*Function) Sin

func (f *Function) Sin(value1 *Value) *Value

func (*Function) Sinh

func (f *Function) Sinh(value1 *Value) *Value

func (*Function) Sqrt

func (f *Function) Sqrt(value1 *Value) *Value

func (*Function) Sshr

func (f *Function) Sshr(value1, value2 *Value) *Value

func (*Function) Store

func (f *Function) Store(dest, value *Value) bool

func (*Function) StoreElem

func (f *Function) StoreElem(baseAddr, index, value *Value) bool

func (*Function) StoreRelative

func (f *Function) StoreRelative(dest *Value, offset int, value *Value) bool

func (*Function) StructPointer

func (f *Function) StructPointer() *Value

func (*Function) Sub

func (f *Function) Sub(value1, value2 *Value) *Value

func (*Function) SubOvf

func (f *Function) SubOvf(value1, value2 *Value) *Value

func (*Function) Tan

func (f *Function) Tan(value1 *Value) *Value

func (*Function) Tanh

func (f *Function) Tanh(value1 *Value) *Value

func (*Function) ToBool

func (f *Function) ToBool(value1 *Value) *Value

func (*Function) ToClosure

func (f *Function) ToClosure() unsafe.Pointer

func (*Function) ToNotBool

func (f *Function) ToNotBool(value1 *Value) *Value

func (*Function) ToVtablePointer

func (f *Function) ToVtablePointer() unsafe.Pointer

func (*Function) Trunc

func (f *Function) Trunc(value1 *Value) *Value

func (*Function) Ushr

func (f *Function) Ushr(value1, value2 *Value) *Value

func (*Function) ValueRef

func (f *Function) ValueRef(value *Value)

func (*Function) Xor

func (f *Function) Xor(value1, value2 *Value) *Value

type Instruction

type Instruction struct {
	*ccall.Instruction
}

func (*Instruction) Code

func (i *Instruction) Code() int

func (*Instruction) Dest

func (i *Instruction) Dest() *Value

func (*Instruction) DestIsValue

func (i *Instruction) DestIsValue() bool

func (*Instruction) Function

func (i *Instruction) Function() *Function

func (*Instruction) Label

func (i *Instruction) Label() *Label

func (*Instruction) Name

func (i *Instruction) Name() string

func (*Instruction) Native

func (i *Instruction) Native() unsafe.Pointer

func (*Instruction) Signature

func (i *Instruction) Signature() *Type

func (*Instruction) Value1

func (i *Instruction) Value1() *Value

func (*Instruction) Value2

func (i *Instruction) Value2() *Value

type Label

type Label struct {
	*ccall.Label
}

type Labels

type Labels []*Label

type Type

type Type struct {
	*ccall.Type
}

func CreateSignature

func CreateSignature(args Types, rtype *Type) *Type

func CreateStruct

func CreateStruct(fields Types, incref int) *Type

func CreateUnion

func CreateUnion(fields Types, incref int) *Type

func (*Type) Alignment

func (t *Type) Alignment() uint

func (*Type) Copy

func (t *Type) Copy() *Type

func (*Type) CreatePointer

func (t *Type) CreatePointer(incref int) *Type

func (*Type) Dump

func (t *Type) Dump(w io.Writer) error

func (*Type) Field

func (t *Type) Field(index uint) *Type

func (*Type) FindName

func (t *Type) FindName(name string) uint

func (*Type) Free

func (t *Type) Free()

func (*Type) HasTag

func (t *Type) HasTag(kind int) bool

func (*Type) IsPointer

func (t *Type) IsPointer() bool

func (*Type) IsPrimitive

func (t *Type) IsPrimitive() bool

func (*Type) IsSignature

func (t *Type) IsSignature() bool

func (*Type) IsStruct

func (t *Type) IsStruct() bool

func (*Type) IsTagged

func (t *Type) IsTagged() bool

func (*Type) IsUnion

func (t *Type) IsUnion() bool

func (*Type) Kind

func (t *Type) Kind() int

func (*Type) Name

func (t *Type) Name(index uint) string

func (*Type) Normalize

func (t *Type) Normalize() *Type

func (*Type) NumFields

func (t *Type) NumFields() uint

func (*Type) NumParams

func (t *Type) NumParams() uint

func (*Type) Offset

func (t *Type) Offset(index uint) uint

func (*Type) Param

func (t *Type) Param(index uint) *Type

func (*Type) PromoteInt

func (t *Type) PromoteInt() *Type

func (*Type) Ref

func (t *Type) Ref() *Type

func (*Type) RemoveTags

func (t *Type) RemoveTags() *Type

func (*Type) Return

func (t *Type) Return() *Type

func (*Type) ReturnViaPointer

func (t *Type) ReturnViaPointer() int

func (*Type) SetOffset

func (t *Type) SetOffset(fieldIndex, offset uint)

func (*Type) SetSizeAndAlignment

func (t *Type) SetSizeAndAlignment(size, alignment int)

func (*Type) SetTaggedType

func (t *Type) SetTaggedType(underlying *Type, incref int)

func (*Type) Size

func (t *Type) Size() uint

func (*Type) TaggedData

func (t *Type) TaggedData() unsafe.Pointer

func (*Type) TaggedKind

func (t *Type) TaggedKind() int

func (*Type) TaggedType

func (t *Type) TaggedType() *Type

type Types

type Types []*Type

type Value

type Value struct {
	*ccall.Value
}

func (*Value) Block

func (v *Value) Block() *Block

func (*Value) Context

func (v *Value) Context() *Context

func (*Value) Float32

func (v *Value) Float32() float32

func (*Value) Float64

func (v *Value) Float64() float64

func (*Value) Function

func (v *Value) Function() *Function

func (*Value) Int

func (v *Value) Int() int

func (*Value) IsAddressable

func (v *Value) IsAddressable() bool

func (*Value) IsConstant

func (v *Value) IsConstant() bool

func (*Value) IsLocal

func (v *Value) IsLocal() bool

func (*Value) IsParameter

func (v *Value) IsParameter() bool

func (*Value) IsTemporary

func (v *Value) IsTemporary() bool

func (*Value) IsTrue

func (v *Value) IsTrue() bool

func (*Value) IsVolatile

func (v *Value) IsVolatile() bool

func (*Value) SetAddressable

func (v *Value) SetAddressable()

func (*Value) SetVolatile

func (v *Value) SetVolatile()

func (*Value) Type

func (v *Value) Type() *Type

type Values

type Values []*Value

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL