func (c *Context) AppendDatum(v operand.Constant) {
	c.activeglobal().Append(v)
}
AppendDatum appends a constant to the current active global data section.
package build
import (
	"errors"
	"fmt"
	"go/types"
	"golang.org/x/tools/go/packages"
	"github.com/mmcloughlin/avo/attr"
	"github.com/mmcloughlin/avo/buildtags"
	"github.com/mmcloughlin/avo/gotypes"
	"github.com/mmcloughlin/avo/ir"
	"github.com/mmcloughlin/avo/operand"
	"github.com/mmcloughlin/avo/reg"
)
type Context struct {
	pkg      *packages.Package
	file     *ir.File
	function *ir.Function
	global   *ir.Global
	errs     ErrorList
	reg.Collection
}
func NewContext() *Context {
	return &Context{
		file:       ir.NewFile(),
		Collection: *reg.NewCollection(),
	}
}
func (c *Context) Package(path string) {
	cfg := &packages.Config{
		Mode: packages.NeedTypes | packages.NeedDeps | packages.NeedImports,
	}
	pkgs, err := packages.Load(cfg, path)
	if err != nil {
		c.adderror(err)
		return
	}
	pkg := pkgs[0]
	if len(pkg.Errors) > 0 {
		for _, err := range pkg.Errors {
			c.adderror(err)
		}
		return
	}
	c.pkg = pkg
}
func (c *Context) Constraints(t buildtags.ConstraintsConvertable) {
	cs := t.ToConstraints()
	if err := cs.Validate(); err != nil {
		c.adderror(err)
		return
	}
	c.file.Constraints = cs
}
func (c *Context) Constraint(t buildtags.ConstraintConvertable) {
	c.Constraints(append(c.file.Constraints, t.ToConstraint()))
}
func (c *Context) ConstraintExpr(expr string) {
	constraint, err := buildtags.ParseConstraint(expr)
	if err != nil {
		c.adderror(err)
		return
	}
	c.Constraint(constraint)
}
func (c *Context) Function(name string) {
	c.function = ir.NewFunction(name)
	c.file.AddSection(c.function)
}
func (c *Context) Doc(lines ...string) {
	c.activefunc().Doc = lines
}
func (c *Context) Pragma(directive string, args ...string) {
	c.activefunc().AddPragma(directive, args...)
}
func (c *Context) Attributes(a attr.Attribute) {
	c.activefunc().Attributes = a
}
func (c *Context) Signature(s *gotypes.Signature) {
	c.activefunc().SetSignature(s)
}
func (c *Context) SignatureExpr(expr string) {
	s, err := gotypes.ParseSignatureInPackage(c.types(), expr)
	if err != nil {
		c.adderror(err)
		return
	}
	c.Signature(s)
}
func (c *Context) Implement(name string) {
	pkg := c.types()
	if pkg == nil {
		c.adderrormessage("no package specified")
		return
	}
	s, err := gotypes.LookupSignature(pkg, name)
	if err != nil {
		c.adderror(err)
		return
	}
	c.Function(name)
	c.Signature(s)
}
func (c *Context) types() *types.Package {
	if c.pkg == nil {
		return nil
	}
	return c.pkg.Types
}
func (c *Context) AllocLocal(size int) operand.Mem {
	return c.activefunc().AllocLocal(size)
}
func (c *Context) Instruction(i *ir.Instruction) {
	c.activefunc().AddInstruction(i)
}
func (c *Context) Label(name string) {
	c.activefunc().AddLabel(ir.Label(name))
}
func (c *Context) Comment(lines ...string) {
	c.activefunc().AddComment(lines...)
}
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")
		return ir.NewFunction("")
	}
	return c.function
}
func (c *Context) StaticGlobal(name string) operand.Mem {
	c.global = ir.NewStaticGlobal(name)
	c.file.AddSection(c.global)
	return c.global.Base()
}
func (c *Context) DataAttributes(a attr.Attribute) {
	c.activeglobal().Attributes = a
}
func (c *Context) AddDatum(offset int, v operand.Constant) {
	if err := c.activeglobal().AddDatum(ir.NewDatum(offset, v)); err != nil {
		c.adderror(err)
	}
}