diff --git a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp --- a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp +++ b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp @@ -9,6 +9,7 @@ #include "SnippetFile.h" #include "Error.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCParser/MCAsmParser.h" #include "llvm/MC/MCParser/MCTargetAsmParser.h" @@ -135,6 +136,21 @@ ObjectFileInfo.InitMCObjectFileInfo(TM.getTargetTriple(), /*PIC*/ false, Context); BenchmarkCodeStreamer Streamer(&Context, TM.getMCRegisterInfo(), &Result); + + std::string Error; + raw_string_ostream ErrorStream(Error); + formatted_raw_ostream InstPrinterOStream(ErrorStream); + const std::unique_ptr InstPrinter( + TM.getTarget().createMCInstPrinter( + TM.getTargetTriple(), TM.getMCAsmInfo()->getAssemblerDialect(), + *TM.getMCAsmInfo(), *TM.getMCInstrInfo(), *TM.getMCRegisterInfo())); + // The following call will take care of calling Streamer.setTargetStreamer. + TM.getTarget().createAsmTargetStreamer(Streamer, InstPrinterOStream, + InstPrinter.get(), + TM.Options.MCOptions.AsmVerbose); + if (!Streamer.getTargetStreamer()) + return make_error("cannot create target asm streamer"); + const std::unique_ptr AsmParser( createMCAsmParser(SM, Context, Streamer, *TM.getMCAsmInfo())); if (!AsmParser) diff --git a/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp --- a/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp @@ -115,6 +115,13 @@ consumeError(std::move(Error)); } +TEST_F(X86SnippetFileTest, NoAsmStreamer) { + auto Snippets = TestCommon(R"( + .cv_fpo_proc foo 4 + )"); + EXPECT_FALSE((bool)Snippets.takeError()); +} + } // namespace } // namespace exegesis } // namespace llvm