| 1 | /* |
| 2 | * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #ifndef AssemblerBuffer_h |
| 27 | #define AssemblerBuffer_hcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/assembler/AssemblerBuffer.h:27:9`! |
| 28 | |
| 29 | #include <wtf/Platform.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h`/ |
| 30 | |
| 31 | #if ENABLEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:57:9`!(ASSEMBLER) |
| 32 | |
| 33 | #include "stdint.h" |
| 34 | #include <string.h> |
| 35 | #include <jit/ExecutableAllocator.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/jit/ExecutableAllocator.h`/ |
| 36 | #include <wtf/Assertions.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h`/ |
| 37 | #include <wtf/FastMalloc.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/FastMalloc.h`/ |
| 38 | |
| 39 | namespace JSCcxx . . $ `<built-in>:463:9`! { |
| 40 | |
| 41 | class AssemblerBuffercxx . . $ QTJSC/AssemblerBuffer# { |
| 42 | static const int inlineCapacitycxx . . $ QTJSC/AssemblerBuffer#inlineCapacity. = 256; |
| 43 | public: |
| 44 | AssemblerBuffercxx . . $ QTJSC/AssemblerBuffer#AssemblerBuffer(49f6e7a06ebc5aa8).() |
| 45 | : m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer.(m_inlineBuffercxx . . $ QTJSC/AssemblerBuffer#m_inlineBuffer.) |
| 46 | , m_capacitycxx . . $ QTJSC/AssemblerBuffer#m_capacity.(inlineCapacitycxx . . $ QTJSC/AssemblerBuffer#inlineCapacity.) |
| 47 | , m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.(0) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | ~cxx . . $ QTJSC/AssemblerBuffer#`~AssemblerBuffer`(49f6e7a06ebc5aa8).AssemblerBuffercxx . . $ QTJSC/AssemblerBuffer#() |
| 52 | { |
| 53 | if (m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer. != m_inlineBuffercxx . . $ QTJSC/AssemblerBuffer#m_inlineBuffer.) |
| 54 | fastFreecxx . . $ fastFree(5d22bdacc48458e8).(m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer.); |
| 55 | } |
| 56 | |
| 57 | void ensureSpacecxx . . $ QTJSC/AssemblerBuffer#ensureSpace(d4f767463ce0a6b3).(int space) |
| 58 | { |
| 59 | if (m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size. > m_capacitycxx . . $ QTJSC/AssemblerBuffer#m_capacity. - space) |
| 60 | growcxx . . $ QTJSC/AssemblerBuffer#grow(d4f767463ce0a6b3).(); |
| 61 | } |
| 62 | |
| 63 | bool isAlignedcxx . . $ QTJSC/AssemblerBuffer#isAligned(4a668f6de69bf818).(int alignment) const |
| 64 | { |
| 65 | return !(m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size. & (alignment - 1)); |
| 66 | } |
| 67 | |
| 68 | void putByteUncheckedcxx . . $ QTJSC/AssemblerBuffer#putByteUnchecked(d4f767463ce0a6b3).(int value) |
| 69 | { |
| 70 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!(m_size > m_capacity - 4)); |
| 71 | m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer.[m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.] = value; |
| 72 | m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.++; |
| 73 | } |
| 74 | |
| 75 | void putBytecxx . . $ QTJSC/AssemblerBuffer#putByte(d4f767463ce0a6b3).(int value) |
| 76 | { |
| 77 | if (m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size. > m_capacitycxx . . $ QTJSC/AssemblerBuffer#m_capacity. - 4) |
| 78 | growcxx . . $ QTJSC/AssemblerBuffer#grow(d4f767463ce0a6b3).(); |
| 79 | putByteUncheckedcxx . . $ QTJSC/AssemblerBuffer#putByteUnchecked(d4f767463ce0a6b3).(value); |
| 80 | } |
| 81 | |
| 82 | void putShortUncheckedcxx . . $ QTJSC/AssemblerBuffer#putShortUnchecked(d4f767463ce0a6b3).(int value) |
| 83 | { |
| 84 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!(m_size > m_capacity - 4)); |
| 85 | *reinterpret_cast<short*>(&m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer.[m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.]) = value; |
| 86 | m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size. += 2; |
| 87 | } |
| 88 | |
| 89 | void putShortcxx . . $ QTJSC/AssemblerBuffer#putShort(d4f767463ce0a6b3).(int value) |
| 90 | { |
| 91 | if (m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size. > m_capacitycxx . . $ QTJSC/AssemblerBuffer#m_capacity. - 4) |
| 92 | growcxx . . $ QTJSC/AssemblerBuffer#grow(d4f767463ce0a6b3).(); |
| 93 | putShortUncheckedcxx . . $ QTJSC/AssemblerBuffer#putShortUnchecked(d4f767463ce0a6b3).(value); |
| 94 | } |
| 95 | |
| 96 | void putIntUncheckedcxx . . $ QTJSC/AssemblerBuffer#putIntUnchecked(d4f767463ce0a6b3).(int value) |
| 97 | { |
| 98 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!(m_size > m_capacity - 4)); |
| 99 | *reinterpret_cast<int*>(&m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer.[m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.]) = value; |
| 100 | m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size. += 4; |
| 101 | } |
| 102 | |
| 103 | void putInt64Uncheckedcxx . . $ QTJSC/AssemblerBuffer#putInt64Unchecked(1624ee8275b10bda).(int64_tcxx . . $ int64_t# value) |
| 104 | { |
| 105 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!(m_size > m_capacity - 8)); |
| 106 | *reinterpret_cast<int64_tcxx . . $ int64_t#*>(&m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer.[m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.]) = value; |
| 107 | m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size. += 8; |
| 108 | } |
| 109 | |
| 110 | void putIntcxx . . $ QTJSC/AssemblerBuffer#putInt(d4f767463ce0a6b3).(int value) |
| 111 | { |
| 112 | if (m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size. > m_capacitycxx . . $ QTJSC/AssemblerBuffer#m_capacity. - 4) |
| 113 | growcxx . . $ QTJSC/AssemblerBuffer#grow(d4f767463ce0a6b3).(); |
| 114 | putIntUncheckedcxx . . $ QTJSC/AssemblerBuffer#putIntUnchecked(d4f767463ce0a6b3).(value); |
| 115 | } |
| 116 | |
| 117 | void* datacxx . . $ QTJSC/AssemblerBuffer#data(45a5c5ac6be858a8).() const |
| 118 | { |
| 119 | return m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer.; |
| 120 | } |
| 121 | |
| 122 | int sizecxx . . $ QTJSC/AssemblerBuffer#size(455f465bc33b4cdf).() const |
| 123 | { |
| 124 | return m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.; |
| 125 | } |
| 126 | |
| 127 | void* executableCopycxx . . $ QTJSC/AssemblerBuffer#executableCopy(27da500743064be4).(ExecutablePoolcxx . . $ QTJSC/ExecutablePool#* allocator) |
| 128 | { |
| 129 | if (!m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.) |
| 130 | return 0; |
| 131 | |
| 132 | void* result = allocator->alloccxx . . $ QTJSC/ExecutablePool#alloc(bfcfa4d6b7f7ef64).(m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.); |
| 133 | |
| 134 | if (!result) |
| 135 | return 0; |
| 136 | |
| 137 | ExecutableAllocatorcxx . . $ QTJSC/ExecutableAllocator#::makeWritablecxx . . $ QTJSC/ExecutableAllocator#makeWritable(5500c4293b1bbef0).(result, m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.); |
| 138 | |
| 139 | return memcpy(result, m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer., m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.); |
| 140 | } |
| 141 | |
| 142 | protected: |
| 143 | void appendcxx . . $ QTJSC/AssemblerBuffer#append(34d26762b42c433a).(const char* data, int size) |
| 144 | { |
| 145 | if (m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size. > m_capacitycxx . . $ QTJSC/AssemblerBuffer#m_capacity. - size) |
| 146 | growcxx . . $ QTJSC/AssemblerBuffer#grow(d4f767463ce0a6b3).(size); |
| 147 | |
| 148 | memcpy(m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer. + m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size., data, size); |
| 149 | m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size. += size; |
| 150 | } |
| 151 | |
| 152 | void growcxx . . $ QTJSC/AssemblerBuffer#grow(d4f767463ce0a6b3).(int extraCapacity = 0) |
| 153 | { |
| 154 | m_capacitycxx . . $ QTJSC/AssemblerBuffer#m_capacity. += m_capacitycxx . . $ QTJSC/AssemblerBuffer#m_capacity. / 2 + extraCapacity; |
| 155 | |
| 156 | if (m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer. == m_inlineBuffercxx . . $ QTJSC/AssemblerBuffer#m_inlineBuffer.) { |
| 157 | char* newBuffer = static_cast<char*>(fastMalloccxx . . $ fastMalloc(bfcfa4d6b7f7ef64).(m_capacitycxx . . $ QTJSC/AssemblerBuffer#m_capacity.)); |
| 158 | m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer. = static_cast<char*>(memcpy(newBuffer, m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer., m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.)); |
| 159 | } else |
| 160 | m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer. = static_cast<char*>(fastRealloccxx . . $ fastRealloc(417ab160f6baadc6).(m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer., m_capacitycxx . . $ QTJSC/AssemblerBuffer#m_capacity.)); |
| 161 | } |
| 162 | |
| 163 | char m_inlineBuffercxx . . $ QTJSC/AssemblerBuffer#m_inlineBuffer.[inlineCapacitycxx . . $ QTJSC/AssemblerBuffer#inlineCapacity.]; |
| 164 | char* m_buffercxx . . $ QTJSC/AssemblerBuffer#m_buffer.; |
| 165 | int m_capacitycxx . . $ QTJSC/AssemblerBuffer#m_capacity.; |
| 166 | int m_sizecxx . . $ QTJSC/AssemblerBuffer#m_size.; |
| 167 | }; |
| 168 | |
| 169 | } // namespace JSC |
| 170 | |
| 171 | #endif // ENABLE(ASSEMBLER) |
| 172 | |
| 173 | #endif // AssemblerBuffer_h |