test:asmFull function test
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
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
4
_demo/asmfullcall/asmfullcall_linux.go
Normal file
4
_demo/asmfullcall/asmfullcall_linux.go
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func verify() {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user