-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from kntkymt/feature/optimize-push-pop
Optimizerのテスト
- Loading branch information
Showing
4 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import XCTest | ||
@testable import Optimizer | ||
import Generator | ||
|
||
final class RemoveImmediatePushPopPathTest: XCTestCase { | ||
|
||
func testRemoved() { | ||
let instructions: [AsmRepresent.Instruction] = [ | ||
.movi(dst: .x0, immediate: 10), | ||
.push(src: .x0), | ||
.pop(dst: .x0), | ||
.ret | ||
] | ||
|
||
let result = RemoveImmediatePushPopPath().optimize(instructions: instructions) | ||
let expected: [AsmRepresent.Instruction] = [ | ||
instructions[0], | ||
instructions[3] | ||
] | ||
|
||
XCTAssertEqual(result, expected) | ||
} | ||
|
||
func testNotRemoved() { | ||
let instructions: [AsmRepresent.Instruction] = [ | ||
.movi(dst: .x0, immediate: 10), | ||
.push(src: .x0), | ||
.add(dst: .x0, src1: .x1, src2: .x0), | ||
.mov(dst: .x1, src: .x0), | ||
.pop(dst: .x0), | ||
.ret | ||
] | ||
|
||
let result = RemoveImmediatePushPopPath().optimize(instructions: instructions) | ||
let expected: [AsmRepresent.Instruction] = instructions | ||
|
||
XCTAssertEqual(result, expected) | ||
} | ||
} |