get the basic add example working

This commit is contained in:
Michael McLoughlin
2018-12-08 22:02:02 -08:00
parent 5431f2edef
commit 20525e1437
4 changed files with 63 additions and 9 deletions

View File

@@ -2,16 +2,43 @@ package pass
import "github.com/mmcloughlin/avo"
// TODO(mbm): pass types
var Compile = Concat(
FunctionPass(LabelTarget),
FunctionPass(CFG),
FunctionPass(Liveness),
FunctionPass(AllocateRegisters),
FunctionPass(BindRegisters),
FunctionPass(VerifyAllocation),
)
// FunctionPass builds a full pass that operates on all functions independently.
func FunctionPass(p func(*avo.Function) error) func(*avo.File) error {
return func(f *avo.File) error {
for _, fn := range f.Functions {
if err := p(fn); err != nil {
type Interface interface {
Execute(*avo.File) error
}
type Func func(*avo.File) error
func (p Func) Execute(f *avo.File) error {
return p(f)
}
type FunctionPass func(*avo.Function) error
func (p FunctionPass) Execute(f *avo.File) error {
for _, fn := range f.Functions {
if err := p(fn); err != nil {
return err
}
}
return nil
}
func Concat(passes ...Interface) Interface {
return Func(func(f *avo.File) error {
for _, p := range passes {
if err := p.Execute(f); err != nil {
return err
}
}
return nil
}
})
}