message: Use SourceMgrDiagnosticHandler in mlir-translate for translations from MLIR input.
  Report errors using the file and line location using SourceMgr's diagnostic reporting. Reduce some horizontal white spacing too.
diff: //
  //===----------------------------------------------------------------------===//
  +#include "mlir/IR/Diagnostics.h"
  #include "mlir/IR/MLIRContext.h"
  #include "mlir/IR/Module.h"
  #include "mlir/Parser.h"
  @@ -43,7 +44,8 @@ static llvm::cl::opt<std::string>
  outputFilename("o", llvm::cl::desc("Output filename"),
  llvm::cl::value_desc("filename"), llvm::cl::init("-"));
  -static Module *parseMLIRInput(StringRef inputFilename, MLIRContext *context) {
  +static Module *parseMLIRInput(StringRef inputFilename, MLIRContext *context,
  + llvm::SourceMgr &sourceMgr) {
  // Set up the input file.
  std::string errorMessage;
  auto file = openInputFile(inputFilename, &errorMessage);
  @@ -52,7 +54,6 @@ static Module *parseMLIRInput(StringRef inputFilename, MLIRContext *context) {
  return nullptr;
  }
  - llvm::SourceMgr sourceMgr;
  sourceMgr.AddNewSourceBuffer(std::move(file), llvm::SMLoc());
  return parseSourceFile(sourceMgr, context);
  }
  @@ -79,7 +80,13 @@ static llvm::SmallVector<TranslateFunction, 16> wrapperStorage;
  // Wraps TranslateToMLIRFunctions and TranslateFromMLIRFunctions into
  // TranslateFunctions before registering them as options.
  struct TranslationParser : public llvm::cl::parser<const TranslateFunction *> {
  - TranslationParser(llvm::cl::Option &opt)
  + TranslationParser(llvm::cl::Option &opt);
  +
  + void printOptionInfo(const llvm::cl::Option &O,
  + size_t GlobalWidth) const override;
  +};
  +
  +TranslationParser::TranslationParser(llvm::cl::Option &opt)
  : llvm::cl::parser<const TranslateFunction *>(opt) {
  const auto &toMLIRRegistry = getTranslationToMLIRRegistry();
  const auto &fromMLIRRegistry = getTranslationFromMLIRRegistry();
  @@ -101,13 +108,16 @@ struct TranslationParser : public llvm::cl::parser<const TranslateFunction *> {
  addLiteralOption(kv.first(), &wrapperStorage.back(), kv.first());
  }
  +
  for (const auto &kv : fromMLIRRegistry) {
  TranslateFromMLIRFunction function = kv.second;
  TranslateFunction wrapper = [function](StringRef inputFilename,
  StringRef outputFilename,
  MLIRContext *context) {
  - auto module =
  - std::unique_ptr<Module>(parseMLIRInput(inputFilename, context));
  + llvm::SourceMgr sourceMgr;
  + SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, context);
  + auto module = std::unique_ptr<Module>(
  + parseMLIRInput(inputFilename, context, sourceMgr));
  if (!module)
  return true;
  return function(module.get(), outputFilename);
  @@ -118,8 +128,8 @@ struct TranslationParser : public llvm::cl::parser<const TranslateFunction *> {
  }
  }
  - void printOptionInfo(const llvm::cl::Option &O,
  - size_t GlobalWidth) const override {
  +void TranslationParser::printOptionInfo(const llvm::cl::Option &O,
  + size_t GlobalWidth) const {
  TranslationParser *TP = const_cast<TranslationParser *>(this);
  llvm::array_pod_sort(TP->Values.begin(), TP->Values.end(),
  [](const TranslationParser::OptionInfo *VT1,
  @@ -129,7 +139,6 @@ struct TranslationParser : public llvm::cl::parser<const TranslateFunction *> {
  using llvm::cl::parser;
  parser<const TranslateFunction *>::printOptionInfo(O, GlobalWidth);
  }
  -};
  int main(int argc, char **argv) {
  llvm::PrettyStackTraceProgram x(argc, argv);
  