This commit is contained in:
xushiwei
2024-05-12 11:11:19 +08:00
parent 64c13fa9ae
commit 0912f1f509
13 changed files with 140 additions and 41 deletions

View File

@@ -57,15 +57,40 @@ type aBuilder struct {
// Builder represents a builder for creating instructions in a function.
type Builder = *aBuilder
// SetBlock sets the current block to the specified basic block.
// Dispose disposes of the builder.
func (b Builder) Dispose() {
b.impl.Dispose()
}
// SetBlock means SetBlockEx(blk, AtEnd).
func (b Builder) SetBlock(blk BasicBlock) Builder {
if b.Func != blk.fn {
panic("mismatched function")
}
if debugInstr {
log.Printf("Block _llgo_%v:\n", blk.idx)
}
b.impl.SetInsertPointAtEnd(blk.impl)
b.SetBlockEx(blk, AtEnd)
return b
}
type InsertPoint int
const (
AtEnd InsertPoint = iota
AtStart
)
// SetBlockEx sets blk as current basic block and pos as its insert point.
func (b Builder) SetBlockEx(blk BasicBlock, pos InsertPoint) Builder {
if b.Func != blk.fn {
panic("mismatched function")
}
switch pos {
case AtEnd:
b.impl.SetInsertPointAtEnd(blk.impl)
case AtStart:
b.impl.SetInsertPointBefore(blk.impl.FirstInstruction())
default:
panic("SetBlockEx: invalid pos")
}
return b
}