Compare commits
357 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
908f0047f8 | ||
|
|
e533903cee | ||
|
|
1be8052caa | ||
|
|
668ce4bd2d | ||
|
|
e7fd038493 | ||
|
|
03edb3bbbe | ||
|
|
307a1a295a | ||
|
|
446df58e92 | ||
|
|
1ad5caba93 | ||
|
|
9eddc0e4f0 | ||
|
|
087ba0d81d | ||
|
|
3c5cd8f38f | ||
|
|
367743530f | ||
|
|
7370ce2793 | ||
|
|
ba61b42ef5 | ||
|
|
f7e362dd90 | ||
|
|
66da072fd7 | ||
|
|
d763534208 | ||
|
|
ad05898543 | ||
|
|
f930f7878d | ||
|
|
d6a75c411b | ||
|
|
568a71e0dc | ||
|
|
c92e9aac2c | ||
|
|
3012c4a3ff | ||
|
|
ebe338ac9a | ||
|
|
a45523a48c | ||
|
|
5bfeea67d7 | ||
|
|
f35f15d36c | ||
|
|
057af792df | ||
|
|
41a850e7b2 | ||
|
|
6be70390a6 | ||
|
|
1cfe3ee9f8 | ||
|
|
c1927c985a | ||
|
|
309f42994b | ||
|
|
feb28ecace | ||
|
|
00f74b7f0a | ||
|
|
fcc0e1776b | ||
|
|
a5ec755c28 | ||
|
|
98945926ca | ||
|
|
d3e3767df4 | ||
|
|
de1281bb66 | ||
|
|
07e55c3d89 | ||
|
|
6e4ebeddf4 | ||
|
|
2b9fb88bf0 | ||
|
|
022965b9c7 | ||
|
|
6278718a24 | ||
|
|
1675daafcd | ||
|
|
ed5b6edf52 | ||
|
|
638caa355c | ||
|
|
78b2f9b455 | ||
|
|
2a35ffcc27 | ||
|
|
5eae8f9af6 | ||
|
|
25381e20d2 | ||
|
|
fc35ff5cd1 | ||
|
|
b10d00b426 | ||
|
|
c634dc25b4 | ||
|
|
2fb4561bf8 | ||
|
|
f167c6dcca | ||
|
|
555ace9e2e | ||
|
|
d07ffb36ad | ||
|
|
9e2b8b77c9 | ||
|
|
29e4af4fb2 | ||
|
|
91513a12b4 | ||
|
|
ee3f55dd41 | ||
|
|
c2e5a78076 | ||
|
|
da3ac3e93d | ||
|
|
278ebbc9bd | ||
|
|
546f93147e | ||
|
|
3e7bfbb45c | ||
|
|
c2cf0443ef | ||
|
|
59d68c6438 | ||
|
|
e0ee199bf1 | ||
|
|
c1bf895674 | ||
|
|
ea4d92e671 | ||
|
|
e3f56105d4 | ||
|
|
c447a87605 | ||
|
|
584e5b1f01 | ||
|
|
207dc4c112 | ||
|
|
6a3581f7a3 | ||
|
|
11e74975b3 | ||
|
|
75ef9ec524 | ||
|
|
9b742e777b | ||
|
|
5d93565e16 | ||
|
|
cebfe5c95b | ||
|
|
7881f3a53b | ||
|
|
56269bd52b | ||
|
|
68c43a2cc9 | ||
|
|
120b507c75 | ||
|
|
44fe7e8dc4 | ||
|
|
75d679f141 | ||
|
|
e9570f2400 | ||
|
|
5b8567310c | ||
|
|
f882221db3 | ||
|
|
8c4d7bd641 | ||
|
|
6a78695fde | ||
|
|
73ad16dedd | ||
|
|
dd98112c5a | ||
|
|
47521d3579 | ||
|
|
0c31300578 | ||
|
|
6340ff7da0 | ||
|
|
b66cb49d80 | ||
|
|
c884184220 | ||
|
|
091fee61e0 | ||
|
|
172a268e77 | ||
|
|
924715fe34 | ||
|
|
35a73b4cde | ||
|
|
238f9593f9 | ||
|
|
9e8b5703dc | ||
|
|
d8bd8be57e | ||
|
|
a4d4e8b3a9 | ||
|
|
703dd17e33 | ||
|
|
bc654a462e | ||
|
|
11535825c0 | ||
|
|
196df40c99 | ||
|
|
7aee6c3a15 | ||
|
|
372b566d23 | ||
|
|
9550354442 | ||
|
|
95c3ddfc39 | ||
|
|
bf4f2b6fa0 | ||
|
|
d3f75a92ad | ||
|
|
369495c8d3 | ||
|
|
dd52f71069 | ||
|
|
af8e2bc19d | ||
|
|
947e5591ea | ||
|
|
521376e8e8 | ||
|
|
55c0adb23d | ||
|
|
b20ad7047f | ||
|
|
fa3149c660 | ||
|
|
1463ed4835 | ||
|
|
b959de18d5 | ||
|
|
edac3f73c2 | ||
|
|
388b19eed5 | ||
|
|
a337136389 | ||
|
|
31d5a8ac10 | ||
|
|
46527f56ce | ||
|
|
a575c17eca | ||
|
|
a6ea3b1e6f | ||
|
|
4d2ad842a4 | ||
|
|
ce0f5f3797 | ||
|
|
9e0d22ac90 | ||
|
|
ddc2c56115 | ||
|
|
acfbe6902a | ||
|
|
f7dfab481b | ||
|
|
23692430d5 | ||
|
|
03fe594339 | ||
|
|
45babef689 | ||
|
|
9ac0450255 | ||
|
|
b1d55f657d | ||
|
|
aac5e7b3cd | ||
|
|
791634c377 | ||
|
|
090149eab6 | ||
|
|
acecbf587d | ||
|
|
4ef46971d0 | ||
|
|
2e3cc49782 | ||
|
|
8a0189b079 | ||
|
|
0edd7f6df0 | ||
|
|
0b058bc2e8 | ||
|
|
f9ef9cab81 | ||
|
|
fbb2150d88 | ||
|
|
0912f1f509 | ||
|
|
64c13fa9ae | ||
|
|
2a5f9d9641 | ||
|
|
6c32fe87e6 | ||
|
|
09e9cc99d3 | ||
|
|
94a7ee024a | ||
|
|
a2d7a8c978 | ||
|
|
15499ddc14 | ||
|
|
97cb312386 | ||
|
|
92827a1f04 | ||
|
|
00222c7808 | ||
|
|
427d87be68 | ||
|
|
2560a333b6 | ||
|
|
c6b76db789 | ||
|
|
1414853fce | ||
|
|
cbe384a3be | ||
|
|
cca46573ea | ||
|
|
2589c23998 | ||
|
|
29830865d9 | ||
|
|
35dbc7b0b5 | ||
|
|
cd266213ce | ||
|
|
875eadeb19 | ||
|
|
67896c63a7 | ||
|
|
c643f734e9 | ||
|
|
31d91f5e87 | ||
|
|
2a92f1bc55 | ||
|
|
d9db5528f5 | ||
|
|
22a4ffb78b | ||
|
|
1fb37c37fe | ||
|
|
aae663e5e5 | ||
|
|
e985eda857 | ||
|
|
c9cc7ad9f7 | ||
|
|
65f88cc64e | ||
|
|
374ff92444 | ||
|
|
6d56a60d2b | ||
|
|
75aea37ced | ||
|
|
b133f70b6b | ||
|
|
093af00bbe | ||
|
|
f1da2613be | ||
|
|
1800c52c04 | ||
|
|
329f65a1ad | ||
|
|
d4dd0c00ff | ||
|
|
d9a24f5ac2 | ||
|
|
a13d9a92bd | ||
|
|
2b70bb60a9 | ||
|
|
48737e361a | ||
|
|
8e9f019f82 | ||
|
|
f6a7815837 | ||
|
|
5016de56fe | ||
|
|
879e4a0061 | ||
|
|
6eaf21e5a6 | ||
|
|
b0b38c02b2 | ||
|
|
cd8e1f2080 | ||
|
|
6cc58c194f | ||
|
|
14cf646c47 | ||
|
|
d49197cbe9 | ||
|
|
1687faa438 | ||
|
|
f0e3e556cf | ||
|
|
c9e8709490 | ||
|
|
52dcfaa452 | ||
|
|
9b5a30896d | ||
|
|
4e1450bbb5 | ||
|
|
d478efe444 | ||
|
|
dacb662d99 | ||
|
|
f8cd76bd92 | ||
|
|
6392fd41c6 | ||
|
|
9d91152f01 | ||
|
|
13972c932b | ||
|
|
81ec9017fc | ||
|
|
79b11b9f51 | ||
|
|
d474a051fd | ||
|
|
073cac8530 | ||
|
|
bc3dca45e7 | ||
|
|
ff36c3dfae | ||
|
|
5a5d86ccc3 | ||
|
|
942b1f5159 | ||
|
|
c93fce87da | ||
|
|
1038b06510 | ||
|
|
f8de6022dc | ||
|
|
a8ead2543d | ||
|
|
db856c4391 | ||
|
|
68949c28c8 | ||
|
|
cf67795ff4 | ||
|
|
1136526e4c | ||
|
|
0edeb5cfd0 | ||
|
|
bc7412f6c9 | ||
|
|
025cff9494 | ||
|
|
445e7154e8 | ||
|
|
4eb7e4000b | ||
|
|
028c6cdf50 | ||
|
|
b08ae1dff3 | ||
|
|
37e7d66343 | ||
|
|
e6d06cc278 | ||
|
|
017fd150cd | ||
|
|
ea7e1de833 | ||
|
|
c2767be178 | ||
|
|
c60be43ac6 | ||
|
|
c373a5b505 | ||
|
|
da20aea408 | ||
|
|
973b5b90dc | ||
|
|
cffb5e9539 | ||
|
|
4b35586566 | ||
|
|
1e075d4830 | ||
|
|
c81b5b5df9 | ||
|
|
80b2b8d061 | ||
|
|
d1a7f63797 | ||
|
|
92359dd03b | ||
|
|
d1430c9f5a | ||
|
|
7feca4478e | ||
|
|
02b1d5ed84 | ||
|
|
99d74ce4b6 | ||
|
|
355094c7e2 | ||
|
|
7f61989869 | ||
|
|
7223ff004a | ||
|
|
df333fb144 | ||
|
|
5c08c55957 | ||
|
|
26b812a62a | ||
|
|
cd3d9c709f | ||
|
|
9da90e7ecf | ||
|
|
f17a4ca1de | ||
|
|
8ab662b373 | ||
|
|
fb839da81e | ||
|
|
244da4b10a | ||
|
|
c0c5271172 | ||
|
|
0066f8bd3f | ||
|
|
be9d209622 | ||
|
|
2bbd828f3a | ||
|
|
4f1b6e95a1 | ||
|
|
87ca3a39dc | ||
|
|
d7df46d578 | ||
|
|
489cbc4782 | ||
|
|
3c33a1d05e | ||
|
|
067cf0cba6 | ||
|
|
03a194a514 | ||
|
|
bdf45c0fcb | ||
|
|
6f679c05a3 | ||
|
|
0b131bd957 | ||
|
|
ebf4c80aff | ||
|
|
18a63e226a | ||
|
|
92f56a2f90 | ||
|
|
926e2d4a2e | ||
|
|
5d1d51dd58 | ||
|
|
52018cd424 | ||
|
|
e9153defee | ||
|
|
889fc8b6a9 | ||
|
|
9b9da3133d | ||
|
|
1c8edb0387 | ||
|
|
c0ef1598c9 | ||
|
|
bc1acee6f5 | ||
|
|
9f25d73826 | ||
|
|
f07a62d136 | ||
|
|
06d6b447e4 | ||
|
|
1cff02e4cc | ||
|
|
809a400f57 | ||
|
|
f1bb42f554 | ||
|
|
4fd8f84536 | ||
|
|
223c24450e | ||
|
|
8a7ddf4dc2 | ||
|
|
08217e5a5a | ||
|
|
424dbd9261 | ||
|
|
b615ada2c3 | ||
|
|
20a47873d0 | ||
|
|
d87ce1a124 | ||
|
|
91d012d33d | ||
|
|
330cb22351 | ||
|
|
236debab33 | ||
|
|
13a1c8ac4b | ||
|
|
29fad7b397 | ||
|
|
8eeac8a26d | ||
|
|
133d41d748 | ||
|
|
d444123062 | ||
|
|
4a5c8d3fbb | ||
|
|
afd3d40348 | ||
|
|
85da86a4f1 | ||
|
|
72d4f0f7f8 | ||
|
|
192b479f18 | ||
|
|
3e6dfa3c05 | ||
|
|
5bd28a1e9e | ||
|
|
a23a2601e4 | ||
|
|
3220b629c7 | ||
|
|
9cf122c31a | ||
|
|
75d513a78a | ||
|
|
3cbe4aac87 | ||
|
|
3e47a977e4 | ||
|
|
40855c2d2a | ||
|
|
b2319eda66 | ||
|
|
5c5b8e62e5 | ||
|
|
fbb1f89ab3 | ||
|
|
25b104cf13 | ||
|
|
be1599b418 | ||
|
|
d462e548b1 | ||
|
|
df1e4708f5 | ||
|
|
cf02f4a34f | ||
|
|
480cf09177 | ||
|
|
52a64a7770 | ||
|
|
8d3cb246c2 | ||
|
|
8f15fd45f2 | ||
|
|
afd02b3d78 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -8,12 +8,18 @@
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
test.db
|
||||
llgo_autogen.ll
|
||||
stories*.bin
|
||||
.DS_Store
|
||||
err.log
|
||||
numpy.txt
|
||||
|
||||
_go/
|
||||
_runtime/
|
||||
_tinygo/
|
||||
build.dir/
|
||||
.vscode/
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "c/llama2/llama2.c"]
|
||||
path = c/llama2/llama2.c
|
||||
url = https://github.com/karpathy/llama2.c.git
|
||||
230
README.md
230
README.md
@@ -8,4 +8,232 @@ llgo - A Go compiler based on LLVM
|
||||
[](https://pkg.go.dev/github.com/goplus/llgo)
|
||||
[](https://github.com/goplus/gop)
|
||||
|
||||
This is a Go compiler based on LLVM in order to better integrate Go with the C ecosystem. 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
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/c"
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("Hello world\n"))
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## Python support
|
||||
|
||||
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
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := math.Sqrt(py.Float(2))
|
||||
c.Printf(c.Str("sqrt(2) = %f\n"), x.Float64())
|
||||
}
|
||||
```
|
||||
|
||||
Here, We call `py.Float(2)` to create a Python number 2, and pass it to Python’s `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
|
||||
|
||||
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
|
||||
|
||||
Follow these steps to generate the `llgo` command (its usage is the same as the `go` command):
|
||||
|
||||
### on macOS
|
||||
|
||||
```sh
|
||||
brew update # execute if needed
|
||||
brew install llvm@17
|
||||
go install -v ./...
|
||||
```
|
||||
|
||||
### on Linux
|
||||
|
||||
```sh
|
||||
echo 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-17 main' | sudo tee /etc/apt/sources.list.d/llvm.list
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
||||
sudo apt-get update # execute if needed
|
||||
sudo apt-get install --no-install-recommends llvm-17-dev
|
||||
go install -v ./...
|
||||
```
|
||||
|
||||
### on Windows
|
||||
|
||||
TODO
|
||||
|
||||
|
||||
## Development tools
|
||||
|
||||
* [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.
|
||||
|
||||
How do I generate these tools?
|
||||
|
||||
```sh
|
||||
go install -v ./... # compile all tools except pydump
|
||||
cd chore/_xtool
|
||||
llgo install ./... # compile pydump
|
||||
```
|
||||
|
||||
## Key modules
|
||||
|
||||
Below are the key modules for understanding the implementation principles of `llgo`:
|
||||
|
||||
* [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`.
|
||||
* [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`.
|
||||
|
||||
21
_demo/concat/concat.go
Normal file
21
_demo/concat/concat.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
func concat(args ...string) (ret string) {
|
||||
for _, v := range args {
|
||||
ret += v
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
result := concat("Hello", " ", "World")
|
||||
c.Fprintf(c.Stderr, c.Str("Hi, %s\n"), c.AllocaCStr(result))
|
||||
}
|
||||
|
||||
/* Expected output (stderr):
|
||||
Hi, Hello World
|
||||
*/
|
||||
63
_demo/genints/gen_ints.go
Normal file
63
_demo/genints/gen_ints.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
type generator struct {
|
||||
val c.Int
|
||||
}
|
||||
|
||||
func (g *generator) next() c.Int {
|
||||
g.val++
|
||||
return g.val
|
||||
}
|
||||
|
||||
func genInts(n int, gen func() c.Int) []c.Int {
|
||||
a := make([]c.Int, n)
|
||||
for i := range a {
|
||||
a[i] = gen()
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func main() {
|
||||
// generate 5 random integers
|
||||
for _, v := range genInts(5, c.Rand) {
|
||||
c.Printf(c.Str("%d\n"), v)
|
||||
}
|
||||
|
||||
// generate 5 integers, each is double of the previous one
|
||||
initVal := c.Int(1)
|
||||
ints := genInts(5, func() c.Int {
|
||||
initVal *= 2
|
||||
return initVal
|
||||
})
|
||||
for _, v := range ints {
|
||||
c.Printf(c.Str("%d\n"), v)
|
||||
}
|
||||
|
||||
// generate 5 integers, each is incremented by 1
|
||||
g := &generator{val: 1}
|
||||
for _, v := range genInts(5, g.next) {
|
||||
c.Printf(c.Str("%d\n"), v)
|
||||
}
|
||||
}
|
||||
|
||||
/* Posible output:
|
||||
16807
|
||||
282475249
|
||||
1622650073
|
||||
984943658
|
||||
1144108930
|
||||
2
|
||||
4
|
||||
8
|
||||
16
|
||||
32
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
*/
|
||||
13
_demo/hello/hello.go
Normal file
13
_demo/hello/hello.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("Hello world\n"))
|
||||
}
|
||||
|
||||
/* Expected output:
|
||||
Hello World
|
||||
*/
|
||||
137
_demo/llama2-c/README.md
Normal file
137
_demo/llama2-c/README.md
Normal file
@@ -0,0 +1,137 @@
|
||||
llama2 - Inference Llama 2 in LLGo
|
||||
=====
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/llama_cute.jpg" width="300" height="300" alt="Cute Llama">
|
||||
</p>
|
||||
|
||||
Have you ever wanted to inference a baby [Llama 2](https://ai.meta.com/llama/) model in Go? No? Well, now you can!
|
||||
|
||||
This is based on [llama2.c](https://github.com/karpathy/llama2.c), we didn't port anything! So it's very different from these Go implementations:
|
||||
* https://github.com/nikolaydubina/llama2.go
|
||||
* https://github.com/tmc/go-llama2
|
||||
|
||||
llgo plays a great role as a bridge, allowing the C ecosystem to be seamlessly connected to Go.
|
||||
|
||||
You might think that you need many billion parameter LLMs to do anything useful, but in fact very small LLMs can have surprisingly strong performance if you make the domain narrow enough (ref: [TinyStories](https://huggingface.co/datasets/roneneldan/TinyStories) paper). This repo is a "fullstack" train + inference solution for Llama 2 LLM, with focus on minimalism and simplicity.
|
||||
|
||||
As the architecture is identical, you can also load and inference Meta's Llama 2 models. However, the current code only inferences models in fp32, so you will most likely not be able to productively load models larger than 7B.
|
||||
|
||||
## feel the magic
|
||||
|
||||
How to run this example? The simplest way is to run it without any arguments:
|
||||
|
||||
```bash
|
||||
llgo run .
|
||||
```
|
||||
|
||||
This means it uses the default model checkpoint file (`stories15M.bin`), and the default prompt (`Once upon a time`).
|
||||
|
||||
You need download the model checkpoint file first. Download this 15M parameter model trained on the [TinyStories](https://huggingface.co/datasets/roneneldan/TinyStories) dataset (~60MB download):
|
||||
|
||||
```bash
|
||||
wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin
|
||||
```
|
||||
|
||||
If you want to specify a prompt (eg. `Long long ago`):
|
||||
|
||||
```bash
|
||||
llgo run . 'Long long ago'
|
||||
```
|
||||
|
||||
We can also try a bit bigger 42M parameter model (ie. `stories42M.bin`):
|
||||
|
||||
```bash
|
||||
wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories42M.bin
|
||||
llgo run . -m stories42M.bin 'Long long ago'
|
||||
```
|
||||
|
||||
There is also an even better 110M param model available, see [models](#models).
|
||||
|
||||
Quick note on sampling, the recommendation for ~best results is to sample with `-t 1.0 -p 0.9`, i.e. temperature 1.0 (default) but also top-p sampling at 0.9 (default). Intuitively, top-p ensures that tokens with tiny probabilities do not get sampled, so we can't get "unlucky" during sampling, and we are less likely to go "off the rails" afterwards. More generally, to control the diversity of samples use either the temperature (i.e. vary `-t` between 0 and 1 and keep top-p off with `-p 0`) or the top-p value (i.e. vary `-p` between 0 and 1 and keep `-t 1`), but not both. Nice explainers on LLM sampling strategies include [this](https://peterchng.com/blog/2023/05/02/token-selection-strategies-top-k-top-p-and-temperature/), [this](https://docs.cohere.com/docs/controlling-generation-with-top-k-top-p) or [this](https://huggingface.co/blog/how-to-generate).
|
||||
|
||||
|
||||
## Meta's Llama 2 models
|
||||
|
||||
As the neural net architecture is identical, we can also inference the Llama 2 models released by Meta. Sadly there is a bit of friction here due to licensing (I can't directly upload the checkpoints, I think). So Step 1, get the Llama 2 checkpoints by following the [Meta instructions](https://github.com/facebookresearch/llama). Once we have those checkpoints, we have to convert them into the llama2.c format.
|
||||
For this we need to install the python dependencies (`pip install -r requirements.txt`) and then use the `export.py` file, e.g. for 7B model:
|
||||
|
||||
```bash
|
||||
python export.py llama2_7b.bin --meta-llama path/to/llama/model/7B
|
||||
```
|
||||
|
||||
The export will take ~10 minutes or so and generate a 26GB file (the weights of the 7B model in float32) called `llama2_7b.bin` in the current directory. It has been [reported](https://github.com/karpathy/llama2.c/pull/85) that despite efforts. I would not attempt to run anything above 7B right now for two reasons: first, 13B+ currently doesn't work because of integer flow in pointer arithmetic, which is yet to be fixed, and second, even if it were fixed, this repo is doing float32 inference right now, so it would be fairly unusably slow. Once the export is done, we can run it:
|
||||
|
||||
```bash
|
||||
./run llama2_7b.bin
|
||||
```
|
||||
|
||||
This ran at about 4 tokens/s compiled with [OpenMP](#OpenMP) on 96 threads on my CPU Linux box in the cloud. (On my MacBook Air M1, currently it's closer to 30 seconds per token if you just build with `make runfast`.) Example output:
|
||||
|
||||
> The purpose of this document is to highlight the state-of-the-art of CoO generation technologies, both recent developments and those in commercial use. The focus is on the technologies with the highest merit to become the dominating processes of the future and therefore to be technologies of interest to S&T ... R&D. As such, CoO generation technologies developed in Russia, Japan and Europe are described in some depth. The document starts with an introduction to cobalt oxides as complex products and a short view on cobalt as an essential material. The document continues with the discussion of the available CoO generation processes with respect to energy and capital consumption as well as to environmental damage.
|
||||
|
||||
base models... ¯\\_(ツ)_/¯. Since we can inference the base model, it should be possible to also inference the chat model quite easily, and have a conversation with it. And if we can find a way to run 7B more efficiently, we can start adding LoRA to our training script, and going wild with finetunes all within the repo!
|
||||
|
||||
You can also try Meta's Code Llama models even if support for them is incomplete. In particular, some hyperparameters changed (e.g. the constant in RoPE layer), so the inference is not exactly correct and a bit buggy right now. Looking into fixes. Make sure to build the tokenizer for the plain and instruct variants and pass it when doing inference.
|
||||
|
||||
```bash
|
||||
python export.py codellama2_7b.bin --meta-llama /path/to/CodeLlama-7b
|
||||
python tokenizer.py --tokenizer-model=/path/to/CodeLlama-7b/tokenizer.model
|
||||
./run codellama2_7b.bin -z /path/to/CodeLlama-7b/tokenizer.bin
|
||||
```
|
||||
|
||||
Chat with Code Llama Instruct:
|
||||
|
||||
```bash
|
||||
python export.py codellama2_7b_instruct.bin --meta-llama /path/to/CodeLlama-7b-Instruct
|
||||
python tokenizer.py --tokenizer-model=/path/to/CodeLlama-7b-Instruct/tokenizer.model
|
||||
./run codellama2_7b_instruct.bin -m chat -z /path/to/CodeLlama-7b-Instruct/tokenizer.bin
|
||||
```
|
||||
|
||||
|
||||
## huggingface models
|
||||
|
||||
We can load any huggingface models that use the Llama 2 architecture. See the script [export.py](export.py) and the `--hf` flag to export the model .bin file.
|
||||
|
||||
## models
|
||||
|
||||
For the sake of examples of smaller, from-scratch models, I trained a small model series on TinyStories. All of these trained in a few hours on my training setup (4X A100 40GB GPUs). The 110M took around 24 hours. I am hosting them on huggingface hub [tinyllamas](https://huggingface.co/karpathy/tinyllamas), both in the original PyTorch .pt, and also in the llama2.c format .bin:
|
||||
|
||||
| model | dim | n_layers | n_heads | n_kv_heads | max context length | parameters | val loss | download
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| 260K | 64 | 5 | 8 | 4 | 512 | 260K | 1.297 | [stories260K](https://huggingface.co/karpathy/tinyllamas/tree/main/stories260K)
|
||||
| OG | 288 | 6 | 6 | 6 | 256 | 15M | 1.072 | [stories15M.bin](https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin) |
|
||||
| 42M| 512 | 8 | 8 | 8 | 1024 | 42M | 0.847 | [stories42M.bin](https://huggingface.co/karpathy/tinyllamas/resolve/main/stories42M.bin) |
|
||||
| 110M| 768 | 12 | 12 | 12 | 1024 | 110M | 0.760 | [stories110M.bin](https://huggingface.co/karpathy/tinyllamas/resolve/main/stories110M.bin) |
|
||||
|
||||
You'll notice that the 110M model is equivalent to GPT-1 in size. Alternatively, this is also the smallest model in the GPT-2 series (`GPT-2 small`), except the max context length is only 1024 instead of 2048. The only notable changes from GPT-1/2 architecture is that Llama uses RoPE relatively positional embeddings instead of absolute/learned positional embeddings, a bit more fancy SwiGLU non-linearity in the MLP, RMSNorm instead of LayerNorm, bias=False on all Linear layers, and is optionally multiquery.
|
||||
|
||||
|
||||
## training
|
||||
|
||||
Let's see how we can train a baby Llama 2 from scratch using the code in this repo. First let's download and pretokenize some source dataset, e.g. I like [TinyStories](https://huggingface.co/datasets/roneneldan/TinyStories) so this is the only example currently available in this repo. But it should be very easy to add datasets, see the code.
|
||||
|
||||
```bash
|
||||
python tinystories.py download
|
||||
python tinystories.py pretokenize
|
||||
```
|
||||
|
||||
Then train our model:
|
||||
|
||||
```bash
|
||||
python train.py
|
||||
```
|
||||
|
||||
**brief training guide**. See the train.py script for more exotic launches and hyperparameter overrides. Here is a brief guide to how to set the parameters. Look at the table at the very end of the [Chinchilla paper](https://arxiv.org/abs/2203.15556) to get a sense of how the Transformer parameters (dim, n_layers, n_heads) grow or shrink together. Extrapolate/interpolate this pattern to get bigger or smaller transformers. Set the max context length however you wish, depending on the problem: this should be the max number of tokens that matter to predict the next token. E.g. Llama 2 uses 2048. Next, you want the _total_ batch size per update (printed by the script as "tokens per iteration will be:") to be somewhere around 100K tokens for medium-sized applications. For tiny applications it could be lower, for large training (e.g. GPTs/LLamas) it is usually ~0.5M, or even more. You get there by first maxing out the batch_size to whatever your system allows (e.g. mine was 16 in a recent run because after that my GPU runs out of memory), and then you want to increase gradient_accumulation_steps to be as high as necessary to reach the total batch size of ~100K. Finally, you want to tune your learning_rate (LR). You want this to be as high as your training allows. Very small networks can get away with a large LR (e.g. 1e-3 or even higher). Large networks need lower LRs. 3e-4 is a safe choice in most medium-sized applications, but can be too low for small networks, so try to increase it! Finally, max_iters is the length of training. Play with different settings. I mostly only ever tune these parameters and leave most of the others unchanged. Here is an example of how I trained the 110M model, which I don't think is anywhere near optimal, but looked sensible to me: dim 768, n_layers 12, n_heads 12 (so size of each head is 768 / 12 = 64 channels), seq len of 1024, batch size 16 (this is the most that fit my A100 40GB GPU), gradient_accumulation_steps = 8 was needed to get total tokens batch size to be 16 batch size * 1024 tokens in sequence * 8 grad_accum = 131,072 tokens per update. Good. Learning rate 4e-4 (probably a little too low). max_iters 200K (probably a bit too high). Dropout 0.1, as that usually helps a bit at medium size. That was it. I ran using Distributed Data Parallel (DDP) on 4 GPUs on my cloud machine, training took ~day or so.
|
||||
|
||||
Totally understand if you want to skip model training, for simple demo just download one of the pretrained models (see [models](#models) section), e.g.:
|
||||
|
||||
```bash
|
||||
wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin
|
||||
```
|
||||
|
||||
Once we have the model.bin file, we can inference in C. Compile the C code first:
|
||||
|
||||
```bash
|
||||
llgo run . -m stories15M.bin
|
||||
```
|
||||
BIN
_demo/llama2-c/assets/llama_cute.jpg
Normal file
BIN
_demo/llama2-c/assets/llama_cute.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 183 KiB |
50
_demo/llama2-c/run.go
Normal file
50
_demo/llama2-c/run.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/llama2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var prompt *c.Char = c.Str("Once upon a time")
|
||||
var checkpointPath *c.Char = c.Str("stories15M.bin")
|
||||
var tokenizerPath *c.Char = c.Str("tokenizer.bin")
|
||||
var temperature, topp c.Float = 1.0, 0.9
|
||||
var steps c.Int = 256
|
||||
var rngSeed uint64 = uint64(c.Time(nil))
|
||||
|
||||
loop: // parse command line arguments
|
||||
for {
|
||||
switch c.Getopt(c.Argc, c.Argv, c.Str("m:")) {
|
||||
case 'm':
|
||||
checkpointPath = c.Optarg
|
||||
c.Fprintf(c.Stderr, c.Str("==> use model: %s\n"), checkpointPath)
|
||||
case -1:
|
||||
break loop
|
||||
}
|
||||
}
|
||||
if c.Optind < c.Argc {
|
||||
prompt = c.Index(c.Argv, c.Optind)
|
||||
c.Fprintf(c.Stderr, c.Str("==> prompt: %s\n"), prompt)
|
||||
}
|
||||
|
||||
// build the Transformer via the model .bin file
|
||||
var transformer llama2.Transformer
|
||||
llama2.BuildTransformer(&transformer, checkpointPath)
|
||||
|
||||
// build the Tokenizer via the tokenizer .bin file
|
||||
var tokenizer llama2.Tokenizer
|
||||
llama2.BuildTokenizer(&tokenizer, tokenizerPath, transformer.Config.VocabSize)
|
||||
|
||||
// build the Sampler
|
||||
var sampler llama2.Sampler
|
||||
llama2.BuildSampler(&sampler, transformer.Config.VocabSize, temperature, topp, rngSeed)
|
||||
|
||||
// run!
|
||||
llama2.Generate(&transformer, &tokenizer, &sampler, prompt, steps)
|
||||
|
||||
// memory and file handles cleanup
|
||||
llama2.FreeSampler(&sampler)
|
||||
llama2.FreeTokenizer(&tokenizer)
|
||||
llama2.FreeTransformer(&transformer)
|
||||
}
|
||||
BIN
_demo/llama2-c/tokenizer.bin
Normal file
BIN
_demo/llama2-c/tokenizer.bin
Normal file
Binary file not shown.
25
_demo/qsort/qsort.go
Normal file
25
_demo/qsort/qsort.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
a := [...]int{100, 8, 23, 2, 7}
|
||||
c.Qsort(c.Pointer(&a), 5, unsafe.Sizeof(0), func(a, b c.Pointer) c.Int {
|
||||
return c.Int(*(*int)(a) - *(*int)(b))
|
||||
})
|
||||
for _, v := range a {
|
||||
c.Printf(c.Str("%d\n"), v)
|
||||
}
|
||||
}
|
||||
|
||||
/* Expected output:
|
||||
2
|
||||
7
|
||||
8
|
||||
23
|
||||
100
|
||||
*/
|
||||
12
_pydemo/callpy/callpy.go
Normal file
12
_pydemo/callpy/callpy.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := math.Sqrt(py.Float(2))
|
||||
c.Printf(c.Str("sqrt(2) = %f\n"), x.Float64())
|
||||
}
|
||||
22
_pydemo/matrix/matrix.go
Normal file
22
_pydemo/matrix/matrix.go
Normal 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
10
_pydemo/pi/pi.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("pi = %f\n"), math.Pi.Float64())
|
||||
}
|
||||
13
_pydemo/statistics/statistics.go
Normal file
13
_pydemo/statistics/statistics.go
Normal 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())
|
||||
}
|
||||
153
c/c.go
Normal file
153
c/c.go
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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 c
|
||||
|
||||
// typedef unsigned int uint;
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
type (
|
||||
Char = int8
|
||||
Int = C.int
|
||||
Uint = C.uint
|
||||
Long = int32
|
||||
Ulong = uint32
|
||||
LongLong = int64
|
||||
UlongLong = uint64
|
||||
Float = float32
|
||||
Double = float64
|
||||
Pointer = unsafe.Pointer
|
||||
FilePtr = unsafe.Pointer
|
||||
)
|
||||
|
||||
type integer interface {
|
||||
~int | ~uint | ~uintptr | ~int32 | ~uint32 | ~int64 | ~uint64
|
||||
}
|
||||
|
||||
//go:linkname Str llgo.cstr
|
||||
func Str(string) *Char
|
||||
|
||||
// llgo:link Advance llgo.advance
|
||||
func Advance[PtrT any](ptr PtrT, offset int) PtrT { return ptr }
|
||||
|
||||
// llgo:link Index llgo.index
|
||||
func Index[T any, I integer](ptr *T, offset I) T { return *ptr }
|
||||
|
||||
//go:linkname Alloca llgo.alloca
|
||||
func Alloca(size uintptr) Pointer
|
||||
|
||||
//go:linkname AllocaCStr llgo.allocaCStr
|
||||
func AllocaCStr(s string) *Char
|
||||
|
||||
//go:linkname Unreachable llgo.unreachable
|
||||
func Unreachable()
|
||||
|
||||
//go:linkname Malloc C.malloc
|
||||
func Malloc(size uintptr) Pointer
|
||||
|
||||
//go:linkname Memcpy C.memcpy
|
||||
func Memcpy(dst, src Pointer, n uintptr) Pointer
|
||||
|
||||
//go:linkname Memset C.memset
|
||||
func Memset(s Pointer, c Int, n uintptr) Pointer
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname GoStringData llgo.stringData
|
||||
func GoStringData(string) *Char
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Remove C.remove
|
||||
func Remove(path *Char) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Exit C.exit
|
||||
func Exit(Int)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Rand C.rand
|
||||
func Rand() Int
|
||||
|
||||
//go:linkname Qsort C.qsort
|
||||
func Qsort(base Pointer, count, elem uintptr, compar func(a, b Pointer) Int)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Stdin __stdinp
|
||||
var Stdin FilePtr
|
||||
|
||||
//go:linkname Stdout __stdoutp
|
||||
var Stdout FilePtr
|
||||
|
||||
//go:linkname Stderr __stderrp
|
||||
var Stderr FilePtr
|
||||
|
||||
//go:linkname Printf C.printf
|
||||
func Printf(format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
//go:linkname Fprintf C.fprintf
|
||||
func Fprintf(fp FilePtr, format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Time C.time
|
||||
func Time(*int32) int32
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type Option struct {
|
||||
Name *Char
|
||||
HasArg Int
|
||||
Flag *Int
|
||||
Val Int
|
||||
}
|
||||
|
||||
//go:linkname Argc __llgo_argc
|
||||
var Argc Int
|
||||
|
||||
//go:linkname Argv __llgo_argv
|
||||
var Argv **Char
|
||||
|
||||
//go:linkname Optarg optarg
|
||||
var Optarg *Char
|
||||
|
||||
//go:linkname Optind optind
|
||||
var Optind Int
|
||||
|
||||
//go:linkname Opterr opterr
|
||||
var Opterr Int
|
||||
|
||||
//go:linkname Optopt optopt
|
||||
var Optopt Int
|
||||
|
||||
//go:linkname Getopt C.getopt
|
||||
func Getopt(argc Int, argv **Char, optstring *Char) Int
|
||||
|
||||
//go:linkname GetoptLong C.getopt_long
|
||||
func GetoptLong(argc Int, argv **Char, optstring *Char, longopts *Option, longindex *Int) Int
|
||||
|
||||
//go:linkname GetoptLongOnly C.getopt_long_only
|
||||
func GetoptLongOnly(argc Int, argv **Char, optstring *Char, longopts *Option, longindex *Int) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
35
c/cjson/README.md
Normal file
35
c/cjson/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
LLGo wrapper of DaveGamble/cJSON
|
||||
=====
|
||||
[](https://github.com/goplus/cjson/actions/workflows/go.yml)
|
||||
[](https://github.com/goplus/cjson/releases)
|
||||
[](https://pkg.go.dev/github.com/goplus/cjson)
|
||||
[](https://github.com/goplus/llgo)
|
||||
[](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 .
|
||||
```
|
||||
27
c/cjson/_demo/mkjson/mkjson.go
Normal file
27
c/cjson/_demo/mkjson/mkjson.go
Normal 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
121
c/cjson/cjson.go
Normal 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
BIN
c/cjson/llgo_autogen.lla
Normal file
Binary file not shown.
26
c/llama2/.gitignore
vendored
Normal file
26
c/llama2/.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# If you prefer the allow list template instead of the deny list, see community template:
|
||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||
#
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
stories*.bin
|
||||
.DS_Store
|
||||
err.log
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
*.swp
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
# Go workspace file
|
||||
go.work*
|
||||
1
c/llama2/llama2.c
Submodule
1
c/llama2/llama2.c
Submodule
Submodule c/llama2/llama2.c added at b3c4b6c3c4
159
c/llama2/llama2.go
Normal file
159
c/llama2/llama2.go
Normal 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)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
2
c/llama2/llama2/run.c
Normal file
2
c/llama2/llama2/run.c
Normal file
@@ -0,0 +1,2 @@
|
||||
#define TESTING
|
||||
#include "../llama2.c/run.c"
|
||||
6
c/llama2/llgo.cfg
Normal file
6
c/llama2/llgo.cfg
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"cl": [
|
||||
"clang -emit-llvm -S -o llgo_autogen.ll -c llama2/run.c",
|
||||
"rm llgo_autogen.lla; zip llgo_autogen.lla llgo_autogen.ll"
|
||||
]
|
||||
}
|
||||
BIN
c/llama2/llgo_autogen.lla
Normal file
BIN
c/llama2/llgo_autogen.lla
Normal file
Binary file not shown.
35
c/sqlite/README.md
Normal file
35
c/sqlite/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
LLGo wrapper of sqlite
|
||||
=====
|
||||
[](https://github.com/goplus/sqlite/actions/workflows/go.yml)
|
||||
[](https://github.com/goplus/sqlite/releases)
|
||||
[](https://pkg.go.dev/github.com/goplus/sqlite)
|
||||
[](https://github.com/goplus/llgo)
|
||||
[](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 .
|
||||
```
|
||||
61
c/sqlite/_demo/sqlitedemo/demo.go
Normal file
61
c/sqlite/_demo/sqlitedemo/demo.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/sqlite"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c.Remove(c.Str("test.db"))
|
||||
|
||||
db, err := sqlite.Open(c.Str("test.db"))
|
||||
check(err, db, "sqlite: Open")
|
||||
|
||||
err = db.Exec(c.Str("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)"), nil, nil, nil)
|
||||
check(err, db, "sqlite: Exec CREATE TABLE")
|
||||
|
||||
stmt, err := db.PrepareV3("INSERT INTO users (id, name) VALUES (?, ?)", 0, nil)
|
||||
check(err, db, "sqlite: PrepareV3 INSERT")
|
||||
|
||||
stmt.BindInt(1, 100)
|
||||
stmt.BindText(2, c.Str("Hello World"), -1, nil)
|
||||
|
||||
err = stmt.Step()
|
||||
checkDone(err, db, "sqlite: Step INSERT 1")
|
||||
|
||||
stmt.Reset()
|
||||
stmt.BindInt(1, 200)
|
||||
stmt.BindText(2, c.Str("This is llgo"), -1, nil)
|
||||
|
||||
err = stmt.Step()
|
||||
checkDone(err, db, "sqlite: Step INSERT 2")
|
||||
|
||||
stmt.Close()
|
||||
|
||||
stmt, err = db.PrepareV3("SELECT * FROM users", 0, nil)
|
||||
check(err, db, "sqlite: PrepareV3 SELECT")
|
||||
|
||||
for {
|
||||
if err = stmt.Step(); err != sqlite.HasRow {
|
||||
break
|
||||
}
|
||||
c.Printf(c.Str("==> id=%d, name=%s\n"), stmt.ColumnInt(0), stmt.ColumnText(1))
|
||||
}
|
||||
checkDone(err, db, "sqlite: Step done")
|
||||
|
||||
stmt.Close()
|
||||
db.Close()
|
||||
}
|
||||
|
||||
func check(err sqlite.Errno, db *sqlite.Sqlite3, at string) {
|
||||
if err != sqlite.OK {
|
||||
c.Printf(c.Str("==> %s Error: (%d) %s\n"), c.AllocaCStr(at), err, db.Errmsg())
|
||||
c.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func checkDone(err sqlite.Errno, db *sqlite.Sqlite3, at string) {
|
||||
if err != sqlite.Done {
|
||||
check(err, db, at)
|
||||
}
|
||||
}
|
||||
BIN
c/sqlite/llgo_autogen.lla
Normal file
BIN
c/sqlite/llgo_autogen.lla
Normal file
Binary file not shown.
262
c/sqlite/sqlite.go
Normal file
262
c/sqlite/sqlite.go
Normal file
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* 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 sqlite
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link: sqlite3"
|
||||
)
|
||||
|
||||
// llgo:type C
|
||||
type Sqlite3 struct {
|
||||
Unused [8]byte
|
||||
}
|
||||
|
||||
// llgo:type C
|
||||
type Stmt struct {
|
||||
Unused [8]byte
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type Errno c.Int
|
||||
|
||||
const (
|
||||
OK Errno = 0 // Successful result
|
||||
|
||||
Error Errno = 1 // Generic error
|
||||
ErrInternal Errno = 2 // Internal logic error in SQLite
|
||||
ErrPerm Errno = 3 // Access permission denied
|
||||
ErrAbort Errno = 4 // Callback routine requested an abort
|
||||
ErrBusy Errno = 5 // The database file is locked
|
||||
ErrLocked Errno = 6 // A table in the database is locked
|
||||
ErrNomem Errno = 7 // A malloc() failed
|
||||
ErrReadOnly Errno = 8 // Attempt to write a readonly database
|
||||
ErrInterrupt Errno = 9 // Operation terminated by sqlite3_interrupt()
|
||||
ErrIo Errno = 10 // Some kind of disk I/O error occurred
|
||||
ErrCorrupt Errno = 11 // The database disk image is malformed
|
||||
ErrNotfound Errno = 12 // Unknown opcode in sqlite3_file_control()
|
||||
ErrFull Errno = 13 // Insertion failed because database is full
|
||||
ErrCantopen Errno = 14 // Unable to open the database file
|
||||
ErrProtocol Errno = 15 // Database lock protocol error
|
||||
_ErrEmpty Errno = 16 // Internal use only
|
||||
ErrSchema Errno = 17 // The database schema changed
|
||||
ErrToobig Errno = 18 // String or BLOB exceeds size limit
|
||||
ErrConstraint Errno = 19 // Abort due to constraint violation
|
||||
ErrMismatch Errno = 20 // Data type mismatch
|
||||
ErrMisuse Errno = 21 // Library used incorrectly
|
||||
ErrNolfs Errno = 22 // Uses OS features not supported on host
|
||||
ErrAuth Errno = 23 // Authorization denied
|
||||
_ErrFormat Errno = 24 // Not used
|
||||
ErrRange Errno = 25 // 2nd parameter to sqlite3_bind out of range
|
||||
ErrNotadb Errno = 26 // File opened that is not a database file
|
||||
ErrNotice Errno = 27 // Notifications from sqlite3_log()
|
||||
ErrWarning Errno = 28 // Warnings from sqlite3_log()
|
||||
|
||||
HasRow Errno = 100 // sqlite3_step() has another row ready
|
||||
Done Errno = 101 // sqlite3_step() has finished executing
|
||||
)
|
||||
|
||||
// llgo:link (Errno).Errstr C.sqlite3_errstr
|
||||
func (err Errno) Errstr() *c.Char { return nil }
|
||||
|
||||
// llgo:link (*Sqlite3).Errmsg C.sqlite3_errmsg
|
||||
func (db *Sqlite3) Errmsg() *c.Char { return nil }
|
||||
|
||||
// llgo:link (*Sqlite3).Errcode C.sqlite3_errcode
|
||||
func (db *Sqlite3) Errcode() Errno { return 0 }
|
||||
|
||||
// llgo:link (*Sqlite3).ExtendedErrcode C.sqlite3_extended_errcode
|
||||
func (db *Sqlite3) ExtendedErrcode() Errno { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname doOpen C.sqlite3_open
|
||||
func doOpen(filename *c.Char, ppDb **Sqlite3) Errno
|
||||
|
||||
//go:linkname doOpenV2 C.sqlite3_open_v2
|
||||
func doOpenV2(filename *c.Char, ppDb **Sqlite3, flags OpenFlags, zVfs *c.Char) Errno
|
||||
|
||||
// OpenFlags represents SQLite open flags.
|
||||
type OpenFlags c.Int
|
||||
|
||||
const (
|
||||
OpenReadOnly OpenFlags = 0x00000001
|
||||
OpenReadWrite OpenFlags = 0x00000002
|
||||
OpenCreate OpenFlags = 0x00000004
|
||||
OpenDeleteOnClose OpenFlags = 0x00000008 // VFS only
|
||||
OpenExclusive OpenFlags = 0x00000010 // VFS only
|
||||
OpenAutoProxy OpenFlags = 0x00000020 // VFS only
|
||||
OpenUri OpenFlags = 0x00000040
|
||||
OpenMemory OpenFlags = 0x00000080
|
||||
OpenMainDb OpenFlags = 0x00000100 // VFS only
|
||||
OpenTempDb OpenFlags = 0x00000200 // VFS only
|
||||
OpenTransientDb OpenFlags = 0x00000400 // VFS only
|
||||
OpenMainJournal OpenFlags = 0x00000800 // VFS only
|
||||
OpenTempJournal OpenFlags = 0x00001000 // VFS only
|
||||
OpenSubJournal OpenFlags = 0x00002000 // VFS only
|
||||
OpenSuperJournal OpenFlags = 0x00004000 // VFS only
|
||||
OpenNoMutex OpenFlags = 0x00008000
|
||||
OpenFullMutex OpenFlags = 0x00010000
|
||||
OpenSharedCache OpenFlags = 0x00020000
|
||||
OpenPrivateCache OpenFlags = 0x00040000
|
||||
OpenWal OpenFlags = 0x00080000 // VFS only
|
||||
OpenNoFollow OpenFlags = 0x01000000
|
||||
OpenExResCode OpenFlags = 0x02000000 // Extended result codes
|
||||
)
|
||||
|
||||
// Opening A New Database Connection
|
||||
// filename: Database filename (UTF-8)
|
||||
func Open(filename *c.Char) (db *Sqlite3, err Errno) {
|
||||
err = doOpen(filename, &db)
|
||||
return
|
||||
}
|
||||
|
||||
// Opening A New Database Connection
|
||||
// filename: Database filename (UTF-8)
|
||||
// zVfs: Name of VFS module to use
|
||||
func OpenV2(filename *c.Char, flags OpenFlags, zVfs *c.Char) (db *Sqlite3, err Errno) {
|
||||
err = doOpenV2(filename, &db, flags, zVfs)
|
||||
return
|
||||
}
|
||||
|
||||
// Closing A Database Connection
|
||||
//
|
||||
// llgo:link (*Sqlite3).Close C.sqlite3_close
|
||||
func (db *Sqlite3) Close() Errno { return 0 }
|
||||
|
||||
// Closing A Database Connection
|
||||
//
|
||||
// llgo:link (*Sqlite3).CloseV2 C.sqlite3_close_v2
|
||||
func (db *Sqlite3) CloseV2() Errno { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// llgo:link (*Sqlite3).doPrepare C.sqlite3_prepare
|
||||
func (*Sqlite3) doPrepare(*c.Char, c.Int, **Stmt, **c.Char) Errno {
|
||||
return 0
|
||||
}
|
||||
|
||||
// llgo:link (*Sqlite3).doPrepareV2 C.sqlite3_prepare_v2
|
||||
func (*Sqlite3) doPrepareV2(*c.Char, c.Int, **Stmt, **c.Char) Errno {
|
||||
return 0
|
||||
}
|
||||
|
||||
// llgo:link (*Sqlite3).doPrepareV3 C.sqlite3_prepare_v3
|
||||
func (*Sqlite3) doPrepareV3(*c.Char, c.Int, PrepareFlags, **Stmt, **c.Char) Errno {
|
||||
return 0
|
||||
}
|
||||
|
||||
// PrepareFlags represents SQLite prepare flags.
|
||||
type PrepareFlags c.Int
|
||||
|
||||
const (
|
||||
PreparePersistent PrepareFlags = 0x01
|
||||
PrepareNormalize PrepareFlags = 0x02
|
||||
PrepareNoVtab PrepareFlags = 0x04
|
||||
)
|
||||
|
||||
// Compiling An SQL Statement
|
||||
// tail: Pointer to unused portion of sql
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
// Destroy A Prepared Statement Object
|
||||
//
|
||||
// llgo:link (*Stmt).Close C.sqlite3_finalize
|
||||
func (stmt *Stmt) Close() Errno { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// llgo:link (*Stmt).BindInt C.sqlite3_bind_int
|
||||
func (*Stmt) BindInt(idx c.Int, val c.Int) Errno { return 0 }
|
||||
|
||||
// llgo:link (*Stmt).BindInt64 C.sqlite3_bind_int64
|
||||
func (*Stmt) BindInt64(idx c.Int, val int64) Errno { return 0 }
|
||||
|
||||
/*
|
||||
const (
|
||||
Static = (func(Pointer))(nil) // val is a static string
|
||||
Transient = (func(Pointer))(-1) // val is a transient (temporary) string
|
||||
)
|
||||
*/
|
||||
|
||||
// llgo:link (*Stmt).BindText C.sqlite3_bind_text
|
||||
func (*Stmt) BindText(idx c.Int, val *c.Char, nByte c.Int, destructor func(c.Pointer)) Errno {
|
||||
return 0
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Reset A Prepared Statement Object
|
||||
//
|
||||
// llgo:link (*Stmt).Reset C.sqlite3_reset
|
||||
func (stmt *Stmt) Reset() Errno {
|
||||
return 0
|
||||
}
|
||||
|
||||
// Evaluate An SQL Statement
|
||||
//
|
||||
// llgo:link (*Stmt).Step C.sqlite3_step
|
||||
func (*Stmt) Step() Errno { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// llgo:link (*Stmt).ColumnCount C.sqlite3_column_count
|
||||
func (stmt *Stmt) ColumnCount() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Stmt).ColumnName C.sqlite3_column_name
|
||||
func (stmt *Stmt) ColumnName(idx c.Int) *c.Char { return nil }
|
||||
|
||||
// llgo:link (*Stmt).ColumnInt C.sqlite3_column_int
|
||||
func (stmt *Stmt) ColumnInt(idx c.Int) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Stmt).ColumnInt64 C.sqlite3_column_int64
|
||||
func (stmt *Stmt) ColumnInt64(idx c.Int) int64 { return 0 }
|
||||
|
||||
// llgo:link (*Stmt).ColumnText C.sqlite3_column_text
|
||||
func (stmt *Stmt) ColumnText(idx c.Int) *c.Char { return nil }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// One-Step Query Execution Interface
|
||||
//
|
||||
// llgo:link (*Sqlite3).Exec C.sqlite3_exec
|
||||
func (*Sqlite3) Exec(
|
||||
sql *c.Char, callback func(arg c.Pointer, resultCols c.Int, colVals, colNames **c.Char) c.Int,
|
||||
arg c.Pointer, errmsg **c.Char) Errno {
|
||||
return 0
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
60
chore/_xtool/pydump/pydump.go
Normal file
60
chore/_xtool/pydump/pydump.go
Normal 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())
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/goplus/llgo/x/ar"
|
||||
"github.com/goplus/llgo/xtool/ar"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
71
chore/clangast/clangast.go
Normal file
71
chore/clangast/clangast.go
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/goplus/llgo/xtool/clang/parser"
|
||||
)
|
||||
|
||||
var (
|
||||
dump = flag.Bool("dump", false, "dump AST")
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "Usage: clangast [-dump] source.i\n")
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
if flag.NArg() < 1 {
|
||||
usage()
|
||||
return
|
||||
}
|
||||
var file = flag.Arg(0)
|
||||
var err error
|
||||
if *dump {
|
||||
doc, _, e := parser.DumpAST(file, nil)
|
||||
if e == nil {
|
||||
os.Stdout.Write(doc)
|
||||
return
|
||||
}
|
||||
err = e
|
||||
} else {
|
||||
doc, _, e := parser.ParseFile(file, 0)
|
||||
if e == nil {
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
check(enc.Encode(doc))
|
||||
return
|
||||
}
|
||||
err = e
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func check(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
41
chore/clangpp/clangpp.go
Normal file
41
chore/clangpp/clangpp.go
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/goplus/llgo/xtool/clang/preprocessor"
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "Usage: clangpp source.c\n")
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
usage()
|
||||
return
|
||||
}
|
||||
infile := os.Args[1]
|
||||
outfile := infile + ".i"
|
||||
if err := preprocessor.Do(infile, outfile, nil); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,9 @@ func main() {
|
||||
|
||||
llgen.Verbose = false
|
||||
|
||||
llgenDir(dir + "/cl/_testlibc")
|
||||
llgenDir(dir + "/cl/_testrt")
|
||||
llgenDir(dir+"/cl/_testpy", "")
|
||||
llgenDir(dir+"/cl/_testdata", "")
|
||||
}
|
||||
|
||||
|
||||
242
chore/llpyg/llpyg.go
Normal file
242
chore/llpyg/llpyg.go
Normal 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
100
chore/llpyg/pysig/parse.go
Normal 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)])
|
||||
}
|
||||
52
chore/llpyg/pysig/parse_test.go
Normal file
52
chore/llpyg/pysig/parse_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,10 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/goplus/llgo/x/nm"
|
||||
"github.com/goplus/llgo/xtool/env/llvm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -29,9 +30,8 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
nm := nm.New("nm")
|
||||
nm := llvm.New().Nm()
|
||||
items, err := nm.List(os.Args[1])
|
||||
check(err)
|
||||
for _, item := range items {
|
||||
if item.File != "" {
|
||||
fmt.Printf("\n%s:\n", item.File)
|
||||
@@ -44,10 +44,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func check(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/goplus/llgo/x/env/llvm"
|
||||
"github.com/goplus/llgo/x/nm"
|
||||
"github.com/goplus/llgo/xtool/env/llvm"
|
||||
"github.com/goplus/llgo/xtool/nm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -64,6 +64,7 @@ func makeIndex() {
|
||||
usrLib(true),
|
||||
stdLib("LLGO_STDROOT"),
|
||||
stdLib("LLGO_USRROOT"),
|
||||
pythonLib(),
|
||||
}
|
||||
err := b.Index(libDirs, idxDir, func(path string) {
|
||||
fmt.Println("==>", path)
|
||||
@@ -72,6 +73,11 @@ func makeIndex() {
|
||||
}
|
||||
|
||||
func query(q string) {
|
||||
if len(q) > 0 {
|
||||
if c := q[0]; c != '*' && c != '_' {
|
||||
q = "_" + q
|
||||
}
|
||||
}
|
||||
files, err := nm.Query(indexDir(), q)
|
||||
check(err)
|
||||
for _, f := range files {
|
||||
@@ -103,6 +109,10 @@ func usrLib(local bool) string {
|
||||
return "/usr/lib"
|
||||
}
|
||||
|
||||
func pythonLib() string {
|
||||
return os.Getenv("LLGO_PYTHON_ROOT")
|
||||
}
|
||||
|
||||
func check(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
@@ -16,12 +18,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
%0 = call i64 @main.max(i64 1, i64 2)
|
||||
ret void
|
||||
%2 = call i64 @main.max(i64 1, i64 2)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
define i64 @main.max(i64 %0, i64 %1) {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@main.hello = global ptr null
|
||||
@main.hello = global [7 x i8] undef
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
@@ -25,13 +27,15 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
%0 = 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)
|
||||
ret void
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/cl/internal/stdio.init"()
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@main.format = global ptr null
|
||||
@main.format = global [10 x i8] undef
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define i64 @"(main.T).Add"(i64 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
@@ -40,15 +42,17 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
%0 = call i64 @"(main.T).Add"(i64 1, i64 2)
|
||||
call void (ptr, ...) @printf(ptr @main.format, i64 %0)
|
||||
ret void
|
||||
%2 = call i64 @"(main.T).Add"(i64 1, i64 2)
|
||||
call void (ptr, ...) @printf(ptr @main.format, i64 %2)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @printf(ptr, ...)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare void @printf(ptr, ...)
|
||||
|
||||
264
cl/_testdata/print/in.go
Normal file
264
cl/_testdata/print/in.go
Normal file
@@ -0,0 +1,264 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
func gwrite(b []byte) {
|
||||
if len(b) == 0 {
|
||||
return
|
||||
}
|
||||
c.Printf(c.Str("%s"), b)
|
||||
}
|
||||
|
||||
func printbool(v bool) {
|
||||
if v {
|
||||
printstring("true")
|
||||
} else {
|
||||
printstring("false")
|
||||
}
|
||||
}
|
||||
|
||||
func printfloat(v float64) {
|
||||
switch {
|
||||
case v != v:
|
||||
printstring("NaN")
|
||||
return
|
||||
case v+v == v && v > 0:
|
||||
printstring("+Inf")
|
||||
return
|
||||
case v+v == v && v < 0:
|
||||
printstring("-Inf")
|
||||
return
|
||||
}
|
||||
|
||||
const n = 7 // digits printed
|
||||
var buf [n + 7]byte
|
||||
buf[0] = '+'
|
||||
e := 0 // exp
|
||||
if v == 0 {
|
||||
if 1/v < 0 {
|
||||
buf[0] = '-'
|
||||
}
|
||||
} else {
|
||||
if v < 0 {
|
||||
v = -v
|
||||
buf[0] = '-'
|
||||
}
|
||||
|
||||
// normalize
|
||||
for v >= 10 {
|
||||
e++
|
||||
v /= 10
|
||||
}
|
||||
for v < 1 {
|
||||
e--
|
||||
v *= 10
|
||||
}
|
||||
|
||||
// round
|
||||
h := 5.0
|
||||
for i := 0; i < n; i++ {
|
||||
h /= 10
|
||||
}
|
||||
v += h
|
||||
if v >= 10 {
|
||||
e++
|
||||
v /= 10
|
||||
}
|
||||
}
|
||||
|
||||
// format +d.dddd+edd
|
||||
for i := 0; i < n; i++ {
|
||||
s := int(v)
|
||||
buf[i+2] = byte(s + '0')
|
||||
v -= float64(s)
|
||||
v *= 10
|
||||
}
|
||||
buf[1] = buf[2]
|
||||
buf[2] = '.'
|
||||
|
||||
buf[n+2] = 'e'
|
||||
buf[n+3] = '+'
|
||||
if e < 0 {
|
||||
e = -e
|
||||
buf[n+3] = '-'
|
||||
}
|
||||
|
||||
buf[n+4] = byte(e/100) + '0'
|
||||
buf[n+5] = byte(e/10)%10 + '0'
|
||||
buf[n+6] = byte(e%10) + '0'
|
||||
gwrite(buf[:])
|
||||
}
|
||||
|
||||
func printuint(v uint64) {
|
||||
var buf [100]byte
|
||||
i := len(buf)
|
||||
for i--; i > 0; i-- {
|
||||
buf[i] = byte(v%10 + '0')
|
||||
if v < 10 {
|
||||
break
|
||||
}
|
||||
v /= 10
|
||||
}
|
||||
gwrite(buf[i:])
|
||||
}
|
||||
|
||||
func printint(v int64) {
|
||||
if v < 0 {
|
||||
printstring("-")
|
||||
v = -v
|
||||
}
|
||||
printuint(uint64(v))
|
||||
}
|
||||
|
||||
var minhexdigits = 0
|
||||
|
||||
func printhex(v uint64) {
|
||||
const dig = "0123456789abcdef"
|
||||
var buf [100]byte
|
||||
i := len(buf)
|
||||
for i--; i > 0; i-- {
|
||||
buf[i] = dig[v%16]
|
||||
if v < 16 && len(buf)-i >= minhexdigits {
|
||||
break
|
||||
}
|
||||
v /= 16
|
||||
}
|
||||
i--
|
||||
buf[i] = 'x'
|
||||
i--
|
||||
buf[i] = '0'
|
||||
gwrite(buf[i:])
|
||||
}
|
||||
|
||||
func printsp() {
|
||||
printstring(" ")
|
||||
}
|
||||
|
||||
func printnl() {
|
||||
printstring("\n")
|
||||
}
|
||||
|
||||
func printstring(s string) {
|
||||
gwrite(bytes(s))
|
||||
}
|
||||
|
||||
type slice struct {
|
||||
array unsafe.Pointer
|
||||
len int
|
||||
cap int
|
||||
}
|
||||
|
||||
type stringStruct struct {
|
||||
str unsafe.Pointer
|
||||
len int
|
||||
}
|
||||
|
||||
func stringStructOf(sp *string) *stringStruct {
|
||||
return (*stringStruct)(unsafe.Pointer(sp))
|
||||
}
|
||||
|
||||
func bytes(s string) (ret []byte) {
|
||||
rp := (*slice)(unsafe.Pointer(&ret))
|
||||
sp := stringStructOf(&s)
|
||||
rp.array = sp.str
|
||||
rp.len = sp.len
|
||||
rp.cap = sp.len
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
printstring("llgo")
|
||||
printnl()
|
||||
printuint(1024)
|
||||
printnl()
|
||||
printhex(0x1234abcf)
|
||||
printnl()
|
||||
prinxor(1)
|
||||
printnl()
|
||||
prinsub(100)
|
||||
printnl()
|
||||
prinusub(1<<64 - 1)
|
||||
printnl()
|
||||
prinfsub(100.1)
|
||||
printnl()
|
||||
printany(float32(1e9))
|
||||
printnl()
|
||||
printany(float64(2e9))
|
||||
printnl()
|
||||
var b bool = true
|
||||
if b == true && b != false {
|
||||
println("check bool", b)
|
||||
}
|
||||
n1 := 0b1001
|
||||
n2 := 0b0011
|
||||
println("check &^", n1&^n2 == 0b1000, n2&^n1 == 0b0010)
|
||||
println(true, false, 'a', 'A', rune('中'),
|
||||
int8(1), int16(2), int32(3), int64(4), 5,
|
||||
uint8(1), uint16(2), uint32(3), uint64(4), uintptr(5),
|
||||
"llgo")
|
||||
}
|
||||
|
||||
func println(args ...any) {
|
||||
for i, v := range args {
|
||||
if i != 0 {
|
||||
printstring(" ")
|
||||
}
|
||||
printany(v)
|
||||
}
|
||||
printnl()
|
||||
}
|
||||
|
||||
func printany(v any) {
|
||||
switch v := v.(type) {
|
||||
case bool:
|
||||
printbool(v)
|
||||
case int:
|
||||
printint(int64(v))
|
||||
case int8:
|
||||
printint(int64(v))
|
||||
case int16:
|
||||
printint(int64(v))
|
||||
case int32:
|
||||
printint(int64(v))
|
||||
case int64:
|
||||
printint(int64(v))
|
||||
case uint:
|
||||
printuint(uint64(v))
|
||||
case uint8:
|
||||
printuint(uint64(v))
|
||||
case uint16:
|
||||
printuint(uint64(v))
|
||||
case uint32:
|
||||
printuint(uint64(v))
|
||||
case uint64:
|
||||
printuint(uint64(v))
|
||||
case uintptr:
|
||||
printuint(uint64(v))
|
||||
case float32:
|
||||
printfloat(float64(v))
|
||||
case float64:
|
||||
printfloat(float64(v))
|
||||
case string:
|
||||
printstring(v)
|
||||
}
|
||||
}
|
||||
|
||||
func prinxor(n int64) {
|
||||
printint(^n)
|
||||
}
|
||||
|
||||
func prinsub(n int64) {
|
||||
printint(-n)
|
||||
}
|
||||
|
||||
func prinusub(n uint64) {
|
||||
printuint(-n)
|
||||
}
|
||||
|
||||
func prinfsub(n float64) {
|
||||
printfloat(-n)
|
||||
}
|
||||
816
cl/_testdata/print/out.ll
Normal file
816
cl/_testdata/print/out.ll
Normal file
@@ -0,0 +1,816 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
%main.stringStruct = type { ptr, i64 }
|
||||
%main.slice = type { ptr, i64, i64 }
|
||||
%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr }
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@main.minhexdigits = global ptr null
|
||||
@0 = private unnamed_addr constant [3 x i8] c"%s\00", align 1
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
@1 = private unnamed_addr constant [5 x i8] c"llgo\00", align 1
|
||||
@2 = private unnamed_addr constant [11 x i8] c"check bool\00", align 1
|
||||
@3 = private unnamed_addr constant [9 x i8] c"check &^\00", align 1
|
||||
@4 = private unnamed_addr constant [5 x i8] c"llgo\00", align 1
|
||||
@5 = private unnamed_addr constant [5 x i8] c"true\00", align 1
|
||||
@6 = private unnamed_addr constant [6 x i8] c"false\00", align 1
|
||||
@7 = private unnamed_addr constant [4 x i8] c"NaN\00", align 1
|
||||
@8 = private unnamed_addr constant [5 x i8] c"+Inf\00", align 1
|
||||
@9 = private unnamed_addr constant [5 x i8] c"-Inf\00", align 1
|
||||
@10 = private unnamed_addr constant [17 x i8] c"0123456789abcdef\00", align 1
|
||||
@11 = private unnamed_addr constant [2 x i8] c"-\00", align 1
|
||||
@12 = private unnamed_addr constant [2 x i8] c" \00", align 1
|
||||
@13 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
|
||||
@14 = private unnamed_addr constant [2 x i8] c" \00", align 1
|
||||
|
||||
define %"github.com/goplus/llgo/internal/runtime.Slice" @main.bytes(%"github.com/goplus/llgo/internal/runtime.String" %0) {
|
||||
_llgo_0:
|
||||
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16)
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %1, align 8
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 24)
|
||||
%3 = call ptr @main.stringStructOf(ptr %1)
|
||||
%4 = getelementptr inbounds %main.stringStruct, ptr %3, i32 0, i32 0
|
||||
%5 = load ptr, ptr %4, align 8
|
||||
%6 = getelementptr inbounds %main.slice, ptr %2, i32 0, i32 0
|
||||
store ptr %5, ptr %6, align 8
|
||||
%7 = getelementptr inbounds %main.stringStruct, ptr %3, i32 0, i32 1
|
||||
%8 = load i64, ptr %7, align 4
|
||||
%9 = getelementptr inbounds %main.slice, ptr %2, i32 0, i32 1
|
||||
store i64 %8, ptr %9, align 4
|
||||
%10 = getelementptr inbounds %main.stringStruct, ptr %3, i32 0, i32 1
|
||||
%11 = load i64, ptr %10, align 4
|
||||
%12 = getelementptr inbounds %main.slice, ptr %2, i32 0, i32 2
|
||||
store i64 %11, ptr %12, align 4
|
||||
%13 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %2, align 8
|
||||
ret %"github.com/goplus/llgo/internal/runtime.Slice" %13
|
||||
}
|
||||
|
||||
define void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
|
||||
_llgo_0:
|
||||
%1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
%2 = icmp eq i64 %1, 0
|
||||
br i1 %2, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
ret void
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
%3 = call i32 (ptr, ...) @printf(ptr @0, %"github.com/goplus/llgo/internal/runtime.Slice" %0)
|
||||
ret void
|
||||
}
|
||||
|
||||
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
|
||||
store i64 0, ptr @main.minhexdigits, align 4
|
||||
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 %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 4)
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %2)
|
||||
call void @main.printnl()
|
||||
call void @main.printuint(i64 1024)
|
||||
call void @main.printnl()
|
||||
call void @main.printhex(i64 305441743)
|
||||
call void @main.printnl()
|
||||
call void @main.prinxor(i64 1)
|
||||
call void @main.printnl()
|
||||
call void @main.prinsub(i64 100)
|
||||
call void @main.printnl()
|
||||
call void @main.prinusub(i64 -1)
|
||||
call void @main.printnl()
|
||||
call void @main.prinfsub(double 1.001000e+02)
|
||||
call void @main.printnl()
|
||||
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13)
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %3, i64 1315859240)
|
||||
call void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %4)
|
||||
call void @main.printnl()
|
||||
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14)
|
||||
%6 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %5, i64 4746175415993761792)
|
||||
call void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %6)
|
||||
call void @main.printnl()
|
||||
br i1 true, label %_llgo_3, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_3
|
||||
%7 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
|
||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %7, i64 0
|
||||
%9 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 10)
|
||||
%10 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %9)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %10, ptr %8, align 8
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %7, i64 1
|
||||
%12 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
|
||||
%13 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %12, i64 -1)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %13, ptr %11, align 8
|
||||
%14 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %7, i64 16, i64 2, i64 0, i64 2, i64 2)
|
||||
call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %14)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_3, %_llgo_1, %_llgo_0
|
||||
%15 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48)
|
||||
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %15, i64 0
|
||||
%17 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 8)
|
||||
%18 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %17)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %18, ptr %16, align 8
|
||||
%19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %15, i64 1
|
||||
%20 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
|
||||
%21 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %20, i64 -1)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %21, ptr %19, align 8
|
||||
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %15, i64 2
|
||||
%23 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
|
||||
%24 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %23, i64 -1)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %24, ptr %22, align 8
|
||||
%25 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %15, i64 16, i64 3, i64 0, i64 3, i64 3)
|
||||
call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %25)
|
||||
%26 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 256)
|
||||
%27 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 0
|
||||
%28 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
|
||||
%29 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %28, i64 -1)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %29, ptr %27, align 8
|
||||
%30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 1
|
||||
%31 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
|
||||
%32 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %31, i64 0)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %32, ptr %30, align 8
|
||||
%33 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 2
|
||||
%34 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
|
||||
%35 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %34, i64 97)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %35, ptr %33, align 8
|
||||
%36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 3
|
||||
%37 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
|
||||
%38 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %37, i64 65)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %38, ptr %36, align 8
|
||||
%39 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 4
|
||||
%40 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
|
||||
%41 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %40, i64 20013)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %41, ptr %39, align 8
|
||||
%42 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 5
|
||||
%43 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3)
|
||||
%44 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %43, i64 1)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %44, ptr %42, align 8
|
||||
%45 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 6
|
||||
%46 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 4)
|
||||
%47 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %46, i64 2)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %47, ptr %45, align 8
|
||||
%48 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 7
|
||||
%49 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
|
||||
%50 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %49, i64 3)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %50, ptr %48, align 8
|
||||
%51 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 8
|
||||
%52 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6)
|
||||
%53 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %52, i64 4)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %53, ptr %51, align 8
|
||||
%54 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 9
|
||||
%55 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
%56 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %55, i64 5)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %56, ptr %54, align 8
|
||||
%57 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 10
|
||||
%58 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8)
|
||||
%59 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %58, i64 1)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %59, ptr %57, align 8
|
||||
%60 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 11
|
||||
%61 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 9)
|
||||
%62 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %61, i64 2)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %62, ptr %60, align 8
|
||||
%63 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 12
|
||||
%64 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 10)
|
||||
%65 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %64, i64 3)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %65, ptr %63, align 8
|
||||
%66 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 13
|
||||
%67 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 11)
|
||||
%68 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %67, i64 4)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %68, ptr %66, align 8
|
||||
%69 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 14
|
||||
%70 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 12)
|
||||
%71 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %70, i64 5)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %71, ptr %69, align 8
|
||||
%72 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %26, i64 15
|
||||
%73 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @4, i64 4)
|
||||
%74 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %73)
|
||||
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)
|
||||
call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %75)
|
||||
ret i32 0
|
||||
|
||||
_llgo_3: ; preds = %_llgo_0
|
||||
br i1 true, label %_llgo_1, label %_llgo_2
|
||||
}
|
||||
|
||||
define void @main.prinfsub(double %0) {
|
||||
_llgo_0:
|
||||
%1 = fneg double %0
|
||||
call void @main.printfloat(double %1)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.prinsub(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = sub i64 0, %0
|
||||
call void @main.printint(i64 %1)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %0) {
|
||||
_llgo_0:
|
||||
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
|
||||
%2 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %1)
|
||||
%3 = extractvalue { i64, i1 } %2, 0
|
||||
%4 = trunc i64 %3 to i1
|
||||
%5 = extractvalue { i64, i1 } %2, 1
|
||||
br i1 %5, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_30, %_llgo_29, %_llgo_28, %_llgo_26, %_llgo_24, %_llgo_22, %_llgo_20, %_llgo_18, %_llgo_16, %_llgo_14, %_llgo_12, %_llgo_10, %_llgo_8, %_llgo_6, %_llgo_4, %_llgo_2
|
||||
ret void
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
call void @main.printbool(i1 %4)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_0
|
||||
%6 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
%7 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %6)
|
||||
%8 = extractvalue { i64, i1 } %7, 0
|
||||
%9 = extractvalue { i64, i1 } %7, 1
|
||||
br i1 %9, label %_llgo_4, label %_llgo_5
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3
|
||||
call void @main.printint(i64 %8)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_5: ; preds = %_llgo_3
|
||||
%10 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3)
|
||||
%11 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %10)
|
||||
%12 = extractvalue { i64, i1 } %11, 0
|
||||
%13 = trunc i64 %12 to i8
|
||||
%14 = extractvalue { i64, i1 } %11, 1
|
||||
br i1 %14, label %_llgo_6, label %_llgo_7
|
||||
|
||||
_llgo_6: ; preds = %_llgo_5
|
||||
%15 = sext i8 %13 to i64
|
||||
call void @main.printint(i64 %15)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_7: ; preds = %_llgo_5
|
||||
%16 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 4)
|
||||
%17 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %16)
|
||||
%18 = extractvalue { i64, i1 } %17, 0
|
||||
%19 = trunc i64 %18 to i16
|
||||
%20 = extractvalue { i64, i1 } %17, 1
|
||||
br i1 %20, label %_llgo_8, label %_llgo_9
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7
|
||||
%21 = sext i16 %19 to i64
|
||||
call void @main.printint(i64 %21)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_9: ; preds = %_llgo_7
|
||||
%22 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
|
||||
%23 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %22)
|
||||
%24 = extractvalue { i64, i1 } %23, 0
|
||||
%25 = trunc i64 %24 to i32
|
||||
%26 = extractvalue { i64, i1 } %23, 1
|
||||
br i1 %26, label %_llgo_10, label %_llgo_11
|
||||
|
||||
_llgo_10: ; preds = %_llgo_9
|
||||
%27 = sext i32 %25 to i64
|
||||
call void @main.printint(i64 %27)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_11: ; preds = %_llgo_9
|
||||
%28 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6)
|
||||
%29 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %28)
|
||||
%30 = extractvalue { i64, i1 } %29, 0
|
||||
%31 = extractvalue { i64, i1 } %29, 1
|
||||
br i1 %31, label %_llgo_12, label %_llgo_13
|
||||
|
||||
_llgo_12: ; preds = %_llgo_11
|
||||
call void @main.printint(i64 %30)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_13: ; preds = %_llgo_11
|
||||
%32 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 7)
|
||||
%33 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %32)
|
||||
%34 = extractvalue { i64, i1 } %33, 0
|
||||
%35 = extractvalue { i64, i1 } %33, 1
|
||||
br i1 %35, label %_llgo_14, label %_llgo_15
|
||||
|
||||
_llgo_14: ; preds = %_llgo_13
|
||||
call void @main.printuint(i64 %34)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_15: ; preds = %_llgo_13
|
||||
%36 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8)
|
||||
%37 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %36)
|
||||
%38 = extractvalue { i64, i1 } %37, 0
|
||||
%39 = trunc i64 %38 to i8
|
||||
%40 = extractvalue { i64, i1 } %37, 1
|
||||
br i1 %40, label %_llgo_16, label %_llgo_17
|
||||
|
||||
_llgo_16: ; preds = %_llgo_15
|
||||
%41 = zext i8 %39 to i64
|
||||
call void @main.printuint(i64 %41)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_17: ; preds = %_llgo_15
|
||||
%42 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 9)
|
||||
%43 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %42)
|
||||
%44 = extractvalue { i64, i1 } %43, 0
|
||||
%45 = trunc i64 %44 to i16
|
||||
%46 = extractvalue { i64, i1 } %43, 1
|
||||
br i1 %46, label %_llgo_18, label %_llgo_19
|
||||
|
||||
_llgo_18: ; preds = %_llgo_17
|
||||
%47 = zext i16 %45 to i64
|
||||
call void @main.printuint(i64 %47)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_19: ; preds = %_llgo_17
|
||||
%48 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 10)
|
||||
%49 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %48)
|
||||
%50 = extractvalue { i64, i1 } %49, 0
|
||||
%51 = trunc i64 %50 to i32
|
||||
%52 = extractvalue { i64, i1 } %49, 1
|
||||
br i1 %52, label %_llgo_20, label %_llgo_21
|
||||
|
||||
_llgo_20: ; preds = %_llgo_19
|
||||
%53 = zext i32 %51 to i64
|
||||
call void @main.printuint(i64 %53)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_21: ; preds = %_llgo_19
|
||||
%54 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 11)
|
||||
%55 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %54)
|
||||
%56 = extractvalue { i64, i1 } %55, 0
|
||||
%57 = extractvalue { i64, i1 } %55, 1
|
||||
br i1 %57, label %_llgo_22, label %_llgo_23
|
||||
|
||||
_llgo_22: ; preds = %_llgo_21
|
||||
call void @main.printuint(i64 %56)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_23: ; preds = %_llgo_21
|
||||
%58 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 12)
|
||||
%59 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %58)
|
||||
%60 = extractvalue { i64, i1 } %59, 0
|
||||
%61 = extractvalue { i64, i1 } %59, 1
|
||||
br i1 %61, label %_llgo_24, label %_llgo_25
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23
|
||||
call void @main.printuint(i64 %60)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_25: ; preds = %_llgo_23
|
||||
%62 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13)
|
||||
%63 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %62)
|
||||
%64 = extractvalue { i64, i1 } %63, 0
|
||||
%65 = trunc i64 %64 to i32
|
||||
%66 = bitcast i32 %65 to float
|
||||
%67 = extractvalue { i64, i1 } %63, 1
|
||||
br i1 %67, label %_llgo_26, label %_llgo_27
|
||||
|
||||
_llgo_26: ; preds = %_llgo_25
|
||||
%68 = fpext float %66 to double
|
||||
call void @main.printfloat(double %68)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_27: ; preds = %_llgo_25
|
||||
%69 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14)
|
||||
%70 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %69)
|
||||
%71 = extractvalue { i64, i1 } %70, 0
|
||||
%72 = bitcast i64 %71 to double
|
||||
%73 = extractvalue { i64, i1 } %70, 1
|
||||
br i1 %73, label %_llgo_28, label %_llgo_29
|
||||
|
||||
_llgo_28: ; preds = %_llgo_27
|
||||
call void @main.printfloat(double %72)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_29: ; preds = %_llgo_27
|
||||
%74 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24)
|
||||
%75 = call { %"github.com/goplus/llgo/internal/runtime.String", i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2String"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %74)
|
||||
%76 = extractvalue { %"github.com/goplus/llgo/internal/runtime.String", i1 } %75, 0
|
||||
%77 = extractvalue { %"github.com/goplus/llgo/internal/runtime.String", i1 } %75, 1
|
||||
br i1 %77, label %_llgo_30, label %_llgo_1
|
||||
|
||||
_llgo_30: ; preds = %_llgo_29
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %76)
|
||||
br label %_llgo_1
|
||||
}
|
||||
|
||||
define void @main.printbool(i1 %0) {
|
||||
_llgo_0:
|
||||
br i1 %0, label %_llgo_1, label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%1 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 4)
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %1)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_3, %_llgo_1
|
||||
ret void
|
||||
|
||||
_llgo_3: ; preds = %_llgo_0
|
||||
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @6, i64 5)
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %2)
|
||||
br label %_llgo_2
|
||||
}
|
||||
|
||||
define void @main.printfloat(double %0) {
|
||||
_llgo_0:
|
||||
%1 = fcmp one double %0, %0
|
||||
br i1 %1, label %_llgo_1, label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 3)
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %2)
|
||||
ret void
|
||||
|
||||
_llgo_2: ; preds = %_llgo_7
|
||||
%3 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @8, i64 4)
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %3)
|
||||
ret void
|
||||
|
||||
_llgo_3: ; preds = %_llgo_0
|
||||
%4 = fadd double %0, %0
|
||||
%5 = fcmp oeq double %4, %0
|
||||
br i1 %5, label %_llgo_6, label %_llgo_7
|
||||
|
||||
_llgo_4: ; preds = %_llgo_10
|
||||
%6 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @9, i64 4)
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %6)
|
||||
ret void
|
||||
|
||||
_llgo_5: ; preds = %_llgo_7
|
||||
%7 = fadd double %0, %0
|
||||
%8 = fcmp oeq double %7, %0
|
||||
br i1 %8, label %_llgo_9, label %_llgo_10
|
||||
|
||||
_llgo_6: ; preds = %_llgo_3
|
||||
%9 = fcmp ogt double %0, 0.000000e+00
|
||||
br label %_llgo_7
|
||||
|
||||
_llgo_7: ; preds = %_llgo_6, %_llgo_3
|
||||
%10 = phi i1 [ false, %_llgo_3 ], [ %9, %_llgo_6 ]
|
||||
br i1 %10, label %_llgo_2, label %_llgo_5
|
||||
|
||||
_llgo_8: ; preds = %_llgo_10
|
||||
%11 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 14)
|
||||
%12 = getelementptr inbounds i8, ptr %11, i64 0
|
||||
store i8 43, ptr %12, align 1
|
||||
%13 = fcmp oeq double %0, 0.000000e+00
|
||||
br i1 %13, label %_llgo_11, label %_llgo_13
|
||||
|
||||
_llgo_9: ; preds = %_llgo_5
|
||||
%14 = fcmp olt double %0, 0.000000e+00
|
||||
br label %_llgo_10
|
||||
|
||||
_llgo_10: ; preds = %_llgo_9, %_llgo_5
|
||||
%15 = phi i1 [ false, %_llgo_5 ], [ %14, %_llgo_9 ]
|
||||
br i1 %15, label %_llgo_4, label %_llgo_8
|
||||
|
||||
_llgo_11: ; preds = %_llgo_8
|
||||
%16 = fdiv double 1.000000e+00, %0
|
||||
%17 = fcmp olt double %16, 0.000000e+00
|
||||
br i1 %17, label %_llgo_14, label %_llgo_12
|
||||
|
||||
_llgo_12: ; preds = %_llgo_24, %_llgo_22, %_llgo_14, %_llgo_11
|
||||
%18 = phi double [ %0, %_llgo_11 ], [ %36, %_llgo_22 ], [ %0, %_llgo_14 ], [ %42, %_llgo_24 ]
|
||||
%19 = phi i64 [ 0, %_llgo_11 ], [ %32, %_llgo_22 ], [ 0, %_llgo_14 ], [ %41, %_llgo_24 ]
|
||||
br label %_llgo_27
|
||||
|
||||
_llgo_13: ; preds = %_llgo_8
|
||||
%20 = fcmp olt double %0, 0.000000e+00
|
||||
br i1 %20, label %_llgo_15, label %_llgo_17
|
||||
|
||||
_llgo_14: ; preds = %_llgo_11
|
||||
%21 = getelementptr inbounds i8, ptr %11, i64 0
|
||||
store i8 45, ptr %21, align 1
|
||||
br label %_llgo_12
|
||||
|
||||
_llgo_15: ; preds = %_llgo_13
|
||||
%22 = fneg double %0
|
||||
%23 = getelementptr inbounds i8, ptr %11, i64 0
|
||||
store i8 45, ptr %23, align 1
|
||||
br label %_llgo_17
|
||||
|
||||
_llgo_16: ; preds = %_llgo_17
|
||||
%24 = add i64 %27, 1
|
||||
%25 = fdiv double %26, 1.000000e+01
|
||||
br label %_llgo_17
|
||||
|
||||
_llgo_17: ; preds = %_llgo_16, %_llgo_15, %_llgo_13
|
||||
%26 = phi double [ %0, %_llgo_13 ], [ %25, %_llgo_16 ], [ %22, %_llgo_15 ]
|
||||
%27 = phi i64 [ 0, %_llgo_13 ], [ %24, %_llgo_16 ], [ 0, %_llgo_15 ]
|
||||
%28 = fcmp oge double %26, 1.000000e+01
|
||||
br i1 %28, label %_llgo_16, label %_llgo_20
|
||||
|
||||
_llgo_18: ; preds = %_llgo_20
|
||||
%29 = sub i64 %32, 1
|
||||
%30 = fmul double %31, 1.000000e+01
|
||||
br label %_llgo_20
|
||||
|
||||
_llgo_19: ; preds = %_llgo_20
|
||||
br label %_llgo_23
|
||||
|
||||
_llgo_20: ; preds = %_llgo_18, %_llgo_17
|
||||
%31 = phi double [ %26, %_llgo_17 ], [ %30, %_llgo_18 ]
|
||||
%32 = phi i64 [ %27, %_llgo_17 ], [ %29, %_llgo_18 ]
|
||||
%33 = fcmp olt double %31, 1.000000e+00
|
||||
br i1 %33, label %_llgo_18, label %_llgo_19
|
||||
|
||||
_llgo_21: ; preds = %_llgo_23
|
||||
%34 = fdiv double %38, 1.000000e+01
|
||||
%35 = add i64 %39, 1
|
||||
br label %_llgo_23
|
||||
|
||||
_llgo_22: ; preds = %_llgo_23
|
||||
%36 = fadd double %31, %38
|
||||
%37 = fcmp oge double %36, 1.000000e+01
|
||||
br i1 %37, label %_llgo_24, label %_llgo_12
|
||||
|
||||
_llgo_23: ; preds = %_llgo_21, %_llgo_19
|
||||
%38 = phi double [ 5.000000e+00, %_llgo_19 ], [ %34, %_llgo_21 ]
|
||||
%39 = phi i64 [ 0, %_llgo_19 ], [ %35, %_llgo_21 ]
|
||||
%40 = icmp slt i64 %39, 7
|
||||
br i1 %40, label %_llgo_21, label %_llgo_22
|
||||
|
||||
_llgo_24: ; preds = %_llgo_22
|
||||
%41 = add i64 %32, 1
|
||||
%42 = fdiv double %36, 1.000000e+01
|
||||
br label %_llgo_12
|
||||
|
||||
_llgo_25: ; preds = %_llgo_27
|
||||
%43 = fptosi double %60 to i64
|
||||
%44 = add i64 %61, 2
|
||||
%45 = add i64 %43, 48
|
||||
%46 = trunc i64 %45 to i8
|
||||
%47 = icmp slt i64 %44, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %47)
|
||||
%48 = getelementptr inbounds i8, ptr %11, i64 %44
|
||||
store i8 %46, ptr %48, align 1
|
||||
%49 = sitofp i64 %43 to double
|
||||
%50 = fsub double %60, %49
|
||||
%51 = fmul double %50, 1.000000e+01
|
||||
%52 = add i64 %61, 1
|
||||
br label %_llgo_27
|
||||
|
||||
_llgo_26: ; preds = %_llgo_27
|
||||
%53 = getelementptr inbounds i8, ptr %11, i64 2
|
||||
%54 = load i8, ptr %53, align 1
|
||||
%55 = getelementptr inbounds i8, ptr %11, i64 1
|
||||
store i8 %54, ptr %55, align 1
|
||||
%56 = getelementptr inbounds i8, ptr %11, i64 2
|
||||
store i8 46, ptr %56, align 1
|
||||
%57 = getelementptr inbounds i8, ptr %11, i64 9
|
||||
store i8 101, ptr %57, align 1
|
||||
%58 = getelementptr inbounds i8, ptr %11, i64 10
|
||||
store i8 43, ptr %58, align 1
|
||||
%59 = icmp slt i64 %19, 0
|
||||
br i1 %59, label %_llgo_28, label %_llgo_29
|
||||
|
||||
_llgo_27: ; preds = %_llgo_25, %_llgo_12
|
||||
%60 = phi double [ %18, %_llgo_12 ], [ %51, %_llgo_25 ]
|
||||
%61 = phi i64 [ 0, %_llgo_12 ], [ %52, %_llgo_25 ]
|
||||
%62 = icmp slt i64 %61, 7
|
||||
br i1 %62, label %_llgo_25, label %_llgo_26
|
||||
|
||||
_llgo_28: ; preds = %_llgo_26
|
||||
%63 = sub i64 0, %19
|
||||
%64 = getelementptr inbounds i8, ptr %11, i64 10
|
||||
store i8 45, ptr %64, align 1
|
||||
br label %_llgo_29
|
||||
|
||||
_llgo_29: ; preds = %_llgo_28, %_llgo_26
|
||||
%65 = phi i64 [ %19, %_llgo_26 ], [ %63, %_llgo_28 ]
|
||||
%66 = sdiv i64 %65, 100
|
||||
%67 = trunc i64 %66 to i8
|
||||
%68 = add i8 %67, 48
|
||||
%69 = getelementptr inbounds i8, ptr %11, i64 11
|
||||
store i8 %68, ptr %69, align 1
|
||||
%70 = sdiv i64 %65, 10
|
||||
%71 = trunc i64 %70 to i8
|
||||
%72 = urem i8 %71, 10
|
||||
%73 = add i8 %72, 48
|
||||
%74 = getelementptr inbounds i8, ptr %11, i64 12
|
||||
store i8 %73, ptr %74, align 1
|
||||
%75 = srem i64 %65, 10
|
||||
%76 = trunc i64 %75 to i8
|
||||
%77 = add i8 %76, 48
|
||||
%78 = getelementptr inbounds i8, ptr %11, i64 13
|
||||
store i8 %77, ptr %78, align 1
|
||||
%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" %79)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.printhex(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 100)
|
||||
br label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_3
|
||||
%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)
|
||||
%4 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %3, 0
|
||||
%5 = getelementptr inbounds i8, ptr %4, i64 %2
|
||||
%6 = load i8, ptr %5, align 1
|
||||
%7 = icmp slt i64 %18, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %7)
|
||||
%8 = getelementptr inbounds i8, ptr %1, i64 %18
|
||||
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
|
||||
%10 = sub i64 %18, 1
|
||||
%11 = icmp slt i64 %10, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %11)
|
||||
%12 = getelementptr inbounds i8, ptr %1, i64 %10
|
||||
store i8 120, ptr %12, align 1
|
||||
%13 = sub i64 %10, 1
|
||||
%14 = icmp slt i64 %13, 0
|
||||
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
|
||||
|
||||
_llgo_3: ; preds = %_llgo_4, %_llgo_0
|
||||
%17 = phi i64 [ %0, %_llgo_0 ], [ %20, %_llgo_4 ]
|
||||
%18 = phi i64 [ 99, %_llgo_0 ], [ %21, %_llgo_4 ]
|
||||
%19 = icmp sgt i64 %18, 0
|
||||
br i1 %19, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_4: ; preds = %_llgo_5, %_llgo_1
|
||||
%20 = udiv i64 %17, 16
|
||||
%21 = sub i64 %18, 1
|
||||
br label %_llgo_3
|
||||
|
||||
_llgo_5: ; preds = %_llgo_1
|
||||
%22 = sub i64 100, %18
|
||||
%23 = load i64, ptr @main.minhexdigits, align 4
|
||||
%24 = icmp sge i64 %22, %23
|
||||
br i1 %24, label %_llgo_2, label %_llgo_4
|
||||
}
|
||||
|
||||
define void @main.printint(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = icmp slt i64 %0, 0
|
||||
br i1 %1, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @11, i64 1)
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %2)
|
||||
%3 = sub i64 0, %0
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%4 = phi i64 [ %0, %_llgo_0 ], [ %3, %_llgo_1 ]
|
||||
call void @main.printuint(i64 %4)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
|
||||
_llgo_0:
|
||||
%1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_5, %_llgo_0
|
||||
%2 = phi i64 [ -1, %_llgo_0 ], [ %3, %_llgo_5 ]
|
||||
%3 = add i64 %2, 1
|
||||
%4 = icmp slt i64 %3, %1
|
||||
br i1 %4, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%5 = icmp slt i64 %3, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %6, i64 %3
|
||||
%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
|
||||
call void @main.printnl()
|
||||
ret void
|
||||
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
%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" %10)
|
||||
br label %_llgo_5
|
||||
|
||||
_llgo_5: ; preds = %_llgo_4, %_llgo_2
|
||||
call void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %8)
|
||||
br label %_llgo_1
|
||||
}
|
||||
|
||||
define void @main.printnl() {
|
||||
_llgo_0:
|
||||
%0 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @13, i64 1)
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %0)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.printsp() {
|
||||
_llgo_0:
|
||||
%0 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @14, i64 1)
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %0)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %0) {
|
||||
_llgo_0:
|
||||
%1 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.bytes(%"github.com/goplus/llgo/internal/runtime.String" %0)
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %1)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.printuint(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 100)
|
||||
br label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_3
|
||||
%2 = urem i64 %9, 10
|
||||
%3 = add i64 %2, 48
|
||||
%4 = trunc i64 %3 to i8
|
||||
%5 = icmp slt i64 %10, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
|
||||
%6 = getelementptr inbounds i8, ptr %1, i64 %10
|
||||
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
|
||||
%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" %8)
|
||||
ret void
|
||||
|
||||
_llgo_3: ; preds = %_llgo_4, %_llgo_0
|
||||
%9 = phi i64 [ %0, %_llgo_0 ], [ %12, %_llgo_4 ]
|
||||
%10 = phi i64 [ 99, %_llgo_0 ], [ %13, %_llgo_4 ]
|
||||
%11 = icmp sgt i64 %10, 0
|
||||
br i1 %11, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_4: ; preds = %_llgo_1
|
||||
%12 = udiv i64 %9, 10
|
||||
%13 = sub i64 %10, 1
|
||||
br label %_llgo_3
|
||||
}
|
||||
|
||||
define void @main.prinusub(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = sub i64 0, %0
|
||||
call void @main.printuint(i64 %1)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.prinxor(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = xor i64 %0, -1
|
||||
call void @main.printint(i64 %1)
|
||||
ret void
|
||||
}
|
||||
|
||||
define ptr @main.stringStructOf(ptr %0) {
|
||||
_llgo_0:
|
||||
ret ptr %0
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
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 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 %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)
|
||||
|
||||
declare { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"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 void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
@@ -1,8 +1,10 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@main.hello = global ptr null
|
||||
@main.hello = global [7 x i8] undef
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
@@ -24,14 +26,16 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
call void (ptr, ...) @printf(ptr @main.hello)
|
||||
ret void
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @printf(ptr, ...)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare void @printf(ptr, ...)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@main.format = global ptr null
|
||||
@main.format = global [10 x i8] undef
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
@@ -27,14 +29,16 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
call void (ptr, ...) @printf(ptr @main.format, i64 100)
|
||||
ret void
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @printf(ptr, ...)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare void @printf(ptr, ...)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@main.format = global ptr null
|
||||
@main.format = global [10 x i8] undef
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define void @"(*main.T).Print"(ptr %0, i64 %1) {
|
||||
_llgo_0:
|
||||
@@ -33,12 +35,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
call void @"(*main.T).Print"(ptr @main.format, i64 100)
|
||||
ret void
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @printf(ptr, ...)
|
||||
|
||||
13
cl/_testdata/uint/in.go
Normal file
13
cl/_testdata/uint/in.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/c"
|
||||
|
||||
func f(a c.Uint) c.Uint {
|
||||
a++
|
||||
return a
|
||||
}
|
||||
|
||||
func main() {
|
||||
var a c.Uint = 100
|
||||
c.Printf(c.Str("Hello, %u\n"), f(a))
|
||||
}
|
||||
41
cl/_testdata/uint/out.ll
Normal file
41
cl/_testdata/uint/out.ll
Normal file
@@ -0,0 +1,41 @@
|
||||
; 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 [11 x i8] c"Hello, %u\0A\00", align 1
|
||||
|
||||
define i32 @main.f(i32 %0) {
|
||||
_llgo_0:
|
||||
%1 = add i32 %0, 1
|
||||
ret i32 %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.f(i32 100)
|
||||
%3 = call i32 (ptr, ...) @printf(ptr @0, i32 %2)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
@@ -3,6 +3,8 @@ source_filename = "main"
|
||||
|
||||
@main.a = global ptr null
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
@@ -18,8 +20,10 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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 i1 false, label %_llgo_1, label %_llgo_2
|
||||
@@ -29,7 +33,7 @@ _llgo_1: ; preds = %_llgo_0
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
23
cl/_testdata/utf8/in.go
Normal file
23
cl/_testdata/utf8/in.go
Normal 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
101
cl/_testdata/utf8/out.ll
Normal 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)
|
||||
13
cl/_testdata/vargs/in.go
Normal file
13
cl/_testdata/vargs/in.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/internal/runtime/c"
|
||||
|
||||
func test(a ...any) {
|
||||
for _, v := range a {
|
||||
c.Printf(c.Str("%d\n"), v.(int))
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
test(1, 2, 3)
|
||||
}
|
||||
89
cl/_testdata/vargs/out.ll
Normal file
89
cl/_testdata/vargs/out.ll
Normal file
@@ -0,0 +1,89 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr }
|
||||
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
@0 = private unnamed_addr constant [4 x i8] c"%d\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 ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48)
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i64 0
|
||||
%4 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %4, i64 1)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %5, ptr %3, align 8
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i64 1
|
||||
%7 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
%8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %7, i64 2)
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %8, ptr %6, align 8
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i64 2
|
||||
%10 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
%11 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %10, i64 3)
|
||||
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)
|
||||
call void @main.test(%"github.com/goplus/llgo/internal/runtime.Slice" %12)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
define void @main.test(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
|
||||
_llgo_0:
|
||||
%1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%2 = phi i64 [ -1, %_llgo_0 ], [ %3, %_llgo_2 ]
|
||||
%3 = add i64 %2, 1
|
||||
%4 = icmp slt i64 %3, %1
|
||||
br i1 %4, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%5 = icmp slt i64 %3, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5)
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %6, i64 %3
|
||||
%8 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %7, align 8
|
||||
%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
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(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 %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
@@ -3,6 +3,8 @@ source_filename = "main"
|
||||
|
||||
@main.a = global ptr null
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
@@ -18,15 +20,17 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
%0 = load i64, ptr @main.a, align 4
|
||||
%1 = add i64 %0, 1
|
||||
store i64 %1, ptr @main.a, align 4
|
||||
%2 = load i64, ptr @main.a, align 4
|
||||
ret void
|
||||
%3 = add i64 %2, 1
|
||||
store i64 %3, ptr @main.a, align 4
|
||||
%4 = load i64, ptr @main.a, align 4
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
11
cl/_testlibc/argv/in.go
Normal file
11
cl/_testlibc/argv/in.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for i := c.Int(0); i < c.Argc; i++ {
|
||||
c.Printf(c.Str("%s\n"), c.Index(c.Argv, i))
|
||||
}
|
||||
}
|
||||
50
cl/_testlibc/argv/out.ll
Normal file
50
cl/_testlibc/argv/out.ll
Normal file
@@ -0,0 +1,50 @@
|
||||
; 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 [4 x i8] c"%s\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()
|
||||
br label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_3
|
||||
%2 = load ptr, ptr @__llgo_argv, align 8
|
||||
%3 = getelementptr ptr, ptr %2, i32 %7
|
||||
%4 = load ptr, ptr %3, align 8
|
||||
%5 = call i32 (ptr, ...) @printf(ptr @0, ptr %4)
|
||||
%6 = add i32 %7, 1
|
||||
br label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_3
|
||||
ret i32 0
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1, %_llgo_0
|
||||
%7 = phi i32 [ 0, %_llgo_0 ], [ %6, %_llgo_1 ]
|
||||
%8 = load i32, ptr @__llgo_argc, align 4
|
||||
%9 = icmp slt i32 %7, %8
|
||||
br i1 %9, label %_llgo_1, label %_llgo_2
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
20
cl/_testlibc/sqlite/in.go
Normal file
20
cl/_testlibc/sqlite/in.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/sqlite"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db, err := sqlite.OpenV2(c.Str(":memory:"), sqlite.OpenReadWrite|sqlite.OpenMemory, nil)
|
||||
check(err)
|
||||
|
||||
db.Close()
|
||||
}
|
||||
|
||||
func check(err sqlite.Errno) {
|
||||
if err != sqlite.OK {
|
||||
c.Printf(c.Str("==> Error: (%d) %s\n"), err, err.Errstr())
|
||||
c.Exit(1)
|
||||
}
|
||||
}
|
||||
62
cl/_testlibc/sqlite/out.ll
Normal file
62
cl/_testlibc/sqlite/out.ll
Normal file
@@ -0,0 +1,62 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@0 = private unnamed_addr constant [20 x i8] c"==> Error: (%d) %s\0A\00", align 1
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
@1 = private unnamed_addr constant [9 x i8] c":memory:\00", align 1
|
||||
|
||||
define void @main.check(i32 %0) {
|
||||
_llgo_0:
|
||||
%1 = icmp ne i32 %0, 0
|
||||
br i1 %1, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call ptr @sqlite3_errstr(i32 %0)
|
||||
%3 = call i32 (ptr, ...) @printf(ptr @0, i32 %0, ptr %2)
|
||||
call void @exit(i32 1)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
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 { ptr, i32 } @"github.com/goplus/llgo/c/sqlite.OpenV2"(ptr @1, i32 130, ptr null)
|
||||
%3 = extractvalue { ptr, i32 } %2, 0
|
||||
%4 = extractvalue { ptr, i32 } %2, 1
|
||||
call void @main.check(i32 %4)
|
||||
%5 = call i32 @sqlite3_close(ptr %3)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare ptr @sqlite3_errstr(i32)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare void @exit(i32)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare { ptr, i32 } @"github.com/goplus/llgo/c/sqlite.OpenV2"(ptr, i32, ptr)
|
||||
|
||||
declare i32 @sqlite3_close(ptr)
|
||||
15
cl/_testpy/callpy/in.go
Normal file
15
cl/_testpy/callpy/in.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
"github.com/goplus/llgo/py/os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := math.Sqrt(py.Float(2))
|
||||
wd := os.Getcwd()
|
||||
c.Printf(c.Str("sqrt(2) = %f\n"), x.Float64())
|
||||
c.Printf(c.Str("cwd = %s\n"), wd.CStr())
|
||||
}
|
||||
74
cl/_testpy/callpy/out.ll
Normal file
74
cl/_testpy/callpy/out.ll
Normal file
@@ -0,0 +1,74 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
@__llgo_py.math.sqrt = linkonce global ptr null
|
||||
@__llgo_py.os.getcwd = linkonce global ptr null
|
||||
@0 = private unnamed_addr constant [14 x i8] c"sqrt(2) = %f\0A\00", align 1
|
||||
@1 = private unnamed_addr constant [10 x i8] c"cwd = %s\0A\00", align 1
|
||||
@__llgo_py.math = external global ptr
|
||||
@2 = private unnamed_addr constant [5 x i8] c"sqrt\00", align 1
|
||||
@__llgo_py.os = external global ptr
|
||||
@3 = private unnamed_addr constant [7 x i8] c"getcwd\00", align 1
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"main.init$guard", align 1
|
||||
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"main.init$guard", align 1
|
||||
call void @"github.com/goplus/llgo/py/math.init"()
|
||||
call void @"github.com/goplus/llgo/py/os.init"()
|
||||
%1 = load ptr, ptr @__llgo_py.math, align 8
|
||||
call void (ptr, ...) @llgoLoadPyModSyms(ptr %1, ptr @2, ptr @__llgo_py.math.sqrt, ptr null)
|
||||
%2 = load ptr, ptr @__llgo_py.os, align 8
|
||||
call void (ptr, ...) @llgoLoadPyModSyms(ptr %2, ptr @3, ptr @__llgo_py.os.getcwd, ptr null)
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
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 = load ptr, ptr @__llgo_py.math.sqrt, align 8
|
||||
%4 = call ptr @PyObject_CallOneArg(ptr %3, ptr %2)
|
||||
%5 = load ptr, ptr @__llgo_py.os.getcwd, align 8
|
||||
%6 = call ptr @PyObject_CallNoArgs(ptr %5)
|
||||
%7 = call double @PyFloat_AsDouble(ptr %4)
|
||||
%8 = call i32 (ptr, ...) @printf(ptr @0, double %7)
|
||||
%9 = call ptr @PyUnicode_AsUTF8(ptr %6)
|
||||
%10 = call i32 (ptr, ...) @printf(ptr @1, ptr %9)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/py/math.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/py/os.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @PyFloat_FromDouble(double)
|
||||
|
||||
declare ptr @PyObject_CallOneArg(ptr, ptr)
|
||||
|
||||
declare ptr @PyObject_CallNoArgs(ptr)
|
||||
|
||||
declare double @PyFloat_AsDouble(ptr)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare ptr @PyUnicode_AsUTF8(ptr)
|
||||
|
||||
declare void @llgoLoadPyModSyms(ptr, ...)
|
||||
|
||||
declare void @Py_Initialize()
|
||||
12
cl/_testpy/gcd/in.go
Normal file
12
cl/_testpy/gcd/in.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := math.Gcd(py.Long(60), py.Long(20), py.Long(25))
|
||||
c.Printf(c.Str("gcd(60, 20, 25) = %d\n"), x.Long())
|
||||
}
|
||||
59
cl/_testpy/gcd/out.ll
Normal file
59
cl/_testpy/gcd/out.ll
Normal 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()
|
||||
14
cl/_testpy/math/in.go
Normal file
14
cl/_testpy/math/in.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package math
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/py"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "py.math"
|
||||
)
|
||||
|
||||
//go:linkname Sqrt py.sqrt
|
||||
func Sqrt(x *py.Object) *py.Object
|
||||
28
cl/_testpy/math/out.ll
Normal file
28
cl/_testpy/math/out.ll
Normal file
@@ -0,0 +1,28 @@
|
||||
; ModuleID = 'math'
|
||||
source_filename = "math"
|
||||
|
||||
@"math.init$guard" = global ptr null
|
||||
@__llgo_py.math = linkonce global ptr null
|
||||
@0 = private unnamed_addr constant [5 x i8] c"math\00", align 1
|
||||
|
||||
define void @math.init() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"math.init$guard", align 1
|
||||
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"math.init$guard", align 1
|
||||
%1 = load ptr, ptr @__llgo_py.math, align 8
|
||||
%2 = icmp ne ptr %1, null
|
||||
br i1 %2, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_3, %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
%3 = call ptr @PyImport_ImportModule(ptr @0)
|
||||
store ptr %3, ptr @__llgo_py.math, align 8
|
||||
br label %_llgo_2
|
||||
}
|
||||
|
||||
declare ptr @PyImport_ImportModule(ptr)
|
||||
24
cl/_testpy/matrix/in.go
Normal file
24
cl/_testpy/matrix/in.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/numpy"
|
||||
)
|
||||
|
||||
func main() {
|
||||
a := py.List(
|
||||
py.List(1.0, 2.0, 3.0),
|
||||
py.List(4.0, 5.0, 6.0),
|
||||
py.List(7.0, 8.0, 9.0),
|
||||
)
|
||||
b := py.List(
|
||||
py.List(9.0, 8.0, 7.0),
|
||||
py.List(6.0, 5.0, 4.0),
|
||||
py.List(3.0, 2.0, 1.0),
|
||||
)
|
||||
x := numpy.Add(a, b)
|
||||
c.Printf(c.Str("a = %s\n"), a.Str().CStr())
|
||||
c.Printf(c.Str("a = %s\n"), b.Str().CStr())
|
||||
c.Printf(c.Str("a+b = %s\n"), x.Str().CStr())
|
||||
}
|
||||
121
cl/_testpy/matrix/out.ll
Normal file
121
cl/_testpy/matrix/out.ll
Normal 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
10
cl/_testpy/pi/in.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("pi = %f\n"), math.Pi.Float64())
|
||||
}
|
||||
49
cl/_testpy/pi/out.ll
Normal file
49
cl/_testpy/pi/out.ll
Normal 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
12
cl/_testpy/pow/in.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/py"
|
||||
"github.com/goplus/llgo/py/math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := math.Pow(py.Float(2), py.Float(3))
|
||||
c.Printf(c.Str("pow(2, 3) = %f\n"), x.Float64())
|
||||
}
|
||||
58
cl/_testpy/pow/out.ll
Normal file
58
cl/_testpy/pow/out.ll
Normal 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()
|
||||
@@ -2,6 +2,8 @@
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
@0 = private unnamed_addr constant [4 x i8] c"Hi\0A\00", align 1
|
||||
@1 = private unnamed_addr constant [3 x i8] c"%s\00", align 1
|
||||
|
||||
@@ -18,14 +20,16 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
%0 = alloca i8, i64 4, align 1
|
||||
%1 = call ptr @memcpy(ptr %0, ptr @0, i64 4)
|
||||
%2 = call i32 (ptr, ...) @printf(ptr @1, ptr %0)
|
||||
ret void
|
||||
%2 = alloca i8, i64 4, align 1
|
||||
%3 = call ptr @memcpy(ptr %2, ptr @0, i64 4)
|
||||
%4 = call i32 (ptr, ...) @printf(ptr @1, ptr %2)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@0 = private unnamed_addr constant [13 x i8] c"Hello world\0A\00", align 1
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define %"github.com/goplus/llgo/internal/runtime.String" @main.hello() {
|
||||
_llgo_0:
|
||||
@@ -26,25 +27,25 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
%0 = call %"github.com/goplus/llgo/internal/runtime.String" @main.hello()
|
||||
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.String" %0)
|
||||
%2 = add i64 %1, 1
|
||||
%3 = alloca i8, i64 %2, align 1
|
||||
%4 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %3, %"github.com/goplus/llgo/internal/runtime.String" %0)
|
||||
%5 = call i32 (ptr, ...) @printf(ptr %4)
|
||||
ret void
|
||||
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @main.hello()
|
||||
%3 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 1
|
||||
%4 = add i64 %3, 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)
|
||||
%7 = call i32 (ptr, ...) @printf(ptr %6)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
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.init"()
|
||||
|
||||
declare i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.Slice")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr, %"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
@@ -4,6 +4,8 @@ source_filename = "main"
|
||||
%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr }
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
@0 = private unnamed_addr constant [10 x i8] c"Hello %d\0A\00", align 1
|
||||
|
||||
define i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.iface" %0) {
|
||||
@@ -27,15 +29,17 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
%1 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %0, i64 100)
|
||||
%2 = call i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.iface" %1)
|
||||
%3 = call i32 (ptr, ...) @printf(ptr @0, i64 %2)
|
||||
ret void
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
%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)
|
||||
%5 = call i32 (ptr, ...) @printf(ptr @0, i64 %4)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr)
|
||||
|
||||
@@ -1,11 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var a int64 = 1<<63 - 1
|
||||
var b int64 = -1 << 63
|
||||
var c uint64 = 1<<64 - 1
|
||||
var n uint64 = 1<<64 - 1
|
||||
|
||||
func main() {
|
||||
var a = []int{1, 2, 3, 4}
|
||||
_ = len(a)
|
||||
_ = len([]int{1, 2, 3, 4})
|
||||
var s = []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]))
|
||||
|
||||
println("hello", "hello"[1:], "hello"[1:2], len("hello"[5:]))
|
||||
println(append(s, 5, 6, 7, 8))
|
||||
data := []byte{'a', 'b', 'c'}
|
||||
data = append(data, "def"...)
|
||||
println(data)
|
||||
var i any = 100
|
||||
println(true, 100, -100, uint(255), int32(-100), 100.5, i, &i, uintptr(unsafe.Pointer(&i)))
|
||||
}
|
||||
|
||||
@@ -2,11 +2,59 @@
|
||||
source_filename = "main"
|
||||
|
||||
%"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.iface" = type { ptr, ptr }
|
||||
|
||||
@main.a = global ptr null
|
||||
@main.b = global ptr null
|
||||
@main.c = global ptr null
|
||||
@"main.init$guard" = global ptr null
|
||||
@main.n = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
@0 = private unnamed_addr constant [2 x i8] c" \00", align 1
|
||||
@1 = private unnamed_addr constant [2 x i8] c" \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" \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() {
|
||||
_llgo_0:
|
||||
@@ -17,46 +65,282 @@ _llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"main.init$guard", align 1
|
||||
store i64 9223372036854775807, ptr @main.a, align 4
|
||||
store i64 -9223372036854775808, ptr @main.b, align 4
|
||||
store i64 -1, ptr @main.c, align 4
|
||||
store i64 -1, ptr @main.n, align 4
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 32)
|
||||
%1 = getelementptr inbounds i64, ptr %0, i64 0
|
||||
store i64 1, ptr %1, align 4
|
||||
%2 = getelementptr inbounds i64, ptr %0, i64 1
|
||||
store i64 2, ptr %2, align 4
|
||||
%3 = getelementptr inbounds i64, ptr %0, i64 2
|
||||
store i64 3, ptr %3, align 4
|
||||
%4 = getelementptr inbounds i64, ptr %0, i64 3
|
||||
store i64 4, ptr %4, align 4
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr %0, i64 4, i64 4)
|
||||
%6 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %5)
|
||||
%7 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 32)
|
||||
%8 = getelementptr inbounds i64, ptr %7, i64 0
|
||||
store i64 1, ptr %8, align 4
|
||||
%9 = getelementptr inbounds i64, ptr %7, i64 1
|
||||
store i64 2, ptr %9, align 4
|
||||
%10 = getelementptr inbounds i64, ptr %7, i64 2
|
||||
store i64 3, ptr %10, align 4
|
||||
%11 = getelementptr inbounds i64, ptr %7, i64 3
|
||||
store i64 4, ptr %11, align 4
|
||||
%12 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr %7, i64 4, i64 4)
|
||||
%13 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %12)
|
||||
ret void
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
|
||||
%3 = getelementptr inbounds i64, ptr %2, i64 0
|
||||
store i64 1, ptr %3, align 4
|
||||
%4 = getelementptr inbounds i64, ptr %2, i64 1
|
||||
store i64 2, ptr %4, align 4
|
||||
%5 = getelementptr inbounds i64, ptr %2, i64 2
|
||||
store i64 3, ptr %5, align 4
|
||||
%6 = getelementptr inbounds i64, ptr %2, i64 3
|
||||
store i64 4, ptr %6, align 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 ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
|
||||
%9 = getelementptr inbounds i64, ptr %8, i64 0
|
||||
%10 = getelementptr inbounds i64, ptr %8, i64 1
|
||||
%11 = getelementptr inbounds i64, ptr %8, i64 2
|
||||
%12 = getelementptr inbounds i64, ptr %8, i64 3
|
||||
store i64 1, ptr %9, align 4
|
||||
store i64 2, ptr %10, align 4
|
||||
store i64 3, ptr %11, align 4
|
||||
store i64 4, ptr %12, align 4
|
||||
%13 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 10)
|
||||
%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)
|
||||
%15 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 1
|
||||
%16 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %7)
|
||||
%17 = 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" %17)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %15)
|
||||
%18 = 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" %18)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %16)
|
||||
%19 = 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" %19)
|
||||
%20 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %14, 1
|
||||
%21 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %14, 2
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %14)
|
||||
%22 = 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" %22)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %20)
|
||||
%23 = 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" %23)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %21)
|
||||
%24 = 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" %24)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
|
||||
%25 = 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" %25)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
|
||||
%26 = 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" %26)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
|
||||
%27 = 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" %27)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
|
||||
%28 = 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" %28)
|
||||
%29 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
|
||||
%30 = getelementptr inbounds i64, ptr %29, i64 0
|
||||
store i64 1, ptr %30, align 4
|
||||
%31 = getelementptr inbounds i64, ptr %29, i64 1
|
||||
store i64 2, ptr %31, align 4
|
||||
%32 = getelementptr inbounds i64, ptr %29, i64 2
|
||||
store i64 3, ptr %32, align 4
|
||||
%33 = getelementptr inbounds i64, ptr %29, i64 3
|
||||
store i64 4, ptr %33, align 4
|
||||
%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)
|
||||
%35 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %34, 1
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %35)
|
||||
%36 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @10, i64 1)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %36)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4)
|
||||
%37 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @11, i64 1)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %37)
|
||||
%38 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
|
||||
%39 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
|
||||
%40 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
|
||||
%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)
|
||||
%42 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %41, 1
|
||||
%43 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
|
||||
%44 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
|
||||
%45 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
|
||||
%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)
|
||||
%47 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %46, 2
|
||||
%48 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
|
||||
%49 = 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 %49, i64 8, i64 %48, i64 1, i64 2, i64 %48)
|
||||
%51 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %50, 1
|
||||
%52 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
|
||||
%53 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
|
||||
%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)
|
||||
%55 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %54, 2
|
||||
%56 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
|
||||
%57 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
|
||||
%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)
|
||||
%59 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %58, 1
|
||||
%60 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2
|
||||
%61 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
|
||||
%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)
|
||||
%63 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %62, 2
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %42)
|
||||
%64 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @12, i64 1)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %64)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %47)
|
||||
%65 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @13, i64 1)
|
||||
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)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %66)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %55)
|
||||
%67 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @15, i64 1)
|
||||
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)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %68)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %63)
|
||||
%69 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @17, i64 1)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %69)
|
||||
%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 ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(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.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 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.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.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)
|
||||
|
||||
18
cl/_testrt/callback/in.go
Normal file
18
cl/_testrt/callback/in.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
func callback(msg *c.Char, f func(*c.Char)) {
|
||||
f(msg)
|
||||
}
|
||||
|
||||
func print(msg *c.Char) {
|
||||
c.Printf(msg)
|
||||
}
|
||||
|
||||
func main() {
|
||||
callback(c.Str("Hello\n"), print)
|
||||
callback(c.Str("callback\n"), print)
|
||||
}
|
||||
68
cl/_testrt/callback/out.ll
Normal file
68
cl/_testrt/callback/out.ll
Normal file
@@ -0,0 +1,68 @@
|
||||
; 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 [7 x i8] c"Hello\0A\00", align 1
|
||||
@1 = private unnamed_addr constant [10 x i8] c"callback\0A\00", align 1
|
||||
|
||||
define void @main.callback(ptr %0, { ptr, ptr } %1) {
|
||||
_llgo_0:
|
||||
%2 = extractvalue { ptr, ptr } %1, 1
|
||||
%3 = extractvalue { ptr, ptr } %1, 0
|
||||
call void %3(ptr %2, ptr %0)
|
||||
ret void
|
||||
}
|
||||
|
||||
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 = alloca { ptr, ptr }, align 8
|
||||
%3 = getelementptr inbounds { ptr, ptr }, ptr %2, i32 0, i32 0
|
||||
store ptr @__llgo_stub.main.print, ptr %3, align 8
|
||||
%4 = getelementptr inbounds { ptr, ptr }, ptr %2, i32 0, i32 1
|
||||
store ptr null, ptr %4, align 8
|
||||
%5 = load { ptr, ptr }, ptr %2, align 8
|
||||
call void @main.callback(ptr @0, { ptr, ptr } %5)
|
||||
%6 = alloca { ptr, ptr }, align 8
|
||||
%7 = getelementptr inbounds { ptr, ptr }, ptr %6, i32 0, i32 0
|
||||
store ptr @__llgo_stub.main.print, ptr %7, align 8
|
||||
%8 = getelementptr inbounds { ptr, ptr }, ptr %6, i32 0, i32 1
|
||||
store ptr null, ptr %8, align 8
|
||||
%9 = load { ptr, ptr }, ptr %6, align 8
|
||||
call void @main.callback(ptr @1, { ptr, ptr } %9)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
define void @main.print(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = call i32 (ptr, ...) @printf(ptr %0)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
define linkonce void @__llgo_stub.main.print(ptr %0, ptr %1) {
|
||||
_llgo_0:
|
||||
tail call void @main.print(ptr %1)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
158
cl/_testrt/cast/in.go
Normal file
158
cl/_testrt/cast/in.go
Normal file
@@ -0,0 +1,158 @@
|
||||
package main
|
||||
|
||||
//"github.com/goplus/llgo/internal/runtime/c"
|
||||
|
||||
func main() {
|
||||
cvt64to8(0, 0)
|
||||
cvt64to8(127, 127)
|
||||
cvt64to8(128, -128)
|
||||
cvt64to8(-128, -128)
|
||||
cvt64to8(-129, 127)
|
||||
cvt64to8(256, 0)
|
||||
|
||||
cvt64to8U(0, 0)
|
||||
cvt64to8U(255, 255)
|
||||
cvt64to8U(256, 0)
|
||||
cvt64to8U(257, 1)
|
||||
cvt64to8U(-1, 255)
|
||||
|
||||
cvt32Fto8(0.1, 0)
|
||||
cvt32Fto8(127.1, 127)
|
||||
cvt32Fto8(128.1, -128)
|
||||
cvt32Fto8(-128.1, -128)
|
||||
cvt32Fto8(-129.1, 127)
|
||||
cvt32Fto8(256.1, 0)
|
||||
|
||||
cvt32Fto8U(0, 0)
|
||||
cvt32Fto8U(255, 255)
|
||||
cvt32Fto8U(256, 0)
|
||||
cvt32Fto8U(257, 1)
|
||||
cvt32Fto8U(-1, 255)
|
||||
|
||||
// MaxInt32 = 1<<31 - 1 // 2147483647
|
||||
// MinInt32 = -1 << 31 // -2147483648
|
||||
cvt32Fto32(0, 0)
|
||||
cvt32Fto32(1.5, 1)
|
||||
cvt32Fto32(1147483647.1, 1147483648)
|
||||
cvt32Fto32(2147483647.1, -2147483648)
|
||||
cvt32Fto32(4147483647.1, -2147483648)
|
||||
cvt32Fto32(-2147483648.1, -2147483648)
|
||||
cvt32Fto32(-2147482648.1, -2147482624)
|
||||
|
||||
// MaxUint32 = 1<<32 - 1 // 4294967295
|
||||
cvt32Fto32U(0, 0)
|
||||
cvt32Fto32U(1.5, 1)
|
||||
cvt32Fto32U(4294967295.1, 0)
|
||||
cvt32Fto32U(5294967295.1, 1000000000)
|
||||
cvt32Fto32U(-4294967295.1, 0)
|
||||
cvt32Fto32U(-1294967295.1, 3000000000)
|
||||
cvt32Fto32U(-1.1, 4294967295)
|
||||
|
||||
// MaxFloat32 = 0x1p127 * (1 + (1 - 0x1p-23)) // 3.40282346638528859811704183484516925440e+38
|
||||
// SmallestNonzeroFloat32 = 0x1p-126 * 0x1p-23 // 1.401298464324817070923729583289916131280e-45
|
||||
// MaxFloat64 = 0x1p1023 * (1 + (1 - 0x1p-52)) // 1.79769313486231570814527423731704356798070e+308
|
||||
// SmallestNonzeroFloat64 = 0x1p-1022 * 0x1p-52 // 4.9406564584124654417656879286822137236505980e-324
|
||||
|
||||
cvt32Fto64F(0, 0)
|
||||
cvt32Fto64F(1.5, 1.5)
|
||||
cvt32Fto64F(1e10, 1e10)
|
||||
cvt32Fto64F(-1e10, -1e10)
|
||||
|
||||
cvt64Fto32F(0, 0)
|
||||
cvt64Fto32F(1.5, 1.5)
|
||||
cvt64Fto32F(1e10, 1e10)
|
||||
cvt64Fto32F(-1e10, -1e10)
|
||||
|
||||
// MaxInt64 = 1<<63 - 1 // 9223372036854775807
|
||||
// MinInt64 = -1 << 63 // -9223372036854775808
|
||||
cvt64to64F(0, 0)
|
||||
cvt64to64F(1e10, 1e10)
|
||||
cvt64to64F(9223372036854775807, 9223372036854775807)
|
||||
cvt64to64F(-9223372036854775807, -9223372036854775807)
|
||||
|
||||
// MaxUint64 = 1<<64 - 1 // 18446744073709551615
|
||||
cvt64Uto64F(0, 0)
|
||||
cvt64Uto64F(1e10, 1e10)
|
||||
cvt64Uto64F(9223372036854775807, 9223372036854775807)
|
||||
cvt64Uto64F(18446744073709551615, 18446744073709551615)
|
||||
|
||||
cvt32to64(0, 0)
|
||||
cvt32to64(2147483647, 2147483647)
|
||||
|
||||
cvtUinptr(1024, 1024)
|
||||
}
|
||||
|
||||
func cvtUinptr(a int32, b uintptr) {
|
||||
if uintptr(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
if int32(b) != a {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
func cvt32to64(a int32, b int64) {
|
||||
if int64(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
func cvt64to64F(a int64, b float64) {
|
||||
if float64(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
func cvt64Uto64F(a uint64, b float64) {
|
||||
if float64(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
func cvt64Fto32F(a float64, b float32) {
|
||||
if float32(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
func cvt32Fto64F(a float32, b float64) {
|
||||
if float64(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
func cvt32Fto32(a float32, b int32) {
|
||||
if int32(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
func cvt32Fto32U(a float32, b uint32) {
|
||||
if uint32(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
func cvt32Fto8(a float32, b int8) {
|
||||
if int8(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
func cvt32Fto8U(a float32, b uint8) {
|
||||
if uint8(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
func cvt64to8(a int64, b int8) {
|
||||
if int8(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
func cvt64to8U(a int, b uint8) {
|
||||
if uint8(a) != b {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
310
cl/_testrt/cast/out.ll
Normal file
310
cl/_testrt/cast/out.ll
Normal file
@@ -0,0 +1,310 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr }
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@0 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@1 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@2 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@3 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@4 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@5 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@6 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@7 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@8 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@9 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@10 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@11 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@12 = private unnamed_addr constant [6 x i8] c"error\00", align 1
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define void @main.cvt32Fto32(float %0, i32 %1) {
|
||||
_llgo_0:
|
||||
%2 = fptosi float %0 to i32
|
||||
%3 = icmp ne i32 %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.cvt32Fto32U(float %0, i32 %1) {
|
||||
_llgo_0:
|
||||
%2 = fptoui float %0 to i32
|
||||
%3 = icmp ne i32 %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.cvt32Fto64F(float %0, double %1) {
|
||||
_llgo_0:
|
||||
%2 = fpext float %0 to double
|
||||
%3 = fcmp one double %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.cvt32Fto8(float %0, i8 %1) {
|
||||
_llgo_0:
|
||||
%2 = fptosi float %0 to i8
|
||||
%3 = icmp ne i8 %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @3, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.cvt32Fto8U(float %0, i8 %1) {
|
||||
_llgo_0:
|
||||
%2 = fptoui float %0 to i8
|
||||
%3 = icmp ne i8 %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @4, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.cvt32to64(i32 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = sext i32 %0 to i64
|
||||
%3 = icmp ne i64 %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.cvt64Fto32F(double %0, float %1) {
|
||||
_llgo_0:
|
||||
%2 = fptrunc double %0 to float
|
||||
%3 = fcmp one float %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @6, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.cvt64Uto64F(i64 %0, double %1) {
|
||||
_llgo_0:
|
||||
%2 = uitofp i64 %0 to double
|
||||
%3 = fcmp one double %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.cvt64to64F(i64 %0, double %1) {
|
||||
_llgo_0:
|
||||
%2 = sitofp i64 %0 to double
|
||||
%3 = fcmp one double %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @8, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.cvt64to8(i64 %0, i8 %1) {
|
||||
_llgo_0:
|
||||
%2 = trunc i64 %0 to i8
|
||||
%3 = icmp ne i8 %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @9, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.cvt64to8U(i64 %0, i8 %1) {
|
||||
_llgo_0:
|
||||
%2 = trunc i64 %0 to i8
|
||||
%3 = icmp ne i8 %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @10, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main.cvtUinptr(i32 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = zext i32 %0 to i64
|
||||
%3 = icmp ne i64 %2, %1
|
||||
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%4 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @11, i64 5)
|
||||
%5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %4)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %5)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
%6 = trunc i64 %1 to i32
|
||||
%7 = icmp ne i32 %6, %0
|
||||
br i1 %7, label %_llgo_3, label %_llgo_4
|
||||
|
||||
_llgo_3: ; preds = %_llgo_2
|
||||
%8 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @12, i64 5)
|
||||
%9 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %8)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %9)
|
||||
unreachable
|
||||
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
ret void
|
||||
}
|
||||
|
||||
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()
|
||||
call void @main.cvt64to8(i64 0, i8 0)
|
||||
call void @main.cvt64to8(i64 127, i8 127)
|
||||
call void @main.cvt64to8(i64 128, i8 -128)
|
||||
call void @main.cvt64to8(i64 -128, i8 -128)
|
||||
call void @main.cvt64to8(i64 -129, i8 127)
|
||||
call void @main.cvt64to8(i64 256, i8 0)
|
||||
call void @main.cvt64to8U(i64 0, i8 0)
|
||||
call void @main.cvt64to8U(i64 255, i8 -1)
|
||||
call void @main.cvt64to8U(i64 256, i8 0)
|
||||
call void @main.cvt64to8U(i64 257, i8 1)
|
||||
call void @main.cvt64to8U(i64 -1, i8 -1)
|
||||
call void @main.cvt32Fto8(float 0x3FB99999A0000000, i8 0)
|
||||
call void @main.cvt32Fto8(float 0x405FC66660000000, i8 127)
|
||||
call void @main.cvt32Fto8(float 0x4060033340000000, i8 -128)
|
||||
call void @main.cvt32Fto8(float 0xC060033340000000, i8 -128)
|
||||
call void @main.cvt32Fto8(float 0xC060233340000000, i8 127)
|
||||
call void @main.cvt32Fto8(float 0x40700199A0000000, i8 0)
|
||||
call void @main.cvt32Fto8U(float 0.000000e+00, i8 0)
|
||||
call void @main.cvt32Fto8U(float 2.550000e+02, i8 -1)
|
||||
call void @main.cvt32Fto8U(float 2.560000e+02, i8 0)
|
||||
call void @main.cvt32Fto8U(float 2.570000e+02, i8 1)
|
||||
call void @main.cvt32Fto8U(float -1.000000e+00, i8 -1)
|
||||
call void @main.cvt32Fto32(float 0.000000e+00, i32 0)
|
||||
call void @main.cvt32Fto32(float 1.500000e+00, i32 1)
|
||||
call void @main.cvt32Fto32(float 0x41D1194D80000000, i32 1147483648)
|
||||
call void @main.cvt32Fto32(float 0x41E0000000000000, i32 -2147483648)
|
||||
call void @main.cvt32Fto32(float 0x41EEE6B280000000, i32 -2147483648)
|
||||
call void @main.cvt32Fto32(float 0xC1E0000000000000, i32 -2147483648)
|
||||
call void @main.cvt32Fto32(float 0xC1DFFFFF00000000, i32 -2147482624)
|
||||
call void @main.cvt32Fto32U(float 0.000000e+00, i32 0)
|
||||
call void @main.cvt32Fto32U(float 1.500000e+00, i32 1)
|
||||
call void @main.cvt32Fto32U(float 0x41F0000000000000, i32 0)
|
||||
call void @main.cvt32Fto32U(float 0x41F3B9ACA0000000, i32 1000000000)
|
||||
call void @main.cvt32Fto32U(float 0xC1F0000000000000, i32 0)
|
||||
call void @main.cvt32Fto32U(float 0xC1D34BE880000000, i32 -1294967296)
|
||||
call void @main.cvt32Fto32U(float 0xBFF19999A0000000, i32 -1)
|
||||
call void @main.cvt32Fto64F(float 0.000000e+00, double 0.000000e+00)
|
||||
call void @main.cvt32Fto64F(float 1.500000e+00, double 1.500000e+00)
|
||||
call void @main.cvt32Fto64F(float 1.000000e+10, double 1.000000e+10)
|
||||
call void @main.cvt32Fto64F(float -1.000000e+10, double -1.000000e+10)
|
||||
call void @main.cvt64Fto32F(double 0.000000e+00, float 0.000000e+00)
|
||||
call void @main.cvt64Fto32F(double 1.500000e+00, float 1.500000e+00)
|
||||
call void @main.cvt64Fto32F(double 1.000000e+10, float 1.000000e+10)
|
||||
call void @main.cvt64Fto32F(double -1.000000e+10, float -1.000000e+10)
|
||||
call void @main.cvt64to64F(i64 0, double 0.000000e+00)
|
||||
call void @main.cvt64to64F(i64 10000000000, double 1.000000e+10)
|
||||
call void @main.cvt64to64F(i64 9223372036854775807, double 0x43E0000000000000)
|
||||
call void @main.cvt64to64F(i64 -9223372036854775807, double 0xC3E0000000000000)
|
||||
call void @main.cvt64Uto64F(i64 0, double 0.000000e+00)
|
||||
call void @main.cvt64Uto64F(i64 10000000000, double 1.000000e+10)
|
||||
call void @main.cvt64Uto64F(i64 9223372036854775807, double 0x43E0000000000000)
|
||||
call void @main.cvt64Uto64F(i64 -1, double 0x43F0000000000000)
|
||||
call void @main.cvt32to64(i32 0, i64 0)
|
||||
call void @main.cvt32to64(i32 2147483647, i64 2147483647)
|
||||
call void @main.cvtUinptr(i32 1024, i64 1024)
|
||||
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.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
18
cl/_testrt/closure/in.go
Normal file
18
cl/_testrt/closure/in.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
func(n1, n2 int) {
|
||||
c.Printf(c.Str("%d %d\n"), n1, n2)
|
||||
}(100, 200)
|
||||
fn1 := func(n1, n2 int) {
|
||||
c.Printf(c.Str("%d %d\n"), n1, n2)
|
||||
}
|
||||
fn2 := func() {
|
||||
fn1(100, 200)
|
||||
}
|
||||
fn2()
|
||||
}
|
||||
88
cl/_testrt/closure/out.ll
Normal file
88
cl/_testrt/closure/out.ll
Normal file
@@ -0,0 +1,88 @@
|
||||
; 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 [7 x i8] c"%d %d\0A\00", align 1
|
||||
@1 = private unnamed_addr constant [7 x i8] c"%d %d\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()
|
||||
call void @"main.main$1"(i64 100, i64 200)
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16)
|
||||
%3 = alloca { ptr, ptr }, align 8
|
||||
%4 = getelementptr inbounds { ptr, ptr }, ptr %3, i32 0, i32 0
|
||||
store ptr @"__llgo_stub.main.main$2", ptr %4, align 8
|
||||
%5 = getelementptr inbounds { ptr, ptr }, ptr %3, i32 0, i32 1
|
||||
store ptr null, ptr %5, align 8
|
||||
%6 = load { ptr, ptr }, ptr %3, align 8
|
||||
store { ptr, ptr } %6, ptr %2, align 8
|
||||
%7 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
|
||||
%8 = getelementptr inbounds { ptr }, ptr %7, i32 0, i32 0
|
||||
store ptr %2, ptr %8, align 8
|
||||
%9 = alloca { ptr, ptr }, align 8
|
||||
%10 = getelementptr inbounds { ptr, ptr }, ptr %9, i32 0, i32 0
|
||||
store ptr @"main.main$3", ptr %10, align 8
|
||||
%11 = getelementptr inbounds { ptr, ptr }, ptr %9, i32 0, i32 1
|
||||
store ptr %7, ptr %11, align 8
|
||||
%12 = load { ptr, ptr }, ptr %9, align 8
|
||||
%13 = extractvalue { ptr, ptr } %12, 1
|
||||
%14 = extractvalue { ptr, ptr } %12, 0
|
||||
call void %14(ptr %13)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
define void @"main.main$1"(i64 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = call i32 (ptr, ...) @printf(ptr @0, i64 %0, i64 %1)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
define void @"main.main$2"(i64 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = call i32 (ptr, ...) @printf(ptr @1, i64 %0, i64 %1)
|
||||
ret void
|
||||
}
|
||||
|
||||
define linkonce void @"__llgo_stub.main.main$2"(ptr %0, i64 %1, i64 %2) {
|
||||
_llgo_0:
|
||||
tail call void @"main.main$2"(i64 %1, i64 %2)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"main.main$3"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { ptr }, ptr %0, align 8
|
||||
%2 = extractvalue { ptr } %1, 0
|
||||
%3 = load { ptr, ptr }, ptr %2, align 8
|
||||
%4 = extractvalue { ptr, ptr } %3, 1
|
||||
%5 = extractvalue { ptr, ptr } %3, 0
|
||||
call void %5(ptr %4, i64 100, i64 200)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
21
cl/_testrt/concat/in.go
Normal file
21
cl/_testrt/concat/in.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
func concat(args ...string) (ret string) {
|
||||
for _, v := range args {
|
||||
ret += v
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func info(s string) string {
|
||||
return "" + s + "..."
|
||||
}
|
||||
|
||||
func main() {
|
||||
result := concat("Hello", " ", "World")
|
||||
c.Fprintf(c.Stderr, c.Str("Hi, %s\n"), c.AllocaCStr(result))
|
||||
}
|
||||
119
cl/_testrt/concat/out.ll
Normal file
119
cl/_testrt/concat/out.ll
Normal file
@@ -0,0 +1,119 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@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_argv = global ptr null
|
||||
@3 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1
|
||||
@4 = private unnamed_addr constant [2 x i8] c" \00", align 1
|
||||
@5 = private unnamed_addr constant [6 x i8] c"World\00", align 1
|
||||
@__stderrp = external global ptr
|
||||
@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) {
|
||||
_llgo_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)
|
||||
%3 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 0
|
||||
%4 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %2, 1
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%5 = phi ptr [ %3, %_llgo_0 ], [ %19, %_llgo_2 ]
|
||||
%6 = phi i64 [ %4, %_llgo_0 ], [ %20, %_llgo_2 ]
|
||||
%7 = phi i64 [ -1, %_llgo_0 ], [ %12, %_llgo_2 ]
|
||||
%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
|
||||
store ptr %5, ptr %9, align 8
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %8, i32 0, i32 1
|
||||
store i64 %6, ptr %10, align 4
|
||||
%11 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %8, align 8
|
||||
%12 = add i64 %7, 1
|
||||
%13 = icmp slt i64 %12, %1
|
||||
br i1 %13, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%14 = icmp slt i64 %12, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %14)
|
||||
%15 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i64 %12
|
||||
%17 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %16, align 8
|
||||
%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
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
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() {
|
||||
_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 ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48)
|
||||
%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 @3, i64 5)
|
||||
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
|
||||
%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
|
||||
%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 @5, i64 5)
|
||||
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)
|
||||
%10 = call %"github.com/goplus/llgo/internal/runtime.String" @main.concat(%"github.com/goplus/llgo/internal/runtime.Slice" %9)
|
||||
%11 = load ptr, ptr @__stderrp, align 8
|
||||
%12 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %10, 1
|
||||
%13 = add i64 %12, 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)
|
||||
%16 = call i32 (ptr, ptr, ...) @fprintf(ptr %11, ptr @6, ptr %15)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
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.NewString"(ptr, i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
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 ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr, %"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare i32 @fprintf(ptr, ptr, ...)
|
||||
@@ -2,6 +2,8 @@
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
@0 = private unnamed_addr constant [14 x i8] c"Hello, world\0A\00", align 1
|
||||
|
||||
define void @main.init() {
|
||||
@@ -17,14 +19,16 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
call void (ptr, ...) @printf(ptr @0)
|
||||
ret void
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @printf(ptr, ...)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare void @printf(ptr, ...)
|
||||
|
||||
19
cl/_testrt/cvar/in.go
Normal file
19
cl/_testrt/cvar/in.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import _ "unsafe"
|
||||
|
||||
//go:linkname barX _bar_x
|
||||
var barX struct {
|
||||
Arr [16]int8
|
||||
Callbacks [2]func()
|
||||
}
|
||||
|
||||
//go:linkname barY _bar_y
|
||||
var barY struct {
|
||||
Arr [16]int8
|
||||
}
|
||||
|
||||
func main() {
|
||||
_ = barX
|
||||
_ = barY
|
||||
}
|
||||
34
cl/_testrt/cvar/out.ll
Normal file
34
cl/_testrt/cvar/out.ll
Normal file
@@ -0,0 +1,34 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@_bar_x = external global ptr
|
||||
@_bar_y = external global ptr
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
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 = load { [16 x i8], [2 x ptr] }, ptr @_bar_x, align 8
|
||||
%3 = load { [16 x i8] }, ptr @_bar_y, align 1
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
16
cl/_testrt/fprintf/in.go
Normal file
16
cl/_testrt/fprintf/in.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import "unsafe"
|
||||
|
||||
//go:linkname cstr llgo.cstr
|
||||
func cstr(string) *int8
|
||||
|
||||
//go:linkname stderr __stderrp
|
||||
var stderr unsafe.Pointer
|
||||
|
||||
//go:linkname fprintf C.fprintf
|
||||
func fprintf(fp unsafe.Pointer, format *int8, __llgo_va_list ...any)
|
||||
|
||||
func main() {
|
||||
fprintf(stderr, cstr("Hello %d\n"), 100)
|
||||
}
|
||||
36
cl/_testrt/fprintf/out.ll
Normal file
36
cl/_testrt/fprintf/out.ll
Normal file
@@ -0,0 +1,36 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@__stderrp = external global ptr
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
@0 = private unnamed_addr constant [10 x i8] c"Hello %d\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 = load ptr, ptr @__stderrp, align 8
|
||||
call void (ptr, ptr, ...) @fprintf(ptr %2, ptr @0, i64 100)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare void @fprintf(ptr, ptr, ...)
|
||||
@@ -1,11 +1,13 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/abi.Type" = type { i64, i64, i32, i8, i8, i8, i8, 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.sizeBasicTypes = global ptr null
|
||||
@main.sizeBasicTypes = global [25 x i64] undef
|
||||
@__llgo_argc = 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
|
||||
|
||||
define ptr @main.Basic(i64 %0) {
|
||||
@@ -17,7 +19,7 @@ _llgo_0:
|
||||
|
||||
define ptr @main.basicType(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 48)
|
||||
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 56)
|
||||
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 0
|
||||
%3 = getelementptr inbounds i64, ptr @main.sizeBasicTypes, i64 %0
|
||||
%4 = load i64, ptr %3, align 4
|
||||
@@ -48,21 +50,23 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
%0 = call ptr @main.Basic(i64 24)
|
||||
%1 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %0, i32 0, i32 6
|
||||
%2 = load i8, ptr %1, align 1
|
||||
%3 = sext i8 %2 to i64
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %0, i32 0, i32 0
|
||||
%5 = load i64, ptr %4, align 4
|
||||
%6 = call i32 (ptr, ...) @printf(ptr @0, i64 %3, i64 %5)
|
||||
ret void
|
||||
%2 = call ptr @main.Basic(i64 24)
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 6
|
||||
%4 = load i8, ptr %3, align 1
|
||||
%5 = sext i8 %4 to i64
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 0
|
||||
%7 = load i64, ptr %6, align 4
|
||||
%8 = call i32 (ptr, ...) @printf(ptr @0, i64 %5, i64 %7)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64)
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/abi.init"()
|
||||
|
||||
|
||||
17
cl/_testrt/gotypes/in.go
Normal file
17
cl/_testrt/gotypes/in.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
type base interface {
|
||||
f(m map[string]func())
|
||||
}
|
||||
|
||||
type bar interface {
|
||||
base
|
||||
g(c chan func())
|
||||
}
|
||||
|
||||
func foo(bar) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
foo(nil)
|
||||
}
|
||||
38
cl/_testrt/gotypes/out.ll
Normal file
38
cl/_testrt/gotypes/out.ll
Normal file
@@ -0,0 +1,38 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr }
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define void @main.foo(%"github.com/goplus/llgo/internal/runtime.iface" %0) {
|
||||
_llgo_0:
|
||||
ret void
|
||||
}
|
||||
|
||||
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()
|
||||
call void @main.foo(%"github.com/goplus/llgo/internal/runtime.iface" zeroinitializer)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
@@ -1,8 +1,10 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@main.format = global ptr null
|
||||
@main.format = global [10 x i8] undef
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
@@ -27,13 +29,15 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @main() {
|
||||
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()
|
||||
%0 = call i32 @strlen(ptr @main.format)
|
||||
call void (ptr, ...) @printf(ptr @main.format, i32 %0)
|
||||
ret void
|
||||
%2 = call i32 @strlen(ptr @main.format)
|
||||
call void (ptr, ...) @printf(ptr @main.format, i32 %2)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
25
cl/_testrt/index/in.go
Normal file
25
cl/_testrt/index/in.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/internal/runtime/c"
|
||||
|
||||
type point struct {
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := [...]point{{1, 2}, {3, 4}, {5, 6}}[2]
|
||||
c.Printf(c.Str("%d %d\n"), a.x, a.y)
|
||||
|
||||
b := [...][2]int{[2]int{1, 2}, [2]int{3, 4}}[1]
|
||||
c.Printf(c.Str("%d %d\n"), b[0], b[1])
|
||||
|
||||
var i int = 2
|
||||
n := [...]int{1, 2, 3, 4, 5}[i]
|
||||
c.Printf(c.Str("%d\n"), n)
|
||||
c.Printf(c.Str("%d\n"), [...]int{1, 2, 3, 4, 5}[i])
|
||||
|
||||
s := "123456"
|
||||
c.Printf(c.Str("%c\n"), s[i])
|
||||
c.Printf(c.Str("%c\n"), "123456"[1])
|
||||
}
|
||||
140
cl/_testrt/index/out.ll
Normal file
140
cl/_testrt/index/out.ll
Normal file
@@ -0,0 +1,140 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%main.point = type { i64, i64 }
|
||||
%"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 [7 x i8] c"%d %d\0A\00", align 1
|
||||
@1 = private unnamed_addr constant [7 x i8] c"%d %d\0A\00", align 1
|
||||
@2 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
|
||||
@3 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
|
||||
@4 = private unnamed_addr constant [4 x i8] c"%c\0A\00", align 1
|
||||
@5 = private unnamed_addr constant [7 x i8] c"123456\00", align 1
|
||||
@6 = private unnamed_addr constant [4 x i8] c"%c\0A\00", align 1
|
||||
@7 = private unnamed_addr constant [7 x i8] c"123456\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 = alloca %main.point, align 8
|
||||
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %2, i64 16)
|
||||
%4 = alloca [3 x %main.point], align 8
|
||||
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %4, i64 48)
|
||||
%6 = getelementptr inbounds %main.point, ptr %5, i64 0
|
||||
%7 = getelementptr inbounds %main.point, ptr %6, i32 0, i32 0
|
||||
%8 = getelementptr inbounds %main.point, ptr %6, i32 0, i32 1
|
||||
%9 = getelementptr inbounds %main.point, ptr %5, i64 1
|
||||
%10 = getelementptr inbounds %main.point, ptr %9, i32 0, i32 0
|
||||
%11 = getelementptr inbounds %main.point, ptr %9, i32 0, i32 1
|
||||
%12 = getelementptr inbounds %main.point, ptr %5, i64 2
|
||||
%13 = getelementptr inbounds %main.point, ptr %12, i32 0, i32 0
|
||||
%14 = getelementptr inbounds %main.point, ptr %12, i32 0, i32 1
|
||||
store i64 1, ptr %7, align 4
|
||||
store i64 2, ptr %8, align 4
|
||||
store i64 3, ptr %10, align 4
|
||||
store i64 4, ptr %11, align 4
|
||||
store i64 5, ptr %13, align 4
|
||||
store i64 6, ptr %14, align 4
|
||||
%15 = load [3 x %main.point], ptr %5, align 4
|
||||
%16 = getelementptr inbounds %main.point, ptr %5, i64 2
|
||||
%17 = load %main.point, ptr %16, align 4
|
||||
store %main.point %17, ptr %3, align 4
|
||||
%18 = getelementptr inbounds %main.point, ptr %3, i32 0, i32 0
|
||||
%19 = load i64, ptr %18, align 4
|
||||
%20 = getelementptr inbounds %main.point, ptr %3, i32 0, i32 1
|
||||
%21 = load i64, ptr %20, align 4
|
||||
%22 = call i32 (ptr, ...) @printf(ptr @0, i64 %19, i64 %21)
|
||||
%23 = alloca [2 x i64], align 8
|
||||
%24 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %23, i64 16)
|
||||
%25 = alloca [2 x [2 x i64]], align 8
|
||||
%26 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %25, i64 32)
|
||||
%27 = getelementptr inbounds [2 x i64], ptr %26, i64 0
|
||||
%28 = getelementptr inbounds i64, ptr %27, i64 0
|
||||
%29 = getelementptr inbounds i64, ptr %27, i64 1
|
||||
%30 = getelementptr inbounds [2 x i64], ptr %26, i64 1
|
||||
%31 = getelementptr inbounds i64, ptr %30, i64 0
|
||||
%32 = getelementptr inbounds i64, ptr %30, i64 1
|
||||
store i64 1, ptr %28, align 4
|
||||
store i64 2, ptr %29, align 4
|
||||
store i64 3, ptr %31, align 4
|
||||
store i64 4, ptr %32, align 4
|
||||
%33 = load [2 x [2 x i64]], ptr %26, align 4
|
||||
%34 = getelementptr inbounds [2 x i64], ptr %26, i64 1
|
||||
%35 = load [2 x i64], ptr %34, align 4
|
||||
store [2 x i64] %35, ptr %24, align 4
|
||||
%36 = getelementptr inbounds i64, ptr %24, i64 0
|
||||
%37 = load i64, ptr %36, align 4
|
||||
%38 = getelementptr inbounds i64, ptr %24, i64 1
|
||||
%39 = load i64, ptr %38, align 4
|
||||
%40 = call i32 (ptr, ...) @printf(ptr @1, i64 %37, i64 %39)
|
||||
%41 = alloca [5 x i64], align 8
|
||||
%42 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %41, i64 40)
|
||||
%43 = getelementptr inbounds i64, ptr %42, i64 0
|
||||
%44 = getelementptr inbounds i64, ptr %42, i64 1
|
||||
%45 = getelementptr inbounds i64, ptr %42, i64 2
|
||||
%46 = getelementptr inbounds i64, ptr %42, i64 3
|
||||
%47 = getelementptr inbounds i64, ptr %42, i64 4
|
||||
store i64 1, ptr %43, align 4
|
||||
store i64 2, ptr %44, align 4
|
||||
store i64 3, ptr %45, align 4
|
||||
store i64 4, ptr %46, align 4
|
||||
store i64 5, ptr %47, align 4
|
||||
%48 = load [5 x i64], ptr %42, align 4
|
||||
%49 = getelementptr inbounds i64, ptr %42, i64 2
|
||||
%50 = load i64, ptr %49, align 4
|
||||
%51 = call i32 (ptr, ...) @printf(ptr @2, i64 %50)
|
||||
%52 = alloca [5 x i64], align 8
|
||||
%53 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %52, i64 40)
|
||||
%54 = getelementptr inbounds i64, ptr %53, i64 0
|
||||
%55 = getelementptr inbounds i64, ptr %53, i64 1
|
||||
%56 = getelementptr inbounds i64, ptr %53, i64 2
|
||||
%57 = getelementptr inbounds i64, ptr %53, i64 3
|
||||
%58 = getelementptr inbounds i64, ptr %53, i64 4
|
||||
store i64 1, ptr %54, align 4
|
||||
store i64 2, ptr %55, align 4
|
||||
store i64 3, ptr %56, align 4
|
||||
store i64 4, ptr %57, align 4
|
||||
store i64 5, ptr %58, align 4
|
||||
%59 = load [5 x i64], ptr %53, align 4
|
||||
%60 = getelementptr inbounds i64, ptr %53, i64 2
|
||||
%61 = load i64, ptr %60, align 4
|
||||
%62 = call i32 (ptr, ...) @printf(ptr @3, i64 %61)
|
||||
%63 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 6)
|
||||
%64 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %63, 0
|
||||
%65 = getelementptr inbounds i8, ptr %64, i64 2
|
||||
%66 = load i8, ptr %65, align 1
|
||||
%67 = call i32 (ptr, ...) @printf(ptr @4, i8 %66)
|
||||
%68 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 6)
|
||||
%69 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %68, 0
|
||||
%70 = getelementptr inbounds i8, ptr %69, i64 1
|
||||
%71 = load i8, ptr %70, align 1
|
||||
%72 = call i32 (ptr, ...) @printf(ptr @6, i8 %71)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)
|
||||
42
cl/_testrt/intgen/in.go
Normal file
42
cl/_testrt/intgen/in.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
type generator struct {
|
||||
val c.Int
|
||||
}
|
||||
|
||||
func (g *generator) next() c.Int {
|
||||
g.val++
|
||||
return g.val
|
||||
}
|
||||
|
||||
func genInts(n int, gen func() c.Int) []c.Int {
|
||||
a := make([]c.Int, n)
|
||||
for i := range a {
|
||||
a[i] = gen()
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func main() {
|
||||
for _, v := range genInts(5, c.Rand) {
|
||||
c.Printf(c.Str("%d\n"), v)
|
||||
}
|
||||
|
||||
initVal := c.Int(1)
|
||||
ints := genInts(5, func() c.Int {
|
||||
initVal *= 2
|
||||
return initVal
|
||||
})
|
||||
for _, v := range ints {
|
||||
c.Printf(c.Str("%d\n"), v)
|
||||
}
|
||||
|
||||
g := &generator{val: 1}
|
||||
for _, v := range genInts(5, g.next) {
|
||||
c.Printf(c.Str("%d\n"), v)
|
||||
}
|
||||
}
|
||||
205
cl/_testrt/intgen/out.ll
Normal file
205
cl/_testrt/intgen/out.ll
Normal file
@@ -0,0 +1,205 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||
%main.generator = type { i32 }
|
||||
|
||||
@"main.init$guard" = global ptr null
|
||||
@__llgo_argc = global ptr null
|
||||
@__llgo_argv = global ptr null
|
||||
@0 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
|
||||
@1 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
|
||||
@2 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
|
||||
|
||||
define %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 %0, { ptr, ptr } %1) {
|
||||
_llgo_0:
|
||||
%2 = mul i64 %0, 4
|
||||
%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)
|
||||
%5 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %4, 1
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%6 = phi i64 [ -1, %_llgo_0 ], [ %7, %_llgo_2 ]
|
||||
%7 = add i64 %6, 1
|
||||
%8 = icmp slt i64 %7, %5
|
||||
br i1 %8, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%9 = extractvalue { ptr, ptr } %1, 1
|
||||
%10 = extractvalue { ptr, ptr } %1, 0
|
||||
%11 = call i32 %10(ptr %9)
|
||||
%12 = icmp slt i64 %7, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %12)
|
||||
%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
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
ret %"github.com/goplus/llgo/internal/runtime.Slice" %4
|
||||
}
|
||||
|
||||
define i32 @"(*main.generator).next"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = getelementptr inbounds %main.generator, ptr %0, i32 0, i32 0
|
||||
%2 = load i32, ptr %1, align 4
|
||||
%3 = add i32 %2, 1
|
||||
%4 = getelementptr inbounds %main.generator, ptr %0, i32 0, i32 0
|
||||
store i32 %3, ptr %4, align 4
|
||||
%5 = getelementptr inbounds %main.generator, ptr %0, i32 0, i32 0
|
||||
%6 = load i32, ptr %5, align 4
|
||||
ret i32 %6
|
||||
}
|
||||
|
||||
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 = alloca { ptr, ptr }, align 8
|
||||
%3 = getelementptr inbounds { ptr, ptr }, ptr %2, i32 0, i32 0
|
||||
store ptr @__llgo_stub.rand, ptr %3, align 8
|
||||
%4 = getelementptr inbounds { ptr, ptr }, ptr %2, i32 0, i32 1
|
||||
store ptr null, ptr %4, 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)
|
||||
%7 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, 1
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%8 = phi i64 [ -1, %_llgo_0 ], [ %9, %_llgo_2 ]
|
||||
%9 = add i64 %8, 1
|
||||
%10 = icmp slt i64 %9, %7
|
||||
br i1 %10, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%11 = icmp slt i64 %9, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %11)
|
||||
%12 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, 0
|
||||
%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
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
%16 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
|
||||
store i32 1, ptr %16, align 4
|
||||
%17 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
|
||||
%18 = getelementptr inbounds { ptr }, ptr %17, i32 0, i32 0
|
||||
store ptr %16, ptr %18, align 8
|
||||
%19 = alloca { ptr, ptr }, align 8
|
||||
%20 = getelementptr inbounds { ptr, ptr }, ptr %19, i32 0, i32 0
|
||||
store ptr @"main.main$1", ptr %20, align 8
|
||||
%21 = getelementptr inbounds { ptr, ptr }, ptr %19, i32 0, i32 1
|
||||
store ptr %17, ptr %21, align 8
|
||||
%22 = load { ptr, ptr }, ptr %19, align 8
|
||||
%23 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %22)
|
||||
%24 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %23, 1
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_5, %_llgo_3
|
||||
%25 = phi i64 [ -1, %_llgo_3 ], [ %26, %_llgo_5 ]
|
||||
%26 = add i64 %25, 1
|
||||
%27 = icmp slt i64 %26, %24
|
||||
br i1 %27, label %_llgo_5, label %_llgo_6
|
||||
|
||||
_llgo_5: ; preds = %_llgo_4
|
||||
%28 = icmp slt i64 %26, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %28)
|
||||
%29 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %23, 0
|
||||
%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
|
||||
|
||||
_llgo_6: ; preds = %_llgo_4
|
||||
%33 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
|
||||
%34 = getelementptr inbounds %main.generator, ptr %33, i32 0, i32 0
|
||||
store i32 1, ptr %34, align 4
|
||||
%35 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
|
||||
%36 = getelementptr inbounds { ptr }, ptr %35, i32 0, i32 0
|
||||
store ptr %33, ptr %36, align 8
|
||||
%37 = alloca { ptr, ptr }, align 8
|
||||
%38 = getelementptr inbounds { ptr, ptr }, ptr %37, i32 0, i32 0
|
||||
store ptr @"main.next$bound", ptr %38, align 8
|
||||
%39 = getelementptr inbounds { ptr, ptr }, ptr %37, i32 0, i32 1
|
||||
store ptr %35, ptr %39, align 8
|
||||
%40 = load { ptr, ptr }, ptr %37, align 8
|
||||
%41 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %40)
|
||||
%42 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %41, 1
|
||||
br label %_llgo_7
|
||||
|
||||
_llgo_7: ; preds = %_llgo_8, %_llgo_6
|
||||
%43 = phi i64 [ -1, %_llgo_6 ], [ %44, %_llgo_8 ]
|
||||
%44 = add i64 %43, 1
|
||||
%45 = icmp slt i64 %44, %42
|
||||
br i1 %45, label %_llgo_8, label %_llgo_9
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7
|
||||
%46 = icmp slt i64 %44, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %46)
|
||||
%47 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %41, 0
|
||||
%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
|
||||
|
||||
_llgo_9: ; preds = %_llgo_7
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
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 void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare i32 @rand()
|
||||
|
||||
define linkonce i32 @__llgo_stub.rand(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = tail call i32 @rand()
|
||||
ret i32 %1
|
||||
}
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
define i32 @"main.main$1"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { ptr }, ptr %0, align 8
|
||||
%2 = extractvalue { ptr } %1, 0
|
||||
%3 = load i32, ptr %2, align 4
|
||||
%4 = mul i32 %3, 2
|
||||
%5 = extractvalue { ptr } %1, 0
|
||||
store i32 %4, ptr %5, align 4
|
||||
%6 = extractvalue { ptr } %1, 0
|
||||
%7 = load i32, ptr %6, align 4
|
||||
ret i32 %7
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64)
|
||||
|
||||
define i32 @"main.next$bound"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { ptr }, ptr %0, align 8
|
||||
%2 = extractvalue { ptr } %1, 0
|
||||
%3 = call i32 @"(*main.generator).next"(ptr %2)
|
||||
ret i32 %3
|
||||
}
|
||||
15
cl/_testrt/linkname/in.go
Normal file
15
cl/_testrt/linkname/in.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
//go:linkname print github.com/goplus/llgo/cl/internal/linktarget.F
|
||||
func print(a, b, c, d *c.Char)
|
||||
|
||||
func main() {
|
||||
print(c.Str("a"), c.Str("b"), c.Str("c"), c.Str("d"))
|
||||
print(c.Str("1"), c.Str("2"), c.Str("3"), c.Str("4"))
|
||||
}
|
||||
42
cl/_testrt/linkname/out.ll
Normal file
42
cl/_testrt/linkname/out.ll
Normal file
@@ -0,0 +1,42 @@
|
||||
; 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 [2 x i8] c"a\00", align 1
|
||||
@1 = private unnamed_addr constant [2 x i8] c"b\00", align 1
|
||||
@2 = private unnamed_addr constant [2 x i8] c"c\00", align 1
|
||||
@3 = private unnamed_addr constant [2 x i8] c"d\00", align 1
|
||||
@4 = private unnamed_addr constant [2 x i8] c"1\00", align 1
|
||||
@5 = private unnamed_addr constant [2 x i8] c"2\00", align 1
|
||||
@6 = private unnamed_addr constant [2 x i8] c"3\00", align 1
|
||||
@7 = private unnamed_addr constant [2 x i8] c"4\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()
|
||||
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)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/cl/internal/linktarget.F"(ptr, ptr, ptr, ptr)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user