2015-11-04 23:32:32 +01:00
|
|
|
//===-- llvm-mc.cpp - Machine Code Hacking Driver ---------------*- C++ -*-===//
|
2009-06-19 01:04:45 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01: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 01:04:45 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-06-19 01:05:21 +02:00
|
|
|
// This utility is a simple driver that allows command line hacking on machine
|
|
|
|
// code.
|
2009-06-19 01:04:45 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-04 11:44:52 +01:00
|
|
|
#include "Disassembler.h"
|
2011-07-26 01:24:55 +02:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
2012-04-16 00:00:22 +02:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2017-10-12 01:34:47 +02:00
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
2012-12-04 11:44:52 +01:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2009-09-14 05:02:37 +02:00
|
|
|
#include "llvm/MC/MCInstPrinter.h"
|
2011-07-11 05:57:24 +02:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2011-07-20 07:58:47 +02:00
|
|
|
#include "llvm/MC/MCObjectFileInfo.h"
|
2018-05-18 20:26:45 +02:00
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
2012-12-04 11:44:52 +01:00
|
|
|
#include "llvm/MC/MCParser/AsmLexer.h"
|
2016-01-27 11:01:28 +01:00
|
|
|
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
|
2011-07-20 07:58:47 +02:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2009-06-24 02:52:40 +02:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2011-07-09 07:47:46 +02:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2020-03-04 00:47:43 +01:00
|
|
|
#include "llvm/MC/MCTargetOptionsCommandFlags.h"
|
2009-06-19 01:04:45 +02:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2014-03-28 22:00:25 +01:00
|
|
|
#include "llvm/Support/Compression.h"
|
2010-08-20 03:07:01 +02:00
|
|
|
#include "llvm/Support/FileUtilities.h"
|
2009-08-14 05:48:55 +02:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2012-12-04 11:44:52 +01:00
|
|
|
#include "llvm/Support/Host.h"
|
2018-04-13 20:26:06 +02:00
|
|
|
#include "llvm/Support/InitLLVM.h"
|
2009-06-19 01:04:45 +02:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2012-12-04 11:44:52 +01:00
|
|
|
#include "llvm/Support/SourceMgr.h"
|
2011-08-24 20:08:43 +02:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
#include "llvm/Support/TargetSelect.h"
|
2012-12-04 11:44:52 +01:00
|
|
|
#include "llvm/Support/ToolOutputFile.h"
|
2018-04-22 10:01:35 +02:00
|
|
|
#include "llvm/Support/WithColor.h"
|
2015-11-04 23:32:32 +01:00
|
|
|
|
2009-06-19 01:04:45 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2020-03-04 00:47:43 +01:00
|
|
|
static mc::RegisterMCTargetOptionsFlags MOF;
|
|
|
|
|
2009-06-19 01:04:45 +02:00
|
|
|
static cl::opt<std::string>
|
|
|
|
InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
|
|
|
|
|
2021-05-26 19:43:32 +02:00
|
|
|
static cl::list<std::string>
|
|
|
|
DisassemblerOptions("M", cl::desc("Disassembler options"));
|
|
|
|
|
2018-05-21 21:44:54 +02: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 01:04:45 +02:00
|
|
|
|
2009-08-27 09:56:39 +02:00
|
|
|
static cl::opt<bool>
|
|
|
|
ShowEncoding("show-encoding", cl::desc("Show instruction encodings"));
|
|
|
|
|
2016-06-17 19:04:56 +02: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 03:11:00 +02:00
|
|
|
|
2017-06-09 02:40:19 +02: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-27 21:45:58 +01:00
|
|
|
|
2010-02-03 19:18:30 +01:00
|
|
|
static cl::opt<bool>
|
|
|
|
ShowInst("show-inst", cl::desc("Show internal instruction representation"));
|
|
|
|
|
2010-08-11 08:37:09 +02:00
|
|
|
static cl::opt<bool>
|
|
|
|
ShowInstOperands("show-inst-operands",
|
|
|
|
cl::desc("Show instructions operands as parsed"));
|
|
|
|
|
2009-09-20 09:17:49 +02:00
|
|
|
static cl::opt<unsigned>
|
|
|
|
OutputAsmVariant("output-asm-variant",
|
|
|
|
cl::desc("Syntax variant to use for output printing"));
|
|
|
|
|
2014-06-11 22:26:40 +02:00
|
|
|
static cl::opt<bool>
|
|
|
|
PrintImmHex("print-imm-hex", cl::init(false),
|
|
|
|
cl::desc("Prefer hex format for immediate values"));
|
|
|
|
|
2015-06-07 03:46:24 +02:00
|
|
|
static cl::list<std::string>
|
|
|
|
DefineSymbol("defsym", cl::desc("Defines a symbol to be an integer constant"));
|
|
|
|
|
2016-07-11 14:42:14 +02: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 11:11:24 +02:00
|
|
|
enum OutputFileType {
|
2010-03-24 00:47:12 +01: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 11:11:24 +02: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 00:47:12 +01: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 11:11:24 +02:00
|
|
|
clEnumValN(OFT_ObjectFile, "obj",
|
2016-10-08 21:41:06 +02: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 11:11:24 +02:00
|
|
|
|
2009-06-21 07:22:37 +02:00
|
|
|
static cl::list<std::string>
|
|
|
|
IncludeDirs("I", cl::desc("Directory of include files"),
|
|
|
|
cl::value_desc("directory"), cl::Prefix);
|
2009-06-19 01:04:45 +02:00
|
|
|
|
2010-03-13 03:20:38 +01:00
|
|
|
static cl::opt<std::string>
|
|
|
|
ArchName("arch", cl::desc("Target arch to assemble for, "
|
2011-06-17 22:35:21 +02:00
|
|
|
"see -version for available targets"));
|
2010-03-13 03:20:38 +01:00
|
|
|
|
2009-07-18 00:38:58 +02:00
|
|
|
static cl::opt<std::string>
|
2009-11-01 23:07:54 +01:00
|
|
|
TripleName("triple", cl::desc("Target triple to assemble for, "
|
2010-03-13 03:20:38 +01:00
|
|
|
"see -version for available targets"));
|
2009-07-18 00:38:58 +02:00
|
|
|
|
2010-10-30 17:57:50 +02: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-07 19:24:38 +02: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 13:58:50 +02:00
|
|
|
static cl::opt<bool> PIC("position-independent",
|
|
|
|
cl::desc("Position independent"), cl::init(false));
|
2011-07-19 08:37:02 +02:00
|
|
|
|
2017-08-02 22:32:26 +02: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 09:51:56 +02:00
|
|
|
|
2010-03-13 03:20:57 +01:00
|
|
|
static cl::opt<bool>
|
2011-06-17 22:35:21 +02:00
|
|
|
NoInitialTextSection("n", cl::desc("Don't assume assembly file starts "
|
|
|
|
"in the text section"));
|
2010-03-13 03:20:57 +01:00
|
|
|
|
2011-11-01 23:27:22 +01:00
|
|
|
static cl::opt<bool>
|
|
|
|
GenDwarfForAssembly("g", cl::desc("Generate dwarf debugging info for assembly "
|
|
|
|
"source files"));
|
|
|
|
|
2012-12-17 22:32:42 +01:00
|
|
|
static cl::opt<std::string>
|
|
|
|
DebugCompilationDir("fdebug-compilation-dir",
|
|
|
|
cl::desc("Specifies the debug info's compilation dir"));
|
|
|
|
|
2018-07-10 16:41:54 +02: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 01:31:01 +01:00
|
|
|
static cl::opt<std::string>
|
|
|
|
MainFileName("main-file-name",
|
|
|
|
cl::desc("Specifies the name we should consider the input file"));
|
|
|
|
|
2014-05-21 02:20:01 +02: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-24 22:23:57 +02:00
|
|
|
static cl::opt<bool> LexMasmIntegers(
|
|
|
|
"masm-integers",
|
|
|
|
cl::desc("Enable binary and hex masm integers (0b110 and 0ABCh)"));
|
|
|
|
|
2020-09-29 22:57:25 +02:00
|
|
|
static cl::opt<bool> LexMasmHexFloats(
|
|
|
|
"masm-hexfloats",
|
|
|
|
cl::desc("Enable MASM-style hex float initializers (3F800000r)"));
|
|
|
|
|
2021-01-26 15:51:50 +01:00
|
|
|
static cl::opt<bool> LexMotorolaIntegers(
|
|
|
|
"motorola-integers",
|
|
|
|
cl::desc("Enable binary and hex Motorola integers (%110 and $ABC)"));
|
|
|
|
|
2014-05-21 23:05:09 +02:00
|
|
|
static cl::opt<bool> NoExecStack("no-exec-stack",
|
|
|
|
cl::desc("File doesn't need an exec stack"));
|
|
|
|
|
2009-06-21 07:22:37 +02:00
|
|
|
enum ActionType {
|
2009-06-21 22:16:42 +02:00
|
|
|
AC_AsLex,
|
2009-12-17 02:49:59 +01:00
|
|
|
AC_Assemble,
|
2010-04-12 21:43:00 +02:00
|
|
|
AC_Disassemble,
|
2012-12-05 19:13:19 +01:00
|
|
|
AC_MDisassemble,
|
2009-06-21 07:22:37 +02:00
|
|
|
};
|
2009-06-19 01:04:45 +02:00
|
|
|
|
2009-06-21 07:22:37 +02:00
|
|
|
static cl::opt<ActionType>
|
|
|
|
Action(cl::desc("Action to perform:"),
|
2009-06-21 22:16:42 +02: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 07:22:37 +02:00
|
|
|
"Assemble a .s file (default)"),
|
2009-12-17 02:49:59 +01:00
|
|
|
clEnumValN(AC_Disassemble, "disassemble",
|
|
|
|
"Disassemble strings of hex bytes"),
|
2012-10-23 00:31:46 +02:00
|
|
|
clEnumValN(AC_MDisassemble, "mdis",
|
2016-10-08 21:41:06 +02:00
|
|
|
"Marked up disassembly of strings of hex bytes")));
|
2009-06-19 01:04:45 +02:00
|
|
|
|
2009-09-04 23:45:34 +02:00
|
|
|
static const Target *GetTarget(const char *ProgName) {
|
2010-03-13 03:20:38 +01:00
|
|
|
// Figure out the target triple.
|
|
|
|
if (TripleName.empty())
|
2011-11-01 22:32:20 +01:00
|
|
|
TripleName = sys::getDefaultTargetTriple();
|
2011-07-26 21:02:16 +02:00
|
|
|
Triple TheTriple(Triple::normalize(TripleName));
|
|
|
|
|
2012-05-09 01:38:45 +02:00
|
|
|
// Get the target specific parser.
|
|
|
|
std::string Error;
|
|
|
|
const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple,
|
|
|
|
Error);
|
|
|
|
if (!TheTarget) {
|
2018-04-22 10:01:35 +02:00
|
|
|
WithColor::error(errs(), ProgName) << Error;
|
2014-04-25 06:24:47 +02:00
|
|
|
return nullptr;
|
2010-03-13 03:20:38 +01:00
|
|
|
}
|
|
|
|
|
2012-05-09 01:38:45 +02:00
|
|
|
// Update the triple name and return the found target.
|
2011-07-26 21:02:16 +02:00
|
|
|
TripleName = TheTriple.getTriple();
|
|
|
|
return TheTarget;
|
2009-09-04 23:45:34 +02:00
|
|
|
}
|
|
|
|
|
2019-10-08 10:21:20 +02:00
|
|
|
static std::unique_ptr<ToolOutputFile> GetOutputStream(StringRef Path,
|
|
|
|
sys::fs::OpenFlags Flags) {
|
2014-08-25 20:16:47 +02:00
|
|
|
std::error_code EC;
|
2019-10-08 10:21:20 +02:00
|
|
|
auto Out = std::make_unique<ToolOutputFile>(Path, EC, Flags);
|
2014-08-25 20:16:47 +02:00
|
|
|
if (EC) {
|
2018-04-22 10:01:35 +02:00
|
|
|
WithColor::error() << EC.message() << '\n';
|
2014-04-25 06:24:47 +02:00
|
|
|
return nullptr;
|
2010-08-20 03:07:01 +02:00
|
|
|
}
|
2010-09-01 16:20:41 +02:00
|
|
|
|
|
|
|
return Out;
|
2010-08-20 03:07:01 +02:00
|
|
|
}
|
|
|
|
|
2011-12-09 19:09:40 +01: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-16 18:46:23 +01:00
|
|
|
static std::string DwarfDebugProducer;
|
2015-11-04 23:32:32 +01:00
|
|
|
static void setDwarfDebugProducer() {
|
2013-01-16 18:46:23 +01:00
|
|
|
if(!getenv("DEBUG_PRODUCER"))
|
|
|
|
return;
|
|
|
|
DwarfDebugProducer += getenv("DEBUG_PRODUCER");
|
|
|
|
}
|
|
|
|
|
2014-06-19 08:22:01 +02:00
|
|
|
static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI,
|
2014-12-12 08:52:19 +01:00
|
|
|
raw_ostream &OS) {
|
2009-09-04 23:45:34 +02:00
|
|
|
|
2012-04-16 13:32:10 +02:00
|
|
|
AsmLexer Lexer(MAI);
|
2014-07-06 16:17:29 +02:00
|
|
|
Lexer.setBuffer(SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID())->getBuffer());
|
2010-07-18 20:31:28 +02:00
|
|
|
|
2009-06-21 22:16:42 +02:00
|
|
|
bool Error = false;
|
2009-07-28 18:56:42 +02:00
|
|
|
while (Lexer.Lex().isNot(AsmToken::Eof)) {
|
2018-03-06 15:02:14 +01:00
|
|
|
Lexer.getTok().dump(OS);
|
|
|
|
OS << "\n";
|
|
|
|
if (Lexer.getTok().getKind() == AsmToken::Error)
|
2009-06-21 22:16:42 +02:00
|
|
|
Error = true;
|
2009-06-21 09:19:10 +02:00
|
|
|
}
|
2009-08-11 06:34:48 +02:00
|
|
|
|
2010-08-20 03:07:01 +02:00
|
|
|
return Error;
|
2009-08-11 06:34:48 +02:00
|
|
|
}
|
|
|
|
|
2016-12-01 19:42:04 +01:00
|
|
|
static int fillCommandLineSymbols(MCAsmParser &Parser) {
|
2016-12-06 03:49:17 +01: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 10:01:35 +02:00
|
|
|
WithColor::error() << "defsym must be of the form: sym=value: " << I
|
|
|
|
<< "\n";
|
2016-12-06 03:49:17 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
int64_t Value;
|
|
|
|
if (Val.getAsInteger(0, Value)) {
|
2018-04-22 10:01:35 +02:00
|
|
|
WithColor::error() << "value is not an integer: " << Val << "\n";
|
2015-06-07 03:46:24 +02:00
|
|
|
return 1;
|
2016-12-06 03:49:17 +01:00
|
|
|
}
|
|
|
|
Parser.getContext().setSymbolValue(Parser.getStreamer(), Sym, Value);
|
|
|
|
}
|
2015-06-07 03:46:24 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-22 04:12:43 +01:00
|
|
|
static int AssembleInput(const char *ProgName, const Target *TheTarget,
|
2012-04-16 13:32:10 +02:00
|
|
|
SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str,
|
2014-06-19 08:22:01 +02:00
|
|
|
MCAsmInfo &MAI, MCSubtargetInfo &STI,
|
2019-08-08 21:13:23 +02:00
|
|
|
MCInstrInfo &MCII, MCTargetOptions const &MCOptions) {
|
2014-04-23 13:16:03 +02:00
|
|
|
std::unique_ptr<MCAsmParser> Parser(
|
|
|
|
createMCAsmParser(SrcMgr, Ctx, Str, MAI));
|
2014-03-06 06:51:42 +01:00
|
|
|
std::unique_ptr<MCTargetAsmParser> TAP(
|
2014-06-19 08:22:08 +02:00
|
|
|
TheTarget->createMCAsmParser(STI, *Parser, MCII, MCOptions));
|
|
|
|
|
2012-04-16 13:32:10 +02:00
|
|
|
if (!TAP) {
|
2018-04-22 10:01:35 +02:00
|
|
|
WithColor::error(errs(), ProgName)
|
|
|
|
<< "this target does not support assembly parsing.\n";
|
2012-04-16 13:32:10 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-06-07 03:46:24 +02:00
|
|
|
int SymbolResult = fillCommandLineSymbols(*Parser);
|
|
|
|
if(SymbolResult)
|
|
|
|
return SymbolResult;
|
2012-04-16 13:32:10 +02:00
|
|
|
Parser->setShowParsedOperands(ShowInstOperands);
|
2014-12-12 08:52:19 +01: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-24 22:23:57 +02:00
|
|
|
Parser->getLexer().setLexMasmIntegers(LexMasmIntegers);
|
2020-09-29 22:57:25 +02:00
|
|
|
Parser->getLexer().setLexMasmHexFloats(LexMasmHexFloats);
|
2021-01-26 15:51:50 +01:00
|
|
|
Parser->getLexer().setLexMotorolaIntegers(LexMotorolaIntegers);
|
2012-04-16 13:32:10 +02:00
|
|
|
|
|
|
|
int Res = Parser->Run(NoInitialTextSection);
|
|
|
|
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2018-04-13 20:26:06 +02:00
|
|
|
InitLLVM X(argc, argv);
|
2012-04-16 13:32:10 +02: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");
|
2020-03-04 00:47:43 +01:00
|
|
|
const MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags();
|
2012-04-16 13:32:10 +02:00
|
|
|
setDwarfDebugFlags(argc, argv);
|
|
|
|
|
2013-01-16 18:46:23 +01:00
|
|
|
setDwarfDebugProducer();
|
|
|
|
|
2012-04-16 13:32:10 +02:00
|
|
|
const char *ProgName = argv[0];
|
2009-08-14 05:48:55 +02:00
|
|
|
const Target *TheTarget = GetTarget(ProgName);
|
|
|
|
if (!TheTarget)
|
|
|
|
return 1;
|
2015-06-16 11:57:38 +02:00
|
|
|
// Now that GetTarget() has (potentially) replaced TripleName, it's safe to
|
|
|
|
// construct the Triple object.
|
|
|
|
Triple TheTriple(TripleName);
|
2009-08-14 05:48:55 +02:00
|
|
|
|
2014-07-06 19:43:13 +02:00
|
|
|
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
|
2021-04-16 16:02:48 +02:00
|
|
|
MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true);
|
2014-07-06 19:43:13 +02:00
|
|
|
if (std::error_code EC = BufferPtr.getError()) {
|
2018-04-22 10:01:35 +02:00
|
|
|
WithColor::error(errs(), ProgName)
|
|
|
|
<< InputFilename << ": " << EC.message() << '\n';
|
2009-06-21 22:16:42 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2014-08-21 22:44:56 +02:00
|
|
|
MemoryBuffer *Buffer = BufferPtr->get();
|
2011-05-09 22:05:25 +02:00
|
|
|
|
2009-06-21 22:16:42 +02:00
|
|
|
SourceMgr SrcMgr;
|
2011-05-09 22:05:25 +02:00
|
|
|
|
2009-08-19 18:25:53 +02:00
|
|
|
// Tell SrcMgr about this buffer, which is what the parser will pick up.
|
2014-08-21 22:44:56 +02:00
|
|
|
SrcMgr.AddNewSourceBuffer(std::move(*BufferPtr), SMLoc());
|
2011-05-09 22:05:25 +02:00
|
|
|
|
2009-06-21 22:16:42 +02:00
|
|
|
// Record the location of the include directories so that the lexer can find
|
|
|
|
// it later.
|
|
|
|
SrcMgr.setIncludeDirs(IncludeDirs);
|
2011-05-09 22:05:25 +02:00
|
|
|
|
2014-03-06 06:51:42 +01:00
|
|
|
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
|
2011-07-18 22:57:22 +02:00
|
|
|
assert(MRI && "Unable to create target register info!");
|
|
|
|
|
2019-10-23 12:24:35 +02:00
|
|
|
std::unique_ptr<MCAsmInfo> MAI(
|
|
|
|
TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
|
2013-05-13 03:16:13 +02:00
|
|
|
assert(MAI && "Unable to create target asm info!");
|
|
|
|
|
2016-05-29 03:11:00 +02:00
|
|
|
MAI->setRelaxELFRelocations(RelaxELFRel);
|
|
|
|
|
2017-06-09 02:40:19 +02:00
|
|
|
if (CompressDebugSections != DebugCompressionType::None) {
|
2014-03-28 21:45:24 +01:00
|
|
|
if (!zlib::isAvailable()) {
|
2018-04-22 10:01:35 +02:00
|
|
|
WithColor::error(errs(), ProgName)
|
|
|
|
<< "build tools with zlib to enable -compress-debug-sections";
|
2014-03-28 21:45:24 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-27 14:27:32 +02:00
|
|
|
MAI->setCompressDebugSections(CompressDebugSections);
|
2014-03-28 21:45:24 +01:00
|
|
|
}
|
2016-07-11 14:42:14 +02:00
|
|
|
MAI->setPreserveAsmComments(PreserveComments);
|
2014-03-27 21:45:58 +01:00
|
|
|
|
2021-05-05 19:03:02 +02: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();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<MCSubtargetInfo> STI(
|
|
|
|
TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
|
|
|
|
assert(STI && "Unable to create subtarget info!");
|
|
|
|
|
2011-07-20 07:58:47 +02:00
|
|
|
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
|
|
|
|
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
|
2021-05-23 23:15:23 +02:00
|
|
|
MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr,
|
2021-05-05 19:03:02 +02:00
|
|
|
&MCOptions);
|
2021-05-23 23:15:23 +02:00
|
|
|
std::unique_ptr<MCObjectFileInfo> MOFI(
|
|
|
|
TheTarget->createMCObjectFileInfo(Ctx, PIC, LargeCodeModel));
|
|
|
|
Ctx.setObjectFileInfo(MOFI.get());
|
2011-07-20 07:58:47 +02:00
|
|
|
|
2011-03-29 00:49:15 +02:00
|
|
|
if (SaveTempLabels)
|
|
|
|
Ctx.setAllowTemporaryLabels(false);
|
2010-12-10 08:39:47 +01:00
|
|
|
|
2011-11-01 23:27:22 +01:00
|
|
|
Ctx.setGenDwarfForAssembly(GenDwarfForAssembly);
|
2014-06-19 08:22:08 +02:00
|
|
|
// Default to 4 for dwarf version.
|
|
|
|
unsigned DwarfVersion = MCOptions.DwarfVersion ? MCOptions.DwarfVersion : 4;
|
2017-03-01 00:40:46 +01:00
|
|
|
if (DwarfVersion < 2 || DwarfVersion > 5) {
|
2014-05-01 10:46:02 +02:00
|
|
|
errs() << ProgName << ": Dwarf version " << DwarfVersion
|
|
|
|
<< " is not supported." << '\n';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
Ctx.setDwarfVersion(DwarfVersion);
|
2020-06-03 08:15:51 +02:00
|
|
|
if (MCOptions.Dwarf64) {
|
|
|
|
// The 64-bit DWARF format was introduced in DWARFv3.
|
|
|
|
if (DwarfVersion < 3) {
|
|
|
|
errs() << ProgName
|
|
|
|
<< ": the 64-bit DWARF format is not supported for DWARF versions "
|
|
|
|
"prior to 3\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// 32-bit targets don't support DWARF64, which requires 64-bit relocations.
|
|
|
|
if (MAI->getCodePointerSize() < 8) {
|
|
|
|
errs() << ProgName
|
|
|
|
<< ": the 64-bit DWARF format is only supported for 64-bit "
|
|
|
|
"targets\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// If needsDwarfSectionOffsetDirective is true, we would eventually call
|
|
|
|
// MCStreamer::emitSymbolValue() with IsSectionRelative = true, but that
|
|
|
|
// is supported only for 4-byte long references.
|
|
|
|
if (MAI->needsDwarfSectionOffsetDirective()) {
|
|
|
|
errs() << ProgName << ": the 64-bit DWARF format is not supported for "
|
|
|
|
<< TheTriple.normalize() << "\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
Ctx.setDwarfFormat(dwarf::DWARF64);
|
|
|
|
}
|
2012-12-17 22:32:42 +01:00
|
|
|
if (!DwarfDebugFlags.empty())
|
2011-12-09 19:09:40 +01:00
|
|
|
Ctx.setDwarfDebugFlags(StringRef(DwarfDebugFlags));
|
2013-01-16 18:46:23 +01:00
|
|
|
if (!DwarfDebugProducer.empty())
|
|
|
|
Ctx.setDwarfDebugProducer(StringRef(DwarfDebugProducer));
|
2012-12-17 22:32:42 +01:00
|
|
|
if (!DebugCompilationDir.empty())
|
|
|
|
Ctx.setCompilationDir(DebugCompilationDir);
|
2016-03-22 23:24:29 +01: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 16:41:54 +02:00
|
|
|
for (const auto &Arg : DebugPrefixMap) {
|
|
|
|
const auto &KV = StringRef(Arg).split('=');
|
2020-01-28 20:23:46 +01:00
|
|
|
Ctx.addDebugPrefixMapEntry(std::string(KV.first), std::string(KV.second));
|
2018-07-10 16:41:54 +02:00
|
|
|
}
|
2012-12-18 01:31:01 +01:00
|
|
|
if (!MainFileName.empty())
|
|
|
|
Ctx.setMainFileName(MainFileName);
|
2019-03-01 21:58:04 +01:00
|
|
|
if (GenDwarfForAssembly)
|
|
|
|
Ctx.setGenDwarfRootFile(InputFilename, Buffer->getBuffer());
|
2011-11-01 23:27:22 +01:00
|
|
|
|
2021-04-06 13:22:41 +02:00
|
|
|
sys::fs::OpenFlags Flags = (FileType == OFT_AssemblyFile)
|
|
|
|
? sys::fs::OF_TextWithCRLF
|
|
|
|
: sys::fs::OF_None;
|
2019-10-08 10:21:20 +02:00
|
|
|
std::unique_ptr<ToolOutputFile> Out = GetOutputStream(OutputFilename, Flags);
|
2010-08-20 03:07:01 +02:00
|
|
|
if (!Out)
|
|
|
|
return 1;
|
|
|
|
|
2018-05-21 21:44:54 +02: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 10:21:20 +02:00
|
|
|
DwoOut = GetOutputStream(SplitDwarfFile, sys::fs::OF_None);
|
2018-05-21 21:44:54 +02:00
|
|
|
if (!DwoOut)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-15 00:14:34 +02:00
|
|
|
std::unique_ptr<buffer_ostream> BOS;
|
|
|
|
raw_pwrite_stream *OS = &Out->os();
|
2014-03-06 06:51:42 +01:00
|
|
|
std::unique_ptr<MCStreamer> Str;
|
2009-08-17 06:23:44 +02:00
|
|
|
|
2014-03-06 06:51:42 +01:00
|
|
|
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
|
2020-11-22 06:04:12 +01:00
|
|
|
assert(MCII && "Unable to create instruction info!");
|
|
|
|
|
2014-04-25 06:24:47 +02:00
|
|
|
MCInstPrinter *IP = nullptr;
|
2009-09-04 23:45:34 +02:00
|
|
|
if (FileType == OFT_AssemblyFile) {
|
2015-09-15 18:17:27 +02:00
|
|
|
IP = TheTarget->createMCInstPrinter(Triple(TripleName), OutputAsmVariant,
|
|
|
|
*MAI, *MCII, *MRI);
|
2014-06-11 22:26:40 +02:00
|
|
|
|
2016-10-31 19:36:31 +01:00
|
|
|
if (!IP) {
|
2018-04-22 10:01:35 +02:00
|
|
|
WithColor::error()
|
|
|
|
<< "unable to create instruction printer for target triple '"
|
2016-10-31 19:36:31 +01:00
|
|
|
<< TheTriple.normalize() << "' with assembly variant "
|
|
|
|
<< OutputAsmVariant << ".\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-05-26 19:43:32 +02:00
|
|
|
for (StringRef Opt : DisassemblerOptions)
|
|
|
|
if (!IP->applyTargetSpecificCLOption(Opt)) {
|
|
|
|
WithColor::error() << "invalid disassembler option '" << Opt << "'\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-06-11 22:26:40 +02:00
|
|
|
// Set the display preference for hex vs. decimal immediates.
|
|
|
|
IP->setPrintImmHex(PrintImmHex);
|
|
|
|
|
|
|
|
// Set up the AsmStreamer.
|
2018-04-27 17:45:54 +02: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 17:54:37 +02:00
|
|
|
auto FOut = std::make_unique<formatted_raw_ostream>(*OS);
|
2018-04-27 17:45:54 +02:00
|
|
|
Str.reset(
|
|
|
|
TheTarget->createAsmStreamer(Ctx, std::move(FOut), /*asmverbose*/ true,
|
|
|
|
/*useDwarfDirectory*/ true, IP,
|
|
|
|
std::move(CE), std::move(MAB), ShowInst));
|
2011-12-06 00:20:14 +01:00
|
|
|
|
2010-03-24 00:47:12 +01:00
|
|
|
} else if (FileType == OFT_Null) {
|
2015-02-19 01:45:04 +01: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 11:11:24 +02:00
|
|
|
} else {
|
|
|
|
assert(FileType == OFT_ObjectFile && "Invalid file type!");
|
2015-04-15 00:14:34 +02:00
|
|
|
|
|
|
|
if (!Out->os().supportsSeeking()) {
|
2019-08-15 17:54:37 +02:00
|
|
|
BOS = std::make_unique<buffer_ostream>(Out->os());
|
2015-04-15 00:14:34 +02:00
|
|
|
OS = BOS.get();
|
|
|
|
}
|
|
|
|
|
2015-03-10 23:03:14 +01:00
|
|
|
MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx);
|
2018-01-03 09:53:05 +01:00
|
|
|
MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions);
|
2015-12-21 23:09:27 +01:00
|
|
|
Str.reset(TheTarget->createMCObjectStreamer(
|
2018-05-18 20:26:45 +02:00
|
|
|
TheTriple, Ctx, std::unique_ptr<MCAsmBackend>(MAB),
|
2018-05-21 21:44:54 +02:00
|
|
|
DwoOut ? MAB->createDwoObjectWriter(*OS, DwoOut->os())
|
|
|
|
: MAB->createObjectWriter(*OS),
|
|
|
|
std::unique_ptr<MCCodeEmitter>(CE), *STI, MCOptions.MCRelaxAll,
|
|
|
|
MCOptions.MCIncrementalLinkerCompatible,
|
2015-12-21 23:09:27 +01:00
|
|
|
/*DWARFMustBeAtTheEnd*/ false));
|
2014-10-15 18:12:52 +02: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 11:11:24 +02:00
|
|
|
}
|
2009-06-25 01:30:00 +02: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-04-30 21:22:40 +02:00
|
|
|
// Use Assembler information for parsing.
|
|
|
|
Str->setUseAssemblerInfoForParsing(true);
|
|
|
|
|
2012-04-16 13:32:10 +02:00
|
|
|
int Res = 1;
|
2012-12-05 19:13:19 +01:00
|
|
|
bool disassemble = false;
|
2009-06-21 07:22:37 +02:00
|
|
|
switch (Action) {
|
2009-06-21 22:16:42 +02:00
|
|
|
case AC_AsLex:
|
2014-12-12 08:52:19 +01:00
|
|
|
Res = AsLexInput(SrcMgr, *MAI, Out->os());
|
2012-04-16 13:32:10 +02:00
|
|
|
break;
|
2009-06-21 07:22:37 +02:00
|
|
|
case AC_Assemble:
|
2014-06-19 08:22:01 +02:00
|
|
|
Res = AssembleInput(ProgName, TheTarget, SrcMgr, Ctx, *Str, *MAI, *STI,
|
2014-06-19 08:22:08 +02:00
|
|
|
*MCII, MCOptions);
|
2012-04-16 13:32:10 +02:00
|
|
|
break;
|
2012-10-23 00:31:46 +02:00
|
|
|
case AC_MDisassemble:
|
2013-02-27 00:04:17 +01:00
|
|
|
assert(IP && "Expected assembly output");
|
2019-07-25 11:54:12 +02:00
|
|
|
IP->setUseMarkup(true);
|
2012-12-05 19:13:19 +01:00
|
|
|
disassemble = true;
|
|
|
|
break;
|
2009-12-17 02:49:59 +01:00
|
|
|
case AC_Disassemble:
|
2012-12-05 19:13:19 +01:00
|
|
|
disassemble = true;
|
2012-04-16 13:32:10 +02:00
|
|
|
break;
|
2009-06-21 07:22:37 +02:00
|
|
|
}
|
2012-12-05 19:13:19 +01:00
|
|
|
if (disassemble)
|
2019-10-15 20:28:22 +02:00
|
|
|
Res = Disassembler::disassemble(*TheTarget, TripleName, *STI, *Str, *Buffer,
|
2019-10-23 12:24:35 +02:00
|
|
|
SrcMgr, Ctx, Out->os(), MCOptions);
|
2012-04-16 13:32:10 +02:00
|
|
|
|
|
|
|
// Keep output if no errors.
|
2018-05-21 21:44:54 +02:00
|
|
|
if (Res == 0) {
|
|
|
|
Out->keep();
|
|
|
|
if (DwoOut)
|
|
|
|
DwoOut->keep();
|
|
|
|
}
|
2012-04-16 13:32:10 +02:00
|
|
|
return Res;
|
2009-06-19 01:04:45 +02:00
|
|
|
}
|