summaryrefslogtreecommitdiff
path: root/tools/edis
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2010-04-13 21:21:57 +0000
committerSean Callanan <scallanan@apple.com>2010-04-13 21:21:57 +0000
commit9899f70a7406d632c82849978bf6981f1ee4ccb5 (patch)
tree8b3b82586ac00721aad38f465f9e579fb7ba9865 /tools/edis
parent0a6f053732c7a654cb9fe3e501680a104c3381a1 (diff)
downloadllvm-9899f70a7406d632c82849978bf6981f1ee4ccb5.tar.gz
llvm-9899f70a7406d632c82849978bf6981f1ee4ccb5.tar.bz2
llvm-9899f70a7406d632c82849978bf6981f1ee4ccb5.tar.xz
Fixed a nasty layering violation in the edis source
code. It used to #include the enhanced disassembly information for the targets it supported straight out of lib/Target/{X86,ARM,...} but now it uses a new interface provided by MCDisassembler, and (so far) implemented by X86 and ARM. Also removed hacky #define-controlled initialization of targets in edis. If clients only want edis to initialize a limited set of targets, they can set --enable-targets on the configure command line. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101179 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/edis')
-rw-r--r--tools/edis/EDDisassembler.cpp76
-rw-r--r--tools/edis/EDDisassembler.h4
-rw-r--r--tools/edis/EDInst.cpp3
-rw-r--r--tools/edis/EDInst.h8
-rw-r--r--tools/edis/EDOperand.cpp1
-rw-r--r--tools/edis/Makefile12
6 files changed, 36 insertions, 68 deletions
diff --git a/tools/edis/EDDisassembler.cpp b/tools/edis/EDDisassembler.cpp
index a766d2fc2b..b87fe62057 100644
--- a/tools/edis/EDDisassembler.cpp
+++ b/tools/edis/EDDisassembler.cpp
@@ -18,6 +18,7 @@
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/MC/EDInstInfo.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler.h"
@@ -39,47 +40,34 @@
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetSelect.h"
-#ifdef EDIS_X86
-#include "../../lib/Target/X86/X86GenEDInfo.inc"
-#endif
-
-#ifdef EDIS_ARM
-#include "../../lib/Target/ARM/ARMGenEDInfo.inc"
-#endif
-
using namespace llvm;
bool EDDisassembler::sInitialized = false;
EDDisassembler::DisassemblerMap_t EDDisassembler::sDisassemblers;
-struct InfoMap {
+struct TripleMap {
Triple::ArchType Arch;
const char *String;
- const InstInfo *Info;
};
-static struct InfoMap infomap[] = {
-#ifdef EDIS_X86
- { Triple::x86, "i386-unknown-unknown", instInfoX86 },
- { Triple::x86_64, "x86_64-unknown-unknown", instInfoX86 },
-#endif
-#ifdef EDIS_ARM
- { Triple::arm, "arm-unknown-unknown", instInfoARM },
- { Triple::thumb, "thumb-unknown-unknown", instInfoARM },
-#endif
- { Triple::InvalidArch, NULL, NULL }
+static struct TripleMap triplemap[] = {
+ { Triple::x86, "i386-unknown-unknown" },
+ { Triple::x86_64, "x86_64-unknown-unknown" },
+ { Triple::arm, "arm-unknown-unknown" },
+ { Triple::thumb, "thumb-unknown-unknown" },
+ { Triple::InvalidArch, NULL, }
};
-/// infoFromArch - Returns the InfoMap corresponding to a given architecture,
+/// infoFromArch - Returns the TripleMap corresponding to a given architecture,
/// or NULL if there is an error
///
/// @arg arch - The Triple::ArchType for the desired architecture
-static const InfoMap *infoFromArch(Triple::ArchType arch) {
+static const char *tripleFromArch(Triple::ArchType arch) {
unsigned int infoIndex;
- for (infoIndex = 0; infomap[infoIndex].String != NULL; ++infoIndex) {
- if (arch == infomap[infoIndex].Arch)
- return &infomap[infoIndex];
+ for (infoIndex = 0; triplemap[infoIndex].String != NULL; ++infoIndex) {
+ if (arch == triplemap[infoIndex].Arch)
+ return triplemap[infoIndex].String;
}
return NULL;
@@ -115,25 +103,17 @@ static int getLLVMSyntaxVariant(Triple::ArchType arch,
}
}
-#define BRINGUP_TARGET(tgt) \
- LLVMInitialize##tgt##TargetInfo(); \
- LLVMInitialize##tgt##Target(); \
- LLVMInitialize##tgt##AsmPrinter(); \
- LLVMInitialize##tgt##AsmParser(); \
- LLVMInitialize##tgt##Disassembler();
-
void EDDisassembler::initialize() {
if (sInitialized)
return;
sInitialized = true;
-#ifdef EDIS_X86
- BRINGUP_TARGET(X86)
-#endif
-#ifdef EDIS_ARM
- BRINGUP_TARGET(ARM)
-#endif
+ InitializeAllTargetInfos();
+ InitializeAllTargets();
+ InitializeAllAsmPrinters();
+ InitializeAllAsmParsers();
+ InitializeAllDisassemblers();
}
#undef BRINGUP_TARGET
@@ -175,14 +155,10 @@ EDDisassembler::EDDisassembler(CPUKey &key) :
HasSemantics(false),
ErrorStream(nulls()),
Key(key) {
- const InfoMap *infoMap = infoFromArch(key.Arch);
-
- if (!infoMap)
- return;
+ const char *triple = tripleFromArch(key.Arch);
- InstInfos = infoMap->Info;
-
- const char *triple = infoMap->String;
+ if (!triple)
+ return;
LLVMSyntaxVariant = getLLVMSyntaxVariant(key.Arch, key.Syntax);
@@ -220,6 +196,8 @@ EDDisassembler::EDDisassembler(CPUKey &key) :
if (!Disassembler)
return;
+
+ InstInfos = Disassembler->getEDInfo();
InstString.reset(new std::string);
InstStream.reset(new raw_string_ostream(*InstString));
@@ -231,8 +209,6 @@ EDDisassembler::EDDisassembler(CPUKey &key) :
GenericAsmLexer.reset(new AsmLexer(*AsmInfo));
SpecificAsmLexer.reset(Tgt->createAsmLexer(*AsmInfo));
SpecificAsmLexer->InstallLexer(*GenericAsmLexer);
-
- InstInfos = infoMap->Info;
initMaps(*targetMachine->getRegisterInfo());
@@ -285,7 +261,7 @@ EDInst *EDDisassembler::createInst(EDByteReaderCallback byteReader,
delete inst;
return NULL;
} else {
- const InstInfo *thisInstInfo;
+ const llvm::EDInstInfo *thisInstInfo;
thisInstInfo = &InstInfos[inst->getOpcode()];
@@ -308,7 +284,6 @@ void EDDisassembler::initMaps(const TargetRegisterInfo &registerInfo) {
switch (Key.Arch) {
default:
break;
-#ifdef EDIS_X86
case Triple::x86:
case Triple::x86_64:
stackPointers.insert(registerIDWithName("SP"));
@@ -319,15 +294,12 @@ void EDDisassembler::initMaps(const TargetRegisterInfo &registerInfo) {
programCounters.insert(registerIDWithName("EIP"));
programCounters.insert(registerIDWithName("RIP"));
break;
-#endif
-#ifdef EDIS_ARM
case Triple::arm:
case Triple::thumb:
stackPointers.insert(registerIDWithName("SP"));
programCounters.insert(registerIDWithName("PC"));
break;
-#endif
}
}
diff --git a/tools/edis/EDDisassembler.h b/tools/edis/EDDisassembler.h
index 9b27fe8170..74a260e825 100644
--- a/tools/edis/EDDisassembler.h
+++ b/tools/edis/EDDisassembler.h
@@ -48,6 +48,8 @@ template <typename T> class SmallVectorImpl;
class SourceMgr;
class Target;
class TargetRegisterInfo;
+
+struct EDInstInfo;
}
/// EDDisassembler - Encapsulates a disassembler for a single architecture and
@@ -143,7 +145,7 @@ struct EDDisassembler {
llvm::sys::Mutex PrinterMutex;
/// The array of instruction information provided by the TableGen backend for
/// the target architecture
- const InstInfo *InstInfos;
+ const llvm::EDInstInfo *InstInfos;
/// The target-specific lexer for use in tokenizing strings, in
/// target-independent and target-specific portions
llvm::OwningPtr<llvm::AsmLexer> GenericAsmLexer;
diff --git a/tools/edis/EDInst.cpp b/tools/edis/EDInst.cpp
index de40770e90..af3a54abbc 100644
--- a/tools/edis/EDInst.cpp
+++ b/tools/edis/EDInst.cpp
@@ -18,6 +18,7 @@
#include "EDOperand.h"
#include "EDToken.h"
+#include "llvm/MC/EDInstInfo.h"
#include "llvm/MC/MCInst.h"
using namespace llvm;
@@ -25,7 +26,7 @@ using namespace llvm;
EDInst::EDInst(llvm::MCInst *inst,
uint64_t byteSize,
EDDisassembler &disassembler,
- const InstInfo *info) :
+ const llvm::EDInstInfo *info) :
Disassembler(disassembler),
Inst(inst),
ThisInstInfo(info),
diff --git a/tools/edis/EDInst.h b/tools/edis/EDInst.h
index db03a7852e..c8a747ff99 100644
--- a/tools/edis/EDInst.h
+++ b/tools/edis/EDInst.h
@@ -23,6 +23,10 @@
#include <string>
#include <vector>
+namespace llvm {
+ struct EDInstInfo;
+}
+
/// CachedResult - Encapsulates the result of a function along with the validity
/// of that result, so that slow functions don't need to run twice
struct CachedResult {
@@ -54,7 +58,7 @@ struct EDInst {
/// The containing MCInst
llvm::MCInst *Inst;
/// The instruction information provided by TableGen for this instruction
- const InstInfo *ThisInstInfo;
+ const llvm::EDInstInfo *ThisInstInfo;
/// The number of bytes for the machine code representation of the instruction
uint64_t ByteSize;
@@ -95,7 +99,7 @@ struct EDInst {
EDInst(llvm::MCInst *inst,
uint64_t byteSize,
EDDisassembler &disassembler,
- const InstInfo *instInfo);
+ const llvm::EDInstInfo *instInfo);
~EDInst();
/// byteSize - returns the number of bytes consumed by the machine code
diff --git a/tools/edis/EDOperand.cpp b/tools/edis/EDOperand.cpp
index 93efd47094..495c0574d6 100644
--- a/tools/edis/EDOperand.cpp
+++ b/tools/edis/EDOperand.cpp
@@ -17,6 +17,7 @@
#include "EDInst.h"
#include "EDOperand.h"
+#include "llvm/MC/EDInstInfo.h"
#include "llvm/MC/MCInst.h"
using namespace llvm;
diff --git a/tools/edis/Makefile b/tools/edis/Makefile
index 57b941e7e4..0ef0dce621 100644
--- a/tools/edis/Makefile
+++ b/tools/edis/Makefile
@@ -49,18 +49,6 @@ ifeq ($(HOST_OS),Darwin)
endif
endif
-EDIS_DEFINES =
-
-ifneq (,$(findstring X86,$(TARGETS_TO_BUILD)))
- EDIS_DEFINES := $(EDIS_DEFINES) -DEDIS_X86
-endif
-
-ifneq (,$(findstring ARM,$(TARGETS_TO_BUILD)))
- EDIS_DEFINES := $(EDIS_DEFINES) -DEDIS_ARM
-endif
-
-CXXFLAGS := $(CXXFLAGS) $(EDIS_DEFINES)
-
EDInfo.inc: $(TBLGEN)
$(Echo) "Building semantic information header"
$(Verb) $(TableGen) -o $(call SYSPATH, $@) -gen-enhanced-disassembly-header /dev/null