cl: clean test

This commit is contained in:
Li Jie
2025-01-09 00:47:45 +08:00
parent 4f9c341103
commit 3d2c014801
19 changed files with 256 additions and 105 deletions

View File

@@ -4,20 +4,20 @@ import (
_ "unsafe"
"github.com/goplus/llgo/c"
_ "github.com/goplus/llgo/compiler/cl/internal/linktarget"
_ "github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget"
)
//go:linkname print github.com/goplus/llgo/compiler/cl/internal/linktarget.F
//go:linkname print github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.F
func print(a, b, c, d *c.Char)
type m struct {
s string
}
//go:linkname setInfo github.com/goplus/llgo/compiler/cl/internal/linktarget.(*m).setInfo
//go:linkname setInfo github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.(*m).setInfo
func setInfo(*m, string)
//go:linkname info github.com/goplus/llgo/compiler/cl/internal/linktarget.m.info
//go:linkname info github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.m.info
func info(m) string
func main() {

View File

@@ -0,0 +1,23 @@
package linktarget
import (
"github.com/goplus/llgo/c"
)
func F(a, b *c.Char) {
c.Printf(c.Str("a: %s, b: %s\n"), a, b)
}
var _ m
type m struct {
s string
}
func (t m) info() string {
return t.s
}
func (t *m) setInfo(s string) {
t.s = s
}

View File

@@ -0,0 +1,55 @@
; ModuleID = 'github.com/goplus/llgo/cl/internal/linktarget'
source_filename = "github.com/goplus/llgo/cl/internal/linktarget"
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/cl/internal/linktarget.m" = type { %"github.com/goplus/llgo/internal/runtime.String" }
@"github.com/goplus/llgo/cl/internal/linktarget.init$guard" = global ptr null
@0 = private unnamed_addr constant [14 x i8] c"a: %s, b: %s\0A\00", align 1
define void @"github.com/goplus/llgo/cl/internal/linktarget.F"(ptr %0, ptr %1) {
_llgo_0:
%2 = call i32 (ptr, ...) @printf(ptr @0, ptr %0, ptr %1)
ret void
}
define void @"github.com/goplus/llgo/cl/internal/linktarget.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/internal/linktarget.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"github.com/goplus/llgo/cl/internal/linktarget.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/cl/internal/linktarget.m.info"(%"github.com/goplus/llgo/cl/internal/linktarget.m" %0) {
_llgo_0:
%1 = alloca %"github.com/goplus/llgo/cl/internal/linktarget.m", align 8
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %1, i64 16)
store %"github.com/goplus/llgo/cl/internal/linktarget.m" %0, ptr %2, align 8
%3 = getelementptr inbounds %"github.com/goplus/llgo/cl/internal/linktarget.m", ptr %2, i32 0, i32 0
%4 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %3, align 8
ret %"github.com/goplus/llgo/internal/runtime.String" %4
}
define %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/cl/internal/linktarget.(*m).info"(ptr %0) {
_llgo_0:
%1 = load %"github.com/goplus/llgo/cl/internal/linktarget.m", ptr %0, align 8
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/cl/internal/linktarget.m.info"(%"github.com/goplus/llgo/cl/internal/linktarget.m" %1)
ret %"github.com/goplus/llgo/internal/runtime.String" %2
}
define void @"github.com/goplus/llgo/cl/internal/linktarget.(*m).setInfo"(ptr %0, %"github.com/goplus/llgo/internal/runtime.String" %1) {
_llgo_0:
%2 = getelementptr inbounds %"github.com/goplus/llgo/cl/internal/linktarget.m", ptr %0, i32 0, i32 0
store %"github.com/goplus/llgo/internal/runtime.String" %1, ptr %2, align 8
ret void
}
declare i32 @printf(ptr, ...)
declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)

View File

@@ -17,7 +17,7 @@ source_filename = "main"
@7 = private unnamed_addr constant [2 x i8] c"4\00", align 1
@8 = private unnamed_addr constant [5 x i8] c"hello", align 1
declare %"github.com/goplus/llgo/runtime/internal/runtime.String" @"github.com/goplus/llgo/compiler/cl/internal/linktarget.m.info"(%main.m)
declare %"github.com/goplus/llgo/runtime/internal/runtime.String" @"github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.m.info"(%main.m)
define void @main.init() {
_llgo_0:
@@ -26,7 +26,7 @@ _llgo_0:
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
call void @"github.com/goplus/llgo/compiler/cl/internal/linktarget.init"()
call void @"github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.init"()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
@@ -39,22 +39,22 @@ _llgo_0:
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/runtime/internal/runtime.init"()
call void @main.init()
call void @"github.com/goplus/llgo/compiler/cl/internal/linktarget.F"(ptr @0, ptr @1, ptr @2, ptr @3)
call void @"github.com/goplus/llgo/compiler/cl/internal/linktarget.F"(ptr @4, ptr @5, ptr @6, ptr @7)
call void @"github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.F"(ptr @0, ptr @1, ptr @2, ptr @3)
call void @"github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.F"(ptr @4, ptr @5, ptr @6, ptr @7)
%2 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 16)
call void @"github.com/goplus/llgo/compiler/cl/internal/linktarget.(*m).setInfo"(ptr %2, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @8, i64 5 })
call void @"github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.(*m).setInfo"(ptr %2, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @8, i64 5 })
%3 = load %main.m, ptr %2, align 8
%4 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" @"github.com/goplus/llgo/compiler/cl/internal/linktarget.m.info"(%main.m %3)
%4 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" @"github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.m.info"(%main.m %3)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %4)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
ret i32 0
}
declare void @"github.com/goplus/llgo/compiler/cl/internal/linktarget.F"(ptr, ptr, ptr, ptr)
declare void @"github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.F"(ptr, ptr, ptr, ptr)
declare void @"github.com/goplus/llgo/compiler/cl/internal/linktarget.(*m).setInfo"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.String")
declare void @"github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.(*m).setInfo"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.String")
declare void @"github.com/goplus/llgo/compiler/cl/internal/linktarget.init"()
declare void @"github.com/goplus/llgo/compiler/cl/_testrt/linkname/linktarget.init"()
declare void @"github.com/goplus/llgo/runtime/internal/runtime.init"()