Mercurial > hg > CbC > CbC_llvm
comparison tools/llvm-mc/Disassembler.cpp @ 77:54457678186b LLVM3.6
LLVM 3.6
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Sep 2014 22:06:00 +0900 |
parents | 95c75e76d11b |
children | 60c9769439b8 |
comparison
equal
deleted
inserted
replaced
34:e874dbf0ad9d | 77:54457678186b |
---|---|
11 // hexadecimal, from standard input or from a file. | 11 // hexadecimal, from standard input or from a file. |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #include "Disassembler.h" | 15 #include "Disassembler.h" |
16 #include "llvm/ADT/OwningPtr.h" | |
17 #include "llvm/ADT/Triple.h" | 16 #include "llvm/ADT/Triple.h" |
17 #include "llvm/MC/MCAsmInfo.h" | |
18 #include "llvm/MC/MCContext.h" | |
18 #include "llvm/MC/MCDisassembler.h" | 19 #include "llvm/MC/MCDisassembler.h" |
19 #include "llvm/MC/MCInst.h" | 20 #include "llvm/MC/MCInst.h" |
21 #include "llvm/MC/MCRegisterInfo.h" | |
20 #include "llvm/MC/MCStreamer.h" | 22 #include "llvm/MC/MCStreamer.h" |
21 #include "llvm/MC/MCSubtargetInfo.h" | 23 #include "llvm/MC/MCSubtargetInfo.h" |
22 #include "llvm/Support/MemoryBuffer.h" | 24 #include "llvm/Support/MemoryBuffer.h" |
23 #include "llvm/Support/MemoryObject.h" | 25 #include "llvm/Support/MemoryObject.h" |
24 #include "llvm/Support/SourceMgr.h" | 26 #include "llvm/Support/SourceMgr.h" |
34 private: | 36 private: |
35 const ByteArrayTy &Bytes; | 37 const ByteArrayTy &Bytes; |
36 public: | 38 public: |
37 VectorMemoryObject(const ByteArrayTy &bytes) : Bytes(bytes) {} | 39 VectorMemoryObject(const ByteArrayTy &bytes) : Bytes(bytes) {} |
38 | 40 |
39 uint64_t getBase() const { return 0; } | 41 uint64_t getBase() const override { return 0; } |
40 uint64_t getExtent() const { return Bytes.size(); } | 42 uint64_t getExtent() const override { return Bytes.size(); } |
41 | 43 |
42 int readByte(uint64_t Addr, uint8_t *Byte) const { | 44 int readByte(uint64_t Addr, uint8_t *Byte) const override { |
43 if (Addr >= getExtent()) | 45 if (Addr >= getExtent()) |
44 return -1; | 46 return -1; |
45 *Byte = Bytes[Addr].first; | 47 *Byte = Bytes[Addr].first; |
46 return 0; | 48 return 0; |
47 } | 49 } |
49 } | 51 } |
50 | 52 |
51 static bool PrintInsts(const MCDisassembler &DisAsm, | 53 static bool PrintInsts(const MCDisassembler &DisAsm, |
52 const ByteArrayTy &Bytes, | 54 const ByteArrayTy &Bytes, |
53 SourceMgr &SM, raw_ostream &Out, | 55 SourceMgr &SM, raw_ostream &Out, |
54 MCStreamer &Streamer, bool InAtomicBlock) { | 56 MCStreamer &Streamer, bool InAtomicBlock, |
57 const MCSubtargetInfo &STI) { | |
55 // Wrap the vector in a MemoryObject. | 58 // Wrap the vector in a MemoryObject. |
56 VectorMemoryObject memoryObject(Bytes); | 59 VectorMemoryObject memoryObject(Bytes); |
57 | 60 |
58 // Disassemble it to strings. | 61 // Disassemble it to strings. |
59 uint64_t Size; | 62 uint64_t Size; |
84 SourceMgr::DK_Warning, | 87 SourceMgr::DK_Warning, |
85 "potentially undefined instruction encoding"); | 88 "potentially undefined instruction encoding"); |
86 // Fall through | 89 // Fall through |
87 | 90 |
88 case MCDisassembler::Success: | 91 case MCDisassembler::Success: |
89 Streamer.EmitInstruction(Inst); | 92 Streamer.EmitInstruction(Inst, STI); |
90 break; | 93 break; |
91 } | 94 } |
92 } | 95 } |
93 | 96 |
94 return false; | 97 return false; |
156 MCSubtargetInfo &STI, | 159 MCSubtargetInfo &STI, |
157 MCStreamer &Streamer, | 160 MCStreamer &Streamer, |
158 MemoryBuffer &Buffer, | 161 MemoryBuffer &Buffer, |
159 SourceMgr &SM, | 162 SourceMgr &SM, |
160 raw_ostream &Out) { | 163 raw_ostream &Out) { |
161 OwningPtr<const MCDisassembler> DisAsm(T.createMCDisassembler(STI)); | 164 |
165 std::unique_ptr<const MCRegisterInfo> MRI(T.createMCRegInfo(Triple)); | |
166 if (!MRI) { | |
167 errs() << "error: no register info for target " << Triple << "\n"; | |
168 return -1; | |
169 } | |
170 | |
171 std::unique_ptr<const MCAsmInfo> MAI(T.createMCAsmInfo(*MRI, Triple)); | |
172 if (!MAI) { | |
173 errs() << "error: no assembly info for target " << Triple << "\n"; | |
174 return -1; | |
175 } | |
176 | |
177 // Set up the MCContext for creating symbols and MCExpr's. | |
178 MCContext Ctx(MAI.get(), MRI.get(), nullptr); | |
179 | |
180 std::unique_ptr<const MCDisassembler> DisAsm( | |
181 T.createMCDisassembler(STI, Ctx)); | |
162 if (!DisAsm) { | 182 if (!DisAsm) { |
163 errs() << "error: no disassembler for target " << Triple << "\n"; | 183 errs() << "error: no disassembler for target " << Triple << "\n"; |
164 return -1; | 184 return -1; |
165 } | 185 } |
166 | 186 |
200 // It's a real token, get the bytes and emit them | 220 // It's a real token, get the bytes and emit them |
201 ErrorOccurred |= ByteArrayFromString(ByteArray, Str, SM); | 221 ErrorOccurred |= ByteArrayFromString(ByteArray, Str, SM); |
202 | 222 |
203 if (!ByteArray.empty()) | 223 if (!ByteArray.empty()) |
204 ErrorOccurred |= PrintInsts(*DisAsm, ByteArray, SM, Out, Streamer, | 224 ErrorOccurred |= PrintInsts(*DisAsm, ByteArray, SM, Out, Streamer, |
205 InAtomicBlock); | 225 InAtomicBlock, STI); |
206 } | 226 } |
207 | 227 |
208 if (InAtomicBlock) { | 228 if (InAtomicBlock) { |
209 SM.PrintMessage(SMLoc::getFromPointer(Str.data()), SourceMgr::DK_Error, | 229 SM.PrintMessage(SMLoc::getFromPointer(Str.data()), SourceMgr::DK_Error, |
210 "unclosed atomic block"); | 230 "unclosed atomic block"); |