本文整理汇总了Golang中github.com/go-llvm/llvm.PointerType函数的典型用法代码示例。如果您正苦于以下问题:Golang PointerType函数的具体用法?Golang PointerType怎么用?Golang PointerType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PointerType函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: makeInterface
func (c *compiler) makeInterface(v *LLVMValue, iface types.Type) *LLVMValue {
llv := v.LLVMValue()
lltyp := llv.Type()
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
if lltyp.TypeKind() == llvm.PointerTypeKind {
llv = c.builder.CreateBitCast(llv, i8ptr, "")
} else {
// If the value fits exactly in a pointer, then we can just
// bitcast it. Otherwise we need to malloc.
if c.target.TypeStoreSize(lltyp) <= uint64(c.target.PointerSize()) {
bits := c.target.TypeSizeInBits(lltyp)
if bits > 0 {
llv = coerce(c.builder, llv, llvm.IntType(int(bits)))
llv = c.builder.CreateIntToPtr(llv, i8ptr, "")
} else {
llv = llvm.ConstNull(i8ptr)
}
} else {
ptr := c.createTypeMalloc(lltyp)
c.builder.CreateStore(llv, ptr)
llv = c.builder.CreateBitCast(ptr, i8ptr, "")
}
}
value := llvm.Undef(c.types.ToLLVM(iface))
rtype := c.types.ToRuntime(v.Type())
rtype = c.builder.CreateBitCast(rtype, llvm.PointerType(llvm.Int8Type(), 0), "")
value = c.builder.CreateInsertValue(value, rtype, 0, "")
value = c.builder.CreateInsertValue(value, llv, 1, "")
if iface.Underlying().(*types.Interface).NumMethods() > 0 {
result := c.NewValue(value, types.NewInterface(nil, nil))
result, _ = result.convertE2I(iface)
return result
}
return c.NewValue(value, iface)
}
开发者ID:rvedam,项目名称:llgo,代码行数:35,代码来源:interfaces.go
示例2: createMainFunction
func (c *compiler) createMainFunction() error {
// In a PNaCl program (plugin), there should not be a "main.main";
// instead, we expect a "main.CreateModule" function.
// See pkg/nacl/ppapi/ppapi.go for more details.
mainMain := c.module.NamedFunction("main.main")
/*
if c.pnacl {
// PNaCl's libppapi_stub.a implements "main", which simply
// calls through to PpapiPluginMain. We define our own "main"
// so that we can capture argc/argv.
if !mainMain.IsNil() {
return fmt.Errorf("Found main.main")
}
pluginMain := c.RuntimeFunction("PpapiPluginMain", "func() int32")
// Synthesise a main which has no return value. We could cast
// PpapiPluginMain, but this is potentially unsafe as its
// calling convention is unspecified.
ftyp := llvm.FunctionType(llvm.VoidType(), nil, false)
mainMain = llvm.AddFunction(c.module.Module, "main.main", ftyp)
entry := llvm.AddBasicBlock(mainMain, "entry")
c.builder.SetInsertPointAtEnd(entry)
c.builder.CreateCall(pluginMain, nil, "")
c.builder.CreateRetVoid()
} else */{
mainMain = c.module.NamedFunction("main.main")
}
if mainMain.IsNil() {
return fmt.Errorf("Could not find main.main")
}
// runtime.main is called by main, with argc, argv, argp,
// and a pointer to main.main, which must be a niladic
// function with no result.
runtimeMain := c.runtime.main.LLVMValue()
ptrptr := llvm.PointerType(llvm.PointerType(llvm.Int8Type(), 0), 0)
ftyp := llvm.FunctionType(llvm.Int32Type(), []llvm.Type{llvm.Int32Type(), ptrptr, ptrptr}, true)
main := llvm.AddFunction(c.module.Module, "main", ftyp)
c.builder.SetCurrentDebugLocation(c.debug.MDNode(nil))
entry := llvm.AddBasicBlock(main, "entry")
c.builder.SetInsertPointAtEnd(entry)
runtimeMainParamTypes := runtimeMain.Type().ElementType().ParamTypes()
args := []llvm.Value{
main.Param(0), // argc
main.Param(1), // argv
main.Param(2), // argp
c.builder.CreateBitCast(mainMain, runtimeMainParamTypes[3], ""),
}
result := c.builder.CreateCall(runtimeMain, args, "")
c.builder.CreateRet(result)
return nil
}
开发者ID:rvedam,项目名称:llgo,代码行数:55,代码来源:compiler.go
示例3: funcLLVMType
func (tm *llvmTypeMap) funcLLVMType(f *types.Signature, name string) llvm.Type {
// If there's a receiver change the receiver to an
// additional (first) parameter, and take the value of
// the resulting signature instead.
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, nil, params, f.Results(), f.Variadic())
return tm.toLLVM(f, name)
}
if typ, ok := tm.types.At(f).(llvm.Type); ok {
return typ
}
typ := llvm.GlobalContext().StructCreateNamed(name)
tm.types.Set(f, typ)
params := f.Params()
param_types := make([]llvm.Type, params.Len())
for i := range param_types {
llvmtyp := tm.ToLLVM(params.At(i).Type())
param_types[i] = 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
}
开发者ID:rvedam,项目名称:llgo,代码行数:52,代码来源:typemap.go
示例4: makeAlgorithmTable
func (tm *TypeMap) makeAlgorithmTable(t types.Type) llvm.Value {
// TODO set these to actual functions.
hashAlg := llvm.ConstNull(llvm.PointerType(tm.alg.hashAlgFunctionType, 0))
printAlg := llvm.ConstNull(llvm.PointerType(tm.alg.printAlgFunctionType, 0))
copyAlg := llvm.ConstNull(llvm.PointerType(tm.alg.copyAlgFunctionType, 0))
equalAlg := tm.alg.eqalg(t)
elems := []llvm.Value{
AlgorithmHash: hashAlg,
AlgorithmEqual: equalAlg,
AlgorithmPrint: printAlg,
AlgorithmCopy: copyAlg,
}
return llvm.ConstStruct(elems, false)
}
开发者ID:rvedam,项目名称:llgo,代码行数:14,代码来源:typemap.go
示例5: makeRuntimeTypeGlobal
func (tm *TypeMap) makeRuntimeTypeGlobal(v llvm.Value, name string) (global, ptr llvm.Value) {
global = llvm.AddGlobal(tm.module, v.Type(), typeSymbol(name))
global.SetInitializer(v)
global.SetLinkage(llvm.LinkOnceAnyLinkage)
ptr = llvm.ConstBitCast(global, llvm.PointerType(tm.runtime.rtype.llvm, 0))
return global, ptr
}
开发者ID:rvedam,项目名称:llgo,代码行数:7,代码来源:typemap.go
示例6: interfaceMethod
// interfaceMethod returns a function pointer for the specified
// interface and method pair.
func (c *compiler) interfaceMethod(iface *LLVMValue, method *types.Func) *LLVMValue {
lliface := iface.LLVMValue()
llitab := c.builder.CreateExtractValue(lliface, 0, "")
llvalue := c.builder.CreateExtractValue(lliface, 1, "")
sig := method.Type().(*types.Signature)
methodset := c.types.MethodSet(sig.Recv().Type())
// TODO(axw) cache ordered method index
var index int
for i := 0; i < methodset.Len(); i++ {
if methodset.At(i).Obj() == method {
index = i
break
}
}
llitab = c.builder.CreateBitCast(llitab, llvm.PointerType(c.runtime.itab.llvm, 0), "")
llifn := c.builder.CreateGEP(llitab, []llvm.Value{
llvm.ConstInt(llvm.Int32Type(), 0, false),
llvm.ConstInt(llvm.Int32Type(), 5, false), // index of itab.fun
}, "")
_ = index
llifn = c.builder.CreateGEP(llifn, []llvm.Value{
llvm.ConstInt(llvm.Int32Type(), uint64(index), false),
}, "")
llifn = c.builder.CreateLoad(llifn, "")
// Strip receiver.
sig = types.NewSignature(nil, nil, sig.Params(), sig.Results(), sig.Variadic())
llfn := llvm.Undef(c.types.ToLLVM(sig))
llifn = c.builder.CreateIntToPtr(llifn, llfn.Type().StructElementTypes()[0], "")
llfn = c.builder.CreateInsertValue(llfn, llifn, 0, "")
llfn = c.builder.CreateInsertValue(llfn, llvalue, 1, "")
return c.NewValue(llfn, sig)
}
开发者ID:rvedam,项目名称:llgo,代码行数:34,代码来源:interfaces.go
示例7: basicLLVMType
func (tm *llvmTypeMap) basicLLVMType(b *types.Basic) llvm.Type {
switch b.Kind() {
case types.Bool:
return llvm.Int1Type()
case types.Int8, types.Uint8:
return llvm.Int8Type()
case types.Int16, types.Uint16:
return llvm.Int16Type()
case types.Int32, types.Uint32:
return llvm.Int32Type()
case types.Uint, types.Int:
return tm.inttype
case types.Int64, types.Uint64:
return llvm.Int64Type()
case types.Float32:
return llvm.FloatType()
case types.Float64:
return llvm.DoubleType()
case types.UnsafePointer, types.Uintptr:
return tm.target.IntPtrType()
case types.Complex64:
f32 := llvm.FloatType()
elements := []llvm.Type{f32, f32}
return llvm.StructType(elements, false)
case types.Complex128:
f64 := llvm.DoubleType()
elements := []llvm.Type{f64, f64}
return llvm.StructType(elements, false)
case types.String:
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
elements := []llvm.Type{i8ptr, tm.inttype}
return llvm.StructType(elements, false)
}
panic(fmt.Sprint("unhandled kind: ", b.Kind))
}
开发者ID:rvedam,项目名称:llgo,代码行数:35,代码来源:typemap.go
示例8: nameRuntimeType
func (tm *TypeMap) nameRuntimeType(n *types.Named) (global, ptr llvm.Value) {
name := typeString(n)
path := "runtime"
if pkg := n.Obj().Pkg(); pkg != nil {
path = pkg.Path()
}
if path != tm.pkgpath {
// We're not compiling the package from whence the type came,
// so we'll just create a pointer to it here.
global := llvm.AddGlobal(tm.module, tm.runtime.rtype.llvm, typeSymbol(name))
global.SetInitializer(llvm.ConstNull(tm.runtime.rtype.llvm))
global.SetLinkage(llvm.CommonLinkage)
return global, global
}
// If the underlying type is Basic, then we always create
// a new global. Otherwise, we clone the value returned
// from toRuntime in case it is cached and reused.
underlying := n.Underlying()
if basic, ok := underlying.(*types.Basic); ok {
global, ptr = tm.basicRuntimeType(basic, true)
global.SetName(typeSymbol(name))
} else {
global, ptr = tm.toRuntime(underlying)
clone := llvm.AddGlobal(tm.module, global.Type().ElementType(), typeSymbol(name))
clone.SetInitializer(global.Initializer())
global = clone
ptr = llvm.ConstBitCast(global, llvm.PointerType(tm.runtime.rtype.llvm, 0))
}
global.SetLinkage(llvm.ExternalLinkage)
// Locate the rtype.
underlyingRuntimeType := global.Initializer()
rtype := underlyingRuntimeType
if rtype.Type() != tm.runtime.rtype.llvm {
rtype = llvm.ConstExtractValue(rtype, []uint32{0})
}
// Insert the uncommon type.
uncommonTypeInit := tm.uncommonType(n, nil)
uncommonType := llvm.AddGlobal(tm.module, uncommonTypeInit.Type(), "")
uncommonType.SetInitializer(uncommonTypeInit)
rtype = llvm.ConstInsertValue(rtype, uncommonType, []uint32{9})
// Replace the rtype's string representation with the one from
// uncommonType. XXX should we have the package name prepended? Probably.
namePtr := llvm.ConstExtractValue(uncommonTypeInit, []uint32{0})
rtype = llvm.ConstInsertValue(rtype, namePtr, []uint32{8})
// Update the global's initialiser. Note that we take a copy
// of the underlying type; we're not updating a shared type.
if underlyingRuntimeType.Type() != tm.runtime.rtype.llvm {
underlyingRuntimeType = llvm.ConstInsertValue(underlyingRuntimeType, rtype, []uint32{0})
} else {
underlyingRuntimeType = rtype
}
global.SetInitializer(underlyingRuntimeType)
return global, ptr
}
开发者ID:rvedam,项目名称:llgo,代码行数:59,代码来源:typemap.go
示例9: coerce
// coerce yields a value of the the type specified, initialised
// to the exact bit pattern as in the specified value.
//
// Note: the value's type and the specified target type must have
// the same size. If the source is an aggregate, then the target
// must also be an aggregate with the same number of fields, each
// of which must have the same size.
func coerce(b llvm.Builder, v llvm.Value, t llvm.Type) llvm.Value {
// FIXME don't do this with alloca
switch t.TypeKind() {
case llvm.ArrayTypeKind, llvm.StructTypeKind:
ptr := b.CreateAlloca(t, "")
ptrv := b.CreateBitCast(ptr, llvm.PointerType(v.Type(), 0), "")
b.CreateStore(v, ptrv)
return b.CreateLoad(ptr, "")
}
vt := v.Type()
switch vt.TypeKind() {
case llvm.ArrayTypeKind, llvm.StructTypeKind:
ptr := b.CreateAlloca(vt, "")
b.CreateStore(v, ptr)
ptrt := b.CreateBitCast(ptr, llvm.PointerType(t, 0), "")
return b.CreateLoad(ptrt, "")
}
return b.CreateBitCast(v, t, "")
}
开发者ID:rvedam,项目名称:llgo,代码行数:26,代码来源:coerce.go
示例10: 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
}
开发者ID:rvedam,项目名称:llgo,代码行数:10,代码来源:println.go
示例11: 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
}
开发者ID:rvedam,项目名称:llgo,代码行数:10,代码来源:println.go
示例12: globalStringPtr
// globalStringPtr returns a *string with the specified value.
func (tm *TypeMap) globalStringPtr(value string) llvm.Value {
strval := llvm.ConstString(value, false)
strglobal := llvm.AddGlobal(tm.module, strval.Type(), "")
strglobal.SetInitializer(strval)
strglobal = llvm.ConstBitCast(strglobal, llvm.PointerType(llvm.Int8Type(), 0))
strlen := llvm.ConstInt(tm.inttype, uint64(len(value)), false)
str := llvm.ConstStruct([]llvm.Value{strglobal, strlen}, false)
g := llvm.AddGlobal(tm.module, str.Type(), "")
g.SetInitializer(str)
return g
}
开发者ID:rvedam,项目名称:llgo,代码行数:12,代码来源:typemap.go
示例13: sliceLLVMType
func (tm *llvmTypeMap) sliceLLVMType(s *types.Slice, name string) llvm.Type {
typ, ok := tm.types.At(s).(llvm.Type)
if !ok {
typ = llvm.GlobalContext().StructCreateNamed(name)
tm.types.Set(s, typ)
elements := []llvm.Type{
llvm.PointerType(tm.ToLLVM(s.Elem()), 0),
tm.inttype,
tm.inttype,
}
typ.StructSetBody(elements, false)
}
return typ
}
开发者ID:rvedam,项目名称:llgo,代码行数:14,代码来源:typemap.go
示例14: interfaceLLVMType
func (tm *llvmTypeMap) interfaceLLVMType(i *types.Interface, name string) llvm.Type {
if typ, ok := tm.types.At(i).(llvm.Type); ok {
return typ
}
// interface{} is represented as {type, value},
// and non-empty interfaces are represented as {itab, value}.
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
rtypeType := i8ptr
valueType := i8ptr
if name == "" {
name = i.String()
}
typ := llvm.GlobalContext().StructCreateNamed(name)
typ.StructSetBody([]llvm.Type{rtypeType, valueType}, false)
return typ
}
开发者ID:rvedam,项目名称:llgo,代码行数:16,代码来源:typemap.go
示例15: makeClosure
// makeClosure creates a closure from a function pointer and
// a set of bindings. The bindings are addresses of captured
// variables.
func (c *compiler) makeClosure(fn *LLVMValue, bindings []*LLVMValue) *LLVMValue {
types := make([]llvm.Type, len(bindings))
for i, binding := range bindings {
types[i] = c.types.ToLLVM(binding.Type())
}
block := c.createTypeMalloc(llvm.StructType(types, false))
for i, binding := range bindings {
addressPtr := c.builder.CreateStructGEP(block, i, "")
c.builder.CreateStore(binding.LLVMValue(), addressPtr)
}
block = c.builder.CreateBitCast(block, llvm.PointerType(llvm.Int8Type(), 0), "")
// fn is a raw function pointer; ToLLVM yields {*fn, *uint8}.
closure := llvm.Undef(c.types.ToLLVM(fn.Type()))
fnptr := c.builder.CreateBitCast(fn.LLVMValue(), closure.Type().StructElementTypes()[0], "")
closure = c.builder.CreateInsertValue(closure, fnptr, 0, "")
closure = c.builder.CreateInsertValue(closure, block, 1, "")
return c.NewValue(closure, fn.Type())
}
开发者ID:rvedam,项目名称:llgo,代码行数:21,代码来源:closures.go
示例16: 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
}
开发者ID:rvedam,项目名称:llgo,代码行数:18,代码来源:alg.go
示例17: makeLiteralSlice
// makeLiteralSlice allocates a new slice, storing in it the provided elements.
func (c *compiler) makeLiteralSlice(v []llvm.Value, elttyp types.Type) llvm.Value {
n := llvm.ConstInt(c.types.inttype, uint64(len(v)), false)
eltType := c.types.ToLLVM(elttyp)
arrayType := llvm.ArrayType(eltType, len(v))
mem := c.createMalloc(llvm.SizeOf(arrayType))
mem = c.builder.CreateIntToPtr(mem, llvm.PointerType(eltType, 0), "")
for i, value := range v {
indices := []llvm.Value{llvm.ConstInt(llvm.Int32Type(), uint64(i), false)}
ep := c.builder.CreateGEP(mem, indices, "")
c.builder.CreateStore(value, ep)
}
slicetyp := types.NewSlice(elttyp)
struct_ := llvm.Undef(c.types.ToLLVM(slicetyp))
struct_ = c.builder.CreateInsertValue(struct_, mem, 0, "")
struct_ = c.builder.CreateInsertValue(struct_, n, 1, "")
struct_ = c.builder.CreateInsertValue(struct_, n, 2, "")
return struct_
}
开发者ID:rvedam,项目名称:llgo,代码行数:19,代码来源:slice.go
示例18: resolveFunction
func (u *unit) resolveFunction(f *ssa.Function) *LLVMValue {
if v, ok := u.globals[f]; ok {
return v
}
name := f.String()
if f.Enclosing != nil {
// Anonymous functions are not guaranteed to
// have unique identifiers at the global scope.
name = f.Enclosing.String() + ":" + name
}
// It's possible that the function already exists in the module;
// for example, if it's a runtime intrinsic that the compiler
// has already referenced.
llvmFunction := u.module.Module.NamedFunction(name)
if llvmFunction.IsNil() {
llvmType := u.llvmtypes.ToLLVM(f.Signature)
llvmType = llvmType.StructElementTypes()[0].ElementType()
if len(f.FreeVars) > 0 {
// Add an implicit first argument.
returnType := llvmType.ReturnType()
paramTypes := llvmType.ParamTypes()
vararg := llvmType.IsFunctionVarArg()
blockElementTypes := make([]llvm.Type, len(f.FreeVars))
for i, fv := range f.FreeVars {
blockElementTypes[i] = u.llvmtypes.ToLLVM(fv.Type())
}
blockType := llvm.StructType(blockElementTypes, false)
blockPtrType := llvm.PointerType(blockType, 0)
paramTypes = append([]llvm.Type{blockPtrType}, paramTypes...)
llvmType = llvm.FunctionType(returnType, paramTypes, vararg)
}
llvmFunction = llvm.AddFunction(u.module.Module, name, llvmType)
if f.Enclosing != nil {
llvmFunction.SetLinkage(llvm.PrivateLinkage)
}
u.undefinedFuncs[f] = true
}
v := u.NewValue(llvmFunction, f.Signature)
u.globals[f] = v
return v
}
开发者ID:rvedam,项目名称:llgo,代码行数:41,代码来源:ssa.go
示例19: getBoolString
func (c *compiler) getBoolString(v llvm.Value) llvm.Value {
startBlock := c.builder.GetInsertBlock()
resultBlock := llvm.InsertBasicBlock(startBlock, "")
resultBlock.MoveAfter(startBlock)
falseBlock := llvm.InsertBasicBlock(resultBlock, "")
CharPtr := llvm.PointerType(llvm.Int8Type(), 0)
falseString := c.builder.CreateGlobalStringPtr("false", "")
falseString = c.builder.CreateBitCast(falseString, CharPtr, "")
trueString := c.builder.CreateGlobalStringPtr("true", "")
trueString = c.builder.CreateBitCast(trueString, CharPtr, "")
c.builder.CreateCondBr(v, resultBlock, falseBlock)
c.builder.SetInsertPointAtEnd(falseBlock)
c.builder.CreateBr(resultBlock)
c.builder.SetInsertPointAtEnd(resultBlock)
result := c.builder.CreatePHI(CharPtr, "")
result.AddIncoming([]llvm.Value{trueString, falseString},
[]llvm.BasicBlock{startBlock, falseBlock})
return result
}
开发者ID:rvedam,项目名称:llgo,代码行数:21,代码来源:println.go
示例20: createCall
// createCall emits the code for a function call,
// taking into account receivers, and panic/defer.
func (c *compiler) createCall(fn *LLVMValue, argValues []*LLVMValue) *LLVMValue {
fntyp := fn.Type().Underlying().(*types.Signature)
args := make([]llvm.Value, len(argValues))
for i, arg := range argValues {
args[i] = arg.LLVMValue()
}
var resultType types.Type
switch results := fntyp.Results(); results.Len() {
case 0: // no-op
case 1:
resultType = results.At(0).Type()
default:
resultType = results
}
// Builtins are represented as a raw function pointer.
fnval := fn.LLVMValue()
if fnval.Type().TypeKind() == llvm.PointerTypeKind {
return c.NewValue(c.builder.CreateCall(fnval, args, ""), resultType)
}
// If context is constant null, then the function does
// not need a context argument.
fnptr := c.builder.CreateExtractValue(fnval, 0, "")
context := c.builder.CreateExtractValue(fnval, 1, "")
llfntyp := fnptr.Type().ElementType()
paramTypes := llfntyp.ParamTypes()
if context.IsNull() {
return c.NewValue(c.builder.CreateCall(fnptr, args, ""), resultType)
}
llfntyp = llvm.FunctionType(
llfntyp.ReturnType(),
append([]llvm.Type{context.Type()}, paramTypes...),
llfntyp.IsFunctionVarArg(),
)
fnptr = c.builder.CreateBitCast(fnptr, llvm.PointerType(llfntyp, 0), "")
result := c.builder.CreateCall(fnptr, append([]llvm.Value{context}, args...), "")
return c.NewValue(result, resultType)
}
开发者ID:rvedam,项目名称:llgo,代码行数:42,代码来源:call.go
注:本文中的github.com/go-llvm/llvm.PointerType函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论