From 4b264663753eb7a4be93228d8f2df41b513b8ce1 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Fri, 15 Mar 2019 10:50:15 -0700 Subject: [PATCH] [flang] Accomodate missing clock_gettime(); remove f18-parse-demo dependence on lib/evaluate; allow #ifdef with no name 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 | 19 ++++++++++++------- flang/tools/f18/CMakeLists.txt | 2 +- flang/tools/f18/f18-parse-demo.cc | 14 ++++++++++++-- flang/tools/f18/stub-evaluate.cc | 27 +++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 flang/tools/f18/stub-evaluate.cc diff --git a/flang/lib/parser/preprocessor.cc b/flang/lib/parser/preprocessor.cc index 92ac42b3..149d72a 100644 --- a/flang/lib/parser/preprocessor.cc +++ b/flang/lib/parser/preprocessor.cc @@ -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, diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt index 9ff61ee..5aca86e 100644 --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -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 ) diff --git a/flang/tools/f18/f18-parse-demo.cc b/flang/tools/f18/f18-parse-demo.cc index 9379c54..83a3c3c 100644 --- a/flang/tools/f18/f18-parse-demo.cc +++ b/flang/tools/f18/f18-parse-demo.cc @@ -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 index 0000000..a5643fa --- /dev/null +++ b/flang/tools/f18/stub-evaluate.cc @@ -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) -- 2.7.4