all: change //go:export to //export
This is the kind that is used in Go (actually CGo) for exporting functions. I think it's best to use //export instead of our custom //go:export pragma, for consistency (they are equivalent in TinyGo). Therefore I've updated all instances to the standard format (except for two that are updated in https://github.com/tinygo-org/tinygo/pull/1024). No smoke tests changed (when comparing the output hash), except for some wasm tests that include DWARF debug info and tend to be flaky anyway.
Этот коммит содержится в:
		
							родитель
							
								
									46345aade6
								
							
						
					
					
						коммит
						cbaa58a2d9
					
				
					 23 изменённых файлов: 51 добавлений и 51 удалений
				
			
		|  | @ -17,7 +17,7 @@ func main() { | ||||||
| 
 | 
 | ||||||
| var led_state bool | var led_state bool | ||||||
| 
 | 
 | ||||||
| //go:export SysTick_Handler | //export SysTick_Handler | ||||||
| func timer_isr() { | func timer_isr() { | ||||||
| 	if led_state { | 	if led_state { | ||||||
| 		machine.LED.Low() | 		machine.LED.Low() | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| The examples here show two different ways of using WebAssembly with TinyGo: | The examples here show two different ways of using WebAssembly with TinyGo: | ||||||
| 
 | 
 | ||||||
| 1. Defining and exporting functions via the `//go:export <name>` directive. See | 1. Defining and exporting functions via the `//export <name>` directive. See | ||||||
| [the export folder](./export) for an example of this.  Additionally, the Wasm | [the export folder](./export) for an example of this.  Additionally, the Wasm | ||||||
| module (which has a default value of `env`) can be specified using | module (which has a default value of `env`) can be specified using | ||||||
| `//go:wasm-module <module>`. | `//go:wasm-module <module>`. | ||||||
|  |  | ||||||
|  | @ -8,12 +8,12 @@ import ( | ||||||
| func main() { | func main() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export add | //export add | ||||||
| func add(a, b int) int { | func add(a, b int) int { | ||||||
| 	return a + b | 	return a + b | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export update | //export update | ||||||
| func update() { | func update() { | ||||||
| 	document := js.Global().Get("document") | 	document := js.Global().Get("document") | ||||||
| 	aStr := document.Call("getElementById", "a").Get("value").String() | 	aStr := document.Call("getElementById", "a").Get("value").String() | ||||||
|  |  | ||||||
|  | @ -10,12 +10,12 @@ import ( | ||||||
| // This matches *i8 in LLVM. | // This matches *i8 in LLVM. | ||||||
| type rawState uint8 | type rawState uint8 | ||||||
| 
 | 
 | ||||||
| //go:export llvm.coro.resume | //export llvm.coro.resume | ||||||
| func (s *rawState) resume() | func (s *rawState) resume() | ||||||
| 
 | 
 | ||||||
| type state struct{ *rawState } | type state struct{ *rawState } | ||||||
| 
 | 
 | ||||||
| //go:export llvm.coro.noop | //export llvm.coro.noop | ||||||
| func noopState() *rawState | func noopState() *rawState | ||||||
| 
 | 
 | ||||||
| // Resume the task until it pauses or completes. | // Resume the task until it pauses or completes. | ||||||
|  |  | ||||||
|  | @ -31,13 +31,13 @@ func (p Pin) Get() bool { | ||||||
| 	return gpioGet(p) | 	return gpioGet(p) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_gpio_configure | //export __tinygo_gpio_configure | ||||||
| func gpioConfigure(pin Pin, config PinConfig) | func gpioConfigure(pin Pin, config PinConfig) | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_gpio_set | //export __tinygo_gpio_set | ||||||
| func gpioSet(pin Pin, value bool) | func gpioSet(pin Pin, value bool) | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_gpio_get | //export __tinygo_gpio_get | ||||||
| func gpioGet(pin Pin) bool | func gpioGet(pin Pin) bool | ||||||
| 
 | 
 | ||||||
| type SPI struct { | type SPI struct { | ||||||
|  | @ -61,10 +61,10 @@ func (spi SPI) Transfer(w byte) (byte, error) { | ||||||
| 	return spiTransfer(spi.Bus, w), nil | 	return spiTransfer(spi.Bus, w), nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_spi_configure | //export __tinygo_spi_configure | ||||||
| func spiConfigure(bus uint8, sck Pin, mosi Pin, miso Pin) | func spiConfigure(bus uint8, sck Pin, mosi Pin, miso Pin) | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_spi_transfer | //export __tinygo_spi_transfer | ||||||
| func spiTransfer(bus uint8, w uint8) uint8 | func spiTransfer(bus uint8, w uint8) uint8 | ||||||
| 
 | 
 | ||||||
| // InitADC enables support for ADC peripherals. | // InitADC enables support for ADC peripherals. | ||||||
|  | @ -81,7 +81,7 @@ func (adc ADC) Get() uint16 { | ||||||
| 	return adcRead(adc.Pin) | 	return adcRead(adc.Pin) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_adc_read | //export __tinygo_adc_read | ||||||
| func adcRead(pin Pin) uint16 | func adcRead(pin Pin) uint16 | ||||||
| 
 | 
 | ||||||
| // InitPWM enables support for PWM peripherals. | // InitPWM enables support for PWM peripherals. | ||||||
|  | @ -98,7 +98,7 @@ func (pwm PWM) Set(value uint16) { | ||||||
| 	pwmSet(pwm.Pin, value) | 	pwmSet(pwm.Pin, value) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_pwm_set | //export __tinygo_pwm_set | ||||||
| func pwmSet(pin Pin, value uint16) | func pwmSet(pin Pin, value uint16) | ||||||
| 
 | 
 | ||||||
| // I2C is a generic implementation of the Inter-IC communication protocol. | // I2C is a generic implementation of the Inter-IC communication protocol. | ||||||
|  | @ -125,10 +125,10 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error { | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_i2c_configure | //export __tinygo_i2c_configure | ||||||
| func i2cConfigure(bus uint8, scl Pin, sda Pin) | func i2cConfigure(bus uint8, scl Pin, sda Pin) | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_i2c_transfer | //export __tinygo_i2c_transfer | ||||||
| func i2cTransfer(bus uint8, w *byte, wlen int, r *byte, rlen int) int | func i2cTransfer(bus uint8, w *byte, wlen int, r *byte, rlen int) int | ||||||
| 
 | 
 | ||||||
| type UART struct { | type UART struct { | ||||||
|  | @ -174,11 +174,11 @@ func (uart UART) WriteByte(b byte) error { | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_uart_configure | //export __tinygo_uart_configure | ||||||
| func uartConfigure(bus uint8, tx Pin, rx Pin) | func uartConfigure(bus uint8, tx Pin, rx Pin) | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_uart_read | //export __tinygo_uart_read | ||||||
| func uartRead(bus uint8, buf *byte, bufLen int) int | func uartRead(bus uint8, buf *byte, bufLen int) int | ||||||
| 
 | 
 | ||||||
| //go:export __tinygo_uart_write | //export __tinygo_uart_write | ||||||
| func uartWrite(bus uint8, buf *byte, bufLen int) int | func uartWrite(bus uint8, buf *byte, bufLen int) int | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ const TargetBits = 32 | ||||||
| //go:extern __heap_base | //go:extern __heap_base | ||||||
| var heapStartSymbol [0]byte | var heapStartSymbol [0]byte | ||||||
| 
 | 
 | ||||||
| //go:export llvm.wasm.memory.size.i32 | //export llvm.wasm.memory.size.i32 | ||||||
| func wasm_memory_size(index int32) int32 | func wasm_memory_size(index int32) int32 | ||||||
| 
 | 
 | ||||||
| var ( | var ( | ||||||
|  |  | ||||||
|  | @ -63,7 +63,7 @@ func math_Ceil(x float64) float64 { | ||||||
| 	return math_ceil(x) | 	return math_ceil(x) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export llvm.ceil.f64 | //export llvm.ceil.f64 | ||||||
| func llvm_ceil(x float64) float64 | func llvm_ceil(x float64) float64 | ||||||
| 
 | 
 | ||||||
| //go:linkname math_ceil math.ceil | //go:linkname math_ceil math.ceil | ||||||
|  | @ -119,7 +119,7 @@ func math_Floor(x float64) float64 { | ||||||
| 	return math_floor(x) | 	return math_floor(x) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export llvm.floor.f64 | //export llvm.floor.f64 | ||||||
| func llvm_floor(x float64) float64 | func llvm_floor(x float64) float64 | ||||||
| 
 | 
 | ||||||
| //go:linkname math_floor math.floor | //go:linkname math_floor math.floor | ||||||
|  | @ -175,7 +175,7 @@ func math_Max(x, y float64) float64 { | ||||||
| 	return math_max(x, y) | 	return math_max(x, y) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export llvm.maximum.f64 | //export llvm.maximum.f64 | ||||||
| func llvm_maximum(x, y float64) float64 | func llvm_maximum(x, y float64) float64 | ||||||
| 
 | 
 | ||||||
| //go:linkname math_max math.max | //go:linkname math_max math.max | ||||||
|  | @ -189,7 +189,7 @@ func math_Min(x, y float64) float64 { | ||||||
| 	return math_min(x, y) | 	return math_min(x, y) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export llvm.minimum.f64 | //export llvm.minimum.f64 | ||||||
| func llvm_minimum(x, y float64) float64 | func llvm_minimum(x, y float64) float64 | ||||||
| 
 | 
 | ||||||
| //go:linkname math_min math.min | //go:linkname math_min math.min | ||||||
|  | @ -239,7 +239,7 @@ func math_Sqrt(x float64) float64 { | ||||||
| 	return math_sqrt(x) | 	return math_sqrt(x) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export llvm.sqrt.f64 | //export llvm.sqrt.f64 | ||||||
| func llvm_sqrt(x float64) float64 | func llvm_sqrt(x float64) float64 | ||||||
| 
 | 
 | ||||||
| //go:linkname math_sqrt math.sqrt | //go:linkname math_sqrt math.sqrt | ||||||
|  | @ -265,7 +265,7 @@ func math_Trunc(x float64) float64 { | ||||||
| 	return math_trunc(x) | 	return math_trunc(x) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export llvm.trunc.f64 | //export llvm.trunc.f64 | ||||||
| func llvm_trunc(x float64) float64 | func llvm_trunc(x float64) float64 | ||||||
| 
 | 
 | ||||||
| //go:linkname math_trunc math.trunc | //go:linkname math_trunc math.trunc | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ package runtime | ||||||
| 
 | 
 | ||||||
| // trap is a compiler hint that this function cannot be executed. It is | // trap is a compiler hint that this function cannot be executed. It is | ||||||
| // translated into either a trap instruction or a call to abort(). | // translated into either a trap instruction or a call to abort(). | ||||||
| //go:export llvm.trap | //export llvm.trap | ||||||
| func trap() | func trap() | ||||||
| 
 | 
 | ||||||
| // Builtin function panic(msg), used as a compiler intrinsic. | // Builtin function panic(msg), used as a compiler intrinsic. | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ var _edata [0]byte | ||||||
| func postinit() {} | func postinit() {} | ||||||
| 
 | 
 | ||||||
| // Entry point for Go. Initialize all packages and call main.main(). | // Entry point for Go. Initialize all packages and call main.main(). | ||||||
| //go:export main | //export main | ||||||
| func main() { | func main() { | ||||||
| 	// Initialize .data and .bss sections. | 	// Initialize .data and .bss sections. | ||||||
| 	preinit() | 	preinit() | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ type timeUnit int64 | ||||||
| 
 | 
 | ||||||
| func postinit() {} | func postinit() {} | ||||||
| 
 | 
 | ||||||
| //go:export Reset_Handler | //export Reset_Handler | ||||||
| func main() { | func main() { | ||||||
| 	preinit() | 	preinit() | ||||||
| 	run() | 	run() | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ type timeUnit int64 | ||||||
| 
 | 
 | ||||||
| func postinit() {} | func postinit() {} | ||||||
| 
 | 
 | ||||||
| //go:export Reset_Handler | //export Reset_Handler | ||||||
| func main() { | func main() { | ||||||
| 	preinit() | 	preinit() | ||||||
| 	run() | 	run() | ||||||
|  |  | ||||||
|  | @ -36,7 +36,7 @@ var _sbss [0]byte | ||||||
| //go:extern _ebss | //go:extern _ebss | ||||||
| var _ebss [0]byte | var _ebss [0]byte | ||||||
| 
 | 
 | ||||||
| //go:export main | //export main | ||||||
| func main() { | func main() { | ||||||
| 	preinit() | 	preinit() | ||||||
| 	run() | 	run() | ||||||
|  |  | ||||||
|  | @ -74,7 +74,7 @@ type interruptStack struct { | ||||||
| // For details, see: | // For details, see: | ||||||
| // https://community.arm.com/developer/ip-products/system/f/embedded-forum/3257/debugging-a-cortex-m0-hard-fault | // https://community.arm.com/developer/ip-products/system/f/embedded-forum/3257/debugging-a-cortex-m0-hard-fault | ||||||
| // https://blog.feabhas.com/2013/02/developing-a-generic-hard-fault-handler-for-arm-cortex-m3cortex-m4/ | // https://blog.feabhas.com/2013/02/developing-a-generic-hard-fault-handler-for-arm-cortex-m3cortex-m4/ | ||||||
| //go:export handleHardFault | //export handleHardFault | ||||||
| func handleHardFault(sp *interruptStack) { | func handleHardFault(sp *interruptStack) { | ||||||
| 	print("fatal error: ") | 	print("fatal error: ") | ||||||
| 	if uintptr(unsafe.Pointer(sp)) < 0x20000000 { | 	if uintptr(unsafe.Pointer(sp)) < 0x20000000 { | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ var timestamp timeUnit | ||||||
| 
 | 
 | ||||||
| func postinit() {} | func postinit() {} | ||||||
| 
 | 
 | ||||||
| //go:export Reset_Handler | //export Reset_Handler | ||||||
| func main() { | func main() { | ||||||
| 	preinit() | 	preinit() | ||||||
| 	run() | 	run() | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ type timeUnit int64 | ||||||
| 
 | 
 | ||||||
| func postinit() {} | func postinit() {} | ||||||
| 
 | 
 | ||||||
| //go:export main | //export main | ||||||
| func main() { | func main() { | ||||||
| 	// Zero the PLIC enable bits on startup: they are not zeroed at reset. | 	// Zero the PLIC enable bits on startup: they are not zeroed at reset. | ||||||
| 	sifive.PLIC.ENABLE[0].Set(0) | 	sifive.PLIC.ENABLE[0].Set(0) | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ func systemInit() | ||||||
| 
 | 
 | ||||||
| func postinit() {} | func postinit() {} | ||||||
| 
 | 
 | ||||||
| //go:export Reset_Handler | //export Reset_Handler | ||||||
| func main() { | func main() { | ||||||
| 	systemInit() | 	systemInit() | ||||||
| 	preinit() | 	preinit() | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ type timeUnit int64 | ||||||
| 
 | 
 | ||||||
| func postinit() {} | func postinit() {} | ||||||
| 
 | 
 | ||||||
| //go:export Reset_Handler | //export Reset_Handler | ||||||
| func main() { | func main() { | ||||||
| 	preinit() | 	preinit() | ||||||
| 	run() | 	run() | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ var timestamp timeUnit | ||||||
| 
 | 
 | ||||||
| func postinit() {} | func postinit() {} | ||||||
| 
 | 
 | ||||||
| //go:export main | //export main | ||||||
| func main() { | func main() { | ||||||
| 	preinit() | 	preinit() | ||||||
| 	run() | 	run() | ||||||
|  |  | ||||||
|  | @ -6,22 +6,22 @@ import ( | ||||||
| 	"unsafe" | 	"unsafe" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| //go:export putchar | //export putchar | ||||||
| func _putchar(c int) int | func _putchar(c int) int | ||||||
| 
 | 
 | ||||||
| //go:export usleep | //export usleep | ||||||
| func usleep(usec uint) int | func usleep(usec uint) int | ||||||
| 
 | 
 | ||||||
| //go:export malloc | //export malloc | ||||||
| func malloc(size uintptr) unsafe.Pointer | func malloc(size uintptr) unsafe.Pointer | ||||||
| 
 | 
 | ||||||
| //go:export abort | //export abort | ||||||
| func abort() | func abort() | ||||||
| 
 | 
 | ||||||
| //go:export exit | //export exit | ||||||
| func exit(code int) | func exit(code int) | ||||||
| 
 | 
 | ||||||
| //go:export clock_gettime | //export clock_gettime | ||||||
| func clock_gettime(clk_id int32, ts *timespec) | func clock_gettime(clk_id int32, ts *timespec) | ||||||
| 
 | 
 | ||||||
| type timeUnit int64 | type timeUnit int64 | ||||||
|  | @ -41,7 +41,7 @@ const CLOCK_MONOTONIC_RAW = 4 | ||||||
| func postinit() {} | func postinit() {} | ||||||
| 
 | 
 | ||||||
| // Entry point for Go. Initialize all packages and call main.main(). | // Entry point for Go. Initialize all packages and call main.main(). | ||||||
| //go:export main | //export main | ||||||
| func main() int { | func main() int { | ||||||
| 	preinit() | 	preinit() | ||||||
| 
 | 
 | ||||||
|  | @ -83,5 +83,5 @@ func extalloc(size uintptr) unsafe.Pointer { | ||||||
| 	return malloc(size) | 	return malloc(size) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export free | //export free | ||||||
| func extfree(ptr unsafe.Pointer) | func extfree(ptr unsafe.Pointer) | ||||||
|  |  | ||||||
|  | @ -53,14 +53,14 @@ func setEventHandler(fn func()) { | ||||||
| 	handleEvent = fn | 	handleEvent = fn | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export resume | //export resume | ||||||
| func resume() { | func resume() { | ||||||
| 	go func() { | 	go func() { | ||||||
| 		handleEvent() | 		handleEvent() | ||||||
| 	}() | 	}() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export go_scheduler | //export go_scheduler | ||||||
| func go_scheduler() { | func go_scheduler() { | ||||||
| 	scheduler() | 	scheduler() | ||||||
| } | } | ||||||
|  | @ -69,10 +69,10 @@ const asyncScheduler = true | ||||||
| 
 | 
 | ||||||
| // This function is called by the scheduler. | // This function is called by the scheduler. | ||||||
| // Schedule a call to runtime.scheduler, do not actually sleep. | // Schedule a call to runtime.scheduler, do not actually sleep. | ||||||
| //go:export runtime.sleepTicks | //export runtime.sleepTicks | ||||||
| func sleepTicks(d timeUnit) | func sleepTicks(d timeUnit) | ||||||
| 
 | 
 | ||||||
| //go:export runtime.ticks | //export runtime.ticks | ||||||
| func ticks() timeUnit | func ticks() timeUnit | ||||||
| 
 | 
 | ||||||
| // Abort executes the wasm 'unreachable' instruction. | // Abort executes the wasm 'unreachable' instruction. | ||||||
|  |  | ||||||
|  | @ -12,7 +12,7 @@ package syscall | ||||||
| //         return errno; | //         return errno; | ||||||
| //     } | //     } | ||||||
| // | // | ||||||
| //go:export __error | //export __error | ||||||
| func libc___error() *int32 | func libc___error() *int32 | ||||||
| 
 | 
 | ||||||
| // getErrno returns the current C errno. It may not have been caused by the last | // getErrno returns the current C errno. It may not have been caused by the last | ||||||
|  |  | ||||||
|  | @ -53,5 +53,5 @@ func splitSlice(p []byte) (buf *byte, len uintptr) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // ssize_t write(int fd, const void *buf, size_t count) | // ssize_t write(int fd, const void *buf, size_t count) | ||||||
| //go:export write | //export write | ||||||
| func libc_write(fd int32, buf *byte, count uint) int | func libc_write(fd int32, buf *byte, count uint) int | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								testdata/calls.go
									
										
									
									
										предоставленный
									
									
								
							
							
						
						
									
										2
									
								
								testdata/calls.go
									
										
									
									
										предоставленный
									
									
								
							|  | @ -100,7 +100,7 @@ func deferred(msg string, i int) { | ||||||
| 	println(msg, i) | 	println(msg, i) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //go:export __exportedDefer | //export __exportedDefer | ||||||
| func exportedDefer() { | func exportedDefer() { | ||||||
| 	println("...exported defer") | 	println("...exported defer") | ||||||
| } | } | ||||||
|  |  | ||||||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 Ayke van Laethem
						Ayke van Laethem