1212// ===----------------------------------------------------------------------===//
1313
1414#include " Disassembler.h"
15- #include " llvm/ADT/Sequence.h"
1615#include " llvm/ADT/StringExtras.h"
1716#include " llvm/MC/MCAsmInfo.h"
1817#include " llvm/MC/MCContext.h"
@@ -34,25 +33,29 @@ using namespace llvm;
3433typedef std::pair<std::vector<unsigned char >, std::vector<const char *>>
3534 ByteArrayTy;
3635
36+ static MCDisassembler::DecodeStatus getInstruction (const MCDisassembler &DisAsm,
37+ const MCSubtargetInfo &STI,
38+ MCInst &Inst, uint64_t &Size,
39+ ArrayRef<uint8_t > Bytes,
40+ uint64_t Address) {
41+ if (STI.getTargetTriple ().getArch () == Triple::hexagon)
42+ return DisAsm.getInstructionBundle (Inst, Size, Bytes, Address, nulls ());
43+ return DisAsm.getInstruction (Inst, Size, Bytes, Address, nulls ());
44+ }
45+
3746static bool printInsts (const MCDisassembler &DisAsm, const ByteArrayTy &Bytes,
3847 SourceMgr &SM, MCStreamer &Streamer, bool InAtomicBlock,
39- const MCSubtargetInfo &STI, unsigned BenchmarkNumRuns ) {
48+ const MCSubtargetInfo &STI, unsigned NumBenchmarkRuns ) {
4049 ArrayRef<uint8_t > Data (Bytes.first );
4150
4251 // Disassemble it to strings.
4352 uint64_t Size;
4453
4554 for (uint64_t Index = 0 ; Index < Bytes.first .size (); Index += Size) {
46- auto getInstruction = [&](MCInst &Inst) -> MCDisassembler::DecodeStatus {
47- if (STI.getTargetTriple ().getArch () == Triple::hexagon)
48- return DisAsm.getInstructionBundle (Inst, Size, Data.slice (Index), Index,
49- nulls ());
50- return DisAsm.getInstruction (Inst, Size, Data.slice (Index), Index,
51- nulls ());
52- };
5355
5456 MCInst Inst;
55- MCDisassembler::DecodeStatus S = getInstruction (Inst);
57+ MCDisassembler::DecodeStatus S =
58+ getInstruction (DisAsm, STI, Inst, Size, Data.slice (Index), Index);
5659 switch (S) {
5760 case MCDisassembler::Fail:
5861 SM.PrintMessage (SMLoc::getFromPointer (Bytes.second [Index]),
@@ -78,23 +81,23 @@ static bool printInsts(const MCDisassembler &DisAsm, const ByteArrayTy &Bytes,
7881 break ;
7982 }
8083
81- if (S == MCDisassembler::Success && BenchmarkNumRuns != 0 ) {
84+ if (S == MCDisassembler::Success && NumBenchmarkRuns != 0 ) {
8285 // Benchmark mode, collect timing for decoding the instruction several
8386 // times.
8487 MCInst BMInst;
8588 TimeTraceScope timeScope (" getInstruction" );
86- for (unsigned _ : llvm::seq< unsigned >(BenchmarkNumRuns) ) {
89+ for (unsigned I = 0 ; I < NumBenchmarkRuns; ++I ) {
8790 BMInst.clear ();
8891 BMInst.setOpcode (0 );
89- S = getInstruction (BMInst);
92+ S = getInstruction (DisAsm, STI, BMInst, Size, Data. slice (Index), Index );
9093 }
9194 }
9295 }
9396
9497 return false ;
9598}
9699
97- static bool skipToToken (StringRef &Str) {
100+ static bool SkipToToken (StringRef &Str) {
98101 for (;;) {
99102 if (Str.empty ())
100103 return false ;
@@ -116,7 +119,7 @@ static bool skipToToken(StringRef &Str) {
116119
117120static bool byteArrayFromString (ByteArrayTy &ByteArray, StringRef &Str,
118121 SourceMgr &SM, bool HexBytes) {
119- while (skipToToken (Str)) {
122+ while (SkipToToken (Str)) {
120123 // Handled by higher level
121124 if (Str[0 ] == ' [' || Str[0 ] == ' ]' )
122125 return false ;
@@ -166,7 +169,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
166169 MCSubtargetInfo &STI, MCStreamer &Streamer,
167170 MemoryBuffer &Buffer, SourceMgr &SM,
168171 MCContext &Ctx, const MCTargetOptions &MCOptions,
169- bool HexBytes, unsigned BenchmarkNumRuns ) {
172+ bool HexBytes, unsigned NumBenchmarkRuns ) {
170173 std::unique_ptr<const MCRegisterInfo> MRI (T.createMCRegInfo (Triple));
171174 if (!MRI) {
172175 errs () << " error: no register info for target " << Triple << " \n " ;
@@ -194,7 +197,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
194197 StringRef Str = Buffer.getBuffer ();
195198 bool InAtomicBlock = false ;
196199
197- while (skipToToken (Str)) {
200+ while (SkipToToken (Str)) {
198201 ByteArray.first .clear ();
199202 ByteArray.second .clear ();
200203
@@ -223,7 +226,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
223226
224227 if (!ByteArray.first .empty ())
225228 ErrorOccurred |= printInsts (*DisAsm, ByteArray, SM, Streamer,
226- InAtomicBlock, STI, BenchmarkNumRuns );
229+ InAtomicBlock, STI, NumBenchmarkRuns );
227230 }
228231
229232 if (InAtomicBlock) {
0 commit comments