pass: add textflags.h if required

Closes #12
This commit is contained in:
Michael McLoughlin
2018-12-31 00:23:15 -08:00
parent 4aaf6bc7ed
commit c62e40f8d2
13 changed files with 43 additions and 25 deletions

4
ast.go
View File

@@ -99,9 +99,7 @@ type File struct {
} }
func NewFile() *File { func NewFile() *File {
return &File{ return &File{}
Includes: []string{"textflag.h"},
}
} }
func (f *File) AddSection(s Section) { func (f *File) AddSection(s Section) {

View File

@@ -1,7 +1,5 @@
// Code generated by command: go run asm.go -out add.s -stubs stub.go. DO NOT EDIT. // Code generated by command: go run asm.go -out add.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func Add(x uint64, y uint64) uint64 // func Add(x uint64, y uint64) uint64
TEXT ·Add(SB), $0-24 TEXT ·Add(SB), $0-24
MOVQ x(FP), AX MOVQ x(FP), AX

View File

@@ -1,7 +1,5 @@
// Code generated by command: go run asm.go -out args.s -stubs stub.go. DO NOT EDIT. // Code generated by command: go run asm.go -out args.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func StringLen(s string) int // func StringLen(s string) int
TEXT ·StringLen(SB), $0-24 TEXT ·StringLen(SB), $0-24
MOVQ s_len+8(FP), AX MOVQ s_len+8(FP), AX

View File

@@ -1,7 +1,5 @@
// Code generated by command: go run asm.go -out complex.s -stubs stub.go. DO NOT EDIT. // Code generated by command: go run asm.go -out complex.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func Real(z complex128) float64 // func Real(z complex128) float64
TEXT ·Real(SB), $0-24 TEXT ·Real(SB), $0-24
MOVSD z_real(FP), X0 MOVSD z_real(FP), X0

View File

@@ -1,7 +1,5 @@
// Code generated by command: go run asm.go -out dot.s -stubs stub.go. DO NOT EDIT. // Code generated by command: go run asm.go -out dot.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func Dot(x []float32, y []float32) float32 // func Dot(x []float32, y []float32) float32
TEXT ·Dot(SB), $0-52 TEXT ·Dot(SB), $0-52
MOVQ x_base(FP), AX MOVQ x_base(FP), AX

View File

@@ -1,7 +1,5 @@
// Code generated by command: go run asm.go -out fnv1a.s -stubs stub.go. DO NOT EDIT. // Code generated by command: go run asm.go -out fnv1a.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func Hash64(data []byte) uint64 // func Hash64(data []byte) uint64
TEXT ·Hash64(SB), $0-32 TEXT ·Hash64(SB), $0-32
MOVQ data_base(FP), CX MOVQ data_base(FP), CX

View File

@@ -1,7 +1,5 @@
// Code generated by command: go run asm.go -out sha1.s -stubs stub.go. DO NOT EDIT. // Code generated by command: go run asm.go -out sha1.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func block(h *[5]uint32, m []byte) // func block(h *[5]uint32, m []byte)
TEXT ·block(SB), $64-32 TEXT ·block(SB), $64-32
MOVQ h(FP), AX MOVQ h(FP), AX

View File

@@ -1,7 +1,5 @@
// Code generated by command: go run asm.go -out stadtx.s -stubs stub.go. DO NOT EDIT. // Code generated by command: go run asm.go -out stadtx.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func Hash(state *State, key []byte) uint64 // func Hash(state *State, key []byte) uint64
TEXT ·Hash(SB), $0-40 TEXT ·Hash(SB), $0-40
MOVQ state(FP), AX MOVQ state(FP), AX

View File

@@ -1,7 +1,5 @@
// Code generated by command: go run asm.go -out sum.s -stubs stub.go. DO NOT EDIT. // Code generated by command: go run asm.go -out sum.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func Sum(xs []uint64) uint64 // func Sum(xs []uint64) uint64
TEXT ·Sum(SB), $0-32 TEXT ·Sum(SB), $0-32
MOVQ xs_base(FP), AX MOVQ xs_base(FP), AX

View File

@@ -14,6 +14,7 @@ var Compile = Concat(
FunctionPass(AllocateRegisters), FunctionPass(AllocateRegisters),
FunctionPass(BindRegisters), FunctionPass(BindRegisters),
FunctionPass(VerifyAllocation), FunctionPass(VerifyAllocation),
Func(IncludeTextFlagHeader),
) )
type Interface interface { type Interface interface {

41
pass/textflag.go Normal file
View File

@@ -0,0 +1,41 @@
package pass
import (
"github.com/mmcloughlin/avo"
)
// IncludeTextFlagHeader includes textflag.h if necessary.
func IncludeTextFlagHeader(f *avo.File) error {
const textflagheader = "textflag.h"
// Check if we already have it.
for _, path := range f.Includes {
if path == textflagheader {
return nil
}
}
// Add it if necessary.
if requirestextflags(f) {
f.Includes = append(f.Includes, textflagheader)
}
return nil
}
// requirestextflags returns whether the file uses flags in the textflags.h header.
func requirestextflags(f *avo.File) bool {
for _, s := range f.Sections {
var a avo.Attribute
switch s := s.(type) {
case *avo.Function:
a = s.Attributes
case *avo.Global:
a = s.Attributes
}
if a.ContainsTextFlags() {
return true
}
}
return false
}

View File

@@ -22,8 +22,6 @@ func TestBasic(t *testing.T) {
AssertPrintsLines(t, ctx, printer.NewGoAsm, []string{ AssertPrintsLines(t, ctx, printer.NewGoAsm, []string{
"// Code generated by avo. DO NOT EDIT.", "// Code generated by avo. DO NOT EDIT.",
"", "",
"#include \"textflag.h\"",
"",
"// func add(x uint64, y uint64) uint64", "// func add(x uint64, y uint64) uint64",
"TEXT ·add(SB), $0-24", "TEXT ·add(SB), $0-24",
"\tMOVQ\tx(FP), AX", "\tMOVQ\tx(FP), AX",
@@ -55,8 +53,6 @@ func TestTextDecl(t *testing.T) {
AssertPrintsLines(t, ctx, printer.NewGoAsm, []string{ AssertPrintsLines(t, ctx, printer.NewGoAsm, []string{
"// Code generated by avo. DO NOT EDIT.", "// Code generated by avo. DO NOT EDIT.",
"", "",
"#include \"textflag.h\"",
"",
"// func noargs()", "// func noargs()",
"TEXT ·noargs(SB), $16", // expect only the frame size "TEXT ·noargs(SB), $16", // expect only the frame size
"\tRET", "\tRET",

View File

@@ -1,7 +1,5 @@
// Code generated by command: go run asm.go -out cast.s -stubs stub.go. DO NOT EDIT. // Code generated by command: go run asm.go -out cast.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func Split(x uint64) (q uint64, l uint32, w uint16, b uint8) // func Split(x uint64) (q uint64, l uint32, w uint16, b uint8)
TEXT ·Split(SB), $0-23 TEXT ·Split(SB), $0-23
MOVQ x(FP), AX MOVQ x(FP), AX