c.AllocaCStrs; cl/_testlibc: allocacstrs

This commit is contained in:
xushiwei
2024-07-13 12:24:06 +08:00
parent e138951e9e
commit 022e46ae38
4 changed files with 144 additions and 3 deletions

View File

@@ -176,7 +176,8 @@ func (b Builder) AllocaCStrs(strs Expr, endWithNil bool) (cstrs Expr) {
tcstr := prog.CStr()
cstrs = b.ArrayAlloca(tcstr, n1)
b.Times(n, func(i Expr) {
s := b.Index(strs, i, nil)
pstr := b.IndexAddr(strs, i)
s := b.Load(pstr)
b.Store(b.Advance(cstrs, i), b.AllocaCStr(s))
})
if endWithNil {

View File

@@ -277,14 +277,14 @@ func (b Builder) Times(n Expr, loop func(i Expr)) {
loop(phi.Expr)
post := b.BinOp(token.ADD, phi.Expr, b.Prog.IntVal(1, typ))
b.Jump(blks[0])
b.SetBlockEx(blks[2], AtEnd, false)
b.blk.last = blks[2].last
phi.AddIncoming(b, []BasicBlock{at, blks[1]}, func(i int, blk BasicBlock) Expr {
if i == 0 {
return b.Prog.IntVal(0, typ)
}
return post
})
b.SetBlockEx(blks[2], AtEnd, false)
b.blk.last = blks[2].last
}
// -----------------------------------------------------------------------------