Compare commits
27 Commits
pr-1405
...
xgopilot/c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3344f9de51 | ||
|
|
f8d7f1d931 | ||
|
|
c47d60d05c | ||
|
|
2d4d516687 | ||
|
|
05da9ec252 | ||
|
|
ebd041082b | ||
|
|
75e77caf29 | ||
|
|
0256ce2232 | ||
|
|
e46d22976a | ||
|
|
6507e3410c | ||
|
|
b2411a1750 | ||
|
|
902ac3b35a | ||
|
|
b62dafbc3a | ||
|
|
89e483b8ec | ||
|
|
18de107520 | ||
|
|
dee7b873a6 | ||
|
|
b3d123e235 | ||
|
|
670f880c78 | ||
|
|
0ee2530c2e | ||
|
|
85fd37e375 | ||
|
|
2b763b631f | ||
|
|
d864e3b685 | ||
|
|
5358d16eb7 | ||
|
|
dcf0898f3b | ||
|
|
05b382fe64 | ||
|
|
816854c9cc | ||
|
|
dba9bcc4e4 |
2
.github/actions/setup-deps/action.yml
vendored
2
.github/actions/setup-deps/action.yml
vendored
@@ -16,8 +16,6 @@ runs:
|
||||
- name: Install macOS dependencies
|
||||
if: runner.os == 'macOS'
|
||||
shell: bash
|
||||
env:
|
||||
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
|
||||
run: |
|
||||
brew update
|
||||
|
||||
|
||||
19
.github/workflows/llgo.yml
vendored
19
.github/workflows/llgo.yml
vendored
@@ -27,7 +27,7 @@ jobs:
|
||||
wget -P ./_demo/c/llama2-c https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin
|
||||
|
||||
- name: Upload model as artifact
|
||||
uses: actions/upload-artifact@v5
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: llama2-model
|
||||
path: ./_demo/c/llama2-c/stories15M.bin
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
with:
|
||||
llvm-version: ${{matrix.llvm}}
|
||||
- name: Download model artifact
|
||||
uses: actions/download-artifact@v6
|
||||
uses: actions/download-artifact@v5
|
||||
with:
|
||||
name: llama2-model
|
||||
path: ./_demo/c/llama2-c/
|
||||
@@ -61,7 +61,7 @@ jobs:
|
||||
if ${{ startsWith(matrix.os, 'macos') }}; then
|
||||
DEMO_PKG="cargs_darwin_arm64.zip"
|
||||
else
|
||||
DEMO_PKG="cargs_linux_amd64.zip"
|
||||
DEMO_PKG="cargs_linux_amd64.zip"
|
||||
fi
|
||||
|
||||
mkdir -p ./_demo/c/cargs/libs
|
||||
@@ -133,13 +133,6 @@ jobs:
|
||||
chmod +x test.sh
|
||||
./test.sh
|
||||
|
||||
- name: Test export with different symbol names on embedded targets
|
||||
run: |
|
||||
echo "Testing //export with different symbol names on embedded targets..."
|
||||
cd _demo/embed/export
|
||||
chmod +x verify_export.sh
|
||||
./verify_export.sh
|
||||
|
||||
- name: _xtool build tests
|
||||
run: |
|
||||
cd _xtool
|
||||
@@ -193,15 +186,11 @@ jobs:
|
||||
uses: actions/setup-go@v6
|
||||
with:
|
||||
go-version: ${{matrix.go}}
|
||||
- name: Test Baremetal GC
|
||||
if: ${{!startsWith(matrix.os, 'macos')}}
|
||||
working-directory: runtime/internal/runtime/tinygogc
|
||||
run: llgo test -tags testGC .
|
||||
|
||||
- name: run llgo test
|
||||
run: |
|
||||
llgo test ./...
|
||||
|
||||
|
||||
hello:
|
||||
continue-on-error: true
|
||||
timeout-minutes: 30
|
||||
|
||||
12
.github/workflows/release-build.yml
vendored
12
.github/workflows/release-build.yml
vendored
@@ -82,7 +82,7 @@ jobs:
|
||||
release --verbose --skip=publish,nfpm,snapcraft --snapshot --clean
|
||||
|
||||
- name: Upload Darwin AMD64 Artifacts
|
||||
uses: actions/upload-artifact@v5
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: llgo-darwin-amd64
|
||||
path: .dist/*darwin-amd64.tar.gz
|
||||
@@ -90,7 +90,7 @@ jobs:
|
||||
include-hidden-files: true
|
||||
|
||||
- name: Upload Darwin ARM64 Artifacts
|
||||
uses: actions/upload-artifact@v5
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: llgo-darwin-arm64
|
||||
path: .dist/*darwin-arm64.tar.gz
|
||||
@@ -98,7 +98,7 @@ jobs:
|
||||
include-hidden-files: true
|
||||
|
||||
- name: Upload Linux AMD64 Artifacts
|
||||
uses: actions/upload-artifact@v5
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: llgo-linux-amd64
|
||||
path: .dist/*linux-amd64.tar.gz
|
||||
@@ -106,7 +106,7 @@ jobs:
|
||||
include-hidden-files: true
|
||||
|
||||
- name: Upload Linux ARM64 Artifacts
|
||||
uses: actions/upload-artifact@v5
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: llgo-linux-arm64
|
||||
path: .dist/*linux-arm64.tar.gz
|
||||
@@ -114,7 +114,7 @@ jobs:
|
||||
include-hidden-files: true
|
||||
|
||||
- name: Upload Checksums
|
||||
uses: actions/upload-artifact@v5
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: llgo-checksums
|
||||
path: .dist/*checksums.txt
|
||||
@@ -158,7 +158,7 @@ jobs:
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
- name: Download Platform Artifact
|
||||
uses: actions/download-artifact@v6
|
||||
uses: actions/download-artifact@v5
|
||||
with:
|
||||
name: llgo-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
path: .
|
||||
|
||||
50
CLAUDE.md
50
CLAUDE.md
@@ -51,56 +51,6 @@ go test ./...
|
||||
|
||||
**Important:** The `LLGO_ROOT` environment variable must be set to the repository root when running llgo commands during development.
|
||||
|
||||
### Update out.ll files after modifying compiler IR generation
|
||||
|
||||
**CRITICAL:** When you modify the compiler's IR generation logic (especially in `ssa/` or `cl/` packages), you MUST update all out.ll test files under the `cl/` directory.
|
||||
|
||||
#### Understanding out.ll files
|
||||
|
||||
The `out.ll` files under the `cl/` directory are comparison IR files that serve as reference outputs for the test suite:
|
||||
- They are generated by `llgen` from the corresponding `in.go` files in the same directory
|
||||
- They reflect the current compiler's LLVM IR representation of the Go source code
|
||||
- They are used by tests to verify that the compiler generates correct and consistent IR output
|
||||
|
||||
#### Required steps after modifying IR generation logic
|
||||
|
||||
1. **Reinstall the tools** to apply your compiler changes:
|
||||
```bash
|
||||
go install -v ./chore/gentests
|
||||
go install -v ./chore/llgen
|
||||
```
|
||||
|
||||
2. **Regenerate out.ll files**:
|
||||
|
||||
**For batch updates (recommended)** - Use `gentests` to regenerate all test files:
|
||||
```bash
|
||||
gentests
|
||||
```
|
||||
This will automatically regenerate all out.ll files in these directories:
|
||||
- `cl/_testlibc`
|
||||
- `cl/_testlibgo`
|
||||
- `cl/_testrt`
|
||||
- `cl/_testgo`
|
||||
- `cl/_testpy`
|
||||
- `cl/_testdata`
|
||||
|
||||
**For individual test inspection** - Use `llgen` to regenerate specific test directories:
|
||||
```bash
|
||||
llgen cl/_testgo/interface
|
||||
llgen cl/_testrt/tpmethod
|
||||
```
|
||||
|
||||
3. **Verify the changes** make sense by reviewing the diff in the out.ll files
|
||||
|
||||
4. **Commit the updated out.ll files** along with your compiler changes
|
||||
|
||||
#### Why this matters
|
||||
|
||||
This process ensures that:
|
||||
- The test suite reflects the current compiler behavior
|
||||
- Changes to IR generation are properly documented and reviewed
|
||||
- Future regressions can be detected by comparing against the reference output
|
||||
|
||||
## Code Quality
|
||||
|
||||
Before submitting any code updates, you must run the following formatting and validation commands:
|
||||
|
||||
@@ -261,7 +261,7 @@ All Go syntax (including `cgo`) is already supported. Here are some examples:
|
||||
|
||||
### Defer
|
||||
|
||||
LLGo now supports `defer` within loops, matching Go's semantics of executing defers in LIFO order for every iteration. The usual caveat from Go still applies: be mindful of loop-heavy defer usage because it allocates per iteration.
|
||||
LLGo `defer` does not support usage in loops. This is not a bug but a feature, because we think that using `defer` in a loop is a very unrecommended practice.
|
||||
|
||||
|
||||
### Garbage Collection (GC)
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
//go:build amd64
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
//go:linkname getsp llgo.stackSave
|
||||
func getsp() unsafe.Pointer
|
||||
|
||||
//go:linkname asmFull llgo.asm
|
||||
func asmFull(instruction string, regs map[string]any) uintptr { return 0 }
|
||||
|
||||
func main() {
|
||||
sp := asmFull("movq %rsp, {}", nil)
|
||||
|
||||
if sp != uintptr(getsp()) {
|
||||
panic("invalid stack pointer")
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
//go:build arm64
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
//go:linkname getsp llgo.stackSave
|
||||
func getsp() unsafe.Pointer
|
||||
|
||||
//go:linkname asmFull llgo.asm
|
||||
func asmFull(instruction string, regs map[string]any) uintptr { return 0 }
|
||||
|
||||
func main() {
|
||||
sp := asmFull("mov {}, sp", nil)
|
||||
|
||||
if sp != uintptr(getsp()) {
|
||||
panic("invalid stack pointer")
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/lib/c"
|
||||
)
|
||||
|
||||
// This demo shows how to use //export with different symbol names on embedded targets.
|
||||
//
|
||||
// On embedded targets, you can export Go functions with different C symbol names.
|
||||
// This is useful for hardware interrupt handlers that require specific names.
|
||||
|
||||
// Standard Go export - same name
|
||||
//
|
||||
//export HelloWorld
|
||||
func HelloWorld() {
|
||||
c.Printf(c.Str("Hello from "))
|
||||
c.Printf(c.Str("HelloWorld\n"))
|
||||
}
|
||||
|
||||
// Embedded target export - different name
|
||||
// Go function name: interruptLPSPI2
|
||||
// Exported C symbol: LPSPI2_IRQHandler
|
||||
//
|
||||
//export LPSPI2_IRQHandler
|
||||
func interruptLPSPI2() {
|
||||
c.Printf(c.Str("LPSPI2 interrupt "))
|
||||
c.Printf(c.Str("handler called\n"))
|
||||
}
|
||||
|
||||
// Embedded target export - different name
|
||||
// Go function name: systemTickHandler
|
||||
// Exported C symbol: SysTick_Handler
|
||||
//
|
||||
//export SysTick_Handler
|
||||
func systemTickHandler() {
|
||||
c.Printf(c.Str("SysTick "))
|
||||
c.Printf(c.Str("handler called\n"))
|
||||
}
|
||||
|
||||
// Embedded target export - different name
|
||||
// Go function name: Add
|
||||
// Exported C symbol: AddFunc
|
||||
//
|
||||
//export AddFunc
|
||||
func Add(a, b int) int {
|
||||
result := a + b
|
||||
c.Printf(c.Str("AddFunc(%d, %d) = %d\n"), a, b, result)
|
||||
return result
|
||||
}
|
||||
|
||||
func main() {
|
||||
c.Printf(c.Str("=== Export Demo ===\n\n"))
|
||||
|
||||
// Call exported functions directly from Go
|
||||
c.Printf(c.Str("Calling HelloWorld:\n"))
|
||||
HelloWorld()
|
||||
|
||||
c.Printf(c.Str("\nSimulating hardware interrupts:\n"))
|
||||
interruptLPSPI2()
|
||||
systemTickHandler()
|
||||
|
||||
c.Printf(c.Str("\nTesting function with return value:\n"))
|
||||
result := Add(10, 20)
|
||||
c.Printf(c.Str("Result: %d\n"), result)
|
||||
|
||||
c.Printf(c.Str("\n=== Demo Complete ===\n"))
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "Building for embedded target..."
|
||||
|
||||
# Build for embedded target as executable
|
||||
# Use llgo directly instead of llgo.sh to avoid go.mod version check
|
||||
llgo build -o test-verify --target=esp32 .
|
||||
|
||||
echo "Checking exported symbols..."
|
||||
|
||||
# Get exported symbols
|
||||
exported_symbols=$(nm -gU ./test-verify.elf | grep -E "(HelloWorld|LPSPI2_IRQHandler|SysTick_Handler|AddFunc)" | awk '{print $NF}')
|
||||
|
||||
echo ""
|
||||
echo "Exported symbols:"
|
||||
echo "$exported_symbols" | awk '{print " " $0}'
|
||||
echo ""
|
||||
|
||||
# Check expected symbols
|
||||
expected=("HelloWorld" "LPSPI2_IRQHandler" "SysTick_Handler" "AddFunc")
|
||||
missing=""
|
||||
|
||||
for symbol in "${expected[@]}"; do
|
||||
if ! echo "$exported_symbols" | grep -q "^$symbol$"; then
|
||||
missing="$missing $symbol"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "$missing" ]; then
|
||||
echo "❌ Missing symbols:$missing"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Symbol name mapping verification:"
|
||||
echo " HelloWorld -> HelloWorld"
|
||||
echo " interruptLPSPI2 -> LPSPI2_IRQHandler"
|
||||
echo " systemTickHandler -> SysTick_Handler"
|
||||
echo " Add -> AddFunc"
|
||||
echo ""
|
||||
echo "🎉 All export symbols verified successfully!"
|
||||
echo ""
|
||||
|
||||
echo "Testing that non-embedded target rejects different export names..."
|
||||
# Build without --target should fail with panic
|
||||
if llgo build -o test-notarget . 2>&1 | grep -q 'export comment has wrong name "LPSPI2_IRQHandler"'; then
|
||||
echo "✅ Correctly rejected different export name on non-embedded target"
|
||||
else
|
||||
echo "❌ Should have panicked with 'export comment has wrong name' error"
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
echo "Note: Different symbol names are only supported on embedded targets."
|
||||
@@ -297,12 +297,6 @@ github_com_goplus_llgo_runtime_internal_clite_pthread_init(void) GO_SYMBOL_RENAM
|
||||
void
|
||||
github_com_goplus_llgo_runtime_internal_clite_pthread_sync_init(void) GO_SYMBOL_RENAME("github.com/goplus/llgo/runtime/internal/clite/pthread/sync.init")
|
||||
|
||||
void
|
||||
github_com_goplus_llgo_runtime_internal_clite_signal_init(void) GO_SYMBOL_RENAME("github.com/goplus/llgo/runtime/internal/clite/signal.init")
|
||||
|
||||
void
|
||||
github_com_goplus_llgo_runtime_internal_clite_tls_init(void) GO_SYMBOL_RENAME("github.com/goplus/llgo/runtime/internal/clite/tls.init")
|
||||
|
||||
void
|
||||
github_com_goplus_llgo_runtime_internal_runtime_goarch_init(void) GO_SYMBOL_RENAME("github.com/goplus/llgo/runtime/internal/runtime/goarch.init")
|
||||
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/build"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Printf("runtime.Compiler = %q\n", runtime.Compiler)
|
||||
|
||||
// Test 1: Check build.Default context
|
||||
ctx := build.Default
|
||||
fmt.Printf("build.Default.Compiler = %q\n", ctx.Compiler)
|
||||
if ctx.Compiler != "gc" {
|
||||
panic(fmt.Sprintf("expected build.Default.Compiler to be \"gc\", got %q", ctx.Compiler))
|
||||
}
|
||||
|
||||
if len(ctx.ToolTags) == 0 {
|
||||
panic("expected build.Default.ToolTags to be non-empty")
|
||||
}
|
||||
fmt.Printf("build.Default.ToolTags = %v\n", ctx.ToolTags)
|
||||
|
||||
if len(ctx.ReleaseTags) == 0 {
|
||||
panic("expected build.Default.ReleaseTags to be non-empty")
|
||||
}
|
||||
fmt.Printf("build.Default.ReleaseTags count = %d\n", len(ctx.ReleaseTags))
|
||||
|
||||
// Validate GOOS and GOARCH are set
|
||||
if ctx.GOOS == "" {
|
||||
panic("expected build.Default.GOOS to be non-empty")
|
||||
}
|
||||
if ctx.GOARCH == "" {
|
||||
panic("expected build.Default.GOARCH to be non-empty")
|
||||
}
|
||||
fmt.Printf("build.Default.GOOS = %q, GOARCH = %q\n", ctx.GOOS, ctx.GOARCH)
|
||||
|
||||
// Test 2: Import standard library package with FindOnly
|
||||
pkg, err := build.Import("fmt", "", build.FindOnly)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("build.Import(\"fmt\") failed: %v", err))
|
||||
}
|
||||
if pkg.ImportPath != "fmt" {
|
||||
panic(fmt.Sprintf("expected ImportPath \"fmt\", got %q", pkg.ImportPath))
|
||||
}
|
||||
if !pkg.Goroot {
|
||||
panic("expected fmt package to be in GOROOT")
|
||||
}
|
||||
fmt.Printf("build.Import(\"fmt\"): ImportPath=%s, Goroot=%v\n", pkg.ImportPath, pkg.Goroot)
|
||||
|
||||
// Test 3: Import nested standard library package
|
||||
osPkg, err := build.Import("os/exec", "", build.FindOnly)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("build.Import(\"os/exec\") failed: %v", err))
|
||||
}
|
||||
if osPkg.ImportPath != "os/exec" {
|
||||
panic(fmt.Sprintf("expected ImportPath \"os/exec\", got %q", osPkg.ImportPath))
|
||||
}
|
||||
if !osPkg.Goroot {
|
||||
panic("expected os/exec package to be in GOROOT")
|
||||
}
|
||||
fmt.Printf("build.Import(\"os/exec\"): ImportPath=%s, Goroot=%v\n", osPkg.ImportPath, osPkg.Goroot)
|
||||
|
||||
// Test 4: Import internal package (should succeed with FindOnly)
|
||||
internalPkg, err := build.Import("internal/cpu", "", build.FindOnly)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("build.Import(\"internal/cpu\") failed: %v", err))
|
||||
}
|
||||
if internalPkg.ImportPath != "internal/cpu" {
|
||||
panic(fmt.Sprintf("expected ImportPath \"internal/cpu\", got %q", internalPkg.ImportPath))
|
||||
}
|
||||
fmt.Printf("build.Import(\"internal/cpu\"): ImportPath=%s\n", internalPkg.ImportPath)
|
||||
|
||||
// Test 5: Import with srcDir parameter
|
||||
runtimePkg, err := build.Import("runtime", "", build.FindOnly)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("build.Import(\"runtime\") failed: %v", err))
|
||||
}
|
||||
if runtimePkg.ImportPath != "runtime" {
|
||||
panic(fmt.Sprintf("expected ImportPath \"runtime\", got %q", runtimePkg.ImportPath))
|
||||
}
|
||||
if runtimePkg.Dir == "" {
|
||||
panic("expected runtime package Dir to be non-empty")
|
||||
}
|
||||
fmt.Printf("build.Import(\"runtime\"): ImportPath=%s, Dir exists=%v\n", runtimePkg.ImportPath, runtimePkg.Dir != "")
|
||||
|
||||
// Test 6: ImportDir with current directory
|
||||
dirPkg, err := build.ImportDir(".", build.FindOnly)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("build.ImportDir(\".\") failed: %v", err))
|
||||
}
|
||||
// Note: Name might be empty with FindOnly mode as it doesn't read source files
|
||||
fmt.Printf("build.ImportDir(\".\"): Dir=%s, ImportPath=%s\n", dirPkg.Dir, dirPkg.ImportPath)
|
||||
|
||||
// Test 7: IsLocalImport with various paths
|
||||
testCases := []struct {
|
||||
path string
|
||||
expected bool
|
||||
}{
|
||||
{"./foo", true},
|
||||
{"../bar", true},
|
||||
{"./", true},
|
||||
{"fmt", false},
|
||||
{"github.com/user/repo", false},
|
||||
{"", false},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
result := build.IsLocalImport(tc.path)
|
||||
if result != tc.expected {
|
||||
panic(fmt.Sprintf("build.IsLocalImport(%q): expected %v, got %v", tc.path, tc.expected, result))
|
||||
}
|
||||
}
|
||||
fmt.Printf("build.IsLocalImport: all test cases passed\n")
|
||||
|
||||
// Test 8: Verify Context has expected fields
|
||||
if ctx.GOPATH == "" && ctx.GOROOT == "" {
|
||||
panic("expected either GOPATH or GOROOT to be set")
|
||||
}
|
||||
fmt.Printf("build.Default.GOROOT exists = %v\n", ctx.GOROOT != "")
|
||||
|
||||
// Test 9: Import with AllowBinary flag
|
||||
binaryPkg, err := build.Import("fmt", "", build.FindOnly|build.AllowBinary)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("build.Import with AllowBinary failed: %v", err))
|
||||
}
|
||||
if binaryPkg.ImportPath != "fmt" {
|
||||
panic(fmt.Sprintf("expected ImportPath \"fmt\", got %q", binaryPkg.ImportPath))
|
||||
}
|
||||
fmt.Printf("build.Import(\"fmt\") with AllowBinary: success\n")
|
||||
|
||||
// Test 10: Verify compiler tag in build context
|
||||
hasCompilerTag := false
|
||||
for _, tag := range ctx.ReleaseTags {
|
||||
if strings.HasPrefix(tag, "go1.") {
|
||||
hasCompilerTag = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasCompilerTag {
|
||||
panic("expected at least one go1.x release tag")
|
||||
}
|
||||
fmt.Printf("build.Default.ReleaseTags: contains go1.x tags = %v\n", hasCompilerTag)
|
||||
|
||||
fmt.Printf("\nSuccess! All go/build public functions work correctly with llgo\n")
|
||||
fmt.Printf("Total tests passed: 10\n")
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := 42
|
||||
p := &x
|
||||
|
||||
// Test 1: Non-pointer value - should return same value
|
||||
v1 := reflect.Indirect(reflect.ValueOf(x))
|
||||
if !v1.IsValid() || v1.Interface() != 42 {
|
||||
panic("Non-pointer test failed: expected 42")
|
||||
}
|
||||
|
||||
// Test 2: Pointer - should dereference
|
||||
v2 := reflect.Indirect(reflect.ValueOf(p))
|
||||
if !v2.IsValid() || v2.Interface() != 42 {
|
||||
panic("Pointer dereference test failed: expected 42")
|
||||
}
|
||||
|
||||
// Test 3: Nil pointer - should return invalid Value
|
||||
var nilPtr *int
|
||||
v3 := reflect.Indirect(reflect.ValueOf(nilPtr))
|
||||
if v3.IsValid() {
|
||||
panic("Nil pointer test failed: expected invalid Value")
|
||||
}
|
||||
|
||||
// Test 4: Struct value - should return same value
|
||||
type Person struct {
|
||||
Name string
|
||||
Age int
|
||||
}
|
||||
person := Person{Name: "Alice", Age: 30}
|
||||
v4 := reflect.Indirect(reflect.ValueOf(person))
|
||||
if !v4.IsValid() || v4.Interface().(Person).Name != "Alice" || v4.Interface().(Person).Age != 30 {
|
||||
panic("Struct value test failed: expected Person{Name: Alice, Age: 30}")
|
||||
}
|
||||
|
||||
// Test 5: Struct pointer - should dereference
|
||||
personPtr := &Person{Name: "Bob", Age: 25}
|
||||
v5 := reflect.Indirect(reflect.ValueOf(personPtr))
|
||||
if !v5.IsValid() || v5.Interface().(Person).Name != "Bob" || v5.Interface().(Person).Age != 25 {
|
||||
panic("Struct pointer test failed: expected Person{Name: Bob, Age: 25}")
|
||||
}
|
||||
|
||||
println("PASS")
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
for _, label := range complexOrder() {
|
||||
println(label)
|
||||
}
|
||||
}
|
||||
|
||||
func complexOrder() (res []string) {
|
||||
record := func(label string) { res = append(res, label) }
|
||||
|
||||
defer record(label1("cleanup-final", 0))
|
||||
defer record(label1("cleanup-before-loop", 0))
|
||||
|
||||
for i := 0; i < 2; i++ {
|
||||
defer record(label1("exit-outer", i))
|
||||
for j := 0; j < 2; j++ {
|
||||
if j == 0 {
|
||||
defer record(label2("branch-even", i, j))
|
||||
} else {
|
||||
defer record(label2("branch-odd", i, j))
|
||||
}
|
||||
for k := 0; k < 2; k++ {
|
||||
nested := label3("nested", i, j, k)
|
||||
defer record(nested)
|
||||
if k == 1 {
|
||||
defer record(label3("nested-tail", i, j, k))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
defer record(label1("post-loop", 0))
|
||||
return
|
||||
}
|
||||
|
||||
func label1(prefix string, a int) string {
|
||||
return prefix + "-" + digit(a)
|
||||
}
|
||||
|
||||
func label2(prefix string, a, b int) string {
|
||||
return prefix + "-" + digit(a) + "-" + digit(b)
|
||||
}
|
||||
|
||||
func label3(prefix string, a, b, c int) string {
|
||||
return prefix + "-" + digit(a) + "-" + digit(b) + "-" + digit(c)
|
||||
}
|
||||
|
||||
func digit(n int) string {
|
||||
return string(rune('0' + n))
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
;
|
||||
@@ -1,7 +0,0 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
for i := 0; i < 3; i++ {
|
||||
defer println("loop", i)
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
;
|
||||
@@ -19,8 +19,9 @@ source_filename = "github.com/goplus/llgo/cl/_testgo/errors"
|
||||
@3 = private unnamed_addr constant [5 x i8] c"Error", align 1
|
||||
@"_llgo_func$zNDVRsWTIpUPKouNUS805RGX--IV9qVK8B31IZbg5to" = linkonce global ptr null, align 8
|
||||
@"*_llgo_github.com/goplus/llgo/cl/_testgo/errors.errorString" = linkonce global ptr null, align 8
|
||||
@"_llgo_iface$Fh8eUJ-Gw4e6TYuajcFIOSCuqSPKAt5nS4ow7xeGXEU" = linkonce global ptr null, align 8
|
||||
@4 = private unnamed_addr constant [8 x i8] c"an error", align 1
|
||||
@_llgo_error = linkonce global ptr null, align 8
|
||||
@4 = private unnamed_addr constant [5 x i8] c"error", align 1
|
||||
@5 = private unnamed_addr constant [8 x i8] c"an error", align 1
|
||||
|
||||
define %"github.com/goplus/llgo/runtime/internal/runtime.iface" @"github.com/goplus/llgo/cl/_testgo/errors.New"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %0) {
|
||||
_llgo_0:
|
||||
@@ -29,12 +30,11 @@ _llgo_0:
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" %0, ptr %2, align 8
|
||||
%3 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/errors.errorString", align 8
|
||||
%4 = load ptr, ptr @"*_llgo_github.com/goplus/llgo/cl/_testgo/errors.errorString", align 8
|
||||
%5 = load ptr, ptr @"_llgo_func$zNDVRsWTIpUPKouNUS805RGX--IV9qVK8B31IZbg5to", align 8
|
||||
%6 = load ptr, ptr @"_llgo_iface$Fh8eUJ-Gw4e6TYuajcFIOSCuqSPKAt5nS4ow7xeGXEU", align 8
|
||||
%7 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %6, ptr %4)
|
||||
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %7, 0
|
||||
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %8, ptr %1, 1
|
||||
ret %"github.com/goplus/llgo/runtime/internal/runtime.iface" %9
|
||||
%5 = load ptr, ptr @_llgo_error, align 8
|
||||
%6 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %5, ptr %4)
|
||||
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %6, 0
|
||||
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %7, ptr %1, 1
|
||||
ret %"github.com/goplus/llgo/runtime/internal/runtime.iface" %8
|
||||
}
|
||||
|
||||
define %"github.com/goplus/llgo/runtime/internal/runtime.String" @"github.com/goplus/llgo/cl/_testgo/errors.(*errorString).Error"(ptr %0) {
|
||||
@@ -60,7 +60,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/errors.main"() {
|
||||
_llgo_0:
|
||||
%0 = call %"github.com/goplus/llgo/runtime/internal/runtime.iface" @"github.com/goplus/llgo/cl/_testgo/errors.New"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 8 })
|
||||
%0 = call %"github.com/goplus/llgo/runtime/internal/runtime.iface" @"github.com/goplus/llgo/cl/_testgo/errors.New"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 8 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintIface"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %0)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
%1 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %0)
|
||||
@@ -142,24 +142,31 @@ _llgo_4: ; preds = %_llgo_3, %_llgo_2
|
||||
%37 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.PointerTo"(ptr %36)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %37)
|
||||
store ptr %37, ptr @"*_llgo_github.com/goplus/llgo/cl/_testgo/errors.errorString", align 8
|
||||
%38 = load ptr, ptr @"_llgo_func$zNDVRsWTIpUPKouNUS805RGX--IV9qVK8B31IZbg5to", align 8
|
||||
%39 = load ptr, ptr @"_llgo_iface$Fh8eUJ-Gw4e6TYuajcFIOSCuqSPKAt5nS4ow7xeGXEU", align 8
|
||||
%38 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 5 })
|
||||
%39 = load ptr, ptr @_llgo_error, align 8
|
||||
%40 = icmp eq ptr %39, null
|
||||
br i1 %40, label %_llgo_5, label %_llgo_6
|
||||
|
||||
_llgo_5: ; preds = %_llgo_4
|
||||
%41 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 5 }, ptr undef }, ptr %38, 1
|
||||
%42 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%43 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %42, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %41, ptr %43, align 8
|
||||
%44 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %42, 0
|
||||
%45 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %44, i64 1, 1
|
||||
%46 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %45, i64 1, 2
|
||||
%47 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 40 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %46)
|
||||
store ptr %47, ptr @"_llgo_iface$Fh8eUJ-Gw4e6TYuajcFIOSCuqSPKAt5nS4ow7xeGXEU", align 8
|
||||
store ptr %38, ptr @_llgo_error, align 8
|
||||
br label %_llgo_6
|
||||
|
||||
_llgo_6: ; preds = %_llgo_5, %_llgo_4
|
||||
%41 = load ptr, ptr @"_llgo_func$zNDVRsWTIpUPKouNUS805RGX--IV9qVK8B31IZbg5to", align 8
|
||||
br i1 %40, label %_llgo_7, label %_llgo_8
|
||||
|
||||
_llgo_7: ; preds = %_llgo_6
|
||||
%42 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 5 }, ptr undef }, ptr %41, 1
|
||||
%43 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%44 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %43, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %42, ptr %44, align 8
|
||||
%45 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %43, 0
|
||||
%46 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %45, i64 1, 1
|
||||
%47 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %46, i64 1, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr %38, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %47)
|
||||
br label %_llgo_8
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7, %_llgo_6
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -181,7 +188,9 @@ declare void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(p
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.PointerTo"(ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr, ptr)
|
||||
|
||||
|
||||
@@ -26,13 +26,11 @@ source_filename = "github.com/goplus/llgo/cl/_testgo/ifaceconv"
|
||||
@6 = private unnamed_addr constant [2 x i8] c"I2", align 1
|
||||
@7 = private unnamed_addr constant [45 x i8] c"github.com/goplus/llgo/cl/_testgo/ifaceconv.g", align 1
|
||||
@8 = private unnamed_addr constant [21 x i8] c"nil i2.(I2) succeeded", align 1
|
||||
@"github.com/goplus/llgo/cl/_testgo/ifaceconv.iface$brpgdLtIeRlPi8QUoTgPCXzlehUkncg7v9aITo-GsF4" = linkonce global ptr null, align 8
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C1" = linkonce global ptr null, align 8
|
||||
@9 = private unnamed_addr constant [2 x i8] c"C1", align 1
|
||||
@"_llgo_struct$n1H8J_3prDN3firMwPxBLVTkE5hJ9Di-AqNvaC9jczw" = linkonce global ptr null, align 8
|
||||
@10 = private unnamed_addr constant [1 x i8] c"f", align 1
|
||||
@11 = private unnamed_addr constant [17 x i8] c"C1 i1.(I0) failed", align 1
|
||||
@"github.com/goplus/llgo/cl/_testgo/ifaceconv.iface$gZBF8fFlqIMZ9M6lT2VWPyc3eu5Co6j0WoKGIEgDPAw" = linkonce global ptr null, align 8
|
||||
@12 = private unnamed_addr constant [17 x i8] c"C1 i1.(I1) failed", align 1
|
||||
@13 = private unnamed_addr constant [20 x i8] c"C1 i1.(I2) succeeded", align 1
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C2" = linkonce global ptr null, align 8
|
||||
@@ -145,14 +143,14 @@ _llgo_6: ; preds = %_llgo_31
|
||||
%21 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %20, 0
|
||||
%22 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %21, ptr null, 1
|
||||
%23 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" zeroinitializer)
|
||||
%24 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.iface$brpgdLtIeRlPi8QUoTgPCXzlehUkncg7v9aITo-GsF4", align 8
|
||||
%24 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.I1", align 8
|
||||
%25 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %24, ptr %23)
|
||||
%26 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %25, 0
|
||||
%27 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %26, ptr null, 1
|
||||
%28 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C1", align 8
|
||||
%29 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
store %"github.com/goplus/llgo/cl/_testgo/ifaceconv.C1" zeroinitializer, ptr %29, align 1
|
||||
%30 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.iface$brpgdLtIeRlPi8QUoTgPCXzlehUkncg7v9aITo-GsF4", align 8
|
||||
%30 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.I1", align 8
|
||||
%31 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %30, ptr %28)
|
||||
%32 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %31, 0
|
||||
%33 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %32, ptr %29, 1
|
||||
@@ -204,7 +202,7 @@ _llgo_12: ; preds = %_llgo_40
|
||||
%55 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C2", align 8
|
||||
%56 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
store %"github.com/goplus/llgo/cl/_testgo/ifaceconv.C2" zeroinitializer, ptr %56, align 1
|
||||
%57 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.iface$brpgdLtIeRlPi8QUoTgPCXzlehUkncg7v9aITo-GsF4", align 8
|
||||
%57 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.I1", align 8
|
||||
%58 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %57, ptr %55)
|
||||
%59 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %58, 0
|
||||
%60 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %59, ptr %56, 1
|
||||
@@ -256,7 +254,7 @@ _llgo_18: ; preds = %_llgo_49
|
||||
%82 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C1", align 8
|
||||
%83 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
store %"github.com/goplus/llgo/cl/_testgo/ifaceconv.C1" zeroinitializer, ptr %83, align 1
|
||||
%84 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.iface$brpgdLtIeRlPi8QUoTgPCXzlehUkncg7v9aITo-GsF4", align 8
|
||||
%84 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.I1", align 8
|
||||
%85 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %84, ptr %82)
|
||||
%86 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %85, 0
|
||||
%87 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %86, ptr %83, 1
|
||||
@@ -370,7 +368,7 @@ _llgo_37: ; preds = %_llgo_36, %_llgo_35
|
||||
|
||||
_llgo_38: ; preds = %_llgo_10
|
||||
%131 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %33, 1
|
||||
%132 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.iface$gZBF8fFlqIMZ9M6lT2VWPyc3eu5Co6j0WoKGIEgDPAw", align 8
|
||||
%132 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.I2", align 8
|
||||
%133 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %132, ptr %48)
|
||||
%134 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %133, 0
|
||||
%135 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %134, ptr %131, 1
|
||||
@@ -420,7 +418,7 @@ _llgo_46: ; preds = %_llgo_45, %_llgo_44
|
||||
|
||||
_llgo_47: ; preds = %_llgo_16
|
||||
%154 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %60, 1
|
||||
%155 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.iface$gZBF8fFlqIMZ9M6lT2VWPyc3eu5Co6j0WoKGIEgDPAw", align 8
|
||||
%155 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.I2", align 8
|
||||
%156 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %155, ptr %75)
|
||||
%157 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %156, 0
|
||||
%158 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %157, ptr %154, 1
|
||||
@@ -544,118 +542,94 @@ _llgo_15: ; preds = %_llgo_14
|
||||
br label %_llgo_16
|
||||
|
||||
_llgo_16: ; preds = %_llgo_15, %_llgo_14
|
||||
%44 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%45 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 45 }, ptr undef }, ptr %44, 1
|
||||
%46 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%47 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %46, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %45, ptr %47, align 8
|
||||
%48 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %46, 0
|
||||
%49 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %48, i64 1, 1
|
||||
%50 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %49, i64 1, 2
|
||||
%51 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 43 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %50)
|
||||
store ptr %51, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.iface$brpgdLtIeRlPi8QUoTgPCXzlehUkncg7v9aITo-GsF4", align 8
|
||||
%52 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 43 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @9, i64 2 }, i64 25, i64 0, i64 1, i64 1)
|
||||
%53 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C1", align 8
|
||||
%54 = icmp eq ptr %53, null
|
||||
br i1 %54, label %_llgo_17, label %_llgo_18
|
||||
%44 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 43 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @9, i64 2 }, i64 25, i64 0, i64 1, i64 1)
|
||||
%45 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C1", align 8
|
||||
%46 = icmp eq ptr %45, null
|
||||
br i1 %46, label %_llgo_17, label %_llgo_18
|
||||
|
||||
_llgo_17: ; preds = %_llgo_16
|
||||
store ptr %52, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C1", align 8
|
||||
store ptr %44, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C1", align 8
|
||||
br label %_llgo_18
|
||||
|
||||
_llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||
%55 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
%56 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %55, 0
|
||||
%57 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %56, i64 0, 1
|
||||
%58 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %57, i64 0, 2
|
||||
%59 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 43 }, i64 0, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %58)
|
||||
store ptr %59, ptr @"_llgo_struct$n1H8J_3prDN3firMwPxBLVTkE5hJ9Di-AqNvaC9jczw", align 8
|
||||
%60 = load ptr, ptr @"_llgo_struct$n1H8J_3prDN3firMwPxBLVTkE5hJ9Di-AqNvaC9jczw", align 8
|
||||
br i1 %54, label %_llgo_19, label %_llgo_20
|
||||
%47 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
%48 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %47, 0
|
||||
%49 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %48, i64 0, 1
|
||||
%50 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %49, i64 0, 2
|
||||
%51 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 43 }, i64 0, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %50)
|
||||
store ptr %51, ptr @"_llgo_struct$n1H8J_3prDN3firMwPxBLVTkE5hJ9Di-AqNvaC9jczw", align 8
|
||||
%52 = load ptr, ptr @"_llgo_struct$n1H8J_3prDN3firMwPxBLVTkE5hJ9Di-AqNvaC9jczw", align 8
|
||||
br i1 %46, label %_llgo_19, label %_llgo_20
|
||||
|
||||
_llgo_19: ; preds = %_llgo_18
|
||||
%61 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%62 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %61, 1
|
||||
%63 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %62, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C1).f", 2
|
||||
%64 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %63, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C1).f", 3
|
||||
%65 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %61, 1
|
||||
%66 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %65, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C1).f", 2
|
||||
%67 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %66, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.C1.f", 3
|
||||
%68 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 40)
|
||||
%69 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %68, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %67, ptr %69, align 8
|
||||
%70 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %68, 0
|
||||
%71 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %70, i64 1, 1
|
||||
%72 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %71, i64 1, 2
|
||||
%73 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 40)
|
||||
%74 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %73, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %64, ptr %74, align 8
|
||||
%75 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %73, 0
|
||||
%76 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %75, i64 1, 1
|
||||
%77 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %76, i64 1, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr %52, ptr %60, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %72, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %77)
|
||||
%53 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%54 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %53, 1
|
||||
%55 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %54, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C1).f", 2
|
||||
%56 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %55, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C1).f", 3
|
||||
%57 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %53, 1
|
||||
%58 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %57, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C1).f", 2
|
||||
%59 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %58, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.C1.f", 3
|
||||
%60 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 40)
|
||||
%61 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %60, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %59, ptr %61, align 8
|
||||
%62 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %60, 0
|
||||
%63 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %62, i64 1, 1
|
||||
%64 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %63, i64 1, 2
|
||||
%65 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 40)
|
||||
%66 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %65, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %56, ptr %66, align 8
|
||||
%67 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %65, 0
|
||||
%68 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %67, i64 1, 1
|
||||
%69 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %68, i64 1, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr %44, ptr %52, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %64, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %69)
|
||||
br label %_llgo_20
|
||||
|
||||
_llgo_20: ; preds = %_llgo_19, %_llgo_18
|
||||
%78 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%79 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%80 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 45 }, ptr undef }, ptr %78, 1
|
||||
%81 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 45 }, ptr undef }, ptr %79, 1
|
||||
%82 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 48)
|
||||
%83 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %82, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %80, ptr %83, align 8
|
||||
%84 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %82, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %81, ptr %84, align 8
|
||||
%85 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %82, 0
|
||||
%86 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %85, i64 2, 1
|
||||
%87 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %86, i64 2, 2
|
||||
%88 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 43 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %87)
|
||||
store ptr %88, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.iface$gZBF8fFlqIMZ9M6lT2VWPyc3eu5Co6j0WoKGIEgDPAw", align 8
|
||||
%89 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 43 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @14, i64 2 }, i64 25, i64 0, i64 2, i64 2)
|
||||
%90 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C2", align 8
|
||||
%91 = icmp eq ptr %90, null
|
||||
br i1 %91, label %_llgo_21, label %_llgo_22
|
||||
%70 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 43 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @14, i64 2 }, i64 25, i64 0, i64 2, i64 2)
|
||||
%71 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C2", align 8
|
||||
%72 = icmp eq ptr %71, null
|
||||
br i1 %72, label %_llgo_21, label %_llgo_22
|
||||
|
||||
_llgo_21: ; preds = %_llgo_20
|
||||
store ptr %89, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C2", align 8
|
||||
store ptr %70, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceconv.C2", align 8
|
||||
br label %_llgo_22
|
||||
|
||||
_llgo_22: ; preds = %_llgo_21, %_llgo_20
|
||||
%92 = load ptr, ptr @"_llgo_struct$n1H8J_3prDN3firMwPxBLVTkE5hJ9Di-AqNvaC9jczw", align 8
|
||||
br i1 %91, label %_llgo_23, label %_llgo_24
|
||||
%73 = load ptr, ptr @"_llgo_struct$n1H8J_3prDN3firMwPxBLVTkE5hJ9Di-AqNvaC9jczw", align 8
|
||||
br i1 %72, label %_llgo_23, label %_llgo_24
|
||||
|
||||
_llgo_23: ; preds = %_llgo_22
|
||||
%93 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%94 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %93, 1
|
||||
%95 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %94, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).f", 2
|
||||
%96 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %95, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).f", 3
|
||||
%97 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %93, 1
|
||||
%98 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %97, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).f", 2
|
||||
%99 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %98, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.C2.f", 3
|
||||
%100 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%101 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %100, 1
|
||||
%102 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %101, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).g", 2
|
||||
%103 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %102, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).g", 3
|
||||
%104 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %100, 1
|
||||
%105 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %104, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).g", 2
|
||||
%106 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %105, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.C2.g", 3
|
||||
%107 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 80)
|
||||
%108 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %107, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %99, ptr %108, align 8
|
||||
%109 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %107, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %106, ptr %109, align 8
|
||||
%110 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %107, 0
|
||||
%111 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %110, i64 2, 1
|
||||
%112 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %111, i64 2, 2
|
||||
%113 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 80)
|
||||
%114 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %113, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %96, ptr %114, align 8
|
||||
%115 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %113, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %103, ptr %115, align 8
|
||||
%116 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %113, 0
|
||||
%117 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %116, i64 2, 1
|
||||
%118 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %117, i64 2, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr %89, ptr %92, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %112, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %118)
|
||||
%74 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%75 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %74, 1
|
||||
%76 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %75, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).f", 2
|
||||
%77 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %76, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).f", 3
|
||||
%78 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %74, 1
|
||||
%79 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %78, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).f", 2
|
||||
%80 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %79, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.C2.f", 3
|
||||
%81 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%82 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %81, 1
|
||||
%83 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %82, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).g", 2
|
||||
%84 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %83, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).g", 3
|
||||
%85 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 45 }, ptr undef, ptr undef, ptr undef }, ptr %81, 1
|
||||
%86 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %85, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.(*C2).g", 2
|
||||
%87 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %86, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceconv.C2.g", 3
|
||||
%88 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 80)
|
||||
%89 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %88, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %80, ptr %89, align 8
|
||||
%90 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %88, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %87, ptr %90, align 8
|
||||
%91 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %88, 0
|
||||
%92 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %91, i64 2, 1
|
||||
%93 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %92, i64 2, 2
|
||||
%94 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 80)
|
||||
%95 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %94, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %77, ptr %95, align 8
|
||||
%96 = getelementptr %"github.com/goplus/llgo/runtime/abi.Method", ptr %94, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Method" %84, ptr %96, align 8
|
||||
%97 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %94, 0
|
||||
%98 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %97, i64 2, 1
|
||||
%99 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %98, i64 2, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr %70, ptr %73, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %93, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %99)
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
@@ -678,8 +652,6 @@ declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr, ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String", i64, i64, i64, i64)
|
||||
|
||||
@@ -24,7 +24,6 @@ source_filename = "github.com/goplus/llgo/cl/_testgo/ifaceprom"
|
||||
@5 = private unnamed_addr constant [47 x i8] c"github.com/goplus/llgo/cl/_testgo/ifaceprom.two", align 1
|
||||
@_llgo_string = linkonce global ptr null, align 8
|
||||
@"_llgo_func$zNDVRsWTIpUPKouNUS805RGX--IV9qVK8B31IZbg5to" = linkonce global ptr null, align 8
|
||||
@"github.com/goplus/llgo/cl/_testgo/ifaceprom.iface$zZ89tENb5h_KNjvpxf1TXPfaWFYn0IZrZwyVf42lRtA" = linkonce global ptr null, align 8
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I" = linkonce global ptr null, align 8
|
||||
@6 = private unnamed_addr constant [1 x i8] c"I", align 1
|
||||
@7 = private unnamed_addr constant [116 x i8] c"type assertion github.com/goplus/llgo/cl/_testgo/ifaceprom.I -> github.com/goplus/llgo/cl/_testgo/ifaceprom.I failed", align 1
|
||||
@@ -146,172 +145,170 @@ _llgo_0:
|
||||
%2 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.impl", align 8
|
||||
%3 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
store %"github.com/goplus/llgo/cl/_testgo/ifaceprom.impl" zeroinitializer, ptr %3, align 1
|
||||
%4 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
%5 = load ptr, ptr @"_llgo_func$zNDVRsWTIpUPKouNUS805RGX--IV9qVK8B31IZbg5to", align 8
|
||||
%6 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.iface$zZ89tENb5h_KNjvpxf1TXPfaWFYn0IZrZwyVf42lRtA", align 8
|
||||
%7 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %6, ptr %2)
|
||||
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %7, 0
|
||||
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %8, ptr %3, 1
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %9, ptr %1, align 8
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, i32 0, i32 0
|
||||
%11 = load %"github.com/goplus/llgo/runtime/internal/runtime.iface", ptr %10, align 8
|
||||
%12 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %11)
|
||||
%13 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %11, 0
|
||||
%14 = getelementptr ptr, ptr %13, i64 3
|
||||
%15 = load ptr, ptr %14, align 8
|
||||
%16 = insertvalue { ptr, ptr } undef, ptr %15, 0
|
||||
%17 = insertvalue { ptr, ptr } %16, ptr %12, 1
|
||||
%18 = extractvalue { ptr, ptr } %17, 1
|
||||
%19 = extractvalue { ptr, ptr } %17, 0
|
||||
%20 = call i64 %19(ptr %18)
|
||||
%21 = icmp ne i64 %20, 1
|
||||
br i1 %21, label %_llgo_1, label %_llgo_2
|
||||
%4 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
%5 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %4, ptr %2)
|
||||
%6 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %5, 0
|
||||
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %6, ptr %3, 1
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %7, ptr %1, align 8
|
||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, i32 0, i32 0
|
||||
%9 = load %"github.com/goplus/llgo/runtime/internal/runtime.iface", ptr %8, align 8
|
||||
%10 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %9)
|
||||
%11 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %9, 0
|
||||
%12 = getelementptr ptr, ptr %11, i64 3
|
||||
%13 = load ptr, ptr %12, align 8
|
||||
%14 = insertvalue { ptr, ptr } undef, ptr %13, 0
|
||||
%15 = insertvalue { ptr, ptr } %14, ptr %10, 1
|
||||
%16 = extractvalue { ptr, ptr } %15, 1
|
||||
%17 = extractvalue { ptr, ptr } %15, 0
|
||||
%18 = call i64 %17(ptr %16)
|
||||
%19 = icmp ne i64 %18, 1
|
||||
br i1 %19, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%22 = load ptr, ptr @_llgo_int, align 8
|
||||
%23 = inttoptr i64 %20 to ptr
|
||||
%24 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %22, 0
|
||||
%25 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %24, ptr %23, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %25)
|
||||
%20 = load ptr, ptr @_llgo_int, align 8
|
||||
%21 = inttoptr i64 %18 to ptr
|
||||
%22 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %20, 0
|
||||
%23 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %22, ptr %21, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %23)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
%26 = load %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, align 8
|
||||
%27 = extractvalue %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S" %26, 0
|
||||
%28 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %27)
|
||||
%29 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %27, 0
|
||||
%30 = getelementptr ptr, ptr %29, i64 3
|
||||
%31 = load ptr, ptr %30, align 8
|
||||
%32 = insertvalue { ptr, ptr } undef, ptr %31, 0
|
||||
%33 = insertvalue { ptr, ptr } %32, ptr %28, 1
|
||||
%34 = extractvalue { ptr, ptr } %33, 1
|
||||
%35 = extractvalue { ptr, ptr } %33, 0
|
||||
%36 = call i64 %35(ptr %34)
|
||||
%37 = icmp ne i64 %36, 1
|
||||
br i1 %37, label %_llgo_3, label %_llgo_4
|
||||
%24 = load %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, align 8
|
||||
%25 = extractvalue %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S" %24, 0
|
||||
%26 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %25)
|
||||
%27 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %25, 0
|
||||
%28 = getelementptr ptr, ptr %27, i64 3
|
||||
%29 = load ptr, ptr %28, align 8
|
||||
%30 = insertvalue { ptr, ptr } undef, ptr %29, 0
|
||||
%31 = insertvalue { ptr, ptr } %30, ptr %26, 1
|
||||
%32 = extractvalue { ptr, ptr } %31, 1
|
||||
%33 = extractvalue { ptr, ptr } %31, 0
|
||||
%34 = call i64 %33(ptr %32)
|
||||
%35 = icmp ne i64 %34, 1
|
||||
br i1 %35, label %_llgo_3, label %_llgo_4
|
||||
|
||||
_llgo_3: ; preds = %_llgo_2
|
||||
%38 = load ptr, ptr @_llgo_int, align 8
|
||||
%39 = inttoptr i64 %36 to ptr
|
||||
%40 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %38, 0
|
||||
%41 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %40, ptr %39, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %41)
|
||||
%36 = load ptr, ptr @_llgo_int, align 8
|
||||
%37 = inttoptr i64 %34 to ptr
|
||||
%38 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %36, 0
|
||||
%39 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %38, ptr %37, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %39)
|
||||
unreachable
|
||||
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
%42 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, i32 0, i32 0
|
||||
%43 = load %"github.com/goplus/llgo/runtime/internal/runtime.iface", ptr %42, align 8
|
||||
%44 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %43)
|
||||
%45 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
%46 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %43, 1
|
||||
%40 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, i32 0, i32 0
|
||||
%41 = load %"github.com/goplus/llgo/runtime/internal/runtime.iface", ptr %40, align 8
|
||||
%42 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %41)
|
||||
%43 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
%44 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %41, 1
|
||||
br i1 true, label %_llgo_17, label %_llgo_18
|
||||
|
||||
_llgo_5: ; preds = %_llgo_17
|
||||
%47 = load ptr, ptr @_llgo_int, align 8
|
||||
%48 = inttoptr i64 %117 to ptr
|
||||
%49 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %47, 0
|
||||
%50 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %49, ptr %48, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %50)
|
||||
%45 = load ptr, ptr @_llgo_int, align 8
|
||||
%46 = inttoptr i64 %115 to ptr
|
||||
%47 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %45, 0
|
||||
%48 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %47, ptr %46, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %48)
|
||||
unreachable
|
||||
|
||||
_llgo_6: ; preds = %_llgo_17
|
||||
%51 = load %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, align 8
|
||||
%52 = extractvalue %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S" %51, 0
|
||||
%53 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %52)
|
||||
%54 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
%55 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %52, 1
|
||||
%49 = load %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, align 8
|
||||
%50 = extractvalue %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S" %49, 0
|
||||
%51 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %50)
|
||||
%52 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
%53 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %50, 1
|
||||
br i1 true, label %_llgo_19, label %_llgo_20
|
||||
|
||||
_llgo_7: ; preds = %_llgo_19
|
||||
%56 = load ptr, ptr @_llgo_int, align 8
|
||||
%57 = inttoptr i64 %128 to ptr
|
||||
%58 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %56, 0
|
||||
%59 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %58, ptr %57, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %59)
|
||||
%54 = load ptr, ptr @_llgo_int, align 8
|
||||
%55 = inttoptr i64 %126 to ptr
|
||||
%56 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %54, 0
|
||||
%57 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %56, ptr %55, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %57)
|
||||
unreachable
|
||||
|
||||
_llgo_8: ; preds = %_llgo_19
|
||||
%60 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, i32 0, i32 0
|
||||
%61 = load %"github.com/goplus/llgo/runtime/internal/runtime.iface", ptr %60, align 8
|
||||
%62 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %61)
|
||||
%63 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %61, 0
|
||||
%64 = getelementptr ptr, ptr %63, i64 4
|
||||
%65 = load ptr, ptr %64, align 8
|
||||
%66 = insertvalue { ptr, ptr } undef, ptr %65, 0
|
||||
%67 = insertvalue { ptr, ptr } %66, ptr %62, 1
|
||||
%68 = extractvalue { ptr, ptr } %67, 1
|
||||
%69 = extractvalue { ptr, ptr } %67, 0
|
||||
%70 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %69(ptr %68)
|
||||
%71 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %70, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 3 })
|
||||
%72 = xor i1 %71, true
|
||||
br i1 %72, label %_llgo_9, label %_llgo_10
|
||||
%58 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, i32 0, i32 0
|
||||
%59 = load %"github.com/goplus/llgo/runtime/internal/runtime.iface", ptr %58, align 8
|
||||
%60 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %59)
|
||||
%61 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %59, 0
|
||||
%62 = getelementptr ptr, ptr %61, i64 4
|
||||
%63 = load ptr, ptr %62, align 8
|
||||
%64 = insertvalue { ptr, ptr } undef, ptr %63, 0
|
||||
%65 = insertvalue { ptr, ptr } %64, ptr %60, 1
|
||||
%66 = extractvalue { ptr, ptr } %65, 1
|
||||
%67 = extractvalue { ptr, ptr } %65, 0
|
||||
%68 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %67(ptr %66)
|
||||
%69 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %68, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 3 })
|
||||
%70 = xor i1 %69, true
|
||||
br i1 %70, label %_llgo_9, label %_llgo_10
|
||||
|
||||
_llgo_9: ; preds = %_llgo_8
|
||||
%73 = load ptr, ptr @_llgo_string, align 8
|
||||
%74 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" %70, ptr %74, align 8
|
||||
%75 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %73, 0
|
||||
%76 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %75, ptr %74, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %76)
|
||||
%71 = load ptr, ptr @_llgo_string, align 8
|
||||
%72 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" %68, ptr %72, align 8
|
||||
%73 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %71, 0
|
||||
%74 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %73, ptr %72, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %74)
|
||||
unreachable
|
||||
|
||||
_llgo_10: ; preds = %_llgo_8
|
||||
%77 = load %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, align 8
|
||||
%78 = extractvalue %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S" %77, 0
|
||||
%79 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %78)
|
||||
%80 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %78, 0
|
||||
%81 = getelementptr ptr, ptr %80, i64 4
|
||||
%82 = load ptr, ptr %81, align 8
|
||||
%83 = insertvalue { ptr, ptr } undef, ptr %82, 0
|
||||
%84 = insertvalue { ptr, ptr } %83, ptr %79, 1
|
||||
%85 = extractvalue { ptr, ptr } %84, 1
|
||||
%86 = extractvalue { ptr, ptr } %84, 0
|
||||
%87 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %86(ptr %85)
|
||||
%88 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %87, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 3 })
|
||||
%89 = xor i1 %88, true
|
||||
br i1 %89, label %_llgo_11, label %_llgo_12
|
||||
%75 = load %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, align 8
|
||||
%76 = extractvalue %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S" %75, 0
|
||||
%77 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %76)
|
||||
%78 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %76, 0
|
||||
%79 = getelementptr ptr, ptr %78, i64 4
|
||||
%80 = load ptr, ptr %79, align 8
|
||||
%81 = insertvalue { ptr, ptr } undef, ptr %80, 0
|
||||
%82 = insertvalue { ptr, ptr } %81, ptr %77, 1
|
||||
%83 = extractvalue { ptr, ptr } %82, 1
|
||||
%84 = extractvalue { ptr, ptr } %82, 0
|
||||
%85 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %84(ptr %83)
|
||||
%86 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %85, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 3 })
|
||||
%87 = xor i1 %86, true
|
||||
br i1 %87, label %_llgo_11, label %_llgo_12
|
||||
|
||||
_llgo_11: ; preds = %_llgo_10
|
||||
%90 = load ptr, ptr @_llgo_string, align 8
|
||||
%91 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" %87, ptr %91, align 8
|
||||
%92 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %90, 0
|
||||
%93 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %92, ptr %91, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %93)
|
||||
%88 = load ptr, ptr @_llgo_string, align 8
|
||||
%89 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" %85, ptr %89, align 8
|
||||
%90 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %88, 0
|
||||
%91 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %90, ptr %89, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %91)
|
||||
unreachable
|
||||
|
||||
_llgo_12: ; preds = %_llgo_10
|
||||
%94 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, i32 0, i32 0
|
||||
%95 = load %"github.com/goplus/llgo/runtime/internal/runtime.iface", ptr %94, align 8
|
||||
%96 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %95)
|
||||
%97 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
%98 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %95, 1
|
||||
%92 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, i32 0, i32 0
|
||||
%93 = load %"github.com/goplus/llgo/runtime/internal/runtime.iface", ptr %92, align 8
|
||||
%94 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %93)
|
||||
%95 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
%96 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %93, 1
|
||||
br i1 true, label %_llgo_21, label %_llgo_22
|
||||
|
||||
_llgo_13: ; preds = %_llgo_21
|
||||
%99 = load ptr, ptr @_llgo_string, align 8
|
||||
%100 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" %139, ptr %100, align 8
|
||||
%101 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %99, 0
|
||||
%102 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %101, ptr %100, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %102)
|
||||
%97 = load ptr, ptr @_llgo_string, align 8
|
||||
%98 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" %137, ptr %98, align 8
|
||||
%99 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %97, 0
|
||||
%100 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %99, ptr %98, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %100)
|
||||
unreachable
|
||||
|
||||
_llgo_14: ; preds = %_llgo_21
|
||||
%103 = load %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, align 8
|
||||
%104 = extractvalue %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S" %103, 0
|
||||
%105 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %104)
|
||||
%106 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
%107 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %104, 1
|
||||
%101 = load %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S", ptr %0, align 8
|
||||
%102 = extractvalue %"github.com/goplus/llgo/cl/_testgo/ifaceprom.S" %101, 0
|
||||
%103 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %102)
|
||||
%104 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
%105 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %102, 1
|
||||
br i1 true, label %_llgo_23, label %_llgo_24
|
||||
|
||||
_llgo_15: ; preds = %_llgo_23
|
||||
%108 = load ptr, ptr @_llgo_string, align 8
|
||||
%109 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" %151, ptr %109, align 8
|
||||
%110 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %108, 0
|
||||
%111 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %110, ptr %109, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %111)
|
||||
%106 = load ptr, ptr @_llgo_string, align 8
|
||||
%107 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" %149, ptr %107, align 8
|
||||
%108 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %106, 0
|
||||
%109 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %108, ptr %107, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %109)
|
||||
unreachable
|
||||
|
||||
_llgo_16: ; preds = %_llgo_23
|
||||
@@ -320,85 +317,85 @@ _llgo_16: ; preds = %_llgo_23
|
||||
ret void
|
||||
|
||||
_llgo_17: ; preds = %_llgo_4
|
||||
%112 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%113 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %112, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %43, ptr %113, align 8
|
||||
%114 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.one$bound", ptr undef }, ptr %112, 1
|
||||
%115 = extractvalue { ptr, ptr } %114, 1
|
||||
%116 = extractvalue { ptr, ptr } %114, 0
|
||||
%117 = call i64 %116(ptr %115)
|
||||
%118 = icmp ne i64 %117, 1
|
||||
br i1 %118, label %_llgo_5, label %_llgo_6
|
||||
%110 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%111 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %110, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %41, ptr %111, align 8
|
||||
%112 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.one$bound", ptr undef }, ptr %110, 1
|
||||
%113 = extractvalue { ptr, ptr } %112, 1
|
||||
%114 = extractvalue { ptr, ptr } %112, 0
|
||||
%115 = call i64 %114(ptr %113)
|
||||
%116 = icmp ne i64 %115, 1
|
||||
br i1 %116, label %_llgo_5, label %_llgo_6
|
||||
|
||||
_llgo_18: ; preds = %_llgo_4
|
||||
%119 = load ptr, ptr @_llgo_string, align 8
|
||||
%120 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 116 }, ptr %120, align 8
|
||||
%121 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %119, 0
|
||||
%122 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %121, ptr %120, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %122)
|
||||
%117 = load ptr, ptr @_llgo_string, align 8
|
||||
%118 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 116 }, ptr %118, align 8
|
||||
%119 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %117, 0
|
||||
%120 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %119, ptr %118, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %120)
|
||||
unreachable
|
||||
|
||||
_llgo_19: ; preds = %_llgo_6
|
||||
%123 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%124 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %123, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %52, ptr %124, align 8
|
||||
%125 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.one$bound", ptr undef }, ptr %123, 1
|
||||
%126 = extractvalue { ptr, ptr } %125, 1
|
||||
%127 = extractvalue { ptr, ptr } %125, 0
|
||||
%128 = call i64 %127(ptr %126)
|
||||
%129 = icmp ne i64 %128, 1
|
||||
br i1 %129, label %_llgo_7, label %_llgo_8
|
||||
%121 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%122 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %121, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %50, ptr %122, align 8
|
||||
%123 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.one$bound", ptr undef }, ptr %121, 1
|
||||
%124 = extractvalue { ptr, ptr } %123, 1
|
||||
%125 = extractvalue { ptr, ptr } %123, 0
|
||||
%126 = call i64 %125(ptr %124)
|
||||
%127 = icmp ne i64 %126, 1
|
||||
br i1 %127, label %_llgo_7, label %_llgo_8
|
||||
|
||||
_llgo_20: ; preds = %_llgo_6
|
||||
%130 = load ptr, ptr @_llgo_string, align 8
|
||||
%131 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 116 }, ptr %131, align 8
|
||||
%132 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %130, 0
|
||||
%133 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %132, ptr %131, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %133)
|
||||
%128 = load ptr, ptr @_llgo_string, align 8
|
||||
%129 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 116 }, ptr %129, align 8
|
||||
%130 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %128, 0
|
||||
%131 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %130, ptr %129, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %131)
|
||||
unreachable
|
||||
|
||||
_llgo_21: ; preds = %_llgo_12
|
||||
%134 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%135 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %134, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %95, ptr %135, align 8
|
||||
%136 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.two$bound", ptr undef }, ptr %134, 1
|
||||
%137 = extractvalue { ptr, ptr } %136, 1
|
||||
%138 = extractvalue { ptr, ptr } %136, 0
|
||||
%139 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %138(ptr %137)
|
||||
%140 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %139, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 3 })
|
||||
%141 = xor i1 %140, true
|
||||
br i1 %141, label %_llgo_13, label %_llgo_14
|
||||
%132 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%133 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %132, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %93, ptr %133, align 8
|
||||
%134 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.two$bound", ptr undef }, ptr %132, 1
|
||||
%135 = extractvalue { ptr, ptr } %134, 1
|
||||
%136 = extractvalue { ptr, ptr } %134, 0
|
||||
%137 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %136(ptr %135)
|
||||
%138 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %137, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 3 })
|
||||
%139 = xor i1 %138, true
|
||||
br i1 %139, label %_llgo_13, label %_llgo_14
|
||||
|
||||
_llgo_22: ; preds = %_llgo_12
|
||||
%142 = load ptr, ptr @_llgo_string, align 8
|
||||
%143 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 116 }, ptr %143, align 8
|
||||
%144 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %142, 0
|
||||
%145 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %144, ptr %143, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %145)
|
||||
%140 = load ptr, ptr @_llgo_string, align 8
|
||||
%141 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 116 }, ptr %141, align 8
|
||||
%142 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %140, 0
|
||||
%143 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %142, ptr %141, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %143)
|
||||
unreachable
|
||||
|
||||
_llgo_23: ; preds = %_llgo_14
|
||||
%146 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%147 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %146, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %104, ptr %147, align 8
|
||||
%148 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.two$bound", ptr undef }, ptr %146, 1
|
||||
%149 = extractvalue { ptr, ptr } %148, 1
|
||||
%150 = extractvalue { ptr, ptr } %148, 0
|
||||
%151 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %150(ptr %149)
|
||||
%152 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %151, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 3 })
|
||||
%153 = xor i1 %152, true
|
||||
br i1 %153, label %_llgo_15, label %_llgo_16
|
||||
%144 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
%145 = getelementptr inbounds { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %144, i32 0, i32 0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.iface" %102, ptr %145, align 8
|
||||
%146 = insertvalue { ptr, ptr } { ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.two$bound", ptr undef }, ptr %144, 1
|
||||
%147 = extractvalue { ptr, ptr } %146, 1
|
||||
%148 = extractvalue { ptr, ptr } %146, 0
|
||||
%149 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %148(ptr %147)
|
||||
%150 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %149, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 3 })
|
||||
%151 = xor i1 %150, true
|
||||
br i1 %151, label %_llgo_15, label %_llgo_16
|
||||
|
||||
_llgo_24: ; preds = %_llgo_14
|
||||
%154 = load ptr, ptr @_llgo_string, align 8
|
||||
%155 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 116 }, ptr %155, align 8
|
||||
%156 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %154, 0
|
||||
%157 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %156, ptr %155, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %157)
|
||||
%152 = load ptr, ptr @_llgo_string, align 8
|
||||
%153 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 116 }, ptr %153, align 8
|
||||
%154 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %152, 0
|
||||
%155 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %154, ptr %153, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %155)
|
||||
unreachable
|
||||
}
|
||||
|
||||
@@ -515,46 +512,32 @@ _llgo_8: ; preds = %_llgo_7, %_llgo_6
|
||||
%65 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %64, i64 2, 1
|
||||
%66 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %65, i64 2, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr %0, ptr %6, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %60, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %66)
|
||||
%67 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
%68 = load ptr, ptr @"_llgo_func$zNDVRsWTIpUPKouNUS805RGX--IV9qVK8B31IZbg5to", align 8
|
||||
%69 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 47 }, ptr undef }, ptr %67, 1
|
||||
%70 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 47 }, ptr undef }, ptr %68, 1
|
||||
%71 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 48)
|
||||
%72 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %71, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %69, ptr %72, align 8
|
||||
%73 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %71, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %70, ptr %73, align 8
|
||||
%74 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %71, 0
|
||||
%75 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %74, i64 2, 1
|
||||
%76 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %75, i64 2, 2
|
||||
%77 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 43 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %76)
|
||||
store ptr %77, ptr @"github.com/goplus/llgo/cl/_testgo/ifaceprom.iface$zZ89tENb5h_KNjvpxf1TXPfaWFYn0IZrZwyVf42lRtA", align 8
|
||||
%78 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 43 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 1 })
|
||||
%79 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
%80 = icmp eq ptr %79, null
|
||||
br i1 %80, label %_llgo_9, label %_llgo_10
|
||||
%67 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 43 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 1 })
|
||||
%68 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
%69 = icmp eq ptr %68, null
|
||||
br i1 %69, label %_llgo_9, label %_llgo_10
|
||||
|
||||
_llgo_9: ; preds = %_llgo_8
|
||||
store ptr %78, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
store ptr %67, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/ifaceprom.I", align 8
|
||||
br label %_llgo_10
|
||||
|
||||
_llgo_10: ; preds = %_llgo_9, %_llgo_8
|
||||
%81 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
%82 = load ptr, ptr @"_llgo_func$zNDVRsWTIpUPKouNUS805RGX--IV9qVK8B31IZbg5to", align 8
|
||||
br i1 %80, label %_llgo_11, label %_llgo_12
|
||||
%70 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
%71 = load ptr, ptr @"_llgo_func$zNDVRsWTIpUPKouNUS805RGX--IV9qVK8B31IZbg5to", align 8
|
||||
br i1 %69, label %_llgo_11, label %_llgo_12
|
||||
|
||||
_llgo_11: ; preds = %_llgo_10
|
||||
%83 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 47 }, ptr undef }, ptr %81, 1
|
||||
%84 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 47 }, ptr undef }, ptr %82, 1
|
||||
%85 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 48)
|
||||
%86 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %85, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %83, ptr %86, align 8
|
||||
%87 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %85, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %84, ptr %87, align 8
|
||||
%88 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %85, 0
|
||||
%89 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %88, i64 2, 1
|
||||
%90 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %89, i64 2, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr %78, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %90)
|
||||
%72 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 47 }, ptr undef }, ptr %70, 1
|
||||
%73 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 47 }, ptr undef }, ptr %71, 1
|
||||
%74 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 48)
|
||||
%75 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %74, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %72, ptr %75, align 8
|
||||
%76 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %74, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %73, ptr %76, align 8
|
||||
%77 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %74, 0
|
||||
%78 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %77, i64 2, 1
|
||||
%79 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %78, i64 2, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr %67, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %79)
|
||||
br label %_llgo_12
|
||||
|
||||
_llgo_12: ; preds = %_llgo_11, %_llgo_10
|
||||
@@ -577,7 +560,9 @@ declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr, ptr)
|
||||
|
||||
@@ -585,10 +570,6 @@ declare void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.c
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
define i64 @"github.com/goplus/llgo/cl/_testgo/ifaceprom.I.one$bound"(ptr %0) {
|
||||
_llgo_0:
|
||||
%1 = load { %"github.com/goplus/llgo/runtime/internal/runtime.iface" }, ptr %0, align 8
|
||||
|
||||
@@ -31,7 +31,6 @@ source_filename = "github.com/goplus/llgo/cl/_testgo/interface"
|
||||
@"*_llgo_github.com/goplus/llgo/cl/_testgo/interface.Game2" = linkonce global ptr null, align 8
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testdata/foo.Gamer" = linkonce global ptr null, align 8
|
||||
@9 = private unnamed_addr constant [5 x i8] c"Gamer", align 1
|
||||
@"github.com/goplus/llgo/cl/_testgo/interface.iface$sO8a1LvuUsjXwiwaC6sR9-L4DiYgiOnZi7iosyShJXg" = linkonce global ptr null, align 8
|
||||
@10 = private unnamed_addr constant [2 x i8] c"OK", align 1
|
||||
@11 = private unnamed_addr constant [4 x i8] c"FAIL", align 1
|
||||
|
||||
@@ -133,7 +132,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_5
|
||||
|
||||
_llgo_3: ; preds = %_llgo_0
|
||||
%26 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %6, 1
|
||||
%27 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/interface.iface$sO8a1LvuUsjXwiwaC6sR9-L4DiYgiOnZi7iosyShJXg", align 8
|
||||
%27 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testdata/foo.Gamer", align 8
|
||||
%28 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %27, ptr %12)
|
||||
%29 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %28, 0
|
||||
%30 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %29, ptr %26, 1
|
||||
@@ -158,7 +157,7 @@ _llgo_5: ; preds = %_llgo_4, %_llgo_3
|
||||
|
||||
_llgo_6: ; preds = %_llgo_2
|
||||
%36 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %11, 1
|
||||
%37 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/interface.iface$sO8a1LvuUsjXwiwaC6sR9-L4DiYgiOnZi7iosyShJXg", align 8
|
||||
%37 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testdata/foo.Gamer", align 8
|
||||
%38 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %37, ptr %23)
|
||||
%39 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %38, 0
|
||||
%40 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %39, ptr %36, 1
|
||||
@@ -405,20 +404,6 @@ _llgo_23: ; preds = %_llgo_22
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
%109 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%110 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%111 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 4 }, ptr undef }, ptr %109, 1
|
||||
%112 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 48 }, ptr undef }, ptr %110, 1
|
||||
%113 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 48)
|
||||
%114 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %113, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %111, ptr %114, align 8
|
||||
%115 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %113, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %112, ptr %115, align 8
|
||||
%116 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %113, 0
|
||||
%117 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %116, i64 2, 1
|
||||
%118 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %117, i64 2, 2
|
||||
%119 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 43 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %118)
|
||||
store ptr %119, ptr @"github.com/goplus/llgo/cl/_testgo/interface.iface$sO8a1LvuUsjXwiwaC6sR9-L4DiYgiOnZi7iosyShJXg", align 8
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -444,8 +429,6 @@ declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterfac
|
||||
|
||||
declare i1 @"github.com/goplus/llgo/runtime/internal/runtime.Implements"(ptr, ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr, ptr)
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
@@ -31,8 +31,9 @@ source_filename = "github.com/goplus/llgo/cl/_testgo/interface1370"
|
||||
@_llgo_bool = linkonce global ptr null, align 8
|
||||
@"_llgo_func$YHeRw3AOvQtzv982-ZO3Yn8vh3Fx89RM3VvI8E4iKVk" = linkonce global ptr null, align 8
|
||||
@"*_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle" = linkonce global ptr null, align 8
|
||||
@"github.com/goplus/llgo/cl/_testgo/interface1370.iface$OopIVfjRcxQr1gmJyGi5G7hHt__vH05AREEM7PthH9o" = linkonce global ptr null, align 8
|
||||
@12 = private unnamed_addr constant [3 x i8] c"ID:", align 1
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Shape" = linkonce global ptr null, align 8
|
||||
@12 = private unnamed_addr constant [5 x i8] c"Shape", align 1
|
||||
@13 = private unnamed_addr constant [3 x i8] c"ID:", align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/interface1370.init"() {
|
||||
_llgo_0:
|
||||
@@ -54,18 +55,15 @@ _llgo_0:
|
||||
%0 = call ptr @"github.com/goplus/llgo/cl/_testdata/geometry1370.NewRectangle"(double 5.000000e+00, double 3.000000e+00)
|
||||
%1 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", align 8
|
||||
%2 = load ptr, ptr @"*_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Rectangle", align 8
|
||||
%3 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||
%4 = load ptr, ptr @"_llgo_func$VZ-8VPNF1RaLICwxc1Ghn7BbgyFX3v762OCdx127EkA", align 8
|
||||
%5 = load ptr, ptr @"_llgo_func$YHeRw3AOvQtzv982-ZO3Yn8vh3Fx89RM3VvI8E4iKVk", align 8
|
||||
%6 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/interface1370.iface$OopIVfjRcxQr1gmJyGi5G7hHt__vH05AREEM7PthH9o", align 8
|
||||
%7 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %6, ptr %2)
|
||||
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %7, 0
|
||||
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %8, ptr %0, 1
|
||||
call void @"github.com/goplus/llgo/cl/_testdata/geometry1370.RegisterShape"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %9, i64 42)
|
||||
%10 = call i64 @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).GetID"(ptr %0)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @12, i64 3 })
|
||||
%3 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Shape", align 8
|
||||
%4 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %3, ptr %2)
|
||||
%5 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %4, 0
|
||||
%6 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %5, ptr %0, 1
|
||||
call void @"github.com/goplus/llgo/cl/_testdata/geometry1370.RegisterShape"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %6, i64 42)
|
||||
%7 = call i64 @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).GetID"(ptr %0)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @13, i64 3 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %10)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %7)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
}
|
||||
@@ -275,24 +273,39 @@ _llgo_19: ; preds = %_llgo_8
|
||||
br label %_llgo_20
|
||||
|
||||
_llgo_20: ; preds = %_llgo_19, %_llgo_8
|
||||
%110 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||
%111 = load ptr, ptr @"_llgo_func$VZ-8VPNF1RaLICwxc1Ghn7BbgyFX3v762OCdx127EkA", align 8
|
||||
%112 = load ptr, ptr @"_llgo_func$YHeRw3AOvQtzv982-ZO3Yn8vh3Fx89RM3VvI8E4iKVk", align 8
|
||||
%113 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 4 }, ptr undef }, ptr %110, 1
|
||||
%114 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @9, i64 54 }, ptr undef }, ptr %111, 1
|
||||
%115 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @11, i64 57 }, ptr undef }, ptr %112, 1
|
||||
%116 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 72)
|
||||
%117 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %116, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %113, ptr %117, align 8
|
||||
%118 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %116, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %114, ptr %118, align 8
|
||||
%119 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %116, i64 2
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %115, ptr %119, align 8
|
||||
%120 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %116, 0
|
||||
%121 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %120, i64 3, 1
|
||||
%122 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %121, i64 3, 2
|
||||
%123 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 47 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %122)
|
||||
store ptr %123, ptr @"github.com/goplus/llgo/cl/_testgo/interface1370.iface$OopIVfjRcxQr1gmJyGi5G7hHt__vH05AREEM7PthH9o", align 8
|
||||
%110 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 48 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @12, i64 5 })
|
||||
%111 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Shape", align 8
|
||||
%112 = icmp eq ptr %111, null
|
||||
br i1 %112, label %_llgo_21, label %_llgo_22
|
||||
|
||||
_llgo_21: ; preds = %_llgo_20
|
||||
store ptr %110, ptr @"_llgo_github.com/goplus/llgo/cl/_testdata/geometry1370.Shape", align 8
|
||||
br label %_llgo_22
|
||||
|
||||
_llgo_22: ; preds = %_llgo_21, %_llgo_20
|
||||
%113 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||
%114 = load ptr, ptr @"_llgo_func$VZ-8VPNF1RaLICwxc1Ghn7BbgyFX3v762OCdx127EkA", align 8
|
||||
%115 = load ptr, ptr @"_llgo_func$YHeRw3AOvQtzv982-ZO3Yn8vh3Fx89RM3VvI8E4iKVk", align 8
|
||||
br i1 %112, label %_llgo_23, label %_llgo_24
|
||||
|
||||
_llgo_23: ; preds = %_llgo_22
|
||||
%116 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 4 }, ptr undef }, ptr %113, 1
|
||||
%117 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @9, i64 54 }, ptr undef }, ptr %114, 1
|
||||
%118 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @11, i64 57 }, ptr undef }, ptr %115, 1
|
||||
%119 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 72)
|
||||
%120 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %119, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %116, ptr %120, align 8
|
||||
%121 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %119, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %117, ptr %121, align 8
|
||||
%122 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %119, i64 2
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %118, ptr %122, align 8
|
||||
%123 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %119, 0
|
||||
%124 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %123, i64 3, 1
|
||||
%125 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %124, i64 3, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr %110, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %125)
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -322,7 +335,9 @@ declare i1 @"github.com/goplus/llgo/cl/_testdata/geometry1370.(*Rectangle).valid
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.PointerTo"(ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr, ptr)
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -32,26 +32,27 @@ source_filename = "github.com/goplus/llgo/cl/_testgo/reflect"
|
||||
@10 = private unnamed_addr constant [1 x i8] c"n", align 1
|
||||
@11 = private unnamed_addr constant [3 x i8] c"Add", align 1
|
||||
@"*_llgo_github.com/goplus/llgo/cl/_testgo/reflect.T" = linkonce global ptr null, align 8
|
||||
@"_llgo_iface$VdBKYV8-gcMjZtZfcf-u2oKoj9Lu3VXwuG8TGCW2S4A" = linkonce global ptr null, align 8
|
||||
@12 = private unnamed_addr constant [7 x i8] c"imethod", align 1
|
||||
@13 = private unnamed_addr constant [6 x i8] c"method", align 1
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testgo/reflect.I" = linkonce global ptr null, align 8
|
||||
@12 = private unnamed_addr constant [1 x i8] c"I", align 1
|
||||
@13 = private unnamed_addr constant [7 x i8] c"imethod", align 1
|
||||
@14 = private unnamed_addr constant [6 x i8] c"method", align 1
|
||||
@_llgo_any = linkonce global ptr null, align 8
|
||||
@"[]_llgo_any" = linkonce global ptr null, align 8
|
||||
@"_llgo_func$KK0iU4Wpi3BdRqssvycXqtgNe2Dq1riBlM61Rds1QsU" = linkonce global ptr null, align 8
|
||||
@"github.com/goplus/llgo/cl/_testgo/reflect.struct$FjMjjQr3-2iTiWyZP1IIQFOz0hUCa0OS6pEm5uVV6Pk" = linkonce global ptr null, align 8
|
||||
@14 = private unnamed_addr constant [10 x i8] c"call.slice", align 1
|
||||
@15 = private unnamed_addr constant [40 x i8] c"type assertion interface{} -> int failed", align 1
|
||||
@15 = private unnamed_addr constant [10 x i8] c"call.slice", align 1
|
||||
@16 = private unnamed_addr constant [40 x i8] c"type assertion interface{} -> int failed", align 1
|
||||
@"map[_llgo_int]_llgo_string" = linkonce global ptr null, align 8
|
||||
@16 = private unnamed_addr constant [7 x i8] c"topbits", align 1
|
||||
@17 = private unnamed_addr constant [4 x i8] c"keys", align 1
|
||||
@18 = private unnamed_addr constant [5 x i8] c"elems", align 1
|
||||
@19 = private unnamed_addr constant [8 x i8] c"overflow", align 1
|
||||
@20 = private unnamed_addr constant [5 x i8] c"hello", align 1
|
||||
@21 = private unnamed_addr constant [5 x i8] c"world", align 1
|
||||
@22 = private unnamed_addr constant [14 x i8] c"MapIndex error", align 1
|
||||
@23 = private unnamed_addr constant [4 x i8] c"todo", align 1
|
||||
@24 = private unnamed_addr constant [12 x i8] c"must invalid", align 1
|
||||
@25 = private unnamed_addr constant [13 x i8] c"MapIter error", align 1
|
||||
@17 = private unnamed_addr constant [7 x i8] c"topbits", align 1
|
||||
@18 = private unnamed_addr constant [4 x i8] c"keys", align 1
|
||||
@19 = private unnamed_addr constant [5 x i8] c"elems", align 1
|
||||
@20 = private unnamed_addr constant [8 x i8] c"overflow", align 1
|
||||
@21 = private unnamed_addr constant [5 x i8] c"hello", align 1
|
||||
@22 = private unnamed_addr constant [5 x i8] c"world", align 1
|
||||
@23 = private unnamed_addr constant [14 x i8] c"MapIndex error", align 1
|
||||
@24 = private unnamed_addr constant [4 x i8] c"todo", align 1
|
||||
@25 = private unnamed_addr constant [12 x i8] c"must invalid", align 1
|
||||
@26 = private unnamed_addr constant [13 x i8] c"MapIter error", align 1
|
||||
|
||||
define i64 @"github.com/goplus/llgo/cl/_testgo/reflect.(*T).Add"(ptr %0, i64 %1) {
|
||||
_llgo_0:
|
||||
@@ -269,112 +270,111 @@ _llgo_0:
|
||||
store i64 1, ptr %1, align 4
|
||||
%2 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/reflect.T", align 8
|
||||
%3 = load ptr, ptr @"*_llgo_github.com/goplus/llgo/cl/_testgo/reflect.T", align 8
|
||||
%4 = load ptr, ptr @"_llgo_func$ekGNsrYBSzltfAjxbl6T8H6Yq8j16wzqS3nDj2xxGMU", align 8
|
||||
%5 = load ptr, ptr @"_llgo_iface$VdBKYV8-gcMjZtZfcf-u2oKoj9Lu3VXwuG8TGCW2S4A", align 8
|
||||
%6 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %5, ptr %3)
|
||||
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %6, 0
|
||||
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %7, ptr %0, 1
|
||||
%9 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %8)
|
||||
%10 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %8, 1
|
||||
%11 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %9, 0
|
||||
%12 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %11, ptr %10, 1
|
||||
%13 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %12)
|
||||
%14 = call %reflect.Value @reflect.Value.Method(%reflect.Value %13, i64 0)
|
||||
%15 = call i64 @reflect.Value.Kind(%reflect.Value %14)
|
||||
%16 = call %"github.com/goplus/llgo/runtime/internal/runtime.iface" @reflect.Value.Type(%reflect.Value %14)
|
||||
%17 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %16)
|
||||
%18 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %16, 0
|
||||
%19 = getelementptr ptr, ptr %18, i64 37
|
||||
%20 = load ptr, ptr %19, align 8
|
||||
%21 = insertvalue { ptr, ptr } undef, ptr %20, 0
|
||||
%22 = insertvalue { ptr, ptr } %21, ptr %17, 1
|
||||
%23 = extractvalue { ptr, ptr } %22, 1
|
||||
%24 = extractvalue { ptr, ptr } %22, 0
|
||||
%25 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %24(ptr %23)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @12, i64 7 })
|
||||
%4 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/reflect.I", align 8
|
||||
%5 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %4, ptr %3)
|
||||
%6 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %5, 0
|
||||
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %6, ptr %0, 1
|
||||
%8 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %7)
|
||||
%9 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %7, 1
|
||||
%10 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %8, 0
|
||||
%11 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %10, ptr %9, 1
|
||||
%12 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %11)
|
||||
%13 = call %reflect.Value @reflect.Value.Method(%reflect.Value %12, i64 0)
|
||||
%14 = call i64 @reflect.Value.Kind(%reflect.Value %13)
|
||||
%15 = call %"github.com/goplus/llgo/runtime/internal/runtime.iface" @reflect.Value.Type(%reflect.Value %13)
|
||||
%16 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %15)
|
||||
%17 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %15, 0
|
||||
%18 = getelementptr ptr, ptr %17, i64 37
|
||||
%19 = load ptr, ptr %18, align 8
|
||||
%20 = insertvalue { ptr, ptr } undef, ptr %19, 0
|
||||
%21 = insertvalue { ptr, ptr } %20, ptr %16, 1
|
||||
%22 = extractvalue { ptr, ptr } %21, 1
|
||||
%23 = extractvalue { ptr, ptr } %21, 0
|
||||
%24 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %23(ptr %22)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @13, i64 7 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintUint"(i64 %15)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintUint"(i64 %14)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %25)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %24)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
%26 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 24)
|
||||
%27 = getelementptr inbounds %reflect.Value, ptr %26, i64 0
|
||||
%28 = load ptr, ptr @_llgo_int, align 8
|
||||
%29 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %28, 0
|
||||
%30 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %29, ptr inttoptr (i64 100 to ptr), 1
|
||||
%31 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %30)
|
||||
store %reflect.Value %31, ptr %27, align 8
|
||||
%32 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %26, 0
|
||||
%33 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %32, i64 1, 1
|
||||
%34 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %33, i64 1, 2
|
||||
%35 = call %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @reflect.Value.Call(%reflect.Value %14, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %34)
|
||||
%36 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %35, 0
|
||||
%37 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %35, 1
|
||||
%38 = icmp sge i64 0, %37
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.AssertIndexRange"(i1 %38)
|
||||
%39 = getelementptr inbounds %reflect.Value, ptr %36, i64 0
|
||||
%40 = load %reflect.Value, ptr %39, align 8
|
||||
%41 = call i64 @reflect.Value.Int(%reflect.Value %40)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %41)
|
||||
%25 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 24)
|
||||
%26 = getelementptr inbounds %reflect.Value, ptr %25, i64 0
|
||||
%27 = load ptr, ptr @_llgo_int, align 8
|
||||
%28 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %27, 0
|
||||
%29 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %28, ptr inttoptr (i64 100 to ptr), 1
|
||||
%30 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %29)
|
||||
store %reflect.Value %30, ptr %26, align 8
|
||||
%31 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %25, 0
|
||||
%32 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %31, i64 1, 1
|
||||
%33 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %32, i64 1, 2
|
||||
%34 = call %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @reflect.Value.Call(%reflect.Value %13, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %33)
|
||||
%35 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %34, 0
|
||||
%36 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %34, 1
|
||||
%37 = icmp sge i64 0, %36
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.AssertIndexRange"(i1 %37)
|
||||
%38 = getelementptr inbounds %reflect.Value, ptr %35, i64 0
|
||||
%39 = load %reflect.Value, ptr %38, align 8
|
||||
%40 = call i64 @reflect.Value.Int(%reflect.Value %39)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %40)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
%42 = call %"github.com/goplus/llgo/runtime/internal/runtime.eface" @reflect.Value.Interface(%reflect.Value %14)
|
||||
%43 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %42, 0
|
||||
%44 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/reflect.struct$QIHBTaw1IFobr8yvWpq-2AJFm3xBNhdW_aNBicqUBGk", align 8
|
||||
%45 = icmp eq ptr %43, %44
|
||||
br i1 %45, label %_llgo_3, label %_llgo_4
|
||||
%41 = call %"github.com/goplus/llgo/runtime/internal/runtime.eface" @reflect.Value.Interface(%reflect.Value %13)
|
||||
%42 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %41, 0
|
||||
%43 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/reflect.struct$QIHBTaw1IFobr8yvWpq-2AJFm3xBNhdW_aNBicqUBGk", align 8
|
||||
%44 = icmp eq ptr %42, %43
|
||||
br i1 %44, label %_llgo_3, label %_llgo_4
|
||||
|
||||
_llgo_1: ; preds = %_llgo_5
|
||||
%46 = load ptr, ptr @_llgo_string, align 8
|
||||
%47 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 5 }, ptr %47, align 8
|
||||
%48 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %46, 0
|
||||
%49 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %48, ptr %47, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %49)
|
||||
%45 = load ptr, ptr @_llgo_string, align 8
|
||||
%46 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 5 }, ptr %46, align 8
|
||||
%47 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %45, 0
|
||||
%48 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %47, ptr %46, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %48)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_5
|
||||
%50 = extractvalue { ptr, ptr } %76, 1
|
||||
%51 = extractvalue { ptr, ptr } %76, 0
|
||||
%52 = call i64 %51(ptr %50, i64 1)
|
||||
%53 = call %"github.com/goplus/llgo/runtime/internal/runtime.eface" @reflect.Value.Interface(%reflect.Value %14)
|
||||
%54 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %53)
|
||||
%55 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 24)
|
||||
%56 = getelementptr inbounds %reflect.Value, ptr %55, i64 0
|
||||
%57 = load ptr, ptr @_llgo_int, align 8
|
||||
%58 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %57, 0
|
||||
%59 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %58, ptr inttoptr (i64 100 to ptr), 1
|
||||
%60 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %59)
|
||||
store %reflect.Value %60, ptr %56, align 8
|
||||
%61 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %55, 0
|
||||
%62 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %61, i64 1, 1
|
||||
%63 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %62, i64 1, 2
|
||||
%64 = call %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @reflect.Value.Call(%reflect.Value %54, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %63)
|
||||
%65 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %64, 0
|
||||
%66 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %64, 1
|
||||
%67 = icmp sge i64 0, %66
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.AssertIndexRange"(i1 %67)
|
||||
%68 = getelementptr inbounds %reflect.Value, ptr %65, i64 0
|
||||
%69 = load %reflect.Value, ptr %68, align 8
|
||||
%70 = call i64 @reflect.Value.Int(%reflect.Value %69)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %70)
|
||||
%49 = extractvalue { ptr, ptr } %75, 1
|
||||
%50 = extractvalue { ptr, ptr } %75, 0
|
||||
%51 = call i64 %50(ptr %49, i64 1)
|
||||
%52 = call %"github.com/goplus/llgo/runtime/internal/runtime.eface" @reflect.Value.Interface(%reflect.Value %13)
|
||||
%53 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %52)
|
||||
%54 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 24)
|
||||
%55 = getelementptr inbounds %reflect.Value, ptr %54, i64 0
|
||||
%56 = load ptr, ptr @_llgo_int, align 8
|
||||
%57 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %56, 0
|
||||
%58 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %57, ptr inttoptr (i64 100 to ptr), 1
|
||||
%59 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %58)
|
||||
store %reflect.Value %59, ptr %55, align 8
|
||||
%60 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %54, 0
|
||||
%61 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %60, i64 1, 1
|
||||
%62 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %61, i64 1, 2
|
||||
%63 = call %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @reflect.Value.Call(%reflect.Value %53, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %62)
|
||||
%64 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %63, 0
|
||||
%65 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %63, 1
|
||||
%66 = icmp sge i64 0, %65
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.AssertIndexRange"(i1 %66)
|
||||
%67 = getelementptr inbounds %reflect.Value, ptr %64, i64 0
|
||||
%68 = load %reflect.Value, ptr %67, align 8
|
||||
%69 = call i64 @reflect.Value.Int(%reflect.Value %68)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %69)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
|
||||
_llgo_3: ; preds = %_llgo_0
|
||||
%71 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %42, 1
|
||||
%72 = load { ptr, ptr }, ptr %71, align 8
|
||||
%73 = insertvalue { { ptr, ptr }, i1 } undef, { ptr, ptr } %72, 0
|
||||
%74 = insertvalue { { ptr, ptr }, i1 } %73, i1 true, 1
|
||||
%70 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %41, 1
|
||||
%71 = load { ptr, ptr }, ptr %70, align 8
|
||||
%72 = insertvalue { { ptr, ptr }, i1 } undef, { ptr, ptr } %71, 0
|
||||
%73 = insertvalue { { ptr, ptr }, i1 } %72, i1 true, 1
|
||||
br label %_llgo_5
|
||||
|
||||
_llgo_4: ; preds = %_llgo_0
|
||||
br label %_llgo_5
|
||||
|
||||
_llgo_5: ; preds = %_llgo_4, %_llgo_3
|
||||
%75 = phi { { ptr, ptr }, i1 } [ %74, %_llgo_3 ], [ zeroinitializer, %_llgo_4 ]
|
||||
%76 = extractvalue { { ptr, ptr }, i1 } %75, 0
|
||||
%77 = extractvalue { { ptr, ptr }, i1 } %75, 1
|
||||
br i1 %77, label %_llgo_2, label %_llgo_1
|
||||
%74 = phi { { ptr, ptr }, i1 } [ %73, %_llgo_3 ], [ zeroinitializer, %_llgo_4 ]
|
||||
%75 = extractvalue { { ptr, ptr }, i1 } %74, 0
|
||||
%76 = extractvalue { { ptr, ptr }, i1 } %74, 1
|
||||
br i1 %76, label %_llgo_2, label %_llgo_1
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/reflect.callMethod"() {
|
||||
@@ -398,7 +398,7 @@ _llgo_0:
|
||||
%15 = extractvalue { ptr, ptr } %14, 1
|
||||
%16 = extractvalue { ptr, ptr } %14, 0
|
||||
%17 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" %16(ptr %15)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @13, i64 6 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @14, i64 6 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintUint"(i64 %7)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
@@ -554,7 +554,7 @@ _llgo_0:
|
||||
%50 = getelementptr inbounds %reflect.Value, ptr %47, i64 1
|
||||
%51 = load %reflect.Value, ptr %50, align 8
|
||||
%52 = call i64 @reflect.Value.Int(%reflect.Value %51)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @14, i64 10 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @15, i64 10 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %46)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
@@ -624,7 +624,7 @@ _llgo_0:
|
||||
%98 = getelementptr inbounds %reflect.Value, ptr %95, i64 1
|
||||
%99 = load %reflect.Value, ptr %98, align 8
|
||||
%100 = call i64 @reflect.Value.Int(%reflect.Value %99)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @14, i64 10 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @15, i64 10 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintInt"(i64 %94)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 32)
|
||||
@@ -681,7 +681,7 @@ _llgo_4: ; preds = %_llgo_2
|
||||
_llgo_5: ; preds = %_llgo_2
|
||||
%38 = load ptr, ptr @_llgo_string, align 8
|
||||
%39 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @15, i64 40 }, ptr %39, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @16, i64 40 }, ptr %39, align 8
|
||||
%40 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %38, 0
|
||||
%41 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %40, ptr %39, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %41)
|
||||
@@ -723,12 +723,12 @@ _llgo_0:
|
||||
%3 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 8)
|
||||
store i64 1, ptr %3, align 4
|
||||
%4 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.MapAssign"(ptr %2, ptr %1, ptr %3)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @20, i64 5 }, ptr %4, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @21, i64 5 }, ptr %4, align 8
|
||||
%5 = load ptr, ptr @"map[_llgo_int]_llgo_string", align 8
|
||||
%6 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 8)
|
||||
store i64 2, ptr %6, align 4
|
||||
%7 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.MapAssign"(ptr %5, ptr %1, ptr %6)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @21, i64 5 }, ptr %7, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @22, i64 5 }, ptr %7, align 8
|
||||
%8 = load ptr, ptr @"map[_llgo_int]_llgo_string", align 8
|
||||
%9 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %8, 0
|
||||
%10 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %9, ptr %1, 1
|
||||
@@ -753,7 +753,7 @@ _llgo_2: ; preds = %_llgo_3
|
||||
%21 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %20)
|
||||
%22 = call %reflect.Value @reflect.Value.MapIndex(%reflect.Value %11, %reflect.Value %21)
|
||||
%23 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" @reflect.Value.String(%reflect.Value %22)
|
||||
%24 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %23, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @21, i64 5 })
|
||||
%24 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %23, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @22, i64 5 })
|
||||
%25 = xor i1 %24, true
|
||||
br i1 %25, label %_llgo_4, label %_llgo_5
|
||||
|
||||
@@ -766,7 +766,7 @@ _llgo_3: ; preds = %_llgo_0
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
%29 = load ptr, ptr @_llgo_string, align 8
|
||||
%30 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @22, i64 14 }, ptr %30, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @23, i64 14 }, ptr %30, align 8
|
||||
%31 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %29, 0
|
||||
%32 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %31, ptr %30, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %32)
|
||||
@@ -779,7 +779,7 @@ _llgo_5: ; preds = %_llgo_2
|
||||
%36 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %35)
|
||||
%37 = load ptr, ptr @_llgo_string, align 8
|
||||
%38 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @23, i64 4 }, ptr %38, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @24, i64 4 }, ptr %38, align 8
|
||||
%39 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %37, 0
|
||||
%40 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %39, ptr %38, 1
|
||||
%41 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %40)
|
||||
@@ -790,14 +790,14 @@ _llgo_5: ; preds = %_llgo_2
|
||||
%45 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %44)
|
||||
%46 = call %reflect.Value @reflect.Value.MapIndex(%reflect.Value %11, %reflect.Value %45)
|
||||
%47 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" @reflect.Value.String(%reflect.Value %46)
|
||||
%48 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %47, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @23, i64 4 })
|
||||
%48 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %47, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @24, i64 4 })
|
||||
%49 = xor i1 %48, true
|
||||
br i1 %49, label %_llgo_6, label %_llgo_7
|
||||
|
||||
_llgo_6: ; preds = %_llgo_5
|
||||
%50 = load ptr, ptr @_llgo_string, align 8
|
||||
%51 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @22, i64 14 }, ptr %51, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @23, i64 14 }, ptr %51, align 8
|
||||
%52 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %50, 0
|
||||
%53 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %52, ptr %51, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %53)
|
||||
@@ -813,7 +813,7 @@ _llgo_7: ; preds = %_llgo_5
|
||||
br i1 %59, label %_llgo_8, label %_llgo_9
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @24, i64 12 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @25, i64 12 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
br label %_llgo_9
|
||||
|
||||
@@ -864,7 +864,7 @@ _llgo_12: ; preds = %_llgo_14, %_llgo_9
|
||||
_llgo_13: ; preds = %_llgo_14, %_llgo_10
|
||||
%90 = load ptr, ptr @_llgo_string, align 8
|
||||
%91 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @25, i64 13 }, ptr %91, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @26, i64 13 }, ptr %91, align 8
|
||||
%92 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %90, 0
|
||||
%93 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %92, ptr %91, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %93)
|
||||
@@ -899,7 +899,7 @@ _llgo_0:
|
||||
%14 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %13)
|
||||
%15 = load ptr, ptr @_llgo_string, align 8
|
||||
%16 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @20, i64 5 }, ptr %16, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @21, i64 5 }, ptr %16, align 8
|
||||
%17 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %15, 0
|
||||
%18 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %17, ptr %16, 1
|
||||
%19 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %18)
|
||||
@@ -910,7 +910,7 @@ _llgo_0:
|
||||
%23 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %22)
|
||||
%24 = load ptr, ptr @_llgo_string, align 8
|
||||
%25 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @21, i64 5 }, ptr %25, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @22, i64 5 }, ptr %25, align 8
|
||||
%26 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %24, 0
|
||||
%27 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %26, ptr %25, 1
|
||||
%28 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %27)
|
||||
@@ -935,7 +935,7 @@ _llgo_2: ; preds = %_llgo_3
|
||||
%38 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %37)
|
||||
%39 = call %reflect.Value @reflect.Value.MapIndex(%reflect.Value %10, %reflect.Value %38)
|
||||
%40 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" @reflect.Value.String(%reflect.Value %39)
|
||||
%41 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %40, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @21, i64 5 })
|
||||
%41 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %40, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @22, i64 5 })
|
||||
%42 = xor i1 %41, true
|
||||
br i1 %42, label %_llgo_4, label %_llgo_5
|
||||
|
||||
@@ -948,7 +948,7 @@ _llgo_3: ; preds = %_llgo_0
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
%46 = load ptr, ptr @_llgo_string, align 8
|
||||
%47 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @22, i64 14 }, ptr %47, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @23, i64 14 }, ptr %47, align 8
|
||||
%48 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %46, 0
|
||||
%49 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %48, ptr %47, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %49)
|
||||
@@ -961,7 +961,7 @@ _llgo_5: ; preds = %_llgo_2
|
||||
%53 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %52)
|
||||
%54 = load ptr, ptr @_llgo_string, align 8
|
||||
%55 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @23, i64 4 }, ptr %55, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @24, i64 4 }, ptr %55, align 8
|
||||
%56 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %54, 0
|
||||
%57 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %56, ptr %55, 1
|
||||
%58 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %57)
|
||||
@@ -972,14 +972,14 @@ _llgo_5: ; preds = %_llgo_2
|
||||
%62 = call %reflect.Value @reflect.ValueOf(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %61)
|
||||
%63 = call %reflect.Value @reflect.Value.MapIndex(%reflect.Value %10, %reflect.Value %62)
|
||||
%64 = call %"github.com/goplus/llgo/runtime/internal/runtime.String" @reflect.Value.String(%reflect.Value %63)
|
||||
%65 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %64, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @23, i64 4 })
|
||||
%65 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.StringEqual"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %64, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @24, i64 4 })
|
||||
%66 = xor i1 %65, true
|
||||
br i1 %66, label %_llgo_6, label %_llgo_7
|
||||
|
||||
_llgo_6: ; preds = %_llgo_5
|
||||
%67 = load ptr, ptr @_llgo_string, align 8
|
||||
%68 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @22, i64 14 }, ptr %68, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @23, i64 14 }, ptr %68, align 8
|
||||
%69 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %67, 0
|
||||
%70 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %69, ptr %68, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %70)
|
||||
@@ -995,7 +995,7 @@ _llgo_7: ; preds = %_llgo_5
|
||||
br i1 %76, label %_llgo_8, label %_llgo_9
|
||||
|
||||
_llgo_8: ; preds = %_llgo_7
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @24, i64 12 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintString"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @25, i64 12 })
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
br label %_llgo_9
|
||||
|
||||
@@ -1046,7 +1046,7 @@ _llgo_12: ; preds = %_llgo_14, %_llgo_9
|
||||
_llgo_13: ; preds = %_llgo_14, %_llgo_10
|
||||
%107 = load ptr, ptr @_llgo_string, align 8
|
||||
%108 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @25, i64 13 }, ptr %108, align 8
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @26, i64 13 }, ptr %108, align 8
|
||||
%109 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %107, 0
|
||||
%110 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %109, ptr %108, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %110)
|
||||
@@ -1207,43 +1207,50 @@ _llgo_13: ; preds = %_llgo_12
|
||||
br label %_llgo_14
|
||||
|
||||
_llgo_14: ; preds = %_llgo_13, %_llgo_12
|
||||
%72 = load ptr, ptr @"_llgo_func$ekGNsrYBSzltfAjxbl6T8H6Yq8j16wzqS3nDj2xxGMU", align 8
|
||||
%73 = load ptr, ptr @"_llgo_iface$VdBKYV8-gcMjZtZfcf-u2oKoj9Lu3VXwuG8TGCW2S4A", align 8
|
||||
%72 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 41 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @12, i64 1 })
|
||||
%73 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/reflect.I", align 8
|
||||
%74 = icmp eq ptr %73, null
|
||||
br i1 %74, label %_llgo_15, label %_llgo_16
|
||||
|
||||
_llgo_15: ; preds = %_llgo_14
|
||||
%75 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @11, i64 3 }, ptr undef }, ptr %72, 1
|
||||
%76 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%77 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %76, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %75, ptr %77, align 8
|
||||
%78 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %76, 0
|
||||
%79 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %78, i64 1, 1
|
||||
%80 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %79, i64 1, 2
|
||||
%81 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 41 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %80)
|
||||
store ptr %81, ptr @"_llgo_iface$VdBKYV8-gcMjZtZfcf-u2oKoj9Lu3VXwuG8TGCW2S4A", align 8
|
||||
store ptr %72, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/reflect.I", align 8
|
||||
br label %_llgo_16
|
||||
|
||||
_llgo_16: ; preds = %_llgo_15, %_llgo_14
|
||||
%82 = load ptr, ptr @_llgo_any, align 8
|
||||
%83 = icmp eq ptr %82, null
|
||||
br i1 %83, label %_llgo_17, label %_llgo_18
|
||||
%75 = load ptr, ptr @"_llgo_func$ekGNsrYBSzltfAjxbl6T8H6Yq8j16wzqS3nDj2xxGMU", align 8
|
||||
br i1 %74, label %_llgo_17, label %_llgo_18
|
||||
|
||||
_llgo_17: ; preds = %_llgo_16
|
||||
%76 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @11, i64 3 }, ptr undef }, ptr %75, 1
|
||||
%77 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%78 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %77, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %76, ptr %78, align 8
|
||||
%79 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %77, 0
|
||||
%80 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %79, i64 1, 1
|
||||
%81 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %80, i64 1, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr %72, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %81)
|
||||
br label %_llgo_18
|
||||
|
||||
_llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||
%82 = load ptr, ptr @_llgo_any, align 8
|
||||
%83 = icmp eq ptr %82, null
|
||||
br i1 %83, label %_llgo_19, label %_llgo_20
|
||||
|
||||
_llgo_19: ; preds = %_llgo_18
|
||||
%84 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
%85 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %84, 0
|
||||
%86 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %85, i64 0, 1
|
||||
%87 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %86, i64 0, 2
|
||||
%88 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 41 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %87)
|
||||
store ptr %88, ptr @_llgo_any, align 8
|
||||
br label %_llgo_18
|
||||
br label %_llgo_20
|
||||
|
||||
_llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||
_llgo_20: ; preds = %_llgo_19, %_llgo_18
|
||||
%89 = load ptr, ptr @"[]_llgo_any", align 8
|
||||
%90 = icmp eq ptr %89, null
|
||||
br i1 %90, label %_llgo_19, label %_llgo_20
|
||||
br i1 %90, label %_llgo_21, label %_llgo_22
|
||||
|
||||
_llgo_19: ; preds = %_llgo_18
|
||||
_llgo_21: ; preds = %_llgo_20
|
||||
%91 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
%92 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %91, 0
|
||||
%93 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %92, i64 0, 1
|
||||
@@ -1251,14 +1258,14 @@ _llgo_19: ; preds = %_llgo_18
|
||||
%95 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 41 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %94)
|
||||
%96 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.SliceOf"(ptr %95)
|
||||
store ptr %96, ptr @"[]_llgo_any", align 8
|
||||
br label %_llgo_20
|
||||
br label %_llgo_22
|
||||
|
||||
_llgo_20: ; preds = %_llgo_19, %_llgo_18
|
||||
_llgo_22: ; preds = %_llgo_21, %_llgo_20
|
||||
%97 = load ptr, ptr @"_llgo_func$KK0iU4Wpi3BdRqssvycXqtgNe2Dq1riBlM61Rds1QsU", align 8
|
||||
%98 = icmp eq ptr %97, null
|
||||
br i1 %98, label %_llgo_21, label %_llgo_22
|
||||
br i1 %98, label %_llgo_23, label %_llgo_24
|
||||
|
||||
_llgo_21: ; preds = %_llgo_20
|
||||
_llgo_23: ; preds = %_llgo_22
|
||||
%99 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||
%100 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||
%101 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||
@@ -1311,9 +1318,9 @@ _llgo_21: ; preds = %_llgo_20
|
||||
%136 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %127, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %135, i1 true)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %136)
|
||||
store ptr %136, ptr @"_llgo_func$KK0iU4Wpi3BdRqssvycXqtgNe2Dq1riBlM61Rds1QsU", align 8
|
||||
br label %_llgo_22
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_22: ; preds = %_llgo_21, %_llgo_20
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
%137 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||
%138 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||
%139 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||
@@ -1379,22 +1386,22 @@ _llgo_22: ; preds = %_llgo_21, %_llgo_20
|
||||
store ptr %184, ptr @"github.com/goplus/llgo/cl/_testgo/reflect.struct$FjMjjQr3-2iTiWyZP1IIQFOz0hUCa0OS6pEm5uVV6Pk", align 8
|
||||
%185 = load ptr, ptr @"map[_llgo_int]_llgo_string", align 8
|
||||
%186 = icmp eq ptr %185, null
|
||||
br i1 %186, label %_llgo_23, label %_llgo_24
|
||||
br i1 %186, label %_llgo_25, label %_llgo_26
|
||||
|
||||
_llgo_23: ; preds = %_llgo_22
|
||||
_llgo_25: ; preds = %_llgo_24
|
||||
%187 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||
%188 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 24)
|
||||
%189 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 40)
|
||||
%190 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.ArrayOf"(i64 8, ptr %189)
|
||||
%191 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @16, i64 7 }, ptr %190, i64 0, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||
%191 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @17, i64 7 }, ptr %190, i64 0, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||
%192 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 34)
|
||||
%193 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.ArrayOf"(i64 8, ptr %192)
|
||||
%194 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @17, i64 4 }, ptr %193, i64 8, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||
%194 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @18, i64 4 }, ptr %193, i64 8, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||
%195 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 24)
|
||||
%196 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.ArrayOf"(i64 8, ptr %195)
|
||||
%197 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @18, i64 5 }, ptr %196, i64 72, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||
%197 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @19, i64 5 }, ptr %196, i64 72, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||
%198 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 58)
|
||||
%199 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @19, i64 8 }, ptr %198, i64 200, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||
%199 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @20, i64 8 }, ptr %198, i64 200, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||
%200 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 224)
|
||||
%201 = getelementptr %"github.com/goplus/llgo/runtime/abi.StructField", ptr %200, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.StructField" %191, ptr %201, align 8
|
||||
@@ -1411,9 +1418,9 @@ _llgo_23: ; preds = %_llgo_22
|
||||
%209 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.MapOf"(ptr %187, ptr %188, ptr %208, i64 4)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %209)
|
||||
store ptr %209, ptr @"map[_llgo_int]_llgo_string", align 8
|
||||
br label %_llgo_24
|
||||
br label %_llgo_26
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
_llgo_26: ; preds = %_llgo_25, %_llgo_24
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -1459,7 +1466,9 @@ declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr, p
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.PointerTo"(ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr, ptr)
|
||||
|
||||
@@ -1473,6 +1482,8 @@ _llgo_0:
|
||||
ret { i64, i64 } %11
|
||||
}
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.SliceOf"(ptr)
|
||||
|
||||
declare %"github.com/goplus/llgo/runtime/internal/runtime.Slice" @reflect.Value.CallSlice(%reflect.Value, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package dep
|
||||
|
||||
import "fmt"
|
||||
|
||||
var VarName = "dep-default"
|
||||
var VarPlain string
|
||||
|
||||
func PrintVar() {
|
||||
fmt.Printf("dep.VarName: %s\n", VarName)
|
||||
fmt.Printf("dep.VarPlain: %s\n", VarPlain)
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
dep "github.com/goplus/llgo/cl/_testgo/rewrite/dep"
|
||||
)
|
||||
|
||||
var VarName = "main-default"
|
||||
var VarPlain string
|
||||
|
||||
func printLine(label, value string) {
|
||||
fmt.Printf("%s: %s\n", label, value)
|
||||
}
|
||||
|
||||
func main() {
|
||||
printLine("main.VarName", VarName)
|
||||
printLine("main.VarPlain", VarPlain)
|
||||
dep.PrintVar()
|
||||
printLine("runtime.GOROOT()", runtime.GOROOT())
|
||||
printLine("runtime.Version()", runtime.Version())
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
;
|
||||
@@ -23,18 +23,19 @@ source_filename = "github.com/goplus/llgo/cl/_testgo/tpinst"
|
||||
@4 = private unnamed_addr constant [5 x i8] c"value", align 1
|
||||
@5 = private unnamed_addr constant [46 x i8] c"github.com/goplus/llgo/cl/_testgo/tpinst.value", align 1
|
||||
@"*_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[int]" = linkonce global ptr null, align 8
|
||||
@"_llgo_iface$Jvxc0PCI_drlfK7S5npMGdZkQLeRkQ_x2e2CifPE6w8" = linkonce global ptr null, align 8
|
||||
@6 = private unnamed_addr constant [5 x i8] c"error", align 1
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.I[int]" = linkonce global ptr null, align 8
|
||||
@6 = private unnamed_addr constant [1 x i8] c"I", align 1
|
||||
@7 = private unnamed_addr constant [5 x i8] c"error", align 1
|
||||
@_llgo_string = linkonce global ptr null, align 8
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]" = linkonce global ptr null, align 8
|
||||
@7 = private unnamed_addr constant [10 x i8] c"M[float64]", align 1
|
||||
@8 = private unnamed_addr constant [10 x i8] c"M[float64]", align 1
|
||||
@_llgo_float64 = linkonce global ptr null, align 8
|
||||
@"github.com/goplus/llgo/cl/_testgo/tpinst.struct$7SZ-TjG6e68olyGxlMRRIOYuZz2LaKIpOrZH-w4GiTU" = linkonce global ptr null, align 8
|
||||
@"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8" = linkonce global ptr null, align 8
|
||||
@"*_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]" = linkonce global ptr null, align 8
|
||||
@"_llgo_iface$2dxw6yZ6V86Spb7J0dTDIoWqg7ba7UDXlAlpJv3-HLk" = linkonce global ptr null, align 8
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.I[float64]" = linkonce global ptr null, align 8
|
||||
@"github.com/goplus/llgo/cl/_testgo/tpinst.iface$2sV9fFeqOv1SzesvwIdhTqCFzDT8ZX5buKUSAoHNSww" = linkonce global ptr null, align 8
|
||||
@8 = private unnamed_addr constant [95 x i8] c"type assertion github.com/goplus/llgo/cl/_testgo/tpinst.I[int] -> interface{value() int} failed", align 1
|
||||
@9 = private unnamed_addr constant [95 x i8] c"type assertion github.com/goplus/llgo/cl/_testgo/tpinst.I[int] -> interface{value() int} failed", align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testgo/tpinst.demo"() {
|
||||
_llgo_0:
|
||||
@@ -43,108 +44,106 @@ _llgo_0:
|
||||
store i64 100, ptr %1, align 4
|
||||
%2 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[int]", align 8
|
||||
%3 = load ptr, ptr @"*_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[int]", align 8
|
||||
%4 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
%5 = load ptr, ptr @"_llgo_iface$Jvxc0PCI_drlfK7S5npMGdZkQLeRkQ_x2e2CifPE6w8", align 8
|
||||
%6 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %5, ptr %3)
|
||||
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %6, 0
|
||||
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %7, ptr %0, 1
|
||||
%9 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %8)
|
||||
%10 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %8, 0
|
||||
%11 = getelementptr ptr, ptr %10, i64 3
|
||||
%12 = load ptr, ptr %11, align 8
|
||||
%13 = insertvalue { ptr, ptr } undef, ptr %12, 0
|
||||
%14 = insertvalue { ptr, ptr } %13, ptr %9, 1
|
||||
%15 = extractvalue { ptr, ptr } %14, 1
|
||||
%16 = extractvalue { ptr, ptr } %14, 0
|
||||
%17 = call i64 %16(ptr %15)
|
||||
%18 = icmp ne i64 %17, 100
|
||||
br i1 %18, label %_llgo_1, label %_llgo_2
|
||||
%4 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.I[int]", align 8
|
||||
%5 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %4, ptr %3)
|
||||
%6 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %5, 0
|
||||
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %6, ptr %0, 1
|
||||
%8 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %7)
|
||||
%9 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %7, 0
|
||||
%10 = getelementptr ptr, ptr %9, i64 3
|
||||
%11 = load ptr, ptr %10, align 8
|
||||
%12 = insertvalue { ptr, ptr } undef, ptr %11, 0
|
||||
%13 = insertvalue { ptr, ptr } %12, ptr %8, 1
|
||||
%14 = extractvalue { ptr, ptr } %13, 1
|
||||
%15 = extractvalue { ptr, ptr } %13, 0
|
||||
%16 = call i64 %15(ptr %14)
|
||||
%17 = icmp ne i64 %16, 100
|
||||
br i1 %17, label %_llgo_1, label %_llgo_2
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
%19 = load ptr, ptr @_llgo_string, align 8
|
||||
%20 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 5 }, ptr %20, align 8
|
||||
%21 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %19, 0
|
||||
%22 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %21, ptr %20, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %22)
|
||||
%18 = load ptr, ptr @_llgo_string, align 8
|
||||
%19 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 5 }, ptr %19, align 8
|
||||
%20 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %18, 0
|
||||
%21 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %20, ptr %19, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %21)
|
||||
unreachable
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
%23 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 8)
|
||||
%24 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", ptr %23, i32 0, i32 0
|
||||
store double 1.001000e+02, ptr %24, align 8
|
||||
%25 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", align 8
|
||||
%26 = load ptr, ptr @"*_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", align 8
|
||||
%27 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||
%28 = load ptr, ptr @"_llgo_iface$2dxw6yZ6V86Spb7J0dTDIoWqg7ba7UDXlAlpJv3-HLk", align 8
|
||||
%29 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %28, ptr %26)
|
||||
%30 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %29, 0
|
||||
%31 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %30, ptr %23, 1
|
||||
%32 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %31)
|
||||
%33 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %31, 0
|
||||
%34 = getelementptr ptr, ptr %33, i64 3
|
||||
%35 = load ptr, ptr %34, align 8
|
||||
%36 = insertvalue { ptr, ptr } undef, ptr %35, 0
|
||||
%37 = insertvalue { ptr, ptr } %36, ptr %32, 1
|
||||
%38 = extractvalue { ptr, ptr } %37, 1
|
||||
%39 = extractvalue { ptr, ptr } %37, 0
|
||||
%40 = call double %39(ptr %38)
|
||||
%41 = fcmp une double %40, 1.001000e+02
|
||||
br i1 %41, label %_llgo_3, label %_llgo_4
|
||||
%22 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 8)
|
||||
%23 = getelementptr inbounds %"github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", ptr %22, i32 0, i32 0
|
||||
store double 1.001000e+02, ptr %23, align 8
|
||||
%24 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", align 8
|
||||
%25 = load ptr, ptr @"*_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", align 8
|
||||
%26 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.I[float64]", align 8
|
||||
%27 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %26, ptr %25)
|
||||
%28 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %27, 0
|
||||
%29 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %28, ptr %22, 1
|
||||
%30 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %29)
|
||||
%31 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %29, 0
|
||||
%32 = getelementptr ptr, ptr %31, i64 3
|
||||
%33 = load ptr, ptr %32, align 8
|
||||
%34 = insertvalue { ptr, ptr } undef, ptr %33, 0
|
||||
%35 = insertvalue { ptr, ptr } %34, ptr %30, 1
|
||||
%36 = extractvalue { ptr, ptr } %35, 1
|
||||
%37 = extractvalue { ptr, ptr } %35, 0
|
||||
%38 = call double %37(ptr %36)
|
||||
%39 = fcmp une double %38, 1.001000e+02
|
||||
br i1 %39, label %_llgo_3, label %_llgo_4
|
||||
|
||||
_llgo_3: ; preds = %_llgo_2
|
||||
%42 = load ptr, ptr @_llgo_string, align 8
|
||||
%43 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 5 }, ptr %43, align 8
|
||||
%44 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %42, 0
|
||||
%45 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %44, ptr %43, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %45)
|
||||
%40 = load ptr, ptr @_llgo_string, align 8
|
||||
%41 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 5 }, ptr %41, align 8
|
||||
%42 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %40, 0
|
||||
%43 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %42, ptr %41, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %43)
|
||||
unreachable
|
||||
|
||||
_llgo_4: ; preds = %_llgo_2
|
||||
%46 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %8)
|
||||
%47 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
%48 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/tpinst.iface$2sV9fFeqOv1SzesvwIdhTqCFzDT8ZX5buKUSAoHNSww", align 8
|
||||
%49 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.Implements"(ptr %48, ptr %46)
|
||||
br i1 %49, label %_llgo_7, label %_llgo_8
|
||||
%44 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %7)
|
||||
%45 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
%46 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/tpinst.iface$2sV9fFeqOv1SzesvwIdhTqCFzDT8ZX5buKUSAoHNSww", align 8
|
||||
%47 = call i1 @"github.com/goplus/llgo/runtime/internal/runtime.Implements"(ptr %46, ptr %44)
|
||||
br i1 %47, label %_llgo_7, label %_llgo_8
|
||||
|
||||
_llgo_5: ; preds = %_llgo_7
|
||||
%50 = load ptr, ptr @_llgo_string, align 8
|
||||
%51 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 5 }, ptr %51, align 8
|
||||
%52 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %50, 0
|
||||
%53 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %52, ptr %51, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %53)
|
||||
%48 = load ptr, ptr @_llgo_string, align 8
|
||||
%49 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 5 }, ptr %49, align 8
|
||||
%50 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %48, 0
|
||||
%51 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %50, ptr %49, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %51)
|
||||
unreachable
|
||||
|
||||
_llgo_6: ; preds = %_llgo_7
|
||||
ret void
|
||||
|
||||
_llgo_7: ; preds = %_llgo_4
|
||||
%54 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %8, 1
|
||||
%55 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/tpinst.iface$2sV9fFeqOv1SzesvwIdhTqCFzDT8ZX5buKUSAoHNSww", align 8
|
||||
%56 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %55, ptr %46)
|
||||
%57 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %56, 0
|
||||
%58 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %57, ptr %54, 1
|
||||
%59 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %58)
|
||||
%60 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %58, 0
|
||||
%61 = getelementptr ptr, ptr %60, i64 3
|
||||
%62 = load ptr, ptr %61, align 8
|
||||
%63 = insertvalue { ptr, ptr } undef, ptr %62, 0
|
||||
%64 = insertvalue { ptr, ptr } %63, ptr %59, 1
|
||||
%65 = extractvalue { ptr, ptr } %64, 1
|
||||
%66 = extractvalue { ptr, ptr } %64, 0
|
||||
%67 = call i64 %66(ptr %65)
|
||||
%68 = icmp ne i64 %67, 100
|
||||
br i1 %68, label %_llgo_5, label %_llgo_6
|
||||
%52 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %7, 1
|
||||
%53 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/tpinst.iface$2sV9fFeqOv1SzesvwIdhTqCFzDT8ZX5buKUSAoHNSww", align 8
|
||||
%54 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %53, ptr %44)
|
||||
%55 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %54, 0
|
||||
%56 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %55, ptr %52, 1
|
||||
%57 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %56)
|
||||
%58 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %56, 0
|
||||
%59 = getelementptr ptr, ptr %58, i64 3
|
||||
%60 = load ptr, ptr %59, align 8
|
||||
%61 = insertvalue { ptr, ptr } undef, ptr %60, 0
|
||||
%62 = insertvalue { ptr, ptr } %61, ptr %57, 1
|
||||
%63 = extractvalue { ptr, ptr } %62, 1
|
||||
%64 = extractvalue { ptr, ptr } %62, 0
|
||||
%65 = call i64 %64(ptr %63)
|
||||
%66 = icmp ne i64 %65, 100
|
||||
br i1 %66, label %_llgo_5, label %_llgo_6
|
||||
|
||||
_llgo_8: ; preds = %_llgo_4
|
||||
%69 = load ptr, ptr @_llgo_string, align 8
|
||||
%70 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @8, i64 95 }, ptr %70, align 8
|
||||
%71 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %69, 0
|
||||
%72 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %71, ptr %70, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %72)
|
||||
%67 = load ptr, ptr @_llgo_string, align 8
|
||||
%68 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @9, i64 95 }, ptr %68, align 8
|
||||
%69 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %67, 0
|
||||
%70 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %69, ptr %68, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %70)
|
||||
unreachable
|
||||
}
|
||||
|
||||
@@ -289,54 +288,61 @@ _llgo_9: ; preds = %_llgo_6
|
||||
br label %_llgo_10
|
||||
|
||||
_llgo_10: ; preds = %_llgo_9, %_llgo_6
|
||||
%47 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
%48 = load ptr, ptr @"_llgo_iface$Jvxc0PCI_drlfK7S5npMGdZkQLeRkQ_x2e2CifPE6w8", align 8
|
||||
%47 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 40 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 1 })
|
||||
%48 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.I[int]", align 8
|
||||
%49 = icmp eq ptr %48, null
|
||||
br i1 %49, label %_llgo_11, label %_llgo_12
|
||||
|
||||
_llgo_11: ; preds = %_llgo_10
|
||||
%50 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 5 }, ptr undef }, ptr %47, 1
|
||||
%51 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%52 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %51, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %50, ptr %52, align 8
|
||||
%53 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %51, 0
|
||||
%54 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %53, i64 1, 1
|
||||
%55 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %54, i64 1, 2
|
||||
%56 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 40 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %55)
|
||||
store ptr %56, ptr @"_llgo_iface$Jvxc0PCI_drlfK7S5npMGdZkQLeRkQ_x2e2CifPE6w8", align 8
|
||||
store ptr %47, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.I[int]", align 8
|
||||
br label %_llgo_12
|
||||
|
||||
_llgo_12: ; preds = %_llgo_11, %_llgo_10
|
||||
%57 = load ptr, ptr @_llgo_string, align 8
|
||||
%58 = icmp eq ptr %57, null
|
||||
br i1 %58, label %_llgo_13, label %_llgo_14
|
||||
%50 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
br i1 %49, label %_llgo_13, label %_llgo_14
|
||||
|
||||
_llgo_13: ; preds = %_llgo_12
|
||||
%59 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 24)
|
||||
store ptr %59, ptr @_llgo_string, align 8
|
||||
%51 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 5 }, ptr undef }, ptr %50, 1
|
||||
%52 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%53 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %52, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %51, ptr %53, align 8
|
||||
%54 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %52, 0
|
||||
%55 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %54, i64 1, 1
|
||||
%56 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %55, i64 1, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr %47, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %56)
|
||||
br label %_llgo_14
|
||||
|
||||
_llgo_14: ; preds = %_llgo_13, %_llgo_12
|
||||
%60 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 40 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 10 }, i64 25, i64 8, i64 0, i64 2)
|
||||
%61 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", align 8
|
||||
%62 = icmp eq ptr %61, null
|
||||
br i1 %62, label %_llgo_15, label %_llgo_16
|
||||
%57 = load ptr, ptr @_llgo_string, align 8
|
||||
%58 = icmp eq ptr %57, null
|
||||
br i1 %58, label %_llgo_15, label %_llgo_16
|
||||
|
||||
_llgo_15: ; preds = %_llgo_14
|
||||
store ptr %60, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", align 8
|
||||
%59 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 24)
|
||||
store ptr %59, ptr @_llgo_string, align 8
|
||||
br label %_llgo_16
|
||||
|
||||
_llgo_16: ; preds = %_llgo_15, %_llgo_14
|
||||
%63 = load ptr, ptr @_llgo_float64, align 8
|
||||
%64 = icmp eq ptr %63, null
|
||||
br i1 %64, label %_llgo_17, label %_llgo_18
|
||||
%60 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 40 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @8, i64 10 }, i64 25, i64 8, i64 0, i64 2)
|
||||
%61 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", align 8
|
||||
%62 = icmp eq ptr %61, null
|
||||
br i1 %62, label %_llgo_17, label %_llgo_18
|
||||
|
||||
_llgo_17: ; preds = %_llgo_16
|
||||
%65 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 46)
|
||||
store ptr %65, ptr @_llgo_float64, align 8
|
||||
store ptr %60, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", align 8
|
||||
br label %_llgo_18
|
||||
|
||||
_llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||
%63 = load ptr, ptr @_llgo_float64, align 8
|
||||
%64 = icmp eq ptr %63, null
|
||||
br i1 %64, label %_llgo_19, label %_llgo_20
|
||||
|
||||
_llgo_19: ; preds = %_llgo_18
|
||||
%65 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 46)
|
||||
store ptr %65, ptr @_llgo_float64, align 8
|
||||
br label %_llgo_20
|
||||
|
||||
_llgo_20: ; preds = %_llgo_19, %_llgo_18
|
||||
%66 = load ptr, ptr @_llgo_float64, align 8
|
||||
%67 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 46)
|
||||
%68 = call %"github.com/goplus/llgo/runtime/abi.StructField" @"github.com/goplus/llgo/runtime/internal/runtime.StructField"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @2, i64 1 }, ptr %67, i64 0, %"github.com/goplus/llgo/runtime/internal/runtime.String" zeroinitializer, i1 false)
|
||||
@@ -349,20 +355,20 @@ _llgo_18: ; preds = %_llgo_17, %_llgo_16
|
||||
%74 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Struct"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 40 }, i64 8, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %73)
|
||||
store ptr %74, ptr @"github.com/goplus/llgo/cl/_testgo/tpinst.struct$7SZ-TjG6e68olyGxlMRRIOYuZz2LaKIpOrZH-w4GiTU", align 8
|
||||
%75 = load ptr, ptr @"github.com/goplus/llgo/cl/_testgo/tpinst.struct$7SZ-TjG6e68olyGxlMRRIOYuZz2LaKIpOrZH-w4GiTU", align 8
|
||||
br i1 %62, label %_llgo_19, label %_llgo_20
|
||||
br i1 %62, label %_llgo_21, label %_llgo_22
|
||||
|
||||
_llgo_19: ; preds = %_llgo_18
|
||||
_llgo_21: ; preds = %_llgo_20
|
||||
%76 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||
%77 = icmp eq ptr %76, null
|
||||
br i1 %77, label %_llgo_21, label %_llgo_22
|
||||
br i1 %77, label %_llgo_23, label %_llgo_24
|
||||
|
||||
_llgo_20: ; preds = %_llgo_22, %_llgo_18
|
||||
%78 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 40 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 10 }, i64 25, i64 8, i64 0, i64 2)
|
||||
_llgo_22: ; preds = %_llgo_24, %_llgo_20
|
||||
%78 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamed"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 40 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @8, i64 10 }, i64 25, i64 8, i64 0, i64 2)
|
||||
%79 = load ptr, ptr @"*_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", align 8
|
||||
%80 = icmp eq ptr %79, null
|
||||
br i1 %80, label %_llgo_23, label %_llgo_24
|
||||
br i1 %80, label %_llgo_25, label %_llgo_26
|
||||
|
||||
_llgo_21: ; preds = %_llgo_19
|
||||
_llgo_23: ; preds = %_llgo_21
|
||||
%81 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 0)
|
||||
%82 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %81, 0
|
||||
%83 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %82, i64 0, 1
|
||||
@@ -377,9 +383,9 @@ _llgo_21: ; preds = %_llgo_19
|
||||
%91 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Func"(%"github.com/goplus/llgo/runtime/internal/runtime.Slice" %84, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %90, i1 false)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %91)
|
||||
store ptr %91, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||
br label %_llgo_22
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_22: ; preds = %_llgo_21, %_llgo_19
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_21
|
||||
%92 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||
%93 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 5 }, ptr undef, ptr undef, ptr undef }, ptr %92, 1
|
||||
%94 = insertvalue %"github.com/goplus/llgo/runtime/abi.Method" %93, ptr @"github.com/goplus/llgo/cl/_testgo/tpinst.(*M[float64]).Value", 2
|
||||
@@ -397,33 +403,40 @@ _llgo_22: ; preds = %_llgo_21, %_llgo_19
|
||||
%104 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %103, i64 2, 1
|
||||
%105 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %104, i64 2, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr %60, ptr %75, { ptr, i64, i64 } zeroinitializer, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %105)
|
||||
br label %_llgo_20
|
||||
br label %_llgo_22
|
||||
|
||||
_llgo_23: ; preds = %_llgo_20
|
||||
_llgo_25: ; preds = %_llgo_22
|
||||
%106 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.PointerTo"(ptr %78)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %106)
|
||||
store ptr %106, ptr @"*_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.M[float64]", align 8
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_20
|
||||
%107 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||
%108 = load ptr, ptr @"_llgo_iface$2dxw6yZ6V86Spb7J0dTDIoWqg7ba7UDXlAlpJv3-HLk", align 8
|
||||
%109 = icmp eq ptr %108, null
|
||||
br i1 %109, label %_llgo_25, label %_llgo_26
|
||||
|
||||
_llgo_25: ; preds = %_llgo_24
|
||||
%110 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 5 }, ptr undef }, ptr %107, 1
|
||||
%111 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%112 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %111, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %110, ptr %112, align 8
|
||||
%113 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %111, 0
|
||||
%114 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %113, i64 1, 1
|
||||
%115 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %114, i64 1, 2
|
||||
%116 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 40 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %115)
|
||||
store ptr %116, ptr @"_llgo_iface$2dxw6yZ6V86Spb7J0dTDIoWqg7ba7UDXlAlpJv3-HLk", align 8
|
||||
br label %_llgo_26
|
||||
|
||||
_llgo_26: ; preds = %_llgo_25, %_llgo_24
|
||||
_llgo_26: ; preds = %_llgo_25, %_llgo_22
|
||||
%107 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @0, i64 40 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @6, i64 1 })
|
||||
%108 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.I[float64]", align 8
|
||||
%109 = icmp eq ptr %108, null
|
||||
br i1 %109, label %_llgo_27, label %_llgo_28
|
||||
|
||||
_llgo_27: ; preds = %_llgo_26
|
||||
store ptr %107, ptr @"_llgo_github.com/goplus/llgo/cl/_testgo/tpinst.I[float64]", align 8
|
||||
br label %_llgo_28
|
||||
|
||||
_llgo_28: ; preds = %_llgo_27, %_llgo_26
|
||||
%110 = load ptr, ptr @"_llgo_func$UYiLlmcWxoOKZPPzvR4LByitNeKoVGoTrB_5ubdOWW8", align 8
|
||||
br i1 %109, label %_llgo_29, label %_llgo_30
|
||||
|
||||
_llgo_29: ; preds = %_llgo_28
|
||||
%111 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @3, i64 5 }, ptr undef }, ptr %110, 1
|
||||
%112 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%113 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %112, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %111, ptr %113, align 8
|
||||
%114 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %112, 0
|
||||
%115 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %114, i64 1, 1
|
||||
%116 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %115, i64 1, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr %107, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %116)
|
||||
br label %_llgo_30
|
||||
|
||||
_llgo_30: ; preds = %_llgo_29, %_llgo_28
|
||||
%117 = load ptr, ptr @"_llgo_func$ETeB8WwW04JEq0ztcm-XPTJtuYvtpkjIsAc0-2NT9zA", align 8
|
||||
%118 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 46 }, ptr undef }, ptr %117, 1
|
||||
%119 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
@@ -455,7 +468,9 @@ declare void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(p
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.PointerTo"(ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr, ptr)
|
||||
|
||||
@@ -465,4 +480,6 @@ declare void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.c
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfaceType"(%"github.com/goplus/llgo/runtime/internal/runtime.iface")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare i1 @"github.com/goplus/llgo/runtime/internal/runtime.Implements"(ptr, ptr)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
//go:linkname getsp llgo.stackSave
|
||||
func getsp() unsafe.Pointer
|
||||
|
||||
func main() {
|
||||
sp := getsp()
|
||||
println(sp)
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
; ModuleID = 'github.com/goplus/llgo/cl/_testrt/stacksave'
|
||||
source_filename = "github.com/goplus/llgo/cl/_testrt/stacksave"
|
||||
|
||||
@"github.com/goplus/llgo/cl/_testrt/stacksave.init$guard" = global i1 false, align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testrt/stacksave.init"() {
|
||||
_llgo_0:
|
||||
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testrt/stacksave.init$guard", align 1
|
||||
br i1 %0, label %_llgo_2, label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_0
|
||||
store i1 true, ptr @"github.com/goplus/llgo/cl/_testrt/stacksave.init$guard", align 1
|
||||
br label %_llgo_2
|
||||
|
||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testrt/stacksave.main"() {
|
||||
_llgo_0:
|
||||
%0 = call ptr @llvm.stacksave()
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintPointer"(ptr %0)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Function Attrs: nocallback nofree nosync nounwind willreturn
|
||||
declare ptr @llvm.stacksave() #0
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintPointer"(ptr)
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8)
|
||||
|
||||
attributes #0 = { nocallback nofree nosync nounwind willreturn }
|
||||
@@ -26,7 +26,8 @@ source_filename = "github.com/goplus/llgo/cl/_testrt/tpabi"
|
||||
@7 = private unnamed_addr constant [83 x i8] c"type assertion any -> github.com/goplus/llgo/cl/_testrt/tpabi.T[string, int] failed", align 1
|
||||
@8 = private unnamed_addr constant [5 x i8] c"hello", align 1
|
||||
@"*_llgo_github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]" = linkonce global ptr null, align 8
|
||||
@"_llgo_iface$BP0p_lUsEd-IbbtJVukGmgrdQkqzcoYzSiwgUvgFvUs" = linkonce global ptr null, align 8
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testrt/tpabi.I" = linkonce global ptr null, align 8
|
||||
@9 = private unnamed_addr constant [1 x i8] c"I", align 1
|
||||
|
||||
define void @"github.com/goplus/llgo/cl/_testrt/tpabi.init"() {
|
||||
_llgo_0:
|
||||
@@ -73,44 +74,43 @@ _llgo_1: ; preds = %_llgo_0
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @8, i64 5 }, ptr %15, align 8
|
||||
store i64 100, ptr %16, align 4
|
||||
%17 = load ptr, ptr @"*_llgo_github.com/goplus/llgo/cl/_testrt/tpabi.T[string,int]", align 8
|
||||
%18 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%19 = load ptr, ptr @"_llgo_iface$BP0p_lUsEd-IbbtJVukGmgrdQkqzcoYzSiwgUvgFvUs", align 8
|
||||
%20 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %19, ptr %17)
|
||||
%21 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %20, 0
|
||||
%22 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %21, ptr %14, 1
|
||||
%23 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %22)
|
||||
%24 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %22, 0
|
||||
%25 = getelementptr ptr, ptr %24, i64 3
|
||||
%26 = load ptr, ptr %25, align 8
|
||||
%27 = insertvalue { ptr, ptr } undef, ptr %26, 0
|
||||
%28 = insertvalue { ptr, ptr } %27, ptr %23, 1
|
||||
%29 = extractvalue { ptr, ptr } %28, 1
|
||||
%30 = extractvalue { ptr, ptr } %28, 0
|
||||
call void %30(ptr %29)
|
||||
%31 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 32)
|
||||
%32 = getelementptr inbounds i64, ptr %31, i64 0
|
||||
%33 = getelementptr inbounds i64, ptr %31, i64 1
|
||||
%34 = getelementptr inbounds i64, ptr %31, i64 2
|
||||
%35 = getelementptr inbounds i64, ptr %31, i64 3
|
||||
store i64 1, ptr %32, align 4
|
||||
store i64 2, ptr %33, align 4
|
||||
store i64 3, ptr %34, align 4
|
||||
store i64 4, ptr %35, align 4
|
||||
%36 = getelementptr [4 x i64], ptr %31, i64 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintPointer"(ptr %36)
|
||||
%18 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testrt/tpabi.I", align 8
|
||||
%19 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %18, ptr %17)
|
||||
%20 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %19, 0
|
||||
%21 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %20, ptr %14, 1
|
||||
%22 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.IfacePtrData"(%"github.com/goplus/llgo/runtime/internal/runtime.iface" %21)
|
||||
%23 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %21, 0
|
||||
%24 = getelementptr ptr, ptr %23, i64 3
|
||||
%25 = load ptr, ptr %24, align 8
|
||||
%26 = insertvalue { ptr, ptr } undef, ptr %25, 0
|
||||
%27 = insertvalue { ptr, ptr } %26, ptr %22, 1
|
||||
%28 = extractvalue { ptr, ptr } %27, 1
|
||||
%29 = extractvalue { ptr, ptr } %27, 0
|
||||
call void %29(ptr %28)
|
||||
%30 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64 32)
|
||||
%31 = getelementptr inbounds i64, ptr %30, i64 0
|
||||
%32 = getelementptr inbounds i64, ptr %30, i64 1
|
||||
%33 = getelementptr inbounds i64, ptr %30, i64 2
|
||||
%34 = getelementptr inbounds i64, ptr %30, i64 3
|
||||
store i64 1, ptr %31, align 4
|
||||
store i64 2, ptr %32, align 4
|
||||
store i64 3, ptr %33, align 4
|
||||
store i64 4, ptr %34, align 4
|
||||
%35 = getelementptr [4 x i64], ptr %30, i64 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintPointer"(ptr %35)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
%37 = getelementptr [4 x i64], ptr %31, i64 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintPointer"(ptr %37)
|
||||
%36 = getelementptr [4 x i64], ptr %30, i64 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintPointer"(ptr %36)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.PrintByte"(i8 10)
|
||||
ret void
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
%38 = load ptr, ptr @_llgo_string, align 8
|
||||
%39 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 83 }, ptr %39, align 8
|
||||
%40 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %38, 0
|
||||
%41 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %40, ptr %39, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %41)
|
||||
%37 = load ptr, ptr @_llgo_string, align 8
|
||||
%38 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 16)
|
||||
store %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 83 }, ptr %38, align 8
|
||||
%39 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" undef, ptr %37, 0
|
||||
%40 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %39, ptr %38, 1
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.Panic"(%"github.com/goplus/llgo/runtime/internal/runtime.eface" %40)
|
||||
unreachable
|
||||
}
|
||||
|
||||
@@ -265,24 +265,31 @@ _llgo_11: ; preds = %_llgo_8
|
||||
br label %_llgo_12
|
||||
|
||||
_llgo_12: ; preds = %_llgo_11, %_llgo_8
|
||||
%60 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
%61 = load ptr, ptr @"_llgo_iface$BP0p_lUsEd-IbbtJVukGmgrdQkqzcoYzSiwgUvgFvUs", align 8
|
||||
%60 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 39 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @9, i64 1 })
|
||||
%61 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testrt/tpabi.I", align 8
|
||||
%62 = icmp eq ptr %61, null
|
||||
br i1 %62, label %_llgo_13, label %_llgo_14
|
||||
|
||||
_llgo_13: ; preds = %_llgo_12
|
||||
%63 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 4 }, ptr undef }, ptr %60, 1
|
||||
%64 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%65 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %64, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %63, ptr %65, align 8
|
||||
%66 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %64, 0
|
||||
%67 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %66, i64 1, 1
|
||||
%68 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %67, i64 1, 2
|
||||
%69 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 39 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %68)
|
||||
store ptr %69, ptr @"_llgo_iface$BP0p_lUsEd-IbbtJVukGmgrdQkqzcoYzSiwgUvgFvUs", align 8
|
||||
store ptr %60, ptr @"_llgo_github.com/goplus/llgo/cl/_testrt/tpabi.I", align 8
|
||||
br label %_llgo_14
|
||||
|
||||
_llgo_14: ; preds = %_llgo_13, %_llgo_12
|
||||
%63 = load ptr, ptr @"_llgo_func$2_iS07vIlF2_rZqWB5eU0IvP_9HviM4MYZNkXZDvbac", align 8
|
||||
br i1 %62, label %_llgo_15, label %_llgo_16
|
||||
|
||||
_llgo_15: ; preds = %_llgo_14
|
||||
%64 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @5, i64 4 }, ptr undef }, ptr %63, 1
|
||||
%65 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%66 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %65, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %64, ptr %66, align 8
|
||||
%67 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %65, 0
|
||||
%68 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %67, i64 1, 1
|
||||
%69 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %68, i64 1, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr %60, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %69)
|
||||
br label %_llgo_16
|
||||
|
||||
_llgo_16: ; preds = %_llgo_15, %_llgo_14
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -312,7 +319,9 @@ declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocZ"(i64)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.PointerTo"(ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.String")
|
||||
|
||||
declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr, %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr, ptr)
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@ source_filename = "github.com/goplus/llgo/cl/_testrt/tpmethod"
|
||||
@10 = private unnamed_addr constant [2 x i8] c"fn", align 1
|
||||
@11 = private unnamed_addr constant [4 x i8] c"Then", align 1
|
||||
@"*_llgo_github.com/goplus/llgo/cl/_testrt/tpmethod.future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]" = linkonce global ptr null, align 8
|
||||
@"_llgo_iface$kSla6xFkiJD3PX1RdCGebCgULXloNxgSHKPEQsXsqos" = linkonce global ptr null, align 8
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testrt/tpmethod.Future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]" = linkonce global ptr null, align 8
|
||||
@12 = private unnamed_addr constant [6 x i8] c"Future", align 1
|
||||
|
||||
define %"github.com/goplus/llgo/runtime/internal/runtime.iface" @"github.com/goplus/llgo/cl/_testrt/tpmethod.ReadFile"(%"github.com/goplus/llgo/runtime/internal/runtime.String" %0) {
|
||||
_llgo_0:
|
||||
@@ -129,14 +130,11 @@ _llgo_0:
|
||||
store { ptr, ptr } %0, ptr %2, align 8
|
||||
%3 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testrt/tpmethod.future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]", align 8
|
||||
%4 = load ptr, ptr @"*_llgo_github.com/goplus/llgo/cl/_testrt/tpmethod.future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]", align 8
|
||||
%5 = load ptr, ptr @"_llgo_func$wp7b63sFyNWPTd8VyEOOosByqpZg5pKsGThGMOTpyvo", align 8
|
||||
%6 = load ptr, ptr @"github.com/goplus/llgo/cl/_testrt/tpmethod.struct$s_pTkk2q6m_bRjfPic11Z1ogmQ-VdSHpGxyzvfszwb8", align 8
|
||||
%7 = load ptr, ptr @"_llgo_func$pIyBXw4qkUL3JRjAVf_wwtiGz7b0evOvoFHlctBJd6o", align 8
|
||||
%8 = load ptr, ptr @"_llgo_iface$kSla6xFkiJD3PX1RdCGebCgULXloNxgSHKPEQsXsqos", align 8
|
||||
%9 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %8, ptr %4)
|
||||
%10 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %9, 0
|
||||
%11 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %10, ptr %1, 1
|
||||
ret %"github.com/goplus/llgo/runtime/internal/runtime.iface" %11
|
||||
%5 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testrt/tpmethod.Future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]", align 8
|
||||
%6 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %5, ptr %4)
|
||||
%7 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %6, 0
|
||||
%8 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %7, ptr %1, 1
|
||||
ret %"github.com/goplus/llgo/runtime/internal/runtime.iface" %8
|
||||
}
|
||||
|
||||
define linkonce void @"__llgo_stub.github.com/goplus/llgo/cl/_testrt/tpmethod.ReadFile$1"(ptr %0, { ptr, ptr } %1) {
|
||||
@@ -525,24 +523,33 @@ _llgo_20: ; preds = %_llgo_19, %_llgo_18
|
||||
%249 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.PointerTo"(ptr %248)
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.SetDirectIface"(ptr %249)
|
||||
store ptr %249, ptr @"*_llgo_github.com/goplus/llgo/cl/_testrt/tpmethod.future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]", align 8
|
||||
%250 = load ptr, ptr @"_llgo_func$pIyBXw4qkUL3JRjAVf_wwtiGz7b0evOvoFHlctBJd6o", align 8
|
||||
%251 = load ptr, ptr @"_llgo_iface$kSla6xFkiJD3PX1RdCGebCgULXloNxgSHKPEQsXsqos", align 8
|
||||
%250 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewNamedInterface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 42 }, %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @12, i64 6 })
|
||||
%251 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testrt/tpmethod.Future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]", align 8
|
||||
%252 = icmp eq ptr %251, null
|
||||
br i1 %252, label %_llgo_21, label %_llgo_22
|
||||
|
||||
_llgo_21: ; preds = %_llgo_20
|
||||
%253 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @11, i64 4 }, ptr undef }, ptr %250, 1
|
||||
%254 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%255 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %254, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %253, ptr %255, align 8
|
||||
%256 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %254, 0
|
||||
%257 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %256, i64 1, 1
|
||||
%258 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %257, i64 1, 2
|
||||
%259 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @1, i64 42 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %258)
|
||||
store ptr %259, ptr @"_llgo_iface$kSla6xFkiJD3PX1RdCGebCgULXloNxgSHKPEQsXsqos", align 8
|
||||
store ptr %250, ptr @"_llgo_github.com/goplus/llgo/cl/_testrt/tpmethod.Future[github.com/goplus/llgo/cl/_testrt/tpmethod.Tuple[error]]", align 8
|
||||
br label %_llgo_22
|
||||
|
||||
_llgo_22: ; preds = %_llgo_21, %_llgo_20
|
||||
%253 = load ptr, ptr @"_llgo_func$wp7b63sFyNWPTd8VyEOOosByqpZg5pKsGThGMOTpyvo", align 8
|
||||
%254 = load ptr, ptr @"github.com/goplus/llgo/cl/_testrt/tpmethod.struct$s_pTkk2q6m_bRjfPic11Z1ogmQ-VdSHpGxyzvfszwb8", align 8
|
||||
%255 = load ptr, ptr @"_llgo_func$pIyBXw4qkUL3JRjAVf_wwtiGz7b0evOvoFHlctBJd6o", align 8
|
||||
br i1 %252, label %_llgo_23, label %_llgo_24
|
||||
|
||||
_llgo_23: ; preds = %_llgo_22
|
||||
%256 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @11, i64 4 }, ptr undef }, ptr %255, 1
|
||||
%257 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 24)
|
||||
%258 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %257, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %256, ptr %258, align 8
|
||||
%259 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %257, 0
|
||||
%260 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %259, i64 1, 1
|
||||
%261 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %260, i64 1, 2
|
||||
call void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamedInterface"(ptr %250, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %261)
|
||||
br label %_llgo_24
|
||||
|
||||
_llgo_24: ; preds = %_llgo_23, %_llgo_22
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -568,8 +575,6 @@ declare void @"github.com/goplus/llgo/runtime/internal/runtime.InitNamed"(ptr, p
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.PointerTo"(ptr)
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String", %"github.com/goplus/llgo/runtime/internal/runtime.Slice")
|
||||
|
||||
declare ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr, ptr)
|
||||
|
||||
attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
|
||||
|
||||
@@ -34,7 +34,6 @@ source_filename = "github.com/goplus/llgo/cl/_testrt/vamethod"
|
||||
@"*_llgo_github.com/goplus/llgo/cl/_testrt/vamethod.CFmt" = linkonce global ptr null, align 8
|
||||
@"_llgo_github.com/goplus/llgo/cl/_testrt/vamethod.IFmt" = linkonce global ptr null, align 8
|
||||
@9 = private unnamed_addr constant [4 x i8] c"IFmt", align 1
|
||||
@"_llgo_iface$a85zs5wWQQoPIERm_en8plssh4spdIeeXZPC-E0TDh0" = linkonce global ptr null, align 8
|
||||
@10 = private unnamed_addr constant [12 x i8] c"%s (%d,%d)\0A\00", align 1
|
||||
@11 = private unnamed_addr constant [5 x i8] c"ifmt\00", align 1
|
||||
@12 = private unnamed_addr constant [5 x i8] c"error", align 1
|
||||
@@ -133,7 +132,7 @@ _llgo_2: ; preds = %_llgo_5
|
||||
|
||||
_llgo_3: ; preds = %_llgo_0
|
||||
%36 = extractvalue %"github.com/goplus/llgo/runtime/internal/runtime.eface" %11, 1
|
||||
%37 = load ptr, ptr @"_llgo_iface$a85zs5wWQQoPIERm_en8plssh4spdIeeXZPC-E0TDh0", align 8
|
||||
%37 = load ptr, ptr @"_llgo_github.com/goplus/llgo/cl/_testrt/vamethod.IFmt", align 8
|
||||
%38 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.NewItab"(ptr %37, ptr %12)
|
||||
%39 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" undef, ptr %38, 0
|
||||
%40 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.iface" %39, ptr %36, 1
|
||||
@@ -420,38 +419,16 @@ _llgo_29: ; preds = %_llgo_28
|
||||
br label %_llgo_30
|
||||
|
||||
_llgo_30: ; preds = %_llgo_29, %_llgo_28
|
||||
%137 = load ptr, ptr @"_llgo_func$sSO5Bw-E3E7TeJqIJF_OmmojTYyqWBhYrUwNYJNw7Bs", align 8
|
||||
%138 = load ptr, ptr @"_llgo_func$vAfTC3ZLX0_lZI-ZNliu0_DkE266FSmKXxj_cqKPPkA", align 8
|
||||
%139 = load ptr, ptr @"_llgo_iface$a85zs5wWQQoPIERm_en8plssh4spdIeeXZPC-E0TDh0", align 8
|
||||
%140 = icmp eq ptr %139, null
|
||||
br i1 %140, label %_llgo_31, label %_llgo_32
|
||||
%137 = load ptr, ptr @_llgo_string, align 8
|
||||
%138 = icmp eq ptr %137, null
|
||||
br i1 %138, label %_llgo_31, label %_llgo_32
|
||||
|
||||
_llgo_31: ; preds = %_llgo_30
|
||||
%141 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @7, i64 6 }, ptr undef }, ptr %137, 1
|
||||
%142 = insertvalue %"github.com/goplus/llgo/runtime/abi.Imethod" { %"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @8, i64 9 }, ptr undef }, ptr %138, 1
|
||||
%143 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.AllocU"(i64 48)
|
||||
%144 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %143, i64 0
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %141, ptr %144, align 8
|
||||
%145 = getelementptr %"github.com/goplus/llgo/runtime/abi.Imethod", ptr %143, i64 1
|
||||
store %"github.com/goplus/llgo/runtime/abi.Imethod" %142, ptr %145, align 8
|
||||
%146 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" undef, ptr %143, 0
|
||||
%147 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %146, i64 2, 1
|
||||
%148 = insertvalue %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %147, i64 2, 2
|
||||
%149 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Interface"(%"github.com/goplus/llgo/runtime/internal/runtime.String" { ptr @4, i64 42 }, %"github.com/goplus/llgo/runtime/internal/runtime.Slice" %148)
|
||||
store ptr %149, ptr @"_llgo_iface$a85zs5wWQQoPIERm_en8plssh4spdIeeXZPC-E0TDh0", align 8
|
||||
%139 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 24)
|
||||
store ptr %139, ptr @_llgo_string, align 8
|
||||
br label %_llgo_32
|
||||
|
||||
_llgo_32: ; preds = %_llgo_31, %_llgo_30
|
||||
%150 = load ptr, ptr @_llgo_string, align 8
|
||||
%151 = icmp eq ptr %150, null
|
||||
br i1 %151, label %_llgo_33, label %_llgo_34
|
||||
|
||||
_llgo_33: ; preds = %_llgo_32
|
||||
%152 = call ptr @"github.com/goplus/llgo/runtime/internal/runtime.Basic"(i64 24)
|
||||
store ptr %152, ptr @_llgo_string, align 8
|
||||
br label %_llgo_34
|
||||
|
||||
_llgo_34: ; preds = %_llgo_33, %_llgo_32
|
||||
ret void
|
||||
}
|
||||
|
||||
|
||||
@@ -393,10 +393,10 @@ func TestErrImport(t *testing.T) {
|
||||
|
||||
func TestErrInitLinkname(t *testing.T) {
|
||||
var ctx context
|
||||
ctx.initLinkname("//llgo:link abc", func(name string, isExport bool) (string, bool, bool) {
|
||||
ctx.initLinkname("//llgo:link abc", func(name string) (string, bool, bool) {
|
||||
return "", false, false
|
||||
})
|
||||
ctx.initLinkname("//go:linkname Printf printf", func(name string, isExport bool) (string, bool, bool) {
|
||||
ctx.initLinkname("//go:linkname Printf printf", func(name string) (string, bool, bool) {
|
||||
return "", false, false
|
||||
})
|
||||
defer func() {
|
||||
@@ -404,7 +404,7 @@ func TestErrInitLinkname(t *testing.T) {
|
||||
t.Fatal("initLinkname: no error?")
|
||||
}
|
||||
}()
|
||||
ctx.initLinkname("//go:linkname Printf printf", func(name string, isExport bool) (string, bool, bool) {
|
||||
ctx.initLinkname("//go:linkname Printf printf", func(name string) (string, bool, bool) {
|
||||
return "foo.Printf", false, name == "Printf"
|
||||
})
|
||||
}
|
||||
@@ -506,238 +506,3 @@ func TestInstantiate(t *testing.T) {
|
||||
t.Fatal("error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleExportDiffName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
enableExportRename bool
|
||||
line string
|
||||
fullName string
|
||||
inPkgName string
|
||||
wantHasLinkname bool
|
||||
wantLinkname string
|
||||
wantExport string
|
||||
}{
|
||||
{
|
||||
name: "ExportDiffNames_DifferentName",
|
||||
enableExportRename: true,
|
||||
line: "//export IRQ_Handler",
|
||||
fullName: "pkg.HandleInterrupt",
|
||||
inPkgName: "HandleInterrupt",
|
||||
wantHasLinkname: true,
|
||||
wantLinkname: "IRQ_Handler",
|
||||
wantExport: "IRQ_Handler",
|
||||
},
|
||||
{
|
||||
name: "ExportDiffNames_SameName",
|
||||
enableExportRename: true,
|
||||
line: "//export SameName",
|
||||
fullName: "pkg.SameName",
|
||||
inPkgName: "SameName",
|
||||
wantHasLinkname: true,
|
||||
wantLinkname: "SameName",
|
||||
wantExport: "SameName",
|
||||
},
|
||||
{
|
||||
name: "ExportDiffNames_WithSpaces",
|
||||
enableExportRename: true,
|
||||
line: "//export Timer_Callback ",
|
||||
fullName: "pkg.OnTimerTick",
|
||||
inPkgName: "OnTimerTick",
|
||||
wantHasLinkname: true,
|
||||
wantLinkname: "Timer_Callback",
|
||||
wantExport: "Timer_Callback",
|
||||
},
|
||||
{
|
||||
name: "ExportDiffNames_Disabled_MatchingName",
|
||||
enableExportRename: false,
|
||||
line: "//export Func",
|
||||
fullName: "pkg.Func",
|
||||
inPkgName: "Func",
|
||||
wantHasLinkname: true,
|
||||
wantLinkname: "Func",
|
||||
wantExport: "Func",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Save and restore global state
|
||||
oldEnableExportRename := enableExportRename
|
||||
defer func() {
|
||||
EnableExportRename(oldEnableExportRename)
|
||||
}()
|
||||
EnableExportRename(tt.enableExportRename)
|
||||
|
||||
// Setup context
|
||||
prog := llssa.NewProgram(nil)
|
||||
pkg := prog.NewPackage("test", "test")
|
||||
ctx := &context{
|
||||
prog: prog,
|
||||
pkg: pkg,
|
||||
}
|
||||
|
||||
// Call initLinkname with closure that mimics initLinknameByDoc behavior
|
||||
ret := ctx.initLinkname(tt.line, func(name string, isExport bool) (string, bool, bool) {
|
||||
return tt.fullName, false, name == tt.inPkgName || (isExport && enableExportRename)
|
||||
})
|
||||
|
||||
// Verify result
|
||||
hasLinkname := (ret == hasLinkname)
|
||||
if hasLinkname != tt.wantHasLinkname {
|
||||
t.Errorf("hasLinkname = %v, want %v", hasLinkname, tt.wantHasLinkname)
|
||||
}
|
||||
|
||||
if tt.wantHasLinkname {
|
||||
// Check linkname was set
|
||||
if link, ok := prog.Linkname(tt.fullName); !ok || link != tt.wantLinkname {
|
||||
t.Errorf("linkname = %q (ok=%v), want %q", link, ok, tt.wantLinkname)
|
||||
}
|
||||
|
||||
// Check export was set
|
||||
exports := pkg.ExportFuncs()
|
||||
if export, ok := exports[tt.fullName]; !ok || export != tt.wantExport {
|
||||
t.Errorf("export = %q (ok=%v), want %q", export, ok, tt.wantExport)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitLinknameByDocExportDiffNames(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
enableExportRename bool
|
||||
doc *ast.CommentGroup
|
||||
fullName string
|
||||
inPkgName string
|
||||
wantExported bool // Whether the symbol should be exported with different name
|
||||
wantLinkname string
|
||||
wantExport string
|
||||
}{
|
||||
{
|
||||
name: "WithExportDiffNames_DifferentNameExported",
|
||||
enableExportRename: true,
|
||||
doc: &ast.CommentGroup{
|
||||
List: []*ast.Comment{
|
||||
{Text: "//export IRQ_Handler"},
|
||||
},
|
||||
},
|
||||
fullName: "pkg.HandleInterrupt",
|
||||
inPkgName: "HandleInterrupt",
|
||||
wantExported: true,
|
||||
wantLinkname: "IRQ_Handler",
|
||||
wantExport: "IRQ_Handler",
|
||||
},
|
||||
{
|
||||
name: "WithoutExportDiffNames_NotExported",
|
||||
enableExportRename: false,
|
||||
doc: &ast.CommentGroup{
|
||||
List: []*ast.Comment{
|
||||
{Text: "//export DifferentName"},
|
||||
},
|
||||
},
|
||||
fullName: "pkg.HandleInterrupt",
|
||||
inPkgName: "HandleInterrupt",
|
||||
wantExported: false,
|
||||
// Without enableExportRename, it goes through normal flow which expects same name
|
||||
// The symbol "DifferentName" won't be found, so no export happens
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Without enableExportRename, export with different name will panic
|
||||
if !tt.wantExported && !tt.enableExportRename {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
t.Error("expected panic for export with different name when enableExportRename=false")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Save and restore global state
|
||||
oldEnableExportRename := enableExportRename
|
||||
defer func() {
|
||||
EnableExportRename(oldEnableExportRename)
|
||||
}()
|
||||
EnableExportRename(tt.enableExportRename)
|
||||
|
||||
// Setup context
|
||||
prog := llssa.NewProgram(nil)
|
||||
pkg := prog.NewPackage("test", "test")
|
||||
ctx := &context{
|
||||
prog: prog,
|
||||
pkg: pkg,
|
||||
}
|
||||
|
||||
// Call initLinknameByDoc
|
||||
ctx.initLinknameByDoc(tt.doc, tt.fullName, tt.inPkgName, false)
|
||||
|
||||
// Verify export behavior
|
||||
exports := pkg.ExportFuncs()
|
||||
if tt.wantExported {
|
||||
// Should have exported the symbol with different name
|
||||
if export, ok := exports[tt.fullName]; !ok || export != tt.wantExport {
|
||||
t.Errorf("export = %q (ok=%v), want %q", export, ok, tt.wantExport)
|
||||
}
|
||||
// Check linkname was also set
|
||||
if link, ok := prog.Linkname(tt.fullName); !ok || link != tt.wantLinkname {
|
||||
t.Errorf("linkname = %q (ok=%v), want %q", link, ok, tt.wantLinkname)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitLinkExportDiffNames(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
enableExportRename bool
|
||||
line string
|
||||
wantPanic bool
|
||||
}{
|
||||
{
|
||||
name: "ExportDiffNames_Enabled_NoError",
|
||||
enableExportRename: true,
|
||||
line: "//export IRQ_Handler",
|
||||
wantPanic: false,
|
||||
},
|
||||
{
|
||||
name: "ExportDiffNames_Disabled_Panic",
|
||||
enableExportRename: false,
|
||||
line: "//export IRQ_Handler",
|
||||
wantPanic: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.wantPanic {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
t.Error("expected panic but didn't panic")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
oldEnableExportRename := enableExportRename
|
||||
defer func() {
|
||||
EnableExportRename(oldEnableExportRename)
|
||||
}()
|
||||
EnableExportRename(tt.enableExportRename)
|
||||
|
||||
prog := llssa.NewProgram(nil)
|
||||
pkg := prog.NewPackage("test", "test")
|
||||
ctx := &context{
|
||||
prog: prog,
|
||||
pkg: pkg,
|
||||
}
|
||||
|
||||
ctx.initLinkname(tt.line, func(inPkgName string, isExport bool) (fullName string, isVar, ok bool) {
|
||||
// Simulate initLinknames scenario: symbol not found (like in decl packages)
|
||||
return "", false, false
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
150
cl/compile.go
150
cl/compile.go
@@ -53,11 +53,6 @@ var (
|
||||
enableDbg bool
|
||||
enableDbgSyms bool
|
||||
disableInline bool
|
||||
|
||||
// enableExportRename enables //export to use different C symbol names than Go function names.
|
||||
// This is for TinyGo compatibility when using -target flag for embedded targets.
|
||||
// Currently, using -target implies TinyGo embedded target mode.
|
||||
enableExportRename bool
|
||||
)
|
||||
|
||||
// SetDebug sets debug flags.
|
||||
@@ -78,12 +73,6 @@ func EnableTrace(b bool) {
|
||||
enableCallTracing = b
|
||||
}
|
||||
|
||||
// EnableExportRename enables or disables //export with different C symbol names.
|
||||
// This is enabled when using -target flag for TinyGo compatibility.
|
||||
func EnableExportRename(b bool) {
|
||||
enableExportRename = b
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type instrOrValue interface {
|
||||
@@ -109,19 +98,18 @@ type pkgInfo struct {
|
||||
type none = struct{}
|
||||
|
||||
type context struct {
|
||||
prog llssa.Program
|
||||
pkg llssa.Package
|
||||
fn llssa.Function
|
||||
fset *token.FileSet
|
||||
goProg *ssa.Program
|
||||
goTyps *types.Package
|
||||
goPkg *ssa.Package
|
||||
pyMod string
|
||||
skips map[string]none
|
||||
loaded map[*types.Package]*pkgInfo // loaded packages
|
||||
bvals map[ssa.Value]llssa.Expr // block values
|
||||
vargs map[*ssa.Alloc][]llssa.Expr // varargs
|
||||
paramDIVars map[*types.Var]llssa.DIVar
|
||||
prog llssa.Program
|
||||
pkg llssa.Package
|
||||
fn llssa.Function
|
||||
fset *token.FileSet
|
||||
goProg *ssa.Program
|
||||
goTyps *types.Package
|
||||
goPkg *ssa.Package
|
||||
pyMod string
|
||||
skips map[string]none
|
||||
loaded map[*types.Package]*pkgInfo // loaded packages
|
||||
bvals map[ssa.Value]llssa.Expr // block values
|
||||
vargs map[*ssa.Alloc][]llssa.Expr // varargs
|
||||
|
||||
patches Patches
|
||||
blkInfos []blocks.Info
|
||||
@@ -138,58 +126,6 @@ type context struct {
|
||||
cgoArgs []llssa.Expr
|
||||
cgoRet llssa.Expr
|
||||
cgoSymbols []string
|
||||
rewrites map[string]string
|
||||
}
|
||||
|
||||
func (p *context) rewriteValue(name string) (string, bool) {
|
||||
if p.rewrites == nil {
|
||||
return "", false
|
||||
}
|
||||
dot := strings.LastIndex(name, ".")
|
||||
if dot < 0 || dot == len(name)-1 {
|
||||
return "", false
|
||||
}
|
||||
varName := name[dot+1:]
|
||||
val, ok := p.rewrites[varName]
|
||||
return val, ok
|
||||
}
|
||||
|
||||
// isStringPtrType checks if typ is a pointer to the basic string type (*string).
|
||||
// This is used to validate that -ldflags -X can only rewrite variables of type *string,
|
||||
// not derived string types like "type T string".
|
||||
func (p *context) isStringPtrType(typ types.Type) bool {
|
||||
ptr, ok := typ.(*types.Pointer)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
basic, ok := ptr.Elem().(*types.Basic)
|
||||
return ok && basic.Kind() == types.String
|
||||
}
|
||||
|
||||
func (p *context) globalFullName(g *ssa.Global) string {
|
||||
name, _, _ := p.varName(g.Pkg.Pkg, g)
|
||||
return name
|
||||
}
|
||||
|
||||
func (p *context) rewriteInitStore(store *ssa.Store, g *ssa.Global) (string, bool) {
|
||||
if p.rewrites == nil {
|
||||
return "", false
|
||||
}
|
||||
fn := store.Block().Parent()
|
||||
if fn == nil || fn.Synthetic != "package initializer" {
|
||||
return "", false
|
||||
}
|
||||
if _, ok := store.Val.(*ssa.Const); !ok {
|
||||
return "", false
|
||||
}
|
||||
if !p.isStringPtrType(g.Type()) {
|
||||
return "", false
|
||||
}
|
||||
value, ok := p.rewriteValue(p.globalFullName(g))
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
return value, true
|
||||
}
|
||||
|
||||
type pkgState byte
|
||||
@@ -239,16 +175,7 @@ func (p *context) compileGlobal(pkg llssa.Package, gbl *ssa.Global) {
|
||||
log.Println("==> NewVar", name, typ)
|
||||
}
|
||||
g := pkg.NewVar(name, typ, llssa.Background(vtype))
|
||||
if value, ok := p.rewriteValue(name); ok {
|
||||
if p.isStringPtrType(gbl.Type()) {
|
||||
g.Init(pkg.ConstString(value))
|
||||
} else {
|
||||
log.Printf("warning: ignoring rewrite for non-string variable %s (type: %v)", name, gbl.Type())
|
||||
if define {
|
||||
g.InitNil()
|
||||
}
|
||||
}
|
||||
} else if define {
|
||||
if define {
|
||||
g.InitNil()
|
||||
}
|
||||
}
|
||||
@@ -336,8 +263,6 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
||||
if f.Recover != nil { // set recover block
|
||||
fn.SetRecover(fn.Block(f.Recover.Index))
|
||||
}
|
||||
dbgEnabled := enableDbg && (f == nil || f.Origin() == nil)
|
||||
dbgSymsEnabled := enableDbgSyms && (f == nil || f.Origin() == nil)
|
||||
p.inits = append(p.inits, func() {
|
||||
p.fn = fn
|
||||
p.state = state // restore pkgState when compiling funcBody
|
||||
@@ -345,11 +270,6 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
||||
p.fn = nil
|
||||
}()
|
||||
p.phis = nil
|
||||
if dbgSymsEnabled {
|
||||
p.paramDIVars = make(map[*types.Var]llssa.DIVar)
|
||||
} else {
|
||||
p.paramDIVars = nil
|
||||
}
|
||||
if debugGoSSA {
|
||||
f.WriteTo(os.Stderr)
|
||||
}
|
||||
@@ -357,7 +277,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
||||
log.Println("==> FuncBody", name)
|
||||
}
|
||||
b := fn.NewBuilder()
|
||||
if dbgEnabled {
|
||||
if enableDbg {
|
||||
pos := p.goProg.Fset.Position(f.Pos())
|
||||
bodyPos := p.getFuncBodyPos(f)
|
||||
b.DebugFunction(fn, pos, bodyPos)
|
||||
@@ -451,9 +371,6 @@ func (p *context) debugParams(b llssa.Builder, f *ssa.Function) {
|
||||
ty := param.Type()
|
||||
argNo := i + 1
|
||||
div := b.DIVarParam(p.fn, pos, param.Name(), p.type_(ty, llssa.InGo), argNo)
|
||||
if p.paramDIVars != nil {
|
||||
p.paramDIVars[variable] = div
|
||||
}
|
||||
b.DIParam(variable, v, div, p.fn, pos, p.fn.Block(0))
|
||||
}
|
||||
}
|
||||
@@ -471,7 +388,7 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
|
||||
b.Printf("call " + fn.Name() + "\n\x00")
|
||||
}
|
||||
// place here to avoid wrong current-block
|
||||
if enableDbgSyms && block.Parent().Origin() == nil && block.Index == 0 {
|
||||
if enableDbgSyms && block.Index == 0 {
|
||||
p.debugParams(b, block.Parent())
|
||||
}
|
||||
if doModInit {
|
||||
@@ -866,7 +783,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
|
||||
p.compileInstrOrValue(b, iv, false)
|
||||
return
|
||||
}
|
||||
if enableDbg && instr.Parent().Origin() == nil {
|
||||
if enableDbg {
|
||||
scope := p.getDebugLocScope(instr.Parent(), instr.Pos())
|
||||
if scope != nil {
|
||||
diScope := b.DIScope(p.fn, scope)
|
||||
@@ -888,13 +805,6 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if p.rewrites != nil {
|
||||
if g, ok := va.(*ssa.Global); ok {
|
||||
if _, ok := p.rewriteInitStore(v, g); ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
ptr := p.compileValue(b, va)
|
||||
val := p.compileValue(b, v.Val)
|
||||
b.Store(ptr, val)
|
||||
@@ -936,7 +846,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
|
||||
x := p.compileValue(b, v.X)
|
||||
b.Send(ch, x)
|
||||
case *ssa.DebugRef:
|
||||
if enableDbgSyms && v.Parent().Origin() == nil {
|
||||
if enableDbgSyms {
|
||||
p.debugRef(b, v)
|
||||
}
|
||||
default:
|
||||
@@ -945,13 +855,14 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
|
||||
}
|
||||
|
||||
func (p *context) getLocalVariable(b llssa.Builder, fn *ssa.Function, v *types.Var) llssa.DIVar {
|
||||
if p.paramDIVars != nil {
|
||||
if div, ok := p.paramDIVars[v]; ok {
|
||||
return div
|
||||
}
|
||||
}
|
||||
pos := p.fset.Position(v.Pos())
|
||||
t := p.type_(v.Type(), llssa.InGo)
|
||||
for i, param := range fn.Params {
|
||||
if param.Object().(*types.Var) == v {
|
||||
argNo := i + 1
|
||||
return b.DIVarParam(p.fn, pos, v.Name(), t, argNo)
|
||||
}
|
||||
}
|
||||
scope := b.DIScope(p.fn, v.Parent())
|
||||
return b.DIVarAuto(scope, pos, v.Name(), t)
|
||||
}
|
||||
@@ -1059,22 +970,12 @@ type Patches = map[string]Patch
|
||||
|
||||
// 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) {
|
||||
ret, _, err = NewPackageEx(prog, nil, nil, pkg, files)
|
||||
ret, _, err = NewPackageEx(prog, nil, pkg, files)
|
||||
return
|
||||
}
|
||||
|
||||
// NewPackageEx compiles a Go package to LLVM IR package.
|
||||
//
|
||||
// Parameters:
|
||||
// - prog: target LLVM SSA program context
|
||||
// - patches: optional package patches applied during compilation
|
||||
// - rewrites: per-package string initializers rewritten at compile time
|
||||
// - pkg: SSA package to compile
|
||||
// - files: parsed AST files that belong to the package
|
||||
//
|
||||
// The rewrites map uses short variable names (without package qualifier) and
|
||||
// only affects string-typed globals defined in the current package.
|
||||
func NewPackageEx(prog llssa.Program, patches Patches, rewrites map[string]string, pkg *ssa.Package, files []*ast.File) (ret llssa.Package, externs []string, err error) {
|
||||
func NewPackageEx(prog llssa.Program, patches Patches, pkg *ssa.Package, files []*ast.File) (ret llssa.Package, externs []string, err error) {
|
||||
pkgProg := pkg.Prog
|
||||
pkgTypes := pkg.Pkg
|
||||
oldTypes := pkgTypes
|
||||
@@ -1107,7 +1008,6 @@ func NewPackageEx(prog llssa.Program, patches Patches, rewrites map[string]strin
|
||||
types.Unsafe: {kind: PkgDeclOnly}, // TODO(xsw): PkgNoInit or PkgDeclOnly?
|
||||
},
|
||||
cgoSymbols: make([]string, 0, 128),
|
||||
rewrites: rewrites,
|
||||
}
|
||||
ctx.initPyModule()
|
||||
ctx.initFiles(pkgPath, files, pkgName == "C")
|
||||
|
||||
22
cl/import.go
22
cl/import.go
@@ -73,7 +73,7 @@ func (p *pkgSymInfo) initLinknames(ctx *context) {
|
||||
lines := bytes.Split(b, sep)
|
||||
for _, line := range lines {
|
||||
if bytes.HasPrefix(line, commentPrefix) {
|
||||
ctx.initLinkname(string(line), func(inPkgName string, isExport bool) (fullName string, isVar, ok bool) {
|
||||
ctx.initLinkname(string(line), func(inPkgName string) (fullName string, isVar, ok bool) {
|
||||
if sym, ok := p.syms[inPkgName]; ok && file == sym.file {
|
||||
return sym.fullName, sym.isVar, true
|
||||
}
|
||||
@@ -277,8 +277,8 @@ func (p *context) initLinknameByDoc(doc *ast.CommentGroup, fullName, inPkgName s
|
||||
if doc != nil {
|
||||
for n := len(doc.List) - 1; n >= 0; n-- {
|
||||
line := doc.List[n].Text
|
||||
ret := p.initLinkname(line, func(name string, isExport bool) (_ string, _, ok bool) {
|
||||
return fullName, isVar, name == inPkgName || (isExport && enableExportRename)
|
||||
ret := p.initLinkname(line, func(name string) (_ string, _, ok bool) {
|
||||
return fullName, isVar, name == inPkgName
|
||||
})
|
||||
if ret != unknownDirective {
|
||||
return ret == hasLinkname
|
||||
@@ -294,7 +294,7 @@ const (
|
||||
unknownDirective = -1
|
||||
)
|
||||
|
||||
func (p *context) initLinkname(line string, f func(inPkgName string, isExport bool) (fullName string, isVar, ok bool)) int {
|
||||
func (p *context) initLinkname(line string, f func(inPkgName string) (fullName string, isVar, ok bool)) int {
|
||||
const (
|
||||
linkname = "//go:linkname "
|
||||
llgolink = "//llgo:link "
|
||||
@@ -324,24 +324,17 @@ func (p *context) initLinkname(line string, f func(inPkgName string, isExport bo
|
||||
return noDirective
|
||||
}
|
||||
|
||||
func (p *context) initLink(line string, prefix int, export bool, f func(inPkgName string, isExport bool) (fullName string, isVar, ok bool)) {
|
||||
func (p *context) initLink(line string, prefix int, export bool, f func(inPkgName string) (fullName string, isVar, ok bool)) {
|
||||
text := strings.TrimSpace(line[prefix:])
|
||||
if idx := strings.IndexByte(text, ' '); idx > 0 {
|
||||
inPkgName := text[:idx]
|
||||
if fullName, _, ok := f(inPkgName, export); ok {
|
||||
if fullName, _, ok := f(inPkgName); ok {
|
||||
link := strings.TrimLeft(text[idx+1:], " ")
|
||||
p.prog.SetLinkname(fullName, link)
|
||||
if export {
|
||||
p.pkg.SetExport(fullName, link)
|
||||
}
|
||||
} else {
|
||||
// Export with different names already processed by initLinknameByDoc
|
||||
if export && enableExportRename {
|
||||
return
|
||||
}
|
||||
if export {
|
||||
panic(fmt.Sprintf("export comment has wrong name %q", inPkgName))
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "==>", line)
|
||||
fmt.Fprintf(os.Stderr, "llgo: linkname %s not found and ignored\n", inPkgName)
|
||||
}
|
||||
@@ -510,8 +503,7 @@ const (
|
||||
llgoCgoCheckPointer = llgoCgoBase + 0x6
|
||||
llgoCgoCgocall = llgoCgoBase + 0x7
|
||||
|
||||
llgoAsm = llgoInstrBase + 0x40
|
||||
llgoStackSave = llgoInstrBase + 0x41
|
||||
llgoAsm = llgoInstrBase + 0x40
|
||||
|
||||
llgoAtomicOpLast = llgoAtomicOpBase + int(llssa.OpUMin)
|
||||
)
|
||||
|
||||
@@ -425,8 +425,7 @@ var llgoInstrs = map[string]int{
|
||||
"_cgoCheckPointer": llgoCgoCheckPointer,
|
||||
"_cgo_runtime_cgocall": llgoCgoCgocall,
|
||||
|
||||
"asm": llgoAsm,
|
||||
"stackSave": llgoStackSave,
|
||||
"asm": llgoAsm,
|
||||
}
|
||||
|
||||
// funcOf returns a function by name and set ftype = goFunc, cFunc, etc.
|
||||
@@ -602,8 +601,6 @@ func (p *context) call(b llssa.Builder, act llssa.DoAction, call *ssa.CallCommon
|
||||
ret = p.sigsetjmp(b, args)
|
||||
case llgoSiglongjmp:
|
||||
p.siglongjmp(b, args)
|
||||
case llgoStackSave:
|
||||
ret = b.StackSave()
|
||||
case llgoSigjmpbuf: // func sigjmpbuf()
|
||||
ret = b.AllocaSigjmpBuf()
|
||||
case llgoDeferData: // func deferData() *Defer
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
package cl
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
gpackages "github.com/goplus/gogen/packages"
|
||||
llssa "github.com/goplus/llgo/ssa"
|
||||
"github.com/goplus/llgo/ssa/ssatest"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
"golang.org/x/tools/go/ssa/ssautil"
|
||||
)
|
||||
|
||||
func init() {
|
||||
llssa.Initialize(llssa.InitAll | llssa.InitNative)
|
||||
}
|
||||
|
||||
func compileWithRewrites(t *testing.T, src string, rewrites map[string]string) string {
|
||||
t.Helper()
|
||||
fset := token.NewFileSet()
|
||||
file, err := parser.ParseFile(fset, "rewrite.go", src, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("parse failed: %v", err)
|
||||
}
|
||||
importer := gpackages.NewImporter(fset)
|
||||
mode := ssa.SanityCheckFunctions | ssa.InstantiateGenerics
|
||||
pkg, _, err := ssautil.BuildPackage(&types.Config{Importer: importer}, fset,
|
||||
types.NewPackage(file.Name.Name, file.Name.Name), []*ast.File{file}, mode)
|
||||
if err != nil {
|
||||
t.Fatalf("build package failed: %v", err)
|
||||
}
|
||||
prog := ssatest.NewProgramEx(t, nil, importer)
|
||||
prog.TypeSizes(types.SizesFor("gc", runtime.GOARCH))
|
||||
ret, _, err := NewPackageEx(prog, nil, rewrites, pkg, []*ast.File{file})
|
||||
if err != nil {
|
||||
t.Fatalf("NewPackageEx failed: %v", err)
|
||||
}
|
||||
return ret.String()
|
||||
}
|
||||
|
||||
func TestRewriteGlobalStrings(t *testing.T) {
|
||||
const src = `package rewritepkg
|
||||
var VarInit = "original_value"
|
||||
var VarPlain string
|
||||
func Use() string { return VarInit + VarPlain }
|
||||
`
|
||||
ir := compileWithRewrites(t, src, map[string]string{
|
||||
"VarInit": "rewrite_init",
|
||||
"VarPlain": "rewrite_plain",
|
||||
})
|
||||
if strings.Contains(ir, "original_value") {
|
||||
t.Fatalf("original initializer still present:\n%s", ir)
|
||||
}
|
||||
for _, want := range []string{`c"rewrite_init"`, `c"rewrite_plain"`} {
|
||||
if !strings.Contains(ir, want) {
|
||||
t.Fatalf("missing %s in IR:\n%s", want, ir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteSkipsNonConstStores(t *testing.T) {
|
||||
const src = `package rewritepkg
|
||||
import "strings"
|
||||
var VarInit = strings.ToUpper("original_value")
|
||||
var VarPlain string
|
||||
func Use() string { return VarInit + VarPlain }
|
||||
`
|
||||
ir := compileWithRewrites(t, src, map[string]string{
|
||||
"VarInit": "rewrite_init",
|
||||
"VarPlain": "rewrite_plain",
|
||||
})
|
||||
if !strings.Contains(ir, `c"rewrite_init"`) {
|
||||
t.Fatalf("expected rewrite_init constant to remain:\n%s", ir)
|
||||
}
|
||||
if !strings.Contains(ir, "strings.ToUpper") {
|
||||
t.Fatalf("expected call to strings.ToUpper in IR:\n%s", ir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteValueNoDot(t *testing.T) {
|
||||
ctx := &context{rewrites: map[string]string{"VarInit": "rewrite_init"}}
|
||||
if _, ok := ctx.rewriteValue("VarInit"); ok {
|
||||
t.Fatalf("rewriteValue should skip names without package prefix")
|
||||
}
|
||||
if _, ok := ctx.rewriteValue("pkg."); ok {
|
||||
t.Fatalf("rewriteValue should skip trailing dot names")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsStringPtrTypeDefault(t *testing.T) {
|
||||
ctx := &context{}
|
||||
if ctx.isStringPtrType(types.NewPointer(types.Typ[types.Int])) {
|
||||
t.Fatalf("expected non-string pointer to return false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsStringPtrTypeBranches(t *testing.T) {
|
||||
ctx := &context{}
|
||||
if ctx.isStringPtrType(types.NewSlice(types.Typ[types.String])) {
|
||||
t.Fatalf("slice should trigger default branch and return false")
|
||||
}
|
||||
if ctx.isStringPtrType(nil) {
|
||||
t.Fatalf("nil type should return false")
|
||||
}
|
||||
if !ctx.isStringPtrType(types.NewPointer(types.Typ[types.String])) {
|
||||
t.Fatalf("*string should return true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteIgnoredInNonInitStore(t *testing.T) {
|
||||
const src = `package rewritepkg
|
||||
var VarInit = "original_value"
|
||||
func Override() { VarInit = "override_value" }
|
||||
`
|
||||
ir := compileWithRewrites(t, src, map[string]string{"VarInit": "rewrite_init"})
|
||||
if !strings.Contains(ir, `c"override_value"`) {
|
||||
t.Fatalf("override store should retain original literal:\n%s", ir)
|
||||
}
|
||||
if !strings.Contains(ir, `c"rewrite_init"`) {
|
||||
t.Fatalf("global initializer should still be rewritten:\n%s", ir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteMissingEntry(t *testing.T) {
|
||||
const src = `package rewritepkg
|
||||
var VarInit = "original_value"
|
||||
var VarOther = "other_value"
|
||||
`
|
||||
ir := compileWithRewrites(t, src, map[string]string{"VarInit": "rewrite_init"})
|
||||
if !strings.Contains(ir, `c"other_value"`) {
|
||||
t.Fatalf("VarOther should keep original initializer:\n%s", ir)
|
||||
}
|
||||
if !strings.Contains(ir, `c"rewrite_init"`) {
|
||||
t.Fatalf("VarInit should still be rewritten:\n%s", ir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteIgnoresNonStringVar(t *testing.T) {
|
||||
const src = `package rewritepkg
|
||||
type wrapper struct{ v int }
|
||||
var VarStruct = wrapper{v: 1}
|
||||
`
|
||||
ir := compileWithRewrites(t, src, map[string]string{"VarStruct": "rewrite_struct"})
|
||||
if strings.Contains(ir, `c"rewrite_struct"`) {
|
||||
t.Fatalf("non-string variables must not be rewritten:\n%s", ir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteIgnoresStringAlias(t *testing.T) {
|
||||
const src = `package rewritepkg
|
||||
type T string
|
||||
var VarAlias T = "original_value"
|
||||
`
|
||||
ir := compileWithRewrites(t, src, map[string]string{"VarAlias": "rewrite_alias"})
|
||||
if strings.Contains(ir, `c"rewrite_alias"`) {
|
||||
t.Fatalf("string alias types must not be rewritten:\n%s", ir)
|
||||
}
|
||||
if !strings.Contains(ir, `c"original_value"`) {
|
||||
t.Fatalf("original value should remain for alias type:\n%s", ir)
|
||||
}
|
||||
}
|
||||
@@ -36,9 +36,6 @@ var CheckLinkArgs bool
|
||||
var CheckLLFiles bool
|
||||
var GenLLFiles bool
|
||||
var ForceEspClang bool
|
||||
var SizeReport bool
|
||||
var SizeFormat string
|
||||
var SizeLevel string
|
||||
|
||||
func AddCommonFlags(fs *flag.FlagSet) {
|
||||
fs.BoolVar(&Verbose, "v", false, "Verbose output")
|
||||
@@ -54,10 +51,6 @@ func AddBuildFlags(fs *flag.FlagSet) {
|
||||
fs.BoolVar(&GenLLFiles, "gen-llfiles", false, "generate .ll files for pkg export")
|
||||
fs.BoolVar(&ForceEspClang, "force-espclang", false, "force to use esp-clang")
|
||||
}
|
||||
|
||||
fs.BoolVar(&SizeReport, "size", false, "Print size report after build")
|
||||
fs.StringVar(&SizeFormat, "size:format", "", "Size report format (text,json)")
|
||||
fs.StringVar(&SizeLevel, "size:level", "", "Size report aggregation level (full,module,package)")
|
||||
}
|
||||
|
||||
func AddBuildModeFlags(fs *flag.FlagSet) {
|
||||
@@ -86,15 +79,6 @@ func UpdateConfig(conf *build.Config) error {
|
||||
conf.Target = Target
|
||||
conf.Port = Port
|
||||
conf.BaudRate = BaudRate
|
||||
if SizeReport || SizeFormat != "" || SizeLevel != "" {
|
||||
conf.SizeReport = true
|
||||
if SizeFormat != "" {
|
||||
conf.SizeFormat = SizeFormat
|
||||
}
|
||||
if SizeLevel != "" {
|
||||
conf.SizeLevel = SizeLevel
|
||||
}
|
||||
}
|
||||
|
||||
switch conf.Mode {
|
||||
case build.ModeBuild:
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
# Defer Loop GC Integration
|
||||
|
||||
## Background
|
||||
|
||||
`defer` chains are stored in a per-thread TLS slot so that unwind paths can locate the active `*runtime.Defer`. With the default allocator (`AllocU`) backed by Boehm GC (bdwgc), those TLS-resident pointers were invisible to the collector. In stress scenarios—e.g. `TestDeferLoopStress` with 1,000,000 defers—the collector reclaimed the defer nodes, leaving dangling pointers and causing crashes inside the deferred closures.
|
||||
|
||||
Prior experiments (`test-defer-dont-free` branch) confirmed the crash disappeared when allocations bypassed GC (plain `malloc` without `free`), pointing to a root-registration gap rather than logical corruption.
|
||||
|
||||
## Solution Overview
|
||||
|
||||
1. **GC-aware TLS slot helper** *(from PR [#1347](https://github.com/goplus/llgo/pull/1347))*
|
||||
- Added `runtime/internal/clite/tls`, which exposes `tls.Alloc` to create per-thread storage that is automatically registered as a Boehm GC root.
|
||||
- `SetThreadDefer` delegates to this helper so every thread reuses the same GC-safe slot without bespoke plumbing.
|
||||
- The package handles TLS key creation, root registration/removal, and invokes an optional destructor when a thread exits.
|
||||
|
||||
2. **SSA codegen synchronization**
|
||||
- `ssa/eh.go` now calls `runtime.SetThreadDefer` whenever it updates the TLS pointer (on first allocation and when restoring the previous link during unwind).
|
||||
- Defer argument nodes and the `runtime.Defer` struct itself are allocated with `aggregateAllocU`, ensuring new memory comes from GC-managed heaps, and nodes are released via `runtime.FreeDeferNode`.
|
||||
|
||||
3. **Non-GC builds**
|
||||
- The `tls` helper falls back to a malloc-backed TLS slot without GC registration, while `FreeDeferNode` continues to release nodes via `c.Free` when building with `-tags nogc`.
|
||||
|
||||
## Testing
|
||||
|
||||
Run the stress and regression suites to validate the integration:
|
||||
|
||||
```sh
|
||||
./llgo.sh test ./test -run TestDeferLoopStress
|
||||
./llgo.sh test ./test
|
||||
```
|
||||
|
||||
The updated `TestDeferLoopStress` now asserts 1,000,000 loop defers execute without failure, catching regressions in GC root tracking.
|
||||
@@ -1,58 +0,0 @@
|
||||
# Size Report Options
|
||||
|
||||
The `llgo build -size` flag emits a TinyGo-style table showing how much code,
|
||||
rodata, data, and BSS each component contributes to the final binary. This
|
||||
document captures the parsing strategy and new aggregation controls.
|
||||
|
||||
## Parsing Strategy
|
||||
|
||||
- We invoke `llvm-readelf --elf-output-style=LLVM --all <binary>` and parse the textual output with an
|
||||
indentation-sensitive state machine (no JSON). Only the `Sections` and
|
||||
`Symbols` blocks are inspected.
|
||||
- Section metadata records the index, address, size, name, and segment. Each
|
||||
section is classified into text/rodata/data/bss buckets.
|
||||
- Symbols are attached to their containing sections with start addresses. By
|
||||
sorting symbols and walking their ranges, we compute byte spans that can be
|
||||
attributed to packages/modules.
|
||||
- Sections with no symbols fall back to `(unknown <section>)`, and gaps become
|
||||
`(padding <section>)` entries so totals still add up.
|
||||
|
||||
## Aggregation Levels
|
||||
|
||||
`-size:level` controls how symbol names are grouped prior to reporting:
|
||||
|
||||
| Level | Behavior |
|
||||
|-----------|---------------------------------------------------------------------------|
|
||||
| `full` | Keeps the raw owner from the symbol name (previous behavior). |
|
||||
| `package` | Uses the list of packages built in `build.Do` and groups by `pkg.PkgPath`. |
|
||||
| `module`* | Default. Groups by `pkg.Module.Path` (or `pkg.PkgPath` if the module is nil). |
|
||||
|
||||
Matching is performed by checking whether the demangled symbol name begins with
|
||||
`pkg.PkgPath + "."`. Symbols that do not match any package and contain `llgo` are
|
||||
bucketed into `llgo-stubs`; other unmatched entries keep their original owner
|
||||
names so we can inspect them later.
|
||||
|
||||
Examples:
|
||||
|
||||
```sh
|
||||
llgo build -size . # module-level aggregation (default)
|
||||
llgo build -size -size:level=package . # collapse by package ID
|
||||
llgo build -size -size:level=full . # show raw symbol owners
|
||||
llgo build -size -size:format=json . # JSON output (works with all levels)
|
||||
```
|
||||
|
||||
## Validation
|
||||
|
||||
1. Unit tests: `go test ./internal/build -run TestParseReadelfOutput -count=1`.
|
||||
2. Real binary test:
|
||||
```sh
|
||||
cd cl/_testgo/rewrite
|
||||
../../../llgo.sh build .
|
||||
LLGO_SIZE_REPORT_BIN=$(pwd)/rewrite \
|
||||
go test ./internal/build -run TestParseReadelfRealBinary -count=1
|
||||
```
|
||||
3. Manual smoke test: `../../../llgo.sh build -size -size:level=module .` (or
|
||||
`package`/`full` as desired).
|
||||
|
||||
The parser works across Mach-O and ELF targets as long as `llvm-readelf` is in
|
||||
`PATH`.
|
||||
4
go.mod
4
go.mod
@@ -6,8 +6,8 @@ toolchain go1.24.1
|
||||
|
||||
require (
|
||||
github.com/goplus/cobra v1.9.12 //gop:class
|
||||
github.com/goplus/gogen v1.19.5
|
||||
github.com/goplus/lib v0.3.1
|
||||
github.com/goplus/gogen v1.19.3
|
||||
github.com/goplus/lib v0.3.0
|
||||
github.com/goplus/llgo/runtime v0.0.0-00010101000000-000000000000
|
||||
github.com/goplus/llvm v0.8.5
|
||||
github.com/goplus/mod v0.17.1
|
||||
|
||||
8
go.sum
8
go.sum
@@ -6,10 +6,10 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/goplus/cobra v1.9.12 h1:0F9EdEbeGyITGz+mqoHoJ5KpUw97p1CkxV74IexHw5s=
|
||||
github.com/goplus/cobra v1.9.12/go.mod h1:p4LhfNJDKEpiGjGiNn0crUXL5dUPA5DX2ztYpEJR34E=
|
||||
github.com/goplus/gogen v1.19.5 h1:YWPwpRA1PusPhptv9jKg/XiN+AQGiAD9r6I86mJ3lR4=
|
||||
github.com/goplus/gogen v1.19.5/go.mod h1:owX2e1EyU5WD+Nm6oH2m/GXjLdlBYcwkLO4wN8HHXZI=
|
||||
github.com/goplus/lib v0.3.1 h1:Xws4DBVvgOMu58awqB972wtvTacDbk3nqcbHjdx9KSg=
|
||||
github.com/goplus/lib v0.3.1/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=
|
||||
github.com/goplus/gogen v1.19.3 h1:sMTe7xME8lWFdPL6NcULykdJtFs9CtXkNACRbaAKTiQ=
|
||||
github.com/goplus/gogen v1.19.3/go.mod h1:owX2e1EyU5WD+Nm6oH2m/GXjLdlBYcwkLO4wN8HHXZI=
|
||||
github.com/goplus/lib v0.3.0 h1:y0ZGb5Q/RikW1oMMB4Di7XIZIpuzh/7mlrR8HNbxXCA=
|
||||
github.com/goplus/lib v0.3.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0=
|
||||
github.com/goplus/llvm v0.8.5 h1:DUnFeYC3Rco622tBEKGg8xkigRAV2fh5ZIfBCt7gOSs=
|
||||
github.com/goplus/llvm v0.8.5/go.mod h1:PeVK8GgzxwAYCiMiUAJb5wJR6xbhj989tu9oulKLLT4=
|
||||
github.com/goplus/mod v0.17.1 h1:ITovxDcc5zbURV/Wrp3/SBsYLgC1KrxY6pq1zMM2V94=
|
||||
|
||||
@@ -132,19 +132,10 @@ type Config struct {
|
||||
CheckLinkArgs bool // check linkargs valid
|
||||
ForceEspClang bool // force to use esp-clang
|
||||
Tags string
|
||||
SizeReport bool // print size report after successful build
|
||||
SizeFormat string // size report format: text,json
|
||||
SizeLevel string // size aggregation level: full,module,package
|
||||
// GlobalRewrites specifies compile-time overrides for global string variables.
|
||||
// Keys are fully qualified package paths (e.g. "main" or "github.com/user/pkg").
|
||||
// Each Rewrites entry maps variable names to replacement string values. Only
|
||||
// string-typed globals are supported and "main" applies to all root main
|
||||
// packages in the current build.
|
||||
GlobalRewrites map[string]Rewrites
|
||||
GlobalNames map[string][]string // pkg => names
|
||||
GlobalDatas map[string]string // pkg.name => data
|
||||
}
|
||||
|
||||
type Rewrites map[string]string
|
||||
|
||||
func NewDefaultConf(mode Mode) *Config {
|
||||
bin := os.Getenv("GOBIN")
|
||||
if bin == "" {
|
||||
@@ -208,15 +199,6 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
||||
if conf.BuildMode == "" {
|
||||
conf.BuildMode = BuildModeExe
|
||||
}
|
||||
if conf.SizeReport && conf.SizeFormat == "" {
|
||||
conf.SizeFormat = "text"
|
||||
}
|
||||
if conf.SizeReport && conf.SizeLevel == "" {
|
||||
conf.SizeLevel = "module"
|
||||
}
|
||||
if err := ensureSizeReporting(conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Handle crosscompile configuration first to set correct GOOS/GOARCH
|
||||
forceEspClang := conf.ForceEspClang || conf.Target != ""
|
||||
export, err := crosscompile.Use(conf.Goos, conf.Goarch, conf.Target, IsWasiThreadsEnabled(), forceEspClang)
|
||||
@@ -232,11 +214,6 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
||||
conf.Goarch = export.GOARCH
|
||||
}
|
||||
|
||||
// Enable different export names for TinyGo compatibility when using -target
|
||||
if conf.Target != "" {
|
||||
cl.EnableExportRename(true)
|
||||
}
|
||||
|
||||
verbose := conf.Verbose
|
||||
patterns := args
|
||||
tags := "llgo,math_big_pure_go"
|
||||
@@ -358,10 +335,6 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
||||
crossCompile: export,
|
||||
cTransformer: cabi.NewTransformer(prog, export.LLVMTarget, export.TargetABI, conf.AbiMode, cabiOptimize),
|
||||
}
|
||||
|
||||
// default runtime globals must be registered before packages are built
|
||||
addGlobalString(conf, "runtime.defaultGOROOT="+runtime.GOROOT(), nil)
|
||||
addGlobalString(conf, "runtime.buildVersion="+runtime.Version(), nil)
|
||||
pkgs, err := buildAllPkgs(ctx, initial, verbose)
|
||||
check(err)
|
||||
if mode == ModeGen {
|
||||
@@ -372,11 +345,19 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
||||
}
|
||||
return nil, fmt.Errorf("initial package not found")
|
||||
}
|
||||
|
||||
dpkg, err := buildAllPkgs(ctx, altPkgs[noRt:], verbose)
|
||||
check(err)
|
||||
allPkgs := append([]*aPackage{}, pkgs...)
|
||||
allPkgs = append(allPkgs, dpkg...)
|
||||
|
||||
// update globals importpath.name=value
|
||||
addGlobalString(conf, "runtime.defaultGOROOT="+runtime.GOROOT(), nil)
|
||||
addGlobalString(conf, "runtime.buildVersion="+runtime.Version(), nil)
|
||||
|
||||
global, err := createGlobals(ctx, ctx.prog, pkgs)
|
||||
check(err)
|
||||
|
||||
for _, pkg := range initial {
|
||||
if needLink(pkg, mode) {
|
||||
name := path.Base(pkg.PkgPath)
|
||||
@@ -388,15 +369,10 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
||||
}
|
||||
|
||||
// Link main package using the output path from buildOutFmts
|
||||
err = linkMainPkg(ctx, pkg, allPkgs, outFmts.Out, verbose)
|
||||
err = linkMainPkg(ctx, pkg, allPkgs, global, outFmts.Out, verbose)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if conf.Mode == ModeBuild && conf.SizeReport {
|
||||
if err := reportBinarySize(outFmts.Out, conf.SizeFormat, conf.SizeLevel, allPkgs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Generate C headers for c-archive and c-shared modes before linking
|
||||
if ctx.buildConf.BuildMode == BuildModeCArchive || ctx.buildConf.BuildMode == BuildModeCShared {
|
||||
@@ -653,59 +629,58 @@ var (
|
||||
errXflags = errors.New("-X flag requires argument of the form importpath.name=value")
|
||||
)
|
||||
|
||||
// maxRewriteValueLength limits the size of rewrite values to prevent
|
||||
// excessive memory usage and potential resource exhaustion during compilation.
|
||||
const maxRewriteValueLength = 1 << 20 // 1 MiB cap per rewrite value
|
||||
|
||||
func addGlobalString(conf *Config, arg string, mainPkgs []string) {
|
||||
addGlobalStringWith(conf, arg, mainPkgs, true)
|
||||
}
|
||||
|
||||
func addGlobalStringWith(conf *Config, arg string, mainPkgs []string, skipIfExists bool) {
|
||||
eq := strings.Index(arg, "=")
|
||||
dot := strings.LastIndex(arg[:eq+1], ".")
|
||||
if eq < 0 || dot < 0 {
|
||||
panic(errXflags)
|
||||
}
|
||||
pkg := arg[:dot]
|
||||
varName := arg[dot+1 : eq]
|
||||
value := arg[eq+1:]
|
||||
validateRewriteInput(pkg, varName, value)
|
||||
pkgs := []string{pkg}
|
||||
if pkg == "main" {
|
||||
pkgs = mainPkgs
|
||||
}
|
||||
if len(pkgs) == 0 {
|
||||
return
|
||||
if conf.GlobalNames == nil {
|
||||
conf.GlobalNames = make(map[string][]string)
|
||||
}
|
||||
if conf.GlobalRewrites == nil {
|
||||
conf.GlobalRewrites = make(map[string]Rewrites)
|
||||
if conf.GlobalDatas == nil {
|
||||
conf.GlobalDatas = make(map[string]string)
|
||||
}
|
||||
for _, realPkg := range pkgs {
|
||||
vars := conf.GlobalRewrites[realPkg]
|
||||
if vars == nil {
|
||||
vars = make(Rewrites)
|
||||
conf.GlobalRewrites[realPkg] = vars
|
||||
for _, pkg := range pkgs {
|
||||
name := pkg + arg[dot:eq]
|
||||
value := arg[eq+1:]
|
||||
if _, ok := conf.GlobalDatas[name]; !ok {
|
||||
conf.GlobalNames[pkg] = append(conf.GlobalNames[pkg], name)
|
||||
}
|
||||
if skipIfExists {
|
||||
if _, exists := vars[varName]; exists {
|
||||
continue
|
||||
}
|
||||
}
|
||||
vars[varName] = value
|
||||
conf.GlobalDatas[name] = value
|
||||
}
|
||||
}
|
||||
|
||||
func validateRewriteInput(pkg, varName, value string) {
|
||||
if pkg == "" || strings.ContainsAny(pkg, " \t\r\n") {
|
||||
panic(fmt.Errorf("invalid package path for rewrite: %q", pkg))
|
||||
func createGlobals(ctx *context, prog llssa.Program, pkgs []*aPackage) (llssa.Package, error) {
|
||||
if len(ctx.buildConf.GlobalDatas) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if !token.IsIdentifier(varName) {
|
||||
panic(fmt.Errorf("invalid variable name for rewrite: %q", varName))
|
||||
for _, pkg := range pkgs {
|
||||
if pkg.ExportFile == "" {
|
||||
continue
|
||||
}
|
||||
if names, ok := ctx.buildConf.GlobalNames[pkg.PkgPath]; ok {
|
||||
err := pkg.LPkg.Undefined(names...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pkg.ExportFile += "-global"
|
||||
pkg.ExportFile, err = exportObject(ctx, pkg.PkgPath+".global", pkg.ExportFile, []byte(pkg.LPkg.String()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(value) > maxRewriteValueLength {
|
||||
panic(fmt.Errorf("rewrite value too large: %d bytes", len(value)))
|
||||
global := prog.NewPackage("", "global")
|
||||
for name, value := range ctx.buildConf.GlobalDatas {
|
||||
global.AddGlobalString(name, value)
|
||||
}
|
||||
return global, nil
|
||||
}
|
||||
|
||||
// compileExtraFiles compiles extra files (.s/.c) from target configuration and returns object files
|
||||
@@ -777,7 +752,7 @@ func compileExtraFiles(ctx *context, verbose bool) ([]string, error) {
|
||||
return objFiles, nil
|
||||
}
|
||||
|
||||
func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, outputPath string, verbose bool) error {
|
||||
func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, global llssa.Package, outputPath string, verbose bool) error {
|
||||
|
||||
needRuntime := false
|
||||
needPyInit := false
|
||||
@@ -794,6 +769,7 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, outputPa
|
||||
if p.ExportFile != "" && aPkg != nil { // skip packages that only contain declarations
|
||||
linkArgs = append(linkArgs, aPkg.LinkArgs...)
|
||||
objFiles = append(objFiles, aPkg.LLFiles...)
|
||||
objFiles = append(objFiles, aPkg.ExportFile)
|
||||
need1, need2 := isNeedRuntimeOrPyInit(ctx, p)
|
||||
if !needRuntime {
|
||||
needRuntime = need1
|
||||
@@ -804,11 +780,11 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, outputPa
|
||||
}
|
||||
})
|
||||
// Generate main module file (needed for global variables even in library modes)
|
||||
entryPkg := genMainModule(ctx, llssa.PkgRuntime, pkg, needRuntime, needPyInit)
|
||||
entryObjFile, err := exportObject(ctx, entryPkg.PkgPath, entryPkg.ExportFile, []byte(entryPkg.LPkg.String()))
|
||||
entryObjFile, err := genMainModuleFile(ctx, llssa.PkgRuntime, pkg, needRuntime, needPyInit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// defer os.Remove(entryLLFile)
|
||||
objFiles = append(objFiles, entryObjFile)
|
||||
|
||||
// Compile extra files from target configuration
|
||||
@@ -818,6 +794,14 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, outputPa
|
||||
}
|
||||
objFiles = append(objFiles, extraObjFiles...)
|
||||
|
||||
if global != nil {
|
||||
export, err := exportObject(ctx, pkg.PkgPath+".global", pkg.ExportFile+"-global", []byte(global.String()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
objFiles = append(objFiles, export)
|
||||
}
|
||||
|
||||
if IsFullRpathEnabled() {
|
||||
// Treat every link-time library search path, specified by the -L parameter, as a runtime search path as well.
|
||||
// This is to ensure the final executable can locate libraries with a relocatable install_name
|
||||
@@ -930,6 +914,118 @@ func needStart(ctx *context) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func genMainModuleFile(ctx *context, rtPkgPath string, pkg *packages.Package, needRuntime, needPyInit bool) (path string, err error) {
|
||||
var (
|
||||
pyInitDecl string
|
||||
pyInit string
|
||||
rtInitDecl string
|
||||
rtInit string
|
||||
)
|
||||
mainPkgPath := pkg.PkgPath
|
||||
if needRuntime {
|
||||
rtInit = "call void @\"" + rtPkgPath + ".init\"()"
|
||||
rtInitDecl = "declare void @\"" + rtPkgPath + ".init\"()"
|
||||
}
|
||||
if needPyInit {
|
||||
pyInit = "call void @Py_Initialize()"
|
||||
pyInitDecl = "declare void @Py_Initialize()"
|
||||
}
|
||||
declSizeT := "%size_t = type i64"
|
||||
if is32Bits(ctx.buildConf.Goarch) {
|
||||
declSizeT = "%size_t = type i32"
|
||||
}
|
||||
stdioDecl := ""
|
||||
stdioNobuf := ""
|
||||
if IsStdioNobuf() {
|
||||
stdioDecl = `
|
||||
@stdout = external global ptr
|
||||
@stderr = external global ptr
|
||||
@__stdout = external global ptr
|
||||
@__stderr = external global ptr
|
||||
declare i32 @setvbuf(ptr, ptr, i32, %size_t)
|
||||
`
|
||||
stdioNobuf = `
|
||||
; Set stdout with no buffer
|
||||
%stdout_is_null = icmp eq ptr @stdout, null
|
||||
%stdout_ptr = select i1 %stdout_is_null, ptr @__stdout, ptr @stdout
|
||||
call i32 @setvbuf(ptr %stdout_ptr, ptr null, i32 2, %size_t 0)
|
||||
; Set stderr with no buffer
|
||||
%stderr_ptr = select i1 %stdout_is_null, ptr @__stderr, ptr @stderr
|
||||
call i32 @setvbuf(ptr %stderr_ptr, ptr null, i32 2, %size_t 0)
|
||||
`
|
||||
}
|
||||
// TODO(lijie): workaround for libc-free
|
||||
// Remove main/_start when -buildmode and libc are ready
|
||||
startDefine := `
|
||||
define weak void @_start() {
|
||||
; argc = 0
|
||||
%argc = add i32 0, 0
|
||||
; argv = null
|
||||
%argv = inttoptr i64 0 to i8**
|
||||
call i32 @main(i32 %argc, i8** %argv)
|
||||
ret void
|
||||
}
|
||||
`
|
||||
mainDefine := "define i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr"
|
||||
if !needStart(ctx) && isWasmTarget(ctx.buildConf.Goos) {
|
||||
mainDefine = "define hidden noundef i32 @__main_argc_argv(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr"
|
||||
}
|
||||
if !needStart(ctx) {
|
||||
startDefine = ""
|
||||
}
|
||||
|
||||
var mainCode string
|
||||
// For library modes (c-archive, c-shared), only generate global variables
|
||||
if ctx.buildConf.BuildMode != BuildModeExe {
|
||||
mainCode = `; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
`
|
||||
} else {
|
||||
// For executable mode, generate full main function
|
||||
mainCode = fmt.Sprintf(`; ModuleID = 'main'
|
||||
source_filename = "main"
|
||||
%s
|
||||
@__llgo_argc = global i32 0, align 4
|
||||
@__llgo_argv = global ptr null, align 8
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
declare void @"%s.init"()
|
||||
declare void @"%s.main"()
|
||||
define weak void @runtime.init() {
|
||||
ret void
|
||||
}
|
||||
|
||||
; TODO(lijie): workaround for syscall patch
|
||||
define weak void @"syscall.init"() {
|
||||
ret void
|
||||
}
|
||||
|
||||
%s
|
||||
|
||||
%s {
|
||||
_llgo_0:
|
||||
store i32 %%0, ptr @__llgo_argc, align 4
|
||||
store ptr %%1, ptr @__llgo_argv, align 8
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
call void @runtime.init()
|
||||
call void @"%s.init"()
|
||||
call void @"%s.main"()
|
||||
ret i32 0
|
||||
}
|
||||
`, declSizeT, stdioDecl,
|
||||
pyInitDecl, rtInitDecl, mainPkgPath, mainPkgPath,
|
||||
startDefine, mainDefine, stdioNobuf,
|
||||
pyInit, rtInit, mainPkgPath, mainPkgPath)
|
||||
}
|
||||
|
||||
return exportObject(ctx, pkg.PkgPath+".main", pkg.ExportFile+"-main", []byte(mainCode))
|
||||
}
|
||||
|
||||
func is32Bits(goarch string) bool {
|
||||
return goarch == "386" || goarch == "arm" || goarch == "mips" || goarch == "wasm"
|
||||
}
|
||||
@@ -954,7 +1050,7 @@ func buildPkg(ctx *context, aPkg *aPackage, verbose bool) error {
|
||||
cl.SetDebug(cl.DbgFlagAll)
|
||||
}
|
||||
|
||||
ret, externs, err := cl.NewPackageEx(ctx.prog, ctx.patches, aPkg.rewriteVars, aPkg.SSA, syntax)
|
||||
ret, externs, err := cl.NewPackageEx(ctx.prog, ctx.patches, aPkg.SSA, syntax)
|
||||
if showDetail {
|
||||
llssa.SetDebug(0)
|
||||
cl.SetDebug(0)
|
||||
@@ -981,11 +1077,10 @@ func buildPkg(ctx *context, aPkg *aPackage, verbose bool) error {
|
||||
aPkg.LinkArgs = append(aPkg.LinkArgs, altLdflags...)
|
||||
}
|
||||
if pkg.ExportFile != "" {
|
||||
exportFile, err := exportObject(ctx, pkg.PkgPath, pkg.ExportFile, []byte(ret.String()))
|
||||
pkg.ExportFile, err = exportObject(ctx, pkg.PkgPath, pkg.ExportFile, []byte(ret.String()))
|
||||
if err != nil {
|
||||
return fmt.Errorf("export object of %v failed: %v", pkgPath, err)
|
||||
}
|
||||
aPkg.LLFiles = append(aPkg.LLFiles, exportFile)
|
||||
if debugBuild || verbose {
|
||||
fmt.Fprintf(os.Stderr, "==> Export %s: %s\n", aPkg.PkgPath, pkg.ExportFile)
|
||||
}
|
||||
@@ -994,15 +1089,11 @@ func buildPkg(ctx *context, aPkg *aPackage, verbose bool) error {
|
||||
}
|
||||
|
||||
func exportObject(ctx *context, pkgPath string, exportFile string, data []byte) (string, error) {
|
||||
base := filepath.Base(exportFile)
|
||||
f, err := os.CreateTemp("", base+"-*.ll")
|
||||
f, err := os.CreateTemp("", "llgo-*.ll")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if _, err := f.Write(data); err != nil {
|
||||
f.Close()
|
||||
return "", err
|
||||
}
|
||||
f.Write(data)
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
return exportFile, err
|
||||
@@ -1020,17 +1111,13 @@ func exportObject(ctx *context, pkgPath string, exportFile string, data []byte)
|
||||
}
|
||||
return exportFile, os.Rename(f.Name(), exportFile)
|
||||
}
|
||||
objFile, err := os.CreateTemp("", base+"-*.o")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
objFile.Close()
|
||||
args := []string{"-o", objFile.Name(), "-c", f.Name(), "-Wno-override-module"}
|
||||
exportFile += ".o"
|
||||
args := []string{"-o", exportFile, "-c", f.Name(), "-Wno-override-module"}
|
||||
if ctx.buildConf.Verbose {
|
||||
fmt.Fprintln(os.Stderr, "clang", args)
|
||||
}
|
||||
cmd := ctx.compiler()
|
||||
return objFile.Name(), cmd.Compile(args...)
|
||||
return exportFile, cmd.Compile(args...)
|
||||
}
|
||||
|
||||
func llcCheck(env *llvm.Env, exportFile string) (msg string, err error) {
|
||||
@@ -1084,9 +1171,8 @@ type aPackage struct {
|
||||
AltPkg *packages.Cached
|
||||
LPkg llssa.Package
|
||||
|
||||
LinkArgs []string
|
||||
LLFiles []string
|
||||
rewriteVars map[string]string
|
||||
LinkArgs []string
|
||||
LLFiles []string
|
||||
}
|
||||
|
||||
type Package = *aPackage
|
||||
@@ -1107,8 +1193,7 @@ func allPkgs(ctx *context, initial []*packages.Package, verbose bool) (all []*aP
|
||||
return
|
||||
}
|
||||
}
|
||||
rewrites := collectRewriteVars(ctx, pkgPath)
|
||||
all = append(all, &aPackage{p, ssaPkg, altPkg, nil, nil, nil, rewrites})
|
||||
all = append(all, &aPackage{p, ssaPkg, altPkg, nil, nil, nil})
|
||||
} else {
|
||||
errs = append(errs, p)
|
||||
}
|
||||
@@ -1116,32 +1201,6 @@ func allPkgs(ctx *context, initial []*packages.Package, verbose bool) (all []*aP
|
||||
return
|
||||
}
|
||||
|
||||
func collectRewriteVars(ctx *context, pkgPath string) map[string]string {
|
||||
data := ctx.buildConf.GlobalRewrites
|
||||
if len(data) == 0 {
|
||||
return nil
|
||||
}
|
||||
basePath := strings.TrimPrefix(pkgPath, altPkgPathPrefix)
|
||||
if vars := data[basePath]; vars != nil {
|
||||
return cloneRewrites(vars)
|
||||
}
|
||||
if vars := data[pkgPath]; vars != nil {
|
||||
return cloneRewrites(vars)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cloneRewrites(src Rewrites) map[string]string {
|
||||
if len(src) == 0 {
|
||||
return nil
|
||||
}
|
||||
dup := make(map[string]string, len(src))
|
||||
for k, v := range src {
|
||||
dup[k] = v
|
||||
}
|
||||
return dup
|
||||
}
|
||||
|
||||
func createSSAPkg(prog *ssa.Program, p *packages.Package, verbose bool) *ssa.Package {
|
||||
pkgSSA := prog.ImportedPackage(p.ID)
|
||||
if pkgSSA == nil {
|
||||
|
||||
@@ -8,9 +8,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/goplus/llgo/internal/mockable"
|
||||
@@ -97,70 +94,4 @@ func TestCmpTest(t *testing.T) {
|
||||
mockRun([]string{"../../cl/_testgo/runtest"}, &Config{Mode: ModeCmpTest})
|
||||
}
|
||||
|
||||
const (
|
||||
rewriteMainPkg = "github.com/goplus/llgo/cl/_testgo/rewrite"
|
||||
rewriteDepPkg = rewriteMainPkg + "/dep"
|
||||
rewriteDirPath = "../../cl/_testgo/rewrite"
|
||||
)
|
||||
|
||||
func TestLdFlagsRewriteVars(t *testing.T) {
|
||||
buildRewriteBinary(t, false, "build-main", "build-pkg")
|
||||
buildRewriteBinary(t, false, "rerun-main", "rerun-pkg")
|
||||
}
|
||||
|
||||
func TestLdFlagsRewriteVarsMainAlias(t *testing.T) {
|
||||
buildRewriteBinary(t, true, "alias-main", "alias-pkg")
|
||||
}
|
||||
|
||||
func buildRewriteBinary(t *testing.T, useMainAlias bool, mainVal, depVal string) {
|
||||
t.Helper()
|
||||
binPath := filepath.Join(t.TempDir(), "rewrite")
|
||||
if runtime.GOOS == "windows" {
|
||||
binPath += ".exe"
|
||||
}
|
||||
|
||||
cfg := &Config{Mode: ModeBuild, OutFile: binPath}
|
||||
mainKey := rewriteMainPkg
|
||||
var mainPkgs []string
|
||||
if useMainAlias {
|
||||
mainKey = "main"
|
||||
mainPkgs = []string{rewriteMainPkg}
|
||||
}
|
||||
mainPlain := mainVal + "-plain"
|
||||
depPlain := depVal + "-plain"
|
||||
gorootVal := "goroot-" + mainVal
|
||||
versionVal := "version-" + mainVal
|
||||
addGlobalString(cfg, mainKey+".VarName="+mainVal, mainPkgs)
|
||||
addGlobalString(cfg, mainKey+".VarPlain="+mainPlain, mainPkgs)
|
||||
addGlobalString(cfg, rewriteDepPkg+".VarName="+depVal, nil)
|
||||
addGlobalString(cfg, rewriteDepPkg+".VarPlain="+depPlain, nil)
|
||||
addGlobalString(cfg, "runtime.defaultGOROOT="+gorootVal, nil)
|
||||
addGlobalString(cfg, "runtime.buildVersion="+versionVal, nil)
|
||||
|
||||
if _, err := Do([]string{rewriteDirPath}, cfg); err != nil {
|
||||
t.Fatalf("ModeBuild failed: %v", err)
|
||||
}
|
||||
got := runBinary(t, binPath)
|
||||
want := fmt.Sprintf(
|
||||
"main.VarName: %s\nmain.VarPlain: %s\ndep.VarName: %s\ndep.VarPlain: %s\nruntime.GOROOT(): %s\nruntime.Version(): %s\n",
|
||||
mainVal, mainPlain, depVal, depPlain, gorootVal, versionVal,
|
||||
)
|
||||
if got != want {
|
||||
t.Fatalf("unexpected binary output:\nwant %q\ngot %q", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func runBinary(t *testing.T, path string, args ...string) string {
|
||||
t.Helper()
|
||||
cmd := exec.Command(path, args...)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run %s: %v\n%s", path, err, output)
|
||||
}
|
||||
return string(output)
|
||||
}
|
||||
|
||||
func TestRunPrintfWithStdioNobuf(t *testing.T) {
|
||||
t.Setenv(llgoStdioNobuf, "1")
|
||||
mockRun([]string{"../../cl/_testdata/printf"}, &Config{Mode: ModeRun})
|
||||
}
|
||||
// TestGenerateOutputFilenames removed - functionality moved to filename_test.go
|
||||
|
||||
@@ -1,231 +0,0 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
/*
|
||||
* 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 build contains the llgo compiler build orchestration logic.
|
||||
//
|
||||
// The main_module.go file generates the entry point module for llgo programs,
|
||||
// which contains the main() function, initialization sequence, and global
|
||||
// variables like argc/argv. This module is generated differently depending on
|
||||
// BuildMode (exe, c-archive, c-shared).
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"go/token"
|
||||
"go/types"
|
||||
|
||||
"github.com/goplus/llgo/internal/packages"
|
||||
llvm "github.com/goplus/llvm"
|
||||
|
||||
llssa "github.com/goplus/llgo/ssa"
|
||||
)
|
||||
|
||||
// genMainModule generates the main entry module for an llgo program.
|
||||
//
|
||||
// The module contains argc/argv globals and, for executable build modes,
|
||||
// the entry function that wires initialization and main. For C archive or
|
||||
// shared library modes, only the globals are emitted.
|
||||
func genMainModule(ctx *context, rtPkgPath string, pkg *packages.Package, needRuntime, needPyInit bool) Package {
|
||||
prog := ctx.prog
|
||||
mainPkg := prog.NewPackage("", pkg.ID+".main")
|
||||
|
||||
argcVar := mainPkg.NewVarEx("__llgo_argc", prog.Pointer(prog.Int32()))
|
||||
argcVar.Init(prog.Zero(prog.Int32()))
|
||||
|
||||
argvValueType := prog.Pointer(prog.CStr())
|
||||
argvVar := mainPkg.NewVarEx("__llgo_argv", prog.Pointer(argvValueType))
|
||||
argvVar.InitNil()
|
||||
|
||||
exportFile := pkg.ExportFile
|
||||
if exportFile == "" {
|
||||
exportFile = pkg.PkgPath
|
||||
}
|
||||
mainAPkg := &aPackage{
|
||||
Package: &packages.Package{
|
||||
PkgPath: pkg.PkgPath + ".main",
|
||||
ExportFile: exportFile + "-main",
|
||||
},
|
||||
LPkg: mainPkg,
|
||||
}
|
||||
|
||||
if ctx.buildConf.BuildMode != BuildModeExe {
|
||||
return mainAPkg
|
||||
}
|
||||
|
||||
runtimeStub := defineWeakNoArgStub(mainPkg, "runtime.init")
|
||||
// TODO(lijie): workaround for syscall patch
|
||||
defineWeakNoArgStub(mainPkg, "syscall.init")
|
||||
|
||||
var pyInit llssa.Function
|
||||
if needPyInit {
|
||||
pyInit = declareNoArgFunc(mainPkg, "Py_Initialize")
|
||||
}
|
||||
|
||||
var rtInit llssa.Function
|
||||
if needRuntime {
|
||||
rtInit = declareNoArgFunc(mainPkg, rtPkgPath+".init")
|
||||
}
|
||||
|
||||
mainInit := declareNoArgFunc(mainPkg, pkg.PkgPath+".init")
|
||||
mainMain := declareNoArgFunc(mainPkg, pkg.PkgPath+".main")
|
||||
|
||||
entryFn := defineEntryFunction(ctx, mainPkg, argcVar, argvVar, argvValueType, runtimeStub, mainInit, mainMain, pyInit, rtInit)
|
||||
|
||||
if needStart(ctx) {
|
||||
defineStart(mainPkg, entryFn, argvValueType)
|
||||
}
|
||||
|
||||
return mainAPkg
|
||||
}
|
||||
|
||||
// defineEntryFunction creates the program's entry function. The name is
|
||||
// "main" for standard targets, or "__main_argc_argv" with hidden visibility
|
||||
// for WASM targets that don't require _start.
|
||||
//
|
||||
// The entry stores argc/argv, optionally disables stdio buffering, runs
|
||||
// initialization hooks (Python, runtime, package init), and finally calls
|
||||
// main.main before returning 0.
|
||||
func defineEntryFunction(ctx *context, pkg llssa.Package, argcVar, argvVar llssa.Global, argvType llssa.Type, runtimeStub, mainInit, mainMain llssa.Function, pyInit, rtInit llssa.Function) llssa.Function {
|
||||
prog := pkg.Prog
|
||||
entryName := "main"
|
||||
if !needStart(ctx) && isWasmTarget(ctx.buildConf.Goos) {
|
||||
entryName = "__main_argc_argv"
|
||||
}
|
||||
sig := newEntrySignature(argvType.RawType())
|
||||
fn := pkg.NewFunc(entryName, sig, llssa.InC)
|
||||
fnVal := pkg.Module().NamedFunction(entryName)
|
||||
if entryName != "main" {
|
||||
fnVal.SetVisibility(llvm.HiddenVisibility)
|
||||
fnVal.SetUnnamedAddr(true)
|
||||
}
|
||||
b := fn.MakeBody(1)
|
||||
b.Store(argcVar.Expr, fn.Param(0))
|
||||
b.Store(argvVar.Expr, fn.Param(1))
|
||||
if IsStdioNobuf() {
|
||||
emitStdioNobuf(b, pkg, ctx.buildConf.Goos)
|
||||
}
|
||||
if pyInit != nil {
|
||||
b.Call(pyInit.Expr)
|
||||
}
|
||||
if rtInit != nil {
|
||||
b.Call(rtInit.Expr)
|
||||
}
|
||||
b.Call(runtimeStub.Expr)
|
||||
b.Call(mainInit.Expr)
|
||||
b.Call(mainMain.Expr)
|
||||
b.Return(prog.IntVal(0, prog.Int32()))
|
||||
return fn
|
||||
}
|
||||
|
||||
func defineStart(pkg llssa.Package, entry llssa.Function, argvType llssa.Type) {
|
||||
fn := pkg.NewFunc("_start", llssa.NoArgsNoRet, llssa.InC)
|
||||
pkg.Module().NamedFunction("_start").SetLinkage(llvm.WeakAnyLinkage)
|
||||
b := fn.MakeBody(1)
|
||||
prog := pkg.Prog
|
||||
b.Call(entry.Expr, prog.IntVal(0, prog.Int32()), prog.Nil(argvType))
|
||||
b.Return()
|
||||
}
|
||||
|
||||
func declareNoArgFunc(pkg llssa.Package, name string) llssa.Function {
|
||||
return pkg.NewFunc(name, llssa.NoArgsNoRet, llssa.InC)
|
||||
}
|
||||
|
||||
func defineWeakNoArgStub(pkg llssa.Package, name string) llssa.Function {
|
||||
fn := pkg.NewFunc(name, llssa.NoArgsNoRet, llssa.InC)
|
||||
pkg.Module().NamedFunction(name).SetLinkage(llvm.WeakAnyLinkage)
|
||||
b := fn.MakeBody(1)
|
||||
b.Return()
|
||||
return fn
|
||||
}
|
||||
|
||||
const (
|
||||
// ioNoBuf represents the _IONBF flag for setvbuf (no buffering)
|
||||
ioNoBuf = 2
|
||||
)
|
||||
|
||||
// emitStdioNobuf generates code to disable buffering on stdout and stderr
|
||||
// when the LLGO_STDIO_NOBUF environment variable is set. Only Darwin uses
|
||||
// the alternate `__stdoutp`/`__stderrp` symbols; other targets rely on the
|
||||
// standard `stdout`/`stderr` globals.
|
||||
func emitStdioNobuf(b llssa.Builder, pkg llssa.Package, goos string) {
|
||||
prog := pkg.Prog
|
||||
streamType := prog.VoidPtr()
|
||||
streamPtrType := prog.Pointer(streamType)
|
||||
|
||||
stdoutName := "stdout"
|
||||
stderrName := "stderr"
|
||||
if goos == "darwin" {
|
||||
stdoutName = "__stdoutp"
|
||||
stderrName = "__stderrp"
|
||||
}
|
||||
stdout := declareExternalPtrGlobal(pkg, stdoutName, streamPtrType)
|
||||
stderr := declareExternalPtrGlobal(pkg, stderrName, streamPtrType)
|
||||
stdoutPtr := b.Load(stdout)
|
||||
stderrPtr := b.Load(stderr)
|
||||
sizeType := prog.Uintptr()
|
||||
setvbuf := declareSetvbuf(pkg, streamPtrType, prog.CStr(), prog.Int32(), sizeType)
|
||||
|
||||
noBufMode := prog.IntVal(ioNoBuf, prog.Int32())
|
||||
zeroSize := prog.Zero(sizeType)
|
||||
nullBuf := prog.Nil(prog.CStr())
|
||||
|
||||
b.Call(setvbuf.Expr, stdoutPtr, nullBuf, noBufMode, zeroSize)
|
||||
b.Call(setvbuf.Expr, stderrPtr, nullBuf, noBufMode, zeroSize)
|
||||
}
|
||||
|
||||
func declareExternalPtrGlobal(pkg llssa.Package, name string, valueType llssa.Type) llssa.Expr {
|
||||
global := pkg.NewVarEx(name, valueType)
|
||||
pkg.Module().NamedGlobal(name).SetLinkage(llvm.ExternalLinkage)
|
||||
return global.Expr
|
||||
}
|
||||
|
||||
func declareSetvbuf(pkg llssa.Package, streamPtrType, bufPtrType, intType, sizeType llssa.Type) llssa.Function {
|
||||
sig := newSignature(
|
||||
[]types.Type{
|
||||
streamPtrType.RawType(),
|
||||
bufPtrType.RawType(),
|
||||
intType.RawType(),
|
||||
sizeType.RawType(),
|
||||
},
|
||||
[]types.Type{intType.RawType()},
|
||||
)
|
||||
return pkg.NewFunc("setvbuf", sig, llssa.InC)
|
||||
}
|
||||
|
||||
func tupleOf(tys ...types.Type) *types.Tuple {
|
||||
if len(tys) == 0 {
|
||||
return types.NewTuple()
|
||||
}
|
||||
vars := make([]*types.Var, len(tys))
|
||||
for i, t := range tys {
|
||||
vars[i] = types.NewParam(token.NoPos, nil, "", t)
|
||||
}
|
||||
return types.NewTuple(vars...)
|
||||
}
|
||||
|
||||
func newSignature(params []types.Type, results []types.Type) *types.Signature {
|
||||
return types.NewSignatureType(nil, nil, nil, tupleOf(params...), tupleOf(results...), false)
|
||||
}
|
||||
|
||||
func newEntrySignature(argvType types.Type) *types.Signature {
|
||||
return newSignature(
|
||||
[]types.Type{types.Typ[types.Int32], argvType},
|
||||
[]types.Type{types.Typ[types.Int32]},
|
||||
)
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
//go:build !llgo
|
||||
// +build !llgo
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/goplus/llvm"
|
||||
|
||||
"github.com/goplus/llgo/internal/packages"
|
||||
llssa "github.com/goplus/llgo/ssa"
|
||||
)
|
||||
|
||||
func init() {
|
||||
llssa.Initialize(llssa.InitAll)
|
||||
}
|
||||
|
||||
func TestGenMainModuleExecutable(t *testing.T) {
|
||||
llvm.InitializeAllTargets()
|
||||
t.Setenv(llgoStdioNobuf, "")
|
||||
ctx := &context{
|
||||
prog: llssa.NewProgram(nil),
|
||||
buildConf: &Config{
|
||||
BuildMode: BuildModeExe,
|
||||
Goos: "linux",
|
||||
Goarch: "amd64",
|
||||
},
|
||||
}
|
||||
pkg := &packages.Package{PkgPath: "example.com/foo", ExportFile: "foo.a"}
|
||||
mod := genMainModule(ctx, llssa.PkgRuntime, pkg, true, true)
|
||||
if mod.ExportFile != "foo.a-main" {
|
||||
t.Fatalf("unexpected export file: %s", mod.ExportFile)
|
||||
}
|
||||
ir := mod.LPkg.String()
|
||||
checks := []string{
|
||||
"define i32 @main(",
|
||||
"call void @Py_Initialize()",
|
||||
"call void @\"example.com/foo.init\"()",
|
||||
"define weak void @_start()",
|
||||
}
|
||||
for _, want := range checks {
|
||||
if !strings.Contains(ir, want) {
|
||||
t.Fatalf("main module IR missing %q:\n%s", want, ir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenMainModuleLibrary(t *testing.T) {
|
||||
llvm.InitializeAllTargets()
|
||||
t.Setenv(llgoStdioNobuf, "")
|
||||
ctx := &context{
|
||||
prog: llssa.NewProgram(nil),
|
||||
buildConf: &Config{
|
||||
BuildMode: BuildModeCArchive,
|
||||
Goos: "linux",
|
||||
Goarch: "amd64",
|
||||
},
|
||||
}
|
||||
pkg := &packages.Package{PkgPath: "example.com/foo", ExportFile: "foo.a"}
|
||||
mod := genMainModule(ctx, llssa.PkgRuntime, pkg, false, false)
|
||||
ir := mod.LPkg.String()
|
||||
if strings.Contains(ir, "define i32 @main") {
|
||||
t.Fatalf("library mode should not emit main function:\n%s", ir)
|
||||
}
|
||||
if !strings.Contains(ir, "@__llgo_argc = global i32 0") {
|
||||
t.Fatalf("library mode missing argc global:\n%s", ir)
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package build
|
||||
|
||||
import "strings"
|
||||
|
||||
// nameResolver maps symbol names to aggregation buckets based on the requested level.
|
||||
type nameResolver struct {
|
||||
level string
|
||||
pkgs []Package
|
||||
moduleMap map[string]string
|
||||
packageMap map[string]string
|
||||
}
|
||||
|
||||
func newNameResolver(level string, pkgs []Package) *nameResolver {
|
||||
lvl := strings.ToLower(strings.TrimSpace(level))
|
||||
if lvl == "" {
|
||||
lvl = "module"
|
||||
}
|
||||
return &nameResolver{
|
||||
level: lvl,
|
||||
pkgs: pkgs,
|
||||
moduleMap: make(map[string]string),
|
||||
packageMap: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *nameResolver) resolve(sym string) string {
|
||||
base := moduleNameFromSymbol(sym)
|
||||
symbol := trimSymbolForMatch(sym)
|
||||
switch r.level {
|
||||
case "full":
|
||||
return base
|
||||
case "package":
|
||||
if pkg := r.matchPackage(symbol); pkg != "" {
|
||||
return pkg
|
||||
}
|
||||
case "module":
|
||||
if mod := r.matchModule(symbol); mod != "" {
|
||||
return mod
|
||||
}
|
||||
}
|
||||
if strings.Contains(symbol, "llgo") {
|
||||
return "llgo-stubs"
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
func (r *nameResolver) matchPackage(symbol string) string {
|
||||
if symbol == "" {
|
||||
return ""
|
||||
}
|
||||
if cached := r.packageMap[symbol]; cached != "" {
|
||||
return cached
|
||||
}
|
||||
for _, pkg := range r.pkgs {
|
||||
if pkg == nil || pkg.Package == nil {
|
||||
continue
|
||||
}
|
||||
id := pkg.PkgPath
|
||||
if id == "" {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(symbol, id+".") {
|
||||
r.packageMap[symbol] = id
|
||||
return id
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (r *nameResolver) matchModule(symbol string) string {
|
||||
if symbol == "" {
|
||||
return ""
|
||||
}
|
||||
if cached := r.moduleMap[symbol]; cached != "" {
|
||||
return cached
|
||||
}
|
||||
for _, pkg := range r.pkgs {
|
||||
if pkg == nil || pkg.Package == nil {
|
||||
continue
|
||||
}
|
||||
path := pkg.PkgPath
|
||||
if path == "" {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(symbol, path+".") {
|
||||
mod := path
|
||||
if pkg.Module != nil && pkg.Module.Path != "" {
|
||||
mod = pkg.Module.Path
|
||||
}
|
||||
r.moduleMap[symbol] = mod
|
||||
return mod
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func trimSymbolForMatch(sym string) string {
|
||||
name := strings.TrimSpace(sym)
|
||||
for len(name) > 0 && (name[0] == '_' || name[0] == '.') {
|
||||
name = name[1:]
|
||||
}
|
||||
if idx := strings.Index(name, " "); idx >= 0 {
|
||||
name = name[:idx]
|
||||
}
|
||||
if idx := strings.Index(name, "@"); idx >= 0 {
|
||||
name = name[:idx]
|
||||
}
|
||||
return name
|
||||
}
|
||||
@@ -1,627 +0,0 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/goplus/llgo/xtool/env/llvm"
|
||||
)
|
||||
|
||||
type sectionKind int
|
||||
|
||||
const (
|
||||
sectionUnknown sectionKind = iota
|
||||
sectionText
|
||||
sectionROData
|
||||
sectionData
|
||||
sectionBSS
|
||||
)
|
||||
|
||||
const (
|
||||
// readelfInitialBuffer is the initial buffer size for reading readelf output.
|
||||
// Most lines in readelf output are less than 1KB.
|
||||
readelfInitialBuffer = 64 * 1024
|
||||
|
||||
// readelfMaxBuffer is the maximum buffer size to handle very long symbol names
|
||||
// or section dumps. Reduced from 64MB to prevent excessive memory consumption
|
||||
// while still accommodating reasonably large binaries.
|
||||
readelfMaxBuffer = 4 * 1024 * 1024
|
||||
)
|
||||
|
||||
// ELF special section indices (from ELF specification)
|
||||
const (
|
||||
SHN_UNDEF = 0x0000 // Undefined section
|
||||
SHN_LORESERVE = 0xFF00 // Start of reserved indices
|
||||
SHN_ABS = 0xFFF1 // Absolute values
|
||||
SHN_COMMON = 0xFFF2 // Common symbols
|
||||
SHN_XINDEX = 0xFFFF // Escape value for extended section indices
|
||||
)
|
||||
|
||||
type sectionInfo struct {
|
||||
Index int
|
||||
Name string
|
||||
Segment string
|
||||
Address uint64
|
||||
Size uint64
|
||||
Kind sectionKind
|
||||
}
|
||||
|
||||
type symbolInfo struct {
|
||||
Name string
|
||||
SectionIndex int
|
||||
Address uint64
|
||||
}
|
||||
|
||||
type readelfData struct {
|
||||
sections map[int]*sectionInfo
|
||||
symbols map[int][]symbolInfo
|
||||
}
|
||||
|
||||
type moduleSize struct {
|
||||
Name string
|
||||
Code uint64
|
||||
ROData uint64
|
||||
Data uint64
|
||||
BSS uint64
|
||||
}
|
||||
|
||||
func (m *moduleSize) Flash() uint64 {
|
||||
return m.Code + m.ROData + m.Data
|
||||
}
|
||||
|
||||
func (m *moduleSize) RAM() uint64 {
|
||||
return m.Data + m.BSS
|
||||
}
|
||||
|
||||
type sizeReport struct {
|
||||
Binary string
|
||||
Modules map[string]*moduleSize
|
||||
Total moduleSize
|
||||
}
|
||||
|
||||
func (r *sizeReport) module(name string) *moduleSize {
|
||||
if name == "" {
|
||||
name = "(anonymous)"
|
||||
}
|
||||
if r.Modules == nil {
|
||||
r.Modules = make(map[string]*moduleSize)
|
||||
}
|
||||
m, ok := r.Modules[name]
|
||||
if !ok {
|
||||
m = &moduleSize{Name: name}
|
||||
r.Modules[name] = m
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (r *sizeReport) add(name string, kind sectionKind, size uint64) {
|
||||
if size == 0 {
|
||||
return
|
||||
}
|
||||
m := r.module(name)
|
||||
switch kind {
|
||||
case sectionText:
|
||||
m.Code += size
|
||||
r.Total.Code += size
|
||||
case sectionROData:
|
||||
m.ROData += size
|
||||
r.Total.ROData += size
|
||||
case sectionData:
|
||||
m.Data += size
|
||||
r.Total.Data += size
|
||||
case sectionBSS:
|
||||
m.BSS += size
|
||||
r.Total.BSS += size
|
||||
}
|
||||
}
|
||||
|
||||
func reportBinarySize(path, format, level string, pkgs []Package) error {
|
||||
report, err := collectBinarySize(path, pkgs, level)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch format {
|
||||
case "", "text":
|
||||
printTextReport(os.Stdout, report)
|
||||
case "json":
|
||||
return emitJSONReport(os.Stdout, report)
|
||||
default:
|
||||
return fmt.Errorf("unknown size format %q (valid: text,json)", format)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func collectBinarySize(path string, pkgs []Package, level string) (*sizeReport, error) {
|
||||
cmd, err := llvm.New("").Readelf("--elf-output-style=LLVM", "--all", path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("llvm-readelf: %w", err)
|
||||
}
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("llvm-readelf stdout: %w", err)
|
||||
}
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, fmt.Errorf("failed to execute llvm-readelf: %w", err)
|
||||
}
|
||||
parsed, parseErr := parseReadelfOutput(stdout)
|
||||
closeErr := stdout.Close()
|
||||
waitErr := cmd.Wait()
|
||||
if waitErr != nil {
|
||||
return nil, fmt.Errorf("llvm-readelf failed: %w\n%s", waitErr, stderr.String())
|
||||
}
|
||||
if parseErr != nil {
|
||||
return nil, fmt.Errorf("parsing llvm-readelf output failed: %w", parseErr)
|
||||
}
|
||||
if closeErr != nil {
|
||||
return nil, fmt.Errorf("closing llvm-readelf stdout pipe failed: %w", closeErr)
|
||||
}
|
||||
report := buildSizeReport(path, parsed, pkgs, level)
|
||||
if report == nil || len(report.Modules) == 0 {
|
||||
return nil, fmt.Errorf("size report: no allocatable sections found in %s", path)
|
||||
}
|
||||
return report, nil
|
||||
}
|
||||
|
||||
func parseReadelfOutput(r io.Reader) (*readelfData, error) {
|
||||
scanner := bufio.NewScanner(r)
|
||||
scanner.Buffer(make([]byte, 0, readelfInitialBuffer), readelfMaxBuffer)
|
||||
|
||||
type ctxKind int
|
||||
const (
|
||||
ctxRoot ctxKind = iota
|
||||
ctxSections
|
||||
ctxSection
|
||||
ctxSymbols
|
||||
ctxSymbol
|
||||
)
|
||||
|
||||
type ctx struct {
|
||||
kind ctxKind
|
||||
indent int
|
||||
}
|
||||
|
||||
stack := []ctx{{kind: ctxRoot, indent: -1}}
|
||||
push := func(kind ctxKind, indent int) {
|
||||
stack = append(stack, ctx{kind: kind, indent: indent})
|
||||
}
|
||||
pop := func(expected ctxKind, indent int) bool {
|
||||
top := stack[len(stack)-1]
|
||||
if top.kind != expected || top.indent != indent {
|
||||
return false
|
||||
}
|
||||
stack = stack[:len(stack)-1]
|
||||
return true
|
||||
}
|
||||
current := func() ctx {
|
||||
return stack[len(stack)-1]
|
||||
}
|
||||
|
||||
data := &readelfData{
|
||||
sections: make(map[int]*sectionInfo),
|
||||
symbols: make(map[int][]symbolInfo),
|
||||
}
|
||||
|
||||
// readelf outputs section references differently:
|
||||
// - Mach-O: section numbers are 1-based in symbol references
|
||||
// - ELF: section numbers in symbol references match the Index directly
|
||||
secIndexBase := 1 // default to Mach-O behavior; switch to 0 for ELF once detected
|
||||
|
||||
var currentSection *sectionInfo
|
||||
var currentSymbol *symbolInfo
|
||||
|
||||
for scanner.Scan() {
|
||||
raw := scanner.Text()
|
||||
trimmed := strings.TrimSpace(raw)
|
||||
if trimmed == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Detect object format early to adjust section index base
|
||||
if strings.HasPrefix(trimmed, "Format:") {
|
||||
lower := strings.ToLower(trimmed)
|
||||
if strings.Contains(lower, "mach-o") {
|
||||
secIndexBase = 1
|
||||
} else if strings.Contains(lower, "elf") {
|
||||
secIndexBase = 0
|
||||
}
|
||||
}
|
||||
indent := countLeadingSpaces(raw)
|
||||
top := current()
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(trimmed, "Sections [") && top.kind == ctxRoot:
|
||||
push(ctxSections, indent)
|
||||
continue
|
||||
case strings.HasPrefix(trimmed, "Symbols [") && top.kind == ctxRoot:
|
||||
push(ctxSymbols, indent)
|
||||
continue
|
||||
case trimmed == "Section {" && top.kind == ctxSections && indent == top.indent+2:
|
||||
currentSection = §ionInfo{Index: -1}
|
||||
push(ctxSection, indent)
|
||||
continue
|
||||
case trimmed == "Symbol {" && top.kind == ctxSymbols && indent == top.indent+2:
|
||||
currentSymbol = &symbolInfo{SectionIndex: -1}
|
||||
push(ctxSymbol, indent)
|
||||
continue
|
||||
case trimmed == "}" && pop(ctxSection, indent):
|
||||
if currentSection != nil && currentSection.Index >= 0 {
|
||||
currentSection.Kind = classifySection(currentSection.Name, currentSection.Segment)
|
||||
data.sections[currentSection.Index] = currentSection
|
||||
}
|
||||
currentSection = nil
|
||||
continue
|
||||
case trimmed == "}" && pop(ctxSymbol, indent):
|
||||
if currentSymbol != nil && currentSymbol.SectionIndex >= 0 {
|
||||
data.symbols[currentSymbol.SectionIndex] = append(data.symbols[currentSymbol.SectionIndex], *currentSymbol)
|
||||
}
|
||||
currentSymbol = nil
|
||||
continue
|
||||
case trimmed == "]" && (top.kind == ctxSections || top.kind == ctxSymbols) && indent == top.indent:
|
||||
stack = stack[:len(stack)-1]
|
||||
continue
|
||||
}
|
||||
|
||||
switch top.kind {
|
||||
case ctxSection:
|
||||
if currentSection == nil {
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case strings.HasPrefix(trimmed, "Index: "):
|
||||
if idx, err := strconv.Atoi(strings.TrimSpace(trimmed[len("Index: "):])); err == nil {
|
||||
currentSection.Index = idx
|
||||
}
|
||||
case strings.HasPrefix(trimmed, "Name: "):
|
||||
currentSection.Name = parseNameField(trimmed[len("Name: "):])
|
||||
case strings.HasPrefix(trimmed, "Segment: "):
|
||||
currentSection.Segment = parseNameField(trimmed[len("Segment: "):])
|
||||
case strings.HasPrefix(trimmed, "Address: "):
|
||||
if val, err := parseUintField(trimmed[len("Address: "):]); err == nil {
|
||||
currentSection.Address = val
|
||||
}
|
||||
case strings.HasPrefix(trimmed, "Size: "):
|
||||
if val, err := parseUintField(trimmed[len("Size: "):]); err == nil {
|
||||
currentSection.Size = val
|
||||
}
|
||||
}
|
||||
case ctxSymbol:
|
||||
if currentSymbol == nil {
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case strings.HasPrefix(trimmed, "Name: "):
|
||||
currentSymbol.Name = parseNameField(trimmed[len("Name: "):])
|
||||
case strings.HasPrefix(trimmed, "Section: "):
|
||||
name, idx := parseSectionRef(trimmed[len("Section: "):], secIndexBase)
|
||||
currentSymbol.SectionIndex = idx
|
||||
if currentSymbol.Name == "" {
|
||||
currentSymbol.Name = name
|
||||
}
|
||||
case strings.HasPrefix(trimmed, "Value: "):
|
||||
if val, err := parseUintField(trimmed[len("Value: "):]); err == nil {
|
||||
currentSymbol.Address = val
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func countLeadingSpaces(line string) int {
|
||||
count := 0
|
||||
for _, ch := range line {
|
||||
if ch != ' ' {
|
||||
break
|
||||
}
|
||||
count++
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func classifySection(name, segment string) sectionKind {
|
||||
ln := strings.ToLower(name)
|
||||
ls := strings.ToLower(segment)
|
||||
switch {
|
||||
case strings.Contains(ln, "text"), strings.Contains(ln, "code"), strings.Contains(ln, "plt"):
|
||||
return sectionText
|
||||
case strings.Contains(ln, "rodata"), strings.Contains(ln, "const"), strings.Contains(ln, "literal"), strings.Contains(ln, "cstring"):
|
||||
return sectionROData
|
||||
case strings.Contains(ln, "bss"), strings.Contains(ln, "tbss"), strings.Contains(ln, "sbss"), strings.Contains(ln, "common"), strings.Contains(ln, "zerofill"):
|
||||
return sectionBSS
|
||||
case strings.Contains(ln, "data"), strings.Contains(ln, "got"), strings.Contains(ln, "init_array"), strings.Contains(ln, "cfstring"), strings.Contains(ln, "tdata"):
|
||||
return sectionData
|
||||
}
|
||||
switch {
|
||||
case strings.Contains(ls, "__text"):
|
||||
return sectionText
|
||||
case strings.Contains(ls, "data_const"):
|
||||
return sectionROData
|
||||
case strings.Contains(ls, "__data"):
|
||||
return sectionData
|
||||
}
|
||||
return sectionUnknown
|
||||
}
|
||||
|
||||
func buildSizeReport(path string, data *readelfData, pkgs []Package, level string) *sizeReport {
|
||||
report := &sizeReport{Binary: path, Modules: make(map[string]*moduleSize)}
|
||||
if data == nil {
|
||||
return report
|
||||
}
|
||||
res := newNameResolver(level, pkgs)
|
||||
var recognized bool
|
||||
for idx, sec := range data.sections {
|
||||
if sec == nil || sec.Size == 0 {
|
||||
continue
|
||||
}
|
||||
if sec.Kind == sectionUnknown {
|
||||
continue
|
||||
}
|
||||
recognized = true
|
||||
end := sec.Address + sec.Size
|
||||
syms := data.symbols[idx]
|
||||
if len(syms) == 0 {
|
||||
report.add("(unknown "+sec.Name+")", sec.Kind, sec.Size)
|
||||
continue
|
||||
}
|
||||
// Sort symbols by address to calculate sizes based on address ranges
|
||||
sort.Slice(syms, func(i, j int) bool {
|
||||
if syms[i].Address == syms[j].Address {
|
||||
return syms[i].Name < syms[j].Name
|
||||
}
|
||||
return syms[i].Address < syms[j].Address
|
||||
})
|
||||
cursor := sec.Address
|
||||
for i := 0; i < len(syms); i++ {
|
||||
sym := syms[i]
|
||||
// Skip symbols that are beyond the section bounds
|
||||
if sym.Address >= end {
|
||||
continue
|
||||
}
|
||||
addr := sym.Address
|
||||
// Clamp symbol address to section start if it's before the section
|
||||
if addr < sec.Address {
|
||||
addr = sec.Address
|
||||
}
|
||||
// Add padding bytes between cursor and current symbol
|
||||
if addr > cursor {
|
||||
report.add("(padding "+sec.Name+")", sec.Kind, addr-cursor)
|
||||
cursor = addr
|
||||
}
|
||||
// Find the next symbol address to calculate this symbol's size.
|
||||
// Symbols at the same address are handled by taking the next different address.
|
||||
next := end
|
||||
// Optimize: check next symbol first before scanning
|
||||
if i+1 < len(syms) && syms[i+1].Address > addr {
|
||||
next = syms[i+1].Address
|
||||
} else {
|
||||
// Only search if next symbol is at same address
|
||||
for j := i + 1; j < len(syms); j++ {
|
||||
if syms[j].Address > addr {
|
||||
next = syms[j].Address
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if next > end {
|
||||
next = end
|
||||
}
|
||||
// Skip symbols with zero size
|
||||
if next <= addr {
|
||||
continue
|
||||
}
|
||||
// Attribute the address range [addr, next) to the symbol's module
|
||||
mod := res.resolve(sym.Name)
|
||||
report.add(mod, sec.Kind, next-addr)
|
||||
cursor = next
|
||||
}
|
||||
// Add any remaining padding at the end of the section
|
||||
if cursor < end {
|
||||
report.add("(padding "+sec.Name+")", sec.Kind, end-cursor)
|
||||
}
|
||||
}
|
||||
if !recognized {
|
||||
return nil
|
||||
}
|
||||
return report
|
||||
}
|
||||
|
||||
func emitJSONReport(w io.Writer, report *sizeReport) error {
|
||||
type moduleJSON struct {
|
||||
Name string `json:"name"`
|
||||
Code uint64 `json:"code"`
|
||||
ROData uint64 `json:"rodata"`
|
||||
Data uint64 `json:"data"`
|
||||
BSS uint64 `json:"bss"`
|
||||
Flash uint64 `json:"flash"`
|
||||
RAM uint64 `json:"ram"`
|
||||
}
|
||||
mods := report.sortedModules()
|
||||
jsonMods := make([]moduleJSON, 0, len(mods))
|
||||
for _, m := range mods {
|
||||
jsonMods = append(jsonMods, moduleJSON{
|
||||
Name: m.Name,
|
||||
Code: m.Code,
|
||||
ROData: m.ROData,
|
||||
Data: m.Data,
|
||||
BSS: m.BSS,
|
||||
Flash: m.Flash(),
|
||||
RAM: m.RAM(),
|
||||
})
|
||||
}
|
||||
payload := struct {
|
||||
Binary string `json:"binary"`
|
||||
Modules []moduleJSON `json:"modules"`
|
||||
Total moduleJSON `json:"total"`
|
||||
}{
|
||||
Binary: filepath.Clean(report.Binary),
|
||||
Modules: jsonMods,
|
||||
Total: moduleJSON{
|
||||
Name: "total",
|
||||
Code: report.Total.Code,
|
||||
ROData: report.Total.ROData,
|
||||
Data: report.Total.Data,
|
||||
BSS: report.Total.BSS,
|
||||
Flash: report.Total.Flash(),
|
||||
RAM: report.Total.RAM(),
|
||||
},
|
||||
}
|
||||
enc := json.NewEncoder(w)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(payload)
|
||||
}
|
||||
|
||||
func printTextReport(w io.Writer, report *sizeReport) {
|
||||
fmt.Fprintf(w, "\nSize report for %s\n", filepath.Clean(report.Binary))
|
||||
fmt.Fprintln(w, " code rodata data bss | flash ram | module")
|
||||
fmt.Fprintln(w, "------------------------------- | --------------- | ----------------")
|
||||
for _, m := range report.sortedModules() {
|
||||
fmt.Fprintf(w, "%7d %7d %7d %7d | %7d %7d | %s\n", m.Code, m.ROData, m.Data, m.BSS, m.Flash(), m.RAM(), m.Name)
|
||||
}
|
||||
fmt.Fprintln(w, "------------------------------- | --------------- | ----------------")
|
||||
fmt.Fprintf(w, "%7d %7d %7d %7d | %7d %7d | total\n", report.Total.Code, report.Total.ROData, report.Total.Data, report.Total.BSS, report.Total.Flash(), report.Total.RAM())
|
||||
}
|
||||
|
||||
func (r *sizeReport) sortedModules() []*moduleSize {
|
||||
mods := make([]*moduleSize, 0, len(r.Modules))
|
||||
for _, m := range r.Modules {
|
||||
mods = append(mods, m)
|
||||
}
|
||||
sort.Slice(mods, func(i, j int) bool {
|
||||
if mods[i].Flash() == mods[j].Flash() {
|
||||
return mods[i].Name < mods[j].Name
|
||||
}
|
||||
return mods[i].Flash() > mods[j].Flash()
|
||||
})
|
||||
return mods
|
||||
}
|
||||
|
||||
// moduleNameFromSymbol extracts the Go package name from a symbol name.
|
||||
// It handles various symbol naming conventions:
|
||||
// - C symbols: Strip leading underscore (e.g., "_main" -> "main")
|
||||
// - Assembler symbols: Strip leading dot (e.g., ".text" -> "text")
|
||||
// - Versioned symbols: Remove version suffix (e.g., "symbol@@GLIBC_2.2.5" -> "symbol")
|
||||
// - Go symbols: Extract package from "package.symbol" format
|
||||
// - Generic types: Strip type parameters (e.g., "pkg(T)" -> "pkg")
|
||||
func moduleNameFromSymbol(raw string) string {
|
||||
name := strings.TrimSpace(raw)
|
||||
// Strip C symbol prefix
|
||||
name = strings.TrimPrefix(name, "_")
|
||||
// Strip assembler symbol prefix
|
||||
name = strings.TrimPrefix(name, ".")
|
||||
if name == "" {
|
||||
return "(anonymous)"
|
||||
}
|
||||
// Remove trailing attributes (e.g., "symbol (weak)")
|
||||
if idx := strings.Index(name, " "); idx > 0 {
|
||||
name = name[:idx]
|
||||
}
|
||||
// Remove version suffix for versioned symbols (e.g., "symbol@@GLIBC_2.2.5")
|
||||
if idx := strings.Index(name, "@"); idx > 0 {
|
||||
name = name[:idx]
|
||||
}
|
||||
// Extract Go package name from "package.symbol" format
|
||||
lastDot := strings.LastIndex(name, ".")
|
||||
if lastDot > 0 {
|
||||
pkg := name[:lastDot]
|
||||
// Strip generic type parameters (e.g., "slices.Sort[int]" -> "slices")
|
||||
if paren := strings.Index(pkg, "("); paren > 0 {
|
||||
pkg = pkg[:paren]
|
||||
}
|
||||
pkg = strings.Trim(pkg, " ")
|
||||
if pkg != "" {
|
||||
return pkg
|
||||
}
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func parseNameField(field string) string {
|
||||
val := strings.TrimSpace(field)
|
||||
if idx := strings.Index(val, "("); idx >= 0 {
|
||||
val = strings.TrimSpace(val[:idx])
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
func parseSectionRef(field string, indexBase int) (string, int) {
|
||||
name := parseNameField(field)
|
||||
idx := strings.Index(field, "(")
|
||||
if idx < 0 {
|
||||
return name, -1
|
||||
}
|
||||
end := strings.Index(field[idx:], ")")
|
||||
if end < 0 {
|
||||
return name, -1
|
||||
}
|
||||
val := strings.TrimSpace(field[idx+1 : idx+end])
|
||||
val = strings.TrimPrefix(val, "0x")
|
||||
if val == "" {
|
||||
return name, -1
|
||||
}
|
||||
num, err := strconv.ParseUint(val, 16, 64)
|
||||
if err != nil {
|
||||
return name, -1
|
||||
}
|
||||
if num == 0 {
|
||||
return name, -1
|
||||
}
|
||||
if indexBase == 0 && num >= SHN_LORESERVE {
|
||||
// Special ELF section indices (SHN_ABS, SHN_COMMON, etc.)
|
||||
return name, -1
|
||||
}
|
||||
if num > math.MaxInt {
|
||||
return name, -1
|
||||
}
|
||||
res := int(num) - indexBase
|
||||
if res < 0 {
|
||||
return name, -1
|
||||
}
|
||||
return name, res
|
||||
}
|
||||
|
||||
func parseUintField(field string) (uint64, error) {
|
||||
val := strings.TrimSpace(field)
|
||||
if strings.HasPrefix(val, "0x") || strings.HasPrefix(val, "0X") {
|
||||
return strconv.ParseUint(val[2:], 16, 64)
|
||||
}
|
||||
return strconv.ParseUint(val, 10, 64)
|
||||
}
|
||||
|
||||
func ensureSizeReporting(conf *Config) error {
|
||||
if !conf.SizeReport {
|
||||
return nil
|
||||
}
|
||||
switch strings.ToLower(conf.SizeLevel) {
|
||||
case "", "module":
|
||||
conf.SizeLevel = "module"
|
||||
case "package", "full":
|
||||
conf.SizeLevel = strings.ToLower(conf.SizeLevel)
|
||||
default:
|
||||
return fmt.Errorf("invalid size level %q (valid: full,module,package)", conf.SizeLevel)
|
||||
}
|
||||
cmd, err := llvm.New("").Readelf("--version")
|
||||
if err != nil {
|
||||
return fmt.Errorf("llvm-readelf not available: %w", err)
|
||||
}
|
||||
cmd.Stdout = io.Discard
|
||||
cmd.Stderr = io.Discard
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("llvm-readelf not available: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
//go:build !llgo
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/go/packages"
|
||||
)
|
||||
|
||||
const sampleReadelf = `Sections [
|
||||
Section {
|
||||
Index: 0
|
||||
Name: __text (5F)
|
||||
Segment: __TEXT (5F)
|
||||
Address: 0x1000
|
||||
Size: 0x20
|
||||
}
|
||||
Section {
|
||||
Index: 1
|
||||
Name: __data
|
||||
Segment: __DATA
|
||||
Address: 0x2000
|
||||
Size: 0x10
|
||||
}
|
||||
Section {
|
||||
Index: 2
|
||||
Name: __common
|
||||
Segment: __DATA
|
||||
Address: 0x3000
|
||||
Size: 0x8
|
||||
}
|
||||
]
|
||||
Symbols [
|
||||
Symbol {
|
||||
Name: _main.main
|
||||
Section: __text (0x1)
|
||||
Value: 0x1000
|
||||
}
|
||||
Symbol {
|
||||
Name: _runtime.init
|
||||
Section: __text (0x1)
|
||||
Value: 0x1010
|
||||
}
|
||||
Symbol {
|
||||
Name: _main.dataVar
|
||||
Section: __data (0x2)
|
||||
Value: 0x2000
|
||||
}
|
||||
Symbol {
|
||||
Name: _runtime.dataVar
|
||||
Section: __data (0x2)
|
||||
Value: 0x2008
|
||||
}
|
||||
Symbol {
|
||||
Name: _runtime.bssVar
|
||||
Section: __common (0x3)
|
||||
Value: 0x3000
|
||||
}
|
||||
]
|
||||
`
|
||||
|
||||
func TestParseReadelfOutput(t *testing.T) {
|
||||
parsed, err := parseReadelfOutput(strings.NewReader(sampleReadelf))
|
||||
if err != nil {
|
||||
t.Fatalf("parseReadelfOutput: %v", err)
|
||||
}
|
||||
report := buildSizeReport("fake.bin", parsed, nil, "")
|
||||
if report == nil {
|
||||
t.Fatal("expected report")
|
||||
}
|
||||
modules := report.Modules
|
||||
if len(modules) == 0 {
|
||||
t.Fatal("expected modules in report")
|
||||
}
|
||||
mainMod, ok := modules["main"]
|
||||
if !ok {
|
||||
t.Fatalf("expected main module, got %v", modules)
|
||||
}
|
||||
if mainMod.Code != 0x10 {
|
||||
t.Fatalf("unexpected main code size: %d", mainMod.Code)
|
||||
}
|
||||
if mainMod.Data != 0x8 {
|
||||
t.Fatalf("unexpected main data size: %d", mainMod.Data)
|
||||
}
|
||||
runtimeMod := modules["runtime"]
|
||||
if runtimeMod.Code != 0x10 {
|
||||
t.Fatalf("unexpected runtime code size: %d", runtimeMod.Code)
|
||||
}
|
||||
if runtimeMod.Data != 0x8 {
|
||||
t.Fatalf("unexpected runtime data size: %d", runtimeMod.Data)
|
||||
}
|
||||
if runtimeMod.BSS != 0x8 {
|
||||
t.Fatalf("unexpected runtime bss size: %d", runtimeMod.BSS)
|
||||
}
|
||||
if report.Total.Flash() != 0x10+0x10+0x8+0x8 {
|
||||
t.Fatalf("unexpected flash total: %d", report.Total.Flash())
|
||||
}
|
||||
if report.Total.RAM() != 0x8+0x8+0x8 {
|
||||
t.Fatalf("unexpected ram total: %d", report.Total.RAM())
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseReadelfRealBinary(t *testing.T) {
|
||||
path := os.Getenv("LLGO_SIZE_REPORT_BIN")
|
||||
if path == "" {
|
||||
return
|
||||
}
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
t.Fatalf("abs path: %v", err)
|
||||
}
|
||||
cmd := exec.Command("llvm-readelf", "--all", absPath)
|
||||
var buf bytes.Buffer
|
||||
cmd.Stdout = &buf
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatalf("llvm-readelf failed: %v", err)
|
||||
}
|
||||
parsed, err := parseReadelfOutput(bytes.NewReader(buf.Bytes()))
|
||||
if err != nil {
|
||||
t.Fatalf("parseReadelfOutput(real): %v", err)
|
||||
}
|
||||
if len(parsed.sections) == 0 {
|
||||
t.Fatal("expected sections in real binary")
|
||||
}
|
||||
report := buildSizeReport(absPath, parsed, nil, "")
|
||||
if len(report.Modules) == 0 {
|
||||
t.Fatalf("expected modules for %s", path)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNameResolver(t *testing.T) {
|
||||
pkgs := []Package{
|
||||
&aPackage{Package: &packages.Package{PkgPath: "github.com/foo/bar", Module: &packages.Module{Path: "github.com/foo"}}},
|
||||
}
|
||||
symbol := "_github.com/foo/bar.Type.method"
|
||||
if got := newNameResolver("package", pkgs).resolve(symbol); got != "github.com/foo/bar" {
|
||||
t.Fatalf("package level want github.com/foo/bar, got %q", got)
|
||||
}
|
||||
if got := newNameResolver("module", pkgs).resolve(symbol); got != "github.com/foo" {
|
||||
t.Fatalf("module level want github.com/foo, got %q", got)
|
||||
}
|
||||
full := newNameResolver("full", pkgs).resolve(symbol)
|
||||
if full != "github.com/foo/bar.Type" {
|
||||
t.Fatalf("full level unexpected: %q", full)
|
||||
}
|
||||
if got := newNameResolver("package", nil).resolve("_llgo_stub.foo"); got != "llgo-stubs" {
|
||||
t.Fatalf("llgo default grouping failed: %q", got)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build !llgo
|
||||
|
||||
package libc
|
||||
|
||||
import (
|
||||
|
||||
2
internal/env/version.go
vendored
2
internal/env/version.go
vendored
@@ -30,6 +30,8 @@ const (
|
||||
var buildVersion string
|
||||
|
||||
// Version returns the version of the running LLGo binary.
|
||||
//
|
||||
//export LLGoVersion
|
||||
func Version() string {
|
||||
if buildVersion != "" {
|
||||
return buildVersion
|
||||
|
||||
622
runtime/_overlay/go/parser/resolver.go
Normal file
622
runtime/_overlay/go/parser/resolver.go
Normal file
@@ -0,0 +1,622 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package parser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/token"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const debugResolve = false
|
||||
|
||||
// resolveFile walks the given file to resolve identifiers within the file
|
||||
// scope, updating ast.Ident.Obj fields with declaration information.
|
||||
//
|
||||
// If declErr is non-nil, it is used to report declaration errors during
|
||||
// resolution. tok is used to format position in error messages.
|
||||
func resolveFile(file *ast.File, handle *token.File, declErr func(token.Pos, string)) {
|
||||
pkgScope := ast.NewScope(nil)
|
||||
r := &resolver{
|
||||
handle: handle,
|
||||
declErr: declErr,
|
||||
topScope: pkgScope,
|
||||
pkgScope: pkgScope,
|
||||
depth: 1,
|
||||
}
|
||||
|
||||
for _, decl := range file.Decls {
|
||||
ast.Walk(r, decl)
|
||||
}
|
||||
|
||||
r.closeScope()
|
||||
assert(r.topScope == nil, "unbalanced scopes")
|
||||
assert(r.labelScope == nil, "unbalanced label scopes")
|
||||
|
||||
// resolve global identifiers within the same file
|
||||
i := 0
|
||||
for _, ident := range r.unresolved {
|
||||
// i <= index for current ident
|
||||
assert(ident.Obj == unresolved, "object already resolved")
|
||||
ident.Obj = r.pkgScope.Lookup(ident.Name) // also removes unresolved sentinel
|
||||
if ident.Obj == nil {
|
||||
r.unresolved[i] = ident
|
||||
i++
|
||||
} else if debugResolve {
|
||||
pos := ident.Obj.Decl.(interface{ Pos() token.Pos }).Pos()
|
||||
r.trace("resolved %s@%v to package object %v", ident.Name, ident.Pos(), pos)
|
||||
}
|
||||
}
|
||||
file.Scope = r.pkgScope
|
||||
file.Unresolved = r.unresolved[0:i]
|
||||
}
|
||||
|
||||
const maxScopeDepth int = 1e3
|
||||
|
||||
type resolver struct {
|
||||
handle *token.File
|
||||
declErr func(token.Pos, string)
|
||||
|
||||
// Ordinary identifier scopes
|
||||
pkgScope *ast.Scope // pkgScope.Outer == nil
|
||||
topScope *ast.Scope // top-most scope; may be pkgScope
|
||||
unresolved []*ast.Ident // unresolved identifiers
|
||||
depth int // scope depth
|
||||
|
||||
// Label scopes
|
||||
// (maintained by open/close LabelScope)
|
||||
labelScope *ast.Scope // label scope for current function
|
||||
targetStack [][]*ast.Ident // stack of unresolved labels
|
||||
}
|
||||
|
||||
func (r *resolver) trace(format string, args ...any) {
|
||||
fmt.Println(strings.Repeat(". ", r.depth) + r.sprintf(format, args...))
|
||||
}
|
||||
|
||||
func (r *resolver) sprintf(format string, args ...any) string {
|
||||
for i, arg := range args {
|
||||
switch arg := arg.(type) {
|
||||
case token.Pos:
|
||||
args[i] = r.handle.Position(arg)
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf(format, args...)
|
||||
}
|
||||
|
||||
func (r *resolver) openScope(pos token.Pos) {
|
||||
r.depth++
|
||||
if r.depth > maxScopeDepth {
|
||||
panic(bailout{pos: pos, msg: "exceeded max scope depth during object resolution"})
|
||||
}
|
||||
if debugResolve {
|
||||
r.trace("opening scope @%v", pos)
|
||||
}
|
||||
r.topScope = ast.NewScope(r.topScope)
|
||||
}
|
||||
|
||||
func (r *resolver) closeScope() {
|
||||
r.depth--
|
||||
if debugResolve {
|
||||
r.trace("closing scope")
|
||||
}
|
||||
r.topScope = r.topScope.Outer
|
||||
}
|
||||
|
||||
func (r *resolver) openLabelScope() {
|
||||
r.labelScope = ast.NewScope(r.labelScope)
|
||||
r.targetStack = append(r.targetStack, nil)
|
||||
}
|
||||
|
||||
func (r *resolver) closeLabelScope() {
|
||||
// resolve labels
|
||||
n := len(r.targetStack) - 1
|
||||
scope := r.labelScope
|
||||
for _, ident := range r.targetStack[n] {
|
||||
ident.Obj = scope.Lookup(ident.Name)
|
||||
if ident.Obj == nil && r.declErr != nil {
|
||||
r.declErr(ident.Pos(), fmt.Sprintf("label %s undefined", ident.Name))
|
||||
}
|
||||
}
|
||||
// pop label scope
|
||||
r.targetStack = r.targetStack[0:n]
|
||||
r.labelScope = r.labelScope.Outer
|
||||
}
|
||||
|
||||
func (r *resolver) declare(decl, data any, scope *ast.Scope, kind ast.ObjKind, idents ...*ast.Ident) {
|
||||
for _, ident := range idents {
|
||||
if ident.Obj != nil {
|
||||
panic(fmt.Sprintf("%v: identifier %s already declared or resolved", ident.Pos(), ident.Name))
|
||||
}
|
||||
obj := ast.NewObj(kind, ident.Name)
|
||||
// remember the corresponding declaration for redeclaration
|
||||
// errors and global variable resolution/typechecking phase
|
||||
obj.Decl = decl
|
||||
obj.Data = data
|
||||
// Identifiers (for receiver type parameters) are written to the scope, but
|
||||
// never set as the resolved object. See go.dev/issue/50956.
|
||||
if _, ok := decl.(*ast.Ident); !ok {
|
||||
ident.Obj = obj
|
||||
}
|
||||
if ident.Name != "_" {
|
||||
if debugResolve {
|
||||
r.trace("declaring %s@%v", ident.Name, ident.Pos())
|
||||
}
|
||||
if alt := scope.Insert(obj); alt != nil && r.declErr != nil {
|
||||
prevDecl := ""
|
||||
if pos := alt.Pos(); pos.IsValid() {
|
||||
prevDecl = r.sprintf("\n\tprevious declaration at %v", pos)
|
||||
}
|
||||
r.declErr(ident.Pos(), fmt.Sprintf("%s redeclared in this block%s", ident.Name, prevDecl))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) shortVarDecl(decl *ast.AssignStmt) {
|
||||
// Go spec: A short variable declaration may redeclare variables
|
||||
// provided they were originally declared in the same block with
|
||||
// the same type, and at least one of the non-blank variables is new.
|
||||
n := 0 // number of new variables
|
||||
for _, x := range decl.Lhs {
|
||||
if ident, isIdent := x.(*ast.Ident); isIdent {
|
||||
assert(ident.Obj == nil, "identifier already declared or resolved")
|
||||
obj := ast.NewObj(ast.Var, ident.Name)
|
||||
// remember corresponding assignment for other tools
|
||||
obj.Decl = decl
|
||||
ident.Obj = obj
|
||||
if ident.Name != "_" {
|
||||
if debugResolve {
|
||||
r.trace("declaring %s@%v", ident.Name, ident.Pos())
|
||||
}
|
||||
if alt := r.topScope.Insert(obj); alt != nil {
|
||||
ident.Obj = alt // redeclaration
|
||||
} else {
|
||||
n++ // new declaration
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if n == 0 && r.declErr != nil {
|
||||
r.declErr(decl.Lhs[0].Pos(), "no new variables on left side of :=")
|
||||
}
|
||||
}
|
||||
|
||||
// The unresolved object is a sentinel to mark identifiers that have been added
|
||||
// to the list of unresolved identifiers. The sentinel is only used for verifying
|
||||
// internal consistency.
|
||||
var unresolved = new(ast.Object)
|
||||
|
||||
// If x is an identifier, resolve attempts to resolve x by looking up
|
||||
// the object it denotes. If no object is found and collectUnresolved is
|
||||
// set, x is marked as unresolved and collected in the list of unresolved
|
||||
// identifiers.
|
||||
func (r *resolver) resolve(ident *ast.Ident, collectUnresolved bool) {
|
||||
if ident.Obj != nil {
|
||||
panic(r.sprintf("%v: identifier %s already declared or resolved", ident.Pos(), ident.Name))
|
||||
}
|
||||
// '_' should never refer to existing declarations, because it has special
|
||||
// handling in the spec.
|
||||
if ident.Name == "_" {
|
||||
return
|
||||
}
|
||||
for s := r.topScope; s != nil; s = s.Outer {
|
||||
if obj := s.Lookup(ident.Name); obj != nil {
|
||||
if debugResolve {
|
||||
r.trace("resolved %v:%s to %v", ident.Pos(), ident.Name, obj)
|
||||
}
|
||||
assert(obj.Name != "", "obj with no name")
|
||||
// Identifiers (for receiver type parameters) are written to the scope,
|
||||
// but never set as the resolved object. See go.dev/issue/50956.
|
||||
if _, ok := obj.Decl.(*ast.Ident); !ok {
|
||||
ident.Obj = obj
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
// all local scopes are known, so any unresolved identifier
|
||||
// must be found either in the file scope, package scope
|
||||
// (perhaps in another file), or universe scope --- collect
|
||||
// them so that they can be resolved later
|
||||
if collectUnresolved {
|
||||
ident.Obj = unresolved
|
||||
r.unresolved = append(r.unresolved, ident)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) walkExprs(list []ast.Expr) {
|
||||
for _, node := range list {
|
||||
ast.Walk(r, node)
|
||||
}
|
||||
}
|
||||
|
||||
func Unparen(e ast.Expr) ast.Expr {
|
||||
for {
|
||||
paren, ok := e.(*ast.ParenExpr)
|
||||
if !ok {
|
||||
return e
|
||||
}
|
||||
e = paren.X
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) walkLHS(list []ast.Expr) {
|
||||
for _, expr := range list {
|
||||
expr := Unparen(expr)
|
||||
if _, ok := expr.(*ast.Ident); !ok && expr != nil {
|
||||
ast.Walk(r, expr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) walkStmts(list []ast.Stmt) {
|
||||
for _, stmt := range list {
|
||||
ast.Walk(r, stmt)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) Visit(node ast.Node) ast.Visitor {
|
||||
if debugResolve && node != nil {
|
||||
r.trace("node %T@%v", node, node.Pos())
|
||||
}
|
||||
|
||||
switch n := node.(type) {
|
||||
|
||||
// Expressions.
|
||||
case *ast.Ident:
|
||||
r.resolve(n, true)
|
||||
|
||||
case *ast.FuncLit:
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
r.walkFuncType(n.Type)
|
||||
r.walkBody(n.Body)
|
||||
|
||||
case *ast.SelectorExpr:
|
||||
ast.Walk(r, n.X)
|
||||
// Note: don't try to resolve n.Sel, as we don't support qualified
|
||||
// resolution.
|
||||
|
||||
case *ast.StructType:
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
r.walkFieldList(n.Fields, ast.Var)
|
||||
|
||||
case *ast.FuncType:
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
r.walkFuncType(n)
|
||||
|
||||
case *ast.CompositeLit:
|
||||
if n.Type != nil {
|
||||
ast.Walk(r, n.Type)
|
||||
}
|
||||
for _, e := range n.Elts {
|
||||
if kv, _ := e.(*ast.KeyValueExpr); kv != nil {
|
||||
// See go.dev/issue/45160: try to resolve composite lit keys, but don't
|
||||
// collect them as unresolved if resolution failed. This replicates
|
||||
// existing behavior when resolving during parsing.
|
||||
if ident, _ := kv.Key.(*ast.Ident); ident != nil {
|
||||
r.resolve(ident, false)
|
||||
} else {
|
||||
ast.Walk(r, kv.Key)
|
||||
}
|
||||
ast.Walk(r, kv.Value)
|
||||
} else {
|
||||
ast.Walk(r, e)
|
||||
}
|
||||
}
|
||||
|
||||
case *ast.InterfaceType:
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
r.walkFieldList(n.Methods, ast.Fun)
|
||||
|
||||
// Statements
|
||||
case *ast.LabeledStmt:
|
||||
r.declare(n, nil, r.labelScope, ast.Lbl, n.Label)
|
||||
ast.Walk(r, n.Stmt)
|
||||
|
||||
case *ast.AssignStmt:
|
||||
r.walkExprs(n.Rhs)
|
||||
if n.Tok == token.DEFINE {
|
||||
r.shortVarDecl(n)
|
||||
} else {
|
||||
r.walkExprs(n.Lhs)
|
||||
}
|
||||
|
||||
case *ast.BranchStmt:
|
||||
// add to list of unresolved targets
|
||||
if n.Tok != token.FALLTHROUGH && n.Label != nil {
|
||||
depth := len(r.targetStack) - 1
|
||||
r.targetStack[depth] = append(r.targetStack[depth], n.Label)
|
||||
}
|
||||
|
||||
case *ast.BlockStmt:
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
r.walkStmts(n.List)
|
||||
|
||||
case *ast.IfStmt:
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
if n.Init != nil {
|
||||
ast.Walk(r, n.Init)
|
||||
}
|
||||
ast.Walk(r, n.Cond)
|
||||
ast.Walk(r, n.Body)
|
||||
if n.Else != nil {
|
||||
ast.Walk(r, n.Else)
|
||||
}
|
||||
|
||||
case *ast.CaseClause:
|
||||
r.walkExprs(n.List)
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
r.walkStmts(n.Body)
|
||||
|
||||
case *ast.SwitchStmt:
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
if n.Init != nil {
|
||||
ast.Walk(r, n.Init)
|
||||
}
|
||||
if n.Tag != nil {
|
||||
// The scope below reproduces some unnecessary behavior of the parser,
|
||||
// opening an extra scope in case this is a type switch. It's not needed
|
||||
// for expression switches.
|
||||
// TODO: remove this once we've matched the parser resolution exactly.
|
||||
if n.Init != nil {
|
||||
r.openScope(n.Tag.Pos())
|
||||
defer r.closeScope()
|
||||
}
|
||||
ast.Walk(r, n.Tag)
|
||||
}
|
||||
if n.Body != nil {
|
||||
r.walkStmts(n.Body.List)
|
||||
}
|
||||
|
||||
case *ast.TypeSwitchStmt:
|
||||
if n.Init != nil {
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
ast.Walk(r, n.Init)
|
||||
}
|
||||
r.openScope(n.Assign.Pos())
|
||||
defer r.closeScope()
|
||||
ast.Walk(r, n.Assign)
|
||||
// s.Body consists only of case clauses, so does not get its own
|
||||
// scope.
|
||||
if n.Body != nil {
|
||||
r.walkStmts(n.Body.List)
|
||||
}
|
||||
|
||||
case *ast.CommClause:
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
if n.Comm != nil {
|
||||
ast.Walk(r, n.Comm)
|
||||
}
|
||||
r.walkStmts(n.Body)
|
||||
|
||||
case *ast.SelectStmt:
|
||||
// as for switch statements, select statement bodies don't get their own
|
||||
// scope.
|
||||
if n.Body != nil {
|
||||
r.walkStmts(n.Body.List)
|
||||
}
|
||||
|
||||
case *ast.ForStmt:
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
if n.Init != nil {
|
||||
ast.Walk(r, n.Init)
|
||||
}
|
||||
if n.Cond != nil {
|
||||
ast.Walk(r, n.Cond)
|
||||
}
|
||||
if n.Post != nil {
|
||||
ast.Walk(r, n.Post)
|
||||
}
|
||||
ast.Walk(r, n.Body)
|
||||
|
||||
case *ast.RangeStmt:
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
ast.Walk(r, n.X)
|
||||
var lhs []ast.Expr
|
||||
if n.Key != nil {
|
||||
lhs = append(lhs, n.Key)
|
||||
}
|
||||
if n.Value != nil {
|
||||
lhs = append(lhs, n.Value)
|
||||
}
|
||||
if len(lhs) > 0 {
|
||||
if n.Tok == token.DEFINE {
|
||||
// Note: we can't exactly match the behavior of object resolution
|
||||
// during the parsing pass here, as it uses the position of the RANGE
|
||||
// token for the RHS OpPos. That information is not contained within
|
||||
// the AST.
|
||||
as := &ast.AssignStmt{
|
||||
Lhs: lhs,
|
||||
Tok: token.DEFINE,
|
||||
TokPos: n.TokPos,
|
||||
Rhs: []ast.Expr{&ast.UnaryExpr{Op: token.RANGE, X: n.X}},
|
||||
}
|
||||
// TODO(rFindley): this walkLHS reproduced the parser resolution, but
|
||||
// is it necessary? By comparison, for a normal AssignStmt we don't
|
||||
// walk the LHS in case there is an invalid identifier list.
|
||||
r.walkLHS(lhs)
|
||||
r.shortVarDecl(as)
|
||||
} else {
|
||||
r.walkExprs(lhs)
|
||||
}
|
||||
}
|
||||
ast.Walk(r, n.Body)
|
||||
|
||||
// Declarations
|
||||
case *ast.GenDecl:
|
||||
switch n.Tok {
|
||||
case token.CONST, token.VAR:
|
||||
for i, spec := range n.Specs {
|
||||
spec := spec.(*ast.ValueSpec)
|
||||
kind := ast.Con
|
||||
if n.Tok == token.VAR {
|
||||
kind = ast.Var
|
||||
}
|
||||
r.walkExprs(spec.Values)
|
||||
if spec.Type != nil {
|
||||
ast.Walk(r, spec.Type)
|
||||
}
|
||||
r.declare(spec, i, r.topScope, kind, spec.Names...)
|
||||
}
|
||||
case token.TYPE:
|
||||
for _, spec := range n.Specs {
|
||||
spec := spec.(*ast.TypeSpec)
|
||||
// Go spec: The scope of a type identifier declared inside a function begins
|
||||
// at the identifier in the TypeSpec and ends at the end of the innermost
|
||||
// containing block.
|
||||
r.declare(spec, nil, r.topScope, ast.Typ, spec.Name)
|
||||
if spec.TypeParams != nil {
|
||||
r.openScope(spec.Pos())
|
||||
r.walkTParams(spec.TypeParams)
|
||||
r.closeScope()
|
||||
}
|
||||
ast.Walk(r, spec.Type)
|
||||
}
|
||||
}
|
||||
|
||||
case *ast.FuncDecl:
|
||||
// Open the function scope.
|
||||
r.openScope(n.Pos())
|
||||
defer r.closeScope()
|
||||
|
||||
r.walkRecv(n.Recv)
|
||||
|
||||
// Type parameters are walked normally: they can reference each other, and
|
||||
// can be referenced by normal parameters.
|
||||
if n.Type.TypeParams != nil {
|
||||
r.walkTParams(n.Type.TypeParams)
|
||||
// TODO(rFindley): need to address receiver type parameters.
|
||||
}
|
||||
|
||||
// Resolve and declare parameters in a specific order to get duplicate
|
||||
// declaration errors in the correct location.
|
||||
r.resolveList(n.Type.Params)
|
||||
r.resolveList(n.Type.Results)
|
||||
r.declareList(n.Recv, ast.Var)
|
||||
r.declareList(n.Type.Params, ast.Var)
|
||||
r.declareList(n.Type.Results, ast.Var)
|
||||
|
||||
r.walkBody(n.Body)
|
||||
if n.Recv == nil && n.Name.Name != "init" {
|
||||
r.declare(n, nil, r.pkgScope, ast.Fun, n.Name)
|
||||
}
|
||||
|
||||
default:
|
||||
return r
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *resolver) walkFuncType(typ *ast.FuncType) {
|
||||
// typ.TypeParams must be walked separately for FuncDecls.
|
||||
r.resolveList(typ.Params)
|
||||
r.resolveList(typ.Results)
|
||||
r.declareList(typ.Params, ast.Var)
|
||||
r.declareList(typ.Results, ast.Var)
|
||||
}
|
||||
|
||||
func (r *resolver) resolveList(list *ast.FieldList) {
|
||||
if list == nil {
|
||||
return
|
||||
}
|
||||
for _, f := range list.List {
|
||||
if f.Type != nil {
|
||||
ast.Walk(r, f.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) declareList(list *ast.FieldList, kind ast.ObjKind) {
|
||||
if list == nil {
|
||||
return
|
||||
}
|
||||
for _, f := range list.List {
|
||||
r.declare(f, nil, r.topScope, kind, f.Names...)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) walkRecv(recv *ast.FieldList) {
|
||||
// If our receiver has receiver type parameters, we must declare them before
|
||||
// trying to resolve the rest of the receiver, and avoid re-resolving the
|
||||
// type parameter identifiers.
|
||||
if recv == nil || len(recv.List) == 0 {
|
||||
return // nothing to do
|
||||
}
|
||||
typ := recv.List[0].Type
|
||||
if ptr, ok := typ.(*ast.StarExpr); ok {
|
||||
typ = ptr.X
|
||||
}
|
||||
|
||||
var declareExprs []ast.Expr // exprs to declare
|
||||
var resolveExprs []ast.Expr // exprs to resolve
|
||||
switch typ := typ.(type) {
|
||||
case *ast.IndexExpr:
|
||||
declareExprs = []ast.Expr{typ.Index}
|
||||
resolveExprs = append(resolveExprs, typ.X)
|
||||
case *ast.IndexListExpr:
|
||||
declareExprs = typ.Indices
|
||||
resolveExprs = append(resolveExprs, typ.X)
|
||||
default:
|
||||
resolveExprs = append(resolveExprs, typ)
|
||||
}
|
||||
for _, expr := range declareExprs {
|
||||
if id, _ := expr.(*ast.Ident); id != nil {
|
||||
r.declare(expr, nil, r.topScope, ast.Typ, id)
|
||||
} else {
|
||||
// The receiver type parameter expression is invalid, but try to resolve
|
||||
// it anyway for consistency.
|
||||
resolveExprs = append(resolveExprs, expr)
|
||||
}
|
||||
}
|
||||
for _, expr := range resolveExprs {
|
||||
if expr != nil {
|
||||
ast.Walk(r, expr)
|
||||
}
|
||||
}
|
||||
// The receiver is invalid, but try to resolve it anyway for consistency.
|
||||
for _, f := range recv.List[1:] {
|
||||
if f.Type != nil {
|
||||
ast.Walk(r, f.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) walkFieldList(list *ast.FieldList, kind ast.ObjKind) {
|
||||
if list == nil {
|
||||
return
|
||||
}
|
||||
r.resolveList(list)
|
||||
r.declareList(list, kind)
|
||||
}
|
||||
|
||||
// walkTParams is like walkFieldList, but declares type parameters eagerly so
|
||||
// that they may be resolved in the constraint expressions held in the field
|
||||
// Type.
|
||||
func (r *resolver) walkTParams(list *ast.FieldList) {
|
||||
r.declareList(list, ast.Typ)
|
||||
r.resolveList(list)
|
||||
}
|
||||
|
||||
func (r *resolver) walkBody(body *ast.BlockStmt) {
|
||||
if body == nil {
|
||||
return
|
||||
}
|
||||
r.openLabelScope()
|
||||
defer r.closeLabelScope()
|
||||
r.walkStmts(body.List)
|
||||
}
|
||||
1
runtime/_overlay/testing/testing.go
Normal file
1
runtime/_overlay/testing/testing.go
Normal file
@@ -0,0 +1 @@
|
||||
package testing
|
||||
2425
runtime/_overlay/testing/testing_go123.go
Normal file
2425
runtime/_overlay/testing/testing_go123.go
Normal file
File diff suppressed because it is too large
Load Diff
2536
runtime/_overlay/testing/testing_go124.go
Normal file
2536
runtime/_overlay/testing/testing_go124.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -22,7 +22,6 @@ var hasAltPkg = map[string]none{
|
||||
"crypto/sha256": {},
|
||||
"crypto/sha512": {},
|
||||
"crypto/subtle": {},
|
||||
"go/build": {},
|
||||
"go/parser": {},
|
||||
"hash/crc32": {},
|
||||
"hash/maphash": {},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//go:build !nogc && !baremetal
|
||||
//go:build !nogc
|
||||
// +build !nogc
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//go:build nogc || baremetal
|
||||
//go:build nogc
|
||||
// +build nogc
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build llgo && !baremetal
|
||||
//go:build llgo
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build llgo && !baremetal && !nogc
|
||||
//go:build llgo && !nogc
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build llgo && (nogc || baremetal)
|
||||
//go:build llgo && nogc
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
//go:build !llgo || baremetal
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025 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 tls
|
||||
|
||||
// Handle is a no-op TLS handle used when building without the llgo tag.
|
||||
type Handle[T any] struct{}
|
||||
|
||||
// Alloc returns a stub TLS handle that ignores all operations.
|
||||
func Alloc[T any](func(*T)) Handle[T] { return Handle[T]{} }
|
||||
|
||||
// Get always returns the zero value.
|
||||
func (Handle[T]) Get() (zero T) { return zero }
|
||||
|
||||
// Set is a no-op.
|
||||
func (Handle[T]) Set(T) {}
|
||||
|
||||
// Clear is a no-op.
|
||||
func (Handle[T]) Clear() {}
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package build provides alternative implementations for go/build.
|
||||
// We override build.Default.Compiler in an init function.
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"go/build"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// LLGO PATCH: Override build.Default.Compiler to be "gc" instead of "llgo"
|
||||
// This prevents "unknown compiler" errors when user code uses go/build package
|
||||
// Even though runtime.Compiler = "llgo", we set build.Default.Compiler = "gc"
|
||||
build.Default.Compiler = "gc"
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/goplus/llgo/runtime/internal/runtime"
|
||||
)
|
||||
|
||||
// llgo:skip init
|
||||
// llgo:skip init CompareString
|
||||
type _bytealg struct{}
|
||||
|
||||
func IndexByte(b []byte, ch byte) int {
|
||||
|
||||
@@ -1759,16 +1759,6 @@ func ValueOf(i any) Value {
|
||||
return unpackEface(i)
|
||||
}
|
||||
|
||||
// Indirect returns the value that v points to.
|
||||
// If v is a nil pointer, Indirect returns a zero Value.
|
||||
// If v is not a pointer, Indirect returns v.
|
||||
func Indirect(v Value) Value {
|
||||
if v.Kind() != Pointer {
|
||||
return v
|
||||
}
|
||||
return v.Elem()
|
||||
}
|
||||
|
||||
// arrayAt returns the i-th element of p,
|
||||
// an array whose elements are eltSize bytes wide.
|
||||
// The array pointed at by p must have at least i+1 elements:
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
package runtime
|
||||
|
||||
import "runtime"
|
||||
|
||||
// Layout of in-memory per-function information prepared by linker
|
||||
// See https://golang.org/s/go12symtab.
|
||||
// Keep in sync with linker (../cmd/link/internal/ld/pcln.go:/pclntab)
|
||||
@@ -28,6 +30,10 @@ func StopTrace() {
|
||||
panic("todo: runtime.StopTrace")
|
||||
}
|
||||
|
||||
func ReadMemStats(m *runtime.MemStats) {
|
||||
panic("todo: runtime.ReadMemStats")
|
||||
}
|
||||
|
||||
func SetMutexProfileFraction(rate int) int {
|
||||
panic("todo: runtime.SetMutexProfileFraction")
|
||||
}
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
//go:build !nogc && !baremetal
|
||||
//go:build !nogc
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/goplus/llgo/runtime/internal/clite/bdwgc"
|
||||
)
|
||||
|
||||
func ReadMemStats(m *runtime.MemStats) {
|
||||
panic("todo: runtime.ReadMemStats")
|
||||
}
|
||||
import "github.com/goplus/llgo/runtime/internal/clite/bdwgc"
|
||||
|
||||
func GC() {
|
||||
bdwgc.Gcollect()
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build !nogc && baremetal
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/goplus/llgo/runtime/internal/runtime/tinygogc"
|
||||
)
|
||||
|
||||
func ReadMemStats(m *runtime.MemStats) {
|
||||
stats := tinygogc.ReadGCStats()
|
||||
m.Alloc = stats.Alloc
|
||||
m.TotalAlloc = stats.TotalAlloc
|
||||
m.Sys = stats.Sys
|
||||
m.Mallocs = stats.Mallocs
|
||||
m.Frees = stats.Frees
|
||||
m.HeapAlloc = stats.HeapAlloc
|
||||
m.HeapSys = stats.HeapSys
|
||||
m.HeapIdle = stats.HeapIdle
|
||||
m.HeapInuse = stats.HeapInuse
|
||||
m.StackInuse = stats.StackInuse
|
||||
m.StackSys = stats.StackSys
|
||||
m.GCSys = stats.GCSys
|
||||
}
|
||||
|
||||
func GC() {
|
||||
tinygogc.GC()
|
||||
}
|
||||
@@ -140,10 +140,6 @@ type Func struct {
|
||||
opaque struct{} // unexported field to disallow conversions
|
||||
}
|
||||
|
||||
func (f *Func) Name() string {
|
||||
panic("todo")
|
||||
}
|
||||
|
||||
// moduledata records information about the layout of the executable
|
||||
// image. It is written by the linker. Any changes here must be
|
||||
// matched changes to the code in cmd/link/internal/ld/symtab.go:symtab.
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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 runtime
|
||||
|
||||
import "github.com/goplus/llgo/runtime/internal/clite/tls"
|
||||
|
||||
var deferTLS = tls.Alloc[*Defer](func(head **Defer) {
|
||||
if head != nil {
|
||||
*head = nil
|
||||
}
|
||||
})
|
||||
|
||||
// SetThreadDefer associates the current thread with the given defer chain.
|
||||
func SetThreadDefer(head *Defer) {
|
||||
deferTLS.Set(head)
|
||||
}
|
||||
|
||||
// GetThreadDefer returns the current thread's defer chain head.
|
||||
func GetThreadDefer() *Defer {
|
||||
return deferTLS.Get()
|
||||
}
|
||||
|
||||
// ClearThreadDefer resets the current thread's defer chain to nil.
|
||||
func ClearThreadDefer() {
|
||||
deferTLS.Clear()
|
||||
}
|
||||
@@ -1,184 +0,0 @@
|
||||
//go:build baremetal || testGC
|
||||
|
||||
package tinygogc
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type GCStats struct {
|
||||
// General statistics.
|
||||
|
||||
// Alloc is bytes of allocated heap objects.
|
||||
//
|
||||
// This is the same as HeapAlloc (see below).
|
||||
Alloc uint64
|
||||
|
||||
// TotalAlloc is cumulative bytes allocated for heap objects.
|
||||
//
|
||||
// TotalAlloc increases as heap objects are allocated, but
|
||||
// unlike Alloc and HeapAlloc, it does not decrease when
|
||||
// objects are freed.
|
||||
TotalAlloc uint64
|
||||
|
||||
// Sys is the total bytes of memory obtained from the OS.
|
||||
//
|
||||
// Sys is the sum of the XSys fields below. Sys measures the
|
||||
// virtual address space reserved by the Go runtime for the
|
||||
// heap, stacks, and other internal data structures. It's
|
||||
// likely that not all of the virtual address space is backed
|
||||
// by physical memory at any given moment, though in general
|
||||
// it all was at some point.
|
||||
Sys uint64
|
||||
|
||||
// Mallocs is the cumulative count of heap objects allocated.
|
||||
// The number of live objects is Mallocs - Frees.
|
||||
Mallocs uint64
|
||||
|
||||
// Frees is the cumulative count of heap objects freed.
|
||||
Frees uint64
|
||||
|
||||
// Heap memory statistics.
|
||||
//
|
||||
// Interpreting the heap statistics requires some knowledge of
|
||||
// how Go organizes memory. Go divides the virtual address
|
||||
// space of the heap into "spans", which are contiguous
|
||||
// regions of memory 8K or larger. A span may be in one of
|
||||
// three states:
|
||||
//
|
||||
// An "idle" span contains no objects or other data. The
|
||||
// physical memory backing an idle span can be released back
|
||||
// to the OS (but the virtual address space never is), or it
|
||||
// can be converted into an "in use" or "stack" span.
|
||||
//
|
||||
// An "in use" span contains at least one heap object and may
|
||||
// have free space available to allocate more heap objects.
|
||||
//
|
||||
// A "stack" span is used for goroutine stacks. Stack spans
|
||||
// are not considered part of the heap. A span can change
|
||||
// between heap and stack memory; it is never used for both
|
||||
// simultaneously.
|
||||
|
||||
// HeapAlloc is bytes of allocated heap objects.
|
||||
//
|
||||
// "Allocated" heap objects include all reachable objects, as
|
||||
// well as unreachable objects that the garbage collector has
|
||||
// not yet freed. Specifically, HeapAlloc increases as heap
|
||||
// objects are allocated and decreases as the heap is swept
|
||||
// and unreachable objects are freed. Sweeping occurs
|
||||
// incrementally between GC cycles, so these two processes
|
||||
// occur simultaneously, and as a result HeapAlloc tends to
|
||||
// change smoothly (in contrast with the sawtooth that is
|
||||
// typical of stop-the-world garbage collectors).
|
||||
HeapAlloc uint64
|
||||
|
||||
// HeapSys is bytes of heap memory obtained from the OS.
|
||||
//
|
||||
// HeapSys measures the amount of virtual address space
|
||||
// reserved for the heap. This includes virtual address space
|
||||
// that has been reserved but not yet used, which consumes no
|
||||
// physical memory, but tends to be small, as well as virtual
|
||||
// address space for which the physical memory has been
|
||||
// returned to the OS after it became unused (see HeapReleased
|
||||
// for a measure of the latter).
|
||||
//
|
||||
// HeapSys estimates the largest size the heap has had.
|
||||
HeapSys uint64
|
||||
|
||||
// HeapIdle is bytes in idle (unused) spans.
|
||||
//
|
||||
// Idle spans have no objects in them. These spans could be
|
||||
// (and may already have been) returned to the OS, or they can
|
||||
// be reused for heap allocations, or they can be reused as
|
||||
// stack memory.
|
||||
//
|
||||
// HeapIdle minus HeapReleased estimates the amount of memory
|
||||
// that could be returned to the OS, but is being retained by
|
||||
// the runtime so it can grow the heap without requesting more
|
||||
// memory from the OS. If this difference is significantly
|
||||
// larger than the heap size, it indicates there was a recent
|
||||
// transient spike in live heap size.
|
||||
HeapIdle uint64
|
||||
|
||||
// HeapInuse is bytes in in-use spans.
|
||||
//
|
||||
// In-use spans have at least one object in them. These spans
|
||||
// can only be used for other objects of roughly the same
|
||||
// size.
|
||||
//
|
||||
// HeapInuse minus HeapAlloc estimates the amount of memory
|
||||
// that has been dedicated to particular size classes, but is
|
||||
// not currently being used. This is an upper bound on
|
||||
// fragmentation, but in general this memory can be reused
|
||||
// efficiently.
|
||||
HeapInuse uint64
|
||||
|
||||
// Stack memory statistics.
|
||||
//
|
||||
// Stacks are not considered part of the heap, but the runtime
|
||||
// can reuse a span of heap memory for stack memory, and
|
||||
// vice-versa.
|
||||
|
||||
// StackInuse is bytes in stack spans.
|
||||
//
|
||||
// In-use stack spans have at least one stack in them. These
|
||||
// spans can only be used for other stacks of the same size.
|
||||
//
|
||||
// There is no StackIdle because unused stack spans are
|
||||
// returned to the heap (and hence counted toward HeapIdle).
|
||||
StackInuse uint64
|
||||
|
||||
// StackSys is bytes of stack memory obtained from the OS.
|
||||
//
|
||||
// StackSys is StackInuse, plus any memory obtained directly
|
||||
// from the OS for OS thread stacks.
|
||||
//
|
||||
// In non-cgo programs this metric is currently equal to StackInuse
|
||||
// (but this should not be relied upon, and the value may change in
|
||||
// the future).
|
||||
//
|
||||
// In cgo programs this metric includes OS thread stacks allocated
|
||||
// directly from the OS. Currently, this only accounts for one stack in
|
||||
// c-shared and c-archive build modes and other sources of stacks from
|
||||
// the OS (notably, any allocated by C code) are not currently measured.
|
||||
// Note this too may change in the future.
|
||||
StackSys uint64
|
||||
|
||||
// GCSys is bytes of memory in garbage collection metadata.
|
||||
GCSys uint64
|
||||
}
|
||||
|
||||
func ReadGCStats() GCStats {
|
||||
var heapInuse, heapIdle uint64
|
||||
|
||||
lock(&gcMutex)
|
||||
|
||||
for block := uintptr(0); block < endBlock; block++ {
|
||||
bstate := gcStateOf(block)
|
||||
if bstate == blockStateFree {
|
||||
heapIdle += uint64(bytesPerBlock)
|
||||
} else {
|
||||
heapInuse += uint64(bytesPerBlock)
|
||||
}
|
||||
}
|
||||
|
||||
stackEnd := uintptr(unsafe.Pointer(&_stackEnd))
|
||||
stackSys := stackTop - stackEnd
|
||||
|
||||
stats := GCStats{
|
||||
Alloc: (gcTotalBlocks - gcFreedBlocks) * uint64(bytesPerBlock),
|
||||
TotalAlloc: gcTotalAlloc,
|
||||
Sys: uint64(heapEnd - heapStart),
|
||||
Mallocs: gcMallocs,
|
||||
Frees: gcFrees,
|
||||
HeapAlloc: (gcTotalBlocks - gcFreedBlocks) * uint64(bytesPerBlock),
|
||||
HeapSys: heapInuse + heapIdle,
|
||||
HeapIdle: heapIdle,
|
||||
HeapInuse: heapInuse,
|
||||
StackInuse: uint64(stackTop - uintptr(getsp())),
|
||||
StackSys: uint64(stackSys),
|
||||
GCSys: uint64(heapEnd - uintptr(metadataStart)),
|
||||
}
|
||||
|
||||
unlock(&gcMutex)
|
||||
|
||||
return stats
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
//go:build !testGC
|
||||
|
||||
package tinygogc
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
// LLGoPackage instructs the LLGo linker to wrap C standard library memory allocation
|
||||
// functions (malloc, realloc, calloc) so they use the tinygogc allocator instead.
|
||||
// This ensures all memory allocations go through the GC, including C library calls.
|
||||
const LLGoPackage = "link: --wrap=malloc --wrap=realloc --wrap=calloc"
|
||||
|
||||
//export __wrap_malloc
|
||||
func __wrap_malloc(size uintptr) unsafe.Pointer {
|
||||
return Alloc(size)
|
||||
}
|
||||
|
||||
//export __wrap_calloc
|
||||
func __wrap_calloc(nmemb, size uintptr) unsafe.Pointer {
|
||||
totalSize := nmemb * size
|
||||
// Check for multiplication overflow
|
||||
if nmemb != 0 && totalSize/nmemb != size {
|
||||
return nil // Overflow
|
||||
}
|
||||
return Alloc(totalSize)
|
||||
}
|
||||
|
||||
//export __wrap_realloc
|
||||
func __wrap_realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer {
|
||||
return Realloc(ptr, size)
|
||||
}
|
||||
|
||||
//go:linkname getsp llgo.stackSave
|
||||
func getsp() unsafe.Pointer
|
||||
|
||||
//go:linkname _heapStart _heapStart
|
||||
var _heapStart [0]byte
|
||||
|
||||
//go:linkname _heapEnd _heapEnd
|
||||
var _heapEnd [0]byte
|
||||
|
||||
//go:linkname _stackStart _stack_top
|
||||
var _stackStart [0]byte
|
||||
|
||||
//go:linkname _stackEnd _stack_end
|
||||
var _stackEnd [0]byte
|
||||
|
||||
//go:linkname _globals_start _globals_start
|
||||
var _globals_start [0]byte
|
||||
|
||||
//go:linkname _globals_end _globals_end
|
||||
var _globals_end [0]byte
|
||||
@@ -1,25 +0,0 @@
|
||||
//go:build testGC
|
||||
|
||||
package tinygogc
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
var currentStack uintptr
|
||||
|
||||
func getsp() uintptr {
|
||||
return currentStack
|
||||
}
|
||||
|
||||
var _heapStart [0]byte
|
||||
|
||||
var _heapEnd [0]byte
|
||||
|
||||
var _stackStart [0]byte
|
||||
|
||||
var _stackEnd [0]byte
|
||||
|
||||
var _globals_start [0]byte
|
||||
|
||||
var _globals_end [0]byte
|
||||
@@ -1,570 +0,0 @@
|
||||
//go:build baremetal || testGC
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018-2025 The TinyGo Authors. All rights reserved.
|
||||
* 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 tinygogc implements a conservative mark-and-sweep garbage collector
|
||||
// for baremetal environments where the standard Go runtime and bdwgc are unavailable.
|
||||
//
|
||||
// This implementation is based on TinyGo's GC and is designed for resource-constrained
|
||||
// embedded systems. It uses a block-based allocator with conservative pointer scanning.
|
||||
//
|
||||
// Build tags:
|
||||
// - baremetal: Enables this GC for baremetal targets
|
||||
// - testGC: Enables testing mode with mock implementations
|
||||
//
|
||||
// Memory Layout:
|
||||
// The heap is divided into fixed-size blocks (32 bytes on 64-bit). Metadata is stored
|
||||
// at the end of the heap, using 2 bits per block to track state (free/head/tail/mark).
|
||||
package tinygogc
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const gcDebug = false
|
||||
|
||||
// blockState stores the four states in which a block can be. It is two bits in
|
||||
// size.
|
||||
const (
|
||||
blockStateFree uint8 = 0 // 00
|
||||
blockStateHead uint8 = 1 // 01
|
||||
blockStateTail uint8 = 2 // 10
|
||||
blockStateMark uint8 = 3 // 11
|
||||
blockStateMask uint8 = 3 // 11
|
||||
)
|
||||
|
||||
// The byte value of a block where every block is a 'tail' block.
|
||||
const blockStateByteAllTails = 0 |
|
||||
uint8(blockStateTail<<(stateBits*3)) |
|
||||
uint8(blockStateTail<<(stateBits*2)) |
|
||||
uint8(blockStateTail<<(stateBits*1)) |
|
||||
uint8(blockStateTail<<(stateBits*0))
|
||||
|
||||
var (
|
||||
heapStart uintptr // start address of heap area
|
||||
heapEnd uintptr // end address of heap area
|
||||
globalsStart uintptr // start address of global variable area
|
||||
globalsEnd uintptr // end address of global variable area
|
||||
stackTop uintptr // the top of stack
|
||||
endBlock uintptr // GC end block index
|
||||
metadataStart unsafe.Pointer // start address of GC metadata
|
||||
|
||||
nextAlloc uintptr // the next block that should be tried by the allocator
|
||||
gcTotalAlloc uint64 // total number of bytes allocated
|
||||
gcTotalBlocks uint64 // total number of allocated blocks
|
||||
gcMallocs uint64 // total number of allocations
|
||||
gcFrees uint64 // total number of objects freed
|
||||
gcFreedBlocks uint64 // total number of freed blocks
|
||||
|
||||
// stackOverflow is a flag which is set when the GC scans too deep while marking.
|
||||
// After it is set, all marked allocations must be re-scanned.
|
||||
markStackOverflow bool
|
||||
|
||||
// zeroSizedAlloc is just a sentinel that gets returned when allocating 0 bytes.
|
||||
zeroSizedAlloc uint8
|
||||
|
||||
gcMutex mutex // gcMutex protects GC related variables
|
||||
isGCInit bool // isGCInit indicates GC initialization state
|
||||
)
|
||||
|
||||
// Some globals + constants for the entire GC.
|
||||
|
||||
const (
|
||||
wordsPerBlock = 4 // number of pointers in an allocated block
|
||||
bytesPerBlock = wordsPerBlock * unsafe.Sizeof(heapStart)
|
||||
stateBits = 2 // how many bits a block state takes (see blockState type)
|
||||
blocksPerStateByte = 8 / stateBits
|
||||
markStackSize = 8 * unsafe.Sizeof((*int)(nil)) // number of to-be-marked blocks to queue before forcing a rescan
|
||||
)
|
||||
|
||||
// this function MUST be initalized first, which means it's required to be initalized before runtime
|
||||
func initGC() {
|
||||
// reserve 2K blocks for libc internal malloc, we cannot wrap those internal functions
|
||||
heapStart = uintptr(unsafe.Pointer(&_heapStart)) + 2048
|
||||
heapEnd = uintptr(unsafe.Pointer(&_heapEnd))
|
||||
globalsStart = uintptr(unsafe.Pointer(&_globals_start))
|
||||
globalsEnd = uintptr(unsafe.Pointer(&_globals_end))
|
||||
totalSize := heapEnd - heapStart
|
||||
metadataSize := (totalSize + blocksPerStateByte*bytesPerBlock) / (1 + blocksPerStateByte*bytesPerBlock)
|
||||
metadataStart = unsafe.Pointer(heapEnd - metadataSize)
|
||||
endBlock = (uintptr(metadataStart) - heapStart) / bytesPerBlock
|
||||
stackTop = uintptr(unsafe.Pointer(&_stackStart))
|
||||
|
||||
c.Memset(metadataStart, 0, metadataSize)
|
||||
}
|
||||
|
||||
func lazyInit() {
|
||||
if !isGCInit {
|
||||
initGC()
|
||||
isGCInit = true
|
||||
}
|
||||
}
|
||||
|
||||
func gcPanic(s *c.Char) {
|
||||
c.Printf(c.Str("%s"), s)
|
||||
c.Exit(2)
|
||||
}
|
||||
|
||||
// blockFromAddr returns a block given an address somewhere in the heap (which
|
||||
// might not be heap-aligned).
|
||||
func blockFromAddr(addr uintptr) uintptr {
|
||||
if addr < heapStart || addr >= uintptr(metadataStart) {
|
||||
gcPanic(c.Str("gc: trying to get block from invalid address"))
|
||||
}
|
||||
return (addr - heapStart) / bytesPerBlock
|
||||
}
|
||||
|
||||
// Return a pointer to the start of the allocated object.
|
||||
func gcPointerOf(blockAddr uintptr) unsafe.Pointer {
|
||||
return unsafe.Pointer(gcAddressOf(blockAddr))
|
||||
}
|
||||
|
||||
// Return the address of the start of the allocated object.
|
||||
func gcAddressOf(blockAddr uintptr) uintptr {
|
||||
addr := heapStart + blockAddr*bytesPerBlock
|
||||
if addr > uintptr(metadataStart) {
|
||||
gcPanic(c.Str("gc: block pointing inside metadata"))
|
||||
}
|
||||
return addr
|
||||
}
|
||||
|
||||
// findHead returns the head (first block) of an object, assuming the block
|
||||
// points to an allocated object. It returns the same block if this block
|
||||
// already points to the head.
|
||||
func gcFindHead(blockAddr uintptr) uintptr {
|
||||
for {
|
||||
// Optimization: check whether the current block state byte (which
|
||||
// contains the state of multiple blocks) is composed entirely of tail
|
||||
// blocks. If so, we can skip back to the last block in the previous
|
||||
// state byte.
|
||||
// This optimization speeds up findHead for pointers that point into a
|
||||
// large allocation.
|
||||
stateByte := gcStateByteOf(blockAddr)
|
||||
if stateByte == blockStateByteAllTails {
|
||||
blockAddr -= (blockAddr % blocksPerStateByte) + 1
|
||||
continue
|
||||
}
|
||||
|
||||
// Check whether we've found a non-tail block, which means we found the
|
||||
// head.
|
||||
state := gcStateFromByte(blockAddr, stateByte)
|
||||
if state != blockStateTail {
|
||||
break
|
||||
}
|
||||
blockAddr--
|
||||
}
|
||||
if gcStateOf(blockAddr) != blockStateHead && gcStateOf(blockAddr) != blockStateMark {
|
||||
gcPanic(c.Str("gc: found tail without head"))
|
||||
}
|
||||
return blockAddr
|
||||
}
|
||||
|
||||
// findNext returns the first block just past the end of the tail. This may or
|
||||
// may not be the head of an object.
|
||||
func gcFindNext(blockAddr uintptr) uintptr {
|
||||
if gcStateOf(blockAddr) == blockStateHead || gcStateOf(blockAddr) == blockStateMark {
|
||||
blockAddr++
|
||||
}
|
||||
for gcAddressOf(blockAddr) < uintptr(metadataStart) && gcStateOf(blockAddr) == blockStateTail {
|
||||
blockAddr++
|
||||
}
|
||||
return blockAddr
|
||||
}
|
||||
|
||||
func gcStateByteOf(blockAddr uintptr) byte {
|
||||
return *(*uint8)(unsafe.Add(metadataStart, blockAddr/blocksPerStateByte))
|
||||
}
|
||||
|
||||
// Return the block state given a state byte. The state byte must have been
|
||||
// obtained using b.stateByte(), otherwise the result is incorrect.
|
||||
func gcStateFromByte(blockAddr uintptr, stateByte byte) uint8 {
|
||||
return uint8(stateByte>>((blockAddr%blocksPerStateByte)*stateBits)) & blockStateMask
|
||||
}
|
||||
|
||||
// State returns the current block state.
|
||||
func gcStateOf(blockAddr uintptr) uint8 {
|
||||
return gcStateFromByte(blockAddr, gcStateByteOf(blockAddr))
|
||||
}
|
||||
|
||||
// setState sets the current block to the given state, which must contain more
|
||||
// bits than the current state. Allowed transitions: from free to any state and
|
||||
// from head to mark.
|
||||
func gcSetState(blockAddr uintptr, newState uint8) {
|
||||
stateBytePtr := (*uint8)(unsafe.Add(metadataStart, blockAddr/blocksPerStateByte))
|
||||
*stateBytePtr |= uint8(newState << ((blockAddr % blocksPerStateByte) * stateBits))
|
||||
if gcStateOf(blockAddr) != newState {
|
||||
gcPanic(c.Str("gc: setState() was not successful"))
|
||||
}
|
||||
}
|
||||
|
||||
// markFree sets the block state to free, no matter what state it was in before.
|
||||
func gcMarkFree(blockAddr uintptr) {
|
||||
stateBytePtr := (*uint8)(unsafe.Add(metadataStart, blockAddr/blocksPerStateByte))
|
||||
*stateBytePtr &^= uint8(blockStateMask << ((blockAddr % blocksPerStateByte) * stateBits))
|
||||
if gcStateOf(blockAddr) != blockStateFree {
|
||||
gcPanic(c.Str("gc: markFree() was not successful"))
|
||||
}
|
||||
*(*[wordsPerBlock]uintptr)(unsafe.Pointer(gcAddressOf(blockAddr))) = [wordsPerBlock]uintptr{}
|
||||
}
|
||||
|
||||
// unmark changes the state of the block from mark to head. It must be marked
|
||||
// before calling this function.
|
||||
func gcUnmark(blockAddr uintptr) {
|
||||
if gcStateOf(blockAddr) != blockStateMark {
|
||||
gcPanic(c.Str("gc: unmark() on a block that is not marked"))
|
||||
}
|
||||
clearMask := blockStateMask ^ blockStateHead // the bits to clear from the state
|
||||
stateBytePtr := (*uint8)(unsafe.Add(metadataStart, blockAddr/blocksPerStateByte))
|
||||
*stateBytePtr &^= uint8(clearMask << ((blockAddr % blocksPerStateByte) * stateBits))
|
||||
if gcStateOf(blockAddr) != blockStateHead {
|
||||
gcPanic(c.Str("gc: unmark() was not successful"))
|
||||
}
|
||||
}
|
||||
|
||||
func isOnHeap(ptr uintptr) bool {
|
||||
return ptr >= heapStart && ptr < uintptr(metadataStart)
|
||||
}
|
||||
|
||||
func isPointer(ptr uintptr) bool {
|
||||
// TODO: implement precise GC
|
||||
return isOnHeap(ptr)
|
||||
}
|
||||
|
||||
// alloc tries to find some free space on the heap, possibly doing a garbage
|
||||
// collection cycle if needed. If no space is free, it panics.
|
||||
//
|
||||
//go:noinline
|
||||
func Alloc(size uintptr) unsafe.Pointer {
|
||||
if size == 0 {
|
||||
return unsafe.Pointer(&zeroSizedAlloc)
|
||||
}
|
||||
lock(&gcMutex)
|
||||
lazyInit()
|
||||
|
||||
gcTotalAlloc += uint64(size)
|
||||
gcMallocs++
|
||||
|
||||
neededBlocks := (size + (bytesPerBlock - 1)) / bytesPerBlock
|
||||
gcTotalBlocks += uint64(neededBlocks)
|
||||
|
||||
// Continue looping until a run of free blocks has been found that fits the
|
||||
// requested size.
|
||||
index := nextAlloc
|
||||
numFreeBlocks := uintptr(0)
|
||||
heapScanCount := uint8(0)
|
||||
for {
|
||||
if index == nextAlloc {
|
||||
if heapScanCount == 0 {
|
||||
heapScanCount = 1
|
||||
} else if heapScanCount == 1 {
|
||||
// The entire heap has been searched for free memory, but none
|
||||
// could be found. Run a garbage collection cycle to reclaim
|
||||
// free memory and try again.
|
||||
heapScanCount = 2
|
||||
freeBytes := gc()
|
||||
heapSize := uintptr(metadataStart) - heapStart
|
||||
if freeBytes < heapSize/3 {
|
||||
// Ensure there is at least 33% headroom.
|
||||
// This percentage was arbitrarily chosen, and may need to
|
||||
// be tuned in the future.
|
||||
growHeap()
|
||||
}
|
||||
} else {
|
||||
// Even after garbage collection, no free memory could be found.
|
||||
// Try to increase heap size.
|
||||
if growHeap() {
|
||||
// Success, the heap was increased in size. Try again with a
|
||||
// larger heap.
|
||||
} else {
|
||||
// Unfortunately the heap could not be increased. This
|
||||
// happens on baremetal systems for example (where all
|
||||
// available RAM has already been dedicated to the heap).
|
||||
gcPanic(c.Str("out of memory"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Wrap around the end of the heap.
|
||||
if index == endBlock {
|
||||
index = 0
|
||||
// Reset numFreeBlocks as allocations cannot wrap.
|
||||
numFreeBlocks = 0
|
||||
// In rare cases, the initial heap might be so small that there are
|
||||
// no blocks at all. In this case, it's better to jump back to the
|
||||
// start of the loop and try again, until the GC realizes there is
|
||||
// no memory and grows the heap.
|
||||
// This can sometimes happen on WebAssembly, where the initial heap
|
||||
// is created by whatever is left on the last memory page.
|
||||
continue
|
||||
}
|
||||
|
||||
// Is the block we're looking at free?
|
||||
if gcStateOf(index) != blockStateFree {
|
||||
// This block is in use. Try again from this point.
|
||||
numFreeBlocks = 0
|
||||
index++
|
||||
continue
|
||||
}
|
||||
numFreeBlocks++
|
||||
index++
|
||||
|
||||
// Are we finished?
|
||||
if numFreeBlocks == neededBlocks {
|
||||
// Found a big enough range of free blocks!
|
||||
nextAlloc = index
|
||||
thisAlloc := index - neededBlocks
|
||||
|
||||
// Set the following blocks as being allocated.
|
||||
gcSetState(thisAlloc, blockStateHead)
|
||||
for i := thisAlloc + 1; i != nextAlloc; i++ {
|
||||
gcSetState(i, blockStateTail)
|
||||
}
|
||||
unlock(&gcMutex)
|
||||
// Return a pointer to this allocation.
|
||||
return c.Memset(gcPointerOf(thisAlloc), 0, size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer {
|
||||
if ptr == nil {
|
||||
return Alloc(size)
|
||||
}
|
||||
lock(&gcMutex)
|
||||
lazyInit()
|
||||
unlock(&gcMutex)
|
||||
|
||||
ptrAddress := uintptr(ptr)
|
||||
endOfTailAddress := gcAddressOf(gcFindNext(blockFromAddr(ptrAddress)))
|
||||
|
||||
// this might be a few bytes longer than the original size of
|
||||
// ptr, because we align to full blocks of size bytesPerBlock
|
||||
oldSize := endOfTailAddress - ptrAddress
|
||||
if size <= oldSize {
|
||||
return ptr
|
||||
}
|
||||
|
||||
newAlloc := Alloc(size)
|
||||
c.Memcpy(newAlloc, ptr, oldSize)
|
||||
free(ptr)
|
||||
|
||||
return newAlloc
|
||||
}
|
||||
|
||||
func free(ptr unsafe.Pointer) {
|
||||
// TODO: free blocks on request, when the compiler knows they're unused.
|
||||
}
|
||||
|
||||
func GC() uintptr {
|
||||
lock(&gcMutex)
|
||||
freeBytes := gc()
|
||||
unlock(&gcMutex)
|
||||
return freeBytes
|
||||
}
|
||||
|
||||
// runGC performs a garbage collection cycle. It is the internal implementation
|
||||
// of the runtime.GC() function. The difference is that it returns the number of
|
||||
// free bytes in the heap after the GC is finished.
|
||||
func gc() (freeBytes uintptr) {
|
||||
lazyInit()
|
||||
|
||||
if gcDebug {
|
||||
println("running collection cycle...")
|
||||
}
|
||||
|
||||
// Mark phase: mark all reachable objects, recursively.
|
||||
gcMarkReachable()
|
||||
|
||||
finishMark()
|
||||
|
||||
// If we're using threads, resume all other threads before starting the
|
||||
// sweep.
|
||||
gcResumeWorld()
|
||||
|
||||
// Sweep phase: free all non-marked objects and unmark marked objects for
|
||||
// the next collection cycle.
|
||||
freeBytes = sweep()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// markRoots reads all pointers from start to end (exclusive) and if they look
|
||||
// like a heap pointer and are unmarked, marks them and scans that object as
|
||||
// well (recursively). The start and end parameters must be valid pointers and
|
||||
// must be aligned.
|
||||
func markRoots(start, end uintptr) {
|
||||
if start >= end {
|
||||
gcPanic(c.Str("gc: unexpected range to mark"))
|
||||
}
|
||||
// Reduce the end bound to avoid reading too far on platforms where pointer alignment is smaller than pointer size.
|
||||
// If the size of the range is 0, then end will be slightly below start after this.
|
||||
end -= unsafe.Sizeof(end) - unsafe.Alignof(end)
|
||||
|
||||
for addr := start; addr < end; addr += unsafe.Alignof(addr) {
|
||||
root := *(*uintptr)(unsafe.Pointer(addr))
|
||||
markRoot(addr, root)
|
||||
}
|
||||
}
|
||||
|
||||
// startMark starts the marking process on a root and all of its children.
|
||||
func startMark(root uintptr) {
|
||||
var stack [markStackSize]uintptr
|
||||
stack[0] = root
|
||||
gcSetState(root, blockStateMark)
|
||||
stackLen := 1
|
||||
for stackLen > 0 {
|
||||
// Pop a block off of the stack.
|
||||
stackLen--
|
||||
block := stack[stackLen]
|
||||
|
||||
start, end := gcAddressOf(block), gcAddressOf(gcFindNext(block))
|
||||
|
||||
for addr := start; addr != end; addr += unsafe.Alignof(addr) {
|
||||
// Load the word.
|
||||
word := *(*uintptr)(unsafe.Pointer(addr))
|
||||
|
||||
if !isPointer(word) {
|
||||
// Not a heap pointer.
|
||||
continue
|
||||
}
|
||||
|
||||
// Find the corresponding memory block.
|
||||
referencedBlock := blockFromAddr(word)
|
||||
|
||||
if gcStateOf(referencedBlock) == blockStateFree {
|
||||
// The to-be-marked object doesn't actually exist.
|
||||
// This is probably a false positive.
|
||||
continue
|
||||
}
|
||||
|
||||
// Move to the block's head.
|
||||
referencedBlock = gcFindHead(referencedBlock)
|
||||
|
||||
if gcStateOf(referencedBlock) == blockStateMark {
|
||||
// The block has already been marked by something else.
|
||||
continue
|
||||
}
|
||||
|
||||
// Mark block.
|
||||
gcSetState(referencedBlock, blockStateMark)
|
||||
|
||||
if stackLen == len(stack) {
|
||||
// The stack is full.
|
||||
// It is necessary to rescan all marked blocks once we are done.
|
||||
markStackOverflow = true
|
||||
if gcDebug {
|
||||
println("gc stack overflowed")
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// Push the pointer onto the stack to be scanned later.
|
||||
stack[stackLen] = referencedBlock
|
||||
stackLen++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// finishMark finishes the marking process by processing all stack overflows.
|
||||
func finishMark() {
|
||||
for markStackOverflow {
|
||||
// Re-mark all blocks.
|
||||
markStackOverflow = false
|
||||
for block := uintptr(0); block < endBlock; block++ {
|
||||
if gcStateOf(block) != blockStateMark {
|
||||
// Block is not marked, so we do not need to rescan it.
|
||||
continue
|
||||
}
|
||||
|
||||
// Re-mark the block.
|
||||
startMark(block)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// mark a GC root at the address addr.
|
||||
func markRoot(addr, root uintptr) {
|
||||
if isOnHeap(root) {
|
||||
block := blockFromAddr(root)
|
||||
if gcStateOf(block) == blockStateFree {
|
||||
// The to-be-marked object doesn't actually exist.
|
||||
// This could either be a dangling pointer (oops!) but most likely
|
||||
// just a false positive.
|
||||
return
|
||||
}
|
||||
head := gcFindHead(block)
|
||||
|
||||
if gcStateOf(head) != blockStateMark {
|
||||
startMark(head)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sweep goes through all memory and frees unmarked
|
||||
// It returns how many bytes are free in the heap after the sweep.
|
||||
func sweep() (freeBytes uintptr) {
|
||||
freeCurrentObject := false
|
||||
var freed uint64
|
||||
|
||||
for block := uintptr(0); block < endBlock; block++ {
|
||||
switch gcStateOf(block) {
|
||||
case blockStateHead:
|
||||
// Unmarked head. Free it, including all tail blocks following it.
|
||||
gcMarkFree(block)
|
||||
freeCurrentObject = true
|
||||
gcFrees++
|
||||
freed++
|
||||
case blockStateTail:
|
||||
if freeCurrentObject {
|
||||
// This is a tail object following an unmarked head.
|
||||
// Free it now.
|
||||
gcMarkFree(block)
|
||||
freed++
|
||||
}
|
||||
case blockStateMark:
|
||||
// This is a marked object. The next tail blocks must not be freed,
|
||||
// but the mark bit must be removed so the next GC cycle will
|
||||
// collect this object if it is unreferenced then.
|
||||
gcUnmark(block)
|
||||
freeCurrentObject = false
|
||||
case blockStateFree:
|
||||
freeBytes += bytesPerBlock
|
||||
}
|
||||
}
|
||||
gcFreedBlocks += freed
|
||||
freeBytes += uintptr(freed) * bytesPerBlock
|
||||
return
|
||||
}
|
||||
|
||||
// growHeap tries to grow the heap size. It returns true if it succeeds, false
|
||||
// otherwise.
|
||||
func growHeap() bool {
|
||||
// On baremetal, there is no way the heap can be grown.
|
||||
return false
|
||||
}
|
||||
|
||||
func gcMarkReachable() {
|
||||
markRoots(uintptr(getsp()), stackTop)
|
||||
markRoots(globalsStart, globalsEnd)
|
||||
}
|
||||
|
||||
func gcResumeWorld() {
|
||||
// Nothing to do here (single threaded).
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package tinygogc
|
||||
|
||||
// TODO(MeteorsLiu): mutex lock for baremetal GC
|
||||
type mutex struct{}
|
||||
|
||||
func lock(m *mutex) {}
|
||||
|
||||
func unlock(m *mutex) {}
|
||||
@@ -1,604 +0,0 @@
|
||||
//go:build testGC
|
||||
|
||||
package tinygogc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
// Mock a typical embedded system with 128KB RAM
|
||||
mockHeapSize = 128 * 1024 // 128KB
|
||||
mockGlobalsSize = 4 * 1024 // 4KB for globals
|
||||
mockStackSize = 8 * 1024 // 8KB for stack
|
||||
mockReservedSize = 2048 // 2KB reserved as in real implementation
|
||||
)
|
||||
|
||||
type testObject struct {
|
||||
data [4]uintptr
|
||||
}
|
||||
|
||||
// mockGCEnv provides a controlled root environment for GC testing
|
||||
type mockGCEnv struct {
|
||||
memory []byte
|
||||
heapStart uintptr
|
||||
heapEnd uintptr
|
||||
globalsStart uintptr
|
||||
globalsEnd uintptr
|
||||
stackStart uintptr
|
||||
stackEnd uintptr
|
||||
// Controlled root sets for testing
|
||||
rootObjects []unsafe.Pointer
|
||||
// Original GC state to restore
|
||||
originalHeapStart uintptr
|
||||
originalHeapEnd uintptr
|
||||
originalGlobalsStart uintptr
|
||||
originalGlobalsEnd uintptr
|
||||
originalStackTop uintptr
|
||||
originalEndBlock uintptr
|
||||
originalMetadataStart unsafe.Pointer
|
||||
originalNextAlloc uintptr
|
||||
originalIsGCInit bool
|
||||
// Mock mode flag
|
||||
mockMode bool
|
||||
}
|
||||
|
||||
// createMockGCEnv creates a completely isolated GC environment
|
||||
func createMockGCEnv() *mockGCEnv {
|
||||
totalMemory := mockHeapSize + mockGlobalsSize + mockStackSize
|
||||
memory := make([]byte, totalMemory)
|
||||
baseAddr := uintptr(unsafe.Pointer(&memory[0]))
|
||||
|
||||
env := &mockGCEnv{
|
||||
memory: memory,
|
||||
globalsStart: baseAddr,
|
||||
globalsEnd: baseAddr + mockGlobalsSize,
|
||||
heapStart: baseAddr + mockGlobalsSize + mockReservedSize,
|
||||
heapEnd: baseAddr + mockGlobalsSize + mockHeapSize,
|
||||
stackStart: baseAddr + mockGlobalsSize + mockHeapSize,
|
||||
stackEnd: baseAddr + uintptr(totalMemory),
|
||||
rootObjects: make([]unsafe.Pointer, 0),
|
||||
mockMode: false,
|
||||
}
|
||||
|
||||
return env
|
||||
}
|
||||
|
||||
// setupMockGC initializes the GC with mock memory layout using initGC's logic
|
||||
func (env *mockGCEnv) setupMockGC() {
|
||||
// Save original GC state
|
||||
env.originalHeapStart = heapStart
|
||||
env.originalHeapEnd = heapEnd
|
||||
env.originalGlobalsStart = globalsStart
|
||||
env.originalGlobalsEnd = globalsEnd
|
||||
env.originalStackTop = stackTop
|
||||
env.originalEndBlock = endBlock
|
||||
env.originalMetadataStart = metadataStart
|
||||
env.originalNextAlloc = nextAlloc
|
||||
env.originalIsGCInit = isGCInit
|
||||
|
||||
// Set currentStack for getsp()
|
||||
currentStack = env.stackStart
|
||||
|
||||
// Apply initGC's logic with our mock memory layout
|
||||
// This is the same logic as initGC() but with our mock addresses
|
||||
heapStart = env.heapStart + 2048 // reserve 2K blocks like initGC does
|
||||
heapEnd = env.heapEnd
|
||||
globalsStart = env.globalsStart
|
||||
globalsEnd = env.globalsEnd
|
||||
stackTop = env.stackEnd
|
||||
|
||||
totalSize := heapEnd - heapStart
|
||||
metadataSize := (totalSize + blocksPerStateByte*bytesPerBlock) / (1 + blocksPerStateByte*bytesPerBlock)
|
||||
metadataStart = unsafe.Pointer(heapEnd - metadataSize)
|
||||
endBlock = (uintptr(metadataStart) - heapStart) / bytesPerBlock
|
||||
|
||||
// Clear metadata using memset like initGC does
|
||||
c.Memset(metadataStart, 0, metadataSize)
|
||||
|
||||
// Reset allocator state and all GC statistics for clean test environment
|
||||
nextAlloc = 0
|
||||
isGCInit = true
|
||||
|
||||
// Reset all GC statistics to start from clean state
|
||||
gcTotalAlloc = 0
|
||||
gcTotalBlocks = 0
|
||||
gcMallocs = 0
|
||||
gcFrees = 0
|
||||
gcFreedBlocks = 0
|
||||
markStackOverflow = false
|
||||
}
|
||||
|
||||
// restoreOriginalGC restores the original GC state
|
||||
func (env *mockGCEnv) restoreOriginalGC() {
|
||||
heapStart = env.originalHeapStart
|
||||
heapEnd = env.originalHeapEnd
|
||||
globalsStart = env.originalGlobalsStart
|
||||
globalsEnd = env.originalGlobalsEnd
|
||||
stackTop = env.originalStackTop
|
||||
endBlock = env.originalEndBlock
|
||||
metadataStart = env.originalMetadataStart
|
||||
nextAlloc = env.originalNextAlloc
|
||||
isGCInit = false
|
||||
}
|
||||
|
||||
// enableMockMode enables mock root scanning mode
|
||||
func (env *mockGCEnv) enableMockMode() {
|
||||
env.mockMode = true
|
||||
}
|
||||
|
||||
// disableMockMode disables mock root scanning mode
|
||||
func (env *mockGCEnv) disableMockMode() {
|
||||
env.mockMode = false
|
||||
}
|
||||
|
||||
// addRoot adds an object to the controlled root set
|
||||
func (env *mockGCEnv) addRoot(ptr unsafe.Pointer) {
|
||||
env.rootObjects = append(env.rootObjects, ptr)
|
||||
}
|
||||
|
||||
// clearRoots removes all objects from the controlled root set
|
||||
func (env *mockGCEnv) clearRoots() {
|
||||
env.rootObjects = env.rootObjects[:0]
|
||||
}
|
||||
|
||||
// mockMarkReachable replaces gcMarkReachable when in mock mode
|
||||
func (env *mockGCEnv) mockMarkReachable() {
|
||||
if !env.mockMode {
|
||||
// Use original logic
|
||||
markRoots(uintptr(getsp()), stackTop)
|
||||
markRoots(globalsStart, globalsEnd)
|
||||
return
|
||||
}
|
||||
|
||||
// Mock mode: only scan our controlled roots
|
||||
for _, root := range env.rootObjects {
|
||||
addr := uintptr(root)
|
||||
markRoot(addr, addr)
|
||||
}
|
||||
}
|
||||
|
||||
// runMockGC runs standard GC but with controlled root scanning
|
||||
func (env *mockGCEnv) runMockGC() uintptr {
|
||||
lock(&gcMutex)
|
||||
defer unlock(&gcMutex)
|
||||
|
||||
lazyInit()
|
||||
|
||||
if gcDebug {
|
||||
println("running mock collection cycle...")
|
||||
}
|
||||
|
||||
// Mark phase: use our mock root scanning
|
||||
env.mockMarkReachable()
|
||||
finishMark()
|
||||
|
||||
// Resume world (no-op in single threaded)
|
||||
gcResumeWorld()
|
||||
|
||||
// Sweep phase: use standard sweep logic
|
||||
return sweep()
|
||||
}
|
||||
|
||||
// createTestObjects creates a network of objects for testing reachability
|
||||
func createTestObjects(env *mockGCEnv) []*testObject {
|
||||
// Allocate several test objects
|
||||
objects := make([]*testObject, 0, 10)
|
||||
|
||||
// Dependencies Graph
|
||||
// root1 -> child1 -> grandchild1 -> child2
|
||||
// root1 -> child2 -> grandchild1
|
||||
|
||||
// Create root objects (reachable from stack/globals)
|
||||
root1 := (*testObject)(Alloc(unsafe.Sizeof(testObject{})))
|
||||
root2 := (*testObject)(Alloc(unsafe.Sizeof(testObject{})))
|
||||
objects = append(objects, root1, root2)
|
||||
|
||||
// Create objects reachable from root1
|
||||
child1 := (*testObject)(Alloc(unsafe.Sizeof(testObject{})))
|
||||
child2 := (*testObject)(Alloc(unsafe.Sizeof(testObject{})))
|
||||
root1.data[0] = uintptr(unsafe.Pointer(child1))
|
||||
root1.data[1] = uintptr(unsafe.Pointer(child2))
|
||||
objects = append(objects, child1, child2)
|
||||
|
||||
// Create objects reachable from child1
|
||||
grandchild1 := (*testObject)(Alloc(unsafe.Sizeof(testObject{})))
|
||||
child1.data[0] = uintptr(unsafe.Pointer(grandchild1))
|
||||
objects = append(objects, grandchild1)
|
||||
|
||||
// Create circular reference between child2 and grandchild1
|
||||
child2.data[0] = uintptr(unsafe.Pointer(grandchild1))
|
||||
grandchild1.data[0] = uintptr(unsafe.Pointer(child2))
|
||||
|
||||
// Create unreachable objects (garbage)
|
||||
garbage1 := (*testObject)(Alloc(unsafe.Sizeof(testObject{})))
|
||||
garbage2 := (*testObject)(Alloc(unsafe.Sizeof(testObject{})))
|
||||
// Create circular reference in garbage
|
||||
garbage1.data[0] = uintptr(unsafe.Pointer(garbage2))
|
||||
garbage2.data[0] = uintptr(unsafe.Pointer(garbage1))
|
||||
objects = append(objects, garbage1, garbage2)
|
||||
|
||||
return objects
|
||||
}
|
||||
|
||||
func TestMockGCBasicAllocation(t *testing.T) {
|
||||
env := createMockGCEnv()
|
||||
env.setupMockGC()
|
||||
defer env.restoreOriginalGC()
|
||||
|
||||
// Test basic allocation
|
||||
ptr1 := Alloc(32)
|
||||
if ptr1 == nil {
|
||||
t.Fatal("Failed to allocate 32 bytes")
|
||||
}
|
||||
|
||||
ptr2 := Alloc(64)
|
||||
if ptr2 == nil {
|
||||
t.Fatal("Failed to allocate 64 bytes")
|
||||
}
|
||||
|
||||
// Verify pointers are within heap bounds
|
||||
addr1 := uintptr(ptr1)
|
||||
addr2 := uintptr(ptr2)
|
||||
|
||||
if addr1 < heapStart || addr1 >= uintptr(metadataStart) {
|
||||
t.Errorf("ptr1 %x not within heap bounds [%x, %x)", addr1, heapStart, uintptr(metadataStart))
|
||||
}
|
||||
|
||||
if addr2 < heapStart || addr2 >= uintptr(metadataStart) {
|
||||
t.Errorf("ptr2 %x not within heap bounds [%x, %x)", addr2, heapStart, uintptr(metadataStart))
|
||||
}
|
||||
|
||||
t.Logf("Allocated ptr1 at %x, ptr2 at %x", addr1, addr2)
|
||||
t.Logf("Heap bounds: [%x, %x)", heapStart, uintptr(metadataStart))
|
||||
}
|
||||
|
||||
func TestMockGCReachabilityAndSweep(t *testing.T) {
|
||||
env := createMockGCEnv()
|
||||
env.setupMockGC()
|
||||
defer env.restoreOriginalGC()
|
||||
|
||||
// Track initial stats
|
||||
initialMallocs := gcMallocs
|
||||
initialFrees := gcFrees
|
||||
|
||||
// Create test object network
|
||||
objects := createTestObjects(env)
|
||||
|
||||
// Add first 2 objects as roots using mock control
|
||||
env.enableMockMode()
|
||||
env.addRoot(unsafe.Pointer(objects[0])) // root1
|
||||
env.addRoot(unsafe.Pointer(objects[1])) // root2
|
||||
|
||||
t.Logf("Created %d objects, 2 are roots", len(objects))
|
||||
t.Logf("Mallocs: %d", gcMallocs-initialMallocs)
|
||||
|
||||
// Verify all objects are initially allocated
|
||||
for i, obj := range objects {
|
||||
addr := uintptr(unsafe.Pointer(obj))
|
||||
block := blockFromAddr(addr)
|
||||
state := gcStateOf(block)
|
||||
if state != blockStateHead {
|
||||
t.Errorf("Object %d at %x has state %d, expected %d (HEAD)", i, addr, state, blockStateHead)
|
||||
}
|
||||
}
|
||||
|
||||
// Perform GC with controlled root scanning
|
||||
freedBytes := env.runMockGC()
|
||||
t.Logf("Freed %d bytes during GC", freedBytes)
|
||||
t.Logf("Frees: %d (delta: %d)", gcFrees, gcFrees-initialFrees)
|
||||
|
||||
// Verify reachable objects are still allocated
|
||||
reachableObjects := []unsafe.Pointer{
|
||||
unsafe.Pointer(objects[0]), // root1
|
||||
unsafe.Pointer(objects[1]), // root2
|
||||
unsafe.Pointer(objects[2]), // child1 (reachable from root1)
|
||||
unsafe.Pointer(objects[3]), // child2 (reachable from root1)
|
||||
unsafe.Pointer(objects[4]), // grandchild1 (reachable from child1, child2)
|
||||
}
|
||||
|
||||
for i, obj := range reachableObjects {
|
||||
addr := uintptr(obj)
|
||||
block := blockFromAddr(addr)
|
||||
state := gcStateOf(block)
|
||||
if state != blockStateHead {
|
||||
t.Errorf("Reachable object %d at %x has state %d, expected %d (HEAD)", i, addr, state, blockStateHead)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify unreachable objects are freed
|
||||
unreachableObjects := []unsafe.Pointer{
|
||||
unsafe.Pointer(objects[5]), // garbage1
|
||||
unsafe.Pointer(objects[6]), // garbage2
|
||||
}
|
||||
|
||||
for i, obj := range unreachableObjects {
|
||||
addr := uintptr(obj)
|
||||
block := blockFromAddr(addr)
|
||||
state := gcStateOf(block)
|
||||
if state != blockStateFree {
|
||||
t.Errorf("Unreachable object %d at %x has state %d, expected %d (FREE)", i, addr, state, blockStateFree)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify some memory was actually freed
|
||||
if freedBytes == 0 {
|
||||
t.Error("Expected some memory to be freed, but freed 0 bytes")
|
||||
}
|
||||
|
||||
if gcFrees == initialFrees {
|
||||
t.Error("Expected some objects to be freed, but free count didn't change")
|
||||
}
|
||||
|
||||
// Clear refs to make grandchild1 unreachable
|
||||
objects[2].data[0] = 0 // child1 -> grandchild1
|
||||
objects[3].data[0] = 0 // child2 -> grandchild1
|
||||
|
||||
// Run GC again with same roots
|
||||
freedBytes = env.runMockGC()
|
||||
|
||||
// child2 should still be reachable (through root1)
|
||||
blockAddr := blockFromAddr(uintptr(unsafe.Pointer(objects[3])))
|
||||
state := gcStateOf(blockAddr)
|
||||
if state != blockStateHead {
|
||||
t.Errorf("Object child2 at %x has state %d, expected %d (HEAD)", blockAddr, state, blockStateHead)
|
||||
}
|
||||
|
||||
// grandchild1 should now be unreachable and freed
|
||||
blockAddr = blockFromAddr(uintptr(unsafe.Pointer(objects[4])))
|
||||
state = gcStateOf(blockAddr)
|
||||
if state != blockStateFree {
|
||||
t.Errorf("Object grandchild1 at %x has state %d, expected %d (FREE)", blockAddr, state, blockStateFree)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMockGCMemoryPressure(t *testing.T) {
|
||||
env := createMockGCEnv()
|
||||
env.setupMockGC()
|
||||
defer env.restoreOriginalGC()
|
||||
|
||||
// Calculate available heap space
|
||||
heapSize := uintptr(metadataStart) - heapStart
|
||||
blockSize := bytesPerBlock
|
||||
maxBlocks := heapSize / blockSize
|
||||
|
||||
t.Logf("Heap size: %d bytes, Block size: %d bytes, Max blocks: %d",
|
||||
heapSize, blockSize, maxBlocks)
|
||||
|
||||
// Allocate until we trigger GC
|
||||
var allocations []unsafe.Pointer
|
||||
allocSize := uintptr(32) // Small allocations
|
||||
|
||||
// Allocate about 80% of heap to trigger GC pressure
|
||||
targetAllocations := int(maxBlocks * 4 / 5) // 80% capacity
|
||||
|
||||
for i := 0; i < targetAllocations; i++ {
|
||||
ptr := Alloc(allocSize)
|
||||
if ptr == nil {
|
||||
t.Fatalf("Failed to allocate at iteration %d", i)
|
||||
}
|
||||
allocations = append(allocations, ptr)
|
||||
}
|
||||
|
||||
initialMallocs := gcMallocs
|
||||
t.Logf("Allocated %d objects (%d mallocs total)", len(allocations), initialMallocs)
|
||||
|
||||
// Enable mock mode and keep only half the allocations as roots
|
||||
env.enableMockMode()
|
||||
keepCount := len(allocations) / 2
|
||||
for i := 0; i < keepCount; i++ {
|
||||
env.addRoot(allocations[i])
|
||||
}
|
||||
|
||||
t.Logf("Keeping %d objects as roots, %d should be freed", keepCount, len(allocations)-keepCount)
|
||||
|
||||
// Force GC with controlled roots
|
||||
freeBytes := env.runMockGC()
|
||||
|
||||
t.Logf("GC freed %d bytes", freeBytes)
|
||||
t.Logf("Objects freed: %d", gcFrees)
|
||||
|
||||
// Try to allocate more after GC
|
||||
for i := 0; i < 10; i++ {
|
||||
ptr := Alloc(allocSize)
|
||||
if ptr == nil {
|
||||
t.Fatalf("Failed to allocate after GC at iteration %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
t.Log("Successfully allocated more objects after GC")
|
||||
}
|
||||
|
||||
func TestMockGCStats(t *testing.T) {
|
||||
env := createMockGCEnv()
|
||||
env.setupMockGC()
|
||||
defer env.restoreOriginalGC()
|
||||
|
||||
// Get initial stats
|
||||
initialStats := ReadGCStats()
|
||||
t.Logf("Initial stats - Mallocs: %d, Frees: %d, TotalAlloc: %d, Alloc: %d",
|
||||
initialStats.Mallocs, initialStats.Frees, initialStats.TotalAlloc, initialStats.Alloc)
|
||||
|
||||
// Verify basic system stats
|
||||
expectedSys := uint64(env.heapEnd - env.heapStart - 2048)
|
||||
if initialStats.Sys != expectedSys {
|
||||
t.Errorf("Expected Sys %d, got %d", expectedSys, initialStats.Sys)
|
||||
}
|
||||
|
||||
expectedGCSys := uint64(env.heapEnd - uintptr(metadataStart))
|
||||
if initialStats.GCSys != expectedGCSys {
|
||||
t.Errorf("Expected GCSys %d, got %d", expectedGCSys, initialStats.GCSys)
|
||||
}
|
||||
|
||||
// Allocate some objects
|
||||
var allocations []unsafe.Pointer
|
||||
allocSize := uintptr(64)
|
||||
numAllocs := 10
|
||||
|
||||
for i := 0; i < numAllocs; i++ {
|
||||
ptr := Alloc(allocSize)
|
||||
if ptr == nil {
|
||||
t.Fatalf("Failed to allocate at iteration %d", i)
|
||||
}
|
||||
allocations = append(allocations, ptr)
|
||||
}
|
||||
|
||||
// Check stats after allocation
|
||||
afterAllocStats := ReadGCStats()
|
||||
t.Logf("After allocation - Mallocs: %d, Frees: %d, TotalAlloc: %d, Alloc: %d",
|
||||
afterAllocStats.Mallocs, afterAllocStats.Frees, afterAllocStats.TotalAlloc, afterAllocStats.Alloc)
|
||||
|
||||
// Verify allocation stats increased
|
||||
if afterAllocStats.Mallocs <= initialStats.Mallocs {
|
||||
t.Errorf("Expected Mallocs to increase from %d, got %d", initialStats.Mallocs, afterAllocStats.Mallocs)
|
||||
}
|
||||
|
||||
if afterAllocStats.TotalAlloc <= initialStats.TotalAlloc {
|
||||
t.Errorf("Expected TotalAlloc to increase from %d, got %d", initialStats.TotalAlloc, afterAllocStats.TotalAlloc)
|
||||
}
|
||||
|
||||
if afterAllocStats.Alloc <= initialStats.Alloc {
|
||||
t.Errorf("Expected Alloc to increase from %d, got %d", initialStats.Alloc, afterAllocStats.Alloc)
|
||||
}
|
||||
|
||||
// Verify Alloc and HeapAlloc are the same
|
||||
if afterAllocStats.Alloc != afterAllocStats.HeapAlloc {
|
||||
t.Errorf("Expected Alloc (%d) to equal HeapAlloc (%d)", afterAllocStats.Alloc, afterAllocStats.HeapAlloc)
|
||||
}
|
||||
|
||||
// Perform GC with controlled roots - keep only half the allocations
|
||||
env.enableMockMode()
|
||||
keepCount := len(allocations) / 2
|
||||
for i := 0; i < keepCount; i++ {
|
||||
env.addRoot(allocations[i])
|
||||
}
|
||||
|
||||
freedBytes := env.runMockGC()
|
||||
t.Logf("GC freed %d bytes", freedBytes)
|
||||
|
||||
// Check stats after GC
|
||||
afterGCStats := ReadGCStats()
|
||||
t.Logf("After GC - Mallocs: %d, Frees: %d, TotalAlloc: %d, Alloc: %d",
|
||||
afterGCStats.Mallocs, afterGCStats.Frees, afterGCStats.TotalAlloc, afterGCStats.Alloc)
|
||||
|
||||
// Verify GC stats
|
||||
if afterGCStats.Frees <= afterAllocStats.Frees {
|
||||
t.Errorf("Expected Frees to increase from %d, got %d", afterAllocStats.Frees, afterGCStats.Frees)
|
||||
}
|
||||
|
||||
// TotalAlloc should not decrease (cumulative)
|
||||
if afterGCStats.TotalAlloc != afterAllocStats.TotalAlloc {
|
||||
t.Errorf("Expected TotalAlloc to remain %d after GC, got %d", afterAllocStats.TotalAlloc, afterGCStats.TotalAlloc)
|
||||
}
|
||||
|
||||
// Alloc should decrease (freed objects)
|
||||
if afterGCStats.Alloc >= afterAllocStats.Alloc {
|
||||
t.Errorf("Expected Alloc to decrease from %d after GC, got %d", afterAllocStats.Alloc, afterGCStats.Alloc)
|
||||
}
|
||||
|
||||
// Verify heap statistics consistency
|
||||
if afterGCStats.HeapSys != afterGCStats.HeapInuse+afterGCStats.HeapIdle {
|
||||
t.Errorf("Expected HeapSys (%d) to equal HeapInuse (%d) + HeapIdle (%d)",
|
||||
afterGCStats.HeapSys, afterGCStats.HeapInuse, afterGCStats.HeapIdle)
|
||||
}
|
||||
|
||||
// Verify live objects calculation
|
||||
expectedLiveObjects := afterGCStats.Mallocs - afterGCStats.Frees
|
||||
t.Logf("Live objects: %d (Mallocs: %d - Frees: %d)", expectedLiveObjects, afterGCStats.Mallocs, afterGCStats.Frees)
|
||||
|
||||
// The number of live objects should be reasonable (we kept half the allocations plus some overhead)
|
||||
if expectedLiveObjects < uint64(keepCount) {
|
||||
t.Errorf("Expected at least %d live objects, got %d", keepCount, expectedLiveObjects)
|
||||
}
|
||||
|
||||
// Test stack statistics
|
||||
if afterGCStats.StackInuse > afterGCStats.StackSys {
|
||||
t.Errorf("StackInuse (%d) should not exceed StackSys (%d)", afterGCStats.StackInuse, afterGCStats.StackSys)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMockGCCircularReferences(t *testing.T) {
|
||||
env := createMockGCEnv()
|
||||
env.setupMockGC()
|
||||
defer env.restoreOriginalGC()
|
||||
|
||||
type Node struct {
|
||||
data [3]uintptr
|
||||
next uintptr
|
||||
}
|
||||
|
||||
// Create a circular linked list
|
||||
nodes := make([]*Node, 5)
|
||||
for i := range nodes {
|
||||
nodes[i] = (*Node)(Alloc(unsafe.Sizeof(Node{})))
|
||||
nodes[i].data[0] = uintptr(i) // Store index as data
|
||||
}
|
||||
|
||||
// Link them in a circle
|
||||
for i := range nodes {
|
||||
nextIdx := (i + 1) % len(nodes)
|
||||
nodes[i].next = uintptr(unsafe.Pointer(nodes[nextIdx]))
|
||||
}
|
||||
|
||||
t.Logf("Created circular list of %d nodes", len(nodes))
|
||||
|
||||
// Initially all should be allocated
|
||||
for i, node := range nodes {
|
||||
addr := uintptr(unsafe.Pointer(node))
|
||||
block := blockFromAddr(addr)
|
||||
state := gcStateOf(block)
|
||||
if state != blockStateHead {
|
||||
t.Errorf("Node %d at %x has state %d, expected %d", i, addr, state, blockStateHead)
|
||||
}
|
||||
}
|
||||
|
||||
// Test 1: With root references - objects should NOT be freed
|
||||
env.enableMockMode()
|
||||
// Add the first node as root (keeps entire circle reachable)
|
||||
env.addRoot(unsafe.Pointer(nodes[0]))
|
||||
|
||||
freeBytes := env.runMockGC()
|
||||
t.Logf("GC with root reference freed %d bytes", freeBytes)
|
||||
|
||||
// All nodes should still be allocated since they're reachable through the root
|
||||
for i, node := range nodes {
|
||||
addr := uintptr(unsafe.Pointer(node))
|
||||
block := blockFromAddr(addr)
|
||||
state := gcStateOf(block)
|
||||
if state != blockStateHead {
|
||||
t.Errorf("Node %d at %x should still be allocated, but has state %d", i, addr, state)
|
||||
}
|
||||
}
|
||||
|
||||
// Test 2: Without root references - all circular objects should be freed
|
||||
env.clearRoots() // Remove all root references
|
||||
|
||||
freeBytes = env.runMockGC()
|
||||
t.Logf("GC without roots freed %d bytes", freeBytes)
|
||||
|
||||
// All nodes should now be freed since they're not reachable from any roots
|
||||
expectedFreed := uintptr(len(nodes)) * ((unsafe.Sizeof(Node{}) + bytesPerBlock - 1) / bytesPerBlock) * bytesPerBlock
|
||||
|
||||
if freeBytes < expectedFreed {
|
||||
t.Errorf("Expected at least %d bytes freed, got %d", expectedFreed, freeBytes)
|
||||
}
|
||||
|
||||
// Verify all nodes are actually freed
|
||||
for i, node := range nodes {
|
||||
addr := uintptr(unsafe.Pointer(node))
|
||||
block := blockFromAddr(addr)
|
||||
state := gcStateOf(block)
|
||||
if state != blockStateFree {
|
||||
t.Errorf("Node %d at %x should be freed, but has state %d", i, addr, state)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify we can allocate new objects in the freed space
|
||||
newPtr := Alloc(unsafe.Sizeof(Node{}))
|
||||
if newPtr == nil {
|
||||
t.Error("Failed to allocate after freeing circular references")
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build !nogc && !baremetal
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025 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 runtime
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/bdwgc"
|
||||
)
|
||||
|
||||
// FreeDeferNode releases a defer argument node allocated from the Boehm heap.
|
||||
func FreeDeferNode(ptr unsafe.Pointer) {
|
||||
if ptr != nil {
|
||||
bdwgc.Free(c.Pointer(ptr))
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
//go:build nogc || baremetal
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025 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 runtime
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
// FreeDeferNode releases the defer node when GC integration is disabled.
|
||||
func FreeDeferNode(ptr unsafe.Pointer) {
|
||||
if ptr != nil {
|
||||
c.Free(ptr)
|
||||
}
|
||||
}
|
||||
@@ -365,7 +365,7 @@ func NewItab(inter *InterfaceType, typ *Type) *Itab {
|
||||
ret.fun[0] = 0
|
||||
} else {
|
||||
data := (*uintptr)(c.Advance(ptr, int(itabHdrSize)))
|
||||
mthds := u.Methods()
|
||||
mthds := methods(u, inter.PkgPath_)
|
||||
for i, m := range inter.Methods {
|
||||
fn := findMethod(mthds, m)
|
||||
if fn == nil {
|
||||
@@ -395,6 +395,13 @@ func findMethod(mthds []abi.Method, im abi.Imethod) abi.Text {
|
||||
return nil
|
||||
}
|
||||
|
||||
func methods(u *abi.UncommonType, from string) []abi.Method {
|
||||
if u.PkgPath_ == from {
|
||||
return u.Methods()
|
||||
}
|
||||
return u.ExportedMethods()
|
||||
}
|
||||
|
||||
func IfaceType(i iface) *abi.Type {
|
||||
if i.tab == nil {
|
||||
return nil
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//go:build !nogc && !baremetal
|
||||
//go:build !nogc
|
||||
// +build !nogc
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
//go:build !nogc && baremetal
|
||||
|
||||
/*
|
||||
* 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 runtime
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/runtime/internal/runtime/tinygogc"
|
||||
)
|
||||
|
||||
// AllocU allocates uninitialized memory.
|
||||
func AllocU(size uintptr) unsafe.Pointer {
|
||||
return tinygogc.Alloc(size)
|
||||
}
|
||||
|
||||
// AllocZ allocates zero-initialized memory.
|
||||
func AllocZ(size uintptr) unsafe.Pointer {
|
||||
return tinygogc.Alloc(size)
|
||||
}
|
||||
@@ -109,6 +109,18 @@ const MaxZero = 1024
|
||||
|
||||
var ZeroVal [MaxZero]byte
|
||||
|
||||
// func init() {
|
||||
// signal.Signal(c.Int(syscall.SIGSEGV), func(v c.Int) {
|
||||
// switch syscall.Signal(v) {
|
||||
// case syscall.SIGSEGV:
|
||||
// panic(errorString("invalid memory address or nil pointer dereference"))
|
||||
// default:
|
||||
// var buf [20]byte
|
||||
// panic(errorString("unexpected signal value: " + string(itoa(buf[:], uint64(v)))))
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type SigjmpBuf struct {
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
//go:build !wasm && !baremetal
|
||||
|
||||
/*
|
||||
* 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 runtime
|
||||
|
||||
import (
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/signal"
|
||||
)
|
||||
|
||||
const (
|
||||
// SIGSEGV is signal number 11 on all Unix-like systems (Linux, Darwin, BSD, etc.)
|
||||
// Using a hardcoded constant avoids importing the syscall package, which would
|
||||
// introduce dependencies on errors and internal/reflectlite packages that cause
|
||||
// linking issues in c-shared and c-archive build modes.
|
||||
SIGSEGV = c.Int(0xb)
|
||||
)
|
||||
|
||||
// This file contains platform-specific runtime initialization for non-wasm targets.
|
||||
// The SIGSEGV signal handler enables Go-style panic recovery for nil pointer dereferences
|
||||
// instead of immediate process termination.
|
||||
//
|
||||
// For wasm platform compatibility, signal handling is excluded via build tags.
|
||||
// See PR #1059 for wasm platform requirements.
|
||||
func init() {
|
||||
signal.Signal(SIGSEGV, func(v c.Int) {
|
||||
if v == SIGSEGV {
|
||||
panic(errorString("invalid memory address or nil pointer dereference"))
|
||||
}
|
||||
var buf [20]byte
|
||||
panic(errorString("unexpected signal value: " + string(itoa(buf[:], uint64(v)))))
|
||||
})
|
||||
}
|
||||
@@ -7,11 +7,27 @@ import (
|
||||
//go:embed _overlay/runtime/runtime.go
|
||||
var fakeRuntime string
|
||||
|
||||
//go:embed _overlay/go/parser/resolver.go
|
||||
var go_parser_resolver string
|
||||
|
||||
//go:embed _overlay/testing/testing.go
|
||||
var testing_testing string
|
||||
|
||||
//go:embed _overlay/testing/testing_go123.go
|
||||
var testing_testing_go123 string
|
||||
|
||||
//go:embed _overlay/testing/testing_go124.go
|
||||
var testing_testing_go124 string
|
||||
|
||||
//go:embed _overlay/net/textproto/textproto.go
|
||||
var net_textproto string
|
||||
|
||||
var OverlayFiles = map[string]string{
|
||||
"math/exp_amd64.go": "package math;",
|
||||
"go/parser/resolver.go": go_parser_resolver,
|
||||
"testing/testing.go": testing_testing,
|
||||
"testing/testing_go123.go": testing_testing_go123,
|
||||
"testing/testing_go124.go": testing_testing_go124,
|
||||
"net/textproto/textproto.go": net_textproto,
|
||||
"runtime/runtime.go": fakeRuntime,
|
||||
}
|
||||
|
||||
@@ -186,6 +186,7 @@ func (b Builder) abiInterfaceOf(t *types.Interface) func() Expr {
|
||||
}
|
||||
return func() Expr {
|
||||
prog := b.Prog
|
||||
pkg := b.Pkg
|
||||
methods := make([]Expr, n)
|
||||
for i := 0; i < n; i++ {
|
||||
m := t.Method(i)
|
||||
@@ -195,7 +196,6 @@ func (b Builder) abiInterfaceOf(t *types.Interface) func() Expr {
|
||||
}
|
||||
methods[i] = b.abiImethodOf(mName, typs[i])
|
||||
}
|
||||
pkg := b.Pkg
|
||||
fn := pkg.rtFunc("Interface")
|
||||
tSlice := lastParamType(prog, fn)
|
||||
methodSlice := b.SliceLit(tSlice, methods...)
|
||||
|
||||
@@ -294,7 +294,7 @@ func (p Function) NewBuilder() Builder {
|
||||
// TODO(xsw): Finalize may cause panic, so comment it.
|
||||
// b.Finalize()
|
||||
return &aBuilder{b, nil, p, p.Pkg, prog,
|
||||
make(map[*types.Scope]DIScope)}
|
||||
make(map[Expr]dbgExpr), make(map[*types.Scope]DIScope)}
|
||||
}
|
||||
|
||||
// HasBody reports whether the function has a body.
|
||||
|
||||
12
ssa/di.go
12
ssa/di.go
@@ -662,8 +662,14 @@ func (b diBuilder) createExpression(ops []uint64) DIExpression {
|
||||
|
||||
// Copy to alloca'd memory to get declareable address.
|
||||
func (b Builder) constructDebugAddr(v Expr) (dbgPtr Expr, dbgVal Expr, exists bool) {
|
||||
if v, ok := b.dbgVars[v]; ok {
|
||||
return v.ptr, v.val, true
|
||||
}
|
||||
t := v.Type.RawType().Underlying()
|
||||
dbgPtr, dbgVal = b.doConstructDebugAddr(v, t)
|
||||
dbgExpr := dbgExpr{dbgPtr, dbgVal}
|
||||
b.dbgVars[v] = dbgExpr
|
||||
b.dbgVars[dbgVal] = dbgExpr
|
||||
return dbgPtr, dbgVal, false
|
||||
}
|
||||
|
||||
@@ -868,7 +874,11 @@ func (b Builder) DebugFunction(f Function, pos token.Position, bodyPos token.Pos
|
||||
}
|
||||
|
||||
func (b Builder) Param(idx int) Expr {
|
||||
return b.Func.Param(idx)
|
||||
p := b.Func.Param(idx)
|
||||
if v, ok := b.dbgVars[p]; ok {
|
||||
return v.val
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
128
ssa/eh.go
128
ssa/eh.go
@@ -91,16 +91,6 @@ func (p Program) tySiglongjmp() *types.Signature {
|
||||
return p.sigljmpTy
|
||||
}
|
||||
|
||||
// func() unsafe.Pointer
|
||||
func (p Program) tyStacksave() *types.Signature {
|
||||
if p.stackSaveTy == nil {
|
||||
paramPtr := types.NewParam(token.NoPos, nil, "", p.VoidPtr().raw.Type)
|
||||
params := types.NewTuple(paramPtr)
|
||||
p.stackSaveTy = types.NewSignatureType(nil, nil, nil, nil, params, false)
|
||||
}
|
||||
return p.stackSaveTy
|
||||
}
|
||||
|
||||
func (b Builder) AllocaSigjmpBuf() Expr {
|
||||
prog := b.Prog
|
||||
n := unsafe.Sizeof(sigjmpbuf{})
|
||||
@@ -108,12 +98,6 @@ func (b Builder) AllocaSigjmpBuf() Expr {
|
||||
return b.Alloca(size)
|
||||
}
|
||||
|
||||
// declare ptr @llvm.stacksave.p0()
|
||||
func (b Builder) StackSave() Expr {
|
||||
fn := b.Pkg.cFunc("llvm.stacksave", b.Prog.tyStacksave())
|
||||
return b.InlineCall(fn)
|
||||
}
|
||||
|
||||
func (b Builder) Sigsetjmp(jb, savemask Expr) Expr {
|
||||
if b.Prog.target.GOARCH == "wasm" {
|
||||
return b.Setjmp(jb)
|
||||
@@ -149,6 +133,10 @@ func (b Builder) Longjmp(jb, retval Expr) {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
deferKey = "__llgo_defer"
|
||||
)
|
||||
|
||||
func (p Function) deferInitBuilder() (b Builder, next BasicBlock) {
|
||||
b = p.NewBuilder()
|
||||
next = b.setBlockMoveLast(p.blks[0])
|
||||
@@ -158,6 +146,7 @@ func (p Function) deferInitBuilder() (b Builder, next BasicBlock) {
|
||||
|
||||
type aDefer struct {
|
||||
nextBit int // next defer bit
|
||||
key Expr // pthread TLS key
|
||||
data Expr // pointer to runtime.Defer
|
||||
bitsPtr Expr // pointer to defer bits
|
||||
rethPtr Expr // next block of Rethrow
|
||||
@@ -169,6 +158,30 @@ type aDefer struct {
|
||||
stmts []func(bits Expr)
|
||||
}
|
||||
|
||||
func (p Package) keyInit(name string) {
|
||||
keyVar := p.VarOf(name)
|
||||
if keyVar == nil {
|
||||
return
|
||||
}
|
||||
prog := p.Prog
|
||||
keyVar.InitNil()
|
||||
keyVar.impl.SetLinkage(llvm.LinkOnceAnyLinkage)
|
||||
|
||||
b := p.afterBuilder()
|
||||
eq := b.BinOp(token.EQL, b.Load(keyVar.Expr), prog.IntVal(0, prog.CInt()))
|
||||
b.IfThen(eq, func() {
|
||||
b.pthreadKeyCreate(keyVar.Expr, prog.Nil(prog.VoidPtr()))
|
||||
})
|
||||
}
|
||||
|
||||
func (p Package) newKey(name string) Global {
|
||||
return p.NewVarEx(name, p.Prog.CIntPtr())
|
||||
}
|
||||
|
||||
func (b Builder) deferKey() Expr {
|
||||
return b.Load(b.Pkg.newKey(deferKey).Expr)
|
||||
}
|
||||
|
||||
const (
|
||||
// 0: addr sigjmpbuf
|
||||
// 1: bits uintptr
|
||||
@@ -201,19 +214,17 @@ func (b Builder) getDefer(kind DoAction) *aDefer {
|
||||
blks := self.MakeBlocks(2)
|
||||
procBlk, rethrowBlk := blks[0], blks[1]
|
||||
|
||||
key := b.deferKey()
|
||||
zero := prog.Val(uintptr(0))
|
||||
link := b.Call(b.Pkg.rtFunc("GetThreadDefer"))
|
||||
link := Expr{b.pthreadGetspecific(key).impl, prog.DeferPtr()}
|
||||
jb := b.AllocaSigjmpBuf()
|
||||
ptr := b.aggregateAllocU(prog.Defer(), jb.impl, zero.impl, link.impl, procBlk.Addr().impl)
|
||||
ptr := b.aggregateAlloca(prog.Defer(), jb.impl, zero.impl, link.impl, procBlk.Addr().impl)
|
||||
deferData := Expr{ptr, prog.DeferPtr()}
|
||||
b.Call(b.Pkg.rtFunc("SetThreadDefer"), deferData)
|
||||
b.pthreadSetspecific(key, deferData)
|
||||
bitsPtr := b.FieldAddr(deferData, deferBits)
|
||||
rethPtr := b.FieldAddr(deferData, deferRethrow)
|
||||
rundPtr := b.FieldAddr(deferData, deferRunDefers)
|
||||
argsPtr := b.FieldAddr(deferData, deferArgs)
|
||||
// Initialize the args list so later guards (e.g. DeferAlways/DeferInLoop)
|
||||
// can safely detect an empty chain without a prior push.
|
||||
b.Store(argsPtr, prog.Nil(prog.VoidPtr()))
|
||||
|
||||
czero := prog.IntVal(0, prog.CInt())
|
||||
retval := b.Sigsetjmp(jb, czero)
|
||||
@@ -226,6 +237,7 @@ func (b Builder) getDefer(kind DoAction) *aDefer {
|
||||
b.If(b.BinOp(token.EQL, retval, czero), next, panicBlk)
|
||||
|
||||
self.defer_ = &aDefer{
|
||||
key: key,
|
||||
data: deferData,
|
||||
bitsPtr: bitsPtr,
|
||||
rethPtr: rethPtr,
|
||||
@@ -250,7 +262,8 @@ func (b Builder) getDefer(kind DoAction) *aDefer {
|
||||
|
||||
// DeferData returns the defer data (*runtime.Defer).
|
||||
func (b Builder) DeferData() Expr {
|
||||
return b.Call(b.Pkg.rtFunc("GetThreadDefer"))
|
||||
key := b.deferKey()
|
||||
return Expr{b.pthreadGetspecific(key).impl, b.Prog.DeferPtr()}
|
||||
}
|
||||
|
||||
// Defer emits a defer instruction.
|
||||
@@ -265,17 +278,14 @@ func (b Builder) Defer(kind DoAction, fn Expr, args ...Expr) {
|
||||
case DeferInCond:
|
||||
prog = b.Prog
|
||||
next := self.nextBit
|
||||
if uintptr(next) >= unsafe.Sizeof(uintptr(0))*8 {
|
||||
panic("too many conditional defers")
|
||||
}
|
||||
self.nextBit++
|
||||
bits := b.Load(self.bitsPtr)
|
||||
nextbit = prog.Val(uintptr(1 << next))
|
||||
b.Store(self.bitsPtr, b.BinOp(token.OR, bits, nextbit))
|
||||
case DeferAlways:
|
||||
// nothing to do
|
||||
case DeferInLoop:
|
||||
// Loop defers rely on a dedicated drain loop inserted below.
|
||||
default:
|
||||
panic("todo: DeferInLoop is not supported - " + b.Func.Name())
|
||||
}
|
||||
typ := b.saveDeferArgs(self, fn, args)
|
||||
self.stmts = append(self.stmts, func(bits Expr) {
|
||||
@@ -288,29 +298,6 @@ func (b Builder) Defer(kind DoAction, fn Expr, args ...Expr) {
|
||||
})
|
||||
case DeferAlways:
|
||||
b.callDefer(self, typ, fn, args)
|
||||
case DeferInLoop:
|
||||
prog := b.Prog
|
||||
condBlk := b.Func.MakeBlock()
|
||||
bodyBlk := b.Func.MakeBlock()
|
||||
exitBlk := b.Func.MakeBlock()
|
||||
// Control flow:
|
||||
// condBlk: check argsPtr for non-nil to see if there's work to drain.
|
||||
// bodyBlk: execute a single defer node, then jump back to condBlk.
|
||||
// exitBlk: reached when the list is empty (argsPtr == nil).
|
||||
// This mirrors runtime's linked-list unwinding semantics for loop defers.
|
||||
|
||||
// jump to condition check before executing
|
||||
b.Jump(condBlk)
|
||||
b.SetBlockEx(condBlk, AtEnd, true)
|
||||
list := b.Load(self.argsPtr)
|
||||
has := b.BinOp(token.NEQ, list, prog.Nil(prog.VoidPtr()))
|
||||
b.If(has, bodyBlk, exitBlk)
|
||||
|
||||
b.SetBlockEx(bodyBlk, AtEnd, true)
|
||||
b.callDefer(self, typ, fn, args)
|
||||
b.Jump(condBlk)
|
||||
|
||||
b.SetBlockEx(exitBlk, AtEnd, true)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -351,7 +338,7 @@ func (b Builder) saveDeferArgs(self *aDefer, fn Expr, args []Expr) Type {
|
||||
flds[i+offset] = arg.impl
|
||||
}
|
||||
typ := prog.Struct(typs...)
|
||||
ptr := Expr{b.aggregateAllocU(typ, flds...), prog.VoidPtr()}
|
||||
ptr := Expr{b.aggregateMalloc(typ, flds...), prog.VoidPtr()}
|
||||
b.Store(self.argsPtr, ptr)
|
||||
return typ
|
||||
}
|
||||
@@ -362,28 +349,19 @@ func (b Builder) callDefer(self *aDefer, typ Type, fn Expr, args []Expr) {
|
||||
return
|
||||
}
|
||||
prog := b.Prog
|
||||
zero := prog.Nil(prog.VoidPtr())
|
||||
list := b.Load(self.argsPtr)
|
||||
has := b.BinOp(token.NEQ, list, zero)
|
||||
// The guard is required because callDefer is reused by endDefer() after the
|
||||
// list has been drained. Without this check we would dereference a nil
|
||||
// pointer when no loop defers were recorded.
|
||||
b.IfThen(has, func() {
|
||||
ptr := b.Load(self.argsPtr)
|
||||
data := b.Load(Expr{ptr.impl, prog.Pointer(typ)})
|
||||
offset := 1
|
||||
b.Store(self.argsPtr, Expr{b.getField(data, 0).impl, prog.VoidPtr()})
|
||||
callFn := fn
|
||||
if callFn.kind == vkClosure {
|
||||
callFn = b.getField(data, 1)
|
||||
offset++
|
||||
}
|
||||
for i := 0; i < len(args); i++ {
|
||||
args[i] = b.getField(data, i+offset)
|
||||
}
|
||||
b.Call(callFn, args...)
|
||||
b.Call(b.Pkg.rtFunc("FreeDeferNode"), ptr)
|
||||
})
|
||||
ptr := b.Load(self.argsPtr)
|
||||
data := b.Load(Expr{ptr.impl, prog.Pointer(typ)})
|
||||
offset := 1
|
||||
b.Store(self.argsPtr, Expr{b.getField(data, 0).impl, prog.VoidPtr()})
|
||||
if fn.kind == vkClosure {
|
||||
fn = b.getField(data, 1)
|
||||
offset++
|
||||
}
|
||||
for i := 0; i < len(args); i++ {
|
||||
args[i] = b.getField(data, i+offset)
|
||||
}
|
||||
b.Call(fn, args...)
|
||||
b.free(ptr)
|
||||
}
|
||||
|
||||
// RunDefers emits instructions to run deferred instructions.
|
||||
@@ -437,7 +415,7 @@ func (p Function) endDefer(b Builder) {
|
||||
}
|
||||
}
|
||||
link := b.getField(b.Load(self.data), deferLink)
|
||||
b.Call(b.Pkg.rtFunc("SetThreadDefer"), link)
|
||||
b.pthreadSetspecific(self.key, link)
|
||||
b.IndirectJump(b.Load(rundPtr), nexts)
|
||||
|
||||
b.SetBlockEx(panicBlk, AtEnd, false) // panicBlk: exec runDefers and rethrow
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
//go:build !llgo
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025 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 ssa_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/goplus/llgo/ssa"
|
||||
"github.com/goplus/llgo/ssa/ssatest"
|
||||
)
|
||||
|
||||
func TestDeferInLoopIR(t *testing.T) {
|
||||
prog := ssatest.NewProgram(t, nil)
|
||||
pkg := prog.NewPackage("foo", "foo")
|
||||
|
||||
callee := pkg.NewFunc("callee", ssa.NoArgsNoRet, ssa.InGo)
|
||||
cb := callee.MakeBody(1)
|
||||
cb.Return()
|
||||
cb.EndBuild()
|
||||
|
||||
fn := pkg.NewFunc("main", ssa.NoArgsNoRet, ssa.InGo)
|
||||
b := fn.MakeBody(1)
|
||||
fn.SetRecover(fn.MakeBlock())
|
||||
|
||||
// Ensure entry block has a terminator like real codegen
|
||||
b.Return()
|
||||
b.SetBlockEx(fn.Block(0), ssa.BeforeLast, true)
|
||||
|
||||
b.Defer(ssa.DeferInLoop, callee.Expr)
|
||||
b.EndBuild()
|
||||
|
||||
ir := pkg.Module().String()
|
||||
if !strings.Contains(ir, "icmp ne ptr") {
|
||||
t.Fatalf("expected loop defer condition in IR, got:\n%s", ir)
|
||||
}
|
||||
}
|
||||
@@ -31,19 +31,6 @@ func (pkg Package) AddGlobalString(name string, value string) {
|
||||
pkg.NewVarEx(name, prog.Pointer(styp)).Init(Expr{cv, styp})
|
||||
}
|
||||
|
||||
// ConstString creates an SSA expression representing a Go string literal. The
|
||||
// returned value is backed by an anonymous global constant and can be used to
|
||||
// initialize package-level variables or other constant contexts that expect a
|
||||
// Go string value.
|
||||
func (pkg Package) ConstString(value string) Expr {
|
||||
prog := pkg.Prog
|
||||
styp := prog.String()
|
||||
data := pkg.createGlobalStr(value)
|
||||
length := prog.IntVal(uint64(len(value)), prog.Uintptr())
|
||||
cv := llvm.ConstNamedStruct(styp.ll, []llvm.Value{data, length.impl})
|
||||
return Expr{cv, styp}
|
||||
}
|
||||
|
||||
// Undefined global string var by names
|
||||
func (pkg Package) Undefined(names ...string) error {
|
||||
prog := pkg.Prog
|
||||
|
||||
@@ -43,11 +43,11 @@ func (b Builder) newItab(tintf, typ Expr) Expr {
|
||||
return b.Call(b.Pkg.rtFunc("NewItab"), tintf, typ)
|
||||
}
|
||||
|
||||
func (b Builder) unsafeInterface(rawIntf *types.Interface, t Expr, data llvm.Value) llvm.Value {
|
||||
func (b Builder) unsafeInterface(rawIntf *types.Interface, originType types.Type, t Expr, data llvm.Value) llvm.Value {
|
||||
if rawIntf.Empty() {
|
||||
return b.unsafeEface(t.impl, data)
|
||||
}
|
||||
tintf := b.abiType(rawIntf)
|
||||
tintf := b.abiType(originType)
|
||||
itab := b.newItab(tintf, t)
|
||||
return b.unsafeIface(itab.impl, data)
|
||||
}
|
||||
@@ -112,7 +112,7 @@ func (b Builder) MakeInterface(tinter Type, x Expr) (ret Expr) {
|
||||
case abi.Indirect:
|
||||
vptr := b.AllocU(typ)
|
||||
b.Store(vptr, x)
|
||||
return Expr{b.unsafeInterface(rawIntf, tabi, vptr.impl), tinter}
|
||||
return Expr{b.unsafeInterface(rawIntf, tinter.raw.Type, tabi, vptr.impl), tinter}
|
||||
}
|
||||
ximpl := x.impl
|
||||
if lvl > 0 {
|
||||
@@ -121,7 +121,7 @@ func (b Builder) MakeInterface(tinter Type, x Expr) (ret Expr) {
|
||||
var u llvm.Value
|
||||
switch kind {
|
||||
case abi.Pointer:
|
||||
return Expr{b.unsafeInterface(rawIntf, tabi, ximpl), tinter}
|
||||
return Expr{b.unsafeInterface(rawIntf, tinter.raw.Type, tabi, ximpl), tinter}
|
||||
case abi.Integer:
|
||||
tu := prog.Uintptr()
|
||||
u = llvm.CreateIntCast(b.impl, ximpl, tu.ll)
|
||||
@@ -136,7 +136,7 @@ func (b Builder) MakeInterface(tinter Type, x Expr) (ret Expr) {
|
||||
panic("todo")
|
||||
}
|
||||
data := llvm.CreateIntToPtr(b.impl, u, prog.tyVoidPtr())
|
||||
return Expr{b.unsafeInterface(rawIntf, tabi, data), tinter}
|
||||
return Expr{b.unsafeInterface(rawIntf, tinter.raw.Type, tabi, data), tinter}
|
||||
}
|
||||
|
||||
func (b Builder) valFromData(typ Type, data llvm.Value) Expr {
|
||||
@@ -249,7 +249,9 @@ func (b Builder) TypeAssert(x Expr, assertedTyp Type, commaOk bool) Expr {
|
||||
} else {
|
||||
if rawIntf, ok := assertedTyp.raw.Type.Underlying().(*types.Interface); ok {
|
||||
eq = b.InlineCall(b.Pkg.rtFunc("Implements"), tabi, tx)
|
||||
val = func() Expr { return Expr{b.unsafeInterface(rawIntf, tx, b.faceData(x.impl)), assertedTyp} }
|
||||
val = func() Expr {
|
||||
return Expr{b.unsafeInterface(rawIntf, assertedTyp.raw.Type, tx, b.faceData(x.impl)), assertedTyp}
|
||||
}
|
||||
} else {
|
||||
eq = b.BinOp(token.EQL, tx, tabi)
|
||||
val = func() Expr { return b.valFromData(assertedTyp, b.faceData(x.impl)) }
|
||||
@@ -305,7 +307,7 @@ func (b Builder) ChangeInterface(typ Type, x Expr) (ret Expr) {
|
||||
rawIntf := typ.raw.Type.Underlying().(*types.Interface)
|
||||
tabi := b.faceAbiType(x)
|
||||
data := b.faceData(x.impl)
|
||||
return Expr{b.unsafeInterface(rawIntf, tabi, data), typ}
|
||||
return Expr{b.unsafeInterface(rawIntf, typ.raw.Type, tabi, data), typ}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -195,7 +195,6 @@ type aProgram struct {
|
||||
mallocTy *types.Signature
|
||||
freeTy *types.Signature
|
||||
memsetInlineTy *types.Signature
|
||||
stackSaveTy *types.Signature
|
||||
|
||||
createKeyTy *types.Signature
|
||||
getSpecTy *types.Signature
|
||||
@@ -798,6 +797,7 @@ func (p Package) afterBuilder() Builder {
|
||||
|
||||
// AfterInit is called after the package is initialized (init all packages that depends on).
|
||||
func (p Package) AfterInit(b Builder, ret BasicBlock) {
|
||||
p.keyInit(deferKey)
|
||||
doAfterb := p.afterb != nil
|
||||
doPyLoadModSyms := p.pyHasModSyms()
|
||||
if doAfterb || doPyLoadModSyms {
|
||||
|
||||
@@ -60,42 +60,6 @@ func TestUnsafeString(t *testing.T) {
|
||||
b.Return()
|
||||
}
|
||||
|
||||
func TestTooManyConditionalDefers(t *testing.T) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
os.Chdir("../../runtime")
|
||||
defer os.Chdir(wd)
|
||||
|
||||
prog := NewProgram(nil)
|
||||
prog.SetRuntime(func() *types.Package {
|
||||
fset := token.NewFileSet()
|
||||
imp := packages.NewImporter(fset)
|
||||
pkg, _ := imp.Import(PkgRuntime)
|
||||
return pkg
|
||||
})
|
||||
|
||||
pkg := prog.NewPackage("foo", "foo")
|
||||
target := pkg.NewFunc("f", NoArgsNoRet, InGo)
|
||||
fn := pkg.NewFunc("main", NoArgsNoRet, InGo)
|
||||
fn.SetRecover(fn.MakeBlock())
|
||||
b := fn.MakeBody(1)
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
t.Fatal("expected panic: too many conditional defers")
|
||||
} else if r != "too many conditional defers" {
|
||||
t.Fatalf("unexpected panic: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
b.Return()
|
||||
for i := 0; i < 65; i++ {
|
||||
b.Defer(DeferInCond, target.Expr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPointerSize(t *testing.T) {
|
||||
expected := unsafe.Sizeof(uintptr(0))
|
||||
if size := NewProgram(nil).PointerSize(); size != int(expected) {
|
||||
|
||||
@@ -57,6 +57,11 @@ func (p BasicBlock) Addr() Expr {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type dbgExpr struct {
|
||||
ptr Expr
|
||||
val Expr
|
||||
}
|
||||
|
||||
type aBuilder struct {
|
||||
impl llvm.Builder
|
||||
blk BasicBlock
|
||||
@@ -64,6 +69,7 @@ type aBuilder struct {
|
||||
Pkg Package
|
||||
Prog Program
|
||||
|
||||
dbgVars map[Expr]dbgExpr // save copied address and values for debug info
|
||||
diScopeCache map[*types.Scope]DIScope // avoid duplicated DILexicalBlock(s)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
_heapEnd = ORIGIN(dram_seg) + LENGTH(dram_seg);
|
||||
__stack = ORIGIN(dram_seg) + LENGTH(dram_seg);
|
||||
__MIN_STACK_SIZE = 0x1000;
|
||||
_stack_top = __stack;
|
||||
|
||||
/* Default entry point */
|
||||
ENTRY(_start)
|
||||
@@ -92,12 +94,6 @@ SECTIONS
|
||||
_iram_end = .;
|
||||
} > iram_seg
|
||||
|
||||
.stack (NOLOAD) :
|
||||
{
|
||||
. += 16K;
|
||||
__stack = .;
|
||||
} > dram_seg
|
||||
|
||||
/**
|
||||
* This section is required to skip .iram0.text area because iram0_0_seg and
|
||||
* dram0_0_seg reflect the same address space on different buses.
|
||||
@@ -152,7 +148,7 @@ SECTIONS
|
||||
} > dram_seg
|
||||
|
||||
/* Check if data + heap + stack exceeds RAM limit */
|
||||
ASSERT(_end <= _heapEnd, "region DRAM overflowed by .data and .bss sections")
|
||||
ASSERT(_end <= __stack - __MIN_STACK_SIZE, "region DRAM overflowed by .data and .bss sections")
|
||||
|
||||
/* Stabs debugging sections. */
|
||||
.stab 0 : { *(.stab) }
|
||||
@@ -197,8 +193,3 @@ SECTIONS
|
||||
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
|
||||
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
|
||||
}
|
||||
|
||||
_globals_start = _data_start;
|
||||
_globals_end = _end;
|
||||
_heapStart = _end;
|
||||
_stack_top = __stack;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
_heapEnd = ORIGIN(dram_seg) + LENGTH(dram_seg);
|
||||
__stack = ORIGIN(dram_seg) + LENGTH(dram_seg);
|
||||
__MIN_STACK_SIZE = 0x2000;
|
||||
|
||||
ENTRY(_start)
|
||||
SECTIONS
|
||||
@@ -25,14 +26,6 @@ SECTIONS
|
||||
the same address within the page on the next page up. */
|
||||
. = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
|
||||
|
||||
.stack (NOLOAD) :
|
||||
{
|
||||
_stack_end = .;
|
||||
. = ALIGN(16);
|
||||
. += 16K;
|
||||
__stack = .;
|
||||
}
|
||||
|
||||
|
||||
.rodata :
|
||||
{
|
||||
@@ -123,7 +116,7 @@ SECTIONS
|
||||
. = DATA_SEGMENT_END (.);
|
||||
|
||||
/* Check if data + heap + stack exceeds RAM limit */
|
||||
ASSERT(. <= _heapEnd, "region DRAM overflowed by .data and .bss sections")
|
||||
ASSERT(. <= __stack - __MIN_STACK_SIZE, "region DRAM overflowed by .data and .bss sections")
|
||||
|
||||
/* Stabs debugging sections. */
|
||||
.stab 0 : { *(.stab) }
|
||||
@@ -172,7 +165,4 @@ SECTIONS
|
||||
|
||||
_sbss = __bss_start;
|
||||
_ebss = _end;
|
||||
_globals_start = _data_start;
|
||||
_globals_end = _end;
|
||||
_heapStart = _end;
|
||||
_stack_top = __stack;
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ MEMORY
|
||||
/* 64k at the end of DRAM, after ROM bootloader stack
|
||||
* or entire DRAM (for QEMU only)
|
||||
*/
|
||||
dram_seg (RW) : org = 0x3ffae000 ,
|
||||
len = 0x52000
|
||||
dram_seg (RW) : org = 0x3FFF0000 ,
|
||||
len = 0x10000
|
||||
}
|
||||
|
||||
INCLUDE "targets/esp32.app.elf.ld";
|
||||
|
||||
@@ -1,326 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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 test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// runLoopDefers exercises a defer statement inside a loop and relies on
|
||||
// defers executing after the loop but before the function returns.
|
||||
func runLoopDefers() (result []int) {
|
||||
for i := 0; i < 3; i++ {
|
||||
v := i
|
||||
defer func() {
|
||||
result = append(result, v)
|
||||
}()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func runLoopDeferCount(n int) (count int) {
|
||||
for i := 0; i < n; i++ {
|
||||
defer func() {
|
||||
count++
|
||||
}()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func runDeferRecover() (recovered any, ran bool) {
|
||||
defer func() {
|
||||
recovered = recover()
|
||||
ran = true
|
||||
}()
|
||||
panic("defer recover sentinel")
|
||||
}
|
||||
|
||||
func runNestedLoopDeferOrder() (order []string) {
|
||||
outerNestedLoop(&order)
|
||||
return
|
||||
}
|
||||
|
||||
func outerNestedLoop(order *[]string) {
|
||||
for i := 0; i < 3; i++ {
|
||||
v := i
|
||||
label := "outer:" + strconv.Itoa(v)
|
||||
defer func(label string) {
|
||||
*order = append(*order, label)
|
||||
}(label)
|
||||
}
|
||||
middleNestedLoop(order)
|
||||
}
|
||||
|
||||
func middleNestedLoop(order *[]string) {
|
||||
for i := 0; i < 2; i++ {
|
||||
v := i
|
||||
label := "middle:" + strconv.Itoa(v)
|
||||
defer func(label string) {
|
||||
*order = append(*order, label)
|
||||
}(label)
|
||||
}
|
||||
innerNestedLoop(order)
|
||||
}
|
||||
|
||||
func innerNestedLoop(order *[]string) {
|
||||
for i := 0; i < 4; i++ {
|
||||
v := i
|
||||
label := "inner:" + strconv.Itoa(v)
|
||||
defer func(label string) {
|
||||
*order = append(*order, label)
|
||||
}(label)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeferInLoopOrder(t *testing.T) {
|
||||
got := runLoopDefers()
|
||||
want := []int{2, 1, 0}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("unexpected defer order: got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeferLoopStress(t *testing.T) {
|
||||
const n = 1_000_000
|
||||
if got := runLoopDeferCount(n); got != n {
|
||||
t.Fatalf("unexpected count: got %d, want %d", got, n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeferRecoverHandlesPanic(t *testing.T) {
|
||||
got, ran := runDeferRecover()
|
||||
want := "defer recover sentinel"
|
||||
if !ran {
|
||||
t.Fatalf("recover defer not executed")
|
||||
}
|
||||
str, ok := got.(string)
|
||||
if !ok {
|
||||
t.Fatalf("recover returned %T, want string", got)
|
||||
}
|
||||
if str != want {
|
||||
t.Fatalf("unexpected recover value: got %q, want %q", str, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNestedDeferLoops(t *testing.T) {
|
||||
got := runNestedLoopDeferOrder()
|
||||
want := []string{
|
||||
"inner:3", "inner:2", "inner:1", "inner:0",
|
||||
"middle:1", "middle:0",
|
||||
"outer:2", "outer:1", "outer:0",
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("unexpected nested order: got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func runNestedConditionalDeferWithRecover() (order []string, recovered any) {
|
||||
defer func() { recovered = recover() }()
|
||||
nestedCondOuter(&order)
|
||||
return
|
||||
}
|
||||
|
||||
func nestedCondOuter(order *[]string) {
|
||||
for i := 0; i < 3; i++ {
|
||||
v := i
|
||||
label := "outer:" + strconv.Itoa(v)
|
||||
if v%2 == 0 {
|
||||
defer func(label string) {
|
||||
*order = append(*order, label)
|
||||
}(label)
|
||||
}
|
||||
nestedCondMiddle(order, v)
|
||||
}
|
||||
}
|
||||
|
||||
func nestedCondMiddle(order *[]string, v int) {
|
||||
for j := 0; j < 3; j++ {
|
||||
u := j
|
||||
label := "middle:" + strconv.Itoa(u)
|
||||
if u < 2 {
|
||||
defer func(label string) {
|
||||
*order = append(*order, label)
|
||||
}(label)
|
||||
}
|
||||
nestedCondInner(order)
|
||||
}
|
||||
if v == 1 {
|
||||
panic("nested-conditional-boom")
|
||||
}
|
||||
}
|
||||
|
||||
func nestedCondInner(order *[]string) {
|
||||
for k := 0; k < 2; k++ {
|
||||
w := k
|
||||
label := "inner:" + strconv.Itoa(w)
|
||||
defer func(label string) {
|
||||
*order = append(*order, label)
|
||||
}(label)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNestedConditionalDeferWithRecover(t *testing.T) {
|
||||
gotOrder, gotRecovered := runNestedConditionalDeferWithRecover()
|
||||
wantRecovered := "nested-conditional-boom"
|
||||
if s, ok := gotRecovered.(string); !ok || s != wantRecovered {
|
||||
t.Fatalf("unexpected recover value: got %v, want %q", gotRecovered, wantRecovered)
|
||||
}
|
||||
wantOrder := []string{
|
||||
"inner:1", "inner:0",
|
||||
"inner:1", "inner:0",
|
||||
"inner:1", "inner:0",
|
||||
"middle:1", "middle:0",
|
||||
"inner:1", "inner:0",
|
||||
"inner:1", "inner:0",
|
||||
"inner:1", "inner:0",
|
||||
"middle:1", "middle:0",
|
||||
"outer:0",
|
||||
}
|
||||
if !reflect.DeepEqual(gotOrder, wantOrder) {
|
||||
t.Fatalf("unexpected nested conditional order: got %v, want %v", gotOrder, wantOrder)
|
||||
}
|
||||
}
|
||||
|
||||
func callWithRecover(fn func()) (recovered any) {
|
||||
defer func() { recovered = recover() }()
|
||||
fn()
|
||||
return
|
||||
}
|
||||
|
||||
func loopBranchEven(order *[]string, i int) {
|
||||
label := "even:" + strconv.Itoa(i)
|
||||
defer func() { *order = append(*order, label) }()
|
||||
}
|
||||
|
||||
func loopBranchOddNoRecover(order *[]string, i int) {
|
||||
label := "odd-wrap:" + strconv.Itoa(i)
|
||||
defer func() { *order = append(*order, label) }()
|
||||
panic("odd-no-recover")
|
||||
}
|
||||
|
||||
func loopBranchOddLocalRecover(order *[]string, i int) {
|
||||
label := "odd-local:" + strconv.Itoa(i)
|
||||
defer func() { *order = append(*order, label) }()
|
||||
defer func() { _ = recover() }()
|
||||
panic("odd-local-recover")
|
||||
}
|
||||
|
||||
func runLoopBranchRecoverMixed(n int) (order []string, recoveredVals []any) {
|
||||
for i := 0; i < n; i++ {
|
||||
if i%2 == 0 {
|
||||
loopBranchEven(&order, i)
|
||||
} else if i%4 == 3 {
|
||||
rec := callWithRecover(func() { loopBranchOddNoRecover(&order, i) })
|
||||
recoveredVals = append(recoveredVals, rec)
|
||||
} else {
|
||||
loopBranchOddLocalRecover(&order, i)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func TestLoopBranchRecoverMixed(t *testing.T) {
|
||||
order, recovered := runLoopBranchRecoverMixed(6)
|
||||
wantOrder := []string{
|
||||
"even:0",
|
||||
"odd-local:1",
|
||||
"even:2",
|
||||
"odd-wrap:3",
|
||||
"even:4",
|
||||
"odd-local:5",
|
||||
}
|
||||
if !reflect.DeepEqual(order, wantOrder) {
|
||||
t.Fatalf("unexpected loop/branch order: got %v, want %v", order, wantOrder)
|
||||
}
|
||||
if len(recovered) != 1 {
|
||||
t.Fatalf("unexpected recovered count: got %d, want %d", len(recovered), 1)
|
||||
}
|
||||
if s, ok := recovered[0].(string); !ok || s != "odd-no-recover" {
|
||||
t.Fatalf("unexpected recovered value: got %v, want %q", recovered[0], "odd-no-recover")
|
||||
}
|
||||
}
|
||||
|
||||
func deepInner(order *[]string) {
|
||||
for i := 0; i < 2; i++ {
|
||||
idx := i
|
||||
label := "inner:" + strconv.Itoa(idx)
|
||||
defer func(label string) {
|
||||
*order = append(*order, label)
|
||||
}(label)
|
||||
if idx == 0 {
|
||||
continue
|
||||
}
|
||||
panic("deep-boom")
|
||||
}
|
||||
}
|
||||
|
||||
func deepMiddle(order *[]string) {
|
||||
for i := 0; i < 2; i++ {
|
||||
idx := i
|
||||
label := "middle:" + strconv.Itoa(idx)
|
||||
defer func(label string) {
|
||||
*order = append(*order, label)
|
||||
}(label)
|
||||
if idx == 0 {
|
||||
continue
|
||||
}
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
panic(rec)
|
||||
}
|
||||
}()
|
||||
deepInner(order)
|
||||
}
|
||||
}
|
||||
|
||||
func deepOuter(order *[]string) (recovered any) {
|
||||
for i := 0; i < 2; i++ {
|
||||
idx := i
|
||||
label := "outer:" + strconv.Itoa(idx)
|
||||
defer func(label string) {
|
||||
*order = append(*order, label)
|
||||
}(label)
|
||||
if idx == 0 {
|
||||
continue
|
||||
}
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
recovered = rec
|
||||
}
|
||||
}()
|
||||
deepMiddle(order)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func TestPanicCrossTwoFunctionsRecover(t *testing.T) {
|
||||
var order []string
|
||||
recovered := deepOuter(&order)
|
||||
if s, ok := recovered.(string); !ok || s != "deep-boom" {
|
||||
t.Fatalf("unexpected recovered value: got %v, want %q", recovered, "deep-boom")
|
||||
}
|
||||
wantOrder := []string{
|
||||
"inner:1", "inner:0",
|
||||
"middle:1", "middle:0",
|
||||
"outer:1", "outer:0",
|
||||
}
|
||||
if !reflect.DeepEqual(order, wantOrder) {
|
||||
t.Fatalf("unexpected cross-function defer order: got %v, want %v", order, wantOrder)
|
||||
}
|
||||
}
|
||||
60
xtool/env/llvm/llvm.go
vendored
60
xtool/env/llvm/llvm.go
vendored
@@ -17,11 +17,9 @@
|
||||
package llvm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/goplus/llgo/internal/env"
|
||||
@@ -110,62 +108,4 @@ func (e *Env) InstallNameTool() *install_name_tool.Cmd {
|
||||
return install_name_tool.New(bin)
|
||||
}
|
||||
|
||||
// Readelf returns a command to execute llvm-readelf with given arguments.
|
||||
func (e *Env) Readelf(args ...string) (*exec.Cmd, error) {
|
||||
path, err := e.toolPath("llvm-readelf")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return exec.Command(path, args...), nil
|
||||
}
|
||||
|
||||
func (e *Env) toolPath(base string) (string, error) {
|
||||
if tool := searchTool(e.binDir, base); tool != "" {
|
||||
return tool, nil
|
||||
}
|
||||
if tool, err := exec.LookPath(base); err == nil {
|
||||
return tool, nil
|
||||
}
|
||||
if tool := searchToolInPath(base); tool != "" {
|
||||
return tool, nil
|
||||
}
|
||||
return "", fmt.Errorf("%s not found", base)
|
||||
}
|
||||
|
||||
func searchTool(dir, base string) string {
|
||||
if dir == "" {
|
||||
return ""
|
||||
}
|
||||
candidate := filepath.Join(dir, base)
|
||||
if isExecutable(candidate) {
|
||||
return candidate
|
||||
}
|
||||
pattern := filepath.Join(dir, base+"-*")
|
||||
matches, _ := filepath.Glob(pattern)
|
||||
sort.Sort(sort.Reverse(sort.StringSlice(matches)))
|
||||
for _, match := range matches {
|
||||
if isExecutable(match) {
|
||||
return match
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func searchToolInPath(base string) string {
|
||||
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
|
||||
if tool := searchTool(dir, base); tool != "" {
|
||||
return tool
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func isExecutable(path string) bool {
|
||||
if path == "" {
|
||||
return false
|
||||
}
|
||||
info, err := os.Stat(path)
|
||||
return err == nil && !info.IsDir()
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user