diff options
Diffstat (limited to 'contrib/llvm/tools/llvm-mc/llvm-mc.cpp')
-rw-r--r-- | contrib/llvm/tools/llvm-mc/llvm-mc.cpp | 80 |
1 files changed, 55 insertions, 25 deletions
diff --git a/contrib/llvm/tools/llvm-mc/llvm-mc.cpp b/contrib/llvm/tools/llvm-mc/llvm-mc.cpp index f7c3748..243899b 100644 --- a/contrib/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/contrib/llvm/tools/llvm-mc/llvm-mc.cpp @@ -12,36 +12,35 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCParser/AsmLexer.h" -#include "llvm/MC/MCParser/MCAsmLexer.h" +#include "Disassembler.h" +#include "llvm/ADT/OwningPtr.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCContext.h" #include "llvm/MC/MCCodeEmitter.h" +#include "llvm/MC/MCContext.h" #include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCObjectFileInfo.h" +#include "llvm/MC/MCParser/AsmLexer.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCTargetAsmParser.h" #include "llvm/MC/SubtargetFeature.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/FormattedStream.h" +#include "llvm/Support/Host.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PrettyStackTrace.h" -#include "llvm/Support/SourceMgr.h" -#include "llvm/Support/ToolOutputFile.h" -#include "llvm/Support/Host.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" +#include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/system_error.h" -#include "Disassembler.h" using namespace llvm; static cl::opt<std::string> @@ -69,6 +68,9 @@ static cl::opt<bool> RelaxAll("mc-relax-all", cl::desc("Relax all fixups")); static cl::opt<bool> +DisableCFI("disable-cfi", cl::desc("Do not use .cfi_* directives")); + +static cl::opt<bool> NoExecStack("mc-no-exec-stack", cl::desc("File doesn't need an exec stack")); enum OutputFileType { @@ -154,12 +156,20 @@ static cl::opt<bool> GenDwarfForAssembly("g", cl::desc("Generate dwarf debugging info for assembly " "source files")); +static cl::opt<std::string> +DebugCompilationDir("fdebug-compilation-dir", + cl::desc("Specifies the debug info's compilation dir")); + +static cl::opt<std::string> +MainFileName("main-file-name", + cl::desc("Specifies the name we should consider the input file")); + enum ActionType { AC_AsLex, AC_Assemble, AC_Disassemble, - AC_EDisassemble, - AC_MDisassemble + AC_MDisassemble, + AC_HDisassemble }; static cl::opt<ActionType> @@ -171,10 +181,11 @@ Action(cl::desc("Action to perform:"), "Assemble a .s file (default)"), clEnumValN(AC_Disassemble, "disassemble", "Disassemble strings of hex bytes"), - clEnumValN(AC_EDisassemble, "edis", - "Enhanced disassembly of strings of hex bytes"), clEnumValN(AC_MDisassemble, "mdis", "Marked up disassembly of strings of hex bytes"), + clEnumValN(AC_HDisassemble, "hdis", + "Disassemble strings of hex bytes printing " + "immediates as hex"), clEnumValEnd)); static const Target *GetTarget(const char *ProgName) { @@ -224,6 +235,13 @@ static void setDwarfDebugFlags(int argc, char **argv) { } } +static std::string DwarfDebugProducer; +static void setDwarfDebugProducer(void) { + if(!getenv("DEBUG_PRODUCER")) + return; + DwarfDebugProducer += getenv("DEBUG_PRODUCER"); +} + static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI, tool_output_file *Out) { AsmLexer Lexer(MAI); @@ -251,9 +269,6 @@ static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI, tool_output_file *Out) case AsmToken::Real: Out->os() << "real: " << Lexer.getTok().getString(); break; - case AsmToken::Register: - Out->os() << "register: " << Lexer.getTok().getRegVal(); - break; case AsmToken::String: Out->os() << "string: " << Lexer.getTok().getString(); break; @@ -344,6 +359,8 @@ int main(int argc, char **argv) { TripleName = Triple::normalize(TripleName); setDwarfDebugFlags(argc, argv); + setDwarfDebugProducer(); + const char *ProgName = argv[0]; const Target *TheTarget = GetTarget(ProgName); if (!TheTarget) @@ -365,7 +382,6 @@ int main(int argc, char **argv) { // it later. SrcMgr.setIncludeDirs(IncludeDirs); - llvm::OwningPtr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(TripleName)); assert(MAI && "Unable to create target asm info!"); @@ -382,8 +398,14 @@ int main(int argc, char **argv) { Ctx.setAllowTemporaryLabels(false); Ctx.setGenDwarfForAssembly(GenDwarfForAssembly); - if (!DwarfDebugFlags.empty()) + if (!DwarfDebugFlags.empty()) Ctx.setDwarfDebugFlags(StringRef(DwarfDebugFlags)); + if (!DwarfDebugProducer.empty()) + Ctx.setDwarfDebugProducer(StringRef(DwarfDebugProducer)); + if (!DebugCompilationDir.empty()) + Ctx.setCompilationDir(DebugCompilationDir); + if (!MainFileName.empty()) + Ctx.setMainFileName(MainFileName); // Package up features to be passed to target/subtarget std::string FeaturesStr; @@ -405,7 +427,7 @@ int main(int argc, char **argv) { OwningPtr<MCSubtargetInfo> STI(TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr)); - MCInstPrinter *IP; + MCInstPrinter *IP = NULL; if (FileType == OFT_AssemblyFile) { IP = TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *MCII, *MRI, *STI); @@ -415,9 +437,10 @@ int main(int argc, char **argv) { CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, *STI, Ctx); MAB = TheTarget->createMCAsmBackend(TripleName, MCPU); } + bool UseCFI = !DisableCFI; Str.reset(TheTarget->createAsmStreamer(Ctx, FOS, /*asmverbose*/true, /*useLoc*/ true, - /*useCFI*/ true, + UseCFI, /*useDwarfDirectory*/ true, IP, CE, MAB, ShowInst)); @@ -433,6 +456,7 @@ int main(int argc, char **argv) { } int Res = 1; + bool disassemble = false; switch (Action) { case AC_AsLex: Res = AsLexInput(SrcMgr, *MAI, Out.get()); @@ -441,16 +465,22 @@ int main(int argc, char **argv) { Res = AssembleInput(ProgName, TheTarget, SrcMgr, Ctx, *Str, *MAI, *STI); break; case AC_MDisassemble: + assert(IP && "Expected assembly output"); IP->setUseMarkup(1); - // Fall through to do disassembly. - case AC_Disassemble: - Res = Disassembler::disassemble(*TheTarget, TripleName, *STI, *Str, - *Buffer, SrcMgr, Out->os()); + disassemble = true; break; - case AC_EDisassemble: - Res = Disassembler::disassembleEnhanced(TripleName, *Buffer, SrcMgr, Out->os()); + case AC_HDisassemble: + assert(IP && "Expected assembly output"); + IP->setPrintImmHex(1); + disassemble = true; + break; + case AC_Disassemble: + disassemble = true; break; } + if (disassemble) + Res = Disassembler::disassemble(*TheTarget, TripleName, *STI, *Str, + *Buffer, SrcMgr, Out->os()); // Keep output if no errors. if (Res == 0) Out->keep(); |