Go to the documentation of this file.
15 #ifndef LLVM_LIB_FILECHECK_FILECHECKIMPL_H
16 #define LLVM_LIB_FILECHECK_FILECHECKIMPL_H
34 class ExpressionValue;
56 unsigned Precision = 0;
58 bool AlternateForm =
false;
68 Precision ==
Other.Precision && AlternateForm ==
Other.AlternateForm;
72 return !(*
this ==
Other);
87 :
Value(
Value), Precision(Precision), AlternateForm(AlternateForm){};
135 return !(*
this ==
Other);
140 assert((
Value != 0 || !Negative) &&
"Unexpected negative zero!");
159 Expected<ExpressionValue>
operator+(
const ExpressionValue &Lhs,
160 const ExpressionValue &Rhs);
161 Expected<ExpressionValue>
operator-(
const ExpressionValue &Lhs,
162 const ExpressionValue &Rhs);
163 Expected<ExpressionValue>
operator*(
const ExpressionValue &Lhs,
164 const ExpressionValue &Rhs);
165 Expected<ExpressionValue>
operator/(
const ExpressionValue &Lhs,
166 const ExpressionValue &Rhs);
167 Expected<ExpressionValue>
max(
const ExpressionValue &Lhs,
168 const ExpressionValue &Rhs);
169 Expected<ExpressionValue>
min(
const ExpressionValue &Lhs,
170 const ExpressionValue &Rhs);
232 OS <<
"undefined variable: " << VarName;
240 std::unique_ptr<ExpressionAST> AST;
249 : AST(
std::
move(AST)), Format(Format) {}
269 std::optional<ExpressionValue>
Value;
273 std::optional<StringRef> StrValue;
278 std::optional<size_t> DefLineNumber;
285 std::optional<size_t> DefLineNumber = std::nullopt)
286 : Name(Name), ImplicitFormat(ImplicitFormat),
287 DefLineNumber(DefLineNumber) {}
309 std::optional<StringRef> NewStrValue = std::nullopt) {
311 StrValue = NewStrValue;
317 Value = std::nullopt;
318 StrValue = std::nullopt;
347 using binop_eval_t = Expected<ExpressionValue> (*)(
const ExpressionValue &,
354 std::unique_ptr<ExpressionAST> LeftOperand;
357 std::unique_ptr<ExpressionAST> RightOperand;
364 std::unique_ptr<ExpressionAST> LeftOp,
365 std::unique_ptr<ExpressionAST> RightOp)
385 class FileCheckPatternContext;
438 std::unique_ptr<Expression> ExpressionPointer;
442 std::unique_ptr<Expression> ExpressionPointer,
445 ExpressionPointer(
std::
move(ExpressionPointer)) {}
486 std::vector<std::unique_ptr<NumericVariable>> NumericVariables;
490 std::vector<std::unique_ptr<Expression>>
Expressions;
494 std::vector<std::unique_ptr<Substitution>> Substitutions;
545 : Diagnostic(Diag), Range(Range) {}
558 SMRange Range = std::nullopt) {
559 return make_error<ErrorDiagnostic>(
566 return get(SM, Start, ErrMsg,
SMRange(Start, End));
580 OS <<
"String not found in input";
604 OS <<
"error previously reported";
608 if (HasErrorReported)
609 return make_error<ErrorReported>();
623 std::string RegExStr;
631 std::vector<Substitution *> Substitutions;
644 std::map<StringRef, unsigned> VariableDefs;
650 struct NumericVariableMatch {
657 unsigned CaptureParenGroup;
678 std::optional<size_t> LineNumber;
681 bool IgnoreCase =
false;
685 std::optional<size_t> Line = std::nullopt)
722 StringRef Expr, std::optional<NumericVariable *> &DefinedNumericVariable,
723 bool IsLegacyLineExpr, std::optional<size_t> LineNumber,
761 std::vector<FileCheckDiag> *Diags)
const;
763 std::vector<FileCheckDiag> *Diags)
const;
766 return !(Substitutions.empty() && VariableDefs.empty());
769 std::vector<FileCheckDiag> *Diags)
const;
777 void AddBackrefToRegEx(
unsigned BackrefNum);
781 unsigned computeMatchDistance(
StringRef Buffer)
const;
806 StringRef Name,
bool IsPseudo, std::optional<size_t> LineNumber,
808 enum class AllowedOperand { LineVar, LegacyLiteral,
Any };
818 static Expected<std::unique_ptr<ExpressionAST>>
819 parseNumericOperand(StringRef &Expr, AllowedOperand AO,
bool ConstraintParsed,
820 std::optional<size_t> LineNumber,
821 FileCheckPatternContext *Context,
const SourceMgr &SM);
831 static Expected<std::unique_ptr<ExpressionAST>>
832 parseBinop(StringRef Expr, StringRef &RemainingExpr,
833 std::unique_ptr<ExpressionAST> LeftOp,
bool IsLegacyLineExpr,
834 std::optional<size_t> LineNumber, FileCheckPatternContext *Context,
835 const SourceMgr &SM);
843 static Expected<std::unique_ptr<ExpressionAST>>
844 parseParenExpr(StringRef &Expr, std::optional<size_t> LineNumber,
845 FileCheckPatternContext *Context,
const SourceMgr &SM);
854 static Expected<std::unique_ptr<ExpressionAST>>
855 parseCallExpr(StringRef &Expr, StringRef FuncName,
856 std::optional<size_t> LineNumber,
857 FileCheckPatternContext *Context,
const SourceMgr &SM);
885 std::vector<FileCheckDiag> *Diags)
const;
897 const std::vector<const Pattern *> &NotStrings,
899 std::vector<FileCheckDiag> *Diags)
const;
902 std::vector<const Pattern *> &NotStrings,
904 std::vector<FileCheckDiag> *Diags)
const;
ExpressionAST(StringRef ExpressionStr)
FileCheckString(const Pattern &P, StringRef S, SMLoc L)
Class representing a numeric value.
bool isNegative() const
Returns true if value is signed and negative, false otherwise.
This is an optimization pass for GlobalISel generic memory operations.
Expected< std::string > getResult() const override
StringRef getVarName() const
Pattern Pat
The pattern to match.
StringRef getMessage() const
StringRef getMessage() const
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
MatchResult(Match M, Error E)
Expected< ExpressionValue > eval() const override
Class to represent an overflow error that might result when manipulating a value.
bool CheckNext(const SourceMgr &SM, StringRef Buffer) const
Verifies that there is a single line in the given Buffer.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
bool operator==(const ExpressionValue &Other) const
bool operator!=(const ExpressionValue &Other) const
static Expected< std::unique_ptr< Expression > > parseNumericSubstitutionBlock(StringRef Expr, std::optional< NumericVariable * > &DefinedNumericVariable, bool IsLegacyLineExpr, std::optional< size_t > LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM)
Parses Expr for a numeric substitution block at line LineNumber, or before input is parsed if LineNum...
static ErrorSuccess success()
Create a success value.
Expression(std::unique_ptr< ExpressionAST > AST, ExpressionFormat Format)
Generic constructor for an expression represented by the given AST and whose matching format is Forma...
SMLoc Loc
The location in the match file that the check string was specified.
virtual Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const
StringSubstitution(FileCheckPatternContext *Context, StringRef VarName, size_t InsertIdx)
bool parsePattern(StringRef PatternStr, StringRef Prefix, SourceMgr &SM, const FileCheckRequest &Req)
Parses the pattern in PatternStr and initializes this Pattern instance accordingly.
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
Expected< ExpressionValue > eval() const override
Class representing an unsigned literal in the AST of an expression.
Base class representing the AST of a given expression.
void clearLocalVars()
Undefines local variables (variables whose name does not start with a '$' sign), i....
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Tagged union holding either a T or a Error.
NumericVariableUse(StringRef Name, NumericVariable *Variable)
void setValue(ExpressionValue NewValue, std::optional< StringRef > NewStrValue=std::nullopt)
Sets value of this numeric variable to NewValue, and sets the input buffer string from which it was p...
Expected< StringRef > getPatternVarValue(StringRef VarName)
MatchResult match(StringRef Buffer, const SourceMgr &SM) const
Matches the pattern string against the input buffer Buffer.
ExpressionFormat getImplicitFormat() const
ExpressionValue getAbsolute() const
void printSubstitutions(const SourceMgr &SM, StringRef Buffer, SMRange MatchRange, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
Prints the value of successful substitutions.
Expected< ExpressionValue >(*)(const ExpressionValue &, const ExpressionValue &) binop_eval_t
Type of functions evaluating a given binary operation.
An error that has already been reported.
Expected< ExpressionValue > eval() const override
Evaluates the value of the binary operation represented by this AST, using EvalBinop on the result of...
Represents a location in source code.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Class to represent an error holding a diagnostic with location information used when printing it.
(vector float) vec_cmpeq(*A, *B) C
ExpressionAST * getAST() const
InstructionCost operator/(const InstructionCost &LHS, const InstructionCost &RHS)
Expected< std::string > getResult() const override
virtual ~Substitution()=default
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
StringRef FromStr
The string that needs to be substituted for something else.
void log(raw_ostream &OS) const override
Print name of variable associated with this error.
Check::FileCheckType getCheckTy() const
Class to represent an undefined variable error, which quotes that variable's name when printed.
Expected< int64_t > getSignedValue() const
Class holding the Pattern global state, shared by all patterns: tables holding values of variables an...
This class implements an extremely fast bulk output stream that can only output to a stream.
static Expected< VariableProperties > parseVariable(StringRef &Str, const SourceMgr &SM)
Parses the string at the start of Str for a variable name.
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
size_t Check(const SourceMgr &SM, StringRef Buffer, bool IsLabelScanMode, size_t &MatchLen, FileCheckRequest &Req, std::vector< FileCheckDiag > *Diags) const
Matches check string and its "not strings" and/or "dag strings".
static Error reportedOrSuccess(bool HasErrorReported)
bool CheckNot(const SourceMgr &SM, StringRef Buffer, const std::vector< const Pattern * > &NotStrings, const FileCheckRequest &Req, std::vector< FileCheckDiag > *Diags) const
Verifies that none of the strings in NotStrings are found in the given Buffer.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef Prefix
Which prefix name this check matched.
MatchResult(size_t MatchPos, size_t MatchLen, Error E)
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Class representing a single binary operation in the AST of an expression.
MatchType
What type of match result does this diagnostic describe?
NumericVariable(StringRef Name, ExpressionFormat ImplicitFormat, std::optional< size_t > DefLineNumber=std::nullopt)
Constructor for a variable Name with implicit format ImplicitFormat defined at line DefLineNumber or ...
virtual Expected< ExpressionValue > eval() const =0
Evaluates and.
Substitution(FileCheckPatternContext *Context, StringRef VarName, size_t InsertIdx)
A check that we found in the input file.
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
Class representing a substitution to perform in the RegExStr string.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
std::optional< StringRef > getStringValue() const
std::optional< size_t > getDefLineNumber() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
std::optional< Match > TheMatch
static Error get(const SourceMgr &SM, SMLoc Loc, const Twine &ErrMsg, SMRange Range=std::nullopt)
Base class for user error types.
APInt operator+(APInt a, const APInt &b)
Class representing an expression and its matching format.
bool CheckSame(const SourceMgr &SM, StringRef Buffer) const
Verifies that there is no newline in the given Buffer.
APInt operator*(APInt a, uint64_t RHS)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
StringRef - Represent a constant reference to a string, i.e.
static Error get(const SourceMgr &SM, StringRef Buffer, const Twine &ErrMsg)
FileCheckPatternContext * getContext() const
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Expected< uint64_t > getUnsignedValue() const
Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const override
void clearValue()
Clears value of this numeric variable, regardless of whether it is currently defined or not.
std::error_code make_error_code(BitcodeError E)
constexpr size_t size() const
size - Get the string size.
virtual ~ExpressionAST()=default
UndefVarError(StringRef VarName)
void printFuzzyMatch(const SourceMgr &SM, StringRef Buffer, std::vector< FileCheckDiag > *Diags) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void log(raw_ostream &OS) const override
Print an error message to an output stream.
NumericSubstitution(FileCheckPatternContext *Context, StringRef ExpressionStr, std::unique_ptr< Expression > ExpressionPointer, size_t InsertIdx)
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
Lightweight error class with error context and mandatory checking.
void log(raw_ostream &OS) const override
Print diagnostic associated with this error when printing the error.
virtual Expected< std::string > getResult() const =0
StringRef getName() const
std::optional< ExpressionValue > getValue() const
ExpressionLiteral(StringRef ExpressionStr, T Val)
Class representing the use of a numeric variable in the AST of an expression.
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
BinaryOperation(StringRef ExpressionStr, binop_eval_t EvalBinop, std::unique_ptr< ExpressionAST > LeftOp, std::unique_ptr< ExpressionAST > RightOp)
std::optional< std::vector< StOtherPiece > > Other
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Contains info about various FileCheck options.
Represents a range in source code.
gvn Early GVN Hoisting of Expressions
Error defineCmdlineVariables(ArrayRef< StringRef > CmdlineDefines, SourceMgr &SM)
Defines string and numeric variables from definitions given on the command line, passed as a vector o...
static bool isValidVarNameStart(char C)
void printVariableDefs(const SourceMgr &SM, FileCheckDiag::MatchType MatchTy, std::vector< FileCheckDiag > *Diags) const
Pattern(Check::FileCheckType Ty, FileCheckPatternContext *Context, std::optional< size_t > Line=std::nullopt)
ErrorDiagnostic(SMDiagnostic &&Diag, SMRange Range)
static SMLoc getFromPointer(const char *Ptr)
Expected< ExpressionFormat > getImplicitFormat(const SourceMgr &SM) const override
Class representing a numeric variable and its associated current value.
StringRef getExpressionStr() const
FileCheckPatternContext * Context
Pointer to a class instance holding, among other things, the table with the values of live string var...
size_t CheckDag(const SourceMgr &SM, StringRef Buffer, std::vector< const Pattern * > &NotStrings, const FileCheckRequest &Req, std::vector< FileCheckDiag > *Diags) const
Matches "dag strings" and their mixed "not strings".
ExpressionFormat getFormat() const
StringRef getFromString() const
void createLineVariable()
Create @LINE pseudo variable.
LLVM Value Representation.
Parsing information about a variable.
std::vector< Pattern > DagNotStrings
All of the strings that are disallowed from occurring between this match string and the previous one ...