Permalink
Browse files

build: Commentf function

Convenience for adding a comment generated with fmt.Sprintf.

Updates #41
  • Loading branch information...
mmcloughlin committed Jan 11, 2019
1 parent 284ee13 commit 94033059eb7e9e2e6bbcdb35f9322dcbb6e88fb4
Showing with 9 additions and 0 deletions.
  1. +6 −0 build/context.go
  2. +3 −0 build/global.go
@@ -2,6 +2,7 @@ package build

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

"github.com/mmcloughlin/avo/attr"
@@ -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")
@@ -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.