ssa: chan send/recv

This commit is contained in:
visualfc
2024-07-02 20:12:12 +08:00
parent 0ead82ae21
commit 2153cf39b5
11 changed files with 190 additions and 1 deletions

View File

@@ -65,6 +65,18 @@ func UnderlyingKind(t types.Type) abi.Kind {
panic("todo")
}
func ChanDir(dir types.ChanDir) (abi.ChanDir, string) {
switch dir {
case types.SendRecv:
return abi.BothDir, "chan"
case types.SendOnly:
return abi.SendDir, "chan->"
case types.RecvOnly:
return abi.RecvDir, "<-chan"
}
panic("invlid chan dir")
}
// -----------------------------------------------------------------------------
type DataKind int
@@ -165,6 +177,18 @@ func (b *Builder) TypeName(t types.Type) (ret string, pub bool) {
key, pub1 := b.TypeName(t.Key())
elem, pub2 := b.TypeName(t.Elem())
return fmt.Sprintf("map[%s]%s", key, elem), pub1 && pub2
case *types.Chan:
elem, pub := b.TypeName(t.Elem())
var s string
switch t.Dir() {
case types.SendRecv:
s = "chan"
case types.SendOnly:
s = "chan<-"
case types.RecvOnly:
s = "<-chan"
}
return fmt.Sprintf("%s %s", s, elem), pub
}
log.Panicf("todo: %T\n", t)
return