ast: move "ast" types from root to ir sub-package

Closes #32
This commit is contained in:
Michael McLoughlin
2019-01-06 14:21:10 -08:00
parent 4a920c22b5
commit 0f63e0906d
15 changed files with 3925 additions and 3925 deletions

View File

@@ -4,10 +4,10 @@ import (
"errors"
"go/types"
"github.com/mmcloughlin/avo"
"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"
"golang.org/x/tools/go/packages"
@@ -16,9 +16,9 @@ import (
// Context maintains state for incrementally building an avo File.
type Context struct {
pkg *packages.Package
file *avo.File
function *avo.Function
global *avo.Global
file *ir.File
function *ir.Function
global *ir.Global
errs ErrorList
reg.Collection
}
@@ -26,7 +26,7 @@ type Context struct {
// NewContext initializes an empty build Context.
func NewContext() *Context {
return &Context{
file: avo.NewFile(),
file: ir.NewFile(),
Collection: *reg.NewCollection(),
}
}
@@ -81,7 +81,7 @@ func (c *Context) ConstraintExpr(expr string) {
// Function starts building a new function with the given name.
func (c *Context) Function(name string) {
c.function = avo.NewFunction(name)
c.function = ir.NewFunction(name)
c.file.AddSection(c.function)
}
@@ -124,19 +124,19 @@ func (c *Context) AllocLocal(size int) operand.Mem {
}
// Instruction adds an instruction to the active function.
func (c *Context) Instruction(i *avo.Instruction) {
func (c *Context) Instruction(i *ir.Instruction) {
c.activefunc().AddInstruction(i)
}
// Label adds a label to the active function.
func (c *Context) Label(name string) {
c.activefunc().AddLabel(avo.Label(name))
c.activefunc().AddLabel(ir.Label(name))
}
func (c *Context) activefunc() *avo.Function {
func (c *Context) activefunc() *ir.Function {
if c.function == nil {
c.adderrormessage("no active function")
return avo.NewFunction("")
return ir.NewFunction("")
}
return c.function
}
@@ -145,7 +145,7 @@ func (c *Context) activefunc() *avo.Function {
// StaticGlobal adds a new static data section to the file and returns a pointer to it.
func (c *Context) StaticGlobal(name string) operand.Mem {
c.global = avo.NewStaticGlobal(name)
c.global = ir.NewStaticGlobal(name)
c.file.AddSection(c.global)
return c.global.Base()
}
@@ -157,7 +157,7 @@ func (c *Context) DataAttributes(a attr.Attribute) {
// AddDatum adds constant v at offset to the current active global data section.
func (c *Context) AddDatum(offset int, v operand.Constant) {
if err := c.activeglobal().AddDatum(avo.NewDatum(offset, v)); err != nil {
if err := c.activeglobal().AddDatum(ir.NewDatum(offset, v)); err != nil {
c.adderror(err)
}
}
@@ -167,10 +167,10 @@ func (c *Context) AppendDatum(v operand.Constant) {
c.activeglobal().Append(v)
}
func (c *Context) activeglobal() *avo.Global {
func (c *Context) activeglobal() *ir.Global {
if c.global == nil {
c.adderrormessage("no active global")
return avo.NewStaticGlobal("")
return ir.NewStaticGlobal("")
}
return c.global
}
@@ -184,6 +184,6 @@ func (c *Context) adderrormessage(msg string) {
}
// Result returns the built file and any accumulated errors.
func (c *Context) Result() (*avo.File, error) {
func (c *Context) Result() (*ir.File, error) {
return c.file, c.errs.Err()
}