From 554e40d6ba1cdeef1c0b82469bce3978fabc84a9 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Mon, 13 Mar 2023 13:56:15 +0100 Subject: [PATCH] Add a message to mlir-opt when reading from stdin to avoid being waiting for nothing It happens from time to time that one may run mlir-opt expecting something to happen, but the process is waiting on stdin. Print a message when reading from stdin to warn developers. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D145469 --- mlir/lib/Tools/mlir-opt/MlirOptMain.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp index d1c5637..a9d165b 100644 --- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp +++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp @@ -32,6 +32,7 @@ #include "llvm/Support/FileUtilities.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/Process.h" #include "llvm/Support/Regex.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/StringSaver.h" @@ -338,6 +339,14 @@ LogicalResult mlir::MlirOptMain(int argc, char **argv, llvm::StringRef toolName, MlirOptMainConfig config = MlirOptMainConfig::createFromCLOptions(); config.preloadDialectsInContext(preloadDialectsInContext); + // When reading from stdin and the input is a tty, it is often a user mistak + // and the process "appears to be stuck". Print a message to let the user know + // about it! + if (inputFilename == "-" && + sys::Process::FileDescriptorIsDisplayed(fileno(stdin))) + llvm::errs() << "(processing input from stdin now, hit ctrl-c/ctrl-d to " + "interrupt)\n"; + // Set up the input file. std::string errorMessage; auto file = openInputFile(inputFilename, &errorMessage); -- 2.7.4