Skip to content

Commit

Permalink
build: Commentf function
Browse files Browse the repository at this point in the history
Convenience for adding a comment generated with fmt.Sprintf.

Updates mmcloughlin#41
  • Loading branch information
mmcloughlin committed Jan 11, 2019
1 parent 284ee13 commit 9403305
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions build/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package build

import (
"errors"
"fmt"
"go/types"

"github.com/mmcloughlin/avo/attr"
Expand Down Expand Up @@ -138,6 +139,11 @@ func (c *Context) Comment(lines ...string) {
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 {
if c.function == nil {
c.adderrormessage("no active function")
Expand Down
3 changes: 3 additions & 0 deletions build/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,8 @@ func Label(name string) { ctx.Label(name) }
// Comment adds comment lines to the active function.
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.
func ConstData(name string, v operand.Constant) operand.Mem { return ctx.ConstData(name, v) }

0 comments on commit 9403305

Please sign in to comment.