[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 12:15:09 PDT 2020


klausler created this revision.
klausler added a reviewer: schweitz.
klausler added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
klausler requested review of this revision.

Support integer and default character stop codes on PAUSE
statements.  Add length argument to STOP statement with a
character stop code.


Repository:
  rG LLVM Github Monorepo

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.295645.patch
Type: text/x-patch
Size: 2701 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20201001/ada20fce/attachment.bin>


More information about the flang-commits mailing list