ast: change file to have a list of sections
This commit is contained in:
22
ast.go
22
ast.go
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user