35 static llvm::cl::OptionCategory mlirQueryCategory(
"mlir-query options");
37 static llvm::cl::list<std::string> commands(
38 "c", llvm::cl::desc(
"Specify command to run"),
39 llvm::cl::value_desc(
"command"), llvm::cl::cat(mlirQueryCategory));
41 static llvm::cl::opt<std::string> inputFilename(
42 llvm::cl::Positional, llvm::cl::desc(
"<input file>"), llvm::cl::init(
"-"),
43 llvm::cl::cat(mlirQueryCategory));
45 static llvm::cl::opt<bool> noImplicitModule{
48 "Disable implicit addition of a top-level module op during parsing"),
49 llvm::cl::init(
false)};
51 static llvm::cl::opt<bool> allowUnregisteredDialects(
52 "allow-unregistered-dialect",
53 llvm::cl::desc(
"Allow operation with no registered dialects"),
54 llvm::cl::init(
false));
56 llvm::cl::HideUnrelatedOptions(mlirQueryCategory);
58 llvm::InitLLVM y(argc, argv);
60 llvm::cl::ParseCommandLineOptions(argc, argv,
"MLIR test case query tool.\n");
65 if (inputFilename ==
"-" &&
66 llvm::sys::Process::FileDescriptorIsDisplayed(fileno(stdin)))
67 llvm::errs() <<
"(processing input from stdin now, hit ctrl-c/ctrl-d to "
71 std::string errorMessage;
74 llvm::errs() << errorMessage <<
"\n";
75 return mlir::failure();
78 auto sourceMgr = llvm::SourceMgr();
79 auto bufferId = sourceMgr.AddNewSourceBuffer(std::move(file), SMLoc());
88 return mlir::failure();
92 if (!commands.empty()) {
93 for (
auto &command : commands) {
95 if (mlir::failed(queryRef->run(llvm::outs(), qs)))
96 return mlir::failure();
99 llvm::LineEditor le(
"mlir-query");
100 le.setListCompleter([&qs](llvm::StringRef line,
size_t pos) {
103 while (std::optional<std::string> line = le.readLine()) {
105 (
void)queryRef->run(llvm::outs(), qs);
106 llvm::outs().flush();
112 return mlir::success();
MLIRContext is the top-level object for a collection of MLIR operations.
void allowUnregisteredDialects(bool allow=true)
Enables creating operations in unregistered dialects.
std::unique_ptr< llvm::MemoryBuffer > openInputFile(llvm::StringRef inputFilename, std::string *errorMessage=nullptr)
Open the file specified by its name for reading.
LogicalResult parseSourceFile(const llvm::SourceMgr &sourceMgr, Block *block, const ParserConfig &config, LocationAttr *sourceFileLoc=nullptr)
This parses the file specified by the indicated SourceMgr and appends parsed operations to the given ...