llgo/ssa: PyNewVar; pyLoad

This commit is contained in:
xushiwei
2024-05-15 18:32:50 +08:00
parent 91513a12b4
commit 29e4af4fb2
11 changed files with 130 additions and 16 deletions

View File

@@ -54,6 +54,26 @@ func (v Expr) Do(b Builder) Expr {
// -----------------------------------------------------------------------------
type pyVarTy struct {
mod Expr
name string
}
func (p pyVarTy) Underlying() types.Type {
panic("don't call")
}
func (p pyVarTy) String() string {
return "pyVar"
}
func pyVarExpr(mod Expr, name string) Expr {
tvar := &aType{raw: rawType{&pyVarTy{mod, name}}, kind: vkPyVarRef}
return Expr{Type: tvar}
}
// -----------------------------------------------------------------------------
type phisExprTy struct {
phis []llvm.Value
Type
@@ -68,7 +88,8 @@ func (p phisExprTy) String() string {
}
func phisExpr(t Type, phis []llvm.Value) Expr {
return Expr{Type: &aType{raw: rawType{&phisExprTy{phis, t}}, kind: vkPhisExpr}}
tphi := &aType{raw: rawType{&phisExprTy{phis, t}}, kind: vkPhisExpr}
return Expr{Type: tphi}
}
// -----------------------------------------------------------------------------
@@ -513,6 +534,9 @@ func (b Builder) Load(ptr Expr) Expr {
if debugInstr {
log.Printf("Load %v\n", ptr.impl)
}
if ptr.kind == vkPyVarRef {
return b.pyLoad(ptr)
}
telem := b.Prog.Elem(ptr.Type)
return Expr{llvm.CreateLoad(b.impl, telem.ll, ptr.impl), telem}
}