Merge pull request #1224 from luoliwoshang/instr/asmfull
cl(feat): llgo.asm implement tinygo.AsmFull
This commit is contained in:
21
_demo/asmfullcall/asmfullcall.go
Normal file
21
_demo/asmfullcall/asmfullcall.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
//llgo:link asmFull llgo.asm
|
||||
func asmFull(instruction string, regs map[string]any) uintptr { return 0 }
|
||||
|
||||
var testVar = 0
|
||||
|
||||
func main() {
|
||||
verify()
|
||||
}
|
||||
|
||||
func check(expected, actual int) {
|
||||
if expected != actual {
|
||||
panic(fmt.Sprintf("Expected: %d, Got: %d\n", expected, actual))
|
||||
}
|
||||
fmt.Println("asm check passed:", actual)
|
||||
}
|
||||
31
_demo/asmfullcall/asmfullcall_darwin.go
Normal file
31
_demo/asmfullcall/asmfullcall_darwin.go
Normal file
@@ -0,0 +1,31 @@
|
||||
//go:build darwin && arm64
|
||||
|
||||
package main
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func verify() {
|
||||
// 0 output & 0 input
|
||||
asmFull("nop", nil)
|
||||
|
||||
// 0 output & 1 input with memory address
|
||||
addr := uintptr(unsafe.Pointer(&testVar))
|
||||
asmFull("str {value}, [{addr}]", map[string]any{
|
||||
"addr": addr,
|
||||
"value": 43,
|
||||
})
|
||||
check(43, testVar)
|
||||
|
||||
// 1 output & 1 input
|
||||
res1 := asmFull("mov {}, {value}", map[string]any{
|
||||
"value": 41,
|
||||
})
|
||||
check(41, int(res1))
|
||||
|
||||
// 1 output & 2 inputs
|
||||
res2 := asmFull("add {}, {a}, {b}", map[string]any{
|
||||
"a": 25,
|
||||
"b": 17,
|
||||
})
|
||||
check(42, int(res2))
|
||||
}
|
||||
30
_demo/asmfullcall/asmfullcall_linux.go
Normal file
30
_demo/asmfullcall/asmfullcall_linux.go
Normal file
@@ -0,0 +1,30 @@
|
||||
//go:build linux && amd64
|
||||
|
||||
package main
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func verify() {
|
||||
// 0 output & 0 input
|
||||
asmFull("nop", nil)
|
||||
|
||||
// 0 output & 1 input with memory address
|
||||
addr := uintptr(unsafe.Pointer(&testVar))
|
||||
asmFull("movq {value}, ({addr})", map[string]any{
|
||||
"addr": addr,
|
||||
"value": 43,
|
||||
})
|
||||
check(43, testVar)
|
||||
|
||||
// 1 output & 1 input
|
||||
res1 := asmFull("movq {value}, {}", map[string]any{
|
||||
"value": 41,
|
||||
})
|
||||
check(41, int(res1))
|
||||
|
||||
res2 := asmFull("leaq ({a},{b}), {}", map[string]any{
|
||||
"a": 25,
|
||||
"b": 17,
|
||||
})
|
||||
check(42, int(res2))
|
||||
}
|
||||
Reference in New Issue
Block a user