本文整理匯總了Golang中github.com/axw/gollvm/llvm.FunctionType函數的典型用法代碼示例。如果您正苦於以下問題:Golang FunctionType函數的具體用法?Golang FunctionType怎麽用?Golang FunctionType使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了FunctionType函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewTypeMap
func NewTypeMap(llvmtm *LLVMTypeMap, module llvm.Module, pkgpath string, exprTypes map[ast.Expr]types.Type, c *FunctionCache, r Resolver) *TypeMap {
tm := &TypeMap{
LLVMTypeMap: llvmtm,
module: module,
pkgpath: pkgpath,
types: make(map[string]runtimeTypeInfo),
expr: exprTypes,
functions: c,
resolver: r,
}
// Load runtime/reflect types, and generate LLVM types for
// the structures we need to populate runtime type information.
pkg, err := c.compiler.parseReflect()
if err != nil {
panic(err) // FIXME return err
}
reflectLLVMType := func(name string) llvm.Type {
obj := pkg.Scope.Lookup(name)
if obj == nil {
panic(fmt.Errorf("Failed to find type: %s", name))
}
return tm.ToLLVM(obj.Type.(types.Type))
}
tm.runtimeType = reflectLLVMType("runtimeType")
tm.runtimeCommonType = reflectLLVMType("commonType")
tm.runtimeUncommonType = reflectLLVMType("uncommonType")
tm.runtimeArrayType = reflectLLVMType("arrayType")
tm.runtimeChanType = reflectLLVMType("chanType")
tm.runtimeFuncType = reflectLLVMType("funcType")
tm.runtimeMethod = reflectLLVMType("method")
tm.runtimeImethod = reflectLLVMType("imethod")
tm.runtimeInterfaceType = reflectLLVMType("interfaceType")
tm.runtimeMapType = reflectLLVMType("mapType")
tm.runtimePtrType = reflectLLVMType("ptrType")
tm.runtimeSliceType = reflectLLVMType("sliceType")
tm.runtimeStructType = reflectLLVMType("structType")
tm.commonType = pkg.Scope.Lookup("commonType").Type.(*types.Name)
// Types for algorithms. See 'runtime/runtime.h'.
uintptrType := tm.target.IntPtrType()
voidPtrType := llvm.PointerType(llvm.Int8Type(), 0)
boolType := llvm.Int1Type()
// Create runtime algorithm function types.
params := []llvm.Type{uintptrType, voidPtrType}
tm.hashAlgFunctionType = llvm.FunctionType(uintptrType, params, false)
params = []llvm.Type{uintptrType, uintptrType, uintptrType}
tm.equalAlgFunctionType = llvm.FunctionType(boolType, params, false)
params = []llvm.Type{uintptrType, voidPtrType}
tm.printAlgFunctionType = llvm.FunctionType(llvm.VoidType(), params, false)
params = []llvm.Type{uintptrType, voidPtrType, voidPtrType}
tm.copyAlgFunctionType = llvm.FunctionType(llvm.VoidType(), params, false)
return tm
}
示例2: NewTypeMap
func NewTypeMap(llvmtm *LLVMTypeMap, pkgpath string, exprTypes map[ast.Expr]types.Type, c *FunctionCache, p map[*ast.Object]string, r Resolver) *TypeMap {
tm := &TypeMap{
LLVMTypeMap: llvmtm,
pkgpath: pkgpath,
types: make(map[types.Type]llvm.Value),
expr: exprTypes,
pkgmap: p,
functions: c,
resolver: r,
}
// Load "reflect.go", and generate LLVM types for the runtime type
// structures.
pkg, err := parseReflect()
if err != nil {
panic(err) // FIXME return err
}
objToLLVMType := func(name string) llvm.Type {
obj := pkg.Scope.Lookup(name)
return tm.ToLLVM(obj.Type.(types.Type))
}
tm.runtimeType = objToLLVMType("runtimeType")
tm.runtimeCommonType = objToLLVMType("commonType")
tm.runtimeUncommonType = objToLLVMType("uncommonType")
tm.runtimeArrayType = objToLLVMType("arrayType")
tm.runtimeChanType = objToLLVMType("chanType")
tm.runtimeFuncType = objToLLVMType("funcType")
tm.runtimeMethod = objToLLVMType("method")
tm.runtimeImethod = objToLLVMType("imethod")
tm.runtimeInterfaceType = objToLLVMType("interfaceType")
tm.runtimeMapType = objToLLVMType("mapType")
tm.runtimePtrType = objToLLVMType("ptrType")
tm.runtimeSliceType = objToLLVMType("sliceType")
tm.runtimeStructType = objToLLVMType("structType")
// Types for algorithms. See 'runtime/runtime.h'.
uintptrType := tm.target.IntPtrType()
voidPtrType := llvm.PointerType(llvm.Int8Type(), 0)
boolType := llvm.Int1Type()
// Create runtime algorithm function types.
params := []llvm.Type{uintptrType, voidPtrType}
tm.hashAlgFunctionType = llvm.FunctionType(uintptrType, params, false)
params = []llvm.Type{uintptrType, uintptrType, uintptrType}
tm.equalAlgFunctionType = llvm.FunctionType(boolType, params, false)
params = []llvm.Type{uintptrType, voidPtrType}
tm.printAlgFunctionType = llvm.FunctionType(llvm.VoidType(), params, false)
params = []llvm.Type{uintptrType, voidPtrType, voidPtrType}
tm.copyAlgFunctionType = llvm.FunctionType(llvm.VoidType(), params, false)
return tm
}
示例3: getnewgoroutine
func getnewgoroutine(module llvm.Module) llvm.Value {
fn := module.NamedFunction("llgo_newgoroutine")
if fn.IsNil() {
i8Ptr := llvm.PointerType(llvm.Int8Type(), 0)
VoidFnPtr := llvm.PointerType(llvm.FunctionType(
llvm.VoidType(), []llvm.Type{i8Ptr}, false), 0)
i32 := llvm.Int32Type()
fn_type := llvm.FunctionType(
llvm.VoidType(), []llvm.Type{VoidFnPtr, i8Ptr, i32}, true)
fn = llvm.AddFunction(module, "llgo_newgoroutine", fn_type)
fn.SetFunctionCallConv(llvm.CCallConv)
}
return fn
}
示例4: addExterns
func addExterns(m *llgo.Module) {
CharPtr := llvm.PointerType(llvm.Int8Type(), 0)
fn_type := llvm.FunctionType(
llvm.Int32Type(), []llvm.Type{CharPtr}, false)
fflush := llvm.AddFunction(m.Module, "fflush", fn_type)
fflush.SetFunctionCallConv(llvm.CCallConv)
}
示例5: mapInsert
// mapInsert inserts a key into a map, returning a pointer to the memory
// location for the value.
func (c *compiler) mapInsert(m *LLVMValue, key Value) *LLVMValue {
mapType := m.Type().(*types.Map)
mapinsert := c.module.Module.NamedFunction("runtime.mapinsert")
ptrType := c.target.IntPtrType()
if mapinsert.IsNil() {
// params: dynamic type, mapptr, keyptr
paramTypes := []llvm.Type{ptrType, ptrType, ptrType}
funcType := llvm.FunctionType(ptrType, paramTypes, false)
mapinsert = llvm.AddFunction(c.module.Module, "runtime.mapinsert", funcType)
}
args := make([]llvm.Value, 3)
args[0] = llvm.ConstPtrToInt(c.types.ToRuntime(m.Type()), ptrType)
args[1] = c.builder.CreatePtrToInt(m.pointer.LLVMValue(), ptrType, "")
if lv, islv := key.(*LLVMValue); islv && lv.pointer != nil {
args[2] = c.builder.CreatePtrToInt(lv.pointer.LLVMValue(), ptrType, "")
}
if args[2].IsNil() {
// Create global constant, so we can take its address.
global := llvm.AddGlobal(c.module.Module, c.types.ToLLVM(key.Type()), "")
global.SetGlobalConstant(true)
global.SetInitializer(key.LLVMValue())
args[2] = c.builder.CreatePtrToInt(global, ptrType, "")
}
eltPtrType := &types.Pointer{Base: mapType.Elt}
result := c.builder.CreateCall(mapinsert, args, "")
result = c.builder.CreateIntToPtr(result, c.types.ToLLVM(eltPtrType), "")
value := c.NewLLVMValue(result, eltPtrType)
return value.makePointee()
}
示例6: funcLLVMType
func (tm *TypeMap) funcLLVMType(f *types.Func) llvm.Type {
param_types := make([]llvm.Type, 0)
// Add receiver parameter.
if f.Recv != nil {
recv_type := f.Recv.Type.(types.Type)
param_types = append(param_types, tm.ToLLVM(recv_type))
}
for _, param := range f.Params {
param_type := param.Type.(types.Type)
param_types = append(param_types, tm.ToLLVM(param_type))
}
var return_type llvm.Type
switch len(f.Results) {
case 0:
return_type = llvm.VoidType()
case 1:
return_type = tm.ToLLVM(f.Results[0].Type.(types.Type))
default:
elements := make([]llvm.Type, len(f.Results))
for i, result := range f.Results {
elements[i] = tm.ToLLVM(result.Type.(types.Type))
}
return_type = llvm.StructType(elements, false)
}
fn_type := llvm.FunctionType(return_type, param_types, false)
return llvm.PointerType(fn_type, 0)
}
示例7: defineMemcpyFunction
func (c *compiler) defineMemcpyFunction(fn llvm.Value) {
entry := llvm.AddBasicBlock(fn, "entry")
c.builder.SetInsertPointAtEnd(entry)
dst, src, size := fn.Param(0), fn.Param(1), fn.Param(2)
pint8 := llvm.PointerType(llvm.Int8Type(), 0)
dst = c.builder.CreateIntToPtr(dst, pint8, "")
src = c.builder.CreateIntToPtr(src, pint8, "")
sizeType := size.Type()
sizeBits := sizeType.IntTypeWidth()
memcpyName := "llvm.memcpy.p0i8.p0i8.i" + strconv.Itoa(sizeBits)
memcpy := c.module.NamedFunction(memcpyName)
if memcpy.IsNil() {
paramtypes := []llvm.Type{
pint8, pint8, size.Type(), llvm.Int32Type(), llvm.Int1Type()}
memcpyType := llvm.FunctionType(llvm.VoidType(), paramtypes, false)
memcpy = llvm.AddFunction(c.module.Module, memcpyName, memcpyType)
}
args := []llvm.Value{
dst, src, size,
llvm.ConstInt(llvm.Int32Type(), 1, false), // single byte alignment
llvm.ConstInt(llvm.Int1Type(), 0, false), // not volatile
}
c.builder.CreateCall(memcpy, args, "")
c.builder.CreateRetVoid()
}
示例8: compareStrings
func (c *compiler) compareStrings(lhs, rhs *LLVMValue, op token.Token) *LLVMValue {
strcmp := c.module.Module.NamedFunction("runtime.strcmp")
if strcmp.IsNil() {
string_type := c.types.ToLLVM(types.String)
param_types := []llvm.Type{string_type, string_type}
func_type := llvm.FunctionType(llvm.Int32Type(), param_types, false)
strcmp = llvm.AddFunction(c.module.Module, "runtime.strcmp", func_type)
}
args := []llvm.Value{lhs.LLVMValue(), rhs.LLVMValue()}
result := c.builder.CreateCall(strcmp, args, "")
zero := llvm.ConstNull(llvm.Int32Type())
var pred llvm.IntPredicate
switch op {
case token.EQL:
pred = llvm.IntEQ
case token.LSS:
pred = llvm.IntSLT
case token.GTR:
pred = llvm.IntSGT
case token.LEQ:
pred = llvm.IntSLE
case token.GEQ:
pred = llvm.IntSGE
case token.NEQ:
panic("NEQ is handled in LLVMValue.BinaryOp")
default:
panic("unreachable")
}
result = c.builder.CreateICmp(pred, result, zero, "")
return c.NewLLVMValue(result, types.Bool)
}
示例9: contextFunction
// contextFunction creates a wrapper function that
// has the same signature as the specified function,
// but has an additional first parameter that accepts
// and ignores the function context value.
//
// contextFunction must be called with a global function
// pointer.
func contextFunction(c *compiler, f *LLVMValue) *LLVMValue {
defer c.builder.SetInsertPointAtEnd(c.builder.GetInsertBlock())
resultType := c.llvmtypes.ToLLVM(f.Type())
fnptr := f.LLVMValue()
contextType := resultType.StructElementTypes()[1]
llfntyp := fnptr.Type().ElementType()
llfntyp = llvm.FunctionType(
llfntyp.ReturnType(),
append([]llvm.Type{contextType}, llfntyp.ParamTypes()...),
llfntyp.IsFunctionVarArg(),
)
wrapper := llvm.AddFunction(c.module.Module, fnptr.Name()+".ctx", llfntyp)
wrapper.SetLinkage(llvm.PrivateLinkage)
entry := llvm.AddBasicBlock(wrapper, "entry")
c.builder.SetInsertPointAtEnd(entry)
args := make([]llvm.Value, len(llfntyp.ParamTypes())-1)
for i := range args {
args[i] = wrapper.Param(i + 1)
}
result := c.builder.CreateCall(fnptr, args, "")
switch nresults := f.Type().(*types.Signature).Results().Len(); nresults {
case 0:
c.builder.CreateRetVoid()
case 1:
c.builder.CreateRet(result)
default:
results := make([]llvm.Value, nresults)
for i := range results {
results[i] = c.builder.CreateExtractValue(result, i, "")
}
c.builder.CreateAggregateRet(results)
}
return c.NewValue(wrapper, f.Type())
}
示例10: compareI2I
// interfacesEqual compares two interfaces for equality, returning
// a dynamic boolean value.
func (lhs *LLVMValue) compareI2I(rhs *LLVMValue) Value {
c := lhs.compiler
b := c.builder
lhsValue := b.CreateExtractValue(lhs.LLVMValue(), 0, "")
rhsValue := b.CreateExtractValue(rhs.LLVMValue(), 0, "")
lhsType := b.CreateExtractValue(lhs.LLVMValue(), 1, "")
rhsType := b.CreateExtractValue(rhs.LLVMValue(), 1, "")
llvmUintptr := c.target.IntPtrType()
runtimeCompareI2I := c.module.Module.NamedFunction("runtime.compareI2I")
if runtimeCompareI2I.IsNil() {
args := []llvm.Type{llvmUintptr, llvmUintptr, llvmUintptr, llvmUintptr}
functype := llvm.FunctionType(llvm.Int1Type(), args, false)
runtimeCompareI2I = llvm.AddFunction(
c.module.Module, "runtime.compareI2I", functype)
}
args := []llvm.Value{
c.builder.CreatePtrToInt(lhsType, llvmUintptr, ""),
c.builder.CreatePtrToInt(rhsType, llvmUintptr, ""),
c.builder.CreatePtrToInt(lhsValue, llvmUintptr, ""),
c.builder.CreatePtrToInt(rhsValue, llvmUintptr, ""),
}
result := c.builder.CreateCall(runtimeCompareI2I, args, "")
return c.NewLLVMValue(result, types.Bool)
}
示例11: NewTypeMap
func NewTypeMap(module llvm.Module, target llvm.TargetData, exprTypes map[ast.Expr]types.Type) *TypeMap {
tm := &TypeMap{module: module, target: target, expr: exprTypes}
tm.types = make(map[types.Type]llvm.Type)
tm.runtime = make(map[types.Type]llvm.Value)
// Load "reflect.go", and generate LLVM types for the runtime type
// structures.
pkg, err := parseReflect()
if err != nil {
panic(err) // FIXME return err
}
objToLLVMType := func(name string) llvm.Type {
obj := pkg.Scope.Lookup(name)
return tm.ToLLVM(obj.Type.(types.Type))
}
tm.runtimeCommonType = objToLLVMType("commonType")
tm.runtimeUncommonType = objToLLVMType("uncommonType")
tm.runtimeArrayType = objToLLVMType("arrayType")
tm.runtimeChanType = objToLLVMType("chanType")
tm.runtimeFuncType = objToLLVMType("funcType")
tm.runtimeInterfaceType = objToLLVMType("interfaceType")
tm.runtimeMapType = objToLLVMType("mapType")
tm.runtimePtrType = objToLLVMType("ptrType")
tm.runtimeSliceType = objToLLVMType("sliceType")
tm.runtimeStructType = objToLLVMType("structType")
// Types for algorithms. See 'runtime/runtime.h'.
uintptrType := tm.target.IntPtrType()
voidPtrType := llvm.PointerType(llvm.Int8Type(), 0)
boolType := llvm.Int1Type()
// Create runtime algorithm function types.
params := []llvm.Type{
llvm.PointerType(uintptrType, 0), uintptrType, voidPtrType}
tm.hashAlgFunctionType = llvm.FunctionType(llvm.VoidType(), params, false)
params = []llvm.Type{
llvm.PointerType(boolType, 0), uintptrType, voidPtrType, voidPtrType}
tm.equalAlgFunctionType = llvm.FunctionType(llvm.VoidType(), params, false)
params = []llvm.Type{uintptrType, voidPtrType}
tm.printAlgFunctionType = llvm.FunctionType(llvm.VoidType(), params, false)
params = []llvm.Type{uintptrType, voidPtrType, voidPtrType}
tm.copyAlgFunctionType = llvm.FunctionType(llvm.VoidType(), params, false)
return tm
}
示例12: funcLLVMType
func (tm *LLVMTypeMap) funcLLVMType(tstr string, f *types.Signature) llvm.Type {
typ, ok := tm.types[tstr]
if !ok {
// If there's a receiver change the receiver to an
// additional (first) parameter, and take the value of
// the resulting signature instead.
var param_types []llvm.Type
if recv := f.Recv(); recv != nil {
params := f.Params()
paramvars := make([]*types.Var, int(params.Len()+1))
paramvars[0] = recv
for i := 0; i < int(params.Len()); i++ {
paramvars[i+1] = params.At(i)
}
params = types.NewTuple(paramvars...)
f := types.NewSignature(nil, params, f.Results(), f.IsVariadic())
return tm.ToLLVM(f)
}
typ = llvm.GlobalContext().StructCreateNamed("")
tm.types[tstr] = typ
params := f.Params()
nparams := int(params.Len())
for i := 0; i < nparams; i++ {
typ := params.At(i).Type()
if f.IsVariadic() && i == nparams-1 {
typ = types.NewSlice(typ)
}
llvmtyp := tm.ToLLVM(typ)
param_types = append(param_types, llvmtyp)
}
var return_type llvm.Type
results := f.Results()
switch nresults := int(results.Len()); nresults {
case 0:
return_type = llvm.VoidType()
case 1:
return_type = tm.ToLLVM(results.At(0).Type())
default:
elements := make([]llvm.Type, nresults)
for i := range elements {
result := results.At(i)
elements[i] = tm.ToLLVM(result.Type())
}
return_type = llvm.StructType(elements, false)
}
fntyp := llvm.FunctionType(return_type, param_types, false)
fnptrtyp := llvm.PointerType(fntyp, 0)
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
elements := []llvm.Type{fnptrtyp, i8ptr} // func, closure
typ.StructSetBody(elements, false)
}
return typ
}
示例13: newAlgorithmMap
func newAlgorithmMap(m llvm.Module, runtime *runtimeInterface, target llvm.TargetData) *algorithmMap {
am := &algorithmMap{
module: m,
runtime: runtime,
}
uintptrType := target.IntPtrType()
voidPtrType := llvm.PointerType(llvm.Int8Type(), 0)
boolType := llvm.Int1Type()
params := []llvm.Type{uintptrType, voidPtrType}
am.hashAlgFunctionType = llvm.FunctionType(uintptrType, params, false)
params = []llvm.Type{uintptrType, uintptrType, uintptrType}
am.equalAlgFunctionType = llvm.FunctionType(boolType, params, false)
params = []llvm.Type{uintptrType, voidPtrType}
am.printAlgFunctionType = llvm.FunctionType(llvm.VoidType(), params, false)
params = []llvm.Type{uintptrType, voidPtrType, voidPtrType}
am.copyAlgFunctionType = llvm.FunctionType(llvm.VoidType(), params, false)
return am
}
示例14: getPrintf
func getPrintf(module llvm.Module) llvm.Value {
printf := module.NamedFunction("printf")
if printf.IsNil() {
charPtr := llvm.PointerType(llvm.Int8Type(), 0)
ftyp := llvm.FunctionType(llvm.Int32Type(), []llvm.Type{charPtr}, true)
printf = llvm.AddFunction(module, "printf", ftyp)
printf.SetFunctionCallConv(llvm.CCallConv)
}
return printf
}
示例15: getFflush
func getFflush(module llvm.Module) llvm.Value {
fflush := module.NamedFunction("fflush")
if fflush.IsNil() {
voidPtr := llvm.PointerType(llvm.Int8Type(), 0)
ftyp := llvm.FunctionType(llvm.Int32Type(), []llvm.Type{voidPtr}, false)
fflush = llvm.AddFunction(module, "fflush", ftyp)
fflush.SetFunctionCallConv(llvm.CCallConv)
}
return fflush
}