X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-mc%2Fllvm-mc.cpp;h=26c99d5283274b6491e46342908399a14f955cce;hb=4f2779b809f6a9bb5ca63b10d55f8302cca2c656;hp=f7c3748f079bc0f3bf07d6aaeb44c463e1eb75bd;hpb=3ed0316f756e2f1730f46654776fcf77f5ace7aa;p=oota-llvm.git diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index f7c3748f079..26c99d52832 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -12,36 +12,32 @@ // //===----------------------------------------------------------------------===// -#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/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/system_error.h" -#include "Disassembler.h" +#include "llvm/Support/ToolOutputFile.h" using namespace llvm; static cl::opt @@ -68,6 +64,9 @@ OutputAsmVariant("output-asm-variant", static cl::opt RelaxAll("mc-relax-all", cl::desc("Relax all fixups")); +static cl::opt +DisableCFI("disable-cfi", cl::desc("Do not use .cfi_* directives")); + static cl::opt NoExecStack("mc-no-exec-stack", cl::desc("File doesn't need an exec stack")); @@ -154,12 +153,20 @@ static cl::opt GenDwarfForAssembly("g", cl::desc("Generate dwarf debugging info for assembly " "source files")); +static cl::opt +DebugCompilationDir("fdebug-compilation-dir", + cl::desc("Specifies the debug info's compilation dir")); + +static cl::opt +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 @@ -171,10 +178,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 +232,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 +266,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 +356,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,25 +379,30 @@ int main(int argc, char **argv) { // it later. SrcMgr.setIncludeDirs(IncludeDirs); - - llvm::OwningPtr MAI(TheTarget->createMCAsmInfo(TripleName)); - assert(MAI && "Unable to create target asm info!"); - llvm::OwningPtr MRI(TheTarget->createMCRegInfo(TripleName)); assert(MRI && "Unable to create target register info!"); + llvm::OwningPtr MAI(TheTarget->createMCAsmInfo(*MRI, TripleName)); + assert(MAI && "Unable to create target asm info!"); + // FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and // MCObjectFileInfo needs a MCContext reference in order to initialize itself. OwningPtr MOFI(new MCObjectFileInfo()); - MCContext Ctx(*MAI, *MRI, MOFI.get(), &SrcMgr); + MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr); MOFI->InitMCObjectFileInfo(TripleName, RelocModel, CMModel, Ctx); if (SaveTempLabels) 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 +424,7 @@ int main(int argc, char **argv) { OwningPtr 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 +434,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 +453,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 +462,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();