Make InstructionLLVM::Dump() more robust for edis in cases when all the

EDOperandIndexForToken(token) calls fail to return a meaningful operand index,
resulting in both operands and comment being empty.  We will use the raw disassembly
string as output in these cases.

There is still a known bug where llvm:tB (A8.6.16 B Encoding T2) is not being processed
as a branch instruction and therefore the symbolic information is not being dumped for
non-raw mode.

llvm-svn: 131615
This commit is contained in:
Johnny Chen 2011-05-19 01:05:37 +00:00
parent 5f06955aa0
commit d746478404
1 changed files with 36 additions and 24 deletions

View File

@ -99,6 +99,16 @@ PadString(Stream *s, const std::string &str, size_t width)
s->Printf("%s ", str.c_str());
}
#include "llvm/ADT/StringRef.h"
static void
StripSpaces(llvm::StringRef &Str)
{
while (!Str.empty() && isspace(Str[0]))
Str = Str.substr(1);
while (!Str.empty() && isspace(Str.back()))
Str = Str.substr(0, Str.size()-1);
}
void
InstructionLLVM::Dump
(
@ -230,7 +240,7 @@ InstructionLLVM::Dump
if (printTokenized)
{
bool show_token;
bool show_token = false;
for (; tokenIndex < numTokens; ++tokenIndex)
{
@ -300,40 +310,42 @@ InstructionLLVM::Dump
}
} // for (tokenIndex)
if (printTokenized)
// If both operands and comment are empty, we will just print out
// the raw disassembly.
if (operands.GetString().empty() && comment.GetString().empty())
{
if (operands.GetString().empty())
{
s->PutCString(opcode.GetString().c_str());
}
const char *str;
if (EDGetInstString(&str, m_inst))
return;
llvm::StringRef raw_disasm(str);
StripSpaces(raw_disasm);
s->PutCString(raw_disasm.str().c_str());
}
else
{
PadString(s, opcode.GetString(), opcodeColumnWidth);
if (comment.GetString().empty())
s->PutCString(operands.GetString().c_str());
else
{
PadString(s, opcode.GetString(), opcodeColumnWidth);
PadString(s, operands.GetString(), operandColumnWidth);
if (comment.GetString().empty())
{
s->PutCString(operands.GetString().c_str());
}
else
{
PadString(s, operands.GetString(), operandColumnWidth);
s->PutCString("; ");
s->PutCString(comment.GetString().c_str());
} // else (comment.GetString().empty())
} // else (operands.GetString().empty())
} // printTokenized
} // for (tokenIndex)
s->PutCString("; ");
s->PutCString(comment.GetString().c_str());
} // else (comment.GetString().empty())
} // else (operands.GetString().empty() && comment.GetString().empty())
} // printTokenized
} // numTokens != -1
if (!printTokenized)
{
const char *str;
if (EDGetInstString(&str, m_inst))
if (EDGetInstString(&str, m_inst)) // 0 on success
return;
else
s->Write(str, strlen(str) - 1);
s->Write(str, strlen(str) - 1);
}
}