Compare commits
144 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df39b66e11 | ||
|
|
adeb5de19f | ||
|
|
26312e0c0e | ||
|
|
cd6d4021b1 | ||
|
|
24d345a970 | ||
|
|
b4fd4a0c38 | ||
|
|
451e695006 | ||
|
|
26b771f9f9 | ||
|
|
0679aedb7e | ||
|
|
bfa4e08a4e | ||
|
|
c1185a34aa | ||
|
|
be0ce57375 | ||
|
|
b204b90ffc | ||
|
|
364b6938a5 | ||
|
|
e188925d2b | ||
|
|
10a47cdbbb | ||
|
|
67014ae4f8 | ||
|
|
b93fc3f028 | ||
|
|
b6e5980510 | ||
|
|
79e8921f76 | ||
|
|
34fe3ca4fc | ||
|
|
f26311c60e | ||
|
|
43f9907af7 | ||
|
|
0e6f5d154e | ||
|
|
7042dd8447 | ||
|
|
05031e0979 | ||
|
|
28b3f6780c | ||
|
|
f8335c6df9 | ||
|
|
9dcdc1f8f3 | ||
|
|
9ae7d4f2bf | ||
|
|
c158169bdf | ||
|
|
e4c1285eaf | ||
|
|
02a5375503 | ||
|
|
32883b4e18 | ||
|
|
6d585e88a4 | ||
|
|
73570b5628 | ||
|
|
e7fcb068d9 | ||
|
|
a137a70278 | ||
|
|
72113991a8 | ||
|
|
a04fb8e7de | ||
|
|
ca2f30cd61 | ||
|
|
ebfad05e3f | ||
|
|
f54ea9d978 | ||
|
|
d4c84cee19 | ||
|
|
4da59cdc97 | ||
|
|
d4e7eb5888 | ||
|
|
f8b0a7105b | ||
|
|
aecde91d33 | ||
|
|
870dde232a | ||
|
|
f7d7f81c49 | ||
|
|
1f04c61482 | ||
|
|
5d957a6b7c | ||
|
|
94f61b0a0c | ||
|
|
de6535b722 | ||
|
|
6dd18e4328 | ||
|
|
c46e4453c7 | ||
|
|
2e6312ec03 | ||
|
|
1566a834e1 | ||
|
|
607deaa3c4 | ||
|
|
686186d5ba | ||
|
|
0c1ef72285 | ||
|
|
d6bd12cfcd | ||
|
|
4a1712f4cd | ||
|
|
b4e298230d | ||
|
|
6cb42a4251 | ||
|
|
3ead4b4d4b | ||
|
|
3c0e321538 | ||
|
|
1f67434c8c | ||
|
|
6058b9851c | ||
|
|
c586319978 | ||
|
|
0591fe0e8b | ||
|
|
dabe3b17e6 | ||
|
|
fbf50d45cb | ||
|
|
d59075e897 | ||
|
|
2b491179f7 | ||
|
|
a62d17b1b1 | ||
|
|
2431758218 | ||
|
|
b94586fdf4 | ||
|
|
a6b83d77bd | ||
|
|
43c55b36c8 | ||
|
|
24c7928c4b | ||
|
|
8c876c302a | ||
|
|
778a4373ae | ||
|
|
7a15cf1157 | ||
|
|
54e3210d7e | ||
|
|
a3197c12a8 | ||
|
|
e7de841939 | ||
|
|
29ba00f370 | ||
|
|
e35d70f338 | ||
|
|
0271c65ca2 | ||
|
|
e604524301 | ||
|
|
298831d987 | ||
|
|
3b2e97a729 | ||
|
|
edaba44c87 | ||
|
|
dc2dc910e8 | ||
|
|
96bf260ce9 | ||
|
|
115ea4ccbb | ||
|
|
3fb400beb4 | ||
|
|
6442279a44 | ||
|
|
592500cb0c | ||
|
|
98f3e45c0a | ||
|
|
e365196ee3 | ||
|
|
f656499c23 | ||
|
|
180c019d2e | ||
|
|
7db50921bc | ||
|
|
257b3f3ee6 | ||
|
|
f7c69b6baf | ||
|
|
89a3b84ea1 | ||
|
|
bec29f99e6 | ||
|
|
72274bda82 | ||
|
|
04b62a62cb | ||
|
|
ab7329d3eb | ||
|
|
a819796ce2 | ||
|
|
8c6cdcc97e | ||
|
|
bf0148e047 | ||
|
|
bcf44b8ab2 | ||
|
|
ebc9711309 | ||
|
|
4097f90938 | ||
|
|
d73f77affc | ||
|
|
b4794dc541 | ||
|
|
5ee156057e | ||
|
|
68a63bb280 | ||
|
|
815677863f | ||
|
|
df2f13c9b6 | ||
|
|
3984037c98 | ||
|
|
9c8570b37d | ||
|
|
f7cddb81df | ||
|
|
dc1fbbf796 | ||
|
|
7b7b4e5f22 | ||
|
|
8c9b0285e4 | ||
|
|
3ff5caef94 | ||
|
|
4a3446a0a5 | ||
|
|
6f6d9b39ba | ||
|
|
7d2f68c5e4 | ||
|
|
5416e92dbf | ||
|
|
340b5bd165 | ||
|
|
fbd15a81b4 | ||
|
|
039d0abce2 | ||
|
|
aefb65b1b8 | ||
|
|
f7c322c311 | ||
|
|
b5507f79e4 | ||
|
|
a2703ce51b | ||
|
|
d48b12aa09 | ||
|
|
452c1fbfd4 |
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
@@ -32,10 +32,10 @@ jobs:
|
||||
- name: Install LLVM ${{ matrix.llvm }} and libgc-dev
|
||||
if: startsWith(matrix.os, 'ubuntu')
|
||||
run: |
|
||||
echo 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-${{ matrix.llvm }} main' | sudo tee /etc/apt/sources.list.d/llvm.list
|
||||
echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-${{ matrix.llvm }} 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
|
||||
sudo apt-get install --no-install-recommends clang-${{ matrix.llvm }} llvm-${{ matrix.llvm }}-dev libgc-dev
|
||||
sudo apt-get install -y llvm-${{ matrix.llvm }}-dev clang-${{ matrix.llvm }} lld-${{ matrix.llvm }} pkg-config libgc-dev libcjson-dev libsqlite3-dev python3.11-dev
|
||||
echo /usr/lib/llvm-${{ matrix.llvm }}/bin >> $GITHUB_PATH
|
||||
|
||||
- name: Clang information
|
||||
|
||||
58
README.md
58
README.md
@@ -34,7 +34,6 @@ The `_demo` directory contains some C standard libary related demos (it start wi
|
||||
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 .
|
||||
```
|
||||
@@ -60,6 +59,8 @@ And you can import any Python library into `llgo` through a program called `llpy
|
||||
* [pytorch](https://pkg.go.dev/github.com/goplus/llgo/py/torch)
|
||||
* [matplotlib](https://pkg.go.dev/github.com/goplus/llgo/py/matplotlib)
|
||||
|
||||
Note: For third-party libraries (such as pandas and pytorch), you still need to install the library files.
|
||||
|
||||
Here is an example using the Python `math` library:
|
||||
|
||||
```go
|
||||
@@ -140,7 +141,6 @@ Note that the file name must be written in a platform-independent format, using
|
||||
Then you can run the demos:
|
||||
|
||||
```sh
|
||||
export LLGOROOT=`pwd`
|
||||
cd <demo-directory> # eg. cd _pydemo/callpy
|
||||
llgo run .
|
||||
```
|
||||
@@ -171,14 +171,13 @@ Common Go syntax is already supported. Except for the following, which needs to
|
||||
|
||||
* map (Very limited support)
|
||||
* chan (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)
|
||||
* [errors](_demo/errors/errors.go): demo to implement error interface
|
||||
* [defer](_demo/defer/defer.go): defer demo
|
||||
* [errors](_cmptest/errors/errors.go): demo to implement error interface
|
||||
* [defer](_cmptest/defer/defer.go): defer demo
|
||||
* [goroutine](_demo/goroutine/goroutine.go): goroutine demo
|
||||
|
||||
|
||||
@@ -206,10 +205,30 @@ Here are the Go packages that can be imported correctly:
|
||||
* [unicode](https://pkg.go.dev/unicode)
|
||||
* [unicode/utf8](https://pkg.go.dev/unicode/utf8)
|
||||
* [unicode/utf16](https://pkg.go.dev/unicode/utf16)
|
||||
* [math/bits](https://pkg.go.dev/math/bits)
|
||||
* [math](https://pkg.go.dev/math)
|
||||
* [math/bits](https://pkg.go.dev/math/bits)
|
||||
* [math/cmplx](https://pkg.go.dev/math/cmplx)
|
||||
* [sort](https://pkg.go.dev/sort)
|
||||
* [strconv](https://pkg.go.dev/strconv)
|
||||
* [sync/atomic](https://pkg.go.dev/sync/atomic)
|
||||
* [sync](https://pkg.go.dev/sync) (partially)
|
||||
* [syscall](https://pkg.go.dev/syscall) (partially)
|
||||
* [os](https://pkg.go.dev/os) (partially)
|
||||
* [reflect](https://pkg.go.dev/reflect) (partially)
|
||||
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [Go 1.20+](https://go.dev) (build only)
|
||||
- [LLVM 17](https://llvm.org)
|
||||
- [LLD 17](https://lld.llvm.org)
|
||||
- [Clang 17](https://clang.llvm.org)
|
||||
- [pkg-config 0.29+](https://www.freedesktop.org/wiki/Software/pkg-config/)
|
||||
- [bdwgc/libgc 8.0+](https://www.hboehm.info/gc/)
|
||||
- [cJSON 1.7+](https://github.com/DaveGamble/cJSON) (optional, for [`github.com/goplus/llgo/c/cjson`](https://pkg.go.dev/github.com/goplus/llgo/c/cjson))
|
||||
- [SQLite 3](https://www.sqlite.org) (optional, for [`github.com/goplus/llgo/c/sqlite`](https://pkg.go.dev/github.com/goplus/llgo/c/sqlite))
|
||||
- [Python 3.11+](https://www.python.org) (optional, for [`github.com/goplus/llgo/py`](https://pkg.go.dev/github.com/goplus/llgo/py))
|
||||
|
||||
## How to install
|
||||
|
||||
Follow these steps to generate the `llgo` command (its usage is the same as the `go` command):
|
||||
@@ -217,20 +236,30 @@ Follow these steps to generate the `llgo` command (its usage is the same as the
|
||||
### on macOS
|
||||
|
||||
```sh
|
||||
brew update # execute if needed
|
||||
brew install libgc
|
||||
brew install llvm@17
|
||||
brew update # execute if needed
|
||||
brew install llvm@17 pkg-config libgc
|
||||
brew install cjson sqlite python@3.12 # optional
|
||||
export PATH=$(brew --prefix llvm@17)/bin:$PATH # you may want to add this to your shell RC file, e.g. ~/.zshrc
|
||||
export CC=clang CXX=clang++ # only for go build; optional if you have other compatible compilers
|
||||
git clone https://github.com/goplus/llgo.git
|
||||
cd llgo
|
||||
export LLGOROOT="/path/to/llgo" # Replace this with the root directory of the llgo project
|
||||
go install -v ./...
|
||||
```
|
||||
|
||||
### on Linux
|
||||
### on Linux (Debian/Ubuntu)
|
||||
|
||||
```sh
|
||||
echo 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-17 main' | sudo tee /etc/apt/sources.list.d/llvm.list
|
||||
echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-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 libgc-dev
|
||||
sudo apt-get install --no-install-recommends llvm-17-dev
|
||||
sudo apt-get update # execute if needed
|
||||
sudo apt-get install -y llvm-17-dev clang-17 lld-17 pkg-config libgc-dev
|
||||
sudo apt-get install -y libcjson-dev libsqlite3-dev python3.12-dev # optional
|
||||
export PATH=/usr/lib/llvm-17/bin:$PATH # you may want to add this to your shell RC file, e.g. ~/.bashrc
|
||||
export CC=clang CXX=clang++ # only for go build; optional if you have other compatible compilers
|
||||
git clone https://github.com/goplus/llgo.git
|
||||
cd llgo
|
||||
export LLGOROOT="/path/to/llgo" # Replace this with the root directory of the llgo project
|
||||
go install -v ./...
|
||||
```
|
||||
|
||||
@@ -250,6 +279,7 @@ TODO
|
||||
How do I generate these tools?
|
||||
|
||||
```sh
|
||||
export CC=clang CXX=clang++ # only for go build; optional if you have other compatible compilers
|
||||
go install -v ./... # compile all tools except pydump
|
||||
cd chore/_xtool
|
||||
llgo install ./... # compile pydump
|
||||
|
||||
@@ -17,6 +17,5 @@ func (e *errorString) Error() string {
|
||||
|
||||
func main() {
|
||||
err := New("an error")
|
||||
println(err)
|
||||
println(err.Error())
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/_demo/interf/foo"
|
||||
"github.com/goplus/llgo/_cmptest/interf/foo"
|
||||
)
|
||||
|
||||
func Foo() any {
|
||||
13
_cmptest/reflect/reflect.go
Normal file
13
_cmptest/reflect/reflect.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import "reflect"
|
||||
|
||||
func main() {
|
||||
tyIntSlice := reflect.SliceOf(reflect.TypeOf(0))
|
||||
v := reflect.Zero(tyIntSlice)
|
||||
v = reflect.Append(v, reflect.ValueOf(1), reflect.ValueOf(2), reflect.ValueOf(3))
|
||||
for i, n := 0, v.Len(); i < n; i++ {
|
||||
item := v.Index(i)
|
||||
println(item.Int())
|
||||
}
|
||||
}
|
||||
14
_cmptest/rtype/rtype.go
Normal file
14
_cmptest/rtype/rtype.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import "reflect"
|
||||
|
||||
func main() {
|
||||
tyIntSlice := reflect.SliceOf(reflect.TypeOf(0))
|
||||
println(tyIntSlice.String())
|
||||
|
||||
v := reflect.Zero(tyIntSlice)
|
||||
println(v.Len())
|
||||
|
||||
v = reflect.ValueOf(100)
|
||||
println(v.Int())
|
||||
}
|
||||
7
_cmptest/strconv/strconv.go
Normal file
7
_cmptest/strconv/strconv.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "strconv"
|
||||
|
||||
func main() {
|
||||
println(strconv.Itoa(-123))
|
||||
}
|
||||
11
_cmptest/syscall/syscall.go
Normal file
11
_cmptest/syscall/syscall.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import "syscall"
|
||||
|
||||
func main() {
|
||||
wd, err := syscall.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
println("cwd:", wd)
|
||||
}
|
||||
24
_demo/catomic/atomic.go
Normal file
24
_demo/catomic/atomic.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c/sync/atomic"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var v int64
|
||||
|
||||
atomic.Store(&v, 100)
|
||||
println("store:", atomic.Load(&v))
|
||||
|
||||
ret := atomic.Add(&v, 1)
|
||||
println("ret:", ret, "v:", v)
|
||||
|
||||
ret, _ = atomic.CompareAndExchange(&v, 100, 102)
|
||||
println("ret:", ret, "vs 100, v:", v)
|
||||
|
||||
ret, _ = atomic.CompareAndExchange(&v, 101, 102)
|
||||
println("ret:", ret, "vs 101, v:", v)
|
||||
|
||||
ret = atomic.Sub(&v, 1)
|
||||
println("ret:", ret, "v:", v)
|
||||
}
|
||||
9
_demo/complex/cmplx.go
Normal file
9
_demo/complex/cmplx.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math/cmplx"
|
||||
)
|
||||
|
||||
func main() {
|
||||
println("abs(3+4i):", cmplx.Abs(3+4i))
|
||||
}
|
||||
38
_demo/cppintf/cppintf.go
Normal file
38
_demo/cppintf/cppintf.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/_demo/cppintf/foo"
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/math"
|
||||
)
|
||||
|
||||
type Bar struct {
|
||||
foo.Callback
|
||||
a int
|
||||
}
|
||||
|
||||
func NewBar(a int) *Bar {
|
||||
return &Bar{
|
||||
Callback: foo.Callback{
|
||||
Vptr: &foo.CallbackVtbl{
|
||||
Val: c.Func((*Bar).getA),
|
||||
Calc: c.Func((*Bar).sqrt),
|
||||
},
|
||||
},
|
||||
a: a,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Bar) getA() int {
|
||||
return p.a
|
||||
}
|
||||
|
||||
func (p *Bar) sqrt(v float64) float64 {
|
||||
return math.Sqrt(v)
|
||||
}
|
||||
|
||||
func main() {
|
||||
bar := NewBar(1)
|
||||
foo.F(&bar.Callback)
|
||||
foo.G(&bar.Callback)
|
||||
}
|
||||
15
_demo/cppintf/foo/bar/bar.cpp
Normal file
15
_demo/cppintf/foo/bar/bar.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#define interface struct
|
||||
|
||||
interface ICallback {
|
||||
virtual int val() = 0;
|
||||
virtual double calc(double v) = 0;
|
||||
};
|
||||
|
||||
extern "C" void f(ICallback* cb) {
|
||||
printf("val: %d\ncalc(2): %lf\n", cb->val(), cb->calc(2));
|
||||
}
|
||||
|
||||
void g(ICallback* cb) {
|
||||
f(cb);
|
||||
}
|
||||
25
_demo/cppintf/foo/foo.go
Normal file
25
_demo/cppintf/foo/foo.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoFiles = "bar/bar.cpp"
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
type Callback struct {
|
||||
Vptr *CallbackVtbl
|
||||
}
|
||||
|
||||
type CallbackVtbl struct {
|
||||
Val unsafe.Pointer
|
||||
Calc unsafe.Pointer
|
||||
}
|
||||
|
||||
//go:linkname F C.f
|
||||
func F(cb *Callback)
|
||||
|
||||
//go:linkname G C._Z1gP9ICallback
|
||||
func G(cb *Callback)
|
||||
BIN
_demo/cppintf/foo/llgo_autogen.lla
Normal file
BIN
_demo/cppintf/foo/llgo_autogen.lla
Normal file
Binary file not shown.
11
_demo/getcwd/getcwd.go
Normal file
11
_demo/getcwd/getcwd.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
wd := os.Getcwd(c.Alloca(os.PATH_MAX), os.PATH_MAX)
|
||||
c.Printf(c.Str("cwd: %s\n"), wd)
|
||||
}
|
||||
23
_demo/sortdemo/sort.go
Normal file
23
_demo/sortdemo/sort.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import "sort"
|
||||
|
||||
func main() {
|
||||
vals := []int{32, 58, 25, 92, 45, 78}
|
||||
sort.Ints(vals)
|
||||
for _, v := range vals {
|
||||
println(v)
|
||||
}
|
||||
|
||||
texts := []string{"apple", "banana", "cherry", "date", "elderberry", "fig"}
|
||||
sort.Slice(texts, func(i, j int) bool {
|
||||
leni, lenj := len(texts[i]), len(texts[j])
|
||||
if leni != lenj {
|
||||
return leni < lenj
|
||||
}
|
||||
return texts[i] < texts[j]
|
||||
})
|
||||
for _, v := range texts {
|
||||
println(v)
|
||||
}
|
||||
}
|
||||
17
c/bitcast/_cast/cast.c
Normal file
17
c/bitcast/_cast/cast.c
Normal file
@@ -0,0 +1,17 @@
|
||||
typedef union {
|
||||
double d;
|
||||
float f;
|
||||
long v;
|
||||
} castUnion;
|
||||
|
||||
double llgoToFloat64(long v) {
|
||||
castUnion k;
|
||||
k.v = v;
|
||||
return k.d;
|
||||
}
|
||||
|
||||
float llgoToFloat32(long v) {
|
||||
castUnion k;
|
||||
k.v = v;
|
||||
return k.f;
|
||||
}
|
||||
30
c/bitcast/bitcast.go
Normal file
30
c/bitcast/bitcast.go
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 bitcast
|
||||
|
||||
import _ "unsafe"
|
||||
|
||||
const (
|
||||
LLGoFiles = "_cast/cast.c"
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
//go:linkname ToFloat64 C.llgoToFloat64
|
||||
func ToFloat64(v uintptr) float64
|
||||
|
||||
//go:linkname ToFloat32 C.llgoToFloat32
|
||||
func ToFloat32(v uintptr) float32
|
||||
BIN
c/bitcast/llgo_autogen.lla
Normal file
BIN
c/bitcast/llgo_autogen.lla
Normal file
Binary file not shown.
80
c/c.go
80
c/c.go
@@ -26,8 +26,6 @@ const (
|
||||
|
||||
type (
|
||||
Char = int8
|
||||
Int = C.int
|
||||
Uint = C.uint
|
||||
Long = int32
|
||||
Ulong = uint32
|
||||
LongLong = int64
|
||||
@@ -38,6 +36,11 @@ type (
|
||||
FilePtr = unsafe.Pointer
|
||||
)
|
||||
|
||||
type (
|
||||
Int C.int
|
||||
Uint C.uint
|
||||
)
|
||||
|
||||
type integer interface {
|
||||
~int | ~uint | ~uintptr | ~int32 | ~uint32 | ~int64 | ~uint64
|
||||
}
|
||||
@@ -45,6 +48,9 @@ type integer interface {
|
||||
//go:linkname Str llgo.cstr
|
||||
func Str(string) *Char
|
||||
|
||||
//go:linkname Func llgo.funcAddr
|
||||
func Func(any) Pointer
|
||||
|
||||
// llgo:link Advance llgo.advance
|
||||
func Advance[PtrT any, I integer](ptr PtrT, offset I) PtrT { return ptr }
|
||||
|
||||
@@ -72,8 +78,73 @@ func Memmove(dst, src Pointer, n uintptr) Pointer
|
||||
//go:linkname Memset C.memset
|
||||
func Memset(s Pointer, c Int, n uintptr) Pointer
|
||||
|
||||
//go:linkname Memchr C.memchr
|
||||
func Memchr(s Pointer, c Int, n uintptr) Pointer
|
||||
|
||||
//go:linkname Memcmp C.memcmp
|
||||
func Memcmp(s1, s2 Pointer, n uintptr) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Strlen C.strlen
|
||||
func Strlen(s *Char) uintptr
|
||||
|
||||
//go:linkname Strcpy C.strcpy
|
||||
func Strcpy(dst, src *Char) *Char
|
||||
|
||||
//go:linkname Strncpy C.strncpy
|
||||
func Strncpy(dst, src *Char, n uintptr) *Char
|
||||
|
||||
//go:linkname Strcat C.strcat
|
||||
func Strcat(dst, src *Char) *Char
|
||||
|
||||
//go:linkname Strncat C.strncat
|
||||
func Strncat(dst, src *Char, n uintptr) *Char
|
||||
|
||||
//go:linkname Strcmp C.strcmp
|
||||
func Strcmp(s1, s2 *Char) Int
|
||||
|
||||
//go:linkname Strncmp C.strncmp
|
||||
func Strncmp(s1, s2 *Char, n uintptr) Int
|
||||
|
||||
//go:linkname Strchr C.strchr
|
||||
func Strchr(s *Char, c Int) *Char
|
||||
|
||||
//go:linkname Strrchr C.strrchr
|
||||
func Strrchr(s *Char, c Int) *Char
|
||||
|
||||
//go:linkname Strstr C.strstr
|
||||
func Strstr(s1, s2 *Char) *Char
|
||||
|
||||
//go:linkname Strdup C.strdup
|
||||
func Strdup(s *Char) *Char
|
||||
|
||||
//go:linkname Strndup C.strndup
|
||||
func Strndup(s *Char, n uintptr) *Char
|
||||
|
||||
//go:linkname Strtok C.strtok
|
||||
func Strtok(s, delim *Char) *Char
|
||||
|
||||
//go:linkname Strerror C.strerror
|
||||
func Strerror(errnum Int) *Char
|
||||
|
||||
//go:linkname Sprintf C.sprintf
|
||||
func Sprintf(s *Char, format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
//go:linkname Snprintf C.snprintf
|
||||
func Snprintf(s *Char, n uintptr, format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
//go:linkname Vsnprintf C.vsnprintf
|
||||
func Vsnprintf(s *Char, n uintptr, format *Char, ap Pointer) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// GoString converts a C string to a Go string.
|
||||
// TODO(xsw): any => int
|
||||
//
|
||||
//go:linkname GoString llgo.string
|
||||
func GoString(cstr *Char, __llgo_va_list /* n */ ...any) string
|
||||
|
||||
//go:linkname GoStringData llgo.stringData
|
||||
func GoStringData(string) *Char
|
||||
|
||||
@@ -134,11 +205,6 @@ func Fflush(fp FilePtr) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Remove C.remove
|
||||
func Remove(path *Char) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Time C.time
|
||||
func Time(*int32) int32
|
||||
|
||||
|
||||
@@ -1,26 +1,18 @@
|
||||
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
|
||||
|
||||
### on macOS (Homebrew)
|
||||
|
||||
```sh
|
||||
brew install cjson
|
||||
```
|
||||
### from source code
|
||||
|
||||
### on Linux (Debian/Ubuntu)
|
||||
|
||||
```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
|
||||
apt-get install -y libcjson-dev
|
||||
```
|
||||
|
||||
## Demos
|
||||
|
||||
151
c/math/cmplx/complex.go
Normal file
151
c/math/cmplx/complex.go
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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 cmplx
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Abs C.cabs
|
||||
func Abs(z complex128) float64
|
||||
|
||||
//go:linkname Acos C.cacos
|
||||
func Acos(z complex128) complex128
|
||||
|
||||
//go:linkname Acosh C.cacosh
|
||||
func Acosh(z complex128) complex128
|
||||
|
||||
//go:linkname Asin C.casin
|
||||
func Asin(z complex128) complex128
|
||||
|
||||
//go:linkname Asinh C.casinh
|
||||
func Asinh(z complex128) complex128
|
||||
|
||||
//go:linkname Atan C.catan
|
||||
func Atan(z complex128) complex128
|
||||
|
||||
//go:linkname Atanh C.catanh
|
||||
func Atanh(z complex128) complex128
|
||||
|
||||
//go:linkname Cos C.ccos
|
||||
func Cos(z complex128) complex128
|
||||
|
||||
//go:linkname Cosh C.ccosh
|
||||
func Cosh(z complex128) complex128
|
||||
|
||||
//go:linkname Exp C.cexp
|
||||
func Exp(z complex128) complex128
|
||||
|
||||
//go:linkname Log C.clog
|
||||
func Log(z complex128) complex128
|
||||
|
||||
//go:linkname Log10 C.clog10
|
||||
func Log10(z complex128) complex128
|
||||
|
||||
//go:linkname Arg C.carg
|
||||
func Arg(z complex128) float64
|
||||
|
||||
//go:linkname Phase C.carg
|
||||
func Phase(z complex128) float64
|
||||
|
||||
//go:linkname Pow C.cpow
|
||||
func Pow(x, y complex128) complex128
|
||||
|
||||
//go:linkname Sin C.csin
|
||||
func Sin(z complex128) complex128
|
||||
|
||||
//go:linkname Sinh C.csinh
|
||||
func Sinh(z complex128) complex128
|
||||
|
||||
//go:linkname Sqrt C.csqrt
|
||||
func Sqrt(z complex128) complex128
|
||||
|
||||
//go:linkname Tan C.ctan
|
||||
func Tan(z complex128) complex128
|
||||
|
||||
//go:linkname Tanh C.ctanh
|
||||
func Tanh(z complex128) complex128
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Absf C.cabsf
|
||||
func Absf(z complex64) float32
|
||||
|
||||
//go:linkname Acosf C.cacosf
|
||||
func Acosf(z complex64) complex64
|
||||
|
||||
//go:linkname Acoshf C.cacoshf
|
||||
func Acoshf(z complex64) complex64
|
||||
|
||||
//go:linkname Asinf C.casinf
|
||||
func Asinf(z complex64) complex64
|
||||
|
||||
//go:linkname Asinhf C.casinhf
|
||||
func Asinhf(z complex64) complex64
|
||||
|
||||
//go:linkname Atanf C.catanf
|
||||
func Atanf(z complex64) complex64
|
||||
|
||||
//go:linkname Atanhf C.catanhf
|
||||
func Atanhf(z complex64) complex64
|
||||
|
||||
//go:linkname Cosf C.ccosf
|
||||
func Cosf(z complex64) complex64
|
||||
|
||||
//go:linkname Coshf C.ccoshf
|
||||
func Coshf(z complex64) complex64
|
||||
|
||||
//go:linkname Expf C.cexpf
|
||||
func Expf(z complex64) complex64
|
||||
|
||||
//go:linkname Logf C.clogf
|
||||
func Logf(z complex64) complex64
|
||||
|
||||
//go:linkname Log10f C.clog10f
|
||||
func Log10f(z complex64) complex64
|
||||
|
||||
//go:linkname Argf C.cargf
|
||||
func Argf(z complex64) float32
|
||||
|
||||
//go:linkname Phasef C.cargf
|
||||
func Phasef(z complex64) float32
|
||||
|
||||
//go:linkname Powf C.cpowf
|
||||
func Powf(x, y complex64) complex64
|
||||
|
||||
//go:linkname Sinf C.csinf
|
||||
func Sinf(z complex64) complex64
|
||||
|
||||
//go:linkname Sinhf C.csinhf
|
||||
func Sinhf(z complex64) complex64
|
||||
|
||||
//go:linkname Sqrtf C.csqrtf
|
||||
func Sqrtf(z complex64) complex64
|
||||
|
||||
//go:linkname Tanf C.ctanf
|
||||
func Tanf(z complex64) complex64
|
||||
|
||||
//go:linkname Tanhf C.ctanhf
|
||||
func Tanhf(z complex64) complex64
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
225
c/os/os.go
Normal file
225
c/os/os.go
Normal file
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* 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 os
|
||||
|
||||
// #include <sys/stat.h>
|
||||
// #include <limits.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
const (
|
||||
PATH_MAX = C.PATH_MAX
|
||||
)
|
||||
|
||||
type (
|
||||
ModeT C.mode_t
|
||||
UidT C.uid_t
|
||||
GidT C.gid_t
|
||||
OffT C.off_t
|
||||
DevT C.dev_t
|
||||
StatT C.struct_stat
|
||||
)
|
||||
|
||||
//go:linkname Errno errno
|
||||
var Errno c.Int
|
||||
|
||||
//go:linkname Umask C.umask
|
||||
func Umask(cmask ModeT) ModeT
|
||||
|
||||
//go:linkname Mkdir C.mkdir
|
||||
func Mkdir(path *c.Char, mode ModeT) c.Int
|
||||
|
||||
//go:linkname Rmdir C.rmdir
|
||||
func Rmdir(path *c.Char) c.Int
|
||||
|
||||
//go:linkname Link C.link
|
||||
func Link(oldpath *c.Char, newpath *c.Char) c.Int
|
||||
|
||||
//go:linkname Symlink C.symlink
|
||||
func Symlink(target *c.Char, linkpath *c.Char) c.Int
|
||||
|
||||
//go:linkname Readlink C.readlink
|
||||
func Readlink(path *c.Char, buf c.Pointer, bufsize uintptr) int
|
||||
|
||||
//go:linkname Unlink C.unlink
|
||||
func Unlink(path *c.Char) c.Int
|
||||
|
||||
//go:linkname Remove C.remove
|
||||
func Remove(path *c.Char) c.Int
|
||||
|
||||
//go:linkname Rename C.rename
|
||||
func Rename(oldpath *c.Char, newpath *c.Char) c.Int
|
||||
|
||||
//go:linkname Stat C.stat
|
||||
func Stat(path *c.Char, buf *StatT) c.Int
|
||||
|
||||
//go:linkname Lstat C.lstat
|
||||
func Lstat(path *c.Char, buf *StatT) c.Int
|
||||
|
||||
//go:linkname Truncate C.truncate
|
||||
func Truncate(path *c.Char, length OffT) c.Int
|
||||
|
||||
//go:linkname Chmod C.chmod
|
||||
func Chmod(path *c.Char, mode ModeT) c.Int
|
||||
|
||||
//go:linkname Chown C.chown
|
||||
func Chown(path *c.Char, owner UidT, group GidT) c.Int
|
||||
|
||||
//go:linkname Lchown C.lchown
|
||||
func Lchown(path *c.Char, owner UidT, group GidT) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Getcwd C.getcwd
|
||||
func Getcwd(buffer c.Pointer, size uintptr) *c.Char
|
||||
|
||||
//go:linkname Chdir C.chdir
|
||||
func Chdir(path *c.Char) c.Int
|
||||
|
||||
//go:linkname Chroot C.chroot
|
||||
func Chroot(path *c.Char) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Environ C.environ
|
||||
func Environ() **c.Char
|
||||
|
||||
//go:linkname Getenv C.getenv
|
||||
func Getenv(name *c.Char) *c.Char
|
||||
|
||||
//go:linkname Setenv C.setenv
|
||||
func Setenv(name *c.Char, value *c.Char, overwrite c.Int) c.Int
|
||||
|
||||
//go:linkname Putenv C.putenv
|
||||
func Putenv(env *c.Char) c.Int
|
||||
|
||||
//go:linkname Unsetenv C.unsetenv
|
||||
func Unsetenv(name *c.Char) c.Int
|
||||
|
||||
//go:linkname Clearenv C.clearenv
|
||||
func Clearenv()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Fchdir C.fchdir
|
||||
func Fchdir(dirfd c.Int) c.Int
|
||||
|
||||
//go:linkname Faccessat C.faccessat
|
||||
func Faccessat(dirfd c.Int, path *c.Char, mode c.Int, flags c.Int) c.Int
|
||||
|
||||
//go:linkname Fchmodat C.fchmodat
|
||||
func Fchmodat(dirfd c.Int, path *c.Char, mode ModeT, flags c.Int) c.Int
|
||||
|
||||
//go:linkname Fchownat C.fchownat
|
||||
func Fchownat(dirfd c.Int, path *c.Char, owner UidT, group GidT, flags c.Int) c.Int
|
||||
|
||||
//go:linkname Fstatat C.fstatat
|
||||
func Fstatat(dirfd c.Int, path *c.Char, buf *StatT, flags c.Int) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Open C.open
|
||||
func Open(path *c.Char, flags c.Int, mode ModeT) c.Int
|
||||
|
||||
//go:linkname Creat C.creat
|
||||
func Creat(path *c.Char, mode ModeT) c.Int
|
||||
|
||||
//go:linkname Dup C.dup
|
||||
func Dup(fd c.Int) c.Int
|
||||
|
||||
//go:linkname Dup2 C.dup2
|
||||
func Dup2(oldfd c.Int, newfd c.Int) c.Int
|
||||
|
||||
/* TODO(xsw):
|
||||
On Alpha, IA-64, MIPS, SuperH, and SPARC/SPARC64, pipe() has the following prototype:
|
||||
struct fd_pair {
|
||||
long fd[2];
|
||||
};
|
||||
struct fd_pair pipe(void);
|
||||
*/
|
||||
//go:linkname Pipe C.pipe
|
||||
func Pipe(fds *[2]c.Int) c.Int
|
||||
|
||||
//go:linkname Mkfifo C.mkfifo
|
||||
func Mkfifo(path *c.Char, mode ModeT) c.Int
|
||||
|
||||
//go:linkname Mknod C.mknod
|
||||
func Mknod(path *c.Char, mode ModeT, dev DevT) c.Int
|
||||
|
||||
//go:linkname Close C.close
|
||||
func Close(fd c.Int) c.Int
|
||||
|
||||
//go:linkname Read C.read
|
||||
func Read(fd c.Int, buf c.Pointer, count uintptr) int
|
||||
|
||||
//go:linkname Write C.write
|
||||
func Write(fd c.Int, buf c.Pointer, count uintptr) int
|
||||
|
||||
//go:linkname Lseek C.lseek
|
||||
func Lseek(fd c.Int, offset OffT, whence c.Int) OffT
|
||||
|
||||
//go:linkname Fsync C.fsync
|
||||
func Fsync(fd c.Int) c.Int
|
||||
|
||||
//go:linkname Ftruncate C.ftruncate
|
||||
func Ftruncate(fd c.Int, length OffT) c.Int
|
||||
|
||||
//go:linkname Fchmod C.fchmod
|
||||
func Fchmod(fd c.Int, mode ModeT) c.Int
|
||||
|
||||
//go:linkname Fchown C.fchown
|
||||
func Fchown(fd c.Int, owner UidT, group GidT) c.Int
|
||||
|
||||
//go:linkname Fstat C.fstat
|
||||
func Fstat(fd c.Int, buf *StatT) c.Int
|
||||
|
||||
//go:linkname Isatty C.isatty
|
||||
func Isatty(fd c.Int) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Exit C.exit
|
||||
func Exit(c.Int)
|
||||
|
||||
//go:linkname Getpid C.getpid
|
||||
func Getpid() c.Int
|
||||
|
||||
//go:linkname Getppid C.getppid
|
||||
func Getppid() c.Int
|
||||
|
||||
//go:linkname Getuid C.getuid
|
||||
func Getuid() UidT
|
||||
|
||||
//go:linkname Geteuid C.geteuid
|
||||
func Geteuid() UidT
|
||||
|
||||
//go:linkname Getgid C.getgid
|
||||
func Getgid() GidT
|
||||
|
||||
//go:linkname Getegid C.getegid
|
||||
func Getegid() GidT
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
7
c/pthread/sync/_pthd/pthd.c
Normal file
7
c/pthread/sync/_pthd/pthd.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <pthread.h>
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
pthread_once_t llgoSyncOnceInitVal = PTHREAD_ONCE_INIT;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
BIN
c/pthread/sync/llgo_autogen.lla
Normal file
BIN
c/pthread/sync/llgo_autogen.lla
Normal file
Binary file not shown.
174
c/pthread/sync/sync.go
Normal file
174
c/pthread/sync/sync.go
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* 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 sync
|
||||
|
||||
// #include <pthread.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/time"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoFiles = "_pthd/pthd.c"
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Once is an object that will perform exactly one action.
|
||||
type Once C.pthread_once_t
|
||||
|
||||
//go:linkname OnceInit llgoSyncOnceInitVal
|
||||
var OnceInit Once
|
||||
|
||||
// llgo:link (*Once).Do C.pthread_once
|
||||
func (o *Once) Do(f func()) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type MutexType c.Int
|
||||
|
||||
const (
|
||||
MUTEX_NORMAL MutexType = C.PTHREAD_MUTEX_NORMAL
|
||||
MUTEX_ERRORCHECK MutexType = C.PTHREAD_MUTEX_ERRORCHECK
|
||||
MUTEX_RECURSIVE MutexType = C.PTHREAD_MUTEX_RECURSIVE
|
||||
MUTEX_DEFAULT MutexType = C.PTHREAD_MUTEX_DEFAULT
|
||||
)
|
||||
|
||||
// MutexAttr is a mutex attribute object.
|
||||
type MutexAttr C.pthread_mutexattr_t
|
||||
|
||||
// llgo:link (*MutexAttr).Init C.pthread_mutexattr_init
|
||||
func (a *MutexAttr) Init(attr *MutexAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*MutexAttr).Destroy C.pthread_mutexattr_destroy
|
||||
func (a *MutexAttr) Destroy() {}
|
||||
|
||||
// llgo:link (*MutexAttr).SetType C.pthread_mutexattr_settype
|
||||
func (a *MutexAttr) SetType(typ MutexType) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Mutex is a mutual exclusion lock.
|
||||
type Mutex C.pthread_mutex_t
|
||||
|
||||
// llgo:link (*Mutex).Init C.pthread_mutex_init
|
||||
func (m *Mutex) Init(attr *MutexAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Mutex).Destroy C.pthread_mutex_destroy
|
||||
func (m *Mutex) Destroy() {}
|
||||
|
||||
// llgo:link (*Mutex).Lock C.pthread_mutex_lock
|
||||
func (m *Mutex) Lock() {}
|
||||
|
||||
// llgo:link (*Mutex).TryLock C.pthread_mutex_trylock
|
||||
func (m *Mutex) TryLock() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Mutex).Unlock C.pthread_mutex_unlock
|
||||
func (m *Mutex) Unlock() {}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// RWLockAttr is a read-write lock attribute object.
|
||||
type RWLockAttr C.pthread_rwlockattr_t
|
||||
|
||||
// llgo:link (*RWLockAttr).Init C.pthread_rwlockattr_init
|
||||
func (a *RWLockAttr) Init(attr *RWLockAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*RWLockAttr).Destroy C.pthread_rwlockattr_destroy
|
||||
func (a *RWLockAttr) Destroy() {}
|
||||
|
||||
// llgo:link (*RWLockAttr).SetPShared C.pthread_rwlockattr_setpshared
|
||||
func (a *RWLockAttr) SetPShared(pshared c.Int) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*RWLockAttr).GetPShared C.pthread_rwlockattr_getpshared
|
||||
func (a *RWLockAttr) GetPShared(pshared *c.Int) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// RWLock is a read-write lock.
|
||||
type RWLock C.pthread_rwlock_t
|
||||
|
||||
// llgo:link (*RWLock).Init C.pthread_rwlock_init
|
||||
func (rw *RWLock) Init(attr *RWLockAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*RWLock).Destroy C.pthread_rwlock_destroy
|
||||
func (rw *RWLock) Destroy() {}
|
||||
|
||||
// llgo:link (*RWLock).RLock C.pthread_rwlock_rdlock
|
||||
func (rw *RWLock) RLock() {}
|
||||
|
||||
// llgo:link (*RWLock).TryRLock C.pthread_rwlock_tryrdlock
|
||||
func (rw *RWLock) TryRLock() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*RWLock).RUnlock C.pthread_rwlock_unlock
|
||||
func (rw *RWLock) RUnlock() {}
|
||||
|
||||
// llgo:link (*RWLock).Lock C.pthread_rwlock_wrlock
|
||||
func (rw *RWLock) Lock() {}
|
||||
|
||||
// llgo:link (*RWLock).TryLock C.pthread_rwlock_trywrlock
|
||||
func (rw *RWLock) TryLock() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*RWLock).Unlock C.pthread_rwlock_unlock
|
||||
func (rw *RWLock) Unlock() {}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// CondAttr is a condition variable attribute object.
|
||||
type CondAttr C.pthread_condattr_t
|
||||
|
||||
// llgo:link (*CondAttr).Init C.pthread_condattr_init
|
||||
func (a *CondAttr) Init(attr *CondAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*CondAttr).Destroy C.pthread_condattr_destroy
|
||||
func (a *CondAttr) Destroy() {}
|
||||
|
||||
// llgo:link (*CondAttr).SetClock C.pthread_condattr_setclock
|
||||
func (a *CondAttr) SetClock(clock time.ClockID) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*CondAttr).GetClock C.pthread_condattr_getclock
|
||||
func (a *CondAttr) GetClock(clock *time.ClockID) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Cond is a condition variable.
|
||||
type Cond C.pthread_cond_t
|
||||
|
||||
// llgo:link (*Cond).Init C.pthread_cond_init
|
||||
func (c *Cond) Init(attr *CondAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Cond).Destroy C.pthread_cond_destroy
|
||||
func (c *Cond) Destroy() {}
|
||||
|
||||
// llgo:link (*Cond).Signal C.pthread_cond_signal
|
||||
func (c *Cond) Signal() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Cond).Broadcast C.pthread_cond_broadcast
|
||||
func (c *Cond) Broadcast() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Cond).Wait C.pthread_cond_wait
|
||||
func (c *Cond) Wait(m *Mutex) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Cond).TimedWait C.pthread_cond_timedwait
|
||||
func (c *Cond) TimedWait(m *Mutex, abstime *time.Timespec) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -1,22 +1,18 @@
|
||||
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
|
||||
|
||||
### on macOS (Homebrew)
|
||||
|
||||
```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
|
||||
brew install sqlite3
|
||||
```
|
||||
|
||||
### on Linux (Debian/Ubuntu)
|
||||
|
||||
```sh
|
||||
apt-get install -y libsqlite3-dev
|
||||
```
|
||||
|
||||
## Demos
|
||||
|
||||
@@ -2,11 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/os"
|
||||
"github.com/goplus/llgo/c/sqlite"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c.Remove(c.Str("test.db"))
|
||||
os.Remove(c.Str("test.db"))
|
||||
|
||||
db, err := sqlite.Open(c.Str("test.db"))
|
||||
check(err, db, "sqlite: Open")
|
||||
|
||||
72
c/sync/atomic/atomic.go
Normal file
72
c/sync/atomic/atomic.go
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 atomic
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
type valtype interface {
|
||||
~int | ~uint | ~uintptr | ~int32 | ~uint32 | ~int64 | ~uint64 | ~unsafe.Pointer
|
||||
}
|
||||
|
||||
// llgo:link Add llgo.atomicAdd
|
||||
func Add[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Sub llgo.atomicSub
|
||||
func Sub[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link And llgo.atomicAnd
|
||||
func And[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link NotAnd llgo.atomicNand
|
||||
func NotAnd[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Or llgo.atomicOr
|
||||
func Or[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Xor llgo.atomicXor
|
||||
func Xor[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Max llgo.atomicMax
|
||||
func Max[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Min llgo.atomicMin
|
||||
func Min[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link UMax llgo.atomicUMax
|
||||
func UMax[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link UMin llgo.atomicUMin
|
||||
func UMin[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Load llgo.atomicLoad
|
||||
func Load[T valtype](ptr *T) T { return *ptr }
|
||||
|
||||
// llgo:link Store llgo.atomicStore
|
||||
func Store[T valtype](ptr *T, v T) {}
|
||||
|
||||
// llgo:link Exchange llgo.atomicXchg
|
||||
func Exchange[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link CompareAndExchange llgo.atomicCmpXchg
|
||||
func CompareAndExchange[T valtype](ptr *T, old, new T) (T, bool) { return old, false }
|
||||
38
c/time/time.go
Normal file
38
c/time/time.go
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 time
|
||||
|
||||
// #include <time.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type Timespec C.struct_timespec
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type ClockID C.clockid_t
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -1215,73 +1215,75 @@ _llgo_24: ; preds = %_llgo_22
|
||||
br label %_llgo_12
|
||||
|
||||
_llgo_25: ; preds = %_llgo_27
|
||||
%52 = fptosi double %69 to i64
|
||||
%53 = add i64 %70, 2
|
||||
%52 = fptosi double %71 to i64
|
||||
%53 = add i64 %72, 2
|
||||
%54 = add i64 %52, 48
|
||||
%55 = trunc i64 %54 to i8
|
||||
%56 = icmp slt i64 %53, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %56)
|
||||
%57 = getelementptr inbounds i8, ptr %20, i64 %53
|
||||
store i8 %55, ptr %57, align 1
|
||||
%58 = sitofp i64 %52 to double
|
||||
%59 = fsub double %69, %58
|
||||
%60 = fmul double %59, 1.000000e+01
|
||||
%61 = add i64 %70, 1
|
||||
%57 = icmp sge i64 %53, 14
|
||||
%58 = or i1 %57, %56
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %58)
|
||||
%59 = getelementptr inbounds i8, ptr %20, i64 %53
|
||||
store i8 %55, ptr %59, align 1
|
||||
%60 = sitofp i64 %52 to double
|
||||
%61 = fsub double %71, %60
|
||||
%62 = fmul double %61, 1.000000e+01
|
||||
%63 = add i64 %72, 1
|
||||
br label %_llgo_27
|
||||
|
||||
_llgo_26: ; preds = %_llgo_27
|
||||
%62 = getelementptr inbounds i8, ptr %20, i64 2
|
||||
%63 = load i8, ptr %62, align 1
|
||||
%64 = getelementptr inbounds i8, ptr %20, i64 1
|
||||
store i8 %63, ptr %64, align 1
|
||||
%65 = getelementptr inbounds i8, ptr %20, i64 2
|
||||
store i8 46, ptr %65, align 1
|
||||
%66 = getelementptr inbounds i8, ptr %20, i64 9
|
||||
store i8 101, ptr %66, align 1
|
||||
%67 = getelementptr inbounds i8, ptr %20, i64 10
|
||||
store i8 43, ptr %67, align 1
|
||||
%68 = icmp slt i64 %28, 0
|
||||
br i1 %68, label %_llgo_28, label %_llgo_29
|
||||
%64 = getelementptr inbounds i8, ptr %20, i64 2
|
||||
%65 = load i8, ptr %64, align 1
|
||||
%66 = getelementptr inbounds i8, ptr %20, i64 1
|
||||
store i8 %65, ptr %66, align 1
|
||||
%67 = getelementptr inbounds i8, ptr %20, i64 2
|
||||
store i8 46, ptr %67, align 1
|
||||
%68 = getelementptr inbounds i8, ptr %20, i64 9
|
||||
store i8 101, ptr %68, align 1
|
||||
%69 = getelementptr inbounds i8, ptr %20, i64 10
|
||||
store i8 43, ptr %69, align 1
|
||||
%70 = icmp slt i64 %28, 0
|
||||
br i1 %70, label %_llgo_28, label %_llgo_29
|
||||
|
||||
_llgo_27: ; preds = %_llgo_25, %_llgo_12
|
||||
%69 = phi double [ %27, %_llgo_12 ], [ %60, %_llgo_25 ]
|
||||
%70 = phi i64 [ 0, %_llgo_12 ], [ %61, %_llgo_25 ]
|
||||
%71 = icmp slt i64 %70, 7
|
||||
br i1 %71, label %_llgo_25, label %_llgo_26
|
||||
%71 = phi double [ %27, %_llgo_12 ], [ %62, %_llgo_25 ]
|
||||
%72 = phi i64 [ 0, %_llgo_12 ], [ %63, %_llgo_25 ]
|
||||
%73 = icmp slt i64 %72, 7
|
||||
br i1 %73, label %_llgo_25, label %_llgo_26
|
||||
|
||||
_llgo_28: ; preds = %_llgo_26
|
||||
%72 = sub i64 0, %28
|
||||
%73 = getelementptr inbounds i8, ptr %20, i64 10
|
||||
store i8 45, ptr %73, align 1
|
||||
%74 = sub i64 0, %28
|
||||
%75 = getelementptr inbounds i8, ptr %20, i64 10
|
||||
store i8 45, ptr %75, align 1
|
||||
br label %_llgo_29
|
||||
|
||||
_llgo_29: ; preds = %_llgo_28, %_llgo_26
|
||||
%74 = phi i64 [ %28, %_llgo_26 ], [ %72, %_llgo_28 ]
|
||||
%75 = sdiv i64 %74, 100
|
||||
%76 = trunc i64 %75 to i8
|
||||
%77 = add i8 %76, 48
|
||||
%78 = getelementptr inbounds i8, ptr %20, i64 11
|
||||
store i8 %77, ptr %78, align 1
|
||||
%79 = sdiv i64 %74, 10
|
||||
%80 = trunc i64 %79 to i8
|
||||
%81 = urem i8 %80, 10
|
||||
%82 = add i8 %81, 48
|
||||
%83 = getelementptr inbounds i8, ptr %20, i64 12
|
||||
store i8 %82, ptr %83, align 1
|
||||
%84 = srem i64 %74, 10
|
||||
%85 = trunc i64 %84 to i8
|
||||
%86 = add i8 %85, 48
|
||||
%87 = getelementptr inbounds i8, ptr %20, i64 13
|
||||
store i8 %86, ptr %87, align 1
|
||||
%88 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%89 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, i32 0, i32 0
|
||||
store ptr %20, ptr %89, align 8
|
||||
%90 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, i32 0, i32 1
|
||||
store i64 14, ptr %90, align 4
|
||||
%91 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, i32 0, i32 2
|
||||
store i64 14, ptr %91, align 4
|
||||
%92 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, align 8
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %92)
|
||||
%76 = phi i64 [ %28, %_llgo_26 ], [ %74, %_llgo_28 ]
|
||||
%77 = sdiv i64 %76, 100
|
||||
%78 = trunc i64 %77 to i8
|
||||
%79 = add i8 %78, 48
|
||||
%80 = getelementptr inbounds i8, ptr %20, i64 11
|
||||
store i8 %79, ptr %80, align 1
|
||||
%81 = sdiv i64 %76, 10
|
||||
%82 = trunc i64 %81 to i8
|
||||
%83 = urem i8 %82, 10
|
||||
%84 = add i8 %83, 48
|
||||
%85 = getelementptr inbounds i8, ptr %20, i64 12
|
||||
store i8 %84, ptr %85, align 1
|
||||
%86 = srem i64 %76, 10
|
||||
%87 = trunc i64 %86 to i8
|
||||
%88 = add i8 %87, 48
|
||||
%89 = getelementptr inbounds i8, ptr %20, i64 13
|
||||
store i8 %88, ptr %89, align 1
|
||||
%90 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%91 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %90, i32 0, i32 0
|
||||
store ptr %20, ptr %91, align 8
|
||||
%92 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %90, i32 0, i32 1
|
||||
store i64 14, ptr %92, align 4
|
||||
%93 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %90, i32 0, i32 2
|
||||
store i64 14, ptr %93, align 4
|
||||
%94 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %90, align 8
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %94)
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -1291,7 +1293,7 @@ _llgo_0:
|
||||
br label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_3
|
||||
%2 = urem i64 %20, 16
|
||||
%2 = urem i64 %28, 16
|
||||
%3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 0
|
||||
store ptr @9, ptr %4, align 8
|
||||
@@ -1299,46 +1301,55 @@ _llgo_1: ; preds = %_llgo_3
|
||||
store i64 16, ptr %5, align 4
|
||||
%6 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %3, align 8
|
||||
%7 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %6, 0
|
||||
%8 = getelementptr inbounds i8, ptr %7, i64 %2
|
||||
%9 = load i8, ptr %8, align 1
|
||||
%10 = icmp slt i64 %21, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %10)
|
||||
%11 = getelementptr inbounds i8, ptr %1, i64 %21
|
||||
store i8 %9, ptr %11, align 1
|
||||
%12 = icmp ult i64 %20, 16
|
||||
br i1 %12, label %_llgo_5, label %_llgo_4
|
||||
%8 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %6, 1
|
||||
%9 = icmp sge i64 %2, %8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %9)
|
||||
%10 = getelementptr inbounds i8, ptr %7, i64 %2
|
||||
%11 = load i8, ptr %10, align 1
|
||||
%12 = icmp slt i64 %29, 0
|
||||
%13 = icmp sge i64 %29, 100
|
||||
%14 = or i1 %13, %12
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %14)
|
||||
%15 = getelementptr inbounds i8, ptr %1, i64 %29
|
||||
store i8 %11, ptr %15, align 1
|
||||
%16 = icmp ult i64 %28, 16
|
||||
br i1 %16, label %_llgo_5, label %_llgo_4
|
||||
|
||||
_llgo_2: ; preds = %_llgo_5, %_llgo_3
|
||||
%13 = sub i64 %21, 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 120, ptr %15, align 1
|
||||
%16 = sub i64 %13, 1
|
||||
%17 = icmp slt i64 %16, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %17)
|
||||
%18 = getelementptr inbounds i8, ptr %1, i64 %16
|
||||
store i8 48, ptr %18, align 1
|
||||
%19 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %16, i64 100, i64 100)
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %19)
|
||||
%17 = sub i64 %29, 1
|
||||
%18 = icmp slt i64 %17, 0
|
||||
%19 = icmp sge i64 %17, 100
|
||||
%20 = or i1 %19, %18
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %20)
|
||||
%21 = getelementptr inbounds i8, ptr %1, i64 %17
|
||||
store i8 120, ptr %21, align 1
|
||||
%22 = sub i64 %17, 1
|
||||
%23 = icmp slt i64 %22, 0
|
||||
%24 = icmp sge i64 %22, 100
|
||||
%25 = or i1 %24, %23
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %25)
|
||||
%26 = getelementptr inbounds i8, ptr %1, i64 %22
|
||||
store i8 48, ptr %26, align 1
|
||||
%27 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %22, i64 100, i64 100)
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %27)
|
||||
ret void
|
||||
|
||||
_llgo_3: ; preds = %_llgo_4, %_llgo_0
|
||||
%20 = phi i64 [ %0, %_llgo_0 ], [ %23, %_llgo_4 ]
|
||||
%21 = phi i64 [ 99, %_llgo_0 ], [ %24, %_llgo_4 ]
|
||||
%22 = icmp sgt i64 %21, 0
|
||||
br i1 %22, label %_llgo_1, label %_llgo_2
|
||||
%28 = phi i64 [ %0, %_llgo_0 ], [ %31, %_llgo_4 ]
|
||||
%29 = phi i64 [ 99, %_llgo_0 ], [ %32, %_llgo_4 ]
|
||||
%30 = icmp sgt i64 %29, 0
|
||||
br i1 %30, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_4: ; preds = %_llgo_5, %_llgo_1
|
||||
%23 = udiv i64 %20, 16
|
||||
%24 = sub i64 %21, 1
|
||||
%31 = udiv i64 %28, 16
|
||||
%32 = sub i64 %29, 1
|
||||
br label %_llgo_3
|
||||
|
||||
_llgo_5: ; preds = %_llgo_1
|
||||
%25 = sub i64 100, %21
|
||||
%26 = load i64, ptr @main.minhexdigits, align 4
|
||||
%27 = icmp sge i64 %25, %26
|
||||
br i1 %27, label %_llgo_2, label %_llgo_4
|
||||
%33 = sub i64 100, %29
|
||||
%34 = load i64, ptr @main.minhexdigits, align 4
|
||||
%35 = icmp sge i64 %33, %34
|
||||
br i1 %35, label %_llgo_2, label %_llgo_4
|
||||
}
|
||||
|
||||
define void @main.printint(i64 %0) {
|
||||
@@ -1375,30 +1386,33 @@ _llgo_1: ; preds = %_llgo_5, %_llgo_0
|
||||
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.eface", ptr %6, i64 %3
|
||||
%8 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, align 8
|
||||
%9 = icmp ne i64 %3, 0
|
||||
br i1 %9, label %_llgo_4, label %_llgo_5
|
||||
%5 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
%7 = icmp slt i64 %3, 0
|
||||
%8 = icmp sge i64 %3, %6
|
||||
%9 = or i1 %8, %7
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %9)
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %5, i64 %3
|
||||
%11 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
|
||||
%12 = icmp ne i64 %3, 0
|
||||
br i1 %12, label %_llgo_4, label %_llgo_5
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
call void @main.printnl()
|
||||
ret void
|
||||
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
%10 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 0
|
||||
store ptr @11, ptr %11, align 8
|
||||
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 1
|
||||
store i64 1, ptr %12, align 4
|
||||
%13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %10, align 8
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %13)
|
||||
%13 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %13, i32 0, i32 0
|
||||
store ptr @11, ptr %14, align 8
|
||||
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %13, i32 0, i32 1
|
||||
store i64 1, ptr %15, align 4
|
||||
%16 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %13, align 8
|
||||
call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %16)
|
||||
br label %_llgo_5
|
||||
|
||||
_llgo_5: ; preds = %_llgo_4, %_llgo_2
|
||||
call void @main.printany(%"github.com/goplus/llgo/internal/runtime.eface" %8)
|
||||
call void @main.printany(%"github.com/goplus/llgo/internal/runtime.eface" %11)
|
||||
br label %_llgo_1
|
||||
}
|
||||
|
||||
@@ -1439,30 +1453,32 @@ _llgo_0:
|
||||
br label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_3
|
||||
%2 = urem i64 %9, 10
|
||||
%2 = urem i64 %11, 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
|
||||
%5 = icmp slt i64 %12, 0
|
||||
%6 = icmp sge i64 %12, 100
|
||||
%7 = or i1 %6, %5
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %7)
|
||||
%8 = getelementptr inbounds i8, ptr %1, i64 %12
|
||||
store i8 %4, ptr %8, align 1
|
||||
%9 = icmp ult i64 %11, 10
|
||||
br i1 %9, label %_llgo_2, label %_llgo_4
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_3
|
||||
%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)
|
||||
%10 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %1, i64 1, i64 100, i64 %12, i64 100, i64 100)
|
||||
call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %10)
|
||||
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
|
||||
%11 = phi i64 [ %0, %_llgo_0 ], [ %14, %_llgo_4 ]
|
||||
%12 = phi i64 [ 99, %_llgo_0 ], [ %15, %_llgo_4 ]
|
||||
%13 = icmp sgt i64 %12, 0
|
||||
br i1 %13, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_4: ; preds = %_llgo_1
|
||||
%12 = udiv i64 %9, 10
|
||||
%13 = sub i64 %10, 1
|
||||
%14 = udiv i64 %11, 10
|
||||
%15 = sub i64 %12, 1
|
||||
br label %_llgo_3
|
||||
}
|
||||
|
||||
@@ -1499,28 +1515,28 @@ _llgo_0:
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13)
|
||||
store ptr %2, ptr @_llgo_float32, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 6
|
||||
%4 = load i8, ptr %3, align 1
|
||||
%5 = or i8 %4, 32
|
||||
store i8 %5, ptr %3, align 1
|
||||
store ptr %2, ptr @_llgo_float32, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%6 = load ptr, ptr @_llgo_float64, align 8
|
||||
%7 = icmp eq ptr %6, null
|
||||
br i1 %7, label %_llgo_3, label %_llgo_4
|
||||
|
||||
_llgo_3: ; preds = %_llgo_2
|
||||
%8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14)
|
||||
store ptr %8, ptr @_llgo_float64, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %8, i32 0, i32 6
|
||||
%10 = load i8, ptr %9, align 1
|
||||
%11 = or i8 %10, 32
|
||||
store i8 %11, ptr %9, align 1
|
||||
store ptr %8, ptr @_llgo_float64, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%12 = load ptr, ptr @_llgo_string, align 8
|
||||
%13 = icmp eq ptr %12, null
|
||||
br i1 %13, label %_llgo_5, label %_llgo_6
|
||||
@@ -1537,168 +1553,168 @@ _llgo_6: ; preds = %_llgo_5, %_llgo_4
|
||||
|
||||
_llgo_7: ; preds = %_llgo_6
|
||||
%17 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
|
||||
store ptr %17, ptr @_llgo_bool, align 8
|
||||
br label %_llgo_8
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7, %_llgo_6
|
||||
%18 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %17, i32 0, i32 6
|
||||
%19 = load i8, ptr %18, align 1
|
||||
%20 = or i8 %19, 32
|
||||
store i8 %20, ptr %18, align 1
|
||||
store ptr %17, ptr @_llgo_bool, align 8
|
||||
br label %_llgo_8
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7, %_llgo_6
|
||||
%21 = load ptr, ptr @_llgo_int32, align 8
|
||||
%22 = icmp eq ptr %21, null
|
||||
br i1 %22, label %_llgo_9, label %_llgo_10
|
||||
|
||||
_llgo_9: ; preds = %_llgo_8
|
||||
%23 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
|
||||
store ptr %23, ptr @_llgo_int32, align 8
|
||||
br label %_llgo_10
|
||||
|
||||
_llgo_10: ; preds = %_llgo_9, %_llgo_8
|
||||
%24 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %23, i32 0, i32 6
|
||||
%25 = load i8, ptr %24, align 1
|
||||
%26 = or i8 %25, 32
|
||||
store i8 %26, ptr %24, align 1
|
||||
store ptr %23, ptr @_llgo_int32, align 8
|
||||
br label %_llgo_10
|
||||
|
||||
_llgo_10: ; preds = %_llgo_9, %_llgo_8
|
||||
%27 = load ptr, ptr @_llgo_int8, align 8
|
||||
%28 = icmp eq ptr %27, null
|
||||
br i1 %28, label %_llgo_11, label %_llgo_12
|
||||
|
||||
_llgo_11: ; preds = %_llgo_10
|
||||
%29 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3)
|
||||
store ptr %29, ptr @_llgo_int8, align 8
|
||||
br label %_llgo_12
|
||||
|
||||
_llgo_12: ; preds = %_llgo_11, %_llgo_10
|
||||
%30 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %29, i32 0, i32 6
|
||||
%31 = load i8, ptr %30, align 1
|
||||
%32 = or i8 %31, 32
|
||||
store i8 %32, ptr %30, align 1
|
||||
store ptr %29, ptr @_llgo_int8, align 8
|
||||
br label %_llgo_12
|
||||
|
||||
_llgo_12: ; preds = %_llgo_11, %_llgo_10
|
||||
%33 = load ptr, ptr @_llgo_int16, align 8
|
||||
%34 = icmp eq ptr %33, null
|
||||
br i1 %34, label %_llgo_13, label %_llgo_14
|
||||
|
||||
_llgo_13: ; preds = %_llgo_12
|
||||
%35 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 4)
|
||||
store ptr %35, ptr @_llgo_int16, align 8
|
||||
br label %_llgo_14
|
||||
|
||||
_llgo_14: ; preds = %_llgo_13, %_llgo_12
|
||||
%36 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %35, i32 0, i32 6
|
||||
%37 = load i8, ptr %36, align 1
|
||||
%38 = or i8 %37, 32
|
||||
store i8 %38, ptr %36, align 1
|
||||
store ptr %35, ptr @_llgo_int16, align 8
|
||||
br label %_llgo_14
|
||||
|
||||
_llgo_14: ; preds = %_llgo_13, %_llgo_12
|
||||
%39 = load ptr, ptr @_llgo_int64, align 8
|
||||
%40 = icmp eq ptr %39, null
|
||||
br i1 %40, label %_llgo_15, label %_llgo_16
|
||||
|
||||
_llgo_15: ; preds = %_llgo_14
|
||||
%41 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6)
|
||||
store ptr %41, ptr @_llgo_int64, align 8
|
||||
br label %_llgo_16
|
||||
|
||||
_llgo_16: ; preds = %_llgo_15, %_llgo_14
|
||||
%42 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %41, i32 0, i32 6
|
||||
%43 = load i8, ptr %42, align 1
|
||||
%44 = or i8 %43, 32
|
||||
store i8 %44, ptr %42, align 1
|
||||
store ptr %41, ptr @_llgo_int64, align 8
|
||||
br label %_llgo_16
|
||||
|
||||
_llgo_16: ; preds = %_llgo_15, %_llgo_14
|
||||
%45 = load ptr, ptr @_llgo_int, align 8
|
||||
%46 = icmp eq ptr %45, null
|
||||
br i1 %46, label %_llgo_17, label %_llgo_18
|
||||
|
||||
_llgo_17: ; preds = %_llgo_16
|
||||
%47 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
store ptr %47, ptr @_llgo_int, align 8
|
||||
br label %_llgo_18
|
||||
|
||||
_llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||
%48 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %47, i32 0, i32 6
|
||||
%49 = load i8, ptr %48, align 1
|
||||
%50 = or i8 %49, 32
|
||||
store i8 %50, ptr %48, align 1
|
||||
store ptr %47, ptr @_llgo_int, align 8
|
||||
br label %_llgo_18
|
||||
|
||||
_llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||
%51 = load ptr, ptr @_llgo_uint8, align 8
|
||||
%52 = icmp eq ptr %51, null
|
||||
br i1 %52, label %_llgo_19, label %_llgo_20
|
||||
|
||||
_llgo_19: ; preds = %_llgo_18
|
||||
%53 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8)
|
||||
store ptr %53, ptr @_llgo_uint8, align 8
|
||||
br label %_llgo_20
|
||||
|
||||
_llgo_20: ; preds = %_llgo_19, %_llgo_18
|
||||
%54 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %53, i32 0, i32 6
|
||||
%55 = load i8, ptr %54, align 1
|
||||
%56 = or i8 %55, 32
|
||||
store i8 %56, ptr %54, align 1
|
||||
store ptr %53, ptr @_llgo_uint8, align 8
|
||||
br label %_llgo_20
|
||||
|
||||
_llgo_20: ; preds = %_llgo_19, %_llgo_18
|
||||
%57 = load ptr, ptr @_llgo_uint16, align 8
|
||||
%58 = icmp eq ptr %57, null
|
||||
br i1 %58, label %_llgo_21, label %_llgo_22
|
||||
|
||||
_llgo_21: ; preds = %_llgo_20
|
||||
%59 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 9)
|
||||
store ptr %59, ptr @_llgo_uint16, align 8
|
||||
br label %_llgo_22
|
||||
|
||||
_llgo_22: ; preds = %_llgo_21, %_llgo_20
|
||||
%60 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %59, i32 0, i32 6
|
||||
%61 = load i8, ptr %60, align 1
|
||||
%62 = or i8 %61, 32
|
||||
store i8 %62, ptr %60, align 1
|
||||
store ptr %59, ptr @_llgo_uint16, align 8
|
||||
br label %_llgo_22
|
||||
|
||||
_llgo_22: ; preds = %_llgo_21, %_llgo_20
|
||||
%63 = load ptr, ptr @_llgo_uint32, align 8
|
||||
%64 = icmp eq ptr %63, null
|
||||
br i1 %64, label %_llgo_23, label %_llgo_24
|
||||
|
||||
_llgo_23: ; preds = %_llgo_22
|
||||
%65 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 10)
|
||||
store ptr %65, ptr @_llgo_uint32, align 8
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
%66 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %65, i32 0, i32 6
|
||||
%67 = load i8, ptr %66, align 1
|
||||
%68 = or i8 %67, 32
|
||||
store i8 %68, ptr %66, align 1
|
||||
store ptr %65, ptr @_llgo_uint32, align 8
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
%69 = load ptr, ptr @_llgo_uint64, align 8
|
||||
%70 = icmp eq ptr %69, null
|
||||
br i1 %70, label %_llgo_25, label %_llgo_26
|
||||
|
||||
_llgo_25: ; preds = %_llgo_24
|
||||
%71 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 11)
|
||||
store ptr %71, ptr @_llgo_uint64, align 8
|
||||
br label %_llgo_26
|
||||
|
||||
_llgo_26: ; preds = %_llgo_25, %_llgo_24
|
||||
%72 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %71, i32 0, i32 6
|
||||
%73 = load i8, ptr %72, align 1
|
||||
%74 = or i8 %73, 32
|
||||
store i8 %74, ptr %72, align 1
|
||||
store ptr %71, ptr @_llgo_uint64, align 8
|
||||
br label %_llgo_26
|
||||
|
||||
_llgo_26: ; preds = %_llgo_25, %_llgo_24
|
||||
%75 = load ptr, ptr @_llgo_uintptr, align 8
|
||||
%76 = icmp eq ptr %75, null
|
||||
br i1 %76, label %_llgo_27, label %_llgo_28
|
||||
|
||||
_llgo_27: ; preds = %_llgo_26
|
||||
%77 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 12)
|
||||
store ptr %77, ptr @_llgo_uintptr, align 8
|
||||
br label %_llgo_28
|
||||
|
||||
_llgo_28: ; preds = %_llgo_27, %_llgo_26
|
||||
%78 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %77, i32 0, i32 6
|
||||
%79 = load i8, ptr %78, align 1
|
||||
%80 = or i8 %79, 32
|
||||
store i8 %80, ptr %78, align 1
|
||||
store ptr %77, ptr @_llgo_uintptr, align 8
|
||||
br label %_llgo_28
|
||||
|
||||
_llgo_28: ; preds = %_llgo_27, %_llgo_26
|
||||
%81 = load ptr, ptr @_llgo_uint, align 8
|
||||
%82 = icmp eq ptr %81, null
|
||||
br i1 %82, label %_llgo_29, label %_llgo_30
|
||||
|
||||
_llgo_29: ; preds = %_llgo_28
|
||||
%83 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 7)
|
||||
store ptr %83, ptr @_llgo_uint, align 8
|
||||
br label %_llgo_30
|
||||
|
||||
_llgo_30: ; preds = %_llgo_29, %_llgo_28
|
||||
%84 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %83, i32 0, i32 6
|
||||
%85 = load i8, ptr %84, align 1
|
||||
%86 = or i8 %85, 32
|
||||
store i8 %86, ptr %84, align 1
|
||||
store ptr %83, ptr @_llgo_uint, align 8
|
||||
br label %_llgo_30
|
||||
|
||||
_llgo_30: ; preds = %_llgo_29, %_llgo_28
|
||||
ret void
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,14 @@ source_filename = "main"
|
||||
|
||||
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
|
||||
%1 = sext i8 %0 to i64
|
||||
%2 = icmp slt i64 %1, 0
|
||||
%3 = icmp sge i64 %1, 8
|
||||
%4 = or i1 %3, %2
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %4)
|
||||
%5 = getelementptr inbounds i8, ptr @main.array, i64 %1
|
||||
%6 = load i8, ptr %5, align 1
|
||||
ret i8 %6
|
||||
}
|
||||
|
||||
define void @main.init() {
|
||||
@@ -57,7 +59,7 @@ _llgo_1: ; preds = %_llgo_3
|
||||
store i64 7, ptr %4, align 4
|
||||
%5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %5, 1
|
||||
%7 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %5, i64 %15, i64 %6)
|
||||
%7 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %5, i64 %15, i64 %6)
|
||||
%8 = call { i32, i64 } @"unicode/utf8.DecodeRuneInString"(%"github.com/goplus/llgo/internal/runtime.String" %7)
|
||||
%9 = extractvalue { i32, i64 } %8, 0
|
||||
%10 = extractvalue { i32, i64 } %8, 1
|
||||
@@ -93,7 +95,7 @@ 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.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String", i64, i64)
|
||||
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringSlice"(%"github.com/goplus/llgo/internal/runtime.String", i64, i64)
|
||||
|
||||
declare { i32, i64 } @"unicode/utf8.DecodeRuneInString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
|
||||
@@ -98,42 +98,45 @@ _llgo_1: ; preds = %_llgo_4, %_llgo_0
|
||||
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.eface", ptr %6, i64 %3
|
||||
%8 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, align 8
|
||||
%9 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %8, 0
|
||||
%10 = load ptr, ptr @_llgo_int, align 8
|
||||
%11 = icmp eq ptr %9, %10
|
||||
br i1 %11, label %_llgo_4, label %_llgo_5
|
||||
%5 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
%7 = icmp slt i64 %3, 0
|
||||
%8 = icmp sge i64 %3, %6
|
||||
%9 = or i1 %8, %7
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %9)
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %5, i64 %3
|
||||
%11 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8
|
||||
%12 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %11, 0
|
||||
%13 = load ptr, ptr @_llgo_int, align 8
|
||||
%14 = icmp eq ptr %12, %13
|
||||
br i1 %14, label %_llgo_4, label %_llgo_5
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
ret void
|
||||
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
%12 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %8, 1
|
||||
%13 = ptrtoint ptr %12 to i64
|
||||
%14 = call i32 (ptr, ...) @printf(ptr @0, i64 %13)
|
||||
%15 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %11, 1
|
||||
%16 = ptrtoint ptr %15 to i64
|
||||
%17 = call i32 (ptr, ...) @printf(ptr @0, i64 %16)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_5: ; preds = %_llgo_2
|
||||
%15 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 0
|
||||
store ptr @1, ptr %16, align 8
|
||||
%17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 1
|
||||
store i64 21, ptr %17, align 4
|
||||
%18 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %15, align 8
|
||||
%19 = load ptr, ptr @_llgo_string, align 8
|
||||
%20 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" %18, ptr %20, align 8
|
||||
%21 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
||||
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %21, i32 0, i32 0
|
||||
store ptr %19, ptr %22, align 8
|
||||
%23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %21, i32 0, i32 1
|
||||
store ptr %20, ptr %23, align 8
|
||||
%24 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %21, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %24)
|
||||
%18 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %18, i32 0, i32 0
|
||||
store ptr @1, ptr %19, align 8
|
||||
%20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %18, i32 0, i32 1
|
||||
store i64 21, ptr %20, align 4
|
||||
%21 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %18, align 8
|
||||
%22 = load ptr, ptr @_llgo_string, align 8
|
||||
%23 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" %21, ptr %23, align 8
|
||||
%24 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
||||
%25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, i32 0, i32 0
|
||||
store ptr %22, ptr %25, align 8
|
||||
%26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, i32 0, i32 1
|
||||
store ptr %23, ptr %26, align 8
|
||||
%27 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %27)
|
||||
unreachable
|
||||
}
|
||||
|
||||
@@ -149,14 +152,14 @@ _llgo_0:
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
store ptr %2, ptr @_llgo_int, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 6
|
||||
%4 = load i8, ptr %3, align 1
|
||||
%5 = or i8 %4, 32
|
||||
store i8 %5, ptr %3, align 1
|
||||
store ptr %2, ptr @_llgo_int, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%6 = load ptr, ptr @_llgo_string, align 8
|
||||
%7 = icmp eq ptr %6, null
|
||||
br i1 %7, label %_llgo_3, label %_llgo_4
|
||||
|
||||
@@ -98,6 +98,22 @@ _llgo_0:
|
||||
ret void
|
||||
}
|
||||
|
||||
define i64 @"main.init#1$1"(i64 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = add i64 %0, %1
|
||||
ret i64 %2
|
||||
}
|
||||
|
||||
define void @"main.init#1$2"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { ptr }, ptr %0, align 8
|
||||
%2 = extractvalue { ptr } %1, 0
|
||||
%3 = load i64, ptr %2, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %3)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"main.init#2"() {
|
||||
_llgo_0:
|
||||
call void @main.assert(i1 true)
|
||||
@@ -556,14 +572,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
|
||||
_llgo_3: ; preds = %_llgo_2
|
||||
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
store ptr %5, ptr @_llgo_int, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %5, i32 0, i32 6
|
||||
%7 = load i8, ptr %6, align 1
|
||||
%8 = or i8 %7, 32
|
||||
store i8 %8, ptr %6, align 1
|
||||
store ptr %5, ptr @_llgo_int, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%9 = load ptr, ptr @"_llgo_struct$n1H8J_3prDN3firMwPxBLVTkE5hJ9Di-AqNvaC9jczw", align 8
|
||||
%10 = icmp eq ptr %9, null
|
||||
br i1 %10, label %_llgo_5, label %_llgo_6
|
||||
@@ -780,21 +796,9 @@ declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplu
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
define void @"main.init#1$2"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { ptr }, ptr %0, align 8
|
||||
%2 = extractvalue { ptr } %1, 0
|
||||
%3 = load i64, ptr %2, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %3)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
}
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
|
||||
|
||||
define i64 @"main.init#1$1"(i64 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = add i64 %0, %1
|
||||
ret i64 %2
|
||||
}
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)
|
||||
|
||||
@@ -815,7 +819,3 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.Interface"(%"github.com/go
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.InitNamed"(ptr, %"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.String", ptr, %"github.com/goplus/llgo/internal/runtime.Slice", %"github.com/goplus/llgo/internal/runtime.Slice")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
@@ -72,10 +72,6 @@ _llgo_3: ; preds = %_llgo_1, %_llgo_0
|
||||
br i1 %22, label %_llgo_2, label %_llgo_1
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
define void @"main.main$1"(ptr %0, %"github.com/goplus/llgo/internal/runtime.String" %1) {
|
||||
_llgo_0:
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %1)
|
||||
@@ -86,6 +82,10 @@ _llgo_0:
|
||||
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.AllocU"(i64)
|
||||
|
||||
declare ptr @malloc(i64)
|
||||
|
||||
@@ -677,14 +677,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
|
||||
_llgo_3: ; preds = %_llgo_2
|
||||
%25 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
store ptr %25, ptr @_llgo_int, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%26 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %25, i32 0, i32 6
|
||||
%27 = load i8, ptr %26, align 1
|
||||
%28 = or i8 %27, 32
|
||||
store i8 %28, ptr %26, align 1
|
||||
store ptr %25, ptr @_llgo_int, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%29 = load ptr, ptr @_llgo_int, align 8
|
||||
%30 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
%31 = icmp eq ptr %30, null
|
||||
|
||||
140
cl/_testgo/indexerr/in.go
Normal file
140
cl/_testgo/indexerr/in.go
Normal file
@@ -0,0 +1,140 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("array -1 must error")
|
||||
}
|
||||
}()
|
||||
array(-1)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("array 2 must error")
|
||||
}
|
||||
}()
|
||||
array(2)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("array2 must error")
|
||||
}
|
||||
}()
|
||||
array2(2)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("slice -1 must error")
|
||||
}
|
||||
}()
|
||||
slice(-1)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("slice 2 must error")
|
||||
}
|
||||
}()
|
||||
slice(2)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("slice2 2 must error")
|
||||
}
|
||||
}()
|
||||
slice2(2)
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("2 must error")
|
||||
}
|
||||
}()
|
||||
a := [...]int{1, 2}
|
||||
var n = -1
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("-1 must error")
|
||||
}
|
||||
}()
|
||||
a := [...]int{1, 2}
|
||||
var n = 2
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("2 must error")
|
||||
}
|
||||
}()
|
||||
a := [...]int{1, 2}
|
||||
var n uint = 2
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("2 must error")
|
||||
}
|
||||
}()
|
||||
a := []int{1, 2}
|
||||
var n = -1
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("-1 must error")
|
||||
}
|
||||
}()
|
||||
a := []int{1, 2}
|
||||
var n = 2
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
panic("2 must error")
|
||||
}
|
||||
}()
|
||||
a := []int{1, 2}
|
||||
var n uint = 2
|
||||
println(a[n])
|
||||
}
|
||||
|
||||
func array(n int) {
|
||||
println([...]int{1, 2}[n])
|
||||
}
|
||||
|
||||
func array2(n uint) {
|
||||
println([...]int{1, 2}[n])
|
||||
}
|
||||
|
||||
func slice(n int) {
|
||||
println([]int{1, 2}[n])
|
||||
}
|
||||
|
||||
func slice2(n int) {
|
||||
println([]int{1, 2}[n])
|
||||
}
|
||||
1
cl/_testgo/indexerr/out.ll
Normal file
1
cl/_testgo/indexerr/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
@@ -536,14 +536,14 @@ _llgo_6: ; preds = %_llgo_12, %_llgo_4
|
||||
|
||||
_llgo_7: ; preds = %_llgo_5
|
||||
%38 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
store ptr %38, ptr @_llgo_int, align 8
|
||||
br label %_llgo_8
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7, %_llgo_5
|
||||
%39 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %38, i32 0, i32 6
|
||||
%40 = load i8, ptr %39, align 1
|
||||
%41 = or i8 %40, 32
|
||||
store i8 %41, ptr %39, align 1
|
||||
store ptr %38, ptr @_llgo_int, align 8
|
||||
br label %_llgo_8
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7, %_llgo_5
|
||||
%42 = load ptr, ptr @_llgo_int, align 8
|
||||
%43 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
%44 = icmp eq ptr %43, null
|
||||
@@ -738,14 +738,14 @@ _llgo_16: ; preds = %_llgo_15, %_llgo_14
|
||||
|
||||
_llgo_17: ; preds = %_llgo_16
|
||||
%151 = call ptr @"github.com/goplus/llgo/internal/runtime.NewNamed"(i64 2, i64 1, i64 1)
|
||||
store ptr %151, ptr @_llgo_main.T1, align 8
|
||||
br label %_llgo_18
|
||||
|
||||
_llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||
%152 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %151, i32 0, i32 6
|
||||
%153 = load i8, ptr %152, align 1
|
||||
%154 = or i8 %153, 32
|
||||
store i8 %154, ptr %152, align 1
|
||||
store ptr %151, ptr @_llgo_main.T1, align 8
|
||||
br label %_llgo_18
|
||||
|
||||
_llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||
%155 = load ptr, ptr @_llgo_int, align 8
|
||||
br i1 %150, label %_llgo_19, label %_llgo_20
|
||||
|
||||
@@ -832,28 +832,28 @@ _llgo_22: ; preds = %_llgo_21, %_llgo_20
|
||||
|
||||
_llgo_23: ; preds = %_llgo_22
|
||||
%201 = call ptr @"github.com/goplus/llgo/internal/runtime.NewNamed"(i64 14, i64 1, i64 1)
|
||||
store ptr %201, ptr @_llgo_main.T2, align 8
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
%202 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %201, i32 0, i32 6
|
||||
%203 = load i8, ptr %202, align 1
|
||||
%204 = or i8 %203, 32
|
||||
store i8 %204, ptr %202, align 1
|
||||
store ptr %201, ptr @_llgo_main.T2, align 8
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
%205 = load ptr, ptr @_llgo_float64, align 8
|
||||
%206 = icmp eq ptr %205, null
|
||||
br i1 %206, label %_llgo_25, label %_llgo_26
|
||||
|
||||
_llgo_25: ; preds = %_llgo_24
|
||||
%207 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14)
|
||||
store ptr %207, ptr @_llgo_float64, align 8
|
||||
br label %_llgo_26
|
||||
|
||||
_llgo_26: ; preds = %_llgo_25, %_llgo_24
|
||||
%208 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %207, i32 0, i32 6
|
||||
%209 = load i8, ptr %208, align 1
|
||||
%210 = or i8 %209, 32
|
||||
store i8 %210, ptr %208, align 1
|
||||
store ptr %207, ptr @_llgo_float64, align 8
|
||||
br label %_llgo_26
|
||||
|
||||
_llgo_26: ; preds = %_llgo_25, %_llgo_24
|
||||
%211 = load ptr, ptr @_llgo_float64, align 8
|
||||
br i1 %200, label %_llgo_27, label %_llgo_28
|
||||
|
||||
@@ -940,28 +940,28 @@ _llgo_30: ; preds = %_llgo_29, %_llgo_28
|
||||
|
||||
_llgo_31: ; preds = %_llgo_30
|
||||
%257 = call ptr @"github.com/goplus/llgo/internal/runtime.NewNamed"(i64 3, i64 0, i64 1)
|
||||
store ptr %257, ptr @_llgo_main.T3, align 8
|
||||
br label %_llgo_32
|
||||
|
||||
_llgo_32: ; preds = %_llgo_31, %_llgo_30
|
||||
%258 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %257, i32 0, i32 6
|
||||
%259 = load i8, ptr %258, align 1
|
||||
%260 = or i8 %259, 32
|
||||
store i8 %260, ptr %258, align 1
|
||||
store ptr %257, ptr @_llgo_main.T3, align 8
|
||||
br label %_llgo_32
|
||||
|
||||
_llgo_32: ; preds = %_llgo_31, %_llgo_30
|
||||
%261 = load ptr, ptr @_llgo_int8, align 8
|
||||
%262 = icmp eq ptr %261, null
|
||||
br i1 %262, label %_llgo_33, label %_llgo_34
|
||||
|
||||
_llgo_33: ; preds = %_llgo_32
|
||||
%263 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3)
|
||||
store ptr %263, ptr @_llgo_int8, align 8
|
||||
br label %_llgo_34
|
||||
|
||||
_llgo_34: ; preds = %_llgo_33, %_llgo_32
|
||||
%264 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %263, i32 0, i32 6
|
||||
%265 = load i8, ptr %264, align 1
|
||||
%266 = or i8 %265, 32
|
||||
store i8 %266, ptr %264, align 1
|
||||
store ptr %263, ptr @_llgo_int8, align 8
|
||||
br label %_llgo_34
|
||||
|
||||
_llgo_34: ; preds = %_llgo_33, %_llgo_32
|
||||
%267 = load ptr, ptr @_llgo_int8, align 8
|
||||
br i1 %256, label %_llgo_35, label %_llgo_36
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -251,14 +251,14 @@ _llgo_0:
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
store ptr %2, ptr @_llgo_int, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 6
|
||||
%4 = load i8, ptr %3, align 1
|
||||
%5 = or i8 %4, 32
|
||||
store i8 %5, ptr %3, align 1
|
||||
store ptr %2, ptr @_llgo_int, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%6 = load ptr, ptr @_llgo_int, align 8
|
||||
%7 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 0
|
||||
@@ -291,11 +291,11 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
store i64 1, ptr %25, align 4
|
||||
%26 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %22, align 8
|
||||
%27 = call ptr @"github.com/goplus/llgo/internal/runtime.Struct"(%"github.com/goplus/llgo/internal/runtime.String" %19, i64 8, %"github.com/goplus/llgo/internal/runtime.Slice" %26)
|
||||
store ptr %27, ptr @"main.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88", align 8
|
||||
%28 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %27, i32 0, i32 6
|
||||
%29 = load i8, ptr %28, align 1
|
||||
%30 = or i8 %29, 32
|
||||
store i8 %30, ptr %28, align 1
|
||||
store ptr %27, ptr @"main.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88", align 8
|
||||
%31 = load ptr, ptr @_llgo_int, align 8
|
||||
%32 = load ptr, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", align 8
|
||||
%33 = icmp eq ptr %32, null
|
||||
@@ -333,14 +333,14 @@ _llgo_3: ; preds = %_llgo_2
|
||||
store i64 1, ptr %52, align 4
|
||||
%53 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %49, align 8
|
||||
%54 = call ptr @"github.com/goplus/llgo/internal/runtime.Struct"(%"github.com/goplus/llgo/internal/runtime.String" %46, i64 8, %"github.com/goplus/llgo/internal/runtime.Slice" %53)
|
||||
store ptr %54, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%55 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %54, i32 0, i32 6
|
||||
%56 = load i8, ptr %55, align 1
|
||||
%57 = or i8 %56, 32
|
||||
store i8 %57, ptr %55, align 1
|
||||
store ptr %54, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
ret void
|
||||
}
|
||||
|
||||
|
||||
@@ -197,14 +197,14 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
|
||||
_llgo_3: ; preds = %_llgo_2
|
||||
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8)
|
||||
store ptr %5, ptr @_llgo_byte, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %5, i32 0, i32 6
|
||||
%7 = load i8, ptr %6, align 1
|
||||
%8 = or i8 %7, 32
|
||||
store i8 %8, ptr %6, align 1
|
||||
store ptr %5, ptr @_llgo_byte, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%9 = load ptr, ptr @_llgo_byte, align 8
|
||||
%10 = load ptr, ptr @"*_llgo_byte", align 8
|
||||
%11 = icmp eq ptr %10, null
|
||||
@@ -223,14 +223,14 @@ _llgo_6: ; preds = %_llgo_5, %_llgo_4
|
||||
|
||||
_llgo_7: ; preds = %_llgo_6
|
||||
%16 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13)
|
||||
store ptr %16, ptr @_llgo_float32, align 8
|
||||
br label %_llgo_8
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7, %_llgo_6
|
||||
%17 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %16, i32 0, i32 6
|
||||
%18 = load i8, ptr %17, align 1
|
||||
%19 = or i8 %18, 32
|
||||
store i8 %19, ptr %17, align 1
|
||||
store ptr %16, ptr @_llgo_float32, align 8
|
||||
br label %_llgo_8
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7, %_llgo_6
|
||||
%20 = load ptr, ptr @_llgo_float32, align 8
|
||||
%21 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %21, i32 0, i32 0
|
||||
|
||||
18
cl/_testgo/tpindex/in.go
Normal file
18
cl/_testgo/tpindex/in.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
// The index function returns the index of the first occurrence of v in s,
|
||||
// or -1 if not present.
|
||||
func index[E comparable](s []E, v E) int {
|
||||
for i, vs := range s {
|
||||
if v == vs {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func main() {
|
||||
s := []int{1, 3, 5, 2, 4}
|
||||
println(index(s, 3))
|
||||
println(index(s, 6))
|
||||
}
|
||||
95
cl/_testgo/tpindex/out.ll
Normal file
95
cl/_testgo/tpindex/out.ll
Normal file
@@ -0,0 +1,95 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
|
||||
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 40)
|
||||
%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 3, ptr %4, align 4
|
||||
%5 = getelementptr inbounds i64, ptr %2, i64 2
|
||||
store i64 5, ptr %5, align 4
|
||||
%6 = getelementptr inbounds i64, ptr %2, i64 3
|
||||
store i64 2, ptr %6, align 4
|
||||
%7 = getelementptr inbounds i64, ptr %2, i64 4
|
||||
store i64 4, ptr %7, align 4
|
||||
%8 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %8, i32 0, i32 0
|
||||
store ptr %2, ptr %9, align 8
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %8, i32 0, i32 1
|
||||
store i64 5, ptr %10, align 4
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %8, i32 0, i32 2
|
||||
store i64 5, ptr %11, align 4
|
||||
%12 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %8, align 8
|
||||
%13 = call i64 @"main.index[int]"(%"github.com/goplus/llgo/internal/runtime.Slice" %12, i64 3)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %13)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%14 = call i64 @"main.index[int]"(%"github.com/goplus/llgo/internal/runtime.Slice" %12, i64 6)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %14)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
define i64 @"main.index[int]"(%"github.com/goplus/llgo/internal/runtime.Slice" %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%3 = phi i64 [ -1, %_llgo_0 ], [ %4, %_llgo_2 ]
|
||||
%4 = add i64 %3, 1
|
||||
%5 = icmp slt i64 %4, %2
|
||||
br i1 %5, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%7 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
%8 = icmp slt i64 %4, 0
|
||||
%9 = icmp sge i64 %4, %7
|
||||
%10 = or i1 %9, %8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %10)
|
||||
%11 = getelementptr inbounds i64, ptr %6, i64 %4
|
||||
%12 = load i64, ptr %11, align 4
|
||||
%13 = icmp eq i64 %1, %12
|
||||
br i1 %13, label %_llgo_4, label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
ret i64 -1
|
||||
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
ret i64 %4
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
36
cl/_testgo/tprecur/in.go
Normal file
36
cl/_testgo/tprecur/in.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
recursive()
|
||||
}
|
||||
|
||||
func recursive() {
|
||||
type T int
|
||||
if got, want := recur1[T](5), T(110); got != want {
|
||||
panic("error")
|
||||
}
|
||||
}
|
||||
|
||||
type Integer interface {
|
||||
~int | ~int32 | ~int64
|
||||
}
|
||||
|
||||
func recur1[T Integer](n T) T {
|
||||
if n == 0 || n == 1 {
|
||||
return T(1)
|
||||
} else {
|
||||
return n * recur2(n-1)
|
||||
}
|
||||
}
|
||||
|
||||
func recur2[T Integer](n T) T {
|
||||
list := make([]T, n)
|
||||
for i, _ := range list {
|
||||
list[i] = T(i + 1)
|
||||
}
|
||||
var sum T
|
||||
for _, elt := range list {
|
||||
sum += elt
|
||||
}
|
||||
return sum + recur1(n-1)
|
||||
}
|
||||
174
cl/_testgo/tprecur/out.ll
Normal file
174
cl/_testgo/tprecur/out.ll
Normal file
@@ -0,0 +1,174 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr }
|
||||
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [5 x i8] c"error", align 1
|
||||
@_llgo_string = linkonce global ptr null, align 8
|
||||
|
||||
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 @"main.init$after"()
|
||||
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.recursive()
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
define void @main.recursive() {
|
||||
_llgo_0:
|
||||
%0 = call i64 @"main.recur1[main.T]"(i64 5)
|
||||
%1 = icmp ne i64 %0, 110
|
||||
br i1 %1, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 0
|
||||
store ptr @0, ptr %3, align 8
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1
|
||||
store i64 5, ptr %4, align 4
|
||||
%5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8
|
||||
%6 = load ptr, ptr @_llgo_string, align 8
|
||||
%7 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" %5, ptr %7, align 8
|
||||
%8 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %8, i32 0, i32 0
|
||||
store ptr %6, ptr %9, align 8
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %8, i32 0, i32 1
|
||||
store ptr %7, ptr %10, align 8
|
||||
%11 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %8, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %11)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
define i64 @"main.recur1[main.T]"(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = icmp eq i64 %0, 0
|
||||
br i1 %1, label %_llgo_1, label %_llgo_3
|
||||
|
||||
_llgo_1: ; preds = %_llgo_3, %_llgo_0
|
||||
ret i64 1
|
||||
|
||||
_llgo_2: ; preds = %_llgo_3
|
||||
%2 = sub i64 %0, 1
|
||||
%3 = call i64 @"main.recur2[main.T]"(i64 %2)
|
||||
%4 = mul i64 %0, %3
|
||||
ret i64 %4
|
||||
|
||||
_llgo_3: ; preds = %_llgo_0
|
||||
%5 = icmp eq i64 %0, 1
|
||||
br i1 %5, label %_llgo_1, label %_llgo_2
|
||||
}
|
||||
|
||||
define void @"main.init$after"() {
|
||||
_llgo_0:
|
||||
%0 = load ptr, ptr @_llgo_string, align 8
|
||||
%1 = icmp eq ptr %0, null
|
||||
br i1 %1, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24)
|
||||
store ptr %2, ptr @_llgo_string, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface")
|
||||
|
||||
define i64 @"main.recur2[main.T]"(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = mul i64 %0, 8
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 %1)
|
||||
%3 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %3, i32 0, i32 0
|
||||
store ptr %2, ptr %4, align 8
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %3, i32 0, i32 1
|
||||
store i64 %0, ptr %5, align 4
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %3, i32 0, i32 2
|
||||
store i64 %0, ptr %6, align 4
|
||||
%7 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %3, align 8
|
||||
%8 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 1
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%9 = phi i64 [ -1, %_llgo_0 ], [ %10, %_llgo_2 ]
|
||||
%10 = add i64 %9, 1
|
||||
%11 = icmp slt i64 %10, %8
|
||||
br i1 %11, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%12 = add i64 %10, 1
|
||||
%13 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
|
||||
%14 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 1
|
||||
%15 = icmp slt i64 %10, 0
|
||||
%16 = icmp sge i64 %10, %14
|
||||
%17 = or i1 %16, %15
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %17)
|
||||
%18 = getelementptr inbounds i64, ptr %13, i64 %10
|
||||
store i64 %12, ptr %18, align 4
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
%19 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 1
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_5, %_llgo_3
|
||||
%20 = phi i64 [ 0, %_llgo_3 ], [ %31, %_llgo_5 ]
|
||||
%21 = phi i64 [ -1, %_llgo_3 ], [ %22, %_llgo_5 ]
|
||||
%22 = add i64 %21, 1
|
||||
%23 = icmp slt i64 %22, %19
|
||||
br i1 %23, label %_llgo_5, label %_llgo_6
|
||||
|
||||
_llgo_5: ; preds = %_llgo_4
|
||||
%24 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0
|
||||
%25 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 1
|
||||
%26 = icmp slt i64 %22, 0
|
||||
%27 = icmp sge i64 %22, %25
|
||||
%28 = or i1 %27, %26
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %28)
|
||||
%29 = getelementptr inbounds i64, ptr %24, i64 %22
|
||||
%30 = load i64, ptr %29, align 4
|
||||
%31 = add i64 %20, %30
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_6: ; preds = %_llgo_4
|
||||
%32 = sub i64 %0, 1
|
||||
%33 = call i64 @"main.recur1[main.T]"(i64 %32)
|
||||
%34 = add i64 %20, %33
|
||||
ret i64 %34
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
63
cl/_testgo/tptypes/in.go
Normal file
63
cl/_testgo/tptypes/in.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
type Data[T any] struct {
|
||||
v T
|
||||
}
|
||||
|
||||
func (p *Data[T]) Set(v T) {
|
||||
p.v = v
|
||||
}
|
||||
|
||||
func (p *(Data[T1])) Set2(v T1) {
|
||||
p.v = v
|
||||
}
|
||||
|
||||
type sliceOf[E any] interface {
|
||||
~[]E
|
||||
}
|
||||
|
||||
type Slice[S sliceOf[T], T any] struct {
|
||||
Data S
|
||||
}
|
||||
|
||||
func (p *Slice[S, T]) Append(t ...T) S {
|
||||
p.Data = append(p.Data, t...)
|
||||
return p.Data
|
||||
}
|
||||
|
||||
func (p *Slice[S1, T1]) Append2(t ...T1) S1 {
|
||||
p.Data = append(p.Data, t...)
|
||||
return p.Data
|
||||
}
|
||||
|
||||
type (
|
||||
DataInt = Data[int]
|
||||
SliceInt = Slice[[]int, int]
|
||||
DataString = Data[string]
|
||||
SliceString = Slice[[]string, string]
|
||||
)
|
||||
|
||||
func main() {
|
||||
println(DataInt{1}.v)
|
||||
println(DataString{"hello"}.v)
|
||||
println(Data[int]{100}.v)
|
||||
println(Data[string]{"hello"}.v)
|
||||
|
||||
// TODO
|
||||
println(Data[struct {
|
||||
X int
|
||||
Y int
|
||||
}]{}.v.X)
|
||||
|
||||
v1 := SliceInt{}
|
||||
v1.Append(100)
|
||||
v2 := SliceString{}
|
||||
v2.Append("hello")
|
||||
v3 := Slice[[]int, int]{}
|
||||
v3.Append([]int{1, 2, 3, 4}...)
|
||||
v3.Append2([]int{1, 2, 3, 4}...)
|
||||
|
||||
println(v1.Data, v1.Data[0])
|
||||
println(v2.Data, v2.Data[0])
|
||||
println(v3.Data, v3.Data[0])
|
||||
}
|
||||
253
cl/_testgo/tptypes/out.ll
Normal file
253
cl/_testgo/tptypes/out.ll
Normal file
@@ -0,0 +1,253 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"main.Data[int]" = type { i64 }
|
||||
%"main.Data[string]" = type { %"github.com/goplus/llgo/internal/runtime.String" }
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
|
||||
%"main.Slice[[]int, int]" = type { %"github.com/goplus/llgo/internal/runtime.Slice" }
|
||||
%"main.Slice[[]string, string]" = type { %"github.com/goplus/llgo/internal/runtime.Slice" }
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [5 x i8] c"hello", 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.Data[int]", align 8
|
||||
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %2, i64 8)
|
||||
%4 = getelementptr inbounds %"main.Data[int]", ptr %3, i32 0, i32 0
|
||||
store i64 1, ptr %4, align 4
|
||||
%5 = load %"main.Data[int]", ptr %3, align 4
|
||||
%6 = extractvalue %"main.Data[int]" %5, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %6)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%7 = alloca %"main.Data[string]", align 8
|
||||
%8 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %7, i64 16)
|
||||
%9 = getelementptr inbounds %"main.Data[string]", ptr %8, i32 0, i32 0
|
||||
%10 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 0
|
||||
store ptr @0, ptr %11, align 8
|
||||
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 1
|
||||
store i64 5, ptr %12, align 4
|
||||
%13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %10, align 8
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" %13, ptr %9, align 8
|
||||
%14 = load %"main.Data[string]", ptr %8, align 8
|
||||
%15 = extractvalue %"main.Data[string]" %14, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %15)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%16 = alloca %"main.Data[int]", align 8
|
||||
%17 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %16, i64 8)
|
||||
%18 = getelementptr inbounds %"main.Data[int]", ptr %17, i32 0, i32 0
|
||||
store i64 100, ptr %18, align 4
|
||||
%19 = load %"main.Data[int]", ptr %17, align 4
|
||||
%20 = extractvalue %"main.Data[int]" %19, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %20)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%21 = alloca %"main.Data[string]", align 8
|
||||
%22 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %21, i64 16)
|
||||
%23 = getelementptr inbounds %"main.Data[string]", ptr %22, i32 0, i32 0
|
||||
%24 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 0
|
||||
store ptr @0, ptr %25, align 8
|
||||
%26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 1
|
||||
store i64 5, ptr %26, align 4
|
||||
%27 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %24, align 8
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" %27, ptr %23, align 8
|
||||
%28 = load %"main.Data[string]", ptr %22, align 8
|
||||
%29 = extractvalue %"main.Data[string]" %28, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %29)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 0)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%30 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 24)
|
||||
%31 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 8)
|
||||
%32 = getelementptr inbounds i64, ptr %31, i64 0
|
||||
store i64 100, ptr %32, align 4
|
||||
%33 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%34 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %33, i32 0, i32 0
|
||||
store ptr %31, ptr %34, align 8
|
||||
%35 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %33, i32 0, i32 1
|
||||
store i64 1, ptr %35, align 4
|
||||
%36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %33, i32 0, i32 2
|
||||
store i64 1, ptr %36, align 4
|
||||
%37 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %33, align 8
|
||||
%38 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"main.(*Slice).Append[[]int, int]"(ptr %30, %"github.com/goplus/llgo/internal/runtime.Slice" %37)
|
||||
%39 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 24)
|
||||
%40 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16)
|
||||
%41 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %40, i64 0
|
||||
%42 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%43 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %42, i32 0, i32 0
|
||||
store ptr @0, ptr %43, align 8
|
||||
%44 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %42, i32 0, i32 1
|
||||
store i64 5, ptr %44, align 4
|
||||
%45 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %42, align 8
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" %45, ptr %41, align 8
|
||||
%46 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%47 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %46, i32 0, i32 0
|
||||
store ptr %40, ptr %47, align 8
|
||||
%48 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %46, i32 0, i32 1
|
||||
store i64 1, ptr %48, align 4
|
||||
%49 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %46, i32 0, i32 2
|
||||
store i64 1, ptr %49, align 4
|
||||
%50 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %46, align 8
|
||||
%51 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"main.(*Slice).Append[[]string, string]"(ptr %39, %"github.com/goplus/llgo/internal/runtime.Slice" %50)
|
||||
%52 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 24)
|
||||
%53 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
|
||||
%54 = getelementptr inbounds i64, ptr %53, i64 0
|
||||
store i64 1, ptr %54, align 4
|
||||
%55 = getelementptr inbounds i64, ptr %53, i64 1
|
||||
store i64 2, ptr %55, align 4
|
||||
%56 = getelementptr inbounds i64, ptr %53, i64 2
|
||||
store i64 3, ptr %56, align 4
|
||||
%57 = getelementptr inbounds i64, ptr %53, i64 3
|
||||
store i64 4, ptr %57, align 4
|
||||
%58 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%59 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %58, i32 0, i32 0
|
||||
store ptr %53, ptr %59, align 8
|
||||
%60 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %58, i32 0, i32 1
|
||||
store i64 4, ptr %60, align 4
|
||||
%61 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %58, i32 0, i32 2
|
||||
store i64 4, ptr %61, align 4
|
||||
%62 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %58, align 8
|
||||
%63 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"main.(*Slice).Append[[]int, int]"(ptr %52, %"github.com/goplus/llgo/internal/runtime.Slice" %62)
|
||||
%64 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
|
||||
%65 = getelementptr inbounds i64, ptr %64, i64 0
|
||||
store i64 1, ptr %65, align 4
|
||||
%66 = getelementptr inbounds i64, ptr %64, i64 1
|
||||
store i64 2, ptr %66, align 4
|
||||
%67 = getelementptr inbounds i64, ptr %64, i64 2
|
||||
store i64 3, ptr %67, align 4
|
||||
%68 = getelementptr inbounds i64, ptr %64, i64 3
|
||||
store i64 4, ptr %68, align 4
|
||||
%69 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%70 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %69, i32 0, i32 0
|
||||
store ptr %64, ptr %70, align 8
|
||||
%71 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %69, i32 0, i32 1
|
||||
store i64 4, ptr %71, align 4
|
||||
%72 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %69, i32 0, i32 2
|
||||
store i64 4, ptr %72, align 4
|
||||
%73 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %69, align 8
|
||||
%74 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"main.(*Slice).Append2[[]int, int]"(ptr %52, %"github.com/goplus/llgo/internal/runtime.Slice" %73)
|
||||
%75 = getelementptr inbounds %"main.Slice[[]int, int]", ptr %30, i32 0, i32 0
|
||||
%76 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %75, align 8
|
||||
%77 = getelementptr inbounds %"main.Slice[[]int, int]", ptr %30, i32 0, i32 0
|
||||
%78 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %77, align 8
|
||||
%79 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %78, 0
|
||||
%80 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %78, 1
|
||||
%81 = icmp sge i64 0, %80
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %81)
|
||||
%82 = getelementptr inbounds i64, ptr %79, i64 0
|
||||
%83 = load i64, ptr %82, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %76)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %83)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%84 = getelementptr inbounds %"main.Slice[[]string, string]", ptr %39, i32 0, i32 0
|
||||
%85 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %84, align 8
|
||||
%86 = getelementptr inbounds %"main.Slice[[]string, string]", ptr %39, i32 0, i32 0
|
||||
%87 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %86, align 8
|
||||
%88 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %87, 0
|
||||
%89 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %87, 1
|
||||
%90 = icmp sge i64 0, %89
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %90)
|
||||
%91 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %88, i64 0
|
||||
%92 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %91, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %85)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %92)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%93 = getelementptr inbounds %"main.Slice[[]int, int]", ptr %52, i32 0, i32 0
|
||||
%94 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %93, align 8
|
||||
%95 = getelementptr inbounds %"main.Slice[[]int, int]", ptr %52, i32 0, i32 0
|
||||
%96 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %95, align 8
|
||||
%97 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %96, 0
|
||||
%98 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %96, 1
|
||||
%99 = icmp sge i64 0, %98
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %99)
|
||||
%100 = getelementptr inbounds i64, ptr %97, i64 0
|
||||
%101 = load i64, ptr %100, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %94)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %101)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
define %"github.com/goplus/llgo/internal/runtime.Slice" @"main.(*Slice).Append[[]int, int]"(ptr %0, %"github.com/goplus/llgo/internal/runtime.Slice" %1) {
|
||||
_llgo_0:
|
||||
%2 = getelementptr inbounds %"main.Slice[[]int, int]", ptr %0, i32 0, i32 0
|
||||
%3 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %2, align 8
|
||||
%4 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %1, 0
|
||||
%5 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %1, 1
|
||||
%6 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice" %3, ptr %4, i64 %5, i64 8)
|
||||
%7 = getelementptr inbounds %"main.Slice[[]int, int]", ptr %0, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/internal/runtime.Slice" %6, ptr %7, align 8
|
||||
%8 = getelementptr inbounds %"main.Slice[[]int, int]", ptr %0, i32 0, i32 0
|
||||
%9 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %8, align 8
|
||||
ret %"github.com/goplus/llgo/internal/runtime.Slice" %9
|
||||
}
|
||||
|
||||
define %"github.com/goplus/llgo/internal/runtime.Slice" @"main.(*Slice).Append[[]string, string]"(ptr %0, %"github.com/goplus/llgo/internal/runtime.Slice" %1) {
|
||||
_llgo_0:
|
||||
%2 = getelementptr inbounds %"main.Slice[[]string, string]", ptr %0, i32 0, i32 0
|
||||
%3 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %2, align 8
|
||||
%4 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %1, 0
|
||||
%5 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %1, 1
|
||||
%6 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice" %3, ptr %4, i64 %5, i64 16)
|
||||
%7 = getelementptr inbounds %"main.Slice[[]string, string]", ptr %0, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/internal/runtime.Slice" %6, ptr %7, align 8
|
||||
%8 = getelementptr inbounds %"main.Slice[[]string, string]", ptr %0, i32 0, i32 0
|
||||
%9 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %8, align 8
|
||||
ret %"github.com/goplus/llgo/internal/runtime.Slice" %9
|
||||
}
|
||||
|
||||
define %"github.com/goplus/llgo/internal/runtime.Slice" @"main.(*Slice).Append2[[]int, int]"(ptr %0, %"github.com/goplus/llgo/internal/runtime.Slice" %1) {
|
||||
_llgo_0:
|
||||
%2 = getelementptr inbounds %"main.Slice[[]int, int]", ptr %0, i32 0, i32 0
|
||||
%3 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %2, align 8
|
||||
%4 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %1, 0
|
||||
%5 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %1, 1
|
||||
%6 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice" %3, ptr %4, i64 %5, i64 8)
|
||||
%7 = getelementptr inbounds %"main.Slice[[]int, int]", ptr %0, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/internal/runtime.Slice" %6, ptr %7, align 8
|
||||
%8 = getelementptr inbounds %"main.Slice[[]int, int]", ptr %0, i32 0, i32 0
|
||||
%9 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %8, align 8
|
||||
ret %"github.com/goplus/llgo/internal/runtime.Slice" %9
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice")
|
||||
|
||||
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)
|
||||
25
cl/_testlibc/atomic/in.go
Normal file
25
cl/_testlibc/atomic/in.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/sync/atomic"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var v int64
|
||||
|
||||
atomic.Store(&v, 100)
|
||||
c.Printf(c.Str("store: %ld\n"), atomic.Load(&v))
|
||||
|
||||
ret := atomic.Add(&v, 1)
|
||||
c.Printf(c.Str("ret: %ld, v: %ld\n"), ret, v)
|
||||
|
||||
ret, _ = atomic.CompareAndExchange(&v, 100, 102)
|
||||
c.Printf(c.Str("ret: %ld vs 100, v: %ld\n"), ret, v)
|
||||
|
||||
ret, _ = atomic.CompareAndExchange(&v, 101, 102)
|
||||
c.Printf(c.Str("ret: %ld vs 101, v: %ld\n"), ret, v)
|
||||
|
||||
ret = atomic.Sub(&v, 1)
|
||||
c.Printf(c.Str("ret: %ld, v: %ld\n"), ret, v)
|
||||
}
|
||||
59
cl/_testlibc/atomic/out.ll
Normal file
59
cl/_testlibc/atomic/out.ll
Normal file
@@ -0,0 +1,59 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [12 x i8] c"store: %ld\0A\00", align 1
|
||||
@1 = private unnamed_addr constant [18 x i8] c"ret: %ld, v: %ld\0A\00", align 1
|
||||
@2 = private unnamed_addr constant [25 x i8] c"ret: %ld vs 100, v: %ld\0A\00", align 1
|
||||
@3 = private unnamed_addr constant [25 x i8] c"ret: %ld vs 101, v: %ld\0A\00", align 1
|
||||
@4 = private unnamed_addr constant [18 x i8] c"ret: %ld, v: %ld\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 8)
|
||||
store atomic i64 100, ptr %2 seq_cst, align 4
|
||||
%3 = load atomic i64, ptr %2 seq_cst, align 4
|
||||
%4 = call i32 (ptr, ...) @printf(ptr @0, i64 %3)
|
||||
%5 = atomicrmw add ptr %2, i64 1 seq_cst, align 8
|
||||
%6 = load i64, ptr %2, align 4
|
||||
%7 = call i32 (ptr, ...) @printf(ptr @1, i64 %5, i64 %6)
|
||||
%8 = cmpxchg ptr %2, i64 100, i64 102 seq_cst seq_cst, align 8
|
||||
%9 = extractvalue { i64, i1 } %8, 0
|
||||
%10 = extractvalue { i64, i1 } %8, 1
|
||||
%11 = load i64, ptr %2, align 4
|
||||
%12 = call i32 (ptr, ...) @printf(ptr @2, i64 %9, i64 %11)
|
||||
%13 = cmpxchg ptr %2, i64 101, i64 102 seq_cst seq_cst, align 8
|
||||
%14 = extractvalue { i64, i1 } %13, 0
|
||||
%15 = extractvalue { i64, i1 } %13, 1
|
||||
%16 = load i64, ptr %2, align 4
|
||||
%17 = call i32 (ptr, ...) @printf(ptr @3, i64 %14, i64 %16)
|
||||
%18 = atomicrmw sub ptr %2, i64 1 seq_cst, align 8
|
||||
%19 = load i64, ptr %2, align 4
|
||||
%20 = call i32 (ptr, ...) @printf(ptr @4, i64 %18, i64 %19)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
21
cl/_testlibc/complex/in.go
Normal file
21
cl/_testlibc/complex/in.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/math/cmplx"
|
||||
)
|
||||
|
||||
func f(c, z complex64, addr c.Pointer) {
|
||||
println("addr:", addr)
|
||||
println("abs(3+4i):", cmplx.Absf(c))
|
||||
println("real(3+4i):", real(z))
|
||||
println("imag(3+4i):", imag(z))
|
||||
}
|
||||
|
||||
func main() {
|
||||
re := float32(3.0)
|
||||
im := float32(4.0)
|
||||
z := complex64(3 + 4i)
|
||||
x := complex(re, im)
|
||||
f(x, z, c.Func(f))
|
||||
}
|
||||
104
cl/_testlibc/complex/out.ll
Normal file
104
cl/_testlibc/complex/out.ll
Normal file
@@ -0,0 +1,104 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@0 = private unnamed_addr constant [5 x i8] c"addr:", align 1
|
||||
@1 = private unnamed_addr constant [10 x i8] c"abs(3+4i):", align 1
|
||||
@2 = private unnamed_addr constant [11 x i8] c"real(3+4i):", align 1
|
||||
@3 = private unnamed_addr constant [11 x i8] c"imag(3+4i):", align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
|
||||
define void @main.f({ float, float } %0, { float, float } %1, ptr %2) {
|
||||
_llgo_0:
|
||||
%3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 0
|
||||
store ptr @0, ptr %4, align 8
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1
|
||||
store i64 5, ptr %5, align 4
|
||||
%6 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %3, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %6)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr %2)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%7 = call float @cabsf({ float, float } %0)
|
||||
%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 @1, ptr %9, align 8
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %8, i32 0, i32 1
|
||||
store i64 10, ptr %10, align 4
|
||||
%11 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %8, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %11)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
%12 = fpext float %7 to double
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %12)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%13 = extractvalue { float, float } %1, 0
|
||||
%14 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i32 0, i32 0
|
||||
store ptr @2, ptr %15, align 8
|
||||
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i32 0, i32 1
|
||||
store i64 11, ptr %16, align 4
|
||||
%17 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %14, align 8
|
||||
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.PrintByte"(i8 32)
|
||||
%18 = fpext float %13 to double
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %18)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%19 = extractvalue { float, float } %1, 1
|
||||
%20 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %20, i32 0, i32 0
|
||||
store ptr @3, ptr %21, align 8
|
||||
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %20, i32 0, i32 1
|
||||
store i64 11, ptr %22, align 4
|
||||
%23 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %20, align 8
|
||||
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.PrintByte"(i8 32)
|
||||
%24 = fpext float %19 to double
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %24)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
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 { float, float }, align 8
|
||||
%3 = getelementptr inbounds { float, float }, ptr %2, i32 0, i32 0
|
||||
store float 3.000000e+00, ptr %3, align 4
|
||||
%4 = getelementptr inbounds { float, float }, ptr %2, i32 0, i32 1
|
||||
store float 4.000000e+00, ptr %4, align 4
|
||||
%5 = load { float, float }, ptr %2, align 4
|
||||
call void @main.f({ float, float } %5, { float, float } { float 3.000000e+00, float 4.000000e+00 }, ptr @main.f)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr)
|
||||
|
||||
declare float @cabsf({ float, float })
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
21
cl/_testlibc/once/in.go
Normal file
21
cl/_testlibc/once/in.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/c/pthread/sync"
|
||||
)
|
||||
|
||||
var once sync.Once = sync.OnceInit
|
||||
|
||||
func f() {
|
||||
once.Do(func() {
|
||||
c.Printf(c.Str("Do once\n"))
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
println(c.GoString(c.Str("sync.Once demo\n"), 9))
|
||||
println(c.GoString(c.Str("sync.Once demo\n")))
|
||||
f()
|
||||
f()
|
||||
}
|
||||
1
cl/_testlibc/once/out.ll
Normal file
1
cl/_testlibc/once/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
@@ -8,8 +8,8 @@ func main() {
|
||||
jb := c.AllocaSigjmpBuf()
|
||||
switch ret := c.Sigsetjmp(jb, 0); ret {
|
||||
case 0:
|
||||
cstr := c.Str("?Hello, setjmp!\n")
|
||||
c.Fprintf(c.Stderr, c.Advance(cstr, 1))
|
||||
cstr := c.Str("??Hello, setjmp!\n")
|
||||
c.Fprintf(c.Stderr, c.Str("%s"), c.Advance(c.Pointer(c.Advance(cstr, 1)), 1))
|
||||
c.Siglongjmp(jb, 1)
|
||||
default:
|
||||
println("exception:", ret)
|
||||
|
||||
24
cl/_testlibgo/atomic/in.go
Normal file
24
cl/_testlibgo/atomic/in.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var v int64
|
||||
|
||||
atomic.StoreInt64(&v, 100)
|
||||
println("store:", atomic.LoadInt64(&v))
|
||||
|
||||
ret := atomic.AddInt64(&v, 1)
|
||||
println("ret:", ret, "v:", v)
|
||||
|
||||
swp := atomic.CompareAndSwapInt64(&v, 100, 102)
|
||||
println("swp:", swp, "v:", v)
|
||||
|
||||
swp = atomic.CompareAndSwapInt64(&v, 101, 102)
|
||||
println("swp:", swp, "v:", v)
|
||||
|
||||
ret = atomic.AddInt64(&v, -1)
|
||||
println("ret:", ret, "v:", v)
|
||||
}
|
||||
158
cl/_testlibgo/atomic/out.ll
Normal file
158
cl/_testlibgo/atomic/out.ll
Normal file
@@ -0,0 +1,158 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [6 x i8] c"store:", align 1
|
||||
@1 = private unnamed_addr constant [4 x i8] c"ret:", align 1
|
||||
@2 = private unnamed_addr constant [2 x i8] c"v:", align 1
|
||||
@3 = private unnamed_addr constant [4 x i8] c"swp:", 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 @"sync/atomic.init"()
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 8)
|
||||
call void @"sync/atomic.StoreInt64"(ptr %2, i64 100)
|
||||
%3 = call i64 @"sync/atomic.LoadInt64"(ptr %2)
|
||||
%4 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 0
|
||||
store ptr @0, ptr %5, align 8
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1
|
||||
store i64 6, ptr %6, align 4
|
||||
%7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %7)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %3)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%8 = call i64 @"sync/atomic.AddInt64"(ptr %2, i64 1)
|
||||
%9 = load i64, ptr %2, align 4
|
||||
%10 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 0
|
||||
store ptr @1, ptr %11, align 8
|
||||
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 1
|
||||
store i64 4, ptr %12, align 4
|
||||
%13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %10, align 8
|
||||
%14 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i32 0, i32 0
|
||||
store ptr @2, ptr %15, align 8
|
||||
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i32 0, i32 1
|
||||
store i64 2, ptr %16, align 4
|
||||
%17 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %14, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %13)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %8)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
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.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %9)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%18 = call i1 @"sync/atomic.CompareAndSwapInt64"(ptr %2, i64 100, i64 102)
|
||||
%19 = load i64, ptr %2, align 4
|
||||
%20 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %20, i32 0, i32 0
|
||||
store ptr @3, ptr %21, align 8
|
||||
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %20, i32 0, i32 1
|
||||
store i64 4, ptr %22, align 4
|
||||
%23 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %20, align 8
|
||||
%24 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 0
|
||||
store ptr @2, ptr %25, align 8
|
||||
%26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 1
|
||||
store i64 2, ptr %26, align 4
|
||||
%27 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %24, align 8
|
||||
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.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %18)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
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.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %19)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%28 = call i1 @"sync/atomic.CompareAndSwapInt64"(ptr %2, i64 101, i64 102)
|
||||
%29 = load i64, ptr %2, align 4
|
||||
%30 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%31 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %30, i32 0, i32 0
|
||||
store ptr @3, ptr %31, align 8
|
||||
%32 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %30, i32 0, i32 1
|
||||
store i64 4, ptr %32, align 4
|
||||
%33 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %30, align 8
|
||||
%34 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%35 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %34, i32 0, i32 0
|
||||
store ptr @2, ptr %35, align 8
|
||||
%36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %34, i32 0, i32 1
|
||||
store i64 2, ptr %36, align 4
|
||||
%37 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %34, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %33)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %28)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %37)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %29)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%38 = call i64 @"sync/atomic.AddInt64"(ptr %2, i64 -1)
|
||||
%39 = load i64, ptr %2, align 4
|
||||
%40 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%41 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %40, i32 0, i32 0
|
||||
store ptr @1, ptr %41, align 8
|
||||
%42 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %40, i32 0, i32 1
|
||||
store i64 4, ptr %42, align 4
|
||||
%43 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %40, align 8
|
||||
%44 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%45 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %44, i32 0, i32 0
|
||||
store ptr @2, ptr %45, align 8
|
||||
%46 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %44, i32 0, i32 1
|
||||
store i64 2, ptr %46, align 4
|
||||
%47 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %44, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %43)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %38)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %47)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %39)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"sync/atomic.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare void @"sync/atomic.StoreInt64"(ptr, i64)
|
||||
|
||||
declare i64 @"sync/atomic.LoadInt64"(ptr)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
|
||||
|
||||
declare i64 @"sync/atomic.AddInt64"(ptr, i64)
|
||||
|
||||
declare i1 @"sync/atomic.CompareAndSwapInt64"(ptr, i64, i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1)
|
||||
19
cl/_testlibgo/complex/in.go
Normal file
19
cl/_testlibgo/complex/in.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math/cmplx"
|
||||
)
|
||||
|
||||
func f(c, z complex128) {
|
||||
println("abs(3+4i):", cmplx.Abs(c))
|
||||
println("real(3+4i):", real(z))
|
||||
println("imag(3+4i):", imag(z))
|
||||
}
|
||||
|
||||
func main() {
|
||||
re := 3.0
|
||||
im := 4.0
|
||||
z := 3 + 4i
|
||||
c := complex(re, im)
|
||||
f(c, z)
|
||||
}
|
||||
91
cl/_testlibgo/complex/out.ll
Normal file
91
cl/_testlibgo/complex/out.ll
Normal file
@@ -0,0 +1,91 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@0 = private unnamed_addr constant [10 x i8] c"abs(3+4i):", align 1
|
||||
@1 = private unnamed_addr constant [11 x i8] c"real(3+4i):", align 1
|
||||
@2 = private unnamed_addr constant [11 x i8] c"imag(3+4i):", align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
|
||||
define void @main.f({ double, double } %0, { double, double } %1) {
|
||||
_llgo_0:
|
||||
%2 = call double @"math/cmplx.Abs"({ double, double } %0)
|
||||
%3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 0
|
||||
store ptr @0, ptr %4, align 8
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1
|
||||
store i64 10, ptr %5, align 4
|
||||
%6 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %3, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %6)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %2)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%7 = extractvalue { double, double } %1, 0
|
||||
%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 @1, ptr %9, align 8
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %8, i32 0, i32 1
|
||||
store i64 11, ptr %10, align 4
|
||||
%11 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %8, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %11)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %7)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%12 = extractvalue { double, double } %1, 1
|
||||
%13 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %13, i32 0, i32 0
|
||||
store ptr @2, ptr %14, align 8
|
||||
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %13, i32 0, i32 1
|
||||
store i64 11, ptr %15, align 4
|
||||
%16 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %13, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %16)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %12)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
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
|
||||
call void @"math/cmplx.init"()
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = alloca { double, double }, align 8
|
||||
%3 = getelementptr inbounds { double, double }, ptr %2, i32 0, i32 0
|
||||
store double 3.000000e+00, ptr %3, align 8
|
||||
%4 = getelementptr inbounds { double, double }, ptr %2, i32 0, i32 1
|
||||
store double 4.000000e+00, ptr %4, align 8
|
||||
%5 = load { double, double }, ptr %2, align 8
|
||||
call void @main.f({ double, double } %5, { double, double } { double 3.000000e+00, double 4.000000e+00 })
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare double @"math/cmplx.Abs"({ double, double })
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double)
|
||||
|
||||
declare void @"math/cmplx.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
8
cl/_testlibgo/errors/in.go
Normal file
8
cl/_testlibgo/errors/in.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package main
|
||||
|
||||
import "errors"
|
||||
|
||||
func main() {
|
||||
err := errors.New("error")
|
||||
panic(err)
|
||||
}
|
||||
60
cl/_testlibgo/errors/out.ll
Normal file
60
cl/_testlibgo/errors/out.ll
Normal file
@@ -0,0 +1,60 @@
|
||||
; 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 }
|
||||
%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr }
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [5 x i8] c"error", 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 @errors.init()
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 0
|
||||
store ptr @0, ptr %3, align 8
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1
|
||||
store i64 5, ptr %4, align 4
|
||||
%5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8
|
||||
%6 = call %"github.com/goplus/llgo/internal/runtime.iface" @errors.New(%"github.com/goplus/llgo/internal/runtime.String" %5)
|
||||
%7 = call ptr @"github.com/goplus/llgo/internal/runtime.IfaceType"(%"github.com/goplus/llgo/internal/runtime.iface" %6)
|
||||
%8 = extractvalue %"github.com/goplus/llgo/internal/runtime.iface" %6, 1
|
||||
%9 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %9, i32 0, i32 0
|
||||
store ptr %7, ptr %10, align 8
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %9, i32 0, i32 1
|
||||
store ptr %8, ptr %11, align 8
|
||||
%12 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %9, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %12)
|
||||
unreachable
|
||||
}
|
||||
|
||||
declare void @errors.init()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare %"github.com/goplus/llgo/internal/runtime.iface" @errors.New(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.IfaceType"(%"github.com/goplus/llgo/internal/runtime.iface")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface")
|
||||
11
cl/_testlibgo/os/in.go
Normal file
11
cl/_testlibgo/os/in.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import "os"
|
||||
|
||||
func main() {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
println("cwd:", wd)
|
||||
}
|
||||
95
cl/_testlibgo/os/out.ll
Normal file
95
cl/_testlibgo/os/out.ll
Normal file
@@ -0,0 +1,95 @@
|
||||
; 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 }
|
||||
%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr }
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@0 = private unnamed_addr constant [4 x i8] c"cwd:", 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 @os.init()
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @main(i32 %0, ptr %1) {
|
||||
_llgo_0:
|
||||
store i32 %0, ptr @__llgo_argc, align 4
|
||||
store ptr %1, ptr @__llgo_argv, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
call void @main.init()
|
||||
%2 = call { %"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.iface" } @os.Getwd()
|
||||
%3 = extractvalue { %"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.iface" } %2, 0
|
||||
%4 = extractvalue { %"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.iface" } %2, 1
|
||||
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.IfaceType"(%"github.com/goplus/llgo/internal/runtime.iface" %4)
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.iface" %4, 1
|
||||
%7 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, i32 0, i32 0
|
||||
store ptr %5, ptr %8, align 8
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, i32 0, i32 1
|
||||
store ptr %6, ptr %9, align 8
|
||||
%10 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, align 8
|
||||
%11 = call ptr @"github.com/goplus/llgo/internal/runtime.IfaceType"(%"github.com/goplus/llgo/internal/runtime.iface" zeroinitializer)
|
||||
%12 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
||||
%13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %12, i32 0, i32 0
|
||||
store ptr %11, ptr %13, align 8
|
||||
%14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %12, i32 0, i32 1
|
||||
store ptr null, ptr %14, align 8
|
||||
%15 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %12, align 8
|
||||
%16 = call i1 @"github.com/goplus/llgo/internal/runtime.EfaceEqual"(%"github.com/goplus/llgo/internal/runtime.eface" %10, %"github.com/goplus/llgo/internal/runtime.eface" %15)
|
||||
%17 = xor i1 %16, true
|
||||
br i1 %17, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%18 = call ptr @"github.com/goplus/llgo/internal/runtime.IfaceType"(%"github.com/goplus/llgo/internal/runtime.iface" %4)
|
||||
%19 = extractvalue %"github.com/goplus/llgo/internal/runtime.iface" %4, 1
|
||||
%20 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
||||
%21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %20, i32 0, i32 0
|
||||
store ptr %18, ptr %21, align 8
|
||||
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %20, i32 0, i32 1
|
||||
store ptr %19, ptr %22, align 8
|
||||
%23 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %20, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %23)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
%24 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 0
|
||||
store ptr @0, ptr %25, align 8
|
||||
%26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 1
|
||||
store i64 4, ptr %26, align 4
|
||||
%27 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %24, align 8
|
||||
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.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %3)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @os.init()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare { %"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.iface" } @os.Getwd()
|
||||
|
||||
declare i1 @"github.com/goplus/llgo/internal/runtime.EfaceEqual"(%"github.com/goplus/llgo/internal/runtime.eface", %"github.com/goplus/llgo/internal/runtime.eface")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.IfaceType"(%"github.com/goplus/llgo/internal/runtime.iface")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
18
cl/_testlibgo/sync/in.go
Normal file
18
cl/_testlibgo/sync/in.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
|
||||
func f(s string) {
|
||||
once.Do(func() {
|
||||
println(s)
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
f("Do once")
|
||||
f("Do twice")
|
||||
}
|
||||
1
cl/_testlibgo/sync/out.ll
Normal file
1
cl/_testlibgo/sync/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
20
cl/_testlibgo/waitgroup/in.go
Normal file
20
cl/_testlibgo/waitgroup/in.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
println("work 1")
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
println("work 2")
|
||||
}()
|
||||
wg.Wait()
|
||||
println("done")
|
||||
}
|
||||
1
cl/_testlibgo/waitgroup/out.ll
Normal file
1
cl/_testlibgo/waitgroup/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
@@ -132,14 +132,14 @@ _llgo_0:
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3)
|
||||
store ptr %2, ptr @_llgo_int8, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 6
|
||||
%4 = load i8, ptr %3, align 1
|
||||
%5 = or i8 %4, 32
|
||||
store i8 %5, ptr %3, align 1
|
||||
store ptr %2, ptr @_llgo_int8, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%6 = load ptr, ptr @_llgo_int8, align 8
|
||||
%7 = load ptr, ptr @"*_llgo_int8", align 8
|
||||
%8 = icmp eq ptr %7, null
|
||||
@@ -167,14 +167,14 @@ _llgo_6: ; preds = %_llgo_5, %_llgo_4
|
||||
|
||||
_llgo_7: ; preds = %_llgo_6
|
||||
%15 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
store ptr %15, ptr @_llgo_int, align 8
|
||||
br label %_llgo_8
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7, %_llgo_6
|
||||
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %15, i32 0, i32 6
|
||||
%17 = load i8, ptr %16, align 1
|
||||
%18 = or i8 %17, 32
|
||||
store i8 %18, ptr %16, align 1
|
||||
store ptr %15, ptr @_llgo_int, align 8
|
||||
br label %_llgo_8
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7, %_llgo_6
|
||||
ret void
|
||||
}
|
||||
|
||||
|
||||
@@ -229,14 +229,14 @@ _llgo_0:
|
||||
store i64 5, ptr %74, align 4
|
||||
%75 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %72, align 8
|
||||
%76 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %75, 1
|
||||
%77 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %75, i64 1, i64 %76)
|
||||
%77 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %75, i64 1, i64 %76)
|
||||
%78 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%79 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %78, i32 0, i32 0
|
||||
store ptr @0, ptr %79, align 8
|
||||
%80 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %78, i32 0, i32 1
|
||||
store i64 5, ptr %80, align 4
|
||||
%81 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %78, align 8
|
||||
%82 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %81, i64 1, i64 2)
|
||||
%82 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %81, i64 1, i64 2)
|
||||
%83 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%84 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %83, i32 0, i32 0
|
||||
store ptr @0, ptr %84, align 8
|
||||
@@ -244,7 +244,7 @@ _llgo_0:
|
||||
store i64 5, ptr %85, align 4
|
||||
%86 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %83, align 8
|
||||
%87 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %86, 1
|
||||
%88 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %86, i64 5, i64 %87)
|
||||
%88 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %86, i64 5, i64 %87)
|
||||
%89 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %88, 1
|
||||
%90 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%91 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %90, i32 0, i32 0
|
||||
@@ -486,133 +486,162 @@ _llgo_3: ; preds = %_llgo_1
|
||||
%205 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromBytes"(%"github.com/goplus/llgo/internal/runtime.Slice" %199)
|
||||
%206 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRunes"(%"github.com/goplus/llgo/internal/runtime.Slice" %204)
|
||||
%207 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %199, 0
|
||||
%208 = getelementptr inbounds i8, ptr %207, i64 3
|
||||
%209 = load i8, ptr %208, align 1
|
||||
%210 = sext i8 %209 to i32
|
||||
%211 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %210)
|
||||
%212 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %204, 0
|
||||
%213 = getelementptr inbounds i32, ptr %212, i64 0
|
||||
%214 = load i32, ptr %213, align 4
|
||||
%215 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %214)
|
||||
%208 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %199, 1
|
||||
%209 = icmp sge i64 3, %208
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %209)
|
||||
%210 = getelementptr inbounds i8, ptr %207, i64 3
|
||||
%211 = load i8, ptr %210, align 1
|
||||
%212 = sext i8 %211 to i32
|
||||
%213 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %212)
|
||||
%214 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %204, 0
|
||||
%215 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %204, 1
|
||||
%216 = icmp sge i64 0, %215
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %216)
|
||||
%217 = getelementptr inbounds i32, ptr %214, i64 0
|
||||
%218 = load i32, ptr %217, align 4
|
||||
%219 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %218)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %205)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %206)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %211)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %213)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %215)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %219)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%216 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%217 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %216, i32 0, i32 0
|
||||
store ptr @4, ptr %217, align 8
|
||||
%218 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %216, i32 0, i32 1
|
||||
store i64 3, ptr %218, align 4
|
||||
%219 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %216, align 8
|
||||
%220 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%221 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %220, i32 0, i32 0
|
||||
store ptr @4, ptr %221, align 8
|
||||
%222 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %220, i32 0, i32 1
|
||||
store i64 3, ptr %222, align 4
|
||||
%223 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %220, align 8
|
||||
%224 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %219, %"github.com/goplus/llgo/internal/runtime.String" %223)
|
||||
%225 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%226 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %225, i32 0, i32 0
|
||||
store ptr @4, ptr %226, align 8
|
||||
%227 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %225, i32 0, i32 1
|
||||
store i64 3, ptr %227, align 4
|
||||
%228 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %225, align 8
|
||||
%224 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%225 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %224, i32 0, i32 0
|
||||
store ptr @4, ptr %225, align 8
|
||||
%226 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %224, i32 0, i32 1
|
||||
store i64 3, ptr %226, align 4
|
||||
%227 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %224, align 8
|
||||
%228 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %223, %"github.com/goplus/llgo/internal/runtime.String" %227)
|
||||
%229 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%230 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %229, i32 0, i32 0
|
||||
store ptr @5, ptr %230, align 8
|
||||
store ptr @4, ptr %230, align 8
|
||||
%231 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %229, i32 0, i32 1
|
||||
store i64 3, ptr %231, align 4
|
||||
%232 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %229, align 8
|
||||
%233 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %228, %"github.com/goplus/llgo/internal/runtime.String" %232)
|
||||
%234 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%235 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %234, i32 0, i32 0
|
||||
store ptr @4, ptr %235, align 8
|
||||
%236 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %234, i32 0, i32 1
|
||||
store i64 3, ptr %236, align 4
|
||||
%237 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %234, align 8
|
||||
%233 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%234 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %233, i32 0, i32 0
|
||||
store ptr @5, ptr %234, align 8
|
||||
%235 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %233, i32 0, i32 1
|
||||
store i64 3, ptr %235, align 4
|
||||
%236 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %233, align 8
|
||||
%237 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %232, %"github.com/goplus/llgo/internal/runtime.String" %236)
|
||||
%238 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%239 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %238, i32 0, i32 0
|
||||
store ptr @5, ptr %239, align 8
|
||||
store ptr @4, ptr %239, align 8
|
||||
%240 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %238, i32 0, i32 1
|
||||
store i64 3, ptr %240, align 4
|
||||
%241 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %238, align 8
|
||||
%242 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %237, %"github.com/goplus/llgo/internal/runtime.String" %241)
|
||||
%243 = xor i1 %242, true
|
||||
%244 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%245 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %244, i32 0, i32 0
|
||||
store ptr @4, ptr %245, align 8
|
||||
%246 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %244, i32 0, i32 1
|
||||
store i64 3, ptr %246, align 4
|
||||
%247 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %244, align 8
|
||||
%242 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%243 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %242, i32 0, i32 0
|
||||
store ptr @5, ptr %243, align 8
|
||||
%244 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %242, i32 0, i32 1
|
||||
store i64 3, ptr %244, align 4
|
||||
%245 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %242, align 8
|
||||
%246 = call i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String" %241, %"github.com/goplus/llgo/internal/runtime.String" %245)
|
||||
%247 = xor i1 %246, true
|
||||
%248 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%249 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %248, i32 0, i32 0
|
||||
store ptr @5, ptr %249, align 8
|
||||
store ptr @4, ptr %249, align 8
|
||||
%250 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %248, i32 0, i32 1
|
||||
store i64 3, ptr %250, align 4
|
||||
%251 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %248, align 8
|
||||
%252 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %247, %"github.com/goplus/llgo/internal/runtime.String" %251)
|
||||
%253 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%254 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %253, i32 0, i32 0
|
||||
store ptr @4, ptr %254, align 8
|
||||
%255 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %253, i32 0, i32 1
|
||||
store i64 3, ptr %255, align 4
|
||||
%256 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %253, align 8
|
||||
%252 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%253 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %252, i32 0, i32 0
|
||||
store ptr @5, ptr %253, align 8
|
||||
%254 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %252, i32 0, i32 1
|
||||
store i64 3, ptr %254, align 4
|
||||
%255 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %252, align 8
|
||||
%256 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %251, %"github.com/goplus/llgo/internal/runtime.String" %255)
|
||||
%257 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%258 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %257, i32 0, i32 0
|
||||
store ptr @5, ptr %258, align 8
|
||||
store ptr @4, ptr %258, align 8
|
||||
%259 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %257, i32 0, i32 1
|
||||
store i64 3, ptr %259, align 4
|
||||
%260 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %257, align 8
|
||||
%261 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %260, %"github.com/goplus/llgo/internal/runtime.String" %256)
|
||||
%262 = xor i1 %261, true
|
||||
%263 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%264 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %263, i32 0, i32 0
|
||||
store ptr @4, ptr %264, align 8
|
||||
%265 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %263, i32 0, i32 1
|
||||
store i64 3, ptr %265, align 4
|
||||
%266 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %263, align 8
|
||||
%261 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%262 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %261, i32 0, i32 0
|
||||
store ptr @5, ptr %262, align 8
|
||||
%263 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %261, i32 0, i32 1
|
||||
store i64 3, ptr %263, align 4
|
||||
%264 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %261, align 8
|
||||
%265 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %264, %"github.com/goplus/llgo/internal/runtime.String" %260)
|
||||
%266 = xor i1 %265, true
|
||||
%267 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%268 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %267, i32 0, i32 0
|
||||
store ptr @5, ptr %268, align 8
|
||||
store ptr @4, ptr %268, align 8
|
||||
%269 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %267, i32 0, i32 1
|
||||
store i64 3, ptr %269, align 4
|
||||
%270 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %267, align 8
|
||||
%271 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %270, %"github.com/goplus/llgo/internal/runtime.String" %266)
|
||||
%272 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%273 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %272, i32 0, i32 0
|
||||
store ptr @4, ptr %273, align 8
|
||||
%274 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %272, i32 0, i32 1
|
||||
store i64 3, ptr %274, align 4
|
||||
%275 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %272, align 8
|
||||
%271 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%272 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %271, i32 0, i32 0
|
||||
store ptr @5, ptr %272, align 8
|
||||
%273 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %271, i32 0, i32 1
|
||||
store i64 3, ptr %273, align 4
|
||||
%274 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %271, align 8
|
||||
%275 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %274, %"github.com/goplus/llgo/internal/runtime.String" %270)
|
||||
%276 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%277 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %276, i32 0, i32 0
|
||||
store ptr @5, ptr %277, align 8
|
||||
store ptr @4, ptr %277, align 8
|
||||
%278 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %276, i32 0, i32 1
|
||||
store i64 3, ptr %278, align 4
|
||||
%279 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %276, align 8
|
||||
%280 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %275, %"github.com/goplus/llgo/internal/runtime.String" %279)
|
||||
%281 = xor i1 %280, true
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %224)
|
||||
%280 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%281 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %280, i32 0, i32 0
|
||||
store ptr @5, ptr %281, align 8
|
||||
%282 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %280, i32 0, i32 1
|
||||
store i64 3, ptr %282, align 4
|
||||
%283 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %280, align 8
|
||||
%284 = call i1 @"github.com/goplus/llgo/internal/runtime.StringLess"(%"github.com/goplus/llgo/internal/runtime.String" %279, %"github.com/goplus/llgo/internal/runtime.String" %283)
|
||||
%285 = xor i1 %284, true
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %228)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %233)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %237)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %243)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %247)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %252)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %256)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %262)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %266)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %271)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %275)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %281)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %285)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
define void @"main.main$1"() {
|
||||
_llgo_0:
|
||||
%0 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%1 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 0
|
||||
store ptr @6, ptr %1, align 8
|
||||
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 1
|
||||
store i64 2, ptr %2, align 4
|
||||
%3 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %0, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %3)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"main.main$2"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { ptr }, ptr %0, align 8
|
||||
%2 = extractvalue { ptr } %1, 0
|
||||
%3 = load i64, ptr %2, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %3)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
@@ -625,7 +654,7 @@ declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
|
||||
|
||||
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String", i64, i64)
|
||||
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringSlice"(%"github.com/goplus/llgo/internal/runtime.String", i64, i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
@@ -639,14 +668,14 @@ _llgo_0:
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
store ptr %2, ptr @_llgo_int, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 6
|
||||
%4 = load i8, ptr %3, align 1
|
||||
%5 = or i8 %4, 32
|
||||
store i8 %5, ptr %3, align 1
|
||||
store ptr %2, ptr @_llgo_int, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -664,31 +693,8 @@ declare void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr)
|
||||
|
||||
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceCopy"(%"github.com/goplus/llgo/internal/runtime.Slice", ptr, i64, i64)
|
||||
|
||||
define void @"main.main$2"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { ptr }, ptr %0, align 8
|
||||
%2 = extractvalue { ptr } %1, 0
|
||||
%3 = load i64, ptr %2, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %3)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64)
|
||||
|
||||
define void @"main.main$1"() {
|
||||
_llgo_0:
|
||||
%0 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%1 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 0
|
||||
store ptr @6, ptr %1, align 8
|
||||
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 1
|
||||
store i64 2, ptr %2, align 4
|
||||
%3 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %0, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %3)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.NewStringIter"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare { i1, i64, i32 } @"github.com/goplus/llgo/internal/runtime.StringIterNext"(ptr)
|
||||
@@ -701,6 +707,8 @@ declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/ll
|
||||
|
||||
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRunes"(%"github.com/goplus/llgo/internal/runtime.Slice")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32)
|
||||
|
||||
declare i1 @"github.com/goplus/llgo/internal/runtime.StringEqual"(%"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
@@ -50,28 +50,18 @@ _llgo_0:
|
||||
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
|
||||
@@ -83,6 +73,16 @@ _llgo_0:
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
20
cl/_testrt/complex/in.go
Normal file
20
cl/_testrt/complex/in.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
type T complex64
|
||||
|
||||
func main() {
|
||||
a := 1 + 2i
|
||||
b := 3 + 4i
|
||||
c := 0 + 0i
|
||||
println(real(a), imag(a))
|
||||
println(-a)
|
||||
println(a + b)
|
||||
println(a - b)
|
||||
println(a * b)
|
||||
println(a / b)
|
||||
println(a / c)
|
||||
println(c / c)
|
||||
println(a == a, a != a)
|
||||
println(a == b, a != b)
|
||||
println(complex128(T(a)) == a)
|
||||
}
|
||||
129
cl/_testrt/complex/out.ll
Normal file
129
cl/_testrt/complex/out.ll
Normal file
@@ -0,0 +1,129 @@
|
||||
; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
|
||||
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/internal/runtime.PrintFloat"(double 1.000000e+00)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double 2.000000e+00)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%2 = alloca { double, double }, align 8
|
||||
%3 = getelementptr inbounds { double, double }, ptr %2, i32 0, i32 0
|
||||
store double -1.000000e+00, ptr %3, align 8
|
||||
%4 = getelementptr inbounds { double, double }, ptr %2, i32 0, i32 1
|
||||
store double -2.000000e+00, ptr %4, align 8
|
||||
%5 = load { double, double }, ptr %2, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintComplex"({ double, double } %5)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%6 = alloca { double, double }, align 8
|
||||
%7 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 0
|
||||
store double 4.000000e+00, ptr %7, align 8
|
||||
%8 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 1
|
||||
store double 6.000000e+00, ptr %8, align 8
|
||||
%9 = load { double, double }, ptr %6, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintComplex"({ double, double } %9)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%10 = alloca { double, double }, align 8
|
||||
%11 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 0
|
||||
store double -2.000000e+00, ptr %11, align 8
|
||||
%12 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 1
|
||||
store double -2.000000e+00, ptr %12, align 8
|
||||
%13 = load { double, double }, ptr %10, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintComplex"({ double, double } %13)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%14 = alloca { double, double }, align 8
|
||||
%15 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
|
||||
store double -5.000000e+00, ptr %15, align 8
|
||||
%16 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
|
||||
store double 1.000000e+01, ptr %16, align 8
|
||||
%17 = load { double, double }, ptr %14, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintComplex"({ double, double } %17)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%18 = alloca { double, double }, align 8
|
||||
%19 = getelementptr inbounds { double, double }, ptr %18, i32 0, i32 0
|
||||
store double 4.400000e-01, ptr %19, align 8
|
||||
%20 = getelementptr inbounds { double, double }, ptr %18, i32 0, i32 1
|
||||
store double -8.000000e-02, ptr %20, align 8
|
||||
%21 = load { double, double }, ptr %18, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintComplex"({ double, double } %21)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%22 = alloca { double, double }, align 8
|
||||
%23 = getelementptr inbounds { double, double }, ptr %22, i32 0, i32 0
|
||||
store double 0x7FF0000000000000, ptr %23, align 8
|
||||
%24 = getelementptr inbounds { double, double }, ptr %22, i32 0, i32 1
|
||||
store double 0x7FF0000000000000, ptr %24, align 8
|
||||
%25 = load { double, double }, ptr %22, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintComplex"({ double, double } %25)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%26 = alloca { double, double }, align 8
|
||||
%27 = getelementptr inbounds { double, double }, ptr %26, i32 0, i32 0
|
||||
store double 0x7FF8000000000000, ptr %27, align 8
|
||||
%28 = getelementptr inbounds { double, double }, ptr %26, i32 0, i32 1
|
||||
store double 0x7FF8000000000000, ptr %28, align 8
|
||||
%29 = load { double, double }, ptr %26, align 8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintComplex"({ double, double } %29)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 true)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 false)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 false)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 true)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%30 = alloca { float, float }, align 8
|
||||
%31 = getelementptr inbounds { float, float }, ptr %30, i32 0, i32 0
|
||||
store float 1.000000e+00, ptr %31, align 4
|
||||
%32 = getelementptr inbounds { float, float }, ptr %30, i32 0, i32 1
|
||||
store float 2.000000e+00, ptr %32, align 4
|
||||
%33 = load { float, float }, ptr %30, align 4
|
||||
%34 = extractvalue { float, float } %33, 0
|
||||
%35 = extractvalue { float, float } %33, 1
|
||||
%36 = fpext float %34 to double
|
||||
%37 = fpext float %35 to double
|
||||
%38 = alloca { double, double }, align 8
|
||||
%39 = getelementptr inbounds { double, double }, ptr %38, i32 0, i32 0
|
||||
store double %36, ptr %39, align 8
|
||||
%40 = getelementptr inbounds { double, double }, ptr %38, i32 0, i32 1
|
||||
store double %37, ptr %40, align 8
|
||||
%41 = load { double, double }, ptr %38, align 8
|
||||
%42 = extractvalue { double, double } %41, 0
|
||||
%43 = extractvalue { double, double } %41, 1
|
||||
%44 = fcmp oeq double %42, 1.000000e+00
|
||||
%45 = fcmp oeq double %43, 2.000000e+00
|
||||
%46 = and i1 %44, %45
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %46)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintComplex"({ double, double })
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1)
|
||||
@@ -24,19 +24,22 @@ _llgo_0:
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%6 = phi %"github.com/goplus/llgo/internal/runtime.String" [ %5, %_llgo_0 ], [ %14, %_llgo_2 ]
|
||||
%6 = phi %"github.com/goplus/llgo/internal/runtime.String" [ %5, %_llgo_0 ], [ %17, %_llgo_2 ]
|
||||
%7 = phi i64 [ -1, %_llgo_0 ], [ %8, %_llgo_2 ]
|
||||
%8 = add i64 %7, 1
|
||||
%9 = icmp slt i64 %8, %1
|
||||
br i1 %9, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%10 = icmp slt i64 %8, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %10)
|
||||
%11 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %11, i64 %8
|
||||
%13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %12, align 8
|
||||
%14 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %6, %"github.com/goplus/llgo/internal/runtime.String" %13)
|
||||
%10 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%11 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
%12 = icmp slt i64 %8, 0
|
||||
%13 = icmp sge i64 %8, %11
|
||||
%14 = or i1 %13, %12
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %14)
|
||||
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i64 %8
|
||||
%16 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %15, align 8
|
||||
%17 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %6, %"github.com/goplus/llgo/internal/runtime.String" %16)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
|
||||
@@ -463,6 +463,11 @@ _llgo_0:
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
define void @"main.main$1"() {
|
||||
_llgo_0:
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
@@ -493,196 +498,196 @@ _llgo_0:
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1)
|
||||
store ptr %2, ptr @_llgo_bool, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 6
|
||||
%4 = load i8, ptr %3, align 1
|
||||
%5 = or i8 %4, 32
|
||||
store i8 %5, ptr %3, align 1
|
||||
store ptr %2, ptr @_llgo_bool, align 8
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
%6 = load ptr, ptr @_llgo_int, align 8
|
||||
%7 = icmp eq ptr %6, null
|
||||
br i1 %7, label %_llgo_3, label %_llgo_4
|
||||
|
||||
_llgo_3: ; preds = %_llgo_2
|
||||
%8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||
store ptr %8, ptr @_llgo_int, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %8, i32 0, i32 6
|
||||
%10 = load i8, ptr %9, align 1
|
||||
%11 = or i8 %10, 32
|
||||
store i8 %11, ptr %9, align 1
|
||||
store ptr %8, ptr @_llgo_int, align 8
|
||||
br label %_llgo_4
|
||||
|
||||
_llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%12 = load ptr, ptr @_llgo_int8, align 8
|
||||
%13 = icmp eq ptr %12, null
|
||||
br i1 %13, label %_llgo_5, label %_llgo_6
|
||||
|
||||
_llgo_5: ; preds = %_llgo_4
|
||||
%14 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3)
|
||||
store ptr %14, ptr @_llgo_int8, align 8
|
||||
br label %_llgo_6
|
||||
|
||||
_llgo_6: ; preds = %_llgo_5, %_llgo_4
|
||||
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %14, i32 0, i32 6
|
||||
%16 = load i8, ptr %15, align 1
|
||||
%17 = or i8 %16, 32
|
||||
store i8 %17, ptr %15, align 1
|
||||
store ptr %14, ptr @_llgo_int8, align 8
|
||||
br label %_llgo_6
|
||||
|
||||
_llgo_6: ; preds = %_llgo_5, %_llgo_4
|
||||
%18 = load ptr, ptr @_llgo_int16, align 8
|
||||
%19 = icmp eq ptr %18, null
|
||||
br i1 %19, label %_llgo_7, label %_llgo_8
|
||||
|
||||
_llgo_7: ; preds = %_llgo_6
|
||||
%20 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 4)
|
||||
store ptr %20, ptr @_llgo_int16, align 8
|
||||
br label %_llgo_8
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7, %_llgo_6
|
||||
%21 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %20, i32 0, i32 6
|
||||
%22 = load i8, ptr %21, align 1
|
||||
%23 = or i8 %22, 32
|
||||
store i8 %23, ptr %21, align 1
|
||||
store ptr %20, ptr @_llgo_int16, align 8
|
||||
br label %_llgo_8
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7, %_llgo_6
|
||||
%24 = load ptr, ptr @_llgo_int32, align 8
|
||||
%25 = icmp eq ptr %24, null
|
||||
br i1 %25, label %_llgo_9, label %_llgo_10
|
||||
|
||||
_llgo_9: ; preds = %_llgo_8
|
||||
%26 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5)
|
||||
store ptr %26, ptr @_llgo_int32, align 8
|
||||
br label %_llgo_10
|
||||
|
||||
_llgo_10: ; preds = %_llgo_9, %_llgo_8
|
||||
%27 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %26, i32 0, i32 6
|
||||
%28 = load i8, ptr %27, align 1
|
||||
%29 = or i8 %28, 32
|
||||
store i8 %29, ptr %27, align 1
|
||||
store ptr %26, ptr @_llgo_int32, align 8
|
||||
br label %_llgo_10
|
||||
|
||||
_llgo_10: ; preds = %_llgo_9, %_llgo_8
|
||||
%30 = load ptr, ptr @_llgo_int64, align 8
|
||||
%31 = icmp eq ptr %30, null
|
||||
br i1 %31, label %_llgo_11, label %_llgo_12
|
||||
|
||||
_llgo_11: ; preds = %_llgo_10
|
||||
%32 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6)
|
||||
store ptr %32, ptr @_llgo_int64, align 8
|
||||
br label %_llgo_12
|
||||
|
||||
_llgo_12: ; preds = %_llgo_11, %_llgo_10
|
||||
%33 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %32, i32 0, i32 6
|
||||
%34 = load i8, ptr %33, align 1
|
||||
%35 = or i8 %34, 32
|
||||
store i8 %35, ptr %33, align 1
|
||||
store ptr %32, ptr @_llgo_int64, align 8
|
||||
br label %_llgo_12
|
||||
|
||||
_llgo_12: ; preds = %_llgo_11, %_llgo_10
|
||||
%36 = load ptr, ptr @_llgo_uint, align 8
|
||||
%37 = icmp eq ptr %36, null
|
||||
br i1 %37, label %_llgo_13, label %_llgo_14
|
||||
|
||||
_llgo_13: ; preds = %_llgo_12
|
||||
%38 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 7)
|
||||
store ptr %38, ptr @_llgo_uint, align 8
|
||||
br label %_llgo_14
|
||||
|
||||
_llgo_14: ; preds = %_llgo_13, %_llgo_12
|
||||
%39 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %38, i32 0, i32 6
|
||||
%40 = load i8, ptr %39, align 1
|
||||
%41 = or i8 %40, 32
|
||||
store i8 %41, ptr %39, align 1
|
||||
store ptr %38, ptr @_llgo_uint, align 8
|
||||
br label %_llgo_14
|
||||
|
||||
_llgo_14: ; preds = %_llgo_13, %_llgo_12
|
||||
%42 = load ptr, ptr @_llgo_uint8, align 8
|
||||
%43 = icmp eq ptr %42, null
|
||||
br i1 %43, label %_llgo_15, label %_llgo_16
|
||||
|
||||
_llgo_15: ; preds = %_llgo_14
|
||||
%44 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8)
|
||||
store ptr %44, ptr @_llgo_uint8, align 8
|
||||
br label %_llgo_16
|
||||
|
||||
_llgo_16: ; preds = %_llgo_15, %_llgo_14
|
||||
%45 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %44, i32 0, i32 6
|
||||
%46 = load i8, ptr %45, align 1
|
||||
%47 = or i8 %46, 32
|
||||
store i8 %47, ptr %45, align 1
|
||||
store ptr %44, ptr @_llgo_uint8, align 8
|
||||
br label %_llgo_16
|
||||
|
||||
_llgo_16: ; preds = %_llgo_15, %_llgo_14
|
||||
%48 = load ptr, ptr @_llgo_uint16, align 8
|
||||
%49 = icmp eq ptr %48, null
|
||||
br i1 %49, label %_llgo_17, label %_llgo_18
|
||||
|
||||
_llgo_17: ; preds = %_llgo_16
|
||||
%50 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 9)
|
||||
store ptr %50, ptr @_llgo_uint16, align 8
|
||||
br label %_llgo_18
|
||||
|
||||
_llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||
%51 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %50, i32 0, i32 6
|
||||
%52 = load i8, ptr %51, align 1
|
||||
%53 = or i8 %52, 32
|
||||
store i8 %53, ptr %51, align 1
|
||||
store ptr %50, ptr @_llgo_uint16, align 8
|
||||
br label %_llgo_18
|
||||
|
||||
_llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||
%54 = load ptr, ptr @_llgo_uint32, align 8
|
||||
%55 = icmp eq ptr %54, null
|
||||
br i1 %55, label %_llgo_19, label %_llgo_20
|
||||
|
||||
_llgo_19: ; preds = %_llgo_18
|
||||
%56 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 10)
|
||||
store ptr %56, ptr @_llgo_uint32, align 8
|
||||
br label %_llgo_20
|
||||
|
||||
_llgo_20: ; preds = %_llgo_19, %_llgo_18
|
||||
%57 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %56, i32 0, i32 6
|
||||
%58 = load i8, ptr %57, align 1
|
||||
%59 = or i8 %58, 32
|
||||
store i8 %59, ptr %57, align 1
|
||||
store ptr %56, ptr @_llgo_uint32, align 8
|
||||
br label %_llgo_20
|
||||
|
||||
_llgo_20: ; preds = %_llgo_19, %_llgo_18
|
||||
%60 = load ptr, ptr @_llgo_uint64, align 8
|
||||
%61 = icmp eq ptr %60, null
|
||||
br i1 %61, label %_llgo_21, label %_llgo_22
|
||||
|
||||
_llgo_21: ; preds = %_llgo_20
|
||||
%62 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 11)
|
||||
store ptr %62, ptr @_llgo_uint64, align 8
|
||||
br label %_llgo_22
|
||||
|
||||
_llgo_22: ; preds = %_llgo_21, %_llgo_20
|
||||
%63 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %62, i32 0, i32 6
|
||||
%64 = load i8, ptr %63, align 1
|
||||
%65 = or i8 %64, 32
|
||||
store i8 %65, ptr %63, align 1
|
||||
store ptr %62, ptr @_llgo_uint64, align 8
|
||||
br label %_llgo_22
|
||||
|
||||
_llgo_22: ; preds = %_llgo_21, %_llgo_20
|
||||
%66 = load ptr, ptr @_llgo_uintptr, align 8
|
||||
%67 = icmp eq ptr %66, null
|
||||
br i1 %67, label %_llgo_23, label %_llgo_24
|
||||
|
||||
_llgo_23: ; preds = %_llgo_22
|
||||
%68 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 12)
|
||||
store ptr %68, ptr @_llgo_uintptr, align 8
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
%69 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %68, i32 0, i32 6
|
||||
%70 = load i8, ptr %69, align 1
|
||||
%71 = or i8 %70, 32
|
||||
store i8 %71, ptr %69, align 1
|
||||
store ptr %68, ptr @_llgo_uintptr, align 8
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
%72 = load ptr, ptr @_llgo_float32, align 8
|
||||
%73 = icmp eq ptr %72, null
|
||||
br i1 %73, label %_llgo_25, label %_llgo_26
|
||||
|
||||
_llgo_25: ; preds = %_llgo_24
|
||||
%74 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13)
|
||||
store ptr %74, ptr @_llgo_float32, align 8
|
||||
br label %_llgo_26
|
||||
|
||||
_llgo_26: ; preds = %_llgo_25, %_llgo_24
|
||||
%75 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %74, i32 0, i32 6
|
||||
%76 = load i8, ptr %75, align 1
|
||||
%77 = or i8 %76, 32
|
||||
store i8 %77, ptr %75, align 1
|
||||
store ptr %74, ptr @_llgo_float32, align 8
|
||||
br label %_llgo_26
|
||||
|
||||
_llgo_26: ; preds = %_llgo_25, %_llgo_24
|
||||
%78 = load ptr, ptr @_llgo_float64, align 8
|
||||
%79 = icmp eq ptr %78, null
|
||||
br i1 %79, label %_llgo_27, label %_llgo_28
|
||||
|
||||
_llgo_27: ; preds = %_llgo_26
|
||||
%80 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14)
|
||||
store ptr %80, ptr @_llgo_float64, align 8
|
||||
br label %_llgo_28
|
||||
|
||||
_llgo_28: ; preds = %_llgo_27, %_llgo_26
|
||||
%81 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %80, i32 0, i32 6
|
||||
%82 = load i8, ptr %81, align 1
|
||||
%83 = or i8 %82, 32
|
||||
store i8 %83, ptr %81, align 1
|
||||
store ptr %80, ptr @_llgo_float64, align 8
|
||||
br label %_llgo_28
|
||||
|
||||
_llgo_28: ; preds = %_llgo_27, %_llgo_26
|
||||
%84 = load ptr, ptr @_llgo_int, align 8
|
||||
%85 = load ptr, ptr @"[10]_llgo_int", align 8
|
||||
%86 = icmp eq ptr %85, null
|
||||
@@ -886,11 +891,6 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.ArrayOf"(i64, ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64)
|
||||
|
||||
define void @"main.main$1"() {
|
||||
_llgo_0:
|
||||
ret void
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.Func"(%"github.com/goplus/llgo/internal/runtime.Slice", %"github.com/goplus/llgo/internal/runtime.Slice", i1)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.PointerTo"(ptr)
|
||||
|
||||
@@ -13,24 +13,28 @@ source_filename = "main"
|
||||
|
||||
define ptr @main.Basic(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = getelementptr inbounds ptr, ptr @main.basicTypes, i64 %0
|
||||
%2 = load ptr, ptr %1, align 8
|
||||
ret ptr %2
|
||||
%1 = icmp sge i64 %0, 25
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %1)
|
||||
%2 = getelementptr inbounds ptr, ptr @main.basicTypes, i64 %0
|
||||
%3 = load ptr, ptr %2, align 8
|
||||
ret ptr %3
|
||||
}
|
||||
|
||||
define ptr @main.basicType(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 72)
|
||||
%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
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 2
|
||||
%6 = trunc i64 %0 to i32
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 6
|
||||
%8 = trunc i64 %0 to i8
|
||||
store i64 %4, ptr %2, align 4
|
||||
store i32 %6, ptr %5, align 4
|
||||
store i8 %8, ptr %7, align 1
|
||||
%3 = icmp sge i64 %0, 25
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %3)
|
||||
%4 = getelementptr inbounds i64, ptr @main.sizeBasicTypes, i64 %0
|
||||
%5 = load i64, ptr %4, align 4
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 2
|
||||
%7 = trunc i64 %0 to i32
|
||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 6
|
||||
%9 = trunc i64 %0 to i8
|
||||
store i64 %5, ptr %2, align 4
|
||||
store i32 %7, ptr %6, align 4
|
||||
store i8 %9, ptr %8, align 1
|
||||
ret ptr %1
|
||||
}
|
||||
|
||||
@@ -67,6 +71,8 @@ _llgo_0:
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/abi.init"()
|
||||
|
||||
@@ -3,9 +3,9 @@ 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
|
||||
@"main.init$guard" = global i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
|
||||
define void @main.foo(%"github.com/goplus/llgo/internal/runtime.iface" %0) {
|
||||
_llgo_0:
|
||||
@@ -1,25 +1,33 @@
|
||||
package main
|
||||
|
||||
import "github.com/goplus/llgo/c"
|
||||
|
||||
type point struct {
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
type N [2]int
|
||||
type T *N
|
||||
type S []int
|
||||
|
||||
func main() {
|
||||
a := [...]point{{1, 2}, {3, 4}, {5, 6}}[2]
|
||||
c.Printf(c.Str("%d %d\n"), a.x, a.y)
|
||||
println(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])
|
||||
println(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])
|
||||
println([...]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])
|
||||
println(string(s[i]))
|
||||
println(string("123456"[1]))
|
||||
|
||||
var n = N{1, 2}
|
||||
var t T = &n
|
||||
println(t[1])
|
||||
var s1 = S{1, 2, 3, 4}
|
||||
println(s1[1])
|
||||
|
||||
println([2]int{}[0])
|
||||
}
|
||||
|
||||
@@ -3,17 +3,12 @@ source_filename = "main"
|
||||
|
||||
%main.point = type { i64, i64 }
|
||||
%"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 i1 false, align 1
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
@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 [6 x i8] c"123456", align 1
|
||||
@6 = private unnamed_addr constant [4 x i8] c"%c\0A\00", align 1
|
||||
@0 = private unnamed_addr constant [6 x i8] c"123456", align 1
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
@@ -61,82 +56,121 @@ _llgo_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 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%64 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %63, i32 0, i32 0
|
||||
store ptr @5, ptr %64, align 8
|
||||
%65 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %63, i32 0, i32 1
|
||||
store i64 6, ptr %65, align 4
|
||||
%66 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %63, align 8
|
||||
%67 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %66, 0
|
||||
%68 = getelementptr inbounds i8, ptr %67, i64 2
|
||||
%69 = load i8, ptr %68, align 1
|
||||
%70 = call i32 (ptr, ...) @printf(ptr @4, i8 %69)
|
||||
%71 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%72 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %71, i32 0, i32 0
|
||||
store ptr @5, ptr %72, align 8
|
||||
%73 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %71, i32 0, i32 1
|
||||
store i64 6, ptr %73, align 4
|
||||
%74 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %71, align 8
|
||||
%75 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %74, 0
|
||||
%76 = getelementptr inbounds i8, ptr %75, i64 1
|
||||
%77 = load i8, ptr %76, align 1
|
||||
%78 = call i32 (ptr, ...) @printf(ptr @6, i8 %77)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %19)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %21)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%22 = alloca [2 x i64], align 8
|
||||
%23 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %22, i64 16)
|
||||
%24 = alloca [2 x [2 x i64]], align 8
|
||||
%25 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %24, i64 32)
|
||||
%26 = getelementptr inbounds [2 x i64], ptr %25, i64 0
|
||||
%27 = getelementptr inbounds i64, ptr %26, i64 0
|
||||
%28 = getelementptr inbounds i64, ptr %26, i64 1
|
||||
%29 = getelementptr inbounds [2 x i64], ptr %25, i64 1
|
||||
%30 = getelementptr inbounds i64, ptr %29, i64 0
|
||||
%31 = getelementptr inbounds i64, ptr %29, i64 1
|
||||
store i64 1, ptr %27, align 4
|
||||
store i64 2, ptr %28, align 4
|
||||
store i64 3, ptr %30, align 4
|
||||
store i64 4, ptr %31, align 4
|
||||
%32 = load [2 x [2 x i64]], ptr %25, align 4
|
||||
%33 = getelementptr inbounds [2 x i64], ptr %25, i64 1
|
||||
%34 = load [2 x i64], ptr %33, align 4
|
||||
store [2 x i64] %34, ptr %23, align 4
|
||||
%35 = getelementptr inbounds i64, ptr %23, i64 0
|
||||
%36 = load i64, ptr %35, align 4
|
||||
%37 = getelementptr inbounds i64, ptr %23, i64 1
|
||||
%38 = load i64, ptr %37, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %36)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %38)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%39 = alloca [5 x i64], align 8
|
||||
%40 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %39, i64 40)
|
||||
%41 = getelementptr inbounds i64, ptr %40, i64 0
|
||||
%42 = getelementptr inbounds i64, ptr %40, i64 1
|
||||
%43 = getelementptr inbounds i64, ptr %40, i64 2
|
||||
%44 = getelementptr inbounds i64, ptr %40, i64 3
|
||||
%45 = getelementptr inbounds i64, ptr %40, i64 4
|
||||
store i64 1, ptr %41, align 4
|
||||
store i64 2, ptr %42, align 4
|
||||
store i64 3, ptr %43, align 4
|
||||
store i64 4, ptr %44, align 4
|
||||
store i64 5, ptr %45, align 4
|
||||
%46 = load [5 x i64], ptr %40, align 4
|
||||
%47 = getelementptr inbounds i64, ptr %40, i64 2
|
||||
%48 = load i64, ptr %47, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %48)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%49 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%50 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %49, i32 0, i32 0
|
||||
store ptr @0, ptr %50, align 8
|
||||
%51 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %49, i32 0, i32 1
|
||||
store i64 6, ptr %51, align 4
|
||||
%52 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %49, align 8
|
||||
%53 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %52, 0
|
||||
%54 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %52, 1
|
||||
%55 = icmp sge i64 2, %54
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %55)
|
||||
%56 = getelementptr inbounds i8, ptr %53, i64 2
|
||||
%57 = load i8, ptr %56, align 1
|
||||
%58 = sext i8 %57 to i32
|
||||
%59 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %58)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %59)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%60 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||
%61 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %60, i32 0, i32 0
|
||||
store ptr @0, ptr %61, align 8
|
||||
%62 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %60, i32 0, i32 1
|
||||
store i64 6, ptr %62, align 4
|
||||
%63 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %60, align 8
|
||||
%64 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %63, 0
|
||||
%65 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %63, 1
|
||||
%66 = icmp sge i64 1, %65
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %66)
|
||||
%67 = getelementptr inbounds i8, ptr %64, i64 1
|
||||
%68 = load i8, ptr %67, align 1
|
||||
%69 = sext i8 %68 to i32
|
||||
%70 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32 %69)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %70)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%71 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16)
|
||||
%72 = getelementptr inbounds i64, ptr %71, i64 0
|
||||
%73 = getelementptr inbounds i64, ptr %71, i64 1
|
||||
store i64 1, ptr %72, align 4
|
||||
store i64 2, ptr %73, align 4
|
||||
%74 = getelementptr inbounds i64, ptr %71, i64 1
|
||||
%75 = load i64, ptr %74, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %75)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
%76 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
|
||||
%77 = getelementptr inbounds i64, ptr %76, i64 0
|
||||
store i64 1, ptr %77, align 4
|
||||
%78 = getelementptr inbounds i64, ptr %76, i64 1
|
||||
store i64 2, ptr %78, align 4
|
||||
%79 = getelementptr inbounds i64, ptr %76, i64 2
|
||||
store i64 3, ptr %79, align 4
|
||||
%80 = getelementptr inbounds i64, ptr %76, i64 3
|
||||
store i64 4, ptr %80, align 4
|
||||
%81 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
|
||||
%82 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %81, i32 0, i32 0
|
||||
store ptr %76, ptr %82, align 8
|
||||
%83 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %81, i32 0, i32 1
|
||||
store i64 4, ptr %83, align 4
|
||||
%84 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %81, i32 0, i32 2
|
||||
store i64 4, ptr %84, align 4
|
||||
%85 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %81, align 8
|
||||
%86 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %85, 0
|
||||
%87 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %85, 1
|
||||
%88 = icmp sge i64 1, %87
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %88)
|
||||
%89 = getelementptr inbounds i64, ptr %86, i64 1
|
||||
%90 = load i64, ptr %89, align 4
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %90)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 0)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
@@ -144,4 +178,14 @@ 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 void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringFromRune"(i32)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
@@ -36,11 +36,14 @@ _llgo_2: ; preds = %_llgo_1
|
||||
%13 = extractvalue { ptr, ptr } %1, 1
|
||||
%14 = extractvalue { ptr, ptr } %1, 0
|
||||
%15 = call i32 %14(ptr %13)
|
||||
%16 = icmp slt i64 %11, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %16)
|
||||
%17 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %8, 0
|
||||
%18 = getelementptr inbounds i32, ptr %17, i64 %11
|
||||
store i32 %15, ptr %18, align 4
|
||||
%16 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %8, 0
|
||||
%17 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %8, 1
|
||||
%18 = icmp slt i64 %11, 0
|
||||
%19 = icmp sge i64 %11, %17
|
||||
%20 = or i1 %19, %18
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %20)
|
||||
%21 = getelementptr inbounds i32, ptr %16, i64 %11
|
||||
store i32 %15, ptr %21, align 4
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
@@ -95,81 +98,103 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
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)
|
||||
%11 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, 0
|
||||
%12 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %6, 1
|
||||
%13 = icmp slt i64 %9, 0
|
||||
%14 = icmp sge i64 %9, %12
|
||||
%15 = or i1 %14, %13
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %15)
|
||||
%16 = getelementptr inbounds i32, ptr %11, i64 %9
|
||||
%17 = load i32, ptr %16, align 4
|
||||
%18 = call i32 (ptr, ...) @printf(ptr @0, i32 %17)
|
||||
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
|
||||
%19 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
|
||||
store i32 1, ptr %19, align 4
|
||||
%20 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
|
||||
%21 = getelementptr inbounds { ptr }, ptr %20, i32 0, i32 0
|
||||
store ptr %19, ptr %21, align 8
|
||||
%22 = alloca { ptr, ptr }, align 8
|
||||
%23 = getelementptr inbounds { ptr, ptr }, ptr %22, i32 0, i32 0
|
||||
store ptr @"main.main$1", ptr %23, align 8
|
||||
%24 = getelementptr inbounds { ptr, ptr }, ptr %22, i32 0, i32 1
|
||||
store ptr %20, ptr %24, align 8
|
||||
%25 = load { ptr, ptr }, ptr %22, align 8
|
||||
%26 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %25)
|
||||
%27 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %26, 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
|
||||
%28 = phi i64 [ -1, %_llgo_3 ], [ %29, %_llgo_5 ]
|
||||
%29 = add i64 %28, 1
|
||||
%30 = icmp slt i64 %29, %27
|
||||
br i1 %30, 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)
|
||||
%31 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %26, 0
|
||||
%32 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %26, 1
|
||||
%33 = icmp slt i64 %29, 0
|
||||
%34 = icmp sge i64 %29, %32
|
||||
%35 = or i1 %34, %33
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %35)
|
||||
%36 = getelementptr inbounds i32, ptr %31, i64 %29
|
||||
%37 = load i32, ptr %36, align 4
|
||||
%38 = call i32 (ptr, ...) @printf(ptr @1, i32 %37)
|
||||
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
|
||||
%39 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
|
||||
%40 = getelementptr inbounds %main.generator, ptr %39, i32 0, i32 0
|
||||
store i32 1, ptr %40, align 4
|
||||
%41 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
|
||||
%42 = getelementptr inbounds { ptr }, ptr %41, i32 0, i32 0
|
||||
store ptr %39, ptr %42, align 8
|
||||
%43 = alloca { ptr, ptr }, align 8
|
||||
%44 = getelementptr inbounds { ptr, ptr }, ptr %43, i32 0, i32 0
|
||||
store ptr @"main.next$bound", ptr %44, align 8
|
||||
%45 = getelementptr inbounds { ptr, ptr }, ptr %43, i32 0, i32 1
|
||||
store ptr %41, ptr %45, align 8
|
||||
%46 = load { ptr, ptr }, ptr %43, align 8
|
||||
%47 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %46)
|
||||
%48 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %47, 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
|
||||
%49 = phi i64 [ -1, %_llgo_6 ], [ %50, %_llgo_8 ]
|
||||
%50 = add i64 %49, 1
|
||||
%51 = icmp slt i64 %50, %48
|
||||
br i1 %51, 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)
|
||||
%52 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %47, 0
|
||||
%53 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %47, 1
|
||||
%54 = icmp slt i64 %50, 0
|
||||
%55 = icmp sge i64 %50, %53
|
||||
%56 = or i1 %55, %54
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %56)
|
||||
%57 = getelementptr inbounds i32, ptr %52, i64 %50
|
||||
%58 = load i32, ptr %57, align 4
|
||||
%59 = call i32 (ptr, ...) @printf(ptr @2, i32 %58)
|
||||
br label %_llgo_7
|
||||
|
||||
_llgo_9: ; preds = %_llgo_7
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
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.AllocZ"(i64)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
@@ -186,19 +211,6 @@ _llgo_0:
|
||||
|
||||
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) {
|
||||
|
||||
@@ -123,10 +123,6 @@ _llgo_0:
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
define i64 @"main.main$1"(ptr %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = load { ptr }, ptr %0, align 8
|
||||
@@ -138,6 +134,10 @@ _llgo_0:
|
||||
ret i64 %7
|
||||
}
|
||||
|
||||
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.AllocU"(i64)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
@@ -49,22 +49,18 @@ _llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%13 = icmp slt i64 %11, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %13)
|
||||
%14 = getelementptr inbounds i64, ptr %2, i64 %11
|
||||
%15 = load i64, ptr %14, align 4
|
||||
%16 = call i32 (ptr, ...) @printf(ptr @0, i64 %15)
|
||||
%14 = icmp sge i64 %11, 5
|
||||
%15 = or i1 %14, %13
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %15)
|
||||
%16 = getelementptr inbounds i64, ptr %2, i64 %11
|
||||
%17 = load i64, ptr %16, align 4
|
||||
%18 = call i32 (ptr, ...) @printf(ptr @0, i64 %17)
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare void @qsort(ptr, i64, i64, ptr)
|
||||
|
||||
define i32 @"main.main$1"(ptr %0, ptr %1) {
|
||||
_llgo_0:
|
||||
%2 = load i64, ptr %0, align 4
|
||||
@@ -74,6 +70,12 @@ _llgo_0:
|
||||
ret i32 %5
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare void @qsort(ptr, i64, i64, ptr)
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
@@ -19,6 +19,12 @@ _llgo_0:
|
||||
ret { ptr, ptr } %3
|
||||
}
|
||||
|
||||
define i64 @"main.add$1"(i64 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = add i64 %0, %1
|
||||
ret i64 %2
|
||||
}
|
||||
|
||||
define { { ptr, ptr }, i64 } @main.add2() {
|
||||
_llgo_0:
|
||||
%0 = alloca { ptr, ptr }, align 8
|
||||
@@ -32,6 +38,12 @@ _llgo_0:
|
||||
ret { { ptr, ptr }, i64 } %mrv1
|
||||
}
|
||||
|
||||
define i64 @"main.add2$1"(i64 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = add i64 %0, %1
|
||||
ret i64 %2
|
||||
}
|
||||
|
||||
define void @main.init() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"main.init$guard", align 1
|
||||
@@ -72,32 +84,6 @@ _llgo_0:
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
define i64 @"main.add$1"(i64 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = add i64 %0, %1
|
||||
ret i64 %2
|
||||
}
|
||||
|
||||
define linkonce i64 @"__llgo_stub.main.add$1"(ptr %0, i64 %1, i64 %2) {
|
||||
_llgo_0:
|
||||
%3 = tail call i64 @"main.add$1"(i64 %1, i64 %2)
|
||||
ret i64 %3
|
||||
}
|
||||
|
||||
define i64 @"main.add2$1"(i64 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = add i64 %0, %1
|
||||
ret i64 %2
|
||||
}
|
||||
|
||||
define linkonce i64 @"__llgo_stub.main.add2$1"(ptr %0, i64 %1, i64 %2) {
|
||||
_llgo_0:
|
||||
%3 = tail call i64 @"main.add2$1"(i64 %1, i64 %2)
|
||||
ret i64 %3
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
define { ptr, ptr } @"main.main$1"() {
|
||||
_llgo_0:
|
||||
%0 = alloca { ptr, ptr }, align 8
|
||||
@@ -109,14 +95,28 @@ _llgo_0:
|
||||
ret { ptr, ptr } %3
|
||||
}
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
define i64 @"main.main$1$1"(i64 %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = add i64 %0, %1
|
||||
ret i64 %2
|
||||
}
|
||||
|
||||
define linkonce i64 @"__llgo_stub.main.add$1"(ptr %0, i64 %1, i64 %2) {
|
||||
_llgo_0:
|
||||
%3 = tail call i64 @"main.add$1"(i64 %1, i64 %2)
|
||||
ret i64 %3
|
||||
}
|
||||
|
||||
define linkonce i64 @"__llgo_stub.main.add2$1"(ptr %0, i64 %1, i64 %2) {
|
||||
_llgo_0:
|
||||
%3 = tail call i64 @"main.add2$1"(i64 %1, i64 %2)
|
||||
ret i64 %3
|
||||
}
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
define linkonce i64 @"__llgo_stub.main.main$1$1"(ptr %0, i64 %1, i64 %2) {
|
||||
_llgo_0:
|
||||
%3 = tail call i64 @"main.main$1$1"(i64 %1, i64 %2)
|
||||
|
||||
@@ -13,6 +13,7 @@ _llgo_0:
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"main.init$guard", align 1
|
||||
call void @syscall.init()
|
||||
store i8 72, ptr @main.format, align 1
|
||||
store i8 101, ptr getelementptr inbounds (i8, ptr @main.format, i64 1), align 1
|
||||
store i8 108, ptr getelementptr inbounds (i8, ptr @main.format, i64 2), align 1
|
||||
@@ -40,6 +41,8 @@ _llgo_0:
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
declare void @syscall.init()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare i32 @strlen(ptr)
|
||||
|
||||
@@ -41,6 +41,7 @@ _llgo_0:
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"main.init$guard", align 1
|
||||
call void @syscall.init()
|
||||
store i8 72, ptr @main.format, align 1
|
||||
store i8 101, ptr getelementptr inbounds (i8, ptr @main.format, i64 1), align 1
|
||||
store i8 108, ptr getelementptr inbounds (i8, ptr @main.format, i64 2), align 1
|
||||
@@ -78,4 +79,6 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)
|
||||
|
||||
declare void @printf(ptr, ...)
|
||||
|
||||
declare void @syscall.init()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
@@ -55,19 +55,22 @@ _llgo_0:
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
%2 = phi i64 [ 0, %_llgo_0 ], [ %10, %_llgo_2 ]
|
||||
%2 = phi i64 [ 0, %_llgo_0 ], [ %13, %_llgo_2 ]
|
||||
%3 = phi i64 [ -1, %_llgo_0 ], [ %4, %_llgo_2 ]
|
||||
%4 = add i64 %3, 1
|
||||
%5 = icmp slt i64 %4, %1
|
||||
br i1 %5, label %_llgo_2, label %_llgo_3
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1
|
||||
%6 = icmp slt i64 %4, 0
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %6)
|
||||
%7 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%8 = getelementptr inbounds i64, ptr %7, i64 %4
|
||||
%9 = load i64, ptr %8, align 4
|
||||
%10 = add i64 %2, %9
|
||||
%6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0
|
||||
%7 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1
|
||||
%8 = icmp slt i64 %4, 0
|
||||
%9 = icmp sge i64 %4, %7
|
||||
%10 = or i1 %9, %8
|
||||
call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %10)
|
||||
%11 = getelementptr inbounds i64, ptr %6, i64 %4
|
||||
%12 = load i64, ptr %11, align 4
|
||||
%13 = add i64 %2, %12
|
||||
br label %_llgo_1
|
||||
|
||||
_llgo_3: ; preds = %_llgo_1
|
||||
|
||||
@@ -29,6 +29,7 @@ _llgo_0:
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"main.init$guard", align 1
|
||||
call void @syscall.init()
|
||||
store i8 72, ptr @main.format, align 1
|
||||
store i8 101, ptr getelementptr inbounds (i8, ptr @main.format, i64 1), align 1
|
||||
store i8 108, ptr getelementptr inbounds (i8, ptr @main.format, i64 2), align 1
|
||||
@@ -62,6 +63,8 @@ _llgo_0:
|
||||
|
||||
declare void @printf(ptr, ...)
|
||||
|
||||
declare void @syscall.init()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
|
||||
|
||||
@@ -104,7 +104,7 @@ func testBlockInfo(t *testing.T, src any, fname, expected, fn string) {
|
||||
pkg := types.NewPackage(name, name)
|
||||
imp := packages.NewImporter(fset)
|
||||
foo, _, err := ssautil.BuildPackage(
|
||||
&types.Config{Importer: imp}, fset, pkg, files, ssa.SanityCheckFunctions)
|
||||
&types.Config{Importer: imp}, fset, pkg, files, ssa.SanityCheckFunctions|ssa.InstantiateGenerics)
|
||||
if err != nil {
|
||||
t.Fatal("BuildPackage failed:", err)
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ import (
|
||||
|
||||
func TestCollectSkipNames(t *testing.T) {
|
||||
ctx := &context{skips: make(map[string]none)}
|
||||
ctx.collectSkipNames("//llgo:skipall")
|
||||
ctx.collectSkipNames("//llgo:skip")
|
||||
ctx.collectSkipNames("//llgo:skip abs")
|
||||
}
|
||||
|
||||
@@ -135,11 +137,17 @@ func TestErrBuiltin(t *testing.T) {
|
||||
test("advance", func(ctx *context) { ctx.advance(nil, nil) })
|
||||
test("alloca", func(ctx *context) { ctx.alloca(nil, nil) })
|
||||
test("allocaCStr", func(ctx *context) { ctx.allocaCStr(nil, nil) })
|
||||
test("string", func(ctx *context) { ctx.string(nil, nil) })
|
||||
test("stringData", func(ctx *context) { ctx.stringData(nil, nil) })
|
||||
test("funcAddr", func(ctx *context) { ctx.funcAddr(nil, nil) })
|
||||
test("sigsetjmp", func(ctx *context) { ctx.sigsetjmp(nil, nil) })
|
||||
test("siglongjmp", func(ctx *context) { ctx.siglongjmp(nil, nil) })
|
||||
test("cstr(NoArgs)", func(ctx *context) { cstr(nil, nil) })
|
||||
test("cstr(Nonconst)", func(ctx *context) { cstr(nil, []ssa.Value{&ssa.Parameter{}}) })
|
||||
test("atomic", func(ctx *context) { ctx.atomic(nil, 0, nil) })
|
||||
test("atomicLoad", func(ctx *context) { ctx.atomicLoad(nil, nil) })
|
||||
test("atomicStore", func(ctx *context) { ctx.atomicStore(nil, nil) })
|
||||
test("atomicCmpXchg", func(ctx *context) { ctx.atomicCmpXchg(nil, nil) })
|
||||
}
|
||||
|
||||
func TestPkgNoInit(t *testing.T) {
|
||||
@@ -205,7 +213,7 @@ func TestIntVal(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIgnoreName(t *testing.T) {
|
||||
if !ignoreName("runtime.foo") || !ignoreName("runtime/foo") || !ignoreName("internal/abi") {
|
||||
if !ignoreName("runtime/foo") || !ignoreName("internal/abi") {
|
||||
t.Fatal("ignoreName failed")
|
||||
}
|
||||
}
|
||||
@@ -214,6 +222,13 @@ func TestErrImport(t *testing.T) {
|
||||
var ctx context
|
||||
pkg := types.NewPackage("foo", "foo")
|
||||
ctx.importPkg(pkg, nil)
|
||||
|
||||
alt := types.NewPackage("bar", "bar")
|
||||
alt.Scope().Insert(
|
||||
types.NewConst(0, alt, "LLGoPackage", types.Typ[types.String], constant.MakeString("noinit")),
|
||||
)
|
||||
ctx.patches = Patches{"foo": &ssa.Package{Pkg: alt}}
|
||||
ctx.importPkg(pkg, &pkgInfo{})
|
||||
}
|
||||
|
||||
func TestErrInitLinkname(t *testing.T) {
|
||||
|
||||
@@ -139,7 +139,7 @@ func TestCompileEx(t *testing.T, src any, fname, expected string) {
|
||||
pkg := types.NewPackage(name, name)
|
||||
imp := packages.NewImporter(fset)
|
||||
foo, _, err := ssautil.BuildPackage(
|
||||
&types.Config{Importer: imp}, fset, pkg, files, ssa.SanityCheckFunctions)
|
||||
&types.Config{Importer: imp}, fset, pkg, files, ssa.SanityCheckFunctions|ssa.InstantiateGenerics)
|
||||
if err != nil {
|
||||
t.Fatal("BuildPackage failed:", err)
|
||||
}
|
||||
|
||||
410
cl/compile.go
410
cl/compile.go
@@ -25,11 +25,12 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/goplus/llgo/cl/blocks"
|
||||
llssa "github.com/goplus/llgo/ssa"
|
||||
"github.com/goplus/llgo/internal/typepatch"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
|
||||
llssa "github.com/goplus/llgo/ssa"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -56,66 +57,6 @@ func SetDebug(dbgFlags dbgFlags) {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
fnNormal = iota
|
||||
fnHasVArg
|
||||
fnIgnore
|
||||
)
|
||||
|
||||
func (p *context) funcKind(vfn ssa.Value) int {
|
||||
if fn, ok := vfn.(*ssa.Function); ok {
|
||||
params := fn.Signature.Params()
|
||||
n := params.Len()
|
||||
if n == 0 {
|
||||
if fn.Signature.Recv() == nil {
|
||||
if fn.Name() == "init" && p.pkgNoInit(fn.Pkg.Pkg) {
|
||||
return fnIgnore
|
||||
}
|
||||
}
|
||||
} else {
|
||||
last := params.At(n - 1)
|
||||
if last.Name() == llssa.NameValist {
|
||||
return fnHasVArg
|
||||
}
|
||||
}
|
||||
}
|
||||
return fnNormal
|
||||
}
|
||||
|
||||
func (p *context) pkgNoInit(pkg *types.Package) bool {
|
||||
p.ensureLoaded(pkg)
|
||||
if i, ok := p.loaded[pkg]; ok {
|
||||
return i.kind >= PkgNoInit
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ignoreName(name string) bool {
|
||||
/* TODO(xsw): confirm this is not needed more
|
||||
if name == "unsafe.init" {
|
||||
return true
|
||||
}
|
||||
*/
|
||||
if strings.HasPrefix(name, "internal/") || strings.HasPrefix(name, "crypto/") ||
|
||||
strings.HasPrefix(name, "arena.") || strings.HasPrefix(name, "maps.") ||
|
||||
strings.HasPrefix(name, "time.") || strings.HasPrefix(name, "syscall.") ||
|
||||
strings.HasPrefix(name, "os.") || strings.HasPrefix(name, "plugin.") ||
|
||||
strings.HasPrefix(name, "reflect.") || strings.HasPrefix(name, "errors.") {
|
||||
return true // TODO(xsw)
|
||||
}
|
||||
return inPkg(name, "runtime") || inPkg(name, "sync")
|
||||
}
|
||||
|
||||
func inPkg(name, pkg string) bool {
|
||||
if len(name) > len(pkg) && strings.HasPrefix(name, pkg) {
|
||||
c := name[len(pkg)]
|
||||
return c == '.' || c == '/'
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type instrOrValue interface {
|
||||
ssa.Instruction
|
||||
ssa.Value
|
||||
@@ -153,14 +94,29 @@ type context struct {
|
||||
bvals map[ssa.Value]llssa.Expr // block values
|
||||
vargs map[*ssa.Alloc][]llssa.Expr // varargs
|
||||
|
||||
patches Patches
|
||||
blkInfos []blocks.Info
|
||||
|
||||
inits []func()
|
||||
phis []func()
|
||||
|
||||
state pkgState
|
||||
inCFunc bool
|
||||
skipall bool
|
||||
}
|
||||
|
||||
type pkgState byte
|
||||
|
||||
const (
|
||||
pkgNormal pkgState = iota
|
||||
pkgHasPatch
|
||||
pkgInPatch
|
||||
|
||||
pkgFNoOldInit = 0x80 // flag if no initFnNameOld
|
||||
)
|
||||
|
||||
func (p *context) inMain(instr ssa.Instruction) bool {
|
||||
return instr.Parent().Name() == "main"
|
||||
return p.fn.Name() == "main"
|
||||
}
|
||||
|
||||
func (p *context) compileType(pkg llssa.Package, t *ssa.Type) {
|
||||
@@ -194,7 +150,7 @@ func (p *context) compileMethods(pkg llssa.Package, typ types.Type) {
|
||||
|
||||
// Global variable.
|
||||
func (p *context) compileGlobal(pkg llssa.Package, gbl *ssa.Global) {
|
||||
typ := gbl.Type()
|
||||
typ := globalType(gbl)
|
||||
name, vtype, define := p.varName(gbl.Pkg.Pkg, gbl)
|
||||
if vtype == pyVar || ignoreName(name) || checkCgo(gbl.Name()) {
|
||||
return
|
||||
@@ -234,12 +190,18 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
||||
*/
|
||||
return nil, nil, ignoredFunc
|
||||
}
|
||||
sig := f.Signature
|
||||
state := p.state
|
||||
isInit := (f.Name() == "init" && sig.Recv() == nil)
|
||||
if isInit && state == pkgHasPatch {
|
||||
name = initFnNameOfHasPatch(name)
|
||||
}
|
||||
|
||||
fn := pkg.FuncOf(name)
|
||||
if fn != nil && fn.HasBody() {
|
||||
return fn, nil, goFunc
|
||||
}
|
||||
|
||||
var sig = f.Signature
|
||||
var hasCtx = len(f.FreeVars) > 0
|
||||
if hasCtx {
|
||||
if debugInstr {
|
||||
@@ -265,9 +227,13 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
||||
}
|
||||
|
||||
if nblk := len(f.Blocks); nblk > 0 {
|
||||
fn.MakeBlocks(nblk) // to set fn.HasBody() = true
|
||||
fn.MakeBlocks(nblk) // to set fn.HasBody() = true
|
||||
if f.Recover != nil { // set recover block
|
||||
fn.SetRecover(fn.Block(f.Recover.Index))
|
||||
}
|
||||
p.inits = append(p.inits, func() {
|
||||
p.fn = fn
|
||||
p.state = state // restore pkgState when compiling funcBody
|
||||
defer func() {
|
||||
p.fn = nil
|
||||
}()
|
||||
@@ -289,7 +255,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
||||
for {
|
||||
block := f.Blocks[i]
|
||||
doMainInit := (i == 0 && name == "main")
|
||||
doModInit := (i == 1 && f.Name() == "init" && sig.Recv() == nil)
|
||||
doModInit := (i == 1 && isInit)
|
||||
p.compileBlock(b, block, off[i], doMainInit, doModInit)
|
||||
if i = p.blkInfos[i].Next; i < 0 {
|
||||
break
|
||||
@@ -300,74 +266,21 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
||||
}
|
||||
b.EndBuild()
|
||||
})
|
||||
for _, af := range f.AnonFuncs {
|
||||
p.compileFuncDecl(pkg, af)
|
||||
}
|
||||
}
|
||||
return fn, nil, goFunc
|
||||
}
|
||||
|
||||
// funcOf returns a function by name and set ftype = goFunc, cFunc, etc.
|
||||
// or returns nil and set ftype = llgoCstr, llgoAlloca, llgoUnreachable, etc.
|
||||
func (p *context) funcOf(fn *ssa.Function) (aFn llssa.Function, pyFn llssa.PyObjRef, ftype int) {
|
||||
pkgTypes, name, ftype := p.funcName(fn, false)
|
||||
switch ftype {
|
||||
case pyFunc:
|
||||
if kind, mod := pkgKindByScope(pkgTypes.Scope()); kind == PkgPyModule {
|
||||
pkg := p.pkg
|
||||
fnName := pysymPrefix + mod + "." + name
|
||||
if pyFn = pkg.PyObjOf(fnName); pyFn == nil {
|
||||
pyFn = pkg.PyNewFunc(fnName, fn.Signature, true)
|
||||
}
|
||||
return
|
||||
}
|
||||
ftype = ignoredFunc
|
||||
case llgoInstr:
|
||||
switch name {
|
||||
case "cstr":
|
||||
ftype = llgoCstr
|
||||
case "advance":
|
||||
ftype = llgoAdvance
|
||||
case "index":
|
||||
ftype = llgoIndex
|
||||
case "alloca":
|
||||
ftype = llgoAlloca
|
||||
case "allocaCStr":
|
||||
ftype = llgoAllocaCStr
|
||||
case "stringData":
|
||||
ftype = llgoStringData
|
||||
case "pyList":
|
||||
ftype = llgoPyList
|
||||
case "sigjmpbuf":
|
||||
ftype = llgoSigjmpbuf
|
||||
case "sigsetjmp":
|
||||
ftype = llgoSigsetjmp
|
||||
case "siglongjmp":
|
||||
ftype = llgoSiglongjmp
|
||||
case "deferData":
|
||||
ftype = llgoDeferData
|
||||
case "unreachable":
|
||||
ftype = llgoUnreachable
|
||||
default:
|
||||
panic("unknown llgo instruction: " + name)
|
||||
}
|
||||
default:
|
||||
pkg := p.pkg
|
||||
if aFn = pkg.FuncOf(name); aFn == nil {
|
||||
if len(fn.FreeVars) > 0 {
|
||||
return nil, nil, ignoredFunc
|
||||
}
|
||||
sig := fn.Signature
|
||||
aFn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), false)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, doMainInit, doModInit bool) llssa.BasicBlock {
|
||||
var last int
|
||||
var pyModInit bool
|
||||
var prog = p.prog
|
||||
var pkg = p.pkg
|
||||
var fn = p.fn
|
||||
var instrs = block.Instrs[n:]
|
||||
var ret = p.fn.Block(block.Index)
|
||||
var ret = fn.Block(block.Index)
|
||||
b.SetBlock(ret)
|
||||
if doModInit {
|
||||
if pyModInit = p.pyMod != ""; pyModInit {
|
||||
@@ -380,7 +293,6 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
|
||||
})
|
||||
}
|
||||
} else if doMainInit {
|
||||
fn := p.fn
|
||||
argc := pkg.NewVar("__llgo_argc", types.NewPointer(types.Typ[types.Int32]), llssa.InC)
|
||||
argv := pkg.NewVar("__llgo_argv", types.NewPointer(argvTy), llssa.InC)
|
||||
argc.InitNil()
|
||||
@@ -390,7 +302,12 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
|
||||
callRuntimeInit(b, pkg)
|
||||
b.Call(pkg.FuncOf("main.init").Expr)
|
||||
}
|
||||
for _, instr := range instrs {
|
||||
for i, instr := range instrs {
|
||||
if i == 1 && doModInit && p.state == pkgInPatch {
|
||||
initFnNameOld := initFnNameOfHasPatch(p.fn.Name())
|
||||
fnOld := pkg.NewFunc(initFnNameOld, llssa.NoArgsNoRet, llssa.InC)
|
||||
b.Call(fnOld.Expr)
|
||||
}
|
||||
p.compileInstr(b, instr)
|
||||
}
|
||||
if pyModInit {
|
||||
@@ -401,7 +318,7 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
|
||||
modPtr := pkg.PyNewModVar(modName, true).Expr
|
||||
mod := b.Load(modPtr)
|
||||
cond := b.BinOp(token.NEQ, mod, prog.Nil(mod.Type))
|
||||
newBlk := p.fn.MakeBlock()
|
||||
newBlk := fn.MakeBlock()
|
||||
b.If(cond, jumpTo, newBlk)
|
||||
b.SetBlockEx(newBlk, llssa.AtEnd, false)
|
||||
b.Store(modPtr, b.PyImportMod(modPath))
|
||||
@@ -478,80 +395,6 @@ func isAllocVargs(ctx *context, v *ssa.Alloc) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// func cstr(string) *int8
|
||||
func cstr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 1 {
|
||||
if c, ok := args[0].(*ssa.Const); ok {
|
||||
if v := c.Value; v.Kind() == constant.String {
|
||||
sv := constant.StringVal(v)
|
||||
return b.CStr(sv)
|
||||
}
|
||||
}
|
||||
}
|
||||
panic("cstr(<string-literal>): invalid arguments")
|
||||
}
|
||||
|
||||
// func index(arr *T, idx int) T
|
||||
func (p *context) index(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
return b.Load(p.advance(b, args))
|
||||
}
|
||||
|
||||
// func advance(ptr *T, offset int) *T
|
||||
func (p *context) advance(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 2 {
|
||||
ptr := p.compileValue(b, args[0])
|
||||
offset := p.compileValue(b, args[1])
|
||||
return b.Advance(ptr, offset)
|
||||
}
|
||||
panic("advance(p ptr, offset int): invalid arguments")
|
||||
}
|
||||
|
||||
// func alloca(size uintptr) unsafe.Pointer
|
||||
func (p *context) alloca(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 1 {
|
||||
n := p.compileValue(b, args[0])
|
||||
return b.Alloca(n)
|
||||
}
|
||||
panic("alloca(size uintptr): invalid arguments")
|
||||
}
|
||||
|
||||
// func allocaCStr(s string) *int8
|
||||
func (p *context) allocaCStr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 1 {
|
||||
s := p.compileValue(b, args[0])
|
||||
return b.AllocaCStr(s)
|
||||
}
|
||||
panic("allocaCStr(s string): invalid arguments")
|
||||
}
|
||||
|
||||
// func stringData(s string) *int8
|
||||
func (p *context) stringData(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 1 {
|
||||
s := p.compileValue(b, args[0])
|
||||
return b.StringData(s)
|
||||
}
|
||||
panic("stringData(s string): invalid arguments")
|
||||
}
|
||||
|
||||
func (p *context) sigsetjmp(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 2 {
|
||||
jb := p.compileValue(b, args[0])
|
||||
savemask := p.compileValue(b, args[1])
|
||||
return b.Sigsetjmp(jb, savemask)
|
||||
}
|
||||
panic("sigsetjmp(jb c.SigjmpBuf, savemask c.Int): invalid arguments")
|
||||
}
|
||||
|
||||
func (p *context) siglongjmp(b llssa.Builder, args []ssa.Value) {
|
||||
if len(args) == 2 {
|
||||
jb := p.compileValue(b, args[0])
|
||||
retval := p.compileValue(b, args[1])
|
||||
b.Siglongjmp(jb, retval)
|
||||
return
|
||||
}
|
||||
panic("siglongjmp(jb c.SigjmpBuf, retval c.Int): invalid arguments")
|
||||
}
|
||||
|
||||
func isPhi(i ssa.Instruction) bool {
|
||||
_, ok := i.(*ssa.Phi)
|
||||
return ok
|
||||
@@ -560,9 +403,6 @@ func isPhi(i ssa.Instruction) bool {
|
||||
func (p *context) compilePhis(b llssa.Builder, block *ssa.BasicBlock) int {
|
||||
fn := p.fn
|
||||
ret := fn.Block(block.Index)
|
||||
if block.Comment == "recover" { // set recover block
|
||||
fn.SetRecover(ret)
|
||||
}
|
||||
b.SetBlockEx(ret, llssa.AtEnd, false)
|
||||
if ninstr := len(block.Instrs); ninstr > 0 {
|
||||
if isPhi(block.Instrs[0]) {
|
||||
@@ -603,79 +443,6 @@ func (p *context) compilePhi(b llssa.Builder, v *ssa.Phi) (ret llssa.Expr) {
|
||||
return
|
||||
}
|
||||
|
||||
func (p *context) call(b llssa.Builder, act llssa.DoAction, call *ssa.CallCommon) (ret llssa.Expr) {
|
||||
cv := call.Value
|
||||
if mthd := call.Method; mthd != nil {
|
||||
o := p.compileValue(b, cv)
|
||||
fn := b.Imethod(o, mthd)
|
||||
args := p.compileValues(b, call.Args, fnNormal)
|
||||
ret = b.Do(act, fn, args...)
|
||||
return
|
||||
}
|
||||
kind := p.funcKind(cv)
|
||||
if kind == fnIgnore {
|
||||
return
|
||||
}
|
||||
args := call.Args
|
||||
if debugGoSSA {
|
||||
log.Println(">>> Do", act, cv, args)
|
||||
}
|
||||
switch cv := cv.(type) {
|
||||
case *ssa.Builtin:
|
||||
fn := cv.Name()
|
||||
if fn == "ssa:wrapnilchk" { // TODO(xsw): check nil ptr
|
||||
arg := args[0]
|
||||
ret = p.compileValue(b, arg)
|
||||
} else {
|
||||
args := p.compileValues(b, args, kind)
|
||||
ret = b.Do(act, llssa.Builtin(fn), args...)
|
||||
}
|
||||
case *ssa.Function:
|
||||
aFn, pyFn, ftype := p.compileFunction(cv)
|
||||
// TODO(xsw): check ca != llssa.Call
|
||||
switch ftype {
|
||||
case goFunc, cFunc:
|
||||
args := p.compileValues(b, args, kind)
|
||||
ret = b.Do(act, aFn.Expr, args...)
|
||||
case pyFunc:
|
||||
args := p.compileValues(b, args, kind)
|
||||
ret = b.Do(act, pyFn.Expr, args...)
|
||||
case llgoPyList:
|
||||
args := p.compileValues(b, args, fnHasVArg)
|
||||
ret = b.PyList(args...)
|
||||
case llgoCstr:
|
||||
ret = cstr(b, args)
|
||||
case llgoAdvance:
|
||||
ret = p.advance(b, args)
|
||||
case llgoIndex:
|
||||
ret = p.index(b, args)
|
||||
case llgoAlloca:
|
||||
ret = p.alloca(b, args)
|
||||
case llgoAllocaCStr:
|
||||
ret = p.allocaCStr(b, args)
|
||||
case llgoStringData:
|
||||
ret = p.stringData(b, args)
|
||||
case llgoSigsetjmp:
|
||||
ret = p.sigsetjmp(b, args)
|
||||
case llgoSiglongjmp:
|
||||
p.siglongjmp(b, args)
|
||||
case llgoSigjmpbuf: // func sigjmpbuf()
|
||||
ret = b.AllocaSigjmpBuf()
|
||||
case llgoDeferData: // func deferData() *Defer
|
||||
ret = b.DeferData()
|
||||
case llgoUnreachable: // func unreachable()
|
||||
b.Unreachable()
|
||||
default:
|
||||
log.Panicln("unknown ftype:", ftype)
|
||||
}
|
||||
default:
|
||||
fn := p.compileValue(b, cv)
|
||||
args := p.compileValues(b, args, kind)
|
||||
ret = b.Do(act, fn, args...)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue bool) (ret llssa.Expr) {
|
||||
if asValue {
|
||||
if v, ok := p.bvals[iv]; ok {
|
||||
@@ -722,10 +489,14 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
|
||||
case *ssa.Index:
|
||||
x := p.compileValue(b, v.X)
|
||||
idx := p.compileValue(b, v.Index)
|
||||
ret = b.Index(x, idx, func(e llssa.Expr) (ret llssa.Expr) {
|
||||
ret = b.Index(x, idx, func(e llssa.Expr) (ret llssa.Expr, zero bool) {
|
||||
if e == x {
|
||||
if n, ok := v.X.(*ssa.UnOp); ok {
|
||||
return p.compileValue(b, n.X)
|
||||
switch n := v.X.(type) {
|
||||
case *ssa.Const:
|
||||
zero = true
|
||||
return
|
||||
case *ssa.UnOp:
|
||||
return p.compileValue(b, n.X), false
|
||||
}
|
||||
}
|
||||
panic(fmt.Errorf("todo: addr of %v", e))
|
||||
@@ -753,12 +524,19 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
|
||||
ret = b.Slice(x, low, high, max)
|
||||
case *ssa.MakeInterface:
|
||||
if refs := *v.Referrers(); len(refs) == 1 {
|
||||
if ref, ok := refs[0].(*ssa.Store); ok {
|
||||
switch ref := refs[0].(type) {
|
||||
case *ssa.Store:
|
||||
if va, ok := ref.Addr.(*ssa.IndexAddr); ok {
|
||||
if _, ok = p.isVArgs(va.X); ok { // varargs: this is a varargs store
|
||||
return
|
||||
}
|
||||
}
|
||||
case *ssa.Call:
|
||||
if fn, ok := ref.Call.Value.(*ssa.Function); ok {
|
||||
if _, _, ftype := p.funcOf(fn); ftype == llgoFuncAddr { // llgo.funcAddr
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
t := p.prog.Type(v.Type(), llssa.InGo)
|
||||
@@ -914,7 +692,11 @@ func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr {
|
||||
return p.varOf(b, v)
|
||||
case *ssa.Const:
|
||||
t := types.Default(v.Type())
|
||||
return b.Const(v.Value, p.prog.Type(t, llssa.InGo))
|
||||
bg := llssa.InGo
|
||||
if p.inCFunc {
|
||||
bg = llssa.InC
|
||||
}
|
||||
return b.Const(v.Value, p.prog.Type(t, bg))
|
||||
case *ssa.FreeVar:
|
||||
fn := v.Parent()
|
||||
for idx, freeVar := range fn.FreeVars {
|
||||
@@ -955,33 +737,41 @@ func (p *context) compileValues(b llssa.Builder, vals []ssa.Value, hasVArg int)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Patches is patches of some packages.
|
||||
type Patches = map[string]*ssa.Package
|
||||
|
||||
// NewPackage compiles a Go package to LLVM IR package.
|
||||
func NewPackage(prog llssa.Program, pkg *ssa.Package, files []*ast.File) (ret llssa.Package, err error) {
|
||||
return NewPackageEx(prog, pkg, nil, files)
|
||||
return NewPackageEx(prog, nil, pkg, files)
|
||||
}
|
||||
|
||||
// NewPackageEx compiles a Go package (pkg) to LLVM IR package.
|
||||
// The Go package may have an alternative package (alt).
|
||||
// The pkg and alt have the same (Pkg *types.Package).
|
||||
func NewPackageEx(prog llssa.Program, pkg, alt *ssa.Package, files []*ast.File) (ret llssa.Package, err error) {
|
||||
// NewPackageEx compiles a Go package to LLVM IR package.
|
||||
func NewPackageEx(prog llssa.Program, patches Patches, pkg *ssa.Package, files []*ast.File) (ret llssa.Package, err error) {
|
||||
pkgProg := pkg.Prog
|
||||
pkgTypes := pkg.Pkg
|
||||
pkgName, pkgPath := pkgTypes.Name(), llssa.PathOf(pkgTypes)
|
||||
alt, hasPatch := patches[pkgPath]
|
||||
if hasPatch {
|
||||
pkgTypes = typepatch.Pkg(pkgTypes, alt.Pkg)
|
||||
pkg.Pkg = pkgTypes
|
||||
alt.Pkg = pkgTypes
|
||||
}
|
||||
if pkgPath == llssa.PkgRuntime {
|
||||
prog.SetRuntime(pkgTypes)
|
||||
}
|
||||
ret = prog.NewPackage(pkgName, pkgPath)
|
||||
|
||||
ctx := &context{
|
||||
prog: prog,
|
||||
pkg: ret,
|
||||
fset: pkgProg.Fset,
|
||||
goProg: pkgProg,
|
||||
goTyps: pkgTypes,
|
||||
goPkg: pkg,
|
||||
link: make(map[string]string),
|
||||
skips: make(map[string]none),
|
||||
vargs: make(map[*ssa.Alloc][]llssa.Expr),
|
||||
prog: prog,
|
||||
pkg: ret,
|
||||
fset: pkgProg.Fset,
|
||||
goProg: pkgProg,
|
||||
goTyps: pkgTypes,
|
||||
goPkg: pkg,
|
||||
patches: patches,
|
||||
link: make(map[string]string),
|
||||
skips: make(map[string]none),
|
||||
vargs: make(map[*ssa.Alloc][]llssa.Expr),
|
||||
loaded: map[*types.Package]*pkgInfo{
|
||||
types.Unsafe: {kind: PkgDeclOnly}, // TODO(xsw): PkgNoInit or PkgDeclOnly?
|
||||
},
|
||||
@@ -989,13 +779,20 @@ func NewPackageEx(prog llssa.Program, pkg, alt *ssa.Package, files []*ast.File)
|
||||
ctx.initPyModule()
|
||||
ctx.initFiles(pkgPath, files)
|
||||
|
||||
if alt != nil {
|
||||
if hasPatch {
|
||||
skips := ctx.skips
|
||||
ctx.skips = nil
|
||||
ctx.state = pkgInPatch
|
||||
if _, ok := skips["init"]; ok || ctx.skipall {
|
||||
ctx.state |= pkgFNoOldInit
|
||||
}
|
||||
processPkg(ctx, ret, alt)
|
||||
ctx.state = pkgHasPatch
|
||||
ctx.skips = skips
|
||||
}
|
||||
processPkg(ctx, ret, pkg)
|
||||
if !ctx.skipall {
|
||||
processPkg(ctx, ret, pkg)
|
||||
}
|
||||
for len(ctx.inits) > 0 {
|
||||
inits := ctx.inits
|
||||
ctx.inits = nil
|
||||
@@ -1006,6 +803,10 @@ func NewPackageEx(prog llssa.Program, pkg, alt *ssa.Package, files []*ast.File)
|
||||
return
|
||||
}
|
||||
|
||||
func initFnNameOfHasPatch(name string) string {
|
||||
return name + "$hasPatch"
|
||||
}
|
||||
|
||||
func processPkg(ctx *context, ret llssa.Package, pkg *ssa.Package) {
|
||||
type namedMember struct {
|
||||
name string
|
||||
@@ -1041,4 +842,15 @@ func processPkg(ctx *context, ret llssa.Package, pkg *ssa.Package) {
|
||||
}
|
||||
}
|
||||
|
||||
func globalType(gbl *ssa.Global) types.Type {
|
||||
t := gbl.Type()
|
||||
if t, ok := t.(*types.Named); ok {
|
||||
o := t.Obj()
|
||||
if pkg := o.Pkg(); typepatch.IsPatched(pkg) {
|
||||
return gbl.Pkg.Pkg.Scope().Lookup(o.Name()).Type()
|
||||
}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
113
cl/import.go
113
cl/import.go
@@ -26,8 +26,9 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
llssa "github.com/goplus/llgo/ssa"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
|
||||
llssa "github.com/goplus/llgo/ssa"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -127,14 +128,22 @@ func pkgKindByScope(scope *types.Scope) (int, string) {
|
||||
}
|
||||
|
||||
func (p *context) importPkg(pkg *types.Package, i *pkgInfo) {
|
||||
pkgPath := llssa.PathOf(pkg)
|
||||
scope := pkg.Scope()
|
||||
kind, _ := pkgKindByScope(scope)
|
||||
if kind == PkgNormal {
|
||||
if alt, ok := p.patches[pkgPath]; ok {
|
||||
pkg = alt.Pkg
|
||||
scope = pkg.Scope()
|
||||
if kind, _ = pkgKindByScope(scope); kind != PkgNormal {
|
||||
goto start
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
start:
|
||||
i.kind = kind
|
||||
fset := p.fset
|
||||
pkgPath := llssa.PathOf(pkg)
|
||||
names := scope.Names()
|
||||
syms := newPkgSymInfo()
|
||||
for _, name := range names {
|
||||
@@ -193,10 +202,12 @@ func (p *context) initFiles(pkgPath string, files []*ast.File) {
|
||||
}
|
||||
}
|
||||
|
||||
// llgo:skip symbol1 symbol2 ...
|
||||
// llgo:skipall
|
||||
func (p *context) collectSkipNames(line string) {
|
||||
const (
|
||||
skip = "//llgo:skip "
|
||||
skip2 = "// llgo:skip "
|
||||
skip = "//llgo:skip"
|
||||
skip2 = "// llgo:skip"
|
||||
)
|
||||
if strings.HasPrefix(line, skip2) {
|
||||
p.collectSkip(line, len(skip2))
|
||||
@@ -206,7 +217,15 @@ func (p *context) collectSkipNames(line string) {
|
||||
}
|
||||
|
||||
func (p *context) collectSkip(line string, prefix int) {
|
||||
names := strings.Split(line[prefix:], " ")
|
||||
line = line[prefix:]
|
||||
if line == "all" {
|
||||
p.skipall = true
|
||||
return
|
||||
}
|
||||
if len(line) == 0 || line[0] != ' ' {
|
||||
return
|
||||
}
|
||||
names := strings.Split(line[1:], " ")
|
||||
for _, name := range names {
|
||||
if name != "" {
|
||||
p.skips[name] = none{}
|
||||
@@ -258,14 +277,18 @@ func (p *context) initLink(line string, prefix int, f func(inPkgName string) (fu
|
||||
}
|
||||
}
|
||||
|
||||
func recvTypeName(t ast.Expr) string {
|
||||
switch t := t.(type) {
|
||||
func recvTypeName(typ ast.Expr) string {
|
||||
retry:
|
||||
switch t := typ.(type) {
|
||||
case *ast.Ident:
|
||||
return t.Name
|
||||
case *ast.IndexExpr:
|
||||
return trecvTypeName(t.X, t.Index)
|
||||
case *ast.IndexListExpr:
|
||||
return trecvTypeName(t.X, t.Indices...)
|
||||
case *ast.ParenExpr:
|
||||
typ = t.X
|
||||
goto retry
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
@@ -318,8 +341,24 @@ func typesFuncName(pkgPath string, fn *types.Func) (fullName, inPkgName string)
|
||||
// - func: pkg.name
|
||||
// - method: pkg.(T).name, pkg.(*T).name
|
||||
func funcName(pkg *types.Package, fn *ssa.Function) string {
|
||||
sig := fn.Signature
|
||||
return llssa.FuncName(pkg, fn.Name(), sig.Recv())
|
||||
var recv *types.Var
|
||||
parent := fn.Parent()
|
||||
if parent != nil { // closure in method
|
||||
recv = parent.Signature.Recv()
|
||||
} else {
|
||||
recv = fn.Signature.Recv()
|
||||
}
|
||||
var fnName string
|
||||
if org := fn.Origin(); org != nil {
|
||||
targs := make([]string, len(fn.TypeArgs()))
|
||||
for i, t := range fn.TypeArgs() {
|
||||
targs[i] = types.TypeString(t, llssa.PathOf)
|
||||
}
|
||||
fnName = org.Name() + "[" + strings.Join(targs, ", ") + "]"
|
||||
} else {
|
||||
fnName = fn.Name()
|
||||
}
|
||||
return llssa.FuncName(pkg, fnName, recv)
|
||||
}
|
||||
|
||||
func checkCgo(fnName string) bool {
|
||||
@@ -342,12 +381,35 @@ const (
|
||||
llgoAllocaCStr = llgoInstrBase + 3
|
||||
llgoAdvance = llgoInstrBase + 4
|
||||
llgoIndex = llgoInstrBase + 5
|
||||
llgoStringData = llgoInstrBase + 6
|
||||
llgoPyList = llgoInstrBase + 7
|
||||
llgoSigjmpbuf = llgoInstrBase + 10
|
||||
llgoSigsetjmp = llgoInstrBase + 11
|
||||
llgoSiglongjmp = llgoInstrBase + 12
|
||||
llgoDeferData = llgoInstrBase + 13
|
||||
llgoDeferData = llgoInstrBase + 6
|
||||
llgoStringData = llgoInstrBase + 7
|
||||
llgoString = llgoInstrBase + 8
|
||||
llgoFuncAddr = llgoInstrBase + 9
|
||||
|
||||
llgoSigjmpbuf = llgoInstrBase + 0xa
|
||||
llgoSigsetjmp = llgoInstrBase + 0xb
|
||||
llgoSiglongjmp = llgoInstrBase + 0xc
|
||||
|
||||
llgoPyList = llgoInstrBase + 0x10
|
||||
|
||||
llgoAtomicLoad = llgoInstrBase + 0x1d
|
||||
llgoAtomicStore = llgoInstrBase + 0x1e
|
||||
llgoAtomicCmpXchg = llgoInstrBase + 0x1f
|
||||
llgoAtomicOpBase = llgoInstrBase + 0x20
|
||||
|
||||
llgoAtomicXchg = llgoAtomicOpBase + llssa.OpXchg
|
||||
llgoAtomicAdd = llgoAtomicOpBase + llssa.OpAdd
|
||||
llgoAtomicSub = llgoAtomicOpBase + llssa.OpSub
|
||||
llgoAtomicAnd = llgoAtomicOpBase + llssa.OpAnd
|
||||
llgoAtomicNand = llgoAtomicOpBase + llssa.OpNand
|
||||
llgoAtomicOr = llgoAtomicOpBase + llssa.OpOr
|
||||
llgoAtomicXor = llgoAtomicOpBase + llssa.OpXor
|
||||
llgoAtomicMax = llgoAtomicOpBase + llssa.OpMax
|
||||
llgoAtomicMin = llgoAtomicOpBase + llssa.OpMin
|
||||
llgoAtomicUMax = llgoAtomicOpBase + llssa.OpUMax
|
||||
llgoAtomicUMin = llgoAtomicOpBase + llssa.OpUMin
|
||||
|
||||
llgoAtomicOpLast = llgoAtomicOpBase + int(llssa.OpUMin)
|
||||
)
|
||||
|
||||
func (p *context) funcName(fn *ssa.Function, ignore bool) (*types.Package, string, int) {
|
||||
@@ -417,7 +479,7 @@ func (p *context) varOf(b llssa.Builder, v *ssa.Global) llssa.Expr {
|
||||
}
|
||||
ret := pkg.VarOf(name)
|
||||
if ret == nil {
|
||||
ret = pkg.NewVar(name, v.Type(), llssa.Background(vtype))
|
||||
ret = pkg.NewVar(name, globalType(v), llssa.Background(vtype))
|
||||
}
|
||||
return ret.Expr
|
||||
}
|
||||
@@ -437,7 +499,7 @@ func (p *context) ensureLoaded(pkgTypes *types.Package) *types.Package {
|
||||
|
||||
func pkgKindByPath(pkgPath string) int {
|
||||
switch pkgPath {
|
||||
case "syscall", "runtime/cgo", "unsafe":
|
||||
case "runtime/cgo", "unsafe":
|
||||
return PkgDeclOnly
|
||||
}
|
||||
return PkgNormal
|
||||
@@ -451,6 +513,23 @@ func replaceGoName(v string, pos int) string {
|
||||
return v
|
||||
}
|
||||
|
||||
func ignoreName(name string) bool {
|
||||
/* TODO(xsw): confirm this is not needed more
|
||||
if name == "unsafe.init" {
|
||||
return true
|
||||
}
|
||||
*/
|
||||
const internal = "internal/"
|
||||
return (strings.HasPrefix(name, internal) && !supportedInternal(name[len(internal):])) ||
|
||||
strings.HasPrefix(name, "crypto/") || strings.HasPrefix(name, "runtime/") ||
|
||||
strings.HasPrefix(name, "arena.") || strings.HasPrefix(name, "maps.") ||
|
||||
strings.HasPrefix(name, "time.") || strings.HasPrefix(name, "plugin.")
|
||||
}
|
||||
|
||||
func supportedInternal(name string) bool {
|
||||
return strings.HasPrefix(name, "bytealg.") || strings.HasPrefix(name, "reflectlite.")
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
|
||||
364
cl/instr.go
Normal file
364
cl/instr.go
Normal file
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
* 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 cl
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/types"
|
||||
"log"
|
||||
|
||||
"golang.org/x/tools/go/ssa"
|
||||
|
||||
llssa "github.com/goplus/llgo/ssa"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// func cstr(string) *int8
|
||||
func cstr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 1 {
|
||||
if c, ok := args[0].(*ssa.Const); ok {
|
||||
if v := c.Value; v.Kind() == constant.String {
|
||||
sv := constant.StringVal(v)
|
||||
return b.CStr(sv)
|
||||
}
|
||||
}
|
||||
}
|
||||
panic("cstr(<string-literal>): invalid arguments")
|
||||
}
|
||||
|
||||
// func index(arr *T, idx int) T
|
||||
func (p *context) index(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
return b.Load(p.advance(b, args))
|
||||
}
|
||||
|
||||
// func advance(ptr *T, offset int) *T
|
||||
func (p *context) advance(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 2 {
|
||||
ptr := p.compileValue(b, args[0])
|
||||
offset := p.compileValue(b, args[1])
|
||||
return b.Advance(ptr, offset)
|
||||
}
|
||||
panic("advance(p ptr, offset int): invalid arguments")
|
||||
}
|
||||
|
||||
// func alloca(size uintptr) unsafe.Pointer
|
||||
func (p *context) alloca(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 1 {
|
||||
n := p.compileValue(b, args[0])
|
||||
return b.Alloca(n)
|
||||
}
|
||||
panic("alloca(size uintptr): invalid arguments")
|
||||
}
|
||||
|
||||
// func allocaCStr(s string) *int8
|
||||
func (p *context) allocaCStr(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 1 {
|
||||
s := p.compileValue(b, args[0])
|
||||
return b.AllocaCStr(s)
|
||||
}
|
||||
panic("allocaCStr(s string): invalid arguments")
|
||||
}
|
||||
|
||||
// func string(cstr *int8, n ...int) *int8
|
||||
func (p *context) string(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 2 {
|
||||
cstr := p.compileValue(b, args[0])
|
||||
n := make([]llssa.Expr, 0, 1)
|
||||
n = p.compileVArg(n, b, args[1])
|
||||
return b.MakeString(cstr, n...)
|
||||
}
|
||||
panic("string(cstr *int8, n ...int): invalid arguments")
|
||||
}
|
||||
|
||||
// func stringData(s string) *int8
|
||||
func (p *context) stringData(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 1 {
|
||||
s := p.compileValue(b, args[0])
|
||||
return b.StringData(s)
|
||||
}
|
||||
panic("stringData(s string): invalid arguments")
|
||||
}
|
||||
|
||||
// func funcAddr(fn any) unsafe.Pointer
|
||||
func (p *context) funcAddr(b llssa.Builder, args []ssa.Value) llssa.Expr {
|
||||
if len(args) == 1 {
|
||||
if fn, ok := args[0].(*ssa.MakeInterface); ok {
|
||||
if fnDecl, ok := fn.X.(*ssa.Function); ok {
|
||||
if aFn, _, _ := p.compileFunction(fnDecl); aFn != nil {
|
||||
return aFn.Expr
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
panic("funcAddr(<func>): invalid arguments")
|
||||
}
|
||||
|
||||
func (p *context) sigsetjmp(b llssa.Builder, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 2 {
|
||||
jb := p.compileValue(b, args[0])
|
||||
savemask := p.compileValue(b, args[1])
|
||||
return b.Sigsetjmp(jb, savemask)
|
||||
}
|
||||
panic("sigsetjmp(jb c.SigjmpBuf, savemask c.Int): invalid arguments")
|
||||
}
|
||||
|
||||
func (p *context) siglongjmp(b llssa.Builder, args []ssa.Value) {
|
||||
if len(args) == 2 {
|
||||
jb := p.compileValue(b, args[0])
|
||||
retval := p.compileValue(b, args[1])
|
||||
b.Siglongjmp(jb, retval)
|
||||
return
|
||||
}
|
||||
panic("siglongjmp(jb c.SigjmpBuf, retval c.Int): invalid arguments")
|
||||
}
|
||||
|
||||
func (p *context) atomic(b llssa.Builder, op llssa.AtomicOp, args []ssa.Value) (ret llssa.Expr) {
|
||||
if len(args) == 2 {
|
||||
addr := p.compileValue(b, args[0])
|
||||
val := p.compileValue(b, args[1])
|
||||
return b.Atomic(op, addr, val)
|
||||
}
|
||||
panic("atomicOp(addr *T, val T) T: invalid arguments")
|
||||
}
|
||||
|
||||
func (p *context) atomicLoad(b llssa.Builder, args []ssa.Value) llssa.Expr {
|
||||
if len(args) == 1 {
|
||||
addr := p.compileValue(b, args[0])
|
||||
return b.Load(addr).SetOrdering(llssa.OrderingSeqConsistent)
|
||||
}
|
||||
panic("atomicLoad(addr *T) T: invalid arguments")
|
||||
}
|
||||
|
||||
func (p *context) atomicStore(b llssa.Builder, args []ssa.Value) {
|
||||
if len(args) == 2 {
|
||||
addr := p.compileValue(b, args[0])
|
||||
val := p.compileValue(b, args[1])
|
||||
b.Store(addr, val).SetOrdering(llssa.OrderingSeqConsistent)
|
||||
return
|
||||
}
|
||||
panic("atomicStore(addr *T, val T) T: invalid arguments")
|
||||
}
|
||||
|
||||
func (p *context) atomicCmpXchg(b llssa.Builder, args []ssa.Value) llssa.Expr {
|
||||
if len(args) == 3 {
|
||||
addr := p.compileValue(b, args[0])
|
||||
old := p.compileValue(b, args[1])
|
||||
new := p.compileValue(b, args[2])
|
||||
return b.AtomicCmpXchg(addr, old, new)
|
||||
}
|
||||
panic("atomicCmpXchg(addr *T, old, new T) T: invalid arguments")
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
var llgoInstrs = map[string]int{
|
||||
"cstr": llgoCstr,
|
||||
"advance": llgoAdvance,
|
||||
"index": llgoIndex,
|
||||
"alloca": llgoAlloca,
|
||||
"allocaCStr": llgoAllocaCStr,
|
||||
"string": llgoString,
|
||||
"stringData": llgoStringData,
|
||||
"funcAddr": llgoFuncAddr,
|
||||
"pyList": llgoPyList,
|
||||
"sigjmpbuf": llgoSigjmpbuf,
|
||||
"sigsetjmp": llgoSigsetjmp,
|
||||
"siglongjmp": llgoSiglongjmp,
|
||||
"deferData": llgoDeferData,
|
||||
"unreachable": llgoUnreachable,
|
||||
|
||||
"atomicLoad": llgoAtomicLoad,
|
||||
"atomicStore": llgoAtomicStore,
|
||||
"atomicCmpXchg": llgoAtomicCmpXchg,
|
||||
|
||||
"atomicXchg": int(llgoAtomicXchg),
|
||||
"atomicAdd": int(llgoAtomicAdd),
|
||||
"atomicSub": int(llgoAtomicSub),
|
||||
"atomicAnd": int(llgoAtomicAnd),
|
||||
"atomicNand": int(llgoAtomicNand),
|
||||
"atomicOr": int(llgoAtomicOr),
|
||||
"atomicXor": int(llgoAtomicXor),
|
||||
"atomicMax": int(llgoAtomicMax),
|
||||
"atomicMin": int(llgoAtomicMin),
|
||||
"atomicUMax": int(llgoAtomicUMax),
|
||||
"atomicUMin": int(llgoAtomicUMin),
|
||||
}
|
||||
|
||||
// funcOf returns a function by name and set ftype = goFunc, cFunc, etc.
|
||||
// or returns nil and set ftype = llgoCstr, llgoAlloca, llgoUnreachable, etc.
|
||||
func (p *context) funcOf(fn *ssa.Function) (aFn llssa.Function, pyFn llssa.PyObjRef, ftype int) {
|
||||
pkgTypes, name, ftype := p.funcName(fn, false)
|
||||
switch ftype {
|
||||
case pyFunc:
|
||||
if kind, mod := pkgKindByScope(pkgTypes.Scope()); kind == PkgPyModule {
|
||||
pkg := p.pkg
|
||||
fnName := pysymPrefix + mod + "." + name
|
||||
if pyFn = pkg.PyObjOf(fnName); pyFn == nil {
|
||||
pyFn = pkg.PyNewFunc(fnName, fn.Signature, true)
|
||||
}
|
||||
return
|
||||
}
|
||||
ftype = ignoredFunc
|
||||
case llgoInstr:
|
||||
if ftype = llgoInstrs[name]; ftype == 0 {
|
||||
panic("unknown llgo instruction: " + name)
|
||||
}
|
||||
default:
|
||||
pkg := p.pkg
|
||||
if aFn = pkg.FuncOf(name); aFn == nil {
|
||||
if len(fn.FreeVars) > 0 {
|
||||
return nil, nil, ignoredFunc
|
||||
}
|
||||
sig := fn.Signature
|
||||
aFn = pkg.NewFuncEx(name, sig, llssa.Background(ftype), false)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
fnNormal = iota
|
||||
fnHasVArg
|
||||
fnIgnore
|
||||
)
|
||||
|
||||
func (p *context) funcKind(vfn ssa.Value) int {
|
||||
if fn, ok := vfn.(*ssa.Function); ok {
|
||||
params := fn.Signature.Params()
|
||||
n := params.Len()
|
||||
if n == 0 {
|
||||
if fn.Signature.Recv() == nil {
|
||||
if fn.Name() == "init" && p.pkgNoInit(fn.Pkg.Pkg) {
|
||||
return fnIgnore
|
||||
}
|
||||
}
|
||||
} else {
|
||||
last := params.At(n - 1)
|
||||
if last.Name() == llssa.NameValist {
|
||||
return fnHasVArg
|
||||
}
|
||||
}
|
||||
}
|
||||
return fnNormal
|
||||
}
|
||||
|
||||
func (p *context) pkgNoInit(pkg *types.Package) bool {
|
||||
p.ensureLoaded(pkg)
|
||||
if i, ok := p.loaded[pkg]; ok {
|
||||
return i.kind >= PkgNoInit
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
func (p *context) call(b llssa.Builder, act llssa.DoAction, call *ssa.CallCommon) (ret llssa.Expr) {
|
||||
cv := call.Value
|
||||
if mthd := call.Method; mthd != nil {
|
||||
o := p.compileValue(b, cv)
|
||||
fn := b.Imethod(o, mthd)
|
||||
args := p.compileValues(b, call.Args, fnNormal)
|
||||
ret = b.Do(act, fn, args...)
|
||||
return
|
||||
}
|
||||
kind := p.funcKind(cv)
|
||||
if kind == fnIgnore {
|
||||
return
|
||||
}
|
||||
args := call.Args
|
||||
if debugGoSSA {
|
||||
log.Println(">>> Do", act, cv, args)
|
||||
}
|
||||
switch cv := cv.(type) {
|
||||
case *ssa.Builtin:
|
||||
fn := cv.Name()
|
||||
if fn == "ssa:wrapnilchk" { // TODO(xsw): check nil ptr
|
||||
arg := args[0]
|
||||
ret = p.compileValue(b, arg)
|
||||
} else {
|
||||
args := p.compileValues(b, args, kind)
|
||||
ret = b.Do(act, llssa.Builtin(fn), args...)
|
||||
}
|
||||
case *ssa.Function:
|
||||
aFn, pyFn, ftype := p.compileFunction(cv)
|
||||
// TODO(xsw): check ca != llssa.Call
|
||||
switch ftype {
|
||||
case cFunc:
|
||||
p.inCFunc = true
|
||||
args := p.compileValues(b, args, kind)
|
||||
p.inCFunc = false
|
||||
ret = b.Do(act, aFn.Expr, args...)
|
||||
case goFunc:
|
||||
args := p.compileValues(b, args, kind)
|
||||
ret = b.Do(act, aFn.Expr, args...)
|
||||
case pyFunc:
|
||||
args := p.compileValues(b, args, kind)
|
||||
ret = b.Do(act, pyFn.Expr, args...)
|
||||
case llgoPyList:
|
||||
args := p.compileValues(b, args, fnHasVArg)
|
||||
ret = b.PyList(args...)
|
||||
case llgoCstr:
|
||||
ret = cstr(b, args)
|
||||
case llgoAdvance:
|
||||
ret = p.advance(b, args)
|
||||
case llgoIndex:
|
||||
ret = p.index(b, args)
|
||||
case llgoAlloca:
|
||||
ret = p.alloca(b, args)
|
||||
case llgoAllocaCStr:
|
||||
ret = p.allocaCStr(b, args)
|
||||
case llgoString:
|
||||
ret = p.string(b, args)
|
||||
case llgoStringData:
|
||||
ret = p.stringData(b, args)
|
||||
case llgoAtomicLoad:
|
||||
ret = p.atomicLoad(b, args)
|
||||
case llgoAtomicStore:
|
||||
p.atomicStore(b, args)
|
||||
case llgoAtomicCmpXchg:
|
||||
ret = p.atomicCmpXchg(b, args)
|
||||
case llgoSigsetjmp:
|
||||
ret = p.sigsetjmp(b, args)
|
||||
case llgoSiglongjmp:
|
||||
p.siglongjmp(b, args)
|
||||
case llgoSigjmpbuf: // func sigjmpbuf()
|
||||
ret = b.AllocaSigjmpBuf()
|
||||
case llgoDeferData: // func deferData() *Defer
|
||||
ret = b.DeferData()
|
||||
case llgoFuncAddr:
|
||||
ret = p.funcAddr(b, args)
|
||||
case llgoUnreachable: // func unreachable()
|
||||
b.Unreachable()
|
||||
default:
|
||||
if ftype >= llgoAtomicOpBase && ftype <= llgoAtomicOpLast {
|
||||
ret = p.atomic(b, llssa.AtomicOp(ftype-llgoAtomicOpBase), args)
|
||||
} else {
|
||||
log.Panicln("unknown ftype:", ftype)
|
||||
}
|
||||
}
|
||||
default:
|
||||
fn := p.compileValue(b, cv)
|
||||
args := p.compileValues(b, args, kind)
|
||||
ret = b.Do(act, fn, args...)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -52,7 +52,7 @@ type Command struct {
|
||||
// Llgo command
|
||||
var Llgo = &Command{
|
||||
UsageLine: "llgo",
|
||||
Short: `llgo is a Go compiler based on LLVM in order to better integrate Go with the C ecosystem.`,
|
||||
Short: `llgo is a Go compiler based on LLVM in order to better integrate Go with the C ecosystem including Python.`,
|
||||
// Commands initialized in package main
|
||||
}
|
||||
|
||||
|
||||
@@ -35,14 +35,29 @@ var Cmd = &base.Command{
|
||||
Short: "Compile and run Go program",
|
||||
}
|
||||
|
||||
// llgo cmptest
|
||||
var CmpTestCmd = &base.Command{
|
||||
UsageLine: "llgo cmptest [build flags] package [arguments...]",
|
||||
Short: "Compile programs by llgo and go, run them and do comparative tests (stdout/stderr/exitcode)",
|
||||
}
|
||||
|
||||
func init() {
|
||||
Cmd.Run = runCmd
|
||||
CmpTestCmd.Run = runCmpTest
|
||||
}
|
||||
|
||||
func runCmd(cmd *base.Command, args []string) {
|
||||
runCmdEx(cmd, args, build.ModeRun)
|
||||
}
|
||||
|
||||
func runCmpTest(cmd *base.Command, args []string) {
|
||||
runCmdEx(cmd, args, build.ModeCmpTest)
|
||||
}
|
||||
|
||||
func runCmdEx(cmd *base.Command, args []string, mode build.Mode) {
|
||||
args, runArgs, err := parseRunArgs(args)
|
||||
check(err)
|
||||
conf := build.NewDefaultConf(build.ModeRun)
|
||||
conf := build.NewDefaultConf(mode)
|
||||
conf.RunArgs = runArgs
|
||||
build.Do(args, conf)
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ func init() {
|
||||
build.Cmd,
|
||||
install.Cmd,
|
||||
run.Cmd,
|
||||
run.CmpTestCmd,
|
||||
clean.Cmd,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,44 @@ const (
|
||||
KindMask = (1 << 5) - 1
|
||||
)
|
||||
|
||||
// String returns the name of k.
|
||||
func (k Kind) String() string {
|
||||
if int(k) < len(kindNames) {
|
||||
return kindNames[k]
|
||||
}
|
||||
return kindNames[0]
|
||||
}
|
||||
|
||||
var kindNames = []string{
|
||||
Invalid: "invalid",
|
||||
Bool: "bool",
|
||||
Int: "int",
|
||||
Int8: "int8",
|
||||
Int16: "int16",
|
||||
Int32: "int32",
|
||||
Int64: "int64",
|
||||
Uint: "uint",
|
||||
Uint8: "uint8",
|
||||
Uint16: "uint16",
|
||||
Uint32: "uint32",
|
||||
Uint64: "uint64",
|
||||
Uintptr: "uintptr",
|
||||
Float32: "float32",
|
||||
Float64: "float64",
|
||||
Complex64: "complex64",
|
||||
Complex128: "complex128",
|
||||
Array: "array",
|
||||
Chan: "chan",
|
||||
Func: "func",
|
||||
Interface: "interface",
|
||||
Map: "map",
|
||||
Pointer: "ptr",
|
||||
Slice: "slice",
|
||||
String: "string",
|
||||
Struct: "struct",
|
||||
UnsafePointer: "unsafe.Pointer",
|
||||
}
|
||||
|
||||
// TFlag is used by a Type to signal what extra type information is
|
||||
// available in the memory directly following the Type value.
|
||||
type TFlag uint8
|
||||
@@ -329,6 +367,22 @@ func (p *Imethod) PkgPath() string {
|
||||
|
||||
func (t *Type) Kind() Kind { return Kind(t.Kind_ & KindMask) }
|
||||
|
||||
func (t *Type) HasName() bool {
|
||||
return t.TFlag&TFlagNamed != 0
|
||||
}
|
||||
|
||||
func (t *Type) Pointers() bool { return t.PtrBytes != 0 }
|
||||
|
||||
// IfaceIndir reports whether t is stored indirectly in an interface value.
|
||||
func (t *Type) IfaceIndir() bool {
|
||||
return t.Kind_&KindDirectIface == 0
|
||||
}
|
||||
|
||||
// isDirectIface reports whether t is stored directly in an interface value.
|
||||
func (t *Type) IsDirectIface() bool {
|
||||
return t.Kind_&KindDirectIface != 0
|
||||
}
|
||||
|
||||
// Size returns the size of data with type t.
|
||||
func (t *Type) Size() uintptr { return t.Size_ }
|
||||
|
||||
@@ -337,10 +391,10 @@ func (t *Type) Align() int { return int(t.Align_) }
|
||||
|
||||
func (t *Type) FieldAlign() int { return int(t.FieldAlign_) }
|
||||
|
||||
// Name returns the name of type t.
|
||||
func (t *Type) Name() string {
|
||||
// String returns string form of type t.
|
||||
func (t *Type) String() string {
|
||||
if t.TFlag&TFlagExtraStar != 0 {
|
||||
return "*" + t.Str_
|
||||
return "*" + t.Str_ // TODO(xsw): misunderstand
|
||||
}
|
||||
return t.Str_
|
||||
}
|
||||
@@ -424,21 +478,21 @@ func (t *Type) Len() int {
|
||||
// Elem returns the element type for t if t is an array, channel, map, pointer, or slice, otherwise nil.
|
||||
func (t *Type) Elem() *Type {
|
||||
switch t.Kind() {
|
||||
case Array:
|
||||
tt := (*ArrayType)(unsafe.Pointer(t))
|
||||
return tt.Elem
|
||||
case Chan:
|
||||
tt := (*ChanType)(unsafe.Pointer(t))
|
||||
return tt.Elem
|
||||
case Map:
|
||||
tt := (*MapType)(unsafe.Pointer(t))
|
||||
return tt.Elem
|
||||
case Pointer:
|
||||
tt := (*PtrType)(unsafe.Pointer(t))
|
||||
return tt.Elem
|
||||
case Slice:
|
||||
tt := (*SliceType)(unsafe.Pointer(t))
|
||||
return tt.Elem
|
||||
case Map:
|
||||
tt := (*MapType)(unsafe.Pointer(t))
|
||||
return tt.Elem
|
||||
case Array:
|
||||
tt := (*ArrayType)(unsafe.Pointer(t))
|
||||
return tt.Elem
|
||||
case Chan:
|
||||
tt := (*ChanType)(unsafe.Pointer(t))
|
||||
return tt.Elem
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user