[flang-commits] [flang] fdcbb54 - [flang][NFC] Add debug dump method to evaluate::Expr and semantics::Symbol
Jean Perier via flang-commits
flang-commits at lists.llvm.org
Thu Sep 30 14:27:09 PDT 2021
Author: Jean Perier
Date: 2021-09-30T23:26:46+02:00
New Revision: fdcbb540fc5ffbf5faa03c2f10fa88ca2c38f845
URL: https://github.com/llvm/llvm-project/commit/fdcbb540fc5ffbf5faa03c2f10fa88ca2c38f845
DIFF: https://github.com/llvm/llvm-project/commit/fdcbb540fc5ffbf5faa03c2f10fa88ca2c38f845.diff
LOG: [flang][NFC] Add debug dump method to evaluate::Expr and semantics::Symbol
Helps debugging when working with symbol/expression issue. The dump
method is easy to call in the debugger.
Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>
Differential Revision: https://reviews.llvm.org/D110856
Added:
Modified:
flang/include/flang/Evaluate/expression.h
flang/include/flang/Semantics/symbol.h
flang/lib/Evaluate/expression.cpp
flang/lib/Semantics/symbol.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Evaluate/expression.h b/flang/include/flang/Evaluate/expression.h
index ea68f6e3e9de0..c33c2422af13c 100644
--- a/flang/include/flang/Evaluate/expression.h
+++ b/flang/include/flang/Evaluate/expression.h
@@ -93,6 +93,9 @@ template <typename RESULT> class ExpressionBase {
std::optional<DynamicType> GetType() const;
int Rank() const;
std::string AsFortran() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
static Derived Rewrite(FoldingContext &, Derived &&);
};
diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index b287b91e14fb7..2282d2bf19192 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -657,6 +657,9 @@ class Symbol {
const DerivedTypeSpec *GetParentTypeSpec(const Scope * = nullptr) const;
SemanticsContext &GetSemanticsContext() const;
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+ LLVM_DUMP_METHOD void dump() const;
+#endif
private:
const Scope *owner_;
diff --git a/flang/lib/Evaluate/expression.cpp b/flang/lib/Evaluate/expression.cpp
index c08e9771514b0..576e3309d536e 100644
--- a/flang/lib/Evaluate/expression.cpp
+++ b/flang/lib/Evaluate/expression.cpp
@@ -111,6 +111,12 @@ DynamicType Parentheses<SomeDerived>::GetType() const {
return left().GetType().value();
}
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+template <typename A> LLVM_DUMP_METHOD void ExpressionBase<A>::dump() const {
+ llvm::errs() << "Expr is <{" << AsFortran() << "}>\n";
+}
+#endif
+
// Equality testing
bool ImpliedDoIndex::operator==(const ImpliedDoIndex &that) const {
diff --git a/flang/lib/Semantics/symbol.cpp b/flang/lib/Semantics/symbol.cpp
index 60e4572547857..78074c3631ed5 100644
--- a/flang/lib/Semantics/symbol.cpp
+++ b/flang/lib/Semantics/symbol.cpp
@@ -535,6 +535,10 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Symbol &symbol) {
return os;
}
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+void Symbol::dump() const { llvm::errs() << *this << '\n'; }
+#endif
+
// Output a unique name for a scope by qualifying it with the names of
// parent scopes. For scopes without corresponding symbols, use the kind
// with an index (e.g. Block1, Block2, etc.).
More information about the flang-commits
mailing list