build: separate compiler and libs
This commit is contained in:
16
compiler/cl/_testpy/callpy/in.go
Normal file
16
compiler/cl/_testpy/callpy/in.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
"github.com/goplus/llgo/py/os"
|
||||
"github.com/goplus/llgo/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := math.Sqrt(py.Float(2))
|
||||
wd := os.Getcwd()
|
||||
c.Printf(c.Str("sqrt(2) = %f\n"), x.Float64())
|
||||
std.Print(py.Str("cwd ="), wd)
|
||||
}
|
||||
82
compiler/cl/_testpy/callpy/out.ll
Normal file
82
compiler/cl/_testpy/callpy/out.ll
Normal file
@@ -0,0 +1,82 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@__llgo_py.math.sqrt = linkonce global ptr null, align 8
|
||||
@__llgo_py.os.getcwd = linkonce global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [14 x i8] c"sqrt(2) = %f\0A\00", align 1
|
||||
@1 = private unnamed_addr constant [6 x i8] c"cwd =\00", align 1
|
||||
@__llgo_py.builtins.print = linkonce global ptr null, align 8
|
||||
@__llgo_py.builtins = external global ptr, align 8
|
||||
@2 = private unnamed_addr constant [6 x i8] c"print\00", align 1
|
||||
@__llgo_py.math = external global ptr, align 8
|
||||
@3 = private unnamed_addr constant [5 x i8] c"sqrt\00", align 1
|
||||
@__llgo_py.os = external global ptr, align 8
|
||||
@4 = private unnamed_addr constant [7 x i8] c"getcwd\00", align 1
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"main.init$guard", align 1
|
||||
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"main.init$guard", align 1
|
||||
call void @"github.com/goplus/llgo/py/math.init"()
|
||||
call void @"github.com/goplus/llgo/py/os.init"()
|
||||
call void @"github.com/goplus/llgo/py/std.init"()
|
||||
%1 = load ptr, ptr @__llgo_py.builtins, align 8
|
||||
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @2, ptr @__llgo_py.builtins.print, ptr null)
|
||||
%2 = load ptr, ptr @__llgo_py.math, align 8
|
||||
call void (ptr, ...) @llgoLoadPyModSyms(ptr %2, ptr @3, ptr @__llgo_py.math.sqrt, ptr null)
|
||||
%3 = load ptr, ptr @__llgo_py.os, align 8
|
||||
call void (ptr, ...) @llgoLoadPyModSyms(ptr %3, ptr @4, ptr @__llgo_py.os.getcwd, ptr null)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = call ptr @PyFloat_FromDouble(double 2.000000e+00)
|
||||
%3 = load ptr, ptr @__llgo_py.math.sqrt, align 8
|
||||
%4 = call ptr @PyObject_CallOneArg(ptr %3, ptr %2)
|
||||
%5 = load ptr, ptr @__llgo_py.os.getcwd, align 8
|
||||
%6 = call ptr @PyObject_CallNoArgs(ptr %5)
|
||||
%7 = call double @PyFloat_AsDouble(ptr %4)
|
||||
%8 = call i32 (ptr, ...) @printf(ptr @0, double %7)
|
||||
%9 = call ptr @PyUnicode_FromString(ptr @1)
|
||||
%10 = load ptr, ptr @__llgo_py.builtins.print, align 8
|
||||
%11 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %10, ptr %9, ptr %6, ptr null)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/py/math.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/py/os.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/py/std.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @PyFloat_FromDouble(double)
|
||||
|
||||
declare ptr @PyObject_CallOneArg(ptr, ptr)
|
||||
|
||||
declare ptr @PyObject_CallNoArgs(ptr)
|
||||
|
||||
declare double @PyFloat_AsDouble(ptr)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare ptr @PyUnicode_FromString(ptr)
|
||||
|
||||
declare ptr @PyObject_CallFunctionObjArgs(ptr, ...)
|
||||
|
||||
declare void @llgoLoadPyModSyms(ptr, ...)
|
||||
12
compiler/cl/_testpy/gcd/in.go
Normal file
12
compiler/cl/_testpy/gcd/in.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := math.Gcd(py.Long(60), py.Long(20), py.Long(25))
|
||||
c.Printf(c.Str("gcd(60, 20, 25) = %d\n"), x.Long())
|
||||
}
|
||||
56
compiler/cl/_testpy/gcd/out.ll
Normal file
56
compiler/cl/_testpy/gcd/out.ll
Normal file
@@ -0,0 +1,56 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@__llgo_py.math.gcd = linkonce global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [22 x i8] c"gcd(60, 20, 25) = %d\0A\00", align 1
|
||||
@__llgo_py.math = external global ptr, align 8
|
||||
@1 = private unnamed_addr constant [4 x i8] c"gcd\00", align 1
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"main.init$guard", align 1
|
||||
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"main.init$guard", align 1
|
||||
call void @"github.com/goplus/llgo/py/math.init"()
|
||||
%1 = load ptr, ptr @__llgo_py.math, align 8
|
||||
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @1, ptr @__llgo_py.math.gcd, ptr null)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = call ptr @PyLong_FromLong(i64 60)
|
||||
%3 = call ptr @PyLong_FromLong(i64 20)
|
||||
%4 = call ptr @PyLong_FromLong(i64 25)
|
||||
%5 = load ptr, ptr @__llgo_py.math.gcd, align 8
|
||||
%6 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %5, ptr %2, ptr %3, ptr %4, ptr null)
|
||||
%7 = call i64 @PyLong_AsLong(ptr %6)
|
||||
%8 = call i32 (ptr, ...) @printf(ptr @0, i64 %7)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/py/math.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @PyLong_FromLong(i64)
|
||||
|
||||
declare ptr @PyObject_CallFunctionObjArgs(ptr, ...)
|
||||
|
||||
declare i64 @PyLong_AsLong(ptr)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare void @llgoLoadPyModSyms(ptr, ...)
|
||||
14
compiler/cl/_testpy/math/in.go
Normal file
14
compiler/cl/_testpy/math/in.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package math
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/py"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "py.math"
|
||||
)
|
||||
|
||||
//go:linkname Sqrt py.sqrt
|
||||
func Sqrt(x *py.Object) *py.Object
|
||||
28
compiler/cl/_testpy/math/out.ll
Normal file
28
compiler/cl/_testpy/math/out.ll
Normal file
@@ -0,0 +1,28 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/cl/_testpy/math'
|
||||
source_filename = "github.com/goplus/llgo/cl/_testpy/math"
|
||||
|
||||
@"github.com/goplus/llgo/cl/_testpy/math.init$guard" = global i1 false, align 1
|
||||
@__llgo_py.math = linkonce global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [5 x i8] c"math\00", align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testpy/math.init"() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testpy/math.init$guard", align 1
|
||||
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"github.com/goplus/llgo/cl/_testpy/math.init$guard", align 1
|
||||
%1 = load ptr, ptr @__llgo_py.math, align 8
|
||||
%2 = icmp ne ptr %1, null
|
||||
br i1 %2, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_3, %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
%3 = call ptr @PyImport_ImportModule(ptr @0)
|
||||
store ptr %3, ptr @__llgo_py.math, align 8
|
||||
br label %_llgo_2
|
||||
}
|
||||
|
||||
declare ptr @PyImport_ImportModule(ptr)
|
||||
24
compiler/cl/_testpy/matrix/in.go
Normal file
24
compiler/cl/_testpy/matrix/in.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/numpy"
|
||||
)
|
||||
|
||||
func main() {
|
||||
a := py.List(
|
||||
py.List(1.0, 2.0, 3.0),
|
||||
py.List(4.0, 5.0, 6.0),
|
||||
py.List(7.0, 8.0, 9.0),
|
||||
)
|
||||
b := py.List(
|
||||
py.List(9.0, 8.0, 7.0),
|
||||
py.List(6.0, 5.0, 4.0),
|
||||
py.List(3.0, 2.0, 1.0),
|
||||
)
|
||||
x := numpy.Add(a, b)
|
||||
c.Printf(c.Str("a = %s\n"), a.Str().CStr())
|
||||
c.Printf(c.Str("a = %s\n"), b.Str().CStr())
|
||||
c.Printf(c.Str("a+b = %s\n"), x.Str().CStr())
|
||||
}
|
||||
118
compiler/cl/_testpy/matrix/out.ll
Normal file
118
compiler/cl/_testpy/matrix/out.ll
Normal file
@@ -0,0 +1,118 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@__llgo_py.numpy.add = linkonce global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [8 x i8] c"a = %s\0A\00", align 1
|
||||
@1 = private unnamed_addr constant [8 x i8] c"a = %s\0A\00", align 1
|
||||
@2 = private unnamed_addr constant [10 x i8] c"a+b = %s\0A\00", align 1
|
||||
@__llgo_py.numpy = external global ptr, align 8
|
||||
@3 = private unnamed_addr constant [4 x i8] c"add\00", align 1
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"main.init$guard", align 1
|
||||
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"main.init$guard", align 1
|
||||
call void @"github.com/goplus/llgo/py/numpy.init"()
|
||||
%1 = load ptr, ptr @__llgo_py.numpy, align 8
|
||||
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @3, ptr @__llgo_py.numpy.add, ptr null)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = call ptr @PyList_New(i64 3)
|
||||
%3 = call ptr @PyFloat_FromDouble(double 1.000000e+00)
|
||||
%4 = call i32 @PyList_SetItem(ptr %2, i64 0, ptr %3)
|
||||
%5 = call ptr @PyFloat_FromDouble(double 2.000000e+00)
|
||||
%6 = call i32 @PyList_SetItem(ptr %2, i64 1, ptr %5)
|
||||
%7 = call ptr @PyFloat_FromDouble(double 3.000000e+00)
|
||||
%8 = call i32 @PyList_SetItem(ptr %2, i64 2, ptr %7)
|
||||
%9 = call ptr @PyList_New(i64 3)
|
||||
%10 = call ptr @PyFloat_FromDouble(double 4.000000e+00)
|
||||
%11 = call i32 @PyList_SetItem(ptr %9, i64 0, ptr %10)
|
||||
%12 = call ptr @PyFloat_FromDouble(double 5.000000e+00)
|
||||
%13 = call i32 @PyList_SetItem(ptr %9, i64 1, ptr %12)
|
||||
%14 = call ptr @PyFloat_FromDouble(double 6.000000e+00)
|
||||
%15 = call i32 @PyList_SetItem(ptr %9, i64 2, ptr %14)
|
||||
%16 = call ptr @PyList_New(i64 3)
|
||||
%17 = call ptr @PyFloat_FromDouble(double 7.000000e+00)
|
||||
%18 = call i32 @PyList_SetItem(ptr %16, i64 0, ptr %17)
|
||||
%19 = call ptr @PyFloat_FromDouble(double 8.000000e+00)
|
||||
%20 = call i32 @PyList_SetItem(ptr %16, i64 1, ptr %19)
|
||||
%21 = call ptr @PyFloat_FromDouble(double 9.000000e+00)
|
||||
%22 = call i32 @PyList_SetItem(ptr %16, i64 2, ptr %21)
|
||||
%23 = call ptr @PyList_New(i64 3)
|
||||
%24 = call i32 @PyList_SetItem(ptr %23, i64 0, ptr %2)
|
||||
%25 = call i32 @PyList_SetItem(ptr %23, i64 1, ptr %9)
|
||||
%26 = call i32 @PyList_SetItem(ptr %23, i64 2, ptr %16)
|
||||
%27 = call ptr @PyList_New(i64 3)
|
||||
%28 = call ptr @PyFloat_FromDouble(double 9.000000e+00)
|
||||
%29 = call i32 @PyList_SetItem(ptr %27, i64 0, ptr %28)
|
||||
%30 = call ptr @PyFloat_FromDouble(double 8.000000e+00)
|
||||
%31 = call i32 @PyList_SetItem(ptr %27, i64 1, ptr %30)
|
||||
%32 = call ptr @PyFloat_FromDouble(double 7.000000e+00)
|
||||
%33 = call i32 @PyList_SetItem(ptr %27, i64 2, ptr %32)
|
||||
%34 = call ptr @PyList_New(i64 3)
|
||||
%35 = call ptr @PyFloat_FromDouble(double 6.000000e+00)
|
||||
%36 = call i32 @PyList_SetItem(ptr %34, i64 0, ptr %35)
|
||||
%37 = call ptr @PyFloat_FromDouble(double 5.000000e+00)
|
||||
%38 = call i32 @PyList_SetItem(ptr %34, i64 1, ptr %37)
|
||||
%39 = call ptr @PyFloat_FromDouble(double 4.000000e+00)
|
||||
%40 = call i32 @PyList_SetItem(ptr %34, i64 2, ptr %39)
|
||||
%41 = call ptr @PyList_New(i64 3)
|
||||
%42 = call ptr @PyFloat_FromDouble(double 3.000000e+00)
|
||||
%43 = call i32 @PyList_SetItem(ptr %41, i64 0, ptr %42)
|
||||
%44 = call ptr @PyFloat_FromDouble(double 2.000000e+00)
|
||||
%45 = call i32 @PyList_SetItem(ptr %41, i64 1, ptr %44)
|
||||
%46 = call ptr @PyFloat_FromDouble(double 1.000000e+00)
|
||||
%47 = call i32 @PyList_SetItem(ptr %41, i64 2, ptr %46)
|
||||
%48 = call ptr @PyList_New(i64 3)
|
||||
%49 = call i32 @PyList_SetItem(ptr %48, i64 0, ptr %27)
|
||||
%50 = call i32 @PyList_SetItem(ptr %48, i64 1, ptr %34)
|
||||
%51 = call i32 @PyList_SetItem(ptr %48, i64 2, ptr %41)
|
||||
%52 = load ptr, ptr @__llgo_py.numpy.add, align 8
|
||||
%53 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %52, ptr %23, ptr %48, ptr null)
|
||||
%54 = call ptr @PyObject_Str(ptr %23)
|
||||
%55 = call ptr @PyUnicode_AsUTF8(ptr %54)
|
||||
%56 = call i32 (ptr, ...) @printf(ptr @0, ptr %55)
|
||||
%57 = call ptr @PyObject_Str(ptr %48)
|
||||
%58 = call ptr @PyUnicode_AsUTF8(ptr %57)
|
||||
%59 = call i32 (ptr, ...) @printf(ptr @1, ptr %58)
|
||||
%60 = call ptr @PyObject_Str(ptr %53)
|
||||
%61 = call ptr @PyUnicode_AsUTF8(ptr %60)
|
||||
%62 = call i32 (ptr, ...) @printf(ptr @2, ptr %61)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/py/numpy.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @PyList_New(i64)
|
||||
|
||||
declare ptr @PyFloat_FromDouble(double)
|
||||
|
||||
declare i32 @PyList_SetItem(ptr, i64, ptr)
|
||||
|
||||
declare ptr @PyObject_CallFunctionObjArgs(ptr, ...)
|
||||
|
||||
declare ptr @PyObject_Str(ptr)
|
||||
|
||||
declare ptr @PyUnicode_AsUTF8(ptr)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare void @llgoLoadPyModSyms(ptr, ...)
|
||||
19
compiler/cl/_testpy/max/in.go
Normal file
19
compiler/cl/_testpy/max/in.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/std"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := std.Max(py.Float(3.0), py.Float(9.0), py.Float(23.0), py.Float(100.0))
|
||||
std.Print(x)
|
||||
|
||||
list := py.List(3.0, 9.0, 23.0, 100.0)
|
||||
y := std.Max(std.Iter(list))
|
||||
std.Print(y)
|
||||
|
||||
tuple := py.Tuple(1.0, 2.0, 3.0)
|
||||
z := std.Max(std.Iter(tuple))
|
||||
std.Print(z)
|
||||
}
|
||||
94
compiler/cl/_testpy/max/out.ll
Normal file
94
compiler/cl/_testpy/max/out.ll
Normal file
@@ -0,0 +1,94 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@__llgo_py.builtins.max = linkonce global ptr null, align 8
|
||||
@__llgo_py.builtins.print = linkonce global ptr null, align 8
|
||||
@__llgo_py.builtins.iter = linkonce global ptr null, align 8
|
||||
@__llgo_py.builtins = external global ptr, align 8
|
||||
@0 = private unnamed_addr constant [5 x i8] c"iter\00", align 1
|
||||
@1 = private unnamed_addr constant [4 x i8] c"max\00", align 1
|
||||
@2 = private unnamed_addr constant [6 x i8] c"print\00", align 1
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"main.init$guard", align 1
|
||||
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"main.init$guard", align 1
|
||||
call void @"github.com/goplus/llgo/py/std.init"()
|
||||
%1 = load ptr, ptr @__llgo_py.builtins, align 8
|
||||
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @0, ptr @__llgo_py.builtins.iter, ptr @1, ptr @__llgo_py.builtins.max, ptr @2, ptr @__llgo_py.builtins.print, ptr null)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = call ptr @PyFloat_FromDouble(double 3.000000e+00)
|
||||
%3 = call ptr @PyFloat_FromDouble(double 9.000000e+00)
|
||||
%4 = call ptr @PyFloat_FromDouble(double 2.300000e+01)
|
||||
%5 = call ptr @PyFloat_FromDouble(double 1.000000e+02)
|
||||
%6 = load ptr, ptr @__llgo_py.builtins.max, align 8
|
||||
%7 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %6, ptr %2, ptr %3, ptr %4, ptr %5, ptr null)
|
||||
%8 = load ptr, ptr @__llgo_py.builtins.print, align 8
|
||||
%9 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %8, ptr %7, ptr null)
|
||||
%10 = call ptr @PyList_New(i64 4)
|
||||
%11 = call ptr @PyFloat_FromDouble(double 3.000000e+00)
|
||||
%12 = call i32 @PyList_SetItem(ptr %10, i64 0, ptr %11)
|
||||
%13 = call ptr @PyFloat_FromDouble(double 9.000000e+00)
|
||||
%14 = call i32 @PyList_SetItem(ptr %10, i64 1, ptr %13)
|
||||
%15 = call ptr @PyFloat_FromDouble(double 2.300000e+01)
|
||||
%16 = call i32 @PyList_SetItem(ptr %10, i64 2, ptr %15)
|
||||
%17 = call ptr @PyFloat_FromDouble(double 1.000000e+02)
|
||||
%18 = call i32 @PyList_SetItem(ptr %10, i64 3, ptr %17)
|
||||
%19 = load ptr, ptr @__llgo_py.builtins.iter, align 8
|
||||
%20 = call ptr @PyObject_CallOneArg(ptr %19, ptr %10)
|
||||
%21 = load ptr, ptr @__llgo_py.builtins.max, align 8
|
||||
%22 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %21, ptr %20, ptr null)
|
||||
%23 = load ptr, ptr @__llgo_py.builtins.print, align 8
|
||||
%24 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %23, ptr %22, ptr null)
|
||||
%25 = call ptr @PyTuple_New(i64 3)
|
||||
%26 = call ptr @PyFloat_FromDouble(double 1.000000e+00)
|
||||
%27 = call i32 @PyTuple_SetItem(ptr %25, i64 0, ptr %26)
|
||||
%28 = call ptr @PyFloat_FromDouble(double 2.000000e+00)
|
||||
%29 = call i32 @PyTuple_SetItem(ptr %25, i64 1, ptr %28)
|
||||
%30 = call ptr @PyFloat_FromDouble(double 3.000000e+00)
|
||||
%31 = call i32 @PyTuple_SetItem(ptr %25, i64 2, ptr %30)
|
||||
%32 = load ptr, ptr @__llgo_py.builtins.iter, align 8
|
||||
%33 = call ptr @PyObject_CallOneArg(ptr %32, ptr %25)
|
||||
%34 = load ptr, ptr @__llgo_py.builtins.max, align 8
|
||||
%35 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %34, ptr %33, ptr null)
|
||||
%36 = load ptr, ptr @__llgo_py.builtins.print, align 8
|
||||
%37 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %36, ptr %35, ptr null)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/py/std.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @PyFloat_FromDouble(double)
|
||||
|
||||
declare ptr @PyObject_CallFunctionObjArgs(ptr, ...)
|
||||
|
||||
declare ptr @PyList_New(i64)
|
||||
|
||||
declare i32 @PyList_SetItem(ptr, i64, ptr)
|
||||
|
||||
declare ptr @PyObject_CallOneArg(ptr, ptr)
|
||||
|
||||
declare ptr @PyTuple_New(i64)
|
||||
|
||||
declare i32 @PyTuple_SetItem(ptr, i64, ptr)
|
||||
|
||||
declare void @llgoLoadPyModSyms(ptr, ...)
|
||||
10
compiler/cl/_testpy/pi/in.go
Normal file
10
compiler/cl/_testpy/pi/in.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("pi = %f\n"), math.Pi.Float64())
|
||||
}
|
||||
46
compiler/cl/_testpy/pi/out.ll
Normal file
46
compiler/cl/_testpy/pi/out.ll
Normal file
@@ -0,0 +1,46 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [9 x i8] c"pi = %f\0A\00", align 1
|
||||
@__llgo_py.math = external global ptr, align 8
|
||||
@1 = private unnamed_addr constant [3 x i8] c"pi\00", align 1
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"main.init$guard", align 1
|
||||
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"main.init$guard", align 1
|
||||
call void @"github.com/goplus/llgo/py/math.init"()
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = load ptr, ptr @__llgo_py.math, align 8
|
||||
%3 = call ptr @PyObject_GetAttrString(ptr %2, ptr @1)
|
||||
%4 = call double @PyFloat_AsDouble(ptr %3)
|
||||
%5 = call i32 (ptr, ...) @printf(ptr @0, double %4)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/py/math.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @PyObject_GetAttrString(ptr, ptr)
|
||||
|
||||
declare double @PyFloat_AsDouble(ptr)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
12
compiler/cl/_testpy/pow/in.go
Normal file
12
compiler/cl/_testpy/pow/in.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := math.Pow(py.Float(2), py.Float(3))
|
||||
c.Printf(c.Str("pow(2, 3) = %f\n"), x.Float64())
|
||||
}
|
||||
55
compiler/cl/_testpy/pow/out.ll
Normal file
55
compiler/cl/_testpy/pow/out.ll
Normal file
@@ -0,0 +1,55 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@__llgo_py.math.pow = linkonce global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [16 x i8] c"pow(2, 3) = %f\0A\00", align 1
|
||||
@__llgo_py.math = external global ptr, align 8
|
||||
@1 = private unnamed_addr constant [4 x i8] c"pow\00", align 1
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"main.init$guard", align 1
|
||||
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"main.init$guard", align 1
|
||||
call void @"github.com/goplus/llgo/py/math.init"()
|
||||
%1 = load ptr, ptr @__llgo_py.math, align 8
|
||||
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @1, ptr @__llgo_py.math.pow, ptr null)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = call ptr @PyFloat_FromDouble(double 2.000000e+00)
|
||||
%3 = call ptr @PyFloat_FromDouble(double 3.000000e+00)
|
||||
%4 = load ptr, ptr @__llgo_py.math.pow, align 8
|
||||
%5 = call ptr (ptr, ...) @PyObject_CallFunctionObjArgs(ptr %4, ptr %2, ptr %3, ptr null)
|
||||
%6 = call double @PyFloat_AsDouble(ptr %5)
|
||||
%7 = call i32 (ptr, ...) @printf(ptr @0, double %6)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/py/math.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @PyFloat_FromDouble(double)
|
||||
|
||||
declare ptr @PyObject_CallFunctionObjArgs(ptr, ...)
|
||||
|
||||
declare double @PyFloat_AsDouble(ptr)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare void @llgoLoadPyModSyms(ptr, ...)
|
||||
Reference in New Issue
Block a user