AssemblerBuffer-x86-shared.cpp (1840B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "jit/x86-shared/AssemblerBuffer-x86-shared.h" 8 9 #include "mozilla/Sprintf.h" 10 11 using namespace js; 12 using namespace jit; 13 14 bool x86_shared::AssemblerBuffer::swap( 15 Vector<uint8_t, 0, SystemAllocPolicy>& bytes) { 16 // For now, specialize to the one use case. 17 MOZ_ASSERT(bytes.empty()); 18 19 if (m_buffer.empty()) { 20 if (bytes.capacity() > m_buffer.capacity()) { 21 size_t newCapacity = bytes.capacity(); 22 uint8_t* newBuffer = bytes.extractRawBuffer(); 23 MOZ_ASSERT(newBuffer); 24 m_buffer.replaceRawBuffer((unsigned char*)newBuffer, 0, newCapacity); 25 } 26 return true; 27 } 28 29 size_t newLength = m_buffer.length(); 30 size_t newCapacity = m_buffer.capacity(); 31 unsigned char* newBuffer = m_buffer.extractRawBuffer(); 32 33 // NB: extractRawBuffer() only returns null if the Vector is using 34 // inline storage and thus a malloc would be needed. In this case, 35 // just make a simple copy. 36 if (!newBuffer) { 37 return bytes.append(m_buffer.begin(), m_buffer.end()); 38 } 39 40 bytes.replaceRawBuffer((uint8_t*)newBuffer, newLength, newCapacity); 41 return true; 42 } 43 44 #ifdef JS_JITSPEW 45 void js::jit::GenericAssembler::spew(const char* fmt, va_list va) { 46 // Buffer to hold the formatted string. Note that this may contain 47 // '%' characters, so do not pass it directly to printf functions. 48 char buf[200]; 49 50 int i = VsprintfLiteral(buf, fmt, va); 51 if (i > -1) { 52 if (printer) { 53 printer->printf("%s\n", buf); 54 } 55 js::jit::JitSpew(js::jit::JitSpew_Codegen, "%s", buf); 56 } 57 } 58 #endif