本文整理汇总了Golang中github.com/axw/gollvm/llvm.AddBasicBlock函数的典型用法代码示例。如果您正苦于以下问题:Golang AddBasicBlock函数的具体用法?Golang AddBasicBlock怎么用?Golang AddBasicBlock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AddBasicBlock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: VisitIfStmt
func (c *compiler) VisitIfStmt(stmt *ast.IfStmt) {
currBlock := c.builder.GetInsertBlock()
resumeBlock := llvm.AddBasicBlock(currBlock.Parent(), "endif")
resumeBlock.MoveAfter(currBlock)
defer c.builder.SetInsertPointAtEnd(resumeBlock)
var ifBlock, elseBlock llvm.BasicBlock
if stmt.Else != nil {
elseBlock = llvm.InsertBasicBlock(resumeBlock, "else")
ifBlock = llvm.InsertBasicBlock(elseBlock, "if")
} else {
ifBlock = llvm.InsertBasicBlock(resumeBlock, "if")
}
if stmt.Else == nil {
elseBlock = resumeBlock
}
if stmt.Init != nil {
c.VisitStmt(stmt.Init)
}
cond_val := c.VisitExpr(stmt.Cond)
c.builder.CreateCondBr(cond_val.LLVMValue(), ifBlock, elseBlock)
c.builder.SetInsertPointAtEnd(ifBlock)
c.VisitBlockStmt(stmt.Body, false)
c.maybeImplicitBranch(resumeBlock)
if stmt.Else != nil {
c.builder.SetInsertPointAtEnd(elseBlock)
c.VisitStmt(stmt.Else)
c.maybeImplicitBranch(resumeBlock)
}
}
开发者ID:qioixiy,项目名称:llgo,代码行数:33,代码来源:stmt.go
示例2: compileLogicalOp
// Binary logical operators are handled specially, outside of the Value
// type, because of the need to perform lazy evaluation.
//
// Binary logical operators are implemented using a Phi node, which takes
// on the appropriate value depending on which basic blocks branch to it.
func (c *compiler) compileLogicalOp(op token.Token, lhs Value, rhsFunc func() Value) Value {
lhsBlock := c.builder.GetInsertBlock()
resultBlock := llvm.AddBasicBlock(lhsBlock.Parent(), "")
resultBlock.MoveAfter(lhsBlock)
rhsBlock := llvm.InsertBasicBlock(resultBlock, "")
falseBlock := llvm.InsertBasicBlock(resultBlock, "")
if op == token.LOR {
c.builder.CreateCondBr(lhs.LLVMValue(), resultBlock, rhsBlock)
} else {
c.builder.CreateCondBr(lhs.LLVMValue(), rhsBlock, falseBlock)
}
c.builder.SetInsertPointAtEnd(rhsBlock)
rhs := rhsFunc()
rhsBlock = c.builder.GetInsertBlock() // rhsFunc may create blocks
c.builder.CreateCondBr(rhs.LLVMValue(), resultBlock, falseBlock)
c.builder.SetInsertPointAtEnd(falseBlock)
c.builder.CreateBr(resultBlock)
c.builder.SetInsertPointAtEnd(resultBlock)
result := c.builder.CreatePHI(llvm.Int1Type(), "")
trueValue := llvm.ConstAllOnes(llvm.Int1Type())
falseValue := llvm.ConstNull(llvm.Int1Type())
var values []llvm.Value
var blocks []llvm.BasicBlock
if op == token.LOR {
values = []llvm.Value{trueValue, trueValue, falseValue}
blocks = []llvm.BasicBlock{lhsBlock, rhsBlock, falseBlock}
} else {
values = []llvm.Value{trueValue, falseValue}
blocks = []llvm.BasicBlock{rhsBlock, falseBlock}
}
result.AddIncoming(values, blocks)
return c.NewLLVMValue(result, types.Bool)
}
开发者ID:kisielk,项目名称:llgo,代码行数:40,代码来源:expr.go
示例3: contextFunction
// contextFunction creates a wrapper function that
// has the same signature as the specified function,
// but has an additional first parameter that accepts
// and ignores the function context value.
//
// contextFunction must be called with a global function
// pointer.
func contextFunction(c *compiler, f *LLVMValue) *LLVMValue {
defer c.builder.SetInsertPointAtEnd(c.builder.GetInsertBlock())
resultType := c.llvmtypes.ToLLVM(f.Type())
fnptr := f.LLVMValue()
contextType := resultType.StructElementTypes()[1]
llfntyp := fnptr.Type().ElementType()
llfntyp = llvm.FunctionType(
llfntyp.ReturnType(),
append([]llvm.Type{contextType}, llfntyp.ParamTypes()...),
llfntyp.IsFunctionVarArg(),
)
wrapper := llvm.AddFunction(c.module.Module, fnptr.Name()+".ctx", llfntyp)
wrapper.SetLinkage(llvm.PrivateLinkage)
entry := llvm.AddBasicBlock(wrapper, "entry")
c.builder.SetInsertPointAtEnd(entry)
args := make([]llvm.Value, len(llfntyp.ParamTypes())-1)
for i := range args {
args[i] = wrapper.Param(i + 1)
}
result := c.builder.CreateCall(fnptr, args, "")
switch nresults := f.Type().(*types.Signature).Results().Len(); nresults {
case 0:
c.builder.CreateRetVoid()
case 1:
c.builder.CreateRet(result)
default:
results := make([]llvm.Value, nresults)
for i := range results {
results[i] = c.builder.CreateExtractValue(result, i, "")
}
c.builder.CreateAggregateRet(results)
}
return c.NewValue(wrapper, f.Type())
}
开发者ID:pcc,项目名称:llgo,代码行数:41,代码来源:ssa.go
示例4: defineMemcpyFunction
func (c *compiler) defineMemcpyFunction(fn llvm.Value) {
entry := llvm.AddBasicBlock(fn, "entry")
c.builder.SetInsertPointAtEnd(entry)
dst, src, size := fn.Param(0), fn.Param(1), fn.Param(2)
pint8 := llvm.PointerType(llvm.Int8Type(), 0)
dst = c.builder.CreateIntToPtr(dst, pint8, "")
src = c.builder.CreateIntToPtr(src, pint8, "")
sizeType := size.Type()
sizeBits := sizeType.IntTypeWidth()
memcpyName := "llvm.memcpy.p0i8.p0i8.i" + strconv.Itoa(sizeBits)
memcpy := c.module.NamedFunction(memcpyName)
if memcpy.IsNil() {
paramtypes := []llvm.Type{
pint8, pint8, size.Type(), llvm.Int32Type(), llvm.Int1Type()}
memcpyType := llvm.FunctionType(llvm.VoidType(), paramtypes, false)
memcpy = llvm.AddFunction(c.module.Module, memcpyName, memcpyType)
}
args := []llvm.Value{
dst, src, size,
llvm.ConstInt(llvm.Int32Type(), 1, false), // single byte alignment
llvm.ConstInt(llvm.Int1Type(), 0, false), // not volatile
}
c.builder.CreateCall(memcpy, args, "")
c.builder.CreateRetVoid()
}
开发者ID:prattmic,项目名称:llgo,代码行数:28,代码来源:intrinsics.go
示例5: 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()
}
开发者ID:hzmangel,项目名称:llgo,代码行数:8,代码来源:intrinsics.go
示例6: promoteMethod
// promoteMethod promotes a named type's method to another type
// which has embedded the named type.
func (c *compiler) promoteMethod(m *types.Func, recv types.Type, indices []int) types.Object {
var pkg *types.Package
if recv, ok := recv.(*types.Named); ok {
pkg = c.objectdata[recv.Obj()].Package
}
recvvar := types.NewVar(pkg, "", recv)
sig := m.Type().(*types.Signature)
sig = types.NewSignature(recvvar, sig.Params(), sig.Results(), sig.IsVariadic())
f := &synthFunc{pkg: pkg, name: m.Name(), typ: sig}
ident := ast.NewIdent(f.Name())
var isptr bool
if ptr, ok := recv.(*types.Pointer); ok {
isptr = true
recv = ptr.Elem()
}
c.objects[ident] = f
c.objectdata[f] = &ObjectData{Ident: ident, Package: pkg}
if pkg == nil || pkg == c.pkg {
if currblock := c.builder.GetInsertBlock(); !currblock.IsNil() {
defer c.builder.SetInsertPointAtEnd(currblock)
}
llvmfn := c.Resolve(ident).LLVMValue()
llvmfn = c.builder.CreateExtractValue(llvmfn, 0, "")
llvmfn.SetLinkage(llvm.LinkOnceODRLinkage)
entry := llvm.AddBasicBlock(llvmfn, "entry")
c.builder.SetInsertPointAtEnd(entry)
realfn := c.Resolve(c.objectdata[m].Ident).LLVMValue()
realfn = c.builder.CreateExtractValue(realfn, 0, "")
args := llvmfn.Params()
recvarg := args[0]
if !isptr {
ptr := c.builder.CreateAlloca(recvarg.Type(), "")
c.builder.CreateStore(recvarg, ptr)
recvarg = ptr
}
for _, i := range indices {
if i == -1 {
recvarg = c.builder.CreateLoad(recvarg, "")
} else {
recvarg = c.builder.CreateStructGEP(recvarg, i, "")
}
}
args[0] = recvarg
result := c.builder.CreateCall(realfn, args, "")
if sig.Results().Len() == 0 {
c.builder.CreateRetVoid()
} else {
c.builder.CreateRet(result)
}
}
return f
}
开发者ID:hzmangel,项目名称:llgo,代码行数:60,代码来源:functions.go
示例7: VisitForStmt
func (c *compiler) VisitForStmt(stmt *ast.ForStmt) {
currBlock := c.builder.GetInsertBlock()
doneBlock := llvm.AddBasicBlock(currBlock.Parent(), "done")
doneBlock.MoveAfter(currBlock)
loopBlock := llvm.InsertBasicBlock(doneBlock, "loop")
defer c.builder.SetInsertPointAtEnd(doneBlock)
condBlock := loopBlock
if stmt.Cond != nil {
condBlock = llvm.InsertBasicBlock(loopBlock, "cond")
}
postBlock := condBlock
if stmt.Post != nil {
postBlock = llvm.InsertBasicBlock(doneBlock, "post")
}
if c.lastlabel != nil {
labelData := c.labelData(c.lastlabel)
labelData.Break = doneBlock
labelData.Continue = postBlock
c.lastlabel = nil
}
c.breakblocks = append(c.breakblocks, doneBlock)
c.continueblocks = append(c.continueblocks, postBlock)
defer func() {
c.breakblocks = c.breakblocks[:len(c.breakblocks)-1]
c.continueblocks = c.continueblocks[:len(c.continueblocks)-1]
}()
// Is there an initializer? Create a new scope and visit the statement.
if stmt.Init != nil {
c.VisitStmt(stmt.Init)
}
// Start the loop.
if stmt.Cond != nil {
c.builder.CreateBr(condBlock)
c.builder.SetInsertPointAtEnd(condBlock)
condVal := c.VisitExpr(stmt.Cond)
c.builder.CreateCondBr(condVal.LLVMValue(), loopBlock, doneBlock)
} else {
c.builder.CreateBr(loopBlock)
}
// Post.
if stmt.Post != nil {
c.builder.SetInsertPointAtEnd(postBlock)
c.VisitStmt(stmt.Post)
c.builder.CreateBr(condBlock)
}
// Loop body.
c.builder.SetInsertPointAtEnd(loopBlock)
c.VisitBlockStmt(stmt.Body, false)
c.maybeImplicitBranch(postBlock)
}
开发者ID:dtcaciuc,项目名称:llgo,代码行数:58,代码来源:stmt.go
示例8: createMainFunction
func (c *compiler) createMainFunction() error {
// In a PNaCl program (plugin), there should not be a "main.main";
// instead, we expect a "main.CreateModule" function.
// See pkg/nacl/ppapi/ppapi.go for more details.
mainMain := c.module.NamedFunction("main.main")
if c.pnacl {
// PNaCl's libppapi_stub.a implements "main", which simply
// calls through to PpapiPluginMain. We define our own "main"
// so that we can capture argc/argv.
if !mainMain.IsNil() {
return fmt.Errorf("Found main.main")
}
pluginMain := c.NamedFunction("PpapiPluginMain", "func() int32")
// Synthesise a main which has no return value. We could cast
// PpapiPluginMain, but this is potentially unsafe as its
// calling convention is unspecified.
ftyp := llvm.FunctionType(llvm.VoidType(), nil, false)
mainMain = llvm.AddFunction(c.module.Module, "main.main", ftyp)
entry := llvm.AddBasicBlock(mainMain, "entry")
c.builder.SetInsertPointAtEnd(entry)
c.builder.CreateCall(pluginMain, nil, "")
c.builder.CreateRetVoid()
} else {
mainMain = c.module.NamedFunction("main.main")
}
if mainMain.IsNil() {
return fmt.Errorf("Could not find main.main")
}
// runtime.main is called by main, with argc, argv, argp,
// and a pointer to main.main, which must be a niladic
// function with no result.
runtimeMain := c.NamedFunction("runtime.main", "func(int32, **byte, **byte, *int8) int32")
main := c.NamedFunction("main", "func(int32, **byte, **byte) int32")
c.builder.SetCurrentDebugLocation(c.debug_info.MDNode(nil))
entry := llvm.AddBasicBlock(main, "entry")
c.builder.SetInsertPointAtEnd(entry)
mainMain = c.builder.CreateBitCast(mainMain, runtimeMain.Type().ElementType().ParamTypes()[3], "")
args := []llvm.Value{main.Param(0), main.Param(1), main.Param(2), mainMain}
result := c.builder.CreateCall(runtimeMain, args, "")
c.builder.CreateRet(result)
return nil
}
开发者ID:quarnster,项目名称:llgo,代码行数:45,代码来源:compiler.go
示例9: 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)
}
开发者ID:prattmic,项目名称:llgo,代码行数:10,代码来源:intrinsics.go
示例10: labelData
func (c *compiler) labelData(label *ast.Ident) *LabelData {
data, ok := label.Obj.Data.(*LabelData)
if !ok {
bb := c.builder.GetInsertBlock()
data = &LabelData{}
data.Goto = llvm.AddBasicBlock(bb.Parent(), label.Name)
label.Obj.Data = data
}
return data
}
开发者ID:payco,项目名称:llgo,代码行数:10,代码来源:labels.go
示例11: VisitLabeledStmt
func (c *compiler) VisitLabeledStmt(stmt *ast.LabeledStmt) {
currBlock := c.builder.GetInsertBlock()
labeledBlock, _ := stmt.Label.Obj.Data.(llvm.BasicBlock)
if labeledBlock.IsNil() {
labeledBlock = llvm.AddBasicBlock(currBlock.Parent(), stmt.Label.Name)
stmt.Label.Obj.Data = labeledBlock
}
labeledBlock.MoveAfter(currBlock)
c.builder.CreateBr(labeledBlock)
c.builder.SetInsertPointAtEnd(labeledBlock)
c.VisitStmt(stmt.Stmt)
}
开发者ID:spate,项目名称:llgo,代码行数:12,代码来源:stmt.go
示例12: VisitForStmt
func (c *compiler) VisitForStmt(stmt *ast.ForStmt) {
curr_block := c.builder.GetInsertBlock()
var cond_block, loop_block, done_block llvm.BasicBlock
if stmt.Cond != nil {
cond_block = llvm.AddBasicBlock(curr_block.Parent(), "cond")
}
loop_block = llvm.AddBasicBlock(curr_block.Parent(), "loop")
done_block = llvm.AddBasicBlock(curr_block.Parent(), "done")
// Is there an initializer? Create a new scope and visit the statement.
if stmt.Init != nil {
c.PushScope()
c.VisitStmt(stmt.Init)
defer c.PopScope()
}
// Start the loop.
if stmt.Cond != nil {
c.builder.CreateBr(cond_block)
c.builder.SetInsertPointAtEnd(cond_block)
cond_val := c.VisitExpr(stmt.Cond)
c.builder.CreateCondBr(
cond_val.LLVMValue(), loop_block, done_block)
} else {
c.builder.CreateBr(loop_block)
}
// Loop body.
c.builder.SetInsertPointAtEnd(loop_block)
c.VisitBlockStmt(stmt.Body)
if stmt.Post != nil {
c.VisitStmt(stmt.Post)
}
if stmt.Cond != nil {
c.builder.CreateBr(cond_block)
} else {
c.builder.CreateBr(loop_block)
}
c.builder.SetInsertPointAtEnd(done_block)
}
开发者ID:prattmic,项目名称:llgo,代码行数:40,代码来源:stmt.go
示例13: VisitForStmt
func (c *compiler) VisitForStmt(stmt *ast.ForStmt) {
currBlock := c.builder.GetInsertBlock()
doneBlock := llvm.AddBasicBlock(currBlock.Parent(), "done")
doneBlock.MoveAfter(currBlock)
loopBlock := llvm.InsertBasicBlock(doneBlock, "loop")
defer c.builder.SetInsertPointAtEnd(doneBlock)
condBlock := loopBlock
if stmt.Cond != nil {
condBlock = llvm.InsertBasicBlock(loopBlock, "cond")
}
postBlock := condBlock
if stmt.Post != nil {
postBlock = llvm.InsertBasicBlock(doneBlock, "post")
}
// Is there an initializer? Create a new scope and visit the statement.
if stmt.Init != nil {
c.PushScope()
c.VisitStmt(stmt.Init)
defer c.PopScope()
}
// Start the loop.
if stmt.Cond != nil {
c.builder.CreateBr(condBlock)
c.builder.SetInsertPointAtEnd(condBlock)
condVal := c.VisitExpr(stmt.Cond)
c.builder.CreateCondBr(condVal.LLVMValue(), loopBlock, doneBlock)
} else {
c.builder.CreateBr(loopBlock)
}
// Post.
if stmt.Post != nil {
c.builder.SetInsertPointAtEnd(postBlock)
c.VisitStmt(stmt.Post)
c.builder.CreateBr(condBlock)
}
// Loop body.
c.builder.SetInsertPointAtEnd(loopBlock)
c.VisitBlockStmt(stmt.Body)
c.maybeImplicitBranch(postBlock)
}
开发者ID:c0der007,项目名称:llgo,代码行数:46,代码来源:stmt.go
示例14: buildPtrRecvFunction
func (c *compiler) buildPtrRecvFunction(fn llvm.Value) llvm.Value {
defer c.builder.SetInsertPointAtEnd(c.builder.GetInsertBlock())
ifname := "*" + fn.Name()
ifn := c.module.Module.NamedFunction(ifname)
fntyp := fn.Type().ElementType()
entry := llvm.AddBasicBlock(ifn, "entry")
c.builder.SetInsertPointAtEnd(entry)
args := ifn.Params()
args[0] = c.builder.CreateLoad(args[0], "recv")
result := c.builder.CreateCall(fn, args, "")
if fntyp.ReturnType().TypeKind() == llvm.VoidTypeKind {
c.builder.CreateRetVoid()
} else {
c.builder.CreateRet(result)
}
return ifn
}
开发者ID:octabrain,项目名称:llgo,代码行数:17,代码来源:decl.go
示例15: VisitIfStmt
func (c *compiler) VisitIfStmt(stmt *ast.IfStmt) {
curr_block := c.builder.GetInsertBlock()
resume_block := llvm.AddBasicBlock(curr_block.Parent(), "endif")
resume_block.MoveAfter(curr_block)
var if_block, else_block llvm.BasicBlock
if stmt.Else != nil {
else_block = llvm.InsertBasicBlock(resume_block, "else")
if_block = llvm.InsertBasicBlock(else_block, "if")
} else {
if_block = llvm.InsertBasicBlock(resume_block, "if")
}
if stmt.Else == nil {
else_block = resume_block
}
if stmt.Init != nil {
c.PushScope()
c.VisitStmt(stmt.Init)
defer c.PopScope()
}
cond_val := c.VisitExpr(stmt.Cond)
c.builder.CreateCondBr(cond_val.LLVMValue(), if_block, else_block)
c.builder.SetInsertPointAtEnd(if_block)
c.VisitBlockStmt(stmt.Body)
if in := if_block.LastInstruction(); in.IsNil() || in.IsATerminatorInst().IsNil() {
c.builder.CreateBr(resume_block)
}
if stmt.Else != nil {
c.builder.SetInsertPointAtEnd(else_block)
c.VisitStmt(stmt.Else)
if in := else_block.LastInstruction(); in.IsNil() || in.IsATerminatorInst().IsNil() {
c.builder.CreateBr(resume_block)
}
}
// If there's a block after the "resume" block (i.e. a nested control
// statement), then create a branch to it as the last instruction.
c.builder.SetInsertPointAtEnd(resume_block)
if last := resume_block.Parent().LastBasicBlock(); last != resume_block {
c.builder.CreateBr(last)
c.builder.SetInsertPointBefore(resume_block.FirstInstruction())
}
}
开发者ID:prattmic,项目名称:llgo,代码行数:46,代码来源:stmt.go
示例16: buildFunction
// buildFunction takes a function Value, a list of parameters, and a body,
// and generates code for the function.
func (c *compiler) buildFunction(f *LLVMValue, params []*ast.Object, body *ast.BlockStmt) {
ftyp := f.Type().(*types.Func)
llvm_fn := f.LLVMValue()
entry := llvm.AddBasicBlock(llvm_fn, "entry")
c.builder.SetInsertPointAtEnd(entry)
// Bind receiver, arguments and return values to their identifiers/objects.
// We'll store each parameter on the stack so they're addressable.
for i, obj := range params {
if obj.Name != "" {
value := llvm_fn.Param(i)
typ := obj.Type.(types.Type)
stackvalue := c.builder.CreateAlloca(c.types.ToLLVM(typ), obj.Name)
c.builder.CreateStore(value, stackvalue)
ptrvalue := c.NewLLVMValue(stackvalue, &types.Pointer{Base: typ})
stackvar := ptrvalue.makePointee()
stackvar.stack = f
obj.Data = stackvar
}
}
// Allocate space on the stack for named results.
for _, obj := range ftyp.Results {
if obj.Name != "" {
typ := obj.Type.(types.Type)
llvmtyp := c.types.ToLLVM(typ)
stackptr := c.builder.CreateAlloca(llvmtyp, obj.Name)
c.builder.CreateStore(llvm.ConstNull(llvmtyp), stackptr)
ptrvalue := c.NewLLVMValue(stackptr, &types.Pointer{Base: typ})
stackvar := ptrvalue.makePointee()
stackvar.stack = f
obj.Data = stackvar
}
}
c.functions = append(c.functions, f)
c.VisitBlockStmt(body, false)
c.functions = c.functions[0 : len(c.functions)-1]
last := llvm_fn.LastBasicBlock()
if in := last.LastInstruction(); in.IsNil() || in.IsATerminatorInst().IsNil() {
// Assume nil return type, AST should be checked first.
c.builder.SetInsertPointAtEnd(last)
c.builder.CreateRetVoid()
}
}
开发者ID:octabrain,项目名称:llgo,代码行数:47,代码来源:decl.go
示例17: defineMemsetFunction
func (c *compiler) defineMemsetFunction(fn llvm.Value) {
entry := llvm.AddBasicBlock(fn, "entry")
c.builder.SetInsertPointAtEnd(entry)
dst, fill, size := fn.Param(0), fn.Param(1), fn.Param(2)
sizeType := size.Type()
sizeBits := sizeType.IntTypeWidth()
memsetName := "llvm.memset.p0i8.i" + strconv.Itoa(sizeBits)
memset := c.NamedFunction(memsetName, "func f(dst *int8, fill byte, size uintptr, align int32, volatile bool)")
pint8 := memset.Type().ElementType().ParamTypes()[0]
dst = c.builder.CreateIntToPtr(dst, pint8, "")
args := []llvm.Value{
dst, fill, size,
llvm.ConstInt(llvm.Int32Type(), 1, false), // single byte alignment
llvm.ConstInt(llvm.Int1Type(), 0, false), // not volatile
}
c.builder.CreateCall(memset, args, "")
c.builder.CreateRetVoid()
}
开发者ID:hzmangel,项目名称:llgo,代码行数:18,代码来源:intrinsics.go
示例18: 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
}
开发者ID:minux,项目名称:llgo,代码行数:39,代码来源:typemap.go
示例19: VisitBranchStmt
func (c *compiler) VisitBranchStmt(stmt *ast.BranchStmt) {
// TODO handle labeled continue, break.
switch stmt.Tok {
case token.BREAK:
block := c.breakblocks[len(c.breakblocks)-1]
c.builder.CreateBr(block)
case token.CONTINUE:
block := c.continueblocks[len(c.continueblocks)-1]
c.builder.CreateBr(block)
case token.GOTO:
block, _ := stmt.Label.Obj.Data.(llvm.BasicBlock)
if block.IsNil() {
f := c.builder.GetInsertBlock().Parent()
block = llvm.AddBasicBlock(f, stmt.Label.Name)
stmt.Label.Obj.Data = block
}
c.builder.CreateBr(block)
default:
// TODO implement goto, fallthrough
panic("unimplemented: " + stmt.Tok.String())
}
}
开发者ID:kisielk,项目名称:llgo,代码行数:22,代码来源:stmt.go
示例20: VisitFuncLit
func (c *compiler) VisitFuncLit(lit *ast.FuncLit) Value {
fn_type := c.VisitFuncType(lit.Type)
fn := llvm.AddFunction(c.module.Module, "", c.types.ToLLVM(fn_type))
fn.SetFunctionCallConv(llvm.FastCallConv)
defer c.builder.SetInsertPointAtEnd(c.builder.GetInsertBlock())
entry := llvm.AddBasicBlock(fn, "entry")
c.builder.SetInsertPointAtEnd(entry)
fn_value := c.NewLLVMValue(fn, fn_type)
c.functions = append(c.functions, fn_value)
c.VisitBlockStmt(lit.Body)
if fn_type.Results == nil {
lasti := entry.LastInstruction()
if lasti.IsNil() || lasti.Opcode() != llvm.Ret {
// Assume nil return type, AST should be checked first.
c.builder.CreateRetVoid()
}
}
c.functions = c.functions[0 : len(c.functions)-1]
return fn_value
}
开发者ID:prattmic,项目名称:llgo,代码行数:22,代码来源:literals.go
注:本文中的github.com/axw/gollvm/llvm.AddBasicBlock函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论