本文整理匯總了Golang中github.com/go-llvm/llvm.ConstNull函數的典型用法代碼示例。如果您正苦於以下問題:Golang ConstNull函數的具體用法?Golang ConstNull怎麽用?Golang ConstNull使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ConstNull函數的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: mdNode
func (d *LocalVariableDescriptor) mdNode(info *DebugInfo) llvm.Value {
return llvm.MDNode([]llvm.Value{
llvm.ConstInt(llvm.Int32Type(), uint64(d.Tag())+llvm.LLVMDebugVersion, false),
info.MDNode(d.Context),
llvm.MDString(d.Name),
info.mdFileNode(d.File),
llvm.ConstInt(llvm.Int32Type(), uint64(d.Line)|(uint64(d.Argument)<<24), false),
info.MDNode(d.Type),
llvm.ConstNull(llvm.Int32Type()), // flags
llvm.ConstNull(llvm.Int32Type()), // optional reference to inline location
})
}
示例3: 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)
}
示例4: compareStrings
func (c *compiler) compareStrings(lhs, rhs *LLVMValue, op token.Token) *LLVMValue {
strcmp := c.runtime.strcmp.LLVMValue()
_string := strcmp.Type().ElementType().ParamTypes()[0]
lhsstr := c.coerceString(lhs.LLVMValue(), _string)
rhsstr := c.coerceString(rhs.LLVMValue(), _string)
args := []llvm.Value{lhsstr, rhsstr}
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.NewValue(result, types.Typ[types.Bool])
}
示例5: UnaryOp
func (v *LLVMValue) UnaryOp(op token.Token) Value {
b := v.compiler.builder
switch op {
case token.SUB:
var value llvm.Value
if isFloat(v.typ) {
zero := llvm.ConstNull(v.compiler.types.ToLLVM(v.Type()))
value = b.CreateFSub(zero, v.LLVMValue(), "")
} else {
value = b.CreateNeg(v.LLVMValue(), "")
}
return v.compiler.NewValue(value, v.typ)
case token.ADD:
return v // No-op
case token.NOT:
value := b.CreateNot(v.LLVMValue(), "")
return v.compiler.NewValue(value, v.typ)
case token.XOR:
lhs := v.LLVMValue()
rhs := llvm.ConstAllOnes(lhs.Type())
value := b.CreateXor(lhs, rhs, "")
return v.compiler.NewValue(value, v.typ)
default:
panic(fmt.Sprintf("Unhandled operator: %s", op))
}
panic("unreachable")
}
示例6: stringIterNext
// stringIterNext advances the iterator, and returns the tuple (ok, k, v).
func (c *compiler) stringIterNext(str *LLVMValue, preds []llvm.BasicBlock) *LLVMValue {
// While Range/Next expresses a mutating operation, we represent them using
// a Phi node where the first incoming branch (before the loop), and all
// others take the previous value plus one.
//
// See ssa.go for comments on (and assertions of) our assumptions.
index := c.builder.CreatePHI(c.types.inttype, "index")
strnext := c.runtime.strnext.LLVMValue()
args := []llvm.Value{
c.coerceString(str.LLVMValue(), strnext.Type().ElementType().ParamTypes()[0]),
index,
}
result := c.builder.CreateCall(strnext, args, "")
nextindex := c.builder.CreateExtractValue(result, 0, "")
runeval := c.builder.CreateExtractValue(result, 1, "")
values := make([]llvm.Value, len(preds))
values[0] = llvm.ConstNull(index.Type())
for i, _ := range preds[1:] {
values[i+1] = nextindex
}
index.AddIncoming(values, preds)
// Create an (ok, index, rune) tuple.
ok := c.builder.CreateIsNotNull(nextindex, "")
typ := tupleType(types.Typ[types.Bool], types.Typ[types.Int], types.Typ[types.Rune])
tuple := llvm.Undef(c.types.ToLLVM(typ))
tuple = c.builder.CreateInsertValue(tuple, ok, 0, "")
tuple = c.builder.CreateInsertValue(tuple, index, 1, "")
tuple = c.builder.CreateInsertValue(tuple, runeval, 2, "")
return c.NewValue(tuple, typ)
}
示例7: 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)
}
示例8: 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
}
示例9: 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
}
示例10: slice
func (c *compiler) slice(x, low, high *LLVMValue) *LLVMValue {
if low != nil {
low = low.Convert(types.Typ[types.Int]).(*LLVMValue)
} else {
low = c.NewValue(llvm.ConstNull(c.types.inttype), types.Typ[types.Int])
}
if high != nil {
high = high.Convert(types.Typ[types.Int]).(*LLVMValue)
} else {
// all bits set is -1
high = c.NewValue(llvm.ConstAllOnes(c.types.inttype), types.Typ[types.Int])
}
switch typ := x.Type().Underlying().(type) {
case *types.Pointer: // *array
sliceslice := c.runtime.sliceslice.LLVMValue()
i8slice := sliceslice.Type().ElementType().ReturnType()
sliceValue := llvm.Undef(i8slice) // temporary slice
arraytyp := typ.Elem().Underlying().(*types.Array)
arrayptr := x.LLVMValue()
arrayptr = c.builder.CreateBitCast(arrayptr, i8slice.StructElementTypes()[0], "")
arraylen := llvm.ConstInt(c.llvmtypes.inttype, uint64(arraytyp.Len()), false)
sliceValue = c.builder.CreateInsertValue(sliceValue, arrayptr, 0, "")
sliceValue = c.builder.CreateInsertValue(sliceValue, arraylen, 1, "")
sliceValue = c.builder.CreateInsertValue(sliceValue, arraylen, 2, "")
sliceTyp := types.NewSlice(arraytyp.Elem())
runtimeTyp := c.types.ToRuntime(sliceTyp)
runtimeTyp = c.builder.CreatePtrToInt(runtimeTyp, c.target.IntPtrType(), "")
args := []llvm.Value{runtimeTyp, sliceValue, low.LLVMValue(), high.LLVMValue()}
result := c.builder.CreateCall(sliceslice, args, "")
llvmSliceTyp := c.types.ToLLVM(sliceTyp)
return c.NewValue(c.coerceSlice(result, llvmSliceTyp), sliceTyp)
case *types.Slice:
sliceslice := c.runtime.sliceslice.LLVMValue()
i8slice := sliceslice.Type().ElementType().ReturnType()
sliceValue := x.LLVMValue()
sliceTyp := sliceValue.Type()
sliceValue = c.coerceSlice(sliceValue, i8slice)
runtimeTyp := c.types.ToRuntime(x.Type())
runtimeTyp = c.builder.CreatePtrToInt(runtimeTyp, c.target.IntPtrType(), "")
args := []llvm.Value{runtimeTyp, sliceValue, low.LLVMValue(), high.LLVMValue()}
result := c.builder.CreateCall(sliceslice, args, "")
return c.NewValue(c.coerceSlice(result, sliceTyp), x.Type())
case *types.Basic:
stringslice := c.runtime.stringslice.LLVMValue()
llv := x.LLVMValue()
args := []llvm.Value{
c.coerceString(llv, stringslice.Type().ElementType().ParamTypes()[0]),
low.LLVMValue(),
high.LLVMValue(),
}
result := c.builder.CreateCall(stringslice, args, "")
return c.NewValue(c.coerceString(result, llv.Type()), x.Type())
default:
panic("unimplemented")
}
panic("unreachable")
}
示例11: mapRuntimeType
func (tm *TypeMap) mapRuntimeType(m *types.Map) (global, ptr llvm.Value) {
rtype := tm.makeRtype(m, reflect.Map)
mapType := llvm.ConstNull(tm.runtime.mapType.llvm)
mapType = llvm.ConstInsertValue(mapType, rtype, []uint32{0})
mapType = llvm.ConstInsertValue(mapType, tm.ToRuntime(m.Key()), []uint32{1})
mapType = llvm.ConstInsertValue(mapType, tm.ToRuntime(m.Elem()), []uint32{2})
return tm.makeRuntimeTypeGlobal(mapType, typeString(m))
}
示例12: boolLLVMValue
func boolLLVMValue(v bool) (lv llvm.Value) {
if v {
lv = llvm.ConstAllOnes(llvm.Int1Type())
} else {
lv = llvm.ConstNull(llvm.Int1Type())
}
return lv
}
示例13: 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
}
示例14: 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
}
示例15: sliceRuntimeType
func (tm *TypeMap) sliceRuntimeType(s *types.Slice) (global, ptr llvm.Value) {
rtype := tm.makeRtype(s, reflect.Slice)
sliceType := llvm.ConstNull(tm.runtime.sliceType.llvm)
global, ptr = tm.makeRuntimeTypeGlobal(sliceType, typeString(s))
tm.types.Set(s, runtimeTypeInfo{global, ptr})
sliceType = llvm.ConstInsertValue(sliceType, rtype, []uint32{0})
elemRuntimeType := tm.ToRuntime(s.Elem())
sliceType = llvm.ConstInsertValue(sliceType, elemRuntimeType, []uint32{1})
global.SetInitializer(sliceType)
return global, ptr
}