ir,build: pragma support (#97)
Adds support for arbitrary compiler directives. Fixes #15
This commit is contained in:
committed by
GitHub
parent
0bcbe82731
commit
c8004ba627
@@ -28,7 +28,18 @@ func (s *stubs) Print(f *ir.File) ([]byte, error) {
|
||||
for _, fn := range f.Functions() {
|
||||
s.NL()
|
||||
s.Comment(fn.Doc...)
|
||||
for _, pragma := range fn.Pragmas {
|
||||
s.pragma(pragma)
|
||||
}
|
||||
s.Printf("%s\n", fn.Stub())
|
||||
}
|
||||
return s.Result()
|
||||
}
|
||||
|
||||
func (s *stubs) pragma(p ir.Pragma) {
|
||||
s.Printf("//go:%s", p.Directive)
|
||||
for _, arg := range p.Arguments {
|
||||
s.Printf(" %s", arg)
|
||||
}
|
||||
s.NL()
|
||||
}
|
||||
|
||||
28
printer/stubs_test.go
Normal file
28
printer/stubs_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package printer_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mmcloughlin/avo/build"
|
||||
"github.com/mmcloughlin/avo/printer"
|
||||
)
|
||||
|
||||
func TestStubsPragmas(t *testing.T) {
|
||||
ctx := build.NewContext()
|
||||
ctx.Function("f")
|
||||
ctx.Pragma("noescape")
|
||||
ctx.Pragma("linkname f remote.f")
|
||||
ctx.SignatureExpr("func(x *uint64)")
|
||||
ctx.RET()
|
||||
|
||||
AssertPrintsLines(t, ctx, printer.NewStubs, []string{
|
||||
"// Code generated by avo. DO NOT EDIT.",
|
||||
"",
|
||||
"package printer",
|
||||
"",
|
||||
"//go:noescape",
|
||||
"//go:linkname f remote.f",
|
||||
"func f(x *uint64)",
|
||||
"",
|
||||
})
|
||||
}
|
||||
@@ -15,6 +15,7 @@ func AssertPrintsLines(t *testing.T, ctx *build.Context, pb printer.Builder, exp
|
||||
lines := strings.Split(output, "\n")
|
||||
|
||||
if len(expect) != len(lines) {
|
||||
t.Logf("output:\n%s", output)
|
||||
t.Fatalf("have %d lines of output; expected %d", len(lines), len(expect))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user