1- //===----------- FunctionTest .swift ---------------------------------------===//
1+ //===----------- Test .swift -------- ---------------------------------------===//
22//
33// This source file is part of the Swift.org open source project
44//
1414//
1515// For general documentation on how to write tests see `Test.swift` in the
1616// SIL module.
17- // To add an optimizer test, use `FunctionTest` instead of `Test` and register
18- // it in `registerOptimizerTests`.
17+ // To add an optimizer test, use `FunctionTest` or `ModuleTest` instead of `Test`
18+ // and register it in `registerOptimizerTests`.
1919//
2020//===----------------------------------------------------------------------===//
2121
2222import SIL
2323import OptimizerBridging
2424
25- /// Like `SIL.Test`, but provides a `FunctionPass ` to the invocation closure.
25+ /// Like `SIL.Test`, but provides a `FunctionPassContext ` to the invocation closure.
2626struct FunctionTest {
2727 let name : String
2828 let invocation : FunctionTestInvocation
@@ -33,6 +33,17 @@ struct FunctionTest {
3333 }
3434}
3535
36+ /// Like `SIL.Test`, but provides a `ModulePassContext` to the invocation closure.
37+ /// This is just a wrapper around a `ModulePass` with the name "test-<testname>".
38+ /// Therefore, module tests must also be added to `Passes.def`.
39+ struct ModuleTest {
40+ let pass : ModulePass
41+
42+ public init ( _ name: String , invocation: @escaping ( ModulePassContext ) -> ( ) ) {
43+ self . pass = ModulePass ( name: " test- " + name, invocation)
44+ }
45+ }
46+
3647/// The type of the closure passed to a FunctionTest.
3748typealias FunctionTestInvocation = @convention ( thin) ( Function , TestArguments , FunctionPassContext ) -> ( )
3849
@@ -74,6 +85,10 @@ private func registerFunctionTest(_ test: FunctionTest) {
7485 }
7586}
7687
88+ private func registerModuleTest( _ test: ModuleTest , _ runFn: @escaping ( @convention ( c) ( BridgedContext ) -> ( ) ) ) {
89+ registerPass ( test. pass, runFn)
90+ }
91+
7792/// The function called by the swift::test::FunctionTest which invokes the
7893/// actual test function.
7994///
0 commit comments