#include <llvm/Support/Format.h>
#include <llvm/Support/MemoryObject.h>
-#if HAVE_LLVM >= 0x0300
+#if HAVE_LLVM >= 0x0306
+#include <llvm/Target/TargetSubtargetInfo.h>
+#endif
+
#include <llvm/Support/TargetRegistry.h>
-#else /* HAVE_LLVM < 0x0300 */
-#include <llvm/Target/TargetRegistry.h>
-#endif /* HAVE_LLVM < 0x0300 */
+#include <llvm/MC/MCSubtargetInfo.h>
-#if HAVE_LLVM >= 0x0209
#include <llvm/Support/Host.h>
-#else /* HAVE_LLVM < 0x0209 */
-#include <llvm/System/Host.h>
-#endif /* HAVE_LLVM < 0x0209 */
-#if HAVE_LLVM >= 0x0207
+#if HAVE_LLVM >= 0x0303
+#include <llvm/IR/Module.h>
+#else
+#include <llvm/Module.h>
+#endif
+
#include <llvm/MC/MCDisassembler.h>
#include <llvm/MC/MCAsmInfo.h>
#include <llvm/MC/MCInst.h>
#include <llvm/MC/MCInstPrinter.h>
-#endif /* HAVE_LLVM >= 0x0207 */
-#if HAVE_LLVM >= 0x0301
#include <llvm/MC/MCRegisterInfo.h>
-#endif /* HAVE_LLVM >= 0x0301 */
-#if HAVE_LLVM >= 0x0303
+#if HAVE_LLVM >= 0x0305
+#define OwningPtr std::unique_ptr
+#elif HAVE_LLVM >= 0x0303
#include <llvm/ADT/OwningPtr.h>
#endif
+#if HAVE_LLVM >= 0x0305
+#include <llvm/MC/MCContext.h>
+#endif
+
#include "util/u_math.h"
#include "util/u_debug.h"
void write_impl(const char *Ptr, size_t Size);
-#if HAVE_LLVM >= 0x207
uint64_t current_pos() const { return pos; }
size_t preferred_buffer_size() const { return 512; }
-#else
- uint64_t current_pos() { return pos; }
- size_t preferred_buffer_size() { return 512; }
-#endif
};
}
+extern "C" const char *
+lp_get_module_id(LLVMModuleRef module)
+{
+ return llvm::unwrap(module)->getModuleIdentifier().c_str();
+}
+
+
/**
* Same as LLVMDumpValue, but through our debugging channels.
*/
}
-#if HAVE_LLVM >= 0x0207
/*
* MemoryObject wrapper around a buffer of memory, to be used by MC
* disassembler.
return 0;
}
};
-#endif /* HAVE_LLVM >= 0x0207 */
/*
static size_t
disassemble(const void* func, llvm::raw_ostream & Out)
{
-#if HAVE_LLVM >= 0x0207
using namespace llvm;
const uint8_t *bytes = (const uint8_t *)func;
* Initialize all used objects.
*/
-#if HAVE_LLVM >= 0x0301
std::string Triple = sys::getDefaultTargetTriple();
-#else
- std::string Triple = sys::getHostTriple();
-#endif
std::string Error;
const Target *T = TargetRegistry::lookupTarget(Triple, Error);
-#if HAVE_LLVM >= 0x0300
- OwningPtr<const MCAsmInfo> AsmInfo(T->createMCAsmInfo(Triple));
+#if HAVE_LLVM >= 0x0304
+ OwningPtr<const MCAsmInfo> AsmInfo(T->createMCAsmInfo(*T->createMCRegInfo(Triple), Triple));
#else
- OwningPtr<const MCAsmInfo> AsmInfo(T->createAsmInfo(Triple));
+ OwningPtr<const MCAsmInfo> AsmInfo(T->createMCAsmInfo(Triple));
#endif
if (!AsmInfo) {
Out << "error: no assembly info for target " << Triple << "\n";
+ Out.flush();
return 0;
}
-#if HAVE_LLVM >= 0x0300
- const MCSubtargetInfo *STI = T->createMCSubtargetInfo(Triple, sys::getHostCPUName(), "");
- OwningPtr<const MCDisassembler> DisAsm(T->createMCDisassembler(*STI));
-#else
- OwningPtr<const MCDisassembler> DisAsm(T->createMCDisassembler());
-#endif
- if (!DisAsm) {
- Out << "error: no disassembler for target " << Triple << "\n";
- return 0;
- }
-
-#if HAVE_LLVM >= 0x0300
unsigned int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
-#else
- int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
-#endif
-#if HAVE_LLVM >= 0x0301
OwningPtr<const MCRegisterInfo> MRI(T->createMCRegInfo(Triple));
if (!MRI) {
Out << "error: no register info for target " << Triple.c_str() << "\n";
+ Out.flush();
return 0;
}
OwningPtr<const MCInstrInfo> MII(T->createMCInstrInfo());
if (!MII) {
Out << "error: no instruction info for target " << Triple.c_str() << "\n";
+ Out.flush();
return 0;
}
+
+#if HAVE_LLVM >= 0x0305
+ OwningPtr<const MCSubtargetInfo> STI(T->createMCSubtargetInfo(Triple, sys::getHostCPUName(), ""));
+ OwningPtr<MCContext> MCCtx(new MCContext(AsmInfo.get(), MRI.get(), 0));
+ OwningPtr<const MCDisassembler> DisAsm(T->createMCDisassembler(*STI, *MCCtx));
+#else
+ OwningPtr<const MCSubtargetInfo> STI(T->createMCSubtargetInfo(Triple, sys::getHostCPUName(), ""));
+ OwningPtr<const MCDisassembler> DisAsm(T->createMCDisassembler(*STI));
#endif
+ if (!DisAsm) {
+ Out << "error: no disassembler for target " << Triple << "\n";
+ Out.flush();
+ return 0;
+ }
+
-#if HAVE_LLVM >= 0x0301
OwningPtr<MCInstPrinter> Printer(
T->createMCInstPrinter(AsmPrinterVariant, *AsmInfo, *MII, *MRI, *STI));
-#elif HAVE_LLVM == 0x0300
- OwningPtr<MCInstPrinter> Printer(
- T->createMCInstPrinter(AsmPrinterVariant, *AsmInfo, *STI));
-#elif HAVE_LLVM >= 0x0208
- OwningPtr<MCInstPrinter> Printer(
- T->createMCInstPrinter(AsmPrinterVariant, *AsmInfo));
-#else
- OwningPtr<MCInstPrinter> Printer(
- T->createMCInstPrinter(AsmPrinterVariant, *AsmInfo, Out));
-#endif
if (!Printer) {
Out << "error: no instruction printer for target " << Triple.c_str() << "\n";
+ Out.flush();
return 0;
}
-#if HAVE_LLVM >= 0x0301
TargetOptions options;
#if defined(DEBUG)
options.JITEmitDebugInfo = true;
#if defined(DEBUG) || defined(PROFILE)
options.NoFramePointerElim = true;
#endif
- TargetMachine *TM = T->createTargetMachine(Triple, sys::getHostCPUName(), "", options);
-#elif HAVE_LLVM == 0x0300
- TargetMachine *TM = T->createTargetMachine(Triple, sys::getHostCPUName(), "");
-#else
- TargetMachine *TM = T->createTargetMachine(Triple, "");
-#endif
+ OwningPtr<TargetMachine> TM(T->createTargetMachine(Triple, sys::getHostCPUName(), "", options));
+#if HAVE_LLVM >= 0x0306
+ const TargetInstrInfo *TII = TM->getSubtargetImpl()->getInstrInfo();
+#else
const TargetInstrInfo *TII = TM->getInstrInfo();
+#endif
/*
* Wrap the data in a MemoryObject
if (!DisAsm->getInstruction(Inst, Size, memoryObject,
pc,
-#if HAVE_LLVM >= 0x0300
nulls(), nulls())) {
-#else
- nulls())) {
-#endif
Out << "invalid";
pc += 1;
}
/*
* Print the instruction.
*/
-#if HAVE_LLVM >= 0x0300
- Printer->printInst(&Inst, Out, "");
-#elif HAVE_LLVM >= 0x208
- Printer->printInst(&Inst, Out);
-#else
- Printer->printInst(&Inst);
-#endif
+ Printer->printInst(&Inst, Out, "");
/*
* Advance.
pc += Size;
-#if HAVE_LLVM >= 0x0300
const MCInstrDesc &TID = TII->get(Inst.getOpcode());
-#else
- const TargetInstrDesc &TID = TII->get(Inst.getOpcode());
-#endif
/*
* Keep track of forward jumps to a nearby address.
Out.flush();
return pc;
-#else /* HAVE_LLVM < 0x0207 */
- (void)func;
- return 0;
-#endif /* HAVE_LLVM < 0x0207 */
}