1 //===-- llvm-mc.cpp - Machine Code Hacking Driver ---------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This utility is a simple driver that allows command line hacking on machine 10 // code. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "Disassembler.h" 15 #include "llvm/MC/MCAsmBackend.h" 16 #include "llvm/MC/MCAsmInfo.h" 17 #include "llvm/MC/MCCodeEmitter.h" 18 #include "llvm/MC/MCContext.h" 19 #include "llvm/MC/MCInstPrinter.h" 20 #include "llvm/MC/MCInstrInfo.h" 21 #include "llvm/MC/MCObjectFileInfo.h" 22 #include "llvm/MC/MCObjectWriter.h" 23 #include "llvm/MC/MCParser/AsmLexer.h" 24 #include "llvm/MC/MCParser/MCTargetAsmParser.h" 25 #include "llvm/MC/MCRegisterInfo.h" 26 #include "llvm/MC/MCStreamer.h" 27 #include "llvm/MC/MCSubtargetInfo.h" 28 #include "llvm/MC/MCTargetOptionsCommandFlags.h" 29 #include "llvm/MC/TargetRegistry.h" 30 #include "llvm/Support/CommandLine.h" 31 #include "llvm/Support/Compression.h" 32 #include "llvm/Support/FileUtilities.h" 33 #include "llvm/Support/FormattedStream.h" 34 #include "llvm/Support/InitLLVM.h" 35 #include "llvm/Support/MemoryBuffer.h" 36 #include "llvm/Support/SourceMgr.h" 37 #include "llvm/Support/TargetSelect.h" 38 #include "llvm/Support/ToolOutputFile.h" 39 #include "llvm/Support/WithColor.h" 40 #include "llvm/TargetParser/Host.h" 41 42 using namespace llvm; 43 44 static mc::RegisterMCTargetOptionsFlags MOF; 45 46 static cl::OptionCategory MCCategory("MC Options"); 47 48 static cl::opt<std::string> InputFilename(cl::Positional, 49 cl::desc("<input file>"), 50 cl::init("-"), cl::cat(MCCategory)); 51 52 static cl::list<std::string> 53 DisassemblerOptions("M", cl::desc("Disassembler options"), 54 cl::cat(MCCategory)); 55 56 static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"), 57 cl::value_desc("filename"), 58 cl::init("-"), cl::cat(MCCategory)); 59 60 static cl::opt<std::string> SplitDwarfFile("split-dwarf-file", 61 cl::desc("DWO output filename"), 62 cl::value_desc("filename"), 63 cl::cat(MCCategory)); 64 65 static cl::opt<bool> ShowEncoding("show-encoding", 66 cl::desc("Show instruction encodings"), 67 cl::cat(MCCategory)); 68 69 static cl::opt<DebugCompressionType> CompressDebugSections( 70 "compress-debug-sections", cl::ValueOptional, 71 cl::init(DebugCompressionType::None), 72 cl::desc("Choose DWARF debug sections compression:"), 73 cl::values(clEnumValN(DebugCompressionType::None, "none", "No compression"), 74 clEnumValN(DebugCompressionType::Zlib, "zlib", "Use zlib"), 75 clEnumValN(DebugCompressionType::Zstd, "zstd", "Use zstd")), 76 cl::cat(MCCategory)); 77 78 static cl::opt<bool> 79 ShowInst("show-inst", cl::desc("Show internal instruction representation"), 80 cl::cat(MCCategory)); 81 82 static cl::opt<bool> 83 ShowInstOperands("show-inst-operands", 84 cl::desc("Show instructions operands as parsed"), 85 cl::cat(MCCategory)); 86 87 static cl::opt<unsigned> 88 OutputAsmVariant("output-asm-variant", 89 cl::desc("Syntax variant to use for output printing"), 90 cl::cat(MCCategory)); 91 92 static cl::opt<bool> 93 PrintImmHex("print-imm-hex", cl::init(false), 94 cl::desc("Prefer hex format for immediate values"), 95 cl::cat(MCCategory)); 96 97 static cl::opt<bool> 98 HexBytes("hex", 99 cl::desc("Take raw hexadecimal bytes as input for disassembly. " 100 "Whitespace is ignored"), 101 cl::cat(MCCategory)); 102 103 static cl::list<std::string> 104 DefineSymbol("defsym", 105 cl::desc("Defines a symbol to be an integer constant"), 106 cl::cat(MCCategory)); 107 108 static cl::opt<bool> 109 PreserveComments("preserve-comments", 110 cl::desc("Preserve Comments in outputted assembly"), 111 cl::cat(MCCategory)); 112 113 static cl::opt<unsigned> CommentColumn("comment-column", 114 cl::desc("Asm comments indentation"), 115 cl::init(40)); 116 117 enum OutputFileType { 118 OFT_Null, 119 OFT_AssemblyFile, 120 OFT_ObjectFile 121 }; 122 static cl::opt<OutputFileType> 123 FileType("filetype", cl::init(OFT_AssemblyFile), 124 cl::desc("Choose an output file type:"), 125 cl::values(clEnumValN(OFT_AssemblyFile, "asm", 126 "Emit an assembly ('.s') file"), 127 clEnumValN(OFT_Null, "null", 128 "Don't emit anything (for timing purposes)"), 129 clEnumValN(OFT_ObjectFile, "obj", 130 "Emit a native object ('.o') file")), 131 cl::cat(MCCategory)); 132 133 static cl::list<std::string> IncludeDirs("I", 134 cl::desc("Directory of include files"), 135 cl::value_desc("directory"), 136 cl::Prefix, cl::cat(MCCategory)); 137 138 static cl::opt<std::string> 139 ArchName("arch", 140 cl::desc("Target arch to assemble for, " 141 "see -version for available targets"), 142 cl::cat(MCCategory)); 143 144 static cl::opt<std::string> 145 TripleName("triple", 146 cl::desc("Target triple to assemble for, " 147 "see -version for available targets"), 148 cl::cat(MCCategory)); 149 150 static cl::opt<std::string> 151 MCPU("mcpu", 152 cl::desc("Target a specific cpu type (-mcpu=help for details)"), 153 cl::value_desc("cpu-name"), cl::init(""), cl::cat(MCCategory)); 154 155 static cl::list<std::string> 156 MAttrs("mattr", cl::CommaSeparated, 157 cl::desc("Target specific attributes (-mattr=help for details)"), 158 cl::value_desc("a1,+a2,-a3,..."), cl::cat(MCCategory)); 159 160 static cl::opt<bool> PIC("position-independent", 161 cl::desc("Position independent"), cl::init(false), 162 cl::cat(MCCategory)); 163 164 static cl::opt<bool> 165 LargeCodeModel("large-code-model", 166 cl::desc("Create cfi directives that assume the code might " 167 "be more than 2gb away"), 168 cl::cat(MCCategory)); 169 170 static cl::opt<bool> 171 NoInitialTextSection("n", 172 cl::desc("Don't assume assembly file starts " 173 "in the text section"), 174 cl::cat(MCCategory)); 175 176 static cl::opt<bool> 177 GenDwarfForAssembly("g", 178 cl::desc("Generate dwarf debugging info for assembly " 179 "source files"), 180 cl::cat(MCCategory)); 181 182 static cl::opt<std::string> 183 DebugCompilationDir("fdebug-compilation-dir", 184 cl::desc("Specifies the debug info's compilation dir"), 185 cl::cat(MCCategory)); 186 187 static cl::list<std::string> DebugPrefixMap( 188 "fdebug-prefix-map", cl::desc("Map file source paths in debug info"), 189 cl::value_desc("= separated key-value pairs"), cl::cat(MCCategory)); 190 191 static cl::opt<std::string> MainFileName( 192 "main-file-name", 193 cl::desc("Specifies the name we should consider the input file"), 194 cl::cat(MCCategory)); 195 196 static cl::opt<bool> LexMasmIntegers( 197 "masm-integers", 198 cl::desc("Enable binary and hex masm integers (0b110 and 0ABCh)"), 199 cl::cat(MCCategory)); 200 201 static cl::opt<bool> LexMasmHexFloats( 202 "masm-hexfloats", 203 cl::desc("Enable MASM-style hex float initializers (3F800000r)"), 204 cl::cat(MCCategory)); 205 206 static cl::opt<bool> LexMotorolaIntegers( 207 "motorola-integers", 208 cl::desc("Enable binary and hex Motorola integers (%110 and $ABC)"), 209 cl::cat(MCCategory)); 210 211 static cl::opt<bool> NoExecStack("no-exec-stack", 212 cl::desc("File doesn't need an exec stack"), 213 cl::cat(MCCategory)); 214 215 enum ActionType { 216 AC_AsLex, 217 AC_Assemble, 218 AC_Disassemble, 219 AC_MDisassemble, 220 AC_CDisassemble, 221 }; 222 223 static cl::opt<ActionType> Action( 224 cl::desc("Action to perform:"), cl::init(AC_Assemble), 225 cl::values(clEnumValN(AC_AsLex, "as-lex", "Lex tokens from a .s file"), 226 clEnumValN(AC_Assemble, "assemble", 227 "Assemble a .s file (default)"), 228 clEnumValN(AC_Disassemble, "disassemble", 229 "Disassemble strings of hex bytes"), 230 clEnumValN(AC_MDisassemble, "mdis", 231 "Marked up disassembly of strings of hex bytes"), 232 clEnumValN(AC_CDisassemble, "cdis", 233 "Colored disassembly of strings of hex bytes")), 234 cl::cat(MCCategory)); 235 236 static const Target *GetTarget(const char *ProgName) { 237 // Figure out the target triple. 238 if (TripleName.empty()) 239 TripleName = sys::getDefaultTargetTriple(); 240 Triple TheTriple(Triple::normalize(TripleName)); 241 242 // Get the target specific parser. 243 std::string Error; 244 const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple, 245 Error); 246 if (!TheTarget) { 247 WithColor::error(errs(), ProgName) << Error; 248 return nullptr; 249 } 250 251 // Update the triple name and return the found target. 252 TripleName = TheTriple.getTriple(); 253 return TheTarget; 254 } 255 256 static std::unique_ptr<ToolOutputFile> GetOutputStream(StringRef Path, 257 sys::fs::OpenFlags Flags) { 258 std::error_code EC; 259 auto Out = std::make_unique<ToolOutputFile>(Path, EC, Flags); 260 if (EC) { 261 WithColor::error() << EC.message() << '\n'; 262 return nullptr; 263 } 264 265 return Out; 266 } 267 268 static std::string DwarfDebugFlags; 269 static void setDwarfDebugFlags(int argc, char **argv) { 270 if (!getenv("RC_DEBUG_OPTIONS")) 271 return; 272 for (int i = 0; i < argc; i++) { 273 DwarfDebugFlags += argv[i]; 274 if (i + 1 < argc) 275 DwarfDebugFlags += " "; 276 } 277 } 278 279 static std::string DwarfDebugProducer; 280 static void setDwarfDebugProducer() { 281 if(!getenv("DEBUG_PRODUCER")) 282 return; 283 DwarfDebugProducer += getenv("DEBUG_PRODUCER"); 284 } 285 286 static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI, 287 raw_ostream &OS) { 288 289 AsmLexer Lexer(MAI); 290 Lexer.setBuffer(SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID())->getBuffer()); 291 292 bool Error = false; 293 while (Lexer.Lex().isNot(AsmToken::Eof)) { 294 Lexer.getTok().dump(OS); 295 OS << "\n"; 296 if (Lexer.getTok().getKind() == AsmToken::Error) 297 Error = true; 298 } 299 300 return Error; 301 } 302 303 static int fillCommandLineSymbols(MCAsmParser &Parser) { 304 for (auto &I: DefineSymbol) { 305 auto Pair = StringRef(I).split('='); 306 auto Sym = Pair.first; 307 auto Val = Pair.second; 308 309 if (Sym.empty() || Val.empty()) { 310 WithColor::error() << "defsym must be of the form: sym=value: " << I 311 << "\n"; 312 return 1; 313 } 314 int64_t Value; 315 if (Val.getAsInteger(0, Value)) { 316 WithColor::error() << "value is not an integer: " << Val << "\n"; 317 return 1; 318 } 319 Parser.getContext().setSymbolValue(Parser.getStreamer(), Sym, Value); 320 } 321 return 0; 322 } 323 324 static int AssembleInput(const char *ProgName, const Target *TheTarget, 325 SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str, 326 MCAsmInfo &MAI, MCSubtargetInfo &STI, 327 MCInstrInfo &MCII, MCTargetOptions const &MCOptions) { 328 std::unique_ptr<MCAsmParser> Parser( 329 createMCAsmParser(SrcMgr, Ctx, Str, MAI)); 330 std::unique_ptr<MCTargetAsmParser> TAP( 331 TheTarget->createMCAsmParser(STI, *Parser, MCII, MCOptions)); 332 333 if (!TAP) { 334 WithColor::error(errs(), ProgName) 335 << "this target does not support assembly parsing.\n"; 336 return 1; 337 } 338 339 int SymbolResult = fillCommandLineSymbols(*Parser); 340 if(SymbolResult) 341 return SymbolResult; 342 Parser->setShowParsedOperands(ShowInstOperands); 343 Parser->setTargetParser(*TAP); 344 Parser->getLexer().setLexMasmIntegers(LexMasmIntegers); 345 Parser->getLexer().setLexMasmHexFloats(LexMasmHexFloats); 346 Parser->getLexer().setLexMotorolaIntegers(LexMotorolaIntegers); 347 348 int Res = Parser->Run(NoInitialTextSection); 349 350 return Res; 351 } 352 353 int main(int argc, char **argv) { 354 InitLLVM X(argc, argv); 355 356 // Initialize targets and assembly printers/parsers. 357 llvm::InitializeAllTargetInfos(); 358 llvm::InitializeAllTargetMCs(); 359 llvm::InitializeAllAsmParsers(); 360 llvm::InitializeAllDisassemblers(); 361 362 // Register the target printer for --version. 363 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); 364 365 cl::HideUnrelatedOptions({&MCCategory, &getColorCategory()}); 366 cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n"); 367 MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags(); 368 MCOptions.CompressDebugSections = CompressDebugSections.getValue(); 369 MCOptions.ShowMCInst = ShowInst; 370 MCOptions.AsmVerbose = true; 371 MCOptions.MCUseDwarfDirectory = MCTargetOptions::EnableDwarfDirectory; 372 373 setDwarfDebugFlags(argc, argv); 374 setDwarfDebugProducer(); 375 376 const char *ProgName = argv[0]; 377 const Target *TheTarget = GetTarget(ProgName); 378 if (!TheTarget) 379 return 1; 380 // Now that GetTarget() has (potentially) replaced TripleName, it's safe to 381 // construct the Triple object. 382 Triple TheTriple(TripleName); 383 384 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr = 385 MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true); 386 if (std::error_code EC = BufferPtr.getError()) { 387 WithColor::error(errs(), ProgName) 388 << InputFilename << ": " << EC.message() << '\n'; 389 return 1; 390 } 391 MemoryBuffer *Buffer = BufferPtr->get(); 392 393 SourceMgr SrcMgr; 394 395 // Tell SrcMgr about this buffer, which is what the parser will pick up. 396 SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc()); 397 398 // Record the location of the include directories so that the lexer can find 399 // it later. 400 SrcMgr.setIncludeDirs(IncludeDirs); 401 402 std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName)); 403 assert(MRI && "Unable to create target register info!"); 404 405 std::unique_ptr<MCAsmInfo> MAI( 406 TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions)); 407 assert(MAI && "Unable to create target asm info!"); 408 409 if (CompressDebugSections != DebugCompressionType::None) { 410 if (const char *Reason = compression::getReasonIfUnsupported( 411 compression::formatFor(CompressDebugSections))) { 412 WithColor::error(errs(), ProgName) 413 << "--compress-debug-sections: " << Reason; 414 return 1; 415 } 416 } 417 MAI->setPreserveAsmComments(PreserveComments); 418 MAI->setCommentColumn(CommentColumn); 419 420 // Package up features to be passed to target/subtarget 421 std::string FeaturesStr; 422 if (MAttrs.size()) { 423 SubtargetFeatures Features; 424 for (unsigned i = 0; i != MAttrs.size(); ++i) 425 Features.AddFeature(MAttrs[i]); 426 FeaturesStr = Features.getString(); 427 } 428 429 std::unique_ptr<MCSubtargetInfo> STI( 430 TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr)); 431 assert(STI && "Unable to create subtarget info!"); 432 433 // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and 434 // MCObjectFileInfo needs a MCContext reference in order to initialize itself. 435 MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr, 436 &MCOptions); 437 std::unique_ptr<MCObjectFileInfo> MOFI( 438 TheTarget->createMCObjectFileInfo(Ctx, PIC, LargeCodeModel)); 439 Ctx.setObjectFileInfo(MOFI.get()); 440 441 Ctx.setGenDwarfForAssembly(GenDwarfForAssembly); 442 // Default to 4 for dwarf version. 443 unsigned DwarfVersion = MCOptions.DwarfVersion ? MCOptions.DwarfVersion : 4; 444 if (DwarfVersion < 2 || DwarfVersion > 5) { 445 errs() << ProgName << ": Dwarf version " << DwarfVersion 446 << " is not supported." << '\n'; 447 return 1; 448 } 449 Ctx.setDwarfVersion(DwarfVersion); 450 if (MCOptions.Dwarf64) { 451 // The 64-bit DWARF format was introduced in DWARFv3. 452 if (DwarfVersion < 3) { 453 errs() << ProgName 454 << ": the 64-bit DWARF format is not supported for DWARF versions " 455 "prior to 3\n"; 456 return 1; 457 } 458 // 32-bit targets don't support DWARF64, which requires 64-bit relocations. 459 if (MAI->getCodePointerSize() < 8) { 460 errs() << ProgName 461 << ": the 64-bit DWARF format is only supported for 64-bit " 462 "targets\n"; 463 return 1; 464 } 465 // If needsDwarfSectionOffsetDirective is true, we would eventually call 466 // MCStreamer::emitSymbolValue() with IsSectionRelative = true, but that 467 // is supported only for 4-byte long references. 468 if (MAI->needsDwarfSectionOffsetDirective()) { 469 errs() << ProgName << ": the 64-bit DWARF format is not supported for " 470 << TheTriple.normalize() << "\n"; 471 return 1; 472 } 473 Ctx.setDwarfFormat(dwarf::DWARF64); 474 } 475 if (!DwarfDebugFlags.empty()) 476 Ctx.setDwarfDebugFlags(StringRef(DwarfDebugFlags)); 477 if (!DwarfDebugProducer.empty()) 478 Ctx.setDwarfDebugProducer(StringRef(DwarfDebugProducer)); 479 if (!DebugCompilationDir.empty()) 480 Ctx.setCompilationDir(DebugCompilationDir); 481 else { 482 // If no compilation dir is set, try to use the current directory. 483 SmallString<128> CWD; 484 if (!sys::fs::current_path(CWD)) 485 Ctx.setCompilationDir(CWD); 486 } 487 for (const auto &Arg : DebugPrefixMap) { 488 const auto &KV = StringRef(Arg).split('='); 489 Ctx.addDebugPrefixMapEntry(std::string(KV.first), std::string(KV.second)); 490 } 491 if (!MainFileName.empty()) 492 Ctx.setMainFileName(MainFileName); 493 if (GenDwarfForAssembly) 494 Ctx.setGenDwarfRootFile(InputFilename, Buffer->getBuffer()); 495 496 sys::fs::OpenFlags Flags = (FileType == OFT_AssemblyFile) 497 ? sys::fs::OF_TextWithCRLF 498 : sys::fs::OF_None; 499 std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename, Flags); 500 if (!Out) 501 return 1; 502 503 std::unique_ptr<ToolOutputFile> DwoOut; 504 if (!SplitDwarfFile.empty()) { 505 if (FileType != OFT_ObjectFile) { 506 WithColor::error() << "dwo output only supported with object files\n"; 507 return 1; 508 } 509 DwoOut = GetOutputStream(SplitDwarfFile, sys::fs::OF_None); 510 if (!DwoOut) 511 return 1; 512 } 513 514 std::unique_ptr<buffer_ostream> BOS; 515 raw_pwrite_stream *OS = &Out->os(); 516 std::unique_ptr<MCStreamer> Str; 517 518 std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo()); 519 assert(MCII && "Unable to create instruction info!"); 520 521 MCInstPrinter *IP = nullptr; 522 if (FileType == OFT_AssemblyFile) { 523 IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant, 524 *MAI, *MCII, *MRI); 525 526 if (!IP) { 527 WithColor::error() 528 << "unable to create instruction printer for target triple '" 529 << TheTriple.normalize() << "' with assembly variant " 530 << OutputAsmVariant << ".\n"; 531 return 1; 532 } 533 534 for (StringRef Opt : DisassemblerOptions) 535 if (!IP->applyTargetSpecificCLOption(Opt)) { 536 WithColor::error() << "invalid disassembler option '" << Opt << "'\n"; 537 return 1; 538 } 539 540 // Set the display preference for hex vs. decimal immediates. 541 IP->setPrintImmHex(PrintImmHex); 542 543 // Set up the AsmStreamer. 544 std::unique_ptr<MCCodeEmitter> CE; 545 if (ShowEncoding) 546 CE.reset(TheTarget->createMCCodeEmitter(*MCII, Ctx)); 547 548 std::unique_ptr<MCAsmBackend> MAB( 549 TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); 550 auto FOut = std::make_unique<formatted_raw_ostream>(*OS); 551 Str.reset(TheTarget->createAsmStreamer(Ctx, std::move(FOut), IP, 552 std::move(CE), std::move(MAB))); 553 554 } else if (FileType == OFT_Null) { 555 Str.reset(TheTarget->createNullStreamer(Ctx)); 556 } else { 557 assert(FileType == OFT_ObjectFile && "Invalid file type!"); 558 559 if (!Out->os().supportsSeeking()) { 560 BOS = std::make_unique<buffer_ostream>(Out->os()); 561 OS = BOS.get(); 562 } 563 564 MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, Ctx); 565 MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions); 566 Str.reset(TheTarget->createMCObjectStreamer( 567 TheTriple, Ctx, std::unique_ptr<MCAsmBackend>(MAB), 568 DwoOut ? MAB->createDwoObjectWriter(*OS, DwoOut->os()) 569 : MAB->createObjectWriter(*OS), 570 std::unique_ptr<MCCodeEmitter>(CE), *STI)); 571 if (NoExecStack) 572 Str->switchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx)); 573 Str->emitVersionForTarget(TheTriple, VersionTuple(), nullptr, 574 VersionTuple()); 575 } 576 577 int Res = 1; 578 bool disassemble = false; 579 switch (Action) { 580 case AC_AsLex: 581 Res = AsLexInput(SrcMgr, *MAI, Out->os()); 582 break; 583 case AC_Assemble: 584 Res = AssembleInput(ProgName, TheTarget, SrcMgr, Ctx, *Str, *MAI, *STI, 585 *MCII, MCOptions); 586 break; 587 case AC_MDisassemble: 588 IP->setUseMarkup(true); 589 disassemble = true; 590 break; 591 case AC_CDisassemble: 592 IP->setUseColor(true); 593 disassemble = true; 594 break; 595 case AC_Disassemble: 596 disassemble = true; 597 break; 598 } 599 if (disassemble) 600 Res = Disassembler::disassemble(*TheTarget, TripleName, *STI, *Str, *Buffer, 601 SrcMgr, Ctx, MCOptions, HexBytes); 602 603 // Keep output if no errors. 604 if (Res == 0) { 605 Out->keep(); 606 if (DwoOut) 607 DwoOut->keep(); 608 } 609 return Res; 610 } 611