Hi,<br>It seems that this breaks cmake build, at least for me.<br><br>Artur<br><br><div class="gmail_quote">On Mon, Apr 12, 2010 at 9:43 PM, Sean Callanan <span dir="ltr"><<a href="mailto:scallanan@apple.com">scallanan@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Author: spyffe<br>
Date: Mon Apr 12 14:43:00 2010<br>
New Revision: 101058<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=101058&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=101058&view=rev</a><br>
Log:<br>
Second try at integrating the edis tester. This<br>
time I use the LIBS variable, which is not subject<br>
to a %.a -> -l% transformation, to link llvm-mc<br>
against libEnhancedDisassembly.<br>
<br>
llvm-mc -edis works the same as llvm-mc<br>
-disassemble, but outputs tokens and operands.<br>
<br>
Modified:<br>
llvm/trunk/tools/Makefile<br>
llvm/trunk/tools/llvm-mc/Disassembler.cpp<br>
llvm/trunk/tools/llvm-mc/Disassembler.h<br>
llvm/trunk/tools/llvm-mc/Makefile<br>
llvm/trunk/tools/llvm-mc/llvm-mc.cpp<br>
<br>
Modified: llvm/trunk/tools/Makefile<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/Makefile?rev=101058&r1=101057&r2=101058&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/Makefile?rev=101058&r1=101057&r2=101058&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/Makefile (original)<br>
+++ llvm/trunk/tools/Makefile Mon Apr 12 14:43:00 2010<br>
@@ -36,6 +36,8 @@<br>
ifeq ($(ENABLE_PIC),1)<br>
# No support for dynamic libraries on windows targets.<br>
ifneq ($(TARGET_OS), $(filter $(TARGET_OS), Cygwin MingW))<br>
+ # libEnhancedDisassembly must be built ahead of llvm-mc<br>
+ # because llvm-mc links against libEnhancedDisassembly<br>
DIRS += edis<br>
<br>
# gold only builds if binutils is around. It requires "lto" to build before<br>
<br>
Modified: llvm/trunk/tools/llvm-mc/Disassembler.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/Disassembler.cpp?rev=101058&r1=101057&r2=101058&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/Disassembler.cpp?rev=101058&r1=101057&r2=101058&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-mc/Disassembler.cpp (original)<br>
+++ llvm/trunk/tools/llvm-mc/Disassembler.cpp Mon Apr 12 14:43:00 2010<br>
@@ -15,6 +15,7 @@<br>
#include "Disassembler.h"<br>
<br>
#include "llvm/ADT/OwningPtr.h"<br>
+#include "llvm/ADT/Triple.h"<br>
#include "llvm/MC/MCAsmInfo.h"<br>
#include "llvm/MC/MCDisassembler.h"<br>
#include "llvm/MC/MCInst.h"<br>
@@ -24,6 +25,9 @@<br>
#include "llvm/Support/MemoryObject.h"<br>
#include "llvm/Support/raw_ostream.h"<br>
#include "llvm/Support/SourceMgr.h"<br>
+<br>
+#include "llvm-c/EnhancedDisassembly.h"<br>
+<br>
using namespace llvm;<br>
<br>
typedef std::vector<std::pair<unsigned char, const char*> > ByteArrayTy;<br>
@@ -64,8 +68,7 @@<br>
/*REMOVE*/ nulls())) {<br>
Printer.printInst(&Inst, outs());<br>
outs() << "\n";<br>
- }<br>
- else {<br>
+ } else {<br>
SM.PrintMessage(SMLoc::getFromPointer(Bytes[Index].second),<br>
"invalid instruction encoding", "warning");<br>
if (Size == 0)<br>
@@ -76,37 +79,9 @@<br>
return false;<br>
}<br>
<br>
-int Disassembler::disassemble(const Target &T, const std::string &Triple,<br>
- MemoryBuffer &Buffer) {<br>
- // Set up disassembler.<br>
- OwningPtr<const MCAsmInfo> AsmInfo(T.createAsmInfo(Triple));<br>
-<br>
- if (!AsmInfo) {<br>
- errs() << "error: no assembly info for target " << Triple << "\n";<br>
- return -1;<br>
- }<br>
-<br>
- OwningPtr<const MCDisassembler> DisAsm(T.createMCDisassembler());<br>
- if (!DisAsm) {<br>
- errs() << "error: no disassembler for target " << Triple << "\n";<br>
- return -1;<br>
- }<br>
-<br>
- OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(0, *AsmInfo));<br>
- if (!IP) {<br>
- errs() << "error: no instruction printer for target " << Triple << '\n';<br>
- return -1;<br>
- }<br>
-<br>
- bool ErrorOccurred = false;<br>
-<br>
- SourceMgr SM;<br>
- SM.AddNewSourceBuffer(&Buffer, SMLoc());<br>
-<br>
- // Convert the input to a vector for disassembly.<br>
- ByteArrayTy ByteArray;<br>
-<br>
- StringRef Str = Buffer.getBuffer();<br>
+static bool ByteArrayFromString(ByteArrayTy &ByteArray,<br>
+ StringRef &Str,<br>
+ SourceMgr &SM) {<br>
while (!Str.empty()) {<br>
// Strip horizontal whitespace.<br>
if (size_t Pos = Str.find_first_not_of(" \t\r")) {<br>
@@ -119,9 +94,9 @@<br>
if (Str[0] == '\n' || Str[0] == '#') {<br>
// Strip to the end of line if we already processed any bytes on this<br>
// line. This strips the comment and/or the \n.<br>
- if (Str[0] == '\n')<br>
+ if (Str[0] == '\n') {<br>
Str = Str.substr(1);<br>
- else {<br>
+ } else {<br>
Str = Str.substr(Str.find_first_of('\n'));<br>
if (!Str.empty())<br>
Str = Str.substr(1);<br>
@@ -138,8 +113,7 @@<br>
if (Value.getAsInteger(0, ByteVal) || ByteVal > 255) {<br>
// If we have an error, print it and skip to the end of line.<br>
SM.PrintMessage(SMLoc::getFromPointer(Value.data()),<br>
- "invalid input token", "error");<br>
- ErrorOccurred = true;<br>
+ "invalid input token", "error");<br>
Str = Str.substr(Str.find('\n'));<br>
ByteArray.clear();<br>
continue;<br>
@@ -149,8 +123,229 @@<br>
Str = Str.substr(Next);<br>
}<br>
<br>
+ return false;<br>
+}<br>
+<br>
+int Disassembler::disassemble(const Target &T, const std::string &Triple,<br>
+ MemoryBuffer &Buffer) {<br>
+ // Set up disassembler.<br>
+ OwningPtr<const MCAsmInfo> AsmInfo(T.createAsmInfo(Triple));<br>
+<br>
+ if (!AsmInfo) {<br>
+ errs() << "error: no assembly info for target " << Triple << "\n";<br>
+ return -1;<br>
+ }<br>
+<br>
+ OwningPtr<const MCDisassembler> DisAsm(T.createMCDisassembler());<br>
+ if (!DisAsm) {<br>
+ errs() << "error: no disassembler for target " << Triple << "\n";<br>
+ return -1;<br>
+ }<br>
+<br>
+ OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(0, *AsmInfo));<br>
+ if (!IP) {<br>
+ errs() << "error: no instruction printer for target " << Triple << '\n';<br>
+ return -1;<br>
+ }<br>
+<br>
+ bool ErrorOccurred = false;<br>
+<br>
+ SourceMgr SM;<br>
+ SM.AddNewSourceBuffer(&Buffer, SMLoc());<br>
+<br>
+ // Convert the input to a vector for disassembly.<br>
+ ByteArrayTy ByteArray;<br>
+ StringRef Str = Buffer.getBuffer();<br>
+<br>
+ ErrorOccurred |= ByteArrayFromString(ByteArray, Str, SM);<br>
+<br>
if (!ByteArray.empty())<br>
ErrorOccurred |= PrintInsts(*DisAsm, *IP, ByteArray, SM);<br>
<br>
return ErrorOccurred;<br>
}<br>
+<br>
+static int byteArrayReader(uint8_t *B, uint64_t A, void *Arg) {<br>
+ ByteArrayTy &ByteArray = *((ByteArrayTy*)Arg);<br>
+<br>
+ if (A >= ByteArray.size())<br>
+ return -1;<br>
+<br>
+ *B = ByteArray[A].first;<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+static int verboseEvaluator(uint64_t *V, unsigned R, void *Arg) {<br>
+ EDDisassemblerRef &disassembler = *((EDDisassemblerRef*)Arg);<br>
+<br>
+ const char *regName;<br>
+<br>
+ if (!EDGetRegisterName(®Name,<br>
+ disassembler,<br>
+ R))<br>
+ outs() << "[" << regName << "/" << R << "]";<br>
+ if (EDRegisterIsStackPointer(disassembler, R))<br>
+ outs() << "(sp)";<br>
+ if (EDRegisterIsProgramCounter(disassembler, R))<br>
+ outs() << "(pc)";<br>
+<br>
+ *V = 0;<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+int Disassembler::disassembleEnhanced(const std::string &TS,<br>
+ MemoryBuffer &Buffer) {<br>
+ ByteArrayTy ByteArray;<br>
+ StringRef Str = Buffer.getBuffer();<br>
+ SourceMgr SM;<br>
+<br>
+ SM.AddNewSourceBuffer(&Buffer, SMLoc());<br>
+<br>
+ if (ByteArrayFromString(ByteArray, Str, SM)) {<br>
+ return -1;<br>
+ }<br>
+<br>
+ EDDisassemblerRef disassembler;<br>
+<br>
+ Triple T(TS);<br>
+ EDAssemblySyntax_t AS;<br>
+<br>
+ switch (T.getArch()) {<br>
+ default:<br>
+ errs() << "error: no default assembly syntax for " << TS.c_str() << "\n";<br>
+ return -1;<br>
+ case Triple::arm:<br>
+ case Triple::thumb:<br>
+ AS = kEDAssemblySyntaxARMUAL;<br>
+ break;<br>
+ case Triple::x86:<br>
+ case Triple::x86_64:<br>
+ AS = kEDAssemblySyntaxX86ATT;<br>
+ break;<br>
+ }<br>
+<br>
+ if (EDGetDisassembler(&disassembler,<br>
+ TS.c_str(),<br>
+ AS)) {<br>
+ errs() << "error: couldn't get disassembler for " << TS.c_str() << "\n";<br>
+ return -1;<br>
+ }<br>
+<br>
+ EDInstRef inst;<br>
+<br>
+ if (EDCreateInsts(&inst, 1, disassembler, byteArrayReader, 0,&ByteArray)<br>
+ != 1) {<br>
+ errs() << "error: Didn't get an instruction\n";<br>
+ return -1;<br>
+ }<br>
+<br>
+ int numTokens = EDNumTokens(inst);<br>
+<br>
+ if (numTokens < 0) {<br>
+ errs() << "error: Couldn't count the instruction's tokens\n";<br>
+ return -1;<br>
+ }<br>
+<br>
+ int tokenIndex;<br>
+<br>
+ for (tokenIndex = 0; tokenIndex < numTokens; ++tokenIndex) {<br>
+ EDTokenRef token;<br>
+<br>
+ if (EDGetToken(&token, inst, tokenIndex)) {<br>
+ errs() << "error: Couldn't get token\n";<br>
+ return -1;<br>
+ }<br>
+<br>
+ const char *buf;<br>
+<br>
+ if (EDGetTokenString(&buf, token)) {<br>
+ errs() << "error: Couldn't get string for token\n";<br>
+ return -1;<br>
+ }<br>
+<br>
+ outs() << "[";<br>
+<br>
+ int operandIndex = EDOperandIndexForToken(token);<br>
+<br>
+ if (operandIndex >= 0)<br>
+ outs() << operandIndex << "-";<br>
+<br>
+ if (EDTokenIsWhitespace(token)) {<br>
+ outs() << "w";<br>
+ } else if (EDTokenIsPunctuation(token)) {<br>
+ outs() << "p";<br>
+ } else if (EDTokenIsOpcode(token)) {<br>
+ outs() << "o";<br>
+ } else if (EDTokenIsLiteral(token)) {<br>
+ outs() << "l";<br>
+ } else if (EDTokenIsRegister(token)) {<br>
+ outs() << "r";<br>
+ } else {<br>
+ outs() << "?";<br>
+ }<br>
+<br>
+ outs() << ":" << buf;<br>
+<br>
+ if (EDTokenIsLiteral(token)) {<br>
+ outs() << "=";<br>
+ if (EDTokenIsNegativeLiteral(token))<br>
+ outs() << "-";<br>
+ uint64_t absoluteValue;<br>
+ if (EDLiteralTokenAbsoluteValue(&absoluteValue, token)) {<br>
+ errs() << "error: Couldn't get the value of a literal token\n";<br>
+ return -1;<br>
+ }<br>
+ outs() << absoluteValue;<br>
+ } else if (EDTokenIsRegister(token)) {<br>
+ outs() << "=";<br>
+ unsigned regID;<br>
+ if (EDRegisterTokenValue(®ID, token)) {<br>
+ errs() << "error: Couldn't get the ID of a register token\n";<br>
+ return -1;<br>
+ }<br>
+ outs() << "r" << regID;<br>
+ }<br>
+<br>
+ outs() << "]";<br>
+ }<br>
+<br>
+ outs() << " ";<br>
+<br>
+ int numOperands = EDNumOperands(inst);<br>
+<br>
+ if (numOperands < 0) {<br>
+ errs() << "error: Couldn't count operands\n";<br>
+ return -1;<br>
+ }<br>
+<br>
+ int operandIndex;<br>
+<br>
+ for (operandIndex = 0; operandIndex < numOperands; ++operandIndex) {<br>
+ outs() << operandIndex << ":";<br>
+<br>
+ EDOperandRef operand;<br>
+<br>
+ if (EDGetOperand(&operand,<br>
+ inst,<br>
+ operandIndex)) {<br>
+ errs() << "error: Couldn't get operand\n";<br>
+ return -1;<br>
+ }<br>
+<br>
+ uint64_t evaluatedResult;<br>
+<br>
+ EDEvaluateOperand(&evaluatedResult,<br>
+ operand,<br>
+ verboseEvaluator,<br>
+ &disassembler);<br>
+<br>
+ outs() << " ";<br>
+ }<br>
+<br>
+ outs() << "\n";<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
<br>
Modified: llvm/trunk/tools/llvm-mc/Disassembler.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/Disassembler.h?rev=101058&r1=101057&r2=101058&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/Disassembler.h?rev=101058&r1=101057&r2=101058&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-mc/Disassembler.h (original)<br>
+++ llvm/trunk/tools/llvm-mc/Disassembler.h Mon Apr 12 14:43:00 2010<br>
@@ -27,6 +27,9 @@<br>
static int disassemble(const Target &target,<br>
const std::string &tripleString,<br>
MemoryBuffer &buffer);<br>
+<br>
+ static int disassembleEnhanced(const std::string &tripleString,<br>
+ MemoryBuffer &buffer);<br>
};<br>
<br>
} // namespace llvm<br>
<br>
Modified: llvm/trunk/tools/llvm-mc/Makefile<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/Makefile?rev=101058&r1=101057&r2=101058&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/Makefile?rev=101058&r1=101057&r2=101058&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-mc/Makefile (original)<br>
+++ llvm/trunk/tools/llvm-mc/Makefile Mon Apr 12 14:43:00 2010<br>
@@ -22,3 +22,6 @@<br>
LINK_COMPONENTS := $(TARGETS_TO_BUILD) MCParser MC support<br>
<br>
include $(LLVM_SRC_ROOT)/Makefile.rules<br>
+<br>
+# Using LIBS instead of USEDLIBS to force static linking<br>
+LIBS += $(LLVMLibDir)/libEnhancedDisassembly.a<br>
<br>
Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=101058&r1=101057&r2=101058&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=101058&r1=101057&r2=101058&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)<br>
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Mon Apr 12 14:43:00 2010<br>
@@ -97,7 +97,8 @@<br>
enum ActionType {<br>
AC_AsLex,<br>
AC_Assemble,<br>
- AC_Disassemble<br>
+ AC_Disassemble,<br>
+ AC_EDisassemble<br>
};<br>
<br>
static cl::opt<ActionType><br>
@@ -109,6 +110,8 @@<br>
"Assemble a .s file (default)"),<br>
clEnumValN(AC_Disassemble, "disassemble",<br>
"Disassemble strings of hex bytes"),<br>
+ clEnumValN(AC_EDisassemble, "edis",<br>
+ "Enhanced disassembly of strings of hex bytes"),<br>
clEnumValEnd));<br>
<br>
static const Target *GetTarget(const char *ProgName) {<br>
@@ -325,7 +328,7 @@<br>
return Res;<br>
}<br>
<br>
-static int DisassembleInput(const char *ProgName) {<br>
+static int DisassembleInput(const char *ProgName, bool Enhanced) {<br>
const Target *TheTarget = GetTarget(ProgName);<br>
if (!TheTarget)<br>
return 0;<br>
@@ -344,7 +347,10 @@<br>
return 1;<br>
}<br>
<br>
- return Disassembler::disassemble(*TheTarget, TripleName, *Buffer);<br>
+ if (Enhanced)<br>
+ return Disassembler::disassembleEnhanced(TripleName, *Buffer);<br>
+ else<br>
+ return Disassembler::disassemble(*TheTarget, TripleName, *Buffer);<br>
}<br>
<br>
<br>
@@ -371,7 +377,9 @@<br>
case AC_Assemble:<br>
return AssembleInput(argv[0]);<br>
case AC_Disassemble:<br>
- return DisassembleInput(argv[0]);<br>
+ return DisassembleInput(argv[0], false);<br>
+ case AC_EDisassemble:<br>
+ return DisassembleInput(argv[0], true);<br>
}<br>
<br>
return 0;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br>