本文整理匯總了Golang中github.com/axw/gollvm/llvm.Value類的典型用法代碼示例。如果您正苦於以下問題:Golang Value類的具體用法?Golang Value怎麽用?Golang Value使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Value類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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)
}
示例3: createMalloc
func (c *compiler) createMalloc(size llvm.Value) llvm.Value {
malloc := c.NamedFunction("runtime.malloc", "func f(uintptr) unsafe.Pointer")
if size.Type().IntTypeWidth() > c.target.IntPtrType().IntTypeWidth() {
size = c.builder.CreateTrunc(size, c.target.IntPtrType(), "")
}
return c.builder.CreateCall(malloc, []llvm.Value{size}, "")
}
示例4: defineFreeFunction
func (c *compiler) defineFreeFunction(fn llvm.Value) {
entry := llvm.AddBasicBlock(fn, "entry")
c.builder.SetInsertPointAtEnd(entry)
ptr := fn.FirstParam()
ptrtyp := llvm.PointerType(llvm.Int8Type(), 0)
c.builder.CreateFree(c.builder.CreateIntToPtr(ptr, ptrtyp, ""))
c.builder.CreateRetVoid()
}
示例5: createGlobalVariableMetadata
// Debug intrinsic collectors.
func createGlobalVariableMetadata(global llvm.Value) llvm.DebugDescriptor {
return &llvm.GlobalVariableDescriptor{
Name: global.Name(),
DisplayName: global.Name(),
//File:
//Line:
Type: int32_debug_type, // FIXME
Value: global}
}
示例6: createMalloc
func (c *compiler) createMalloc(size llvm.Value) llvm.Value {
malloc := c.NamedFunction("runtime.malloc", "func(uintptr) unsafe.Pointer")
switch n := size.Type().IntTypeWidth() - c.target.IntPtrType().IntTypeWidth(); {
case n < 0:
size = c.builder.CreateZExt(size, c.target.IntPtrType(), "")
case n > 0:
size = c.builder.CreateTrunc(size, c.target.IntPtrType(), "")
}
return c.builder.CreateCall(malloc, []llvm.Value{size}, "")
}
示例7: createMalloc
func (c *compiler) createMalloc(size llvm.Value) llvm.Value {
malloc := c.runtime.malloc.LLVMValue()
switch n := size.Type().IntTypeWidth() - c.target.IntPtrType().IntTypeWidth(); {
case n < 0:
size = c.builder.CreateZExt(size, c.target.IntPtrType(), "")
case n > 0:
size = c.builder.CreateTrunc(size, c.target.IntPtrType(), "")
}
return c.builder.CreateCall(malloc, []llvm.Value{size}, "")
}
示例8: defineMallocFunction
func (c *compiler) defineMallocFunction(fn llvm.Value) {
entry := llvm.AddBasicBlock(fn, "entry")
c.builder.SetInsertPointAtEnd(entry)
size := fn.FirstParam()
ptr := c.builder.CreateArrayMalloc(llvm.Int8Type(), size, "")
// XXX memset to zero, or leave that to Go runtime code?
fn_type := fn.Type().ElementType()
result := c.builder.CreatePtrToInt(ptr, fn_type.ReturnType(), "")
c.builder.CreateRet(result)
}
示例9: CreateLoad
func (b *Builder) CreateLoad(v llvm.Value, name string) llvm.Value {
if v.Type().ElementType() == b.types.ptrstandin {
// We represent recursive pointer types (T = *T)
// in LLVM as a pointer to "ptrstdin", where
// ptrstandin is a unique named struct.
//
// Cast the the pointer to a pointer to its own type first.
v = b.CreateBitCast(v, llvm.PointerType(v.Type(), 0), "")
}
return b.Builder.CreateLoad(v, name)
}
示例10: makeFunc
func (c *compiler) makeFunc(ident *ast.Ident, ftyp *types.Signature) *LLVMValue {
fname := ident.String()
if ftyp.Recv() == nil && fname == "init" {
// Make "init" functions anonymous.
fname = ""
} else {
var pkgname string
if recv := ftyp.Recv(); recv != nil {
var recvname string
switch recvtyp := recv.Type().(type) {
case *types.Pointer:
if named, ok := recvtyp.Elem().(*types.Named); ok {
obj := named.Obj()
recvname = "*" + obj.Name()
pkgname = obj.Pkg().Path()
}
case *types.Named:
named := recvtyp
obj := named.Obj()
recvname = obj.Name()
pkgname = obj.Pkg().Path()
}
if recvname != "" {
fname = fmt.Sprintf("%s.%s", recvname, fname)
} else {
// If the receiver is an unnamed struct, we're
// synthesising a method for an unnamed struct
// type. There's no meaningful name to give the
// function, so leave it up to LLVM.
fname = ""
}
} else {
obj := c.typeinfo.Objects[ident]
pkgname = obj.Pkg().Path()
}
if fname != "" {
fname = pkgname + "." + fname
}
}
// gcimporter may produce multiple AST objects for the same function.
llvmftyp := c.types.ToLLVM(ftyp)
var fn llvm.Value
if fname != "" {
fn = c.module.Module.NamedFunction(fname)
}
if fn.IsNil() {
llvmfptrtyp := llvmftyp.StructElementTypes()[0].ElementType()
fn = llvm.AddFunction(c.module.Module, fname, llvmfptrtyp)
}
fn = llvm.ConstInsertValue(llvm.ConstNull(llvmftyp), fn, []uint32{0})
return c.NewValue(fn, ftyp)
}
示例11: coerce
// coerce yields a value of the the type specified, initialised
// to the exact bit pattern as in the specified value.
//
// Note: the specified value must be a non-aggregate, and its type
// and the specified type must have the same size.
func (c *compiler) coerce(v llvm.Value, t llvm.Type) llvm.Value {
switch t.TypeKind() {
case llvm.ArrayTypeKind, llvm.StructTypeKind:
ptr := c.builder.CreateAlloca(t, "")
ptrv := c.builder.CreateBitCast(ptr, llvm.PointerType(v.Type(), 0), "")
c.builder.CreateStore(v, ptrv)
return c.builder.CreateLoad(ptr, "")
default:
return c.builder.CreateBitCast(v, t, "")
}
panic("unreachable")
}
示例12: newStackVarEx
func (c *compiler) newStackVarEx(argument int, stackf *LLVMValue, v types.Object, value llvm.Value, name string) (stackvalue llvm.Value, stackvar *LLVMValue) {
typ := v.Type()
// We need to put alloca instructions in the top block or the values
// displayed when inspecting these variables in a debugger will be
// completely messed up.
curBlock := c.builder.GetInsertBlock()
if p := curBlock.Parent(); !p.IsNil() {
fb := p.FirstBasicBlock()
fi := fb.FirstInstruction()
if !fb.IsNil() && !fi.IsNil() {
c.builder.SetInsertPointBefore(fi)
}
}
old := c.builder.CurrentDebugLocation()
c.builder.SetCurrentDebugLocation(llvm.Value{})
stackvalue = c.builder.CreateAlloca(c.types.ToLLVM(typ), name)
// For arguments we want to insert the store instruction
// without debug information to ensure that they are executed
// (and hence have proper values) before the debugger hits the
// first line in a function.
if argument == 0 {
c.builder.SetCurrentDebugLocation(old)
c.builder.SetInsertPointAtEnd(curBlock)
}
if !value.IsNil() {
c.builder.CreateStore(value, stackvalue)
}
c.builder.SetCurrentDebugLocation(old)
c.builder.SetInsertPointAtEnd(curBlock)
ptrvalue := c.NewValue(stackvalue, types.NewPointer(typ))
stackvar = ptrvalue.makePointee()
stackvar.stack = stackf
c.objectdata[v].Value = stackvar
file := c.fileset.File(v.Pos())
tag := llvm.DW_TAG_auto_variable
if argument > 0 {
tag = llvm.DW_TAG_arg_variable
}
ld := llvm.NewLocalVariableDescriptor(tag)
ld.Argument = uint32(argument)
ld.Line = uint32(file.Line(v.Pos()))
ld.Name = name
ld.File = &llvm.ContextDescriptor{llvm.FileDescriptor(file.Name())}
ld.Type = c.tollvmDebugDescriptor(typ)
ld.Context = c.currentDebugContext()
c.builder.InsertDeclare(c.module.Module, llvm.MDNode([]llvm.Value{stackvalue}), c.debug_info.MDNode(ld))
return stackvalue, stackvar
}
示例13: CreateStore
func (b *Builder) CreateStore(v, ptr llvm.Value) {
if !b.types.ptrstandin.IsNil() {
vtyp, ptrtyp := v.Type(), ptr.Type()
if vtyp == ptrtyp {
// We must be dealing with a pointer to a recursive pointer
// type, so bitcast the pointer to a pointer to its own
// type first.
ptr = b.CreateBitCast(ptr, llvm.PointerType(ptrtyp, 0), "")
}
}
b.Builder.CreateStore(v, ptr)
}
示例14: memsetZero
func (c *compiler) memsetZero(ptr llvm.Value, size llvm.Value) {
memset := c.runtime.memset.LLVMValue()
switch n := size.Type().IntTypeWidth() - c.target.IntPtrType().IntTypeWidth(); {
case n < 0:
size = c.builder.CreateZExt(size, c.target.IntPtrType(), "")
case n > 0:
size = c.builder.CreateTrunc(size, c.target.IntPtrType(), "")
}
ptr = c.builder.CreatePtrToInt(ptr, c.target.IntPtrType(), "")
fill := llvm.ConstNull(llvm.Int8Type())
c.builder.CreateCall(memset, []llvm.Value{ptr, fill, size}, "")
}
示例15: memsetZero
func (c *compiler) memsetZero(ptr llvm.Value, size llvm.Value) {
memset := c.NamedFunction("runtime.memset", "func f(dst unsafe.Pointer, fill byte, size uintptr)")
switch n := size.Type().IntTypeWidth() - c.target.IntPtrType().IntTypeWidth(); {
case n < 0:
size = c.builder.CreateZExt(size, c.target.IntPtrType(), "")
case n > 0:
size = c.builder.CreateTrunc(size, c.target.IntPtrType(), "")
}
ptr = c.builder.CreatePtrToInt(ptr, c.target.IntPtrType(), "")
fill := llvm.ConstNull(llvm.Int8Type())
c.builder.CreateCall(memset, []llvm.Value{ptr, fill, size}, "")
}