add label type
This commit is contained in:
@@ -26,11 +26,19 @@ func (c *Context) Function(name string) {
|
||||
}
|
||||
|
||||
func (c *Context) Instruction(i avo.Instruction) {
|
||||
c.node(i)
|
||||
}
|
||||
|
||||
func (c *Context) Label(l avo.Label) {
|
||||
c.node(l)
|
||||
}
|
||||
|
||||
func (c *Context) node(n avo.Node) {
|
||||
if c.function == nil {
|
||||
c.AddErrorMessage("no active function")
|
||||
return
|
||||
}
|
||||
c.function.AddInstruction(i)
|
||||
c.function.AddNode(n)
|
||||
}
|
||||
|
||||
//go:generate avogen -output zinstructions.go build
|
||||
@@ -47,7 +55,7 @@ func (c *Context) Result() (*avo.File, []error) {
|
||||
return c.file, c.errs
|
||||
}
|
||||
|
||||
func (c *Context) Generate(wout, werr io.Writer) {
|
||||
func (c *Context) Main(wout, werr io.Writer) int {
|
||||
diag := log.New(werr, "", 0)
|
||||
|
||||
f, errs := c.Result()
|
||||
@@ -55,11 +63,14 @@ func (c *Context) Generate(wout, werr io.Writer) {
|
||||
for _, err := range errs {
|
||||
diag.Println(err)
|
||||
}
|
||||
return
|
||||
return 1
|
||||
}
|
||||
|
||||
p := avo.NewGoPrinter(wout)
|
||||
if err := p.Print(f); err != nil {
|
||||
diag.Fatal(err)
|
||||
diag.Println(err)
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -5,12 +5,15 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/mmcloughlin/avo"
|
||||
)
|
||||
|
||||
// ctx provides a global build context.
|
||||
var ctx = NewContext()
|
||||
|
||||
func TEXT(name string) { ctx.Function(name) }
|
||||
func TEXT(name string) { ctx.Function(name) }
|
||||
func LABEL(name string) { ctx.Label(avo.Label(name)) }
|
||||
|
||||
var (
|
||||
output = flag.String("output", "", "output filename (default stdout)")
|
||||
@@ -31,5 +34,5 @@ func EOF() {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Generate(w, os.Stderr)
|
||||
os.Exit(ctx.Main(w, os.Stderr))
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user