pass: VerifyMemOperands (#127)

Introduces a pass to verify memory operands. This is added to a new
Verify pass, that in future could do much more.

Updates #125
This commit is contained in:
Michael McLoughlin
2020-01-22 19:59:02 -08:00
committed by GitHub
parent ff7a160610
commit 126469f13d
3 changed files with 107 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ import (
// Compile pass compiles an avo file. Upon successful completion the avo file
// may be printed to Go assembly.
var Compile = Concat(
Verify,
FunctionPass(PruneJumpToFollowingLabel),
FunctionPass(PruneDanglingLabels),
FunctionPass(LabelTarget),
@@ -51,6 +52,22 @@ func (p FunctionPass) Execute(f *ir.File) error {
return nil
}
// InstructionPass is a convenience for implementing a full file pass with a
// function that operates on each Instruction independently.
type InstructionPass func(*ir.Instruction) error
// Execute calls p on every instruction in the file. Exits on the first error.
func (p InstructionPass) Execute(f *ir.File) error {
for _, fn := range f.Functions() {
for _, i := range fn.Instructions() {
if err := p(i); err != nil {
return err
}
}
}
return nil
}
// Concat returns a pass that executes the given passes in order, stopping on the first error.
func Concat(passes ...Interface) Interface {
return Func(func(f *ir.File) error {