mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
[FileCheck] Remove implementation types from API
Summary: Remove use of FileCheckPatternContext and FileCheckString concrete types from FileCheck API to allow moving it and the other implementation only only declarations into a private header file. Reviewers: jhenderson, chandlerc, jdenny, probinson, grimar, arichardson, rnk Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68186 llvm-svn: 373211
This commit is contained in:
parent
2790dd8d16
commit
6057227852
@ -728,10 +728,13 @@ struct FileCheckString {
|
|||||||
/// use information from the request.
|
/// use information from the request.
|
||||||
class FileCheck {
|
class FileCheck {
|
||||||
FileCheckRequest Req;
|
FileCheckRequest Req;
|
||||||
FileCheckPatternContext PatternContext;
|
std::unique_ptr<FileCheckPatternContext> PatternContext;
|
||||||
|
// C++17 TODO: make this a plain std::vector.
|
||||||
|
std::unique_ptr<std::vector<FileCheckString>> CheckStrings;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileCheck(FileCheckRequest Req) : Req(Req) {}
|
explicit FileCheck(FileCheckRequest Req);
|
||||||
|
~FileCheck();
|
||||||
|
|
||||||
// Combines the check prefixes into a single regex so that we can efficiently
|
// Combines the check prefixes into a single regex so that we can efficiently
|
||||||
// scan for any of the set.
|
// scan for any of the set.
|
||||||
@ -741,13 +744,11 @@ public:
|
|||||||
Regex buildCheckPrefixRegex();
|
Regex buildCheckPrefixRegex();
|
||||||
|
|
||||||
/// Reads the check file from \p Buffer and records the expected strings it
|
/// Reads the check file from \p Buffer and records the expected strings it
|
||||||
/// contains in the \p CheckStrings vector. Errors are reported against
|
/// contains. Errors are reported against \p SM.
|
||||||
/// \p SM.
|
|
||||||
///
|
///
|
||||||
/// Only expected strings whose prefix is one of those listed in \p PrefixRE
|
/// Only expected strings whose prefix is one of those listed in \p PrefixRE
|
||||||
/// are recorded. \returns true in case of an error, false otherwise.
|
/// are recorded. \returns true in case of an error, false otherwise.
|
||||||
bool ReadCheckFile(SourceMgr &SM, StringRef Buffer, Regex &PrefixRE,
|
bool readCheckFile(SourceMgr &SM, StringRef Buffer, Regex &PrefixRE);
|
||||||
std::vector<FileCheckString> &CheckStrings);
|
|
||||||
|
|
||||||
bool ValidateCheckPrefixes();
|
bool ValidateCheckPrefixes();
|
||||||
|
|
||||||
@ -757,12 +758,11 @@ public:
|
|||||||
SmallVectorImpl<char> &OutputBuffer);
|
SmallVectorImpl<char> &OutputBuffer);
|
||||||
|
|
||||||
/// Checks the input to FileCheck provided in the \p Buffer against the
|
/// Checks the input to FileCheck provided in the \p Buffer against the
|
||||||
/// \p CheckStrings read from the check file and record diagnostics emitted
|
/// expected strings read from the check file and record diagnostics emitted
|
||||||
/// in \p Diags. Errors are recorded against \p SM.
|
/// in \p Diags. Errors are recorded against \p SM.
|
||||||
///
|
///
|
||||||
/// \returns false if the input fails to satisfy the checks.
|
/// \returns false if the input fails to satisfy the checks.
|
||||||
bool CheckInput(SourceMgr &SM, StringRef Buffer,
|
bool checkInput(SourceMgr &SM, StringRef Buffer,
|
||||||
ArrayRef<FileCheckString> CheckStrings,
|
|
||||||
std::vector<FileCheckDiag> *Diags = nullptr);
|
std::vector<FileCheckDiag> *Diags = nullptr);
|
||||||
};
|
};
|
||||||
} // namespace llvm
|
} // namespace llvm
|
||||||
|
@ -1116,16 +1116,22 @@ void FileCheckPatternContext::createLineVariable() {
|
|||||||
GlobalNumericVariableTable[LineName] = LineVariable;
|
GlobalNumericVariableTable[LineName] = LineVariable;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileCheck::ReadCheckFile(SourceMgr &SM, StringRef Buffer, Regex &PrefixRE,
|
FileCheck::FileCheck(FileCheckRequest Req)
|
||||||
std::vector<FileCheckString> &CheckStrings) {
|
: Req(Req), PatternContext(std::make_unique<FileCheckPatternContext>()),
|
||||||
|
CheckStrings(std::make_unique<std::vector<FileCheckString>>()) {}
|
||||||
|
|
||||||
|
FileCheck::~FileCheck() = default;
|
||||||
|
|
||||||
|
bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
|
||||||
|
Regex &PrefixRE) {
|
||||||
Error DefineError =
|
Error DefineError =
|
||||||
PatternContext.defineCmdlineVariables(Req.GlobalDefines, SM);
|
PatternContext->defineCmdlineVariables(Req.GlobalDefines, SM);
|
||||||
if (DefineError) {
|
if (DefineError) {
|
||||||
logAllUnhandledErrors(std::move(DefineError), errs());
|
logAllUnhandledErrors(std::move(DefineError), errs());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PatternContext.createLineVariable();
|
PatternContext->createLineVariable();
|
||||||
|
|
||||||
std::vector<FileCheckPattern> ImplicitNegativeChecks;
|
std::vector<FileCheckPattern> ImplicitNegativeChecks;
|
||||||
for (const auto &PatternString : Req.ImplicitCheckNot) {
|
for (const auto &PatternString : Req.ImplicitCheckNot) {
|
||||||
@ -1141,7 +1147,7 @@ bool FileCheck::ReadCheckFile(SourceMgr &SM, StringRef Buffer, Regex &PrefixRE,
|
|||||||
SM.AddNewSourceBuffer(std::move(CmdLine), SMLoc());
|
SM.AddNewSourceBuffer(std::move(CmdLine), SMLoc());
|
||||||
|
|
||||||
ImplicitNegativeChecks.push_back(
|
ImplicitNegativeChecks.push_back(
|
||||||
FileCheckPattern(Check::CheckNot, &PatternContext));
|
FileCheckPattern(Check::CheckNot, PatternContext.get()));
|
||||||
ImplicitNegativeChecks.back().parsePattern(PatternInBuffer,
|
ImplicitNegativeChecks.back().parsePattern(PatternInBuffer,
|
||||||
"IMPLICIT-CHECK", SM, Req);
|
"IMPLICIT-CHECK", SM, Req);
|
||||||
}
|
}
|
||||||
@ -1204,7 +1210,7 @@ bool FileCheck::ReadCheckFile(SourceMgr &SM, StringRef Buffer, Regex &PrefixRE,
|
|||||||
SMLoc PatternLoc = SMLoc::getFromPointer(Buffer.data());
|
SMLoc PatternLoc = SMLoc::getFromPointer(Buffer.data());
|
||||||
|
|
||||||
// Parse the pattern.
|
// Parse the pattern.
|
||||||
FileCheckPattern P(CheckTy, &PatternContext, LineNumber);
|
FileCheckPattern P(CheckTy, PatternContext.get(), LineNumber);
|
||||||
if (P.parsePattern(Buffer.substr(0, EOL), UsedPrefix, SM, Req))
|
if (P.parsePattern(Buffer.substr(0, EOL), UsedPrefix, SM, Req))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -1222,7 +1228,7 @@ bool FileCheck::ReadCheckFile(SourceMgr &SM, StringRef Buffer, Regex &PrefixRE,
|
|||||||
// Verify that CHECK-NEXT/SAME/EMPTY lines have at least one CHECK line before them.
|
// Verify that CHECK-NEXT/SAME/EMPTY lines have at least one CHECK line before them.
|
||||||
if ((CheckTy == Check::CheckNext || CheckTy == Check::CheckSame ||
|
if ((CheckTy == Check::CheckNext || CheckTy == Check::CheckSame ||
|
||||||
CheckTy == Check::CheckEmpty) &&
|
CheckTy == Check::CheckEmpty) &&
|
||||||
CheckStrings.empty()) {
|
CheckStrings->empty()) {
|
||||||
StringRef Type = CheckTy == Check::CheckNext
|
StringRef Type = CheckTy == Check::CheckNext
|
||||||
? "NEXT"
|
? "NEXT"
|
||||||
: CheckTy == Check::CheckEmpty ? "EMPTY" : "SAME";
|
: CheckTy == Check::CheckEmpty ? "EMPTY" : "SAME";
|
||||||
@ -1240,21 +1246,21 @@ bool FileCheck::ReadCheckFile(SourceMgr &SM, StringRef Buffer, Regex &PrefixRE,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Okay, add the string we captured to the output vector and move on.
|
// Okay, add the string we captured to the output vector and move on.
|
||||||
CheckStrings.emplace_back(P, UsedPrefix, PatternLoc);
|
CheckStrings->emplace_back(P, UsedPrefix, PatternLoc);
|
||||||
std::swap(DagNotMatches, CheckStrings.back().DagNotStrings);
|
std::swap(DagNotMatches, CheckStrings->back().DagNotStrings);
|
||||||
DagNotMatches = ImplicitNegativeChecks;
|
DagNotMatches = ImplicitNegativeChecks;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an EOF pattern for any trailing CHECK-DAG/-NOTs, and use the first
|
// Add an EOF pattern for any trailing CHECK-DAG/-NOTs, and use the first
|
||||||
// prefix as a filler for the error message.
|
// prefix as a filler for the error message.
|
||||||
if (!DagNotMatches.empty()) {
|
if (!DagNotMatches.empty()) {
|
||||||
CheckStrings.emplace_back(
|
CheckStrings->emplace_back(
|
||||||
FileCheckPattern(Check::CheckEOF, &PatternContext, LineNumber + 1),
|
FileCheckPattern(Check::CheckEOF, PatternContext.get(), LineNumber + 1),
|
||||||
*Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data()));
|
*Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data()));
|
||||||
std::swap(DagNotMatches, CheckStrings.back().DagNotStrings);
|
std::swap(DagNotMatches, CheckStrings->back().DagNotStrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CheckStrings.empty()) {
|
if (CheckStrings->empty()) {
|
||||||
errs() << "error: no check strings found with prefix"
|
errs() << "error: no check strings found with prefix"
|
||||||
<< (Req.CheckPrefixes.size() > 1 ? "es " : " ");
|
<< (Req.CheckPrefixes.size() > 1 ? "es " : " ");
|
||||||
auto I = Req.CheckPrefixes.begin();
|
auto I = Req.CheckPrefixes.begin();
|
||||||
@ -1916,18 +1922,17 @@ void FileCheckPatternContext::clearLocalVars() {
|
|||||||
GlobalNumericVariableTable.erase(Var);
|
GlobalNumericVariableTable.erase(Var);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileCheck::CheckInput(SourceMgr &SM, StringRef Buffer,
|
bool FileCheck::checkInput(SourceMgr &SM, StringRef Buffer,
|
||||||
ArrayRef<FileCheckString> CheckStrings,
|
|
||||||
std::vector<FileCheckDiag> *Diags) {
|
std::vector<FileCheckDiag> *Diags) {
|
||||||
bool ChecksFailed = false;
|
bool ChecksFailed = false;
|
||||||
|
|
||||||
unsigned i = 0, j = 0, e = CheckStrings.size();
|
unsigned i = 0, j = 0, e = CheckStrings->size();
|
||||||
while (true) {
|
while (true) {
|
||||||
StringRef CheckRegion;
|
StringRef CheckRegion;
|
||||||
if (j == e) {
|
if (j == e) {
|
||||||
CheckRegion = Buffer;
|
CheckRegion = Buffer;
|
||||||
} else {
|
} else {
|
||||||
const FileCheckString &CheckLabelStr = CheckStrings[j];
|
const FileCheckString &CheckLabelStr = (*CheckStrings)[j];
|
||||||
if (CheckLabelStr.Pat.getCheckTy() != Check::CheckLabel) {
|
if (CheckLabelStr.Pat.getCheckTy() != Check::CheckLabel) {
|
||||||
++j;
|
++j;
|
||||||
continue;
|
continue;
|
||||||
@ -1950,10 +1955,10 @@ bool FileCheck::CheckInput(SourceMgr &SM, StringRef Buffer,
|
|||||||
// CHECK-LABEL and it would clear variables defined on the command-line
|
// CHECK-LABEL and it would clear variables defined on the command-line
|
||||||
// before they get used.
|
// before they get used.
|
||||||
if (i != 0 && Req.EnableVarScope)
|
if (i != 0 && Req.EnableVarScope)
|
||||||
PatternContext.clearLocalVars();
|
PatternContext->clearLocalVars();
|
||||||
|
|
||||||
for (; i != j; ++i) {
|
for (; i != j; ++i) {
|
||||||
const FileCheckString &CheckStr = CheckStrings[i];
|
const FileCheckString &CheckStr = (*CheckStrings)[i];
|
||||||
|
|
||||||
// Check each string within the scanned region, including a second check
|
// Check each string within the scanned region, including a second check
|
||||||
// of any final CHECK-LABEL (to verify CHECK-NOT and CHECK-DAG)
|
// of any final CHECK-LABEL (to verify CHECK-NOT and CHECK-DAG)
|
||||||
|
@ -195,12 +195,11 @@ static inline bool CheckMachineFunction(const MachineFunction &MF,
|
|||||||
SM.AddNewSourceBuffer(MemoryBuffer::getMemBuffer(CheckFileText, "CheckFile"),
|
SM.AddNewSourceBuffer(MemoryBuffer::getMemBuffer(CheckFileText, "CheckFile"),
|
||||||
SMLoc());
|
SMLoc());
|
||||||
Regex PrefixRE = FC.buildCheckPrefixRegex();
|
Regex PrefixRE = FC.buildCheckPrefixRegex();
|
||||||
std::vector<FileCheckString> CheckStrings;
|
if (FC.readCheckFile(SM, CheckFileText, PrefixRE))
|
||||||
if (FC.ReadCheckFile(SM, CheckFileText, PrefixRE, CheckStrings))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto OutBuffer = OutputBuf->getBuffer();
|
auto OutBuffer = OutputBuf->getBuffer();
|
||||||
SM.AddNewSourceBuffer(std::move(OutputBuf), SMLoc());
|
SM.AddNewSourceBuffer(std::move(OutputBuf), SMLoc());
|
||||||
return FC.CheckInput(SM, OutBuffer, CheckStrings);
|
return FC.checkInput(SM, OutBuffer);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -597,8 +597,7 @@ int main(int argc, char **argv) {
|
|||||||
CheckFileText, CheckFile.getBufferIdentifier()),
|
CheckFileText, CheckFile.getBufferIdentifier()),
|
||||||
SMLoc());
|
SMLoc());
|
||||||
|
|
||||||
std::vector<FileCheckString> CheckStrings;
|
if (FC.readCheckFile(SM, CheckFileText, PrefixRE))
|
||||||
if (FC.ReadCheckFile(SM, CheckFileText, PrefixRE, CheckStrings))
|
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
// Open the file to check and add it to SourceMgr.
|
// Open the file to check and add it to SourceMgr.
|
||||||
@ -628,7 +627,7 @@ int main(int argc, char **argv) {
|
|||||||
DumpInput = DumpInputOnFailure ? DumpInputFail : DumpInputNever;
|
DumpInput = DumpInputOnFailure ? DumpInputFail : DumpInputNever;
|
||||||
|
|
||||||
std::vector<FileCheckDiag> Diags;
|
std::vector<FileCheckDiag> Diags;
|
||||||
int ExitCode = FC.CheckInput(SM, InputFileText, CheckStrings,
|
int ExitCode = FC.checkInput(SM, InputFileText,
|
||||||
DumpInput == DumpInputNever ? nullptr : &Diags)
|
DumpInput == DumpInputNever ? nullptr : &Diags)
|
||||||
? EXIT_SUCCESS
|
? EXIT_SUCCESS
|
||||||
: 1;
|
: 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user