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 #include "src/signature.h" | 5 #include "src/signature.h" |
6 | 6 |
7 #include "src/handles.h" | 7 #include "src/handles.h" |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 #include "src/zone-containers.h" | 9 #include "src/zone-containers.h" |
10 | 10 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 body_.push_back(imm1); | 182 body_.push_back(imm1); |
183 body_.push_back(imm2); | 183 body_.push_back(imm2); |
184 } | 184 } |
185 | 185 |
186 void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode, | 186 void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode, |
187 uint32_t immediate) { | 187 uint32_t immediate) { |
188 body_.push_back(static_cast<byte>(opcode)); | 188 body_.push_back(static_cast<byte>(opcode)); |
189 EmitVarInt(immediate); | 189 EmitVarInt(immediate); |
190 } | 190 } |
191 | 191 |
| 192 void WasmFunctionBuilder::EmitI32Const(int32_t value) { |
| 193 // TODO(titzer): variable-length signed and unsigned i32 constants. |
| 194 if (-128 <= value && value <= 127) { |
| 195 EmitWithU8(kExprI8Const, static_cast<byte>(value)); |
| 196 } else { |
| 197 byte code[] = {WASM_I32V_5(value)}; |
| 198 EmitCode(code, sizeof(code)); |
| 199 } |
| 200 } |
| 201 |
192 uint32_t WasmFunctionBuilder::EmitEditableVarIntImmediate() { | 202 uint32_t WasmFunctionBuilder::EmitEditableVarIntImmediate() { |
193 // Guess that the immediate will be 1 byte. If it is more, we'll have to | 203 // Guess that the immediate will be 1 byte. If it is more, we'll have to |
194 // shift everything down. | 204 // shift everything down. |
195 body_.push_back(0); | 205 body_.push_back(0); |
196 return static_cast<uint32_t>(body_.size()) - 1; | 206 return static_cast<uint32_t>(body_.size()) - 1; |
197 } | 207 } |
198 | 208 |
199 void WasmFunctionBuilder::EditVarIntImmediate(uint32_t offset, | 209 void WasmFunctionBuilder::EditVarIntImmediate(uint32_t offset, |
200 const uint32_t immediate) { | 210 const uint32_t immediate) { |
201 uint32_t immediate_size = | 211 uint32_t immediate_size = |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 if (sizes.body_size > 0) { | 735 if (sizes.body_size > 0) { |
726 byte* section = EmitSection(WasmSection::Code::End, &header); | 736 byte* section = EmitSection(WasmSection::Code::End, &header); |
727 FixupSection(section, header); | 737 FixupSection(section, header); |
728 } | 738 } |
729 | 739 |
730 return new (zone) WasmModuleIndex(buffer, buffer + sizes.total()); | 740 return new (zone) WasmModuleIndex(buffer, buffer + sizes.total()); |
731 } | 741 } |
732 } // namespace wasm | 742 } // namespace wasm |
733 } // namespace internal | 743 } // namespace internal |
734 } // namespace v8 | 744 } // namespace v8 |
OLD | NEW |