Skip to content

Commit 36805c8

Browse files
committed
[Test] Moved test-spec parsing test to Swift.
To prove out that the bridging works.
1 parent dab8c14 commit 36805c8

File tree

3 files changed

+74
-85
lines changed

3 files changed

+74
-85
lines changed

SwiftCompilerSources/Sources/SIL/Test.swift

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,72 @@ private func registerFunctionTest(
148148
}
149149

150150
public func registerSILTests() {
151+
registerFunctionTest(parseTestSpecificationTest, implementation: { parseTestSpecificationTest.run($0, $1, $2) })
151152
}
153+
154+
// Arguments:
155+
// - string: list of characters, each of which specifies subsequent arguments
156+
// - A: (block) argument
157+
// - F: function
158+
// - B: block
159+
// - I: instruction
160+
// - V: value
161+
// - O: operand
162+
// - b: boolean
163+
// - u: unsigned
164+
// - s: string
165+
// - ...
166+
// - an argument of the type specified in the initial string
167+
// - ...
168+
// Dumps:
169+
// - for each argument (after the initial string)
170+
// - its type
171+
// - something to identify the instance (mostly this means calling dump)
172+
let parseTestSpecificationTest =
173+
FunctionTest(name: "test_specification_parsing") { function, arguments, context in
174+
struct _Stderr : TextOutputStream {
175+
public init() {}
176+
177+
public mutating func write(_ string: String) {
178+
for c in string.utf8 {
179+
_swift_stdlib_putc_stderr(CInt(c))
180+
}
181+
}
182+
}
183+
var stderr = _Stderr()
184+
let expectedFields = arguments.takeString()
185+
for expectedField in expectedFields.string {
186+
switch expectedField {
187+
case "A":
188+
let argument = arguments.takeArgument()
189+
print("argument:\n\(argument)", to: &stderr)
190+
case "F":
191+
let function = arguments.takeFunction()
192+
print("function: \(function.name)", to: &stderr)
193+
case "B":
194+
let block = arguments.takeBlock()
195+
print("block:\n\(block)", to: &stderr)
196+
case "I":
197+
let instruction = arguments.takeInstruction()
198+
print("instruction: \(instruction)", to: &stderr)
199+
case "V":
200+
let value = arguments.takeValue()
201+
print("value: \(value)", to: &stderr)
202+
case "O":
203+
let operand = arguments.takeOperand()
204+
print("operand: \(operand)", to: &stderr)
205+
case "u":
206+
let u = arguments.takeInt()
207+
print("uint: \(u)", to: &stderr)
208+
case "b":
209+
let b = arguments.takeBool()
210+
print("bool: \(b)", to: &stderr)
211+
case "s":
212+
let s = arguments.takeString()
213+
print("string: \(s)", to: &stderr)
214+
default:
215+
fatalError("unknown field type was expected?!");
216+
}
217+
}
218+
}
219+

lib/SILOptimizer/UtilityPasses/TestRunner.cpp

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -148,85 +148,6 @@ static FunctionTest FunctionGetSelfArgumentIndex(
148148
llvm::errs() << "self argument index = " << index << "\n";
149149
});
150150

151-
// Arguments:
152-
// - string: list of characters, each of which specifies subsequent arguments
153-
// - A: (block) argument
154-
// - F: function
155-
// - B: block
156-
// - I: instruction
157-
// - V: value
158-
// - O: operand
159-
// - b: boolean
160-
// - u: unsigned
161-
// - s: string
162-
// - ...
163-
// - an argument of the type specified in the initial string
164-
// - ...
165-
// Dumps:
166-
// - for each argument (after the initial string)
167-
// - its type
168-
// - something to identify the instance (mostly this means calling dump)
169-
static FunctionTest TestSpecificationTest(
170-
"test_specification_parsing",
171-
[](auto &function, auto &arguments, auto &test) {
172-
auto expectedFields = arguments.takeString();
173-
for (auto expectedField : expectedFields) {
174-
switch (expectedField) {
175-
case 'A': {
176-
auto *argument = arguments.takeBlockArgument();
177-
llvm::errs() << "argument:\n";
178-
argument->dump();
179-
break;
180-
}
181-
case 'F': {
182-
auto *function = arguments.takeFunction();
183-
llvm::errs() << "function: " << function->getName() << "\n";
184-
break;
185-
}
186-
case 'B': {
187-
auto *block = arguments.takeBlock();
188-
llvm::errs() << "block:\n";
189-
block->dump();
190-
break;
191-
}
192-
case 'I': {
193-
auto *instruction = arguments.takeInstruction();
194-
llvm::errs() << "instruction: ";
195-
instruction->dump();
196-
break;
197-
}
198-
case 'V': {
199-
auto value = arguments.takeValue();
200-
llvm::errs() << "value: ";
201-
value->dump();
202-
break;
203-
}
204-
case 'O': {
205-
auto *operand = arguments.takeOperand();
206-
llvm::errs() << "operand: ";
207-
operand->print(llvm::errs());
208-
break;
209-
}
210-
case 'u': {
211-
auto u = arguments.takeUInt();
212-
llvm::errs() << "uint: " << u << "\n";
213-
break;
214-
}
215-
case 'b': {
216-
auto b = arguments.takeBool();
217-
llvm::errs() << "bool: " << b << "\n";
218-
break;
219-
}
220-
case 's': {
221-
auto s = arguments.takeString();
222-
llvm::errs() << "string: " << s << "\n";
223-
break;
224-
}
225-
default:
226-
llvm_unreachable("unknown field type was expected?!");
227-
}
228-
}
229-
});
230151
} // namespace swift::test
231152

232153
//===----------------------------------------------------------------------===//

test/SILOptimizer/test_specification_parsing.sil

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %target-sil-opt -test-runner %s 2>&1 | %FileCheck %s
22

3+
// REQUIRES: swift_in_compiler
4+
35
sil_stage raw
46

57
import Builtin
@@ -8,8 +10,8 @@ import Builtin
810
// CHECK: test_arg_parsing_reference
911
// CHECK: test_arg_parsing_referenceable
1012
// CHECK: test_arg_parsing
11-
// CHECK: bool: 1
12-
// CHECK: bool: 0
13+
// CHECK: bool: true
14+
// CHECK: bool: false
1315
// CHECK-LABEL: end running test 1 of {{[^,]+}} on test_arg_parsing: test_specification_parsing
1416
// CHECK-LABEL: begin running test 2 of {{[^,]+}} on test_arg_parsing: test_specification_parsing
1517
// CHECK: block:
@@ -45,10 +47,8 @@ import Builtin
4547
// CHECK: instruction: // function_ref something_remarkable
4648
// CHECK-LABEL: end running test 5 of {{[^,]+}} on test_arg_parsing: test_specification_parsing
4749
// CHECK-LABEL: begin running test 6 of {{[^,]+}} on test_arg_parsing: test_specification_parsing
48-
// CHECK: operand:
49-
// CHECK: Owner: return {{%[^,]+}} : $()
50-
// CHECK: operand:
51-
// CHECK: Value: {{%[^,]+}} = tuple ({{%[^,]+}} : $())
50+
// CHECK: operand: operand #0 of return {{%[^,]+}} : $()
51+
// CHECK: operand: operand #1 of {{%[^,]+}} = tuple
5252
// CHECK-LABEL: end running test 6 of {{[^,]+}} on test_arg_parsing: test_specification_parsing
5353
// CHECK-LABEL: begin running test 7 of {{[^,]+}} on test_arg_parsing: test_specification_parsing
5454
// CHECK: value: {{%[^,]+}} = tuple ({{%[^,]+}} : $(), {{%[^,]+}} : $(_: ()), {{%[^,]+}} : $((), (_: ())))

0 commit comments

Comments
 (0)