From b428a8af0800da6e83022c89700e2f74295d389a Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Thu, 21 Aug 2025 11:04:03 +0800 Subject: [PATCH] test:asmFull function test --- _demo/asmfullcall/asmfullcall.go | 21 +++++++++++++++++ _demo/asmfullcall/asmfullcall_darwin.go | 31 +++++++++++++++++++++++++ _demo/asmfullcall/asmfullcall_linux.go | 4 ++++ 3 files changed, 56 insertions(+) create mode 100644 _demo/asmfullcall/asmfullcall.go create mode 100644 _demo/asmfullcall/asmfullcall_darwin.go create mode 100644 _demo/asmfullcall/asmfullcall_linux.go diff --git a/_demo/asmfullcall/asmfullcall.go b/_demo/asmfullcall/asmfullcall.go new file mode 100644 index 00000000..5ced4d85 --- /dev/null +++ b/_demo/asmfullcall/asmfullcall.go @@ -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) +} diff --git a/_demo/asmfullcall/asmfullcall_darwin.go b/_demo/asmfullcall/asmfullcall_darwin.go new file mode 100644 index 00000000..5e537a21 --- /dev/null +++ b/_demo/asmfullcall/asmfullcall_darwin.go @@ -0,0 +1,31 @@ +//go:build darwin + +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)) +} diff --git a/_demo/asmfullcall/asmfullcall_linux.go b/_demo/asmfullcall/asmfullcall_linux.go new file mode 100644 index 00000000..b0e60f75 --- /dev/null +++ b/_demo/asmfullcall/asmfullcall_linux.go @@ -0,0 +1,4 @@ +package main + +func verify() { +}