本文整理匯總了Golang中github.com/axw/gollvm/llvm.BasicBlock.LastInstruction方法的典型用法代碼示例。如果您正苦於以下問題:Golang BasicBlock.LastInstruction方法的具體用法?Golang BasicBlock.LastInstruction怎麽用?Golang BasicBlock.LastInstruction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/axw/gollvm/llvm.BasicBlock
的用法示例。
在下文中一共展示了BasicBlock.LastInstruction方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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())
}
}