some command line flags for builders
This commit is contained in:
@@ -20,9 +20,7 @@ func NewContext() *Context {
|
||||
}
|
||||
}
|
||||
|
||||
//go:generate avogen -output zinstructions.go build
|
||||
|
||||
func (c *Context) TEXT(name string) {
|
||||
func (c *Context) Function(name string) {
|
||||
c.function = avo.NewFunction(name)
|
||||
c.file.Functions = append(c.file.Functions, c.function)
|
||||
}
|
||||
@@ -35,6 +33,8 @@ func (c *Context) Instruction(i avo.Instruction) {
|
||||
c.function.AddInstruction(i)
|
||||
}
|
||||
|
||||
//go:generate avogen -output zinstructions.go build
|
||||
|
||||
func (c *Context) AddError(err error) {
|
||||
c.errs = append(c.errs, err)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,35 @@
|
||||
package build
|
||||
|
||||
import "os"
|
||||
import (
|
||||
"flag"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// ctx provides a global build context.
|
||||
var ctx = NewContext()
|
||||
|
||||
func TEXT(name string) { ctx.TEXT(name) }
|
||||
func EOF() { ctx.Generate(os.Stdout, os.Stderr) }
|
||||
func TEXT(name string) { ctx.Function(name) }
|
||||
|
||||
var (
|
||||
output = flag.String("output", "", "output filename (default stdout)")
|
||||
)
|
||||
|
||||
func EOF() {
|
||||
if !flag.Parsed() {
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
var w io.Writer = os.Stdout
|
||||
if *output != "" {
|
||||
if f, err := os.Create(*output); err != nil {
|
||||
log.Fatal(err)
|
||||
} else {
|
||||
defer f.Close()
|
||||
w = f
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Generate(w, os.Stderr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user