本文整理汇总了Golang中github.com/go-llvm/llvm.ConstInt函数的典型用法代码示例。如果您正苦于以下问题:Golang ConstInt函数的具体用法?Golang ConstInt怎么用?Golang ConstInt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ConstInt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: mdNode
func (d subrangeDescriptor) mdNode(info *DebugInfo) llvm.Value {
return llvm.MDNode([]llvm.Value{
llvm.ConstInt(llvm.Int32Type(), uint64(d.Tag())+llvm.LLVMDebugVersion, false),
llvm.ConstInt(llvm.Int64Type(), uint64(d.low), true),
llvm.ConstInt(llvm.Int64Type(), uint64(d.high), true),
})
}
示例3: setLocation
func (d *debugInfo) setLocation(b llvm.Builder, pos token.Pos) {
position := d.Fset.Position(pos)
b.SetCurrentDebugLocation(llvm.MDNode([]llvm.Value{
llvm.ConstInt(llvm.Int32Type(), uint64(position.Line), true),
llvm.ConstInt(llvm.Int32Type(), uint64(position.Column), true),
d.MDNode(d.context()),
llvm.Value{},
}))
}
示例4: callCap
func (c *compiler) callCap(arg *LLVMValue) *LLVMValue {
var v llvm.Value
switch typ := arg.Type().Underlying().(type) {
case *types.Array:
v = llvm.ConstInt(c.llvmtypes.inttype, uint64(typ.Len()), false)
case *types.Pointer:
atyp := typ.Elem().Underlying().(*types.Array)
v = llvm.ConstInt(c.llvmtypes.inttype, uint64(atyp.Len()), false)
case *types.Slice:
v = c.builder.CreateExtractValue(arg.LLVMValue(), 2, "")
case *types.Chan:
f := c.runtime.chancap.LLVMValue()
v = c.builder.CreateCall(f, []llvm.Value{arg.LLVMValue()}, "")
}
return c.NewValue(v, types.Typ[types.Int])
}
示例5: 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")
}
示例6: 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_
}
示例7: 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
}
示例8: arrayRuntimeType
func (tm *TypeMap) arrayRuntimeType(a *types.Array) (global, ptr llvm.Value) {
rtype := tm.makeRtype(a, reflect.Array)
elemRuntimeType := tm.ToRuntime(a.Elem())
sliceRuntimeType := tm.ToRuntime(types.NewSlice(a.Elem()))
uintptrlen := llvm.ConstInt(tm.target.IntPtrType(), uint64(a.Len()), false)
arrayType := llvm.ConstNull(tm.runtime.arrayType.llvm)
arrayType = llvm.ConstInsertValue(arrayType, rtype, []uint32{0})
arrayType = llvm.ConstInsertValue(arrayType, elemRuntimeType, []uint32{1})
arrayType = llvm.ConstInsertValue(arrayType, sliceRuntimeType, []uint32{2})
arrayType = llvm.ConstInsertValue(arrayType, uintptrlen, []uint32{3})
return tm.makeRuntimeTypeGlobal(arrayType, typeString(a))
}
示例9: callLen
func (c *compiler) callLen(arg *LLVMValue) *LLVMValue {
var lenvalue llvm.Value
switch typ := arg.Type().Underlying().(type) {
case *types.Array:
lenvalue = llvm.ConstInt(c.llvmtypes.inttype, uint64(typ.Len()), false)
case *types.Pointer:
atyp := typ.Elem().Underlying().(*types.Array)
lenvalue = llvm.ConstInt(c.llvmtypes.inttype, uint64(atyp.Len()), false)
case *types.Slice:
lenvalue = c.builder.CreateExtractValue(arg.LLVMValue(), 1, "")
case *types.Map:
f := c.runtime.maplen.LLVMValue()
lenvalue = c.builder.CreateCall(f, []llvm.Value{arg.LLVMValue()}, "")
case *types.Basic:
if isString(typ) {
lenvalue = c.builder.CreateExtractValue(arg.LLVMValue(), 1, "")
}
case *types.Chan:
f := c.runtime.chanlen.LLVMValue()
lenvalue = c.builder.CreateCall(f, []llvm.Value{arg.LLVMValue()}, "")
}
return c.NewValue(lenvalue, types.Typ[types.Int])
}
示例10: 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.
typ := llvm.ConstNull(tm.runtime.rtype.llvm)
elementTypes := tm.runtime.rtype.llvm.StructElementTypes()
// Size.
size := llvm.ConstInt(elementTypes[0], uint64(tm.Sizeof(t)), false)
typ = llvm.ConstInsertValue(typ, size, []uint32{0})
// TODO hash
// TODO padding
// Alignment.
align := llvm.ConstInt(llvm.Int8Type(), uint64(tm.Alignof(t)), false)
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(t.String())
typ = llvm.ConstInsertValue(typ, stringrep, []uint32{8})
// TODO gc
return typ
}
示例11: 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
}
示例12: 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
}
示例13: funcRuntimeType
func (tm *TypeMap) funcRuntimeType(f *types.Signature) (global, ptr llvm.Value) {
rtype := tm.makeRtype(f, reflect.Func)
funcType := llvm.ConstNull(tm.runtime.funcType.llvm)
global, ptr = tm.makeRuntimeTypeGlobal(funcType, typeString(f))
tm.types.Set(f, runtimeTypeInfo{global, ptr})
funcType = llvm.ConstInsertValue(funcType, rtype, []uint32{0})
// dotdotdot
if f.Variadic() {
variadic := llvm.ConstInt(llvm.Int1Type(), 1, false)
funcType = llvm.ConstInsertValue(funcType, variadic, []uint32{1})
}
// in
intypes := tm.rtypeSlice(f.Params())
funcType = llvm.ConstInsertValue(funcType, intypes, []uint32{2})
// out
outtypes := tm.rtypeSlice(f.Results())
funcType = llvm.ConstInsertValue(funcType, outtypes, []uint32{3})
global.SetInitializer(funcType)
return global, ptr
}
示例14: chanRuntimeType
func (tm *TypeMap) chanRuntimeType(c *types.Chan) (global, ptr llvm.Value) {
rtype := tm.makeRtype(c, reflect.Chan)
chanType := llvm.ConstNull(tm.runtime.chanType.llvm)
chanType = llvm.ConstInsertValue(chanType, rtype, []uint32{0})
chanType = llvm.ConstInsertValue(chanType, tm.ToRuntime(c.Elem()), []uint32{1})
// go/ast and reflect disagree on values for direction.
var dir reflect.ChanDir
switch c.Dir() {
case types.SendOnly:
dir = reflect.SendDir
case types.RecvOnly:
dir = reflect.RecvDir
case types.SendRecv:
dir = reflect.SendDir | reflect.RecvDir
}
uintptrdir := llvm.ConstInt(tm.target.IntPtrType(), uint64(dir), false)
chanType = llvm.ConstInsertValue(chanType, uintptrdir, []uint32{2})
return tm.makeRuntimeTypeGlobal(chanType, typeString(c))
}
示例15: shift
func (lhs *LLVMValue) shift(rhs *LLVMValue, op token.Token) *LLVMValue {
rhs = rhs.Convert(lhs.Type()).(*LLVMValue)
lhsval := lhs.LLVMValue()
bits := rhs.LLVMValue()
unsigned := isUnsigned(lhs.Type())
b := lhs.compiler.builder
// Shifting >= width of lhs yields undefined behaviour, so we must select.
max := llvm.ConstInt(bits.Type(), uint64(lhsval.Type().IntTypeWidth()-1), false)
var result llvm.Value
if !unsigned && op == token.SHR {
bits := b.CreateSelect(b.CreateICmp(llvm.IntULE, bits, max, ""), bits, max, "")
result = b.CreateAShr(lhsval, bits, "")
} else {
if op == token.SHL {
result = b.CreateShl(lhsval, bits, "")
} else {
result = b.CreateLShr(lhsval, bits, "")
}
zero := llvm.ConstNull(lhsval.Type())
result = b.CreateSelect(b.CreateICmp(llvm.IntULE, bits, max, ""), result, zero, "")
}
return lhs.compiler.NewValue(result, lhs.typ)
}