move out c/cpp/py

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

8
cl/_testdata/apkg/in.go Normal file
View File

@@ -0,0 +1,8 @@
package apkg
func Max(a, b float64) float64 {
if a > b {
return a
}
return b
}

29
cl/_testdata/apkg/out.ll Normal file
View File

@@ -0,0 +1,29 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/apkg'
source_filename = "github.com/goplus/llgo/cl/_testdata/apkg"
@"github.com/goplus/llgo/cl/_testdata/apkg.init$guard" = global i1 false, align 1
define double @"github.com/goplus/llgo/cl/_testdata/apkg.Max"(double %0, double %1) {
_llgo_0:
%2 = fcmp ogt double %0, %1
br i1 %2, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0
ret double %0
_llgo_2: ; preds = %_llgo_0
ret double %1
}
define void @"github.com/goplus/llgo/cl/_testdata/apkg.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/apkg.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/_testdata/apkg.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}

View File

@@ -0,0 +1 @@
-dbg

569
cl/_testdata/debug/in.go Normal file
View File

@@ -0,0 +1,569 @@
package main
import "errors"
type Base struct {
name string
}
type E struct {
// Base
i int
}
type StructWithAllTypeFields struct {
i8 int8
i16 int16
i32 int32
i64 int64
i int
u8 uint8
u16 uint16
u32 uint32
u64 uint64
u uint
f32 float32
f64 float64
b bool
c64 complex64
c128 complex128
slice []int
arr [3]int
arr2 [3]E
s string
e E
pf *StructWithAllTypeFields // resursive
pi *int
intr Interface
m map[string]uint64
c chan int
err error
fn func(string) (int, error)
pad1 int
pad2 int
}
type Interface interface {
Foo(a []int, b string) int
}
type Struct struct{}
func (s *Struct) Foo(a []int, b string) int {
return 1
}
func FuncWithAllTypeStructParam(s StructWithAllTypeFields) {
println(&s)
// Expected:
// all variables: s
// s.i8: '\x01'
// s.i16: 2
// s.i32: 3
// s.i64: 4
// s.i: 5
// s.u8: '\x06'
// s.u16: 7
// s.u32: 8
// s.u64: 9
// s.u: 10
// s.f32: 11
// s.f64: 12
// s.b: true
// s.c64: complex64{real = 13, imag = 14}
// s.c128: complex128{real = 15, imag = 16}
// s.slice: []int{21, 22, 23}
// s.arr: [3]int{24, 25, 26}
// s.arr2: [3]github.com/goplus/llgo/cl/_testdata/debug.E{{i = 27}, {i = 28}, {i = 29}}
// s.s: "hello"
// s.e: github.com/goplus/llgo/cl/_testdata/debug.E{i = 30}
// s.pad1: 100
// s.pad2: 200
s.i8 = '\b'
// Expected:
// s.i8: '\b'
// s.i16: 2
println(len(s.s), s.i8)
}
// Params is a function with all types of parameters.
func FuncWithAllTypeParams(
i8 int8,
i16 int16,
i32 int32,
i64 int64,
i int,
u8 uint8,
u16 uint16,
u32 uint32,
u64 uint64,
u uint,
f32 float32,
f64 float64,
b bool,
c64 complex64,
c128 complex128,
slice []int,
arr [3]int,
arr2 [3]E,
s string,
e E,
f StructWithAllTypeFields,
pf *StructWithAllTypeFields,
pi *int,
intr Interface,
m map[string]uint64,
c chan int,
err error,
fn func(string) (int, error),
) (int, error) {
// Expected:
// all variables: i8 i16 i32 i64 i u8 u16 u32 u64 u f32 f64 b c64 c128 slice arr arr2 s e f pf pi intr m c err fn
// i32: 3
// i64: 4
// i: 5
// u32: 8
// u64: 9
// u: 10
// f32: 11
// f64: 12
// slice: []int{21, 22, 23}
// arr: [3]int{24, 25, 26}
// arr2: [3]github.com/goplus/llgo/cl/_testdata/debug.E{{i = 27}, {i = 28}, {i = 29}}
// slice[0]: 21
// slice[1]: 22
// slice[2]: 23
// arr[0]: 24
// arr[1]: 25
// arr[2]: 26
// arr2[0].i: 27
// arr2[1].i: 28
// arr2[2].i: 29
// e: github.com/goplus/llgo/cl/_testdata/debug.E{i = 30}
// Expected(skip):
// i8: '\b'
// i16: 2
// u8: '\x06'
// u16: 7
// b: true
println(
i8, i16, i32, i64, i, u8, u16, u32, u64, u,
f32, f64, b,
c64, c128,
slice, arr[0:],
s,
&e,
&f, pf, pi, intr, m,
c,
err,
fn,
)
i8 = 9
i16 = 10
i32 = 11
i64 = 12
i = 13
u8 = 14
u16 = 15
u32 = 16
u64 = 17
u = 18
f32 = 19
f64 = 20
b = false
c64 = 21 + 22i
c128 = 23 + 24i
slice = []int{31, 32, 33}
arr = [3]int{34, 35, 36}
arr2 = [3]E{{i: 37}, {i: 38}, {i: 39}}
s = "world"
e = E{i: 40}
println(i8, i16, i32, i64, i, u8, u16, u32, u64, u,
f32, f64, b,
c64, c128,
slice, arr[0:], &arr2,
s,
&e,
&f, pf, pi, intr, m,
c,
err,
fn,
)
// Expected:
// i8: '\t'
// i16: 10
// i32: 11
// i64: 12
// i: 13
// u8: '\x0e'
// u16: 15
// u32: 16
// u64: 17
// u: 18
// f32: 19
// f64: 20
// b: false
// c64: complex64{real = 21, imag = 22}
// c128: complex128{real = 23, imag = 24}
// slice: []int{31, 32, 33}
// arr2: [3]github.com/goplus/llgo/cl/_testdata/debug.E{{i = 37}, {i = 38}, {i = 39}}
// s: "world"
// e: github.com/goplus/llgo/cl/_testdata/debug.E{i = 40}
// Expected(skip):
// arr: [3]int{34, 35, 36}
return 1, errors.New("some error")
}
type TinyStruct struct {
I int
}
type SmallStruct struct {
I int
J int
}
type MidStruct struct {
I int
J int
K int
}
type BigStruct struct {
I int
J int
K int
L int
M int
N int
O int
P int
Q int
R int
}
func FuncStructParams(t TinyStruct, s SmallStruct, m MidStruct, b BigStruct) {
// println(&t, &s, &m, &b)
// Expected:
// all variables: t s m b
// t.I: 1
// s.I: 2
// s.J: 3
// m.I: 4
// m.J: 5
// m.K: 6
// b.I: 7
// b.J: 8
// b.K: 9
// b.L: 10
// b.M: 11
// b.N: 12
// b.O: 13
// b.P: 14
// b.Q: 15
// b.R: 16
println(t.I, s.I, s.J, m.I, m.J, m.K, b.I, b.J, b.K, b.L, b.M, b.N, b.O, b.P, b.Q, b.R)
t.I = 10
s.I = 20
s.J = 21
m.I = 40
m.J = 41
m.K = 42
b.I = 70
b.J = 71
b.K = 72
b.L = 73
b.M = 74
b.N = 75
b.O = 76
b.P = 77
b.Q = 78
b.R = 79
// Expected:
// all variables: t s m b
// t.I: 10
// s.I: 20
// s.J: 21
// m.I: 40
// m.J: 41
// m.K: 42
// b.I: 70
// b.J: 71
// b.K: 72
// b.L: 73
// b.M: 74
// b.N: 75
// b.O: 76
// b.P: 77
// b.Q: 78
// b.R: 79
println("done")
}
func FuncStructPtrParams(t *TinyStruct, s *SmallStruct, m *MidStruct, b *BigStruct) {
// Expected:
// all variables: t s m b
// t.I: 1
// s.I: 2
// s.J: 3
// m.I: 4
// m.J: 5
// m.K: 6
// b.I: 7
// b.J: 8
// b.K: 9
// b.L: 10
// b.M: 11
// b.N: 12
// b.O: 13
// b.P: 14
// b.Q: 15
// b.R: 16
println(t, s, m, b)
t.I = 10
s.I = 20
s.J = 21
m.I = 40
m.J = 41
m.K = 42
b.I = 70
b.J = 71
b.K = 72
b.L = 73
b.M = 74
b.N = 75
b.O = 76
b.P = 77
b.Q = 78
b.R = 79
// Expected:
// all variables: t s m b
// t.I: 10
// s.I: 20
// s.J: 21
// m.I: 40
// m.J: 41
// m.K: 42
// b.I: 70
// b.J: 71
// b.K: 72
// b.L: 73
// b.M: 74
// b.N: 75
// b.O: 76
// b.P: 77
// b.Q: 78
// b.R: 79
println(t.I, s.I, s.J, m.I, m.J, m.K, b.I, b.J, b.K, b.L, b.M, b.N, b.O, b.P, b.Q, b.R)
println("done")
}
func ScopeIf(branch int) {
a := 1
// Expected:
// all variables: a branch
// a: 1
if branch == 1 {
b := 2
c := 3
// Expected:
// all variables: a b c branch
// a: 1
// b: 2
// c: 3
// branch: 1
println(a, b, c)
} else {
c := 3
d := 4
// Expected:
// all variables: a c d branch
// a: 1
// c: 3
// d: 4
// branch: 0
println(a, c, d)
}
// Expected:
// all variables: a branch
// a: 1
println("a:", a)
}
func ScopeFor() {
a := 1
for i := 0; i < 10; i++ {
switch i {
case 0:
println("i is 0")
// Expected:
// all variables: i a
// i: 0
// a: 1
println("i:", i)
case 1:
println("i is 1")
// Expected:
// all variables: i a
// i: 1
// a: 1
println("i:", i)
default:
println("i is", i)
}
}
println("a:", a)
}
func ScopeSwitch(i int) {
a := 0
switch i {
case 1:
b := 1
println("i is 1")
// Expected:
// all variables: i a b
// i: 1
// a: 0
// b: 1
println("i:", i, "a:", a, "b:", b)
case 2:
c := 2
println("i is 2")
// Expected:
// all variables: i a c
// i: 2
// a: 0
// c: 2
println("i:", i, "a:", a, "c:", c)
default:
d := 3
println("i is", i)
// Expected:
// all variables: i a d
// i: 3
// a: 0
// d: 3
println("i:", i, "a:", a, "d:", d)
}
// Expected:
// all variables: a i
// a: 0
println("a:", a)
}
func main() {
FuncStructParams(TinyStruct{I: 1}, SmallStruct{I: 2, J: 3}, MidStruct{I: 4, J: 5, K: 6}, BigStruct{I: 7, J: 8, K: 9, L: 10, M: 11, N: 12, O: 13, P: 14, Q: 15, R: 16})
FuncStructPtrParams(&TinyStruct{I: 1}, &SmallStruct{I: 2, J: 3}, &MidStruct{I: 4, J: 5, K: 6}, &BigStruct{I: 7, J: 8, K: 9, L: 10, M: 11, N: 12, O: 13, P: 14, Q: 15, R: 16})
i := 100
s := StructWithAllTypeFields{
i8: 1,
i16: 2,
i32: 3,
i64: 4,
i: 5,
u8: 6,
u16: 7,
u32: 8,
u64: 9,
u: 10,
f32: 11,
f64: 12,
b: true,
c64: 13 + 14i,
c128: 15 + 16i,
slice: []int{21, 22, 23},
arr: [3]int{24, 25, 26},
arr2: [3]E{{i: 27}, {i: 28}, {i: 29}},
s: "hello",
e: E{i: 30},
pf: &StructWithAllTypeFields{i16: 100},
pi: &i,
intr: &Struct{},
m: map[string]uint64{"a": 31, "b": 32},
c: make(chan int),
err: errors.New("Test error"),
fn: func(s string) (int, error) {
println("fn:", s)
i = 201
return 1, errors.New("fn error")
},
pad1: 100,
pad2: 200,
}
// Expected:
// all variables: s i err
// s.i8: '\x01'
// s.i16: 2
// s.i32: 3
// s.i64: 4
// s.i: 5
// s.u8: '\x06'
// s.u16: 7
// s.u32: 8
// s.u64: 9
// s.u: 10
// s.f32: 11
// s.f64: 12
// s.b: true
// s.c64: complex64{real = 13, imag = 14}
// s.c128: complex128{real = 15, imag = 16}
// s.slice: []int{21, 22, 23}
// s.arr: [3]int{24, 25, 26}
// s.arr2: [3]github.com/goplus/llgo/cl/_testdata/debug.E{{i = 27}, {i = 28}, {i = 29}}
// s.s: "hello"
// s.e: github.com/goplus/llgo/cl/_testdata/debug.E{i = 30}
// s.pf.i16: 100
// *(s.pf).i16: 100
// *(s.pi): 100
globalStructPtr = &s
globalStruct = s
println("globalInt:", globalInt)
// Expected(skip):
// all variables: globalInt globalStruct globalStructPtr s i err
println("s:", &s)
FuncWithAllTypeStructParam(s)
println("called function with struct")
i, err := FuncWithAllTypeParams(
s.i8, s.i16, s.i32, s.i64, s.i, s.u8, s.u16, s.u32, s.u64, s.u,
s.f32, s.f64, s.b,
s.c64, s.c128,
s.slice, s.arr, s.arr2,
s.s,
s.e, s,
s.pf, s.pi,
s.intr,
s.m,
s.c,
s.err,
s.fn,
)
println(i, err)
ScopeIf(1)
ScopeIf(0)
ScopeFor()
ScopeSwitch(1)
ScopeSwitch(2)
ScopeSwitch(3)
println(globalStructPtr)
println(&globalStruct)
s.i8 = 0x12
println(s.i8)
// Expected:
// all variables: s i err
// s.i8: '\x12'
// Expected(skip):
// globalStruct.i8: '\x01'
println((*globalStructPtr).i8)
println("done")
println("")
println(&s, &globalStruct, globalStructPtr.i16, globalStructPtr)
globalStructPtr = nil
}
var globalInt int = 301
var globalStruct StructWithAllTypeFields
var globalStructPtr *StructWithAllTypeFields

View File

@@ -0,0 +1 @@
;

12
cl/_testdata/fncall/in.go Normal file
View File

@@ -0,0 +1,12 @@
package main
func max(a, b int) int {
if a > b {
return a
}
return b
}
func main() {
_ = max(1, 2)
}

View File

@@ -0,0 +1,35 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/fncall'
source_filename = "github.com/goplus/llgo/cl/_testdata/fncall"
@"github.com/goplus/llgo/cl/_testdata/fncall.init$guard" = global i1 false, align 1
define void @"github.com/goplus/llgo/cl/_testdata/fncall.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/fncall.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/_testdata/fncall.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/fncall.main"() {
_llgo_0:
%0 = call i64 @"github.com/goplus/llgo/cl/_testdata/fncall.max"(i64 1, i64 2)
ret void
}
define i64 @"github.com/goplus/llgo/cl/_testdata/fncall.max"(i64 %0, i64 %1) {
_llgo_0:
%2 = icmp sgt i64 %0, %1
br i1 %2, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0
ret i64 %0
_llgo_2: ; preds = %_llgo_0
ret i64 %1
}

33
cl/_testdata/foo/foo.go Normal file
View File

@@ -0,0 +1,33 @@
package foo
func Bar() any {
return struct{ V int }{1}
}
func F() any {
return struct{ v int }{1}
}
type Foo struct {
pb *byte
F float32
}
func (v Foo) Pb() *byte {
return v.pb
}
type Gamer interface {
initGame()
Load()
}
type Game struct {
}
func (g *Game) initGame() {
}
func (g *Game) Load() {
println("load")
}

143
cl/_testdata/foo/out.ll Normal file
View File

@@ -0,0 +1,143 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/foo'
source_filename = "github.com/goplus/llgo/cl/_testdata/foo"
%"github.com/goplus/llgo/runtime/internal/runtime.eface" = type { ptr, ptr }
%"github.com/goplus/llgo/cl/_testdata/foo.Foo" = type { ptr, float }
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { 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/runtime/internal/runtime.Slice" = type { ptr, i64, i64 }
@"github.com/goplus/llgo/cl/_testdata/foo.init$guard" = global i1 false, align 1
@_llgo_int = linkonce global ptr null, align 8
@"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk" = linkonce global ptr null, align 8
@0 = private unnamed_addr constant [1 x i8] c"V", align 1
@1 = private unnamed_addr constant [39 x i8] c"github.com/goplus/llgo/cl/_testdata/foo", align 1
@"github.com/goplus/llgo/cl/_testdata/foo.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88" = linkonce global ptr null, align 8
@2 = private unnamed_addr constant [1 x i8] c"v", align 1
@3 = private unnamed_addr constant [4 x i8] c"load", align 1
define %"github.com/goplus/llgo/runtime/internal/runtime.eface" @"github.com/goplus/llgo/cl/_testdata/foo.Bar"() {
_llgo_0:
%0 = alloca { i64 }, align 8
call void @llvm.memset(ptr %0, i8 0, i64 8, i1 false)
%1 = getelementptr inbounds { i64 }, ptr %0, i32 0, i32 0
store i64 1, ptr %1, align 4
%2 = load { i64 }, ptr %0, align 4
%3 = load ptr, ptr @_llgo_int, align 8
%4 = load ptr, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", align 8
%5 = extractvalue { i64 } %2, 0
%6 = inttoptr i64 %5 to ptr
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %4, 0
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %7, ptr %6, 1
ret %"github.com/goplus/llgo/runtime/internal/runtime.eface" %8
}
define %"github.com/goplus/llgo/runtime/internal/runtime.eface" @"github.com/goplus/llgo/cl/_testdata/foo.F"() {
_llgo_0:
%0 = alloca { i64 }, align 8
call void @llvm.memset(ptr %0, i8 0, i64 8, i1 false)
%1 = getelementptr inbounds { i64 }, ptr %0, i32 0, i32 0
store i64 1, ptr %1, align 4
%2 = load { i64 }, ptr %0, align 4
%3 = load ptr, ptr @"github.com/goplus/llgo/cl/_testdata/foo.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88", align 8
%4 = extractvalue { i64 } %2, 0
%5 = inttoptr i64 %4 to ptr
%6 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %3, 0
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %6, ptr %5, 1
ret %"github.com/goplus/llgo/runtime/internal/runtime.eface" %7
}
define ptr @"github.com/goplus/llgo/cl/_testdata/foo.Foo.Pb"(%"github.com/goplus/llgo/cl/_testdata/foo.Foo" %0) {
_llgo_0:
%1 = alloca %"github.com/goplus/llgo/cl/_testdata/foo.Foo", align 8
call void @llvm.memset(ptr %1, i8 0, i64 16, i1 false)
store %"github.com/goplus/llgo/cl/_testdata/foo.Foo" %0, ptr %1, align 8
%2 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testdata/foo.Foo", ptr %1, i32 0, i32 0
%3 = load ptr, ptr %2, align 8
ret ptr %3
}
define ptr @"github.com/goplus/llgo/cl/_testdata/foo.(*Foo).Pb"(ptr %0) {
_llgo_0:
%1 = load %"github.com/goplus/llgo/cl/_testdata/foo.Foo", ptr %0, align 8
%2 = call ptr @"github.com/goplus/llgo/cl/_testdata/foo.Foo.Pb"(%"github.com/goplus/llgo/cl/_testdata/foo.Foo" %1)
ret ptr %2
}
define void @"github.com/goplus/llgo/cl/_testdata/foo.(*Game).Load"(ptr %0) {
_llgo_0:
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 4 })
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/foo.(*Game).initGame"(ptr %0) {
_llgo_0:
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/foo.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/foo.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/_testdata/foo.init$guard", align 1
call void @"github.com/goplus/llgo/cl/_testdata/foo.init$after"()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset(ptr nocapture writeonly, i8, i64, i1 immarg) #0
define void @"github.com/goplus/llgo/cl/_testdata/foo.init$after"() {
_llgo_0:
%0 = load ptr, ptr @_llgo_int, 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 34)
store ptr %2, ptr @_llgo_int, align 8
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
%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 39 }, 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 39 }, i64 8, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %17)
store ptr %18, ptr @"github.com/goplus/llgo/cl/_testdata/foo.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88", align 8
ret void
}
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 ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String")
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8)
attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }

View File

@@ -0,0 +1,10 @@
package main
import "github.com/goplus/llgo/cl/_testdata/importpkg/stdio"
var hello = [...]int8{'H', 'e', 'l', 'l', 'o', '\n', 0}
func main() {
_ = stdio.Max(2, 100)
stdio.Printf(&hello[0])
}

View File

@@ -0,0 +1,39 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/importpkg'
source_filename = "github.com/goplus/llgo/cl/_testdata/importpkg"
@"github.com/goplus/llgo/cl/_testdata/importpkg.hello" = global [7 x i8] zeroinitializer, align 1
@"github.com/goplus/llgo/cl/_testdata/importpkg.init$guard" = global i1 false, align 1
define void @"github.com/goplus/llgo/cl/_testdata/importpkg.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/importpkg.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/_testdata/importpkg.init$guard", align 1
call void @"github.com/goplus/llgo/cl/_testdata/importpkg/stdio.init"()
store i8 72, ptr @"github.com/goplus/llgo/cl/_testdata/importpkg.hello", align 1
store i8 101, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/importpkg.hello", i64 1), align 1
store i8 108, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/importpkg.hello", i64 2), align 1
store i8 108, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/importpkg.hello", i64 3), align 1
store i8 111, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/importpkg.hello", i64 4), align 1
store i8 10, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/importpkg.hello", i64 5), align 1
store i8 0, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/importpkg.hello", i64 6), align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/importpkg.main"() {
_llgo_0:
%0 = call i64 @"github.com/goplus/llgo/cl/_testdata/importpkg/stdio.Max"(i64 2, i64 100)
call void (ptr, ...) @printf(ptr @"github.com/goplus/llgo/cl/_testdata/importpkg.hello")
ret void
}
declare void @"github.com/goplus/llgo/cl/_testdata/importpkg/stdio.init"()
declare i64 @"github.com/goplus/llgo/cl/_testdata/importpkg/stdio.Max"(i64, i64)
declare void @printf(ptr, ...)

View File

@@ -0,0 +1,17 @@
package stdio
import _ "unsafe"
const (
LLGoPackage = true
)
//go:linkname Printf C.printf
func Printf(format *int8, __llgo_va_list ...any)
func Max(a, b int) int {
if a > b {
return a
}
return b
}

View File

@@ -0,0 +1,7 @@
//go:build llgo
// +build llgo
package llgotag
func Foo() {
}

View File

@@ -0,0 +1,22 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/llgotag'
source_filename = "github.com/goplus/llgo/cl/_testdata/llgotag"
@"github.com/goplus/llgo/cl/_testdata/llgotag.init$guard" = global i1 false, align 1
define void @"github.com/goplus/llgo/cl/_testdata/llgotag.Foo"() {
_llgo_0:
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/llgotag.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/llgotag.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/_testdata/llgotag.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}

19
cl/_testdata/method/in.go Normal file
View File

@@ -0,0 +1,19 @@
package main
import _ "unsafe"
type T int
func (a T) Add(b T) T {
return a + b
}
//go:linkname printf C.printf
func printf(format *int8, __llgo_va_list ...any)
var format = [...]int8{'H', 'e', 'l', 'l', 'o', ' ', '%', 'd', '\n', 0}
func main() {
a := T(1)
printf(&format[0], a.Add(2))
}

View File

@@ -0,0 +1,50 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/method'
source_filename = "github.com/goplus/llgo/cl/_testdata/method"
@"github.com/goplus/llgo/cl/_testdata/method.format" = global [10 x i8] zeroinitializer, align 1
@"github.com/goplus/llgo/cl/_testdata/method.init$guard" = global i1 false, align 1
define i64 @"github.com/goplus/llgo/cl/_testdata/method.T.Add"(i64 %0, i64 %1) {
_llgo_0:
%2 = add i64 %0, %1
ret i64 %2
}
define i64 @"github.com/goplus/llgo/cl/_testdata/method.(*T).Add"(ptr %0, i64 %1) {
_llgo_0:
%2 = load i64, ptr %0, align 4
%3 = call i64 @"github.com/goplus/llgo/cl/_testdata/method.T.Add"(i64 %2, i64 %1)
ret i64 %3
}
define void @"github.com/goplus/llgo/cl/_testdata/method.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/method.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/_testdata/method.init$guard", align 1
store i8 72, ptr @"github.com/goplus/llgo/cl/_testdata/method.format", align 1
store i8 101, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/method.format", i64 1), align 1
store i8 108, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/method.format", i64 2), align 1
store i8 108, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/method.format", i64 3), align 1
store i8 111, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/method.format", i64 4), align 1
store i8 32, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/method.format", i64 5), align 1
store i8 37, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/method.format", i64 6), align 1
store i8 100, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/method.format", i64 7), align 1
store i8 10, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/method.format", i64 8), align 1
store i8 0, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/method.format", i64 9), align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/method.main"() {
_llgo_0:
%0 = call i64 @"github.com/goplus/llgo/cl/_testdata/method.T.Add"(i64 1, i64 2)
call void (ptr, ...) @printf(ptr @"github.com/goplus/llgo/cl/_testdata/method.format", i64 %0)
ret void
}
declare void @printf(ptr, ...)

277
cl/_testdata/print/in.go Normal file
View File

@@ -0,0 +1,277 @@
package main
import (
"unsafe"
"github.com/goplus/lib/c"
)
func gwrite(b []byte) {
if len(b) == 0 {
return
}
for _, v := range b {
c.Printf(c.Str("%c"), v)
}
}
func printbool(v bool) {
if v {
printstring("true")
} else {
printstring("false")
}
}
func printfloat(v float64) {
switch {
case v != v:
printstring("NaN")
return
case v+v == v && v > 0:
printstring("+Inf")
return
case v+v == v && v < 0:
printstring("-Inf")
return
}
const n = 7 // digits printed
var buf [n + 7]byte
buf[0] = '+'
e := 0 // exp
if v == 0 {
if 1/v < 0 {
buf[0] = '-'
}
} else {
if v < 0 {
v = -v
buf[0] = '-'
}
// normalize
for v >= 10 {
e++
v /= 10
}
for v < 1 {
e--
v *= 10
}
// round
h := 5.0
for i := 0; i < n; i++ {
h /= 10
}
v += h
if v >= 10 {
e++
v /= 10
}
}
// format +d.dddd+edd
for i := 0; i < n; i++ {
s := int(v)
buf[i+2] = byte(s + '0')
v -= float64(s)
v *= 10
}
buf[1] = buf[2]
buf[2] = '.'
buf[n+2] = 'e'
buf[n+3] = '+'
if e < 0 {
e = -e
buf[n+3] = '-'
}
buf[n+4] = byte(e/100) + '0'
buf[n+5] = byte(e/10)%10 + '0'
buf[n+6] = byte(e%10) + '0'
gwrite(buf[:])
}
func printuint(v uint64) {
var buf [100]byte
i := len(buf)
for i--; i > 0; i-- {
buf[i] = byte(v%10 + '0')
if v < 10 {
break
}
v /= 10
}
gwrite(buf[i:])
}
func printint(v int64) {
if v < 0 {
printstring("-")
v = -v
}
printuint(uint64(v))
}
var minhexdigits = 0
func printhex(v uint64) {
const dig = "0123456789abcdef"
var buf [100]byte
i := len(buf)
for i--; i > 0; i-- {
buf[i] = dig[v%16]
if v < 16 && len(buf)-i >= minhexdigits {
break
}
v /= 16
}
i--
buf[i] = 'x'
i--
buf[i] = '0'
gwrite(buf[i:])
}
func printsp() {
printstring(" ")
}
func printnl() {
printstring("\n")
}
func printstring(s string) {
gwrite(bytes(s))
}
type slice struct {
array unsafe.Pointer
len int
cap int
}
type stringStruct struct {
str unsafe.Pointer
len int
}
func stringStructOf(sp *string) *stringStruct {
return (*stringStruct)(unsafe.Pointer(sp))
}
func bytes(s string) (ret []byte) {
rp := (*slice)(unsafe.Pointer(&ret))
sp := stringStructOf(&s)
rp.array = sp.str
rp.len = sp.len
rp.cap = sp.len
return
}
func main() {
printstring("llgo")
printnl()
printuint(1024)
printnl()
printhex(0x1234abcf)
printnl()
prinxor(1)
printnl()
prinsub(100)
printnl()
prinusub(1<<64 - 1)
printnl()
prinfsub(100.1)
printnl()
printany(float32(1e9))
printnl()
printany(float64(2e9))
printnl()
var b bool = true
if b == true && b != false {
println("check bool", b)
}
n1 := 0b1001
n2 := 0b0011
println("check &^", n1&^n2 == 0b1000, n2&^n1 == 0b0010)
println(true, false, 'a', 'A', rune('中'),
int8(1), int16(2), int32(3), int64(4), 5,
uint8(1), uint16(2), uint32(3), uint64(4), uintptr(5),
"llgo")
println(1 + 2i)
}
func println(args ...any) {
for i, v := range args {
if i != 0 {
printstring(" ")
}
printany(v)
}
printnl()
}
func printany(v any) {
switch v := v.(type) {
case bool:
printbool(v)
case int:
printint(int64(v))
case int8:
printint(int64(v))
case int16:
printint(int64(v))
case int32:
printint(int64(v))
case int64:
printint(int64(v))
case uint:
printuint(uint64(v))
case uint8:
printuint(uint64(v))
case uint16:
printuint(uint64(v))
case uint32:
printuint(uint64(v))
case uint64:
printuint(uint64(v))
case uintptr:
printuint(uint64(v))
case float32:
printfloat(float64(v))
case float64:
printfloat(float64(v))
case complex64:
printstring("(")
printfloat(float64(real(v)))
printfloat(float64(imag(v)))
printstring("i)")
case complex128:
printstring("(")
printfloat(real(v))
printfloat(imag(v))
printstring("i)")
case string:
printstring(v)
}
}
func prinxor(n int64) {
printint(^n)
}
func prinsub(n int64) {
printint(-n)
}
func prinusub(n uint64) {
printuint(-n)
}
func prinfsub(n float64) {
printfloat(-n)
}

1355
cl/_testdata/print/out.ll Normal file

File diff suppressed because it is too large Load Diff

12
cl/_testdata/printf/in.go Normal file
View File

@@ -0,0 +1,12 @@
package main
import _ "unsafe"
//go:linkname printf C.printf
func printf(format *int8, __llgo_va_list ...any)
var hello = [...]int8{'H', 'e', 'l', 'l', 'o', '\n', 0}
func main() {
printf(&hello[0])
}

View File

@@ -0,0 +1,33 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/printf'
source_filename = "github.com/goplus/llgo/cl/_testdata/printf"
@"github.com/goplus/llgo/cl/_testdata/printf.hello" = global [7 x i8] zeroinitializer, align 1
@"github.com/goplus/llgo/cl/_testdata/printf.init$guard" = global i1 false, align 1
define void @"github.com/goplus/llgo/cl/_testdata/printf.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/printf.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/_testdata/printf.init$guard", align 1
store i8 72, ptr @"github.com/goplus/llgo/cl/_testdata/printf.hello", align 1
store i8 101, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printf.hello", i64 1), align 1
store i8 108, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printf.hello", i64 2), align 1
store i8 108, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printf.hello", i64 3), align 1
store i8 111, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printf.hello", i64 4), align 1
store i8 10, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printf.hello", i64 5), align 1
store i8 0, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printf.hello", i64 6), align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/printf.main"() {
_llgo_0:
call void (ptr, ...) @printf(ptr @"github.com/goplus/llgo/cl/_testdata/printf.hello")
ret void
}
declare void @printf(ptr, ...)

View File

@@ -0,0 +1,12 @@
package main
import _ "unsafe"
//go:linkname printf C.printf
func printf(format *int8, __llgo_va_list ...any)
var format = [...]int8{'H', 'e', 'l', 'l', 'o', ' ', '%', 'd', '\n', 0}
func main() {
printf(&format[0], 100)
}

View File

@@ -0,0 +1,36 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/printval'
source_filename = "github.com/goplus/llgo/cl/_testdata/printval"
@"github.com/goplus/llgo/cl/_testdata/printval.format" = global [10 x i8] zeroinitializer, align 1
@"github.com/goplus/llgo/cl/_testdata/printval.init$guard" = global i1 false, align 1
define void @"github.com/goplus/llgo/cl/_testdata/printval.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/printval.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/_testdata/printval.init$guard", align 1
store i8 72, ptr @"github.com/goplus/llgo/cl/_testdata/printval.format", align 1
store i8 101, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printval.format", i64 1), align 1
store i8 108, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printval.format", i64 2), align 1
store i8 108, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printval.format", i64 3), align 1
store i8 111, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printval.format", i64 4), align 1
store i8 32, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printval.format", i64 5), align 1
store i8 37, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printval.format", i64 6), align 1
store i8 100, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printval.format", i64 7), align 1
store i8 10, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printval.format", i64 8), align 1
store i8 0, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/printval.format", i64 9), align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/printval.main"() {
_llgo_0:
call void (ptr, ...) @printf(ptr @"github.com/goplus/llgo/cl/_testdata/printval.format", i64 100)
ret void
}
declare void @printf(ptr, ...)

View File

@@ -0,0 +1,19 @@
package main
import _ "unsafe"
//go:linkname printf C.printf
func printf(format *int8, __llgo_va_list ...any)
type T int8
func (f *T) Print(v int) {
printf((*int8)(f), v)
}
var format = [...]T{'H', 'e', 'l', 'l', 'o', ' ', '%', 'd', '\n', 0}
func main() {
f := &format[0]
f.Print(100)
}

View File

@@ -0,0 +1,42 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/ptrmthd'
source_filename = "github.com/goplus/llgo/cl/_testdata/ptrmthd"
@"github.com/goplus/llgo/cl/_testdata/ptrmthd.format" = global [10 x i8] zeroinitializer, align 1
@"github.com/goplus/llgo/cl/_testdata/ptrmthd.init$guard" = global i1 false, align 1
define void @"github.com/goplus/llgo/cl/_testdata/ptrmthd.(*T).Print"(ptr %0, i64 %1) {
_llgo_0:
call void (ptr, ...) @printf(ptr %0, i64 %1)
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/ptrmthd.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.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/_testdata/ptrmthd.init$guard", align 1
store i8 72, ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.format", align 1
store i8 101, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.format", i64 1), align 1
store i8 108, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.format", i64 2), align 1
store i8 108, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.format", i64 3), align 1
store i8 111, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.format", i64 4), align 1
store i8 32, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.format", i64 5), align 1
store i8 37, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.format", i64 6), align 1
store i8 100, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.format", i64 7), align 1
store i8 10, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.format", i64 8), align 1
store i8 0, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.format", i64 9), align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/ptrmthd.main"() {
_llgo_0:
call void @"github.com/goplus/llgo/cl/_testdata/ptrmthd.(*T).Print"(ptr @"github.com/goplus/llgo/cl/_testdata/ptrmthd.format", i64 100)
ret void
}
declare void @printf(ptr, ...)

13
cl/_testdata/uint/in.go Normal file
View File

@@ -0,0 +1,13 @@
package main
import "github.com/goplus/lib/c"
func f(a c.Uint) c.Uint {
a++
return a
}
func main() {
var a c.Uint = 100
c.Printf(c.Str("Hello, %u\n"), f(a))
}

33
cl/_testdata/uint/out.ll Normal file
View File

@@ -0,0 +1,33 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/uint'
source_filename = "github.com/goplus/llgo/cl/_testdata/uint"
@"github.com/goplus/llgo/cl/_testdata/uint.init$guard" = global i1 false, align 1
@0 = private unnamed_addr constant [11 x i8] c"Hello, %u\0A\00", align 1
define i32 @"github.com/goplus/llgo/cl/_testdata/uint.f"(i32 %0) {
_llgo_0:
%1 = add i32 %0, 1
ret i32 %1
}
define void @"github.com/goplus/llgo/cl/_testdata/uint.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/uint.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/_testdata/uint.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/uint.main"() {
_llgo_0:
%0 = call i32 @"github.com/goplus/llgo/cl/_testdata/uint.f"(i32 100)
%1 = call i32 (ptr, ...) @printf(ptr @0, i32 %0)
ret void
}
declare i32 @printf(ptr, ...)

View File

@@ -0,0 +1,11 @@
package main
const c = 100
var a float64 = 1
func main() {
if c > 100 {
a = 0
}
}

View File

@@ -0,0 +1,31 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/untyped'
source_filename = "github.com/goplus/llgo/cl/_testdata/untyped"
@"github.com/goplus/llgo/cl/_testdata/untyped.a" = global double 0.000000e+00, align 8
@"github.com/goplus/llgo/cl/_testdata/untyped.init$guard" = global i1 false, align 1
define void @"github.com/goplus/llgo/cl/_testdata/untyped.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/untyped.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/_testdata/untyped.init$guard", align 1
store double 1.000000e+00, ptr @"github.com/goplus/llgo/cl/_testdata/untyped.a", align 8
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/untyped.main"() {
_llgo_0:
br i1 false, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0
store double 0.000000e+00, ptr @"github.com/goplus/llgo/cl/_testdata/untyped.a", align 8
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}

23
cl/_testdata/utf8/in.go Normal file
View File

@@ -0,0 +1,23 @@
package main
import (
"unicode/utf8"
)
func main() {
var str = "中abcd"
for i := 0; i < len(str); {
r, n := utf8.DecodeRuneInString(str[i:])
i += n
println(r)
}
println(index(2) == 3)
}
var array = [...]uint8{
1, 2, 3, 4, 5, 6, 7, 8,
}
func index(n int8) uint8 {
return array[n]
}

84
cl/_testdata/utf8/out.ll Normal file
View File

@@ -0,0 +1,84 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/utf8'
source_filename = "github.com/goplus/llgo/cl/_testdata/utf8"
%"github.com/goplus/llgo/runtime/internal/runtime.String" = type { ptr, i64 }
@"github.com/goplus/llgo/cl/_testdata/utf8.array" = global [8 x i8] zeroinitializer, align 1
@"github.com/goplus/llgo/cl/_testdata/utf8.init$guard" = global i1 false, align 1
@0 = private unnamed_addr constant [7 x i8] c"\E4\B8\ADabcd", align 1
define i8 @"github.com/goplus/llgo/cl/_testdata/utf8.index"(i8 %0) {
_llgo_0:
%1 = sext i8 %0 to i64
%2 = icmp slt i64 %1, 0
%3 = icmp sge i64 %1, 8
%4 = or i1 %3, %2
call void @"github.com/goplus/llgo/runtime/internal/runtime.AssertIndexRange"(i1 %4)
%5 = getelementptr inbounds i8, ptr @"github.com/goplus/llgo/cl/_testdata/utf8.array", i64 %1
%6 = load i8, ptr %5, align 1
ret i8 %6
}
define void @"github.com/goplus/llgo/cl/_testdata/utf8.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/utf8.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/_testdata/utf8.init$guard", align 1
call void @"unicode/utf8.init"()
store i8 1, ptr @"github.com/goplus/llgo/cl/_testdata/utf8.array", align 1
store i8 2, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/utf8.array", i64 1), align 1
store i8 3, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/utf8.array", i64 2), align 1
store i8 4, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/utf8.array", i64 3), align 1
store i8 5, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/utf8.array", i64 4), align 1
store i8 6, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/utf8.array", i64 5), align 1
store i8 7, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/utf8.array", i64 6), align 1
store i8 8, ptr getelementptr inbounds (i8, ptr @"github.com/goplus/llgo/cl/_testdata/utf8.array", i64 7), align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/utf8.main"() {
_llgo_0:
br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0
%0 = phi i64 [ 0, %_llgo_0 ], [ %6, %_llgo_2 ]
%1 = icmp slt i64 %0, 7
br i1 %1, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1
%2 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" @"github.com/goplus/llgo/runtime/internal/runtime.StringSlice"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 7 }, i64 %0, i64 7)
%3 = call { i32, i64 } @"unicode/utf8.DecodeRuneInString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %2)
%4 = extractvalue { i32, i64 } %3, 0
%5 = extractvalue { i32, i64 } %3, 1
%6 = add i64 %0, %5
%7 = sext i32 %4 to i64
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %7)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
br label %_llgo_1
_llgo_3: ; preds = %_llgo_1
%8 = call i8 @"github.com/goplus/llgo/cl/_testdata/utf8.index"(i8 2)
%9 = icmp eq i8 %8, 3
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintBool"(i1 %9)
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
ret void
}
declare void @"github.com/goplus/llgo/runtime/internal/runtime.AssertIndexRange"(i1)
declare void @"unicode/utf8.init"()
declare %"github.com/goplus/llgo/runtime/internal/runtime.String" @"github.com/goplus/llgo/runtime/internal/runtime.StringSlice"(%"github.com/goplus/llgo/runtime/internal/runtime.String", i64, i64)
declare { i32, i64 } @"unicode/utf8.DecodeRuneInString"(%"github.com/goplus/llgo/runtime/internal/runtime.String")
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintBool"(i1)

13
cl/_testdata/vargs/in.go Normal file
View File

@@ -0,0 +1,13 @@
package main
import "github.com/goplus/lib/c"
func test(a ...any) {
for _, v := range a {
c.Printf(c.Str("%d\n"), v.(int))
}
}
func main() {
test(1, 2, 3)
}

132
cl/_testdata/vargs/out.ll Normal file
View File

@@ -0,0 +1,132 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/vargs'
source_filename = "github.com/goplus/llgo/cl/_testdata/vargs"
%"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.String" = type { ptr, i64 }
@"github.com/goplus/llgo/cl/_testdata/vargs.init$guard" = global i1 false, align 1
@_llgo_int = linkonce global ptr null, align 8
@0 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@1 = private unnamed_addr constant [40 x i8] c"type assertion interface{} -> int failed", align 1
@_llgo_string = linkonce global ptr null, align 8
define void @"github.com/goplus/llgo/cl/_testdata/vargs.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/vargs.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/_testdata/vargs.init$guard", align 1
call void @"github.com/goplus/llgo/cl/_testdata/vargs.init$after"()
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/vargs.main"() {
_llgo_0:
%0 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 48)
%1 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.eface", ptr %0, i64 0
%2 = load ptr, ptr @_llgo_int, align 8
%3 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %2, 0
%4 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %3, ptr inttoptr (i64 1 to ptr), 1
store %"github.com/goplus/llgo/runtime/internal/runtime.eface" %4, ptr %1, align 8
%5 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.eface", ptr %0, i64 1
%6 = load ptr, ptr @_llgo_int, align 8
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %6, 0
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %7, ptr inttoptr (i64 2 to ptr), 1
store %"github.com/goplus/llgo/runtime/internal/runtime.eface" %8, ptr %5, align 8
%9 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.eface", ptr %0, i64 2
%10 = load ptr, ptr @_llgo_int, align 8
%11 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %10, 0
%12 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %11, ptr inttoptr (i64 3 to ptr), 1
store %"github.com/goplus/llgo/runtime/internal/runtime.eface" %12, ptr %9, align 8
%13 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %0, 0
%14 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %13, i64 3, 1
%15 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %14, i64 3, 2
call void @"github.com/goplus/llgo/cl/_testdata/vargs.test"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %15)
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/vargs.test"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %0) {
_llgo_0:
%1 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %0, 1
br label %_llgo_1
_llgo_1: ; preds = %_llgo_4, %_llgo_0
%2 = phi i64 [ -1, %_llgo_0 ], [ %3, %_llgo_4 ]
%3 = add i64 %2, 1
%4 = icmp slt i64 %3, %1
br i1 %4, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1
%5 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %0, 0
%6 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %0, 1
%7 = icmp slt i64 %3, 0
%8 = icmp sge i64 %3, %6
%9 = or i1 %8, %7
call void @"github.com/goplus/llgo/runtime/internal/runtime.AssertIndexRange"(i1 %9)
%10 = getelementptr inbounds %"github.com/goplus/llgo/runtime/internal/runtime.eface", ptr %5, i64 %3
%11 = load %"github.com/goplus/llgo/runtime/internal/runtime.eface", ptr %10, align 8
%12 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %11, 0
%13 = load ptr, ptr @_llgo_int, align 8
%14 = icmp eq ptr %12, %13
br i1 %14, label %_llgo_4, label %_llgo_5
_llgo_3: ; preds = %_llgo_1
ret void
_llgo_4: ; preds = %_llgo_2
%15 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %11, 1
%16 = ptrtoint ptr %15 to i64
%17 = call i32 (ptr, ...) @printf(ptr @0, i64 %16)
br label %_llgo_1
_llgo_5: ; preds = %_llgo_2
%18 = load ptr, ptr @_llgo_string, align 8
%19 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 40 }, 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
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %21)
unreachable
}
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
define void @"github.com/goplus/llgo/cl/_testdata/vargs.init$after"() {
_llgo_0:
%0 = load ptr, ptr @_llgo_int, 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 34)
store ptr %2, ptr @_llgo_int, align 8
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
%3 = load ptr, ptr @_llgo_string, 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 24)
store ptr %5, ptr @_llgo_string, align 8
br label %_llgo_4
_llgo_4: ; preds = %_llgo_3, %_llgo_2
ret void
}
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.AssertIndexRange"(i1)
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64)
declare void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface")
declare i32 @printf(ptr, ...)

View File

@@ -0,0 +1,8 @@
package main
var a = 100
func main() {
a++
_ = a
}

View File

@@ -0,0 +1,28 @@
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/varinit'
source_filename = "github.com/goplus/llgo/cl/_testdata/varinit"
@"github.com/goplus/llgo/cl/_testdata/varinit.a" = global i64 0, align 8
@"github.com/goplus/llgo/cl/_testdata/varinit.init$guard" = global i1 false, align 1
define void @"github.com/goplus/llgo/cl/_testdata/varinit.init"() {
_llgo_0:
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/varinit.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/_testdata/varinit.init$guard", align 1
store i64 100, ptr @"github.com/goplus/llgo/cl/_testdata/varinit.a", align 4
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @"github.com/goplus/llgo/cl/_testdata/varinit.main"() {
_llgo_0:
%0 = load i64, ptr @"github.com/goplus/llgo/cl/_testdata/varinit.a", align 4
%1 = add i64 %0, 1
store i64 %1, ptr @"github.com/goplus/llgo/cl/_testdata/varinit.a", align 4
%2 = load i64, ptr @"github.com/goplus/llgo/cl/_testdata/varinit.a", align 4
ret void
}