Skip to content

Commit 309ae61

Browse files
rintaronkcsgexi
authored andcommitted
[Syntax] Add '-parse-only' option to 'swift-syntax-test' tool
Mainly for performance syntax parsing performance test.
1 parent d32b342 commit 309ae61

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tools/swift-syntax-test/swift-syntax-test.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum class ActionType {
4343
FullLexRoundTrip,
4444
FullParseRoundTrip,
4545
SerializeRawTree,
46+
ParseOnly,
4647
ParserGen,
4748
EOFPos,
4849
None
@@ -66,6 +67,9 @@ Action(llvm::cl::desc("Action (required):"),
6667
"round-trip-parse",
6768
"Parse the source file and print it back out for "
6869
"comparing against the input"),
70+
clEnumValN(ActionType::ParseOnly,
71+
"parse-only",
72+
"Parse the source file with syntax nodes and exit"),
6973
clEnumValN(ActionType::ParserGen,
7074
"parse-gen",
7175
"Parse the source file and print it back out for "
@@ -233,6 +237,13 @@ int doSerializeRawTree(const char *MainExecutablePath,
233237
return EXIT_SUCCESS;
234238
}
235239

240+
int doParseOnly(const char *MainExecutablePath,
241+
const StringRef InputFileName) {
242+
CompilerInstance Instance;
243+
SourceFile *SF = getSourceFile(Instance, InputFileName, MainExecutablePath);
244+
return SF ? EXIT_SUCCESS : EXIT_FAILURE;
245+
}
246+
236247
int dumpParserGen(const char *MainExecutablePath,
237248
const StringRef InputFileName) {
238249
CompilerInstance Instance;
@@ -266,7 +277,6 @@ int dumpEOFSourceLoc(const char *MainExecutablePath,
266277
llvm::outs() << CharSourceRange(SourceMgr, StartLoc, EndLoc).str();
267278
return 0;
268279
}
269-
270280
}// end of anonymous namespace
271281

272282
int main(int argc, char *argv[]) {
@@ -297,6 +307,9 @@ int main(int argc, char *argv[]) {
297307
case ActionType::SerializeRawTree:
298308
ExitCode = doSerializeRawTree(argv[0], options::InputSourceFilename);
299309
break;
310+
case ActionType::ParseOnly:
311+
ExitCode = doParseOnly(argv[0], options::InputSourceFilename);
312+
break;
300313
case ActionType::ParserGen:
301314
ExitCode = dumpParserGen(argv[0], options::InputSourceFilename);
302315
break;

0 commit comments

Comments
 (0)