Compare commits
54 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9203c366e7 | ||
|
|
11a8af1db2 | ||
|
|
c8fb7eafa0 | ||
|
|
ffc1f712a3 | ||
|
|
cfc8687851 | ||
|
|
953699b2fd | ||
|
|
9a16fff27e | ||
|
|
ac0d104231 | ||
|
|
881efea006 | ||
|
|
f6a380d293 | ||
|
|
a971b93994 | ||
|
|
c4f0dd124d | ||
|
|
93b9b7d44c | ||
|
|
7552bfe39b | ||
|
|
2601faaff2 | ||
|
|
cb2e28d086 | ||
|
|
337877313a | ||
|
|
1693942cee | ||
|
|
867a1ce2f4 | ||
|
|
26b997537f | ||
|
|
19056b8a19 | ||
|
|
10d603b377 | ||
|
|
3f41c313ad | ||
|
|
d440949c1d | ||
|
|
64314dc6cf | ||
|
|
decb9d7f11 | ||
|
|
975b0b74ee | ||
|
|
9aa7807b02 | ||
|
|
337c6cfa25 | ||
|
|
f09a423ee7 | ||
|
|
3bf28f52c4 | ||
|
|
f794592f42 | ||
|
|
98bd05b47b | ||
|
|
3edbde0839 | ||
|
|
a2d92eac0b | ||
|
|
eb47c545ec | ||
|
|
c858f79449 | ||
|
|
27f6efbdec | ||
|
|
bba7494ffd | ||
|
|
0f79cad5a7 | ||
|
|
9e7bacbe23 | ||
|
|
2301a4834d | ||
|
|
40e0f58079 | ||
|
|
c23fb144cf | ||
|
|
caac681ac3 | ||
|
|
9ba3b3ef8f | ||
|
|
d7e523948b | ||
|
|
10a75138d1 | ||
|
|
d48b19c866 | ||
|
|
1fdcb55eba | ||
|
|
16cec9f045 | ||
|
|
438b0bd1b0 | ||
|
|
e8a91696d6 | ||
|
|
3ac9055493 |
2
.github/codecov.yml
vendored
2
.github/codecov.yml
vendored
@@ -8,4 +8,4 @@ coverage:
|
||||
- "internal/packages"
|
||||
- "internal/typepatch"
|
||||
- "internal/github"
|
||||
- "xtool/cppkg"
|
||||
- "xtool"
|
||||
|
||||
25
cl/_testgo/alias/in.go
Normal file
25
cl/_testgo/alias/in.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
type Point struct {
|
||||
x float64
|
||||
y float64
|
||||
}
|
||||
|
||||
func (p *Point) Scale(factor float64) {
|
||||
p.x *= factor
|
||||
p.y *= factor
|
||||
}
|
||||
|
||||
type MyPoint = Point
|
||||
|
||||
func (p *MyPoint) Move(dx, dy float64) {
|
||||
p.x += dx
|
||||
p.y += dy
|
||||
}
|
||||
|
||||
func main() {
|
||||
pt := &MyPoint{1, 2}
|
||||
pt.Scale(2)
|
||||
pt.Move(3, 4)
|
||||
println(pt.x, pt.y)
|
||||
}
|
||||
75
cl/_testgo/alias/out.ll
Normal file
75
cl/_testgo/alias/out.ll
Normal file
@@ -0,0 +1,75 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/cl/_testgo/alias'
|
||||
source_filename = "github.com/goplus/llgo/cl/_testgo/alias"
|
||||
|
||||
%"github.com/goplus/llgo/cl/_testgo/alias.Point" = type { double, double }
|
||||
|
||||
@"github.com/goplus/llgo/cl/_testgo/alias.init$guard" = global i1 false, align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/alias.(*Point).Move"(ptr %0, double %1, double %2) {
|
||||
_llgo_0:
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 0
|
||||
%4 = load double, ptr %3, align 8
|
||||
%5 = fadd double %4, %1
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 0
|
||||
store double %5, ptr %6, align 8
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 1
|
||||
%8 = load double, ptr %7, align 8
|
||||
%9 = fadd double %8, %2
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 1
|
||||
store double %9, ptr %10, align 8
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/alias.(*Point).Scale"(ptr %0, double %1) {
|
||||
_llgo_0:
|
||||
%2 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 0
|
||||
%3 = load double, ptr %2, align 8
|
||||
%4 = fmul double %3, %1
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 0
|
||||
store double %4, ptr %5, align 8
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 1
|
||||
%7 = load double, ptr %6, align 8
|
||||
%8 = fmul double %7, %1
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 1
|
||||
store double %8, ptr %9, align 8
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/alias.init"() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testgo/alias.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/_testgo/alias.init$guard", align 1
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/alias.main"() {
|
||||
_llgo_0:
|
||||
%0 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 16)
|
||||
%1 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 0
|
||||
%2 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 1
|
||||
store double 1.000000e+00, ptr %1, align 8
|
||||
store double 2.000000e+00, ptr %2, align 8
|
||||
call void @"github.com/goplus/llgo/cl/_testgo/alias.(*Point).Scale"(ptr %0, double 2.000000e+00)
|
||||
call void @"github.com/goplus/llgo/cl/_testgo/alias.(*Point).Move"(ptr %0, double 3.000000e+00, double 4.000000e+00)
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 0
|
||||
%4 = load double, ptr %3, align 8
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/alias.Point", ptr %0, i32 0, i32 1
|
||||
%6 = load double, ptr %5, align 8
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double %4)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double %6)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintFloat"(double)
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8)
|
||||
@@ -319,7 +319,7 @@ _llgo_17: ; preds = %_llgo_4
|
||||
%108 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%109 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %108, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %43, ptr %109, align 8
|
||||
%110 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.one$bound", ptr undef }, ptr %108, 1
|
||||
%110 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.one$bound", ptr undef }, ptr %108, 1
|
||||
%111 = extractvalue { ptr, ptr } %110, 1
|
||||
%112 = extractvalue { ptr, ptr } %110, 0
|
||||
%113 = call i64 %112(ptr %111)
|
||||
@@ -339,7 +339,7 @@ _llgo_19: ; preds = %_llgo_6
|
||||
%119 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%120 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %119, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %51, ptr %120, align 8
|
||||
%121 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.one$bound", ptr undef }, ptr %119, 1
|
||||
%121 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.one$bound", ptr undef }, ptr %119, 1
|
||||
%122 = extractvalue { ptr, ptr } %121, 1
|
||||
%123 = extractvalue { ptr, ptr } %121, 0
|
||||
%124 = call i64 %123(ptr %122)
|
||||
@@ -359,7 +359,7 @@ _llgo_21: ; preds = %_llgo_12
|
||||
%130 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%131 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %130, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %93, ptr %131, align 8
|
||||
%132 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.two$bound", ptr undef }, ptr %130, 1
|
||||
%132 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.two$bound", ptr undef }, ptr %130, 1
|
||||
%133 = extractvalue { ptr, ptr } %132, 1
|
||||
%134 = extractvalue { ptr, ptr } %132, 0
|
||||
%135 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %134(ptr %133)
|
||||
@@ -380,7 +380,7 @@ _llgo_23: ; preds = %_llgo_14
|
||||
%142 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%143 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %142, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %101, ptr %143, align 8
|
||||
%144 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.two$bound", ptr undef }, ptr %142, 1
|
||||
%144 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.two$bound", ptr undef }, ptr %142, 1
|
||||
%145 = extractvalue { ptr, ptr } %144, 1
|
||||
%146 = extractvalue { ptr, ptr } %144, 0
|
||||
%147 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %146(ptr %145)
|
||||
@@ -585,7 +585,7 @@ declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
define i64 @"github.com/goplus/llgo/cl/_testgo/ifaceprom.one$bound"(ptr %0) {
|
||||
define i64 @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.one$bound"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %0, align 8
|
||||
%2 = extractvalue { %"github.com/goplus/llgo/runtime/internal/runtime.iface" } %1, 0
|
||||
@@ -603,7 +603,7 @@ _llgo_0:
|
||||
|
||||
declare i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
define %"github.com/goplus/llgo/runtime/internal/runtime.String" @"github.com/goplus/llgo/cl/_testgo/ifaceprom.two$bound"(ptr %0) {
|
||||
define %"github.com/goplus/llgo/runtime/internal/runtime.String" @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.two$bound"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %0, align 8
|
||||
%2 = extractvalue { %"github.com/goplus/llgo/runtime/internal/runtime.iface" } %1, 0
|
||||
|
||||
24
cl/_testgo/reflectfn/in.go
Normal file
24
cl/_testgo/reflectfn/in.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func demo() {
|
||||
println("demo")
|
||||
}
|
||||
|
||||
func main() {
|
||||
v := 100
|
||||
fn := func() {
|
||||
println(v)
|
||||
}
|
||||
fdemo := demo
|
||||
fmt.Println(fn)
|
||||
fmt.Println(demo)
|
||||
fmt.Println(fdemo)
|
||||
fmt.Println(reflect.ValueOf(fn).UnsafePointer())
|
||||
fmt.Println(reflect.ValueOf(demo).UnsafePointer())
|
||||
fmt.Println(reflect.ValueOf(fdemo).UnsafePointer())
|
||||
}
|
||||
244
cl/_testgo/reflectfn/out.ll
Normal file
244
cl/_testgo/reflectfn/out.ll
Normal file
@@ -0,0 +1,244 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/cl/_testgo/reflectfn'
|
||||
source_filename = "github.com/goplus/llgo/cl/_testgo/reflectfn"
|
||||
|
||||
%"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/runtime/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||
%"github.com/goplus/llgo/runtime/internal/runtime.iface" = type { ptr, ptr }
|
||||
%reflect.Value = type { ptr, ptr, i64 }
|
||||
%"github.com/goplus/llgo/runtime/abi.StructField" = type { %"github.com/goplus/llgo/runtime/internal/runtime.String", ptr, i64, %"github.com/goplus/llgo/runtime/internal/runtime.String", i1 }
|
||||
|
||||
@"github.com/goplus/llgo/cl/_testgo/reflectfn.init$guard" = global i1 false, align 1
|
||||
@0 = private unnamed_addr constant [4 x i8] c"demo", align 1
|
||||
@"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac" = linkonce global ptr null, align 8
|
||||
@_llgo_Pointer = linkonce global ptr null, align 8
|
||||
@"github.com/goplus/llgo/cl/_testgo/reflectfn.struct$b7Su1hWaFih-M0M9hMk6nO_RD1K_GQu5WjIXQp6Q2e8" = linkonce global ptr null, align 8
|
||||
@1 = private unnamed_addr constant [2 x i8] c"$f", align 1
|
||||
@2 = private unnamed_addr constant [5 x i8] c"$data", align 1
|
||||
@3 = private unnamed_addr constant [43 x i8] c"github.com/goplus/llgo/cl/_testgo/reflectfn", align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/reflectfn.demo"() {
|
||||
_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 10)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/reflectfn.init"() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testgo/reflectfn.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/_testgo/reflectfn.init$guard", align 1
|
||||
call void @fmt.init()
|
||||
call void @reflect.init()
|
||||
call void @"github.com/goplus/llgo/cl/_testgo/reflectfn.init$after"()
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/reflectfn.main"() {
|
||||
_llgo_0:
|
||||
%0 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 8)
|
||||
store i64 100, ptr %0, align 4
|
||||
%1 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 8)
|
||||
%2 = getelementptr inbounds { ptr }, ptr %1, i32 0, i32 0
|
||||
store ptr %0, ptr %2, align 8
|
||||
%3 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/reflectfn.main$1", ptr undef }, ptr %1, 1
|
||||
%4 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 16)
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.eface", ptr %4, i64 0
|
||||
%6 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%7 = load ptr, ptr @_llgo_Pointer, align 8
|
||||
%8 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/reflectfn.struct$b7Su1hWaFih-M0M9hMk6nO_RD1K_GQu5WjIXQp6Q2e8", align 8
|
||||
%9 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store { ptr, ptr } %3, ptr %9, align 8
|
||||
%10 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %8, 0
|
||||
%11 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %10, ptr %9, 1
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.eface" %11, ptr %5, align 8
|
||||
%12 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %4, 0
|
||||
%13 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %12, i64 1, 1
|
||||
%14 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %13, i64 1, 2
|
||||
%15 = call { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @fmt.Println(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %14)
|
||||
%16 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 16)
|
||||
%17 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.eface", ptr %16, i64 0
|
||||
%18 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/reflectfn.struct$b7Su1hWaFih-M0M9hMk6nO_RD1K_GQu5WjIXQp6Q2e8", align 8
|
||||
%19 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store { ptr, ptr } { ptr @"__llgo_stub.github.com/goplus/llgo/cl/_testgo/reflectfn.demo", ptr null }, ptr %19, align 8
|
||||
%20 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %18, 0
|
||||
%21 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %20, ptr %19, 1
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.eface" %21, ptr %17, align 8
|
||||
%22 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %16, 0
|
||||
%23 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %22, i64 1, 1
|
||||
%24 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %23, i64 1, 2
|
||||
%25 = call { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @fmt.Println(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %24)
|
||||
%26 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 16)
|
||||
%27 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.eface", ptr %26, i64 0
|
||||
%28 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/reflectfn.struct$b7Su1hWaFih-M0M9hMk6nO_RD1K_GQu5WjIXQp6Q2e8", align 8
|
||||
%29 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store { ptr, ptr } { ptr @"__llgo_stub.github.com/goplus/llgo/cl/_testgo/reflectfn.demo", ptr null }, ptr %29, align 8
|
||||
%30 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %28, 0
|
||||
%31 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %30, ptr %29, 1
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.eface" %31, ptr %27, align 8
|
||||
%32 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %26, 0
|
||||
%33 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %32, i64 1, 1
|
||||
%34 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %33, i64 1, 2
|
||||
%35 = call { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @fmt.Println(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %34)
|
||||
%36 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/reflectfn.struct$b7Su1hWaFih-M0M9hMk6nO_RD1K_GQu5WjIXQp6Q2e8", align 8
|
||||
%37 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store { ptr, ptr } %3, ptr %37, align 8
|
||||
%38 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %36, 0
|
||||
%39 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %38, ptr %37, 1
|
||||
%40 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %39)
|
||||
%41 = call ptr @reflect.Value.UnsafePointer(%reflect.Value %40)
|
||||
%42 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 16)
|
||||
%43 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.eface", ptr %42, i64 0
|
||||
%44 = load ptr, ptr @_llgo_Pointer, align 8
|
||||
%45 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %44, 0
|
||||
%46 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %45, ptr %41, 1
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.eface" %46, ptr %43, align 8
|
||||
%47 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %42, 0
|
||||
%48 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %47, i64 1, 1
|
||||
%49 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %48, i64 1, 2
|
||||
%50 = call { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @fmt.Println(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %49)
|
||||
%51 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/reflectfn.struct$b7Su1hWaFih-M0M9hMk6nO_RD1K_GQu5WjIXQp6Q2e8", align 8
|
||||
%52 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store { ptr, ptr } { ptr @"__llgo_stub.github.com/goplus/llgo/cl/_testgo/reflectfn.demo", ptr null }, ptr %52, align 8
|
||||
%53 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %51, 0
|
||||
%54 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %53, ptr %52, 1
|
||||
%55 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %54)
|
||||
%56 = call ptr @reflect.Value.UnsafePointer(%reflect.Value %55)
|
||||
%57 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 16)
|
||||
%58 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.eface", ptr %57, i64 0
|
||||
%59 = load ptr, ptr @_llgo_Pointer, align 8
|
||||
%60 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %59, 0
|
||||
%61 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %60, ptr %56, 1
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.eface" %61, ptr %58, align 8
|
||||
%62 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %57, 0
|
||||
%63 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %62, i64 1, 1
|
||||
%64 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %63, i64 1, 2
|
||||
%65 = call { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @fmt.Println(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %64)
|
||||
%66 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/reflectfn.struct$b7Su1hWaFih-M0M9hMk6nO_RD1K_GQu5WjIXQp6Q2e8", align 8
|
||||
%67 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store { ptr, ptr } { ptr @"__llgo_stub.github.com/goplus/llgo/cl/_testgo/reflectfn.demo", ptr null }, ptr %67, align 8
|
||||
%68 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %66, 0
|
||||
%69 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %68, ptr %67, 1
|
||||
%70 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %69)
|
||||
%71 = call ptr @reflect.Value.UnsafePointer(%reflect.Value %70)
|
||||
%72 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 16)
|
||||
%73 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.eface", ptr %72, i64 0
|
||||
%74 = load ptr, ptr @_llgo_Pointer, align 8
|
||||
%75 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %74, 0
|
||||
%76 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %75, ptr %71, 1
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.eface" %76, ptr %73, align 8
|
||||
%77 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %72, 0
|
||||
%78 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %77, i64 1, 1
|
||||
%79 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %78, i64 1, 2
|
||||
%80 = call { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @fmt.Println(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %79)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/reflectfn.main$1"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { ptr }, ptr %0, align 8
|
||||
%2 = extractvalue { ptr } %1, 0
|
||||
%3 = load i64, ptr %2, align 4
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %3)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
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 @fmt.init()
|
||||
|
||||
declare void @reflect.init()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64)
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/reflectfn.init$after"() {
|
||||
_llgo_0:
|
||||
%0 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%1 = icmp eq ptr %0, null
|
||||
br i1 %1, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
%3 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %2, 0
|
||||
%4 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %3, i64 0, 1
|
||||
%5 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %4, i64 0, 2
|
||||
%6 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %6, 0
|
||||
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %7, i64 0, 1
|
||||
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %8, i64 0, 2
|
||||
%10 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %5, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %9, i1 false)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %10)
|
||||
store ptr %10, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%11 = load ptr, ptr @_llgo_Pointer, align 8
|
||||
%12 = icmp eq ptr %11, null
|
||||
br i1 %12, label %_llgo_3, label %_llgo_4
|
||||
|
||||
_llgo_3: ; preds = %_llgo_2
|
||||
%13 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 58)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %13)
|
||||
store ptr %13, ptr @_llgo_Pointer, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%14 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
%15 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %14, 0
|
||||
%16 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %15, i64 0, 1
|
||||
%17 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %16, i64 0, 2
|
||||
%18 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
%19 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %18, 0
|
||||
%20 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %19, i64 0, 1
|
||||
%21 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %20, i64 0, 2
|
||||
%22 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %17, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %21, i1 false)
|
||||
%23 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 2 }, ptr %22, i64 0, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||
%24 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 58)
|
||||
%25 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 5 }, ptr %24, i64 8, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||
%26 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 112)
|
||||
%27 = getelementptr %"github.com/goplus/llgo/runtime/abi.StructField", ptr %26, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.StructField" %23, ptr %27, align 8
|
||||
%28 = getelementptr %"github.com/goplus/llgo/runtime/abi.StructField", ptr %26, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.StructField" %25, ptr %28, align 8
|
||||
%29 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %26, 0
|
||||
%30 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %29, i64 2, 1
|
||||
%31 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %30, i64 2, 2
|
||||
%32 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 43 }, i64 16, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %31)
|
||||
store ptr %32, ptr @"github.com/goplus/llgo/cl/_testgo/reflectfn.struct$b7Su1hWaFih-M0M9hMk6nO_RD1K_GQu5WjIXQp6Q2e8", align 8
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice", %"github.com/goplus/llgo/runtime/internal/runtime.Slice", i1)
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String", i64, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String", ptr, i64, %"github.com/goplus/llgo/runtime/internal/runtime.String", i1)
|
||||
|
||||
declare { i64, %"github.com/goplus/llgo/runtime/internal/runtime.iface" } @fmt.Println(%"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
define linkonce void @"__llgo_stub.github.com/goplus/llgo/cl/_testgo/reflectfn.demo"(ptr %0) {
|
||||
_llgo_0:
|
||||
tail call void @"github.com/goplus/llgo/cl/_testgo/reflectfn.demo"()
|
||||
ret void
|
||||
}
|
||||
|
||||
declare %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface")
|
||||
|
||||
declare ptr @reflect.Value.UnsafePointer(%reflect.Value)
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64)
|
||||
@@ -5,8 +5,8 @@ source_filename = "github.com/goplus/llgo/cl/_testgo/tpnamed"
|
||||
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
|
||||
%"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[error]" = type { ptr, ptr }
|
||||
%"github.com/goplus/llgo/runtime/internal/runtime.iface" = type { ptr, ptr }
|
||||
%"github.com/goplus/llgo/cl/_testgo/tpnamed.IO[[0]byte]" = type { ptr, ptr }
|
||||
%"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[[0]byte]" = type { ptr, ptr }
|
||||
%"github.com/goplus/llgo/cl/_testgo/tpnamed.IO[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" = type { ptr, ptr }
|
||||
%"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" = type { ptr, ptr }
|
||||
|
||||
@"github.com/goplus/llgo/cl/_testgo/tpnamed.init$guard" = global i1 false, align 1
|
||||
|
||||
@@ -40,13 +40,13 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/tpnamed.main"() {
|
||||
_llgo_0:
|
||||
%0 = call [0 x i8] @"github.com/goplus/llgo/cl/_testgo/tpnamed.RunIO[[0]byte]"(%"github.com/goplus/llgo/cl/_testgo/tpnamed.IO[[0]byte]" { ptr @"__llgo_stub.github.com/goplus/llgo/cl/_testgo/tpnamed.main$1", ptr null })
|
||||
%0 = call [0 x i8] @"github.com/goplus/llgo/cl/_testgo/tpnamed.RunIO[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]"(%"github.com/goplus/llgo/cl/_testgo/tpnamed.IO[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" { ptr @"__llgo_stub.github.com/goplus/llgo/cl/_testgo/tpnamed.main$1", ptr null })
|
||||
ret void
|
||||
}
|
||||
|
||||
define %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[[0]byte]" @"github.com/goplus/llgo/cl/_testgo/tpnamed.main$1"() {
|
||||
define %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" @"github.com/goplus/llgo/cl/_testgo/tpnamed.main$1"() {
|
||||
_llgo_0:
|
||||
ret %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[[0]byte]" { ptr @"__llgo_stub.github.com/goplus/llgo/cl/_testgo/tpnamed.main$1$1", ptr null }
|
||||
ret %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" { ptr @"__llgo_stub.github.com/goplus/llgo/cl/_testgo/tpnamed.main$1$1", ptr null }
|
||||
}
|
||||
|
||||
define [0 x i8] @"github.com/goplus/llgo/cl/_testgo/tpnamed.main$1$1"() {
|
||||
@@ -66,19 +66,19 @@ _llgo_0:
|
||||
ret %"github.com/goplus/llgo/runtime/internal/runtime.iface" %1
|
||||
}
|
||||
|
||||
define linkonce %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[[0]byte]" @"__llgo_stub.github.com/goplus/llgo/cl/_testgo/tpnamed.main$1"(ptr %0) {
|
||||
define linkonce %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" @"__llgo_stub.github.com/goplus/llgo/cl/_testgo/tpnamed.main$1"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = tail call %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[[0]byte]" @"github.com/goplus/llgo/cl/_testgo/tpnamed.main$1"()
|
||||
ret %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[[0]byte]" %1
|
||||
%1 = tail call %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" @"github.com/goplus/llgo/cl/_testgo/tpnamed.main$1"()
|
||||
ret %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" %1
|
||||
}
|
||||
|
||||
define linkonce [0 x i8] @"github.com/goplus/llgo/cl/_testgo/tpnamed.RunIO[[0]byte]"(%"github.com/goplus/llgo/cl/_testgo/tpnamed.IO[[0]byte]" %0) {
|
||||
define linkonce [0 x i8] @"github.com/goplus/llgo/cl/_testgo/tpnamed.RunIO[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]"(%"github.com/goplus/llgo/cl/_testgo/tpnamed.IO[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" %0) {
|
||||
_llgo_0:
|
||||
%1 = extractvalue %"github.com/goplus/llgo/cl/_testgo/tpnamed.IO[[0]byte]" %0, 1
|
||||
%2 = extractvalue %"github.com/goplus/llgo/cl/_testgo/tpnamed.IO[[0]byte]" %0, 0
|
||||
%3 = call %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[[0]byte]" %2(ptr %1)
|
||||
%4 = extractvalue %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[[0]byte]" %3, 1
|
||||
%5 = extractvalue %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[[0]byte]" %3, 0
|
||||
%1 = extractvalue %"github.com/goplus/llgo/cl/_testgo/tpnamed.IO[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" %0, 1
|
||||
%2 = extractvalue %"github.com/goplus/llgo/cl/_testgo/tpnamed.IO[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" %0, 0
|
||||
%3 = call %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" %2(ptr %1)
|
||||
%4 = extractvalue %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" %3, 1
|
||||
%5 = extractvalue %"github.com/goplus/llgo/cl/_testgo/tpnamed.Future[github.com/goplus/llgo/cl/_testgo/tpnamed.Void]" %3, 0
|
||||
%6 = call [0 x i8] %5(ptr %4)
|
||||
ret [0 x i8] %6
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@ source_filename = "github.com/goplus/llgo/cl/_testrt/any"
|
||||
@"github.com/goplus/llgo/cl/_testrt/any.init$guard" = global i1 false, align 1
|
||||
@_llgo_int8 = linkonce global ptr null, align 8
|
||||
@"*_llgo_int8" = linkonce global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [34 x i8] c"type assertion any -> *int8 failed", align 1
|
||||
@0 = private unnamed_addr constant [58 x i8] c"type assertion any -> *github.com/goplus/lib/c.Char failed", align 1
|
||||
@_llgo_string = linkonce global ptr null, align 8
|
||||
@_llgo_int = linkonce global ptr null, align 8
|
||||
@1 = private unnamed_addr constant [32 x i8] c"type assertion any -> int failed", align 1
|
||||
@@ -29,7 +29,7 @@ _llgo_1: ; preds = %_llgo_0
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
%6 = load ptr, ptr @_llgo_string, align 8
|
||||
%7 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 34 }, ptr %7, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 58 }, ptr %7, align 8
|
||||
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %6, 0
|
||||
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %8, ptr %7, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %9)
|
||||
|
||||
25
cl/_testrt/closurebound/in.go
Normal file
25
cl/_testrt/closurebound/in.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
se := demo1{}
|
||||
f := se.encode
|
||||
if f() != 1 {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
var my = demo2{}.encode
|
||||
|
||||
type demo1 struct {
|
||||
}
|
||||
|
||||
func (se demo1) encode() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
type demo2 struct {
|
||||
}
|
||||
|
||||
func (se demo2) encode() int {
|
||||
return 2
|
||||
}
|
||||
117
cl/_testrt/closurebound/out.ll
Normal file
117
cl/_testrt/closurebound/out.ll
Normal file
@@ -0,0 +1,117 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/cl/_testrt/closurebound'
|
||||
source_filename = "github.com/goplus/llgo/cl/_testrt/closurebound"
|
||||
|
||||
%"github.com/goplus/llgo/cl/_testrt/closurebound.demo1" = type {}
|
||||
%"github.com/goplus/llgo/cl/_testrt/closurebound.demo2" = type {}
|
||||
%"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/_testrt/closurebound.init$guard" = global i1 false, align 1
|
||||
@"github.com/goplus/llgo/cl/_testrt/closurebound.my" = global { ptr, ptr } zeroinitializer, align 8
|
||||
@0 = private unnamed_addr constant [5 x i8] c"error", align 1
|
||||
@_llgo_string = linkonce global ptr null, align 8
|
||||
|
||||
define i64 @"github.com/goplus/llgo/cl/_testrt/closurebound.demo1.encode"(%"github.com/goplus/llgo/cl/_testrt/closurebound.demo1" %0) {
|
||||
_llgo_0:
|
||||
ret i64 1
|
||||
}
|
||||
|
||||
define i64 @"github.com/goplus/llgo/cl/_testrt/closurebound.(*demo1).encode"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load %"github.com/goplus/llgo/cl/_testrt/closurebound.demo1", ptr %0, align 1
|
||||
%2 = call i64 @"github.com/goplus/llgo/cl/_testrt/closurebound.demo1.encode"(%"github.com/goplus/llgo/cl/_testrt/closurebound.demo1" %1)
|
||||
ret i64 %2
|
||||
}
|
||||
|
||||
define i64 @"github.com/goplus/llgo/cl/_testrt/closurebound.demo2.encode"(%"github.com/goplus/llgo/cl/_testrt/closurebound.demo2" %0) {
|
||||
_llgo_0:
|
||||
ret i64 2
|
||||
}
|
||||
|
||||
define i64 @"github.com/goplus/llgo/cl/_testrt/closurebound.(*demo2).encode"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load %"github.com/goplus/llgo/cl/_testrt/closurebound.demo2", ptr %0, align 1
|
||||
%2 = call i64 @"github.com/goplus/llgo/cl/_testrt/closurebound.demo2.encode"(%"github.com/goplus/llgo/cl/_testrt/closurebound.demo2" %1)
|
||||
ret i64 %2
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testrt/closurebound.init"() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testrt/closurebound.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/_testrt/closurebound.init$guard", align 1
|
||||
call void @"github.com/goplus/llgo/cl/_testrt/closurebound.init$after"()
|
||||
%1 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
%2 = getelementptr inbounds { %"github.com/goplus/llgo/cl/_testrt/closurebound.demo2" }, ptr %1, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/cl/_testrt/closurebound.demo2" zeroinitializer, ptr %2, align 1
|
||||
%3 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testrt/closurebound.demo2.encode$bound", ptr undef }, ptr %1, 1
|
||||
store { ptr, ptr } %3, ptr @"github.com/goplus/llgo/cl/_testrt/closurebound.my", align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testrt/closurebound.main"() {
|
||||
_llgo_0:
|
||||
%0 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
%1 = getelementptr inbounds { %"github.com/goplus/llgo/cl/_testrt/closurebound.demo1" }, ptr %0, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/cl/_testrt/closurebound.demo1" zeroinitializer, ptr %1, align 1
|
||||
%2 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testrt/closurebound.demo1.encode$bound", ptr undef }, ptr %0, 1
|
||||
%3 = extractvalue { ptr, ptr } %2, 1
|
||||
%4 = extractvalue { ptr, ptr } %2, 0
|
||||
%5 = call i64 %4(ptr %3)
|
||||
%6 = icmp ne i64 %5, 1
|
||||
br i1 %6, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%7 = load ptr, ptr @_llgo_string, align 8
|
||||
%8 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 5 }, ptr %8, align 8
|
||||
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %7, 0
|
||||
%10 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %9, ptr %8, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %10)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i64 @"github.com/goplus/llgo/cl/_testrt/closurebound.demo2.encode$bound"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { %"github.com/goplus/llgo/cl/_testrt/closurebound.demo2" }, ptr %0, align 1
|
||||
%2 = extractvalue { %"github.com/goplus/llgo/cl/_testrt/closurebound.demo2" } %1, 0
|
||||
%3 = call i64 @"github.com/goplus/llgo/cl/_testrt/closurebound.demo2.encode"(%"github.com/goplus/llgo/cl/_testrt/closurebound.demo2" %2)
|
||||
ret i64 %3
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64)
|
||||
|
||||
define i64 @"github.com/goplus/llgo/cl/_testrt/closurebound.demo1.encode$bound"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { %"github.com/goplus/llgo/cl/_testrt/closurebound.demo1" }, ptr %0, align 1
|
||||
%2 = extractvalue { %"github.com/goplus/llgo/cl/_testrt/closurebound.demo1" } %1, 0
|
||||
%3 = call i64 @"github.com/goplus/llgo/cl/_testrt/closurebound.demo1.encode"(%"github.com/goplus/llgo/cl/_testrt/closurebound.demo1" %2)
|
||||
ret i64 %3
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testrt/closurebound.init$after"() {
|
||||
_llgo_0:
|
||||
%0 = load ptr, ptr @_llgo_string, align 8
|
||||
%1 = icmp eq ptr %0, null
|
||||
br i1 %1, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 24)
|
||||
store ptr %2, ptr @_llgo_string, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface")
|
||||
@@ -29,7 +29,7 @@ _llgo_0:
|
||||
%3 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 8)
|
||||
%4 = getelementptr inbounds { ptr }, ptr %3, i32 0, i32 0
|
||||
store ptr %1, ptr %4, align 8
|
||||
%5 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testrt/closureconv.add$bound", ptr undef }, ptr %3, 1
|
||||
%5 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testrt/closureconv.(*Call).add$bound", ptr undef }, ptr %3, 1
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testrt/closureconv.Call", ptr %1, i32 0, i32 0
|
||||
%7 = alloca %"github.com/goplus/llgo/cl/_testrt/closureconv.Func", align 8
|
||||
store { ptr, ptr } %5, ptr %7, align 8
|
||||
@@ -46,7 +46,7 @@ _llgo_0:
|
||||
%1 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 8)
|
||||
%2 = getelementptr inbounds { ptr }, ptr %1, i32 0, i32 0
|
||||
store ptr %0, ptr %2, align 8
|
||||
%3 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testrt/closureconv.add$bound", ptr undef }, ptr %1, 1
|
||||
%3 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testrt/closureconv.(*Call).add$bound", ptr undef }, ptr %1, 1
|
||||
%4 = alloca %"github.com/goplus/llgo/cl/_testrt/closureconv.Func", align 8
|
||||
store { ptr, ptr } %3, ptr %4, align 8
|
||||
%5 = load %"github.com/goplus/llgo/cl/_testrt/closureconv.Func", ptr %4, align 8
|
||||
@@ -158,7 +158,7 @@ _llgo_0:
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
|
||||
|
||||
define i64 @"github.com/goplus/llgo/cl/_testrt/closureconv.add$bound"(ptr %0, i64 %1, i64 %2) {
|
||||
define i64 @"github.com/goplus/llgo/cl/_testrt/closureconv.(*Call).add$bound"(ptr %0, i64 %1, i64 %2) {
|
||||
_llgo_0:
|
||||
%3 = load { ptr }, ptr %0, align 8
|
||||
%4 = extractvalue { ptr } %3, 0
|
||||
|
||||
@@ -124,7 +124,7 @@ _llgo_6: ; preds = %_llgo_4
|
||||
%32 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 8)
|
||||
%33 = getelementptr inbounds { ptr }, ptr %32, i32 0, i32 0
|
||||
store ptr %30, ptr %33, align 8
|
||||
%34 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testrt/intgen.next$bound", ptr undef }, ptr %32, 1
|
||||
%34 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testrt/intgen.(*generator).next$bound", ptr undef }, ptr %32, 1
|
||||
%35 = call %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @"github.com/goplus/llgo/cl/_testrt/intgen.genInts"(i64 5, { ptr, ptr } %34)
|
||||
%36 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %35, 1
|
||||
br label %_llgo_7
|
||||
@@ -182,7 +182,7 @@ declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64)
|
||||
|
||||
define i32 @"github.com/goplus/llgo/cl/_testrt/intgen.next$bound"(ptr %0) {
|
||||
define i32 @"github.com/goplus/llgo/cl/_testrt/intgen.(*generator).next$bound"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { ptr }, ptr %0, align 8
|
||||
%2 = extractvalue { ptr } %1, 0
|
||||
|
||||
@@ -402,6 +402,10 @@ func funcName(pkg *types.Package, fn *ssa.Function, org bool) string {
|
||||
recv = parent.Signature.Recv()
|
||||
} else {
|
||||
recv = fn.Signature.Recv()
|
||||
// check $bound
|
||||
if recv == nil && strings.HasSuffix(fn.Name(), "$bound") && len(fn.FreeVars) == 1 {
|
||||
recv = types.NewVar(token.NoPos, nil, "", fn.FreeVars[0].Type())
|
||||
}
|
||||
}
|
||||
var fnName string
|
||||
if org := fn.Origin(); org != nil {
|
||||
|
||||
82
cmd/internal/base/pass.go
Normal file
82
cmd/internal/base/pass.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type stringValue struct {
|
||||
p *PassArgs
|
||||
name string
|
||||
}
|
||||
|
||||
func (p *stringValue) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p *stringValue) Set(v string) error {
|
||||
p.p.Args = append(p.p.Args, fmt.Sprintf("-%v=%v", p.name, v))
|
||||
return nil
|
||||
}
|
||||
|
||||
type boolValue struct {
|
||||
p *PassArgs
|
||||
name string
|
||||
}
|
||||
|
||||
func (p *boolValue) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p *boolValue) Set(v string) error {
|
||||
p.p.Args = append(p.p.Args, fmt.Sprintf("-%v=%v", p.name, v))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *boolValue) IsBoolFlag() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type PassArgs struct {
|
||||
Args []string
|
||||
Flag *flag.FlagSet
|
||||
}
|
||||
|
||||
func (p *PassArgs) Tags() string {
|
||||
for _, v := range p.Args {
|
||||
if strings.HasPrefix(v, "-tags=") {
|
||||
return v[6:]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p *PassArgs) Var(names ...string) {
|
||||
for _, name := range names {
|
||||
p.Flag.Var(&stringValue{p: p, name: name}, name, "")
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PassArgs) Bool(names ...string) {
|
||||
for _, name := range names {
|
||||
p.Flag.Var(&boolValue{p: p, name: name}, name, "")
|
||||
}
|
||||
}
|
||||
|
||||
func NewPassArgs(flag *flag.FlagSet) *PassArgs {
|
||||
p := &PassArgs{Flag: flag}
|
||||
return p
|
||||
}
|
||||
|
||||
func PassBuildFlags(cmd *Command) *PassArgs {
|
||||
p := NewPassArgs(&cmd.Flag)
|
||||
p.Bool("n", "x")
|
||||
p.Bool("a")
|
||||
p.Bool("linkshared", "race", "msan", "asan",
|
||||
"trimpath", "work")
|
||||
p.Var("p", "asmflags", "compiler", "buildmode",
|
||||
"gcflags", "gccgoflags", "installsuffix",
|
||||
"ldflags", "pkgdir", "toolexec", "buildvcs")
|
||||
return p
|
||||
}
|
||||
@@ -35,13 +35,15 @@ var Cmd = &base.Command{
|
||||
|
||||
func init() {
|
||||
Cmd.Run = runCmd
|
||||
base.PassBuildFlags(Cmd)
|
||||
flags.AddBuildFlags(&Cmd.Flag)
|
||||
flags.AddOutputFlags(&Cmd.Flag)
|
||||
}
|
||||
|
||||
func runCmd(cmd *base.Command, args []string) {
|
||||
|
||||
if err := cmd.Flag.Parse(args); err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
|
||||
conf := build.NewDefaultConf(build.ModeBuild)
|
||||
|
||||
@@ -35,8 +35,9 @@ func init() {
|
||||
}
|
||||
|
||||
func runCmd(cmd *base.Command, args []string) {
|
||||
|
||||
if err := cmd.Flag.Parse(args); err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
|
||||
conf := build.NewDefaultConf(0)
|
||||
|
||||
@@ -39,8 +39,9 @@ func init() {
|
||||
}
|
||||
|
||||
func runCmd(cmd *base.Command, args []string) {
|
||||
|
||||
if err := cmd.Flag.Parse(args); err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
|
||||
conf := build.NewDefaultConf(build.ModeInstall)
|
||||
|
||||
@@ -47,6 +47,7 @@ var CmpTestCmd = &base.Command{
|
||||
func init() {
|
||||
Cmd.Run = runCmd
|
||||
CmpTestCmd.Run = runCmpTest
|
||||
base.PassBuildFlags(Cmd)
|
||||
flags.AddBuildFlags(&Cmd.Flag)
|
||||
flags.AddBuildFlags(&CmpTestCmd.Flag)
|
||||
flags.AddCmpTestFlags(&CmpTestCmd.Flag)
|
||||
@@ -61,8 +62,9 @@ func runCmpTest(cmd *base.Command, args []string) {
|
||||
}
|
||||
|
||||
func runCmdEx(cmd *base.Command, args []string, mode build.Mode) {
|
||||
|
||||
if err := cmd.Flag.Parse(args); err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
|
||||
conf := build.NewDefaultConf(mode)
|
||||
|
||||
@@ -21,8 +21,9 @@ func init() {
|
||||
}
|
||||
|
||||
func runCmd(cmd *base.Command, args []string) {
|
||||
|
||||
if err := cmd.Flag.Parse(args); err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
|
||||
conf := build.NewDefaultConf(build.ModeTest)
|
||||
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
self "github.com/goplus/llgo/cmd/internal/build"
|
||||
)
|
||||
|
||||
use "build [flags] [packages]"
|
||||
|
||||
short "Compile packages and dependencies"
|
||||
|
||||
flagOff
|
||||
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
self "github.com/goplus/llgo/cmd/internal/clean"
|
||||
)
|
||||
|
||||
use "clean [flags] [packages]"
|
||||
|
||||
short "Remove object files and cached files"
|
||||
|
||||
flagOff
|
||||
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
self "github.com/goplus/llgo/cmd/internal/run"
|
||||
)
|
||||
|
||||
use "cmptest [flags] package [arguments...]"
|
||||
|
||||
short "Compile and run with llgo, compare result (stdout/stderr/exitcode) with go or llgo.expect; generate llgo.expect file if -gen is specified"
|
||||
|
||||
flagOff
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
short "Manage C/C++ packages"
|
||||
|
||||
run => {
|
||||
help
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
self "github.com/goplus/llgo/xtool/cppkg"
|
||||
)
|
||||
|
||||
short "Install a C/C++ package from github.com/goplus/cppkg"
|
||||
|
||||
long `Installs a C/C++ package with the given name and version. For example:
|
||||
|
||||
llgo cppkg install davegamble/cjson@1.7.18
|
||||
llgo cppkg install davegamble/cjson@latest
|
||||
llgo cppkg install davegamble/cjson
|
||||
`
|
||||
|
||||
run args => {
|
||||
if args.len < 1 {
|
||||
help
|
||||
return
|
||||
}
|
||||
|
||||
self.install args[0], self.DefaultFlags
|
||||
}
|
||||
@@ -13,6 +13,8 @@
|
||||
* See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
use "get [flags] [packages]"
|
||||
|
||||
short "Add dependencies to current module and install them"
|
||||
|
||||
run args => {
|
||||
|
||||
@@ -5,243 +5,209 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/goplus/cobra/xcmd"
|
||||
build1 "github.com/goplus/llgo/cmd/internal/build"
|
||||
clean1 "github.com/goplus/llgo/cmd/internal/clean"
|
||||
install1 "github.com/goplus/llgo/cmd/internal/install"
|
||||
run1 "github.com/goplus/llgo/cmd/internal/run"
|
||||
test1 "github.com/goplus/llgo/cmd/internal/test"
|
||||
"github.com/goplus/llgo/cmd/internal/build"
|
||||
"github.com/goplus/llgo/cmd/internal/clean"
|
||||
"github.com/goplus/llgo/cmd/internal/install"
|
||||
"github.com/goplus/llgo/cmd/internal/run"
|
||||
"github.com/goplus/llgo/cmd/internal/test"
|
||||
"github.com/goplus/llgo/internal/env"
|
||||
cppkg1 "github.com/goplus/llgo/xtool/cppkg"
|
||||
"github.com/qiniu/x/stringutil"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
const _ = true
|
||||
|
||||
type build struct {
|
||||
type Cmd_build struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type clean struct {
|
||||
type Cmd_clean struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type cmptest struct {
|
||||
type Cmd_cmptest struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type cppkg struct {
|
||||
type Cmd_get struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type cppkg_install struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type get struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type install struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type run struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type test struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type version struct {
|
||||
type Cmd_install struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type App struct {
|
||||
xcmd.App
|
||||
}
|
||||
|
||||
type Cmd_run struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type Cmd_test struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
type Cmd_version struct {
|
||||
xcmd.Command
|
||||
*App
|
||||
}
|
||||
//line cmd/llgo/main_app.gox:1
|
||||
func (this *App) MainEntry() {
|
||||
//line cmd/llgo/main_app.gox:1:1
|
||||
this.Short(`llgo is a Go compiler based on LLVM in order to better integrate Go with the C ecosystem including Python.`)
|
||||
}
|
||||
func (this *App) Main() {
|
||||
_gop_obj0 := &build{App: this}
|
||||
_gop_obj1 := &clean{App: this}
|
||||
_gop_obj2 := &cmptest{App: this}
|
||||
_gop_obj3 := &cppkg{App: this}
|
||||
_gop_obj4 := &cppkg_install{App: this}
|
||||
_gop_obj5 := &get{App: this}
|
||||
_gop_obj6 := &install{App: this}
|
||||
_gop_obj7 := &run{App: this}
|
||||
_gop_obj8 := &test{App: this}
|
||||
_gop_obj9 := &version{App: this}
|
||||
xcmd.Gopt_App_Main(this, _gop_obj0, _gop_obj1, _gop_obj2, _gop_obj3, _gop_obj4, _gop_obj5, _gop_obj6, _gop_obj7, _gop_obj8, _gop_obj9)
|
||||
_gop_obj0 := &Cmd_build{App: this}
|
||||
_gop_obj1 := &Cmd_clean{App: this}
|
||||
_gop_obj2 := &Cmd_cmptest{App: this}
|
||||
_gop_obj3 := &Cmd_get{App: this}
|
||||
_gop_obj4 := &Cmd_install{App: this}
|
||||
_gop_obj5 := &Cmd_run{App: this}
|
||||
_gop_obj6 := &Cmd_test{App: this}
|
||||
_gop_obj7 := &Cmd_version{App: this}
|
||||
xcmd.Gopt_App_Main(this, _gop_obj0, _gop_obj1, _gop_obj2, _gop_obj3, _gop_obj4, _gop_obj5, _gop_obj6, _gop_obj7)
|
||||
}
|
||||
//line cmd/llgo/build_cmd.gox:20
|
||||
func (this *build) Main(_gop_arg0 string) {
|
||||
func (this *Cmd_build) Main(_gop_arg0 string) {
|
||||
this.Command.Main(_gop_arg0)
|
||||
//line cmd/llgo/build_cmd.gox:20:1
|
||||
this.Short("Compile packages and dependencies")
|
||||
this.Use("build [flags] [packages]")
|
||||
//line cmd/llgo/build_cmd.gox:22:1
|
||||
this.FlagOff()
|
||||
this.Short("Compile packages and dependencies")
|
||||
//line cmd/llgo/build_cmd.gox:24:1
|
||||
this.FlagOff()
|
||||
//line cmd/llgo/build_cmd.gox:26:1
|
||||
this.Run__1(func(args []string) {
|
||||
//line cmd/llgo/build_cmd.gox:25:1
|
||||
build1.Cmd.Run(build1.Cmd, args)
|
||||
//line cmd/llgo/build_cmd.gox:27:1
|
||||
build.Cmd.Run(build.Cmd, args)
|
||||
})
|
||||
}
|
||||
func (this *build) Classfname() string {
|
||||
func (this *Cmd_build) Classfname() string {
|
||||
return "build"
|
||||
}
|
||||
//line cmd/llgo/clean_cmd.gox:20
|
||||
func (this *clean) Main(_gop_arg0 string) {
|
||||
func (this *Cmd_clean) Main(_gop_arg0 string) {
|
||||
this.Command.Main(_gop_arg0)
|
||||
//line cmd/llgo/clean_cmd.gox:20:1
|
||||
this.Short("Remove object files and cached files")
|
||||
this.Use("clean [flags] [packages]")
|
||||
//line cmd/llgo/clean_cmd.gox:22:1
|
||||
this.FlagOff()
|
||||
this.Short("Remove object files and cached files")
|
||||
//line cmd/llgo/clean_cmd.gox:24:1
|
||||
this.FlagOff()
|
||||
//line cmd/llgo/clean_cmd.gox:26:1
|
||||
this.Run__1(func(args []string) {
|
||||
//line cmd/llgo/clean_cmd.gox:25:1
|
||||
clean1.Cmd.Run(clean1.Cmd, args)
|
||||
//line cmd/llgo/clean_cmd.gox:27:1
|
||||
clean.Cmd.Run(clean.Cmd, args)
|
||||
})
|
||||
}
|
||||
func (this *clean) Classfname() string {
|
||||
func (this *Cmd_clean) Classfname() string {
|
||||
return "clean"
|
||||
}
|
||||
//line cmd/llgo/cmptest_cmd.gox:20
|
||||
func (this *cmptest) Main(_gop_arg0 string) {
|
||||
func (this *Cmd_cmptest) Main(_gop_arg0 string) {
|
||||
this.Command.Main(_gop_arg0)
|
||||
//line cmd/llgo/cmptest_cmd.gox:20:1
|
||||
this.Short("Compile and run with llgo, compare result (stdout/stderr/exitcode) with go or llgo.expect; generate llgo.expect file if -gen is specified")
|
||||
this.Use("cmptest [flags] package [arguments...]")
|
||||
//line cmd/llgo/cmptest_cmd.gox:22:1
|
||||
this.FlagOff()
|
||||
this.Short("Compile and run with llgo, compare result (stdout/stderr/exitcode) with go or llgo.expect; generate llgo.expect file if -gen is specified")
|
||||
//line cmd/llgo/cmptest_cmd.gox:24:1
|
||||
this.FlagOff()
|
||||
//line cmd/llgo/cmptest_cmd.gox:26:1
|
||||
this.Run__1(func(args []string) {
|
||||
//line cmd/llgo/cmptest_cmd.gox:25:1
|
||||
run1.CmpTestCmd.Run(run1.CmpTestCmd, args)
|
||||
//line cmd/llgo/cmptest_cmd.gox:27:1
|
||||
run.CmpTestCmd.Run(run.CmpTestCmd, args)
|
||||
})
|
||||
}
|
||||
func (this *cmptest) Classfname() string {
|
||||
func (this *Cmd_cmptest) Classfname() string {
|
||||
return "cmptest"
|
||||
}
|
||||
//line cmd/llgo/cppkg_cmd.gox:16
|
||||
func (this *cppkg) Main(_gop_arg0 string) {
|
||||
this.Command.Main(_gop_arg0)
|
||||
//line cmd/llgo/cppkg_cmd.gox:16:1
|
||||
this.Short("Manage C/C++ packages")
|
||||
//line cmd/llgo/cppkg_cmd.gox:18:1
|
||||
this.Run__0(func() {
|
||||
//line cmd/llgo/cppkg_cmd.gox:19:1
|
||||
this.Help()
|
||||
})
|
||||
}
|
||||
func (this *cppkg) Classfname() string {
|
||||
return "cppkg"
|
||||
}
|
||||
//line cmd/llgo/cppkg_install_cmd.gox:20
|
||||
func (this *cppkg_install) Main(_gop_arg0 string) {
|
||||
this.Command.Main(_gop_arg0)
|
||||
//line cmd/llgo/cppkg_install_cmd.gox:20:1
|
||||
this.Short("Install a C/C++ package from github.com/goplus/cppkg")
|
||||
//line cmd/llgo/cppkg_install_cmd.gox:22:1
|
||||
this.Long(`Installs a C/C++ package with the given name and version. For example:
|
||||
|
||||
llgo cppkg install davegamble/cjson@1.7.18
|
||||
llgo cppkg install davegamble/cjson@latest
|
||||
llgo cppkg install davegamble/cjson
|
||||
`)
|
||||
//line cmd/llgo/cppkg_install_cmd.gox:29:1
|
||||
this.Run__1(func(args []string) {
|
||||
//line cmd/llgo/cppkg_install_cmd.gox:30:1
|
||||
if len(args) < 1 {
|
||||
//line cmd/llgo/cppkg_install_cmd.gox:31:1
|
||||
this.Help()
|
||||
//line cmd/llgo/cppkg_install_cmd.gox:32:1
|
||||
return
|
||||
}
|
||||
//line cmd/llgo/cppkg_install_cmd.gox:35:1
|
||||
cppkg1.Install(args[0], cppkg1.DefaultFlags)
|
||||
})
|
||||
}
|
||||
func (this *cppkg_install) Classfname() string {
|
||||
return "cppkg_install"
|
||||
}
|
||||
//line cmd/llgo/get_cmd.gox:16
|
||||
func (this *get) Main(_gop_arg0 string) {
|
||||
func (this *Cmd_get) Main(_gop_arg0 string) {
|
||||
this.Command.Main(_gop_arg0)
|
||||
//line cmd/llgo/get_cmd.gox:16:1
|
||||
this.Short("Add dependencies to current module and install them")
|
||||
this.Use("get [flags] [packages]")
|
||||
//line cmd/llgo/get_cmd.gox:18:1
|
||||
this.Short("Add dependencies to current module and install them")
|
||||
//line cmd/llgo/get_cmd.gox:20:1
|
||||
this.Run__1(func(args []string) {
|
||||
//line cmd/llgo/get_cmd.gox:19:1
|
||||
//line cmd/llgo/get_cmd.gox:21:1
|
||||
panic("todo")
|
||||
})
|
||||
}
|
||||
func (this *get) Classfname() string {
|
||||
func (this *Cmd_get) Classfname() string {
|
||||
return "get"
|
||||
}
|
||||
//line cmd/llgo/install_cmd.gox:20
|
||||
func (this *install) Main(_gop_arg0 string) {
|
||||
func (this *Cmd_install) Main(_gop_arg0 string) {
|
||||
this.Command.Main(_gop_arg0)
|
||||
//line cmd/llgo/install_cmd.gox:20:1
|
||||
this.Short("Compile and install packages and dependencies")
|
||||
this.Use("install [flags] [packages]")
|
||||
//line cmd/llgo/install_cmd.gox:22:1
|
||||
this.FlagOff()
|
||||
this.Short("Compile and install packages and dependencies")
|
||||
//line cmd/llgo/install_cmd.gox:24:1
|
||||
this.FlagOff()
|
||||
//line cmd/llgo/install_cmd.gox:26:1
|
||||
this.Run__1(func(args []string) {
|
||||
//line cmd/llgo/install_cmd.gox:25:1
|
||||
install1.Cmd.Run(install1.Cmd, args)
|
||||
//line cmd/llgo/install_cmd.gox:27:1
|
||||
install.Cmd.Run(install.Cmd, args)
|
||||
})
|
||||
}
|
||||
func (this *install) Classfname() string {
|
||||
func (this *Cmd_install) Classfname() string {
|
||||
return "install"
|
||||
}
|
||||
//line cmd/llgo/run_cmd.gox:20
|
||||
func (this *run) Main(_gop_arg0 string) {
|
||||
func (this *Cmd_run) Main(_gop_arg0 string) {
|
||||
this.Command.Main(_gop_arg0)
|
||||
//line cmd/llgo/run_cmd.gox:20:1
|
||||
this.Short("Compile and run Go program")
|
||||
this.Use("run [flags] package [arguments...]")
|
||||
//line cmd/llgo/run_cmd.gox:22:1
|
||||
this.FlagOff()
|
||||
this.Short("Compile and run Go program")
|
||||
//line cmd/llgo/run_cmd.gox:24:1
|
||||
this.FlagOff()
|
||||
//line cmd/llgo/run_cmd.gox:26:1
|
||||
this.Run__1(func(args []string) {
|
||||
//line cmd/llgo/run_cmd.gox:25:1
|
||||
run1.Cmd.Run(run1.Cmd, args)
|
||||
//line cmd/llgo/run_cmd.gox:27:1
|
||||
run.Cmd.Run(run.Cmd, args)
|
||||
})
|
||||
}
|
||||
func (this *run) Classfname() string {
|
||||
func (this *Cmd_run) Classfname() string {
|
||||
return "run"
|
||||
}
|
||||
//line cmd/llgo/test_cmd.gox:20
|
||||
func (this *test) Main(_gop_arg0 string) {
|
||||
func (this *Cmd_test) Main(_gop_arg0 string) {
|
||||
this.Command.Main(_gop_arg0)
|
||||
//line cmd/llgo/test_cmd.gox:20:1
|
||||
this.Short("Compile and run Go test")
|
||||
this.Use("test [flags] package [arguments...]")
|
||||
//line cmd/llgo/test_cmd.gox:22:1
|
||||
this.FlagOff()
|
||||
this.Short("Compile and run Go test")
|
||||
//line cmd/llgo/test_cmd.gox:24:1
|
||||
this.FlagOff()
|
||||
//line cmd/llgo/test_cmd.gox:26:1
|
||||
this.Run__1(func(args []string) {
|
||||
//line cmd/llgo/test_cmd.gox:25:1
|
||||
test1.Cmd.Run(test1.Cmd, args)
|
||||
//line cmd/llgo/test_cmd.gox:27:1
|
||||
test.Cmd.Run(test.Cmd, args)
|
||||
})
|
||||
}
|
||||
func (this *test) Classfname() string {
|
||||
func (this *Cmd_test) Classfname() string {
|
||||
return "test"
|
||||
}
|
||||
//line cmd/llgo/version_cmd.gox:22
|
||||
func (this *version) Main(_gop_arg0 string) {
|
||||
func (this *Cmd_version) Main(_gop_arg0 string) {
|
||||
this.Command.Main(_gop_arg0)
|
||||
//line cmd/llgo/version_cmd.gox:22:1
|
||||
this.Short("Print LLGo version")
|
||||
this.Use("version")
|
||||
//line cmd/llgo/version_cmd.gox:24:1
|
||||
this.Short("Print LLGo version")
|
||||
//line cmd/llgo/version_cmd.gox:26:1
|
||||
this.Run__0(func() {
|
||||
//line cmd/llgo/version_cmd.gox:25:1
|
||||
//line cmd/llgo/version_cmd.gox:27:1
|
||||
fmt.Println(stringutil.Concat("llgo ", env.Version(), " ", runtime.GOOS, "/", runtime.GOARCH))
|
||||
})
|
||||
}
|
||||
func (this *version) Classfname() string {
|
||||
func (this *Cmd_version) Classfname() string {
|
||||
return "version"
|
||||
}
|
||||
func main() {
|
||||
//line cmd/llgo/version_cmd.gox:24:1
|
||||
new(App).Main()
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
self "github.com/goplus/llgo/cmd/internal/install"
|
||||
)
|
||||
|
||||
use "install [flags] [packages]"
|
||||
|
||||
short "Compile and install packages and dependencies"
|
||||
|
||||
flagOff
|
||||
|
||||
1
cmd/llgo/main_app.gox
Normal file
1
cmd/llgo/main_app.gox
Normal file
@@ -0,0 +1 @@
|
||||
short `llgo is a Go compiler based on LLVM in order to better integrate Go with the C ecosystem including Python.`
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
self "github.com/goplus/llgo/cmd/internal/run"
|
||||
)
|
||||
|
||||
use "run [flags] package [arguments...]"
|
||||
|
||||
short "Compile and run Go program"
|
||||
|
||||
flagOff
|
||||
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
self "github.com/goplus/llgo/cmd/internal/test"
|
||||
)
|
||||
|
||||
use "test [flags] package [arguments...]"
|
||||
|
||||
short "Compile and run Go test"
|
||||
|
||||
flagOff
|
||||
|
||||
@@ -19,6 +19,8 @@ import (
|
||||
"github.com/goplus/llgo/internal/env"
|
||||
)
|
||||
|
||||
use "version"
|
||||
|
||||
short "Print LLGo version"
|
||||
|
||||
run => {
|
||||
|
||||
17
go.mod
17
go.mod
@@ -1,22 +1,23 @@
|
||||
module github.com/goplus/llgo
|
||||
|
||||
go 1.22.0
|
||||
go 1.23
|
||||
|
||||
toolchain go1.24.1
|
||||
|
||||
require (
|
||||
github.com/goccy/go-yaml v1.17.1
|
||||
github.com/goplus/cobra v1.9.8 //gop:class
|
||||
github.com/goplus/gogen v1.17.3
|
||||
github.com/goplus/cobra v1.9.12 //gop:class
|
||||
github.com/goplus/gogen v1.18.1
|
||||
github.com/goplus/lib v0.2.0
|
||||
github.com/goplus/llgo/runtime v0.0.0-00010101000000-000000000000
|
||||
github.com/goplus/llvm v0.8.3
|
||||
github.com/goplus/mod v0.16.0
|
||||
github.com/qiniu/x v1.13.19
|
||||
golang.org/x/mod v0.23.0
|
||||
github.com/goplus/mod v0.16.1
|
||||
github.com/qiniu/x v1.14.6
|
||||
golang.org/x/tools v0.30.0
|
||||
)
|
||||
|
||||
require golang.org/x/sync v0.11.0 // indirect
|
||||
require (
|
||||
golang.org/x/mod v0.23.0 // indirect
|
||||
golang.org/x/sync v0.11.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/goplus/llgo/runtime => ./runtime
|
||||
|
||||
18
go.sum
18
go.sum
@@ -1,19 +1,17 @@
|
||||
github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY=
|
||||
github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/goplus/cobra v1.9.8 h1:4ZvhxUepT35vreZdxjl/bwnJdwhWyWCGnc60+v22x14=
|
||||
github.com/goplus/cobra v1.9.8/go.mod h1:p4LhfNJDKEpiGjGiNn0crUXL5dUPA5DX2ztYpEJR34E=
|
||||
github.com/goplus/gogen v1.17.3 h1:Xhoj2KQw4feRdPEtOYjTUe9lSvNIoxBG4urhdjf+fUg=
|
||||
github.com/goplus/gogen v1.17.3/go.mod h1:owX2e1EyU5WD+Nm6oH2m/GXjLdlBYcwkLO4wN8HHXZI=
|
||||
github.com/goplus/cobra v1.9.12 h1:0F9EdEbeGyITGz+mqoHoJ5KpUw97p1CkxV74IexHw5s=
|
||||
github.com/goplus/cobra v1.9.12/go.mod h1:p4LhfNJDKEpiGjGiNn0crUXL5dUPA5DX2ztYpEJR34E=
|
||||
github.com/goplus/gogen v1.18.1 h1:ys18IiQwQ4QeQ3Mmk4vzql0Yfr6r+hkkQdjaL/M0Isc=
|
||||
github.com/goplus/gogen v1.18.1/go.mod h1:owX2e1EyU5WD+Nm6oH2m/GXjLdlBYcwkLO4wN8HHXZI=
|
||||
github.com/goplus/lib v0.2.0 h1:AjqkN1XK5H23wZMMlpaUYAMCDAdSBQ2NMFrLtSh7W4g=
|
||||
github.com/goplus/lib v0.2.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=
|
||||
github.com/goplus/llvm v0.8.3 h1:is1zOwhiQZWtLnOmSMVPO+1sPa2uK/XJ/FjTSfIjGBU=
|
||||
github.com/goplus/llvm v0.8.3/go.mod h1:PeVK8GgzxwAYCiMiUAJb5wJR6xbhj989tu9oulKLLT4=
|
||||
github.com/goplus/mod v0.16.0 h1:5CHXx3no7YaMN5HN2sgZe9MbQnc8118JLjbOeetSTfc=
|
||||
github.com/goplus/mod v0.16.0/go.mod h1:U69PUD2e1MnI2DYhuumj1Z6wvZ1bNbKqHUk1MK8Diqo=
|
||||
github.com/qiniu/x v1.13.19 h1:rZzWpifNjMtaMhhVnYHw9RGUn+84KGtclDZ9HAKtuZQ=
|
||||
github.com/qiniu/x v1.13.19/go.mod h1:AiovSOCaRijaf3fj+0CBOpR1457pn24b0Vdb1JpwhII=
|
||||
github.com/goplus/mod v0.16.1 h1:2O+rKubJTn+Fighz3kckwpW87STSZ6s3m/YECfXuNhE=
|
||||
github.com/goplus/mod v0.16.1/go.mod h1:8d1P+pBavZfNQtJo4A742DgsLTtSf26BQn51owhmNqI=
|
||||
github.com/qiniu/x v1.14.6 h1:JY8jOumYFshuqNAjVkF6zsYhbcwM8A199ALkUOvJPks=
|
||||
github.com/qiniu/x v1.14.6/go.mod h1:AiovSOCaRijaf3fj+0CBOpR1457pn24b0Vdb1JpwhII=
|
||||
golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
|
||||
golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package github
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Author represents a github user or bot.
|
||||
type Author struct {
|
||||
Login string `json:"login"` // github-actions[bot]
|
||||
ID int `json:"id"` // 41898282
|
||||
NodeID string `json:"node_id"` // MDM6Qm90NDE4OTgyODI=
|
||||
AvatarURL string `json:"avatar_url"` // https://avatars.githubusercontent.com/in/15368?v=4
|
||||
URL string `json:"url"` // https://api.github.com/users/github-actions%5Bbot%5D
|
||||
HtmlURL string `json:"html_url"` // https://github.com/apps/github-actions
|
||||
Type string `json:"type"` // Bot
|
||||
SiteAdmin bool `json:"site_admin"` // false
|
||||
}
|
||||
|
||||
// CommitAuthor represents the author of a GitHub commit.
|
||||
type CommitAuthor struct {
|
||||
Name string `json:"name"` // xushiwei
|
||||
Email string `json:"email"` // x@goplus.org
|
||||
Date string `json:"date"` // 2025-04-21T14:13:29Z
|
||||
}
|
||||
|
||||
// CommitSummary represents the summary of a GitHub commit.
|
||||
type CommitSummary struct {
|
||||
Author CommitAuthor `json:"author"`
|
||||
Message string `json:"message"` // Merge pull request #2296 from goplus/main\n\nv1.4.0
|
||||
}
|
||||
|
||||
// CommitDetail represents the details of a GitHub commit.
|
||||
type CommitDetail struct {
|
||||
NodeID string `json:"node_id"` // C_kwDOAtpGOtoAKDE2OGEwODlmOWY5ZTNhNDdhMTliMTRjZDczODQ4N2M2ZTJkMTMxYmE
|
||||
Commit CommitSummary `json:"commit"`
|
||||
Author Author `json:"author"`
|
||||
}
|
||||
|
||||
func commitURL(pkgPath, sha string) string {
|
||||
return "https://api.github.com/repos/" + pkgPath + "/commits/" + sha
|
||||
}
|
||||
|
||||
// GetCommit retrieves the details of a specific commit from a GitHub repository.
|
||||
func GetCommit(pkgPath, shaOrURL string) (ret *CommitDetail, err error) {
|
||||
url := shaOrURL
|
||||
if !strings.HasPrefix(shaOrURL, "https://") {
|
||||
url = commitURL(pkgPath, shaOrURL)
|
||||
}
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
ret = new(CommitDetail)
|
||||
err = json.NewDecoder(resp.Body).Decode(ret)
|
||||
return
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package github
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// ReleaseAsset represents a GitHub release asset.
|
||||
type ReleaseAsset struct {
|
||||
URL string `json:"url"` // https://api.github.com/repos/flintlib/flint/releases/assets/242245930
|
||||
ID int `json:"id"` // 242245930
|
||||
NodeID string `json:"node_id"` // RA_kwDOAC8YHs4OcGEq
|
||||
Name string `json:"name"` // flint-3.2.2.tar.gz
|
||||
ContentType string `json:"content_type"` // application/x-gtar
|
||||
State string `json:"state"` // uploaded
|
||||
Size int64 `json:"size"` // 123456
|
||||
DownloadCount int `json:"download_count"` // 176
|
||||
UpdatedAt string `json:"updated_at"` // 2025-03-31T08:54:16Z
|
||||
BrowserDownloadURL string `json:"browser_download_url"` // https://github.com/flintlib/flint/releases/download/v3.2.2/flint-3.2.2.tar.gz
|
||||
}
|
||||
|
||||
// Release represents a GitHub release.
|
||||
type Release struct {
|
||||
URL string `json:"url"` // https://api.github.com/repos/flintlib/flint/releases/209285187
|
||||
ID int `json:"id"` // 209285187
|
||||
NodeID string `json:"node_id"` // RE_kwDOAC8YHs4MeXBD
|
||||
TagName string `json:"tag_name"` // v3.2.2
|
||||
TargetCommitish string `json:"target_commitish"` // b8223680e38ad048355a421bf7f617bb6c5d5e12
|
||||
Name string `json:"name"` // FLINT v3.2.2
|
||||
PublishedAt string `json:"published_at"` // 2025-03-31T08:54:16Z
|
||||
Body string `json:"body"` // Release Notes
|
||||
TarballURL string `json:"tarball_url"` // https://api.github.com/repos/flintlib/flint/tarball/v3.2.2
|
||||
ZipballURL string `json:"zipball_url"` // https://api.github.com/repos/flintlib/flint/zipball/v3.2.2
|
||||
Author Author `json:"author"`
|
||||
Assets []*ReleaseAsset `json:"assets"`
|
||||
Prerelease bool `json:"prerelease"`
|
||||
}
|
||||
|
||||
// releaseURL constructs the URL for a GitHub release.
|
||||
func releaseURL(pkgPath, ver string) string {
|
||||
if ver == "" || ver == "latest" {
|
||||
return "https://api.github.com/repos/" + pkgPath + "/releases/latest"
|
||||
}
|
||||
return "https://api.github.com/repos/" + pkgPath + "/releases/tags/" + ver
|
||||
}
|
||||
|
||||
// GetRelease fetches the release information from GitHub.
|
||||
func GetRelease(pkgPath, ver string) (ret *Release, err error) {
|
||||
url := releaseURL(pkgPath, ver)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
ret = new(Release)
|
||||
err = json.NewDecoder(resp.Body).Decode(ret)
|
||||
return
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package github
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrBreak = errors.New("break")
|
||||
ErrNotFound = errors.New("not found")
|
||||
)
|
||||
|
||||
// Commit represents a commit in a GitHub repository.
|
||||
type Commit struct {
|
||||
SHA string `json:"sha"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// Tag represents a GitHub tag.
|
||||
type Tag struct {
|
||||
Name string `json:"name"`
|
||||
ZipballURL string `json:"zipball_url"`
|
||||
TarballURL string `json:"tarball_url"`
|
||||
Commit Commit `json:"commit"`
|
||||
NodeID string `json:"node_id"`
|
||||
}
|
||||
|
||||
// tagsURL constructs the URL for fetching tags from a GitHub repository.
|
||||
func tagsURL(pkgPath string) string {
|
||||
return "https://api.github.com/repos/" + pkgPath + "/tags"
|
||||
}
|
||||
|
||||
// GetTag retrieves a specific tag from a GitHub repository.
|
||||
func GetTag(pkgPath, ver string) (tag *Tag, err error) {
|
||||
err = ErrNotFound
|
||||
EnumTags(pkgPath, 0, func(tags []*Tag, page, total int) error {
|
||||
for _, t := range tags {
|
||||
if t.Name == ver {
|
||||
tag = t
|
||||
err = nil
|
||||
return ErrBreak
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// EnumTags enumerates the tags of a GitHub repository.
|
||||
func EnumTags(pkgPath string, page int, pager func(tags []*Tag, page, total int) error) (err error) {
|
||||
total := 0
|
||||
ubase := tagsURL(pkgPath)
|
||||
|
||||
loop:
|
||||
u := ubase
|
||||
if page > 0 {
|
||||
vals := url.Values{"page": []string{strconv.Itoa(page + 1)}}
|
||||
u += "?" + vals.Encode()
|
||||
}
|
||||
resp, err := http.Get(u)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var tags []*Tag
|
||||
err = json.NewDecoder(resp.Body).Decode(&tags)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Link: <https://api.github.com/repositories/47859258/tags?page=2>; rel="next",
|
||||
// <https://api.github.com/repositories/47859258/tags?page=5>; rel="last"
|
||||
if total == 0 {
|
||||
const relLast = `rel="last"`
|
||||
total = page + 1
|
||||
link := resp.Header.Get("Link")
|
||||
for _, part := range strings.Split(link, ",") {
|
||||
if strings.HasSuffix(part, relLast) {
|
||||
left := strings.TrimSpace(part[:len(part)-len(relLast)])
|
||||
lastUrl := strings.TrimSuffix(strings.TrimPrefix(left, "<"), ">;")
|
||||
if pos := strings.LastIndexByte(lastUrl, '?'); pos >= 0 {
|
||||
if vals, e := url.ParseQuery(lastUrl[pos+1:]); e == nil {
|
||||
if n, e := strconv.Atoi(vals.Get("page")); e == nil {
|
||||
total = n
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
err = pager(tags, page, total)
|
||||
if err != nil {
|
||||
if err == ErrBreak {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
page++
|
||||
if page < total {
|
||||
goto loop
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -87,12 +87,6 @@ func Remove(path *c.Char) c.Int
|
||||
//go:linkname Rename C.rename
|
||||
func Rename(oldpath *c.Char, newpath *c.Char) c.Int
|
||||
|
||||
//go:linkname Stat C.stat
|
||||
func Stat(path *c.Char, buf *StatT) c.Int
|
||||
|
||||
//go:linkname Lstat C.lstat
|
||||
func Lstat(path *c.Char, buf *StatT) c.Int
|
||||
|
||||
//go:linkname Truncate C.truncate
|
||||
func Truncate(path *c.Char, length OffT) c.Int
|
||||
|
||||
@@ -285,7 +279,7 @@ func Exit(c.Int)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Upon successful completion, the value 0 is returned; otherwise the value -1
|
||||
// Upon successful completion, the value 0 is returned; otherwise the value -1
|
||||
// is returned and the global variable errno is set to indicate the error.
|
||||
//
|
||||
//go:linkname Sysctl C.sysctl
|
||||
|
||||
16
runtime/internal/clite/os/stat.go
Normal file
16
runtime/internal/clite/os/stat.go
Normal file
@@ -0,0 +1,16 @@
|
||||
//go:build !darwin
|
||||
// +build !darwin
|
||||
|
||||
package os
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
//go:linkname Stat C.stat
|
||||
func Stat(path *c.Char, buf *StatT) c.Int
|
||||
|
||||
//go:linkname Lstat C.lstat
|
||||
func Lstat(path *c.Char, buf *StatT) c.Int
|
||||
13
runtime/internal/clite/os/stat_darwin.go
Normal file
13
runtime/internal/clite/os/stat_darwin.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package os
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
//go:linkname Stat C.stat64
|
||||
func Stat(path *c.Char, buf *StatT) c.Int
|
||||
|
||||
//go:linkname Lstat C.lstat64
|
||||
func Lstat(path *c.Char, buf *StatT) c.Int
|
||||
@@ -7,7 +7,6 @@
|
||||
package syscall
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"structs"
|
||||
"unsafe"
|
||||
)
|
||||
@@ -297,11 +296,19 @@ func joinPath(dir, file string) string {
|
||||
}
|
||||
|
||||
func isAbs(path string) bool {
|
||||
return strings.HasPrefix(path, "/")
|
||||
return hasPrefix(path, "/")
|
||||
}
|
||||
|
||||
func isDir(path string) bool {
|
||||
return strings.HasSuffix(path, "/")
|
||||
return hasSuffix(path, "/")
|
||||
}
|
||||
|
||||
func hasPrefix(s, prefix string) bool {
|
||||
return len(s) >= len(prefix) && s[:len(prefix)] == prefix
|
||||
}
|
||||
|
||||
func hasSuffix(s, suffix string) bool {
|
||||
return len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix
|
||||
}
|
||||
|
||||
type Stat_t struct {
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "noinit"
|
||||
LLGoPackage = true
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -74,3 +74,25 @@ func Kill(pid int, signum Signal) error {
|
||||
func ProcExit(code int32) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func _utoa(buf []byte, val uint64) []byte {
|
||||
i := len(buf) - 1
|
||||
for val >= 10 {
|
||||
buf[i] = byte(val%10 + '0')
|
||||
i--
|
||||
val /= 10
|
||||
}
|
||||
buf[i] = byte(val + '0')
|
||||
return buf[i:]
|
||||
}
|
||||
|
||||
func utoa(val uint64) string {
|
||||
return string(_utoa(make([]byte, 20), val))
|
||||
}
|
||||
|
||||
func itoa(val int64) string {
|
||||
if val < 0 {
|
||||
return "-" + string(_utoa(make([]byte, 20), uint64(-val)))
|
||||
}
|
||||
return string(_utoa(make([]byte, 20), uint64(val)))
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
package syscall
|
||||
|
||||
import "strconv"
|
||||
|
||||
type Errno uintptr
|
||||
|
||||
func (e Errno) Error() string {
|
||||
@@ -13,7 +11,7 @@ func (e Errno) Error() string {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return "errno " + strconv.Itoa(int(e))
|
||||
return "errno " + utoa(uint64(e))
|
||||
}
|
||||
|
||||
func (e Errno) Is(target error) bool {
|
||||
@@ -51,5 +49,5 @@ func (s Signal) String() string {
|
||||
return str
|
||||
}
|
||||
}
|
||||
return "signal " + strconv.Itoa(int(s))
|
||||
return "signal " + itoa(int64(s))
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
package syscall
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@@ -79,7 +78,7 @@ func (e Errno) Error() string {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return "errno " + strconv.Itoa(int(e))
|
||||
return "errno " + utoa(uint64(e))
|
||||
}
|
||||
|
||||
func (e Errno) Is(target error) bool {
|
||||
@@ -209,7 +208,7 @@ func (s Signal) String() string {
|
||||
case SIGSYS:
|
||||
return "bad system call"
|
||||
default:
|
||||
return "signal " + strconv.Itoa(int(s))
|
||||
return "signal " + utoa(uint64(s))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ func statNolog(name string) (FileInfo, error) {
|
||||
if err != nil {
|
||||
return nil, &PathError{Op: "stat", Path: name, Err: err}
|
||||
}
|
||||
fillFileStatFromSys(&fs, name)
|
||||
return &fs, nil
|
||||
}
|
||||
|
||||
@@ -47,5 +48,6 @@ func lstatNolog(name string) (FileInfo, error) {
|
||||
if err != nil {
|
||||
return nil, &PathError{Op: "lstat", Path: name, Err: err}
|
||||
}
|
||||
fillFileStatFromSys(&fs, name)
|
||||
return &fs, nil
|
||||
}
|
||||
|
||||
@@ -124,6 +124,9 @@ func (v Value) typ() *abi.Type {
|
||||
// v.Kind() must be Pointer, Map, Chan, Func, or UnsafePointer
|
||||
// if v.Kind() == Pointer, the base type must not be not-in-heap.
|
||||
func (v Value) pointer() unsafe.Pointer {
|
||||
if v.typ_.IsClosure() {
|
||||
return v.ptr
|
||||
}
|
||||
if v.typ().Size() != goarch.PtrSize || !v.typ().Pointers() {
|
||||
panic("can't call pointer on a non-pointer Value")
|
||||
}
|
||||
|
||||
@@ -72,13 +72,13 @@ func Basic(_kind Kind) *Type {
|
||||
kind := _kind & abi.KindMask
|
||||
if tyBasic[kind] == nil {
|
||||
name, size, align := basicTypeInfo(kind)
|
||||
var bytes uintptr
|
||||
if kind == abi.String {
|
||||
bytes = pointerSize
|
||||
var ptrBytes uintptr
|
||||
if kind == abi.String || kind == abi.UnsafePointer {
|
||||
ptrBytes = pointerSize
|
||||
}
|
||||
tyBasic[kind] = &Type{
|
||||
Size_: size,
|
||||
PtrBytes: bytes,
|
||||
PtrBytes: ptrBytes,
|
||||
Hash: uint32(kind),
|
||||
Align_: uint8(align),
|
||||
FieldAlign_: uint8(align),
|
||||
|
||||
27
ssa/type.go
27
ssa/type.go
@@ -538,20 +538,15 @@ func PathOf(pkg *types.Package) string {
|
||||
// - method: pkg.T.name, pkg.(*T).name
|
||||
func FuncName(pkg *types.Package, name string, recv *types.Var, org bool) string {
|
||||
if recv != nil {
|
||||
named, ptr := recvNamed(recv.Type())
|
||||
var tName string
|
||||
t := recv.Type()
|
||||
if org {
|
||||
if tp, ok := t.(*types.Pointer); ok {
|
||||
tName = "(*" + tp.Elem().(*types.Named).Obj().Name() + ")"
|
||||
tName = named.Obj().Name()
|
||||
} else {
|
||||
tName = t.(*types.Named).Obj().Name()
|
||||
}
|
||||
} else {
|
||||
if tp, ok := t.(*types.Pointer); ok {
|
||||
tName = "(*" + abi.NamedName(tp.Elem().(*types.Named)) + ")"
|
||||
} else {
|
||||
tName = abi.NamedName(t.(*types.Named))
|
||||
tName = abi.NamedName(named)
|
||||
}
|
||||
if ptr {
|
||||
tName = "(*" + tName + ")"
|
||||
}
|
||||
return PathOf(pkg) + "." + tName + "." + name
|
||||
}
|
||||
@@ -559,6 +554,18 @@ func FuncName(pkg *types.Package, name string, recv *types.Var, org bool) string
|
||||
return ret
|
||||
}
|
||||
|
||||
func recvNamed(t types.Type) (typ *types.Named, ptr bool) {
|
||||
if tp, ok := t.(*types.Pointer); ok {
|
||||
t = tp.Elem()
|
||||
ptr = true
|
||||
}
|
||||
if _, ok := t.(*types.Alias); ok {
|
||||
t = types.Unalias(t)
|
||||
}
|
||||
typ, _ = t.(*types.Named)
|
||||
return
|
||||
}
|
||||
|
||||
func TypeArgs(typeArgs []types.Type) string {
|
||||
return abi.TypeArgs(typeArgs)
|
||||
}
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cppkg
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrNotFound is the error resulting if a path search failed to find
|
||||
// an executable file.
|
||||
ErrNotFound = exec.ErrNotFound
|
||||
)
|
||||
|
||||
// Tool represents a tool that can be executed.
|
||||
type Tool struct {
|
||||
cmd string
|
||||
installs [][]string
|
||||
}
|
||||
|
||||
// NewTool creates a new Tool instance with the specified tool and install commands.
|
||||
func NewTool(cmd string, installs []string) *Tool {
|
||||
inst := make([][]string, len(installs))
|
||||
for i, install := range installs {
|
||||
inst[i] = strings.Split(install, " ")
|
||||
}
|
||||
return &Tool{
|
||||
cmd: cmd,
|
||||
installs: inst,
|
||||
}
|
||||
}
|
||||
|
||||
// New creates a new command with the specified arguments.
|
||||
func (p *Tool) New(quietInstall bool, args ...string) (cmd *exec.Cmd, err error) {
|
||||
app, err := p.Get(quietInstall)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return exec.Command(app, args...), nil
|
||||
}
|
||||
|
||||
// Get retrieves the path of the command.
|
||||
// If the command is not found, it attempts to install it using the specified
|
||||
// install commands.
|
||||
func (p *Tool) Get(quietInstall bool) (app string, err error) {
|
||||
app, err = exec.LookPath(p.cmd)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
amPath, install, err := p.getAppManager()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c := exec.Command(amPath, install[1:]...)
|
||||
c.Stdout = os.Stdout
|
||||
c.Stderr = os.Stderr
|
||||
if err = c.Run(); err != nil {
|
||||
return
|
||||
}
|
||||
return exec.LookPath(p.cmd)
|
||||
}
|
||||
|
||||
func (p *Tool) getAppManager() (amPath string, install []string, err error) {
|
||||
for _, install = range p.installs {
|
||||
am := install[0]
|
||||
if amPath, err = exec.LookPath(am); err == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
err = ErrNotFound
|
||||
return
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cppkg
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/goccy/go-yaml"
|
||||
"github.com/goplus/llgo/internal/github"
|
||||
"github.com/qiniu/x/httputil"
|
||||
)
|
||||
|
||||
var conanCmd = NewTool("conan", []string{
|
||||
"brew install conan",
|
||||
"apt-get install conan",
|
||||
})
|
||||
|
||||
type conandata struct {
|
||||
Sources map[string]any `yaml:"sources"`
|
||||
}
|
||||
|
||||
func replaceVer(src any, fromVer, toVer string) any {
|
||||
switch src := src.(type) {
|
||||
case map[string]any:
|
||||
doReplace(src, fromVer, toVer)
|
||||
case []any:
|
||||
for _, u := range src {
|
||||
doReplace(u.(map[string]any), fromVer, toVer)
|
||||
}
|
||||
}
|
||||
return src
|
||||
}
|
||||
|
||||
func doReplace(src map[string]any, fromVer, toVer string) {
|
||||
switch url := src["url"].(type) {
|
||||
case string:
|
||||
src["url"] = strings.ReplaceAll(url, fromVer, toVer)
|
||||
delete(src, "sha256")
|
||||
// TODO(xsw): src["sha256"] = hash
|
||||
case []any:
|
||||
for i, u := range url {
|
||||
url[i] = strings.ReplaceAll(u.(string), fromVer, toVer)
|
||||
}
|
||||
delete(src, "sha256")
|
||||
// TODO(xsw): src["sha256"] = hash
|
||||
}
|
||||
}
|
||||
|
||||
type githubRelease struct {
|
||||
PublishedAt string
|
||||
}
|
||||
|
||||
func getRelease(pkg *Package, tagPattern string) (ret *githubRelease, err error) {
|
||||
if tagPattern == "" {
|
||||
return nil, ErrDynamicTag
|
||||
}
|
||||
if pkg.gr != nil {
|
||||
return &githubRelease{PublishedAt: pkg.gr.PublishedAt}, nil
|
||||
}
|
||||
ver := strings.Replace(tagPattern, "*", pkg.Version, 1)
|
||||
gr, err := github.GetRelease(pkg.Path, ver)
|
||||
if err == nil {
|
||||
ret = &githubRelease{PublishedAt: gr.PublishedAt}
|
||||
return
|
||||
}
|
||||
t, err := github.GetTag(pkg.Path, ver)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c, err := github.GetCommit(pkg.Path, t.Commit.URL)
|
||||
if err == nil {
|
||||
ret = &githubRelease{PublishedAt: c.Commit.Author.Date}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Install installs the specified package using Conan.
|
||||
func (p *Manager) Install(pkg *Package, flags int) (err error) {
|
||||
outDir := p.outDir(pkg)
|
||||
os.MkdirAll(outDir, os.ModePerm)
|
||||
|
||||
var rev string
|
||||
var gr *githubRelease
|
||||
var conandataYml, conanfilePy []byte
|
||||
|
||||
conanfileDir := p.conanfileDir(pkg.Path, pkg.Folder)
|
||||
pkgVer := pkg.Version
|
||||
template := pkg.Template
|
||||
if template != nil {
|
||||
gr, err = getRelease(pkg, template.Tag)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = copyDirR(conanfileDir, outDir)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
conanfilePy, err = os.ReadFile(outDir + "/conanfile.py")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
conandataFile := outDir + "/conandata.yml"
|
||||
conandataYml, err = os.ReadFile(conandataFile)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var cd conandata
|
||||
err = yaml.Unmarshal(conandataYml, &cd)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fromVer := template.FromVer
|
||||
source, ok := cd.Sources[fromVer]
|
||||
if !ok {
|
||||
return ErrVersionNotFound
|
||||
}
|
||||
cd.Sources = map[string]any{
|
||||
pkgVer: replaceVer(source, fromVer, pkgVer),
|
||||
}
|
||||
conandataYml, err = yaml.Marshal(cd)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = os.WriteFile(conandataFile, conandataYml, os.ModePerm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
rev = recipeRevision(pkg, gr, conandataYml)
|
||||
conanfileDir = outDir
|
||||
}
|
||||
|
||||
outFile := outDir + "/out.json"
|
||||
out, err := os.Create(outFile)
|
||||
if err == nil {
|
||||
defer out.Close()
|
||||
} else {
|
||||
out = os.Stdout
|
||||
}
|
||||
|
||||
nameAndVer := pkg.Name + "/" + pkgVer
|
||||
if template == nil {
|
||||
return conanInstall(nameAndVer, outDir, conanfileDir, out, flags)
|
||||
}
|
||||
|
||||
logFile := ""
|
||||
if flags&LogRevertProxy != 0 {
|
||||
logFile = outDir + "/rp.log"
|
||||
}
|
||||
return remoteProxy(flags, logFile, func() error {
|
||||
return conanInstall(nameAndVer, outDir, conanfileDir, out, flags)
|
||||
}, func(mux *http.ServeMux) {
|
||||
base := "/v2/conans/" + nameAndVer
|
||||
revbase := base + "/_/_/revisions/" + rev
|
||||
mux.HandleFunc(base+"/_/_/latest", func(w http.ResponseWriter, r *http.Request) {
|
||||
h := w.Header()
|
||||
h.Set("Cache-Control", "public,max-age=300")
|
||||
httputil.Reply(w, http.StatusOK, map[string]any{
|
||||
"revision": rev,
|
||||
"time": gr.PublishedAt,
|
||||
})
|
||||
})
|
||||
mux.HandleFunc(revbase+"/files", func(w http.ResponseWriter, r *http.Request) {
|
||||
h := w.Header()
|
||||
h.Set("Cache-Control", "public,max-age=3600")
|
||||
empty := map[string]any{}
|
||||
httputil.Reply(w, http.StatusOK, map[string]any{
|
||||
"files": map[string]any{
|
||||
"conan_export.tgz": empty,
|
||||
"conanmanifest.txt": empty,
|
||||
"conanfile.py": empty,
|
||||
},
|
||||
})
|
||||
})
|
||||
mux.HandleFunc(revbase+"/files/conanfile.py", func(w http.ResponseWriter, r *http.Request) {
|
||||
h := w.Header()
|
||||
h.Set("Cache-Control", "public,max-age=3600")
|
||||
h.Set("Content-Disposition", `attachment; filename="conanfile.py"`)
|
||||
httputil.ReplyWith(w, http.StatusOK, "text/x-python", conanfilePy)
|
||||
})
|
||||
const conanmanifest = "%d\nconandata.yml: %s\nconanfile.py: %s\n"
|
||||
mux.HandleFunc(revbase+"/files/conanmanifest.txt", func(w http.ResponseWriter, r *http.Request) {
|
||||
mtime, err := unixTime(gr.PublishedAt)
|
||||
if err != nil {
|
||||
replyError(w, err)
|
||||
return
|
||||
}
|
||||
h := w.Header()
|
||||
h.Set("Cache-Control", "public,max-age=3600")
|
||||
h.Set("Content-Disposition", `attachment; filename="conanmanifest.txt"`)
|
||||
data := fmt.Sprintf(conanmanifest, mtime, md5Of(conandataYml), md5Of(conanfilePy))
|
||||
httputil.ReplyWithStream(w, http.StatusOK, "text/plain", strings.NewReader(data), int64(len(data)))
|
||||
})
|
||||
mux.HandleFunc(revbase+"/files/conan_export.tgz", func(w http.ResponseWriter, r *http.Request) {
|
||||
conanExportTgz, err := tgzOfConandata(outDir)
|
||||
if err != nil {
|
||||
replyError(w, err)
|
||||
return
|
||||
}
|
||||
h := w.Header()
|
||||
h.Set("Cache-Control", "public,max-age=3600")
|
||||
h.Set("Content-Disposition", `attachment; filename="conan_export.tgz"`)
|
||||
httputil.ReplyWith(w, http.StatusOK, "application/x-gzip", conanExportTgz)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Manager) outDir(pkg *Package) string {
|
||||
return p.cacheDir + "/build/" + pkg.Name + "@" + pkg.Version
|
||||
}
|
||||
|
||||
func (p *Manager) conanfileDir(pkgPath, pkgFolder string) string {
|
||||
root := p.indexRoot()
|
||||
return root + "/" + pkgPath + "/" + pkgFolder
|
||||
}
|
||||
|
||||
func conanInstall(pkg, outDir, conanfileDir string, out io.Writer, flags int) (err error) {
|
||||
args := make([]string, 0, 12)
|
||||
args = append(args, "install",
|
||||
"--requires", pkg,
|
||||
"--generator", "PkgConfigDeps",
|
||||
"--build", "missing",
|
||||
"--format", "json",
|
||||
"--output-folder", outDir,
|
||||
)
|
||||
quietInstall := flags&ToolQuietInstall != 0
|
||||
cmd, err := conanCmd.New(quietInstall, args...)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cmd.Dir = conanfileDir
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = out
|
||||
err = cmd.Run()
|
||||
return
|
||||
}
|
||||
|
||||
func recipeRevision(_ *Package, _ *githubRelease, conandataYml []byte) string {
|
||||
return md5Of(conandataYml)
|
||||
}
|
||||
|
||||
func md5Of(data []byte) string {
|
||||
h := md5.New()
|
||||
h.Write(data)
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
func tgzOfConandata(outDir string) (_ []byte, err error) {
|
||||
cmd := exec.Command("tar", "-czf", "conan_export.tgz", "conandata.yml")
|
||||
cmd.Dir = outDir
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return os.ReadFile(outDir + "/conan_export.tgz")
|
||||
}
|
||||
|
||||
func unixTime(tstr string) (ret int64, err error) {
|
||||
t, err := time.Parse(time.RFC3339, tstr)
|
||||
if err == nil {
|
||||
ret = t.Unix()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func copyDirR(srcDir, destDir string) error {
|
||||
if cp, err := exec.LookPath("cp"); err == nil {
|
||||
return exec.Command(cp, "-r", "-p", srcDir+"/", destDir).Run()
|
||||
}
|
||||
if cp, err := exec.LookPath("xcopy"); err == nil {
|
||||
// TODO(xsw): check xcopy
|
||||
return exec.Command(cp, "/E", "/I", "/Y", srcDir+"/", destDir).Run()
|
||||
}
|
||||
return errors.New("copy command not found")
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cppkg
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultFlags is the default flags for package installation.
|
||||
DefaultFlags = IndexAutoUpdate | ToolQuietInstall
|
||||
)
|
||||
|
||||
// Install installs a package with the given name and version.
|
||||
// pkgAndVer: 7bitcoder/7bitconf@1.2.0
|
||||
func Install(pkgAndVer string, flags int) {
|
||||
pkgPath, ver := parsePkgVer(pkgAndVer)
|
||||
|
||||
m, err := New("")
|
||||
check(err)
|
||||
|
||||
pkg, err := m.Lookup(pkgPath, ver, flags)
|
||||
check(err)
|
||||
|
||||
err = m.Install(pkg, flags)
|
||||
check(err)
|
||||
}
|
||||
|
||||
func parsePkgVer(pkg string) (string, string) {
|
||||
parts := strings.SplitN(pkg, "@", 2)
|
||||
if len(parts) == 1 {
|
||||
return parts[0], ""
|
||||
}
|
||||
return parts[0], parts[1]
|
||||
}
|
||||
|
||||
func check(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cppkg
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/goccy/go-yaml"
|
||||
"github.com/goplus/llgo/internal/github"
|
||||
"golang.org/x/mod/semver"
|
||||
)
|
||||
|
||||
var gitCmd = NewTool("git", []string{
|
||||
"brew install git",
|
||||
"apt-get install git",
|
||||
})
|
||||
|
||||
// Manager represents a package manager for C/C++ packages.
|
||||
type Manager struct {
|
||||
cacheDir string
|
||||
}
|
||||
|
||||
func New(cacheDir string) (ret *Manager, err error) {
|
||||
if cacheDir == "" {
|
||||
cacheDir, err = os.UserCacheDir()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cacheDir += "/cppkg"
|
||||
}
|
||||
os.MkdirAll(cacheDir, os.ModePerm)
|
||||
ret = &Manager{
|
||||
cacheDir: cacheDir,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type version struct {
|
||||
Folder string `yaml:"folder"`
|
||||
}
|
||||
|
||||
// Template represents a template for package versions.
|
||||
type Template struct {
|
||||
FromVer string `yaml:"from"`
|
||||
Folder string `yaml:"folder"`
|
||||
Tag string `yaml:"tag,omitempty"` // pattern with *, empty if dynamic tag
|
||||
}
|
||||
|
||||
type config struct {
|
||||
PkgName string `yaml:"name"`
|
||||
Versions map[string]version `yaml:"versions"`
|
||||
Template Template `yaml:"template"`
|
||||
}
|
||||
|
||||
// Package represents a C/C++ package.
|
||||
type Package struct {
|
||||
Name string
|
||||
Path string
|
||||
Version string
|
||||
Folder string
|
||||
Template *Template
|
||||
|
||||
gr *github.Release // optional
|
||||
}
|
||||
|
||||
var (
|
||||
// ErrVersionNotFound is returned when the specified version is not found.
|
||||
ErrVersionNotFound = errors.New("version not found")
|
||||
|
||||
// ErrDynamicTag is returned when the tag is dynamic.
|
||||
ErrDynamicTag = errors.New("dynamic tag")
|
||||
)
|
||||
|
||||
const (
|
||||
// IndexAutoUpdate is a flag to automatically update the index.
|
||||
IndexAutoUpdate = 1 << iota
|
||||
|
||||
// ToolQuietInstall is a flag to suppress output during installation.
|
||||
ToolQuietInstall
|
||||
|
||||
// LogRevertProxy is a flag to log revert proxy.
|
||||
LogRevertProxy
|
||||
)
|
||||
|
||||
// Lookup looks up a package by its path and version.
|
||||
func (p *Manager) Lookup(pkgPath, ver string, flags int) (_ *Package, err error) {
|
||||
root := p.indexRoot()
|
||||
err = indexUpate(root, flags)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
pkgDir := root + "/" + pkgPath
|
||||
confFile := pkgDir + "/config.yml"
|
||||
b, err := os.ReadFile(confFile)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var conf config
|
||||
err = yaml.Unmarshal(b, &conf)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if ver == "" || ver == "latest" {
|
||||
if conf.Template.Tag == "" {
|
||||
return nil, ErrDynamicTag
|
||||
}
|
||||
gr, e := github.GetRelease(pkgPath, "")
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
ver, err = verByTag(gr.TagName, conf.Template.Tag)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
templ := conf.Template
|
||||
return &Package{conf.PkgName, pkgPath, ver, templ.Folder, &templ, gr}, nil
|
||||
}
|
||||
|
||||
if v, ok := conf.Versions[ver]; ok {
|
||||
return &Package{conf.PkgName, pkgPath, ver, v.Folder, nil, nil}, nil
|
||||
}
|
||||
if compareVer(ver, conf.Template.FromVer) < 0 {
|
||||
err = ErrVersionNotFound
|
||||
return
|
||||
}
|
||||
templ := conf.Template
|
||||
return &Package{conf.PkgName, pkgPath, ver, templ.Folder, &templ, nil}, nil
|
||||
}
|
||||
|
||||
func (p *Manager) indexRoot() string {
|
||||
return p.cacheDir + "/index"
|
||||
}
|
||||
|
||||
func indexUpate(root string, flags int) (err error) {
|
||||
if _, err = os.Stat(root + "/.git"); os.IsNotExist(err) {
|
||||
os.RemoveAll(root)
|
||||
return indexInit(root, flags)
|
||||
}
|
||||
if flags&IndexAutoUpdate != 0 {
|
||||
quietInstall := flags&ToolQuietInstall != 0
|
||||
git, e := gitCmd.New(quietInstall, "pull", "--ff-only", "origin", "main")
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
git.Dir = root
|
||||
git.Stdout = os.Stdout
|
||||
git.Stderr = os.Stderr
|
||||
err = git.Run()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func indexInit(root string, flags int) (err error) {
|
||||
quietInstall := flags&ToolQuietInstall != 0
|
||||
git, err := gitCmd.New(quietInstall, "clone", "https://github.com/goplus/cppkg.git", root)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
git.Stdout = os.Stdout
|
||||
git.Stderr = os.Stderr
|
||||
err = git.Run()
|
||||
return
|
||||
}
|
||||
|
||||
func compareVer(v1, v2 string) int {
|
||||
return semver.Compare("v"+v1, "v"+v2)
|
||||
}
|
||||
|
||||
func verByTag(tag, tagPattern string) (ver string, err error) {
|
||||
if pos := strings.IndexByte(tagPattern, '*'); pos >= 0 {
|
||||
prefix := tagPattern[:pos]
|
||||
suffix := tagPattern[pos+1:]
|
||||
if strings.HasPrefix(tag, prefix) && strings.HasSuffix(tag, suffix) {
|
||||
ver = tag[pos : len(tag)-len(suffix)]
|
||||
return
|
||||
}
|
||||
}
|
||||
return "", errors.New("tag not match: " + tag + " with " + tagPattern)
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cppkg
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
stdlog "log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type rtHandler func(req *http.Request) (resp *http.Response, err error)
|
||||
|
||||
func (p rtHandler) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
return p(req)
|
||||
}
|
||||
|
||||
type teeReader struct {
|
||||
rc io.ReadCloser
|
||||
b bytes.Buffer
|
||||
req *http.Request
|
||||
resp *http.Response
|
||||
log *stdlog.Logger
|
||||
}
|
||||
|
||||
func (p *teeReader) Read(b []byte) (n int, err error) {
|
||||
n, err = p.rc.Read(b)
|
||||
p.b.Write(b[:n])
|
||||
return
|
||||
}
|
||||
|
||||
func (p *teeReader) Close() error {
|
||||
err := p.rc.Close()
|
||||
if log := p.log; log != nil {
|
||||
resp := *p.resp
|
||||
resp.Body = io.NopCloser(&p.b)
|
||||
var b bytes.Buffer
|
||||
p.req.Write(&b)
|
||||
resp.Write(&b)
|
||||
log.Print(b.String())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
type response = httptest.ResponseRecorder
|
||||
|
||||
func newResponse() *response {
|
||||
return httptest.NewRecorder()
|
||||
}
|
||||
|
||||
type revertProxy = httptest.Server
|
||||
type rpFunc = func(mux *http.ServeMux)
|
||||
|
||||
const (
|
||||
passThrough = http.StatusNotFound
|
||||
)
|
||||
|
||||
func replyError(w http.ResponseWriter, _ error) {
|
||||
w.WriteHeader(passThrough)
|
||||
}
|
||||
|
||||
func startRevertProxy(endpoint string, f rpFunc, log *stdlog.Logger) (_ *revertProxy, err error) {
|
||||
rpURL, err := url.Parse(endpoint)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var mux *http.ServeMux
|
||||
if f != nil {
|
||||
mux = http.NewServeMux()
|
||||
f(mux)
|
||||
}
|
||||
proxy := httptest.NewServer(&httputil.ReverseProxy{
|
||||
Rewrite: func(r *httputil.ProxyRequest) {
|
||||
r.SetURL(rpURL)
|
||||
},
|
||||
Transport: rtHandler(func(req *http.Request) (resp *http.Response, err error) {
|
||||
if mux != nil {
|
||||
w := newResponse()
|
||||
mux.ServeHTTP(w, req)
|
||||
if w.Code != passThrough {
|
||||
resp = w.Result()
|
||||
}
|
||||
}
|
||||
if resp == nil {
|
||||
resp, err = http.DefaultTransport.RoundTrip(req)
|
||||
}
|
||||
if err == nil && resp.Body != nil {
|
||||
resp.Body = &teeReader{
|
||||
rc: resp.Body,
|
||||
req: req,
|
||||
resp: resp,
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
return
|
||||
}),
|
||||
})
|
||||
return proxy, nil
|
||||
}
|
||||
|
||||
const (
|
||||
conanCenter = "conancenter"
|
||||
conanEndpoint = "https://center2.conan.io"
|
||||
)
|
||||
|
||||
type remoteList []struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
func remoteProxy(flags int, logFile string, f func() error, rpf rpFunc) (err error) {
|
||||
quietInstall := flags&ToolQuietInstall != 0
|
||||
app, err := conanCmd.Get(quietInstall)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
endpoint := conanEndpoint
|
||||
cmd := exec.Command(app, "remote", "list", "-f", "json")
|
||||
if b, err := cmd.Output(); err == nil {
|
||||
var rl remoteList
|
||||
if json.Unmarshal(b, &rl) == nil {
|
||||
for _, r := range rl {
|
||||
if r.Name == conanCenter && strings.HasPrefix(r.URL, "https://") {
|
||||
endpoint = r.URL
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
defer func() {
|
||||
exec.Command(app, "remote", "add", "--force", conanCenter, endpoint).Run()
|
||||
}()
|
||||
|
||||
var log *stdlog.Logger
|
||||
if logFile != "" {
|
||||
f, err := os.Create(logFile)
|
||||
if err == nil {
|
||||
defer f.Close()
|
||||
log = stdlog.New(f, "", stdlog.LstdFlags)
|
||||
}
|
||||
}
|
||||
rp, err := startRevertProxy(conanEndpoint, rpf, log)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rp.Close()
|
||||
|
||||
err = exec.Command(app, "remote", "add", "--force", conanCenter, rp.URL).Run()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return f()
|
||||
}
|
||||
Reference in New Issue
Block a user