*
**************************************************************************/
+#include <stddef.h>
+
#include <llvm-c/Core.h>
#include <llvm/Target/TargetMachine.h>
-#include <llvm/Target/TargetRegistry.h>
-#include <llvm/Target/TargetSelect.h>
#include <llvm/Target/TargetInstrInfo.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Support/MemoryObject.h>
+
+#if HAVE_LLVM >= 0x0300
+#include <llvm/Support/TargetRegistry.h>
+#else /* HAVE_LLVM < 0x0300 */
+#include <llvm/Target/TargetRegistry.h>
+#endif /* HAVE_LLVM < 0x0300 */
+
+#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
#include <llvm/MC/MCDisassembler.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 */
#include "util/u_math.h"
#include "util/u_debug.h"
uint64_t pos;
void write_impl(const char *Ptr, size_t Size);
- uint64_t current_pos() { return pos; }
- uint64_t current_pos() const { return pos; }
#if HAVE_LLVM >= 0x207
- uint64_t preferred_buffer_size() { return 512; }
+ 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
};
/*
* Limit disassembly to this extent
*/
- const uint64_t extent = 0x10000;
+ const uint64_t extent = 96 * 1024;
uint64_t max_pc = 0;
* 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 >= 0x0208
- InitializeNativeTargetAsmPrinter();
+#if HAVE_LLVM >= 0x0300
+ OwningPtr<const MCAsmInfo> AsmInfo(T->createMCAsmInfo(Triple));
#else
- InitializeAllAsmPrinters();
-#endif
-
- InitializeAllDisassemblers();
-
OwningPtr<const MCAsmInfo> AsmInfo(T->createAsmInfo(Triple));
+#endif
if (!AsmInfo) {
debug_printf("error: no assembly info for target %s\n", Triple.c_str());
return;
}
+#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) {
debug_printf("error: no disassembler for target %s\n", Triple.c_str());
return;
raw_debug_ostream Out;
+#if HAVE_LLVM >= 0x0300
+ unsigned int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
+#else
int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
-#if HAVE_LLVM >= 0x0208
+#endif
+
+#if HAVE_LLVM >= 0x0301
+ OwningPtr<const MCRegisterInfo> MRI(T->createMCRegInfo(Triple));
+ if (!MRI) {
+ debug_printf("error: no register info for target %s\n", Triple.c_str());
+ return;
+ }
+
+ OwningPtr<const MCInstrInfo> MII(T->createMCInstrInfo());
+ if (!MII) {
+ debug_printf("error: no instruction info for target %s\n", Triple.c_str());
+ return;
+ }
+#endif
+
+#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
return;
}
+#if HAVE_LLVM >= 0x0301
+ TargetOptions options;
+#if defined(DEBUG)
+ options.JITEmitDebugInfo = true;
+#endif
+#if defined(PIPE_ARCH_X86)
+ options.StackAlignmentOverride = 4;
+#endif
+#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
const TargetInstrInfo *TII = TM->getInstrInfo();
if (!DisAsm->getInstruction(Inst, Size, memoryObject,
pc,
- nulls())) {
+#if HAVE_LLVM >= 0x0300
+ nulls(), nulls())) {
+#else
+ nulls())) {
+#endif
debug_printf("invalid\n");
pc += 1;
}
* Print the instruction.
*/
-#if HAVE_LLVM >= 0x208
+#if HAVE_LLVM >= 0x0300
+ Printer->printInst(&Inst, Out, "");
+#elif HAVE_LLVM >= 0x208
Printer->printInst(&Inst, Out);
#else
Printer->printInst(&Inst);
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.