[flang-commits] [PATCH] D88692: [flang] Extend runtime API for PAUSE to allow a stop code
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Thu Oct 1 17:22:48 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3261aefc72b3: [flang] Extend runtime API for PAUSE to allow a stop code (authored by klausler).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D88692/new/
https://reviews.llvm.org/D88692
Files:
flang/runtime/stop.cpp
flang/runtime/stop.h
Index: flang/runtime/stop.h
===================================================================
--- flang/runtime/stop.h
+++ flang/runtime/stop.h
@@ -18,9 +18,11 @@
// Program-initiated image stop
NORETURN void RTNAME(StopStatement)(int code DEFAULT_VALUE(EXIT_SUCCESS),
bool isErrorStop DEFAULT_VALUE(false), bool quiet DEFAULT_VALUE(false));
-NORETURN void RTNAME(StopStatementText)(const char *,
+NORETURN void RTNAME(StopStatementText)(const char *, size_t,
bool isErrorStop DEFAULT_VALUE(false), bool quiet DEFAULT_VALUE(false));
void RTNAME(PauseStatement)(NO_ARGUMENTS);
+void RTNAME(PauseStatementInt)(int);
+void RTNAME(PauseStatementText)(const char *, size_t);
NORETURN void RTNAME(FailImageStatement)(NO_ARGUMENTS);
NORETURN void RTNAME(ProgramEndStatement)(NO_ARGUMENTS);
Index: flang/runtime/stop.cpp
===================================================================
--- flang/runtime/stop.cpp
+++ flang/runtime/stop.cpp
@@ -64,26 +64,53 @@
}
[[noreturn]] void RTNAME(StopStatementText)(
- const char *code, bool isErrorStop, bool quiet) {
+ const char *code, std::size_t length, bool isErrorStop, bool quiet) {
CloseAllExternalUnits("STOP statement");
if (!quiet) {
- std::fprintf(
- stderr, "Fortran %s: %s\n", isErrorStop ? "ERROR STOP" : "STOP", code);
+ std::fprintf(stderr, "Fortran %s: %.*s\n",
+ isErrorStop ? "ERROR STOP" : "STOP", static_cast<int>(length), code);
DescribeIEEESignaledExceptions();
}
std::exit(EXIT_FAILURE);
}
-void RTNAME(PauseStatement)() {
+static bool StartPause() {
if (Fortran::runtime::io::IsATerminal(0)) {
Fortran::runtime::io::IoErrorHandler handler{"PAUSE statement"};
Fortran::runtime::io::ExternalFileUnit::FlushAll(handler);
+ return true;
+ }
+ return false;
+}
+
+static void EndPause() {
+ std::fflush(nullptr);
+ if (std::fgetc(stdin) == EOF) {
+ CloseAllExternalUnits("PAUSE statement");
+ std::exit(EXIT_SUCCESS);
+ }
+}
+
+void RTNAME(PauseStatement)() {
+ if (StartPause()) {
std::fputs("Fortran PAUSE: hit RETURN to continue:", stderr);
- std::fflush(nullptr);
- if (std::fgetc(stdin) == EOF) {
- CloseAllExternalUnits("PAUSE statement");
- std::exit(EXIT_SUCCESS);
- }
+ EndPause();
+ }
+}
+
+void RTNAME(PauseStatementInt)(int code) {
+ if (StartPause()) {
+ std::fprintf(stderr, "Fortran PAUSE %d: hit RETURN to continue:", code);
+ EndPause();
+ }
+}
+
+void RTNAME(PauseStatementText)(const char *code, std::size_t length) {
+ if (StartPause()) {
+ std::fprintf(stderr,
+ "Fortran PAUSE %.*s: hit RETURN to continue:", static_cast<int>(length),
+ code);
+ EndPause();
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88692.295703.patch
Type: text/x-patch
Size: 2701 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20201002/c86f959e/attachment-0001.bin>
More information about the flang-commits
mailing list