llgo/ssa: rtType, rtFunc

This commit is contained in:
xushiwei
2024-04-27 17:39:25 +08:00
parent f1761c0c9c
commit 6a02c3ac4c
14 changed files with 259 additions and 19 deletions

16
cl/_testcgo/any/in.go Normal file
View File

@@ -0,0 +1,16 @@
package main
import _ "unsafe"
func incVal(a any) int {
return a.(int) + 1
}
//go:linkname printf C.printf
func printf(format *int8, __llgo_va_list ...any)
var format = [...]int8{'H', 'e', 'l', 'l', 'o', ' ', '%', 'd', '\n', 0}
func main() {
printf(&format[0], incVal(100))
}

0
cl/_testcgo/any/out.ll Normal file
View File

View File

@@ -329,6 +329,9 @@ func (p *context) compileInstrAndValue(b llssa.Builder, iv instrAndValue) (ret l
return
}
panic("todo")
case *ssa.TypeAssert:
x := p.compileValue(b, v.X)
ret = b.TypeAssert(x, p.prog.Type(v.AssertedType), v.CommaOk)
default:
panic(fmt.Sprintf("compileInstrAndValue: unknown instr - %T\n", iv))
}

View File

@@ -28,7 +28,7 @@ func testCompile(t *testing.T, src, expected string) {
}
func TestFromTestcgo(t *testing.T) {
cltest.FromDir(t, "", "./_testcgo", true)
cltest.FromDir(t, "any", "./_testcgo", true)
}
func TestFromTestdata(t *testing.T) {