Skip to content

Commit

Permalink
Merge pull request #911 from visualfc/reflect.conv
Browse files Browse the repository at this point in the history
internal/lib/reflect: convertOp
  • Loading branch information
xushiwei authored Feb 5, 2025
2 parents faef4ff + 9ddd4d4 commit 29ec301
Show file tree
Hide file tree
Showing 22 changed files with 4,326 additions and 2,912 deletions.
12 changes: 12 additions & 0 deletions c/bitcast/_cast/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ float llgoToFloat32(long v) {
k.v = v;
return k.f;
}

long llgoFromFloat64(double v) {
castUnion k;
k.d = v;
return k.v;
}

long llgoFromFloat32(float v) {
castUnion k;
k.f = v;
return k.v;
}
6 changes: 6 additions & 0 deletions c/bitcast/bitcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ func ToFloat64(v uintptr) float64

//go:linkname ToFloat32 C.llgoToFloat32
func ToFloat32(v uintptr) float32

//go:linkname FromFloat64 C.llgoFromFloat64
func FromFloat64(v float64) uintptr

//go:linkname FromFloat32 C.llgoFromFloat32
func FromFloat32(v float32) uintptr
48 changes: 20 additions & 28 deletions compiler/cl/_testdata/foo/out.ll
Original file line number Diff line number Diff line change
Expand Up @@ -105,34 +105,26 @@ _llgo_1: ; preds = %_llgo_0
br label %_llgo_2

_llgo_2: ; preds = %_llgo_1, %_llgo_0
%3 = load ptr, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", align 8
%4 = icmp eq ptr %3, null
br i1 %4, label %_llgo_3, label %_llgo_4

_llgo_3: ; preds = %_llgo_2
%5 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
%6 = 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 @0, i64 1 }, ptr %5, i64 0, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
%7 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 56)
%8 = getelementptr %"github.com/goplus/llgo/runtime/abi.StructField", ptr %7, i64 0
store %"github.com/goplus/llgo/runtime/abi.StructField" %6, ptr %8, align 8
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %7, 0
%10 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %9, i64 1, 1
%11 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %10, i64 1, 2
%12 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 48 }, i64 8, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %11)
store ptr %12, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", align 8
br label %_llgo_4

_llgo_4: ; preds = %_llgo_3, %_llgo_2
%13 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
%14 = 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 1 }, ptr %13, i64 0, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
%15 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 56)
%16 = getelementptr %"github.com/goplus/llgo/runtime/abi.StructField", ptr %15, i64 0
store %"github.com/goplus/llgo/runtime/abi.StructField" %14, ptr %16, align 8
%17 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %15, 0
%18 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %17, i64 1, 1
%19 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %18, i64 1, 2
%20 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 48 }, i64 8, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %19)
store ptr %20, ptr @"github.com/goplus/llgo/compiler/cl/_testdata/foo.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88", align 8
%3 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
%4 = 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 @0, i64 1 }, ptr %3, i64 0, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
%5 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 56)
%6 = getelementptr %"github.com/goplus/llgo/runtime/abi.StructField", ptr %5, i64 0
store %"github.com/goplus/llgo/runtime/abi.StructField" %4, ptr %6, align 8
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %5, 0
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %7, i64 1, 1
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %8, i64 1, 2
%10 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 48 }, i64 8, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %9)
store ptr %10, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", align 8
%11 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
%12 = 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 1 }, ptr %11, i64 0, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
%13 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 56)
%14 = getelementptr %"github.com/goplus/llgo/runtime/abi.StructField", ptr %13, i64 0
store %"github.com/goplus/llgo/runtime/abi.StructField" %12, ptr %14, align 8
%15 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %13, 0
%16 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %15, i64 1, 1
%17 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %16, i64 1, 2
%18 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 48 }, i64 8, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %17)
store ptr %18, ptr @"github.com/goplus/llgo/compiler/cl/_testdata/foo.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88", align 8
ret void
}

Expand Down
Loading

0 comments on commit 29ec301

Please sign in to comment.