From 94033059eb7e9e2e6bbcdb35f9322dcbb6e88fb4 Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Fri, 11 Jan 2019 10:51:32 -0800 Subject: [PATCH] build: Commentf function Convenience for adding a comment generated with fmt.Sprintf. Updates #41 --- build/context.go | 6 ++++++ build/global.go | 3 +++ 2 files changed, 9 insertions(+) diff --git a/build/context.go b/build/context.go index 28948e6..7e14627 100644 --- a/build/context.go +++ b/build/context.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") diff --git a/build/global.go b/build/global.go index d0722d3..b50235d 100644 --- a/build/global.go +++ b/build/global.go @@ -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) }