Compare commits

..

128 Commits

Author SHA1 Message Date
xushiwei
908f0047f8 Merge pull request #199 from visualfc/index
ssa: checkIndex for index/indexAddr
2024-05-18 16:48:26 +08:00
xushiwei
e533903cee Merge pull request #202 from xushiwei/q
py/torch; llpyg: use pysigfetch (by goplus/hdq)
2024-05-18 16:46:56 +08:00
xushiwei
1be8052caa llpyg: fix pysigfetch error handling 2024-05-18 16:45:02 +08:00
xushiwei
668ce4bd2d py/torch; llpyg: use pysigfetch (by goplus/hdq) 2024-05-18 16:03:49 +08:00
visualfc
e7fd038493 ssa: checkIndex for index/indexAddr 2024-05-18 11:08:39 +08:00
visualfc
03edb3bbbe runtime: assertRuntimeError assertNegativeShift assertIndexRange 2024-05-18 10:16:57 +08:00
xushiwei
307a1a295a Merge pull request #201 from xushiwei/q
mv x/ => c/
2024-05-17 22:43:39 +08:00
xushiwei
446df58e92 TestSqlite 2024-05-17 22:41:39 +08:00
xushiwei
1ad5caba93 cl: _testlibc/sqlite fix 2024-05-17 22:38:32 +08:00
xushiwei
9eddc0e4f0 submodule c/llama2/llama2.c 2024-05-17 22:34:34 +08:00
xushiwei
087ba0d81d mv x/ => c/ 2024-05-17 22:33:57 +08:00
xushiwei
3c5cd8f38f Merge pull request #200 from xushiwei/q
py/torch
2024-05-17 21:50:00 +08:00
xushiwei
367743530f py/torch 2024-05-17 21:46:38 +08:00
xushiwei
7370ce2793 Merge pull request #198 from xushiwei/q
Cstr (for Go+)
2024-05-17 21:19:51 +08:00
xushiwei
ba61b42ef5 Cstr (for Go+) 2024-05-17 21:14:41 +08:00
xushiwei
f7e362dd90 Merge pull request #197 from visualfc/global_array
ssa: fix global array
2024-05-17 19:38:51 +08:00
visualfc
66da072fd7 ssa: fix global array 2024-05-17 19:30:56 +08:00
xushiwei
d763534208 Merge pull request #196 from xushiwei/q
build: checkFlag fix (for Go+)
2024-05-17 13:57:31 +08:00
xushiwei
ad05898543 build: checkFlag fix (for Go+) 2024-05-17 13:54:00 +08:00
xushiwei
f930f7878d Merge pull request #195 from xushiwei/q
cl: out.ll regen
2024-05-17 11:16:58 +08:00
xushiwei
d6a75c411b _testpy/pi 2024-05-17 11:14:19 +08:00
xushiwei
568a71e0dc cl: out.ll regen 2024-05-17 11:11:22 +08:00
xushiwei
c92e9aac2c Merge pull request #189 from tsingbx/main_return_0
Main return 0
2024-05-17 11:09:20 +08:00
xushiwei
3012c4a3ff Merge branch 'main' into main_return_0 2024-05-17 11:05:09 +08:00
xushiwei
ebe338ac9a Merge pull request #193 from visualfc/type
ssa: type uint/byte/int32/uint32/int64/uint64
2024-05-17 11:04:12 +08:00
tsingbx
a45523a48c run gentests 2024-05-17 09:48:21 +08:00
tsingbx
5bfeea67d7 change main return to C int 2024-05-17 09:31:48 +08:00
visualfc
f35f15d36c ssa: type uint/byte/int32/uint32/int64/uint64 2024-05-17 09:28:57 +08:00
tsingbx
057af792df main return type chang to C int 2024-05-17 09:06:53 +08:00
xushiwei
41a850e7b2 Merge pull request #194 from xushiwei/q
py/{numpy, pandas}
2024-05-17 09:04:56 +08:00
xushiwei
6be70390a6 py/{numpy, pandas} 2024-05-17 09:01:36 +08:00
xushiwei
1cfe3ee9f8 Merge pull request #192 from xushiwei/q
pysig.Parse; py/pandas
2024-05-17 05:30:18 +08:00
xushiwei
c1927c985a pysig.Parse; py/pandas 2024-05-17 05:25:13 +08:00
xushiwei
309f42994b Merge pull request #191 from visualfc/castint
ssa: fix castInt
2024-05-16 21:20:23 +08:00
visualfc
feb28ecace ssa: fix castInt 2024-05-16 20:43:16 +08:00
xushiwei
00f74b7f0a Merge pull request #190 from xushiwei/q
build fix: -L dir
2024-05-16 18:42:45 +08:00
xushiwei
fcc0e1776b build fix: -L dir 2024-05-16 18:40:49 +08:00
xushiwei
a5ec755c28 Merge pull request #188 from visualfc/shift_check
ssa: binop check shl/shr
2024-05-16 18:04:25 +08:00
visualfc
98945926ca ssa: binop check shl/shr 2024-05-16 16:27:49 +08:00
tsingbx
d3e3767df4 Merge branch 'main' of https://github.com/goplus/llgo into main_return_0 2024-05-16 15:35:05 +08:00
tsingbx
de1281bb66 Add return value to llvm's ir main function definition 2024-05-16 15:27:14 +08:00
xushiwei
07e55c3d89 Merge pull request #187 from visualfc/shift
ssa: binop fix shl/shr size
2024-05-16 10:48:03 +08:00
visualfc
6e4ebeddf4 ssa: binop fix shl/shr size 2024-05-16 10:20:02 +08:00
xushiwei
2b9fb88bf0 Merge pull request #183 from visualfc/print
ssa: builtin print/println
2024-05-16 09:40:14 +08:00
visualfc
022965b9c7 ssa: builtin print/println 2024-05-16 09:33:25 +08:00
xushiwei
6278718a24 Merge pull request #186 from xushiwei/q
README: Key modules
2024-05-16 07:08:46 +08:00
xushiwei
1675daafcd Key modules 2024-05-16 07:08:10 +08:00
xushiwei
ed5b6edf52 Merge pull request #185 from xushiwei/q
README: Development tools
2024-05-16 06:34:55 +08:00
xushiwei
638caa355c Development tools 2024-05-16 06:34:18 +08:00
xushiwei
78b2f9b455 Update README.md 2024-05-16 01:08:21 +08:00
xushiwei
2a35ffcc27 Merge pull request #184 from xushiwei/q
README
2024-05-16 00:06:24 +08:00
xushiwei
5eae8f9af6 README 2024-05-16 00:02:10 +08:00
xushiwei
25381e20d2 TestSqlite 2024-05-15 21:43:38 +08:00
xushiwei
fc35ff5cd1 Merge pull request #182 from xushiwei/q
sqlite demo
2024-05-15 21:39:00 +08:00
xushiwei
b10d00b426 rm TestSqlite 2024-05-15 21:36:48 +08:00
xushiwei
c634dc25b4 sqlite demo 2024-05-15 21:27:42 +08:00
xushiwei
2fb4561bf8 Merge pull request #181 from xushiwei/q
rm submodule sqlite
2024-05-15 21:14:10 +08:00
xushiwei
f167c6dcca rm submodule sqlite 2024-05-15 21:12:58 +08:00
xushiwei
555ace9e2e Merge pull request #179 from xushiwei/q
llgo/ssa: PyNewVar; pyLoad
2024-05-15 18:49:10 +08:00
xushiwei
d07ffb36ad TestUserdefExpr: pyVarTy 2024-05-15 18:45:53 +08:00
xushiwei
9e2b8b77c9 py/math: remove vars 2024-05-15 18:40:54 +08:00
xushiwei
29e4af4fb2 llgo/ssa: PyNewVar; pyLoad 2024-05-15 18:32:50 +08:00
xushiwei
91513a12b4 llgo/ssa: refactor python related names (PyXXX) 2024-05-15 17:19:47 +08:00
xushiwei
ee3f55dd41 compileGlobal: skip pyVar 2024-05-15 16:51:44 +08:00
xushiwei
c2e5a78076 compileFuncDecl remove param: call bool 2024-05-15 16:40:10 +08:00
xushiwei
da3ac3e93d Merge pull request #178 from xushiwei/q
README: python support
2024-05-15 16:05:01 +08:00
xushiwei
278ebbc9bd README: python support 2024-05-15 16:04:20 +08:00
xushiwei
546f93147e Merge pull request #177 from xushiwei/q
llgo instr: pyList
2024-05-15 15:46:18 +08:00
xushiwei
3e7bfbb45c llgo instr: pyList 2024-05-15 15:42:58 +08:00
xushiwei
c2cf0443ef Merge remote-tracking branch 'gop/main' into q 2024-05-15 14:49:25 +08:00
xushiwei
59d68c6438 llgo/ssa: PyList 2024-05-15 14:49:00 +08:00
xushiwei
e0ee199bf1 Merge pull request #176 from xushiwei/q
numpy demo: _pydemo/matrix
2024-05-15 13:59:43 +08:00
xushiwei
c1bf895674 llpyg: numpy/inspect 2024-05-15 13:57:26 +08:00
xushiwei
ea4d92e671 py/os fix 2024-05-15 13:51:58 +08:00
xushiwei
e3f56105d4 numpy demo: _pydemo/matrix 2024-05-15 13:49:19 +08:00
xushiwei
c447a87605 Merge pull request #175 from xushiwei/q
cl: _testpy/gcd
2024-05-15 13:33:56 +08:00
xushiwei
584e5b1f01 TestPrintf fix 2024-05-15 13:30:48 +08:00
xushiwei
207dc4c112 Merge pull request #174 from visualfc/append
ssa: add builtin append
2024-05-15 13:27:58 +08:00
xushiwei
6a3581f7a3 goTypes.cvtFunc fix: remove sig.Variadic flag 2024-05-15 13:24:44 +08:00
xushiwei
11e74975b3 llgo/ssa: rm HasVArg/IsVArg 2024-05-15 13:09:43 +08:00
xushiwei
75ef9ec524 x 2024-05-15 12:01:36 +08:00
xushiwei
9b742e777b cl: _testpy/gcd 2024-05-15 11:59:53 +08:00
visualfc
5d93565e16 ssa: add builtin append 2024-05-15 10:43:26 +08:00
xushiwei
cebfe5c95b Merge pull request #173 from xushiwei/q
cl: _testpy/pow (multiargs)
2024-05-15 08:57:09 +08:00
xushiwei
7881f3a53b x 2024-05-15 08:54:29 +08:00
xushiwei
56269bd52b cl: _testpy/pow (multiargs) 2024-05-15 08:44:00 +08:00
xushiwei
68c43a2cc9 Merge pull request #172 from xushiwei/q
py/numpy
2024-05-15 00:33:10 +08:00
xushiwei
120b507c75 numpy: array, etc 2024-05-15 00:29:54 +08:00
xushiwei
44fe7e8dc4 py/numpy 2024-05-14 23:56:55 +08:00
xushiwei
75d679f141 Merge pull request #171 from xushiwei/q
py/sys; llpyg: prompt import mod fail; py: fix typo
2024-05-14 22:36:03 +08:00
xushiwei
e9570f2400 llpyg: prompt import mod fail; py: fix typo 2024-05-14 22:33:36 +08:00
xushiwei
5b8567310c Merge pull request #170 from xushiwei/q
py/json, py/statistics; demo: statistics.mean
2024-05-14 21:08:14 +08:00
xushiwei
f882221db3 py/math 2024-05-14 21:06:25 +08:00
xushiwei
8c4d7bd641 py/json, py/statistics; demo: statistics.mean 2024-05-14 20:53:13 +08:00
xushiwei
6a78695fde Merge pull request #169 from xushiwei/q
llpyg fix: handle / in sig; llpyg math
2024-05-14 20:17:24 +08:00
xushiwei
73ad16dedd llpyg fix: handle / in sig 2024-05-14 20:14:59 +08:00
xushiwei
dd98112c5a Merge pull request #168 from xushiwei/q
llpyg os
2024-05-14 19:40:49 +08:00
xushiwei
47521d3579 llpyg fix: empty params 2024-05-14 19:38:30 +08:00
xushiwei
0c31300578 llpyg os 2024-05-14 19:19:46 +08:00
xushiwei
6340ff7da0 Merge pull request #166 from visualfc/stringcat
ssa: fix binop string cat ret type
2024-05-14 18:23:51 +08:00
xushiwei
b66cb49d80 Merge pull request #167 from xushiwei/q
llpyg
2024-05-14 18:22:41 +08:00
xushiwei
c884184220 py llgen 2024-05-14 18:19:44 +08:00
xushiwei
091fee61e0 llpyg: pkg.NewFuncDecl 2024-05-14 18:16:32 +08:00
xushiwei
172a268e77 llpyg: ready to test 2024-05-14 17:22:36 +08:00
visualfc
924715fe34 ssa: fix binop string cat ret type 2024-05-14 15:58:33 +08:00
xushiwei
35a73b4cde llpyg: todo 2024-05-14 15:34:53 +08:00
xushiwei
238f9593f9 Update README.md 2024-05-14 13:34:47 +08:00
xushiwei
9e8b5703dc Merge pull request #165 from xushiwei/q
llpyg => pydump
2024-05-14 13:27:51 +08:00
xushiwei
d8bd8be57e llpyg => pydump 2024-05-14 13:23:21 +08:00
xushiwei
a4d4e8b3a9 Merge pull request #164 from xushiwei/q
llgo/x/cjson
2024-05-14 11:52:22 +08:00
xushiwei
703dd17e33 llgo/x/cjson 2024-05-14 11:49:37 +08:00
xushiwei
bc654a462e Merge pull request #162 from xushiwei/q
build: support packages out of llgo
2024-05-14 08:49:11 +08:00
xushiwei
11535825c0 build: support packages out of llgo 2024-05-14 08:40:42 +08:00
xushiwei
196df40c99 Merge pull request #161 from xushiwei/q
llpyg sig fix
2024-05-14 00:34:58 +08:00
xushiwei
7aee6c3a15 llpyg sig fix 2024-05-14 00:31:30 +08:00
xushiwei
372b566d23 mv _xtool => chore/_xtool 2024-05-13 23:03:54 +08:00
xushiwei
9550354442 Merge pull request #160 from xushiwei/q
llpyg: todo
2024-05-13 22:12:17 +08:00
xushiwei
95c3ddfc39 math 2024-05-13 22:05:49 +08:00
xushiwei
bf4f2b6fa0 py/builtins: todo 2024-05-13 22:02:47 +08:00
xushiwei
d3f75a92ad llpyg: print doc 2024-05-13 21:01:39 +08:00
xushiwei
369495c8d3 Merge pull request #159 from xushiwei/q
llpyg: use inspect.Signature
2024-05-13 19:51:05 +08:00
xushiwei
dd52f71069 llpyg: use inspect.Signature 2024-05-13 19:48:33 +08:00
xushiwei
af8e2bc19d Merge pull request #158 from xushiwei/q
_xtool: llpyg
2024-05-13 18:34:33 +08:00
xushiwei
947e5591ea py llgo_autogen 2024-05-13 18:32:43 +08:00
xushiwei
521376e8e8 py 2024-05-13 18:29:00 +08:00
xushiwei
55c0adb23d _testpy/callpy fix 2024-05-13 18:25:05 +08:00
xushiwei
b20ad7047f _xtool: llpyg 2024-05-13 18:24:00 +08:00
xushiwei
fa3149c660 Update README.md 2024-05-13 01:27:02 +08:00
151 changed files with 29999 additions and 1169 deletions

1
.gitignore vendored
View File

@@ -13,6 +13,7 @@ llgo_autogen.ll
stories*.bin stories*.bin
.DS_Store .DS_Store
err.log err.log
numpy.txt
_go/ _go/
_runtime/ _runtime/

7
.gitmodules vendored
View File

@@ -1,6 +1,3 @@
[submodule "x/llama2/llama2.c"] [submodule "c/llama2/llama2.c"]
path = x/llama2/llama2.c path = c/llama2/llama2.c
url = https://github.com/karpathy/llama2.c.git url = https://github.com/karpathy/llama2.c.git
[submodule "x/sqlite/sqlite"]
path = x/sqlite/sqlite
url = https://github.com/sqlite/sqlite.git

192
README.md
View File

@@ -8,7 +8,8 @@ llgo - A Go compiler based on LLVM
[![GoDoc](https://pkg.go.dev/badge/github.com/goplus/llgo.svg)](https://pkg.go.dev/github.com/goplus/llgo) [![GoDoc](https://pkg.go.dev/badge/github.com/goplus/llgo.svg)](https://pkg.go.dev/github.com/goplus/llgo)
[![Language](https://img.shields.io/badge/language-Go+-blue.svg)](https://github.com/goplus/gop) [![Language](https://img.shields.io/badge/language-Go+-blue.svg)](https://github.com/goplus/gop)
This is a Go compiler based on LLVM in order to better integrate Go with the C ecosystem including Python. It's a subproject of [the Go+ project](https://github.com/goplus/gop). LLGo is a Go compiler based on LLVM in order to better integrate Go with the C ecosystem including Python. It's a subproject of [the Go+ project](https://github.com/goplus/gop).
## C standard libary support ## C standard libary support
@@ -22,14 +23,40 @@ func main() {
} }
``` ```
This is a simple example of calling the C `printf` function to print `Hello world`. Here, `c.Str` is not a function for converting a Go string to a C string, but a built-in instruction supported by llgo for generating a C string constant. This is a simple example of calling the C `printf` function to print `Hello world`. Here, `c.Str` is not a function for converting a Go string to a C string, but a built-in instruction supported by `llgo` for generating a C string constant.
The `_demo` directory contains some C standard libary related demos (it start with `_` to prevent the `go` command from compiling it):
* [hello](_demo/hello/hello.go): call C `printf` to print `Hello world`
* [concat](_demo/concat/concat.go): call C `fprintf` with `stderr`
* [qsort](_demo/qsort/qsort.go): call C function with a callback (eg. `qsort`)
To run these demos (If you haven't installed `llgo` yet, please refer to [How to install](#how-to-install)):
```sh
export LLGOROOT=`pwd`
cd <demo-directory> # eg. cd _demo/hello
llgo run .
```
See [github.com/goplus/llgo/c](https://pkg.go.dev/github.com/goplus/llgo/c) for more detials. See [github.com/goplus/llgo/c](https://pkg.go.dev/github.com/goplus/llgo/c) for more detials.
## Python support ## Python support
You can import a Python library in llgo! For example: You can import a Python library in LLGo!
And you can import any Python library into `llgo` through a program called `llpyg` (see [Development tools](#development-tools)). The currently imported libraries include:
* [sys](https://pkg.go.dev/github.com/goplus/llgo/py/sys)
* [os](https://pkg.go.dev/github.com/goplus/llgo/py/os)
* [math](https://pkg.go.dev/github.com/goplus/llgo/py/math)
* [json](https://pkg.go.dev/github.com/goplus/llgo/py/json)
* [inspect](https://pkg.go.dev/github.com/goplus/llgo/py/inspect)
* [statistics](https://pkg.go.dev/github.com/goplus/llgo/py/statistics)
* [numpy](https://pkg.go.dev/github.com/goplus/llgo/py/numpy)
Here is an example using the Python `math` library:
```go ```go
package main package main
@@ -46,12 +73,119 @@ func main() {
} }
``` ```
Here, We call `py.Float(2)` to create a Python floating point number 2, and pass it to Pythons `math.sqrt` to get `x`. Then use `x.Float64()` to convert the Python object to Go's `float64` type, and finally we print the value through C `printf`. Here, We call `py.Float(2)` to create a Python number 2, and pass it to Pythons `math.sqrt` to get `x`. Then use `x.Float64()` to convert x to Go's `float64` type, and print the value through the C `printf` function.
Let's look at a slightly more complex example. For example, we use `numpy` to calculate:
```go
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+b = %s\n"), x.Str().CStr())
}
```
Here we define two 3x3 matrices a and b, add them to get x, and then print the result.
The `_pydemo` directory contains some python related demos:
* [callpy](_pydemo/callpy/callpy.go): call Python standard library function `math.sqrt`
* [pi](_pydemo/pi/pi.go): print python constants `math.pi`
* [statistics](_pydemo/statistics/statistics.go): define a python list and call `statistics.mean` to get the mean
* [matrix](_pydemo/matrix/matrix.go): a basic `numpy` demo
To run these demos, you need to set the `LLGO_LIB_PYTHON` environment variable first.
If Python is in the search path for `clang` linking, then `LLGO_LIB_PYTHON` only needs to be set to the name of the Python library. For example:
```sh
export LLGO_LIB_PYTHON=python3.12
```
You can also specify the path to tell `llgo` where the Python library is located:
```sh
export LLGO_LIB_PYTHON=/foo/bar/python3.12
```
For example, `/opt/homebrew/Frameworks/Python.framework/Versions/3.12/libpython3.12.dylib` is a typical python library location under macOS. So we should set it like this:
```sh
export LLGO_LIB_PYTHON=/opt/homebrew/Frameworks/Python.framework/Versions/3.12/python3.12
```
Note that the file name must be written in a platform-independent format, using `python3.12` instead of `libpython3.12.dylib`.
Then you can run the demos:
```sh
export LLGOROOT=`pwd`
cd <demo-directory> # eg. cd _pydemo/callpy
llgo run .
```
See [github.com/goplus/llgo/py](https://pkg.go.dev/github.com/goplus/llgo/py) for more detials.
## Other frequently used libraries ## Other frequently used libraries
TODO LLGo can easily import any libraries from the C ecosystem. Currently, this import process is still manual, but in the future, it will be automated similar to Python library imports.
The currently imported libraries include:
* [llama2.c](https://pkg.go.dev/github.com/goplus/llgo/c/llama2)
* [cjson](https://pkg.go.dev/github.com/goplus/llgo/c/cjson)
* [sqlite](https://pkg.go.dev/github.com/goplus/llgo/c/sqlite)
Here are some examples related to them:
* [llama2-c](_demo/llama2-c): inference Llama 2 (It's the first llgo AI example)
* [mkjson](c/cjson/_demo/mkjson/mkjson.go): create a json object and print it
* [sqlitedemo](c/sqlite/_demo/sqlitedemo/demo.go): a basic sqlite demo
## Go syntax support
The priority of `llgo` feature iteration is:
* Popular C/Python libraries
* Full Go syntax
* Go standard libraries
* Popular Go packages
Common Go syntax is already supported. Except for the following, which needs to be improved:
* interface (Limited support)
* map (Very limited support)
* panic (Limited support)
* recover (Not supported yet)
* defer (Not supported yet)
* gc (Not supported yet)
* chan (Not supported yet)
* goroutine (Not supported yet)
* generics (Not supported yet)
Here are some examples related to Go syntax:
* [concat](_demo/concat/concat.go): define a variadic function
* [genints](_demo/genints/genints.go): various forms of closure usage (including C function, recv.method and anonymous function)
## How to install ## How to install
@@ -81,45 +215,25 @@ go install -v ./...
TODO TODO
## Demo ## Development tools
The `_demo` directory contains our demos (it start with `_` to prevent the `go` command from compiling it): * [pydump](chore/_xtool/pydump): It's the first program compiled by `llgo` (NOT `go`) in a production environment. It outputs symbol information (functions, variables, and constants) from a Python library in JSON format, preparing for the generation of corresponding packages in `llgo`.
* [llpyg](chore/llpyg): It is used to automatically convert Python libraries into Go packages that `llgo` can import. It depends on `pydump` to accomplish the task.
* [llgen](chore/llgen): It is used to compile Go packages into LLVM IR files (*.ll).
* [ssadump](chore/ssadump): It is a Go SSA builder and interpreter.
* [hello](_demo/hello/hello.go): call C printf to print `Hello world` How do I generate these tools?
* [concat](_demo/concat/concat.go): call C fprintf with stderr, and Go variadic function
* [qsort](_demo/qsort/qsort.go): call C function with a callback (eg. qsort)
* [genints](_demo/genints/genints.go): various forms of closure usage (including C function, recv.method and anonymous function)
* [llama2-c](_demo/llama2-c): inference Llama 2 (It's the first llgo AI example)
And the `_pydemo` directory contains python related demos:
* [callpy](_pydemo/callpy/callpy.go): call Python standard library function `math.sqrt`
### How to run demos
To run the demos in directory `_demo`:
```sh ```sh
cd <demo-directory> # eg. cd _demo/genints go install -v ./... # compile all tools except pydump
llgo run . cd chore/_xtool
llgo install ./... # compile pydump
``` ```
To run the demos in directory `_pydemo`, you need to set the `LLGO_LIB_PYTHON` environment variable first. Assuming you use Python 3.12, and the `libpython3.12.so` (or `libpython3.12.dylib` or `python3.12.lib`) file is in the /foo/bar directory, then you need to set `LLGO_LIB_PYTHON` to: ## Key modules
```sh Below are the key modules for understanding the implementation principles of `llgo`:
export LLGO_LIB_PYTHON=/foo/bar/python3.12
```
For example, `/opt/homebrew/Frameworks/Python.framework/Versions/3.12/libpython3.12.dylib` is a typical python lib location under macOS. So we should set it like this: * [llgo/ssa](https://pkg.go.dev/github.com/goplus/llgo/ssa): It generates LLVM IR files (LLVM SSA) using the semantics (interfaces) of Go SSA. Although `LLVM SSA` and `Go SSA` are both IR languages, they work at completely different levels. `LLVM SSA` is closer to machine code, which abstracts different instruction sets. While `Go SSA` is closer to a high-level language. We can think of it as the instruction set of the `Go computer`. `llgo/ssa` is not just limited to the `llgo` compiler. If we view it as the high-level expressive power of `LLVM`, you'll find it very useful. Prior to `llgo/ssa`, you had to operate `LLVM` using machine code semantics. But now, with the advanced SSA form (in the semantics of Go SSA), you can conveniently utilize `LLVM`.
* [llgo/cl](https://pkg.go.dev/github.com/goplus/llgo/cl): It is the core of the llgo compiler. It converts a Go package into LLVM IR files. It depends on `llgo/ssa`.
```sh * [llgo/internal/build](https://pkg.go.dev/github.com/goplus/llgo/internal/build): It strings together the entire compilation process of `llgo`. It depends on `llgo/ssa` and `llgo/cl`.
export LLGO_LIB_PYTHON=/opt/homebrew/Frameworks/Python.framework/Versions/3.12/python3.12
```
Then you can run the demos in directory `_pydemo`:
```sh
cd <demo-directory> # eg. cd _pydemo/callpy
llgo run .
```

View File

@@ -2,7 +2,7 @@ package main
import ( import (
"github.com/goplus/llgo/c" "github.com/goplus/llgo/c"
"github.com/goplus/llgo/x/llama2" "github.com/goplus/llgo/c/llama2"
) )
func main() { func main() {

22
_pydemo/matrix/matrix.go Normal file
View File

@@ -0,0 +1,22 @@
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+b = %s\n"), x.Str().CStr())
}

10
_pydemo/pi/pi.go Normal file
View 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())
}

View File

@@ -0,0 +1,13 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/statistics"
)
func main() {
list := py.List(1.0, 2.0, 3.0, 4.0, 4.0)
mean := statistics.Mean(list)
c.Printf(c.Str("mean(1, 2, 3, 4, 4) = %f\n"), mean.Float64())
}

5
c/c.go
View File

@@ -28,7 +28,12 @@ type (
Char = int8 Char = int8
Int = C.int Int = C.int
Uint = C.uint Uint = C.uint
Long = int32
Ulong = uint32
LongLong = int64
UlongLong = uint64
Float = float32 Float = float32
Double = float64
Pointer = unsafe.Pointer Pointer = unsafe.Pointer
FilePtr = unsafe.Pointer FilePtr = unsafe.Pointer
) )

35
c/cjson/README.md Normal file
View File

@@ -0,0 +1,35 @@
LLGo wrapper of DaveGamble/cJSON
=====
[![Build Status](https://github.com/goplus/cjson/actions/workflows/go.yml/badge.svg)](https://github.com/goplus/cjson/actions/workflows/go.yml)
[![GitHub release](https://img.shields.io/github/v/tag/goplus/cjson.svg?label=release)](https://github.com/goplus/cjson/releases)
[![GoDoc](https://pkg.go.dev/badge/github.com/goplus/cjson.svg)](https://pkg.go.dev/github.com/goplus/cjson)
[![Compiler](https://img.shields.io/badge/compiler-llgo-darkgreen.svg)](https://github.com/goplus/llgo)
[![Language](https://img.shields.io/badge/language-Go+-blue.svg)](https://github.com/goplus/gop)
## How to install
```sh
git clone https://github.com/goplus/cjson.git
cd cjson
git submodule init
git submodule update
mkdir build.dir
cd build.dir
cmake ../cJSON
sudo make install
```
## Demos
The `_demo` directory contains our demos (it start with `_` to prevent the `go` command from compiling it):
* [mkjson](_demo/mkjson/mkjson.go): create a json object and print it
### How to run demos
To run the demos in directory `_demo`:
```sh
cd <demo-directory> # eg. cd _demo/mkjson
llgo run .
```

View File

@@ -0,0 +1,27 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/cjson"
)
func main() {
mod := cjson.Object()
mod.SetItem(c.Str("name"), cjson.String(c.Str("math")))
syms := cjson.Array()
fn := cjson.Object()
fn.SetItem(c.Str("name"), cjson.String(c.Str("sqrt")))
fn.SetItem(c.Str("sig"), cjson.String(c.Str("(x, /)")))
syms.AddItem(fn)
v := cjson.Object()
v.SetItem(c.Str("name"), cjson.String(c.Str("pi")))
syms.AddItem(v)
mod.SetItem(c.Str("items"), syms)
c.Printf(c.Str("%s\n"), mod.CStr())
mod.Delete()
}

121
c/cjson/cjson.go Normal file
View File

@@ -0,0 +1,121 @@
/*
* Copyright (c) 2024 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 cjson
import (
_ "unsafe"
"github.com/goplus/llgo/c"
)
const (
LLGoPackage = "link: cjson"
)
// llgo:type C
type JSON struct {
Unused [0]byte
}
//go:linkname Null C.cJSON_CreateNull
func Null() *JSON
//go:linkname True C.cJSON_CreateTrue
func True() *JSON
//go:linkname False C.cJSON_CreateFalse
func False() *JSON
//go:linkname Bool C.cJSON_CreateBool
func Bool(boolean c.Int) *JSON
//go:linkname Number C.cJSON_CreateNumber
func Number(num float64) *JSON
//go:linkname String C.cJSON_CreateString
func String(str *c.Char) *JSON
//go:linkname Array C.cJSON_CreateArray
func Array() *JSON
//go:linkname Object C.cJSON_CreateObject
func Object() *JSON
// raw json
//
//go:linkname Raw C.cJSON_CreateRaw
func Raw(raw *c.Char) *JSON
// Create a string where valuestring references a string so
// it will not be freed by Delete
//
//go:linkname StringRef C.cJSON_CreateStringReference
func StringRef(str *c.Char) *JSON
// Create an object that only references it's elements so
// they will not be freed by Delete
//
//go:linkname ObjectRef C.cJSON_CreateObjectReference
func ObjectRef(child *JSON) *JSON
// Create an array that only references it's elements so
// they will not be freed by Delete
//
//go:linkname ArrayRef C.cJSON_CreateArrayReference
func ArrayRef(child *JSON) *JSON
// Delete a JSON entity and all subentities.
//
// llgo:link (*JSON).Delete C.cJSON_Delete
func (o *JSON) Delete() {}
// Append item to the specified array.
//
// llgo:link (*JSON).AddItem C.cJSON_AddItemToArray
func (o *JSON) AddItem(item *JSON) c.Int { return 0 }
// Append item to the specified object.
//
// llgo:link (*JSON).SetItem C.cJSON_AddItemToObject
func (o *JSON) SetItem(key *c.Char, item *JSON) c.Int { return 0 }
// llgo:link (*JSON).CStr C.cJSON_PrintUnformatted
func (o *JSON) CStr() *c.Char { return nil }
// Same as CStr. Provided for Go+.
//
// llgo:link (*JSON).Cstr C.cJSON_PrintUnformatted
func (o *JSON) Cstr() *c.Char { return nil }
// Render a JSON entity to text for transfer/storage.
//
// llgo:link (*JSON).Print C.cJSON_Print
func (o *JSON) Print() *c.Char { return nil }
// Render a JSON entity to text for transfer/storage without any formatting.
//
// llgo:link (*JSON).PrintUnformatted C.cJSON_PrintUnformatted
func (o *JSON) PrintUnformatted() *c.Char { return nil }
// Render a JSON entity to text using a buffered strategy.
//
// prebuffer is a guess at the final size. guessing well reduces reallocation.
//
// fmt=0 gives unformatted, =1 gives formatted.
//
// llgo:link (*JSON).PrintBuffered C.cJSON_PrintBuffered
func (o *JSON) PrintBuffered(prebuffer c.Int, fmt c.Int) *c.Char { return nil }

BIN
c/cjson/llgo_autogen.lla Normal file

Binary file not shown.

159
c/llama2/llama2.go Normal file
View File

@@ -0,0 +1,159 @@
/*
* Copyright (c) 2024 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 llama2
import (
_ "unsafe"
"github.com/goplus/llgo/c"
)
const (
LLGoPackage = "link"
)
// -----------------------------------------------------------------------------
// llgo:type C
type TokenIndex struct {
Str *c.Char
Id c.Int
}
// llgo:type C
type Tokenizer struct {
Vocab **c.Char
VocabScores *c.Float
SortedVocab *TokenIndex
VocabSize c.Int
MaxTokenLength c.Uint
BytePieces [512]uint8 // stores all single-byte strings
}
//go:linkname BuildTokenizer C.build_tokenizer
func BuildTokenizer(t *Tokenizer, tokenizerPath *c.Char, vocabSize c.Int)
//go:linkname FreeTokenizer C.free_tokenizer
func FreeTokenizer(t *Tokenizer)
// -----------------------------------------------------------------------------
// llgo:type C
type Config struct {
Dim c.Int // transformer dimension
HiddenDim c.Int // for ffn layers
NLayers c.Int // number of layers
NHeads c.Int // number of query heads
NKVHeads c.Int // number of key/value heads (can be < query heads because of multiquery)
VocabSize c.Int // vocabulary size, usually 256 (byte-level)
SeqLen c.Int // max sequence length
}
// llgo:type C
type TransformerWeights struct {
// token embedding table
TokenEmbeddingTable *c.Float // (vocab_size, dim)
// weights for rmsnorms
RmsAttWeight *c.Float // (layer, dim) rmsnorm weights
RmsFfnWeight *c.Float // (layer, dim)
// weights for matmuls. note dim == n_heads * head_size
Wq *c.Float // (layer, dim, n_heads * head_size)
Wk *c.Float // (layer, dim, n_kv_heads * head_size)
Wv *c.Float // (layer, dim, n_kv_heads * head_size)
Wo *c.Float // (layer, n_heads * head_size, dim)
// weights for ffn
W1 *c.Float // (layer, hidden_dim, dim)
W2 *c.Float // (layer, dim, hidden_dim)
W3 *c.Float // (layer, hidden_dim, dim)
// final rmsnorm
RmsFinalWeight *c.Float // (dim,)
// (optional) classifier weights for the logits, on the last layer
Wcls *c.Float
}
// llgo:type C
type RunState struct {
// current wave of activations
X *c.Float // activation at current time stamp (dim,)
Xb *c.Float // same, but inside a residual branch (dim,)
Xb2 *c.Float // an additional buffer just for convenience (dim,)
Hb *c.Float // buffer for hidden dimension in the ffn (hidden_dim,)
Hb2 *c.Float // buffer for hidden dimension in the ffn (hidden_dim,)
Q *c.Float // query (dim,)
K *c.Float // key (dim,)
V *c.Float // value (dim,)
Att *c.Float // buffer for scores/attention values (n_heads, seq_len)
Logits *c.Float // output logits
// kv cache
KeyCache *c.Float // (layer, seq_len, dim)
ValueCache *c.Float // (layer, seq_len, dim)
}
// llgo:type C
type Transformer struct {
Config Config // the hyperparameters of the architecture (the blueprint)
Weights TransformerWeights // the weights of the model
State RunState // buffers for the "wave" of activations in the forward pass
// some more state needed to properly clean up the memory mapping (sigh)
Fd c.Int // file descriptor for memory mapping
Data *c.Float // memory mapped data pointer
FileSize uintptr // size of the checkpoint file in bytes
}
//go:linkname BuildTransformer C.build_transformer
func BuildTransformer(t *Transformer, checkpointPath *c.Char)
//go:linkname FreeTransformer C.free_transformer
func FreeTransformer(t *Transformer)
// -----------------------------------------------------------------------------
// llgo:type C
type ProbIndex struct {
Prob c.Float
Index c.Int
} // struct used when sorting probabilities during top-p sampling
// llgo:type C
type Sampler struct {
VocabSize c.Int
Probindex *ProbIndex // buffer used in top-p sampling
Temperature c.Float
Topp c.Float
RngState uint64
}
//go:linkname BuildSampler C.build_sampler
func BuildSampler(sampler *Sampler, vocabSize c.Int, temperature c.Float, topp c.Float, rngSeed uint64)
//go:linkname FreeSampler C.free_sampler
func FreeSampler(sampler *Sampler)
// -----------------------------------------------------------------------------
//go:linkname Generate C.generate
func Generate(
transformer *Transformer, tokenizer *Tokenizer, sampler *Sampler,
prompt *c.Char, steps c.Int)
//go:linkname Chat C.chat
func Chat(
transformer *Transformer, tokenizer *Tokenizer, sampler *Sampler,
cliUserPrompt *c.Char, cliSystemPrompt *c.Char, steps c.Int)
// -----------------------------------------------------------------------------

View File

@@ -1,6 +1,6 @@
{ {
"cl": [ "cl": [
"clang -emit-llvm -S -o llgo_autogen.ll -c llama2/run.c", "clang -emit-llvm -S -o llgo_autogen.ll -c llama2/run.c",
"zip llgo_autogen.lla llgo_autogen.ll" "rm llgo_autogen.lla; zip llgo_autogen.lla llgo_autogen.ll"
] ]
} }

35
c/sqlite/README.md Normal file
View File

@@ -0,0 +1,35 @@
LLGo wrapper of sqlite
=====
[![Build Status](https://github.com/goplus/sqlite/actions/workflows/go.yml/badge.svg)](https://github.com/goplus/sqlite/actions/workflows/go.yml)
[![GitHub release](https://img.shields.io/github/v/tag/goplus/sqlite.svg?label=release)](https://github.com/goplus/sqlite/releases)
[![GoDoc](https://pkg.go.dev/badge/github.com/goplus/sqlite.svg)](https://pkg.go.dev/github.com/goplus/sqlite)
[![Compiler](https://img.shields.io/badge/compiler-llgo-darkgreen.svg)](https://github.com/goplus/llgo)
[![Language](https://img.shields.io/badge/language-Go+-blue.svg)](https://github.com/goplus/gop)
## How to install
```sh
git clone https://github.com/goplus/sqlite.git
cd sqlite
git submodule init
git submodule update
mkdir build.dir
cd build.dir
../sqlite/configure --enable-shared
sudo make install
```
## Demos
The `_demo` directory contains our demos (it start with `_` to prevent the `go` command from compiling it):
* [sqlitedemo](_demo/sqlitedemo/demo.go): a basic sqlite demo
### How to run demos
To run the demos in directory `_demo`:
```sh
cd <demo-directory> # eg. cd _demo/sqlitedemo
llgo run .
```

View File

@@ -2,7 +2,7 @@ package main
import ( import (
"github.com/goplus/llgo/c" "github.com/goplus/llgo/c"
"github.com/goplus/llgo/x/sqlite" "github.com/goplus/llgo/c/sqlite"
) )
func main() { func main() {

BIN
c/sqlite/llgo_autogen.lla Normal file

Binary file not shown.

View File

@@ -22,27 +22,23 @@ import (
"github.com/goplus/llgo/c" "github.com/goplus/llgo/c"
) )
type (
Char = c.Char
Int = c.Int
Pointer = c.Pointer
)
const ( const (
LLGoPackage = "link" LLGoPackage = "link: sqlite3"
) )
// llgo:type C // llgo:type C
type Sqlite3 struct { type Sqlite3 struct {
Unused [8]byte
} }
// llgo:type C // llgo:type C
type Stmt struct { type Stmt struct {
Unused [8]byte
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
type Errno Int type Errno c.Int
const ( const (
OK Errno = 0 // Successful result OK Errno = 0 // Successful result
@@ -81,10 +77,10 @@ const (
) )
// llgo:link (Errno).Errstr C.sqlite3_errstr // llgo:link (Errno).Errstr C.sqlite3_errstr
func (err Errno) Errstr() *Char { return nil } func (err Errno) Errstr() *c.Char { return nil }
// llgo:link (*Sqlite3).Errmsg C.sqlite3_errmsg // llgo:link (*Sqlite3).Errmsg C.sqlite3_errmsg
func (db *Sqlite3) Errmsg() *Char { return nil } func (db *Sqlite3) Errmsg() *c.Char { return nil }
// llgo:link (*Sqlite3).Errcode C.sqlite3_errcode // llgo:link (*Sqlite3).Errcode C.sqlite3_errcode
func (db *Sqlite3) Errcode() Errno { return 0 } func (db *Sqlite3) Errcode() Errno { return 0 }
@@ -95,13 +91,13 @@ func (db *Sqlite3) ExtendedErrcode() Errno { return 0 }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
//go:linkname doOpen C.sqlite3_open //go:linkname doOpen C.sqlite3_open
func doOpen(filename *Char, ppDb **Sqlite3) Errno func doOpen(filename *c.Char, ppDb **Sqlite3) Errno
//go:linkname doOpenV2 C.sqlite3_open_v2 //go:linkname doOpenV2 C.sqlite3_open_v2
func doOpenV2(filename *Char, ppDb **Sqlite3, flags OpenFlags, zVfs *Char) Errno func doOpenV2(filename *c.Char, ppDb **Sqlite3, flags OpenFlags, zVfs *c.Char) Errno
// OpenFlags represents SQLite open flags. // OpenFlags represents SQLite open flags.
type OpenFlags Int type OpenFlags c.Int
const ( const (
OpenReadOnly OpenFlags = 0x00000001 OpenReadOnly OpenFlags = 0x00000001
@@ -130,7 +126,7 @@ const (
// Opening A New Database Connection // Opening A New Database Connection
// filename: Database filename (UTF-8) // filename: Database filename (UTF-8)
func Open(filename *Char) (db *Sqlite3, err Errno) { func Open(filename *c.Char) (db *Sqlite3, err Errno) {
err = doOpen(filename, &db) err = doOpen(filename, &db)
return return
} }
@@ -138,7 +134,7 @@ func Open(filename *Char) (db *Sqlite3, err Errno) {
// Opening A New Database Connection // Opening A New Database Connection
// filename: Database filename (UTF-8) // filename: Database filename (UTF-8)
// zVfs: Name of VFS module to use // zVfs: Name of VFS module to use
func OpenV2(filename *Char, flags OpenFlags, zVfs *Char) (db *Sqlite3, err Errno) { func OpenV2(filename *c.Char, flags OpenFlags, zVfs *c.Char) (db *Sqlite3, err Errno) {
err = doOpenV2(filename, &db, flags, zVfs) err = doOpenV2(filename, &db, flags, zVfs)
return return
} }
@@ -156,22 +152,22 @@ func (db *Sqlite3) CloseV2() Errno { return 0 }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// llgo:link (*Sqlite3).doPrepare C.sqlite3_prepare // llgo:link (*Sqlite3).doPrepare C.sqlite3_prepare
func (*Sqlite3) doPrepare(*Char, Int, **Stmt, **Char) Errno { func (*Sqlite3) doPrepare(*c.Char, c.Int, **Stmt, **c.Char) Errno {
return 0 return 0
} }
// llgo:link (*Sqlite3).doPrepareV2 C.sqlite3_prepare_v2 // llgo:link (*Sqlite3).doPrepareV2 C.sqlite3_prepare_v2
func (*Sqlite3) doPrepareV2(*Char, Int, **Stmt, **Char) Errno { func (*Sqlite3) doPrepareV2(*c.Char, c.Int, **Stmt, **c.Char) Errno {
return 0 return 0
} }
// llgo:link (*Sqlite3).doPrepareV3 C.sqlite3_prepare_v3 // llgo:link (*Sqlite3).doPrepareV3 C.sqlite3_prepare_v3
func (*Sqlite3) doPrepareV3(*Char, Int, PrepareFlags, **Stmt, **Char) Errno { func (*Sqlite3) doPrepareV3(*c.Char, c.Int, PrepareFlags, **Stmt, **c.Char) Errno {
return 0 return 0
} }
// PrepareFlags represents SQLite prepare flags. // PrepareFlags represents SQLite prepare flags.
type PrepareFlags Int type PrepareFlags c.Int
const ( const (
PreparePersistent PrepareFlags = 0x01 PreparePersistent PrepareFlags = 0x01
@@ -181,17 +177,17 @@ const (
// Compiling An SQL Statement // Compiling An SQL Statement
// tail: Pointer to unused portion of sql // tail: Pointer to unused portion of sql
func (db *Sqlite3) Prepare(sql string, tail **Char) (stmt *Stmt, err Errno) { func (db *Sqlite3) Prepare(sql string, tail **c.Char) (stmt *Stmt, err Errno) {
err = db.doPrepare(c.GoStringData(sql), c.Int(len(sql)), &stmt, tail) err = db.doPrepare(c.GoStringData(sql), c.Int(len(sql)), &stmt, tail)
return return
} }
func (db *Sqlite3) PrepareV2(sql string, tail **Char) (stmt *Stmt, err Errno) { func (db *Sqlite3) PrepareV2(sql string, tail **c.Char) (stmt *Stmt, err Errno) {
err = db.doPrepareV2(c.GoStringData(sql), c.Int(len(sql)), &stmt, tail) err = db.doPrepareV2(c.GoStringData(sql), c.Int(len(sql)), &stmt, tail)
return return
} }
func (db *Sqlite3) PrepareV3(sql string, flags PrepareFlags, tail **Char) (stmt *Stmt, err Errno) { func (db *Sqlite3) PrepareV3(sql string, flags PrepareFlags, tail **c.Char) (stmt *Stmt, err Errno) {
err = db.doPrepareV3(c.GoStringData(sql), c.Int(len(sql)), flags, &stmt, tail) err = db.doPrepareV3(c.GoStringData(sql), c.Int(len(sql)), flags, &stmt, tail)
return return
} }
@@ -204,10 +200,10 @@ func (stmt *Stmt) Close() Errno { return 0 }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// llgo:link (*Stmt).BindInt C.sqlite3_bind_int // llgo:link (*Stmt).BindInt C.sqlite3_bind_int
func (*Stmt) BindInt(idx Int, val Int) Errno { return 0 } func (*Stmt) BindInt(idx c.Int, val c.Int) Errno { return 0 }
// llgo:link (*Stmt).BindInt64 C.sqlite3_bind_int64 // llgo:link (*Stmt).BindInt64 C.sqlite3_bind_int64
func (*Stmt) BindInt64(idx Int, val int64) Errno { return 0 } func (*Stmt) BindInt64(idx c.Int, val int64) Errno { return 0 }
/* /*
const ( const (
@@ -217,7 +213,9 @@ const (
*/ */
// llgo:link (*Stmt).BindText C.sqlite3_bind_text // llgo:link (*Stmt).BindText C.sqlite3_bind_text
func (*Stmt) BindText(idx Int, val *Char, nByte Int, destructor func(Pointer)) Errno { return 0 } func (*Stmt) BindText(idx c.Int, val *c.Char, nByte c.Int, destructor func(c.Pointer)) Errno {
return 0
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -236,19 +234,19 @@ func (*Stmt) Step() Errno { return 0 }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// llgo:link (*Stmt).ColumnCount C.sqlite3_column_count // llgo:link (*Stmt).ColumnCount C.sqlite3_column_count
func (stmt *Stmt) ColumnCount() Int { return 0 } func (stmt *Stmt) ColumnCount() c.Int { return 0 }
// llgo:link (*Stmt).ColumnName C.sqlite3_column_name // llgo:link (*Stmt).ColumnName C.sqlite3_column_name
func (stmt *Stmt) ColumnName(idx Int) *Char { return nil } func (stmt *Stmt) ColumnName(idx c.Int) *c.Char { return nil }
// llgo:link (*Stmt).ColumnInt C.sqlite3_column_int // llgo:link (*Stmt).ColumnInt C.sqlite3_column_int
func (stmt *Stmt) ColumnInt(idx Int) Int { return 0 } func (stmt *Stmt) ColumnInt(idx c.Int) c.Int { return 0 }
// llgo:link (*Stmt).ColumnInt64 C.sqlite3_column_int64 // llgo:link (*Stmt).ColumnInt64 C.sqlite3_column_int64
func (stmt *Stmt) ColumnInt64(idx Int) int64 { return 0 } func (stmt *Stmt) ColumnInt64(idx c.Int) int64 { return 0 }
// llgo:link (*Stmt).ColumnText C.sqlite3_column_text // llgo:link (*Stmt).ColumnText C.sqlite3_column_text
func (stmt *Stmt) ColumnText(idx Int) *Char { return nil } func (stmt *Stmt) ColumnText(idx c.Int) *c.Char { return nil }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -256,8 +254,8 @@ func (stmt *Stmt) ColumnText(idx Int) *Char { return nil }
// //
// llgo:link (*Sqlite3).Exec C.sqlite3_exec // llgo:link (*Sqlite3).Exec C.sqlite3_exec
func (*Sqlite3) Exec( func (*Sqlite3) Exec(
sql *Char, callback func(arg Pointer, resultCols Int, colVals, colNames **Char) Int, sql *c.Char, callback func(arg c.Pointer, resultCols c.Int, colVals, colNames **c.Char) c.Int,
arg Pointer, errmsg **Char) Errno { arg c.Pointer, errmsg **c.Char) Errno {
return 0 return 0
} }

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 2024 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 main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/cjson"
"github.com/goplus/llgo/py"
"github.com/goplus/llgo/py/inspect"
)
func main() {
if c.Argc < 2 {
c.Fprintf(c.Stderr, c.Str("Usage: pydump <pythonLibPath>\n"))
return
}
pyLib := c.Index(c.Argv, 1)
py.Initialize()
root := cjson.Object()
root.SetItem(c.Str("name"), cjson.String(pyLib))
items := cjson.Array()
mod := py.ImportModule(pyLib)
keys := mod.ModuleGetDict().DictKeys()
for i, n := uintptr(0), keys.ListLen(); i < n; i++ {
key := keys.ListItem(i)
val := mod.GetAttr(key)
doc := val.GetAttrString(c.Str("__doc__"))
sym := cjson.Object()
sym.SetItem(c.Str("type"), cjson.String(val.Type().TypeName().CStr()))
sym.SetItem(c.Str("name"), cjson.String(key.CStr()))
if doc != nil {
sym.SetItem(c.Str("doc"), cjson.String(doc.CStr()))
}
if val.Callable() != 0 {
sig := inspect.Signature(val)
sym.SetItem(c.Str("sig"), cjson.String(sig.Str().CStr()))
}
items.AddItem(sym)
}
root.SetItem(c.Str("items"), items)
c.Printf(c.Str("%s\n"), root.CStr())
}

242
chore/llpyg/llpyg.go Normal file
View File

@@ -0,0 +1,242 @@
/*
* Copyright (c) 2024 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 main
import (
"bytes"
"encoding/json"
"fmt"
"go/ast"
"go/token"
"go/types"
"log"
"os"
"os/exec"
"strings"
"github.com/goplus/gogen"
"github.com/goplus/llgo/chore/llpyg/pysig"
"github.com/goplus/llgo/ssa"
)
type symbol struct {
Name string `json:"name"`
Type string `json:"type"`
Doc string `json:"doc"`
Sig string `json:"sig"`
URL string `json:"url"`
}
type module struct {
Name string `json:"name"`
Items []*symbol `json:"items"`
}
func pydump(pyLib string) (mod module) {
var out bytes.Buffer
cmd := exec.Command("pydump", pyLib)
cmd.Stdout = &out
cmd.Stderr = os.Stderr
cmd.Run()
json.Unmarshal(out.Bytes(), &mod)
return
}
func pysigfetch(pyLib string, names []string) (mod module) {
var out bytes.Buffer
cmd := exec.Command("pysigfetch", pyLib, "-")
cmd.Stdin = strings.NewReader(strings.Join(names, " "))
cmd.Stdout = &out
cmd.Stderr = os.Stderr
cmd.Run()
json.Unmarshal(out.Bytes(), &mod)
return
}
func main() {
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "Usage: llpyg <pythonLibPath>")
return
}
pyLib := os.Args[1]
mod := pydump(pyLib)
if mod.Name != pyLib {
log.Printf("import module %s failed\n", pyLib)
os.Exit(1)
}
pkg := gogen.NewPackage("", pyLib, nil)
pkg.Import("unsafe").MarkForceUsed(pkg) // import _ "unsafe"
py := pkg.Import("github.com/goplus/llgo/py") // import "github.com/goplus/llgo/py"
f := func(cb *gogen.CodeBuilder) int {
cb.Val("py." + mod.Name)
return 1
}
defs := pkg.NewConstDefs(pkg.Types.Scope())
defs.New(f, 0, 0, nil, "LLGoPackage")
obj := py.Ref("Object").(*types.TypeName).Type().(*types.Named)
objPtr := types.NewPointer(obj)
ret := types.NewTuple(pkg.NewParam(0, "", objPtr))
ctx := &context{pkg, obj, objPtr, ret, nil, py}
ctx.genMod(pkg, &mod)
skips := ctx.skips
if n := len(skips); n > 0 {
log.Printf("==> There are %d signatures not found, fetch from doc site\n", n)
mod = pysigfetch(pyLib, skips)
ctx.skips = skips[:0]
ctx.genMod(pkg, &mod)
if len(mod.Items) > 0 {
skips = ctx.skips
}
if n := len(skips); n > 0 {
log.Printf("==> Skip %d symbols:\n%v\n", n, skips)
}
}
pkg.WriteTo(os.Stdout)
}
type context struct {
pkg *gogen.Package
obj *types.Named
objPtr *types.Pointer
ret *types.Tuple
skips []string
py gogen.PkgRef
}
func (ctx *context) genMod(pkg *gogen.Package, mod *module) {
for _, sym := range mod.Items {
switch sym.Type {
case "builtin_function_or_method", "function", "ufunc", "method-wrapper":
ctx.genFunc(pkg, sym)
case "str", "float", "bool", "type", "dict", "tuple", "list", "object", "module",
"int", "set", "frozenset", "flags", "bool_", "pybind11_type", "layout",
"memory_format", "qscheme", "dtype", "tensortype": // skip
case "": // pysigfetch: page not found
ctx.skips = append(ctx.skips, sym.Name)
default:
t := sym.Type
if len(t) > 0 && (t[0] >= 'a' && t[0] <= 'z') && !strings.HasSuffix(t, "_info") {
log.Panicln("unsupport type:", sym.Type)
}
}
}
}
func (ctx *context) genFunc(pkg *gogen.Package, sym *symbol) {
name, symSig := sym.Name, sym.Sig
if len(name) == 0 || name[0] == '_' {
return
}
if symSig == "<NULL>" {
ctx.skips = append(ctx.skips, name)
return
}
params, variadic := ctx.genParams(pkg, symSig)
name = genName(name, -1)
sig := types.NewSignatureType(nil, nil, nil, params, ctx.ret, variadic)
fn := pkg.NewFuncDecl(token.NoPos, name, sig)
list := ctx.genDoc(sym.Doc)
if sym.URL != "" {
if len(list) > 0 {
list = append(list, emptyCommentLine)
}
list = append(list, genSee(sym.URL))
}
if len(list) > 0 {
list = append(list, emptyCommentLine)
}
list = append(list, ctx.genLinkname(name, sym))
fn.SetComments(pkg, &ast.CommentGroup{List: list})
// fn.BodyStart(pkg).End()
}
func (ctx *context) genParams(pkg *gogen.Package, sig string) (*types.Tuple, bool) {
args := pysig.Parse(sig)
if len(args) == 0 {
return nil, false
}
n := len(args)
objPtr := ctx.objPtr
list := make([]*types.Var, 0, n)
for i := 0; i < n; i++ {
name := args[i].Name
if name == "/" {
continue
}
if name == "*" || name == "\\*" {
break
}
if strings.HasPrefix(name, "*") {
if name[1] != '*' {
list = append(list, ssa.VArg())
return types.NewTuple(list...), true
}
return types.NewTuple(list...), false
}
list = append(list, pkg.NewParam(0, genName(name, 0), objPtr))
}
return types.NewTuple(list...), false
}
func genName(name string, idxDontTitle int) string {
parts := strings.Split(name, "_")
for i, part := range parts {
if i != idxDontTitle && part != "" {
if c := part[0]; c >= 'a' && c <= 'z' {
part = string(c+'A'-'a') + part[1:]
}
parts[i] = part
}
}
name = strings.Join(parts, "")
switch name {
case "default", "func", "var", "":
name += "_"
}
return name
}
func (ctx *context) genLinkname(name string, sym *symbol) *ast.Comment {
return &ast.Comment{Text: "//go:linkname " + name + " py." + sym.Name}
}
func (ctx *context) genDoc(doc string) []*ast.Comment {
if doc == "" {
return make([]*ast.Comment, 0, 4)
}
lines := strings.Split(doc, "\n")
list := make([]*ast.Comment, len(lines), len(lines)+4)
for i, line := range lines {
list[i] = &ast.Comment{Text: "// " + line}
}
return list
}
func genSee(url string) *ast.Comment {
return &ast.Comment{Text: "// See " + url}
}
var (
emptyCommentLine = &ast.Comment{Text: "//"}
)

100
chore/llpyg/pysig/parse.go Normal file
View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2024 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 pysig
import (
"strings"
)
type Arg struct {
Name string
Type string
DefVal string
}
// Parse parses a Python function signature.
func Parse(sig string) (args []*Arg) {
sig = strings.TrimPrefix(sig, "(")
for {
pos := strings.IndexAny(sig, ",:=)")
if pos <= 0 {
return
}
arg := &Arg{Name: strings.TrimSpace(sig[:pos])}
args = append(args, arg)
c := sig[pos]
sig = sig[pos+1:]
switch c {
case ',':
continue
case ':':
arg.Type, sig = parseType(sig)
if strings.HasPrefix(sig, "=") {
arg.DefVal, sig = parseDefVal(sig[1:])
}
case '=':
arg.DefVal, sig = parseDefVal(sig)
case ')':
return
}
sig = strings.TrimPrefix(sig, ",")
}
}
const (
allSpecials = "([<'\""
)
var pairStops = map[byte]string{
'(': ")" + allSpecials,
'[': "]" + allSpecials,
'<': ">" + allSpecials,
'\'': "'" + allSpecials,
'"': "\"",
}
func parseText(sig string, stops string) (left string) {
for {
pos := strings.IndexAny(sig, stops)
if pos < 0 {
return sig
}
if c := sig[pos]; c != stops[0] {
if pstop, ok := pairStops[c]; ok {
sig = strings.TrimPrefix(parseText(sig[pos+1:], pstop), pstop[:1])
continue
}
}
return sig[pos:]
}
}
// stops: "=,)"
func parseType(sig string) (string, string) {
left := parseText(sig, "=,)"+allSpecials)
return resultOf(sig, left), left
}
// stops: ",)"
func parseDefVal(sig string) (string, string) {
left := parseText(sig, ",)"+allSpecials)
return resultOf(sig, left), left
}
func resultOf(sig, left string) string {
return strings.TrimSpace(sig[:len(sig)-len(left)])
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2024 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 pysig
import "testing"
func TestParse(t *testing.T) {
type testCase struct {
sig string
args []*Arg
}
cases := []testCase{
{"(start=None, *, unit: 'str | None' = None) -> 'TimedeltaIndex'", []*Arg{
{Name: "start", DefVal: "None"},
{Name: "*"},
{Name: "unit", Type: "'str | None'", DefVal: "None"},
}},
{"()", nil},
{"(a =", []*Arg{{Name: "a"}}},
{"(a) -> int", []*Arg{{Name: "a"}}},
{"(a: int)", []*Arg{{Name: "a", Type: "int"}}},
{"(a: int = 1, b: float)", []*Arg{{Name: "a", Type: "int", DefVal: "1"}, {Name: "b", Type: "float"}}},
{"(a = <1>, b = 2.0)", []*Arg{{Name: "a", DefVal: "<1>"}, {Name: "b", DefVal: "2.0"}}},
{"(a: 'Suffixes' = ('_x', '_y'))", []*Arg{{Name: "a", Type: "'Suffixes'", DefVal: "('_x', '_y')"}}},
}
for _, c := range cases {
args := Parse(c.sig)
if len(args) != len(c.args) {
t.Fatalf("%s: len(args) = %v, want %v", c.sig, len(args), len(c.args))
}
for i, arg := range args {
want := c.args[i]
if arg.Name != want.Name || arg.Type != want.Type || arg.DefVal != want.DefVal {
t.Fatalf("%s: args[%v] = %v, want %v", c.sig, i, arg, want)
}
}
}
}

View File

@@ -18,14 +18,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"() call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init() call void @main.init()
%2 = call i64 @main.max(i64 1, i64 2) %2 = call i64 @main.max(i64 1, i64 2)
ret void ret i32 0
} }
define i64 @main.max(i64 %0, i64 %1) { define i64 @main.max(i64 %0, i64 %1) {

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main' ; ModuleID = 'main'
source_filename = "main" source_filename = "main"
@main.hello = global ptr null @main.hello = global [7 x i8] undef
@"main.init$guard" = global ptr null @"main.init$guard" = global ptr null
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@@ -27,7 +27,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -35,7 +35,7 @@ _llgo_0:
call void @main.init() call void @main.init()
%2 = call i64 @"github.com/goplus/llgo/cl/internal/stdio.Max"(i64 2, i64 100) %2 = call i64 @"github.com/goplus/llgo/cl/internal/stdio.Max"(i64 2, i64 100)
call void (ptr, ...) @printf(ptr @main.hello) call void (ptr, ...) @printf(ptr @main.hello)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/cl/internal/stdio.init"() declare void @"github.com/goplus/llgo/cl/internal/stdio.init"()

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main' ; ModuleID = 'main'
source_filename = "main" source_filename = "main"
@main.format = global ptr null @main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null @"main.init$guard" = global ptr null
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@@ -42,7 +42,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -50,7 +50,7 @@ _llgo_0:
call void @main.init() call void @main.init()
%2 = call i64 @"(main.T).Add"(i64 1, i64 2) %2 = call i64 @"(main.T).Add"(i64 1, i64 2)
call void (ptr, ...) @printf(ptr @main.format, i64 %2) call void (ptr, ...) @printf(ptr @main.format, i64 %2)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -51,7 +51,7 @@ _llgo_0:
define void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %0) { define void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0: _llgo_0:
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) %1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
%2 = icmp eq i64 %1, 0 %2 = icmp eq i64 %1, 0
br i1 %2, label %_llgo_1, label %_llgo_2 br i1 %2, label %_llgo_1, label %_llgo_2
@@ -77,7 +77,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -205,7 +205,7 @@ _llgo_2: ; preds = %_llgo_3, %_llgo_1,
store %"github.com/goplus/llgo/internal/runtime.iface" %74, ptr %72, align 8 store %"github.com/goplus/llgo/internal/runtime.iface" %74, ptr %72, align 8
%75 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %26, i64 16, i64 16, i64 0, i64 16, i64 16) %75 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %26, i64 16, i64 16, i64 0, i64 16, i64 16)
call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %75) call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %75)
ret void ret i32 0
_llgo_3: ; preds = %_llgo_0 _llgo_3: ; preds = %_llgo_0
br i1 true, label %_llgo_1, label %_llgo_2 br i1 true, label %_llgo_1, label %_llgo_2
@@ -322,7 +322,7 @@ _llgo_15: ; preds = %_llgo_13
br i1 %40, label %_llgo_16, label %_llgo_17 br i1 %40, label %_llgo_16, label %_llgo_17
_llgo_16: ; preds = %_llgo_15 _llgo_16: ; preds = %_llgo_15
%41 = sext i8 %39 to i64 %41 = zext i8 %39 to i64
call void @main.printuint(i64 %41) call void @main.printuint(i64 %41)
br label %_llgo_1 br label %_llgo_1
@@ -335,7 +335,7 @@ _llgo_17: ; preds = %_llgo_15
br i1 %46, label %_llgo_18, label %_llgo_19 br i1 %46, label %_llgo_18, label %_llgo_19
_llgo_18: ; preds = %_llgo_17 _llgo_18: ; preds = %_llgo_17
%47 = sext i16 %45 to i64 %47 = zext i16 %45 to i64
call void @main.printuint(i64 %47) call void @main.printuint(i64 %47)
br label %_llgo_1 br label %_llgo_1
@@ -348,7 +348,7 @@ _llgo_19: ; preds = %_llgo_17
br i1 %52, label %_llgo_20, label %_llgo_21 br i1 %52, label %_llgo_20, label %_llgo_21
_llgo_20: ; preds = %_llgo_19 _llgo_20: ; preds = %_llgo_19
%53 = sext i32 %51 to i64 %53 = zext i32 %51 to i64
call void @main.printuint(i64 %53) call void @main.printuint(i64 %53)
br label %_llgo_1 br label %_llgo_1
@@ -555,64 +555,66 @@ _llgo_24: ; preds = %_llgo_22
br label %_llgo_12 br label %_llgo_12
_llgo_25: ; preds = %_llgo_27 _llgo_25: ; preds = %_llgo_27
%43 = fptosi double %59 to i64 %43 = fptosi double %60 to i64
%44 = add i64 %60, 2 %44 = add i64 %61, 2
%45 = add i64 %43, 48 %45 = add i64 %43, 48
%46 = trunc i64 %45 to i8 %46 = trunc i64 %45 to i8
%47 = getelementptr inbounds i8, ptr %11, i64 %44 %47 = icmp slt i64 %44, 0
store i8 %46, ptr %47, align 1 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %47)
%48 = sitofp i64 %43 to double %48 = getelementptr inbounds i8, ptr %11, i64 %44
%49 = fsub double %59, %48 store i8 %46, ptr %48, align 1
%50 = fmul double %49, 1.000000e+01 %49 = sitofp i64 %43 to double
%51 = add i64 %60, 1 %50 = fsub double %60, %49
%51 = fmul double %50, 1.000000e+01
%52 = add i64 %61, 1
br label %_llgo_27 br label %_llgo_27
_llgo_26: ; preds = %_llgo_27 _llgo_26: ; preds = %_llgo_27
%52 = getelementptr inbounds i8, ptr %11, i64 2 %53 = getelementptr inbounds i8, ptr %11, i64 2
%53 = load i8, ptr %52, align 1 %54 = load i8, ptr %53, align 1
%54 = getelementptr inbounds i8, ptr %11, i64 1 %55 = getelementptr inbounds i8, ptr %11, i64 1
store i8 %53, ptr %54, align 1 store i8 %54, ptr %55, align 1
%55 = getelementptr inbounds i8, ptr %11, i64 2 %56 = getelementptr inbounds i8, ptr %11, i64 2
store i8 46, ptr %55, align 1 store i8 46, ptr %56, align 1
%56 = getelementptr inbounds i8, ptr %11, i64 9 %57 = getelementptr inbounds i8, ptr %11, i64 9
store i8 101, ptr %56, align 1 store i8 101, ptr %57, align 1
%57 = getelementptr inbounds i8, ptr %11, i64 10 %58 = getelementptr inbounds i8, ptr %11, i64 10
store i8 43, ptr %57, align 1 store i8 43, ptr %58, align 1
%58 = icmp slt i64 %19, 0 %59 = icmp slt i64 %19, 0
br i1 %58, label %_llgo_28, label %_llgo_29 br i1 %59, label %_llgo_28, label %_llgo_29
_llgo_27: ; preds = %_llgo_25, %_llgo_12 _llgo_27: ; preds = %_llgo_25, %_llgo_12
%59 = phi double [ %18, %_llgo_12 ], [ %50, %_llgo_25 ] %60 = phi double [ %18, %_llgo_12 ], [ %51, %_llgo_25 ]
%60 = phi i64 [ 0, %_llgo_12 ], [ %51, %_llgo_25 ] %61 = phi i64 [ 0, %_llgo_12 ], [ %52, %_llgo_25 ]
%61 = icmp slt i64 %60, 7 %62 = icmp slt i64 %61, 7
br i1 %61, label %_llgo_25, label %_llgo_26 br i1 %62, label %_llgo_25, label %_llgo_26
_llgo_28: ; preds = %_llgo_26 _llgo_28: ; preds = %_llgo_26
%62 = sub i64 0, %19 %63 = sub i64 0, %19
%63 = getelementptr inbounds i8, ptr %11, i64 10 %64 = getelementptr inbounds i8, ptr %11, i64 10
store i8 45, ptr %63, align 1 store i8 45, ptr %64, align 1
br label %_llgo_29 br label %_llgo_29
_llgo_29: ; preds = %_llgo_28, %_llgo_26 _llgo_29: ; preds = %_llgo_28, %_llgo_26
%64 = phi i64 [ %19, %_llgo_26 ], [ %62, %_llgo_28 ] %65 = phi i64 [ %19, %_llgo_26 ], [ %63, %_llgo_28 ]
%65 = sdiv i64 %64, 100 %66 = sdiv i64 %65, 100
%66 = trunc i64 %65 to i8 %67 = trunc i64 %66 to i8
%67 = add i8 %66, 48 %68 = add i8 %67, 48
%68 = getelementptr inbounds i8, ptr %11, i64 11 %69 = getelementptr inbounds i8, ptr %11, i64 11
store i8 %67, ptr %68, align 1 store i8 %68, ptr %69, align 1
%69 = sdiv i64 %64, 10 %70 = sdiv i64 %65, 10
%70 = trunc i64 %69 to i8 %71 = trunc i64 %70 to i8
%71 = urem i8 %70, 10 %72 = urem i8 %71, 10
%72 = add i8 %71, 48 %73 = add i8 %72, 48
%73 = getelementptr inbounds i8, ptr %11, i64 12 %74 = getelementptr inbounds i8, ptr %11, i64 12
store i8 %72, ptr %73, align 1 store i8 %73, ptr %74, align 1
%74 = srem i64 %64, 10 %75 = srem i64 %65, 10
%75 = trunc i64 %74 to i8 %76 = trunc i64 %75 to i8
%76 = add i8 %75, 48 %77 = add i8 %76, 48
%77 = getelementptr inbounds i8, ptr %11, i64 13 %78 = getelementptr inbounds i8, ptr %11, i64 13
store i8 %76, ptr %77, align 1 store i8 %77, ptr %78, align 1
%78 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %11, i64 1, i64 14, i64 0, i64 14, i64 14) %79 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %11, i64 1, i64 14, i64 0, i64 14, i64 14)
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %78) call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %79)
ret void ret void
} }
@@ -622,43 +624,49 @@ _llgo_0:
br label %_llgo_3 br label %_llgo_3
_llgo_1: ; preds = %_llgo_3 _llgo_1: ; preds = %_llgo_3
%2 = urem i64 %14, 16 %2 = urem i64 %17, 16
%3 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @10, i64 16) %3 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @10, i64 16)
%4 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %3, 0 %4 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %3, 0
%5 = getelementptr inbounds i8, ptr %4, i64 %2 %5 = getelementptr inbounds i8, ptr %4, i64 %2
%6 = load i8, ptr %5, align 1 %6 = load i8, ptr %5, align 1
%7 = getelementptr inbounds i8, ptr %1, i64 %15 %7 = icmp slt i64 %18, 0
store i8 %6, ptr %7, align 1 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %7)
%8 = icmp ult i64 %14, 16 %8 = getelementptr inbounds i8, ptr %1, i64 %18
br i1 %8, label %_llgo_5, label %_llgo_4 store i8 %6, ptr %8, align 1
%9 = icmp ult i64 %17, 16
br i1 %9, label %_llgo_5, label %_llgo_4
_llgo_2: ; preds = %_llgo_5, %_llgo_3 _llgo_2: ; preds = %_llgo_5, %_llgo_3
%9 = sub i64 %15, 1 %10 = sub i64 %18, 1
%10 = getelementptr inbounds i8, ptr %1, i64 %9 %11 = icmp slt i64 %10, 0
store i8 120, ptr %10, align 1 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %11)
%11 = sub i64 %9, 1 %12 = getelementptr inbounds i8, ptr %1, i64 %10
%12 = getelementptr inbounds i8, ptr %1, i64 %11 store i8 120, ptr %12, align 1
store i8 48, ptr %12, align 1 %13 = sub i64 %10, 1
%13 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %11, i64 100, i64 100) %14 = icmp slt i64 %13, 0
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %13) call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %14)
%15 = getelementptr inbounds i8, ptr %1, i64 %13
store i8 48, ptr %15, align 1
%16 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %13, i64 100, i64 100)
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %16)
ret void ret void
_llgo_3: ; preds = %_llgo_4, %_llgo_0 _llgo_3: ; preds = %_llgo_4, %_llgo_0
%14 = phi i64 [ %0, %_llgo_0 ], [ %17, %_llgo_4 ] %17 = phi i64 [ %0, %_llgo_0 ], [ %20, %_llgo_4 ]
%15 = phi i64 [ 99, %_llgo_0 ], [ %18, %_llgo_4 ] %18 = phi i64 [ 99, %_llgo_0 ], [ %21, %_llgo_4 ]
%16 = icmp sgt i64 %15, 0 %19 = icmp sgt i64 %18, 0
br i1 %16, label %_llgo_1, label %_llgo_2 br i1 %19, label %_llgo_1, label %_llgo_2
_llgo_4: ; preds = %_llgo_5, %_llgo_1 _llgo_4: ; preds = %_llgo_5, %_llgo_1
%17 = udiv i64 %14, 16 %20 = udiv i64 %17, 16
%18 = sub i64 %15, 1 %21 = sub i64 %18, 1
br label %_llgo_3 br label %_llgo_3
_llgo_5: ; preds = %_llgo_1 _llgo_5: ; preds = %_llgo_1
%19 = sub i64 100, %15 %22 = sub i64 100, %18
%20 = load i64, ptr @main.minhexdigits, align 4 %23 = load i64, ptr @main.minhexdigits, align 4
%21 = icmp sge i64 %19, %20 %24 = icmp sge i64 %22, %23
br i1 %21, label %_llgo_2, label %_llgo_4 br i1 %24, label %_llgo_2, label %_llgo_4
} }
define void @main.printint(i64 %0) { define void @main.printint(i64 %0) {
@@ -680,7 +688,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
define void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %0) { define void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0: _llgo_0:
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) %1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
br label %_llgo_1 br label %_llgo_1
_llgo_1: ; preds = %_llgo_5, %_llgo_0 _llgo_1: ; preds = %_llgo_5, %_llgo_0
@@ -690,23 +698,25 @@ _llgo_1: ; preds = %_llgo_5, %_llgo_0
br i1 %4, label %_llgo_2, label %_llgo_3 br i1 %4, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1 _llgo_2: ; preds = %_llgo_1
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) %5 = icmp slt i64 %3, 0
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %5, i64 %3 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
%7 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %6, align 8 %6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
%8 = icmp ne i64 %3, 0 %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %6, i64 %3
br i1 %8, label %_llgo_4, label %_llgo_5 %8 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %7, align 8
%9 = icmp ne i64 %3, 0
br i1 %9, label %_llgo_4, label %_llgo_5
_llgo_3: ; preds = %_llgo_1 _llgo_3: ; preds = %_llgo_1
call void @main.printnl() call void @main.printnl()
ret void ret void
_llgo_4: ; preds = %_llgo_2 _llgo_4: ; preds = %_llgo_2
%9 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @12, i64 1) %10 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @12, i64 1)
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %9) call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %10)
br label %_llgo_5 br label %_llgo_5
_llgo_5: ; preds = %_llgo_4, %_llgo_2 _llgo_5: ; preds = %_llgo_4, %_llgo_2
call void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %7) call void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %8)
br label %_llgo_1 br label %_llgo_1
} }
@@ -737,28 +747,30 @@ _llgo_0:
br label %_llgo_3 br label %_llgo_3
_llgo_1: ; preds = %_llgo_3 _llgo_1: ; preds = %_llgo_3
%2 = urem i64 %8, 10 %2 = urem i64 %9, 10
%3 = add i64 %2, 48 %3 = add i64 %2, 48
%4 = trunc i64 %3 to i8 %4 = trunc i64 %3 to i8
%5 = getelementptr inbounds i8, ptr %1, i64 %9 %5 = icmp slt i64 %10, 0
store i8 %4, ptr %5, align 1 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
%6 = icmp ult i64 %8, 10 %6 = getelementptr inbounds i8, ptr %1, i64 %10
br i1 %6, label %_llgo_2, label %_llgo_4 store i8 %4, ptr %6, align 1
%7 = icmp ult i64 %9, 10
br i1 %7, label %_llgo_2, label %_llgo_4
_llgo_2: ; preds = %_llgo_3, %_llgo_1 _llgo_2: ; preds = %_llgo_3, %_llgo_1
%7 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %9, i64 100, i64 100) %8 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %10, i64 100, i64 100)
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %7) call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %8)
ret void ret void
_llgo_3: ; preds = %_llgo_4, %_llgo_0 _llgo_3: ; preds = %_llgo_4, %_llgo_0
%8 = phi i64 [ %0, %_llgo_0 ], [ %11, %_llgo_4 ] %9 = phi i64 [ %0, %_llgo_0 ], [ %12, %_llgo_4 ]
%9 = phi i64 [ 99, %_llgo_0 ], [ %12, %_llgo_4 ] %10 = phi i64 [ 99, %_llgo_0 ], [ %13, %_llgo_4 ]
%10 = icmp sgt i64 %9, 0 %11 = icmp sgt i64 %10, 0
br i1 %10, label %_llgo_1, label %_llgo_2 br i1 %11, label %_llgo_1, label %_llgo_2
_llgo_4: ; preds = %_llgo_1 _llgo_4: ; preds = %_llgo_1
%11 = udiv i64 %8, 10 %12 = udiv i64 %9, 10
%12 = sub i64 %9, 1 %13 = sub i64 %10, 1
br label %_llgo_3 br label %_llgo_3
} }
@@ -783,8 +795,6 @@ _llgo_0:
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare i32 @printf(ptr, ...) declare i32 @printf(ptr, ...)
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()
@@ -803,4 +813,4 @@ declare { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"gith
declare { %"github.com/goplus/llgo/internal/runtime.String", i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2String"(%"github.com/goplus/llgo/internal/runtime.iface", ptr) declare { %"github.com/goplus/llgo/internal/runtime.String", i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2String"(%"github.com/goplus/llgo/internal/runtime.iface", ptr)
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice") declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main' ; ModuleID = 'main'
source_filename = "main" source_filename = "main"
@main.hello = global ptr null @main.hello = global [7 x i8] undef
@"main.init$guard" = global ptr null @"main.init$guard" = global ptr null
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@@ -26,14 +26,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"() call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init() call void @main.init()
call void (ptr, ...) @printf(ptr @main.hello) call void (ptr, ...) @printf(ptr @main.hello)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main' ; ModuleID = 'main'
source_filename = "main" source_filename = "main"
@main.format = global ptr null @main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null @"main.init$guard" = global ptr null
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@@ -29,14 +29,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"() call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init() call void @main.init()
call void (ptr, ...) @printf(ptr @main.format, i64 100) call void (ptr, ...) @printf(ptr @main.format, i64 100)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main' ; ModuleID = 'main'
source_filename = "main" source_filename = "main"
@main.format = global ptr null @main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null @"main.init$guard" = global ptr null
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@@ -35,14 +35,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"() call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init() call void @main.init()
call void @"(*main.T).Print"(ptr @main.format, i64 100) call void @"(*main.T).Print"(ptr @main.format, i64 100)
ret void ret i32 0
} }
declare void @printf(ptr, ...) declare void @printf(ptr, ...)

View File

@@ -25,7 +25,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -33,7 +33,7 @@ _llgo_0:
call void @main.init() call void @main.init()
%2 = call i32 @main.f(i32 100) %2 = call i32 @main.f(i32 100)
%3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2) %3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -33,7 +33,7 @@ _llgo_1: ; preds = %_llgo_0
br label %_llgo_2 br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0 _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

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]
}

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

@@ -0,0 +1,101 @@
; ModuleID = 'main'
source_filename = "main"
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
@main.array = global [8 x i8] undef
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@0 = private unnamed_addr constant [8 x i8] c"\E4\B8\ADabcd\00", align 1
@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@2 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@3 = private unnamed_addr constant [8 x i8] c"\E4\B8\ADabcd\00", align 1
define i8 @main.index(i8 %0) {
_llgo_0:
%1 = icmp slt i8 %0, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %1)
%2 = zext i8 %0 to i64
%3 = getelementptr inbounds i8, ptr @main.array, i64 %2
%4 = load i8, ptr %3, align 1
ret i8 %4
}
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 @"unicode/utf8.init"()
store i8 1, ptr @main.array, align 1
store i8 2, ptr getelementptr inbounds (i8, ptr @main.array, i64 1), align 1
store i8 3, ptr getelementptr inbounds (i8, ptr @main.array, i64 2), align 1
store i8 4, ptr getelementptr inbounds (i8, ptr @main.array, i64 3), align 1
store i8 5, ptr getelementptr inbounds (i8, ptr @main.array, i64 4), align 1
store i8 6, ptr getelementptr inbounds (i8, ptr @main.array, i64 5), align 1
store i8 7, ptr getelementptr inbounds (i8, ptr @main.array, i64 6), align 1
store i8 8, ptr getelementptr inbounds (i8, ptr @main.array, i64 7), align 1
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()
br label %_llgo_3
_llgo_1: ; preds = %_llgo_3
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 7)
%3 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 1
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %2, i64 %14, i64 %3)
%5 = call { i32, i64 } @"unicode/utf8.DecodeRuneInString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
%6 = extractvalue { i32, i64 } %5, 0
%7 = extractvalue { i32, i64 } %5, 1
%8 = add i64 %14, %7
%9 = sext i32 %6 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %9)
%10 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %10)
br label %_llgo_3
_llgo_2: ; preds = %_llgo_3
%11 = call i8 @main.index(i8 2)
%12 = icmp eq i8 %11, 3
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %12)
%13 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %13)
ret i32 0
_llgo_3: ; preds = %_llgo_1, %_llgo_0
%14 = phi i64 [ 0, %_llgo_0 ], [ %8, %_llgo_1 ]
%15 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 7)
%16 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %15, 1
%17 = icmp slt i64 %14, %16
br i1 %17, label %_llgo_1, label %_llgo_2
}
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare void @"unicode/utf8.init"()
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String", i64, i64)
declare { i32, i64 } @"unicode/utf8.DecodeRuneInString"(%"github.com/goplus/llgo/internal/runtime.String")
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
declare void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1)

View File

@@ -22,7 +22,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -43,12 +43,12 @@ _llgo_0:
store %"github.com/goplus/llgo/internal/runtime.iface" %11, ptr %9, align 8 store %"github.com/goplus/llgo/internal/runtime.iface" %11, ptr %9, align 8
%12 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 16, i64 3, i64 0, i64 3, i64 3) %12 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 16, i64 3, i64 0, i64 3, i64 3)
call void @main.test(%"github.com/goplus/llgo/internal/runtime.Slice" %12) call void @main.test(%"github.com/goplus/llgo/internal/runtime.Slice" %12)
ret void ret i32 0
} }
define void @main.test(%"github.com/goplus/llgo/internal/runtime.Slice" %0) { define void @main.test(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0: _llgo_0:
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) %1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
br label %_llgo_1 br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0 _llgo_1: ; preds = %_llgo_2, %_llgo_0
@@ -58,12 +58,14 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
br i1 %4, label %_llgo_2, label %_llgo_3 br i1 %4, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1 _llgo_2: ; preds = %_llgo_1
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) %5 = icmp slt i64 %3, 0
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %5, i64 %3 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
%7 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %6, align 8 %6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
%8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %6, i64 %3
%9 = call i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %7, ptr %8) %8 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %7, align 8
%10 = call i32 (ptr, ...) @printf(ptr @0, i64 %9) %9 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
%10 = call i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %8, ptr %9)
%11 = call i32 (ptr, ...) @printf(ptr @0, i64 %10)
br label %_llgo_1 br label %_llgo_1
_llgo_3: ; preds = %_llgo_1 _llgo_3: ; preds = %_llgo_1
@@ -80,9 +82,7 @@ declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llg
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64) declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice") declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr) declare i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr)

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -30,7 +30,7 @@ _llgo_0:
%3 = add i64 %2, 1 %3 = add i64 %2, 1
store i64 %3, ptr @main.a, align 4 store i64 %3, ptr @main.a, align 4
%4 = load i64, ptr @main.a, align 4 %4 = load i64, ptr @main.a, align 4
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -19,7 +19,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -36,7 +36,7 @@ _llgo_1: ; preds = %_llgo_3
br label %_llgo_3 br label %_llgo_3
_llgo_2: ; preds = %_llgo_3 _llgo_2: ; preds = %_llgo_3
ret void ret i32 0
_llgo_3: ; preds = %_llgo_1, %_llgo_0 _llgo_3: ; preds = %_llgo_1, %_llgo_0
%7 = phi i32 [ 0, %_llgo_0 ], [ %6, %_llgo_1 ] %7 = phi i32 [ 0, %_llgo_0 ], [ %6, %_llgo_1 ]

View File

@@ -2,7 +2,7 @@ package main
import ( import (
"github.com/goplus/llgo/c" "github.com/goplus/llgo/c"
"github.com/goplus/llgo/x/sqlite" "github.com/goplus/llgo/c/sqlite"
) )
func main() { func main() {

View File

@@ -35,18 +35,18 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"() call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init() call void @main.init()
%2 = call { ptr, i32 } @"github.com/goplus/llgo/x/sqlite.OpenV2"(ptr @1, i32 130, ptr null) %2 = call { ptr, i32 } @"github.com/goplus/llgo/c/sqlite.OpenV2"(ptr @1, i32 130, ptr null)
%3 = extractvalue { ptr, i32 } %2, 0 %3 = extractvalue { ptr, i32 } %2, 0
%4 = extractvalue { ptr, i32 } %2, 1 %4 = extractvalue { ptr, i32 } %2, 1
call void @main.check(i32 %4) call void @main.check(i32 %4)
%5 = call i32 @sqlite3_close(ptr %3) %5 = call i32 @sqlite3_close(ptr %3)
ret void ret i32 0
} }
declare ptr @sqlite3_errstr(i32) declare ptr @sqlite3_errstr(i32)
@@ -57,6 +57,6 @@ declare void @exit(i32)
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare { ptr, i32 } @"github.com/goplus/llgo/x/sqlite.OpenV2"(ptr, i32, ptr) declare { ptr, i32 } @"github.com/goplus/llgo/c/sqlite.OpenV2"(ptr, i32, ptr)
declare i32 @sqlite3_close(ptr) declare i32 @sqlite3_close(ptr)

View File

@@ -32,7 +32,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
call void @Py_Initialize() call void @Py_Initialize()
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
@@ -46,9 +46,9 @@ _llgo_0:
%6 = call ptr @PyObject_CallNoArgs(ptr %5) %6 = call ptr @PyObject_CallNoArgs(ptr %5)
%7 = call double @PyFloat_AsDouble(ptr %4) %7 = call double @PyFloat_AsDouble(ptr %4)
%8 = call i32 (ptr, ...) @printf(ptr @0, double %7) %8 = call i32 (ptr, ...) @printf(ptr @0, double %7)
%9 = call ptr @PyBytes_AsString(ptr %6) %9 = call ptr @PyUnicode_AsUTF8(ptr %6)
%10 = call i32 (ptr, ...) @printf(ptr @1, ptr %9) %10 = call i32 (ptr, ...) @printf(ptr @1, ptr %9)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/py/math.init"() declare void @"github.com/goplus/llgo/py/math.init"()
@@ -67,7 +67,7 @@ declare double @PyFloat_AsDouble(ptr)
declare i32 @printf(ptr, ...) declare i32 @printf(ptr, ...)
declare ptr @PyBytes_AsString(ptr) declare ptr @PyUnicode_AsUTF8(ptr)
declare void @llgoLoadPyModSyms(ptr, ...) declare void @llgoLoadPyModSyms(ptr, ...)

12
cl/_testpy/gcd/in.go Normal file
View 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())
}

59
cl/_testpy/gcd/out.ll Normal file
View File

@@ -0,0 +1,59 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@__llgo_py.math.gcd = linkonce global ptr null
@0 = private unnamed_addr constant [22 x i8] c"gcd(60, 20, 25) = %d\0A\00", align 1
@__llgo_py.math = external global ptr
@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:
call void @Py_Initialize()
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(i32 60)
%3 = call ptr @PyLong_FromLong(i32 20)
%4 = call ptr @PyLong_FromLong(i32 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 i32 @PyLong_AsLong(ptr %6)
%8 = call i32 (ptr, ...) @printf(ptr @0, i32 %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(i32)
declare ptr @PyObject_CallFunctionObjArgs(ptr, ...)
declare i32 @PyLong_AsLong(ptr)
declare i32 @printf(ptr, ...)
declare void @llgoLoadPyModSyms(ptr, ...)
declare void @Py_Initialize()

View File

@@ -1,7 +1,6 @@
; ModuleID = 'math' ; ModuleID = 'math'
source_filename = "math" source_filename = "math"
@__llgo_py.math.sqrt = external global ptr
@"math.init$guard" = global ptr null @"math.init$guard" = global ptr null
@__llgo_py.math = linkonce global ptr null @__llgo_py.math = linkonce global ptr null
@0 = private unnamed_addr constant [5 x i8] c"math\00", align 1 @0 = private unnamed_addr constant [5 x i8] c"math\00", align 1

24
cl/_testpy/matrix/in.go Normal file
View 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())
}

121
cl/_testpy/matrix/out.ll Normal file
View File

@@ -0,0 +1,121 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@__llgo_py.numpy.add = linkonce global ptr null
@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
@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:
call void @Py_Initialize()
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, ...)
declare void @Py_Initialize()

10
cl/_testpy/pi/in.go Normal file
View 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())
}

49
cl/_testpy/pi/out.ll Normal file
View File

@@ -0,0 +1,49 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@0 = private unnamed_addr constant [9 x i8] c"pi = %f\0A\00", align 1
@__llgo_py.math = external global ptr
@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:
call void @Py_Initialize()
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, ...)
declare void @Py_Initialize()

12
cl/_testpy/pow/in.go Normal file
View 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())
}

58
cl/_testpy/pow/out.ll Normal file
View File

@@ -0,0 +1,58 @@
; ModuleID = 'main'
source_filename = "main"
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@__llgo_py.math.pow = linkonce global ptr null
@0 = private unnamed_addr constant [16 x i8] c"pow(2, 3) = %f\0A\00", align 1
@__llgo_py.math = external global ptr
@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:
call void @Py_Initialize()
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, ...)
declare void @Py_Initialize()

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -29,7 +29,7 @@ _llgo_0:
%2 = alloca i8, i64 4, align 1 %2 = alloca i8, i64 4, align 1
%3 = call ptr @memcpy(ptr %2, ptr @0, i64 4) %3 = call ptr @memcpy(ptr %2, ptr @0, i64 4)
%4 = call i32 (ptr, ...) @printf(ptr @1, ptr %2) %4 = call i32 (ptr, ...) @printf(ptr @1, ptr %2)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -27,7 +27,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -39,7 +39,7 @@ _llgo_0:
%5 = alloca i8, i64 %4, align 1 %5 = alloca i8, i64 %4, align 1
%6 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %5, %"github.com/goplus/llgo/internal/runtime.String" %2) %6 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %5, %"github.com/goplus/llgo/internal/runtime.String" %2)
%7 = call i32 (ptr, ...) @printf(ptr %6) %7 = call i32 (ptr, ...) @printf(ptr %6)
ret void ret i32 0
} }
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64) declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)

View File

@@ -29,7 +29,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -39,7 +39,7 @@ _llgo_0:
%3 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %2, i64 100) %3 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %2, i64 100)
%4 = call i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.iface" %3) %4 = call i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.iface" %3)
%5 = call i32 (ptr, ...) @printf(ptr @0, i64 %4) %5 = call i32 (ptr, ...) @printf(ptr @0, i64 %4)
ret void ret i32 0
} }
declare i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr) declare i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr)

View File

@@ -1,7 +1,7 @@
package main package main
import ( import (
"github.com/goplus/llgo/internal/runtime/c" "unsafe"
) )
var a int64 = 1<<63 - 1 var a int64 = 1<<63 - 1
@@ -11,41 +11,19 @@ var n uint64 = 1<<64 - 1
func main() { func main() {
var s = []int{1, 2, 3, 4} var s = []int{1, 2, 3, 4}
var a = [...]int{1, 2, 3, 4} var a = [...]int{1, 2, 3, 4}
d := make([]byte, 4, 10)
println(s, len(s), cap(s))
println(d, len(d), cap(d))
println(len(a), cap(a), cap(&a), len(&a))
println(len([]int{1, 2, 3, 4}), len([4]int{1, 2, 3, 4}))
println(len(s[1:]), cap(s[1:]), len(s[1:2]), cap(s[1:2]), len(s[1:2:2]), cap(s[1:2:2]))
println(len(a[1:]), cap(a[1:]), len(a[1:2]), cap(a[1:2]), len(a[1:2:2]), cap(a[1:2:2]))
out(len(s)) println("hello", "hello"[1:], "hello"[1:2], len("hello"[5:]))
out(len([]int{1, 2, 3, 4})) println(append(s, 5, 6, 7, 8))
out(len(a)) data := []byte{'a', 'b', 'c'}
out(len(&a)) data = append(data, "def"...)
out(len([4]int{1, 2, 3, 4})) println(data)
var i any = 100
out(cap(s)) println(true, 100, -100, uint(255), int32(-100), 100.5, i, &i, uintptr(unsafe.Pointer(&i)))
out(cap(a))
out(cap(&a))
out(len(s[1:]))
out(cap(s[1:]))
out(len(s[1:2]))
out(cap(s[1:2]))
out(len(s[1:2:2]))
out(cap(s[1:2:2]))
out(len(a[1:]))
out(cap(a[1:]))
out(len(a[1:2]))
out(cap(a[1:2]))
out(len(a[1:2:2]))
out(cap(a[1:2:2]))
string_len("hello")
string_len("hello"[1:])
string_len("hello"[1:2])
string_len("hello"[5:])
}
func string_len(s string) {
out(len(s))
}
func out(n int) {
c.Printf(c.Str("%d\n"), n)
} }

View File

@@ -3,6 +3,7 @@ source_filename = "main"
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 } %"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 } %"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr }
@main.a = global ptr null @main.a = global ptr null
@main.b = global ptr null @main.b = global ptr null
@@ -10,11 +11,50 @@ source_filename = "main"
@main.n = global ptr null @main.n = global ptr null
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@0 = private unnamed_addr constant [6 x i8] c"hello\00", align 1 @0 = private unnamed_addr constant [2 x i8] c" \00", align 1
@1 = private unnamed_addr constant [6 x i8] c"hello\00", align 1 @1 = private unnamed_addr constant [2 x i8] c" \00", align 1
@2 = private unnamed_addr constant [6 x i8] c"hello\00", align 1 @2 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@3 = private unnamed_addr constant [6 x i8] c"hello\00", align 1 @3 = private unnamed_addr constant [2 x i8] c" \00", align 1
@4 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 @4 = private unnamed_addr constant [2 x i8] c" \00", align 1
@5 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@6 = private unnamed_addr constant [2 x i8] c" \00", align 1
@7 = private unnamed_addr constant [2 x i8] c" \00", align 1
@8 = private unnamed_addr constant [2 x i8] c" \00", align 1
@9 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@10 = private unnamed_addr constant [2 x i8] c" \00", align 1
@11 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@12 = private unnamed_addr constant [2 x i8] c" \00", align 1
@13 = private unnamed_addr constant [2 x i8] c" \00", align 1
@14 = private unnamed_addr constant [2 x i8] c" \00", align 1
@15 = private unnamed_addr constant [2 x i8] c" \00", align 1
@16 = private unnamed_addr constant [2 x i8] c" \00", align 1
@17 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@18 = private unnamed_addr constant [2 x i8] c" \00", align 1
@19 = private unnamed_addr constant [2 x i8] c" \00", align 1
@20 = private unnamed_addr constant [2 x i8] c" \00", align 1
@21 = private unnamed_addr constant [2 x i8] c" \00", align 1
@22 = private unnamed_addr constant [2 x i8] c" \00", align 1
@23 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@24 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@25 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@26 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@27 = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@28 = private unnamed_addr constant [2 x i8] c" \00", align 1
@29 = private unnamed_addr constant [2 x i8] c" \00", align 1
@30 = private unnamed_addr constant [2 x i8] c" \00", align 1
@31 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@32 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@33 = private unnamed_addr constant [4 x i8] c"def\00", align 1
@34 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@35 = private unnamed_addr constant [2 x i8] c" \00", align 1
@36 = private unnamed_addr constant [2 x i8] c" \00", align 1
@37 = private unnamed_addr constant [2 x i8] c" \00", align 1
@38 = private unnamed_addr constant [2 x i8] c" \00", align 1
@39 = private unnamed_addr constant [2 x i8] c" \00", align 1
@40 = private unnamed_addr constant [2 x i8] c" \00", align 1
@41 = private unnamed_addr constant [2 x i8] c" \00", align 1
@42 = private unnamed_addr constant [2 x i8] c" \00", align 1
@43 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
define void @main.init() { define void @main.init() {
_llgo_0: _llgo_0:
@@ -32,7 +72,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -57,104 +97,220 @@ _llgo_0:
store i64 2, ptr %10, align 4 store i64 2, ptr %10, align 4
store i64 3, ptr %11, align 4 store i64 3, ptr %11, align 4
store i64 4, ptr %12, align 4 store i64 4, ptr %12, align 4
%13 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) %13 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 10)
call void @main.out(i64 %13) %14 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %13, i64 1, i64 10, i64 0, i64 4, i64 10)
%14 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32) %15 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 1
%15 = getelementptr inbounds i64, ptr %14, i64 0 %16 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
store i64 1, ptr %15, align 4 call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%16 = getelementptr inbounds i64, ptr %14, i64 1 %17 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 1)
store i64 2, ptr %16, align 4 call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %17)
%17 = getelementptr inbounds i64, ptr %14, i64 2 call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %15)
store i64 3, ptr %17, align 4 %18 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 1)
%18 = getelementptr inbounds i64, ptr %14, i64 3 call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %18)
store i64 4, ptr %18, align 4 call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %16)
%19 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %14, i64 8, i64 4, i64 0, i64 4, i64 4) %19 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 1)
%20 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %19) call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %19)
call void @main.out(i64 %20) %20 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %14, 1
call void @main.out(i64 4) %21 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %14, 2
call void @main.out(i64 4) call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %14)
call void @main.out(i64 4) %22 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 1)
%21 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %22)
call void @main.out(i64 %21) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %20)
call void @main.out(i64 4) %23 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @4, i64 1)
call void @main.out(i64 4) call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %23)
%22 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %21)
%23 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) %24 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 1)
%24 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %24)
%25 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %24, i64 8, i64 %22, i64 1, i64 %23, i64 %22) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
%26 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %25) %25 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @6, i64 1)
call void @main.out(i64 %26) call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %25)
%27 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
%28 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) %26 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 1)
%29 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %26)
%30 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %29, i64 8, i64 %27, i64 1, i64 %28, i64 %27) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
%31 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %30) %27 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @8, i64 1)
call void @main.out(i64 %31) call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %27)
%32 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
%33 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) %28 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @9, i64 1)
%34 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %33, i64 8, i64 %32, i64 1, i64 2, i64 %32) call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %28)
%35 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %34) %29 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
call void @main.out(i64 %35) %30 = getelementptr inbounds i64, ptr %29, i64 0
%36 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) store i64 1, ptr %30, align 4
%37 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) %31 = getelementptr inbounds i64, ptr %29, i64 1
%38 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %37, i64 8, i64 %36, i64 1, i64 2, i64 %36) store i64 2, ptr %31, align 4
%39 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %38) %32 = getelementptr inbounds i64, ptr %29, i64 2
call void @main.out(i64 %39) store i64 3, ptr %32, align 4
%40 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) %33 = getelementptr inbounds i64, ptr %29, i64 3
%41 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) store i64 4, ptr %33, align 4
%42 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %41, i64 8, i64 %40, i64 1, i64 2, i64 2) %34 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %29, i64 8, i64 4, i64 0, i64 4, i64 4)
%43 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %42) %35 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %34, 1
call void @main.out(i64 %43) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %35)
%44 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) %36 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @10, i64 1)
%45 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %36)
%46 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %45, i64 8, i64 %44, i64 1, i64 2, i64 2) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
%47 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %46) %37 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @11, i64 1)
call void @main.out(i64 %47) call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %37)
%48 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 4, i64 4) %38 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%49 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %48) %39 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
call void @main.out(i64 %49) %40 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
%50 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 4, i64 4) %41 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %40, i64 8, i64 %38, i64 1, i64 %39, i64 %38)
%51 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %50) %42 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %41, 1
call void @main.out(i64 %51) %43 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%52 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 4) %44 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%53 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %52) %45 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
call void @main.out(i64 %53) %46 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %45, i64 8, i64 %43, i64 1, i64 %44, i64 %43)
%54 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 4) %47 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %46, 2
%55 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %54) %48 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
call void @main.out(i64 %55) %49 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
%56 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 2) %50 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %49, i64 8, i64 %48, i64 1, i64 2, i64 %48)
%57 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %56) %51 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %50, 1
call void @main.out(i64 %57) %52 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
%58 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 2) %53 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
%59 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %58) %54 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %53, i64 8, i64 %52, i64 1, i64 2, i64 %52)
call void @main.out(i64 %59) %55 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %54, 2
%60 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 5) %56 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
call void @main.string_len(%"github.com/goplus/llgo/internal/runtime.String" %60) %57 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
%61 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 5) %58 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %57, i64 8, i64 %56, i64 1, i64 2, i64 2)
%62 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %61, 1 %59 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %58, 1
%63 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %61, i64 1, i64 %62) %60 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
call void @main.string_len(%"github.com/goplus/llgo/internal/runtime.String" %63) %61 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
%64 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 5) %62 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %61, i64 8, i64 %60, i64 1, i64 2, i64 2)
%65 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %64, i64 1, i64 2) %63 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %62, 2
call void @main.string_len(%"github.com/goplus/llgo/internal/runtime.String" %65) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %42)
%66 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 5) %64 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @12, i64 1)
%67 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %66, 1 call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %64)
%68 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %66, i64 5, i64 %67) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %47)
call void @main.string_len(%"github.com/goplus/llgo/internal/runtime.String" %68) %65 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @13, i64 1)
ret void call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %65)
} call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %51)
%66 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @14, i64 1)
define void @main.out(i64 %0) { call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %66)
_llgo_0: call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %55)
%1 = call i32 (ptr, ...) @printf(ptr @4, i64 %0) %67 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @15, i64 1)
ret void call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %67)
} call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %59)
%68 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @16, i64 1)
define void @main.string_len(%"github.com/goplus/llgo/internal/runtime.String" %0) { call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %68)
_llgo_0: call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %63)
%1 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %0, 1 %69 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @17, i64 1)
call void @main.out(i64 %1) call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %69)
ret void %70 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 4, i64 4)
%71 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %70, 1
%72 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 4, i64 4)
%73 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %72, 2
%74 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 4)
%75 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %74, 1
%76 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 4)
%77 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %76, 2
%78 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 2)
%79 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %78, 1
%80 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 2)
%81 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %80, 2
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %71)
%82 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @18, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %82)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %73)
%83 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @19, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %83)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %75)
%84 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @20, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %84)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %77)
%85 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @21, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %85)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %79)
%86 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @22, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %86)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %81)
%87 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @23, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %87)
%88 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @24, i64 5)
%89 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %88, 1
%90 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %88, i64 1, i64 %89)
%91 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @25, i64 5)
%92 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %91, i64 1, i64 2)
%93 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @26, i64 5)
%94 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %93, 1
%95 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %93, i64 5, i64 %94)
%96 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %95, 1
%97 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @27, i64 5)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %97)
%98 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @28, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %98)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %90)
%99 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @29, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %99)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %92)
%100 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @30, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %100)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %96)
%101 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @31, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %101)
%102 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%103 = getelementptr inbounds i64, ptr %102, i64 0
store i64 5, ptr %103, align 4
%104 = getelementptr inbounds i64, ptr %102, i64 1
store i64 6, ptr %104, align 4
%105 = getelementptr inbounds i64, ptr %102, i64 2
store i64 7, ptr %105, align 4
%106 = getelementptr inbounds i64, ptr %102, i64 3
store i64 8, ptr %106, align 4
%107 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %102, i64 8, i64 4, i64 0, i64 4, i64 4)
%108 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %107, 0
%109 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %107, 1
%110 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice" %7, ptr %108, i64 %109, i64 8)
call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %110)
%111 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @32, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %111)
%112 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 3)
%113 = getelementptr inbounds i8, ptr %112, i64 0
store i8 97, ptr %113, align 1
%114 = getelementptr inbounds i8, ptr %112, i64 1
store i8 98, ptr %114, align 1
%115 = getelementptr inbounds i8, ptr %112, i64 2
store i8 99, ptr %115, align 1
%116 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %112, i64 1, i64 3, i64 0, i64 3, i64 3)
%117 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @33, i64 3)
%118 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %117, 0
%119 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %117, 1
%120 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice" %116, ptr %118, i64 %119, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %120)
%121 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @34, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %121)
%122 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16)
%123 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
%124 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %123, i64 100)
store %"github.com/goplus/llgo/internal/runtime.iface" %124, ptr %122, align 8
%125 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %122, align 8
%126 = ptrtoint ptr %122 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 true)
%127 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @35, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %127)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 100)
%128 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @36, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %128)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 -100)
%129 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @37, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %129)
call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 255)
%130 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @38, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %130)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 -100)
%131 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @39, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %131)
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double 1.005000e+02)
%132 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @40, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %132)
call void @"github.com/goplus/llgo/internal/runtime.PrintIface"(%"github.com/goplus/llgo/internal/runtime.iface" %125)
%133 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @41, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %133)
call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr %122)
%134 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @42, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %134)
call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %126)
%135 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @43, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %135)
ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()
@@ -163,14 +319,28 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64) declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice") declare void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice") declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64) declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String", i64, i64) declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String", i64, i64)
declare i32 @printf(ptr, ...) declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice", ptr, i64, i64)
declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64)
declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr, i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1)
declare void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double)
declare void @"github.com/goplus/llgo/internal/runtime.PrintIface"(%"github.com/goplus/llgo/internal/runtime.iface")
declare void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr)

View File

@@ -28,7 +28,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -48,7 +48,7 @@ _llgo_0:
store ptr null, ptr %8, align 8 store ptr null, ptr %8, align 8
%9 = load { ptr, ptr }, ptr %6, align 8 %9 = load { ptr, ptr }, ptr %6, align 8
call void @main.callback(ptr @1, { ptr, ptr } %9) call void @main.callback(ptr @1, { ptr, ptr } %9)
ret void ret i32 0
} }
define void @main.print(ptr %0) { define void @main.print(ptr %0) {

View File

@@ -199,7 +199,7 @@ _llgo_2: ; preds = %_llgo_0
define void @main.cvtUinptr(i32 %0, i64 %1) { define void @main.cvtUinptr(i32 %0, i64 %1) {
_llgo_0: _llgo_0:
%2 = sext i32 %0 to i64 %2 = zext i32 %0 to i64
%3 = icmp ne i64 %2, %1 %3 = icmp ne i64 %2, %1
br i1 %3, label %_llgo_1, label %_llgo_2 br i1 %3, label %_llgo_1, label %_llgo_2
@@ -237,7 +237,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -298,7 +298,7 @@ _llgo_0:
call void @main.cvt32to64(i32 0, i64 0) call void @main.cvt32to64(i32 0, i64 0)
call void @main.cvt32to64(i32 2147483647, i64 2147483647) call void @main.cvt32to64(i32 2147483647, i64 2147483647)
call void @main.cvtUinptr(i32 1024, i64 1024) call void @main.cvtUinptr(i32 1024, i64 1024)
ret void ret i32 0
} }
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64) declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -47,7 +47,7 @@ _llgo_0:
%13 = extractvalue { ptr, ptr } %12, 1 %13 = extractvalue { ptr, ptr } %12, 1
%14 = extractvalue { ptr, ptr } %12, 0 %14 = extractvalue { ptr, ptr } %12, 0
call void %14(ptr %13) call void %14(ptr %13)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -11,6 +11,10 @@ func concat(args ...string) (ret string) {
return return
} }
func info(s string) string {
return "" + s + "..."
}
func main() { func main() {
result := concat("Hello", " ", "World") result := concat("Hello", " ", "World")
c.Fprintf(c.Stderr, c.Str("Hi, %s\n"), c.AllocaCStr(result)) c.Fprintf(c.Stderr, c.Str("Hi, %s\n"), c.AllocaCStr(result))

View File

@@ -6,25 +6,27 @@ source_filename = "main"
@"main.init$guard" = global ptr null @"main.init$guard" = global ptr null
@0 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 @0 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
@1 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
@2 = private unnamed_addr constant [4 x i8] c"...\00", align 1
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@1 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1 @3 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1
@2 = private unnamed_addr constant [2 x i8] c" \00", align 1 @4 = private unnamed_addr constant [2 x i8] c" \00", align 1
@3 = private unnamed_addr constant [6 x i8] c"World\00", align 1 @5 = private unnamed_addr constant [6 x i8] c"World\00", align 1
@__stderrp = external global ptr @__stderrp = external global ptr
@4 = private unnamed_addr constant [8 x i8] c"Hi, %s\0A\00", align 1 @6 = private unnamed_addr constant [8 x i8] c"Hi, %s\0A\00", align 1
define %"github.com/goplus/llgo/internal/runtime.String" @main.concat(%"github.com/goplus/llgo/internal/runtime.Slice" %0) { define %"github.com/goplus/llgo/internal/runtime.String" @main.concat(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0: _llgo_0:
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) %1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 0) %2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 0)
%3 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 0 %3 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 0
%4 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 1 %4 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 1
br label %_llgo_1 br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0 _llgo_1: ; preds = %_llgo_2, %_llgo_0
%5 = phi ptr [ %3, %_llgo_0 ], [ %18, %_llgo_2 ] %5 = phi ptr [ %3, %_llgo_0 ], [ %19, %_llgo_2 ]
%6 = phi i64 [ %4, %_llgo_0 ], [ %19, %_llgo_2 ] %6 = phi i64 [ %4, %_llgo_0 ], [ %20, %_llgo_2 ]
%7 = phi i64 [ -1, %_llgo_0 ], [ %12, %_llgo_2 ] %7 = phi i64 [ -1, %_llgo_0 ], [ %12, %_llgo_2 ]
%8 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %8 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %8, i32 0, i32 0 %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %8, i32 0, i32 0
@@ -37,18 +39,29 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
br i1 %13, label %_llgo_2, label %_llgo_3 br i1 %13, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1 _llgo_2: ; preds = %_llgo_1
%14 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) %14 = icmp slt i64 %12, 0
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i64 %12 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %14)
%16 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %15, align 8 %15 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
%17 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %11, %"github.com/goplus/llgo/internal/runtime.String" %16) %16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i64 %12
%18 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %17, 0 %17 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %16, align 8
%19 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %17, 1 %18 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %11, %"github.com/goplus/llgo/internal/runtime.String" %17)
%19 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %18, 0
%20 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %18, 1
br label %_llgo_1 br label %_llgo_1
_llgo_3: ; preds = %_llgo_1 _llgo_3: ; preds = %_llgo_1
ret %"github.com/goplus/llgo/internal/runtime.String" %11 ret %"github.com/goplus/llgo/internal/runtime.String" %11
} }
define %"github.com/goplus/llgo/internal/runtime.String" @main.info(%"github.com/goplus/llgo/internal/runtime.String" %0) {
_llgo_0:
%1 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 0)
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %1, %"github.com/goplus/llgo/internal/runtime.String" %0)
%3 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 3)
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %2, %"github.com/goplus/llgo/internal/runtime.String" %3)
ret %"github.com/goplus/llgo/internal/runtime.String" %4
}
define void @main.init() { define void @main.init() {
_llgo_0: _llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1 %0 = load i1, ptr @"main.init$guard", align 1
@@ -62,7 +75,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -70,13 +83,13 @@ _llgo_0:
call void @main.init() call void @main.init()
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48) %2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48)
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 0 %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 0
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 5) %4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 5)
store %"github.com/goplus/llgo/internal/runtime.String" %4, ptr %3, align 8 store %"github.com/goplus/llgo/internal/runtime.String" %4, ptr %3, align 8
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 1 %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 1
%6 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 1) %6 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @4, i64 1)
store %"github.com/goplus/llgo/internal/runtime.String" %6, ptr %5, align 8 store %"github.com/goplus/llgo/internal/runtime.String" %6, ptr %5, align 8
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 2 %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i64 2
%8 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 5) %8 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 5)
store %"github.com/goplus/llgo/internal/runtime.String" %8, ptr %7, align 8 store %"github.com/goplus/llgo/internal/runtime.String" %8, ptr %7, align 8
%9 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 16, i64 3, i64 0, i64 3, i64 3) %9 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 16, i64 3, i64 0, i64 3, i64 3)
%10 = call %"github.com/goplus/llgo/internal/runtime.String" @main.concat(%"github.com/goplus/llgo/internal/runtime.Slice" %9) %10 = call %"github.com/goplus/llgo/internal/runtime.String" @main.concat(%"github.com/goplus/llgo/internal/runtime.Slice" %9)
@@ -85,13 +98,11 @@ _llgo_0:
%13 = add i64 %12, 1 %13 = add i64 %12, 1
%14 = alloca i8, i64 %13, align 1 %14 = alloca i8, i64 %13, align 1
%15 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %14, %"github.com/goplus/llgo/internal/runtime.String" %10) %15 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %14, %"github.com/goplus/llgo/internal/runtime.String" %10)
%16 = call i32 (ptr, ptr, ...) @fprintf(ptr %11, ptr @4, ptr %15) %16 = call i32 (ptr, ptr, ...) @fprintf(ptr %11, ptr @6, ptr %15)
ret void ret i32 0
} }
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice") declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.String") declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.String")

View File

@@ -19,14 +19,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"() call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init() call void @main.init()
call void (ptr, ...) @printf(ptr @0) call void (ptr, ...) @printf(ptr @0)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -28,7 +28,7 @@ _llgo_0:
call void @main.init() call void @main.init()
%2 = load { [16 x i8], [2 x ptr] }, ptr @_bar_x, align 8 %2 = load { [16 x i8], [2 x ptr] }, ptr @_bar_x, align 8
%3 = load { [16 x i8] }, ptr @_bar_y, align 1 %3 = load { [16 x i8] }, ptr @_bar_y, align 1
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -20,7 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -28,7 +28,7 @@ _llgo_0:
call void @main.init() call void @main.init()
%2 = load ptr, ptr @__stderrp, align 8 %2 = load ptr, ptr @__stderrp, align 8
call void (ptr, ptr, ...) @fprintf(ptr %2, ptr @0, i64 100) call void (ptr, ptr, ...) @fprintf(ptr %2, ptr @0, i64 100)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -3,9 +3,9 @@ source_filename = "main"
%"github.com/goplus/llgo/internal/abi.Type" = type { i64, i64, i32, i8, i8, i8, i8, { ptr, ptr }, ptr, i32, i32 } %"github.com/goplus/llgo/internal/abi.Type" = type { i64, i64, i32, i8, i8, i8, i8, { ptr, ptr }, ptr, i32, i32 }
@main.basicTypes = global ptr null @main.basicTypes = global [25 x ptr] undef
@"main.init$guard" = global ptr null @"main.init$guard" = global ptr null
@main.sizeBasicTypes = global ptr null @main.sizeBasicTypes = global [25 x i64] undef
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@0 = private unnamed_addr constant [20 x i8] c"Kind: %d, Size: %d\0A\00", align 1 @0 = private unnamed_addr constant [20 x i8] c"Kind: %d, Size: %d\0A\00", align 1
@@ -50,7 +50,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -63,7 +63,7 @@ _llgo_0:
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 0
%7 = load i64, ptr %6, align 4 %7 = load i64, ptr %6, align 4
%8 = call i32 (ptr, ...) @printf(ptr @0, i64 %5, i64 %7) %8 = call i32 (ptr, ...) @printf(ptr @0, i64 %5, i64 %7)
ret void ret i32 0
} }
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)

View File

@@ -25,14 +25,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"() call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init() call void @main.init()
call void @main.foo(%"github.com/goplus/llgo/internal/runtime.iface" zeroinitializer) call void @main.foo(%"github.com/goplus/llgo/internal/runtime.iface" zeroinitializer)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main' ; ModuleID = 'main'
source_filename = "main" source_filename = "main"
@main.format = global ptr null @main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null @"main.init$guard" = global ptr null
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@@ -29,7 +29,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -37,7 +37,7 @@ _llgo_0:
call void @main.init() call void @main.init()
%2 = call i32 @strlen(ptr @main.format) %2 = call i32 @strlen(ptr @main.format)
call void (ptr, ...) @printf(ptr @main.format, i32 %2) call void (ptr, ...) @printf(ptr @main.format, i32 %2)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -29,7 +29,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -128,7 +128,7 @@ _llgo_0:
%70 = getelementptr inbounds i8, ptr %69, i64 1 %70 = getelementptr inbounds i8, ptr %69, i64 1
%71 = load i8, ptr %70, align 1 %71 = load i8, ptr %70, align 1
%72 = call i32 (ptr, ...) @printf(ptr @6, i8 %71) %72 = call i32 (ptr, ...) @printf(ptr @6, i8 %71)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -16,7 +16,7 @@ _llgo_0:
%2 = mul i64 %0, 4 %2 = mul i64 %0, 4
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 %2) %3 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 %2)
%4 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr %3, i64 %0, i64 %0) %4 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr %3, i64 %0, i64 %0)
%5 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %4) %5 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %4, 1
br label %_llgo_1 br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0 _llgo_1: ; preds = %_llgo_2, %_llgo_0
@@ -29,9 +29,11 @@ _llgo_2: ; preds = %_llgo_1
%9 = extractvalue { ptr, ptr } %1, 1 %9 = extractvalue { ptr, ptr } %1, 1
%10 = extractvalue { ptr, ptr } %1, 0 %10 = extractvalue { ptr, ptr } %1, 0
%11 = call i32 %10(ptr %9) %11 = call i32 %10(ptr %9)
%12 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %4) %12 = icmp slt i64 %7, 0
%13 = getelementptr inbounds i32, ptr %12, i64 %7 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %12)
store i32 %11, ptr %13, align 4 %13 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %4, 0
%14 = getelementptr inbounds i32, ptr %13, i64 %7
store i32 %11, ptr %14, align 4
br label %_llgo_1 br label %_llgo_1
_llgo_3: ; preds = %_llgo_1 _llgo_3: ; preds = %_llgo_1
@@ -63,7 +65,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -76,7 +78,7 @@ _llgo_0:
store ptr null, ptr %4, align 8 store ptr null, ptr %4, align 8
%5 = load { ptr, ptr }, ptr %2, align 8 %5 = load { ptr, ptr }, ptr %2, align 8
%6 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %5) %6 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %5)
%7 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %6) %7 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, 1
br label %_llgo_1 br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0 _llgo_1: ; preds = %_llgo_2, %_llgo_0
@@ -86,82 +88,86 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
br i1 %10, label %_llgo_2, label %_llgo_3 br i1 %10, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1 _llgo_2: ; preds = %_llgo_1
%11 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %6) %11 = icmp slt i64 %9, 0
%12 = getelementptr inbounds i32, ptr %11, i64 %9 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %11)
%13 = load i32, ptr %12, align 4 %12 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, 0
%14 = call i32 (ptr, ...) @printf(ptr @0, i32 %13) %13 = getelementptr inbounds i32, ptr %12, i64 %9
%14 = load i32, ptr %13, align 4
%15 = call i32 (ptr, ...) @printf(ptr @0, i32 %14)
br label %_llgo_1 br label %_llgo_1
_llgo_3: ; preds = %_llgo_1 _llgo_3: ; preds = %_llgo_1
%15 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4) %16 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
store i32 1, ptr %15, align 4 store i32 1, ptr %16, align 4
%16 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8) %17 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
%17 = getelementptr inbounds { ptr }, ptr %16, i32 0, i32 0 %18 = getelementptr inbounds { ptr }, ptr %17, i32 0, i32 0
store ptr %15, ptr %17, align 8 store ptr %16, ptr %18, align 8
%18 = alloca { ptr, ptr }, align 8 %19 = alloca { ptr, ptr }, align 8
%19 = getelementptr inbounds { ptr, ptr }, ptr %18, i32 0, i32 0 %20 = getelementptr inbounds { ptr, ptr }, ptr %19, i32 0, i32 0
store ptr @"main.main$1", ptr %19, align 8 store ptr @"main.main$1", ptr %20, align 8
%20 = getelementptr inbounds { ptr, ptr }, ptr %18, i32 0, i32 1 %21 = getelementptr inbounds { ptr, ptr }, ptr %19, i32 0, i32 1
store ptr %16, ptr %20, align 8 store ptr %17, ptr %21, align 8
%21 = load { ptr, ptr }, ptr %18, align 8 %22 = load { ptr, ptr }, ptr %19, align 8
%22 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %21) %23 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %22)
%23 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %22) %24 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %23, 1
br label %_llgo_4 br label %_llgo_4
_llgo_4: ; preds = %_llgo_5, %_llgo_3 _llgo_4: ; preds = %_llgo_5, %_llgo_3
%24 = phi i64 [ -1, %_llgo_3 ], [ %25, %_llgo_5 ] %25 = phi i64 [ -1, %_llgo_3 ], [ %26, %_llgo_5 ]
%25 = add i64 %24, 1 %26 = add i64 %25, 1
%26 = icmp slt i64 %25, %23 %27 = icmp slt i64 %26, %24
br i1 %26, label %_llgo_5, label %_llgo_6 br i1 %27, label %_llgo_5, label %_llgo_6
_llgo_5: ; preds = %_llgo_4 _llgo_5: ; preds = %_llgo_4
%27 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %22) %28 = icmp slt i64 %26, 0
%28 = getelementptr inbounds i32, ptr %27, i64 %25 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %28)
%29 = load i32, ptr %28, align 4 %29 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %23, 0
%30 = call i32 (ptr, ...) @printf(ptr @1, i32 %29) %30 = getelementptr inbounds i32, ptr %29, i64 %26
%31 = load i32, ptr %30, align 4
%32 = call i32 (ptr, ...) @printf(ptr @1, i32 %31)
br label %_llgo_4 br label %_llgo_4
_llgo_6: ; preds = %_llgo_4 _llgo_6: ; preds = %_llgo_4
%31 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4) %33 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
%32 = getelementptr inbounds %main.generator, ptr %31, i32 0, i32 0 %34 = getelementptr inbounds %main.generator, ptr %33, i32 0, i32 0
store i32 1, ptr %32, align 4 store i32 1, ptr %34, align 4
%33 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8) %35 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
%34 = getelementptr inbounds { ptr }, ptr %33, i32 0, i32 0 %36 = getelementptr inbounds { ptr }, ptr %35, i32 0, i32 0
store ptr %31, ptr %34, align 8 store ptr %33, ptr %36, align 8
%35 = alloca { ptr, ptr }, align 8 %37 = alloca { ptr, ptr }, align 8
%36 = getelementptr inbounds { ptr, ptr }, ptr %35, i32 0, i32 0 %38 = getelementptr inbounds { ptr, ptr }, ptr %37, i32 0, i32 0
store ptr @"main.next$bound", ptr %36, align 8 store ptr @"main.next$bound", ptr %38, align 8
%37 = getelementptr inbounds { ptr, ptr }, ptr %35, i32 0, i32 1 %39 = getelementptr inbounds { ptr, ptr }, ptr %37, i32 0, i32 1
store ptr %33, ptr %37, align 8 store ptr %35, ptr %39, align 8
%38 = load { ptr, ptr }, ptr %35, align 8 %40 = load { ptr, ptr }, ptr %37, align 8
%39 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %38) %41 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %40)
%40 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %39) %42 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %41, 1
br label %_llgo_7 br label %_llgo_7
_llgo_7: ; preds = %_llgo_8, %_llgo_6 _llgo_7: ; preds = %_llgo_8, %_llgo_6
%41 = phi i64 [ -1, %_llgo_6 ], [ %42, %_llgo_8 ] %43 = phi i64 [ -1, %_llgo_6 ], [ %44, %_llgo_8 ]
%42 = add i64 %41, 1 %44 = add i64 %43, 1
%43 = icmp slt i64 %42, %40 %45 = icmp slt i64 %44, %42
br i1 %43, label %_llgo_8, label %_llgo_9 br i1 %45, label %_llgo_8, label %_llgo_9
_llgo_8: ; preds = %_llgo_7 _llgo_8: ; preds = %_llgo_7
%44 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %39) %46 = icmp slt i64 %44, 0
%45 = getelementptr inbounds i32, ptr %44, i64 %42 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %46)
%46 = load i32, ptr %45, align 4 %47 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %41, 0
%47 = call i32 (ptr, ...) @printf(ptr @2, i32 %46) %48 = getelementptr inbounds i32, ptr %47, i64 %44
%49 = load i32, ptr %48, align 4
%50 = call i32 (ptr, ...) @printf(ptr @2, i32 %49)
br label %_llgo_7 br label %_llgo_7
_llgo_9: ; preds = %_llgo_7 _llgo_9: ; preds = %_llgo_7
ret void ret i32 0
} }
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr, i64, i64) declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr, i64, i64)
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice") declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -26,7 +26,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -34,7 +34,7 @@ _llgo_0:
call void @main.init() call void @main.init()
call void @"github.com/goplus/llgo/cl/internal/linktarget.F"(ptr @0, ptr @1, ptr @2, ptr @3) call void @"github.com/goplus/llgo/cl/internal/linktarget.F"(ptr @0, ptr @1, ptr @2, ptr @3)
call void @"github.com/goplus/llgo/cl/internal/linktarget.F"(ptr @4, ptr @5, ptr @6, ptr @7) call void @"github.com/goplus/llgo/cl/internal/linktarget.F"(ptr @4, ptr @5, ptr @6, ptr @7)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/cl/internal/linktarget.F"(ptr, ptr, ptr, ptr) declare void @"github.com/goplus/llgo/cl/internal/linktarget.F"(ptr, ptr, ptr, ptr)

View File

@@ -19,7 +19,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -27,7 +27,7 @@ _llgo_0:
call void @main.init() call void @main.init()
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"() %2 = call ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"()
%3 = call i32 (ptr, ...) @printf(ptr @0, <null operand!>) %3 = call i32 (ptr, ...) @printf(ptr @0, <null operand!>)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

42
cl/_testrt/mask/in.go Normal file
View File

@@ -0,0 +1,42 @@
package main
func main() {
println(mask(1))
println(mask_shl(127, 5))
println(mask_shl8(127, 5))
println(mask_shl8u(127, 5))
println(mask_shl8(127, 16))
println(mask_shl8u(127, 16))
println(mask_shr(127, 5))
println(mask_shr8(127, 5))
println(mask_shr8u(127, 5))
println(mask_shr8(127, 16))
}
func mask(x int8) int32 {
return int32(x) << 31 >> 31
}
func mask_shl8(x int8, y int) int8 {
return x << y
}
func mask_shl8u(x uint8, y int) uint8 {
return x << y
}
func mask_shl(x int, y int) int {
return x << y
}
func mask_shr8(x int8, y int) int8 {
return x >> y
}
func mask_shr8u(x uint8, y int) uint8 {
return x >> y
}
func mask_shr(x int, y int) int {
return x >> y
}

173
cl/_testrt/mask/out.ll Normal file
View File

@@ -0,0 +1,173 @@
; ModuleID = 'main'
source_filename = "main"
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@0 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@2 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@3 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@4 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@5 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@6 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@7 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@8 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@9 = private unnamed_addr constant [2 x i8] c"\0A\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
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 i32 @main.mask(i8 1)
%3 = sext i32 %2 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %3)
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
%5 = call i64 @main.mask_shl(i64 127, i64 5)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %5)
%6 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %6)
%7 = call i8 @main.mask_shl8(i8 127, i64 5)
%8 = sext i8 %7 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %8)
%9 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %9)
%10 = call i8 @main.mask_shl8u(i8 127, i64 5)
%11 = zext i8 %10 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %11)
%12 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %12)
%13 = call i8 @main.mask_shl8(i8 127, i64 16)
%14 = sext i8 %13 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %14)
%15 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @4, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %15)
%16 = call i8 @main.mask_shl8u(i8 127, i64 16)
%17 = zext i8 %16 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %17)
%18 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %18)
%19 = call i64 @main.mask_shr(i64 127, i64 5)
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %19)
%20 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @6, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %20)
%21 = call i8 @main.mask_shr8(i8 127, i64 5)
%22 = sext i8 %21 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %22)
%23 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %23)
%24 = call i8 @main.mask_shr8u(i8 127, i64 5)
%25 = zext i8 %24 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %25)
%26 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @8, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %26)
%27 = call i8 @main.mask_shr8(i8 127, i64 16)
%28 = sext i8 %27 to i64
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %28)
%29 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @9, i64 1)
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %29)
ret i32 0
}
define i32 @main.mask(i8 %0) {
_llgo_0:
%1 = sext i8 %0 to i32
%2 = shl i32 %1, 31
%3 = select i1 false, i32 0, i32 %2
%4 = ashr i32 %3, 31
ret i32 %4
}
define i64 @main.mask_shl(i64 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = icmp uge i64 %1, 64
%4 = shl i64 %0, %1
%5 = select i1 %3, i64 0, i64 %4
ret i64 %5
}
define i8 @main.mask_shl8(i8 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = trunc i64 %1 to i8
%4 = icmp uge i8 %3, 8
%5 = shl i8 %0, %3
%6 = select i1 %4, i8 0, i8 %5
ret i8 %6
}
define i8 @main.mask_shl8u(i8 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = trunc i64 %1 to i8
%4 = icmp uge i8 %3, 8
%5 = shl i8 %0, %3
%6 = select i1 %4, i8 0, i8 %5
ret i8 %6
}
define i64 @main.mask_shr(i64 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = icmp uge i64 %1, 64
%4 = select i1 %3, i64 63, i64 %1
%5 = ashr i64 %0, %4
ret i64 %5
}
define i8 @main.mask_shr8(i8 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = trunc i64 %1 to i8
%4 = icmp uge i8 %3, 8
%5 = select i1 %4, i8 7, i8 %3
%6 = ashr i8 %0, %5
ret i8 %6
}
define i8 @main.mask_shr8u(i8 %0, i64 %1) {
_llgo_0:
%2 = icmp slt i64 %1, 0
call void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1 %2)
%3 = trunc i64 %1 to i8
%4 = icmp uge i8 %3, 8
%5 = lshr i8 %0, %3
%6 = select i1 %4, i8 0, i8 %5
ret i8 %6
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)
declare void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.AssertNegativeShift"(i1)

View File

@@ -23,7 +23,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -120,7 +120,7 @@ _llgo_0:
%77 = extractvalue { ptr, ptr } %75, 0 %77 = extractvalue { ptr, ptr } %75, 0
%78 = call i64 %77(ptr %76, i64 -3) %78 = call i64 %77(ptr %76, i64 -3)
%79 = call i32 (ptr, ...) @printf(ptr @0, i64 %46, i64 %53, i64 %57, i64 %63, i64 %69, i64 %78) %79 = call i32 (ptr, ...) @printf(ptr @0, i64 %46, i64 %53, i64 %57, i64 %63, i64 %69, i64 %78)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -22,7 +22,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8

View File

@@ -19,7 +19,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -48,13 +48,15 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
br i1 %12, label %_llgo_2, label %_llgo_3 br i1 %12, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1 _llgo_2: ; preds = %_llgo_1
%13 = getelementptr inbounds i64, ptr %2, i64 %11 %13 = icmp slt i64 %11, 0
%14 = load i64, ptr %13, align 4 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %13)
%15 = call i32 (ptr, ...) @printf(ptr @0, i64 %14) %14 = getelementptr inbounds i64, ptr %2, i64 %11
%15 = load i64, ptr %14, align 4
%16 = call i32 (ptr, ...) @printf(ptr @0, i64 %15)
br label %_llgo_1 br label %_llgo_1
_llgo_3: ; preds = %_llgo_1 _llgo_3: ; preds = %_llgo_1
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()
@@ -72,4 +74,6 @@ _llgo_0:
ret i32 %5 ret i32 %5
} }
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare i32 @printf(ptr, ...) declare i32 @printf(ptr, ...)

View File

@@ -45,7 +45,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -69,7 +69,7 @@ _llgo_0:
%17 = extractvalue { ptr, ptr } %15, 0 %17 = extractvalue { ptr, ptr } %15, 0
%18 = call i64 %17(ptr %16, i64 100, i64 200) %18 = call i64 %17(ptr %16, i64 100, i64 200)
%19 = call i32 (ptr, ...) @printf(ptr @2, i64 %18, i64 %14) %19 = call i32 (ptr, ...) @printf(ptr @2, i64 %18, i64 %14)
ret void ret i32 0
} }
define i64 @"main.add$1"(i64 %0, i64 %1) { define i64 @"main.add$1"(i64 %0, i64 %1) {

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main' ; ModuleID = 'main'
source_filename = "main" source_filename = "main"
@main.format = global ptr null @main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null @"main.init$guard" = global ptr null
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@@ -29,7 +29,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -37,7 +37,7 @@ _llgo_0:
call void @main.init() call void @main.init()
%2 = call i32 @strlen(ptr @main.format) %2 = call i32 @strlen(ptr @main.format)
call void (ptr, ...) @printf(ptr @main.format, i32 %2) call void (ptr, ...) @printf(ptr @main.format, i32 %2)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -3,7 +3,7 @@ source_filename = "main"
%main.Foo = type { i32, i1 } %main.Foo = type { i32, i1 }
@main.format = global ptr null @main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null @"main.init$guard" = global ptr null
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@@ -57,7 +57,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -71,7 +71,7 @@ _llgo_0:
store i1 true, ptr %5, align 1 store i1 true, ptr %5, align 1
%6 = load %main.Foo, ptr %3, align 4 %6 = load %main.Foo, ptr %3, align 4
call void @"(main.Foo).Print"(%main.Foo %6) call void @"(main.Foo).Print"(%main.Foo %6)
ret void ret i32 0
} }
declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64) declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)

View File

@@ -21,7 +21,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -39,26 +39,28 @@ _llgo_0:
%7 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 8, i64 4, i64 0, i64 4, i64 4) %7 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 8, i64 4, i64 0, i64 4, i64 4)
%8 = call i64 @main.sum(%"github.com/goplus/llgo/internal/runtime.Slice" %7) %8 = call i64 @main.sum(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
%9 = call i32 (ptr, ...) @printf(ptr @0, i64 %8) %9 = call i32 (ptr, ...) @printf(ptr @0, i64 %8)
ret void ret i32 0
} }
define i64 @main.sum(%"github.com/goplus/llgo/internal/runtime.Slice" %0) { define i64 @main.sum(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0: _llgo_0:
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) %1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
br label %_llgo_1 br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0 _llgo_1: ; preds = %_llgo_2, %_llgo_0
%2 = phi i64 [ 0, %_llgo_0 ], [ %9, %_llgo_2 ] %2 = phi i64 [ 0, %_llgo_0 ], [ %10, %_llgo_2 ]
%3 = phi i64 [ -1, %_llgo_0 ], [ %4, %_llgo_2 ] %3 = phi i64 [ -1, %_llgo_0 ], [ %4, %_llgo_2 ]
%4 = add i64 %3, 1 %4 = add i64 %3, 1
%5 = icmp slt i64 %4, %1 %5 = icmp slt i64 %4, %1
br i1 %5, label %_llgo_2, label %_llgo_3 br i1 %5, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1 _llgo_2: ; preds = %_llgo_1
%6 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) %6 = icmp slt i64 %4, 0
%7 = getelementptr inbounds i64, ptr %6, i64 %4 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %6)
%8 = load i64, ptr %7, align 4 %7 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
%9 = add i64 %2, %8 %8 = getelementptr inbounds i64, ptr %7, i64 %4
%9 = load i64, ptr %8, align 4
%10 = add i64 %2, %9
br label %_llgo_1 br label %_llgo_1
_llgo_3: ; preds = %_llgo_1 _llgo_3: ; preds = %_llgo_1
@@ -73,6 +75,4 @@ declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llg
declare i32 @printf(ptr, ...) declare i32 @printf(ptr, ...)
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice") declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice")

View File

@@ -1,7 +1,7 @@
; ModuleID = 'main' ; ModuleID = 'main'
source_filename = "main" source_filename = "main"
@main.format = global ptr null @main.format = global [10 x i8] undef
@"main.init$guard" = global ptr null @"main.init$guard" = global ptr null
@__llgo_argc = global ptr null @__llgo_argc = global ptr null
@__llgo_argv = global ptr null @__llgo_argv = global ptr null
@@ -45,7 +45,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -57,7 +57,7 @@ _llgo_0:
store i32 100, ptr %3, align 4 store i32 100, ptr %3, align 4
store i1 true, ptr %4, align 1 store i1 true, ptr %4, align 1
call void @main.Print(ptr %2) call void @main.Print(ptr %2)
ret void ret i32 0
} }
declare void @printf(ptr, ...) declare void @printf(ptr, ...)

View File

@@ -25,7 +25,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void ret void
} }
define void @main(i32 %0, ptr %1) { define i32 @main(i32 %0, ptr %1) {
_llgo_0: _llgo_0:
store i32 %0, ptr @__llgo_argc, align 4 store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8 store ptr %1, ptr @__llgo_argv, align 8
@@ -33,7 +33,7 @@ _llgo_0:
call void @main.init() call void @main.init()
call void @main.foo() call void @main.foo()
%2 = call i32 (ptr, ...) @printf(ptr @0) %2 = call i32 (ptr, ...) @printf(ptr @0)
ret void ret i32 0
} }
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -226,5 +226,5 @@ func TestErrVarOf(t *testing.T) {
} }
ssaPkg := &ssa.Package{Pkg: pkgTypes} ssaPkg := &ssa.Package{Pkg: pkgTypes}
g := &ssa.Global{Pkg: ssaPkg} g := &ssa.Global{Pkg: ssaPkg}
ctx.varOf(g) ctx.varOf(nil, g)
} }

View File

@@ -152,6 +152,10 @@ type context struct {
phis []func() phis []func()
} }
func (p *context) inMain(instr ssa.Instruction) bool {
return instr.Parent().Name() == "main"
}
func (p *context) compileType(pkg llssa.Package, t *ssa.Type) { func (p *context) compileType(pkg llssa.Package, t *ssa.Type) {
tn := t.Object().(*types.TypeName) tn := t.Object().(*types.TypeName)
if tn.IsAlias() { // don't need to compile alias type if tn.IsAlias() { // don't need to compile alias type
@@ -176,7 +180,7 @@ func (p *context) compileMethods(pkg llssa.Package, typ types.Type) {
for i, n := 0, mthds.Len(); i < n; i++ { for i, n := 0, mthds.Len(); i < n; i++ {
mthd := mthds.At(i) mthd := mthds.At(i)
if ssaMthd := prog.MethodValue(mthd); ssaMthd != nil { if ssaMthd := prog.MethodValue(mthd); ssaMthd != nil {
p.compileFuncDecl(pkg, ssaMthd, false) p.compileFuncDecl(pkg, ssaMthd)
} }
} }
} }
@@ -185,7 +189,7 @@ func (p *context) compileMethods(pkg llssa.Package, typ types.Type) {
func (p *context) compileGlobal(pkg llssa.Package, gbl *ssa.Global) { func (p *context) compileGlobal(pkg llssa.Package, gbl *ssa.Global) {
typ := gbl.Type() typ := gbl.Type()
name, vtype := p.varName(gbl.Pkg.Pkg, gbl) name, vtype := p.varName(gbl.Pkg.Pkg, gbl)
if ignoreName(name) || checkCgo(gbl.Name()) { if vtype == pyVar || ignoreName(name) || checkCgo(gbl.Name()) {
return return
} }
if debugInstr { if debugInstr {
@@ -211,14 +215,16 @@ var (
argvTy = types.NewPointer(types.NewPointer(types.Typ[types.Int8])) argvTy = types.NewPointer(types.NewPointer(types.Typ[types.Int8]))
) )
func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function, call bool) (llssa.Function, llssa.PyObjRef, int) { func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Function, llssa.PyObjRef, int) {
pkgTypes, name, ftype := p.funcName(f, true) pkgTypes, name, ftype := p.funcName(f, true)
if ftype != goFunc { if ftype != goFunc {
/*
if ftype == pyFunc { if ftype == pyFunc {
// TODO(xsw): pyMod == "" // TODO(xsw): pyMod == ""
fnName := pysymPrefix + p.pyMod + "." + name fnName := pysymPrefix + p.pyMod + "." + name
return nil, pkg.NewPyFunc(fnName, f.Signature, call), pyFunc return nil, pkg.NewPyFunc(fnName, f.Signature, call), pyFunc
} }
*/
return nil, nil, ignoredFunc return nil, nil, ignoredFunc
} }
fn := pkg.FuncOf(name) fn := pkg.FuncOf(name)
@@ -236,7 +242,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function, call bool)
sig = llssa.FuncAddCtx(ctx, sig) sig = llssa.FuncAddCtx(ctx, sig)
} else { } else {
if debugInstr { if debugInstr {
log.Println("==> NewFunc", name, "type:", sig.Recv(), sig) log.Println("==> NewFunc", name, "type:", sig.Recv(), sig, "ftype:", ftype)
} }
} }
if fn == nil { if fn == nil {
@@ -244,10 +250,13 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function, call bool)
argc := types.NewParam(token.NoPos, pkgTypes, "", types.Typ[types.Int32]) argc := types.NewParam(token.NoPos, pkgTypes, "", types.Typ[types.Int32])
argv := types.NewParam(token.NoPos, pkgTypes, "", argvTy) argv := types.NewParam(token.NoPos, pkgTypes, "", argvTy)
params := types.NewTuple(argc, argv) params := types.NewTuple(argc, argv)
sig = types.NewSignatureType(nil, nil, nil, params, nil, false) ret := types.NewParam(token.NoPos, pkgTypes, "", p.prog.CInt().RawType())
results := types.NewTuple(ret)
sig = types.NewSignatureType(nil, nil, nil, params, results, false)
} }
fn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), hasCtx) fn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), hasCtx)
} }
if nblk := len(f.Blocks); nblk > 0 { if nblk := len(f.Blocks); nblk > 0 {
fn.MakeBlocks(nblk) // to set fn.HasBody() = true fn.MakeBlocks(nblk) // to set fn.HasBody() = true
p.inits = append(p.inits, func() { p.inits = append(p.inits, func() {
@@ -291,7 +300,7 @@ func (p *context) funcOf(fn *ssa.Function) (aFn llssa.Function, pyFn llssa.PyObj
pkg := p.pkg pkg := p.pkg
fnName := pysymPrefix + mod + "." + name fnName := pysymPrefix + mod + "." + name
if pyFn = pkg.PyObjOf(fnName); pyFn == nil { if pyFn = pkg.PyObjOf(fnName); pyFn == nil {
pyFn = pkg.NewPyFunc(fnName, fn.Signature, true) pyFn = pkg.PyNewFunc(fnName, fn.Signature, true)
return return
} }
} }
@@ -310,6 +319,8 @@ func (p *context) funcOf(fn *ssa.Function) (aFn llssa.Function, pyFn llssa.PyObj
ftype = llgoAllocaCStr ftype = llgoAllocaCStr
case "stringData": case "stringData":
ftype = llgoStringData ftype = llgoStringData
case "pyList":
ftype = llgoPyList
case "unreachable": case "unreachable":
ftype = llgoUnreachable ftype = llgoUnreachable
default: default:
@@ -367,7 +378,7 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
b.SetBlockEx(ret, llssa.AfterInit) b.SetBlockEx(ret, llssa.AfterInit)
for _, modName := range modNames { for _, modName := range modNames {
objs := mods[modName] objs := mods[modName]
b.LoadPyModSyms(modName, objs...) b.PyLoadModSyms(modName, objs...)
} }
} }
}) })
@@ -391,13 +402,13 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
jumpTo := p.jumpTo(jump) jumpTo := p.jumpTo(jump)
modPath := p.pyMod modPath := p.pyMod
modName := pysymPrefix + modPath modName := pysymPrefix + modPath
modPtr := pkg.NewPyModVar(modName, true).Expr modPtr := pkg.PyNewModVar(modName, true).Expr
mod := b.Load(modPtr) mod := b.Load(modPtr)
cond := b.BinOp(token.NEQ, mod, prog.Null(mod.Type)) cond := b.BinOp(token.NEQ, mod, prog.Null(mod.Type))
newBlk := p.fn.MakeBlock() newBlk := p.fn.MakeBlock()
b.If(cond, jumpTo, newBlk) b.If(cond, jumpTo, newBlk)
b.SetBlock(newBlk) b.SetBlock(newBlk)
b.Store(modPtr, b.ImportPyMod(modPath)) b.Store(modPtr, b.PyImportMod(modPath))
b.Jump(jumpTo) b.Jump(jumpTo)
} }
return ret return ret
@@ -600,6 +611,9 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
case pyFunc: case pyFunc:
args := p.compileValues(b, args, kind) args := p.compileValues(b, args, kind)
ret = b.Call(pyFn.Expr, args...) ret = b.Call(pyFn.Expr, args...)
case llgoPyList:
args := p.compileValues(b, args, fnHasVArg)
ret = b.PyList(args...)
case llgoCstr: case llgoCstr:
ret = cstr(b, args) ret = cstr(b, args)
case llgoAdvance: case llgoAdvance:
@@ -772,6 +786,10 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
results[i] = p.compileValue(b, r) results[i] = p.compileValue(b, r)
} }
} }
if p.inMain(instr) {
results = make([]llssa.Expr, 1)
results[0] = p.prog.IntVal(0, p.prog.CInt())
}
b.Return(results...) b.Return(results...)
case *ssa.If: case *ssa.If:
fn := p.fn fn := p.fn
@@ -797,7 +815,7 @@ func (p *context) compileFunction(v *ssa.Function) (goFn llssa.Function, pyFn ll
// v.Pkg == nil: means auto generated function? // v.Pkg == nil: means auto generated function?
if v.Pkg == p.goPkg || v.Pkg == nil { if v.Pkg == p.goPkg || v.Pkg == nil {
// function in this package // function in this package
goFn, pyFn, kind = p.compileFuncDecl(p.pkg, v, true) goFn, pyFn, kind = p.compileFuncDecl(p.pkg, v)
if kind != ignoredFunc { if kind != ignoredFunc {
return return
} }
@@ -824,8 +842,7 @@ func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr {
} }
return pyFn.Expr return pyFn.Expr
case *ssa.Global: case *ssa.Global:
g := p.varOf(v) return p.varOf(b, v)
return g.Expr
case *ssa.Const: case *ssa.Const:
t := types.Default(v.Type()) t := types.Default(v.Type())
return b.Const(v.Value, p.prog.Type(t, llssa.InGo)) return b.Const(v.Value, p.prog.Type(t, llssa.InGo))
@@ -916,7 +933,7 @@ func NewPackage(prog llssa.Program, pkg *ssa.Package, files []*ast.File) (ret ll
// Do not try to build generic (non-instantiated) functions. // Do not try to build generic (non-instantiated) functions.
continue continue
} }
ctx.compileFuncDecl(ret, member, false) ctx.compileFuncDecl(ret, member)
case *ssa.Type: case *ssa.Type:
ctx.compileType(ret, member) ctx.compileType(ret, member)
case *ssa.Global: case *ssa.Global:

View File

@@ -45,7 +45,7 @@ func TestFromTestdata(t *testing.T) {
} }
func TestSqlite(t *testing.T) { func TestSqlite(t *testing.T) {
cltest.Pkg(t, "github.com/goplus/llgo/x/sqlite", "../x/sqlite/sqlite.ll") cltest.Pkg(t, "github.com/goplus/llgo/c/sqlite", "../c/sqlite/llgo_autogen.ll")
} }
func TestFromTestpymath(t *testing.T) { func TestFromTestpymath(t *testing.T) {

View File

@@ -318,6 +318,7 @@ const (
llgoAdvance = llgoInstrBase + 4 llgoAdvance = llgoInstrBase + 4
llgoIndex = llgoInstrBase + 5 llgoIndex = llgoInstrBase + 5
llgoStringData = llgoInstrBase + 6 llgoStringData = llgoInstrBase + 6
llgoPyList = llgoInstrBase + 7
) )
func (p *context) funcName(fn *ssa.Function, ignore bool) (*types.Package, string, int) { func (p *context) funcName(fn *ssa.Function, ignore bool) (*types.Package, string, int) {
@@ -358,24 +359,35 @@ const (
ignoredVar = iota ignoredVar = iota
goVar = int(llssa.InGo) goVar = int(llssa.InGo)
cVar = int(llssa.InC) cVar = int(llssa.InC)
pyVar = int(llssa.InPython)
) )
func (p *context) varName(pkg *types.Package, v *ssa.Global) (vName string, vtype int) { func (p *context) varName(pkg *types.Package, v *ssa.Global) (vName string, vtype int) {
name := llssa.FullName(pkg, v.Name()) name := llssa.FullName(pkg, v.Name())
if v, ok := p.link[name]; ok { if v, ok := p.link[name]; ok {
if strings.HasPrefix(v, "py.") {
return v[3:], pyVar
}
return v, cVar return v, cVar
} }
return name, goVar return name, goVar
} }
func (p *context) varOf(v *ssa.Global) (ret llssa.Global) { func (p *context) varOf(b llssa.Builder, v *ssa.Global) llssa.Expr {
pkgTypes := p.ensureLoaded(v.Pkg.Pkg) pkgTypes := p.ensureLoaded(v.Pkg.Pkg)
pkg := p.pkg pkg := p.pkg
name, vtype := p.varName(pkgTypes, v) name, vtype := p.varName(pkgTypes, v)
if ret = pkg.VarOf(name); ret == nil { if vtype == pyVar {
if kind, mod := pkgKindByScope(pkgTypes.Scope()); kind == PkgPyModule {
return b.PyNewVar(pysymPrefix+mod, name).Expr
}
panic("unreachable")
}
ret := pkg.VarOf(name)
if ret == nil {
ret = pkg.NewVar(name, v.Type(), llssa.Background(vtype)) ret = pkg.NewVar(name, v.Type(), llssa.Background(vtype))
} }
return return ret.Expr
} }
func (p *context) ensureLoaded(pkgTypes *types.Package) *types.Package { func (p *context) ensureLoaded(pkgTypes *types.Package) *types.Package {

Binary file not shown.

View File

@@ -200,19 +200,21 @@ func buildAllPkgs(prog llssa.Program, initial []*packages.Package, mode Mode, ve
if isPkgInLLGo(pkgPath) { if isPkgInLLGo(pkgPath) {
pkg.ExportFile = concatPkgLinkFiles(pkgPath) pkg.ExportFile = concatPkgLinkFiles(pkgPath)
} else { } else {
panic("todo") // panic("todo")
// TODO(xsw): support packages out of llgo
pkg.ExportFile = ""
} }
if kind == cl.PkgLinkExtern { // need to be linked with external library if kind == cl.PkgLinkExtern { // need to be linked with external library
linkFile := os.ExpandEnv(strings.TrimSpace(param)) linkFile := os.ExpandEnv(strings.TrimSpace(param))
dir, lib := filepath.Split(linkFile) dir, lib := filepath.Split(linkFile)
command := " -l " + lib command := " -l " + lib
if dir != "" { if dir != "" {
command += " -L " + dir command += " -L " + dir[:len(dir)-1]
} }
if isMultiLinkFiles(pkg.ExportFile) { if isSingleLinkFile(pkg.ExportFile) {
pkg.ExportFile = command + pkg.ExportFile
} else {
pkg.ExportFile = command + " " + pkg.ExportFile pkg.ExportFile = command + " " + pkg.ExportFile
} else {
pkg.ExportFile = command + pkg.ExportFile
} }
} }
default: default:
@@ -369,6 +371,7 @@ var (
"-x": false, // -x: print the commands "-x": false, // -x: print the commands
"-tags": true, // -tags 'tag,list': a space-separated list of build tags to consider satisfied during the build "-tags": true, // -tags 'tag,list': a space-separated list of build tags to consider satisfied during the build
"-pkgdir": true, // -pkgdir dir: install and load all packages from dir instead of the usual locations "-pkgdir": true, // -pkgdir dir: install and load all packages from dir instead of the usual locations
"-ldflags": true, // --ldflags 'flag list': arguments to pass on each go tool link invocation
} }
) )
@@ -401,7 +404,11 @@ func SkipFlagArgs(args []string) int {
} }
func checkFlag(arg string, i *int, verbose *bool, swflags map[string]bool) { func checkFlag(arg string, i *int, verbose *bool, swflags map[string]bool) {
if hasarg, ok := swflags[arg]; ok { if pos := strings.IndexByte(arg, '='); pos > 0 {
if verbose != nil && arg == "-v=true" {
*verbose = true
}
} else if hasarg, ok := swflags[arg]; ok {
if hasarg { if hasarg {
*i++ *i++
} else if verbose != nil && arg == "-v" { } else if verbose != nil && arg == "-v" {
@@ -454,14 +461,14 @@ func llgoRoot() string {
} }
func appendLinkFiles(args []string, file string) []string { func appendLinkFiles(args []string, file string) []string {
if isMultiLinkFiles(file) { if isSingleLinkFile(file) {
return append(args, strings.Split(file[1:], " ")...)
}
return append(args, file) return append(args, file)
}
return append(args, strings.Split(file[1:], " ")...)
} }
func isMultiLinkFiles(ret string) bool { func isSingleLinkFile(ret string) bool {
return len(ret) > 0 && ret[0] == ' ' return len(ret) > 0 && ret[0] != ' '
} }
func concatPkgLinkFiles(pkgPath string) string { func concatPkgLinkFiles(pkgPath string) string {

View File

@@ -103,8 +103,6 @@ func SmartDoFile(inFile string, pkgPath ...string) {
fname := autgenFile fname := autgenFile
if inCompilerDir(absDir) { if inCompilerDir(absDir) {
fname = "out.ll" fname = "out.ll"
} else if inSqlite(absDir) {
fname = "sqlite.ll"
} }
outFile := dir + fname outFile := dir + fname
@@ -129,7 +127,3 @@ func genZip(dir string, outFile, inFile string) {
func inCompilerDir(dir string) bool { func inCompilerDir(dir string) bool {
return strings.Contains(dir, "/llgo/cl/") return strings.Contains(dir, "/llgo/cl/")
} }
func inSqlite(dir string) bool {
return strings.HasSuffix(dir, "/llgo/x/sqlite")
}

27
internal/runtime/error.go Normal file
View File

@@ -0,0 +1,27 @@
package runtime
type errorString string
func (e errorString) RuntimeError() {}
func (e errorString) Error() string {
return "runtime error: " + string(e)
}
func AssertRuntimeError(b bool, msg string) {
if b {
panic(errorString(msg).Error())
}
}
func AssertNegativeShift(b bool) {
if b {
panic(errorString("negative shift amount").Error())
}
}
func AssertIndexRange(b bool) {
if b {
panic(errorString("index out of range").Error())
}
}

Binary file not shown.

172
internal/runtime/print.go Normal file
View File

@@ -0,0 +1,172 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package runtime
import (
"unsafe"
"github.com/goplus/llgo/c"
)
// The compiler knows that a print of a value of this type
// should use printhex instead of printuint (decimal).
func bytes(s string) (ret []byte) {
rp := (*Slice)(unsafe.Pointer(&ret))
sp := (*String)(unsafe.Pointer(&s))
rp.data = sp.data
rp.len = sp.len
rp.cap = sp.len
return
}
func gwrite(b []byte) {
if len(b) == 0 {
return
}
for _, v := range b {
c.Fprintf(c.Stderr, 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 PrintComplex(c complex128) {
// print("(", real(c), imag(c), "i)")
// }
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))
}
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 >= 0 {
break
}
v /= 16
}
i--
buf[i] = 'x'
i--
buf[i] = '0'
gwrite(buf[i:])
}
func PrintPointer(p unsafe.Pointer) {
PrintHex(uint64(uintptr(p)))
}
func PrintString(s string) {
gwrite(bytes(s))
}
func PrintSlice(s Slice) {
sp := (*Slice)(unsafe.Pointer(&s))
print("[", s.len, "/", s.cap, "]")
PrintPointer(sp.data)
}
func PrintIface(i iface) {
print("(", i.tab, ",", i.data, ")")
}

40
internal/runtime/slice.go Normal file
View File

@@ -0,0 +1,40 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package runtime
// nextslicecap computes the next appropriate slice length.
func nextslicecap(newLen, oldCap int) int {
newcap := oldCap
doublecap := newcap + newcap
if newLen > doublecap {
return newLen
}
const threshold = 256
if oldCap < threshold {
return doublecap
}
for {
// Transition from growing 2x for small slices
// to growing 1.25x for large slices. This formula
// gives a smooth-ish transition between the two.
newcap += (newcap + 3*threshold) >> 2
// We need to check `newcap >= newLen` and whether `newcap` overflowed.
// newLen is guaranteed to be larger than zero, hence
// when newcap overflows then `uint(newcap) > uint(newLen)`.
// This allows to check for both with the same comparison.
if uint(newcap) >= uint(newLen) {
break
}
}
// Set newcap to the requested cap when
// the newcap calculation overflowed.
if newcap <= 0 {
return newLen
}
return newcap
}

View File

@@ -70,4 +70,25 @@ func SliceData(s Slice) unsafe.Pointer {
return s.data return s.data
} }
// SliceAppend append elem data and returns a slice.
func SliceAppend(src Slice, data unsafe.Pointer, num, etSize int) Slice {
if etSize == 0 {
return src
}
oldLen := src.len
newLen := src.len + num
if newLen > src.cap {
newCap := nextslicecap(newLen, src.cap)
p := AllocZ(uintptr(newCap * etSize))
if oldLen != 0 {
c.Memcpy(p, src.data, uintptr(oldLen*etSize))
}
src.data = p
src.cap = newCap
}
src.len = newLen
c.Memcpy(c.Advance(src.data, oldLen*etSize), data, uintptr(num*etSize))
return src
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

49
py/_pyg/llpyg/llpyg.c Normal file
View File

@@ -0,0 +1,49 @@
#include <stdlib.h>
#include <stdio.h>
typedef struct PyObject PyObject;
void Py_Initialize();
PyObject* PyImport_ImportModule(const char* modName);
PyObject* PyModule_GetDict(PyObject* mod);
PyObject* PyObject_Str(PyObject* obj);
PyObject* PyDict_Keys(PyObject* dict);
PyObject* PyList_GetItem(PyObject* list, size_t index);
PyObject* PyTuple_GetItem(PyObject* tuple, size_t index);
PyObject* PyObject_GetAttr(PyObject* mod, PyObject* attrName);
PyObject* PyObject_GetAttrString(PyObject* mod, const char* attrName);
PyObject* PyObject_CallOneArg(PyObject* fn, PyObject* arg);
const char* PyUnicode_AsUTF8(PyObject* str);
size_t PyList_Size(PyObject* list);
int PyCallable_Check(PyObject*);
int main() {
Py_Initialize();
PyObject* inspect = PyImport_ImportModule("inspect");
PyObject* signature = PyObject_GetAttrString(inspect, "signature");
PyObject* mod = PyImport_ImportModule("numpy");
PyObject* dict = PyModule_GetDict(mod);
PyObject* keys = PyDict_Keys(dict);
size_t i, n;
n = PyList_Size(keys);
for (i = 0; i < n; i++) {
PyObject* key = PyList_GetItem(keys, i);
PyObject* val = PyObject_GetAttr(mod, key);
if (PyCallable_Check(val) != 0) {
PyObject* doc = PyObject_GetAttrString(val, "__doc__");
PyObject* sig = PyObject_CallOneArg(signature, val);
printf("-----------------------------------\n");
printf("sig: %p\n", sig);
printf("%s: %s\n", PyUnicode_AsUTF8(key), PyUnicode_AsUTF8(PyObject_Str(sig)));
printf("%s\n", PyUnicode_AsUTF8(key));
if (doc != NULL) {
printf("%s\n", PyUnicode_AsUTF8(doc));
}
}
}
return 0;
}

View File

@@ -1,5 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
// example: // example:
// llgoLoadPyModSyms(mod, "name1", &func1, "name2", &func2, NULL) // llgoLoadPyModSyms(mod, "name1", &func1, "name2", &func2, NULL)
@@ -23,3 +24,30 @@ void llgoLoadPyModSyms(PyObject* mod, ...) {
} }
va_end(ap); va_end(ap);
} }
/*
wchar_t* toWcs(const char* str) {
size_t len = mbstowcs(NULL, str, 0);
wchar_t* wstr = (wchar_t*)malloc((len + 1) * sizeof(wchar_t));
mbstowcs(wstr, str, len + 1);
return wstr;
}
char* toMbs(const wchar_t* str) {
size_t len = wcstombs(NULL, str, 0);
char* mstr = (char*)malloc(len + 1);
wcstombs(mstr, str, len + 1);
return mstr;
}
wchar_t *Py_GetPath();
void Py_SetPath(const wchar_t* path);
void Py_Initialize();
void llgoPyInitialize() {
setenv("PYTHONPATH", "/opt/homebrew/lib/python3.12/site-packages", 1);
Py_Initialize();
printf("sys.path = %s\n", toMbs(Py_GetPath()));
}
*/

33
py/arg.go Normal file
View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024 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 py
import (
_ "unsafe"
"github.com/goplus/llgo/c"
)
// https://docs.python.org/3/c-api/arg.html
// Create a new value based on a format string similar to those accepted by the
// PyArg_Parse* family of functions and a sequence of values. Returns the value or
// nil in the case of an error; an exception will be raised if nil is returned.
// See https://docs.python.org/3/c-api/arg.html#c.Py_BuildValue
//
//go:linkname BuildValue C.Py_BuildValue
func BuildValue(format *c.Char, __llgo_va_list ...any) *Object

61
py/builtins/builtins.go Normal file
View File

@@ -0,0 +1,61 @@
/*
* Copyright (c) 2024 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 builtins
import (
_ "unsafe"
"github.com/goplus/llgo/py"
)
const (
LLGoPackage = "py.inspect"
)
// https://docs.python.org/3/library/functions.html
// https://docs.python.org/3/library/constants.html
// print(*objects, sep=' ', end='\n', file=None, flush=False)
//
// Print objects to the text stream file, separated by sep and followed by
// end. sep, end, file, and flush, if present, must be given as keyword
// arguments.
//
// All non-keyword arguments are converted to strings like str() does and
// written to the stream, separated by sep and followed by end. Both sep
// and end must be strings; they can also be None, which means to use the
// default values. If no objects are given, print() will just write end.
//
//go:linkname Print py.print
func Print(objects ...*py.Object)
//go:linkname PrintEx py.print
func PrintEx(__llgo_kwargs *py.Object, objects ...*py.Object)
// Invoke the built-in help system. (This function is intended for interactive
// use.) If no argument is given, the interactive help system starts on the
// interpreter console. If the argument is a string, then the string is looked
// up as the name of a module, function, class, method, keyword, or documentation
// topic, and a help page is printed on the console. If the argument is any other
// kind of object, a help page on the object is generated.
//
// Note that if a slash(/) appears in the parameter list of a function when invoking
// help(), it means that the parameters prior to the slash are positional-only. For
// more info, see the FAQ entry on positional-only parameters.
//
//go:linkname Help py.help
func Help(object *py.Object)

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More