move out c/cpp/py

This commit is contained in:
Li Jie
2025-04-03 15:52:18 +08:00
parent 0a8a4eb6a6
commit ed366568b4
777 changed files with 4608 additions and 139122 deletions

View File

@@ -0,0 +1,24 @@
package main
import (
"sync/atomic"
)
func main() {
var v int64
atomic.StoreInt64(&v, 100)
println("store:", atomic.LoadInt64(&v))
ret := atomic.AddInt64(&v, 1)
println("ret:", ret, "v:", v)
swp := atomic.CompareAndSwapInt64(&v, 100, 102)
println("swp:", swp, "v:", v)
swp = atomic.CompareAndSwapInt64(&v, 101, 102)
println("swp:", swp, "v:", v)
ret = atomic.AddInt64(&v, -1)
println("ret:", ret, "v:", v)
}

View File

@@ -0,0 +1,92 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testlibgo/atomic'
source_filename = "github.com/goplus/llgo/cl/_testlibgo/atomic"
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
@"github.com/goplus/llgo/cl/_testlibgo/atomic.init$guard" = global i1 false, align 1
@0 = private unnamed_addr constant [6 x i8] c"store:", align 1
@1 = private unnamed_addr constant [4 x i8] c"ret:", align 1
@2 = private unnamed_addr constant [2 x i8] c"v:", align 1
@3 = private unnamed_addr constant [4 x i8] c"swp:", align 1
define void @"github.com/goplus/llgo/cl/_testlibgo/atomic.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibgo/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/_testlibgo/atomic.init$guard", align 1
call void @"sync/atomic.init"()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testlibgo/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
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 6 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %1)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%2 = call i64 @"sync/atomic.AddInt64"(ptr %0, i64 1)
%3 = load i64, ptr %0, align 4
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 4 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %2)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 2 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %3)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%4 = call i1 @"sync/atomic.CompareAndSwapInt64"(ptr %0, i64 100, i64 102)
%5 = load i64, ptr %0, align 4
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 4 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintBool"(i1 %4)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 2 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %5)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%6 = call i1 @"sync/atomic.CompareAndSwapInt64"(ptr %0, i64 101, i64 102)
%7 = load i64, ptr %0, align 4
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 4 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintBool"(i1 %6)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 2 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %7)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%8 = call i64 @"sync/atomic.AddInt64"(ptr %0, i64 -1)
%9 = load i64, ptr %0, align 4
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 4 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %8)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 2 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %9)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
ret void
}
declare void @"sync/atomic.init"()
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
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.PrintInt"(i64)
declare i64 @"sync/atomic.AddInt64"(ptr, i64)
declare i1 @"sync/atomic.CompareAndSwapInt64"(ptr, i64, i64)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintBool"(i1)

15
cl/_testlibgo/bytes/in.go Normal file
View File

@@ -0,0 +1,15 @@
package main
import (
"bytes"
)
func main() {
var b bytes.Buffer // A Buffer needs no initialization.
b.Write([]byte("Hello "))
b.WriteString("World")
println("buf", b.Bytes(), b.String())
println(bytes.EqualFold([]byte("Go"), []byte("go")))
}

View File

@@ -0,0 +1,73 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testlibgo/bytes'
source_filename = "github.com/goplus/llgo/cl/_testlibgo/bytes"
%"github.com/goplus/llgo/runtime/internal/runtime.Slice" = type { ptr, i64, i64 }
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/runtime/internal/runtime.iface" = type { ptr, ptr }
@"github.com/goplus/llgo/cl/_testlibgo/bytes.init$guard" = global i1 false, align 1
@0 = private unnamed_addr constant [6 x i8] c"Hello ", align 1
@1 = private unnamed_addr constant [5 x i8] c"World", align 1
@2 = private unnamed_addr constant [3 x i8] c"buf", align 1
@3 = private unnamed_addr constant [2 x i8] c"Go", align 1
@4 = private unnamed_addr constant [2 x i8] c"go", align 1
define void @"github.com/goplus/llgo/cl/_testlibgo/bytes.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibgo/bytes.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/_testlibgo/bytes.init$guard", align 1
call void @bytes.init()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testlibgo/bytes.main"() {
_llgo_0:
%0 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 40)
%1 = call %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @"github.com/goplus/llgo/runtime/internal/runtime.StringToBytes"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 6 })
%2 = call { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @"bytes.(*Buffer).Write"(ptr %0, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %1)
%3 = call { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @"bytes.(*Buffer).WriteString"(ptr %0, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 5 })
%4 = call %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @"bytes.(*Buffer).Bytes"(ptr %0)
%5 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" @"bytes.(*Buffer).String"(ptr %0)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 3 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %4)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %5)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%6 = call %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @"github.com/goplus/llgo/runtime/internal/runtime.StringToBytes"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 2 })
%7 = call %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @"github.com/goplus/llgo/runtime/internal/runtime.StringToBytes"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 2 })
%8 = call i1 @bytes.EqualFold(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %6, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %7)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintBool"(i1 %8)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
ret void
}
declare void @bytes.init()
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
declare %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @"github.com/goplus/llgo/runtime/internal/runtime.StringToBytes"(%"github.com/goplus/llgo/runtime/internal/runtime.String")
declare { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @"bytes.(*Buffer).Write"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
declare { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @"bytes.(*Buffer).WriteString"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.String")
declare %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @"bytes.(*Buffer).Bytes"(ptr)
declare %"github.com/goplus/llgo/runtime/internal/runtime.String" @"bytes.(*Buffer).String"(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)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice")
declare i1 @bytes.EqualFold(%"github.com/goplus/llgo/runtime/internal/runtime.Slice", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintBool"(i1)

View File

@@ -0,0 +1,19 @@
package main
import (
"math/cmplx"
)
func f(c, z complex128) {
println("abs(3+4i):", cmplx.Abs(c))
println("real(3+4i):", real(z))
println("imag(3+4i):", imag(z))
}
func main() {
re := 3.0
im := 4.0
z := 3 + 4i
c := complex(re, im)
f(c, z)
}

View File

@@ -0,0 +1,59 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testlibgo/complex'
source_filename = "github.com/goplus/llgo/cl/_testlibgo/complex"
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
@"github.com/goplus/llgo/cl/_testlibgo/complex.init$guard" = global i1 false, align 1
@0 = private unnamed_addr constant [10 x i8] c"abs(3+4i):", align 1
@1 = private unnamed_addr constant [11 x i8] c"real(3+4i):", align 1
@2 = private unnamed_addr constant [11 x i8] c"imag(3+4i):", align 1
define void @"github.com/goplus/llgo/cl/_testlibgo/complex.f"({ double, double } %0, { double, double } %1) {
_llgo_0:
%2 = call double @cabs({ double, double } %0)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 10 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double %2)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%3 = extractvalue { double, double } %1, 0
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 11 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double %3)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%4 = extractvalue { double, double } %1, 1
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)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double %4)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
ret void
}
define void @"github.com/goplus/llgo/cl/_testlibgo/complex.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibgo/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/_testlibgo/complex.init$guard", align 1
call void @"math/cmplx.init"()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testlibgo/complex.main"() {
_llgo_0:
call void @"github.com/goplus/llgo/cl/_testlibgo/complex.f"({ double, double } { double 3.000000e+00, double 4.000000e+00 }, { double, double } { double 3.000000e+00, double 4.000000e+00 })
ret void
}
declare double @cabs({ double, double })
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.PrintFloat"(double)
declare void @"math/cmplx.init"()

View File

@@ -0,0 +1,8 @@
package main
import "errors"
func main() {
err := errors.New("error")
panic(err)
}

View File

@@ -0,0 +1,42 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testlibgo/errors'
source_filename = "github.com/goplus/llgo/cl/_testlibgo/errors"
%"github.com/goplus/llgo/runtime/internal/runtime.iface" = type { ptr, ptr }
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/runtime/internal/runtime.eface" = type { ptr, ptr }
@"github.com/goplus/llgo/cl/_testlibgo/errors.init$guard" = global i1 false, align 1
@0 = private unnamed_addr constant [5 x i8] c"error", align 1
define void @"github.com/goplus/llgo/cl/_testlibgo/errors.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibgo/errors.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/_testlibgo/errors.init$guard", align 1
call void @errors.init()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testlibgo/errors.main"() {
_llgo_0:
%0 = call %"github.com/goplus/llgo/runtime/internal/runtime.iface" @errors.New(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 5 })
%1 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %0)
%2 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %0, 1
%3 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %1, 0
%4 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %3, ptr %2, 1
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %4)
unreachable
}
declare void @errors.init()
declare %"github.com/goplus/llgo/runtime/internal/runtime.iface" @errors.New(%"github.com/goplus/llgo/runtime/internal/runtime.String")
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface")
declare void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface")

11
cl/_testlibgo/math/in.go Normal file
View File

@@ -0,0 +1,11 @@
package main
import (
"math"
)
func main() {
println(math.Sqrt(2))
println(math.Abs(-1.2))
println(math.Ldexp(1.2, 3))
}

44
cl/_testlibgo/math/out.ll Normal file
View File

@@ -0,0 +1,44 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testlibgo/math'
source_filename = "github.com/goplus/llgo/cl/_testlibgo/math"
@"github.com/goplus/llgo/cl/_testlibgo/math.init$guard" = global i1 false, align 1
define void @"github.com/goplus/llgo/cl/_testlibgo/math.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibgo/math.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/_testlibgo/math.init$guard", align 1
call void @math.init()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testlibgo/math.main"() {
_llgo_0:
%0 = call double @sqrt(double 2.000000e+00)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double %0)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%1 = call double @math.Abs(double -1.200000e+00)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double %1)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%2 = call double @math.Ldexp(double 1.200000e+00, i64 3)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double %2)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
ret void
}
declare void @math.init()
declare double @sqrt(double)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8)
declare double @math.Abs(double)
declare double @math.Ldexp(double, i64)

View File

@@ -0,0 +1,10 @@
package main
import (
"math/bits"
)
func main() {
println(bits.Len8(20))
println(bits.OnesCount(20))
}

View File

@@ -0,0 +1,39 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testlibgo/mathbits'
source_filename = "github.com/goplus/llgo/cl/_testlibgo/mathbits"
@"github.com/goplus/llgo/cl/_testlibgo/mathbits.init$guard" = global i1 false, align 1
define void @"github.com/goplus/llgo/cl/_testlibgo/mathbits.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibgo/mathbits.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/_testlibgo/mathbits.init$guard", align 1
call void @"math/bits.init"()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testlibgo/mathbits.main"() {
_llgo_0:
%0 = call i64 @"math/bits.Len8"(i8 20)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %0)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%1 = call i64 @"math/bits.OnesCount"(i64 20)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %1)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
ret void
}
declare void @"math/bits.init"()
declare i64 @"math/bits.Len8"(i8)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8)
declare i64 @"math/bits.OnesCount"(i64)

View File

@@ -0,0 +1,7 @@
package main
import "net/textproto"
func main() {
println(textproto.CanonicalMIMEHeaderKey("host"))
}

View File

@@ -0,0 +1,37 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testlibgo/nettextproto'
source_filename = "github.com/goplus/llgo/cl/_testlibgo/nettextproto"
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
@"github.com/goplus/llgo/cl/_testlibgo/nettextproto.init$guard" = global i1 false, align 1
@0 = private unnamed_addr constant [4 x i8] c"host", align 1
define void @"github.com/goplus/llgo/cl/_testlibgo/nettextproto.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibgo/nettextproto.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/_testlibgo/nettextproto.init$guard", align 1
call void @"net/textproto.init"()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testlibgo/nettextproto.main"() {
_llgo_0:
%0 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" @"net/textproto.CanonicalMIMEHeaderKey"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 4 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %0)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
ret void
}
declare void @"net/textproto.init"()
declare %"github.com/goplus/llgo/runtime/internal/runtime.String" @"net/textproto.CanonicalMIMEHeaderKey"(%"github.com/goplus/llgo/runtime/internal/runtime.String")
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)

11
cl/_testlibgo/os/in.go Normal file
View File

@@ -0,0 +1,11 @@
package main
import "os"
func main() {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
println("cwd:", wd)
}

69
cl/_testlibgo/os/out.ll Normal file
View File

@@ -0,0 +1,69 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testlibgo/os'
source_filename = "github.com/goplus/llgo/cl/_testlibgo/os"
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/runtime/internal/runtime.iface" = type { ptr, ptr }
%"github.com/goplus/llgo/runtime/internal/runtime.eface" = type { ptr, ptr }
@"github.com/goplus/llgo/cl/_testlibgo/os.init$guard" = global i1 false, align 1
@0 = private unnamed_addr constant [4 x i8] c"cwd:", align 1
define void @"github.com/goplus/llgo/cl/_testlibgo/os.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibgo/os.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/_testlibgo/os.init$guard", align 1
call void @os.init()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testlibgo/os.main"() {
_llgo_0:
%0 = call { %"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @os.Getwd()
%1 = extractvalue { %"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.iface" } %0, 0
%2 = extractvalue { %"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.iface" } %0, 1
%3 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %2)
%4 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %2, 1
%5 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %3, 0
%6 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %5, ptr %4, 1
%7 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" zeroinitializer)
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %7, 0
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %8, ptr null, 1
%10 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.EfaceEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %6, %"github.com/goplus/llgo/runtime/internal/runtime.eface" %9)
%11 = xor i1 %10, true
br i1 %11, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0
%12 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %2)
%13 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %2, 1
%14 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %12, 0
%15 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %14, ptr %13, 1
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %15)
unreachable
_llgo_2: ; preds = %_llgo_0
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 4 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %1)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
ret void
}
declare void @os.init()
declare { %"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @os.Getwd()
declare i1 @"github.com/goplus/llgo/runtime/internal/runtime.EfaceEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.eface", %"github.com/goplus/llgo/runtime/internal/runtime.eface")
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface")
declare void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface")
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)

View File

@@ -0,0 +1,20 @@
package main
import (
"strings"
"unicode"
)
func main() {
var b strings.Builder
b.Write([]byte("Hello "))
b.WriteString("World")
println("len:", b.Len(), "cap:", b.Cap(), "string:", b.String())
f := func(c rune) bool {
return unicode.Is(unicode.Han, c)
}
println(strings.IndexFunc("Hello, 世界", f))
println(strings.IndexFunc("Hello, world", f))
}

View File

@@ -0,0 +1,102 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testlibgo/strings'
source_filename = "github.com/goplus/llgo/cl/_testlibgo/strings"
%"github.com/goplus/llgo/runtime/internal/runtime.Slice" = type { ptr, i64, i64 }
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/runtime/internal/runtime.iface" = type { ptr, ptr }
@"github.com/goplus/llgo/cl/_testlibgo/strings.init$guard" = global i1 false, align 1
@0 = private unnamed_addr constant [6 x i8] c"Hello ", align 1
@1 = private unnamed_addr constant [5 x i8] c"World", align 1
@2 = private unnamed_addr constant [4 x i8] c"len:", align 1
@3 = private unnamed_addr constant [4 x i8] c"cap:", align 1
@4 = private unnamed_addr constant [7 x i8] c"string:", align 1
@5 = private unnamed_addr constant [13 x i8] c"Hello, \E4\B8\96\E7\95\8C", align 1
@6 = private unnamed_addr constant [12 x i8] c"Hello, world", align 1
@unicode.Han = external global ptr, align 8
define void @"github.com/goplus/llgo/cl/_testlibgo/strings.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testlibgo/strings.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/_testlibgo/strings.init$guard", align 1
call void @strings.init()
call void @unicode.init()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testlibgo/strings.main"() {
_llgo_0:
%0 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 32)
%1 = call %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @"github.com/goplus/llgo/runtime/internal/runtime.StringToBytes"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 6 })
%2 = call { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @"strings.(*Builder).Write"(ptr %0, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %1)
%3 = call { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @"strings.(*Builder).WriteString"(ptr %0, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 5 })
%4 = call i64 @"strings.(*Builder).Len"(ptr %0)
%5 = call i64 @"strings.(*Builder).Cap"(ptr %0)
%6 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" @"strings.(*Builder).String"(ptr %0)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 4 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %4)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 4 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %5)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 7 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %6)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%7 = call i64 @strings.IndexFunc(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 13 }, { ptr, ptr } { ptr @"__llgo_stub.github.com/goplus/llgo/cl/_testlibgo/strings.main$1", ptr null })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %7)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
%8 = call i64 @strings.IndexFunc(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 12 }, { ptr, ptr } { ptr @"__llgo_stub.github.com/goplus/llgo/cl/_testlibgo/strings.main$1", ptr null })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %8)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
ret void
}
define i1 @"github.com/goplus/llgo/cl/_testlibgo/strings.main$1"(i32 %0) {
_llgo_0:
%1 = load ptr, ptr @unicode.Han, align 8
%2 = call i1 @unicode.Is(ptr %1, i32 %0)
ret i1 %2
}
declare void @strings.init()
declare void @unicode.init()
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
declare %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @"github.com/goplus/llgo/runtime/internal/runtime.StringToBytes"(%"github.com/goplus/llgo/runtime/internal/runtime.String")
declare { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @"strings.(*Builder).Write"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
declare { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @"strings.(*Builder).WriteString"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.String")
declare i64 @"strings.(*Builder).Len"(ptr)
declare i64 @"strings.(*Builder).Cap"(ptr)
declare %"github.com/goplus/llgo/runtime/internal/runtime.String" @"strings.(*Builder).String"(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)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64)
declare i64 @strings.IndexFunc(%"github.com/goplus/llgo/runtime/internal/runtime.String", { ptr, ptr })
define linkonce i1 @"__llgo_stub.github.com/goplus/llgo/cl/_testlibgo/strings.main$1"(ptr %0, i32 %1) {
_llgo_0:
%2 = tail call i1 @"github.com/goplus/llgo/cl/_testlibgo/strings.main$1"(i32 %1)
ret i1 %2
}
declare i1 @unicode.Is(ptr, i32)

18
cl/_testlibgo/sync/in.go Normal file
View File

@@ -0,0 +1,18 @@
package main
import (
"sync"
)
var once sync.Once
func f(s string) {
once.Do(func() {
println(s)
})
}
func main() {
f("Do once")
f("Do twice")
}

View File

@@ -0,0 +1 @@
;

View File

@@ -0,0 +1,20 @@
package main
import (
"sync"
)
func main() {
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
println("work 1")
}()
go func() {
defer wg.Done()
println("work 2")
}()
wg.Wait()
println("done")
}

View File

@@ -0,0 +1 @@
;