Skip to content

Commit 9403305

Browse files
committed
build: Commentf function
Convenience for adding a comment generated with fmt.Sprintf. Updates mmcloughlin#41
1 parent 284ee13 commit 9403305

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

build/context.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package build
22

33
import (
44
"errors"
5+
"fmt"
56
"go/types"
67

78
"github.com/mmcloughlin/avo/attr"
@@ -138,6 +139,11 @@ func (c *Context) Comment(lines ...string) {
138139
c.activefunc().AddComment(lines...)
139140
}
140141

142+
// Commentf adds a formtted comment line.
143+
func (c *Context) Commentf(format string, a ...interface{}) {
144+
c.Comment(fmt.Sprintf(format, a...))
145+
}
146+
141147
func (c *Context) activefunc() *ir.Function {
142148
if c.function == nil {
143149
c.adderrormessage("no active function")

build/global.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,8 @@ func Label(name string) { ctx.Label(name) }
128128
// Comment adds comment lines to the active function.
129129
func Comment(lines ...string) { ctx.Comment(lines...) }
130130

131+
// Commentf adds a formtted comment line.
132+
func Commentf(format string, a ...interface{}) { ctx.Commentf(format, a...) }
133+
131134
// ConstData builds a static data section containing just the given constant.
132135
func ConstData(name string, v operand.Constant) operand.Mem { return ctx.ConstData(name, v) }

0 commit comments

Comments
 (0)