build: separate compiler and libs
This commit is contained in:
16
compiler/cl/_testlibc/allocacstrs/in.go
Normal file
16
compiler/cl/_testlibc/allocacstrs/in.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/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++
|
||||
}
|
||||
}
|
||||
101
compiler/cl/_testlibc/allocacstrs/out.ll
Normal file
101
compiler/cl/_testlibc/allocacstrs/out.ll
Normal file
@@ -0,0 +1,101 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@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 @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 i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48)
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 0
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" { ptr @0, i64 1 }, ptr %3, align 8
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 1
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" { ptr @1, i64 1 }, ptr %4, align 8
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 2
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" { ptr @2, i64 1 }, ptr %5, align 8
|
||||
%6 = insertvalue %"github.com/goplus/llgo/internal/runtime.Slice" undef, ptr %2, 0
|
||||
%7 = insertvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, i64 3, 1
|
||||
%8 = insertvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, i64 3, 2
|
||||
%9 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %8, 1
|
||||
%10 = add i64 %9, 1
|
||||
%11 = alloca ptr, i64 %10, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_1: ; preds = %_llgo_3, %_llgo_6
|
||||
%12 = phi i64 [ 0, %_llgo_6 ], [ %17, %_llgo_3 ]
|
||||
%13 = getelementptr ptr, ptr %11, i64 %12
|
||||
%14 = load ptr, ptr %13, align 8
|
||||
%15 = icmp eq ptr %14, null
|
||||
br i1 %15, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
ret i32 0
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
%16 = call i32 (ptr, ...) @printf(ptr @3, ptr %14)
|
||||
%17 = add i64 %12, 1
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_4: ; preds = %_llgo_5, %_llgo_0
|
||||
%18 = phi i64 [ 0, %_llgo_0 ], [ %32, %_llgo_5 ]
|
||||
%19 = icmp slt i64 %18, %9
|
||||
br i1 %19, label %_llgo_5, label %_llgo_6
|
||||
|
||||
_llgo_5: ; preds = %_llgo_4
|
||||
%20 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %8, 0
|
||||
%21 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %8, 1
|
||||
%22 = icmp slt i64 %18, 0
|
||||
%23 = icmp sge i64 %18, %21
|
||||
%24 = or i1 %23, %22
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %24)
|
||||
%25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %20, i64 %18
|
||||
%26 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %25, align 8
|
||||
%27 = getelementptr ptr, ptr %11, i64 %18
|
||||
%28 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %26, 1
|
||||
%29 = add i64 %28, 1
|
||||
%30 = alloca i8, i64 %29, align 1
|
||||
%31 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %30, %"github.com/goplus/llgo/internal/runtime.String" %26)
|
||||
store ptr %31, ptr %27, align 8
|
||||
%32 = add i64 %18, 1
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_6: ; preds = %_llgo_4
|
||||
%33 = getelementptr ptr, ptr %11, i64 %9
|
||||
store ptr null, ptr %33, align 8
|
||||
br label %_llgo_1
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr, %"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
11
compiler/cl/_testlibc/argv/in.go
Normal file
11
compiler/cl/_testlibc/argv/in.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for i := c.Int(0); i < c.Argc; i++ {
|
||||
c.Printf(c.Str("%s\n"), c.Index(c.Argv, i))
|
||||
}
|
||||
}
|
||||
50
compiler/cl/_testlibc/argv/out.ll
Normal file
50
compiler/cl/_testlibc/argv/out.ll
Normal file
@@ -0,0 +1,50 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
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 i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%2 = phi i32 [ 0, %_llgo_0 ], [ %9, %_llgo_2 ]
|
||||
%3 = load i32, ptr @__llgo_argc, align 4
|
||||
%4 = icmp slt i32 %2, %3
|
||||
br i1 %4, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%5 = load ptr, ptr @__llgo_argv, align 8
|
||||
%6 = getelementptr ptr, ptr %5, i32 %2
|
||||
%7 = load ptr, ptr %6, align 8
|
||||
%8 = call i32 (ptr, ...) @printf(ptr @0, ptr %7)
|
||||
%9 = add i32 %2, 1
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
25
compiler/cl/_testlibc/atomic/in.go
Normal file
25
compiler/cl/_testlibc/atomic/in.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/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)
|
||||
}
|
||||
59
compiler/cl/_testlibc/atomic/out.ll
Normal file
59
compiler/cl/_testlibc/atomic/out.ll
Normal file
@@ -0,0 +1,59 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@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 @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 i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 8)
|
||||
store atomic i64 100, ptr %2 seq_cst, align 4
|
||||
%3 = load atomic i64, ptr %2 seq_cst, align 4
|
||||
%4 = call i32 (ptr, ...) @printf(ptr @0, i64 %3)
|
||||
%5 = atomicrmw add ptr %2, i64 1 seq_cst, align 8
|
||||
%6 = load i64, ptr %2, align 4
|
||||
%7 = call i32 (ptr, ...) @printf(ptr @1, i64 %5, i64 %6)
|
||||
%8 = cmpxchg ptr %2, i64 100, i64 102 seq_cst seq_cst, align 8
|
||||
%9 = extractvalue { i64, i1 } %8, 0
|
||||
%10 = extractvalue { i64, i1 } %8, 1
|
||||
%11 = load i64, ptr %2, align 4
|
||||
%12 = call i32 (ptr, ...) @printf(ptr @2, i64 %9, i64 %11)
|
||||
%13 = cmpxchg ptr %2, i64 101, i64 102 seq_cst seq_cst, align 8
|
||||
%14 = extractvalue { i64, i1 } %13, 0
|
||||
%15 = extractvalue { i64, i1 } %13, 1
|
||||
%16 = load i64, ptr %2, align 4
|
||||
%17 = call i32 (ptr, ...) @printf(ptr @3, i64 %14, i64 %16)
|
||||
%18 = atomicrmw sub ptr %2, i64 1 seq_cst, align 8
|
||||
%19 = load i64, ptr %2, align 4
|
||||
%20 = call i32 (ptr, ...) @printf(ptr @4, i64 %18, i64 %19)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
21
compiler/cl/_testlibc/complex/in.go
Normal file
21
compiler/cl/_testlibc/complex/in.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/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))
|
||||
}
|
||||
74
compiler/cl/_testlibc/complex/out.ll
Normal file
74
compiler/cl/_testlibc/complex/out.ll
Normal file
@@ -0,0 +1,74 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
|
||||
@"main.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
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
|
||||
define void @main.f({ float, float } %0, { float, float } %1, ptr %2) {
|
||||
_llgo_0:
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" { ptr @0, i64 5 })
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr %2)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%3 = call float @cabsf({ float, float } %0)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" { ptr @1, i64 10 })
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
%4 = fpext float %3 to double
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%5 = extractvalue { float, float } %1, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" { ptr @2, i64 11 })
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
%6 = fpext float %5 to double
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %6)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%7 = extractvalue { float, float } %1, 1
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" { ptr @3, i64 11 })
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
%8 = fpext float %7 to double
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %8)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
}
|
||||
|
||||
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 i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
call void @main.f({ float, float } { float 3.000000e+00, float 4.000000e+00 }, { float, float } { float 3.000000e+00, float 4.000000e+00 }, ptr @main.f)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr)
|
||||
|
||||
declare float @cabsf({ float, float })
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
17
compiler/cl/_testlibc/defer/in.go
Normal file
17
compiler/cl/_testlibc/defer/in.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/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
compiler/cl/_testlibc/defer/out.ll
Normal file
1
compiler/cl/_testlibc/defer/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
15
compiler/cl/_testlibc/demangle/in.go
Normal file
15
compiler/cl/_testlibc/demangle/in.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/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")
|
||||
}
|
||||
}
|
||||
57
compiler/cl/_testlibc/demangle/out.ll
Normal file
57
compiler/cl/_testlibc/demangle/out.ll
Normal file
@@ -0,0 +1,57 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@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 @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 i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = call ptr @_ZN4llvm15itaniumDemangleENSt3__117basic_string_viewIcNS0_11char_traitsIcEEEEb(%"github.com/goplus/llgo/internal/runtime.String" { ptr @0, i64 29 }, i1 true)
|
||||
%3 = icmp ne ptr %2, null
|
||||
br i1 %3, label %_llgo_1, label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call i32 (ptr, ...) @printf(ptr @1, ptr %2)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_3, %_llgo_1
|
||||
ret i32 0
|
||||
|
||||
_llgo_3: ; preds = %_llgo_0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" { ptr @2, i64 18 })
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
br label %_llgo_2
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @_ZN4llvm15itaniumDemangleENSt3__117basic_string_viewIcNS0_11char_traitsIcEEEEb(%"github.com/goplus/llgo/internal/runtime.String", i1)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
21
compiler/cl/_testlibc/once/in.go
Normal file
21
compiler/cl/_testlibc/once/in.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/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
compiler/cl/_testlibc/once/out.ll
Normal file
1
compiler/cl/_testlibc/once/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
17
compiler/cl/_testlibc/setjmp/in.go
Normal file
17
compiler/cl/_testlibc/setjmp/in.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/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
compiler/cl/_testlibc/setjmp/out.ll
Normal file
1
compiler/cl/_testlibc/setjmp/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
20
compiler/cl/_testlibc/sqlite/in.go
Normal file
20
compiler/cl/_testlibc/sqlite/in.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/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)
|
||||
}
|
||||
}
|
||||
62
compiler/cl/_testlibc/sqlite/out.ll
Normal file
62
compiler/cl/_testlibc/sqlite/out.ll
Normal file
@@ -0,0 +1,62 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@0 = private unnamed_addr constant [20 x i8] c"==> Error: (%d) %s\0A\00", align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@1 = private unnamed_addr constant [9 x i8] c":memory:\00", align 1
|
||||
|
||||
define void @main.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 @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 i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = call { ptr, i32 } @"github.com/goplus/llgo/c/sqlite.OpenV2"(ptr @1, i32 130, ptr null)
|
||||
%3 = extractvalue { ptr, i32 } %2, 0
|
||||
%4 = extractvalue { ptr, i32 } %2, 1
|
||||
call void @main.check(i32 %4)
|
||||
%5 = call i32 @sqlite3_close(ptr %3)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare ptr @sqlite3_errstr(i32)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare void @exit(i32)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare { ptr, i32 } @"github.com/goplus/llgo/c/sqlite.OpenV2"(ptr, i32, ptr)
|
||||
|
||||
declare i32 @sqlite3_close(ptr)
|
||||
Reference in New Issue
Block a user