mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-27 23:28:42 +00:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 14b96f6f68 | |||
| b5626e70cb | |||
| c201faab92 | |||
| 2e47a9c5cd | |||
| e13d4ba3d0 | |||
| 9dcb63ca98 | |||
| 78ddc51471 | |||
| c931bc7394 | |||
| 1f3e0004a9 | |||
| d4cb92f27c | |||
| ee5bc65c97 | |||
| 4f1b69827d | |||
| 73f519b589 | |||
| 25abfff632 | |||
| e39358d0ee | |||
| 105fe9b25d | |||
| 753f4b38b4 | |||
| d144b11611 | |||
| 1ef1aa7862 | |||
| 83c98a23ce | |||
| 336b9b33ab |
@@ -20,6 +20,8 @@ src/device/stm32/*.go
|
||||
src/device/stm32/*.s
|
||||
src/device/kendryte/*.go
|
||||
src/device/kendryte/*.s
|
||||
src/device/renesas/*.go
|
||||
src/device/renesas/*.s
|
||||
src/device/rp/*.go
|
||||
src/device/rp/*.s
|
||||
./vendor
|
||||
|
||||
@@ -32,9 +32,6 @@
|
||||
[submodule "lib/macos-minimal-sdk"]
|
||||
path = lib/macos-minimal-sdk
|
||||
url = https://github.com/aykevl/macos-minimal-sdk.git
|
||||
[submodule "lib/renesas-svd"]
|
||||
path = lib/renesas-svd
|
||||
url = https://github.com/tinygo-org/renesas-svd.git
|
||||
[submodule "src/net"]
|
||||
path = src/net
|
||||
url = https://github.com/tinygo-org/net.git
|
||||
|
||||
+33
-3
@@ -185,7 +185,7 @@ fmt-check: ## Warn if any source needs reformatting
|
||||
@unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1
|
||||
|
||||
|
||||
gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp gen-device-rp ## Generate microcontroller-specific sources
|
||||
gen-device: gen-device-avr gen-device-esp gen-device-nrf gen-device-sam gen-device-sifive gen-device-kendryte gen-device-nxp gen-device-rp gen-device-renesas ## Generate microcontroller-specific sources
|
||||
ifneq ($(STM32), 0)
|
||||
gen-device: gen-device-stm32
|
||||
endif
|
||||
@@ -234,7 +234,7 @@ gen-device-rp: build/gen-device-svd
|
||||
GO111MODULE=off $(GO) fmt ./src/device/rp
|
||||
|
||||
gen-device-renesas: build/gen-device-svd
|
||||
./build/gen-device-svd -source=https://github.com/tinygo-org/renesas-svd lib/renesas-svd/ src/device/renesas/
|
||||
./build/gen-device-svd -source=https://github.com/cmsis-svd/cmsis-svd-data/tree/master/data/Renesas lib/cmsis-svd/data/Renesas/ src/device/renesas/
|
||||
GO111MODULE=off $(GO) fmt ./src/device/renesas
|
||||
|
||||
$(LLVM_PROJECTDIR)/llvm:
|
||||
@@ -267,7 +267,7 @@ 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)
|
||||
|
||||
# Generate WASI syscall bindings
|
||||
WASM_TOOLS_MODULE=github.com/ydnar/wasm-tools-go
|
||||
WASM_TOOLS_MODULE=github.com/bytecodealliance/wasm-tools-go
|
||||
.PHONY: wasi-syscall
|
||||
wasi-syscall: wasi-cm
|
||||
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
|
||||
@@ -299,30 +299,39 @@ test: wasi-libc check-nodejs-version
|
||||
TEST_PACKAGES_SLOW = \
|
||||
compress/bzip2 \
|
||||
crypto/dsa \
|
||||
crypto/ecdsa \
|
||||
index/suffixarray \
|
||||
|
||||
# Standard library packages that pass tests quickly on darwin, linux, wasi, and windows
|
||||
TEST_PACKAGES_FAST = \
|
||||
cmp \
|
||||
compress/lzw \
|
||||
compress/zlib \
|
||||
container/heap \
|
||||
container/list \
|
||||
container/ring \
|
||||
crypto/des \
|
||||
crypto/elliptic \
|
||||
crypto/md5 \
|
||||
crypto/rc4 \
|
||||
crypto/sha1 \
|
||||
crypto/sha256 \
|
||||
crypto/sha512 \
|
||||
database/sql/driver \
|
||||
debug/macho \
|
||||
embed \
|
||||
embed/internal/embedtest \
|
||||
encoding \
|
||||
encoding/ascii85 \
|
||||
encoding/asn1 \
|
||||
encoding/base32 \
|
||||
encoding/base64 \
|
||||
encoding/csv \
|
||||
encoding/hex \
|
||||
go/ast \
|
||||
go/format \
|
||||
go/scanner \
|
||||
go/version \
|
||||
hash \
|
||||
hash/adler32 \
|
||||
hash/crc64 \
|
||||
@@ -334,6 +343,7 @@ TEST_PACKAGES_FAST = \
|
||||
math/cmplx \
|
||||
net/http/internal/ascii \
|
||||
net/mail \
|
||||
net/textproto \
|
||||
os \
|
||||
path \
|
||||
reflect \
|
||||
@@ -357,11 +367,17 @@ endif
|
||||
# archive/zip requires os.ReadAt, which is not yet supported on windows
|
||||
# bytes requires mmap
|
||||
# compress/flate appears to hang on wasi
|
||||
# context requires recover(), which is not yet supported on wasi
|
||||
# crypto/aes requires recover(), which is not yet supported on wasi
|
||||
# crypto/hmac fails on wasi, it exits with a "slice out of range" panic
|
||||
# debug/plan9obj requires os.ReadAt, which is not yet supported on windows
|
||||
# go/build/constraint requires recover(), which is not yet supported on wasi
|
||||
# image requires recover(), which is not yet supported on wasi
|
||||
# io/ioutil requires os.ReadDir, which is not yet supported on windows or wasi
|
||||
# mime exits with "bufio.Scanner: Read returned impossible count" on wasi
|
||||
# mime/multipart has a nil pointer dereference (stack overflow?)
|
||||
# mime/quotedprintable requires syscall.Faccessat
|
||||
# regexp/syntax requires recover() which is not yet supported on wasi
|
||||
# strconv requires recover() which is not yet supported on wasi
|
||||
# text/tabwriter requires recover(), which is not yet supported on wasi
|
||||
# text/template/parse requires recover(), which is not yet supported on wasi
|
||||
@@ -371,14 +387,20 @@ endif
|
||||
TEST_PACKAGES_LINUX := \
|
||||
archive/zip \
|
||||
compress/flate \
|
||||
context \
|
||||
crypto/aes \
|
||||
crypto/hmac \
|
||||
debug/dwarf \
|
||||
debug/plan9obj \
|
||||
go/build/constraint \
|
||||
image \
|
||||
io/ioutil \
|
||||
mime \
|
||||
mime/multipart \
|
||||
mime/quotedprintable \
|
||||
net \
|
||||
os/user \
|
||||
regexp/syntax \
|
||||
strconv \
|
||||
text/tabwriter \
|
||||
text/template/parse
|
||||
@@ -387,8 +409,14 @@ TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX)
|
||||
|
||||
TEST_PACKAGES_WINDOWS := \
|
||||
compress/flate \
|
||||
context \
|
||||
crypto/aes \
|
||||
crypto/hmac \
|
||||
go/build/constraint \
|
||||
mime \
|
||||
mime/multipart \
|
||||
os/user \
|
||||
regexp/syntax \
|
||||
strconv \
|
||||
text/template/parse \
|
||||
$(nil)
|
||||
@@ -642,6 +670,8 @@ endif
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=xiao examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=rak4631 examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/dac
|
||||
@$(MD5SUM) test.hex
|
||||
$(TINYGO) build -size short -o test.hex -target=pyportal examples/dac
|
||||
|
||||
@@ -336,19 +336,19 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
||||
spec.Features = "+fp-armv8,+neon,-fmv,-outline-atomics"
|
||||
}
|
||||
case "mips", "mipsle":
|
||||
spec.CPU = "mips32r2"
|
||||
spec.CPU = "mips32"
|
||||
spec.CFlags = append(spec.CFlags, "-fno-pic")
|
||||
if options.GOOS == "mips" {
|
||||
if options.GOARCH == "mips" {
|
||||
llvmarch = "mips" // big endian
|
||||
} else {
|
||||
llvmarch = "mipsel" // little endian
|
||||
}
|
||||
switch options.GOMIPS {
|
||||
case "hardfloat":
|
||||
spec.Features = "+fpxx,+mips32r2,+nooddspreg,-noabicalls"
|
||||
spec.Features = "+fpxx,+mips32,+nooddspreg,-noabicalls"
|
||||
case "softfloat":
|
||||
spec.SoftFloat = true
|
||||
spec.Features = "+mips32r2,+soft-float,-noabicalls"
|
||||
spec.Features = "+mips32,+soft-float,-noabicalls"
|
||||
spec.CFlags = append(spec.CFlags, "-msoft-float")
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid GOMIPS=%s: must be hardfloat or softfloat", options.GOMIPS)
|
||||
@@ -389,6 +389,7 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
||||
"-platform_version", "macos", platformVersion, platformVersion,
|
||||
)
|
||||
spec.ExtraFiles = append(spec.ExtraFiles,
|
||||
"src/runtime/os_darwin.c",
|
||||
"src/runtime/runtime_unix.c")
|
||||
case "linux":
|
||||
spec.Linker = "ld.lld"
|
||||
|
||||
@@ -1847,7 +1847,9 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error)
|
||||
case strings.HasPrefix(name, "(device/riscv.CSR)."):
|
||||
return b.emitCSROperation(instr)
|
||||
case strings.HasPrefix(name, "syscall.Syscall") || strings.HasPrefix(name, "syscall.RawSyscall") || strings.HasPrefix(name, "golang.org/x/sys/unix.Syscall") || strings.HasPrefix(name, "golang.org/x/sys/unix.RawSyscall"):
|
||||
return b.createSyscall(instr)
|
||||
if b.GOOS != "darwin" {
|
||||
return b.createSyscall(instr)
|
||||
}
|
||||
case strings.HasPrefix(name, "syscall.rawSyscallNoError") || strings.HasPrefix(name, "golang.org/x/sys/unix.RawSyscallNoError"):
|
||||
return b.createRawSyscallNoError(instr)
|
||||
case name == "runtime.supportsRecover":
|
||||
@@ -1865,6 +1867,11 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error)
|
||||
return llvm.ConstInt(b.ctx.Int8Type(), panicStrategy, false), nil
|
||||
case name == "runtime/interrupt.New":
|
||||
return b.createInterruptGlobal(instr)
|
||||
case name == "internal/abi.FuncPCABI0":
|
||||
retval := b.createDarwinFuncPCABI0Call(instr)
|
||||
if !retval.IsNil() {
|
||||
return retval, nil
|
||||
}
|
||||
}
|
||||
|
||||
calleeType, callee = b.getFunction(fn)
|
||||
|
||||
+8
-1
@@ -16,6 +16,7 @@ package compiler
|
||||
import (
|
||||
"go/types"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/tinygo-org/tinygo/compiler/llvmutil"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
@@ -198,7 +199,13 @@ jal 1f
|
||||
addiu $$ra, 8
|
||||
sw $$ra, 4($$5)
|
||||
.set at`
|
||||
constraints = "={$4},{$5},~{$1},~{$2},~{$3},~{$5},~{$6},~{$7},~{$8},~{$9},~{$10},~{$11},~{$12},~{$13},~{$14},~{$15},~{$16},~{$17},~{$18},~{$19},~{$20},~{$21},~{$22},~{$23},~{$24},~{$25},~{$26},~{$27},~{$28},~{$29},~{$30},~{$31},~{$f0},~{$f1},~{$f2},~{$f3},~{$f4},~{$f5},~{$f6},~{$f7},~{$f8},~{$f9},~{$f10},~{$f11},~{$f12},~{$f13},~{$f14},~{$f15},~{$f16},~{$f17},~{$f18},~{$f19},~{$f20},~{$f21},~{$f22},~{$f23},~{$f24},~{$f25},~{$f26},~{$f27},~{$f28},~{$f29},~{$f30},~{$f31},~{memory}"
|
||||
constraints = "={$4},{$5},~{$1},~{$2},~{$3},~{$5},~{$6},~{$7},~{$8},~{$9},~{$10},~{$11},~{$12},~{$13},~{$14},~{$15},~{$16},~{$17},~{$18},~{$19},~{$20},~{$21},~{$22},~{$23},~{$24},~{$25},~{$26},~{$27},~{$28},~{$29},~{$30},~{$31},~{memory}"
|
||||
if !strings.Contains(b.Features, "+soft-float") {
|
||||
// Using floating point registers together with GOMIPS=softfloat
|
||||
// results in a crash: "This value type is not natively supported!"
|
||||
// So only add them when using hardfloat.
|
||||
constraints += ",~{$f0},~{$f1},~{$f2},~{$f3},~{$f4},~{$f5},~{$f6},~{$f7},~{$f8},~{$f9},~{$f10},~{$f11},~{$f12},~{$f13},~{$f14},~{$f15},~{$f16},~{$f17},~{$f18},~{$f19},~{$f20},~{$f21},~{$f22},~{$f23},~{$f24},~{$f25},~{$f26},~{$f27},~{$f28},~{$f29},~{$f30},~{$f31}"
|
||||
}
|
||||
case "riscv32":
|
||||
asmString = `
|
||||
la a2, 1f
|
||||
|
||||
+33
-31
@@ -13,37 +13,7 @@ import (
|
||||
|
||||
// createGo emits code to start a new goroutine.
|
||||
func (b *builder) createGo(instr *ssa.Go) {
|
||||
// Get all function parameters to pass to the goroutine.
|
||||
var params []llvm.Value
|
||||
for _, param := range instr.Call.Args {
|
||||
params = append(params, b.getValue(param, getPos(instr)))
|
||||
}
|
||||
|
||||
var prefix string
|
||||
var funcPtr llvm.Value
|
||||
var funcType llvm.Type
|
||||
hasContext := false
|
||||
if callee := instr.Call.StaticCallee(); callee != nil {
|
||||
// Static callee is known. This makes it easier to start a new
|
||||
// goroutine.
|
||||
var context llvm.Value
|
||||
switch value := instr.Call.Value.(type) {
|
||||
case *ssa.Function:
|
||||
// Goroutine call is regular function call. No context is necessary.
|
||||
case *ssa.MakeClosure:
|
||||
// A goroutine call on a func value, but the callee is trivial to find. For
|
||||
// example: immediately applied functions.
|
||||
funcValue := b.getValue(value, getPos(instr))
|
||||
context = b.extractFuncContext(funcValue)
|
||||
default:
|
||||
panic("StaticCallee returned an unexpected value")
|
||||
}
|
||||
if !context.IsNil() {
|
||||
params = append(params, context) // context parameter
|
||||
hasContext = true
|
||||
}
|
||||
funcType, funcPtr = b.getFunction(callee)
|
||||
} else if builtin, ok := instr.Call.Value.(*ssa.Builtin); ok {
|
||||
if builtin, ok := instr.Call.Value.(*ssa.Builtin); ok {
|
||||
// We cheat. None of the builtins do any long or blocking operation, so
|
||||
// we might as well run these builtins right away without the program
|
||||
// noticing the difference.
|
||||
@@ -74,6 +44,38 @@ func (b *builder) createGo(instr *ssa.Go) {
|
||||
}
|
||||
b.createBuiltin(argTypes, argValues, builtin.Name(), instr.Pos())
|
||||
return
|
||||
}
|
||||
|
||||
// Get all function parameters to pass to the goroutine.
|
||||
var params []llvm.Value
|
||||
for _, param := range instr.Call.Args {
|
||||
params = append(params, b.expandFormalParam(b.getValue(param, getPos(instr)))...)
|
||||
}
|
||||
|
||||
var prefix string
|
||||
var funcPtr llvm.Value
|
||||
var funcType llvm.Type
|
||||
hasContext := false
|
||||
if callee := instr.Call.StaticCallee(); callee != nil {
|
||||
// Static callee is known. This makes it easier to start a new
|
||||
// goroutine.
|
||||
var context llvm.Value
|
||||
switch value := instr.Call.Value.(type) {
|
||||
case *ssa.Function:
|
||||
// Goroutine call is regular function call. No context is necessary.
|
||||
case *ssa.MakeClosure:
|
||||
// A goroutine call on a func value, but the callee is trivial to find. For
|
||||
// example: immediately applied functions.
|
||||
funcValue := b.getValue(value, getPos(instr))
|
||||
context = b.extractFuncContext(funcValue)
|
||||
default:
|
||||
panic("StaticCallee returned an unexpected value")
|
||||
}
|
||||
if !context.IsNil() {
|
||||
params = append(params, context) // context parameter
|
||||
hasContext = true
|
||||
}
|
||||
funcType, funcPtr = b.getFunction(callee)
|
||||
} else if instr.Call.IsInvoke() {
|
||||
// This is a method call on an interface value.
|
||||
itf := b.getValue(instr.Call.Value, getPos(instr))
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package llvmutil
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -216,3 +217,13 @@ func Version() int {
|
||||
}
|
||||
return major
|
||||
}
|
||||
|
||||
// Return the byte order for the given target triple. Most targets are little
|
||||
// endian, but for example MIPS can be big-endian.
|
||||
func ByteOrder(target string) binary.ByteOrder {
|
||||
if strings.HasPrefix(target, "mips-") {
|
||||
return binary.BigEndian
|
||||
} else {
|
||||
return binary.LittleEndian
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package compiler
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/go/ssa"
|
||||
"tinygo.org/x/go-llvm"
|
||||
@@ -329,3 +330,64 @@ func (b *builder) createRawSyscallNoError(call *ssa.CallCommon) (llvm.Value, err
|
||||
retval = b.CreateInsertValue(retval, llvm.ConstInt(b.uintptrType, 0, false), 1, "")
|
||||
return retval, nil
|
||||
}
|
||||
|
||||
// Lower a call to internal/abi.FuncPCABI0 on MacOS.
|
||||
// This function is called like this:
|
||||
//
|
||||
// syscall(abi.FuncPCABI0(libc_mkdir_trampoline), uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
|
||||
//
|
||||
// So we'll want to return a function pointer (as uintptr) that points to the
|
||||
// libc function. Specifically, we _don't_ want to point to the trampoline
|
||||
// function (which is implemented in Go assembly which we can't read), but
|
||||
// rather to the actually intended function. For this we're going to assume that
|
||||
// all the functions follow a specific pattern: libc_<functionname>_trampoline.
|
||||
//
|
||||
// The return value is the function pointer as an uintptr, or a nil value if
|
||||
// this isn't possible (and a regular call should be made as fallback).
|
||||
func (b *builder) createDarwinFuncPCABI0Call(instr *ssa.CallCommon) llvm.Value {
|
||||
if b.GOOS != "darwin" {
|
||||
// This has only been tested on MacOS (and only seems to be used there).
|
||||
return llvm.Value{}
|
||||
}
|
||||
|
||||
// Check that it uses a function call like syscall.libc_*_trampoline
|
||||
itf := instr.Args[0].(*ssa.MakeInterface)
|
||||
calledFn := itf.X.(*ssa.Function)
|
||||
if pkgName := calledFn.Pkg.Pkg.Path(); pkgName != "syscall" && pkgName != "internal/syscall/unix" {
|
||||
return llvm.Value{}
|
||||
}
|
||||
if !strings.HasPrefix(calledFn.Name(), "libc_") || !strings.HasSuffix(calledFn.Name(), "_trampoline") {
|
||||
|
||||
return llvm.Value{}
|
||||
}
|
||||
|
||||
// Extract the libc function name.
|
||||
name := strings.TrimPrefix(strings.TrimSuffix(calledFn.Name(), "_trampoline"), "libc_")
|
||||
if name == "open" {
|
||||
// Special case: open() is a variadic function and can't be called like
|
||||
// a regular function. Therefore, we need to use a wrapper implemented
|
||||
// in C.
|
||||
name = "syscall_libc_open"
|
||||
}
|
||||
if b.GOARCH == "amd64" {
|
||||
if name == "fdopendir" || name == "readdir_r" {
|
||||
// Hack to support amd64, which needs the $INODE64 suffix.
|
||||
// This is also done in upstream Go:
|
||||
// https://github.com/golang/go/commit/096ab3c21b88ccc7d411379d09fe6274e3159467
|
||||
name += "$INODE64"
|
||||
}
|
||||
}
|
||||
|
||||
// Obtain the C function.
|
||||
// Use a simple function (no parameters or return value) because all we need
|
||||
// is the address of the function.
|
||||
llvmFn := b.mod.NamedFunction(name)
|
||||
if llvmFn.IsNil() {
|
||||
llvmFnType := llvm.FunctionType(b.ctx.VoidType(), nil, false)
|
||||
llvmFn = llvm.AddFunction(b.mod, name, llvmFnType)
|
||||
}
|
||||
|
||||
// Cast the function pointer to a uintptr (because that's what
|
||||
// abi.FuncPCABI0 returns).
|
||||
return b.CreatePtrToInt(llvmFn, b.uintptrType, "")
|
||||
}
|
||||
|
||||
+5
-7
@@ -3,8 +3,6 @@ source_filename = "goroutine.go"
|
||||
target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
|
||||
target triple = "thumbv7m-unknown-unknown-eabi"
|
||||
|
||||
%runtime._string = type { ptr, i32 }
|
||||
|
||||
@"main$string" = internal unnamed_addr constant [4 x i8] c"test", align 1
|
||||
|
||||
; Function Attrs: allockind("alloc,zeroed") allocsize(0)
|
||||
@@ -150,12 +148,12 @@ define hidden void @main.startInterfaceMethod(ptr %itf.typecode, ptr %itf.value,
|
||||
entry:
|
||||
%0 = call align 4 dereferenceable(16) ptr @runtime.alloc(i32 16, ptr null, ptr undef) #9
|
||||
store ptr %itf.value, ptr %0, align 4
|
||||
%1 = getelementptr inbounds { ptr, %runtime._string, ptr }, ptr %0, i32 0, i32 1
|
||||
%1 = getelementptr inbounds { ptr, ptr, i32, ptr }, ptr %0, i32 0, i32 1
|
||||
store ptr @"main$string", ptr %1, align 4
|
||||
%.repack1 = getelementptr inbounds { ptr, %runtime._string, ptr }, ptr %0, i32 0, i32 1, i32 1
|
||||
store i32 4, ptr %.repack1, align 4
|
||||
%2 = getelementptr inbounds { ptr, %runtime._string, ptr }, ptr %0, i32 0, i32 2
|
||||
store ptr %itf.typecode, ptr %2, align 4
|
||||
%2 = getelementptr inbounds { ptr, ptr, i32, ptr }, ptr %0, i32 0, i32 2
|
||||
store i32 4, ptr %2, align 4
|
||||
%3 = getelementptr inbounds { ptr, ptr, i32, ptr }, ptr %0, i32 0, i32 3
|
||||
store ptr %itf.typecode, ptr %3, align 4
|
||||
%stacksize = call i32 @"internal/task.getGoroutineStackSize"(i32 ptrtoint (ptr @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), ptr undef) #9
|
||||
call void @"internal/task.start"(i32 ptrtoint (ptr @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), ptr nonnull %0, i32 %stacksize, ptr undef) #9
|
||||
ret void
|
||||
|
||||
+5
-7
@@ -3,8 +3,6 @@ source_filename = "goroutine.go"
|
||||
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
|
||||
target triple = "wasm32-unknown-wasi"
|
||||
|
||||
%runtime._string = type { ptr, i32 }
|
||||
|
||||
@"main$string" = internal unnamed_addr constant [4 x i8] c"test", align 1
|
||||
|
||||
; Function Attrs: allockind("alloc,zeroed") allocsize(0)
|
||||
@@ -161,12 +159,12 @@ entry:
|
||||
%0 = call align 4 dereferenceable(16) ptr @runtime.alloc(i32 16, ptr null, ptr undef) #9
|
||||
call void @runtime.trackPointer(ptr nonnull %0, ptr nonnull %stackalloc, ptr undef) #9
|
||||
store ptr %itf.value, ptr %0, align 4
|
||||
%1 = getelementptr inbounds { ptr, %runtime._string, ptr }, ptr %0, i32 0, i32 1
|
||||
%1 = getelementptr inbounds { ptr, ptr, i32, ptr }, ptr %0, i32 0, i32 1
|
||||
store ptr @"main$string", ptr %1, align 4
|
||||
%.repack1 = getelementptr inbounds { ptr, %runtime._string, ptr }, ptr %0, i32 0, i32 1, i32 1
|
||||
store i32 4, ptr %.repack1, align 4
|
||||
%2 = getelementptr inbounds { ptr, %runtime._string, ptr }, ptr %0, i32 0, i32 2
|
||||
store ptr %itf.typecode, ptr %2, align 4
|
||||
%2 = getelementptr inbounds { ptr, ptr, i32, ptr }, ptr %0, i32 0, i32 2
|
||||
store i32 4, ptr %2, align 4
|
||||
%3 = getelementptr inbounds { ptr, ptr, i32, ptr }, ptr %0, i32 0, i32 3
|
||||
store ptr %itf.typecode, ptr %3, align 4
|
||||
call void @"internal/task.start"(i32 ptrtoint (ptr @"interface:{Print:func:{basic:string}{}}.Print$invoke$gowrapper" to i32), ptr nonnull %0, i32 65536, ptr undef) #9
|
||||
ret void
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// Version of TinyGo.
|
||||
// Update this value before release of new version of software.
|
||||
const version = "0.33.0"
|
||||
const version = "0.34.0-dev"
|
||||
|
||||
var (
|
||||
// This variable is set at build time using -ldflags parameters.
|
||||
|
||||
@@ -2,11 +2,11 @@ module github.com/tinygo-org/tinygo/internal/tools
|
||||
|
||||
go 1.22.4
|
||||
|
||||
require github.com/ydnar/wasm-tools-go v0.1.4
|
||||
require github.com/bytecodealliance/wasm-tools-go v0.2.0
|
||||
|
||||
require (
|
||||
github.com/coreos/go-semver v0.3.1 // indirect
|
||||
github.com/urfave/cli/v3 v3.0.0-alpha9 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
golang.org/x/mod v0.19.0 // indirect
|
||||
golang.org/x/mod v0.21.0 // indirect
|
||||
)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
github.com/bytecodealliance/wasm-tools-go v0.2.0 h1:JdmiZew7ewHjf+ZGGRE4gZM85Ad/PGW/5I57hepEOjQ=
|
||||
github.com/bytecodealliance/wasm-tools-go v0.2.0/go.mod h1:2GnJCUlcDrslZ/L6+yYqoUnewDlBvqRS2N/0NW9ro6w=
|
||||
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/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
@@ -12,14 +14,12 @@ github.com/urfave/cli/v3 v3.0.0-alpha9 h1:P0RMy5fQm1AslQS+XCmy9UknDXctOmG/q/FZkU
|
||||
github.com/urfave/cli/v3 v3.0.0-alpha9/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
github.com/ydnar/wasm-tools-go v0.1.4 h1:+25WqBj0AhLx8OFvZvrs7bQO6L3WtQ7t6JzQEYsXQb8=
|
||||
github.com/ydnar/wasm-tools-go v0.1.4/go.mod h1:lQfv2Tde3tRgZDSYriro0EmdSHzP1mrHPMmYNahSS/g=
|
||||
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
|
||||
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
|
||||
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
|
||||
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
|
||||
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
|
||||
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
_ "github.com/ydnar/wasm-tools-go/cmd/wit-bindgen-go"
|
||||
_ "github.com/bytecodealliance/wasm-tools-go/cmd/wit-bindgen-go"
|
||||
)
|
||||
|
||||
//go:generate go install github.com/ydnar/wasm-tools-go/cmd/wit-bindgen-go
|
||||
//go:generate go install github.com/bytecodealliance/wasm-tools-go/cmd/wit-bindgen-go
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
package interp
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/tinygo-org/tinygo/compiler/llvmutil"
|
||||
"tinygo.org/x/go-llvm"
|
||||
)
|
||||
|
||||
@@ -24,6 +26,7 @@ type runner struct {
|
||||
dataPtrType llvm.Type // often used type so created in advance
|
||||
uintptrType llvm.Type // equivalent to uintptr in Go
|
||||
maxAlign int // maximum alignment of an object, alignment of runtime.alloc() result
|
||||
byteOrder binary.ByteOrder // big-endian or little-endian
|
||||
debug bool // log debug messages
|
||||
pkgName string // package name of the currently executing package
|
||||
functionCache map[llvm.Value]*function // cache of compiled functions
|
||||
@@ -38,6 +41,7 @@ func newRunner(mod llvm.Module, timeout time.Duration, debug bool) *runner {
|
||||
r := runner{
|
||||
mod: mod,
|
||||
targetData: llvm.NewTargetData(mod.DataLayout()),
|
||||
byteOrder: llvmutil.ByteOrder(mod.Target()),
|
||||
debug: debug,
|
||||
functionCache: make(map[llvm.Value]*function),
|
||||
objects: []object{{}},
|
||||
|
||||
+49
-49
@@ -173,7 +173,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
case 3:
|
||||
// Conditional branch: [cond, thenBB, elseBB]
|
||||
lastBB = currentBB
|
||||
switch operands[0].Uint() {
|
||||
switch operands[0].Uint(r) {
|
||||
case 1: // true -> thenBB
|
||||
currentBB = int(operands[1].(literalValue).value.(uint32))
|
||||
case 0: // false -> elseBB
|
||||
@@ -191,12 +191,12 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
}
|
||||
case llvm.Switch:
|
||||
// Switch statement: [value, defaultLabel, case0, label0, case1, label1, ...]
|
||||
value := operands[0].Uint()
|
||||
targetLabel := operands[1].Uint() // default label
|
||||
value := operands[0].Uint(r)
|
||||
targetLabel := operands[1].Uint(r) // default label
|
||||
// Do a lazy switch by iterating over all cases.
|
||||
for i := 2; i < len(operands); i += 2 {
|
||||
if value == operands[i].Uint() {
|
||||
targetLabel = operands[i+1].Uint()
|
||||
if value == operands[i].Uint(r) {
|
||||
targetLabel = operands[i+1].Uint(r)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
// Select is much like a ternary operator: it picks a result from
|
||||
// the second and third operand based on the boolean first operand.
|
||||
var result value
|
||||
switch operands[0].Uint() {
|
||||
switch operands[0].Uint(r) {
|
||||
case 1:
|
||||
result = operands[1]
|
||||
case 0:
|
||||
@@ -282,7 +282,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
// by creating a global variable.
|
||||
|
||||
// Get the requested memory size to be allocated.
|
||||
size := operands[1].Uint()
|
||||
size := operands[1].Uint(r)
|
||||
|
||||
// Get the object layout, if it is available.
|
||||
llvmLayoutType := r.getLLVMTypeFromLayout(operands[2])
|
||||
@@ -318,9 +318,9 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
// memmove(dst, src, n*elemSize)
|
||||
// return int(n)
|
||||
// }
|
||||
dstLen := operands[3].Uint()
|
||||
srcLen := operands[4].Uint()
|
||||
elemSize := operands[5].Uint()
|
||||
dstLen := operands[3].Uint(r)
|
||||
srcLen := operands[4].Uint(r)
|
||||
elemSize := operands[5].Uint(r)
|
||||
n := srcLen
|
||||
if n > dstLen {
|
||||
n = dstLen
|
||||
@@ -374,7 +374,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
if err != nil {
|
||||
return nil, mem, r.errorAt(inst, err)
|
||||
}
|
||||
nBytes := uint32(operands[3].Uint())
|
||||
nBytes := uint32(operands[3].Uint(r))
|
||||
dstObj := mem.getWritable(dst.index())
|
||||
dstBuf := dstObj.buffer.asRawValue(r)
|
||||
if mem.get(src.index()).buffer == nil {
|
||||
@@ -661,8 +661,8 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
// pointer into the underlying object.
|
||||
var offset int64
|
||||
for i := 1; i < len(operands); i += 2 {
|
||||
index := operands[i].Int()
|
||||
elementSize := operands[i+1].Int()
|
||||
index := operands[i].Int(r)
|
||||
elementSize := operands[i+1].Int(r)
|
||||
if elementSize < 0 {
|
||||
// This is a struct field.
|
||||
offset += index
|
||||
@@ -677,7 +677,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
return nil, mem, r.errorAt(inst, err)
|
||||
}
|
||||
// GEP on fixed pointer value (for example, memory-mapped I/O).
|
||||
ptrValue := operands[0].Uint() + uint64(offset)
|
||||
ptrValue := operands[0].Uint(r) + uint64(offset)
|
||||
locals[inst.localIndex] = makeLiteralInt(ptrValue, int(operands[0].len(r)*8))
|
||||
continue
|
||||
}
|
||||
@@ -739,11 +739,11 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
var lhs, rhs float64
|
||||
switch operands[0].len(r) {
|
||||
case 8:
|
||||
lhs = math.Float64frombits(operands[0].Uint())
|
||||
rhs = math.Float64frombits(operands[1].Uint())
|
||||
lhs = math.Float64frombits(operands[0].Uint(r))
|
||||
rhs = math.Float64frombits(operands[1].Uint(r))
|
||||
case 4:
|
||||
lhs = float64(math.Float32frombits(uint32(operands[0].Uint())))
|
||||
rhs = float64(math.Float32frombits(uint32(operands[1].Uint())))
|
||||
lhs = float64(math.Float32frombits(uint32(operands[0].Uint(r))))
|
||||
rhs = float64(math.Float32frombits(uint32(operands[1].Uint(r))))
|
||||
default:
|
||||
panic("unknown float type")
|
||||
}
|
||||
@@ -782,23 +782,23 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
if inst.opcode == llvm.Add {
|
||||
// This likely means this is part of a
|
||||
// unsafe.Pointer(uintptr(ptr) + offset) pattern.
|
||||
lhsPtr, err = lhsPtr.addOffset(int64(rhs.Uint()))
|
||||
lhsPtr, err = lhsPtr.addOffset(int64(rhs.Uint(r)))
|
||||
if err != nil {
|
||||
return nil, mem, r.errorAt(inst, err)
|
||||
}
|
||||
locals[inst.localIndex] = lhsPtr
|
||||
} else if inst.opcode == llvm.Xor && rhs.Uint() == 0 {
|
||||
} else if inst.opcode == llvm.Xor && rhs.Uint(r) == 0 {
|
||||
// Special workaround for strings.noescape, see
|
||||
// src/strings/builder.go in the Go source tree. This is
|
||||
// the identity operator, so we can return the input.
|
||||
locals[inst.localIndex] = lhs
|
||||
} else if inst.opcode == llvm.And && rhs.Uint() < 8 {
|
||||
} else if inst.opcode == llvm.And && rhs.Uint(r) < 8 {
|
||||
// This is probably part of a pattern to get the lower bits
|
||||
// of a pointer for pointer tagging, like this:
|
||||
// uintptr(unsafe.Pointer(t)) & 0b11
|
||||
// We can actually support this easily by ANDing with the
|
||||
// pointer offset.
|
||||
result := uint64(lhsPtr.offset()) & rhs.Uint()
|
||||
result := uint64(lhsPtr.offset()) & rhs.Uint(r)
|
||||
locals[inst.localIndex] = makeLiteralInt(result, int(lhs.len(r)*8))
|
||||
} else {
|
||||
// Catch-all for weird operations that should just be done
|
||||
@@ -813,31 +813,31 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
var result uint64
|
||||
switch inst.opcode {
|
||||
case llvm.Add:
|
||||
result = lhs.Uint() + rhs.Uint()
|
||||
result = lhs.Uint(r) + rhs.Uint(r)
|
||||
case llvm.Sub:
|
||||
result = lhs.Uint() - rhs.Uint()
|
||||
result = lhs.Uint(r) - rhs.Uint(r)
|
||||
case llvm.Mul:
|
||||
result = lhs.Uint() * rhs.Uint()
|
||||
result = lhs.Uint(r) * rhs.Uint(r)
|
||||
case llvm.UDiv:
|
||||
result = lhs.Uint() / rhs.Uint()
|
||||
result = lhs.Uint(r) / rhs.Uint(r)
|
||||
case llvm.SDiv:
|
||||
result = uint64(lhs.Int() / rhs.Int())
|
||||
result = uint64(lhs.Int(r) / rhs.Int(r))
|
||||
case llvm.URem:
|
||||
result = lhs.Uint() % rhs.Uint()
|
||||
result = lhs.Uint(r) % rhs.Uint(r)
|
||||
case llvm.SRem:
|
||||
result = uint64(lhs.Int() % rhs.Int())
|
||||
result = uint64(lhs.Int(r) % rhs.Int(r))
|
||||
case llvm.Shl:
|
||||
result = lhs.Uint() << rhs.Uint()
|
||||
result = lhs.Uint(r) << rhs.Uint(r)
|
||||
case llvm.LShr:
|
||||
result = lhs.Uint() >> rhs.Uint()
|
||||
result = lhs.Uint(r) >> rhs.Uint(r)
|
||||
case llvm.AShr:
|
||||
result = uint64(lhs.Int() >> rhs.Uint())
|
||||
result = uint64(lhs.Int(r) >> rhs.Uint(r))
|
||||
case llvm.And:
|
||||
result = lhs.Uint() & rhs.Uint()
|
||||
result = lhs.Uint(r) & rhs.Uint(r)
|
||||
case llvm.Or:
|
||||
result = lhs.Uint() | rhs.Uint()
|
||||
result = lhs.Uint(r) | rhs.Uint(r)
|
||||
case llvm.Xor:
|
||||
result = lhs.Uint() ^ rhs.Uint()
|
||||
result = lhs.Uint(r) ^ rhs.Uint(r)
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
@@ -855,11 +855,11 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
// and then truncating it as necessary.
|
||||
var value uint64
|
||||
if inst.opcode == llvm.SExt {
|
||||
value = uint64(operands[0].Int())
|
||||
value = uint64(operands[0].Int(r))
|
||||
} else {
|
||||
value = operands[0].Uint()
|
||||
value = operands[0].Uint(r)
|
||||
}
|
||||
bitwidth := operands[1].Uint()
|
||||
bitwidth := operands[1].Uint(r)
|
||||
if r.debug {
|
||||
fmt.Fprintln(os.Stderr, indent+instructionNameMap[inst.opcode]+":", value, bitwidth)
|
||||
}
|
||||
@@ -868,11 +868,11 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
||||
var value float64
|
||||
switch inst.opcode {
|
||||
case llvm.SIToFP:
|
||||
value = float64(operands[0].Int())
|
||||
value = float64(operands[0].Int(r))
|
||||
case llvm.UIToFP:
|
||||
value = float64(operands[0].Uint())
|
||||
value = float64(operands[0].Uint(r))
|
||||
}
|
||||
bitwidth := operands[1].Uint()
|
||||
bitwidth := operands[1].Uint(r)
|
||||
if r.debug {
|
||||
fmt.Fprintln(os.Stderr, indent+instructionNameMap[inst.opcode]+":", value, bitwidth)
|
||||
}
|
||||
@@ -918,21 +918,21 @@ func (r *runner) interpretICmp(lhs, rhs value, predicate llvm.IntPredicate) bool
|
||||
}
|
||||
return result
|
||||
case llvm.IntUGT:
|
||||
return lhs.Uint() > rhs.Uint()
|
||||
return lhs.Uint(r) > rhs.Uint(r)
|
||||
case llvm.IntUGE:
|
||||
return lhs.Uint() >= rhs.Uint()
|
||||
return lhs.Uint(r) >= rhs.Uint(r)
|
||||
case llvm.IntULT:
|
||||
return lhs.Uint() < rhs.Uint()
|
||||
return lhs.Uint(r) < rhs.Uint(r)
|
||||
case llvm.IntULE:
|
||||
return lhs.Uint() <= rhs.Uint()
|
||||
return lhs.Uint(r) <= rhs.Uint(r)
|
||||
case llvm.IntSGT:
|
||||
return lhs.Int() > rhs.Int()
|
||||
return lhs.Int(r) > rhs.Int(r)
|
||||
case llvm.IntSGE:
|
||||
return lhs.Int() >= rhs.Int()
|
||||
return lhs.Int(r) >= rhs.Int(r)
|
||||
case llvm.IntSLT:
|
||||
return lhs.Int() < rhs.Int()
|
||||
return lhs.Int(r) < rhs.Int(r)
|
||||
case llvm.IntSLE:
|
||||
return lhs.Int() <= rhs.Int()
|
||||
return lhs.Int(r) <= rhs.Int(r)
|
||||
default:
|
||||
// _should_ be unreachable, until LLVM adds new icmp operands (unlikely)
|
||||
panic("interp: unsupported icmp")
|
||||
|
||||
+41
-35
@@ -361,8 +361,8 @@ type value interface {
|
||||
clone() value
|
||||
asPointer(*runner) (pointerValue, error)
|
||||
asRawValue(*runner) rawValue
|
||||
Uint() uint64
|
||||
Int() int64
|
||||
Uint(*runner) uint64
|
||||
Int(*runner) int64
|
||||
toLLVMValue(llvm.Type, *memoryView) (llvm.Value, error)
|
||||
String() string
|
||||
}
|
||||
@@ -405,7 +405,8 @@ func (v literalValue) len(r *runner) uint32 {
|
||||
}
|
||||
|
||||
func (v literalValue) String() string {
|
||||
return strconv.FormatInt(v.Int(), 10)
|
||||
// Note: passing a nil *runner to v.Int because we know it won't use it.
|
||||
return strconv.FormatInt(v.Int(nil), 10)
|
||||
}
|
||||
|
||||
func (v literalValue) clone() value {
|
||||
@@ -421,13 +422,13 @@ func (v literalValue) asRawValue(r *runner) rawValue {
|
||||
switch value := v.value.(type) {
|
||||
case uint64:
|
||||
buf = make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(buf, value)
|
||||
r.byteOrder.PutUint64(buf, value)
|
||||
case uint32:
|
||||
buf = make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(buf, uint32(value))
|
||||
r.byteOrder.PutUint32(buf, uint32(value))
|
||||
case uint16:
|
||||
buf = make([]byte, 2)
|
||||
binary.LittleEndian.PutUint16(buf, uint16(value))
|
||||
r.byteOrder.PutUint16(buf, uint16(value))
|
||||
case uint8:
|
||||
buf = []byte{uint8(value)}
|
||||
default:
|
||||
@@ -440,7 +441,7 @@ func (v literalValue) asRawValue(r *runner) rawValue {
|
||||
return raw
|
||||
}
|
||||
|
||||
func (v literalValue) Uint() uint64 {
|
||||
func (v literalValue) Uint(r *runner) uint64 {
|
||||
switch value := v.value.(type) {
|
||||
case uint64:
|
||||
return value
|
||||
@@ -455,7 +456,7 @@ func (v literalValue) Uint() uint64 {
|
||||
}
|
||||
}
|
||||
|
||||
func (v literalValue) Int() int64 {
|
||||
func (v literalValue) Int(r *runner) int64 {
|
||||
switch value := v.value.(type) {
|
||||
case uint64:
|
||||
return int64(value)
|
||||
@@ -553,11 +554,11 @@ func (v pointerValue) asRawValue(r *runner) rawValue {
|
||||
return rv
|
||||
}
|
||||
|
||||
func (v pointerValue) Uint() uint64 {
|
||||
func (v pointerValue) Uint(r *runner) uint64 {
|
||||
panic("cannot convert pointer to integer")
|
||||
}
|
||||
|
||||
func (v pointerValue) Int() int64 {
|
||||
func (v pointerValue) Int(r *runner) int64 {
|
||||
panic("cannot convert pointer to integer")
|
||||
}
|
||||
|
||||
@@ -702,7 +703,12 @@ func (v rawValue) String() string {
|
||||
}
|
||||
// Format as number if none of the buf is a pointer.
|
||||
if !v.hasPointer() {
|
||||
return strconv.FormatInt(v.Int(), 10)
|
||||
// Construct a fake runner, which is little endian.
|
||||
// We only use String() for debugging, so this is is good enough
|
||||
// (the printed value will just be slightly wrong when debugging the
|
||||
// interp package with GOOS=mips for example).
|
||||
r := &runner{byteOrder: binary.LittleEndian}
|
||||
return strconv.FormatInt(v.Int(r), 10)
|
||||
}
|
||||
}
|
||||
return "<[…" + strconv.Itoa(len(v.buf)) + "]>"
|
||||
@@ -738,33 +744,33 @@ func (v rawValue) bytes() []byte {
|
||||
return buf
|
||||
}
|
||||
|
||||
func (v rawValue) Uint() uint64 {
|
||||
func (v rawValue) Uint(r *runner) uint64 {
|
||||
buf := v.bytes()
|
||||
|
||||
switch len(v.buf) {
|
||||
case 1:
|
||||
return uint64(buf[0])
|
||||
case 2:
|
||||
return uint64(binary.LittleEndian.Uint16(buf))
|
||||
return uint64(r.byteOrder.Uint16(buf))
|
||||
case 4:
|
||||
return uint64(binary.LittleEndian.Uint32(buf))
|
||||
return uint64(r.byteOrder.Uint32(buf))
|
||||
case 8:
|
||||
return binary.LittleEndian.Uint64(buf)
|
||||
return r.byteOrder.Uint64(buf)
|
||||
default:
|
||||
panic("unknown integer size")
|
||||
}
|
||||
}
|
||||
|
||||
func (v rawValue) Int() int64 {
|
||||
func (v rawValue) Int(r *runner) int64 {
|
||||
switch len(v.buf) {
|
||||
case 1:
|
||||
return int64(int8(v.Uint()))
|
||||
return int64(int8(v.Uint(r)))
|
||||
case 2:
|
||||
return int64(int16(v.Uint()))
|
||||
return int64(int16(v.Uint(r)))
|
||||
case 4:
|
||||
return int64(int32(v.Uint()))
|
||||
return int64(int32(v.Uint(r)))
|
||||
case 8:
|
||||
return int64(int64(v.Uint()))
|
||||
return int64(int64(v.Uint(r)))
|
||||
default:
|
||||
panic("unknown integer size")
|
||||
}
|
||||
@@ -878,11 +884,11 @@ func (v rawValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Value,
|
||||
var n uint64
|
||||
switch llvmType.IntTypeWidth() {
|
||||
case 64:
|
||||
n = rawValue{v.buf[:8]}.Uint()
|
||||
n = rawValue{v.buf[:8]}.Uint(mem.r)
|
||||
case 32:
|
||||
n = rawValue{v.buf[:4]}.Uint()
|
||||
n = rawValue{v.buf[:4]}.Uint(mem.r)
|
||||
case 16:
|
||||
n = rawValue{v.buf[:2]}.Uint()
|
||||
n = rawValue{v.buf[:2]}.Uint(mem.r)
|
||||
case 8:
|
||||
n = uint64(v.buf[0])
|
||||
case 1:
|
||||
@@ -951,7 +957,7 @@ func (v rawValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Value,
|
||||
}
|
||||
// This is either a null pointer or a raw pointer for memory-mapped I/O
|
||||
// (such as 0xe000ed00).
|
||||
ptr := rawValue{v.buf[:mem.r.pointerSize]}.Uint()
|
||||
ptr := rawValue{v.buf[:mem.r.pointerSize]}.Uint(mem.r)
|
||||
if ptr == 0 {
|
||||
// Null pointer.
|
||||
return llvm.ConstNull(llvmType), nil
|
||||
@@ -969,11 +975,11 @@ func (v rawValue) toLLVMValue(llvmType llvm.Type, mem *memoryView) (llvm.Value,
|
||||
}
|
||||
return llvm.ConstIntToPtr(ptrValue, llvmType), nil
|
||||
case llvm.DoubleTypeKind:
|
||||
b := rawValue{v.buf[:8]}.Uint()
|
||||
b := rawValue{v.buf[:8]}.Uint(mem.r)
|
||||
f := math.Float64frombits(b)
|
||||
return llvm.ConstFloat(llvmType, f), nil
|
||||
case llvm.FloatTypeKind:
|
||||
b := uint32(rawValue{v.buf[:4]}.Uint())
|
||||
b := uint32(rawValue{v.buf[:4]}.Uint(mem.r))
|
||||
f := math.Float32frombits(b)
|
||||
return llvm.ConstFloat(llvmType, float64(f)), nil
|
||||
default:
|
||||
@@ -1065,19 +1071,19 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) {
|
||||
switch llvmValue.Type().IntTypeWidth() {
|
||||
case 64:
|
||||
var buf [8]byte
|
||||
binary.LittleEndian.PutUint64(buf[:], n)
|
||||
r.byteOrder.PutUint64(buf[:], n)
|
||||
for i, b := range buf {
|
||||
v.buf[i] = uint64(b)
|
||||
}
|
||||
case 32:
|
||||
var buf [4]byte
|
||||
binary.LittleEndian.PutUint32(buf[:], uint32(n))
|
||||
r.byteOrder.PutUint32(buf[:], uint32(n))
|
||||
for i, b := range buf {
|
||||
v.buf[i] = uint64(b)
|
||||
}
|
||||
case 16:
|
||||
var buf [2]byte
|
||||
binary.LittleEndian.PutUint16(buf[:], uint16(n))
|
||||
r.byteOrder.PutUint16(buf[:], uint16(n))
|
||||
for i, b := range buf {
|
||||
v.buf[i] = uint64(b)
|
||||
}
|
||||
@@ -1109,14 +1115,14 @@ func (v *rawValue) set(llvmValue llvm.Value, r *runner) {
|
||||
case llvm.DoubleTypeKind:
|
||||
f, _ := llvmValue.DoubleValue()
|
||||
var buf [8]byte
|
||||
binary.LittleEndian.PutUint64(buf[:], math.Float64bits(f))
|
||||
r.byteOrder.PutUint64(buf[:], math.Float64bits(f))
|
||||
for i, b := range buf {
|
||||
v.buf[i] = uint64(b)
|
||||
}
|
||||
case llvm.FloatTypeKind:
|
||||
f, _ := llvmValue.DoubleValue()
|
||||
var buf [4]byte
|
||||
binary.LittleEndian.PutUint32(buf[:], math.Float32bits(float32(f)))
|
||||
r.byteOrder.PutUint32(buf[:], math.Float32bits(float32(f)))
|
||||
for i, b := range buf {
|
||||
v.buf[i] = uint64(b)
|
||||
}
|
||||
@@ -1166,11 +1172,11 @@ func (v localValue) asRawValue(r *runner) rawValue {
|
||||
panic("interp: localValue.asRawValue")
|
||||
}
|
||||
|
||||
func (v localValue) Uint() uint64 {
|
||||
func (v localValue) Uint(r *runner) uint64 {
|
||||
panic("interp: localValue.Uint")
|
||||
}
|
||||
|
||||
func (v localValue) Int() int64 {
|
||||
func (v localValue) Int(r *runner) int64 {
|
||||
panic("interp: localValue.Int")
|
||||
}
|
||||
|
||||
@@ -1254,7 +1260,7 @@ func (r *runner) readObjectLayout(layoutValue value) (uint64, *big.Int) {
|
||||
ptr, err := layoutValue.asPointer(r)
|
||||
if err == errIntegerAsPointer {
|
||||
// It's an integer, which means it's a small object or unknown.
|
||||
layout := layoutValue.Uint()
|
||||
layout := layoutValue.Uint(r)
|
||||
if layout == 0 {
|
||||
// Nil pointer, which means the layout is unknown.
|
||||
return 0, nil
|
||||
@@ -1287,7 +1293,7 @@ func (r *runner) readObjectLayout(layoutValue value) (uint64, *big.Int) {
|
||||
|
||||
// Read the object size in words and the bitmap from the global.
|
||||
buf := r.objects[ptr.index()].buffer.(rawValue)
|
||||
objectSizeWords := rawValue{buf: buf.buf[:r.pointerSize]}.Uint()
|
||||
objectSizeWords := rawValue{buf: buf.buf[:r.pointerSize]}.Uint(r)
|
||||
rawByteValues := buf.buf[r.pointerSize:]
|
||||
rawBytes := make([]byte, len(rawByteValues))
|
||||
for i, v := range rawByteValues {
|
||||
|
||||
+1
-1
Submodule lib/macos-minimal-sdk updated: 91ac2eabd8...4e4113e3b1
Submodule lib/renesas-svd deleted from 03d7688085
+1
-1
@@ -218,7 +218,7 @@ func listGorootMergeLinks(goroot, tinygoroot string, overrides map[string]bool)
|
||||
// with the TinyGo version. This is the case on some targets.
|
||||
func needsSyscallPackage(buildTags []string) bool {
|
||||
for _, tag := range buildTags {
|
||||
if tag == "baremetal" || tag == "darwin" || tag == "nintendoswitch" || tag == "tinygo.wasm" {
|
||||
if tag == "baremetal" || tag == "nintendoswitch" || tag == "tinygo.wasm" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,13 +305,11 @@ func Test(pkgName string, stdout, stderr io.Writer, options *compileopts.Options
|
||||
//
|
||||
// Ex. run --dir=.. --dir=../.. --dir=../../..
|
||||
var dirs []string
|
||||
switch config.Options.Target {
|
||||
switch config.Target.GOOS {
|
||||
case "wasip1":
|
||||
dirs = dirsToModuleRootRel(result.MainDir, result.ModuleRoot)
|
||||
case "wasip2":
|
||||
dirs = dirsToModuleRootAbs(result.MainDir, result.ModuleRoot)
|
||||
default:
|
||||
return fmt.Errorf("unknown GOOS target: %v", config.Options.Target)
|
||||
dirs = dirsToModuleRootAbs(result.MainDir, result.ModuleRoot)
|
||||
}
|
||||
|
||||
args := []string{"run"}
|
||||
|
||||
+17
-1
@@ -36,7 +36,7 @@ var supportedLinuxArches = map[string]string{
|
||||
"X86Linux": "linux/386",
|
||||
"ARMLinux": "linux/arm/6",
|
||||
"ARM64Linux": "linux/arm64",
|
||||
"MIPSLinux": "linux/mipsle/hardfloat",
|
||||
"MIPSLinux": "linux/mips/hardfloat",
|
||||
"WASIp1": "wasip1/wasm",
|
||||
}
|
||||
|
||||
@@ -177,6 +177,15 @@ func TestBuild(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
t.Run("MIPS little-endian", func(t *testing.T) {
|
||||
// Run a single test for GOARCH=mipsle to see whether it works at
|
||||
// all. It is already mostly tested because GOARCH=mips and
|
||||
// GOARCH=mipsle are so similar, but it's good to have an extra test
|
||||
// to be sure.
|
||||
t.Parallel()
|
||||
options := optionsFromOSARCH("linux/mipsle/softfloat", sema)
|
||||
runTest("cgo/", options, t, nil, nil)
|
||||
})
|
||||
t.Run("WebAssembly", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
runPlatTests(optionsFromTarget("wasm", sema), tests, t)
|
||||
@@ -220,6 +229,13 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if options.GOOS == "linux" && options.GOARCH == "mips" {
|
||||
if name == "cgo/" {
|
||||
// CGo isn't supported yet on big-endian systems (needs updates
|
||||
// to bitfield access methods).
|
||||
continue
|
||||
}
|
||||
}
|
||||
if options.Target == "simavr" {
|
||||
// Not all tests are currently supported on AVR.
|
||||
// Skip the ones that aren't.
|
||||
|
||||
@@ -4,11 +4,9 @@ package abi
|
||||
// (in particular internal/syscall/unix on MacOS). They do not currently have an
|
||||
// implementation, in part because TinyGo doesn't use ABI0 or ABIInternal (it
|
||||
// uses a C-like calling convention).
|
||||
// Calls to FuncPCABI0 however are treated specially by the compiler when
|
||||
// compiling for MacOS.
|
||||
|
||||
func FuncPCABI0(f interface{}) uintptr {
|
||||
panic("unimplemented: internal/abi.FuncPCABI0")
|
||||
}
|
||||
func FuncPCABI0(f interface{}) uintptr
|
||||
|
||||
func FuncPCABIInternal(f interface{}) uintptr {
|
||||
panic("unimplemented: internal/abi.FuncPCABIInternal")
|
||||
}
|
||||
func FuncPCABIInternal(f interface{}) uintptr
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package command represents the world "wasi:cli/command@0.2.0".
|
||||
package command
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package environment represents the imported interface "wasi:cli/environment@0.2.0".
|
||||
package environment
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package exit represents the imported interface "wasi:cli/exit@0.2.0".
|
||||
package exit
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
package run
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package run represents the exported interface "wasi:cli/run@0.2.0".
|
||||
package run
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package stderr represents the imported interface "wasi:cli/stderr@0.2.0".
|
||||
package stderr
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package stdin represents the imported interface "wasi:cli/stdin@0.2.0".
|
||||
package stdin
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package stdout represents the imported interface "wasi:cli/stdout@0.2.0".
|
||||
package stdout
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package terminalinput represents the imported interface "wasi:cli/terminal-input@0.2.0".
|
||||
//
|
||||
// Terminal input.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package terminaloutput represents the imported interface "wasi:cli/terminal-output@0.2.0".
|
||||
//
|
||||
// Terminal output.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package terminalstderr represents the imported interface "wasi:cli/terminal-stderr@0.2.0".
|
||||
//
|
||||
// An interface providing an optional `terminal-output` for stderr as a
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package terminalstdin represents the imported interface "wasi:cli/terminal-stdin@0.2.0".
|
||||
//
|
||||
// An interface providing an optional `terminal-input` for stdin as a
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package terminalstdout represents the imported interface "wasi:cli/terminal-stdout@0.2.0".
|
||||
//
|
||||
// An interface providing an optional `terminal-output` for stdout as a
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.0".
|
||||
//
|
||||
// WASI Monotonic Clock is a clock API intended to let users measure elapsed
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.0".
|
||||
//
|
||||
// WASI Wall Clock is a clock API intended to let users query the current
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package preopens represents the imported interface "wasi:filesystem/preopens@0.2.0".
|
||||
package preopens
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package types represents the imported interface "wasi:filesystem/types@0.2.0".
|
||||
//
|
||||
// WASI filesystem is a filesystem API primarily intended to let users run WASI
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package ioerror represents the imported interface "wasi:io/error@0.2.0".
|
||||
package ioerror
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package poll represents the imported interface "wasi:io/poll@0.2.0".
|
||||
//
|
||||
// A poll API intended to let users wait for I/O events on multiple handles
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
package streams
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package streams represents the imported interface "wasi:io/streams@0.2.0".
|
||||
//
|
||||
// WASI I/O is an I/O abstraction API which is currently focused on providing
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package insecureseed represents the imported interface "wasi:random/insecure-seed@0.2.0".
|
||||
//
|
||||
// The insecure-seed interface for seeding hash-map DoS resistance.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package insecure represents the imported interface "wasi:random/insecure@0.2.0".
|
||||
//
|
||||
// The insecure interface for insecure pseudo-random numbers.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package random represents the imported interface "wasi:random/random@0.2.0".
|
||||
//
|
||||
// WASI Random is a random data API.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package instancenetwork represents the imported interface "wasi:sockets/instance-network@0.2.0".
|
||||
//
|
||||
// This interface provides a value-export of the default network handle..
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
package ipnamelookup
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package ipnamelookup represents the imported interface "wasi:sockets/ip-name-lookup@0.2.0".
|
||||
package ipnamelookup
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
package network
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package network represents the imported interface "wasi:sockets/network@0.2.0".
|
||||
package network
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package tcpcreatesocket represents the imported interface "wasi:sockets/tcp-create-socket@0.2.0".
|
||||
package tcpcreatesocket
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
package tcp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package tcp represents the imported interface "wasi:sockets/tcp@0.2.0".
|
||||
package tcp
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package udpcreatesocket represents the imported interface "wasi:sockets/udp-create-socket@0.2.0".
|
||||
package udpcreatesocket
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
package udp
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// Code generated by wit-bindgen-go. DO NOT EDIT.
|
||||
|
||||
//go:build !wasip1
|
||||
|
||||
// Package udp represents the imported interface "wasi:sockets/udp@0.2.0".
|
||||
package udp
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
//go:build rak4631
|
||||
|
||||
package machine
|
||||
|
||||
const HasLowFrequencyCrystal = true
|
||||
|
||||
// Digital Pins
|
||||
const (
|
||||
D0 Pin = P0_28
|
||||
D1 Pin = P0_02
|
||||
)
|
||||
|
||||
// Analog pins
|
||||
const (
|
||||
A0 Pin = P0_17
|
||||
A1 Pin = P1_02
|
||||
A2 Pin = P0_21
|
||||
)
|
||||
|
||||
// Onboard LEDs
|
||||
const (
|
||||
LED = LED2
|
||||
LED1 = P1_03
|
||||
LED2 = P1_04
|
||||
)
|
||||
|
||||
// UART pins
|
||||
const (
|
||||
// Default to UART1
|
||||
UART_RX_PIN = UART0_RX_PIN
|
||||
UART_TX_PIN = UART0_TX_PIN
|
||||
|
||||
// UART1
|
||||
UART0_RX_PIN = P0_19
|
||||
UART0_TX_PIN = P0_20
|
||||
|
||||
// UART2
|
||||
UART1_RX_PIN = P0_15
|
||||
UART1_TX_PIN = P0_16
|
||||
)
|
||||
|
||||
// I2C pins
|
||||
const (
|
||||
SDA_PIN = SDA1_PIN
|
||||
SCL_PIN = SCL1_PIN
|
||||
|
||||
SDA1_PIN = P0_13
|
||||
SCL1_PIN = P0_14
|
||||
|
||||
SDA2_PIN = P0_24
|
||||
SCL2_PIN = P0_25
|
||||
)
|
||||
|
||||
// SPI pins
|
||||
const (
|
||||
SPI0_SCK_PIN = P0_03
|
||||
SPI0_SDO_PIN = P0_29
|
||||
SPI0_SDI_PIN = P0_30
|
||||
)
|
||||
|
||||
// Peripherals
|
||||
const (
|
||||
LORA_NSS = P1_10
|
||||
LORA_SCK = P1_11
|
||||
LORA_MOSI = P1_12
|
||||
LORA_MISO = P1_13
|
||||
LORA_BUSY = P1_14
|
||||
LORA_DIO1 = P1_15
|
||||
LORA_NRESET = P1_06
|
||||
LORA_POWER = P1_05
|
||||
)
|
||||
|
||||
// USB CDC identifiers
|
||||
const (
|
||||
usb_STRING_PRODUCT = "WisCore RAK4631 Board"
|
||||
usb_STRING_MANUFACTURER = "RAKwireless"
|
||||
)
|
||||
|
||||
var (
|
||||
usb_VID uint16 = 0x239a
|
||||
usb_PID uint16 = 0x8029
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultUART = UART0
|
||||
)
|
||||
@@ -135,7 +135,7 @@ func darwinOpenDir(fd syscallFd) (uintptr, string, error) {
|
||||
}
|
||||
var dir uintptr
|
||||
for {
|
||||
dir, err = syscall.Fdopendir(fd2)
|
||||
dir, err = fdopendir(fd2)
|
||||
if err != syscall.EINTR {
|
||||
break
|
||||
}
|
||||
@@ -149,6 +149,9 @@ func darwinOpenDir(fd syscallFd) (uintptr, string, error) {
|
||||
|
||||
// Implemented in syscall/syscall_libc_darwin_*.go.
|
||||
|
||||
//go:linkname fdopendir syscall.fdopendir
|
||||
func fdopendir(fd int) (dir uintptr, err error)
|
||||
|
||||
//go:linkname closedir syscall.closedir
|
||||
func closedir(dir uintptr) (err error)
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package os
|
||||
|
||||
import "syscall"
|
||||
|
||||
func pipe(p []int) error {
|
||||
return syscall.Pipe(p)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
//go:build (linux && !baremetal && !wasm_unknown) || wasip1 || wasip2
|
||||
|
||||
package os
|
||||
|
||||
import "syscall"
|
||||
|
||||
func pipe(p []int) error {
|
||||
return syscall.Pipe2(p, syscall.O_CLOEXEC)
|
||||
}
|
||||
@@ -135,3 +135,17 @@ func Readlink(name string) (string, error) {
|
||||
func tempDir() string {
|
||||
return "/tmp"
|
||||
}
|
||||
|
||||
// Truncate is unsupported on this system.
|
||||
func Truncate(filename string, size int64) (err error) {
|
||||
return ErrUnsupported
|
||||
}
|
||||
|
||||
// Truncate is unsupported on this system.
|
||||
func (f *File) Truncate(size int64) (err error) {
|
||||
if f.handle == nil {
|
||||
return ErrClosed
|
||||
}
|
||||
|
||||
return Truncate(f.name, size)
|
||||
}
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ func Truncate(name string, size int64) error {
|
||||
|
||||
func Pipe() (r *File, w *File, err error) {
|
||||
var p [2]int
|
||||
err = handleSyscallError(syscall.Pipe2(p[:], syscall.O_CLOEXEC))
|
||||
err = handleSyscallError(pipe(p[:]))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
//go:build mips
|
||||
|
||||
package reflect
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// loadValue loads a value that may or may not be word-aligned. The number of
|
||||
// bytes given in size are loaded. The biggest possible size it can load is that
|
||||
// of an uintptr.
|
||||
func loadValue(ptr unsafe.Pointer, size uintptr) uintptr {
|
||||
loadedValue := uintptr(0)
|
||||
for i := uintptr(0); i < size; i++ {
|
||||
loadedValue <<= 8
|
||||
loadedValue |= uintptr(*(*byte)(ptr))
|
||||
ptr = unsafe.Add(ptr, 1)
|
||||
}
|
||||
return loadedValue
|
||||
}
|
||||
|
||||
// storeValue is the inverse of loadValue. It stores a value to a pointer that
|
||||
// doesn't need to be aligned.
|
||||
func storeValue(ptr unsafe.Pointer, size, value uintptr) {
|
||||
// This could perhaps be optimized using bits.ReverseBytes32 if needed.
|
||||
value <<= (unsafe.Sizeof(uintptr(0)) - size) * 8
|
||||
for i := uintptr(0); i < size; i++ {
|
||||
*(*byte)(ptr) = byte(value >> ((unsafe.Sizeof(uintptr(0)) - 1) * 8))
|
||||
ptr = unsafe.Add(ptr, 1)
|
||||
value <<= 8
|
||||
}
|
||||
}
|
||||
|
||||
// maskAndShift cuts out a part of a uintptr. Note that the offset may not be 0.
|
||||
func maskAndShift(value, offset, size uintptr) uintptr {
|
||||
mask := ^uintptr(0) >> ((unsafe.Sizeof(uintptr(0)) - size) * 8)
|
||||
return (uintptr(value) >> ((unsafe.Sizeof(uintptr(0)) - offset - size) * 8)) & mask
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//go:build !mips
|
||||
|
||||
package reflect
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// loadValue loads a value that may or may not be word-aligned. The number of
|
||||
// bytes given in size are loaded. The biggest possible size it can load is that
|
||||
// of an uintptr.
|
||||
func loadValue(ptr unsafe.Pointer, size uintptr) uintptr {
|
||||
loadedValue := uintptr(0)
|
||||
shift := uintptr(0)
|
||||
for i := uintptr(0); i < size; i++ {
|
||||
loadedValue |= uintptr(*(*byte)(ptr)) << shift
|
||||
shift += 8
|
||||
ptr = unsafe.Add(ptr, 1)
|
||||
}
|
||||
return loadedValue
|
||||
}
|
||||
|
||||
// storeValue is the inverse of loadValue. It stores a value to a pointer that
|
||||
// doesn't need to be aligned.
|
||||
func storeValue(ptr unsafe.Pointer, size, value uintptr) {
|
||||
for i := uintptr(0); i < size; i++ {
|
||||
*(*byte)(ptr) = byte(value)
|
||||
ptr = unsafe.Add(ptr, 1)
|
||||
value >>= 8
|
||||
}
|
||||
}
|
||||
|
||||
// maskAndShift cuts out a part of a uintptr. Note that the offset may not be 0.
|
||||
func maskAndShift(value, offset, size uintptr) uintptr {
|
||||
mask := ^uintptr(0) >> ((unsafe.Sizeof(uintptr(0)) - size) * 8)
|
||||
return (uintptr(value) >> (offset * 8)) & mask
|
||||
}
|
||||
+4
-27
@@ -887,26 +887,6 @@ func (v Value) Index(i int) Value {
|
||||
}
|
||||
}
|
||||
|
||||
// loadValue loads a value that may or may not be word-aligned. The number of
|
||||
// bytes given in size are loaded. The biggest possible size it can load is that
|
||||
// of an uintptr.
|
||||
func loadValue(ptr unsafe.Pointer, size uintptr) uintptr {
|
||||
loadedValue := uintptr(0)
|
||||
shift := uintptr(0)
|
||||
for i := uintptr(0); i < size; i++ {
|
||||
loadedValue |= uintptr(*(*byte)(ptr)) << shift
|
||||
shift += 8
|
||||
ptr = unsafe.Add(ptr, 1)
|
||||
}
|
||||
return loadedValue
|
||||
}
|
||||
|
||||
// maskAndShift cuts out a part of a uintptr. Note that the offset may not be 0.
|
||||
func maskAndShift(value, offset, size uintptr) uintptr {
|
||||
mask := ^uintptr(0) >> ((unsafe.Sizeof(uintptr(0)) - size) * 8)
|
||||
return (uintptr(value) >> (offset * 8)) & mask
|
||||
}
|
||||
|
||||
func (v Value) NumMethod() int {
|
||||
return v.typecode.NumMethod()
|
||||
}
|
||||
@@ -1088,9 +1068,7 @@ func (v Value) Set(x Value) {
|
||||
if v.typecode.Kind() == Interface && x.typecode.Kind() != Interface {
|
||||
// move the value of x back into the interface, if possible
|
||||
if x.isIndirect() && x.typecode.Size() <= unsafe.Sizeof(uintptr(0)) {
|
||||
var value uintptr
|
||||
memcpy(unsafe.Pointer(&value), x.value, x.typecode.Size())
|
||||
x.value = unsafe.Pointer(value)
|
||||
x.value = unsafe.Pointer(loadValue(x.value, x.typecode.Size()))
|
||||
}
|
||||
|
||||
intf := composeInterface(unsafe.Pointer(x.typecode), x.value)
|
||||
@@ -1101,12 +1079,11 @@ func (v Value) Set(x Value) {
|
||||
}
|
||||
|
||||
size := v.typecode.Size()
|
||||
xptr := x.value
|
||||
if size <= unsafe.Sizeof(uintptr(0)) && !x.isIndirect() {
|
||||
value := x.value
|
||||
xptr = unsafe.Pointer(&value)
|
||||
storeValue(v.value, size, uintptr(x.value))
|
||||
} else {
|
||||
memcpy(v.value, x.value, size)
|
||||
}
|
||||
memcpy(v.value, xptr, size)
|
||||
}
|
||||
|
||||
func (v Value) SetZero() {
|
||||
|
||||
+27
-2
@@ -1,7 +1,32 @@
|
||||
// Wrapper function because 'open' is a variadic function and variadic functions
|
||||
// use a different (incompatible) calling convention on darwin/arm64.
|
||||
//go:build none
|
||||
|
||||
// This file is included in the build, despite the //go:build line above.
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
// Wrapper function because 'open' is a variadic function and variadic functions
|
||||
// use a different (incompatible) calling convention on darwin/arm64.
|
||||
// This function is referenced from the compiler, when it sees a
|
||||
// syscall.libc_open_trampoline function.
|
||||
int syscall_libc_open(const char *pathname, int flags, mode_t mode) {
|
||||
return open(pathname, flags, mode);
|
||||
}
|
||||
|
||||
// The following functions are called by the runtime because Go can't call
|
||||
// function pointers directly.
|
||||
|
||||
int tinygo_syscall(int (*fn)(uintptr_t a1, uintptr_t a2, uintptr_t a3), uintptr_t a1, uintptr_t a2, uintptr_t a3) {
|
||||
return fn(a1, a2, a3);
|
||||
}
|
||||
|
||||
uintptr_t tinygo_syscallX(uintptr_t (*fn)(uintptr_t a1, uintptr_t a2, uintptr_t a3), uintptr_t a1, uintptr_t a2, uintptr_t a3) {
|
||||
return fn(a1, a2, a3);
|
||||
}
|
||||
|
||||
int tinygo_syscall6(int (*fn)(uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6), uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6) {
|
||||
return fn(a1, a2, a3, a4, a5, a6);
|
||||
}
|
||||
|
||||
uintptr_t tinygo_syscall6X(uintptr_t (*fn)(uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6), uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6) {
|
||||
return fn(a1, a2, a3, a4, a5, a6);
|
||||
}
|
||||
|
||||
+100
-2
@@ -4,8 +4,6 @@ package runtime
|
||||
|
||||
import "unsafe"
|
||||
|
||||
import "C" // dummy import so that os_darwin.c works
|
||||
|
||||
const GOOS = "darwin"
|
||||
|
||||
const (
|
||||
@@ -127,7 +125,107 @@ func hardwareRand() (n uint64, ok bool) {
|
||||
return n, true
|
||||
}
|
||||
|
||||
//go:linkname syscall_Getpagesize syscall.Getpagesize
|
||||
func syscall_Getpagesize() int {
|
||||
return int(libc_getpagesize())
|
||||
}
|
||||
|
||||
// Call "system calls" (actually: libc functions) in a special way.
|
||||
// - Most calls calls return a C int (which is 32-bits), and -1 on failure.
|
||||
// - syscallX* is for functions that return a 64-bit integer (and also return
|
||||
// -1 on failure).
|
||||
// - syscallPtr is for functions that return a pointer on success or NULL on
|
||||
// failure.
|
||||
// - rawSyscall seems to avoid some stack modifications, which isn't relevant
|
||||
// to TinyGo.
|
||||
|
||||
//go:linkname syscall_syscall syscall.syscall
|
||||
func syscall_syscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
|
||||
// For TinyGo we don't need to do anything special to call C functions.
|
||||
return syscall_rawSyscall(fn, a1, a2, a3)
|
||||
}
|
||||
|
||||
//go:linkname syscall_rawSyscall syscall.rawSyscall
|
||||
func syscall_rawSyscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
|
||||
result := call_syscall(fn, a1, a2, a3)
|
||||
r1 = uintptr(result)
|
||||
if result == -1 {
|
||||
// Syscall returns -1 on failure.
|
||||
err = uintptr(*libc___error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//go:linkname syscall_syscallX syscall.syscallX
|
||||
func syscall_syscallX(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
|
||||
r1 = call_syscallX(fn, a1, a2, a3)
|
||||
if int64(r1) == -1 {
|
||||
// Syscall returns -1 on failure.
|
||||
err = uintptr(*libc___error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//go:linkname syscall_syscallPtr syscall.syscallPtr
|
||||
func syscall_syscallPtr(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
|
||||
r1 = call_syscallX(fn, a1, a2, a3)
|
||||
if r1 == 0 {
|
||||
// Syscall returns a pointer on success, or NULL on failure.
|
||||
err = uintptr(*libc___error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//go:linkname syscall_syscall6 syscall.syscall6
|
||||
func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
|
||||
result := call_syscall6(fn, a1, a2, a3, a4, a5, a6)
|
||||
r1 = uintptr(result)
|
||||
if result == -1 {
|
||||
// Syscall returns -1 on failure.
|
||||
err = uintptr(*libc___error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//go:linkname syscall_syscall6X syscall.syscall6X
|
||||
func syscall_syscall6X(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
|
||||
r1 = call_syscall6X(fn, a1, a2, a3, a4, a5, a6)
|
||||
if int64(r1) == -1 {
|
||||
// Syscall returns -1 on failure.
|
||||
err = uintptr(*libc___error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// uint32_t arc4random(void);
|
||||
//
|
||||
//export arc4random
|
||||
func libc_arc4random() uint32
|
||||
|
||||
// int getpagesize(void);
|
||||
//
|
||||
//export getpagesize
|
||||
func libc_getpagesize() int32
|
||||
|
||||
// This function returns the error location in the darwin ABI.
|
||||
// Discovered by compiling the following code using Clang:
|
||||
//
|
||||
// #include <errno.h>
|
||||
// int getErrno() {
|
||||
// return errno;
|
||||
// }
|
||||
//
|
||||
//export __error
|
||||
func libc___error() *int32
|
||||
|
||||
//export tinygo_syscall
|
||||
func call_syscall(fn, a1, a2, a3 uintptr) int32
|
||||
|
||||
//export tinygo_syscallX
|
||||
func call_syscallX(fn, a1, a2, a3 uintptr) uintptr
|
||||
|
||||
//export tinygo_syscall6
|
||||
func call_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) int32
|
||||
|
||||
//export tinygo_syscall6X
|
||||
func call_syscall6X(fn, a1, a2, a3, a4, a5, a6 uintptr) uintptr
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package runtime
|
||||
|
||||
// Called from syscall package before Exec.
|
||||
//
|
||||
//go:linkname syscall_runtime_BeforeExec syscall.runtime_BeforeExec
|
||||
func syscall_runtime_BeforeExec() {
|
||||
// Used in BigGo to serialize exec / thread creation. Stubbing to
|
||||
// satisfy link.
|
||||
}
|
||||
|
||||
// Called from syscall package after Exec.
|
||||
//
|
||||
//go:linkname syscall_runtime_AfterExec syscall.runtime_AfterExec
|
||||
func syscall_runtime_AfterExec() {
|
||||
}
|
||||
@@ -13,19 +13,11 @@ type timeUnit int64
|
||||
|
||||
//export wasi:cli/run@0.2.0#run
|
||||
func __wasi_cli_run_run() uint32 {
|
||||
_start()
|
||||
return 0
|
||||
}
|
||||
|
||||
//export _start
|
||||
func _start() {
|
||||
// These need to be initialized early so that the heap can be initialized.
|
||||
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
|
||||
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
|
||||
run()
|
||||
}
|
||||
|
||||
func init() {
|
||||
return 0
|
||||
}
|
||||
|
||||
var args []string
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build darwin || nintendoswitch || wasip1
|
||||
//go:build nintendoswitch || wasip1
|
||||
|
||||
package syscall
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !wasip1 && !wasip2 && !darwin
|
||||
//go:build !wasip1 && !wasip2
|
||||
|
||||
package syscall
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build darwin || linux
|
||||
//go:build linux
|
||||
|
||||
package syscall_test
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build darwin || nintendoswitch || wasip1 || wasip2
|
||||
//go:build nintendoswitch || wasip1 || wasip2
|
||||
|
||||
package syscall
|
||||
|
||||
|
||||
@@ -1,432 +0,0 @@
|
||||
//go:build darwin
|
||||
|
||||
package syscall
|
||||
|
||||
import (
|
||||
"internal/itoa"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// This file defines errno and constants to match the darwin libsystem ABI.
|
||||
// Values have been copied from src/syscall/zerrors_darwin_amd64.go.
|
||||
|
||||
// This function returns the error location in the darwin ABI.
|
||||
// Discovered by compiling the following code using Clang:
|
||||
//
|
||||
// #include <errno.h>
|
||||
// int getErrno() {
|
||||
// return errno;
|
||||
// }
|
||||
//
|
||||
//export __error
|
||||
func libc___error() *int32
|
||||
|
||||
// getErrno returns the current C errno. It may not have been caused by the last
|
||||
// call, so it should only be relied upon when the last call indicates an error
|
||||
// (for example, by returning -1).
|
||||
func getErrno() Errno {
|
||||
errptr := libc___error()
|
||||
return Errno(uintptr(*errptr))
|
||||
}
|
||||
|
||||
func (e Errno) Is(target error) bool {
|
||||
switch target.Error() {
|
||||
case "permission denied":
|
||||
return e == EACCES || e == EPERM
|
||||
case "file already exists":
|
||||
return e == EEXIST
|
||||
case "file does not exist":
|
||||
return e == ENOENT
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Source: upstream zerrors_darwin_amd64.go
|
||||
const (
|
||||
DT_BLK = 0x6
|
||||
DT_CHR = 0x2
|
||||
DT_DIR = 0x4
|
||||
DT_FIFO = 0x1
|
||||
DT_LNK = 0xa
|
||||
DT_REG = 0x8
|
||||
DT_SOCK = 0xc
|
||||
DT_UNKNOWN = 0x0
|
||||
DT_WHT = 0xe
|
||||
F_GETFL = 0x3
|
||||
F_SETFL = 0x4
|
||||
O_NONBLOCK = 0x4
|
||||
TIOCSPGRP = 0x80047476
|
||||
)
|
||||
|
||||
// Source: https://opensource.apple.com/source/xnu/xnu-7195.141.2/bsd/sys/errno.h.auto.html
|
||||
const (
|
||||
EPERM Errno = 1
|
||||
ENOENT Errno = 2
|
||||
ESRCH Errno = 3
|
||||
EINTR Errno = 4
|
||||
EIO Errno = 5
|
||||
ENXIO Errno = 6
|
||||
E2BIG Errno = 7
|
||||
ENOEXEC Errno = 8
|
||||
EBADF Errno = 9
|
||||
ECHILD Errno = 10
|
||||
EDEADLK Errno = 11
|
||||
ENOMEM Errno = 12
|
||||
EACCES Errno = 13
|
||||
EFAULT Errno = 14
|
||||
ENOTBLK Errno = 15
|
||||
EBUSY Errno = 16
|
||||
EEXIST Errno = 17
|
||||
EXDEV Errno = 18
|
||||
ENODEV Errno = 19
|
||||
ENOTDIR Errno = 20
|
||||
EISDIR Errno = 21
|
||||
EINVAL Errno = 22
|
||||
ENFILE Errno = 23
|
||||
EMFILE Errno = 24
|
||||
ENOTTY Errno = 25
|
||||
ETXTBSY Errno = 26
|
||||
EFBIG Errno = 27
|
||||
ENOSPC Errno = 28
|
||||
ESPIPE Errno = 29
|
||||
EROFS Errno = 30
|
||||
EMLINK Errno = 31
|
||||
EPIPE Errno = 32
|
||||
EDOM Errno = 33
|
||||
ERANGE Errno = 34
|
||||
EAGAIN Errno = 35
|
||||
EWOULDBLOCK Errno = EAGAIN
|
||||
EINPROGRESS Errno = 36
|
||||
EALREADY Errno = 37
|
||||
ENOTSOCK Errno = 38
|
||||
EDESTADDRREQ Errno = 39
|
||||
EMSGSIZE Errno = 40
|
||||
EPROTOTYPE Errno = 41
|
||||
ENOPROTOOPT Errno = 42
|
||||
EPROTONOSUPPORT Errno = 43
|
||||
ESOCKTNOSUPPORT Errno = 44
|
||||
ENOTSUP Errno = 45
|
||||
EPFNOSUPPORT Errno = 46
|
||||
EAFNOSUPPORT Errno = 47
|
||||
EADDRINUSE Errno = 48
|
||||
EADDRNOTAVAIL Errno = 49
|
||||
ENETDOWN Errno = 50
|
||||
ENETUNREACH Errno = 51
|
||||
ENETRESET Errno = 52
|
||||
ECONNABORTED Errno = 53
|
||||
ECONNRESET Errno = 54
|
||||
ENOBUFS Errno = 55
|
||||
EISCONN Errno = 56
|
||||
ENOTCONN Errno = 57
|
||||
ESHUTDOWN Errno = 58
|
||||
ETOOMANYREFS Errno = 59
|
||||
ETIMEDOUT Errno = 60
|
||||
ECONNREFUSED Errno = 61
|
||||
ELOOP Errno = 62
|
||||
ENAMETOOLONG Errno = 63
|
||||
EHOSTDOWN Errno = 64
|
||||
EHOSTUNREACH Errno = 65
|
||||
ENOTEMPTY Errno = 66
|
||||
EPROCLIM Errno = 67
|
||||
EUSERS Errno = 68
|
||||
EDQUOT Errno = 69
|
||||
ESTALE Errno = 70
|
||||
EREMOTE Errno = 71
|
||||
EBADRPC Errno = 72
|
||||
ERPCMISMATCH Errno = 73
|
||||
EPROGUNAVAIL Errno = 74
|
||||
EPROGMISMATCH Errno = 75
|
||||
EPROCUNAVAIL Errno = 76
|
||||
ENOLCK Errno = 77
|
||||
ENOSYS Errno = 78
|
||||
EFTYPE Errno = 79
|
||||
EAUTH Errno = 80
|
||||
ENEEDAUTH Errno = 81
|
||||
EPWROFF Errno = 82
|
||||
EDEVERR Errno = 83
|
||||
EOVERFLOW Errno = 84
|
||||
EBADEXEC Errno = 85
|
||||
EBADARCH Errno = 86
|
||||
ESHLIBVERS Errno = 87
|
||||
EBADMACHO Errno = 88
|
||||
ECANCELED Errno = 89
|
||||
EIDRM Errno = 90
|
||||
ENOMSG Errno = 91
|
||||
EILSEQ Errno = 92
|
||||
ENOATTR Errno = 93
|
||||
EBADMSG Errno = 94
|
||||
EMULTIHOP Errno = 95
|
||||
ENODATA Errno = 96
|
||||
ENOLINK Errno = 97
|
||||
ENOSR Errno = 98
|
||||
ENOSTR Errno = 99
|
||||
EPROTO Errno = 100
|
||||
ETIME Errno = 101
|
||||
EOPNOTSUPP Errno = 102
|
||||
ENOPOLICY Errno = 103
|
||||
ENOTRECOVERABLE Errno = 104
|
||||
EOWNERDEAD Errno = 105
|
||||
EQFULL Errno = 106
|
||||
ELAST Errno = 106
|
||||
)
|
||||
|
||||
type Signal int
|
||||
|
||||
// Source: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/sys/signal.h
|
||||
const (
|
||||
SIGINT Signal = 2 /* interrupt */
|
||||
SIGQUIT Signal = 3 /* quit */
|
||||
SIGILL Signal = 4 /* illegal instruction (not reset when caught) */
|
||||
SIGTRAP Signal = 5 /* trace trap (not reset when caught) */
|
||||
SIGABRT Signal = 6 /* abort() */
|
||||
SIGFPE Signal = 8 /* floating point exception */
|
||||
SIGKILL Signal = 9 /* kill (cannot be caught or ignored) */
|
||||
SIGBUS Signal = 10 /* bus error */
|
||||
SIGSEGV Signal = 11 /* segmentation violation */
|
||||
SIGPIPE Signal = 13 /* write on a pipe with no one to read it */
|
||||
SIGTERM Signal = 15 /* software termination signal from kill */
|
||||
SIGCHLD Signal = 20 /* to parent on child stop or exit */
|
||||
)
|
||||
|
||||
func (s Signal) Signal() {}
|
||||
|
||||
func (s Signal) String() string {
|
||||
if 0 <= s && int(s) < len(signals) {
|
||||
str := signals[s]
|
||||
if str != "" {
|
||||
return str
|
||||
}
|
||||
}
|
||||
return "signal " + itoa.Itoa(int(s))
|
||||
}
|
||||
|
||||
var signals = [...]string{}
|
||||
|
||||
const (
|
||||
Stdin = 0
|
||||
Stdout = 1
|
||||
Stderr = 2
|
||||
)
|
||||
|
||||
const (
|
||||
O_RDONLY = 0x0
|
||||
O_WRONLY = 0x1
|
||||
O_RDWR = 0x2
|
||||
O_APPEND = 0x8
|
||||
O_SYNC = 0x80
|
||||
O_CREAT = 0x200
|
||||
O_TRUNC = 0x400
|
||||
O_EXCL = 0x800
|
||||
|
||||
O_CLOEXEC = 0x01000000
|
||||
)
|
||||
|
||||
// Source: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/sys/mman.h.auto.html
|
||||
const (
|
||||
PROT_NONE = 0x00 // no permissions
|
||||
PROT_READ = 0x01 // pages can be read
|
||||
PROT_WRITE = 0x02 // pages can be written
|
||||
PROT_EXEC = 0x04 // pages can be executed
|
||||
|
||||
MAP_SHARED = 0x0001 // share changes
|
||||
MAP_PRIVATE = 0x0002 // changes are private
|
||||
|
||||
MAP_FILE = 0x0000 // map from file (default)
|
||||
MAP_ANON = 0x1000 // allocated from memory, swap space
|
||||
MAP_ANONYMOUS = MAP_ANON
|
||||
)
|
||||
|
||||
type Timespec struct {
|
||||
Sec int64
|
||||
Nsec int64
|
||||
}
|
||||
|
||||
// Unix returns the time stored in ts as seconds plus nanoseconds.
|
||||
func (ts *Timespec) Unix() (sec int64, nsec int64) {
|
||||
return int64(ts.Sec), int64(ts.Nsec)
|
||||
}
|
||||
|
||||
// Source: upstream ztypes_darwin_amd64.go
|
||||
type Dirent struct {
|
||||
Ino uint64
|
||||
Seekoff uint64
|
||||
Reclen uint16
|
||||
Namlen uint16
|
||||
Type uint8
|
||||
Name [1024]int8
|
||||
Pad_cgo_0 [3]byte
|
||||
}
|
||||
|
||||
type Stat_t struct {
|
||||
Dev int32
|
||||
Mode uint16
|
||||
Nlink uint16
|
||||
Ino uint64
|
||||
Uid uint32
|
||||
Gid uint32
|
||||
Rdev int32
|
||||
Pad_cgo_0 [4]byte
|
||||
Atimespec Timespec
|
||||
Mtimespec Timespec
|
||||
Ctimespec Timespec
|
||||
Btimespec Timespec
|
||||
Size int64
|
||||
Blocks int64
|
||||
Blksize int32
|
||||
Flags uint32
|
||||
Gen uint32
|
||||
Lspare int32
|
||||
Qspare [2]int64
|
||||
}
|
||||
|
||||
// Source: https://github.com/apple/darwin-xnu/blob/main/bsd/sys/_types/_s_ifmt.h
|
||||
const (
|
||||
S_IEXEC = 0x40
|
||||
S_IFBLK = 0x6000
|
||||
S_IFCHR = 0x2000
|
||||
S_IFDIR = 0x4000
|
||||
S_IFIFO = 0x1000
|
||||
S_IFLNK = 0xa000
|
||||
S_IFMT = 0xf000
|
||||
S_IFREG = 0x8000
|
||||
S_IFSOCK = 0xc000
|
||||
S_IFWHT = 0xe000
|
||||
S_IREAD = 0x100
|
||||
S_IRGRP = 0x20
|
||||
S_IROTH = 0x4
|
||||
S_IRUSR = 0x100
|
||||
S_IRWXG = 0x38
|
||||
S_IRWXO = 0x7
|
||||
S_IRWXU = 0x1c0
|
||||
S_ISGID = 0x400
|
||||
S_ISTXT = 0x200
|
||||
S_ISUID = 0x800
|
||||
S_ISVTX = 0x200
|
||||
S_IWGRP = 0x10
|
||||
S_IWOTH = 0x2
|
||||
S_IWRITE = 0x80
|
||||
S_IWUSR = 0x80
|
||||
S_IXGRP = 0x8
|
||||
S_IXOTH = 0x1
|
||||
S_IXUSR = 0x40
|
||||
)
|
||||
|
||||
func Stat(path string, p *Stat_t) (err error) {
|
||||
data := cstring(path)
|
||||
n := libc_stat(&data[0], unsafe.Pointer(p))
|
||||
|
||||
if n < 0 {
|
||||
err = getErrno()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Fstat(fd int, p *Stat_t) (err error) {
|
||||
n := libc_fstat(int32(fd), unsafe.Pointer(p))
|
||||
|
||||
if n < 0 {
|
||||
err = getErrno()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Lstat(path string, p *Stat_t) (err error) {
|
||||
data := cstring(path)
|
||||
n := libc_lstat(&data[0], unsafe.Pointer(p))
|
||||
if n < 0 {
|
||||
err = getErrno()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Fdopendir(fd int) (dir uintptr, err error) {
|
||||
r0 := libc_fdopendir(int32(fd))
|
||||
dir = uintptr(r0)
|
||||
if dir == 0 {
|
||||
err = getErrno()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Pipe2(fds []int, flags int) (err error) {
|
||||
// Mac only has Pipe, which ignores the flags argument
|
||||
buf := make([]int32, 2)
|
||||
fail := int(libc_pipe(&buf[0]))
|
||||
if fail < 0 {
|
||||
err = getErrno()
|
||||
} else {
|
||||
fds[0] = int(buf[0])
|
||||
fds[1] = int(buf[1])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Chmod(path string, mode uint32) (err error) {
|
||||
data := cstring(path)
|
||||
fail := int(libc_chmod(&data[0], mode))
|
||||
if fail < 0 {
|
||||
err = getErrno()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func closedir(dir uintptr) (err error) {
|
||||
e := libc_closedir(unsafe.Pointer(dir))
|
||||
if e != 0 {
|
||||
err = getErrno()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func readdir_r(dir uintptr, entry *Dirent, result **Dirent) (err error) {
|
||||
e1 := libc_readdir_r(unsafe.Pointer(dir), unsafe.Pointer(entry), unsafe.Pointer(result))
|
||||
if e1 != 0 {
|
||||
err = getErrno()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Getpagesize() int {
|
||||
return int(libc_getpagesize())
|
||||
}
|
||||
|
||||
// The following RawSockAddr* types have been copied from the Go source tree and
|
||||
// are here purely to fix build errors.
|
||||
|
||||
type RawSockaddr struct {
|
||||
Len uint8
|
||||
Family uint8
|
||||
Data [14]int8
|
||||
}
|
||||
|
||||
type RawSockaddrInet4 struct {
|
||||
Len uint8
|
||||
Family uint8
|
||||
Port uint16
|
||||
Addr [4]byte /* in_addr */
|
||||
Zero [8]int8
|
||||
}
|
||||
|
||||
type RawSockaddrInet6 struct {
|
||||
Len uint8
|
||||
Family uint8
|
||||
Port uint16
|
||||
Flowinfo uint32
|
||||
Addr [16]byte /* in6_addr */
|
||||
Scope_id uint32
|
||||
}
|
||||
|
||||
// int pipe(int32 *fds);
|
||||
//
|
||||
//export pipe
|
||||
func libc_pipe(fds *int32) int32
|
||||
|
||||
// int getpagesize();
|
||||
//
|
||||
//export getpagesize
|
||||
func libc_getpagesize() int32
|
||||
|
||||
// int open(const char *pathname, int flags, mode_t mode);
|
||||
//
|
||||
//export syscall_libc_open
|
||||
func libc_open(pathname *byte, flags int32, mode uint32) int32
|
||||
@@ -1,43 +0,0 @@
|
||||
//go:build darwin
|
||||
|
||||
package syscall
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// The odd $INODE64 suffix is an Apple compatibility feature, see
|
||||
// __DARWIN_INODE64 in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h
|
||||
// and https://assert.cc/posts/darwin_use_64_bit_inode_vs_ctypes/
|
||||
// Without it, you get the old, smaller struct stat from mac os 10.2 or so.
|
||||
// It not needed on arm64.
|
||||
|
||||
// struct DIR * buf fdopendir(int fd);
|
||||
//
|
||||
//export fdopendir$INODE64
|
||||
func libc_fdopendir(fd int32) unsafe.Pointer
|
||||
|
||||
// int closedir(struct DIR * buf);
|
||||
//
|
||||
//export closedir
|
||||
func libc_closedir(unsafe.Pointer) int32
|
||||
|
||||
// int readdir_r(struct DIR * buf, struct dirent *entry, struct dirent **result);
|
||||
//
|
||||
//export readdir_r$INODE64
|
||||
func libc_readdir_r(unsafe.Pointer, unsafe.Pointer, unsafe.Pointer) int32
|
||||
|
||||
// int stat(const char *path, struct stat * buf);
|
||||
//
|
||||
//export stat$INODE64
|
||||
func libc_stat(pathname *byte, ptr unsafe.Pointer) int32
|
||||
|
||||
// int fstat(int fd, struct stat * buf);
|
||||
//
|
||||
//export fstat$INODE64
|
||||
func libc_fstat(fd int32, ptr unsafe.Pointer) int32
|
||||
|
||||
// int lstat(const char *path, struct stat * buf);
|
||||
//
|
||||
//export lstat$INODE64
|
||||
func libc_lstat(pathname *byte, ptr unsafe.Pointer) int32
|
||||
@@ -1,37 +0,0 @@
|
||||
//go:build darwin
|
||||
|
||||
package syscall
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// struct DIR * buf fdopendir(int fd);
|
||||
//
|
||||
//export fdopendir
|
||||
func libc_fdopendir(fd int32) unsafe.Pointer
|
||||
|
||||
// int closedir(struct DIR * buf);
|
||||
//
|
||||
//export closedir
|
||||
func libc_closedir(unsafe.Pointer) int32
|
||||
|
||||
// int readdir_r(struct DIR * buf, struct dirent *entry, struct dirent **result);
|
||||
//
|
||||
//export readdir_r
|
||||
func libc_readdir_r(unsafe.Pointer, unsafe.Pointer, unsafe.Pointer) int32
|
||||
|
||||
// int stat(const char *path, struct stat * buf);
|
||||
//
|
||||
//export stat
|
||||
func libc_stat(pathname *byte, ptr unsafe.Pointer) int32
|
||||
|
||||
// int fstat(int fd, struct stat * buf);
|
||||
//
|
||||
//export fstat
|
||||
func libc_fstat(fd int32, ptr unsafe.Pointer) int32
|
||||
|
||||
// int lstat(const char *path, struct stat * buf);
|
||||
//
|
||||
//export lstat
|
||||
func libc_lstat(pathname *byte, ptr unsafe.Pointer) int32
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"inherits": ["nrf52840", "nrf52840-s140v6-uf2"],
|
||||
"build-tags": ["rak4631"],
|
||||
"serial-port": ["239a:8029"],
|
||||
"msd-volume-name": ["RAK4631"]
|
||||
}
|
||||
+2
-1
@@ -17,7 +17,8 @@
|
||||
],
|
||||
"ldflags": [
|
||||
"--stack-first",
|
||||
"--no-demangle"
|
||||
"--no-demangle",
|
||||
"--no-entry"
|
||||
],
|
||||
"extra-files": [
|
||||
"src/runtime/asm_tinygowasm.S"
|
||||
|
||||
Vendored
+16
@@ -86,6 +86,10 @@ func main() {
|
||||
testCond()
|
||||
|
||||
testIssue1790()
|
||||
|
||||
done := make(chan int)
|
||||
go testPaddedParameters(paddedStruct{x: 5, y: 7}, done)
|
||||
<-done
|
||||
}
|
||||
|
||||
func acquire(m *sync.Mutex) {
|
||||
@@ -243,3 +247,15 @@ func (f Foo) Wait() {
|
||||
time.Sleep(time.Microsecond)
|
||||
println(" ...waited")
|
||||
}
|
||||
|
||||
type paddedStruct struct {
|
||||
x uint8
|
||||
_ [0]int64
|
||||
y uint8
|
||||
}
|
||||
|
||||
// Structs with interesting padding used to crash.
|
||||
func testPaddedParameters(s paddedStruct, done chan int) {
|
||||
println("paddedStruct:", s.x, s.y)
|
||||
close(done)
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -26,3 +26,4 @@ called: Foo.Nowait
|
||||
called: Foo.Wait
|
||||
...waited
|
||||
done with 'go on interface'
|
||||
paddedStruct: 5 7
|
||||
|
||||
Reference in New Issue
Block a user