add a new MachineModuleInfoMachO class, which is the per-module
[llvm/avr.git] / lib / System / Disassembler.cpp
blobbad427a58d8cbdcb624dc9dd8d50132e8ab0ad14
1 //===- lib/System/Disassembler.cpp ------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the necessary glue to call external disassembler
11 // libraries.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Config/config.h"
16 #include "llvm/System/Disassembler.h"
18 #include <cassert>
19 #include <iomanip>
20 #include <string>
21 #include <sstream>
23 #if USE_UDIS86
24 #include <udis86.h>
25 #endif
27 using namespace llvm;
29 bool llvm::sys::hasDisassembler()
31 #if defined (__i386__) || defined (__amd64__) || defined (__x86_64__)
32 // We have option to enable udis86 library.
33 # if USE_UDIS86
34 return true;
35 #else
36 return false;
37 #endif
38 #else
39 return false;
40 #endif
43 std::string llvm::sys::disassembleBuffer(uint8_t* start, size_t length,
44 uint64_t pc) {
45 std::stringstream res;
47 #if defined (__i386__) || defined (__amd64__) || defined (__x86_64__)
48 unsigned bits;
49 # if defined(__i386__)
50 bits = 32;
51 # else
52 bits = 64;
53 # endif
55 # if USE_UDIS86
56 ud_t ud_obj;
58 ud_init(&ud_obj);
59 ud_set_input_buffer(&ud_obj, start, length);
60 ud_set_mode(&ud_obj, bits);
61 ud_set_pc(&ud_obj, pc);
62 ud_set_syntax(&ud_obj, UD_SYN_ATT);
64 res << std::setbase(16)
65 << std::setw(bits/4);
67 while (ud_disassemble(&ud_obj)) {
68 res << ud_insn_off(&ud_obj) << ":\t" << ud_insn_asm(&ud_obj) << "\n";
70 # else
71 res << "No disassembler available. See configure help for options.\n";
72 # endif
74 #else
75 res << "No disassembler available. See configure help for options.\n";
76 #endif
78 return res.str();