Merge pull request #1224 from luoliwoshang/instr/asmfull

cl(feat): llgo.asm implement tinygo.AsmFull
This commit is contained in:
xushiwei
2025-08-28 11:41:31 +08:00
committed by GitHub
8 changed files with 460 additions and 6 deletions

View 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)
}

View 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))
}

View 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))
}