cl: support llgo.cstr

This commit is contained in:
xushiwei
2024-04-29 13:59:06 +08:00
parent 637db665c3
commit 4eb2ddaf15
8 changed files with 147 additions and 31 deletions

13
cl/_testdata/cstr/in.go Normal file
View File

@@ -0,0 +1,13 @@
package main
import _ "unsafe"
//go:linkname cstr llgo.cstr
func cstr(string) *int8
//go:linkname printf C.printf
func printf(format *int8, __llgo_va_list ...any)
func main() {
printf(cstr("Hello, world\n"))
}

26
cl/_testdata/cstr/out.ll Normal file
View File

@@ -0,0 +1,26 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main() {
_llgo_0:
call void @main.init()
call void (ptr, ...) @printf([14 x i8] c"Hello, world\0A\00")
ret void
}
declare void @printf(ptr, ...)