- OwningPtr<MCAsmParser> Parser(createMCAsmParser(*TheTarget, SrcMgr, Ctx,
- *Str.get(), *MAI));
- OwningPtr<TargetAsmParser> TAP(TheTarget->createAsmParser(*Parser, *TM));
- if (!TAP) {
- errs() << ProgName
- << ": error: this target does not support assembly parsing.\n";
- return 1;
- }
-
- Parser->setShowParsedOperands(ShowInstOperands);
- Parser->setTargetParser(*TAP.get());
-
- int Res = Parser->Run(NoInitialTextSection);
-
- // Keep output if no errors.
- if (Res == 0) Out->keep();
-
- return Res;
-}
-
-static int DisassembleInput(const char *ProgName, bool Enhanced) {
- const Target *TheTarget = GetTarget(ProgName);
- if (!TheTarget)
- return 0;
-
- OwningPtr<MemoryBuffer> Buffer;
- if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, Buffer)) {
- errs() << ProgName << ": " << ec.message() << '\n';
- return 1;
- }
-
- OwningPtr<tool_output_file> Out(GetOutputStream());
- if (!Out)
- return 1;
-
- int Res;
- if (Enhanced) {
- Res =
- Disassembler::disassembleEnhanced(TripleName, *Buffer.take(), Out->os());
- } else {
- // Package up features to be passed to target/subtarget
- std::string FeaturesStr;
- if (MCPU.size()) {
- SubtargetFeatures Features;
- Features.setCPU(MCPU);
- FeaturesStr = Features.getString();
- }
-
- // FIXME: We shouldn't need to do this (and link in codegen).
- // When we split this out, we should do it in a way that makes
- // it straightforward to switch subtargets on the fly (.e.g,
- // the .cpu and .code16 directives).
- OwningPtr<TargetMachine> TM(TheTarget->createTargetMachine(TripleName,
- FeaturesStr));
-
- if (!TM) {
- errs() << ProgName << ": error: could not create target for triple '"
- << TripleName << "'.\n";
- return 1;
- }
-
- Res = Disassembler::disassemble(*TheTarget, *TM, TripleName,
- *Buffer.take(), Out->os());
- }
-
- // Keep output if no errors.
- if (Res == 0) Out->keep();
-
- return Res;
-}
-
-
-int main(int argc, char **argv) {
- // Print a stack trace if we signal out.
- sys::PrintStackTraceOnErrorSignal();
- PrettyStackTraceProgram X(argc, argv);
- llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
-
- // Initialize targets and assembly printers/parsers.
- llvm::InitializeAllTargetInfos();
- // FIXME: We shouldn't need to initialize the Target(Machine)s.
- llvm::InitializeAllTargets();
- llvm::InitializeAllAsmPrinters();
- llvm::InitializeAllAsmParsers();
- llvm::InitializeAllDisassemblers();
-
- cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n");
- TripleName = Triple::normalize(TripleName);
-