本文整理汇总了Golang中github.com/axw/gollvm/llvm.AddGlobal函数的典型用法代码示例。如果您正苦于以下问题:Golang AddGlobal函数的具体用法?Golang AddGlobal怎么用?Golang AddGlobal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AddGlobal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: nameRuntimeType
func (tm *TypeMap) nameRuntimeType(n *types.Named) (global, ptr llvm.Value) {
var path string
if data, ok := tm.functions.objectdata[n.Obj()]; ok {
path = pkgpath(data.Package)
}
if path == "" {
// Set to "runtime", so the builtin types have a home.
path = "runtime"
}
globalname := "__llgo.type." + path + "." + n.Obj().Name()
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.runtimeType, globalname)
global.SetInitializer(llvm.ConstNull(tm.runtimeType))
global.SetLinkage(llvm.CommonLinkage)
return global, global
}
underlying := n.Underlying()
if name, ok := underlying.(*types.Named); ok {
underlying = name.Underlying()
}
global, ptr = tm.toRuntime(underlying)
// Locate the rtype.
underlyingRuntimeType := global.Initializer()
rtype := underlyingRuntimeType
if rtype.Type() != tm.runtimeType {
rtype = llvm.ConstExtractValue(rtype, []uint32{0})
}
// Insert the uncommon type.
uncommonTypeInit := tm.uncommonType(n, false)
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.runtimeType {
underlyingRuntimeType = llvm.ConstInsertValue(underlyingRuntimeType, rtype, []uint32{0})
} else {
underlyingRuntimeType = rtype
}
global.SetName(globalname)
global.SetInitializer(underlyingRuntimeType)
return global, ptr
}
开发者ID:hzmangel,项目名称:llgo,代码行数:55,代码来源:typemap.go
示例3: 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:minux,项目名称:llgo,代码行数:12,代码来源:typemap.go
示例4: pointerRuntimeType
func (tm *TypeMap) pointerRuntimeType(p *types.Pointer) (global, ptr llvm.Value) {
// Is the base type a named type from another package? If so, we'll
// create a reference to the externally defined symbol.
var globalname string
if n, ok := p.Base.(*types.Name); ok {
pkgpath := n.Package
if pkgpath == "" {
pkgpath = "runtime"
}
globalname = "__llgo.type.*" + n.String()
if pkgpath != tm.pkgpath {
global := llvm.AddGlobal(tm.module, tm.runtimeType, globalname)
global.SetInitializer(llvm.ConstNull(tm.runtimeType))
global.SetLinkage(llvm.CommonLinkage)
return global, global
}
}
commonType := tm.makeCommonType(p, reflect.Ptr)
if n, ok := p.Base.(*types.Name); ok {
uncommonTypeInit := tm.uncommonType(n, true)
uncommonType := llvm.AddGlobal(tm.module, uncommonTypeInit.Type(), "")
uncommonType.SetInitializer(uncommonTypeInit)
commonType = llvm.ConstInsertValue(commonType, uncommonType, []uint32{9})
}
baseTypeGlobal, baseTypePtr := tm.toRuntime(p.Base)
ptrType := llvm.ConstNull(tm.runtimePtrType)
ptrType = llvm.ConstInsertValue(ptrType, commonType, []uint32{0})
ptrType = llvm.ConstInsertValue(ptrType, baseTypePtr, []uint32{1})
global, ptr = tm.makeRuntimeTypeGlobal(ptrType)
global.SetName(globalname)
// Set ptrToThis in the base type's commonType.
baseRuntimeType := baseTypeGlobal.Initializer()
baseType := llvm.ConstExtractValue(baseRuntimeType, []uint32{1})
if baseType.Type() == tm.runtimeCommonType {
baseType = llvm.ConstInsertValue(baseType, ptr, []uint32{10})
} else {
commonType := llvm.ConstExtractValue(baseType, []uint32{0})
commonType = llvm.ConstInsertValue(commonType, ptr, []uint32{10})
baseType = llvm.ConstInsertValue(baseType, commonType, []uint32{0})
}
baseRuntimeType = llvm.ConstInsertValue(baseRuntimeType, baseType, []uint32{1})
baseTypeGlobal.SetInitializer(baseRuntimeType)
return global, ptr
}
开发者ID:kelsieflynn,项目名称:llgo,代码行数:48,代码来源:llvmtypes.go
示例5: basicRuntimeType
// basicRuntimeType creates the runtime type structure for
// a basic type. If underlying is true, then a new global
// is always created.
func (tm *TypeMap) basicRuntimeType(b *types.Basic, underlying bool) (global, ptr llvm.Value) {
b = types.Typ[b.Kind()] // unalias
var name string
if !underlying {
name = typeString(b)
if tm.pkgpath != "runtime" {
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
}
}
rtype := tm.makeRtype(b, basicReflectKinds[b.Kind()])
global, ptr = tm.makeRuntimeTypeGlobal(rtype, name)
global.SetLinkage(llvm.ExternalLinkage)
if !underlying {
switch b.Kind() {
case types.Int32:
llvm.AddAlias(tm.module, global.Type(), global, typeSymbol("rune"))
case types.Uint8:
llvm.AddAlias(tm.module, global.Type(), global, typeSymbol("byte"))
}
}
return global, ptr
}
开发者ID:minux,项目名称:llgo,代码行数:28,代码来源:typemap.go
示例6: 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
示例7: nameRuntimeType
func (tm *TypeMap) nameRuntimeType(n *types.Name) (global, ptr llvm.Value) {
global, ptr = tm.makeRuntimeType(n.Underlying)
globalInit := global.Initializer()
// Locate the common type.
underlyingRuntimeType := llvm.ConstExtractValue(globalInit, []uint32{1})
commonType := underlyingRuntimeType
if _, ok := n.Underlying.(*types.Basic); !ok {
commonType = llvm.ConstExtractValue(commonType, []uint32{0})
}
// Insert the uncommon type.
uncommonTypeInit := llvm.ConstNull(tm.runtimeUncommonType)
uncommonType := llvm.AddGlobal(tm.module, uncommonTypeInit.Type(), "")
uncommonType.SetInitializer(uncommonTypeInit)
commonType = llvm.ConstInsertValue(commonType, uncommonType, []uint32{8})
// Update the global's initialiser.
if _, ok := n.Underlying.(*types.Basic); !ok {
underlyingRuntimeType = llvm.ConstInsertValue(underlyingRuntimeType, commonType, []uint32{0})
} else {
underlyingRuntimeType = commonType
}
globalInit = llvm.ConstInsertValue(globalInit, underlyingRuntimeType, []uint32{1})
global.SetName("__llgo.reflect." + n.Obj.Name)
return global, ptr
}
开发者ID:c0der007,项目名称:llgo,代码行数:27,代码来源:llvmtypes.go
示例8: mapLookup
// mapLookup searches a map for a specified key, returning a pointer to the
// memory location for the value. If insert is given as true, and the key
// does not exist in the map, it will be added with an uninitialised value.
func (c *compiler) mapLookup(m *LLVMValue, key Value, insert bool) (elem *LLVMValue, notnull *LLVMValue) {
mapType := m.Type().Underlying().(*types.Map)
maplookup := c.NamedFunction("runtime.maplookup", "func f(t, m, k uintptr, insert bool) uintptr")
ptrType := c.target.IntPtrType()
args := make([]llvm.Value, 4)
args[0] = llvm.ConstPtrToInt(c.types.ToRuntime(mapType), ptrType)
args[1] = c.builder.CreatePtrToInt(m.LLVMValue(), ptrType, "")
if insert {
args[3] = llvm.ConstAllOnes(llvm.Int1Type())
} else {
args[3] = llvm.ConstNull(llvm.Int1Type())
}
if lv, islv := key.(*LLVMValue); islv && lv.pointer != nil {
args[2] = c.builder.CreatePtrToInt(lv.pointer.LLVMValue(), ptrType, "")
}
if args[2].IsNil() {
stackval := c.builder.CreateAlloca(c.types.ToLLVM(key.Type()), "")
c.builder.CreateStore(key.LLVMValue(), stackval)
args[2] = c.builder.CreatePtrToInt(stackval, ptrType, "")
}
eltPtrType := types.NewPointer(mapType.Elem())
llvmtyp := c.types.ToLLVM(eltPtrType)
zeroglobal := llvm.AddGlobal(c.module.Module, llvmtyp.ElementType(), "")
zeroglobal.SetInitializer(llvm.ConstNull(llvmtyp.ElementType()))
result := c.builder.CreateCall(maplookup, args, "")
result = c.builder.CreateIntToPtr(result, llvmtyp, "")
notnull_ := c.builder.CreateIsNotNull(result, "")
result = c.builder.CreateSelect(notnull_, result, zeroglobal, "")
value := c.NewValue(result, eltPtrType)
return value.makePointee(), c.NewValue(notnull_, types.Typ[types.Bool])
}
开发者ID:hzmangel,项目名称:llgo,代码行数:36,代码来源:maps.go
示例9: 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()
}
开发者ID:prattmic,项目名称:llgo,代码行数:33,代码来源:maps.go
示例10: nameRuntimeType
func (tm *TypeMap) nameRuntimeType(n *types.Name) llvm.Value {
underlyingRuntimeType := tm.ToRuntime(n.Underlying).Initializer()
result := llvm.AddGlobal(tm.module, underlyingRuntimeType.Type(), "")
result.SetName("__llgo.reflect." + n.Obj.Name)
elementTypes := tm.runtimeCommonType.StructElementTypes()
ptr := llvm.ConstBitCast(result, elementTypes[9])
commonType := llvm.ConstInsertValue(underlyingRuntimeType, ptr, []uint32{9})
uncommonTypeInit := llvm.ConstNull(tm.runtimeUncommonType) // TODO
uncommonType := llvm.AddGlobal(tm.module, uncommonTypeInit.Type(), "")
uncommonType.SetInitializer(uncommonTypeInit)
commonType = llvm.ConstInsertValue(commonType, uncommonType, []uint32{8})
// TODO set string, uncommonType.
result.SetInitializer(commonType)
return result
}
开发者ID:prattmic,项目名称:llgo,代码行数:17,代码来源:llvmtypes.go
示例11: basicRuntimeType
func (tm *TypeMap) basicRuntimeType(b *types.Basic) llvm.Value {
commonType := tm.makeCommonType(b, reflect.Kind(b.Kind))
result := llvm.AddGlobal(tm.module, commonType.Type(), "")
elementTypes := tm.runtimeCommonType.StructElementTypes()
ptr := llvm.ConstBitCast(result, elementTypes[9])
commonType = llvm.ConstInsertValue(commonType, ptr, []uint32{9})
result.SetInitializer(commonType)
return result
}
开发者ID:prattmic,项目名称:llgo,代码行数:9,代码来源:llvmtypes.go
示例12: Resolve
func (c *compiler) Resolve(ident *ast.Ident) Value {
obj := c.typeinfo.Objects[ident]
data := c.objectdata[obj]
if data.Value != nil {
return data.Value
}
var value *LLVMValue
switch obj := obj.(type) {
case *types.Func:
value = c.makeFunc(ident, obj.Type().(*types.Signature))
case *synthFunc:
value = c.makeFunc(ident, obj.Type().(*types.Signature))
case *types.Var:
if data.Ident.Obj != nil {
switch decl := data.Ident.Obj.Decl.(type) {
case *ast.ValueSpec:
c.VisitValueSpec(decl)
case *ast.Field:
// No-op. Fields will be yielded for function
// arg/recv/ret. We update the .Data field of the
// object when we enter the function definition.
if data.Value == nil {
panic("expected object value")
}
}
}
// If it's an external variable, we'll need to create a global
// value reference here. It may be possible for multiple objects
// to refer to the same variable.
value = data.Value
if value == nil {
module := c.module.Module
t := obj.Type()
name := obj.Pkg().Path() + "." + obj.Name()
g := module.NamedGlobal(name)
if g.IsNil() {
g = llvm.AddGlobal(module, c.types.ToLLVM(t), name)
}
value = c.NewValue(g, types.NewPointer(t)).makePointee()
}
case *types.Const:
value = c.NewConstValue(obj.Val(), obj.Type())
default:
panic(fmt.Sprintf("unreachable (%T)", obj))
}
data.Value = value
return value
}
开发者ID:quarnster,项目名称:llgo,代码行数:54,代码来源:compiler.go
示例13: mapRuntimeType
func (tm *TypeMap) mapRuntimeType(m *types.Map) llvm.Value {
result := llvm.AddGlobal(tm.module, tm.runtimeMapType, "")
elementTypes := tm.runtimeCommonType.StructElementTypes()
ptr := llvm.ConstBitCast(result, elementTypes[9])
commonType := tm.makeCommonType(m, reflect.Map)
commonType = llvm.ConstInsertValue(commonType, ptr, []uint32{9})
init := llvm.ConstNull(tm.runtimeMapType)
init = llvm.ConstInsertValue(init, commonType, []uint32{0})
result.SetInitializer(init)
// TODO set key, elem
return result
}
开发者ID:prattmic,项目名称:llgo,代码行数:15,代码来源:llvmtypes.go
示例14: structRuntimeType
func (tm *TypeMap) structRuntimeType(s *types.Struct) llvm.Value {
result := llvm.AddGlobal(tm.module, tm.runtimeStructType, "")
elementTypes := tm.runtimeCommonType.StructElementTypes()
ptr := llvm.ConstBitCast(result, elementTypes[9])
commonType := tm.makeCommonType(s, reflect.Struct)
commonType = llvm.ConstInsertValue(commonType, ptr, []uint32{9})
init := llvm.ConstNull(tm.runtimeStructType)
init = llvm.ConstInsertValue(init, commonType, []uint32{0})
result.SetInitializer(init)
// TODO set fields
//panic("unimplemented")
return result
}
开发者ID:prattmic,项目名称:llgo,代码行数:16,代码来源:llvmtypes.go
示例15: makeRuntimeTypeGlobal
func (tm *TypeMap) makeRuntimeTypeGlobal(v llvm.Value) (global, ptr llvm.Value) {
// Each runtime type is preceded by an interface{}.
initType := llvm.StructType([]llvm.Type{tm.runtimeType, v.Type()}, false)
global = llvm.AddGlobal(tm.module, initType, "")
ptr = llvm.ConstBitCast(global, llvm.PointerType(tm.runtimeType, 0))
// interface{} containing v's *commonType representation.
runtimeTypeValue := llvm.Undef(tm.runtimeType)
zero := llvm.ConstNull(llvm.Int32Type())
one := llvm.ConstInt(llvm.Int32Type(), 1, false)
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
if tm.commonTypePtrRuntimeType.IsNil() {
// Create a dummy pointer value, which we'll update straight after
// defining the runtime type info for commonType.
tm.commonTypePtrRuntimeType = llvm.Undef(i8ptr)
commonTypePtr := &types.Pointer{Base: tm.commonType}
commonTypeGlobal, commonTypeRuntimeType := tm.makeRuntimeType(tm.commonType)
tm.types[tm.commonType.String()] = runtimeTypeInfo{commonTypeGlobal, commonTypeRuntimeType}
commonTypePtrGlobal, commonTypePtrRuntimeType := tm.makeRuntimeType(commonTypePtr)
tm.types[commonTypePtr.String()] = runtimeTypeInfo{commonTypePtrGlobal, commonTypePtrRuntimeType}
tm.commonTypePtrRuntimeType = llvm.ConstBitCast(commonTypePtrRuntimeType, i8ptr)
if tm.pkgpath == tm.commonType.Package {
// Update the interace{} header of the commonType/*commonType
// runtime types we just created.
for _, g := range [...]llvm.Value{commonTypeGlobal, commonTypePtrGlobal} {
init := g.Initializer()
typptr := tm.commonTypePtrRuntimeType
runtimeTypeValue := llvm.ConstExtractValue(init, []uint32{0})
runtimeTypeValue = llvm.ConstInsertValue(runtimeTypeValue, typptr, []uint32{0})
init = llvm.ConstInsertValue(init, runtimeTypeValue, []uint32{0})
g.SetInitializer(init)
}
}
}
commonTypePtr := llvm.ConstGEP(global, []llvm.Value{zero, one})
commonTypePtr = llvm.ConstBitCast(commonTypePtr, i8ptr)
runtimeTypeValue = llvm.ConstInsertValue(runtimeTypeValue, tm.commonTypePtrRuntimeType, []uint32{0})
runtimeTypeValue = llvm.ConstInsertValue(runtimeTypeValue, commonTypePtr, []uint32{1})
init := llvm.Undef(initType)
init = llvm.ConstInsertValue(init, runtimeTypeValue, []uint32{0})
init = llvm.ConstInsertValue(init, v, []uint32{1})
global.SetInitializer(init)
return global, ptr
}
开发者ID:kelsieflynn,项目名称:llgo,代码行数:46,代码来源:llvmtypes.go
示例16: basicRuntimeType
// basicRuntimeType creates the runtime type structure for
// a basic type. If underlying is true, then a new global
// is always created.
func (tm *TypeMap) basicRuntimeType(b *types.Basic, underlying bool) (global, ptr llvm.Value) {
var globalname string
if !underlying {
globalname = "__llgo.type.runtime." + tm.TypeString(b)
if tm.pkgpath != "runtime" {
global := llvm.AddGlobal(tm.module, tm.runtimeType, globalname)
global.SetInitializer(llvm.ConstNull(tm.runtimeType))
global.SetLinkage(llvm.CommonLinkage)
return global, global
}
}
rtype := tm.makeRtype(b, basicReflectKinds[b.Kind()])
global, ptr = tm.makeRuntimeTypeGlobal(rtype)
if globalname != "" {
global.SetName(globalname)
}
return global, ptr
}
开发者ID:quarnster,项目名称:llgo,代码行数:21,代码来源:typemap.go
示例17: makeSlice
func (tm *TypeMap) makeSlice(values []llvm.Value, slicetyp llvm.Type) llvm.Value {
ptrtyp := slicetyp.StructElementTypes()[0]
var globalptr llvm.Value
if len(values) > 0 {
array := llvm.ConstArray(ptrtyp.ElementType(), values)
globalptr = llvm.AddGlobal(tm.module, array.Type(), "")
globalptr.SetInitializer(array)
globalptr = llvm.ConstBitCast(globalptr, ptrtyp)
} else {
globalptr = llvm.ConstNull(ptrtyp)
}
len_ := llvm.ConstInt(tm.inttype, uint64(len(values)), false)
slice := llvm.ConstNull(slicetyp)
slice = llvm.ConstInsertValue(slice, globalptr, []uint32{0})
slice = llvm.ConstInsertValue(slice, len_, []uint32{1})
slice = llvm.ConstInsertValue(slice, len_, []uint32{2})
return slice
}
开发者ID:minux,项目名称:llgo,代码行数:18,代码来源:typemap.go
示例18: interfaceRuntimeType
func (tm *TypeMap) interfaceRuntimeType(i *types.Interface) (global, ptr llvm.Value) {
rtype := tm.makeRtype(i, reflect.Interface)
interfaceType := llvm.ConstNull(tm.runtimeInterfaceType)
interfaceType = llvm.ConstInsertValue(interfaceType, rtype, []uint32{0})
imethods := make([]llvm.Value, i.NumMethods())
for index := range imethods {
method := i.Method(index)
//name, pkgPath, type
imethod := llvm.ConstNull(tm.runtimeImethod)
name := tm.globalStringPtr(method.Name())
name = llvm.ConstBitCast(name, tm.runtimeImethod.StructElementTypes()[0])
imethod = llvm.ConstInsertValue(imethod, name, []uint32{0})
//imethod = llvm.ConstInsertValue(imethod, , []uint32{1})
//imethod = llvm.ConstInsertValue(imethod, , []uint32{2})
imethods[index] = imethod
}
var imethodsGlobalPtr llvm.Value
imethodPtrType := llvm.PointerType(tm.runtimeImethod, 0)
if len(imethods) > 0 {
imethodsArray := llvm.ConstArray(tm.runtimeImethod, imethods)
imethodsGlobalPtr = llvm.AddGlobal(tm.module, imethodsArray.Type(), "")
imethodsGlobalPtr.SetInitializer(imethodsArray)
imethodsGlobalPtr = llvm.ConstBitCast(imethodsGlobalPtr, imethodPtrType)
} else {
imethodsGlobalPtr = llvm.ConstNull(imethodPtrType)
}
len_ := llvm.ConstInt(tm.inttype, uint64(i.NumMethods()), false)
imethodsSliceType := tm.runtimeInterfaceType.StructElementTypes()[1]
imethodsSlice := llvm.ConstNull(imethodsSliceType)
imethodsSlice = llvm.ConstInsertValue(imethodsSlice, imethodsGlobalPtr, []uint32{0})
imethodsSlice = llvm.ConstInsertValue(imethodsSlice, len_, []uint32{1})
imethodsSlice = llvm.ConstInsertValue(imethodsSlice, len_, []uint32{2})
interfaceType = llvm.ConstInsertValue(interfaceType, imethodsSlice, []uint32{1})
return tm.makeRuntimeTypeGlobal(interfaceType)
}
开发者ID:hzmangel,项目名称:llgo,代码行数:40,代码来源:typemap.go
示例19: makeRtype
func (tm *TypeMap) makeRtype(t types.Type, k reflect.Kind) llvm.Value {
// Not sure if there's an easier way to do this, but if you just
// use ConstStruct, you end up getting a different llvm.Type.
lt := tm.ToLLVM(t)
typ := llvm.ConstNull(tm.runtimeType)
elementTypes := tm.runtimeType.StructElementTypes()
// Size.
size := llvm.SizeOf(lt)
if size.Type().IntTypeWidth() > elementTypes[0].IntTypeWidth() {
size = llvm.ConstTrunc(size, elementTypes[0])
}
typ = llvm.ConstInsertValue(typ, size, []uint32{0})
// TODO hash
// TODO padding
// Alignment.
align := llvm.ConstTrunc(llvm.AlignOf(lt), llvm.Int8Type())
typ = llvm.ConstInsertValue(typ, align, []uint32{3}) // var
typ = llvm.ConstInsertValue(typ, align, []uint32{4}) // field
// Kind.
kind := llvm.ConstInt(llvm.Int8Type(), uint64(k), false)
typ = llvm.ConstInsertValue(typ, kind, []uint32{5})
// Algorithm table.
alg := tm.makeAlgorithmTable(t)
algptr := llvm.AddGlobal(tm.module, alg.Type(), "")
algptr.SetInitializer(alg)
algptr = llvm.ConstBitCast(algptr, elementTypes[6])
typ = llvm.ConstInsertValue(typ, algptr, []uint32{6})
// String representation.
stringrep := tm.globalStringPtr(tm.TypeString(t))
typ = llvm.ConstInsertValue(typ, stringrep, []uint32{8})
// TODO gc
return typ
}
开发者ID:hzmangel,项目名称:llgo,代码行数:40,代码来源:typemap.go
示例20: makeRuntimeTypeGlobal
func (tm *TypeMap) makeRuntimeTypeGlobal(v llvm.Value) (global, ptr llvm.Value) {
runtimeTypeValue := llvm.ConstNull(tm.runtimeType)
initType := llvm.StructType([]llvm.Type{tm.runtimeType, v.Type()}, false)
global = llvm.AddGlobal(tm.module, initType, "")
ptr = llvm.ConstBitCast(global, llvm.PointerType(tm.runtimeType, 0))
// Set ptrToThis in v's commonType.
if v.Type() == tm.runtimeCommonType {
v = llvm.ConstInsertValue(v, ptr, []uint32{9})
} else {
commonType := llvm.ConstExtractValue(v, []uint32{0})
commonType = llvm.ConstInsertValue(commonType, ptr, []uint32{9})
v = llvm.ConstInsertValue(v, commonType, []uint32{0})
}
init := llvm.Undef(initType)
//runtimeTypeValue = llvm.ConstInsertValue() TODO
init = llvm.ConstInsertValue(init, runtimeTypeValue, []uint32{0})
init = llvm.ConstInsertValue(init, v, []uint32{1})
global.SetInitializer(init)
return
}
开发者ID:c0der007,项目名称:llgo,代码行数:23,代码来源:llvmtypes.go
注:本文中的github.com/axw/gollvm/llvm.AddGlobal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论