forked from mmcloughlin/avo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d29c634
commit 9243d29
Showing
11 changed files
with
250 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"math" | ||
|
||
. "github.com/mmcloughlin/avo/build" | ||
. "github.com/mmcloughlin/avo/operand" | ||
) | ||
|
||
func main() { | ||
bytes := GLOBL("bytes") | ||
DATA(0, U64(0x0011223344556677)) | ||
DATA(8, String("strconst")) | ||
DATA(16, F32(math.Pi)) | ||
DATA(24, F64(math.Pi)) | ||
DATA(32, U32(0x00112233)) | ||
DATA(36, U16(0x4455)) | ||
DATA(38, U8(0x66)) | ||
DATA(39, U8(0x77)) | ||
|
||
// TEXT ·DataAt(SB),0,$0-9 | ||
TEXT("DataAt", "func(i int) byte") | ||
i := Load(Param("i"), GP64v()) // MOVQ i+0(FP), AX | ||
ptr := Mem{Base: GP64v()} | ||
LEAQ(bytes, ptr.Base) // LEAQ b<>+0x00(SB), BX | ||
b := GP8v() | ||
MOVB(ptr.Idx(i, 1), b) // MOVB 0(BX)(AX*1), CL | ||
Store(b, ReturnIndex(0)) // MOVB CL, ret+8(FP) | ||
RET() // RET | ||
|
||
Generate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Code generated by command: go run asm.go -out data.s -stubs stub.go. DO NOT EDIT. | ||
|
||
#include "textflag.h" | ||
|
||
DATA bytes<>(SB)/8, $0x0011223344556677 | ||
DATA bytes<>+8(SB)/8, $"strconst" | ||
DATA bytes<>+16(SB)/4, $(3.1415927) | ||
DATA bytes<>+24(SB)/8, $(3.141592653589793) | ||
DATA bytes<>+32(SB)/4, $0x00112233 | ||
DATA bytes<>+36(SB)/2, $0x4455 | ||
DATA bytes<>+38(SB)/1, $0x66 | ||
DATA bytes<>+39(SB)/1, $0x77 | ||
GLOBL ·bytes<>(SB), RODATA, $40 | ||
|
||
// func DataAt(i int) byte | ||
TEXT ·DataAt(SB),0,$0-9 | ||
MOVQ i(FP), AX | ||
LEAQ bytes<>(SB), CX | ||
MOVB (CX)(AX*1), AL | ||
MOVB AL, ret+8(FP) | ||
RET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package data | ||
|
||
import ( | ||
"encoding/binary" | ||
"math" | ||
"testing" | ||
) | ||
|
||
//go:generate go run asm.go -out data.s -stubs stub.go | ||
|
||
func TestDataAt(t *testing.T) { | ||
order := binary.LittleEndian | ||
expect := make([]byte, 40) | ||
order.PutUint64(expect[0:], 0x0011223344556677) // DATA(0, U64(0x0011223344556677)) | ||
copy(expect[8:], []byte("strconst")) // DATA(8, String("strconst")) | ||
order.PutUint32(expect[16:], math.Float32bits(math.Pi)) // DATA(16, F32(math.Pi)) | ||
order.PutUint64(expect[24:], math.Float64bits(math.Pi)) // DATA(24, F64(math.Pi)) | ||
order.PutUint32(expect[32:], 0x00112233) // DATA(32, U32(0x00112233)) | ||
order.PutUint16(expect[36:], 0x4455) // DATA(36, U16(0x4455)) | ||
expect[38] = 0x66 // DATA(38, U8(0x66)) | ||
expect[39] = 0x77 // DATA(39, U8(0x77)) | ||
|
||
for i, e := range expect { | ||
b := DataAt(i) | ||
if b != e { | ||
t.Errorf("DataAt(%d) = %#02x; expected %#02x", i, b, e) | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters