[PATCH] D110856: [flang][NFC] Add debug dump method to evaluate::Expr and semantics::Symbol

Jean Perier via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 30 10:10:14 PDT 2021


jeanPerier created this revision.
jeanPerier added reviewers: clementval, schweitz, sscalpone, klausler.
jeanPerier added a project: Flang.
Herald added a subscriber: jdoerfert.
jeanPerier requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110856

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


Index: flang/lib/Semantics/symbol.cpp
===================================================================
--- flang/lib/Semantics/symbol.cpp
+++ flang/lib/Semantics/symbol.cpp
@@ -535,6 +535,10 @@
   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.).
Index: flang/lib/Evaluate/expression.cpp
===================================================================
--- flang/lib/Evaluate/expression.cpp
+++ flang/lib/Evaluate/expression.cpp
@@ -18,6 +18,7 @@
 #include "flang/Semantics/symbol.h"
 #include "flang/Semantics/tools.h"
 #include "flang/Semantics/type.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include <string>
 #include <type_traits>
@@ -111,6 +112,12 @@
   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: flang/include/flang/Semantics/symbol.h
===================================================================
--- flang/include/flang/Semantics/symbol.h
+++ flang/include/flang/Semantics/symbol.h
@@ -657,6 +657,9 @@
   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: flang/include/flang/Evaluate/expression.h
===================================================================
--- flang/include/flang/Evaluate/expression.h
+++ flang/include/flang/Evaluate/expression.h
@@ -93,6 +93,9 @@
   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 &&);
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110856.376265.patch
Type: text/x-patch
Size: 2346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210930/695d85d8/attachment.bin>


More information about the llvm-commits mailing list