move out c/cpp/py
This commit is contained in:
16
cl/_testlibc/allocacstrs/in.go
Normal file
16
cl/_testlibc/allocacstrs/in.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/lib/c"
|
||||
|
||||
func main() {
|
||||
cstrs := c.AllocaCStrs([]string{"a", "b", "c"}, true)
|
||||
n := 0
|
||||
for {
|
||||
cstr := *c.Advance(cstrs, n)
|
||||
if cstr == nil {
|
||||
break
|
||||
}
|
||||
c.Printf(c.Str("%s\n"), cstr)
|
||||
n++
|
||||
}
|
||||
}
|
||||
93
cl/_testlibc/allocacstrs/out.ll
Normal file
93
cl/_testlibc/allocacstrs/out.ll
Normal file
@@ -0,0 +1,93 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/cl/_testlibc/allocacstrs'
|
||||
source_filename = "github.com/goplus/llgo/cl/_testlibc/allocacstrs"
|
||||
|
||||
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
|
||||
%"github.com/goplus/llgo/runtime/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||
|
||||
@"github.com/goplus/llgo/cl/_testlibc/allocacstrs.init$guard" = global i1 false, align 1
|
||||
@0 = private unnamed_addr constant [1 x i8] c"a", align 1
|
||||
@1 = private unnamed_addr constant [1 x i8] c"b", align 1
|
||||
@2 = private unnamed_addr constant [1 x i8] c"c", align 1
|
||||
@3 = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/allocacstrs.init"() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibc/allocacstrs.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/_testlibc/allocacstrs.init$guard", align 1
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/allocacstrs.main"() {
|
||||
_llgo_0:
|
||||
%0 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 48)
|
||||
%1 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr %0, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 1 }, ptr %1, align 8
|
||||
%2 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr %0, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 1 }, ptr %2, align 8
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr %0, i64 2
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 1 }, ptr %3, align 8
|
||||
%4 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %0, 0
|
||||
%5 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %4, i64 3, 1
|
||||
%6 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %5, i64 3, 2
|
||||
%7 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %6, 1
|
||||
%8 = add i64 %7, 1
|
||||
%9 = alloca ptr, i64 %8, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_1: ; preds = %_llgo_3, %_llgo_6
|
||||
%10 = phi i64 [ 0, %_llgo_6 ], [ %15, %_llgo_3 ]
|
||||
%11 = getelementptr ptr, ptr %9, i64 %10
|
||||
%12 = load ptr, ptr %11, align 8
|
||||
%13 = icmp eq ptr %12, null
|
||||
br i1 %13, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
ret void
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
%14 = call i32 (ptr, ...) @printf(ptr @3, ptr %12)
|
||||
%15 = add i64 %10, 1
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_4: ; preds = %_llgo_5, %_llgo_0
|
||||
%16 = phi i64 [ 0, %_llgo_0 ], [ %30, %_llgo_5 ]
|
||||
%17 = icmp slt i64 %16, %7
|
||||
br i1 %17, label %_llgo_5, label %_llgo_6
|
||||
|
||||
_llgo_5: ; preds = %_llgo_4
|
||||
%18 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %6, 0
|
||||
%19 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %6, 1
|
||||
%20 = icmp slt i64 %16, 0
|
||||
%21 = icmp sge i64 %16, %19
|
||||
%22 = or i1 %21, %20
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.AssertIndexRange"(i1 %22)
|
||||
%23 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr %18, i64 %16
|
||||
%24 = load %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr %23, align 8
|
||||
%25 = getelementptr ptr, ptr %9, i64 %16
|
||||
%26 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.String" %24, 1
|
||||
%27 = add i64 %26, 1
|
||||
%28 = alloca i8, i64 %27, align 1
|
||||
%29 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.CStrCopy"(ptr %28, %"github.com/goplus/llgo/runtime/internal/runtime.String" %24)
|
||||
store ptr %29, ptr %25, align 8
|
||||
%30 = add i64 %16, 1
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_6: ; preds = %_llgo_4
|
||||
%31 = getelementptr ptr, ptr %9, i64 %7
|
||||
store ptr null, ptr %31, align 8
|
||||
br label %_llgo_1
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.CStrCopy"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
11
cl/_testlibc/argv/in.go
Normal file
11
cl/_testlibc/argv/in.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for i := c.Int(0); i < c.Argc; i++ {
|
||||
c.Printf(c.Str("%s\n"), c.Index(c.Argv, i))
|
||||
}
|
||||
}
|
||||
44
cl/_testlibc/argv/out.ll
Normal file
44
cl/_testlibc/argv/out.ll
Normal file
@@ -0,0 +1,44 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/cl/_testlibc/argv'
|
||||
source_filename = "github.com/goplus/llgo/cl/_testlibc/argv"
|
||||
|
||||
@"github.com/goplus/llgo/cl/_testlibc/argv.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = external global i32, align 4
|
||||
@0 = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
@__llgo_argv = external global ptr, align 8
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/argv.init"() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibc/argv.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/_testlibc/argv.init$guard", align 1
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/argv.main"() {
|
||||
_llgo_0:
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%0 = phi i32 [ 0, %_llgo_0 ], [ %7, %_llgo_2 ]
|
||||
%1 = load i32, ptr @__llgo_argc, align 4
|
||||
%2 = icmp slt i32 %0, %1
|
||||
br i1 %2, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%3 = load ptr, ptr @__llgo_argv, align 8
|
||||
%4 = getelementptr ptr, ptr %3, i32 %0
|
||||
%5 = load ptr, ptr %4, align 8
|
||||
%6 = call i32 (ptr, ...) @printf(ptr @0, ptr %5)
|
||||
%7 = add i32 %0, 1
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
ret void
|
||||
}
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
25
cl/_testlibc/atomic/in.go
Normal file
25
cl/_testlibc/atomic/in.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/sync/atomic"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var v int64
|
||||
|
||||
atomic.Store(&v, 100)
|
||||
c.Printf(c.Str("store: %ld\n"), atomic.Load(&v))
|
||||
|
||||
ret := atomic.Add(&v, 1)
|
||||
c.Printf(c.Str("ret: %ld, v: %ld\n"), ret, v)
|
||||
|
||||
ret, _ = atomic.CompareAndExchange(&v, 100, 102)
|
||||
c.Printf(c.Str("ret: %ld vs 100, v: %ld\n"), ret, v)
|
||||
|
||||
ret, _ = atomic.CompareAndExchange(&v, 101, 102)
|
||||
c.Printf(c.Str("ret: %ld vs 101, v: %ld\n"), ret, v)
|
||||
|
||||
ret = atomic.Sub(&v, 1)
|
||||
c.Printf(c.Str("ret: %ld, v: %ld\n"), ret, v)
|
||||
}
|
||||
51
cl/_testlibc/atomic/out.ll
Normal file
51
cl/_testlibc/atomic/out.ll
Normal file
@@ -0,0 +1,51 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/cl/_testlibc/atomic'
|
||||
source_filename = "github.com/goplus/llgo/cl/_testlibc/atomic"
|
||||
|
||||
@"github.com/goplus/llgo/cl/_testlibc/atomic.init$guard" = global i1 false, align 1
|
||||
@0 = private unnamed_addr constant [12 x i8] c"store: %ld\0A\00", align 1
|
||||
@1 = private unnamed_addr constant [18 x i8] c"ret: %ld, v: %ld\0A\00", align 1
|
||||
@2 = private unnamed_addr constant [25 x i8] c"ret: %ld vs 100, v: %ld\0A\00", align 1
|
||||
@3 = private unnamed_addr constant [25 x i8] c"ret: %ld vs 101, v: %ld\0A\00", align 1
|
||||
@4 = private unnamed_addr constant [18 x i8] c"ret: %ld, v: %ld\0A\00", align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/atomic.init"() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibc/atomic.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/_testlibc/atomic.init$guard", align 1
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/atomic.main"() {
|
||||
_llgo_0:
|
||||
%0 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 8)
|
||||
store atomic i64 100, ptr %0 seq_cst, align 4
|
||||
%1 = load atomic i64, ptr %0 seq_cst, align 4
|
||||
%2 = call i32 (ptr, ...) @printf(ptr @0, i64 %1)
|
||||
%3 = atomicrmw add ptr %0, i64 1 seq_cst, align 8
|
||||
%4 = load i64, ptr %0, align 4
|
||||
%5 = call i32 (ptr, ...) @printf(ptr @1, i64 %3, i64 %4)
|
||||
%6 = cmpxchg ptr %0, i64 100, i64 102 seq_cst seq_cst, align 8
|
||||
%7 = extractvalue { i64, i1 } %6, 0
|
||||
%8 = extractvalue { i64, i1 } %6, 1
|
||||
%9 = load i64, ptr %0, align 4
|
||||
%10 = call i32 (ptr, ...) @printf(ptr @2, i64 %7, i64 %9)
|
||||
%11 = cmpxchg ptr %0, i64 101, i64 102 seq_cst seq_cst, align 8
|
||||
%12 = extractvalue { i64, i1 } %11, 0
|
||||
%13 = extractvalue { i64, i1 } %11, 1
|
||||
%14 = load i64, ptr %0, align 4
|
||||
%15 = call i32 (ptr, ...) @printf(ptr @3, i64 %12, i64 %14)
|
||||
%16 = atomicrmw sub ptr %0, i64 1 seq_cst, align 8
|
||||
%17 = load i64, ptr %0, align 4
|
||||
%18 = call i32 (ptr, ...) @printf(ptr @4, i64 %16, i64 %17)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
21
cl/_testlibc/complex/in.go
Normal file
21
cl/_testlibc/complex/in.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/math/cmplx"
|
||||
)
|
||||
|
||||
func f(c, z complex64, addr c.Pointer) {
|
||||
println("addr:", addr)
|
||||
println("abs(3+4i):", cmplx.Absf(c))
|
||||
println("real(3+4i):", real(z))
|
||||
println("imag(3+4i):", imag(z))
|
||||
}
|
||||
|
||||
func main() {
|
||||
re := float32(3.0)
|
||||
im := float32(4.0)
|
||||
z := complex64(3 + 4i)
|
||||
x := complex(re, im)
|
||||
f(x, z, c.Func(f))
|
||||
}
|
||||
66
cl/_testlibc/complex/out.ll
Normal file
66
cl/_testlibc/complex/out.ll
Normal file
@@ -0,0 +1,66 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/cl/_testlibc/complex'
|
||||
source_filename = "github.com/goplus/llgo/cl/_testlibc/complex"
|
||||
|
||||
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
|
||||
|
||||
@"github.com/goplus/llgo/cl/_testlibc/complex.init$guard" = global i1 false, align 1
|
||||
@0 = private unnamed_addr constant [5 x i8] c"addr:", align 1
|
||||
@1 = private unnamed_addr constant [10 x i8] c"abs(3+4i):", align 1
|
||||
@2 = private unnamed_addr constant [11 x i8] c"real(3+4i):", align 1
|
||||
@3 = private unnamed_addr constant [11 x i8] c"imag(3+4i):", align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/complex.f"({ float, float } %0, { float, float } %1, ptr %2) {
|
||||
_llgo_0:
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 5 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintPointer"(ptr %2)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
%3 = call float @cabsf({ float, float } %0)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 10 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
%4 = fpext float %3 to double
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double %4)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
%5 = extractvalue { float, float } %1, 0
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 11 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
%6 = fpext float %5 to double
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double %6)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
%7 = extractvalue { float, float } %1, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 11 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
%8 = fpext float %7 to double
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double %8)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/complex.init"() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibc/complex.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/_testlibc/complex.init$guard", align 1
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/complex.main"() {
|
||||
_llgo_0:
|
||||
call void @"github.com/goplus/llgo/cl/_testlibc/complex.f"({ float, float } { float 3.000000e+00, float 4.000000e+00 }, { float, float } { float 3.000000e+00, float 4.000000e+00 }, ptr @"github.com/goplus/llgo/cl/_testlibc/complex.f")
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintPointer"(ptr)
|
||||
|
||||
declare float @cabsf({ float, float })
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double)
|
||||
17
cl/_testlibc/defer/in.go
Normal file
17
cl/_testlibc/defer/in.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/lib/c"
|
||||
|
||||
func f(s string) bool {
|
||||
return len(s) > 2
|
||||
}
|
||||
|
||||
func main() {
|
||||
c.GoDeferData()
|
||||
if s := "hello"; f(s) {
|
||||
defer c.Printf(c.Str("%s\n"), c.AllocaCStr(s))
|
||||
} else {
|
||||
defer c.Printf(c.Str("world\n"))
|
||||
}
|
||||
defer c.Printf(c.Str("bye\n"))
|
||||
}
|
||||
1
cl/_testlibc/defer/out.ll
Normal file
1
cl/_testlibc/defer/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
15
cl/_testlibc/demangle/in.go
Normal file
15
cl/_testlibc/demangle/in.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/cpp/llvm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mangledName := "__ZNK9INIReader10ParseErrorEv"
|
||||
if name := llvm.ItaniumDemangle(mangledName, true); name != nil {
|
||||
c.Printf(c.Str("%s\n"), name)
|
||||
} else {
|
||||
println("Failed to demangle")
|
||||
}
|
||||
}
|
||||
49
cl/_testlibc/demangle/out.ll
Normal file
49
cl/_testlibc/demangle/out.ll
Normal file
@@ -0,0 +1,49 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/cl/_testlibc/demangle'
|
||||
source_filename = "github.com/goplus/llgo/cl/_testlibc/demangle"
|
||||
|
||||
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
|
||||
|
||||
@"github.com/goplus/llgo/cl/_testlibc/demangle.init$guard" = global i1 false, align 1
|
||||
@0 = private unnamed_addr constant [29 x i8] c"__ZNK9INIReader10ParseErrorEv", align 1
|
||||
@1 = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
@2 = private unnamed_addr constant [18 x i8] c"Failed to demangle", align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/demangle.init"() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibc/demangle.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/_testlibc/demangle.init$guard", align 1
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/demangle.main"() {
|
||||
_llgo_0:
|
||||
%0 = call ptr @_ZN4llvm15itaniumDemangleENSt3__117basic_string_viewIcNS0_11char_traitsIcEEEEb(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 29 }, i1 true)
|
||||
%1 = icmp ne ptr %0, null
|
||||
br i1 %1, label %_llgo_1, label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call i32 (ptr, ...) @printf(ptr @1, ptr %0)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_3, %_llgo_1
|
||||
ret void
|
||||
|
||||
_llgo_3: ; preds = %_llgo_0
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 18 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
br label %_llgo_2
|
||||
}
|
||||
|
||||
declare ptr @_ZN4llvm15itaniumDemangleENSt3__117basic_string_viewIcNS0_11char_traitsIcEEEEb(%"github.com/goplus/llgo/runtime/internal/runtime.String", i1)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8)
|
||||
21
cl/_testlibc/once/in.go
Normal file
21
cl/_testlibc/once/in.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/pthread/sync"
|
||||
)
|
||||
|
||||
var once sync.Once = sync.OnceInit
|
||||
|
||||
func f() {
|
||||
once.Do(func() {
|
||||
c.Printf(c.Str("Do once\n"))
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
println(c.GoString(c.Str("sync.Once demo\n"), 9))
|
||||
println(c.GoString(c.Str("sync.Once demo\n")))
|
||||
f()
|
||||
f()
|
||||
}
|
||||
1
cl/_testlibc/once/out.ll
Normal file
1
cl/_testlibc/once/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
17
cl/_testlibc/setjmp/in.go
Normal file
17
cl/_testlibc/setjmp/in.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
jb := c.AllocaSigjmpBuf()
|
||||
switch ret := c.Sigsetjmp(jb, 0); ret {
|
||||
case 0:
|
||||
cstr := c.Str("??Hello, setjmp!\n")
|
||||
c.Fprintf(c.Stderr, c.Str("%s"), c.Advance(c.Pointer(c.Advance(cstr, 1)), 1))
|
||||
c.Siglongjmp(jb, 1)
|
||||
default:
|
||||
println("exception:", ret)
|
||||
}
|
||||
}
|
||||
1
cl/_testlibc/setjmp/out.ll
Normal file
1
cl/_testlibc/setjmp/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
20
cl/_testlibc/sqlite/in.go
Normal file
20
cl/_testlibc/sqlite/in.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
"github.com/goplus/lib/c/sqlite"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db, err := sqlite.OpenV2(c.Str(":memory:"), sqlite.OpenReadWrite|sqlite.OpenMemory, nil)
|
||||
check(err)
|
||||
|
||||
db.Close()
|
||||
}
|
||||
|
||||
func check(err sqlite.Errno) {
|
||||
if err != sqlite.OK {
|
||||
c.Printf(c.Str("==> Error: (%d) %s\n"), err, err.Errstr())
|
||||
c.Exit(1)
|
||||
}
|
||||
}
|
||||
54
cl/_testlibc/sqlite/out.ll
Normal file
54
cl/_testlibc/sqlite/out.ll
Normal file
@@ -0,0 +1,54 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/cl/_testlibc/sqlite'
|
||||
source_filename = "github.com/goplus/llgo/cl/_testlibc/sqlite"
|
||||
|
||||
@"github.com/goplus/llgo/cl/_testlibc/sqlite.init$guard" = global i1 false, align 1
|
||||
@0 = private unnamed_addr constant [20 x i8] c"==> Error: (%d) %s\0A\00", align 1
|
||||
@1 = private unnamed_addr constant [9 x i8] c":memory:\00", align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/sqlite.check"(i32 %0) {
|
||||
_llgo_0:
|
||||
%1 = icmp ne i32 %0, 0
|
||||
br i1 %1, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call ptr @sqlite3_errstr(i32 %0)
|
||||
%3 = call i32 (ptr, ...) @printf(ptr @0, i32 %0, ptr %2)
|
||||
call void @exit(i32 1)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/sqlite.init"() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibc/sqlite.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/_testlibc/sqlite.init$guard", align 1
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testlibc/sqlite.main"() {
|
||||
_llgo_0:
|
||||
%0 = call { ptr, i32 } @"github.com/goplus/lib/c/sqlite.OpenV2"(ptr @1, i32 130, ptr null)
|
||||
%1 = extractvalue { ptr, i32 } %0, 0
|
||||
%2 = extractvalue { ptr, i32 } %0, 1
|
||||
call void @"github.com/goplus/llgo/cl/_testlibc/sqlite.check"(i32 %2)
|
||||
%3 = call i32 @sqlite3_close(ptr %1)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @sqlite3_errstr(i32)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare void @exit(i32)
|
||||
|
||||
declare { ptr, i32 } @"github.com/goplus/lib/c/sqlite.OpenV2"(ptr, i32, ptr)
|
||||
|
||||
declare i32 @sqlite3_close(ptr)
|
||||
Reference in New Issue
Block a user