[flang] Add -fdebug-dump-parse-tree and -fdebug-resolve-names
authorTim Keith <tkeith@nvidia.com>
Thu, 12 Apr 2018 21:20:26 +0000 (14:20 -0700)
committerTim Keith <tkeith@nvidia.com>
Fri, 13 Apr 2018 03:01:40 +0000 (20:01 -0700)
"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

flang/lib/semantics/ParseTreeDump.h
flang/lib/semantics/resolve-names.cc
flang/lib/semantics/resolve-names.h [new file with mode: 0644]
flang/tools/f18/CMakeLists.txt
flang/tools/f18/f18.cc
flang/tools/f18/test-type.cc [deleted file]

index 949ccce..a6f4e7d 100644 (file)
@@ -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();
index aef5181..dc9522d 100644 (file)
@@ -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 (file)
index 0000000..6689d1f
--- /dev/null
@@ -0,0 +1,10 @@
+#include <iosfwd>
+
+namespace Fortran::parser {
+class Program;
+class CookedSource;
+}  // namespace Fortran::parser
+
+namespace Fortran::semantics {
+void ResolveNames(const parser::Program &, const parser::CookedSource &);
+}  // namespace Fortran::semantics
index bb64814..7a197a5 100644 (file)
@@ -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 ##########
 
index fec8f67..d12ec01 100644 (file)
@@ -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 <cerrno>
 #include <cstdio>
 #include <cstring>
@@ -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<std::string> 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 (file)
index 4db3d1f..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "../../lib/parser/parsing.h"
-#include "../../lib/semantics/make-types.h"
-
-#include <iostream>
-#include <string>
-
-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;
-}