build: Commentf function
Convenience for adding a comment generated with fmt.Sprintf. Updates #41
This commit is contained in:
@@ -2,6 +2,7 @@ package build
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"go/types"
|
"go/types"
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/attr"
|
"github.com/mmcloughlin/avo/attr"
|
||||||
@@ -138,6 +139,11 @@ func (c *Context) Comment(lines ...string) {
|
|||||||
c.activefunc().AddComment(lines...)
|
c.activefunc().AddComment(lines...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Commentf adds a formtted comment line.
|
||||||
|
func (c *Context) Commentf(format string, a ...interface{}) {
|
||||||
|
c.Comment(fmt.Sprintf(format, a...))
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Context) activefunc() *ir.Function {
|
func (c *Context) activefunc() *ir.Function {
|
||||||
if c.function == nil {
|
if c.function == nil {
|
||||||
c.adderrormessage("no active function")
|
c.adderrormessage("no active function")
|
||||||
|
|||||||
@@ -128,5 +128,8 @@ func Label(name string) { ctx.Label(name) }
|
|||||||
// Comment adds comment lines to the active function.
|
// Comment adds comment lines to the active function.
|
||||||
func Comment(lines ...string) { ctx.Comment(lines...) }
|
func Comment(lines ...string) { ctx.Comment(lines...) }
|
||||||
|
|
||||||
|
// Commentf adds a formtted comment line.
|
||||||
|
func Commentf(format string, a ...interface{}) { ctx.Commentf(format, a...) }
|
||||||
|
|
||||||
// ConstData builds a static data section containing just the given constant.
|
// ConstData builds a static data section containing just the given constant.
|
||||||
func ConstData(name string, v operand.Constant) operand.Mem { return ctx.ConstData(name, v) }
|
func ConstData(name string, v operand.Constant) operand.Mem { return ctx.ConstData(name, v) }
|
||||||
|
|||||||
Reference in New Issue
Block a user