Files
tinygo/src/runtime/runtime_wasm.go
T
Ayke van Laethem 611bca39ab all: rename 'arm' to 'tinygo.arm' for Cortex-M
Let the standard library think that it is compiling for js/wasm.

The most correct way of supporting bare metal Cortex-M targets would be
using the 'arm' build tag and specifying no OS or an 'undefined' OS
(perhaps GOOS=noos?). However, there is no build tag for specifying no
OS at all, the closest possible is GOOS=js which makes very few
assumptions.

Sadly GOOS=js also makes some assumptions: it assumes to be running with
GOARCH=wasm. This would not be such a problem, just add js, wasm and arm
as build tags. However, having two GOARCH build tags leads to an error
in internal/cpu: it defines variables for both architectures which then
conflict.

To work around these problems, the 'arm' target has been renamed to
'tinygo.arm', which should work around these problems. In the future, a
GOOS=noos (or similar) should be added which can work with any
architecture and doesn't implement OS-specific stuff.
2018-11-09 11:50:38 +01:00

56 lines
894 B
Go

// +build wasm,!tinygo.arm,!avr
package runtime
type timeUnit int64
const tickMicros = 1
var timestamp timeUnit
// CommonWA: io_get_stdout
func _Cfunc_io_get_stdout() int32
// CommonWA: resource_write
func _Cfunc_resource_write(id int32, ptr *uint8, len int32) int32
var stdout int32
func init() {
stdout = _Cfunc_io_get_stdout()
}
//go:export _start
func _start() {
initAll()
}
//go:export cwa_main
func cwa_main() {
initAll() // _start is not called by olin/cwa so has to be called here
mainWrapper()
}
func putchar(c byte) {
_Cfunc_resource_write(stdout, &c, 1)
}
func sleepTicks(d timeUnit) {
// TODO: actually sleep here for the given time.
timestamp += d
}
func ticks() timeUnit {
return timestamp
}
// Align on word boundary.
func align(ptr uintptr) uintptr {
return (ptr + 3) &^ 3
}
// Abort executes the wasm 'unreachable' instruction.
func abort() {
trap()
}