diff options
-rw-r--r-- | src/3rdparty/masm/config.h | 15 | ||||
-rw-r--r-- | src/3rdparty/masm/disassembler/udis86/udis86_decode.c | 2 | ||||
-rw-r--r-- | src/3rdparty/masm/disassembler/udis86/udis86_types.h | 2 | ||||
-rw-r--r-- | src/3rdparty/masm/masm-defs.pri | 2 | ||||
-rw-r--r-- | src/3rdparty/masm/stubs/WTFStubs.cpp | 10 | ||||
-rw-r--r-- | src/3rdparty/masm/stubs/WTFStubs.h | 1 | ||||
-rw-r--r-- | src/3rdparty/masm/wtf/DataLog.h | 2 | ||||
-rw-r--r-- | src/qml/jit/qv4isel_masm.cpp | 74 |
8 files changed, 66 insertions, 42 deletions
diff --git a/src/3rdparty/masm/config.h b/src/3rdparty/masm/config.h index 80d4d4d8db..18bb9ed61a 100644 --- a/src/3rdparty/masm/config.h +++ b/src/3rdparty/masm/config.h @@ -48,9 +48,20 @@ #include <wtf/FastAllocBase.h> #include <wtf/RefPtr.h> #include <cmath> -#else + +#ifdef _MSC_VER +#define snprintf _snprintf +#endif // _MSC_VER +#else // !__cplusplus + #include <math.h> -#endif + +#ifdef _MSC_VER +#define inline +#include <stdio.h> +#endif // _MSC_VER + +#endif // __cplusplus #include <limits.h> #endif // MASM_CONFIG_H diff --git a/src/3rdparty/masm/disassembler/udis86/udis86_decode.c b/src/3rdparty/masm/disassembler/udis86/udis86_decode.c index 3d567b6df2..2ebd56b2a9 100644 --- a/src/3rdparty/masm/disassembler/udis86/udis86_decode.c +++ b/src/3rdparty/masm/disassembler/udis86/udis86_decode.c @@ -34,8 +34,10 @@ #include "udis86_decode.h" #include <wtf/Assertions.h> +#ifndef _MSC_VER #define dbg(x, n...) /* #define dbg printf */ +#endif // _MSC_VER #ifndef __UD_STANDALONE__ # include <string.h> diff --git a/src/3rdparty/masm/disassembler/udis86/udis86_types.h b/src/3rdparty/masm/disassembler/udis86/udis86_types.h index 320d1ca491..520a24c541 100644 --- a/src/3rdparty/masm/disassembler/udis86/udis86_types.h +++ b/src/3rdparty/masm/disassembler/udis86/udis86_types.h @@ -43,10 +43,12 @@ typedef unsigned __int16 uint16_t; typedef unsigned __int32 uint32_t; typedef unsigned __int64 uint64_t; +# ifndef _STDINT typedef __int8 int8_t; typedef __int16 int16_t; typedef __int32 int32_t; typedef __int64 int64_t; +# endif #else # define FMT64 "%ll" # ifndef __UD_STANDALONE__ diff --git a/src/3rdparty/masm/masm-defs.pri b/src/3rdparty/masm/masm-defs.pri index 66506dccf5..d0980c5312 100644 --- a/src/3rdparty/masm/masm-defs.pri +++ b/src/3rdparty/masm/masm-defs.pri @@ -24,7 +24,7 @@ INCLUDEPATH += $$PWD/stubs/wtf INCLUDEPATH += $$PWD disassembler { - if(isEqual(QT_ARCH, "i386")|isEqual(QT_ARCH, "x86_64")):!win*: DEFINES += WTF_USE_UDIS86=1 + if(isEqual(QT_ARCH, "i386")|isEqual(QT_ARCH, "x86_64")): DEFINES += WTF_USE_UDIS86=1 if(isEqual(QT_ARCH, "arm")): DEFINES += WTF_USE_ARMV7_DISASSEMBLER=1 } else { DEFINES += WTF_USE_UDIS86=0 diff --git a/src/3rdparty/masm/stubs/WTFStubs.cpp b/src/3rdparty/masm/stubs/WTFStubs.cpp index dff692fd67..d1c684dbaf 100644 --- a/src/3rdparty/masm/stubs/WTFStubs.cpp +++ b/src/3rdparty/masm/stubs/WTFStubs.cpp @@ -68,7 +68,13 @@ uint32_t cryptographicallyRandomNumber() return 0; } -static FilePrintStream* s_dataFile; +static PrintStream* s_dataFile; + +void setDataFile(PrintStream *ps) +{ + delete s_dataFile; + s_dataFile = ps; +} void setDataFile(FILE* f) { @@ -76,7 +82,7 @@ void setDataFile(FILE* f) s_dataFile = new FilePrintStream(f, FilePrintStream::Borrow); } -FilePrintStream& dataFile() +PrintStream& dataFile() { if (!s_dataFile) s_dataFile = new FilePrintStream(stderr, FilePrintStream::Borrow); diff --git a/src/3rdparty/masm/stubs/WTFStubs.h b/src/3rdparty/masm/stubs/WTFStubs.h index e6a7291acf..c36089bce9 100644 --- a/src/3rdparty/masm/stubs/WTFStubs.h +++ b/src/3rdparty/masm/stubs/WTFStubs.h @@ -44,6 +44,7 @@ namespace WTF { void setDataFile(FILE* f); +void setDataFile(class PrintStream *); } diff --git a/src/3rdparty/masm/wtf/DataLog.h b/src/3rdparty/masm/wtf/DataLog.h index 0bd8efe727..2b3df09970 100644 --- a/src/3rdparty/masm/wtf/DataLog.h +++ b/src/3rdparty/masm/wtf/DataLog.h @@ -34,7 +34,7 @@ namespace WTF { -WTF_EXPORT_PRIVATE FilePrintStream& dataFile(); +WTF_EXPORT_PRIVATE PrintStream &dataFile(); WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0); WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2); diff --git a/src/qml/jit/qv4isel_masm.cpp b/src/qml/jit/qv4isel_masm.cpp index 80f22551cd..332c244a6c 100644 --- a/src/qml/jit/qv4isel_masm.cpp +++ b/src/qml/jit/qv4isel_masm.cpp @@ -52,6 +52,8 @@ #include "qv4unop_p.h" #include "qv4binop_p.h" +#include <QtCore/QBuffer> + #include <assembler/LinkBuffer.h> #include <WTFStubs.h> @@ -75,12 +77,41 @@ inline bool isPregOrConst(IR::Expr *e) return t->kind == IR::Temp::PhysicalRegister; return e->asConst() != 0; } + +class QIODevicePrintStream: public PrintStream +{ + Q_DISABLE_COPY(QIODevicePrintStream) + +public: + explicit QIODevicePrintStream(QIODevice *dest) + : dest(dest) + , buf(4096, '0') + { + Q_ASSERT(dest); + } + + ~QIODevicePrintStream() + {} + + void vprintf(const char* format, va_list argList) WTF_ATTRIBUTE_PRINTF(2, 0) + { + const int written = vsnprintf(buf.data(), buf.size(), format, argList); + if (written > 0) + dest->write(buf.constData(), written); + memset(buf.data(), 0, qMin(written, buf.size())); + } + + void flush() + {} + +private: + QIODevice *dest; + QByteArray buf; +}; } // anonymous namespace -#if OS(LINUX) || OS(MAC_OS_X) -static void printDisassembledOutputWithCalls(const char* output, const QHash<void*, const char*>& functions) +static void printDisassembledOutputWithCalls(QByteArray processedOutput, const QHash<void*, const char*>& functions) { - QByteArray processedOutput(output); for (QHash<void*, const char*>::ConstIterator it = functions.begin(), end = functions.end(); it != end; ++it) { QByteArray ptrString = QByteArray::number(quintptr(it.key()), 16); @@ -89,7 +120,6 @@ static void printDisassembledOutputWithCalls(const char* output, const QHash<voi } fprintf(stderr, "%s\n", processedOutput.constData()); } -#endif JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize) { @@ -142,25 +172,9 @@ JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize) static bool showCode = !qgetenv("QV4_SHOW_ASM").isNull(); if (showCode) { -#if OS(LINUX) && !defined(Q_OS_ANDROID) - char* disasmOutput = 0; - size_t disasmLength = 0; - FILE* disasmStream = open_memstream(&disasmOutput, &disasmLength); - WTF::setDataFile(disasmStream); -#elif OS(MAC_OS_X) - struct MemStream { - QByteArray buf; - static int write(void *cookie, const char *buf, int len) { - MemStream *stream = reinterpret_cast<MemStream *>(cookie); - stream->buf.append(buf, len); - return len; - } - }; - MemStream memStream; - - FILE* disasmStream = fwopen(&memStream, MemStream::write); - WTF::setDataFile(disasmStream); -#endif + QBuffer buf; + buf.open(QIODevice::WriteOnly); + WTF::setDataFile(new QIODevicePrintStream(&buf)); QByteArray name = _function->name->toUtf8(); if (name.isEmpty()) { @@ -171,19 +185,7 @@ JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize) codeRef = linkBuffer.finalizeCodeWithDisassembly("%s", name.data()); WTF::setDataFile(stderr); -#if (OS(LINUX) && !defined(Q_OS_ANDROID)) || OS(MAC_OS_X) - fclose(disasmStream); -# if OS(MAC_OS_X) - char *disasmOutput = memStream.buf.data(); -# endif -# if CPU(X86) || CPU(X86_64) || CPU(ARM) - QHash<void*, String*> idents; - printDisassembledOutputWithCalls(disasmOutput, functions); -# endif -# if OS(LINUX) - free(disasmOutput); -# endif -#endif + printDisassembledOutputWithCalls(buf.data(), functions); } else { codeRef = linkBuffer.finalizeCodeWithoutDisassembly(); } |