本文整理匯總了Golang中github.com/axw/gollvm/llvm.ConstBitCast函數的典型用法代碼示例。如果您正苦於以下問題:Golang ConstBitCast函數的具體用法?Golang ConstBitCast怎麽用?Golang ConstBitCast使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ConstBitCast函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: interfaceRuntimeType
func (tm *TypeMap) interfaceRuntimeType(i *types.Interface) (global, ptr llvm.Value) {
rtype := tm.makeRtype(i, reflect.Interface)
interfaceType := llvm.ConstNull(tm.runtime.interfaceType.llvm)
global, ptr = tm.makeRuntimeTypeGlobal(interfaceType, typeString(i))
tm.types.Set(i, runtimeTypeInfo{global, ptr})
interfaceType = llvm.ConstInsertValue(interfaceType, rtype, []uint32{0})
methodset := tm.MethodSet(i)
imethods := make([]llvm.Value, methodset.Len())
for index := 0; index < methodset.Len(); index++ {
method := methodset.At(index).Obj()
imethod := llvm.ConstNull(tm.runtime.imethod.llvm)
name := tm.globalStringPtr(method.Name())
name = llvm.ConstBitCast(name, tm.runtime.imethod.llvm.StructElementTypes()[0])
mtyp := tm.ToRuntime(method.Type())
imethod = llvm.ConstInsertValue(imethod, name, []uint32{0})
if !ast.IsExported(method.Name()) {
pkgpath := tm.globalStringPtr(method.Pkg().Path())
pkgpath = llvm.ConstBitCast(pkgpath, tm.runtime.imethod.llvm.StructElementTypes()[1])
imethod = llvm.ConstInsertValue(imethod, pkgpath, []uint32{1})
}
imethod = llvm.ConstInsertValue(imethod, mtyp, []uint32{2})
imethods[index] = imethod
}
imethodsSliceType := tm.runtime.interfaceType.llvm.StructElementTypes()[1]
imethodsSlice := tm.makeSlice(imethods, imethodsSliceType)
interfaceType = llvm.ConstInsertValue(interfaceType, imethodsSlice, []uint32{1})
global.SetInitializer(interfaceType)
return global, ptr
}
示例2: interfaceRuntimeType
func (tm *TypeMap) interfaceRuntimeType(tstr string, i *types.Interface) (global, ptr llvm.Value) {
rtype := tm.makeRtype(i, reflect.Interface)
interfaceType := llvm.ConstNull(tm.runtimeInterfaceType)
global, ptr = tm.makeRuntimeTypeGlobal(interfaceType)
tm.types.record(tstr, global, ptr)
interfaceType = llvm.ConstInsertValue(interfaceType, rtype, []uint32{0})
methodset := i.MethodSet()
imethods := make([]llvm.Value, methodset.Len())
for index := 0; index < methodset.Len(); index++ {
method := methodset.At(index).Obj()
imethod := llvm.ConstNull(tm.runtimeImethod)
name := tm.globalStringPtr(method.Name())
name = llvm.ConstBitCast(name, tm.runtimeImethod.StructElementTypes()[0])
//pkgpath := tm.globalStringPtr(tm.functions.objectdata[method].Package.Path())
//pkgpath = llvm.ConstBitCast(name, tm.runtimeImethod.StructElementTypes()[1])
mtyp := tm.ToRuntime(method.Type())
imethod = llvm.ConstInsertValue(imethod, name, []uint32{0})
//imethod = llvm.ConstInsertValue(imethod, pkgpath, []uint32{1})
imethod = llvm.ConstInsertValue(imethod, mtyp, []uint32{2})
imethods[index] = imethod
}
imethodsSliceType := tm.runtimeInterfaceType.StructElementTypes()[1]
imethodsSlice := tm.makeSlice(imethods, imethodsSliceType)
interfaceType = llvm.ConstInsertValue(interfaceType, imethodsSlice, []uint32{1})
global.SetInitializer(interfaceType)
return global, ptr
}
示例3: uncommonType
func (tm *TypeMap) uncommonType(n *types.Named, ptr bool) llvm.Value {
uncommonTypeInit := llvm.ConstNull(tm.runtimeUncommonType)
namePtr := tm.globalStringPtr(n.Obj().Name())
uncommonTypeInit = llvm.ConstInsertValue(uncommonTypeInit, namePtr, []uint32{0})
_, path := tm.qualifiedName(n)
pkgpathPtr := tm.globalStringPtr(path)
uncommonTypeInit = llvm.ConstInsertValue(uncommonTypeInit, pkgpathPtr, []uint32{1})
methodset := tm.functions.methods(n)
methodfuncs := methodset.nonptr
if ptr {
methodfuncs = methodset.ptr
}
// Store methods.
methods := make([]llvm.Value, len(methodfuncs))
for i, mfunc := range methodfuncs {
ftyp := mfunc.Type().(*types.Signature)
method := llvm.ConstNull(tm.runtimeMethod)
name := tm.globalStringPtr(mfunc.Name())
name = llvm.ConstBitCast(name, tm.runtimeMethod.StructElementTypes()[0])
// name
method = llvm.ConstInsertValue(method, name, []uint32{0})
// pkgPath
method = llvm.ConstInsertValue(method, pkgpathPtr, []uint32{1})
// mtyp (method type, no receiver)
{
ftyp := types.NewSignature(nil, nil, ftyp.Params(), ftyp.Results(), ftyp.IsVariadic())
mtyp := tm.ToRuntime(ftyp)
method = llvm.ConstInsertValue(method, mtyp, []uint32{2})
}
// typ (function type, with receiver)
typ := tm.ToRuntime(ftyp)
method = llvm.ConstInsertValue(method, typ, []uint32{3})
// tfn (standard method/function pointer for plain method calls)
tfn := tm.resolver.Resolve(tm.functions.objectdata[mfunc].Ident).LLVMValue()
tfn = llvm.ConstExtractValue(tfn, []uint32{0})
tfn = llvm.ConstPtrToInt(tfn, tm.target.IntPtrType())
// ifn (single-word receiver function pointer for interface calls)
ifn := tfn
if !ptr && tm.Sizeof(ftyp.Recv().Type()) > int64(tm.target.PointerSize()) {
mfunc := methodset.lookup(mfunc.Name(), true)
ifn = tm.resolver.Resolve(tm.functions.objectdata[mfunc].Ident).LLVMValue()
ifn = llvm.ConstExtractValue(ifn, []uint32{0})
ifn = llvm.ConstPtrToInt(ifn, tm.target.IntPtrType())
}
method = llvm.ConstInsertValue(method, ifn, []uint32{4})
method = llvm.ConstInsertValue(method, tfn, []uint32{5})
methods[i] = method
}
methodsSliceType := tm.runtimeUncommonType.StructElementTypes()[2]
methodsSlice := tm.makeSlice(methods, methodsSliceType)
uncommonTypeInit = llvm.ConstInsertValue(uncommonTypeInit, methodsSlice, []uint32{2})
return uncommonTypeInit
}
示例4: 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
}
示例5: 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
}
示例6: 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
}
示例7: 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
}
示例8: structRuntimeType
func (tm *TypeMap) structRuntimeType(s *types.Struct) (global, ptr llvm.Value) {
rtype := tm.makeRtype(s, reflect.Struct)
structType := llvm.ConstNull(tm.runtime.structType.llvm)
structType = llvm.ConstInsertValue(structType, rtype, []uint32{0})
global, ptr = tm.makeRuntimeTypeGlobal(structType, typeString(s))
tm.types.Set(s, runtimeTypeInfo{global, ptr})
fieldVars := make([]*types.Var, s.NumFields())
for i := range fieldVars {
fieldVars[i] = s.Field(i)
}
offsets := tm.Offsetsof(fieldVars)
structFields := make([]llvm.Value, len(fieldVars))
for i := range structFields {
field := fieldVars[i]
structField := llvm.ConstNull(tm.runtime.structField.llvm)
if !field.Anonymous() {
name := tm.globalStringPtr(field.Name())
name = llvm.ConstBitCast(name, tm.runtime.structField.llvm.StructElementTypes()[0])
structField = llvm.ConstInsertValue(structField, name, []uint32{0})
}
if !ast.IsExported(field.Name()) {
pkgpath := tm.globalStringPtr(field.Pkg().Path())
pkgpath = llvm.ConstBitCast(pkgpath, tm.runtime.structField.llvm.StructElementTypes()[1])
structField = llvm.ConstInsertValue(structField, pkgpath, []uint32{1})
}
fieldType := tm.ToRuntime(field.Type())
structField = llvm.ConstInsertValue(structField, fieldType, []uint32{2})
if tag := s.Tag(i); tag != "" {
tag := tm.globalStringPtr(tag)
tag = llvm.ConstBitCast(tag, tm.runtime.structField.llvm.StructElementTypes()[3])
structField = llvm.ConstInsertValue(structField, tag, []uint32{3})
}
offset := llvm.ConstInt(tm.runtime.structField.llvm.StructElementTypes()[4], uint64(offsets[i]), false)
structField = llvm.ConstInsertValue(structField, offset, []uint32{4})
structFields[i] = structField
}
structFieldsSliceType := tm.runtime.structType.llvm.StructElementTypes()[1]
structFieldsSlice := tm.makeSlice(structFields, structFieldsSliceType)
structType = llvm.ConstInsertValue(structType, structFieldsSlice, []uint32{1})
global.SetInitializer(structType)
return global, ptr
}
示例9: 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
}
示例10: 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)
}
示例11: 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
}
示例12: 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
}
示例13: 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
}
示例14: 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
}
示例15: convertI2V
// convertI2V converts an interface to a value.
func (v *LLVMValue) convertI2V(typ types.Type) (result, success Value) {
typptrType := llvm.PointerType(llvm.Int8Type(), 0)
runtimeType := v.compiler.types.ToRuntime(typ)
runtimeType = llvm.ConstBitCast(runtimeType, typptrType)
vval := v.LLVMValue()
builder := v.compiler.builder
ifaceType := builder.CreateExtractValue(vval, 0, "")
diff := builder.CreatePtrDiff(runtimeType, ifaceType, "")
zero := llvm.ConstNull(diff.Type())
predicate := builder.CreateICmp(llvm.IntEQ, diff, zero, "")
// If result is zero, then we've got a match.
end := llvm.InsertBasicBlock(builder.GetInsertBlock(), "end")
end.MoveAfter(builder.GetInsertBlock())
nonmatch := llvm.InsertBasicBlock(end, "nonmatch")
match := llvm.InsertBasicBlock(nonmatch, "match")
builder.CreateCondBr(predicate, match, nonmatch)
builder.SetInsertPointAtEnd(match)
matchResultValue := v.loadI2V(typ).LLVMValue()
builder.CreateBr(end)
builder.SetInsertPointAtEnd(nonmatch)
nonmatchResultValue := llvm.ConstNull(matchResultValue.Type())
builder.CreateBr(end)
builder.SetInsertPointAtEnd(end)
successValue := builder.CreatePHI(llvm.Int1Type(), "")
resultValue := builder.CreatePHI(matchResultValue.Type(), "")
successValues := []llvm.Value{llvm.ConstAllOnes(llvm.Int1Type()), llvm.ConstNull(llvm.Int1Type())}
successBlocks := []llvm.BasicBlock{match, nonmatch}
successValue.AddIncoming(successValues, successBlocks)
success = v.compiler.NewLLVMValue(successValue, types.Bool)
resultValues := []llvm.Value{matchResultValue, nonmatchResultValue}
resultBlocks := []llvm.BasicBlock{match, nonmatch}
resultValue.AddIncoming(resultValues, resultBlocks)
result = v.compiler.NewLLVMValue(resultValue, typ)
return result, success
}