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/zone-containers.h" | 9 #include "src/zone/zone-containers.h" |
10 | 10 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 body_.push_back(imm2); | 115 body_.push_back(imm2); |
116 } | 116 } |
117 | 117 |
118 void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode, | 118 void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode, |
119 uint32_t immediate) { | 119 uint32_t immediate) { |
120 body_.push_back(static_cast<byte>(opcode)); | 120 body_.push_back(static_cast<byte>(opcode)); |
121 EmitVarInt(immediate); | 121 EmitVarInt(immediate); |
122 } | 122 } |
123 | 123 |
124 void WasmFunctionBuilder::EmitI32Const(int32_t value) { | 124 void WasmFunctionBuilder::EmitI32Const(int32_t value) { |
125 // TODO(titzer): variable-length signed and unsigned i32 constants. | 125 if (-64 <= value && value <= 63) { |
126 if (-128 <= value && value <= 127) { | 126 EmitWithU8(kExprI32Const, static_cast<byte>(value & 0x7F)); |
127 EmitWithU8(kExprI8Const, static_cast<byte>(value)); | |
128 } else { | 127 } else { |
| 128 // TODO(titzer): variable-length signed and unsigned i32 constants. |
129 byte code[] = {WASM_I32V_5(value)}; | 129 byte code[] = {WASM_I32V_5(value)}; |
130 EmitCode(code, sizeof(code)); | 130 EmitCode(code, sizeof(code)); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 void WasmFunctionBuilder::EmitDirectCallIndex(uint32_t index) { | 134 void WasmFunctionBuilder::EmitDirectCallIndex(uint32_t index) { |
135 DirectCallIndex call; | 135 DirectCallIndex call; |
136 call.offset = body_.size(); | 136 call.offset = body_.size(); |
137 call.direct_index = index; | 137 call.direct_index = index; |
138 direct_calls_.push_back(call); | 138 direct_calls_.push_back(call); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 // Emit the offset table per function. | 535 // Emit the offset table per function. |
536 for (auto function : functions_) { | 536 for (auto function : functions_) { |
537 function->WriteAsmWasmOffsetTable(buffer); | 537 function->WriteAsmWasmOffsetTable(buffer); |
538 } | 538 } |
539 // Append a 0 to indicate that this is an encoded table. | 539 // Append a 0 to indicate that this is an encoded table. |
540 buffer.write_u8(0); | 540 buffer.write_u8(0); |
541 } | 541 } |
542 } // namespace wasm | 542 } // namespace wasm |
543 } // namespace internal | 543 } // namespace internal |
544 } // namespace v8 | 544 } // namespace v8 |
OLD | NEW |