runtime, targets: some WIP on wasm unknown in part from PR #3072
Signed-off-by: deadprogram <ron@hybridgroup.com>
Этот коммит содержится в:
		
							родитель
							
								
									828b9614c2
								
							
						
					
					
						коммит
						186018abeb
					
				
					 8 изменённых файлов: 129 добавлений и 5 удалений
				
			
		| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
//go:build linux && !baremetal && !nintendoswitch && !wasi
 | 
			
		||||
//go:build linux && !baremetal && !nintendoswitch && !wasi && !wasm_unknown
 | 
			
		||||
 | 
			
		||||
package runtime
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
//go:build linux && (baremetal || nintendoswitch || wasi)
 | 
			
		||||
//go:build linux && (baremetal || nintendoswitch || wasi || wasm_unknown)
 | 
			
		||||
 | 
			
		||||
// Other systems that aren't operating systems supported by the Go toolchain
 | 
			
		||||
// need to pretend to be an existing operating system. Linux seems like a good
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
//go:build tinygo.wasm
 | 
			
		||||
//go:build tinygo.wasm && !wasm_unknown
 | 
			
		||||
 | 
			
		||||
package runtime
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										50
									
								
								src/runtime/runtime_tinygowasm_unknown.go
									
										
									
									
									
										Обычный файл
									
								
							
							
						
						
									
										50
									
								
								src/runtime/runtime_tinygowasm_unknown.go
									
										
									
									
									
										Обычный файл
									
								
							| 
						 | 
				
			
			@ -0,0 +1,50 @@
 | 
			
		|||
//go:build wasm_unknown
 | 
			
		||||
 | 
			
		||||
package runtime
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	stdout = 1
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func putchar(c byte) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getchar() byte {
 | 
			
		||||
	// dummy, TODO
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func buffered() int {
 | 
			
		||||
	// dummy, TODO
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//go:linkname now time.now
 | 
			
		||||
func now() (sec int64, nsec int32, mono int64) {
 | 
			
		||||
	return 0, 0, 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Abort executes the wasm 'unreachable' instruction.
 | 
			
		||||
func abort() {
 | 
			
		||||
	trap()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//go:linkname syscall_Exit syscall.Exit
 | 
			
		||||
func syscall_Exit(code int) {
 | 
			
		||||
	//proc_exit(uint32(code))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TinyGo does not yet support any form of parallelism on WebAssembly, so these
 | 
			
		||||
// can be left empty.
 | 
			
		||||
 | 
			
		||||
//go:linkname procPin sync/atomic.runtime_procPin
 | 
			
		||||
func procPin() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//go:linkname procUnpin sync/atomic.runtime_procUnpin
 | 
			
		||||
func procUnpin() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hardwareRand() (n uint64, ok bool) {
 | 
			
		||||
	return 0, false
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
//go:build (darwin || (linux && !baremetal && !wasi)) && !nintendoswitch
 | 
			
		||||
//go:build (darwin || (linux && !baremetal && !wasi && !wasm_unknown)) && !nintendoswitch
 | 
			
		||||
 | 
			
		||||
package runtime
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
//go:build wasm && !wasi && !scheduler.none && !wasip1
 | 
			
		||||
//go:build wasm && !wasi && !scheduler.none && !wasip1 && !wasm_unknown
 | 
			
		||||
 | 
			
		||||
package runtime
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										49
									
								
								src/runtime/runtime_wasm_unknown.go
									
										
									
									
									
										Обычный файл
									
								
							
							
						
						
									
										49
									
								
								src/runtime/runtime_wasm_unknown.go
									
										
									
									
									
										Обычный файл
									
								
							| 
						 | 
				
			
			@ -0,0 +1,49 @@
 | 
			
		|||
//go:build wasm_unknown
 | 
			
		||||
 | 
			
		||||
package runtime
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"unsafe"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type timeUnit int64
 | 
			
		||||
 | 
			
		||||
// libc constructors
 | 
			
		||||
//
 | 
			
		||||
//export __wasm_call_ctors
 | 
			
		||||
func __wasm_call_ctors()
 | 
			
		||||
 | 
			
		||||
//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()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Read the command line arguments from WASI.
 | 
			
		||||
// For example, they can be passed to a program with wasmtime like this:
 | 
			
		||||
//
 | 
			
		||||
//	wasmtime run ./program.wasm arg1 arg2
 | 
			
		||||
func init() {
 | 
			
		||||
	__wasm_call_ctors()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var args []string
 | 
			
		||||
 | 
			
		||||
func ticksToNanoseconds(ticks timeUnit) int64 {
 | 
			
		||||
	return int64(ticks)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func nanosecondsToTicks(ns int64) timeUnit {
 | 
			
		||||
	return timeUnit(ns)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const timePrecisionNanoseconds = 1000 // TODO: how can we determine the appropriate `precision`?
 | 
			
		||||
 | 
			
		||||
func sleepTicks(d timeUnit) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ticks() timeUnit {
 | 
			
		||||
	return timeUnit(0)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										25
									
								
								targets/wasm-unknown.json
									
										
									
									
									
										Обычный файл
									
								
							
							
						
						
									
										25
									
								
								targets/wasm-unknown.json
									
										
									
									
									
										Обычный файл
									
								
							| 
						 | 
				
			
			@ -0,0 +1,25 @@
 | 
			
		|||
{
 | 
			
		||||
	"llvm-target":   "wasm32-unknown-unknown",
 | 
			
		||||
	"cpu":           "generic",
 | 
			
		||||
	"features":      "+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext",
 | 
			
		||||
	"build-tags":    ["tinygo.wasm", "wasm_unknown"],
 | 
			
		||||
	"goos":          "linux",
 | 
			
		||||
	"goarch":        "arm",
 | 
			
		||||
	"linker":        "wasm-ld",
 | 
			
		||||
	"rtlib":         "compiler-rt",
 | 
			
		||||
	"scheduler":     "none",
 | 
			
		||||
	"default-stack-size": 4096,
 | 
			
		||||
	"cflags": [
 | 
			
		||||
		"-mbulk-memory",
 | 
			
		||||
		"-mnontrapping-fptoint",
 | 
			
		||||
		"-msign-ext"
 | 
			
		||||
	],
 | 
			
		||||
	"ldflags": [
 | 
			
		||||
		"--no-demangle",
 | 
			
		||||
		"--no-entry"
 | 
			
		||||
	],
 | 
			
		||||
	"extra-files": [
 | 
			
		||||
		"src/runtime/asm_tinygowasm.S"
 | 
			
		||||
	],
 | 
			
		||||
	"emulator":      "wasmtime --dir={tmpDir}::/tmp {}"
 | 
			
		||||
}
 | 
			
		||||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче