ast: change file to have a list of sections

This commit is contained in:
Michael McLoughlin
2018-12-26 18:58:12 -08:00
parent bf6031521f
commit d29c6340d7
6 changed files with 30 additions and 12 deletions

22
ast.go
View File

@@ -10,10 +10,6 @@ type Asm interface {
Asm() string
}
type Operand interface {
Asm
}
type Node interface {
node()
}
@@ -90,15 +86,29 @@ func (i Instruction) OutputRegisters() []reg.Register {
return rs
}
type Section interface {
section()
}
// File represents an assembly file.
type File struct {
Functions []*Function
Sections []Section
}
func NewFile() *File {
return &File{}
}
func (f *File) Functions() []*Function {
var fns []*Function
for _, s := range f.Sections {
if fn, ok := s.(*Function); ok {
fns = append(fns, fn)
}
}
return fns
}
// Function represents an assembly function.
type Function struct {
Name string
@@ -114,6 +124,8 @@ type Function struct {
Allocation reg.Allocation
}
func (f Function) section() {}
func NewFunction(name string) *Function {
return &Function{
Name: name,