OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_WASM_MACRO_GEN_H_ | 5 #ifndef V8_WASM_MACRO_GEN_H_ |
6 #define V8_WASM_MACRO_GEN_H_ | 6 #define V8_WASM_MACRO_GEN_H_ |
7 | 7 |
8 #include "src/wasm/wasm-opcodes.h" | 8 #include "src/wasm/wasm-opcodes.h" |
9 | 9 |
10 #include "src/zone-containers.h" | 10 #include "src/zone-containers.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // A helper for encoding local declarations prepended to the body of a | 133 // A helper for encoding local declarations prepended to the body of a |
134 // function. | 134 // function. |
135 // TODO(titzer): move this to an appropriate header. | 135 // TODO(titzer): move this to an appropriate header. |
136 class LocalDeclEncoder { | 136 class LocalDeclEncoder { |
137 public: | 137 public: |
138 explicit LocalDeclEncoder(Zone* zone, FunctionSig* s = nullptr) | 138 explicit LocalDeclEncoder(Zone* zone, FunctionSig* s = nullptr) |
139 : sig(s), local_decls(zone), total(0) {} | 139 : sig(s), local_decls(zone), total(0) {} |
140 | 140 |
141 // Prepend local declarations by creating a new buffer and copying data | 141 // Prepend local declarations by creating a new buffer and copying data |
142 // over. The new buffer must be delete[]'d by the caller. | 142 // over. The new buffer must be delete[]'d by the caller. |
143 void Prepend(const byte** start, const byte** end) const { | 143 void Prepend(Zone* zone, const byte** start, const byte** end) const { |
144 size_t size = (*end - *start); | 144 size_t size = (*end - *start); |
145 byte* buffer = new byte[Size() + size]; | 145 byte* buffer = reinterpret_cast<byte*>(zone->New(Size() + size)); |
146 size_t pos = Emit(buffer); | 146 size_t pos = Emit(buffer); |
147 memcpy(buffer + pos, *start, size); | 147 memcpy(buffer + pos, *start, size); |
148 pos += size; | 148 pos += size; |
149 *start = buffer; | 149 *start = buffer; |
150 *end = buffer + pos; | 150 *end = buffer + pos; |
151 } | 151 } |
152 | 152 |
153 size_t Emit(byte* buffer) const { | 153 size_t Emit(byte* buffer) const { |
154 size_t pos = 0; | 154 size_t pos = 0; |
155 pos = WriteUint32v(buffer, pos, static_cast<uint32_t>(local_decls.size())); | 155 pos = WriteUint32v(buffer, pos, static_cast<uint32_t>(local_decls.size())); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 #define SIG_ENTRY_x(r) kWasmFunctionTypeForm, 0, 1, r | 592 #define SIG_ENTRY_x(r) kWasmFunctionTypeForm, 0, 1, r |
593 #define SIG_ENTRY_x_x(r, a) kWasmFunctionTypeForm, 1, a, 1, r | 593 #define SIG_ENTRY_x_x(r, a) kWasmFunctionTypeForm, 1, a, 1, r |
594 #define SIG_ENTRY_x_xx(r, a, b) kWasmFunctionTypeForm, 2, a, b, 1, r | 594 #define SIG_ENTRY_x_xx(r, a, b) kWasmFunctionTypeForm, 2, a, b, 1, r |
595 #define SIG_ENTRY_x_xxx(r, a, b, c) kWasmFunctionTypeForm, 3, a, b, c, 1, r | 595 #define SIG_ENTRY_x_xxx(r, a, b, c) kWasmFunctionTypeForm, 3, a, b, c, 1, r |
596 #define SIZEOF_SIG_ENTRY_x 4 | 596 #define SIZEOF_SIG_ENTRY_x 4 |
597 #define SIZEOF_SIG_ENTRY_x_x 5 | 597 #define SIZEOF_SIG_ENTRY_x_x 5 |
598 #define SIZEOF_SIG_ENTRY_x_xx 6 | 598 #define SIZEOF_SIG_ENTRY_x_xx 6 |
599 #define SIZEOF_SIG_ENTRY_x_xxx 7 | 599 #define SIZEOF_SIG_ENTRY_x_xxx 7 |
600 | 600 |
601 #endif // V8_WASM_MACRO_GEN_H_ | 601 #endif // V8_WASM_MACRO_GEN_H_ |
OLD | NEW |