some command line flags for builders

This commit is contained in:
Michael McLoughlin
2018-11-30 20:58:51 -08:00
parent 9b9f5b7e0c
commit 241b5ea673
2 changed files with 32 additions and 6 deletions

View File

@@ -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)
}

View File

@@ -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)
}