本文整理汇总了Golang中github.com/axw/gollvm/llvm.PointerType函数的典型用法代码示例。如果您正苦于以下问题:Golang PointerType函数的具体用法?Golang PointerType怎么用?Golang PointerType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PointerType函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: makeAlgorithmTable
func (tm *TypeMap) makeAlgorithmTable(t types.Type) llvm.Value {
// TODO set these to actual functions.
hashAlg := llvm.ConstNull(llvm.PointerType(tm.hashAlgFunctionType, 0))
printAlg := llvm.ConstNull(llvm.PointerType(tm.printAlgFunctionType, 0))
copyAlg := llvm.ConstNull(llvm.PointerType(tm.copyAlgFunctionType, 0))
const eqalgsig = "func(uintptr, unsafe.Pointer, unsafe.Pointer) bool"
var equalAlg llvm.Value
switch t := t.(type) {
case *types.Basic:
switch t.Kind() {
case types.String:
equalAlg = tm.functions.NamedFunction("runtime.streqalg", eqalgsig)
case types.Float32:
equalAlg = tm.functions.NamedFunction("runtime.f32eqalg", eqalgsig)
case types.Float64:
equalAlg = tm.functions.NamedFunction("runtime.f64eqalg", eqalgsig)
case types.Complex64:
equalAlg = tm.functions.NamedFunction("runtime.c64eqalg", eqalgsig)
case types.Complex128:
equalAlg = tm.functions.NamedFunction("runtime.c128eqalg", eqalgsig)
}
}
if equalAlg.IsNil() {
equalAlg = tm.functions.NamedFunction("runtime.memequal", eqalgsig)
}
elems := []llvm.Value{hashAlg, equalAlg, printAlg, copyAlg}
return llvm.ConstStruct(elems, false)
}
开发者ID:quarnster,项目名称:llgo,代码行数:29,代码来源:typemap.go
示例2: 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:minux,项目名称:llgo,代码行数:35,代码来源:interfaces.go
示例3: 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
}
开发者ID:hzmangel,项目名称:llgo,代码行数:57,代码来源: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.hashAlgFunctionType, 0))
equalAlg := llvm.ConstNull(llvm.PointerType(tm.equalAlgFunctionType, 0))
printAlg := llvm.ConstNull(llvm.PointerType(tm.printAlgFunctionType, 0))
copyAlg := llvm.ConstNull(llvm.PointerType(tm.copyAlgFunctionType, 0))
elems := []llvm.Value{hashAlg, equalAlg, printAlg, copyAlg}
return llvm.ConstStruct(elems, false)
}
开发者ID:prattmic,项目名称:llgo,代码行数:10,代码来源:llvmtypes.go
示例5: makeAlgorithmTable
func (tm *TypeMap) makeAlgorithmTable(t types.Type) llvm.Value {
// TODO set these to actual functions.
hashAlg := llvm.ConstNull(llvm.PointerType(tm.hashAlgFunctionType, 0))
printAlg := llvm.ConstNull(llvm.PointerType(tm.printAlgFunctionType, 0))
copyAlg := llvm.ConstNull(llvm.PointerType(tm.copyAlgFunctionType, 0))
equalAlg := tm.functions.NamedFunction("runtime.memequal", "func f(uintptr, unsafe.Pointer, unsafe.Pointer) bool")
elems := []llvm.Value{hashAlg, equalAlg, printAlg, copyAlg}
return llvm.ConstStruct(elems, false)
}
开发者ID:spate,项目名称:llgo,代码行数:10,代码来源:llvmtypes.go
示例6: 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:minux,项目名称:llgo,代码行数:55,代码来源:compiler.go
示例7: 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:minux,项目名称:llgo,代码行数:52,代码来源:typemap.go
示例8: 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:minux,项目名称:llgo,代码行数:14,代码来源:typemap.go
示例9: pointerLLVMType
func (tm *LLVMTypeMap) pointerLLVMType(p *types.Pointer) llvm.Type {
if p.Elem().Underlying() == p {
// Recursive pointers must be handled specially, as
// LLVM does not permit recursive types except via
// named structs.
if tm.ptrstandin.IsNil() {
ctx := llvm.GlobalContext()
unique := ctx.StructCreateNamed("")
tm.ptrstandin = llvm.PointerType(unique, 0)
}
return llvm.PointerType(tm.ptrstandin, 0)
}
return llvm.PointerType(tm.ToLLVM(p.Elem()), 0)
}
开发者ID:hzmangel,项目名称:llgo,代码行数:14,代码来源:typemap.go
示例10: 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
}
开发者ID:payco,项目名称:llgo,代码行数:14,代码来源:goroutine.go
示例11: 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)
}
开发者ID:c0der007,项目名称:llgo,代码行数:31,代码来源:llvmtypes.go
示例12: 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:minux,项目名称:llgo,代码行数:7,代码来源:typemap.go
示例13: 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()
}
开发者ID:prattmic,项目名称:llgo,代码行数:28,代码来源:intrinsics.go
示例14: makeAlgorithmTable
func (tm *TypeMap) makeAlgorithmTable(t types.Type) llvm.Value {
// TODO set these to actual functions.
hashAlg := llvm.ConstNull(llvm.PointerType(tm.hashAlgFunctionType, 0))
printAlg := llvm.ConstNull(llvm.PointerType(tm.printAlgFunctionType, 0))
copyAlg := llvm.ConstNull(llvm.PointerType(tm.copyAlgFunctionType, 0))
equalAlgName := "runtime.memequal"
equalAlg := tm.module.NamedFunction(equalAlgName)
if equalAlg.IsNil() {
equalAlg = llvm.AddFunction(
tm.module, equalAlgName, tm.equalAlgFunctionType)
}
elems := []llvm.Value{hashAlg, equalAlg, printAlg, copyAlg}
return llvm.ConstStruct(elems, false)
}
开发者ID:c0der007,项目名称:llgo,代码行数:16,代码来源:llvmtypes.go
示例15: 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:minux,项目名称:llgo,代码行数:34,代码来源:interfaces.go
示例16: makeSlice
// makeSlice allocates a new slice with the optional length and capacity,
// initialising its contents to their zero values.
func (c *compiler) makeSlice(elttyp types.Type, length, capacity Value) llvm.Value {
var lengthValue llvm.Value
if length != nil {
lengthValue = length.Convert(types.Typ[types.Int]).LLVMValue()
} else {
lengthValue = llvm.ConstNull(c.llvmtypes.inttype)
}
// TODO check capacity >= length
capacityValue := lengthValue
if capacity != nil {
capacityValue = capacity.Convert(types.Typ[types.Int]).LLVMValue()
}
eltType := c.types.ToLLVM(elttyp)
sizeof := llvm.ConstTruncOrBitCast(llvm.SizeOf(eltType), c.types.inttype)
size := c.builder.CreateMul(capacityValue, sizeof, "")
mem := c.createMalloc(size)
mem = c.builder.CreateIntToPtr(mem, llvm.PointerType(eltType, 0), "")
c.memsetZero(mem, size)
slicetyp := types.NewSlice(elttyp)
struct_ := llvm.Undef(c.types.ToLLVM(slicetyp))
struct_ = c.builder.CreateInsertValue(struct_, mem, 0, "")
struct_ = c.builder.CreateInsertValue(struct_, lengthValue, 1, "")
struct_ = c.builder.CreateInsertValue(struct_, capacityValue, 2, "")
return struct_
}
开发者ID:hzmangel,项目名称:llgo,代码行数:30,代码来源:slice.go
示例17: 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:minux,项目名称:llgo,代码行数:35,代码来源:typemap.go
示例18: basicLLVMType
func (tm *TypeMap) basicLLVMType(b *types.Basic) llvm.Type {
switch b.Kind {
case types.BoolKind:
return llvm.Int1Type()
case types.Int8Kind, types.Uint8Kind:
return llvm.Int8Type()
case types.Int16Kind, types.Uint16Kind:
return llvm.Int16Type()
case types.Int32Kind, types.Uint32Kind:
return llvm.Int32Type()
case types.Int64Kind, types.Uint64Kind:
return llvm.Int64Type()
case types.Float32Kind:
return llvm.FloatType()
case types.Float64Kind:
return llvm.DoubleType()
case types.UnsafePointerKind, types.UintptrKind,
types.UintKind, types.IntKind:
return tm.target.IntPtrType()
//case Complex64: TODO
//case Complex128:
//case UntypedInt:
//case UntypedFloat:
//case UntypedComplex:
case types.StringKind:
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
elements := []llvm.Type{i8ptr, llvm.Int32Type()}
return llvm.StructType(elements, false)
}
panic(fmt.Sprint("unhandled kind: ", b.Kind))
}
开发者ID:c0der007,项目名称:llgo,代码行数:31,代码来源:llvmtypes.go
示例19: 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)
}
开发者ID:c0der007,项目名称:llgo,代码行数:7,代码来源:utils_test.go
示例20: 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:minux,项目名称:llgo,代码行数:59,代码来源:typemap.go
注:本文中的github.com/axw/gollvm/llvm.PointerType函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论