diff options
author | Thomas Preud'homme <thomas.preudhomme@arm.com> | 2023-07-03 22:51:55 +0000 |
---|---|---|
committer | Thomas Preud'homme <thomas.preudhomme@arm.com> | 2023-08-07 17:36:05 +0100 |
commit | e15e969a4faca759fe7f0e4ab0f54aed43f98bbc (patch) | |
tree | 95b8d5186602c1f370de2572d0961befdaefbc63 /llvm/lib/FileCheck/FileCheck.cpp | |
parent | e894c3d1a9ac50f5e91a7ab9e28cab74b6e349f2 (diff) | |
download | llvm-e15e969a4faca759fe7f0e4ab0f54aed43f98bbc.zip llvm-e15e969a4faca759fe7f0e4ab0f54aed43f98bbc.tar.gz llvm-e15e969a4faca759fe7f0e4ab0f54aed43f98bbc.tar.bz2 |
[FileCheck, 4/4] NFC: Stop using ExpressionValue
Use APInt directly instead.
Depends On D150880
Reviewed By: arichardson
Differential Revision: https://reviews.llvm.org/D154430
Diffstat (limited to 'llvm/lib/FileCheck/FileCheck.cpp')
-rw-r--r-- | llvm/lib/FileCheck/FileCheck.cpp | 89 |
1 files changed, 34 insertions, 55 deletions
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp index b344b71..60a0d59 100644 --- a/llvm/lib/FileCheck/FileCheck.cpp +++ b/llvm/lib/FileCheck/FileCheck.cpp @@ -78,8 +78,7 @@ Expected<std::string> ExpressionFormat::getWildcardRegex() const { } Expected<std::string> -ExpressionFormat::getMatchingString(ExpressionValue IntegerValue) const { - APInt IntValue = IntegerValue.getAPIntValue(); +ExpressionFormat::getMatchingString(APInt IntValue) const { if (Value != Kind::Signed && IntValue.isNegative()) return make_error<OverflowError>(); @@ -135,7 +134,7 @@ static APInt toSigned(APInt AbsVal, bool Negative) { return Result; } -Expected<ExpressionValue> +Expected<APInt> ExpressionFormat::valueFromStringRepr(StringRef StrVal, const SourceMgr &SM) const { bool ValueIsSigned = Value == Kind::Signed; @@ -155,76 +154,59 @@ ExpressionFormat::valueFromStringRepr(StringRef StrVal, if (ParseFailure) return ErrorDiagnostic::get(SM, StrVal, "unable to represent numeric value"); - return ExpressionValue(toSigned(ResultValue, Negative)); + return toSigned(ResultValue, Negative); } -Expected<ExpressionValue> llvm::exprAdd(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { - APInt Result = LeftOperand.getAPIntValue().sadd_ov( - RightOperand.getAPIntValue(), Overflow); - return ExpressionValue(Result); +Expected<APInt> llvm::exprAdd(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { + return LeftOperand.sadd_ov(RightOperand, Overflow); } -Expected<ExpressionValue> llvm::exprSub(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { - APInt Result = LeftOperand.getAPIntValue().ssub_ov( - RightOperand.getAPIntValue(), Overflow); - return ExpressionValue(Result); +Expected<APInt> llvm::exprSub(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { + return LeftOperand.ssub_ov(RightOperand, Overflow); } -Expected<ExpressionValue> llvm::exprMul(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { - APInt Result = LeftOperand.getAPIntValue().smul_ov( - RightOperand.getAPIntValue(), Overflow); - return ExpressionValue(Result); +Expected<APInt> llvm::exprMul(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { + return LeftOperand.smul_ov(RightOperand, Overflow); } -Expected<ExpressionValue> llvm::exprDiv(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { +Expected<APInt> llvm::exprDiv(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { // Check for division by zero. - if (RightOperand.getAPIntValue().isZero()) + if (RightOperand.isZero()) return make_error<OverflowError>(); - APInt Result = LeftOperand.getAPIntValue().sdiv_ov( - RightOperand.getAPIntValue(), Overflow); - return ExpressionValue(Result); + return LeftOperand.sdiv_ov(RightOperand, Overflow); } -Expected<ExpressionValue> llvm::exprMax(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { +Expected<APInt> llvm::exprMax(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { Overflow = false; - return LeftOperand.getAPIntValue().slt(RightOperand.getAPIntValue()) - ? RightOperand - : LeftOperand; + return LeftOperand.slt(RightOperand) ? RightOperand : LeftOperand; } -Expected<ExpressionValue> llvm::exprMin(const ExpressionValue &LeftOperand, - const ExpressionValue &RightOperand, - bool &Overflow) { +Expected<APInt> llvm::exprMin(const APInt &LeftOperand, + const APInt &RightOperand, bool &Overflow) { Overflow = false; - if (cantFail(exprMax(LeftOperand, RightOperand, Overflow)).getAPIntValue() == - LeftOperand.getAPIntValue()) + if (cantFail(exprMax(LeftOperand, RightOperand, Overflow)) == LeftOperand) return RightOperand; return LeftOperand; } -Expected<ExpressionValue> NumericVariableUse::eval() const { - std::optional<ExpressionValue> Value = Variable->getValue(); +Expected<APInt> NumericVariableUse::eval() const { + std::optional<APInt> Value = Variable->getValue(); if (Value) return *Value; return make_error<UndefVarError>(getExpressionStr()); } -Expected<ExpressionValue> BinaryOperation::eval() const { - Expected<ExpressionValue> MaybeLeftOp = LeftOperand->eval(); - Expected<ExpressionValue> MaybeRightOp = RightOperand->eval(); +Expected<APInt> BinaryOperation::eval() const { + Expected<APInt> MaybeLeftOp = LeftOperand->eval(); + Expected<APInt> MaybeRightOp = RightOperand->eval(); // Bubble up any error (e.g. undefined variables) in the recursive // evaluation. @@ -237,8 +219,8 @@ Expected<ExpressionValue> BinaryOperation::eval() const { return std::move(Err); } - APInt LeftOp = MaybeLeftOp->getAPIntValue(); - APInt RightOp = MaybeRightOp->getAPIntValue(); + APInt LeftOp = *MaybeLeftOp; + APInt RightOp = *MaybeRightOp; bool Overflow; // Ensure both operands have the same bitwidth. unsigned LeftBitWidth = LeftOp.getBitWidth(); @@ -247,8 +229,7 @@ Expected<ExpressionValue> BinaryOperation::eval() const { LeftOp = LeftOp.sext(NewBitWidth); RightOp = RightOp.sext(NewBitWidth); do { - Expected<ExpressionValue> MaybeResult = - EvalBinop(ExpressionValue(LeftOp), ExpressionValue(RightOp), Overflow); + Expected<APInt> MaybeResult = EvalBinop(LeftOp, RightOp, Overflow); if (!MaybeResult) return MaybeResult.takeError(); @@ -291,8 +272,7 @@ BinaryOperation::getImplicitFormat(const SourceMgr &SM) const { Expected<std::string> NumericSubstitution::getResult() const { assert(ExpressionPointer->getAST() != nullptr && "Substituting empty expression"); - Expected<ExpressionValue> EvaluatedValue = - ExpressionPointer->getAST()->eval(); + Expected<APInt> EvaluatedValue = ExpressionPointer->getAST()->eval(); if (!EvaluatedValue) return EvaluatedValue.takeError(); ExpressionFormat Format = ExpressionPointer->getFormat(); @@ -1117,7 +1097,7 @@ Pattern::MatchResult Pattern::match(StringRef Buffer, TmpStr = RegExStr; if (LineNumber) Context->LineVariable->setValue( - ExpressionValue(APInt(sizeof(*LineNumber) * 8, *LineNumber))); + APInt(sizeof(*LineNumber) * 8, *LineNumber)); size_t InsertOffset = 0; // Substitute all string variables and expressions whose values are only @@ -1196,8 +1176,7 @@ Pattern::MatchResult Pattern::match(StringRef Buffer, StringRef MatchedValue = MatchInfo[CaptureParenGroup]; ExpressionFormat Format = DefinedNumericVariable->getImplicitFormat(); - Expected<ExpressionValue> Value = - Format.valueFromStringRepr(MatchedValue, SM); + Expected<APInt> Value = Format.valueFromStringRepr(MatchedValue, SM); if (!Value) return MatchResult(TheMatch, Value.takeError()); DefinedNumericVariable->setValue(*Value, MatchedValue); @@ -2583,7 +2562,7 @@ Error FileCheckPatternContext::defineCmdlineVariables( // to, since the expression of a command-line variable definition should // only use variables defined earlier on the command-line. If not, this // is an error and we report it. - Expected<ExpressionValue> Value = Expression->getAST()->eval(); + Expected<APInt> Value = Expression->getAST()->eval(); if (!Value) { Errs = joinErrors(std::move(Errs), Value.takeError()); continue; |