diff --git a/flang/include/flang/Evaluate/expression.h b/flang/include/flang/Evaluate/expression.h --- a/flang/include/flang/Evaluate/expression.h +++ b/flang/include/flang/Evaluate/expression.h @@ -93,6 +93,9 @@ std::optional 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 --- a/flang/include/flang/Semantics/symbol.h +++ b/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_; diff --git a/flang/lib/Evaluate/expression.cpp b/flang/lib/Evaluate/expression.cpp --- a/flang/lib/Evaluate/expression.cpp +++ b/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 #include @@ -111,6 +112,12 @@ return left().GetType().value(); } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) +template LLVM_DUMP_METHOD void ExpressionBase::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 --- a/flang/lib/Semantics/symbol.cpp +++ b/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.).