[flang][NFC] Add debug dump method to evaluate::Expr and semantics::Symbol
authorJean Perier <jperier@nvidia.com>
Thu, 30 Sep 2021 21:16:29 +0000 (23:16 +0200)
committerJean Perier <jperier@nvidia.com>
Thu, 30 Sep 2021 21:26:46 +0000 (23:26 +0200)
Helps debugging when working with symbol/expression issue. The dump
method is easy to call in the debugger.

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Differential Revision: https://reviews.llvm.org/D110856

flang/include/flang/Evaluate/expression.h
flang/include/flang/Semantics/symbol.h
flang/lib/Evaluate/expression.cpp
flang/lib/Semantics/symbol.cpp

index ea68f6e..c33c242 100644 (file)
@@ -93,6 +93,9 @@ public:
   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 &&);
 };
index b287b91..2282d2b 100644 (file)
@@ -657,6 +657,9 @@ public:
   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_;
index c08e977..576e330 100644 (file)
@@ -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 {
index 60e4572..78074c3 100644 (file)
@@ -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.).