diff options
author | dim <dim@FreeBSD.org> | 2011-05-02 19:34:44 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-05-02 19:34:44 +0000 |
commit | 2b066988909948dc3d53d01760bc2d71d32f3feb (patch) | |
tree | fc5f365fb9035b2d0c622bbf06c9bbe8627d7279 /tools/llvm-mc | |
parent | c80ac9d286b8fcc6d1ee5d76048134cf80aa9edc (diff) | |
download | FreeBSD-src-2b066988909948dc3d53d01760bc2d71d32f3feb.zip FreeBSD-src-2b066988909948dc3d53d01760bc2d71d32f3feb.tar.gz |
Vendor import of llvm trunk r130700:
http://llvm.org/svn/llvm-project/llvm/trunk@130700
Diffstat (limited to 'tools/llvm-mc')
-rw-r--r-- | tools/llvm-mc/Disassembler.cpp | 9 | ||||
-rw-r--r-- | tools/llvm-mc/Disassembler.h | 6 | ||||
-rw-r--r-- | tools/llvm-mc/llvm-mc.cpp | 39 |
3 files changed, 43 insertions, 11 deletions
diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp index d98b57e..cdd1892 100644 --- a/tools/llvm-mc/Disassembler.cpp +++ b/tools/llvm-mc/Disassembler.cpp @@ -127,7 +127,8 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray, return false; } -int Disassembler::disassemble(const Target &T, const std::string &Triple, +int Disassembler::disassemble(const Target &T, TargetMachine &TM, + const std::string &Triple, MemoryBuffer &Buffer, raw_ostream &Out) { // Set up disassembler. @@ -145,7 +146,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple, } int AsmPrinterVariant = AsmInfo->getAssemblerDialect(); - OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(AsmPrinterVariant, + OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(TM, AsmPrinterVariant, *AsmInfo)); if (!IP) { errs() << "error: no instruction printer for target " << Triple << '\n'; @@ -239,12 +240,12 @@ int Disassembler::disassembleEnhanced(const std::string &TS, OwningPtr<EDInst> inst(disassembler->createInst(byteArrayReader, 0, &ByteArray)); - ByteArray.erase (ByteArray.begin(), ByteArray.begin() + inst->byteSize()); - if (inst == 0) { errs() << "error: Didn't get an instruction\n"; return -1; } + + ByteArray.erase (ByteArray.begin(), ByteArray.begin() + inst->byteSize()); unsigned numTokens = inst->numTokens(); if ((int)numTokens < 0) { diff --git a/tools/llvm-mc/Disassembler.h b/tools/llvm-mc/Disassembler.h index b56f2e9..aaf77b5 100644 --- a/tools/llvm-mc/Disassembler.h +++ b/tools/llvm-mc/Disassembler.h @@ -19,13 +19,15 @@ namespace llvm { -class Target; class MemoryBuffer; +class Target; +class TargetMachine; class raw_ostream; class Disassembler { public: - static int disassemble(const Target &target, + static int disassemble(const Target &target, + TargetMachine &TM, const std::string &tripleString, MemoryBuffer &buffer, raw_ostream &Out); diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 2c22bed..24cc263 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -113,6 +113,10 @@ static cl::opt<bool> NoInitialTextSection("n", cl::desc( "Don't assume assembly file starts in the text section")); +static cl::opt<bool> +SaveTempLabels("L", cl::desc( + "Don't discard temporary labels")); + enum ActionType { AC_AsLex, AC_Assemble, @@ -327,6 +331,8 @@ static int AssembleInput(const char *ProgName) { const TargetAsmInfo *tai = new TargetAsmInfo(*TM); MCContext Ctx(*MAI, tai); + if (SaveTempLabels) + Ctx.setAllowTemporaryLabels(false); OwningPtr<tool_output_file> Out(GetOutputStream()); if (!Out) @@ -342,7 +348,7 @@ static int AssembleInput(const char *ProgName) { // FIXME: There is a bit of code duplication with addPassesToEmitFile. if (FileType == OFT_AssemblyFile) { MCInstPrinter *IP = - TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI); + TheTarget->createMCInstPrinter(*TM, OutputAsmVariant, *MAI); MCCodeEmitter *CE = 0; TargetAsmBackend *TAB = 0; if (ShowEncoding) { @@ -350,7 +356,8 @@ static int AssembleInput(const char *ProgName) { TAB = TheTarget->createAsmBackend(TripleName); } Str.reset(TheTarget->createAsmStreamer(Ctx, FOS, /*asmverbose*/true, - /*useLoc*/ true, IP, CE, TAB, + /*useLoc*/ true, + /*useCFI*/ true, IP, CE, TAB, ShowInst)); } else if (FileType == OFT_Null) { Str.reset(createNullStreamer(Ctx)); @@ -403,12 +410,34 @@ static int DisassembleInput(const char *ProgName, bool Enhanced) { return 1; int Res; - if (Enhanced) + if (Enhanced) { Res = Disassembler::disassembleEnhanced(TripleName, *Buffer.take(), Out->os()); - else - Res = Disassembler::disassemble(*TheTarget, TripleName, + } else { + // Package up features to be passed to target/subtarget + std::string FeaturesStr; + if (MCPU.size()) { + SubtargetFeatures Features; + Features.setCPU(MCPU); + FeaturesStr = Features.getString(); + } + + // FIXME: We shouldn't need to do this (and link in codegen). + // When we split this out, we should do it in a way that makes + // it straightforward to switch subtargets on the fly (.e.g, + // the .cpu and .code16 directives). + OwningPtr<TargetMachine> TM(TheTarget->createTargetMachine(TripleName, + FeaturesStr)); + + if (!TM) { + errs() << ProgName << ": error: could not create target for triple '" + << TripleName << "'.\n"; + return 1; + } + + Res = Disassembler::disassemble(*TheTarget, *TM, TripleName, *Buffer.take(), Out->os()); + } // Keep output if no errors. if (Res == 0) Out->keep(); |