start example/test for components access
This commit is contained in:
21
examples/components/asm.go
Normal file
21
examples/components/asm.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
. "github.com/mmcloughlin/avo/build"
|
||||
)
|
||||
|
||||
func main() {
|
||||
Package("github.com/mmcloughlin/avo/examples/components")
|
||||
|
||||
// Add confirms that we correctly deduce the packing of Struct.
|
||||
TEXT("Add", "func(x uint64, s Struct, y uint64) uint64")
|
||||
x := Load(Param("x"), GP64v())
|
||||
y := Load(Param("y"), GP64v())
|
||||
ADDQ(x, y)
|
||||
Store(y, ReturnIndex(0))
|
||||
RET()
|
||||
|
||||
Generate()
|
||||
}
|
||||
20
examples/components/components.go
Normal file
20
examples/components/components.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package components
|
||||
|
||||
type Struct struct {
|
||||
Byte byte
|
||||
Uint32 uint32
|
||||
Uint64 uint64
|
||||
Float32 float32
|
||||
Float64 float64
|
||||
String string
|
||||
Slice []Sub
|
||||
Array [5]Sub
|
||||
Complex64 complex64
|
||||
Complex128 complex128
|
||||
}
|
||||
|
||||
type Sub struct {
|
||||
A uint64
|
||||
B [3]byte
|
||||
C uint16
|
||||
}
|
||||
10
examples/components/components.s
Normal file
10
examples/components/components.s
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
// func Add(x uint64, s Struct, y uint64) uint64
|
||||
TEXT ·Add(SB),0,$0-200
|
||||
MOVQ x(FP), AX
|
||||
MOVQ y+184(FP), CX
|
||||
ADDQ AX, CX
|
||||
MOVQ CX, ret+192(FP)
|
||||
RET
|
||||
15
examples/components/components_test.go
Normal file
15
examples/components/components_test.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package components
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"testing/quick"
|
||||
)
|
||||
|
||||
//go:generate go run asm.go -out components.s -stubs stub.go
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
expect := func(x uint64, s Struct, y uint64) uint64 { return x + y }
|
||||
if err := quick.CheckEqual(Add, expect, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
3
examples/components/stub.go
Normal file
3
examples/components/stub.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package components
|
||||
|
||||
func Add(x uint64, s Struct, y uint64) uint64
|
||||
Reference in New Issue
Block a user