本文整理匯總了Golang中github.com/axw/gollvm/llvm.GlobalContext函數的典型用法代碼示例。如果您正苦於以下問題:Golang GlobalContext函數的具體用法?Golang GlobalContext怎麽用?Golang GlobalContext使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GlobalContext函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: funcLLVMType
func (tm *LLVMTypeMap) funcLLVMType(tstr string, f *types.Signature) llvm.Type {
typ, ok := tm.types[tstr]
if !ok {
// If there's a receiver change the receiver to an
// additional (first) parameter, and take the value of
// the resulting signature instead.
var param_types []llvm.Type
if recv := f.Recv(); recv != nil {
params := f.Params()
paramvars := make([]*types.Var, int(params.Len()+1))
paramvars[0] = recv
for i := 0; i < int(params.Len()); i++ {
paramvars[i+1] = params.At(i)
}
params = types.NewTuple(paramvars...)
f := types.NewSignature(nil, params, f.Results(), f.IsVariadic())
return tm.ToLLVM(f)
}
typ = llvm.GlobalContext().StructCreateNamed("")
tm.types[tstr] = typ
params := f.Params()
nparams := int(params.Len())
for i := 0; i < nparams; i++ {
typ := params.At(i).Type()
if f.IsVariadic() && i == nparams-1 {
typ = types.NewSlice(typ)
}
llvmtyp := tm.ToLLVM(typ)
param_types = append(param_types, llvmtyp)
}
var return_type llvm.Type
results := f.Results()
switch nresults := int(results.Len()); nresults {
case 0:
return_type = llvm.VoidType()
case 1:
return_type = tm.ToLLVM(results.At(0).Type())
default:
elements := make([]llvm.Type, nresults)
for i := range elements {
result := results.At(i)
elements[i] = tm.ToLLVM(result.Type())
}
return_type = llvm.StructType(elements, false)
}
fntyp := llvm.FunctionType(return_type, param_types, false)
fnptrtyp := llvm.PointerType(fntyp, 0)
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
elements := []llvm.Type{fnptrtyp, i8ptr} // func, closure
typ.StructSetBody(elements, false)
}
return typ
}
示例2: funcLLVMType
func (tm *llvmTypeMap) funcLLVMType(f *types.Signature, name string) llvm.Type {
// If there's a receiver change the receiver to an
// additional (first) parameter, and take the value of
// the resulting signature instead.
if recv := f.Recv(); recv != nil {
params := f.Params()
paramvars := make([]*types.Var, int(params.Len()+1))
paramvars[0] = recv
for i := 0; i < int(params.Len()); i++ {
paramvars[i+1] = params.At(i)
}
params = types.NewTuple(paramvars...)
f := types.NewSignature(nil, nil, params, f.Results(), f.Variadic())
return tm.toLLVM(f, name)
}
if typ, ok := tm.types.At(f).(llvm.Type); ok {
return typ
}
typ := llvm.GlobalContext().StructCreateNamed(name)
tm.types.Set(f, typ)
params := f.Params()
param_types := make([]llvm.Type, params.Len())
for i := range param_types {
llvmtyp := tm.ToLLVM(params.At(i).Type())
param_types[i] = llvmtyp
}
var return_type llvm.Type
results := f.Results()
switch nresults := int(results.Len()); nresults {
case 0:
return_type = llvm.VoidType()
case 1:
return_type = tm.ToLLVM(results.At(0).Type())
default:
elements := make([]llvm.Type, nresults)
for i := range elements {
result := results.At(i)
elements[i] = tm.ToLLVM(result.Type())
}
return_type = llvm.StructType(elements, false)
}
fntyp := llvm.FunctionType(return_type, param_types, false)
fnptrtyp := llvm.PointerType(fntyp, 0)
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
elements := []llvm.Type{fnptrtyp, i8ptr} // func, closure
typ.StructSetBody(elements, false)
return typ
}
示例3: pointerLLVMType
func (tm *LLVMTypeMap) pointerLLVMType(p *types.Pointer) llvm.Type {
if p.Elem().Underlying() == p {
// Recursive pointers must be handled specially, as
// LLVM does not permit recursive types except via
// named structs.
if tm.ptrstandin.IsNil() {
ctx := llvm.GlobalContext()
unique := ctx.StructCreateNamed("")
tm.ptrstandin = llvm.PointerType(unique, 0)
}
return llvm.PointerType(tm.ptrstandin, 0)
}
return llvm.PointerType(tm.ToLLVM(p.Elem()), 0)
}
示例4: sliceLLVMType
func (tm *LLVMTypeMap) sliceLLVMType(tstr string, s *types.Slice) llvm.Type {
typ, ok := tm.types[tstr]
if !ok {
typ = llvm.GlobalContext().StructCreateNamed("")
tm.types[tstr] = typ
elements := []llvm.Type{
llvm.PointerType(tm.ToLLVM(s.Elem()), 0),
tm.inttype,
tm.inttype,
}
typ.StructSetBody(elements, false)
}
return typ
}
示例5: structLLVMType
func (tm *LLVMTypeMap) structLLVMType(tstr string, s *types.Struct) llvm.Type {
typ, ok := tm.types[tstr]
if !ok {
typ = llvm.GlobalContext().StructCreateNamed("")
tm.types[tstr] = typ
elements := make([]llvm.Type, len(s.Fields))
for i, f := range s.Fields {
ft := f.Type.(types.Type)
elements[i] = tm.ToLLVM(ft)
}
typ.StructSetBody(elements, false)
}
return typ
}
示例6: sliceLLVMType
func (tm *llvmTypeMap) sliceLLVMType(s *types.Slice, name string) llvm.Type {
typ, ok := tm.types.At(s).(llvm.Type)
if !ok {
typ = llvm.GlobalContext().StructCreateNamed(name)
tm.types.Set(s, typ)
elements := []llvm.Type{
llvm.PointerType(tm.ToLLVM(s.Elem()), 0),
tm.inttype,
tm.inttype,
}
typ.StructSetBody(elements, false)
}
return typ
}
示例7: structLLVMType
func (tm *llvmTypeMap) structLLVMType(s *types.Struct, name string) llvm.Type {
typ, ok := tm.types.At(s).(llvm.Type)
if !ok {
typ = llvm.GlobalContext().StructCreateNamed(name)
tm.types.Set(s, typ)
elements := make([]llvm.Type, s.NumFields())
for i := range elements {
f := s.Field(i)
ft := f.Type()
elements[i] = tm.ToLLVM(ft)
}
typ.StructSetBody(elements, false)
}
return typ
}
示例8: mapLLVMType
func (tm *TypeMap) mapLLVMType(m *types.Map) llvm.Type {
// XXX This map type will change in the future, when I get around to it.
// At the moment, it's representing a really dumb singly linked list.
list_type := llvm.GlobalContext().StructCreateNamed("")
list_ptr_type := llvm.PointerType(list_type, 0)
size_type := llvm.Int32Type()
element_types := []llvm.Type{size_type, list_type}
typ := llvm.StructType(element_types, false)
tm.types[m] = typ
list_element_types := []llvm.Type{
list_ptr_type, tm.ToLLVM(m.Key), tm.ToLLVM(m.Elt)}
list_type.StructSetBody(list_element_types, false)
return typ
}
示例9: interfaceLLVMType
func (tm *llvmTypeMap) interfaceLLVMType(i *types.Interface, name string) llvm.Type {
if typ, ok := tm.types.At(i).(llvm.Type); ok {
return typ
}
// interface{} is represented as {type, value},
// and non-empty interfaces are represented as {itab, value}.
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
rtypeType := i8ptr
valueType := i8ptr
if name == "" {
name = i.String()
}
typ := llvm.GlobalContext().StructCreateNamed(name)
typ.StructSetBody([]llvm.Type{rtypeType, valueType}, false)
return typ
}
示例10: structLLVMType
func (tm *TypeMap) structLLVMType(s *types.Struct) llvm.Type {
// Types may be circular, so we need to first create an empty
// struct type, then fill in its body after visiting its
// members.
typ, ok := tm.types[s]
if !ok {
typ = llvm.GlobalContext().StructCreateNamed("")
tm.types[s] = typ
elements := make([]llvm.Type, len(s.Fields))
for i, f := range s.Fields {
ft := f.Type.(types.Type)
elements[i] = tm.ToLLVM(ft)
}
typ.StructSetBody(elements, false)
}
return typ
}
示例11: NewLLVMTypeMap
func NewLLVMTypeMap(target llvm.TargetData) *llvmTypeMap {
// spec says int is either 32-bit or 64-bit.
var inttype llvm.Type
if target.PointerSize() >= 8 {
inttype = llvm.Int64Type()
} else {
inttype = llvm.Int32Type()
}
return &llvmTypeMap{
StdSizes: &types.StdSizes{
WordSize: int64(target.PointerSize()),
MaxAlign: 8,
},
target: target,
inttype: inttype,
ptrstandin: llvm.GlobalContext().StructCreateNamed(""),
}
}
示例12: interfaceLLVMType
func (tm *LLVMTypeMap) interfaceLLVMType(tstr string, i *types.Interface) llvm.Type {
typ, ok := tm.types[tstr]
if !ok {
typ = llvm.GlobalContext().StructCreateNamed("")
tm.types[tstr] = typ
valptr_type := llvm.PointerType(llvm.Int8Type(), 0)
typptr_type := valptr_type // runtimeType may not be defined yet
elements := make([]llvm.Type, 2+i.NumMethods())
elements[0] = typptr_type // type
elements[1] = valptr_type // value
for n, m := range sortedMethods(i) {
fntype := m.Type()
elements[n+2] = tm.ToLLVM(fntype).StructElementTypes()[0]
}
typ.StructSetBody(elements, false)
}
return typ
}
示例13: interfaceLLVMType
func (tm *LLVMTypeMap) interfaceLLVMType(tstr string, i *types.Interface) llvm.Type {
typ, ok := tm.types[tstr]
if !ok {
typ = llvm.GlobalContext().StructCreateNamed("")
tm.types[tstr] = typ
valptr_type := llvm.PointerType(llvm.Int8Type(), 0)
typptr_type := valptr_type // runtimeType may not be defined yet
elements := make([]llvm.Type, 2+i.NumMethods())
elements[0] = typptr_type // type
elements[1] = valptr_type // value
for n := 0; n < i.NumMethods(); n++ {
// Add an opaque pointer parameter to the function for the
// struct pointer. Take a copy of the Type here, so we don't
// change how the Interface's TypeString is determined.
m := i.Method(n)
fntype := m.Type()
elements[n+2] = tm.ToLLVM(fntype).StructElementTypes()[0]
}
typ.StructSetBody(elements, false)
}
return typ
}
示例14: interfaceFuncWrapper
func (tm *TypeMap) interfaceFuncWrapper(f llvm.Value) llvm.Value {
ftyp := f.Type().ElementType()
paramTypes := ftyp.ParamTypes()
recvType := paramTypes[0]
paramTypes[0] = llvm.PointerType(llvm.Int8Type(), 0)
newf := llvm.AddFunction(f.GlobalParent(), f.Name()+".ifn", llvm.FunctionType(
ftyp.ReturnType(),
paramTypes,
ftyp.IsFunctionVarArg(),
))
b := llvm.GlobalContext().NewBuilder()
defer b.Dispose()
entry := llvm.AddBasicBlock(newf, "entry")
b.SetInsertPointAtEnd(entry)
args := make([]llvm.Value, len(paramTypes))
for i := range paramTypes {
args[i] = newf.Param(i)
}
recvBits := int(tm.target.TypeSizeInBits(recvType))
if recvBits > 0 {
args[0] = b.CreatePtrToInt(args[0], tm.target.IntPtrType(), "")
if args[0].Type().IntTypeWidth() > recvBits {
args[0] = b.CreateTrunc(args[0], llvm.IntType(recvBits), "")
}
args[0] = coerce(b, args[0], recvType)
} else {
args[0] = llvm.ConstNull(recvType)
}
result := b.CreateCall(f, args, "")
if result.Type().TypeKind() == llvm.VoidTypeKind {
b.CreateRetVoid()
} else {
b.CreateRet(result)
}
return newf
}
示例15: interfaceLLVMType
func (tm *LLVMTypeMap) interfaceLLVMType(tstr string, i *types.Interface) llvm.Type {
typ, ok := tm.types[tstr]
if !ok {
typ = llvm.GlobalContext().StructCreateNamed("")
tm.types[tstr] = typ
valptr_type := llvm.PointerType(llvm.Int8Type(), 0)
typptr_type := valptr_type // runtimeCommonType may not be defined yet
elements := make([]llvm.Type, 2+len(i.Methods))
elements[0] = typptr_type // type
elements[1] = valptr_type // value
for n, m := range i.Methods {
// Add an opaque pointer parameter to the function for the
// struct pointer.
fntype := m.Type.(*types.Func)
receiver_type := &types.Pointer{Base: types.Int8}
fntype.Recv = ast.NewObj(ast.Var, "")
fntype.Recv.Type = receiver_type
elements[n+2] = tm.ToLLVM(fntype)
fntype.Recv = nil
}
typ.StructSetBody(elements, false)
}
return typ
}