compiler: always use fat function pointers with context

This reduces complexity in the compiler without affecting binary sizes
too much.

Cortex-M0:   no changes
Linux x64:   no changes
WebAssembly: some testcases (calls, coroutines, map) are slightly bigger
This commit is contained in:
Ayke van Laethem
2018-12-09 18:10:04 +01:00
parent 3fec22e819
commit 564b1b3312
12 changed files with 125 additions and 246 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ package runtime
// trap is a compiler hint that this function cannot be executed. It is
// translated into either a trap instruction or a call to abort().
//go:linkname trap llvm.trap
//go:export llvm.trap
func trap()
// Builtin function panic(msg), used as a compiler intrinsic.
+18 -14
View File
@@ -6,16 +6,25 @@ import (
"unsafe"
)
func _Cfunc_putchar(c int) int
func _Cfunc_usleep(usec uint) int
func _Cfunc_malloc(size uintptr) unsafe.Pointer
func _Cfunc_abort()
func _Cfunc_clock_gettime(clk_id uint, ts *timespec)
//go:export putchar
func _putchar(c int) int
//go:export usleep
func usleep(usec uint) int
//go:export malloc
func malloc(size uintptr) unsafe.Pointer
//go:export abort
func abort()
//go:export clock_gettime
func clock_gettime(clk_id uint, ts *timespec)
const heapSize = 1 * 1024 * 1024 // 1MB to start
var (
heapStart = uintptr(_Cfunc_malloc(heapSize))
heapStart = uintptr(malloc(heapSize))
heapEnd = heapStart + heapSize
)
@@ -45,11 +54,11 @@ func main() int {
}
func putchar(c byte) {
_Cfunc_putchar(int(c))
_putchar(int(c))
}
func sleepTicks(d timeUnit) {
_Cfunc_usleep(uint(d) / 1000)
usleep(uint(d) / 1000)
}
// Return monotonic time in nanoseconds.
@@ -57,15 +66,10 @@ func sleepTicks(d timeUnit) {
// TODO: noescape
func monotime() uint64 {
ts := timespec{}
_Cfunc_clock_gettime(CLOCK_MONOTONIC_RAW, &ts)
clock_gettime(CLOCK_MONOTONIC_RAW, &ts)
return uint64(ts.tv_sec)*1000*1000*1000 + uint64(ts.tv_nsec)
}
func ticks() timeUnit {
return timeUnit(monotime())
}
func abort() {
// panic() exits with exit code 2.
_Cfunc_abort()
}
+6 -6
View File
@@ -8,16 +8,16 @@ const tickMicros = 1
var timestamp timeUnit
// CommonWA: io_get_stdout
func _Cfunc_io_get_stdout() int32
//go:export io_get_stdout
func io_get_stdout() int32
// CommonWA: resource_write
func _Cfunc_resource_write(id int32, ptr *uint8, len int32) int32
//go:export resource_write
func resource_write(id int32, ptr *uint8, len int32) int32
var stdout int32
func init() {
stdout = _Cfunc_io_get_stdout()
stdout = io_get_stdout()
}
//go:export _start
@@ -32,7 +32,7 @@ func cwa_main() {
}
func putchar(c byte) {
_Cfunc_resource_write(stdout, &c, 1)
resource_write(stdout, &c, 1)
}
func sleepTicks(d timeUnit) {
+4 -4
View File
@@ -31,16 +31,16 @@ const schedulerDebug = false
// must not be used directly, it is meant to be used as an opaque *i8 in LLVM.
type coroutine uint8
//go:linkname resume llvm.coro.resume
//go:export llvm.coro.resume
func (t *coroutine) resume()
//go:linkname destroy llvm.coro.destroy
//go:export llvm.coro.destroy
func (t *coroutine) destroy()
//go:linkname done llvm.coro.done
//go:export llvm.coro.done
func (t *coroutine) done() bool
//go:linkname _promise llvm.coro.promise
//go:export llvm.coro.promise
func (t *coroutine) _promise(alignment int32, from bool) unsafe.Pointer
// Get the promise belonging to a task.