cl: _testdata/printf: almost done

This commit is contained in:
xushiwei
2024-04-21 15:12:57 +08:00
parent 8f31e4a6d3
commit 4641cb11eb
12 changed files with 305 additions and 265 deletions

View File

@@ -17,6 +17,10 @@
package ssa
import (
"bytes"
"fmt"
"log"
"github.com/goplus/llvm"
)
@@ -57,12 +61,26 @@ func (b Builder) SetBlock(blk BasicBlock) Builder {
if b.fn != blk.fn {
panic("mismatched function")
}
if debugInstr {
log.Printf("Block _llgo_%v:\n", blk.idx)
}
b.impl.SetInsertPointAtEnd(blk.impl)
return b
}
// Return emits a return instruction.
func (b Builder) Return(results ...Expr) {
if debugInstr {
var b bytes.Buffer
fmt.Fprint(&b, "Return ")
for i, arg := range results {
if i > 0 {
fmt.Fprint(&b, ", ")
}
fmt.Fprint(&b, arg.impl)
}
log.Println(b.String())
}
switch n := len(results); n {
case 0:
b.impl.CreateRetVoid()
@@ -78,6 +96,9 @@ func (b Builder) Jump(jmpb BasicBlock) {
if b.fn != jmpb.fn {
panic("mismatched function")
}
if debugInstr {
log.Printf("Jump _llgo_%v\n", jmpb.idx)
}
b.impl.CreateBr(jmpb.impl)
}
@@ -86,6 +107,9 @@ func (b Builder) If(cond Expr, thenb, elseb BasicBlock) {
if b.fn != thenb.fn || b.fn != elseb.fn {
panic("mismatched function")
}
if debugInstr {
log.Printf("If %v, _llgo_%v, _llgo_%v\n", cond.impl, thenb.idx, elseb.idx)
}
b.impl.CreateCondBr(cond.impl, thenb.impl, elseb.impl)
}