[flang] Accomodate missing clock_gettime(); remove f18-parse-demo dependence on lib...
authorpeter klausler <pklausler@nvidia.com>
Fri, 15 Mar 2019 17:50:15 +0000 (10:50 -0700)
committerpeter klausler <pklausler@nvidia.com>
Fri, 15 Mar 2019 17:50:15 +0000 (10:50 -0700)
Original-commit: flang-compiler/f18@330fd8116febab2416afeb8c08d6216c1edd9e55
Reviewed-on: https://github.com/flang-compiler/f18/pull/335
Tree-same-pre-rewrite: false

flang/lib/parser/preprocessor.cc
flang/tools/f18/CMakeLists.txt
flang/tools/f18/f18-parse-demo.cc
flang/tools/f18/stub-evaluate.cc [new file with mode: 0644]

index 92ac42b..149d72a 100644 (file)
@@ -459,17 +459,22 @@ void Preprocessor::Directive(const TokenSequence &dir, Prescanner *prescanner) {
       }
     }
   } else if (dirName == "ifdef" || dirName == "ifndef") {
+    bool doThen{false};
     if (nameToken.empty()) {
+      // Warning, not error, in PGI.
+      // This misusage appears in WRF & other SPEC codes (might be a local mod).
       prescanner->Say(
           dir.GetIntervalProvenanceRange(dirOffset, tokens - dirOffset),
-          "#%s: missing name"_err_en_US, dirName.data());
-      return;
+          "#%s: missing name"_en_US, dirName.data());
+    } else {
+      j = dir.SkipBlanks(j + 1);
+      if (j != tokens) {
+        prescanner->Say(dir.GetIntervalProvenanceRange(j, tokens - j),
+            "#%s: excess tokens at end of directive"_en_US, dirName.data());
+      }
+      doThen = IsNameDefined(nameToken) == (dirName == "ifdef");
     }
-    j = dir.SkipBlanks(j + 1);
-    if (j != tokens) {
-      prescanner->Say(dir.GetIntervalProvenanceRange(j, tokens - j),
-          "#%s: excess tokens at end of directive"_err_en_US, dirName.data());
-    } else if (IsNameDefined(nameToken) == (dirName == "ifdef")) {
+    if (doThen) {
       ifStack_.push(CanDeadElseAppear::Yes);
     } else {
       SkipDisabledConditionalCode(dirName, IsElseActive::Yes, prescanner,
index 9ff61ee..5aca86e 100644 (file)
@@ -32,9 +32,9 @@ target_link_libraries(f18
 
 add_executable(f18-parse-demo
   f18-parse-demo.cc
+  stub-evaluate.cc
 )
 
 target_link_libraries(f18-parse-demo
   FortranParser
-  FortranEvaluate
 )
index 9379c54..83a3c3c 100644 (file)
@@ -70,11 +70,17 @@ void CleanUpAtExit() {
   }
 }
 
+#if _POSIX_C_SOURCE >= 199309L && defined CLOCK_PROCESS_CPUTIME_ID
+static constexpr bool canTime{true};
 double CPUseconds() {
   struct timespec tspec;
   clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tspec);
   return tspec.tv_nsec * 1.0e-9 + tspec.tv_sec;
 }
+#else
+static constexpr bool canTime{false};
+double CPUseconds() { return 0; }
+#endif
 
 struct DriverOptions {
   DriverOptions() {}
@@ -187,8 +193,12 @@ std::string CompileFortran(
   parsing.Parse(&std::cout);
   auto stop{CPUseconds()};
   if (driver.timeParse) {
-    std::cout << "parse time for " << path << ": " << (stop - start)
-              << " CPU seconds\n";
+    if (canTime) {
+      std::cout << "parse time for " << path << ": " << (stop - start)
+                << " CPU seconds\n";
+    } else {
+      std::cout << "no timing information due to lack of clock_gettime()\n";
+    }
   }
 
   parsing.ClearLog();
diff --git a/flang/tools/f18/stub-evaluate.cc b/flang/tools/f18/stub-evaluate.cc
new file mode 100644 (file)
index 0000000..a5643fa
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (c) 2018-2019, NVIDIA CORPORATION.  All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// The parse tree has slots in which pointers to typed expressions may be
+// placed.  When using the parser without the expression library, as here,
+// we need to stub out the dependence.
+
+#include "../../lib/common/indirection.h"
+
+namespace Fortran::evaluate {
+struct GenericExprWrapper {
+  bool operator==(const GenericExprWrapper &) const { return false; }
+};
+}
+
+DEFINE_OWNING_DESTRUCTOR(OwningPointer, evaluate::GenericExprWrapper)