diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/arm/neon/functions.go b/arm/neon/functions.go old mode 100644 new mode 100755 index 56dd53b..9ec5136 --- a/arm/neon/functions.go +++ b/arm/neon/functions.go @@ -9048,4 +9048,3 @@ func VabalHighS32(v0 Int64X2, v1 Int32X4, v2 Int32X4) Int64X2 { func VabalHighS16(v0 Int32X4, v1 Int16X8, v2 Int16X8) Int32X4 { return Int32X4(C.vabal_high_s16(C.int32x4_t(v0), C.int16x8_t(v1), C.int16x8_t(v2))) } - diff --git a/arm/neon/generate.go b/arm/neon/generate.go new file mode 100644 index 0000000..7f562bd --- /dev/null +++ b/arm/neon/generate.go @@ -0,0 +1,4 @@ +package neon + +//go:generate go run ../../cmd/generator -package=neon -types -o types.go +//go:generate go run ../../cmd/generator -package=neon -funcs -o functions.go diff --git a/arm/neon/types.go b/arm/neon/types.go old mode 100644 new mode 100755 diff --git a/cmd/generator/main.go b/cmd/generator/main.go index 68844d8..e7fa2e7 100644 --- a/cmd/generator/main.go +++ b/cmd/generator/main.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "io" "log" "os" "os/exec" @@ -14,6 +15,11 @@ func main() { app := cli.App{ Name: "go-simd-generator", Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "package", + Usage: "Go package name", + Required: true, + }, &cli.BoolFlag{ Name: "types", Usage: "skip types", @@ -22,6 +28,11 @@ func main() { Name: "funcs", Usage: "skip functions", }, + &cli.StringFlag{ + Name: "output", + Aliases: []string{"o"}, + Usage: "output file", + }, }, Action: action, } @@ -40,7 +51,7 @@ func action(cli *cli.Context) error { return err } pkg := &scanner.Package{ - Name: "neon", + Name: cli.String("package"), C: []string{ "#include ", }, @@ -53,7 +64,18 @@ func action(cli *cli.Context) error { if !cli.Bool("funcs") { pkg.Functions = nil } - pkg.WriteTo(os.Stdout) + var w io.Writer + if output := cli.String("output"); len(output) > 0 { + f, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm) + if err != nil { + return err + } + defer f.Close() + w = f + } else { + w = os.Stdout + } + pkg.WriteTo(w) return nil } diff --git a/scanner/function.go b/scanner/function.go index a08cbb7..ddffb8d 100644 --- a/scanner/function.go +++ b/scanner/function.go @@ -20,7 +20,8 @@ type Arg struct { const funcTemplate = `func %s(%s) %s { return %s(C.%s(%s)) -}` +} +` func (f *Function) String() string { return fmt.Sprintf( diff --git a/scanner/package.go b/scanner/package.go index 8ea8206..3e9f106 100644 --- a/scanner/package.go +++ b/scanner/package.go @@ -14,11 +14,11 @@ type Package struct { } func (pkg *Package) WriteTo(w io.Writer) error { - if _, err := fmt.Fprintf(w, "package %s\n\n", pkg.Name); err != nil { + if _, err := fmt.Fprintf(w, "package %s\n", pkg.Name); err != nil { return err } if len(pkg.C) > 0 { - if _, err := fmt.Fprintf(w, "/*\n%s\n*/\nimport \"C\"\n\n", strings.Join(pkg.C, "\n")); err != nil { + if _, err := fmt.Fprintf(w, "\n/*\n%s\n*/\nimport \"C\"\n", strings.Join(pkg.C, "\n")); err != nil { return err } } @@ -26,7 +26,7 @@ func (pkg *Package) WriteTo(w io.Writer) error { if strings.Contains(string(t), "float16") { continue } - if _, err := fmt.Fprintf(w, "type %s C.%s\n\n", t.GoString(), t); err != nil { + if _, err := fmt.Fprintf(w, "\ntype %s C.%s\n", t.GoString(), t); err != nil { return err } } @@ -40,7 +40,7 @@ funcs: continue funcs } } - if _, err := fmt.Fprintf(w, "%s\n\n", fn.String()); err != nil { + if _, err := fmt.Fprintf(w, "\n%s", fn.String()); err != nil { return err } }