llgo/ssa: abiMapOf

This commit is contained in:
xushiwei
2024-06-14 22:07:48 +08:00
parent 47b20b01d0
commit 33d73eaecd
5 changed files with 63 additions and 5 deletions

View File

@@ -159,6 +159,10 @@ func (b *Builder) TypeName(t types.Type) (ret string, pub bool) {
return "_llgo_any", true
}
return b.InterfaceName(t)
case *types.Map:
key, pub1 := b.TypeName(t.Key())
elem, pub2 := b.TypeName(t.Elem())
return fmt.Sprintf("map[%s]%s", key, elem), pub1 && pub2
}
log.Panicf("todo: %T\n", t)
return

View File

@@ -66,6 +66,8 @@ func (b Builder) abiTypeOf(t types.Type) func() Expr {
return b.abiFuncOf(t)
case *types.Slice:
return b.abiSliceOf(t)
case *types.Map:
return b.abiMapOf(t)
case *types.Array:
return b.abiArrayOf(t)
}
@@ -244,6 +246,14 @@ func (b Builder) abiPointerOf(t *types.Pointer) func() Expr {
}
}
func (b Builder) abiMapOf(t *types.Map) func() Expr {
key := b.abiType(t.Key())
elem := b.abiType(t.Elem())
return func() Expr {
return b.Call(b.Pkg.rtFunc("MapOf"), key, elem)
}
}
func (b Builder) abiSliceOf(t *types.Slice) func() Expr {
elem := b.abiType(t.Elem())
return func() Expr {

View File

@@ -365,7 +365,9 @@ func (b Builder) MapUpdate(m, k, v Expr) {
panic("TODO: not a map")
}
tabi := b.abiType(t.raw.Type)
ptr := b.InlineCall(b.Pkg.rtFunc("MapAssign"), tabi, m, k)
prog := b.Prog
ptrimpl := b.InlineCall(b.Pkg.rtFunc("MapAssign"), tabi, m, k).impl
ptr := Expr{ptrimpl, prog.Pointer(v.Type)}
b.Store(ptr, v) // TODO(xsw): indirect store
}