gotypes,build: pointer dereference (#61)
Provides a method on `gotypes.Component` to allow pointer dereference. This will enable `gotypes` helpers to be used with struct pointer arguments, for example. Updates #53 Fixes #54
This commit is contained in:
committed by
GitHub
parent
eb225e9d2c
commit
9eb409b935
@@ -109,3 +109,10 @@ TEXT ·FieldComplex128Real(SB), NOSPLIT, $0-184
|
||||
MOVSD s_Complex128_real+160(FP), X0
|
||||
MOVSD X0, ret+176(FP)
|
||||
RET
|
||||
|
||||
// func DereferenceFloat32(s *Struct) float32
|
||||
TEXT ·DereferenceFloat32(SB), NOSPLIT, $0-12
|
||||
MOVQ s+0(FP), AX
|
||||
MOVSS 16(AX), X0
|
||||
MOVSS X0, ret+8(FP)
|
||||
RET
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package args
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"testing/quick"
|
||||
)
|
||||
@@ -36,3 +37,12 @@ func TestFunctionsEqual(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDereferenceFloat32(t *testing.T) {
|
||||
expect := float32(math.Pi)
|
||||
s := Struct{Float32: expect}
|
||||
got := DereferenceFloat32(&s)
|
||||
if got != expect {
|
||||
t.Errorf("DereferenceFloat32(%v) = %v; expect %v", s, got, expect)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,5 +99,11 @@ func main() {
|
||||
Store(c128r, ReturnIndex(0))
|
||||
RET()
|
||||
|
||||
TEXT("DereferenceFloat32", NOSPLIT, "func(s *Struct) float32")
|
||||
s := Dereference(Param("s"))
|
||||
f := Load(s.Field("Float32"), XMM())
|
||||
Store(f, ReturnIndex(0))
|
||||
|
||||
RET()
|
||||
Generate()
|
||||
}
|
||||
|
||||
@@ -37,3 +37,5 @@ func FieldArrayOneC(s Struct) uint16
|
||||
func FieldComplex64Imag(s Struct) float32
|
||||
|
||||
func FieldComplex128Real(s Struct) float64
|
||||
|
||||
func DereferenceFloat32(s *Struct) float32
|
||||
|
||||
Reference in New Issue
Block a user