summaryrefslogtreecommitdiff
path: root/tools/llvm-mc
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2011-03-21 04:13:46 +0000
committerBill Wendling <isanbard@gmail.com>2011-03-21 04:13:46 +0000
commita5c177e70a42f48e4885075c4c48aad0816a2817 (patch)
treeaeeef1186b086a66459727967e2e2d71ff800c92 /tools/llvm-mc
parent262a8627870c38f385944fc2ed9ae365347adf47 (diff)
downloadllvm-a5c177e70a42f48e4885075c4c48aad0816a2817.tar.gz
llvm-a5c177e70a42f48e4885075c4c48aad0816a2817.tar.bz2
llvm-a5c177e70a42f48e4885075c4c48aad0816a2817.tar.xz
We need to pass the TargetMachine object to the InstPrinter if we are printing
the alias of an InstAlias instead of the thing being aliased. Because we need to know the features that are valid for an InstAlias. This is part of a work-in-progress. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127986 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-mc')
-rw-r--r--tools/llvm-mc/Disassembler.cpp5
-rw-r--r--tools/llvm-mc/Disassembler.h6
-rw-r--r--tools/llvm-mc/llvm-mc.cpp30
3 files changed, 33 insertions, 8 deletions
diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp
index d98b57ebc6..41b92a1b30 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';
diff --git a/tools/llvm-mc/Disassembler.h b/tools/llvm-mc/Disassembler.h
index b56f2e9545..aaf77b5a0f 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 2c22bedf1c..b7818665ab 100644
--- a/tools/llvm-mc/llvm-mc.cpp
+++ b/tools/llvm-mc/llvm-mc.cpp
@@ -342,7 +342,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) {
@@ -403,12 +403,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();