From: Tim Keith Date: Thu, 12 Apr 2018 21:20:26 +0000 (-0700) Subject: [flang] Add -fdebug-dump-parse-tree and -fdebug-resolve-names X-Git-Tag: llvmorg-12-init~9537^2~2723 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c9d838e8a70662a970c283d21f98fd4b6ab66685;p=platform%2Fupstream%2Fllvm.git [flang] Add -fdebug-dump-parse-tree and -fdebug-resolve-names "f18 -fdebug-resolve-names -fparse-only ..." is equivalent to what test-type used to do, so the test-type executable can be eliminated. -fdebug-dump-parse-tree does the parse-tree dumping that test-sema does, but test-sema does more so I have left it alone. Original-commit: flang-compiler/f18@8b3816528e6463acd18bbf6ed29c40869b15ea3a Reviewed-on: https://github.com/flang-compiler/f18/pull/55 --- diff --git a/flang/lib/semantics/ParseTreeDump.h b/flang/lib/semantics/ParseTreeDump.h index 949ccce..a6f4e7d 100644 --- a/flang/lib/semantics/ParseTreeDump.h +++ b/flang/lib/semantics/ParseTreeDump.h @@ -111,6 +111,8 @@ public: } } + bool Pre(const parser::Name &x) { return Pre(x.ToString()); } + bool Pre(const std::string &x) { if (emptyline ) { out_indent(); diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index aef5181..dc9522d 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -1,3 +1,4 @@ +#include "resolve-names.h" #include "attr.h" #include "scope.h" #include "symbol.h" diff --git a/flang/lib/semantics/resolve-names.h b/flang/lib/semantics/resolve-names.h new file mode 100644 index 0000000..6689d1f --- /dev/null +++ b/flang/lib/semantics/resolve-names.h @@ -0,0 +1,10 @@ +#include + +namespace Fortran::parser { +class Program; +class CookedSource; +} // namespace Fortran::parser + +namespace Fortran::semantics { +void ResolveNames(const parser::Program &, const parser::CookedSource &); +} // namespace Fortran::semantics diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt index bb64814..7a197a5 100644 --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -6,18 +6,8 @@ add_executable( f18 ) target_link_libraries( f18 FortranParser - ) - -######## test-type ########## - -add_executable( test-type - test-type.cc -) - -target_link_libraries( test-type - FortranParser FlangSemantics - ) +) ######## test-sema ########## diff --git a/flang/tools/f18/f18.cc b/flang/tools/f18/f18.cc index fec8f67..d12ec01 100644 --- a/flang/tools/f18/f18.cc +++ b/flang/tools/f18/f18.cc @@ -7,6 +7,8 @@ #include "../../lib/parser/parsing.h" #include "../../lib/parser/provenance.h" #include "../../lib/parser/unparse.h" +#include "../../lib/semantics/ParseTreeDump.h" +#include "../../lib/semantics/resolve-names.h" #include #include #include @@ -68,6 +70,8 @@ struct DriverOptions { bool dumpProvenance{false}; bool dumpCookedChars{false}; bool dumpUnparse{false}; + bool dumpParseTree{false}; + bool debugResolveNames{false}; bool measureTree{false}; std::vector pgf90Args; const char *prefix{nullptr}; @@ -172,6 +176,13 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options, if (driver.measureTree) { MeasureParseTree(*parsing.parseTree()); } + if (driver.debugResolveNames) { + Fortran::semantics::ResolveNames( + *parsing.parseTree(), parsing.messages().cooked()); + } + if (driver.dumpParseTree) { + Fortran::parser::DumpTree(*parsing.parseTree()); + } if (driver.dumpUnparse) { Unparse(std::cout, *parsing.parseTree(), driver.encoding, true /*capitalize*/); @@ -306,6 +317,10 @@ int main(int argc, char *const argv[]) { driver.dumpCookedChars = true; } else if (arg == "-fdebug-dump-provenance") { driver.dumpProvenance = true; + } else if (arg == "-fdebug-dump-parse-tree") { + driver.dumpParseTree = true; + } else if (arg == "-fdebug-resolve-names") { + driver.debugResolveNames = true; } else if (arg == "-fdebug-measure-parse-tree") { driver.measureTree = true; } else if (arg == "-funparse") { @@ -341,6 +356,8 @@ int main(int argc, char *const argv[]) { << " -funparse parse & reformat only, no code generation\n" << " -fdebug-measure-parse-tree\n" << " -fdebug-dump-provenance\n" + << " -fdebug-dump-parse-tree\n" + << " -fdebug-resolve-names\n" << " -v -c -o -I -D -U have their usual meanings\n" << " -help print this again\n" << "Other options are passed through to the compiler.\n"; diff --git a/flang/tools/f18/test-type.cc b/flang/tools/f18/test-type.cc deleted file mode 100644 index 4db3d1f..0000000 --- a/flang/tools/f18/test-type.cc +++ /dev/null @@ -1,22 +0,0 @@ -#include "../../lib/parser/parsing.h" -#include "../../lib/semantics/make-types.h" - -#include -#include - -using namespace Fortran; -using namespace parser; - -int main(int argc, char *const argv[]) { - if (argc != 2) { - std::cerr << "Expected 1 source file, got " << (argc - 1) << "\n"; - return EXIT_FAILURE; - } - std::string path{argv[1]}; - parser::Parsing parsing; - if (parsing.ForTesting(path, std::cerr)) { - semantics::MakeTypes(*parsing.parseTree(), parsing.messages().cooked()); - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -}