2015-11-05 06:32:32 +08:00
|
|
|
//===-- llvm-mc.cpp - Machine Code Hacking Driver ---------------*- C++ -*-===//
|
2009-06-19 07:04:45 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-06-19 07:04:45 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-06-19 07:05:21 +08:00
|
|
|
// This utility is a simple driver that allows command line hacking on machine
|
|
|
|
// code.
|
2009-06-19 07:04:45 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-04 18:44:52 +08:00
|
|
|
#include "Disassembler.h"
|
2011-07-26 07:24:55 +08:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
2012-04-16 06:00:22 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2017-10-12 07:34:47 +08:00
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
2012-12-04 18:44:52 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2009-09-14 11:02:37 +08:00
|
|
|
#include "llvm/MC/MCInstPrinter.h"
|
2011-07-11 11:57:24 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2011-07-20 13:58:47 +08:00
|
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
2018-05-19 02:26:45 +08:00
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
2012-12-04 18:44:52 +08:00
|
|
|
#include "llvm/MC/MCParser/AsmLexer.h"
|
2016-01-27 18:01:28 +08:00
|
|
|
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
|
2011-07-20 13:58:47 +08:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2009-06-24 08:52:40 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2011-07-09 13:47:46 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2018-04-12 02:49:37 +08:00
|
|
|
#include "llvm/MC/MCTargetOptionsCommandFlags.inc"
|
2009-06-19 07:04:45 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2014-03-29 05:00:25 +08:00
|
|
|
#include "llvm/Support/Compression.h"
|
2010-08-20 09:07:01 +08:00
|
|
|
#include "llvm/Support/FileUtilities.h"
|
2009-08-14 11:48:55 +08:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2012-12-04 18:44:52 +08:00
|
|
|
#include "llvm/Support/Host.h"
|
2018-04-14 02:26:06 +08:00
|
|
|
#include "llvm/Support/InitLLVM.h"
|
2009-06-19 07:04:45 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2012-12-04 18:44:52 +08:00
|
|
|
#include "llvm/Support/SourceMgr.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
#include "llvm/Support/TargetSelect.h"
|
2012-12-04 18:44:52 +08:00
|
|
|
#include "llvm/Support/ToolOutputFile.h"
|
2018-04-22 16:01:35 +08:00
|
|
|
#include "llvm/Support/WithColor.h"
|
2015-11-05 06:32:32 +08:00
|
|
|
|
2009-06-19 07:04:45 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
static cl::opt<std::string>
|
|
|
|
InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
|
|
|
|
|
2018-05-22 03:44:54 +08:00
|
|
|
static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),
|
|
|
|
cl::value_desc("filename"),
|
|
|
|
cl::init("-"));
|
|
|
|
|
|
|
|
static cl::opt<std::string> SplitDwarfFile("split-dwarf-file",
|
|
|
|
cl::desc("DWO output filename"),
|
|
|
|
cl::value_desc("filename"));
|
2009-06-19 07:04:45 +08:00
|
|
|
|
2009-08-27 15:56:39 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
ShowEncoding("show-encoding", cl::desc("Show instruction encodings"));
|
|
|
|
|
2016-06-18 01:04:56 +08:00
|
|
|
static cl::opt<bool> RelaxELFRel(
|
|
|
|
"relax-relocations", cl::init(true),
|
|
|
|
cl::desc("Emit R_X86_64_GOTPCRELX instead of R_X86_64_GOTPCREL"));
|
2016-05-29 09:11:00 +08:00
|
|
|
|
2017-06-09 08:40:19 +08:00
|
|
|
static cl::opt<DebugCompressionType> CompressDebugSections(
|
|
|
|
"compress-debug-sections", cl::ValueOptional,
|
|
|
|
cl::init(DebugCompressionType::None),
|
|
|
|
cl::desc("Choose DWARF debug sections compression:"),
|
|
|
|
cl::values(clEnumValN(DebugCompressionType::None, "none", "No compression"),
|
|
|
|
clEnumValN(DebugCompressionType::Z, "zlib",
|
|
|
|
"Use zlib compression"),
|
|
|
|
clEnumValN(DebugCompressionType::GNU, "zlib-gnu",
|
|
|
|
"Use zlib-gnu compression (deprecated)")));
|
2014-03-28 04:45:58 +08:00
|
|
|
|
2010-02-04 02:18:30 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
ShowInst("show-inst", cl::desc("Show internal instruction representation"));
|
|
|
|
|
2010-08-11 14:37:09 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
ShowInstOperands("show-inst-operands",
|
|
|
|
cl::desc("Show instructions operands as parsed"));
|
|
|
|
|
2009-09-20 15:17:49 +08:00
|
|
|
static cl::opt<unsigned>
|
|
|
|
OutputAsmVariant("output-asm-variant",
|
|
|
|
cl::desc("Syntax variant to use for output printing"));
|
|
|
|
|
2014-06-12 04:26:40 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
PrintImmHex("print-imm-hex", cl::init(false),
|
|
|
|
cl::desc("Prefer hex format for immediate values"));
|
|
|
|
|
2015-06-07 09:46:24 +08:00
|
|
|
static cl::list<std::string>
|
|
|
|
DefineSymbol("defsym", cl::desc("Defines a symbol to be an integer constant"));
|
|
|
|
|
2016-07-11 20:42:14 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
PreserveComments("preserve-comments",
|
|
|
|
cl::desc("Preserve Comments in outputted assembly"));
|
|
|
|
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 17:11:24 +08:00
|
|
|
enum OutputFileType {
|
2010-03-24 07:47:12 +08:00
|
|
|
OFT_Null,
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 17:11:24 +08:00
|
|
|
OFT_AssemblyFile,
|
|
|
|
OFT_ObjectFile
|
|
|
|
};
|
|
|
|
static cl::opt<OutputFileType>
|
|
|
|
FileType("filetype", cl::init(OFT_AssemblyFile),
|
|
|
|
cl::desc("Choose an output file type:"),
|
|
|
|
cl::values(
|
|
|
|
clEnumValN(OFT_AssemblyFile, "asm",
|
|
|
|
"Emit an assembly ('.s') file"),
|
2010-03-24 07:47:12 +08:00
|
|
|
clEnumValN(OFT_Null, "null",
|
|
|
|
"Don't emit anything (for timing purposes)"),
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 17:11:24 +08:00
|
|
|
clEnumValN(OFT_ObjectFile, "obj",
|
2016-10-09 03:41:06 +08:00
|
|
|
"Emit a native object ('.o') file")));
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 17:11:24 +08:00
|
|
|
|
2009-06-21 13:22:37 +08:00
|
|
|
static cl::list<std::string>
|
|
|
|
IncludeDirs("I", cl::desc("Directory of include files"),
|
|
|
|
cl::value_desc("directory"), cl::Prefix);
|
2009-06-19 07:04:45 +08:00
|
|
|
|
2010-03-13 10:20:38 +08:00
|
|
|
static cl::opt<std::string>
|
|
|
|
ArchName("arch", cl::desc("Target arch to assemble for, "
|
2011-06-18 04:35:21 +08:00
|
|
|
"see -version for available targets"));
|
2010-03-13 10:20:38 +08:00
|
|
|
|
2009-07-18 06:38:58 +08:00
|
|
|
static cl::opt<std::string>
|
2009-11-02 06:07:54 +08:00
|
|
|
TripleName("triple", cl::desc("Target triple to assemble for, "
|
2010-03-13 10:20:38 +08:00
|
|
|
"see -version for available targets"));
|
2009-07-18 06:38:58 +08:00
|
|
|
|
2010-10-30 23:57:50 +08:00
|
|
|
static cl::opt<std::string>
|
|
|
|
MCPU("mcpu",
|
|
|
|
cl::desc("Target a specific cpu type (-mcpu=help for details)"),
|
|
|
|
cl::value_desc("cpu-name"),
|
|
|
|
cl::init(""));
|
|
|
|
|
2011-09-08 01:24:38 +08:00
|
|
|
static cl::list<std::string>
|
|
|
|
MAttrs("mattr",
|
|
|
|
cl::CommaSeparated,
|
|
|
|
cl::desc("Target specific attributes (-mattr=help for details)"),
|
|
|
|
cl::value_desc("a1,+a2,-a3,..."));
|
|
|
|
|
2016-05-18 19:58:50 +08:00
|
|
|
static cl::opt<bool> PIC("position-independent",
|
|
|
|
cl::desc("Position independent"), cl::init(false));
|
2011-07-19 14:37:02 +08:00
|
|
|
|
2017-08-03 04:32:26 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
LargeCodeModel("large-code-model",
|
|
|
|
cl::desc("Create cfi directives that assume the code might "
|
|
|
|
"be more than 2gb away"));
|
2011-07-20 15:51:56 +08:00
|
|
|
|
2010-03-13 10:20:57 +08:00
|
|
|
static cl::opt<bool>
|
2011-06-18 04:35:21 +08:00
|
|
|
NoInitialTextSection("n", cl::desc("Don't assume assembly file starts "
|
|
|
|
"in the text section"));
|
2010-03-13 10:20:57 +08:00
|
|
|
|
2011-11-02 06:27:22 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
GenDwarfForAssembly("g", cl::desc("Generate dwarf debugging info for assembly "
|
|
|
|
"source files"));
|
|
|
|
|
2012-12-18 05:32:42 +08:00
|
|
|
static cl::opt<std::string>
|
|
|
|
DebugCompilationDir("fdebug-compilation-dir",
|
|
|
|
cl::desc("Specifies the debug info's compilation dir"));
|
|
|
|
|
2018-07-10 22:41:54 +08:00
|
|
|
static cl::list<std::string>
|
|
|
|
DebugPrefixMap("fdebug-prefix-map",
|
|
|
|
cl::desc("Map file source paths in debug info"),
|
|
|
|
cl::value_desc("= separated key-value pairs"));
|
|
|
|
|
2012-12-18 08:31:01 +08:00
|
|
|
static cl::opt<std::string>
|
|
|
|
MainFileName("main-file-name",
|
|
|
|
cl::desc("Specifies the name we should consider the input file"));
|
|
|
|
|
2014-05-21 08:20:01 +08:00
|
|
|
static cl::opt<bool> SaveTempLabels("save-temp-labels",
|
|
|
|
cl::desc("Don't discard temporary labels"));
|
|
|
|
|
[MC] Separate masm integer literal lexer support from inline asm
Summary:
This renames the IsParsingMSInlineAsm member variable of AsmLexer to
LexMasmIntegers and moves it up to MCAsmLexer. This is the only behavior
controlled by that variable. I added a public setter, so that it can be
set from outside or from the llvm-mc command line. We may need to
arrange things so that users can get this behavior from clang, but
that's future work.
I also put additional hex literal lexing functionality under this flag
to fix PR32973. It appears that this hex literal parsing wasn't intended
to be enabled in non-masm-style blocks.
Now, masm integers (0b1101 and 0ABCh) work in __asm blocks from clang,
but 0b label references work when using .intel_syntax in standalone .s
files.
However, 0b label references will *not* work from __asm blocks in clang.
They will work from GCC inline asm blocks, which it sounds like is
important for Crypto++ as mentioned in PR36144.
Essentially, we only lex masm literals for inline asm blobs that use
intel syntax. If the .intel_syntax directive is used inside a gnu-style
inline asm statement, masm literals will not be lexed, which is
compatible with gas and llvm-mc standalone .s assembly.
This fixes PR36144 and PR32973.
Reviewers: Gerolf, avt77
Subscribers: eraman, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D53535
llvm-svn: 345189
2018-10-25 04:23:57 +08:00
|
|
|
static cl::opt<bool> LexMasmIntegers(
|
|
|
|
"masm-integers",
|
|
|
|
cl::desc("Enable binary and hex masm integers (0b110 and 0ABCh)"));
|
|
|
|
|
2014-05-22 05:05:09 +08:00
|
|
|
static cl::opt<bool> NoExecStack("no-exec-stack",
|
|
|
|
cl::desc("File doesn't need an exec stack"));
|
|
|
|
|
2009-06-21 13:22:37 +08:00
|
|
|
enum ActionType {
|
2009-06-22 04:16:42 +08:00
|
|
|
AC_AsLex,
|
2009-12-17 09:49:59 +08:00
|
|
|
AC_Assemble,
|
2010-04-13 03:43:00 +08:00
|
|
|
AC_Disassemble,
|
2012-12-06 02:13:19 +08:00
|
|
|
AC_MDisassemble,
|
2009-06-21 13:22:37 +08:00
|
|
|
};
|
2009-06-19 07:04:45 +08:00
|
|
|
|
2009-06-21 13:22:37 +08:00
|
|
|
static cl::opt<ActionType>
|
|
|
|
Action(cl::desc("Action to perform:"),
|
2009-06-22 04:16:42 +08:00
|
|
|
cl::init(AC_Assemble),
|
|
|
|
cl::values(clEnumValN(AC_AsLex, "as-lex",
|
|
|
|
"Lex tokens from a .s file"),
|
|
|
|
clEnumValN(AC_Assemble, "assemble",
|
2009-06-21 13:22:37 +08:00
|
|
|
"Assemble a .s file (default)"),
|
2009-12-17 09:49:59 +08:00
|
|
|
clEnumValN(AC_Disassemble, "disassemble",
|
|
|
|
"Disassemble strings of hex bytes"),
|
2012-10-23 06:31:46 +08:00
|
|
|
clEnumValN(AC_MDisassemble, "mdis",
|
2016-10-09 03:41:06 +08:00
|
|
|
"Marked up disassembly of strings of hex bytes")));
|
2009-06-19 07:04:45 +08:00
|
|
|
|
2009-09-05 05:45:34 +08:00
|
|
|
static const Target *GetTarget(const char *ProgName) {
|
2010-03-13 10:20:38 +08:00
|
|
|
// Figure out the target triple.
|
|
|
|
if (TripleName.empty())
|
2011-11-02 05:32:20 +08:00
|
|
|
TripleName = sys::getDefaultTargetTriple();
|
2011-07-27 03:02:16 +08:00
|
|
|
Triple TheTriple(Triple::normalize(TripleName));
|
|
|
|
|
2012-05-09 07:38:45 +08:00
|
|
|
// Get the target specific parser.
|
|
|
|
std::string Error;
|
|
|
|
const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple,
|
|
|
|
Error);
|
|
|
|
if (!TheTarget) {
|
2018-04-22 16:01:35 +08:00
|
|
|
WithColor::error(errs(), ProgName) << Error;
|
2014-04-25 12:24:47 +08:00
|
|
|
return nullptr;
|
2010-03-13 10:20:38 +08:00
|
|
|
}
|
|
|
|
|
2012-05-09 07:38:45 +08:00
|
|
|
// Update the triple name and return the found target.
|
2011-07-27 03:02:16 +08:00
|
|
|
TripleName = TheTriple.getTriple();
|
|
|
|
return TheTarget;
|
2009-09-05 05:45:34 +08:00
|
|
|
}
|
|
|
|
|
2019-10-08 16:21:20 +08:00
|
|
|
static std::unique_ptr<ToolOutputFile> GetOutputStream(StringRef Path,
|
|
|
|
sys::fs::OpenFlags Flags) {
|
2014-08-26 02:16:47 +08:00
|
|
|
std::error_code EC;
|
2019-10-08 16:21:20 +08:00
|
|
|
auto Out = std::make_unique<ToolOutputFile>(Path, EC, Flags);
|
2014-08-26 02:16:47 +08:00
|
|
|
if (EC) {
|
2018-04-22 16:01:35 +08:00
|
|
|
WithColor::error() << EC.message() << '\n';
|
2014-04-25 12:24:47 +08:00
|
|
|
return nullptr;
|
2010-08-20 09:07:01 +08:00
|
|
|
}
|
2010-09-01 22:20:41 +08:00
|
|
|
|
|
|
|
return Out;
|
2010-08-20 09:07:01 +08:00
|
|
|
}
|
|
|
|
|
2011-12-10 02:09:40 +08:00
|
|
|
static std::string DwarfDebugFlags;
|
|
|
|
static void setDwarfDebugFlags(int argc, char **argv) {
|
|
|
|
if (!getenv("RC_DEBUG_OPTIONS"))
|
|
|
|
return;
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
DwarfDebugFlags += argv[i];
|
|
|
|
if (i + 1 < argc)
|
|
|
|
DwarfDebugFlags += " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-17 01:46:23 +08:00
|
|
|
static std::string DwarfDebugProducer;
|
2015-11-05 06:32:32 +08:00
|
|
|
static void setDwarfDebugProducer() {
|
2013-01-17 01:46:23 +08:00
|
|
|
if(!getenv("DEBUG_PRODUCER"))
|
|
|
|
return;
|
|
|
|
DwarfDebugProducer += getenv("DEBUG_PRODUCER");
|
|
|
|
}
|
|
|
|
|
2014-06-19 14:22:01 +08:00
|
|
|
static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI,
|
2014-12-12 15:52:19 +08:00
|
|
|
raw_ostream &OS) {
|
2009-09-05 05:45:34 +08:00
|
|
|
|
2012-04-16 19:32:10 +08:00
|
|
|
AsmLexer Lexer(MAI);
|
2014-07-06 22:17:29 +08:00
|
|
|
Lexer.setBuffer(SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID())->getBuffer());
|
2010-07-19 02:31:28 +08:00
|
|
|
|
2009-06-22 04:16:42 +08:00
|
|
|
bool Error = false;
|
2009-07-29 00:56:42 +08:00
|
|
|
while (Lexer.Lex().isNot(AsmToken::Eof)) {
|
2018-03-06 22:02:14 +08:00
|
|
|
Lexer.getTok().dump(OS);
|
|
|
|
OS << "\n";
|
|
|
|
if (Lexer.getTok().getKind() == AsmToken::Error)
|
2009-06-22 04:16:42 +08:00
|
|
|
Error = true;
|
2009-06-21 15:19:10 +08:00
|
|
|
}
|
2009-08-11 12:34:48 +08:00
|
|
|
|
2010-08-20 09:07:01 +08:00
|
|
|
return Error;
|
2009-08-11 12:34:48 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 02:42:04 +08:00
|
|
|
static int fillCommandLineSymbols(MCAsmParser &Parser) {
|
2016-12-06 10:49:17 +08:00
|
|
|
for (auto &I: DefineSymbol) {
|
|
|
|
auto Pair = StringRef(I).split('=');
|
|
|
|
auto Sym = Pair.first;
|
|
|
|
auto Val = Pair.second;
|
|
|
|
|
|
|
|
if (Sym.empty() || Val.empty()) {
|
2018-04-22 16:01:35 +08:00
|
|
|
WithColor::error() << "defsym must be of the form: sym=value: " << I
|
|
|
|
<< "\n";
|
2016-12-06 10:49:17 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
int64_t Value;
|
|
|
|
if (Val.getAsInteger(0, Value)) {
|
2018-04-22 16:01:35 +08:00
|
|
|
WithColor::error() << "value is not an integer: " << Val << "\n";
|
2015-06-07 09:46:24 +08:00
|
|
|
return 1;
|
2016-12-06 10:49:17 +08:00
|
|
|
}
|
|
|
|
Parser.getContext().setSymbolValue(Parser.getStreamer(), Sym, Value);
|
|
|
|
}
|
2015-06-07 09:46:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-22 11:12:43 +08:00
|
|
|
static int AssembleInput(const char *ProgName, const Target *TheTarget,
|
2012-04-16 19:32:10 +08:00
|
|
|
SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str,
|
2014-06-19 14:22:01 +08:00
|
|
|
MCAsmInfo &MAI, MCSubtargetInfo &STI,
|
2019-08-09 03:13:23 +08:00
|
|
|
MCInstrInfo &MCII, MCTargetOptions const &MCOptions) {
|
2014-04-23 19:16:03 +08:00
|
|
|
std::unique_ptr<MCAsmParser> Parser(
|
|
|
|
createMCAsmParser(SrcMgr, Ctx, Str, MAI));
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<MCTargetAsmParser> TAP(
|
2014-06-19 14:22:08 +08:00
|
|
|
TheTarget->createMCAsmParser(STI, *Parser, MCII, MCOptions));
|
|
|
|
|
2012-04-16 19:32:10 +08:00
|
|
|
if (!TAP) {
|
2018-04-22 16:01:35 +08:00
|
|
|
WithColor::error(errs(), ProgName)
|
|
|
|
<< "this target does not support assembly parsing.\n";
|
2012-04-16 19:32:10 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-06-07 09:46:24 +08:00
|
|
|
int SymbolResult = fillCommandLineSymbols(*Parser);
|
|
|
|
if(SymbolResult)
|
|
|
|
return SymbolResult;
|
2012-04-16 19:32:10 +08:00
|
|
|
Parser->setShowParsedOperands(ShowInstOperands);
|
2014-12-12 15:52:19 +08:00
|
|
|
Parser->setTargetParser(*TAP);
|
[MC] Separate masm integer literal lexer support from inline asm
Summary:
This renames the IsParsingMSInlineAsm member variable of AsmLexer to
LexMasmIntegers and moves it up to MCAsmLexer. This is the only behavior
controlled by that variable. I added a public setter, so that it can be
set from outside or from the llvm-mc command line. We may need to
arrange things so that users can get this behavior from clang, but
that's future work.
I also put additional hex literal lexing functionality under this flag
to fix PR32973. It appears that this hex literal parsing wasn't intended
to be enabled in non-masm-style blocks.
Now, masm integers (0b1101 and 0ABCh) work in __asm blocks from clang,
but 0b label references work when using .intel_syntax in standalone .s
files.
However, 0b label references will *not* work from __asm blocks in clang.
They will work from GCC inline asm blocks, which it sounds like is
important for Crypto++ as mentioned in PR36144.
Essentially, we only lex masm literals for inline asm blobs that use
intel syntax. If the .intel_syntax directive is used inside a gnu-style
inline asm statement, masm literals will not be lexed, which is
compatible with gas and llvm-mc standalone .s assembly.
This fixes PR36144 and PR32973.
Reviewers: Gerolf, avt77
Subscribers: eraman, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D53535
llvm-svn: 345189
2018-10-25 04:23:57 +08:00
|
|
|
Parser->getLexer().setLexMasmIntegers(LexMasmIntegers);
|
2012-04-16 19:32:10 +08:00
|
|
|
|
|
|
|
int Res = Parser->Run(NoInitialTextSection);
|
|
|
|
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2018-04-14 02:26:06 +08:00
|
|
|
InitLLVM X(argc, argv);
|
2012-04-16 19:32:10 +08:00
|
|
|
|
|
|
|
// Initialize targets and assembly printers/parsers.
|
|
|
|
llvm::InitializeAllTargetInfos();
|
|
|
|
llvm::InitializeAllTargetMCs();
|
|
|
|
llvm::InitializeAllAsmParsers();
|
|
|
|
llvm::InitializeAllDisassemblers();
|
|
|
|
|
|
|
|
// Register the target printer for --version.
|
|
|
|
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
|
|
|
|
|
|
|
|
cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n");
|
2019-08-09 03:13:23 +08:00
|
|
|
const MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags();
|
2012-04-16 19:32:10 +08:00
|
|
|
setDwarfDebugFlags(argc, argv);
|
|
|
|
|
2013-01-17 01:46:23 +08:00
|
|
|
setDwarfDebugProducer();
|
|
|
|
|
2012-04-16 19:32:10 +08:00
|
|
|
const char *ProgName = argv[0];
|
2009-08-14 11:48:55 +08:00
|
|
|
const Target *TheTarget = GetTarget(ProgName);
|
|
|
|
if (!TheTarget)
|
|
|
|
return 1;
|
2015-06-16 17:57:38 +08:00
|
|
|
// Now that GetTarget() has (potentially) replaced TripleName, it's safe to
|
|
|
|
// construct the Triple object.
|
|
|
|
Triple TheTriple(TripleName);
|
2009-08-14 11:48:55 +08:00
|
|
|
|
2014-07-07 01:43:13 +08:00
|
|
|
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
|
|
|
|
MemoryBuffer::getFileOrSTDIN(InputFilename);
|
|
|
|
if (std::error_code EC = BufferPtr.getError()) {
|
2018-04-22 16:01:35 +08:00
|
|
|
WithColor::error(errs(), ProgName)
|
|
|
|
<< InputFilename << ": " << EC.message() << '\n';
|
2009-06-22 04:16:42 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2014-08-22 04:44:56 +08:00
|
|
|
MemoryBuffer *Buffer = BufferPtr->get();
|
2011-05-10 04:05:25 +08:00
|
|
|
|
2009-06-22 04:16:42 +08:00
|
|
|
SourceMgr SrcMgr;
|
2011-05-10 04:05:25 +08:00
|
|
|
|
2009-08-20 00:25:53 +08:00
|
|
|
// Tell SrcMgr about this buffer, which is what the parser will pick up.
|
2014-08-22 04:44:56 +08:00
|
|
|
SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc());
|
2011-05-10 04:05:25 +08:00
|
|
|
|
2009-06-22 04:16:42 +08:00
|
|
|
// Record the location of the include directories so that the lexer can find
|
|
|
|
// it later.
|
|
|
|
SrcMgr.setIncludeDirs(IncludeDirs);
|
2011-05-10 04:05:25 +08:00
|
|
|
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
|
2011-07-19 04:57:22 +08:00
|
|
|
assert(MRI && "Unable to create target register info!");
|
|
|
|
|
2019-10-23 18:24:35 +08:00
|
|
|
std::unique_ptr<MCAsmInfo> MAI(
|
|
|
|
TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
|
2013-05-13 09:16:13 +08:00
|
|
|
assert(MAI && "Unable to create target asm info!");
|
|
|
|
|
2016-05-29 09:11:00 +08:00
|
|
|
MAI->setRelaxELFRelocations(RelaxELFRel);
|
|
|
|
|
2017-06-09 08:40:19 +08:00
|
|
|
if (CompressDebugSections != DebugCompressionType::None) {
|
2014-03-29 04:45:24 +08:00
|
|
|
if (!zlib::isAvailable()) {
|
2018-04-22 16:01:35 +08:00
|
|
|
WithColor::error(errs(), ProgName)
|
|
|
|
<< "build tools with zlib to enable -compress-debug-sections";
|
2014-03-29 04:45:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-27 20:27:32 +08:00
|
|
|
MAI->setCompressDebugSections(CompressDebugSections);
|
2014-03-29 04:45:24 +08:00
|
|
|
}
|
2016-07-11 20:42:14 +08:00
|
|
|
MAI->setPreserveAsmComments(PreserveComments);
|
2014-03-28 04:45:58 +08:00
|
|
|
|
2011-07-20 13:58:47 +08:00
|
|
|
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
|
|
|
|
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
|
2014-06-29 01:46:19 +08:00
|
|
|
MCObjectFileInfo MOFI;
|
2019-08-09 03:13:23 +08:00
|
|
|
MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr, &MCOptions);
|
2017-08-03 04:32:26 +08:00
|
|
|
MOFI.InitMCObjectFileInfo(TheTriple, PIC, Ctx, LargeCodeModel);
|
2011-07-20 13:58:47 +08:00
|
|
|
|
2011-03-29 06:49:15 +08:00
|
|
|
if (SaveTempLabels)
|
|
|
|
Ctx.setAllowTemporaryLabels(false);
|
2010-12-10 15:39:47 +08:00
|
|
|
|
2011-11-02 06:27:22 +08:00
|
|
|
Ctx.setGenDwarfForAssembly(GenDwarfForAssembly);
|
2014-06-19 14:22:08 +08:00
|
|
|
// Default to 4 for dwarf version.
|
|
|
|
unsigned DwarfVersion = MCOptions.DwarfVersion ? MCOptions.DwarfVersion : 4;
|
2017-03-01 07:40:46 +08:00
|
|
|
if (DwarfVersion < 2 || DwarfVersion > 5) {
|
2014-05-01 16:46:02 +08:00
|
|
|
errs() << ProgName << ": Dwarf version " << DwarfVersion
|
|
|
|
<< " is not supported." << '\n';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
Ctx.setDwarfVersion(DwarfVersion);
|
2012-12-18 05:32:42 +08:00
|
|
|
if (!DwarfDebugFlags.empty())
|
2011-12-10 02:09:40 +08:00
|
|
|
Ctx.setDwarfDebugFlags(StringRef(DwarfDebugFlags));
|
2013-01-17 01:46:23 +08:00
|
|
|
if (!DwarfDebugProducer.empty())
|
|
|
|
Ctx.setDwarfDebugProducer(StringRef(DwarfDebugProducer));
|
2012-12-18 05:32:42 +08:00
|
|
|
if (!DebugCompilationDir.empty())
|
|
|
|
Ctx.setCompilationDir(DebugCompilationDir);
|
2016-03-23 06:24:29 +08:00
|
|
|
else {
|
|
|
|
// If no compilation dir is set, try to use the current directory.
|
|
|
|
SmallString<128> CWD;
|
|
|
|
if (!sys::fs::current_path(CWD))
|
|
|
|
Ctx.setCompilationDir(CWD);
|
|
|
|
}
|
2018-07-10 22:41:54 +08:00
|
|
|
for (const auto &Arg : DebugPrefixMap) {
|
|
|
|
const auto &KV = StringRef(Arg).split('=');
|
2020-01-29 03:23:46 +08:00
|
|
|
Ctx.addDebugPrefixMapEntry(std::string(KV.first), std::string(KV.second));
|
2018-07-10 22:41:54 +08:00
|
|
|
}
|
2012-12-18 08:31:01 +08:00
|
|
|
if (!MainFileName.empty())
|
|
|
|
Ctx.setMainFileName(MainFileName);
|
2019-03-02 04:58:04 +08:00
|
|
|
if (GenDwarfForAssembly)
|
|
|
|
Ctx.setGenDwarfRootFile(InputFilename, Buffer->getBuffer());
|
2011-11-02 06:27:22 +08:00
|
|
|
|
2011-09-08 01:24:38 +08:00
|
|
|
// Package up features to be passed to target/subtarget
|
|
|
|
std::string FeaturesStr;
|
|
|
|
if (MAttrs.size()) {
|
|
|
|
SubtargetFeatures Features;
|
|
|
|
for (unsigned i = 0; i != MAttrs.size(); ++i)
|
|
|
|
Features.AddFeature(MAttrs[i]);
|
|
|
|
FeaturesStr = Features.getString();
|
|
|
|
}
|
|
|
|
|
2019-10-08 16:21:20 +08:00
|
|
|
sys::fs::OpenFlags Flags = (FileType == OFT_AssemblyFile) ? sys::fs::OF_Text
|
|
|
|
: sys::fs::OF_None;
|
|
|
|
std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename, Flags);
|
2010-08-20 09:07:01 +08:00
|
|
|
if (!Out)
|
|
|
|
return 1;
|
|
|
|
|
2018-05-22 03:44:54 +08:00
|
|
|
std::unique_ptr<ToolOutputFile> DwoOut;
|
|
|
|
if (!SplitDwarfFile.empty()) {
|
|
|
|
if (FileType != OFT_ObjectFile) {
|
|
|
|
WithColor::error() << "dwo output only supported with object files\n";
|
|
|
|
return 1;
|
|
|
|
}
|
2019-10-08 16:21:20 +08:00
|
|
|
DwoOut = GetOutputStream(SplitDwarfFile, sys::fs::OF_None);
|
2018-05-22 03:44:54 +08:00
|
|
|
if (!DwoOut)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-15 06:14:34 +08:00
|
|
|
std::unique_ptr<buffer_ostream> BOS;
|
|
|
|
raw_pwrite_stream *OS = &Out->os();
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<MCStreamer> Str;
|
2009-08-17 12:23:44 +08:00
|
|
|
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
|
|
|
|
std::unique_ptr<MCSubtargetInfo> STI(
|
|
|
|
TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
|
2011-07-09 13:47:46 +08:00
|
|
|
|
2014-04-25 12:24:47 +08:00
|
|
|
MCInstPrinter *IP = nullptr;
|
2009-09-05 05:45:34 +08:00
|
|
|
if (FileType == OFT_AssemblyFile) {
|
2015-09-16 00:17:27 +08:00
|
|
|
IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant,
|
|
|
|
*MAI, *MCII, *MRI);
|
2014-06-12 04:26:40 +08:00
|
|
|
|
2016-11-01 02:36:31 +08:00
|
|
|
if (!IP) {
|
2018-04-22 16:01:35 +08:00
|
|
|
WithColor::error()
|
|
|
|
<< "unable to create instruction printer for target triple '"
|
2016-11-01 02:36:31 +08:00
|
|
|
<< TheTriple.normalize() << "' with assembly variant "
|
|
|
|
<< OutputAsmVariant << ".\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-06-12 04:26:40 +08:00
|
|
|
// Set the display preference for hex vs. decimal immediates.
|
|
|
|
IP->setPrintImmHex(PrintImmHex);
|
|
|
|
|
|
|
|
// Set up the AsmStreamer.
|
2018-04-27 23:45:54 +08:00
|
|
|
std::unique_ptr<MCCodeEmitter> CE;
|
|
|
|
if (ShowEncoding)
|
|
|
|
CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx));
|
|
|
|
|
|
|
|
std::unique_ptr<MCAsmBackend> MAB(
|
|
|
|
TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions));
|
2019-08-15 23:54:37 +08:00
|
|
|
auto FOut = std::make_unique<formatted_raw_ostream>(*OS);
|
2018-04-27 23:45:54 +08:00
|
|
|
Str.reset(
|
|
|
|
TheTarget->createAsmStreamer(Ctx, std::move(FOut), /*asmverbose*/ true,
|
|
|
|
/*useDwarfDirectory*/ true, IP,
|
|
|
|
std::move(CE), std::move(MAB), ShowInst));
|
2011-12-06 07:20:14 +08:00
|
|
|
|
2010-03-24 07:47:12 +08:00
|
|
|
} else if (FileType == OFT_Null) {
|
2015-02-19 08:45:04 +08:00
|
|
|
Str.reset(TheTarget->createNullStreamer(Ctx));
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 17:11:24 +08:00
|
|
|
} else {
|
|
|
|
assert(FileType == OFT_ObjectFile && "Invalid file type!");
|
2015-04-15 06:14:34 +08:00
|
|
|
|
2015-06-18 00:26:47 +08:00
|
|
|
// Don't waste memory on names of temp labels.
|
|
|
|
Ctx.setUseNamesOnTempLabels(false);
|
|
|
|
|
2015-04-15 06:14:34 +08:00
|
|
|
if (!Out->os().supportsSeeking()) {
|
2019-08-15 23:54:37 +08:00
|
|
|
BOS = std::make_unique<buffer_ostream>(Out->os());
|
2015-04-15 06:14:34 +08:00
|
|
|
OS = BOS.get();
|
|
|
|
}
|
|
|
|
|
2015-03-11 06:03:14 +08:00
|
|
|
MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx);
|
2018-01-03 16:53:05 +08:00
|
|
|
MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions);
|
2015-12-22 06:09:27 +08:00
|
|
|
Str.reset(TheTarget->createMCObjectStreamer(
|
2018-05-19 02:26:45 +08:00
|
|
|
TheTriple, Ctx, std::unique_ptr<MCAsmBackend>(MAB),
|
2018-05-22 03:44:54 +08:00
|
|
|
DwoOut ? MAB->createDwoObjectWriter(*OS, DwoOut->os())
|
|
|
|
: MAB->createObjectWriter(*OS),
|
|
|
|
std::unique_ptr<MCCodeEmitter>(CE), *STI, MCOptions.MCRelaxAll,
|
|
|
|
MCOptions.MCIncrementalLinkerCompatible,
|
2015-12-22 06:09:27 +08:00
|
|
|
/*DWARFMustBeAtTheEnd*/ false));
|
2014-10-16 00:12:52 +08:00
|
|
|
if (NoExecStack)
|
|
|
|
Str->InitSections(true);
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 17:11:24 +08:00
|
|
|
}
|
2009-06-25 07:30:00 +08:00
|
|
|
|
[MC] Change AsmParser to leverage Assembler during evaluation
Teach AsmParser to check with Assembler for when evaluating constant
expressions. This improves the handing of preprocessor expressions
that must be resolved at parse time. This idiom can be found as
assembling-time assertion checks in source-level assemblers. Note that
this relies on the MCStreamer to keep sufficient tabs on Section /
Fragment information which the MCAsmStreamer does not. As a result the
textual output may fail where the equivalent object generation would
pass. This can most easily be resolved by folding the MCAsmStreamer
and MCObjectStreamer together which is planned for in a separate
patch.
Currently, this feature is only enabled for assembly input, keeping IR
compilation consistent between assembly and object generation.
Reviewers: echristo, rnk, probinson, espindola, peter.smith
Reviewed By: peter.smith
Subscribers: eraman, peter.smith, arichardson, jyknight, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D45164
llvm-svn: 331218
2018-05-01 03:22:40 +08:00
|
|
|
// Use Assembler information for parsing.
|
|
|
|
Str->setUseAssemblerInfoForParsing(true);
|
|
|
|
|
2012-04-16 19:32:10 +08:00
|
|
|
int Res = 1;
|
2012-12-06 02:13:19 +08:00
|
|
|
bool disassemble = false;
|
2009-06-21 13:22:37 +08:00
|
|
|
switch (Action) {
|
2009-06-22 04:16:42 +08:00
|
|
|
case AC_AsLex:
|
2014-12-12 15:52:19 +08:00
|
|
|
Res = AsLexInput(SrcMgr, *MAI, Out->os());
|
2012-04-16 19:32:10 +08:00
|
|
|
break;
|
2009-06-21 13:22:37 +08:00
|
|
|
case AC_Assemble:
|
2014-06-19 14:22:01 +08:00
|
|
|
Res = AssembleInput(ProgName, TheTarget, SrcMgr, Ctx, *Str, *MAI, *STI,
|
2014-06-19 14:22:08 +08:00
|
|
|
*MCII, MCOptions);
|
2012-04-16 19:32:10 +08:00
|
|
|
break;
|
2012-10-23 06:31:46 +08:00
|
|
|
case AC_MDisassemble:
|
2013-02-27 07:04:17 +08:00
|
|
|
assert(IP && "Expected assembly output");
|
2019-07-25 17:54:12 +08:00
|
|
|
IP->setUseMarkup(true);
|
2012-12-06 02:13:19 +08:00
|
|
|
disassemble = true;
|
|
|
|
break;
|
2009-12-17 09:49:59 +08:00
|
|
|
case AC_Disassemble:
|
2012-12-06 02:13:19 +08:00
|
|
|
disassemble = true;
|
2012-04-16 19:32:10 +08:00
|
|
|
break;
|
2009-06-21 13:22:37 +08:00
|
|
|
}
|
2012-12-06 02:13:19 +08:00
|
|
|
if (disassemble)
|
2019-10-16 02:28:22 +08:00
|
|
|
Res = Disassembler::disassemble(*TheTarget, TripleName, *STI, *Str, *Buffer,
|
2019-10-23 18:24:35 +08:00
|
|
|
SrcMgr, Ctx, Out->os(), MCOptions);
|
2012-04-16 19:32:10 +08:00
|
|
|
|
|
|
|
// Keep output if no errors.
|
2018-05-22 03:44:54 +08:00
|
|
|
if (Res == 0) {
|
|
|
|
Out->keep();
|
|
|
|
if (DwoOut)
|
|
|
|
DwoOut->keep();
|
|
|
|
}
|
2012-04-16 19:32:10 +08:00
|
|
|
return Res;
|
2009-06-19 07:04:45 +08:00
|
|
|
}
|