[flang] Accomodate missing clock_gettime(); remove f18-parse-demo dependence on lib/evaluate; allow #ifdef with no name
Original-commit: flang-compiler/f18@330fd8116f Reviewed-on: https://github.com/flang-compiler/f18/pull/335 Tree-same-pre-rewrite: false
This commit is contained in:
parent
7b77100155
commit
4b26466375
|
@ -459,17 +459,22 @@ void Preprocessor::Directive(const TokenSequence &dir, Prescanner *prescanner) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (dirName == "ifdef" || dirName == "ifndef") {
|
} else if (dirName == "ifdef" || dirName == "ifndef") {
|
||||||
|
bool doThen{false};
|
||||||
if (nameToken.empty()) {
|
if (nameToken.empty()) {
|
||||||
|
// Warning, not error, in PGI.
|
||||||
|
// This misusage appears in WRF & other SPEC codes (might be a local mod).
|
||||||
prescanner->Say(
|
prescanner->Say(
|
||||||
dir.GetIntervalProvenanceRange(dirOffset, tokens - dirOffset),
|
dir.GetIntervalProvenanceRange(dirOffset, tokens - dirOffset),
|
||||||
"#%s: missing name"_err_en_US, dirName.data());
|
"#%s: missing name"_en_US, dirName.data());
|
||||||
return;
|
} 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 (doThen) {
|
||||||
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")) {
|
|
||||||
ifStack_.push(CanDeadElseAppear::Yes);
|
ifStack_.push(CanDeadElseAppear::Yes);
|
||||||
} else {
|
} else {
|
||||||
SkipDisabledConditionalCode(dirName, IsElseActive::Yes, prescanner,
|
SkipDisabledConditionalCode(dirName, IsElseActive::Yes, prescanner,
|
||||||
|
|
|
@ -32,9 +32,9 @@ target_link_libraries(f18
|
||||||
|
|
||||||
add_executable(f18-parse-demo
|
add_executable(f18-parse-demo
|
||||||
f18-parse-demo.cc
|
f18-parse-demo.cc
|
||||||
|
stub-evaluate.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(f18-parse-demo
|
target_link_libraries(f18-parse-demo
|
||||||
FortranParser
|
FortranParser
|
||||||
FortranEvaluate
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -70,11 +70,17 @@ void CleanUpAtExit() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if _POSIX_C_SOURCE >= 199309L && defined CLOCK_PROCESS_CPUTIME_ID
|
||||||
|
static constexpr bool canTime{true};
|
||||||
double CPUseconds() {
|
double CPUseconds() {
|
||||||
struct timespec tspec;
|
struct timespec tspec;
|
||||||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tspec);
|
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tspec);
|
||||||
return tspec.tv_nsec * 1.0e-9 + tspec.tv_sec;
|
return tspec.tv_nsec * 1.0e-9 + tspec.tv_sec;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
static constexpr bool canTime{false};
|
||||||
|
double CPUseconds() { return 0; }
|
||||||
|
#endif
|
||||||
|
|
||||||
struct DriverOptions {
|
struct DriverOptions {
|
||||||
DriverOptions() {}
|
DriverOptions() {}
|
||||||
|
@ -187,8 +193,12 @@ std::string CompileFortran(
|
||||||
parsing.Parse(&std::cout);
|
parsing.Parse(&std::cout);
|
||||||
auto stop{CPUseconds()};
|
auto stop{CPUseconds()};
|
||||||
if (driver.timeParse) {
|
if (driver.timeParse) {
|
||||||
std::cout << "parse time for " << path << ": " << (stop - start)
|
if (canTime) {
|
||||||
<< " CPU seconds\n";
|
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();
|
parsing.ClearLog();
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue