mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 12:03:41 +00:00
Compare commits
59 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e60eeb368 | |||
| e5a8d69300 | |||
| 4f8672c9ab | |||
| a7416e7300 | |||
| d63d8e0899 | |||
| 8e009de8a8 | |||
| d6527ece02 | |||
| 211425c3e9 | |||
| 429aea8e74 | |||
| 7755780a49 | |||
| 3a7c25f987 | |||
| a4cbe3326e | |||
| 5282b4efac | |||
| 6a25fd494e | |||
| d95c1b5982 | |||
| 24eed9e376 | |||
| c2af1d183e | |||
| 64651115c2 | |||
| b6c3d142db | |||
| fafe80704f | |||
| a2be2f3330 | |||
| 05fc49a0cf | |||
| 417aa4312e | |||
| bf88cdea90 | |||
| c8d0b87a67 | |||
| 99a618385b | |||
| 9e143efd73 | |||
| d5c70a1cd3 | |||
| bbb2b0c95b | |||
| 4768c7d431 | |||
| 4f7c64cb24 | |||
| ff2a79de7c | |||
| 04c7057ea6 | |||
| f76e8d2812 | |||
| bcdc5e0097 | |||
| 2bee29959b | |||
| cab3834bc9 | |||
| 7f970a45c2 | |||
| ebf70ab18e | |||
| 226744a538 | |||
| dc876c6ed4 | |||
| 5a09084c73 | |||
| 6c9074772c | |||
| e49663809b | |||
| 7d6d93f7aa | |||
| 8c54e3dd88 | |||
| 47c0debe4b | |||
| 9a1cde40a8 | |||
| 20fc814635 | |||
| 64d8a04308 | |||
| b95effbdd7 | |||
| 92c130c7be | |||
| 31c4bc1151 | |||
| 42f5e55ed5 | |||
| 81da7bb4c1 | |||
| 209754493b | |||
| b0aef96340 | |||
| 056394e24b | |||
| 1545659817 |
@@ -165,6 +165,7 @@ jobs:
|
|||||||
ln -s ~/lib/tinygo/bin/tinygo ~/go/bin/tinygo
|
ln -s ~/lib/tinygo/bin/tinygo ~/go/bin/tinygo
|
||||||
- run: make tinygo-test-wasip1-fast
|
- run: make tinygo-test-wasip1-fast
|
||||||
- run: make tinygo-test-wasip2-fast
|
- run: make tinygo-test-wasip2-fast
|
||||||
|
- run: make tinygo-test-wasm
|
||||||
- run: make smoketest
|
- run: make smoketest
|
||||||
assert-test-linux:
|
assert-test-linux:
|
||||||
# Run all tests that can run on Linux, with LLVM assertions enabled to catch
|
# Run all tests that can run on Linux, with LLVM assertions enabled to catch
|
||||||
@@ -277,7 +278,7 @@ jobs:
|
|||||||
run: make tinygo-test
|
run: make tinygo-test
|
||||||
- run: make smoketest
|
- run: make smoketest
|
||||||
- run: make wasmtest
|
- run: make wasmtest
|
||||||
- run: make tinygo-baremetal
|
- run: make tinygo-test-baremetal
|
||||||
build-linux-cross:
|
build-linux-cross:
|
||||||
# Build ARM Linux binaries, ready for release.
|
# Build ARM Linux binaries, ready for release.
|
||||||
# This intentionally uses an older Linux image, so that we compile against
|
# This intentionally uses an older Linux image, so that we compile against
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ jobs:
|
|||||||
run: sudo apt-get remove llvm-18
|
run: sudo apt-get remove llvm-18
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Pull musl
|
- name: Pull musl, bdwgc
|
||||||
run: |
|
run: |
|
||||||
git submodule update --init lib/musl
|
git submodule update --init lib/musl lib/bdwgc
|
||||||
- name: Restore LLVM source cache
|
- name: Restore LLVM source cache
|
||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
id: cache-llvm-source
|
id: cache-llvm-source
|
||||||
|
|||||||
@@ -39,3 +39,6 @@
|
|||||||
[submodule "lib/wasi-cli"]
|
[submodule "lib/wasi-cli"]
|
||||||
path = lib/wasi-cli
|
path = lib/wasi-cli
|
||||||
url = https://github.com/WebAssembly/wasi-cli
|
url = https://github.com/WebAssembly/wasi-cli
|
||||||
|
[submodule "lib/bdwgc"]
|
||||||
|
path = lib/bdwgc
|
||||||
|
url = https://github.com/ivmai/bdwgc.git
|
||||||
|
|||||||
+119
@@ -1,3 +1,122 @@
|
|||||||
|
0.37.0
|
||||||
|
---
|
||||||
|
* **general**
|
||||||
|
- add the Boehm-Demers-Weiser GC on Linux
|
||||||
|
* **ci**
|
||||||
|
- add more tests for wasm and baremetal
|
||||||
|
* **compiler**
|
||||||
|
- crypto/internal/sysrand is allowed to use unsafe signatures
|
||||||
|
* **examples**
|
||||||
|
- add goroutine benchmark to examples
|
||||||
|
* **fixes**
|
||||||
|
- ensure use of pointers for SPI interface on atsam21/atsam51 and other machines/boards that were missing implementation (#4798)
|
||||||
|
- replace loop counter with hw timer for USB SetAddressReq on rp2040 (#4796)
|
||||||
|
* **internal**
|
||||||
|
- update to go.bytecodealliance.org@v0.6.2 in GNUmakefile and internal/wasm-tools
|
||||||
|
- exclude certain files when copying package in internal/cm
|
||||||
|
- update to go.bytecodealliance.org/cm@v0.2.2 in internal/cm
|
||||||
|
- remove old reflect.go in internal/reflectlite
|
||||||
|
* **loader**
|
||||||
|
- use build tags for package iter and iter methods on reflect.Value in loader, iter, reflect
|
||||||
|
- add shim for go1.22 and earlier in loader, iter
|
||||||
|
* **machine**
|
||||||
|
- bump rp2040 to 200MHz (#4768)
|
||||||
|
- correct register address for Pin.SetInterrupt for rp2350 (#4782)
|
||||||
|
- don't block the rp2xxx UART interrupt handler
|
||||||
|
- fix RP2040 Pico board on the playground
|
||||||
|
- add flash support for rp2350 (#4803)
|
||||||
|
* **os**
|
||||||
|
- add stub Symlink for wasm
|
||||||
|
* **refactor**
|
||||||
|
- use *SPI everywhere to make consistent for implementations. Fixes #4663 "in reverse" by making SPI a pointer everywhere, as discussed in the comments.
|
||||||
|
* **reflect**
|
||||||
|
- add Value.SetIter{Key,Value} and MapIter.Reset in reflect, internal/reflectlite
|
||||||
|
- embed reflectlite types into reflect types in reflect, internal/reflectlite
|
||||||
|
- add Go 1.24 iter.Seq[2] methods
|
||||||
|
- copy reflect iter tests from upstream Go
|
||||||
|
- panic on Type.CanSeq[2] instead of returning false
|
||||||
|
- remove strconv.go
|
||||||
|
- remove unused go:linkname functions
|
||||||
|
* **riscv-qemu**
|
||||||
|
- add VirtIO RNG device
|
||||||
|
- increase stack size
|
||||||
|
* **runtime**
|
||||||
|
- only allocate heap memory when needed
|
||||||
|
- remove unused file func.go
|
||||||
|
- use package reflectlite
|
||||||
|
* **transform**
|
||||||
|
- cherry-pick from #4774
|
||||||
|
|
||||||
|
|
||||||
|
0.36.0
|
||||||
|
---
|
||||||
|
* **general**
|
||||||
|
- add initial Go 1.24 support
|
||||||
|
- add support for LLVM 19
|
||||||
|
- update license for 2025
|
||||||
|
- make small corrections for README regarding wasm
|
||||||
|
- use GOOS and GOARCH for building wasm simulated boards
|
||||||
|
- only infer target for wasm when GOOS and GOARCH are set correctly, not just based on file extension
|
||||||
|
- add test-corpus-wasip2
|
||||||
|
- use older image for cross-compiling builds
|
||||||
|
- update Linux builds to run on ubuntu-latest since 20.04 is being retired
|
||||||
|
- ensure build output directory is created
|
||||||
|
- add NoSandbox flag to chrome headless that is run during WASM tests, since this is now required for Ubuntu 23+ and we are using Ubuntu 24+ when running Github Actions
|
||||||
|
- update wasmtime used for CI to 29.0.1 to fix issue with install during CI tests
|
||||||
|
- update to use `Get-CimInstance` as `wmic` is being deprecated on WIndows
|
||||||
|
- remove unnecessary executable permissions
|
||||||
|
- `goenv`: update to new v0.36.0 development version
|
||||||
|
* **compiler**
|
||||||
|
- `builder`: fix parsing of external ld.lld error messages
|
||||||
|
- `cgo`: mangle identifier names
|
||||||
|
- `interp`: correctly mark functions as modifying memory
|
||||||
|
- add buildmode=wasi-legacy to support existing base of users who expected the older behavior for wasi modules to not return an exit code as if they were reactors
|
||||||
|
* **standard library**
|
||||||
|
- `crypto/tls`: add Dialer.DialContext() to fix websocket client
|
||||||
|
- `crypto/tls`: add VersionTLS constants and VersionName(version uint16) method that turns it into a string, copied from big go
|
||||||
|
- `internal/syscall/unix`: use our own version of this package
|
||||||
|
- `machine`: replace hard-coded cpu frequencies on rp2xxx
|
||||||
|
- `machine`: bump rp2350 CPUFrequency to 150 MHz
|
||||||
|
- `machine`: compute rp2 clock dividers from crystal and target frequency
|
||||||
|
- `machine`: remove bytes package dependency in flash code
|
||||||
|
- `machine/usb/descriptor`: avoid bytes package
|
||||||
|
- `net`: update to latest submodule with httptest subpackage and ResolveIPAddress implementation
|
||||||
|
- `os`: add File.Chdir support
|
||||||
|
- `os`: implement stub Chdir for non-OS systems
|
||||||
|
- `os/file`: add file.Chmod
|
||||||
|
- `reflect`: implement Value.Equal
|
||||||
|
- `runtime`: add FIPS helper functions
|
||||||
|
- `runtime`: manually initialize xorshift state
|
||||||
|
- `sync`: move Mutex to internal/task
|
||||||
|
- `syscall`: add wasip1 RandomGet
|
||||||
|
- `testing`: add Chdir
|
||||||
|
- `wasip2`: add stubs to get internal/syscall/unix to work
|
||||||
|
* **fixes**
|
||||||
|
- correctly handle calls for GetRNG() when being made from nrf devices with SoftDevice enabled
|
||||||
|
- fix stm32f103 ADC
|
||||||
|
- `wasm`: correctly handle id lookup for finalizeRef call
|
||||||
|
- `wasm`: avoid total failure on wasm finalizer call
|
||||||
|
- `wasm`: convert offset as signed int into unsigned int in syscall/js.stringVal in wasm_exec.js
|
||||||
|
* **targets**
|
||||||
|
- rp2350: add pll generalized solution; fix ADC handles; pwm period fix
|
||||||
|
- rp2350: extending support to include the rp2350b
|
||||||
|
- rp2350: cleanup: unexport internal USB and clock package variable, consts and types
|
||||||
|
- nrf: make ADC resolution changeable
|
||||||
|
- turn on GC for TKey1 device, since it does in fact work
|
||||||
|
- match Pico2 stack size to Pico
|
||||||
|
* **boards**
|
||||||
|
- add support for Pimoroni Pico Plus2
|
||||||
|
- add target for pico2-w board
|
||||||
|
- add comboat_fw tag for elecrow W5 boards with Combo-AT Wifi firmware
|
||||||
|
- add support for Elecrow Pico rp2350 W5 boards
|
||||||
|
- add support for Elecrow Pico rp2040 W5 boards
|
||||||
|
- add support for NRF51 HW-651
|
||||||
|
- add support for esp32c3-supermini
|
||||||
|
- add support for waveshare-rp2040-tiny
|
||||||
|
* **examples**
|
||||||
|
- add naive debouncing for pininterrupt example
|
||||||
|
|
||||||
|
|
||||||
0.35.0
|
0.35.0
|
||||||
---
|
---
|
||||||
* **general**
|
* **general**
|
||||||
|
|||||||
+57
-16
@@ -267,16 +267,17 @@ lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a:
|
|||||||
cd lib/wasi-libc && $(MAKE) -j4 EXTRA_CFLAGS="-O2 -g -DNDEBUG -mnontrapping-fptoint -msign-ext" MALLOC_IMPL=none CC="$(CLANG)" AR=$(LLVM_AR) NM=$(LLVM_NM)
|
cd lib/wasi-libc && $(MAKE) -j4 EXTRA_CFLAGS="-O2 -g -DNDEBUG -mnontrapping-fptoint -msign-ext" MALLOC_IMPL=none CC="$(CLANG)" AR=$(LLVM_AR) NM=$(LLVM_NM)
|
||||||
|
|
||||||
# Generate WASI syscall bindings
|
# Generate WASI syscall bindings
|
||||||
WASM_TOOLS_MODULE=github.com/bytecodealliance/wasm-tools-go
|
WASM_TOOLS_MODULE=go.bytecodealliance.org
|
||||||
.PHONY: wasi-syscall
|
.PHONY: wasi-syscall
|
||||||
wasi-syscall: wasi-cm
|
wasi-syscall: wasi-cm
|
||||||
|
rm -rf ./src/internal/wasi/*
|
||||||
go run -modfile ./internal/wasm-tools/go.mod $(WASM_TOOLS_MODULE)/cmd/wit-bindgen-go generate --versioned -o ./src/internal -p internal --cm internal/cm ./lib/wasi-cli/wit
|
go run -modfile ./internal/wasm-tools/go.mod $(WASM_TOOLS_MODULE)/cmd/wit-bindgen-go generate --versioned -o ./src/internal -p internal --cm internal/cm ./lib/wasi-cli/wit
|
||||||
|
|
||||||
# Copy package cm into src/internal/cm
|
# Copy package cm into src/internal/cm
|
||||||
.PHONY: wasi-cm
|
.PHONY: wasi-cm
|
||||||
wasi-cm:
|
wasi-cm:
|
||||||
# rm -rf ./src/internal/cm
|
rm -rf ./src/internal/cm/*
|
||||||
rsync -rv --delete --exclude '*_test.go' $(shell go list -modfile ./internal/wasm-tools/go.mod -m -f {{.Dir}} $(WASM_TOOLS_MODULE))/cm ./src/internal/
|
rsync -rv --delete --exclude go.mod --exclude '*_test.go' --exclude '*_json.go' --exclude '*.md' --exclude LICENSE $(shell go list -modfile ./internal/wasm-tools/go.mod -m -f {{.Dir}} $(WASM_TOOLS_MODULE)/cm)/ ./src/internal/cm
|
||||||
|
|
||||||
# Check for Node.js used during WASM tests.
|
# Check for Node.js used during WASM tests.
|
||||||
NODEJS_VERSION := $(word 1,$(subst ., ,$(shell node -v | cut -c 2-)))
|
NODEJS_VERSION := $(word 1,$(subst ., ,$(shell node -v | cut -c 2-)))
|
||||||
@@ -407,6 +408,36 @@ TEST_PACKAGES_WINDOWS := \
|
|||||||
text/template/parse \
|
text/template/parse \
|
||||||
$(nil)
|
$(nil)
|
||||||
|
|
||||||
|
|
||||||
|
# These packages cannot be tested on wasm, mostly because these tests assume a
|
||||||
|
# working filesystem. This could perhaps be fixed, by supporting filesystem
|
||||||
|
# access when running inside Node.js.
|
||||||
|
TEST_PACKAGES_WASM = $(filter-out $(TEST_PACKAGES_NONWASM), $(TEST_PACKAGES_FAST))
|
||||||
|
TEST_PACKAGES_NONWASM = \
|
||||||
|
compress/lzw \
|
||||||
|
compress/zlib \
|
||||||
|
crypto/ecdsa \
|
||||||
|
debug/macho \
|
||||||
|
embed/internal/embedtest \
|
||||||
|
go/format \
|
||||||
|
os \
|
||||||
|
testing \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
|
# These packages cannot be tested on baremetal.
|
||||||
|
#
|
||||||
|
# Some reasons why the tests don't pass on baremetal:
|
||||||
|
#
|
||||||
|
# * No filesystem is available, so packages like compress/zlib can't be tested
|
||||||
|
# (just like wasm).
|
||||||
|
# * picolibc math functions apparently are less precise, the math package
|
||||||
|
# fails on baremetal.
|
||||||
|
TEST_PACKAGES_BAREMETAL = $(filter-out $(TEST_PACKAGES_NONBAREMETAL), $(TEST_PACKAGES_FAST))
|
||||||
|
TEST_PACKAGES_NONBAREMETAL = \
|
||||||
|
$(TEST_PACKAGES_NONWASM) \
|
||||||
|
math \
|
||||||
|
$(nil)
|
||||||
|
|
||||||
# Report platforms on which each standard library package is known to pass tests
|
# Report platforms on which each standard library package is known to pass tests
|
||||||
jointmp := $(shell echo /tmp/join.$$$$)
|
jointmp := $(shell echo /tmp/join.$$$$)
|
||||||
report-stdlib-tests-pass:
|
report-stdlib-tests-pass:
|
||||||
@@ -450,6 +481,8 @@ tinygo-bench-fast:
|
|||||||
$(TINYGO) test -bench . $(TEST_PACKAGES_HOST)
|
$(TINYGO) test -bench . $(TEST_PACKAGES_HOST)
|
||||||
|
|
||||||
# Same thing, except for wasi rather than the current platform.
|
# Same thing, except for wasi rather than the current platform.
|
||||||
|
tinygo-test-wasm:
|
||||||
|
$(TINYGO) test -target wasm $(TEST_PACKAGES_WASM)
|
||||||
tinygo-test-wasi:
|
tinygo-test-wasi:
|
||||||
$(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
|
$(TINYGO) test -target wasip1 $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_SLOW) ./tests/runtime_wasi
|
||||||
tinygo-test-wasip1:
|
tinygo-test-wasip1:
|
||||||
@@ -484,6 +517,10 @@ tinygo-bench-wasip2:
|
|||||||
tinygo-bench-wasip2-fast:
|
tinygo-bench-wasip2-fast:
|
||||||
$(TINYGO) test -target wasip2 -bench . $(TEST_PACKAGES_FAST)
|
$(TINYGO) test -target wasip2 -bench . $(TEST_PACKAGES_FAST)
|
||||||
|
|
||||||
|
# Run tests on riscv-qemu since that one provides a large amount of memory.
|
||||||
|
tinygo-test-baremetal:
|
||||||
|
$(TINYGO) test -target riscv-qemu $(TEST_PACKAGES_BAREMETAL)
|
||||||
|
|
||||||
# Test external packages in a large corpus.
|
# Test external packages in a large corpus.
|
||||||
test-corpus:
|
test-corpus:
|
||||||
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml
|
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml
|
||||||
@@ -491,11 +528,8 @@ test-corpus-fast:
|
|||||||
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus -short . -corpus=testdata/corpus.yaml
|
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus -short . -corpus=testdata/corpus.yaml
|
||||||
test-corpus-wasi: wasi-libc
|
test-corpus-wasi: wasi-libc
|
||||||
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml -target=wasip1
|
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml -target=wasip1
|
||||||
|
test-corpus-wasip2: wasi-libc
|
||||||
tinygo-baremetal:
|
CGO_CPPFLAGS="$(CGO_CPPFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) test $(GOTESTFLAGS) -timeout=1h -buildmode exe -tags byollvm -run TestCorpus . -corpus=testdata/corpus.yaml -target=wasip2
|
||||||
# Regression tests that run on a baremetal target and don't fit in either main_test.go or smoketest.
|
|
||||||
# regression test for #2666: e.g. encoding/hex must pass on baremetal
|
|
||||||
$(TINYGO) test -target cortex-m-qemu encoding/hex
|
|
||||||
|
|
||||||
.PHONY: testchdir
|
.PHONY: testchdir
|
||||||
testchdir:
|
testchdir:
|
||||||
@@ -567,21 +601,23 @@ smoketest: testchdir
|
|||||||
@$(MD5SUM) test.hex
|
@$(MD5SUM) test.hex
|
||||||
# test simulated boards on play.tinygo.org
|
# test simulated boards on play.tinygo.org
|
||||||
ifneq ($(WASM), 0)
|
ifneq ($(WASM), 0)
|
||||||
$(TINYGO) build -size short -o test.wasm -tags=arduino examples/blinky1
|
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=arduino examples/blinky1
|
||||||
@$(MD5SUM) test.wasm
|
@$(MD5SUM) test.wasm
|
||||||
$(TINYGO) build -size short -o test.wasm -tags=hifive1b examples/blinky1
|
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=hifive1b examples/blinky1
|
||||||
@$(MD5SUM) test.wasm
|
@$(MD5SUM) test.wasm
|
||||||
$(TINYGO) build -size short -o test.wasm -tags=reelboard examples/blinky1
|
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=reelboard examples/blinky1
|
||||||
@$(MD5SUM) test.wasm
|
@$(MD5SUM) test.wasm
|
||||||
$(TINYGO) build -size short -o test.wasm -tags=microbit examples/microbit-blink
|
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=microbit examples/microbit-blink
|
||||||
@$(MD5SUM) test.wasm
|
@$(MD5SUM) test.wasm
|
||||||
$(TINYGO) build -size short -o test.wasm -tags=circuitplay_express examples/blinky1
|
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=circuitplay_express examples/blinky1
|
||||||
@$(MD5SUM) test.wasm
|
@$(MD5SUM) test.wasm
|
||||||
$(TINYGO) build -size short -o test.wasm -tags=circuitplay_bluefruit examples/blinky1
|
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=circuitplay_bluefruit examples/blinky1
|
||||||
@$(MD5SUM) test.wasm
|
@$(MD5SUM) test.wasm
|
||||||
$(TINYGO) build -size short -o test.wasm -tags=mch2022 examples/machinetest
|
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=mch2022 examples/machinetest
|
||||||
@$(MD5SUM) test.wasm
|
@$(MD5SUM) test.wasm
|
||||||
$(TINYGO) build -size short -o test.wasm -tags=gopher_badge examples/blinky1
|
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=gopher_badge examples/blinky1
|
||||||
|
@$(MD5SUM) test.wasm
|
||||||
|
GOOS=js GOARCH=wasm $(TINYGO) build -size short -o test.wasm -tags=pico examples/blinky1
|
||||||
@$(MD5SUM) test.wasm
|
@$(MD5SUM) test.wasm
|
||||||
endif
|
endif
|
||||||
# test all targets/boards
|
# test all targets/boards
|
||||||
@@ -905,6 +941,7 @@ wasmtest:
|
|||||||
|
|
||||||
build/release: tinygo gen-device wasi-libc $(if $(filter 1,$(USE_SYSTEM_BINARYEN)),,binaryen)
|
build/release: tinygo gen-device wasi-libc $(if $(filter 1,$(USE_SYSTEM_BINARYEN)),,binaryen)
|
||||||
@mkdir -p build/release/tinygo/bin
|
@mkdir -p build/release/tinygo/bin
|
||||||
|
@mkdir -p build/release/tinygo/lib/bdwgc
|
||||||
@mkdir -p build/release/tinygo/lib/clang/include
|
@mkdir -p build/release/tinygo/lib/clang/include
|
||||||
@mkdir -p build/release/tinygo/lib/CMSIS/CMSIS
|
@mkdir -p build/release/tinygo/lib/CMSIS/CMSIS
|
||||||
@mkdir -p build/release/tinygo/lib/macos-minimal-sdk
|
@mkdir -p build/release/tinygo/lib/macos-minimal-sdk
|
||||||
@@ -926,6 +963,7 @@ build/release: tinygo gen-device wasi-libc $(if $(filter 1,$(USE_SYSTEM_BINARYEN
|
|||||||
ifneq ($(USE_SYSTEM_BINARYEN),1)
|
ifneq ($(USE_SYSTEM_BINARYEN),1)
|
||||||
@cp -p build/wasm-opt$(EXE) build/release/tinygo/bin
|
@cp -p build/wasm-opt$(EXE) build/release/tinygo/bin
|
||||||
endif
|
endif
|
||||||
|
@cp -rp lib/bdwgc/* build/release/tinygo/lib/bdwgc
|
||||||
@cp -p $(abspath $(CLANG_SRC))/lib/Headers/*.h build/release/tinygo/lib/clang/include
|
@cp -p $(abspath $(CLANG_SRC))/lib/Headers/*.h build/release/tinygo/lib/clang/include
|
||||||
@cp -rp lib/CMSIS/CMSIS/Include build/release/tinygo/lib/CMSIS/CMSIS
|
@cp -rp lib/CMSIS/CMSIS/Include build/release/tinygo/lib/CMSIS/CMSIS
|
||||||
@cp -rp lib/CMSIS/README.md build/release/tinygo/lib/CMSIS
|
@cp -rp lib/CMSIS/README.md build/release/tinygo/lib/CMSIS
|
||||||
@@ -939,6 +977,7 @@ endif
|
|||||||
@cp -rp lib/musl/crt/crt1.c build/release/tinygo/lib/musl/crt
|
@cp -rp lib/musl/crt/crt1.c build/release/tinygo/lib/musl/crt
|
||||||
@cp -rp lib/musl/COPYRIGHT build/release/tinygo/lib/musl
|
@cp -rp lib/musl/COPYRIGHT build/release/tinygo/lib/musl
|
||||||
@cp -rp lib/musl/include build/release/tinygo/lib/musl
|
@cp -rp lib/musl/include build/release/tinygo/lib/musl
|
||||||
|
@cp -rp lib/musl/src/ctype build/release/tinygo/lib/musl/src
|
||||||
@cp -rp lib/musl/src/env build/release/tinygo/lib/musl/src
|
@cp -rp lib/musl/src/env build/release/tinygo/lib/musl/src
|
||||||
@cp -rp lib/musl/src/errno build/release/tinygo/lib/musl/src
|
@cp -rp lib/musl/src/errno build/release/tinygo/lib/musl/src
|
||||||
@cp -rp lib/musl/src/exit build/release/tinygo/lib/musl/src
|
@cp -rp lib/musl/src/exit build/release/tinygo/lib/musl/src
|
||||||
@@ -953,8 +992,10 @@ endif
|
|||||||
@cp -rp lib/musl/src/math build/release/tinygo/lib/musl/src
|
@cp -rp lib/musl/src/math build/release/tinygo/lib/musl/src
|
||||||
@cp -rp lib/musl/src/misc build/release/tinygo/lib/musl/src
|
@cp -rp lib/musl/src/misc build/release/tinygo/lib/musl/src
|
||||||
@cp -rp lib/musl/src/multibyte build/release/tinygo/lib/musl/src
|
@cp -rp lib/musl/src/multibyte build/release/tinygo/lib/musl/src
|
||||||
|
@cp -rp lib/musl/src/sched build/release/tinygo/lib/musl/src
|
||||||
@cp -rp lib/musl/src/signal build/release/tinygo/lib/musl/src
|
@cp -rp lib/musl/src/signal build/release/tinygo/lib/musl/src
|
||||||
@cp -rp lib/musl/src/stdio build/release/tinygo/lib/musl/src
|
@cp -rp lib/musl/src/stdio build/release/tinygo/lib/musl/src
|
||||||
|
@cp -rp lib/musl/src/stdlib build/release/tinygo/lib/musl/src
|
||||||
@cp -rp lib/musl/src/string build/release/tinygo/lib/musl/src
|
@cp -rp lib/musl/src/string build/release/tinygo/lib/musl/src
|
||||||
@cp -rp lib/musl/src/thread build/release/tinygo/lib/musl/src
|
@cp -rp lib/musl/src/thread build/release/tinygo/lib/musl/src
|
||||||
@cp -rp lib/musl/src/time build/release/tinygo/lib/musl/src
|
@cp -rp lib/musl/src/time build/release/tinygo/lib/musl/src
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
Copyright (c) 2018-2023 The TinyGo Authors. All rights reserved.
|
Copyright (c) 2018-2025 The TinyGo Authors. All rights reserved.
|
||||||
|
|
||||||
TinyGo includes portions of the Go standard library.
|
TinyGo includes portions of the Go standard library.
|
||||||
Copyright (c) 2009-2023 The Go Authors. All rights reserved.
|
Copyright (c) 2009-2024 The Go Authors. All rights reserved.
|
||||||
|
|
||||||
TinyGo includes portions of LLVM, which is under the Apache License v2.0 with
|
TinyGo includes portions of LLVM, which is under the Apache License v2.0 with
|
||||||
LLVM Exceptions. See https://llvm.org/LICENSE.txt for license information.
|
LLVM Exceptions. See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
|||||||
@@ -48,20 +48,22 @@ Here is a small TinyGo program for use by a WASI host application:
|
|||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
//go:wasm-module yourmodulename
|
//go:wasmexport add
|
||||||
//export add
|
|
||||||
func add(x, y uint32) uint32 {
|
func add(x, y uint32) uint32 {
|
||||||
return x + y
|
return x + y
|
||||||
}
|
}
|
||||||
|
|
||||||
// main is required for the `wasip1` target, even if it isn't used.
|
|
||||||
func main() {}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This compiles the above TinyGo program for use on any WASI runtime:
|
This compiles the above TinyGo program for use on any WASI Preview 1 runtime:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
tinygo build -o main.wasm -target=wasip1 main.go
|
tinygo build -buildmode=c-shared -o add.wasm -target=wasip1 add.go
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use the same syntax as Go 1.24+:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
GOARCH=wasip1 GOOS=wasm tinygo build -buildmode=c-shared -o add.wasm add.go
|
||||||
```
|
```
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package builder
|
||||||
|
|
||||||
|
// The well-known conservative Boehm-Demers-Weiser GC.
|
||||||
|
// This file provides a way to compile this GC for use with TinyGo.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/tinygo-org/tinygo/goenv"
|
||||||
|
)
|
||||||
|
|
||||||
|
var BoehmGC = Library{
|
||||||
|
name: "bdwgc",
|
||||||
|
cflags: func(target, headerPath string) []string {
|
||||||
|
libdir := filepath.Join(goenv.Get("TINYGOROOT"), "lib/bdwgc")
|
||||||
|
return []string{
|
||||||
|
// use a modern environment
|
||||||
|
"-DUSE_MMAP", // mmap is available
|
||||||
|
"-DUSE_MUNMAP", // return memory to the OS using munmap
|
||||||
|
"-DGC_BUILTIN_ATOMIC", // use compiler intrinsics for atomic operations
|
||||||
|
"-DNO_EXECUTE_PERMISSION", // don't make the heap executable
|
||||||
|
|
||||||
|
// specific flags for TinyGo
|
||||||
|
"-DALL_INTERIOR_POINTERS", // scan interior pointers (needed for Go)
|
||||||
|
"-DIGNORE_DYNAMIC_LOADING", // we don't support dynamic loading at the moment
|
||||||
|
"-DNO_GETCONTEXT", // musl doesn't support getcontext()
|
||||||
|
|
||||||
|
// Special flag to work around the lack of __data_start in ld.lld.
|
||||||
|
// TODO: try to fix this in LLVM/lld directly so we don't have to
|
||||||
|
// work around it anymore.
|
||||||
|
"-DGC_DONT_REGISTER_MAIN_STATIC_DATA",
|
||||||
|
|
||||||
|
// Do not scan the stack. We have our own mechanism to do this.
|
||||||
|
"-DSTACK_NOT_SCANNED",
|
||||||
|
|
||||||
|
// Assertions can be enabled while debugging GC issues.
|
||||||
|
//"-DGC_ASSERTIONS",
|
||||||
|
|
||||||
|
// Threading is not yet supported, so these are disabled.
|
||||||
|
//"-DGC_THREADS",
|
||||||
|
//"-DTHREAD_LOCAL_ALLOC",
|
||||||
|
|
||||||
|
"-I" + libdir + "/include",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sourceDir: func() string {
|
||||||
|
return filepath.Join(goenv.Get("TINYGOROOT"), "lib/bdwgc")
|
||||||
|
},
|
||||||
|
librarySources: func(target string) ([]string, error) {
|
||||||
|
return []string{
|
||||||
|
"allchblk.c",
|
||||||
|
"alloc.c",
|
||||||
|
"blacklst.c",
|
||||||
|
"dbg_mlc.c",
|
||||||
|
"dyn_load.c",
|
||||||
|
"finalize.c",
|
||||||
|
"headers.c",
|
||||||
|
"mach_dep.c",
|
||||||
|
"malloc.c",
|
||||||
|
"mark.c",
|
||||||
|
"mark_rts.c",
|
||||||
|
"misc.c",
|
||||||
|
"new_hblk.c",
|
||||||
|
"obj_map.c",
|
||||||
|
"os_dep.c",
|
||||||
|
"pthread_stop_world.c",
|
||||||
|
"pthread_support.c",
|
||||||
|
"reclaim.c",
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
|
}
|
||||||
+62
-48
@@ -147,20 +147,22 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
|
|||||||
// the libc needs them.
|
// the libc needs them.
|
||||||
root := goenv.Get("TINYGOROOT")
|
root := goenv.Get("TINYGOROOT")
|
||||||
var libcDependencies []*compileJob
|
var libcDependencies []*compileJob
|
||||||
|
var libcJob *compileJob
|
||||||
switch config.Target.Libc {
|
switch config.Target.Libc {
|
||||||
case "darwin-libSystem":
|
case "darwin-libSystem":
|
||||||
job := makeDarwinLibSystemJob(config, tmpdir)
|
job := makeDarwinLibSystemJob(config, tmpdir)
|
||||||
libcDependencies = append(libcDependencies, job)
|
libcDependencies = append(libcDependencies, job)
|
||||||
case "musl":
|
case "musl":
|
||||||
job, unlock, err := libMusl.load(config, tmpdir)
|
var unlock func()
|
||||||
|
libcJob, unlock, err = libMusl.load(config, tmpdir, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
}
|
}
|
||||||
defer unlock()
|
defer unlock()
|
||||||
libcDependencies = append(libcDependencies, dummyCompileJob(filepath.Join(filepath.Dir(job.result), "crt1.o")))
|
libcDependencies = append(libcDependencies, dummyCompileJob(filepath.Join(filepath.Dir(libcJob.result), "crt1.o")))
|
||||||
libcDependencies = append(libcDependencies, job)
|
libcDependencies = append(libcDependencies, libcJob)
|
||||||
case "picolibc":
|
case "picolibc":
|
||||||
libcJob, unlock, err := libPicolibc.load(config, tmpdir)
|
libcJob, unlock, err := libPicolibc.load(config, tmpdir, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
}
|
}
|
||||||
@@ -173,14 +175,14 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
|
|||||||
}
|
}
|
||||||
libcDependencies = append(libcDependencies, dummyCompileJob(path))
|
libcDependencies = append(libcDependencies, dummyCompileJob(path))
|
||||||
case "wasmbuiltins":
|
case "wasmbuiltins":
|
||||||
libcJob, unlock, err := libWasmBuiltins.load(config, tmpdir)
|
libcJob, unlock, err := libWasmBuiltins.load(config, tmpdir, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
}
|
}
|
||||||
defer unlock()
|
defer unlock()
|
||||||
libcDependencies = append(libcDependencies, libcJob)
|
libcDependencies = append(libcDependencies, libcJob)
|
||||||
case "mingw-w64":
|
case "mingw-w64":
|
||||||
job, unlock, err := libMinGW.load(config, tmpdir)
|
job, unlock, err := libMinGW.load(config, tmpdir, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
}
|
}
|
||||||
@@ -449,8 +451,15 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
|
|||||||
if global.IsNil() {
|
if global.IsNil() {
|
||||||
return errors.New("global not found: " + globalName)
|
return errors.New("global not found: " + globalName)
|
||||||
}
|
}
|
||||||
|
globalType := global.GlobalValueType()
|
||||||
|
if globalType.TypeKind() != llvm.StructTypeKind || globalType.StructName() != "runtime._string" {
|
||||||
|
// Verify this is indeed a string. This is needed so
|
||||||
|
// that makeGlobalsModule can just create the right
|
||||||
|
// globals of string type without checking.
|
||||||
|
return fmt.Errorf("%s: not a string", globalName)
|
||||||
|
}
|
||||||
name := global.Name()
|
name := global.Name()
|
||||||
newGlobal := llvm.AddGlobal(mod, global.GlobalValueType(), name+".tmp")
|
newGlobal := llvm.AddGlobal(mod, globalType, name+".tmp")
|
||||||
global.ReplaceAllUsesWith(newGlobal)
|
global.ReplaceAllUsesWith(newGlobal)
|
||||||
global.EraseFromParentAsGlobal()
|
global.EraseFromParentAsGlobal()
|
||||||
newGlobal.SetName(name)
|
newGlobal.SetName(name)
|
||||||
@@ -538,6 +547,15 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert values from -ldflags="-X ..." into the IR.
|
||||||
|
// This is a separate module, so that the "runtime._string" type
|
||||||
|
// doesn't need to match precisely. LLVM tends to rename that type
|
||||||
|
// sometimes, leading to errors. But linking in a separate module
|
||||||
|
// works fine. See:
|
||||||
|
// https://github.com/tinygo-org/tinygo/issues/4810
|
||||||
|
globalsMod := makeGlobalsModule(ctx, globalValues, machine)
|
||||||
|
llvm.LinkModules(mod, globalsMod)
|
||||||
|
|
||||||
// Create runtime.initAll function that calls the runtime
|
// Create runtime.initAll function that calls the runtime
|
||||||
// initializer of each package.
|
// initializer of each package.
|
||||||
llvmInitFn := mod.NamedFunction("runtime.initAll")
|
llvmInitFn := mod.NamedFunction("runtime.initAll")
|
||||||
@@ -590,7 +608,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
|
|||||||
|
|
||||||
// Run all optimization passes, which are much more effective now
|
// Run all optimization passes, which are much more effective now
|
||||||
// that the optimizer can see the whole program at once.
|
// that the optimizer can see the whole program at once.
|
||||||
err := optimizeProgram(mod, config, globalValues)
|
err := optimizeProgram(mod, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -685,7 +703,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
|
|||||||
// Add compiler-rt dependency if needed. Usually this is a simple load from
|
// Add compiler-rt dependency if needed. Usually this is a simple load from
|
||||||
// a cache.
|
// a cache.
|
||||||
if config.Target.RTLib == "compiler-rt" {
|
if config.Target.RTLib == "compiler-rt" {
|
||||||
job, unlock, err := libCompilerRT.load(config, tmpdir)
|
job, unlock, err := libCompilerRT.load(config, tmpdir, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
@@ -693,6 +711,19 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
|
|||||||
linkerDependencies = append(linkerDependencies, job)
|
linkerDependencies = append(linkerDependencies, job)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The Boehm collector is stored in a separate C library.
|
||||||
|
if config.GC() == "boehm" {
|
||||||
|
if libcJob == nil {
|
||||||
|
return BuildResult{}, fmt.Errorf("boehm GC isn't supported with libc %s", config.Target.Libc)
|
||||||
|
}
|
||||||
|
job, unlock, err := BoehmGC.load(config, tmpdir, libcJob)
|
||||||
|
if err != nil {
|
||||||
|
return BuildResult{}, err
|
||||||
|
}
|
||||||
|
defer unlock()
|
||||||
|
linkerDependencies = append(linkerDependencies, job)
|
||||||
|
}
|
||||||
|
|
||||||
// Add jobs to compile extra files. These files are in C or assembly and
|
// Add jobs to compile extra files. These files are in C or assembly and
|
||||||
// contain things like the interrupt vector table and low level operations
|
// contain things like the interrupt vector table and low level operations
|
||||||
// such as stack switching.
|
// such as stack switching.
|
||||||
@@ -1145,7 +1176,7 @@ func createEmbedObjectFile(data, hexSum, sourceFile, sourceDir, tmpdir string, c
|
|||||||
// optimizeProgram runs a series of optimizations and transformations that are
|
// optimizeProgram runs a series of optimizations and transformations that are
|
||||||
// needed to convert a program to its final form. Some transformations are not
|
// needed to convert a program to its final form. Some transformations are not
|
||||||
// optional and must be run as the compiler expects them to run.
|
// optional and must be run as the compiler expects them to run.
|
||||||
func optimizeProgram(mod llvm.Module, config *compileopts.Config, globalValues map[string]map[string]string) error {
|
func optimizeProgram(mod llvm.Module, config *compileopts.Config) error {
|
||||||
err := interp.Run(mod, config.Options.InterpTimeout, config.DumpSSA())
|
err := interp.Run(mod, config.Options.InterpTimeout, config.DumpSSA())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1163,12 +1194,6 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config, globalValues m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert values from -ldflags="-X ..." into the IR.
|
|
||||||
err = setGlobalValues(mod, globalValues)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run most of the whole-program optimizations (including the whole
|
// Run most of the whole-program optimizations (including the whole
|
||||||
// O0/O1/O2/Os/Oz optimization pipeline).
|
// O0/O1/O2/Os/Oz optimization pipeline).
|
||||||
errs := transform.Optimize(mod, config)
|
errs := transform.Optimize(mod, config)
|
||||||
@@ -1182,10 +1207,19 @@ func optimizeProgram(mod llvm.Module, config *compileopts.Config, globalValues m
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// setGlobalValues sets the global values from the -ldflags="-X ..." compiler
|
func makeGlobalsModule(ctx llvm.Context, globals map[string]map[string]string, machine llvm.TargetMachine) llvm.Module {
|
||||||
// option in the given module. An error may be returned if the global is not of
|
mod := ctx.NewModule("cmdline-globals")
|
||||||
// the expected type.
|
targetData := machine.CreateTargetData()
|
||||||
func setGlobalValues(mod llvm.Module, globals map[string]map[string]string) error {
|
defer targetData.Dispose()
|
||||||
|
mod.SetDataLayout(targetData.String())
|
||||||
|
|
||||||
|
stringType := ctx.StructCreateNamed("runtime._string")
|
||||||
|
uintptrType := ctx.IntType(targetData.PointerSize() * 8)
|
||||||
|
stringType.StructSetBody([]llvm.Type{
|
||||||
|
llvm.PointerType(ctx.Int8Type(), 0),
|
||||||
|
uintptrType,
|
||||||
|
}, false)
|
||||||
|
|
||||||
var pkgPaths []string
|
var pkgPaths []string
|
||||||
for pkgPath := range globals {
|
for pkgPath := range globals {
|
||||||
pkgPaths = append(pkgPaths, pkgPath)
|
pkgPaths = append(pkgPaths, pkgPath)
|
||||||
@@ -1201,24 +1235,6 @@ func setGlobalValues(mod llvm.Module, globals map[string]map[string]string) erro
|
|||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
value := pkg[name]
|
value := pkg[name]
|
||||||
globalName := pkgPath + "." + name
|
globalName := pkgPath + "." + name
|
||||||
global := mod.NamedGlobal(globalName)
|
|
||||||
if global.IsNil() || !global.Initializer().IsNil() {
|
|
||||||
// The global either does not exist (optimized away?) or has
|
|
||||||
// some value, in which case it has already been initialized at
|
|
||||||
// package init time.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// A strin is a {ptr, len} pair. We need these types to build the
|
|
||||||
// initializer.
|
|
||||||
initializerType := global.GlobalValueType()
|
|
||||||
if initializerType.TypeKind() != llvm.StructTypeKind || initializerType.StructName() == "" {
|
|
||||||
return fmt.Errorf("%s: not a string", globalName)
|
|
||||||
}
|
|
||||||
elementTypes := initializerType.StructElementTypes()
|
|
||||||
if len(elementTypes) != 2 {
|
|
||||||
return fmt.Errorf("%s: not a string", globalName)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a buffer for the string contents.
|
// Create a buffer for the string contents.
|
||||||
bufInitializer := mod.Context().ConstString(value, false)
|
bufInitializer := mod.Context().ConstString(value, false)
|
||||||
@@ -1229,22 +1245,20 @@ func setGlobalValues(mod llvm.Module, globals map[string]map[string]string) erro
|
|||||||
buf.SetLinkage(llvm.PrivateLinkage)
|
buf.SetLinkage(llvm.PrivateLinkage)
|
||||||
|
|
||||||
// Create the string value, which is a {ptr, len} pair.
|
// Create the string value, which is a {ptr, len} pair.
|
||||||
zero := llvm.ConstInt(mod.Context().Int32Type(), 0, false)
|
length := llvm.ConstInt(uintptrType, uint64(len(value)), false)
|
||||||
ptr := llvm.ConstGEP(bufInitializer.Type(), buf, []llvm.Value{zero, zero})
|
initializer := llvm.ConstNamedStruct(stringType, []llvm.Value{
|
||||||
if ptr.Type() != elementTypes[0] {
|
buf,
|
||||||
return fmt.Errorf("%s: not a string", globalName)
|
|
||||||
}
|
|
||||||
length := llvm.ConstInt(elementTypes[1], uint64(len(value)), false)
|
|
||||||
initializer := llvm.ConstNamedStruct(initializerType, []llvm.Value{
|
|
||||||
ptr,
|
|
||||||
length,
|
length,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Set the initializer. No initializer should be set at this point.
|
// Create the string global.
|
||||||
|
global := llvm.AddGlobal(mod, stringType, globalName)
|
||||||
global.SetInitializer(initializer)
|
global.SetInitializer(initializer)
|
||||||
|
global.SetAlignment(targetData.PrefTypeAlignment(stringType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
|
return mod
|
||||||
}
|
}
|
||||||
|
|
||||||
// functionStackSizes keeps stack size information about a single function
|
// functionStackSizes keeps stack size information about a single function
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ func TestClangAttributes(t *testing.T) {
|
|||||||
{GOOS: "darwin", GOARCH: "arm64"},
|
{GOOS: "darwin", GOARCH: "arm64"},
|
||||||
{GOOS: "windows", GOARCH: "amd64"},
|
{GOOS: "windows", GOARCH: "amd64"},
|
||||||
{GOOS: "windows", GOARCH: "arm64"},
|
{GOOS: "windows", GOARCH: "arm64"},
|
||||||
{GOOS: "wasip1", GOARCH: "wasm"},
|
|
||||||
} {
|
} {
|
||||||
name := "GOOS=" + options.GOOS + ",GOARCH=" + options.GOARCH
|
name := "GOOS=" + options.GOOS + ",GOARCH=" + options.GOARCH
|
||||||
if options.GOARCH == "arm" {
|
if options.GOARCH == "arm" {
|
||||||
|
|||||||
+20
-5
@@ -43,7 +43,11 @@ type Library struct {
|
|||||||
// output archive file, it is expected to be removed after use.
|
// output archive file, it is expected to be removed after use.
|
||||||
// As a side effect, this call creates the library header files if they didn't
|
// As a side effect, this call creates the library header files if they didn't
|
||||||
// exist yet.
|
// exist yet.
|
||||||
func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJob, abortLock func(), err error) {
|
// The provided libc job (if not null) will cause this libc to be added as a
|
||||||
|
// dependency for all C compiler jobs, and adds libc headers for the given
|
||||||
|
// target config. In other words, pass this libc if the library needs a libc to
|
||||||
|
// compile.
|
||||||
|
func (l *Library) load(config *compileopts.Config, tmpdir string, libc *compileJob) (job *compileJob, abortLock func(), err error) {
|
||||||
outdir, precompiled := config.LibcPath(l.name)
|
outdir, precompiled := config.LibcPath(l.name)
|
||||||
archiveFilePath := filepath.Join(outdir, "lib.a")
|
archiveFilePath := filepath.Join(outdir, "lib.a")
|
||||||
if precompiled {
|
if precompiled {
|
||||||
@@ -181,6 +185,9 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
|
|||||||
args = append(args, "-mfpu=vfpv2")
|
args = append(args, "-mfpu=vfpv2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if libc != nil {
|
||||||
|
args = append(args, config.LibcCFlags()...)
|
||||||
|
}
|
||||||
|
|
||||||
var once sync.Once
|
var once sync.Once
|
||||||
|
|
||||||
@@ -233,7 +240,7 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
|
|||||||
objpath := filepath.Join(dir, cleanpath+".o")
|
objpath := filepath.Join(dir, cleanpath+".o")
|
||||||
os.MkdirAll(filepath.Dir(objpath), 0o777)
|
os.MkdirAll(filepath.Dir(objpath), 0o777)
|
||||||
objs = append(objs, objpath)
|
objs = append(objs, objpath)
|
||||||
job.dependencies = append(job.dependencies, &compileJob{
|
objfile := &compileJob{
|
||||||
description: "compile " + srcpath,
|
description: "compile " + srcpath,
|
||||||
run: func(*compileJob) error {
|
run: func(*compileJob) error {
|
||||||
var compileArgs []string
|
var compileArgs []string
|
||||||
@@ -248,7 +255,11 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
if libc != nil {
|
||||||
|
objfile.dependencies = append(objfile.dependencies, libc)
|
||||||
|
}
|
||||||
|
job.dependencies = append(job.dependencies, objfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create crt1.o job, if needed.
|
// Create crt1.o job, if needed.
|
||||||
@@ -257,7 +268,7 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
|
|||||||
// won't make much of a difference in speed).
|
// won't make much of a difference in speed).
|
||||||
if l.crt1Source != "" {
|
if l.crt1Source != "" {
|
||||||
srcpath := filepath.Join(sourceDir, l.crt1Source)
|
srcpath := filepath.Join(sourceDir, l.crt1Source)
|
||||||
job.dependencies = append(job.dependencies, &compileJob{
|
crt1Job := &compileJob{
|
||||||
description: "compile " + srcpath,
|
description: "compile " + srcpath,
|
||||||
run: func(*compileJob) error {
|
run: func(*compileJob) error {
|
||||||
var compileArgs []string
|
var compileArgs []string
|
||||||
@@ -277,7 +288,11 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
|
|||||||
}
|
}
|
||||||
return os.Rename(tmpfile.Name(), filepath.Join(outdir, "crt1.o"))
|
return os.Rename(tmpfile.Name(), filepath.Join(outdir, "crt1.o"))
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
if libc != nil {
|
||||||
|
crt1Job.dependencies = append(crt1Job.dependencies, libc)
|
||||||
|
}
|
||||||
|
job.dependencies = append(job.dependencies, crt1Job)
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true
|
ok = true
|
||||||
|
|||||||
@@ -113,26 +113,32 @@ var libMusl = Library{
|
|||||||
librarySources: func(target string) ([]string, error) {
|
librarySources: func(target string) ([]string, error) {
|
||||||
arch := compileopts.MuslArchitecture(target)
|
arch := compileopts.MuslArchitecture(target)
|
||||||
globs := []string{
|
globs := []string{
|
||||||
|
"ctype/*.c",
|
||||||
"env/*.c",
|
"env/*.c",
|
||||||
"errno/*.c",
|
"errno/*.c",
|
||||||
"exit/*.c",
|
"exit/*.c",
|
||||||
"fcntl/*.c",
|
"fcntl/*.c",
|
||||||
"internal/defsysinfo.c",
|
"internal/defsysinfo.c",
|
||||||
|
"internal/intscan.c",
|
||||||
"internal/libc.c",
|
"internal/libc.c",
|
||||||
|
"internal/shgetc.c",
|
||||||
"internal/syscall_ret.c",
|
"internal/syscall_ret.c",
|
||||||
"internal/vdso.c",
|
"internal/vdso.c",
|
||||||
"legacy/*.c",
|
"legacy/*.c",
|
||||||
"locale/*.c",
|
"locale/*.c",
|
||||||
"linux/*.c",
|
"linux/*.c",
|
||||||
|
"locale/*.c",
|
||||||
"malloc/*.c",
|
"malloc/*.c",
|
||||||
"malloc/mallocng/*.c",
|
"malloc/mallocng/*.c",
|
||||||
"mman/*.c",
|
"mman/*.c",
|
||||||
"math/*.c",
|
"math/*.c",
|
||||||
"misc/*.c",
|
"misc/*.c",
|
||||||
"multibyte/*.c",
|
"multibyte/*.c",
|
||||||
|
"sched/*.c",
|
||||||
"signal/" + arch + "/*.s",
|
"signal/" + arch + "/*.s",
|
||||||
"signal/*.c",
|
"signal/*.c",
|
||||||
"stdio/*.c",
|
"stdio/*.c",
|
||||||
|
"stdlib/*.c",
|
||||||
"string/*.c",
|
"string/*.c",
|
||||||
"thread/" + arch + "/*.s",
|
"thread/" + arch + "/*.s",
|
||||||
"thread/*.c",
|
"thread/*.c",
|
||||||
|
|||||||
+67
-53
@@ -261,6 +261,10 @@ func (c *Config) LibcPath(name string) (path string, precompiled bool) {
|
|||||||
if c.Target.SoftFloat {
|
if c.Target.SoftFloat {
|
||||||
archname += "-softfloat"
|
archname += "-softfloat"
|
||||||
}
|
}
|
||||||
|
if name == "bdwgc" {
|
||||||
|
// Boehm GC is compiled against a particular libc.
|
||||||
|
archname += "-" + c.Target.Libc
|
||||||
|
}
|
||||||
|
|
||||||
// Try to load a precompiled library.
|
// Try to load a precompiled library.
|
||||||
precompiledDir := filepath.Join(goenv.Get("TINYGOROOT"), "pkg", archname, name)
|
precompiledDir := filepath.Join(goenv.Get("TINYGOROOT"), "pkg", archname, name)
|
||||||
@@ -315,59 +319,7 @@ func (c *Config) CFlags(libclang bool) []string {
|
|||||||
"-resource-dir="+resourceDir,
|
"-resource-dir="+resourceDir,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
switch c.Target.Libc {
|
cflags = append(cflags, c.LibcCFlags()...)
|
||||||
case "darwin-libSystem":
|
|
||||||
root := goenv.Get("TINYGOROOT")
|
|
||||||
cflags = append(cflags,
|
|
||||||
"-nostdlibinc",
|
|
||||||
"-isystem", filepath.Join(root, "lib/macos-minimal-sdk/src/usr/include"),
|
|
||||||
)
|
|
||||||
case "picolibc":
|
|
||||||
root := goenv.Get("TINYGOROOT")
|
|
||||||
picolibcDir := filepath.Join(root, "lib", "picolibc", "newlib", "libc")
|
|
||||||
path, _ := c.LibcPath("picolibc")
|
|
||||||
cflags = append(cflags,
|
|
||||||
"-nostdlibinc",
|
|
||||||
"-isystem", filepath.Join(path, "include"),
|
|
||||||
"-isystem", filepath.Join(picolibcDir, "include"),
|
|
||||||
"-isystem", filepath.Join(picolibcDir, "tinystdio"),
|
|
||||||
"-D__PICOLIBC_ERRNO_FUNCTION=__errno_location",
|
|
||||||
)
|
|
||||||
case "musl":
|
|
||||||
root := goenv.Get("TINYGOROOT")
|
|
||||||
path, _ := c.LibcPath("musl")
|
|
||||||
arch := MuslArchitecture(c.Triple())
|
|
||||||
cflags = append(cflags,
|
|
||||||
"-nostdlibinc",
|
|
||||||
"-isystem", filepath.Join(path, "include"),
|
|
||||||
"-isystem", filepath.Join(root, "lib", "musl", "arch", arch),
|
|
||||||
"-isystem", filepath.Join(root, "lib", "musl", "arch", "generic"),
|
|
||||||
"-isystem", filepath.Join(root, "lib", "musl", "include"),
|
|
||||||
)
|
|
||||||
case "wasi-libc":
|
|
||||||
root := goenv.Get("TINYGOROOT")
|
|
||||||
cflags = append(cflags,
|
|
||||||
"-nostdlibinc",
|
|
||||||
"-isystem", root+"/lib/wasi-libc/sysroot/include")
|
|
||||||
case "wasmbuiltins":
|
|
||||||
// nothing to add (library is purely for builtins)
|
|
||||||
case "mingw-w64":
|
|
||||||
root := goenv.Get("TINYGOROOT")
|
|
||||||
path, _ := c.LibcPath("mingw-w64")
|
|
||||||
cflags = append(cflags,
|
|
||||||
"-nostdlibinc",
|
|
||||||
"-isystem", filepath.Join(path, "include"),
|
|
||||||
"-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "crt"),
|
|
||||||
"-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "defaults", "include"),
|
|
||||||
"-D_UCRT",
|
|
||||||
)
|
|
||||||
case "":
|
|
||||||
// No libc specified, nothing to add.
|
|
||||||
default:
|
|
||||||
// Incorrect configuration. This could be handled in a better way, but
|
|
||||||
// usually this will be found by developers (not by TinyGo users).
|
|
||||||
panic("unknown libc: " + c.Target.Libc)
|
|
||||||
}
|
|
||||||
// Always emit debug information. It is optionally stripped at link time.
|
// Always emit debug information. It is optionally stripped at link time.
|
||||||
cflags = append(cflags, "-gdwarf-4")
|
cflags = append(cflags, "-gdwarf-4")
|
||||||
// Use the same optimization level as TinyGo.
|
// Use the same optimization level as TinyGo.
|
||||||
@@ -394,6 +346,68 @@ func (c *Config) CFlags(libclang bool) []string {
|
|||||||
return cflags
|
return cflags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LibcCFlags returns the C compiler flags for the configured libc.
|
||||||
|
// It only uses flags that are part of the libc path (triple, cpu, abi, libc
|
||||||
|
// name) so it can safely be used to compile another C library.
|
||||||
|
func (c *Config) LibcCFlags() []string {
|
||||||
|
switch c.Target.Libc {
|
||||||
|
case "darwin-libSystem":
|
||||||
|
root := goenv.Get("TINYGOROOT")
|
||||||
|
return []string{
|
||||||
|
"-nostdlibinc",
|
||||||
|
"-isystem", filepath.Join(root, "lib/macos-minimal-sdk/src/usr/include"),
|
||||||
|
}
|
||||||
|
case "picolibc":
|
||||||
|
root := goenv.Get("TINYGOROOT")
|
||||||
|
picolibcDir := filepath.Join(root, "lib", "picolibc", "newlib", "libc")
|
||||||
|
path, _ := c.LibcPath("picolibc")
|
||||||
|
return []string{
|
||||||
|
"-nostdlibinc",
|
||||||
|
"-isystem", filepath.Join(path, "include"),
|
||||||
|
"-isystem", filepath.Join(picolibcDir, "include"),
|
||||||
|
"-isystem", filepath.Join(picolibcDir, "tinystdio"),
|
||||||
|
"-D__PICOLIBC_ERRNO_FUNCTION=__errno_location",
|
||||||
|
}
|
||||||
|
case "musl":
|
||||||
|
root := goenv.Get("TINYGOROOT")
|
||||||
|
path, _ := c.LibcPath("musl")
|
||||||
|
arch := MuslArchitecture(c.Triple())
|
||||||
|
return []string{
|
||||||
|
"-nostdlibinc",
|
||||||
|
"-isystem", filepath.Join(path, "include"),
|
||||||
|
"-isystem", filepath.Join(root, "lib", "musl", "arch", arch),
|
||||||
|
"-isystem", filepath.Join(root, "lib", "musl", "arch", "generic"),
|
||||||
|
"-isystem", filepath.Join(root, "lib", "musl", "include"),
|
||||||
|
}
|
||||||
|
case "wasi-libc":
|
||||||
|
root := goenv.Get("TINYGOROOT")
|
||||||
|
return []string{
|
||||||
|
"-nostdlibinc",
|
||||||
|
"-isystem", root + "/lib/wasi-libc/sysroot/include",
|
||||||
|
}
|
||||||
|
case "wasmbuiltins":
|
||||||
|
// nothing to add (library is purely for builtins)
|
||||||
|
return nil
|
||||||
|
case "mingw-w64":
|
||||||
|
root := goenv.Get("TINYGOROOT")
|
||||||
|
path, _ := c.LibcPath("mingw-w64")
|
||||||
|
return []string{
|
||||||
|
"-nostdlibinc",
|
||||||
|
"-isystem", filepath.Join(path, "include"),
|
||||||
|
"-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "crt"),
|
||||||
|
"-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "defaults", "include"),
|
||||||
|
"-D_UCRT",
|
||||||
|
}
|
||||||
|
case "":
|
||||||
|
// No libc specified, nothing to add.
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
// Incorrect configuration. This could be handled in a better way, but
|
||||||
|
// usually this will be found by developers (not by TinyGo users).
|
||||||
|
panic("unknown libc: " + c.Target.Libc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// LDFlags returns the flags to pass to the linker. A few more flags are needed
|
// LDFlags returns the flags to pass to the linker. A few more flags are needed
|
||||||
// (like the one for the compiler runtime), but this represents the majority of
|
// (like the one for the compiler runtime), but this represents the majority of
|
||||||
// the flags.
|
// the flags.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
validBuildModeOptions = []string{"default", "c-shared", "wasi-legacy"}
|
validBuildModeOptions = []string{"default", "c-shared", "wasi-legacy"}
|
||||||
validGCOptions = []string{"none", "leaking", "conservative", "custom", "precise"}
|
validGCOptions = []string{"none", "leaking", "conservative", "custom", "precise", "boehm"}
|
||||||
validSchedulerOptions = []string{"none", "tasks", "asyncify"}
|
validSchedulerOptions = []string{"none", "tasks", "asyncify"}
|
||||||
validSerialOptions = []string{"none", "uart", "usb", "rtt"}
|
validSerialOptions = []string{"none", "uart", "usb", "rtt"}
|
||||||
validPrintSizeOptions = []string{"none", "short", "full", "html"}
|
validPrintSizeOptions = []string{"none", "short", "full", "html"}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func TestVerifyOptions(t *testing.T) {
|
func TestVerifyOptions(t *testing.T) {
|
||||||
|
|
||||||
expectedGCError := errors.New(`invalid gc option 'incorrect': valid values are none, leaking, conservative, custom, precise`)
|
expectedGCError := errors.New(`invalid gc option 'incorrect': valid values are none, leaking, conservative, custom, precise, boehm`)
|
||||||
expectedSchedulerError := errors.New(`invalid scheduler option 'incorrect': valid values are none, tasks, asyncify`)
|
expectedSchedulerError := errors.New(`invalid scheduler option 'incorrect': valid values are none, tasks, asyncify`)
|
||||||
expectedPrintSizeError := errors.New(`invalid size option 'incorrect': valid values are none, short, full, html`)
|
expectedPrintSizeError := errors.New(`invalid size option 'incorrect': valid values are none, short, full, html`)
|
||||||
expectedPanicStrategyError := errors.New(`invalid panic option 'incorrect': valid values are print, trap`)
|
expectedPanicStrategyError := errors.New(`invalid panic option 'incorrect': valid values are print, trap`)
|
||||||
|
|||||||
+6
-29
@@ -247,7 +247,6 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
|||||||
GOOS: options.GOOS,
|
GOOS: options.GOOS,
|
||||||
GOARCH: options.GOARCH,
|
GOARCH: options.GOARCH,
|
||||||
BuildTags: []string{options.GOOS, options.GOARCH},
|
BuildTags: []string{options.GOOS, options.GOARCH},
|
||||||
GC: "precise",
|
|
||||||
Scheduler: "tasks",
|
Scheduler: "tasks",
|
||||||
Linker: "cc",
|
Linker: "cc",
|
||||||
DefaultStackSize: 1024 * 64, // 64kB
|
DefaultStackSize: 1024 * 64, // 64kB
|
||||||
@@ -356,17 +355,7 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
|||||||
return nil, fmt.Errorf("invalid GOMIPS=%s: must be hardfloat or softfloat", options.GOMIPS)
|
return nil, fmt.Errorf("invalid GOMIPS=%s: must be hardfloat or softfloat", options.GOMIPS)
|
||||||
}
|
}
|
||||||
case "wasm":
|
case "wasm":
|
||||||
llvmarch = "wasm32"
|
return nil, fmt.Errorf("GOARCH=wasm but GOOS is unset. Please set GOOS to wasm, wasip1, or wasip2.")
|
||||||
spec.CPU = "generic"
|
|
||||||
spec.Features = "+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types"
|
|
||||||
spec.BuildTags = append(spec.BuildTags, "tinygo.wasm")
|
|
||||||
spec.CFlags = append(spec.CFlags,
|
|
||||||
"-mbulk-memory",
|
|
||||||
"-mnontrapping-fptoint",
|
|
||||||
"-mno-multivalue",
|
|
||||||
"-mno-reference-types",
|
|
||||||
"-msign-ext",
|
|
||||||
)
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown GOARCH=%s", options.GOARCH)
|
return nil, fmt.Errorf("unknown GOARCH=%s", options.GOARCH)
|
||||||
}
|
}
|
||||||
@@ -376,6 +365,7 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
|||||||
llvmvendor := "unknown"
|
llvmvendor := "unknown"
|
||||||
switch options.GOOS {
|
switch options.GOOS {
|
||||||
case "darwin":
|
case "darwin":
|
||||||
|
spec.GC = "precise"
|
||||||
platformVersion := "10.12.0"
|
platformVersion := "10.12.0"
|
||||||
if options.GOARCH == "arm64" {
|
if options.GOARCH == "arm64" {
|
||||||
platformVersion = "11.0.0" // first macosx platform with arm64 support
|
platformVersion = "11.0.0" // first macosx platform with arm64 support
|
||||||
@@ -398,6 +388,7 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
|||||||
"src/runtime/runtime_unix.c",
|
"src/runtime/runtime_unix.c",
|
||||||
"src/runtime/signal.c")
|
"src/runtime/signal.c")
|
||||||
case "linux":
|
case "linux":
|
||||||
|
spec.GC = "boehm"
|
||||||
spec.Linker = "ld.lld"
|
spec.Linker = "ld.lld"
|
||||||
spec.RTLib = "compiler-rt"
|
spec.RTLib = "compiler-rt"
|
||||||
spec.Libc = "musl"
|
spec.Libc = "musl"
|
||||||
@@ -421,6 +412,7 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
|||||||
"src/runtime/runtime_unix.c",
|
"src/runtime/runtime_unix.c",
|
||||||
"src/runtime/signal.c")
|
"src/runtime/signal.c")
|
||||||
case "windows":
|
case "windows":
|
||||||
|
spec.GC = "precise"
|
||||||
spec.Linker = "ld.lld"
|
spec.Linker = "ld.lld"
|
||||||
spec.Libc = "mingw-w64"
|
spec.Libc = "mingw-w64"
|
||||||
// Note: using a medium code model, low image base and no ASLR
|
// Note: using a medium code model, low image base and no ASLR
|
||||||
@@ -446,23 +438,8 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
|||||||
"--no-insert-timestamp",
|
"--no-insert-timestamp",
|
||||||
"--no-dynamicbase",
|
"--no-dynamicbase",
|
||||||
)
|
)
|
||||||
case "wasip1":
|
case "wasm", "wasip1", "wasip2":
|
||||||
spec.GC = "" // use default GC
|
return nil, fmt.Errorf("GOOS=%s but GOARCH is unset. Please set GOARCH to wasm", options.GOOS)
|
||||||
spec.Scheduler = "asyncify"
|
|
||||||
spec.Linker = "wasm-ld"
|
|
||||||
spec.RTLib = "compiler-rt"
|
|
||||||
spec.Libc = "wasi-libc"
|
|
||||||
spec.DefaultStackSize = 1024 * 64 // 64kB
|
|
||||||
spec.LDFlags = append(spec.LDFlags,
|
|
||||||
"--stack-first",
|
|
||||||
"--no-demangle",
|
|
||||||
)
|
|
||||||
spec.Emulator = "wasmtime run --dir={tmpDir}::/tmp {}"
|
|
||||||
spec.ExtraFiles = append(spec.ExtraFiles,
|
|
||||||
"src/runtime/asm_tinygowasm.S",
|
|
||||||
"src/internal/task/task_asyncify_wasm.S",
|
|
||||||
)
|
|
||||||
llvmos = "wasi"
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown GOOS=%s", options.GOOS)
|
return nil, fmt.Errorf("unknown GOOS=%s", options.GOOS)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -371,13 +371,6 @@ func (c *compilerContext) getPointerBitmap(typ llvm.Type, pos token.Pos) *big.In
|
|||||||
return big.NewInt(1)
|
return big.NewInt(1)
|
||||||
case llvm.StructTypeKind:
|
case llvm.StructTypeKind:
|
||||||
ptrs := big.NewInt(0)
|
ptrs := big.NewInt(0)
|
||||||
if typ.StructName() == "runtime.funcValue" {
|
|
||||||
// Hack: the type runtime.funcValue contains an 'id' field which is
|
|
||||||
// of type uintptr, but before the LowerFuncValues pass it actually
|
|
||||||
// contains a pointer (ptrtoint) to a global. This trips up the
|
|
||||||
// interp package. Therefore, make the id field a pointer for now.
|
|
||||||
typ = c.ctx.StructType([]llvm.Type{c.dataPtrType, c.dataPtrType}, false)
|
|
||||||
}
|
|
||||||
for i, subtyp := range typ.StructElementTypes() {
|
for i, subtyp := range typ.StructElementTypes() {
|
||||||
subptrs := c.getPointerBitmap(subtyp, pos)
|
subptrs := c.getPointerBitmap(subtyp, pos)
|
||||||
if subptrs.BitLen() == 0 {
|
if subptrs.BitLen() == 0 {
|
||||||
|
|||||||
+1
-1
@@ -446,7 +446,7 @@ func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) {
|
|||||||
// The list of allowed types is based on this proposal:
|
// The list of allowed types is based on this proposal:
|
||||||
// https://github.com/golang/go/issues/59149
|
// https://github.com/golang/go/issues/59149
|
||||||
func (c *compilerContext) checkWasmImportExport(f *ssa.Function, pragma string) {
|
func (c *compilerContext) checkWasmImportExport(f *ssa.Function, pragma string) {
|
||||||
if c.pkg.Path() == "runtime" || c.pkg.Path() == "syscall/js" || c.pkg.Path() == "syscall" {
|
if c.pkg.Path() == "runtime" || c.pkg.Path() == "syscall/js" || c.pkg.Path() == "syscall" || c.pkg.Path() == "crypto/internal/sysrand" {
|
||||||
// The runtime is a special case. Allow all kinds of parameters
|
// The runtime is a special case. Allow all kinds of parameters
|
||||||
// (importantly, including pointers).
|
// (importantly, including pointers).
|
||||||
return
|
return
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
// Version of TinyGo.
|
// Version of TinyGo.
|
||||||
// Update this value before release of new version of software.
|
// Update this value before release of new version of software.
|
||||||
const version = "0.36.0-dev"
|
const version = "0.37.0"
|
||||||
|
|
||||||
// Return TinyGo version, either in the form 0.30.0 or as a development version
|
// Return TinyGo version, either in the form 0.30.0 or as a development version
|
||||||
// (like 0.30.0-dev-abcd012).
|
// (like 0.30.0-dev-abcd012).
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
module github.com/tinygo-org/tinygo/internal/tools
|
module github.com/tinygo-org/tinygo/internal/wasm-tools
|
||||||
|
|
||||||
go 1.22.4
|
go 1.23.0
|
||||||
|
|
||||||
require github.com/bytecodealliance/wasm-tools-go v0.3.1
|
require (
|
||||||
|
go.bytecodealliance.org v0.6.2
|
||||||
|
go.bytecodealliance.org/cm v0.2.2
|
||||||
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/coreos/go-semver v0.3.1 // indirect
|
github.com/coreos/go-semver v0.3.1 // indirect
|
||||||
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
|
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
|
||||||
github.com/klauspost/compress v1.17.9 // indirect
|
github.com/klauspost/compress v1.18.0 // indirect
|
||||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
github.com/regclient/regclient v0.7.1 // indirect
|
github.com/regclient/regclient v0.8.2 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||||
|
github.com/tetratelabs/wazero v1.9.0 // indirect
|
||||||
github.com/ulikunitz/xz v0.5.12 // indirect
|
github.com/ulikunitz/xz v0.5.12 // indirect
|
||||||
github.com/urfave/cli/v3 v3.0.0-alpha9.2 // indirect
|
github.com/urfave/cli/v3 v3.0.0-beta1 // indirect
|
||||||
golang.org/x/mod v0.21.0 // indirect
|
golang.org/x/mod v0.24.0 // indirect
|
||||||
golang.org/x/sys v0.26.0 // indirect
|
golang.org/x/sys v0.31.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
+22
-18
@@ -1,5 +1,3 @@
|
|||||||
github.com/bytecodealliance/wasm-tools-go v0.3.1 h1:9Q9PjSzkbiVmkUvZ7nYCfJ02mcQDBalxycA3s8g7kR4=
|
|
||||||
github.com/bytecodealliance/wasm-tools-go v0.3.1/go.mod h1:vNAQ8DAEp6xvvk+TUHah5DslLEa76f4H6e737OeaxuY=
|
|
||||||
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
|
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
|
||||||
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
|
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@@ -7,16 +5,16 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4=
|
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4=
|
||||||
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
|
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
|
||||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
||||||
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
||||||
github.com/olareg/olareg v0.1.0 h1:1dXBOgPrig5N7zoXyIZVQqU0QBo6sD9pbL6UYjY75CA=
|
github.com/olareg/olareg v0.1.1 h1:Ui7q93zjcoF+U9U71sgqgZWByDoZOpqHitUXEu2xV+g=
|
||||||
github.com/olareg/olareg v0.1.0/go.mod h1:RBuU7JW7SoIIxZKzLRhq8sVtQeAHzCAtRrXEBx2KlM4=
|
github.com/olareg/olareg v0.1.1/go.mod h1:w8NP4SWrHHtxsFaUiv1lnCnYPm4sN1seCd2h7FK/dc0=
|
||||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||||
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/regclient/regclient v0.7.1 h1:qEsJrTmZd98fZKjueAbrZCSNGU+ifnr6xjlSAs3WOPs=
|
github.com/regclient/regclient v0.8.2 h1:23BQ3jWgKYHHIXUhp/S9laVJDHDoOQaQCzXMJ4undVE=
|
||||||
github.com/regclient/regclient v0.7.1/go.mod h1:+w/BFtJuw0h0nzIw/z2+1FuA2/dVXBzDq4rYmziJpMc=
|
github.com/regclient/regclient v0.8.2/go.mod h1:uGyetv0o6VLyRDjtfeBqp/QBwRLJ3Hcn07/+8QbhNcM=
|
||||||
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
|
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
|
||||||
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
|
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
|
||||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
@@ -25,19 +23,25 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
|
||||||
|
github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM=
|
||||||
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
|
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
|
||||||
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||||
github.com/urfave/cli/v3 v3.0.0-alpha9.2 h1:CL8llQj3dGRLVQQzHxS+ZYRLanOuhyK1fXgLKD+qV+Y=
|
github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg=
|
||||||
github.com/urfave/cli/v3 v3.0.0-alpha9.2/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
|
github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
|
||||||
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
|
go.bytecodealliance.org v0.6.2 h1:Jy4u5DVmSkXgsnwojBhJ+AD/YsJsR3VzVnxF0xRCqTQ=
|
||||||
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
go.bytecodealliance.org v0.6.2/go.mod h1:gqjTJm0y9NSksG4py/lSjIQ/SNuIlOQ+hCIEPQwtJgA=
|
||||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
go.bytecodealliance.org/cm v0.2.2 h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA=
|
||||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
go.bytecodealliance.org/cm v0.2.2/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI=
|
||||||
|
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
|
||||||
|
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
||||||
|
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
|
||||||
|
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
|
golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=
|
||||||
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
|
golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
package tools
|
package tools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "github.com/bytecodealliance/wasm-tools-go/cmd/wit-bindgen-go"
|
_ "go.bytecodealliance.org/cm"
|
||||||
|
_ "go.bytecodealliance.org/cmd/wit-bindgen-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate go install github.com/bytecodealliance/wasm-tools-go/cmd/wit-bindgen-go
|
//go:generate go install go.bytecodealliance.org/cmd/wit-bindgen-go
|
||||||
|
|||||||
@@ -824,19 +824,6 @@ func (v rawValue) rawLLVMValue(mem *memoryView) (llvm.Value, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return llvm.Value{}, err
|
return llvm.Value{}, err
|
||||||
}
|
}
|
||||||
if !field.IsAGlobalVariable().IsNil() {
|
|
||||||
elementType := field.GlobalValueType()
|
|
||||||
if elementType.TypeKind() == llvm.StructTypeKind {
|
|
||||||
// There are some special pointer types that should be used
|
|
||||||
// as a ptrtoint, so that they can be used in certain
|
|
||||||
// optimizations.
|
|
||||||
name := elementType.StructName()
|
|
||||||
if name == "runtime.funcValueWithSignature" {
|
|
||||||
uintptrType := ctx.IntType(int(mem.r.pointerSize) * 8)
|
|
||||||
field = llvm.ConstPtrToInt(field, uintptrType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
structFields = append(structFields, field)
|
structFields = append(structFields, field)
|
||||||
i += mem.r.pointerSize
|
i += mem.r.pointerSize
|
||||||
continue
|
continue
|
||||||
|
|||||||
Submodule
+1
Submodule lib/bdwgc added at d1ff06cc50
@@ -269,6 +269,8 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
|
|||||||
|
|
||||||
if needsSyscallPackage {
|
if needsSyscallPackage {
|
||||||
paths["syscall/"] = true // include syscall/js
|
paths["syscall/"] = true // include syscall/js
|
||||||
|
paths["internal/syscall/"] = true
|
||||||
|
paths["internal/syscall/unix/"] = false
|
||||||
}
|
}
|
||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1684,8 +1684,24 @@ func main() {
|
|||||||
usage(command)
|
usage(command)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if options.Target == "" && filepath.Ext(outpath) == ".wasm" {
|
if options.Target == "" {
|
||||||
options.Target = "wasm"
|
switch {
|
||||||
|
case options.GOARCH == "wasm":
|
||||||
|
switch options.GOOS {
|
||||||
|
case "js":
|
||||||
|
options.Target = "wasm"
|
||||||
|
case "wasip1":
|
||||||
|
options.Target = "wasip1"
|
||||||
|
case "wasip2":
|
||||||
|
options.Target = "wasip2"
|
||||||
|
default:
|
||||||
|
fmt.Fprintln(os.Stderr, "GOARCH=wasm but GOOS is not set correctly. Please set GOOS to wasm, wasip1, or wasip2.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
case filepath.Ext(outpath) == ".wasm":
|
||||||
|
fmt.Fprintln(os.Stderr, "you appear to want to build a wasm file, but have not specified either a target flag, or the GOARCH/GOOS to use.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := Build(pkgName, outpath, options)
|
err := Build(pkgName, outpath, options)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey
|
//go:build nrf || (stm32 && !(stm32f103 || stm32l0x1)) || (sam && atsamd51) || (sam && atsame5x) || esp32c3 || tkey || (tinygo.riscv32 && virt)
|
||||||
|
|
||||||
// If you update the above build constraint, you'll probably also need to update
|
// If you update the above build constraint, you'll probably also need to update
|
||||||
// src/runtime/rand_hwrng.go.
|
// src/runtime/rand_hwrng.go.
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"machine"
|
||||||
|
"runtime"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const N = 500000
|
||||||
|
const Ngoro = 4
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
start := time.Now()
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(Ngoro)
|
||||||
|
for i := 0; i < Ngoro; i++ {
|
||||||
|
go adder(&wg, N)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
elapsed := time.Since(start)
|
||||||
|
goroutineCtxSwitchOverhead := (elapsed / (Ngoro * N)).String()
|
||||||
|
|
||||||
|
elapsedstr := elapsed.String()
|
||||||
|
machine.LED.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
for {
|
||||||
|
println("bench:", elapsedstr, "goroutine ctx switch:", goroutineCtxSwitchOverhead)
|
||||||
|
machine.LED.High()
|
||||||
|
time.Sleep(elapsed)
|
||||||
|
machine.LED.Low()
|
||||||
|
time.Sleep(elapsed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func adder(wg *sync.WaitGroup, num int) {
|
||||||
|
for i := 0; i < num; i++ {
|
||||||
|
runtime.Gosched()
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package cm
|
||||||
|
|
||||||
|
// CaseUnmarshaler returns an function that can unmarshal text into
|
||||||
|
// [variant] or [enum] case T.
|
||||||
|
//
|
||||||
|
// [enum]: https://component-model.bytecodealliance.org/design/wit.html#enums
|
||||||
|
// [variant]: https://component-model.bytecodealliance.org/design/wit.html#variants
|
||||||
|
func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, text []byte) error {
|
||||||
|
if len(cases) <= linearScanThreshold {
|
||||||
|
return func(v *T, text []byte) error {
|
||||||
|
if len(text) == 0 {
|
||||||
|
return &emptyTextError{}
|
||||||
|
}
|
||||||
|
s := string(text)
|
||||||
|
for i := 0; i < len(cases); i++ {
|
||||||
|
if cases[i] == s {
|
||||||
|
*v = T(i)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &noMatchingCaseError{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m := make(map[string]T, len(cases))
|
||||||
|
for i, v := range cases {
|
||||||
|
m[v] = T(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
return func(v *T, text []byte) error {
|
||||||
|
if len(text) == 0 {
|
||||||
|
return &emptyTextError{}
|
||||||
|
}
|
||||||
|
c, ok := m[string(text)]
|
||||||
|
if !ok {
|
||||||
|
return &noMatchingCaseError{}
|
||||||
|
}
|
||||||
|
*v = c
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const linearScanThreshold = 16
|
||||||
|
|
||||||
|
type emptyTextError struct{}
|
||||||
|
|
||||||
|
func (*emptyTextError) Error() string { return "empty text" }
|
||||||
|
|
||||||
|
type noMatchingCaseError struct{}
|
||||||
|
|
||||||
|
func (*noMatchingCaseError) Error() string { return "no matching case" }
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Package cm contains types and functions for interfacing with the WebAssembly Component Model.
|
// Package cm provides types and functions for interfacing with the WebAssembly Component Model.
|
||||||
//
|
//
|
||||||
// The types in this package (such as [List], [Option], [Result], and [Variant]) are designed to match the memory layout
|
// The types in this package (such as [List], [Option], [Result], and [Variant]) are designed to match the memory layout
|
||||||
// of [Component Model] types as specified in the [Canonical ABI].
|
// of [Component Model] types as specified in the [Canonical ABI].
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// This file exists for testing this package without WebAssembly,
|
||||||
|
// allowing empty function bodies with a //go:wasmimport directive.
|
||||||
|
// See https://pkg.go.dev/cmd/compile for more information.
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package cm
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
// ErrorContext represents the Component Model [error-context] type,
|
||||||
|
// an immutable, non-deterministic, host-defined value meant to aid in debugging.
|
||||||
|
//
|
||||||
|
// [error-context]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-context-type
|
||||||
|
type ErrorContext struct {
|
||||||
|
_ HostLayout
|
||||||
|
errorContext
|
||||||
|
}
|
||||||
|
|
||||||
|
type errorContext uint32
|
||||||
|
|
||||||
|
// Error implements the [error] interface. It returns the debug message associated with err.
|
||||||
|
func (err errorContext) Error() string {
|
||||||
|
return err.DebugMessage()
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements [fmt.Stringer].
|
||||||
|
func (err errorContext) String() string {
|
||||||
|
return err.DebugMessage()
|
||||||
|
}
|
||||||
|
|
||||||
|
// DebugMessage represents the Canonical ABI [error-context.debug-message] function.
|
||||||
|
//
|
||||||
|
// [error-context.debug-message]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-contextdebug-message
|
||||||
|
func (err errorContext) DebugMessage() string {
|
||||||
|
var s string
|
||||||
|
wasmimport_errorContextDebugMessage(err, unsafe.Pointer(&s))
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop represents the Canonical ABI [error-context.drop] function.
|
||||||
|
//
|
||||||
|
// [error-context.drop]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-contextdrop
|
||||||
|
func (err errorContext) Drop() {
|
||||||
|
wasmimport_errorContextDrop(err)
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package cm
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
// msg uses unsafe.Pointer for compatibility with go1.23 and lower.
|
||||||
|
//
|
||||||
|
//go:wasmimport canon error-context.debug-message
|
||||||
|
//go:noescape
|
||||||
|
func wasmimport_errorContextDebugMessage(err errorContext, msg unsafe.Pointer)
|
||||||
|
|
||||||
|
//go:wasmimport canon error-context.drop
|
||||||
|
//go:noescape
|
||||||
|
func wasmimport_errorContextDrop(err errorContext)
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package cm
|
||||||
|
|
||||||
|
// Future represents the Component Model [future] type.
|
||||||
|
// A future is a special case of stream. In non-error cases,
|
||||||
|
// a future delivers exactly one value before being automatically closed.
|
||||||
|
//
|
||||||
|
// [future]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#asynchronous-value-types
|
||||||
|
type Future[T any] struct {
|
||||||
|
_ HostLayout
|
||||||
|
future[T]
|
||||||
|
}
|
||||||
|
|
||||||
|
type future[T any] uint32
|
||||||
|
|
||||||
|
// TODO: implement methods on type future
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package cm
|
package cm
|
||||||
|
|
||||||
import "unsafe"
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
// List represents a Component Model list.
|
// List represents a Component Model list.
|
||||||
// The binary representation of list<T> is similar to a Go slice minus the cap field.
|
// The binary representation of list<T> is similar to a Go slice minus the cap field.
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package cm
|
||||||
|
|
||||||
|
// Stream represents the Component Model [stream] type.
|
||||||
|
// A stream is a special case of stream. In non-error cases,
|
||||||
|
// a stream delivers exactly one value before being automatically closed.
|
||||||
|
//
|
||||||
|
// [stream]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#asynchronous-value-types
|
||||||
|
type Stream[T any] struct {
|
||||||
|
_ HostLayout
|
||||||
|
stream[T]
|
||||||
|
}
|
||||||
|
|
||||||
|
type stream[T any] uint32
|
||||||
|
|
||||||
|
// TODO: implement methods on type stream
|
||||||
@@ -3,10 +3,9 @@ package cm
|
|||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
// Discriminant is the set of types that can represent the tag or discriminator of a variant.
|
// Discriminant is the set of types that can represent the tag or discriminator of a variant.
|
||||||
// Use bool for 2-case variant types, result<T>, or option<T> types, uint8 where there are 256 or
|
// Use uint8 where there are 256 or fewer cases, uint16 for up to 65,536 cases, or uint32 for anything greater.
|
||||||
// fewer cases, uint16 for up to 65,536 cases, or uint32 for anything greater.
|
|
||||||
type Discriminant interface {
|
type Discriminant interface {
|
||||||
bool | uint8 | uint16 | uint32
|
uint8 | uint16 | uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variant represents a loosely-typed Component Model variant.
|
// Variant represents a loosely-typed Component Model variant.
|
||||||
|
|||||||
@@ -0,0 +1,196 @@
|
|||||||
|
// Copyright 2009 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Deep equality test via reflection
|
||||||
|
|
||||||
|
package reflectlite
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
// During deepValueEqual, must keep track of checks that are
|
||||||
|
// in progress. The comparison algorithm assumes that all
|
||||||
|
// checks in progress are true when it reencounters them.
|
||||||
|
// Visited comparisons are stored in a map indexed by visit.
|
||||||
|
type visit struct {
|
||||||
|
a1 unsafe.Pointer
|
||||||
|
a2 unsafe.Pointer
|
||||||
|
typ *RawType
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests for deep equality using reflected types. The map argument tracks
|
||||||
|
// comparisons that have already been seen, which allows short circuiting on
|
||||||
|
// recursive types.
|
||||||
|
func deepValueEqual(v1, v2 Value, visited map[visit]struct{}) bool {
|
||||||
|
if !v1.IsValid() || !v2.IsValid() {
|
||||||
|
return v1.IsValid() == v2.IsValid()
|
||||||
|
}
|
||||||
|
if v1.typecode != v2.typecode {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// We want to avoid putting more in the visited map than we need to.
|
||||||
|
// For any possible reference cycle that might be encountered,
|
||||||
|
// hard(v1, v2) needs to return true for at least one of the types in the cycle,
|
||||||
|
// and it's safe and valid to get Value's internal pointer.
|
||||||
|
hard := func(v1, v2 Value) bool {
|
||||||
|
switch v1.Kind() {
|
||||||
|
case Map, Slice, Ptr, Interface:
|
||||||
|
// Nil pointers cannot be cyclic. Avoid putting them in the visited map.
|
||||||
|
return !v1.IsNil() && !v2.IsNil()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if hard(v1, v2) {
|
||||||
|
addr1 := v1.pointer()
|
||||||
|
addr2 := v2.pointer()
|
||||||
|
if uintptr(addr1) > uintptr(addr2) {
|
||||||
|
// Canonicalize order to reduce number of entries in visited.
|
||||||
|
// Assumes non-moving garbage collector.
|
||||||
|
addr1, addr2 = addr2, addr1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Short circuit if references are already seen.
|
||||||
|
v := visit{addr1, addr2, v1.typecode}
|
||||||
|
if _, ok := visited[v]; ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remember for later.
|
||||||
|
visited[v] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch v1.Kind() {
|
||||||
|
case Array:
|
||||||
|
for i := 0; i < v1.Len(); i++ {
|
||||||
|
if !deepValueEqual(v1.Index(i), v2.Index(i), visited) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
case Slice:
|
||||||
|
if v1.IsNil() != v2.IsNil() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if v1.Len() != v2.Len() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if v1.UnsafePointer() == v2.UnsafePointer() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for i := 0; i < v1.Len(); i++ {
|
||||||
|
if !deepValueEqual(v1.Index(i), v2.Index(i), visited) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
case Interface:
|
||||||
|
if v1.IsNil() || v2.IsNil() {
|
||||||
|
return v1.IsNil() == v2.IsNil()
|
||||||
|
}
|
||||||
|
return deepValueEqual(v1.Elem(), v2.Elem(), visited)
|
||||||
|
case Ptr:
|
||||||
|
if v1.UnsafePointer() == v2.UnsafePointer() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return deepValueEqual(v1.Elem(), v2.Elem(), visited)
|
||||||
|
case Struct:
|
||||||
|
for i, n := 0, v1.NumField(); i < n; i++ {
|
||||||
|
if !deepValueEqual(v1.Field(i), v2.Field(i), visited) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
case Map:
|
||||||
|
if v1.IsNil() != v2.IsNil() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if v1.Len() != v2.Len() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if v1.UnsafePointer() == v2.UnsafePointer() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, k := range v1.MapKeys() {
|
||||||
|
val1 := v1.MapIndex(k)
|
||||||
|
val2 := v2.MapIndex(k)
|
||||||
|
if !val1.IsValid() || !val2.IsValid() || !deepValueEqual(val1, val2, visited) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
case Func:
|
||||||
|
if v1.IsNil() && v2.IsNil() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Can't do better than this:
|
||||||
|
return false
|
||||||
|
default:
|
||||||
|
// Normal equality suffices
|
||||||
|
return valueInterfaceUnsafe(v1) == valueInterfaceUnsafe(v2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepEqual reports whether x and y are “deeply equal”, defined as follows.
|
||||||
|
// Two values of identical type are deeply equal if one of the following cases applies.
|
||||||
|
// Values of distinct types are never deeply equal.
|
||||||
|
//
|
||||||
|
// Array values are deeply equal when their corresponding elements are deeply equal.
|
||||||
|
//
|
||||||
|
// Struct values are deeply equal if their corresponding fields,
|
||||||
|
// both exported and unexported, are deeply equal.
|
||||||
|
//
|
||||||
|
// Func values are deeply equal if both are nil; otherwise they are not deeply equal.
|
||||||
|
//
|
||||||
|
// Interface values are deeply equal if they hold deeply equal concrete values.
|
||||||
|
//
|
||||||
|
// Map values are deeply equal when all of the following are true:
|
||||||
|
// they are both nil or both non-nil, they have the same length,
|
||||||
|
// and either they are the same map object or their corresponding keys
|
||||||
|
// (matched using Go equality) map to deeply equal values.
|
||||||
|
//
|
||||||
|
// Pointer values are deeply equal if they are equal using Go's == operator
|
||||||
|
// or if they point to deeply equal values.
|
||||||
|
//
|
||||||
|
// Slice values are deeply equal when all of the following are true:
|
||||||
|
// they are both nil or both non-nil, they have the same length,
|
||||||
|
// and either they point to the same initial entry of the same underlying array
|
||||||
|
// (that is, &x[0] == &y[0]) or their corresponding elements (up to length) are deeply equal.
|
||||||
|
// Note that a non-nil empty slice and a nil slice (for example, []byte{} and []byte(nil))
|
||||||
|
// are not deeply equal.
|
||||||
|
//
|
||||||
|
// Other values - numbers, bools, strings, and channels - are deeply equal
|
||||||
|
// if they are equal using Go's == operator.
|
||||||
|
//
|
||||||
|
// In general DeepEqual is a recursive relaxation of Go's == operator.
|
||||||
|
// However, this idea is impossible to implement without some inconsistency.
|
||||||
|
// Specifically, it is possible for a value to be unequal to itself,
|
||||||
|
// either because it is of func type (uncomparable in general)
|
||||||
|
// or because it is a floating-point NaN value (not equal to itself in floating-point comparison),
|
||||||
|
// or because it is an array, struct, or interface containing
|
||||||
|
// such a value.
|
||||||
|
// On the other hand, pointer values are always equal to themselves,
|
||||||
|
// even if they point at or contain such problematic values,
|
||||||
|
// because they compare equal using Go's == operator, and that
|
||||||
|
// is a sufficient condition to be deeply equal, regardless of content.
|
||||||
|
// DeepEqual has been defined so that the same short-cut applies
|
||||||
|
// to slices and maps: if x and y are the same slice or the same map,
|
||||||
|
// they are deeply equal regardless of content.
|
||||||
|
//
|
||||||
|
// As DeepEqual traverses the data values it may find a cycle. The
|
||||||
|
// second and subsequent times that DeepEqual compares two pointer
|
||||||
|
// values that have been compared before, it treats the values as
|
||||||
|
// equal rather than examining the values to which they point.
|
||||||
|
// This ensures that DeepEqual terminates.
|
||||||
|
func DeepEqual(x, y interface{}) bool {
|
||||||
|
if x == nil || y == nil {
|
||||||
|
return x == y
|
||||||
|
}
|
||||||
|
v1 := ValueOf(x)
|
||||||
|
v2 := ValueOf(y)
|
||||||
|
if v1.typecode != v2.typecode {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return deepValueEqual(v1, v2, make(map[visit]struct{}))
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//go:build mips
|
//go:build mips
|
||||||
|
|
||||||
package reflect
|
package reflectlite
|
||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//go:build !mips
|
//go:build !mips
|
||||||
|
|
||||||
package reflect
|
package reflectlite
|
||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package reflectlite
|
|
||||||
|
|
||||||
import "reflect"
|
|
||||||
|
|
||||||
func Swapper(slice interface{}) func(i, j int) {
|
|
||||||
return reflect.Swapper(slice)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Kind = reflect.Kind
|
|
||||||
type Type = reflect.Type
|
|
||||||
type Value = reflect.Value
|
|
||||||
|
|
||||||
const (
|
|
||||||
Invalid Kind = reflect.Invalid
|
|
||||||
Bool Kind = reflect.Bool
|
|
||||||
Int Kind = reflect.Int
|
|
||||||
Int8 Kind = reflect.Int8
|
|
||||||
Int16 Kind = reflect.Int16
|
|
||||||
Int32 Kind = reflect.Int32
|
|
||||||
Int64 Kind = reflect.Int64
|
|
||||||
Uint Kind = reflect.Uint
|
|
||||||
Uint8 Kind = reflect.Uint8
|
|
||||||
Uint16 Kind = reflect.Uint16
|
|
||||||
Uint32 Kind = reflect.Uint32
|
|
||||||
Uint64 Kind = reflect.Uint64
|
|
||||||
Uintptr Kind = reflect.Uintptr
|
|
||||||
Float32 Kind = reflect.Float32
|
|
||||||
Float64 Kind = reflect.Float64
|
|
||||||
Complex64 Kind = reflect.Complex64
|
|
||||||
Complex128 Kind = reflect.Complex128
|
|
||||||
Array Kind = reflect.Array
|
|
||||||
Chan Kind = reflect.Chan
|
|
||||||
Func Kind = reflect.Func
|
|
||||||
Interface Kind = reflect.Interface
|
|
||||||
Map Kind = reflect.Map
|
|
||||||
Ptr Kind = reflect.Ptr
|
|
||||||
Slice Kind = reflect.Slice
|
|
||||||
String Kind = reflect.String
|
|
||||||
Struct Kind = reflect.Struct
|
|
||||||
UnsafePointer Kind = reflect.UnsafePointer
|
|
||||||
)
|
|
||||||
|
|
||||||
func ValueOf(i interface{}) reflect.Value {
|
|
||||||
return reflect.ValueOf(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TypeOf(i interface{}) reflect.Type {
|
|
||||||
return reflect.TypeOf(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
type ValueError = reflect.ValueError
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package reflect
|
package reflectlite
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package reflectlite
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
// Some of code here has been copied from the Go sources:
|
||||||
|
// https://github.com/golang/go/blob/go1.15.2/src/reflect/swapper.go
|
||||||
|
// It has the following copyright note:
|
||||||
|
//
|
||||||
|
// Copyright 2016 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.
|
||||||
|
|
||||||
|
func Swapper(slice interface{}) func(i, j int) {
|
||||||
|
v := ValueOf(slice)
|
||||||
|
if v.Kind() != Slice {
|
||||||
|
panic(&ValueError{Method: "Swapper"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just return Nop func if nothing to swap.
|
||||||
|
if v.Len() < 2 {
|
||||||
|
return func(i, j int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
typ := v.typecode.Elem()
|
||||||
|
size := typ.Size()
|
||||||
|
|
||||||
|
header := (*sliceHeader)(v.value)
|
||||||
|
tmp := unsafe.Pointer(&make([]byte, size)[0])
|
||||||
|
|
||||||
|
return func(i, j int) {
|
||||||
|
if uint(i) >= uint(header.len) || uint(j) >= uint(header.len) {
|
||||||
|
panic("reflect: slice index out of range")
|
||||||
|
}
|
||||||
|
val1 := unsafe.Add(header.data, uintptr(i)*size)
|
||||||
|
val2 := unsafe.Add(header.data, uintptr(j)*size)
|
||||||
|
memcpy(tmp, val1, size)
|
||||||
|
memcpy(val1, val2, size)
|
||||||
|
memcpy(val2, tmp, size)
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,105 @@
|
|||||||
|
// 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 reflectlite
|
||||||
|
|
||||||
|
// VisibleFields returns all the visible fields in t, which must be a
|
||||||
|
// struct type. A field is defined as visible if it's accessible
|
||||||
|
// directly with a FieldByName call. The returned fields include fields
|
||||||
|
// inside anonymous struct members and unexported fields. They follow
|
||||||
|
// the same order found in the struct, with anonymous fields followed
|
||||||
|
// immediately by their promoted fields.
|
||||||
|
//
|
||||||
|
// For each element e of the returned slice, the corresponding field
|
||||||
|
// can be retrieved from a value v of type t by calling v.FieldByIndex(e.Index).
|
||||||
|
func VisibleFields(t Type) []StructField {
|
||||||
|
if t == nil {
|
||||||
|
panic("reflect: VisibleFields(nil)")
|
||||||
|
}
|
||||||
|
if t.Kind() != Struct {
|
||||||
|
panic("reflect.VisibleFields of non-struct type")
|
||||||
|
}
|
||||||
|
w := &visibleFieldsWalker{
|
||||||
|
byName: make(map[string]int),
|
||||||
|
visiting: make(map[Type]bool),
|
||||||
|
fields: make([]StructField, 0, t.NumField()),
|
||||||
|
index: make([]int, 0, 2),
|
||||||
|
}
|
||||||
|
w.walk(t)
|
||||||
|
// Remove all the fields that have been hidden.
|
||||||
|
// Use an in-place removal that avoids copying in
|
||||||
|
// the common case that there are no hidden fields.
|
||||||
|
j := 0
|
||||||
|
for i := range w.fields {
|
||||||
|
f := &w.fields[i]
|
||||||
|
if f.Name == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if i != j {
|
||||||
|
// A field has been removed. We need to shuffle
|
||||||
|
// all the subsequent elements up.
|
||||||
|
w.fields[j] = *f
|
||||||
|
}
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
return w.fields[:j]
|
||||||
|
}
|
||||||
|
|
||||||
|
type visibleFieldsWalker struct {
|
||||||
|
byName map[string]int
|
||||||
|
visiting map[Type]bool
|
||||||
|
fields []StructField
|
||||||
|
index []int
|
||||||
|
}
|
||||||
|
|
||||||
|
// walk walks all the fields in the struct type t, visiting
|
||||||
|
// fields in index preorder and appending them to w.fields
|
||||||
|
// (this maintains the required ordering).
|
||||||
|
// Fields that have been overridden have their
|
||||||
|
// Name field cleared.
|
||||||
|
func (w *visibleFieldsWalker) walk(t Type) {
|
||||||
|
if w.visiting[t] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.visiting[t] = true
|
||||||
|
for i := 0; i < t.NumField(); i++ {
|
||||||
|
f := t.Field(i)
|
||||||
|
w.index = append(w.index, i)
|
||||||
|
add := true
|
||||||
|
if oldIndex, ok := w.byName[f.Name]; ok {
|
||||||
|
old := &w.fields[oldIndex]
|
||||||
|
if len(w.index) == len(old.Index) {
|
||||||
|
// Fields with the same name at the same depth
|
||||||
|
// cancel one another out. Set the field name
|
||||||
|
// to empty to signify that has happened, and
|
||||||
|
// there's no need to add this field.
|
||||||
|
old.Name = ""
|
||||||
|
add = false
|
||||||
|
} else if len(w.index) < len(old.Index) {
|
||||||
|
// The old field loses because it's deeper than the new one.
|
||||||
|
old.Name = ""
|
||||||
|
} else {
|
||||||
|
// The old field wins because it's shallower than the new one.
|
||||||
|
add = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if add {
|
||||||
|
// Copy the index so that it's not overwritten
|
||||||
|
// by the other appends.
|
||||||
|
f.Index = append([]int(nil), w.index...)
|
||||||
|
w.byName[f.Name] = len(w.fields)
|
||||||
|
w.fields = append(w.fields, f)
|
||||||
|
}
|
||||||
|
if f.Anonymous {
|
||||||
|
if f.Type.Kind() == Pointer {
|
||||||
|
f.Type = f.Type.Elem()
|
||||||
|
}
|
||||||
|
if f.Type.Kind() == Struct {
|
||||||
|
w.walk(f.Type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.index = w.index[:len(w.index)-1]
|
||||||
|
}
|
||||||
|
delete(w.visiting, t)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package unix
|
||||||
|
|
||||||
|
const (
|
||||||
|
R_OK = 0x4
|
||||||
|
W_OK = 0x2
|
||||||
|
X_OK = 0x1
|
||||||
|
)
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package unix
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
func Eaccess(path string, mode uint32) error {
|
||||||
|
// We don't support this syscall on baremetal or wasm.
|
||||||
|
// Callers are generally able to deal with this since unix.Eaccess also
|
||||||
|
// isn't available on Android.
|
||||||
|
return syscall.ENOSYS
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package unix
|
||||||
|
|
||||||
|
type GetRandomFlag uintptr
|
||||||
|
|
||||||
|
const (
|
||||||
|
GRND_NONBLOCK GetRandomFlag = 0x0001
|
||||||
|
GRND_RANDOM GetRandomFlag = 0x0002
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) {
|
||||||
|
panic("todo: unix.GetRandom")
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,7 @@ import (
|
|||||||
//
|
//
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func Exit(status cm.BoolResult) {
|
func Exit(status cm.BoolResult) {
|
||||||
status0 := cm.BoolToU32(status)
|
status0 := (uint32)(cm.BoolToU32(status))
|
||||||
wasmimport_Exit((uint32)(status0))
|
wasmimport_Exit((uint32)(status0))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ import (
|
|||||||
//export wasi:cli/run@0.2.0#run
|
//export wasi:cli/run@0.2.0#run
|
||||||
func wasmexport_Run() (result0 uint32) {
|
func wasmexport_Run() (result0 uint32) {
|
||||||
result := Exports.Run()
|
result := Exports.Run()
|
||||||
result0 = cm.BoolToU32(result)
|
result0 = (uint32)(cm.BoolToU32(result))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ import (
|
|||||||
// nanoseconds: u32,
|
// nanoseconds: u32,
|
||||||
// }
|
// }
|
||||||
type DateTime struct {
|
type DateTime struct {
|
||||||
_ cm.HostLayout
|
_ cm.HostLayout `json:"-"`
|
||||||
Seconds uint64
|
Seconds uint64 `json:"seconds"`
|
||||||
Nanoseconds uint32
|
Nanoseconds uint32 `json:"nanoseconds"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now represents the imported function "now".
|
// Now represents the imported function "now".
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func lower_NewTimestamp(v NewTimestamp) (f0 uint32, f1 uint64, f2 uint32) {
|
|||||||
f0 = (uint32)(v.Tag())
|
f0 = (uint32)(v.Tag())
|
||||||
switch f0 {
|
switch f0 {
|
||||||
case 2: // timestamp
|
case 2: // timestamp
|
||||||
v1, v2 := lower_DateTime(*v.Timestamp())
|
v1, v2 := lower_DateTime(*cm.Case[DateTime](&v, 2))
|
||||||
f1 = (uint64)(v1)
|
f1 = (uint64)(v1)
|
||||||
f2 = (uint32)(v2)
|
f2 = (uint32)(v2)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ const (
|
|||||||
DescriptorTypeSocket
|
DescriptorTypeSocket
|
||||||
)
|
)
|
||||||
|
|
||||||
var stringsDescriptorType = [8]string{
|
var _DescriptorTypeStrings = [8]string{
|
||||||
"unknown",
|
"unknown",
|
||||||
"block-device",
|
"block-device",
|
||||||
"character-device",
|
"character-device",
|
||||||
@@ -119,9 +119,22 @@ var stringsDescriptorType = [8]string{
|
|||||||
|
|
||||||
// String implements [fmt.Stringer], returning the enum case name of e.
|
// String implements [fmt.Stringer], returning the enum case name of e.
|
||||||
func (e DescriptorType) String() string {
|
func (e DescriptorType) String() string {
|
||||||
return stringsDescriptorType[e]
|
return _DescriptorTypeStrings[e]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalText implements [encoding.TextMarshaler].
|
||||||
|
func (e DescriptorType) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(e.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum
|
||||||
|
// case. Returns an error if the supplied text is not one of the enum cases.
|
||||||
|
func (e *DescriptorType) UnmarshalText(text []byte) error {
|
||||||
|
return _DescriptorTypeUnmarshalCase(e, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DescriptorTypeUnmarshalCase = cm.CaseUnmarshaler[DescriptorType](_DescriptorTypeStrings[:])
|
||||||
|
|
||||||
// DescriptorFlags represents the flags "wasi:filesystem/types@0.2.0#descriptor-flags".
|
// DescriptorFlags represents the flags "wasi:filesystem/types@0.2.0#descriptor-flags".
|
||||||
//
|
//
|
||||||
// Descriptor flags.
|
// Descriptor flags.
|
||||||
@@ -246,34 +259,34 @@ type LinkCount uint64
|
|||||||
// status-change-timestamp: option<datetime>,
|
// status-change-timestamp: option<datetime>,
|
||||||
// }
|
// }
|
||||||
type DescriptorStat struct {
|
type DescriptorStat struct {
|
||||||
_ cm.HostLayout
|
_ cm.HostLayout `json:"-"`
|
||||||
// File type.
|
// File type.
|
||||||
Type DescriptorType
|
Type DescriptorType `json:"type"`
|
||||||
|
|
||||||
// Number of hard links to the file.
|
// Number of hard links to the file.
|
||||||
LinkCount LinkCount
|
LinkCount LinkCount `json:"link-count"`
|
||||||
|
|
||||||
// For regular files, the file size in bytes. For symbolic links, the
|
// For regular files, the file size in bytes. For symbolic links, the
|
||||||
// length in bytes of the pathname contained in the symbolic link.
|
// length in bytes of the pathname contained in the symbolic link.
|
||||||
Size FileSize
|
Size FileSize `json:"size"`
|
||||||
|
|
||||||
// Last data access timestamp.
|
// Last data access timestamp.
|
||||||
//
|
//
|
||||||
// If the `option` is none, the platform doesn't maintain an access
|
// If the `option` is none, the platform doesn't maintain an access
|
||||||
// timestamp for this file.
|
// timestamp for this file.
|
||||||
DataAccessTimestamp cm.Option[DateTime]
|
DataAccessTimestamp cm.Option[DateTime] `json:"data-access-timestamp"`
|
||||||
|
|
||||||
// Last data modification timestamp.
|
// Last data modification timestamp.
|
||||||
//
|
//
|
||||||
// If the `option` is none, the platform doesn't maintain a
|
// If the `option` is none, the platform doesn't maintain a
|
||||||
// modification timestamp for this file.
|
// modification timestamp for this file.
|
||||||
DataModificationTimestamp cm.Option[DateTime]
|
DataModificationTimestamp cm.Option[DateTime] `json:"data-modification-timestamp"`
|
||||||
|
|
||||||
// Last file status-change timestamp.
|
// Last file status-change timestamp.
|
||||||
//
|
//
|
||||||
// If the `option` is none, the platform doesn't maintain a
|
// If the `option` is none, the platform doesn't maintain a
|
||||||
// status-change timestamp for this file.
|
// status-change timestamp for this file.
|
||||||
StatusChangeTimestamp cm.Option[DateTime]
|
StatusChangeTimestamp cm.Option[DateTime] `json:"status-change-timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTimestamp represents the variant "wasi:filesystem/types@0.2.0#new-timestamp".
|
// NewTimestamp represents the variant "wasi:filesystem/types@0.2.0#new-timestamp".
|
||||||
@@ -326,7 +339,7 @@ func (self *NewTimestamp) Timestamp() *DateTime {
|
|||||||
return cm.Case[DateTime](self, 2)
|
return cm.Case[DateTime](self, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
var stringsNewTimestamp = [3]string{
|
var _NewTimestampStrings = [3]string{
|
||||||
"no-change",
|
"no-change",
|
||||||
"now",
|
"now",
|
||||||
"timestamp",
|
"timestamp",
|
||||||
@@ -334,7 +347,7 @@ var stringsNewTimestamp = [3]string{
|
|||||||
|
|
||||||
// String implements [fmt.Stringer], returning the variant case name of v.
|
// String implements [fmt.Stringer], returning the variant case name of v.
|
||||||
func (v NewTimestamp) String() string {
|
func (v NewTimestamp) String() string {
|
||||||
return stringsNewTimestamp[v.Tag()]
|
return _NewTimestampStrings[v.Tag()]
|
||||||
}
|
}
|
||||||
|
|
||||||
// DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry".
|
// DirectoryEntry represents the record "wasi:filesystem/types@0.2.0#directory-entry".
|
||||||
@@ -346,12 +359,12 @@ func (v NewTimestamp) String() string {
|
|||||||
// name: string,
|
// name: string,
|
||||||
// }
|
// }
|
||||||
type DirectoryEntry struct {
|
type DirectoryEntry struct {
|
||||||
_ cm.HostLayout
|
_ cm.HostLayout `json:"-"`
|
||||||
// The type of the file referred to by this directory entry.
|
// The type of the file referred to by this directory entry.
|
||||||
Type DescriptorType
|
Type DescriptorType `json:"type"`
|
||||||
|
|
||||||
// The name of the object.
|
// The name of the object.
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrorCode represents the enum "wasi:filesystem/types@0.2.0#error-code".
|
// ErrorCode represents the enum "wasi:filesystem/types@0.2.0#error-code".
|
||||||
@@ -516,7 +529,7 @@ const (
|
|||||||
ErrorCodeCrossDevice
|
ErrorCodeCrossDevice
|
||||||
)
|
)
|
||||||
|
|
||||||
var stringsErrorCode = [37]string{
|
var _ErrorCodeStrings = [37]string{
|
||||||
"access",
|
"access",
|
||||||
"would-block",
|
"would-block",
|
||||||
"already",
|
"already",
|
||||||
@@ -558,9 +571,22 @@ var stringsErrorCode = [37]string{
|
|||||||
|
|
||||||
// String implements [fmt.Stringer], returning the enum case name of e.
|
// String implements [fmt.Stringer], returning the enum case name of e.
|
||||||
func (e ErrorCode) String() string {
|
func (e ErrorCode) String() string {
|
||||||
return stringsErrorCode[e]
|
return _ErrorCodeStrings[e]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalText implements [encoding.TextMarshaler].
|
||||||
|
func (e ErrorCode) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(e.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum
|
||||||
|
// case. Returns an error if the supplied text is not one of the enum cases.
|
||||||
|
func (e *ErrorCode) UnmarshalText(text []byte) error {
|
||||||
|
return _ErrorCodeUnmarshalCase(e, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ErrorCodeUnmarshalCase = cm.CaseUnmarshaler[ErrorCode](_ErrorCodeStrings[:])
|
||||||
|
|
||||||
// Advice represents the enum "wasi:filesystem/types@0.2.0#advice".
|
// Advice represents the enum "wasi:filesystem/types@0.2.0#advice".
|
||||||
//
|
//
|
||||||
// File or memory access pattern advisory information.
|
// File or memory access pattern advisory information.
|
||||||
@@ -601,7 +627,7 @@ const (
|
|||||||
AdviceNoReuse
|
AdviceNoReuse
|
||||||
)
|
)
|
||||||
|
|
||||||
var stringsAdvice = [6]string{
|
var _AdviceStrings = [6]string{
|
||||||
"normal",
|
"normal",
|
||||||
"sequential",
|
"sequential",
|
||||||
"random",
|
"random",
|
||||||
@@ -612,9 +638,22 @@ var stringsAdvice = [6]string{
|
|||||||
|
|
||||||
// String implements [fmt.Stringer], returning the enum case name of e.
|
// String implements [fmt.Stringer], returning the enum case name of e.
|
||||||
func (e Advice) String() string {
|
func (e Advice) String() string {
|
||||||
return stringsAdvice[e]
|
return _AdviceStrings[e]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalText implements [encoding.TextMarshaler].
|
||||||
|
func (e Advice) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(e.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum
|
||||||
|
// case. Returns an error if the supplied text is not one of the enum cases.
|
||||||
|
func (e *Advice) UnmarshalText(text []byte) error {
|
||||||
|
return _AdviceUnmarshalCase(e, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _AdviceUnmarshalCase = cm.CaseUnmarshaler[Advice](_AdviceStrings[:])
|
||||||
|
|
||||||
// MetadataHashValue represents the record "wasi:filesystem/types@0.2.0#metadata-hash-value".
|
// MetadataHashValue represents the record "wasi:filesystem/types@0.2.0#metadata-hash-value".
|
||||||
//
|
//
|
||||||
// A 128-bit hash value, split into parts because wasm doesn't have a
|
// A 128-bit hash value, split into parts because wasm doesn't have a
|
||||||
@@ -625,12 +664,12 @@ func (e Advice) String() string {
|
|||||||
// upper: u64,
|
// upper: u64,
|
||||||
// }
|
// }
|
||||||
type MetadataHashValue struct {
|
type MetadataHashValue struct {
|
||||||
_ cm.HostLayout
|
_ cm.HostLayout `json:"-"`
|
||||||
// 64 bits of a 128-bit hash value.
|
// 64 bits of a 128-bit hash value.
|
||||||
Lower uint64
|
Lower uint64 `json:"lower"`
|
||||||
|
|
||||||
// Another 64 bits of a 128-bit hash value.
|
// Another 64 bits of a 128-bit hash value.
|
||||||
Upper uint64
|
Upper uint64 `json:"upper"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Descriptor represents the imported resource "wasi:filesystem/types@0.2.0#descriptor".
|
// Descriptor represents the imported resource "wasi:filesystem/types@0.2.0#descriptor".
|
||||||
@@ -761,7 +800,7 @@ func (self Descriptor) IsSameObject(other Descriptor) (result bool) {
|
|||||||
self0 := cm.Reinterpret[uint32](self)
|
self0 := cm.Reinterpret[uint32](self)
|
||||||
other0 := cm.Reinterpret[uint32](other)
|
other0 := cm.Reinterpret[uint32](other)
|
||||||
result0 := wasmimport_DescriptorIsSameObject((uint32)(self0), (uint32)(other0))
|
result0 := wasmimport_DescriptorIsSameObject((uint32)(self0), (uint32)(other0))
|
||||||
result = cm.U32ToBool((uint32)(result0))
|
result = (bool)(cm.U32ToBool((uint32)(result0)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func (self Pollable) Block() {
|
|||||||
func (self Pollable) Ready() (result bool) {
|
func (self Pollable) Ready() (result bool) {
|
||||||
self0 := cm.Reinterpret[uint32](self)
|
self0 := cm.Reinterpret[uint32](self)
|
||||||
result0 := wasmimport_PollableReady((uint32)(self0))
|
result0 := wasmimport_PollableReady((uint32)(self0))
|
||||||
result = cm.U32ToBool((uint32)(result0))
|
result = (bool)(cm.U32ToBool((uint32)(result0)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
|
||||||
|
|
||||||
package streams
|
|
||||||
|
|
||||||
import (
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// StreamErrorShape is used for storage in variant or result types.
|
|
||||||
type StreamErrorShape struct {
|
|
||||||
shape [unsafe.Sizeof(StreamError{})]byte
|
|
||||||
}
|
|
||||||
@@ -64,14 +64,14 @@ func (self *StreamError) Closed() bool {
|
|||||||
return self.Tag() == 1
|
return self.Tag() == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var stringsStreamError = [2]string{
|
var _StreamErrorStrings = [2]string{
|
||||||
"last-operation-failed",
|
"last-operation-failed",
|
||||||
"closed",
|
"closed",
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements [fmt.Stringer], returning the variant case name of v.
|
// String implements [fmt.Stringer], returning the variant case name of v.
|
||||||
func (v StreamError) String() string {
|
func (v StreamError) String() string {
|
||||||
return stringsStreamError[v.Tag()]
|
return _StreamErrorStrings[v.Tag()]
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputStream represents the imported resource "wasi:io/streams@0.2.0#input-stream".
|
// InputStream represents the imported resource "wasi:io/streams@0.2.0#input-stream".
|
||||||
@@ -273,13 +273,13 @@ func (self OutputStream) BlockingSplice(src InputStream, len_ uint64) (result cm
|
|||||||
//
|
//
|
||||||
// let pollable = this.subscribe();
|
// let pollable = this.subscribe();
|
||||||
// while !contents.is_empty() {
|
// while !contents.is_empty() {
|
||||||
// // Wait for the stream to become writable
|
// // Wait for the stream to become writable
|
||||||
// pollable.block();
|
// pollable.block();
|
||||||
// let Ok(n) = this.check-write(); // eliding error handling
|
// let Ok(n) = this.check-write(); // eliding error handling
|
||||||
// let len = min(n, contents.len());
|
// let len = min(n, contents.len());
|
||||||
// let (chunk, rest) = contents.split_at(len);
|
// let (chunk, rest) = contents.split_at(len);
|
||||||
// this.write(chunk ); // eliding error handling
|
// this.write(chunk ); // eliding error handling
|
||||||
// contents = rest;
|
// contents = rest;
|
||||||
// }
|
// }
|
||||||
// this.flush();
|
// this.flush();
|
||||||
// // Wait for completion of `flush`
|
// // Wait for completion of `flush`
|
||||||
@@ -309,12 +309,12 @@ func (self OutputStream) BlockingWriteAndFlush(contents cm.List[uint8]) (result
|
|||||||
//
|
//
|
||||||
// let pollable = this.subscribe();
|
// let pollable = this.subscribe();
|
||||||
// while num_zeroes != 0 {
|
// while num_zeroes != 0 {
|
||||||
// // Wait for the stream to become writable
|
// // Wait for the stream to become writable
|
||||||
// pollable.block();
|
// pollable.block();
|
||||||
// let Ok(n) = this.check-write(); // eliding error handling
|
// let Ok(n) = this.check-write(); // eliding error handling
|
||||||
// let len = min(n, num_zeroes);
|
// let len = min(n, num_zeroes);
|
||||||
// this.write-zeroes(len); // eliding error handling
|
// this.write-zeroes(len); // eliding error handling
|
||||||
// num_zeroes -= len;
|
// num_zeroes -= len;
|
||||||
// }
|
// }
|
||||||
// this.flush();
|
// this.flush();
|
||||||
// // Wait for completion of `flush`
|
// // Wait for completion of `flush`
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ const (
|
|||||||
ErrorCodePermanentResolverFailure
|
ErrorCodePermanentResolverFailure
|
||||||
)
|
)
|
||||||
|
|
||||||
var stringsErrorCode = [21]string{
|
var _ErrorCodeStrings = [21]string{
|
||||||
"unknown",
|
"unknown",
|
||||||
"access-denied",
|
"access-denied",
|
||||||
"not-supported",
|
"not-supported",
|
||||||
@@ -179,9 +179,22 @@ var stringsErrorCode = [21]string{
|
|||||||
|
|
||||||
// String implements [fmt.Stringer], returning the enum case name of e.
|
// String implements [fmt.Stringer], returning the enum case name of e.
|
||||||
func (e ErrorCode) String() string {
|
func (e ErrorCode) String() string {
|
||||||
return stringsErrorCode[e]
|
return _ErrorCodeStrings[e]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalText implements [encoding.TextMarshaler].
|
||||||
|
func (e ErrorCode) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(e.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum
|
||||||
|
// case. Returns an error if the supplied text is not one of the enum cases.
|
||||||
|
func (e *ErrorCode) UnmarshalText(text []byte) error {
|
||||||
|
return _ErrorCodeUnmarshalCase(e, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ErrorCodeUnmarshalCase = cm.CaseUnmarshaler[ErrorCode](_ErrorCodeStrings[:])
|
||||||
|
|
||||||
// IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family".
|
// IPAddressFamily represents the enum "wasi:sockets/network@0.2.0#ip-address-family".
|
||||||
//
|
//
|
||||||
// enum ip-address-family {
|
// enum ip-address-family {
|
||||||
@@ -198,16 +211,29 @@ const (
|
|||||||
IPAddressFamilyIPv6
|
IPAddressFamilyIPv6
|
||||||
)
|
)
|
||||||
|
|
||||||
var stringsIPAddressFamily = [2]string{
|
var _IPAddressFamilyStrings = [2]string{
|
||||||
"ipv4",
|
"ipv4",
|
||||||
"ipv6",
|
"ipv6",
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements [fmt.Stringer], returning the enum case name of e.
|
// String implements [fmt.Stringer], returning the enum case name of e.
|
||||||
func (e IPAddressFamily) String() string {
|
func (e IPAddressFamily) String() string {
|
||||||
return stringsIPAddressFamily[e]
|
return _IPAddressFamilyStrings[e]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalText implements [encoding.TextMarshaler].
|
||||||
|
func (e IPAddressFamily) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(e.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum
|
||||||
|
// case. Returns an error if the supplied text is not one of the enum cases.
|
||||||
|
func (e *IPAddressFamily) UnmarshalText(text []byte) error {
|
||||||
|
return _IPAddressFamilyUnmarshalCase(e, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _IPAddressFamilyUnmarshalCase = cm.CaseUnmarshaler[IPAddressFamily](_IPAddressFamilyStrings[:])
|
||||||
|
|
||||||
// IPv4Address represents the tuple "wasi:sockets/network@0.2.0#ipv4-address".
|
// IPv4Address represents the tuple "wasi:sockets/network@0.2.0#ipv4-address".
|
||||||
//
|
//
|
||||||
// type ipv4-address = tuple<u8, u8, u8, u8>
|
// type ipv4-address = tuple<u8, u8, u8, u8>
|
||||||
@@ -246,14 +272,14 @@ func (self *IPAddress) IPv6() *IPv6Address {
|
|||||||
return cm.Case[IPv6Address](self, 1)
|
return cm.Case[IPv6Address](self, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
var stringsIPAddress = [2]string{
|
var _IPAddressStrings = [2]string{
|
||||||
"ipv4",
|
"ipv4",
|
||||||
"ipv6",
|
"ipv6",
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements [fmt.Stringer], returning the variant case name of v.
|
// String implements [fmt.Stringer], returning the variant case name of v.
|
||||||
func (v IPAddress) String() string {
|
func (v IPAddress) String() string {
|
||||||
return stringsIPAddress[v.Tag()]
|
return _IPAddressStrings[v.Tag()]
|
||||||
}
|
}
|
||||||
|
|
||||||
// IPv4SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv4-socket-address".
|
// IPv4SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv4-socket-address".
|
||||||
@@ -263,12 +289,12 @@ func (v IPAddress) String() string {
|
|||||||
// address: ipv4-address,
|
// address: ipv4-address,
|
||||||
// }
|
// }
|
||||||
type IPv4SocketAddress struct {
|
type IPv4SocketAddress struct {
|
||||||
_ cm.HostLayout
|
_ cm.HostLayout `json:"-"`
|
||||||
// sin_port
|
// sin_port
|
||||||
Port uint16
|
Port uint16 `json:"port"`
|
||||||
|
|
||||||
// sin_addr
|
// sin_addr
|
||||||
Address IPv4Address
|
Address IPv4Address `json:"address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IPv6SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv6-socket-address".
|
// IPv6SocketAddress represents the record "wasi:sockets/network@0.2.0#ipv6-socket-address".
|
||||||
@@ -280,18 +306,18 @@ type IPv4SocketAddress struct {
|
|||||||
// scope-id: u32,
|
// scope-id: u32,
|
||||||
// }
|
// }
|
||||||
type IPv6SocketAddress struct {
|
type IPv6SocketAddress struct {
|
||||||
_ cm.HostLayout
|
_ cm.HostLayout `json:"-"`
|
||||||
// sin6_port
|
// sin6_port
|
||||||
Port uint16
|
Port uint16 `json:"port"`
|
||||||
|
|
||||||
// sin6_flowinfo
|
// sin6_flowinfo
|
||||||
FlowInfo uint32
|
FlowInfo uint32 `json:"flow-info"`
|
||||||
|
|
||||||
// sin6_addr
|
// sin6_addr
|
||||||
Address IPv6Address
|
Address IPv6Address `json:"address"`
|
||||||
|
|
||||||
// sin6_scope_id
|
// sin6_scope_id
|
||||||
ScopeID uint32
|
ScopeID uint32 `json:"scope-id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address".
|
// IPSocketAddress represents the variant "wasi:sockets/network@0.2.0#ip-socket-address".
|
||||||
@@ -322,12 +348,12 @@ func (self *IPSocketAddress) IPv6() *IPv6SocketAddress {
|
|||||||
return cm.Case[IPv6SocketAddress](self, 1)
|
return cm.Case[IPv6SocketAddress](self, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
var stringsIPSocketAddress = [2]string{
|
var _IPSocketAddressStrings = [2]string{
|
||||||
"ipv4",
|
"ipv4",
|
||||||
"ipv6",
|
"ipv6",
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements [fmt.Stringer], returning the variant case name of v.
|
// String implements [fmt.Stringer], returning the variant case name of v.
|
||||||
func (v IPSocketAddress) String() string {
|
func (v IPSocketAddress) String() string {
|
||||||
return stringsIPSocketAddress[v.Tag()]
|
return _IPSocketAddressStrings[v.Tag()]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ type TupleInputStreamOutputStreamShape struct {
|
|||||||
// IPSocketAddressShape is used for storage in variant or result types.
|
// IPSocketAddressShape is used for storage in variant or result types.
|
||||||
type IPSocketAddressShape struct {
|
type IPSocketAddressShape struct {
|
||||||
_ cm.HostLayout
|
_ cm.HostLayout
|
||||||
shape [unsafe.Sizeof(network.IPSocketAddress{})]byte
|
shape [unsafe.Sizeof(IPSocketAddress{})]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) {
|
func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) {
|
||||||
@@ -64,14 +64,14 @@ func lower_IPSocketAddress(v network.IPSocketAddress) (f0 uint32, f1 uint32, f2
|
|||||||
f0 = (uint32)(v.Tag())
|
f0 = (uint32)(v.Tag())
|
||||||
switch f0 {
|
switch f0 {
|
||||||
case 0: // ipv4
|
case 0: // ipv4
|
||||||
v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*v.IPv4())
|
v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*cm.Case[network.IPv4SocketAddress](&v, 0))
|
||||||
f1 = (uint32)(v1)
|
f1 = (uint32)(v1)
|
||||||
f2 = (uint32)(v2)
|
f2 = (uint32)(v2)
|
||||||
f3 = (uint32)(v3)
|
f3 = (uint32)(v3)
|
||||||
f4 = (uint32)(v4)
|
f4 = (uint32)(v4)
|
||||||
f5 = (uint32)(v5)
|
f5 = (uint32)(v5)
|
||||||
case 1: // ipv6
|
case 1: // ipv6
|
||||||
v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*v.IPv6())
|
v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*cm.Case[network.IPv6SocketAddress](&v, 1))
|
||||||
f1 = (uint32)(v1)
|
f1 = (uint32)(v1)
|
||||||
f2 = (uint32)(v2)
|
f2 = (uint32)(v2)
|
||||||
f3 = (uint32)(v3)
|
f3 = (uint32)(v3)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func wasmimport_TCPSocketKeepAliveCount(self0 uint32, result *cm.Result[uint32,
|
|||||||
|
|
||||||
//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-enabled
|
//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-enabled
|
||||||
//go:noescape
|
//go:noescape
|
||||||
func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[bool, bool, ErrorCode])
|
func wasmimport_TCPSocketKeepAliveEnabled(self0 uint32, result *cm.Result[ErrorCode, bool, ErrorCode])
|
||||||
|
|
||||||
//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-idle-time
|
//go:wasmimport wasi:sockets/tcp@0.2.0 [method]tcp-socket.keep-alive-idle-time
|
||||||
//go:noescape
|
//go:noescape
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ const (
|
|||||||
ShutdownTypeBoth
|
ShutdownTypeBoth
|
||||||
)
|
)
|
||||||
|
|
||||||
var stringsShutdownType = [3]string{
|
var _ShutdownTypeStrings = [3]string{
|
||||||
"receive",
|
"receive",
|
||||||
"send",
|
"send",
|
||||||
"both",
|
"both",
|
||||||
@@ -79,9 +79,22 @@ var stringsShutdownType = [3]string{
|
|||||||
|
|
||||||
// String implements [fmt.Stringer], returning the enum case name of e.
|
// String implements [fmt.Stringer], returning the enum case name of e.
|
||||||
func (e ShutdownType) String() string {
|
func (e ShutdownType) String() string {
|
||||||
return stringsShutdownType[e]
|
return _ShutdownTypeStrings[e]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalText implements [encoding.TextMarshaler].
|
||||||
|
func (e ShutdownType) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(e.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements [encoding.TextUnmarshaler], unmarshaling into an enum
|
||||||
|
// case. Returns an error if the supplied text is not one of the enum cases.
|
||||||
|
func (e *ShutdownType) UnmarshalText(text []byte) error {
|
||||||
|
return _ShutdownTypeUnmarshalCase(e, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ShutdownTypeUnmarshalCase = cm.CaseUnmarshaler[ShutdownType](_ShutdownTypeStrings[:])
|
||||||
|
|
||||||
// TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.0#tcp-socket".
|
// TCPSocket represents the imported resource "wasi:sockets/tcp@0.2.0#tcp-socket".
|
||||||
//
|
//
|
||||||
// A TCP socket resource.
|
// A TCP socket resource.
|
||||||
@@ -241,7 +254,7 @@ func (self TCPSocket) HopLimit() (result cm.Result[uint8, uint8, ErrorCode]) {
|
|||||||
func (self TCPSocket) IsListening() (result bool) {
|
func (self TCPSocket) IsListening() (result bool) {
|
||||||
self0 := cm.Reinterpret[uint32](self)
|
self0 := cm.Reinterpret[uint32](self)
|
||||||
result0 := wasmimport_TCPSocketIsListening((uint32)(self0))
|
result0 := wasmimport_TCPSocketIsListening((uint32)(self0))
|
||||||
result = cm.U32ToBool((uint32)(result0))
|
result = (bool)(cm.U32ToBool((uint32)(result0)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +298,7 @@ func (self TCPSocket) KeepAliveCount() (result cm.Result[uint32, uint32, ErrorCo
|
|||||||
// keep-alive-enabled: func() -> result<bool, error-code>
|
// keep-alive-enabled: func() -> result<bool, error-code>
|
||||||
//
|
//
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
func (self TCPSocket) KeepAliveEnabled() (result cm.Result[bool, bool, ErrorCode]) {
|
func (self TCPSocket) KeepAliveEnabled() (result cm.Result[ErrorCode, bool, ErrorCode]) {
|
||||||
self0 := cm.Reinterpret[uint32](self)
|
self0 := cm.Reinterpret[uint32](self)
|
||||||
wasmimport_TCPSocketKeepAliveEnabled((uint32)(self0), &result)
|
wasmimport_TCPSocketKeepAliveEnabled((uint32)(self0), &result)
|
||||||
return
|
return
|
||||||
@@ -457,7 +470,7 @@ func (self TCPSocket) SetKeepAliveCount(value uint32) (result cm.Result[ErrorCod
|
|||||||
//go:nosplit
|
//go:nosplit
|
||||||
func (self TCPSocket) SetKeepAliveEnabled(value bool) (result cm.Result[ErrorCode, struct{}, ErrorCode]) {
|
func (self TCPSocket) SetKeepAliveEnabled(value bool) (result cm.Result[ErrorCode, struct{}, ErrorCode]) {
|
||||||
self0 := cm.Reinterpret[uint32](self)
|
self0 := cm.Reinterpret[uint32](self)
|
||||||
value0 := cm.BoolToU32(value)
|
value0 := (uint32)(cm.BoolToU32(value))
|
||||||
wasmimport_TCPSocketSetKeepAliveEnabled((uint32)(self0), (uint32)(value0), &result)
|
wasmimport_TCPSocketSetKeepAliveEnabled((uint32)(self0), (uint32)(value0), &result)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
// IPSocketAddressShape is used for storage in variant or result types.
|
// IPSocketAddressShape is used for storage in variant or result types.
|
||||||
type IPSocketAddressShape struct {
|
type IPSocketAddressShape struct {
|
||||||
_ cm.HostLayout
|
_ cm.HostLayout
|
||||||
shape [unsafe.Sizeof(network.IPSocketAddress{})]byte
|
shape [unsafe.Sizeof(IPSocketAddress{})]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) {
|
func lower_IPv4Address(v network.IPv4Address) (f0 uint32, f1 uint32, f2 uint32, f3 uint32) {
|
||||||
@@ -52,14 +52,14 @@ func lower_IPSocketAddress(v network.IPSocketAddress) (f0 uint32, f1 uint32, f2
|
|||||||
f0 = (uint32)(v.Tag())
|
f0 = (uint32)(v.Tag())
|
||||||
switch f0 {
|
switch f0 {
|
||||||
case 0: // ipv4
|
case 0: // ipv4
|
||||||
v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*v.IPv4())
|
v1, v2, v3, v4, v5 := lower_IPv4SocketAddress(*cm.Case[network.IPv4SocketAddress](&v, 0))
|
||||||
f1 = (uint32)(v1)
|
f1 = (uint32)(v1)
|
||||||
f2 = (uint32)(v2)
|
f2 = (uint32)(v2)
|
||||||
f3 = (uint32)(v3)
|
f3 = (uint32)(v3)
|
||||||
f4 = (uint32)(v4)
|
f4 = (uint32)(v4)
|
||||||
f5 = (uint32)(v5)
|
f5 = (uint32)(v5)
|
||||||
case 1: // ipv6
|
case 1: // ipv6
|
||||||
v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*v.IPv6())
|
v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11 := lower_IPv6SocketAddress(*cm.Case[network.IPv6SocketAddress](&v, 1))
|
||||||
f1 = (uint32)(v1)
|
f1 = (uint32)(v1)
|
||||||
f2 = (uint32)(v2)
|
f2 = (uint32)(v2)
|
||||||
f3 = (uint32)(v3)
|
f3 = (uint32)(v3)
|
||||||
|
|||||||
@@ -43,11 +43,11 @@ type IPAddressFamily = network.IPAddressFamily
|
|||||||
// remote-address: ip-socket-address,
|
// remote-address: ip-socket-address,
|
||||||
// }
|
// }
|
||||||
type IncomingDatagram struct {
|
type IncomingDatagram struct {
|
||||||
_ cm.HostLayout
|
_ cm.HostLayout `json:"-"`
|
||||||
// The payload.
|
// The payload.
|
||||||
//
|
//
|
||||||
// Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes.
|
// Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes.
|
||||||
Data cm.List[uint8]
|
Data cm.List[uint8] `json:"data"`
|
||||||
|
|
||||||
// The source address.
|
// The source address.
|
||||||
//
|
//
|
||||||
@@ -55,7 +55,7 @@ type IncomingDatagram struct {
|
|||||||
// with, if any.
|
// with, if any.
|
||||||
//
|
//
|
||||||
// Equivalent to the `src_addr` out parameter of `recvfrom`.
|
// Equivalent to the `src_addr` out parameter of `recvfrom`.
|
||||||
RemoteAddress IPSocketAddress
|
RemoteAddress IPSocketAddress `json:"remote-address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram".
|
// OutgoingDatagram represents the record "wasi:sockets/udp@0.2.0#outgoing-datagram".
|
||||||
@@ -67,9 +67,9 @@ type IncomingDatagram struct {
|
|||||||
// remote-address: option<ip-socket-address>,
|
// remote-address: option<ip-socket-address>,
|
||||||
// }
|
// }
|
||||||
type OutgoingDatagram struct {
|
type OutgoingDatagram struct {
|
||||||
_ cm.HostLayout
|
_ cm.HostLayout `json:"-"`
|
||||||
// The payload.
|
// The payload.
|
||||||
Data cm.List[uint8]
|
Data cm.List[uint8] `json:"data"`
|
||||||
|
|
||||||
// The destination address.
|
// The destination address.
|
||||||
//
|
//
|
||||||
@@ -80,7 +80,7 @@ type OutgoingDatagram struct {
|
|||||||
//
|
//
|
||||||
// If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise
|
// If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise
|
||||||
// it is equivalent to `sendto`.
|
// it is equivalent to `sendto`.
|
||||||
RemoteAddress cm.Option[IPSocketAddress]
|
RemoteAddress cm.Option[IPSocketAddress] `json:"remote-address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UDPSocket represents the imported resource "wasi:sockets/udp@0.2.0#udp-socket".
|
// UDPSocket represents the imported resource "wasi:sockets/udp@0.2.0#udp-socket".
|
||||||
@@ -321,10 +321,10 @@ func (self UDPSocket) StartBind(network_ Network, localAddress IPSocketAddress)
|
|||||||
// The POSIX equivalent in pseudo-code is:
|
// The POSIX equivalent in pseudo-code is:
|
||||||
//
|
//
|
||||||
// if (was previously connected) {
|
// if (was previously connected) {
|
||||||
// connect(s, AF_UNSPEC)
|
// connect(s, AF_UNSPEC)
|
||||||
// }
|
// }
|
||||||
// if (remote_address is Some) {
|
// if (remote_address is Some) {
|
||||||
// connect(s, remote_address)
|
// connect(s, remote_address)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Unlike in POSIX, the socket must already be explicitly bound.
|
// Unlike in POSIX, the socket must already be explicitly bound.
|
||||||
|
|||||||
@@ -186,15 +186,15 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
SPI1 = SPI{
|
SPI1 = &SPI{
|
||||||
Bus: stm32.SPI2,
|
Bus: stm32.SPI2,
|
||||||
AltFuncSelector: AF5_SPI1_SPI2,
|
AltFuncSelector: AF5_SPI1_SPI2,
|
||||||
}
|
}
|
||||||
SPI2 = SPI{
|
SPI2 = &SPI{
|
||||||
Bus: stm32.SPI3,
|
Bus: stm32.SPI3,
|
||||||
AltFuncSelector: AF6_SPI3,
|
AltFuncSelector: AF6_SPI3,
|
||||||
}
|
}
|
||||||
SPI3 = SPI{
|
SPI3 = &SPI{
|
||||||
Bus: stm32.SPI1,
|
Bus: stm32.SPI1,
|
||||||
AltFuncSelector: AF5_SPI1_SPI2,
|
AltFuncSelector: AF5_SPI1_SPI2,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ var (
|
|||||||
I2C0 = I2C1
|
I2C0 = I2C1
|
||||||
|
|
||||||
// SPI
|
// SPI
|
||||||
SPI3 = SPI{
|
SPI3 = &SPI{
|
||||||
Bus: stm32.SPI3,
|
Bus: stm32.SPI3,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import "device/sifive"
|
|||||||
|
|
||||||
// SPI on the HiFive1.
|
// SPI on the HiFive1.
|
||||||
var (
|
var (
|
||||||
SPI1 = SPI{
|
SPI1 = &SPI{
|
||||||
Bus: sifive.QSPI1,
|
Bus: sifive.QSPI1,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -84,10 +84,10 @@ var (
|
|||||||
I2C0 = I2C1
|
I2C0 = I2C1
|
||||||
|
|
||||||
// SPI
|
// SPI
|
||||||
SPI0 = SPI{
|
SPI0 = &SPI{
|
||||||
Bus: stm32.SPI1,
|
Bus: stm32.SPI1,
|
||||||
}
|
}
|
||||||
SPI1 = &SPI0
|
SPI1 = SPI0
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ var (
|
|||||||
I2C0 = I2C2
|
I2C0 = I2C2
|
||||||
|
|
||||||
// SPI
|
// SPI
|
||||||
SPI3 = SPI{
|
SPI3 = &SPI{
|
||||||
Bus: stm32.SPI3,
|
Bus: stm32.SPI3,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import "device/kendryte"
|
|||||||
|
|
||||||
// SPI on the MAix Bit.
|
// SPI on the MAix Bit.
|
||||||
var (
|
var (
|
||||||
SPI0 = SPI{
|
SPI0 = &SPI{
|
||||||
Bus: kendryte.SPI0,
|
Bus: kendryte.SPI0,
|
||||||
}
|
}
|
||||||
SPI1 = SPI{
|
SPI1 = &SPI{
|
||||||
Bus: kendryte.SPI1,
|
Bus: kendryte.SPI1,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -89,11 +89,11 @@ const (
|
|||||||
|
|
||||||
// Since the first interface is named SPI1, both SPI0 and SPI1 refer to SPI1.
|
// Since the first interface is named SPI1, both SPI0 and SPI1 refer to SPI1.
|
||||||
var (
|
var (
|
||||||
SPI0 = SPI{
|
SPI0 = &SPI{
|
||||||
Bus: stm32.SPI1,
|
Bus: stm32.SPI1,
|
||||||
AltFuncSelector: AF5_SPI1_SPI2,
|
AltFuncSelector: AF5_SPI1_SPI2,
|
||||||
}
|
}
|
||||||
SPI1 = &SPI0
|
SPI1 = SPI0
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -86,11 +86,11 @@ var (
|
|||||||
I2C0 = I2C1
|
I2C0 = I2C1
|
||||||
|
|
||||||
// SPI
|
// SPI
|
||||||
SPI0 = SPI{
|
SPI0 = &SPI{
|
||||||
Bus: stm32.SPI1,
|
Bus: stm32.SPI1,
|
||||||
AltFuncSelector: 0,
|
AltFuncSelector: 0,
|
||||||
}
|
}
|
||||||
SPI1 = &SPI0
|
SPI1 = SPI0
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ var (
|
|||||||
I2C0 = I2C1
|
I2C0 = I2C1
|
||||||
|
|
||||||
// SPI
|
// SPI
|
||||||
SPI3 = SPI{
|
SPI3 = &SPI{
|
||||||
Bus: stm32.SPI3,
|
Bus: stm32.SPI3,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ const (
|
|||||||
// Since the first interface is named SPI1, both SPI0 and SPI1 refer to SPI1.
|
// Since the first interface is named SPI1, both SPI0 and SPI1 refer to SPI1.
|
||||||
// TODO: implement SPI2 and SPI3.
|
// TODO: implement SPI2 and SPI3.
|
||||||
var (
|
var (
|
||||||
SPI0 = SPI{
|
SPI0 = &SPI{
|
||||||
Bus: stm32.SPI1,
|
Bus: stm32.SPI1,
|
||||||
AltFuncSelector: AF5_SPI1_SPI2,
|
AltFuncSelector: AF5_SPI1_SPI2,
|
||||||
}
|
}
|
||||||
SPI1 = &SPI0
|
SPI1 = SPI0
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -86,11 +86,11 @@ const (
|
|||||||
// Since the first interface is named SPI1, both SPI0 and SPI1 refer to SPI1.
|
// Since the first interface is named SPI1, both SPI0 and SPI1 refer to SPI1.
|
||||||
// TODO: implement SPI2 and SPI3.
|
// TODO: implement SPI2 and SPI3.
|
||||||
var (
|
var (
|
||||||
SPI0 = SPI{
|
SPI0 = &SPI{
|
||||||
Bus: stm32.SPI1,
|
Bus: stm32.SPI1,
|
||||||
AltFuncSelector: AF5_SPI1_SPI2,
|
AltFuncSelector: AF5_SPI1_SPI2,
|
||||||
}
|
}
|
||||||
SPI1 = &SPI0
|
SPI1 = SPI0
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -263,9 +263,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
SPI0 = SPI1 // SPI0 is an alias of SPI1 (LPSPI4)
|
SPI0 = SPI1 // SPI0 is an alias of SPI1 (LPSPI4)
|
||||||
SPI1 = &_SPI1
|
SPI1 = &SPI{
|
||||||
_SPI1 = SPI{
|
|
||||||
Bus: nxp.LPSPI4,
|
Bus: nxp.LPSPI4,
|
||||||
muxSDI: muxSelect{ // D12 (PB1 [B0_01])
|
muxSDI: muxSelect{ // D12 (PB1 [B0_01])
|
||||||
mux: nxp.IOMUXC_LPSPI4_SDI_SELECT_INPUT_DAISY_GPIO_B0_01_ALT3,
|
mux: nxp.IOMUXC_LPSPI4_SDI_SELECT_INPUT_DAISY_GPIO_B0_01_ALT3,
|
||||||
@@ -284,8 +283,7 @@ var (
|
|||||||
sel: &nxp.IOMUXC.LPSPI4_PCS0_SELECT_INPUT,
|
sel: &nxp.IOMUXC.LPSPI4_PCS0_SELECT_INPUT,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
SPI2 = &_SPI2
|
SPI2 = &SPI{
|
||||||
_SPI2 = SPI{
|
|
||||||
Bus: nxp.LPSPI3,
|
Bus: nxp.LPSPI3,
|
||||||
muxSDI: muxSelect{ // D1 (PA2 [AD_B0_02])
|
muxSDI: muxSelect{ // D1 (PA2 [AD_B0_02])
|
||||||
mux: nxp.IOMUXC_LPSPI3_SDI_SELECT_INPUT_DAISY_GPIO_AD_B0_02_ALT7,
|
mux: nxp.IOMUXC_LPSPI3_SDI_SELECT_INPUT_DAISY_GPIO_AD_B0_02_ALT7,
|
||||||
@@ -304,8 +302,7 @@ var (
|
|||||||
sel: &nxp.IOMUXC.LPSPI3_PCS0_SELECT_INPUT,
|
sel: &nxp.IOMUXC.LPSPI3_PCS0_SELECT_INPUT,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
SPI3 = &_SPI3
|
SPI3 = &SPI{
|
||||||
_SPI3 = SPI{
|
|
||||||
Bus: nxp.LPSPI1,
|
Bus: nxp.LPSPI1,
|
||||||
muxSDI: muxSelect{ // D34 (PC15 [SD_B0_03])
|
muxSDI: muxSelect{ // D34 (PC15 [SD_B0_03])
|
||||||
mux: nxp.IOMUXC_LPSPI1_SDI_SELECT_INPUT_DAISY_GPIO_SD_B0_03_ALT4,
|
mux: nxp.IOMUXC_LPSPI1_SDI_SELECT_INPUT_DAISY_GPIO_SD_B0_03_ALT4,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//go:build nrf || nrf51 || nrf52 || nrf528xx || stm32f4 || stm32l4 || stm32wlx || atsamd21 || atsamd51 || atsame5x || rp2040
|
//go:build nrf || nrf51 || nrf52 || nrf528xx || stm32f4 || stm32l4 || stm32wlx || atsamd21 || atsamd51 || atsame5x || rp2040 || rp2350
|
||||||
|
|
||||||
package machine
|
package machine
|
||||||
|
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ type SPI struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Configure is intended to setup the SPI interface.
|
// Configure is intended to setup the SPI interface.
|
||||||
func (s SPI) Configure(config SPIConfig) error {
|
func (s *SPI) Configure(config SPIConfig) error {
|
||||||
|
|
||||||
// This is only here to help catch a bug with the configuration
|
// This is only here to help catch a bug with the configuration
|
||||||
// where a machine missed a value.
|
// where a machine missed a value.
|
||||||
@@ -330,7 +330,7 @@ func (s SPI) Configure(config SPIConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Transfer writes the byte into the register and returns the read content
|
// Transfer writes the byte into the register and returns the read content
|
||||||
func (s SPI) Transfer(b byte) (byte, error) {
|
func (s *SPI) Transfer(b byte) (byte, error) {
|
||||||
s.spdr.Set(uint8(b))
|
s.spdr.Set(uint8(b))
|
||||||
|
|
||||||
for !s.spsr.HasBits(s.spsrSPIF) {
|
for !s.spsr.HasBits(s.spsrSPIF) {
|
||||||
|
|||||||
@@ -927,7 +927,7 @@ func (pwm PWM) Set(channel uint8, value uint32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SPI configuration
|
// SPI configuration
|
||||||
var SPI0 = SPI{
|
var SPI0 = &SPI{
|
||||||
spcr: avr.SPCR,
|
spcr: avr.SPCR,
|
||||||
spdr: avr.SPDR,
|
spdr: avr.SPDR,
|
||||||
spsr: avr.SPSR,
|
spsr: avr.SPSR,
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func (p Pin) getPortMask() (*volatile.Register8, uint8) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SPI configuration
|
// SPI configuration
|
||||||
var SPI0 = SPI{
|
var SPI0 = &SPI{
|
||||||
spcr: avr.SPCR,
|
spcr: avr.SPCR,
|
||||||
spsr: avr.SPSR,
|
spsr: avr.SPSR,
|
||||||
spdr: avr.SPDR,
|
spdr: avr.SPDR,
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ func (p Pin) getPortMask() (*volatile.Register8, uint8) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SPI configuration
|
// SPI configuration
|
||||||
var SPI0 = SPI{
|
var SPI0 = &SPI{
|
||||||
spcr: avr.SPCR,
|
spcr: avr.SPCR,
|
||||||
spdr: avr.SPDR,
|
spdr: avr.SPDR,
|
||||||
spsr: avr.SPSR,
|
spsr: avr.SPSR,
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ var I2C0 = &I2C{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SPI configuration
|
// SPI configuration
|
||||||
var SPI0 = SPI{
|
var SPI0 = &SPI{
|
||||||
spcr: avr.SPCR,
|
spcr: avr.SPCR,
|
||||||
spdr: avr.SPDR,
|
spdr: avr.SPDR,
|
||||||
spsr: avr.SPSR,
|
spsr: avr.SPSR,
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ var I2C1 = &I2C{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SPI configuration
|
// SPI configuration
|
||||||
var SPI0 = SPI{
|
var SPI0 = &SPI{
|
||||||
spcr: avr.SPCR0,
|
spcr: avr.SPCR0,
|
||||||
spdr: avr.SPDR0,
|
spdr: avr.SPDR0,
|
||||||
spsr: avr.SPSR0,
|
spsr: avr.SPSR0,
|
||||||
@@ -82,7 +82,7 @@ var SPI0 = SPI{
|
|||||||
cs: PB2,
|
cs: PB2,
|
||||||
}
|
}
|
||||||
|
|
||||||
var SPI1 = SPI{
|
var SPI1 = &SPI{
|
||||||
spcr: avr.SPCR1,
|
spcr: avr.SPCR1,
|
||||||
spdr: avr.SPDR1,
|
spdr: avr.SPDR1,
|
||||||
spsr: avr.SPSR1,
|
spsr: avr.SPSR1,
|
||||||
|
|||||||
@@ -1224,7 +1224,7 @@ type SPIConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Configure is intended to setup the SPI interface.
|
// Configure is intended to setup the SPI interface.
|
||||||
func (spi SPI) Configure(config SPIConfig) error {
|
func (spi *SPI) Configure(config SPIConfig) error {
|
||||||
// Use default pins if not set.
|
// Use default pins if not set.
|
||||||
if config.SCK == 0 && config.SDO == 0 && config.SDI == 0 {
|
if config.SCK == 0 && config.SDO == 0 && config.SDI == 0 {
|
||||||
config.SCK = SPI0_SCK_PIN
|
config.SCK = SPI0_SCK_PIN
|
||||||
@@ -1346,7 +1346,7 @@ func (spi SPI) Configure(config SPIConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Transfer writes/reads a single byte using the SPI interface.
|
// Transfer writes/reads a single byte using the SPI interface.
|
||||||
func (spi SPI) Transfer(w byte) (byte, error) {
|
func (spi *SPI) Transfer(w byte) (byte, error) {
|
||||||
// write data
|
// write data
|
||||||
spi.Bus.DATA.Set(uint32(w))
|
spi.Bus.DATA.Set(uint32(w))
|
||||||
|
|
||||||
@@ -1375,7 +1375,7 @@ func (spi SPI) Transfer(w byte) (byte, error) {
|
|||||||
// This form sends zeros, putting the result into the rx buffer. Good for reading a "result packet":
|
// This form sends zeros, putting the result into the rx buffer. Good for reading a "result packet":
|
||||||
//
|
//
|
||||||
// spi.Tx(nil, rx)
|
// spi.Tx(nil, rx)
|
||||||
func (spi SPI) Tx(w, r []byte) error {
|
func (spi *SPI) Tx(w, r []byte) error {
|
||||||
switch {
|
switch {
|
||||||
case w == nil:
|
case w == nil:
|
||||||
// read only, so write zero and read a result.
|
// read only, so write zero and read a result.
|
||||||
@@ -1396,7 +1396,7 @@ func (spi SPI) Tx(w, r []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (spi SPI) tx(tx []byte) {
|
func (spi *SPI) tx(tx []byte) {
|
||||||
for i := 0; i < len(tx); i++ {
|
for i := 0; i < len(tx); i++ {
|
||||||
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPI_INTFLAG_DRE) {
|
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPI_INTFLAG_DRE) {
|
||||||
}
|
}
|
||||||
@@ -1411,7 +1411,7 @@ func (spi SPI) tx(tx []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (spi SPI) rx(rx []byte) {
|
func (spi *SPI) rx(rx []byte) {
|
||||||
spi.Bus.DATA.Set(0)
|
spi.Bus.DATA.Set(0)
|
||||||
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPI_INTFLAG_DRE) {
|
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPI_INTFLAG_DRE) {
|
||||||
}
|
}
|
||||||
@@ -1427,7 +1427,7 @@ func (spi SPI) rx(rx []byte) {
|
|||||||
rx[len(rx)-1] = byte(spi.Bus.DATA.Get())
|
rx[len(rx)-1] = byte(spi.Bus.DATA.Get())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (spi SPI) txrx(tx, rx []byte) {
|
func (spi *SPI) txrx(tx, rx []byte) {
|
||||||
spi.Bus.DATA.Set(uint32(tx[0]))
|
spi.Bus.DATA.Set(uint32(tx[0]))
|
||||||
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPI_INTFLAG_DRE) {
|
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPI_INTFLAG_DRE) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ var (
|
|||||||
sercomI2CM2 = &I2C{Bus: sam.SERCOM2_I2CM, SERCOM: 2}
|
sercomI2CM2 = &I2C{Bus: sam.SERCOM2_I2CM, SERCOM: 2}
|
||||||
sercomI2CM3 = &I2C{Bus: sam.SERCOM3_I2CM, SERCOM: 3}
|
sercomI2CM3 = &I2C{Bus: sam.SERCOM3_I2CM, SERCOM: 3}
|
||||||
|
|
||||||
sercomSPIM0 = SPI{Bus: sam.SERCOM0_SPI, SERCOM: 0}
|
sercomSPIM0 = &SPI{Bus: sam.SERCOM0_SPI, SERCOM: 0}
|
||||||
sercomSPIM1 = SPI{Bus: sam.SERCOM1_SPI, SERCOM: 1}
|
sercomSPIM1 = &SPI{Bus: sam.SERCOM1_SPI, SERCOM: 1}
|
||||||
sercomSPIM2 = SPI{Bus: sam.SERCOM2_SPI, SERCOM: 2}
|
sercomSPIM2 = &SPI{Bus: sam.SERCOM2_SPI, SERCOM: 2}
|
||||||
sercomSPIM3 = SPI{Bus: sam.SERCOM3_SPI, SERCOM: 3}
|
sercomSPIM3 = &SPI{Bus: sam.SERCOM3_SPI, SERCOM: 3}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ var (
|
|||||||
sercomI2CM4 = &I2C{Bus: sam.SERCOM4_I2CM, SERCOM: 4}
|
sercomI2CM4 = &I2C{Bus: sam.SERCOM4_I2CM, SERCOM: 4}
|
||||||
sercomI2CM5 = &I2C{Bus: sam.SERCOM5_I2CM, SERCOM: 5}
|
sercomI2CM5 = &I2C{Bus: sam.SERCOM5_I2CM, SERCOM: 5}
|
||||||
|
|
||||||
sercomSPIM0 = SPI{Bus: sam.SERCOM0_SPI, SERCOM: 0}
|
sercomSPIM0 = &SPI{Bus: sam.SERCOM0_SPI, SERCOM: 0}
|
||||||
sercomSPIM1 = SPI{Bus: sam.SERCOM1_SPI, SERCOM: 1}
|
sercomSPIM1 = &SPI{Bus: sam.SERCOM1_SPI, SERCOM: 1}
|
||||||
sercomSPIM2 = SPI{Bus: sam.SERCOM2_SPI, SERCOM: 2}
|
sercomSPIM2 = &SPI{Bus: sam.SERCOM2_SPI, SERCOM: 2}
|
||||||
sercomSPIM3 = SPI{Bus: sam.SERCOM3_SPI, SERCOM: 3}
|
sercomSPIM3 = &SPI{Bus: sam.SERCOM3_SPI, SERCOM: 3}
|
||||||
sercomSPIM4 = SPI{Bus: sam.SERCOM4_SPI, SERCOM: 4}
|
sercomSPIM4 = &SPI{Bus: sam.SERCOM4_SPI, SERCOM: 4}
|
||||||
sercomSPIM5 = SPI{Bus: sam.SERCOM5_SPI, SERCOM: 5}
|
sercomSPIM5 = &SPI{Bus: sam.SERCOM5_SPI, SERCOM: 5}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -1431,7 +1431,7 @@ type SPIConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Configure is intended to setup the SPI interface.
|
// Configure is intended to setup the SPI interface.
|
||||||
func (spi SPI) Configure(config SPIConfig) error {
|
func (spi *SPI) Configure(config SPIConfig) error {
|
||||||
// Use default pins if not set.
|
// Use default pins if not set.
|
||||||
if config.SCK == 0 && config.SDO == 0 && config.SDI == 0 {
|
if config.SCK == 0 && config.SDO == 0 && config.SDI == 0 {
|
||||||
config.SCK = SPI0_SCK_PIN
|
config.SCK = SPI0_SCK_PIN
|
||||||
@@ -1574,7 +1574,7 @@ func (spi SPI) Configure(config SPIConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Transfer writes/reads a single byte using the SPI interface.
|
// Transfer writes/reads a single byte using the SPI interface.
|
||||||
func (spi SPI) Transfer(w byte) (byte, error) {
|
func (spi *SPI) Transfer(w byte) (byte, error) {
|
||||||
// write data
|
// write data
|
||||||
spi.Bus.DATA.Set(uint32(w))
|
spi.Bus.DATA.Set(uint32(w))
|
||||||
|
|
||||||
@@ -1603,7 +1603,7 @@ func (spi SPI) Transfer(w byte) (byte, error) {
|
|||||||
// This form sends zeros, putting the result into the rx buffer. Good for reading a "result packet":
|
// This form sends zeros, putting the result into the rx buffer. Good for reading a "result packet":
|
||||||
//
|
//
|
||||||
// spi.Tx(nil, rx)
|
// spi.Tx(nil, rx)
|
||||||
func (spi SPI) Tx(w, r []byte) error {
|
func (spi *SPI) Tx(w, r []byte) error {
|
||||||
switch {
|
switch {
|
||||||
case w == nil:
|
case w == nil:
|
||||||
// read only, so write zero and read a result.
|
// read only, so write zero and read a result.
|
||||||
@@ -1624,7 +1624,7 @@ func (spi SPI) Tx(w, r []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (spi SPI) tx(tx []byte) {
|
func (spi *SPI) tx(tx []byte) {
|
||||||
for i := 0; i < len(tx); i++ {
|
for i := 0; i < len(tx); i++ {
|
||||||
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPIM_INTFLAG_DRE) {
|
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPIM_INTFLAG_DRE) {
|
||||||
}
|
}
|
||||||
@@ -1639,7 +1639,7 @@ func (spi SPI) tx(tx []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (spi SPI) rx(rx []byte) {
|
func (spi *SPI) rx(rx []byte) {
|
||||||
spi.Bus.DATA.Set(0)
|
spi.Bus.DATA.Set(0)
|
||||||
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPIM_INTFLAG_DRE) {
|
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPIM_INTFLAG_DRE) {
|
||||||
}
|
}
|
||||||
@@ -1655,7 +1655,7 @@ func (spi SPI) rx(rx []byte) {
|
|||||||
rx[len(rx)-1] = byte(spi.Bus.DATA.Get())
|
rx[len(rx)-1] = byte(spi.Bus.DATA.Get())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (spi SPI) txrx(tx, rx []byte) {
|
func (spi *SPI) txrx(tx, rx []byte) {
|
||||||
spi.Bus.DATA.Set(uint32(tx[0]))
|
spi.Bus.DATA.Set(uint32(tx[0]))
|
||||||
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPIM_INTFLAG_DRE) {
|
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPIM_INTFLAG_DRE) {
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user