[llvm-commits] [llvm] r91892 - /llvm/trunk/tools/llvm-mc/HexDisassembler.cpp
Chris Lattner
sabre at nondot.org
Mon Dec 21 22:24:00 PST 2009
Author: lattner
Date: Tue Dec 22 00:24:00 2009
New Revision: 91892
URL: http://llvm.org/viewvc/llvm-project?rev=91892&view=rev
Log:
don't crash on blank lines, rename some variables.
Modified:
llvm/trunk/tools/llvm-mc/HexDisassembler.cpp
Modified: llvm/trunk/tools/llvm-mc/HexDisassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/HexDisassembler.cpp?rev=91892&r1=91891&r2=91892&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/HexDisassembler.cpp (original)
+++ llvm/trunk/tools/llvm-mc/HexDisassembler.cpp Tue Dec 22 00:24:00 2009
@@ -84,75 +84,68 @@
}
}
-int HexDisassembler::disassemble(const Target &target,
- const std::string &tripleString,
- MemoryBuffer &buffer) {
- // Set up disassembler
+int HexDisassembler::disassemble(const Target &T, const std::string &Triple,
+ MemoryBuffer &Buffer) {
+ // Set up disassembler.
+ llvm::OwningPtr<const llvm::MCAsmInfo> AsmInfo(T.createAsmInfo(Triple));
- llvm::OwningPtr<const llvm::MCAsmInfo> asmInfo
- (target.createAsmInfo(tripleString));
-
- if (!asmInfo) {
- errs() << "error: no assembly info for target " << tripleString << "\n";
+ if (!AsmInfo) {
+ errs() << "error: no assembly info for target " << Triple << "\n";
return -1;
}
- llvm::OwningPtr<const llvm::MCDisassembler> disassembler
- (target.createMCDisassembler());
-
- if (!disassembler) {
- errs() << "error: no disassembler for target " << tripleString << "\n";
+ llvm::OwningPtr<const llvm::MCDisassembler> DisAsm(T.createMCDisassembler());
+ if (!DisAsm) {
+ errs() << "error: no disassembler for target " << Triple << "\n";
return -1;
}
- llvm::MCInstPrinter *instPrinter = target.createMCInstPrinter(0,
- *asmInfo,
- outs());
+ llvm::MCInstPrinter *InstPrinter = T.createMCInstPrinter(0, *AsmInfo, outs());
- if (!instPrinter) {
- errs() << "error: no instruction printer for target " << tripleString
+ if (!InstPrinter) {
+ errs() << "error: no instruction printer for target " << Triple
<< "\n";
return -1;
}
// Convert the input to a vector for disassembly.
+ std::vector<unsigned char> ByteArray;
- std::vector<unsigned char> bytes;
-
- StringRef str = buffer.getBuffer();
+ StringRef Str = Buffer.getBuffer();
- while (!str.empty()) {
- if(str.find_first_of("\n") < str.find_first_not_of(" \t\n\r")) {
- printInst(*disassembler, *instPrinter, bytes);
+ while (!Str.empty()) {
+ if (Str.find_first_of('\n') < Str.find_first_not_of(" \t\n\r")) {
+ if (!ByteArray.empty())
+ printInst(*DisAsm, *InstPrinter, ByteArray);
- bytes.clear();
+ ByteArray.clear();
}
// Skip leading space.
- str = str.substr(str.find_first_not_of(" \t\n\r"));
+ Str = Str.substr(Str.find_first_not_of(" \t\n\r"));
// Get the current token.
- size_t next = str.find_first_of(" \t\n\r");
+ size_t Next = Str.find_first_of(" \t\n\r");
- if(next == (size_t)StringRef::npos)
+ if(Next == (size_t)StringRef::npos)
break;
- StringRef value = str.slice(0, next);
+ StringRef Value = Str.slice(0, Next);
// Convert to a byte and add to the byte vector.
- unsigned byte;
- if (value.getAsInteger(0, byte) || byte > 255) {
- errs() << "warning: invalid input token '" << value << "' of length "
- << next << "\n";
+ unsigned ByteVal;
+ if (Value.getAsInteger(0, ByteVal) || ByteVal > 255) {
+ errs() << "warning: invalid input token '" << Value << "' of length "
+ << Next << "\n";
}
else {
- bytes.push_back((unsigned char)byte);
+ ByteArray.push_back((unsigned char)ByteVal);
}
- str = str.substr(next);
+ Str = Str.substr(Next);
}
- if (!bytes.empty())
- printInst(*disassembler, *instPrinter, bytes);
+ if (!ByteArray.empty())
+ printInst(*DisAsm, *InstPrinter, ByteArray);
return 0;
}
More information about the llvm-commits
mailing list