| 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/objects-inl.h" | 8 #include "src/objects-inl.h" |
| 9 #include "src/v8.h" | 9 #include "src/v8.h" |
| 10 #include "src/zone/zone-containers.h" | 10 #include "src/zone/zone-containers.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 body_(builder->zone()), | 55 body_(builder->zone()), |
| 56 name_(builder->zone()), | 56 name_(builder->zone()), |
| 57 exported_names_(builder->zone()), | 57 exported_names_(builder->zone()), |
| 58 i32_temps_(builder->zone()), | 58 i32_temps_(builder->zone()), |
| 59 i64_temps_(builder->zone()), | 59 i64_temps_(builder->zone()), |
| 60 f32_temps_(builder->zone()), | 60 f32_temps_(builder->zone()), |
| 61 f64_temps_(builder->zone()), | 61 f64_temps_(builder->zone()), |
| 62 direct_calls_(builder->zone()), | 62 direct_calls_(builder->zone()), |
| 63 asm_offsets_(builder->zone(), 8) {} | 63 asm_offsets_(builder->zone(), 8) {} |
| 64 | 64 |
| 65 void WasmFunctionBuilder::EmitVarInt(int32_t val) { |
| 66 byte buffer[5]; |
| 67 byte* ptr = buffer; |
| 68 LEBHelper::write_i32v(&ptr, val); |
| 69 DCHECK_GE(5, ptr - buffer); |
| 70 body_.insert(body_.end(), buffer, ptr); |
| 71 } |
| 72 |
| 65 void WasmFunctionBuilder::EmitVarUint(uint32_t val) { | 73 void WasmFunctionBuilder::EmitVarUint(uint32_t val) { |
| 66 byte buffer[8]; | 74 byte buffer[5]; |
| 67 byte* ptr = buffer; | 75 byte* ptr = buffer; |
| 68 LEBHelper::write_u32v(&ptr, val); | 76 LEBHelper::write_u32v(&ptr, val); |
| 69 for (byte* p = buffer; p < ptr; p++) { | 77 DCHECK_GE(5, ptr - buffer); |
| 70 body_.push_back(*p); | 78 body_.insert(body_.end(), buffer, ptr); |
| 71 } | |
| 72 } | 79 } |
| 73 | 80 |
| 74 void WasmFunctionBuilder::SetSignature(FunctionSig* sig) { | 81 void WasmFunctionBuilder::SetSignature(FunctionSig* sig) { |
| 75 DCHECK(!locals_.has_sig()); | 82 DCHECK(!locals_.has_sig()); |
| 76 locals_.set_sig(sig); | 83 locals_.set_sig(sig); |
| 77 signature_index_ = builder_->AddSignature(sig); | 84 signature_index_ = builder_->AddSignature(sig); |
| 78 } | 85 } |
| 79 | 86 |
| 80 uint32_t WasmFunctionBuilder::AddLocal(ValueType type) { | 87 uint32_t WasmFunctionBuilder::AddLocal(ValueType type) { |
| 81 DCHECK(locals_.has_sig()); | 88 DCHECK(locals_.has_sig()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 109 body_.push_back(immediate); | 116 body_.push_back(immediate); |
| 110 } | 117 } |
| 111 | 118 |
| 112 void WasmFunctionBuilder::EmitWithU8U8(WasmOpcode opcode, const byte imm1, | 119 void WasmFunctionBuilder::EmitWithU8U8(WasmOpcode opcode, const byte imm1, |
| 113 const byte imm2) { | 120 const byte imm2) { |
| 114 body_.push_back(static_cast<byte>(opcode)); | 121 body_.push_back(static_cast<byte>(opcode)); |
| 115 body_.push_back(imm1); | 122 body_.push_back(imm1); |
| 116 body_.push_back(imm2); | 123 body_.push_back(imm2); |
| 117 } | 124 } |
| 118 | 125 |
| 126 void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode, int32_t immediate) { |
| 127 body_.push_back(static_cast<byte>(opcode)); |
| 128 EmitVarInt(immediate); |
| 129 } |
| 130 |
| 119 void WasmFunctionBuilder::EmitWithVarUint(WasmOpcode opcode, | 131 void WasmFunctionBuilder::EmitWithVarUint(WasmOpcode opcode, |
| 120 uint32_t immediate) { | 132 uint32_t immediate) { |
| 121 body_.push_back(static_cast<byte>(opcode)); | 133 body_.push_back(static_cast<byte>(opcode)); |
| 122 EmitVarUint(immediate); | 134 EmitVarUint(immediate); |
| 123 } | 135 } |
| 124 | 136 |
| 125 void WasmFunctionBuilder::EmitI32Const(int32_t value) { | 137 void WasmFunctionBuilder::EmitI32Const(int32_t value) { |
| 126 if (-64 <= value && value <= 63) { | 138 EmitWithVarInt(kExprI32Const, value); |
| 127 EmitWithU8(kExprI32Const, static_cast<byte>(value & 0x7F)); | |
| 128 } else { | |
| 129 // TODO(titzer): variable-length signed and unsigned i32 constants. | |
| 130 byte code[] = {WASM_I32V_5(value)}; | |
| 131 EmitCode(code, sizeof(code)); | |
| 132 } | |
| 133 } | 139 } |
| 134 | 140 |
| 135 void WasmFunctionBuilder::EmitDirectCallIndex(uint32_t index) { | 141 void WasmFunctionBuilder::EmitDirectCallIndex(uint32_t index) { |
| 136 DirectCallIndex call; | 142 DirectCallIndex call; |
| 137 call.offset = body_.size(); | 143 call.offset = body_.size(); |
| 138 call.direct_index = index; | 144 call.direct_index = index; |
| 139 direct_calls_.push_back(call); | 145 direct_calls_.push_back(call); |
| 140 byte code[] = {U32V_5(0)}; | 146 byte code[] = {U32V_5(0)}; |
| 141 EmitCode(code, sizeof(code)); | 147 EmitCode(code, sizeof(code)); |
| 142 } | 148 } |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 // Emit the offset table per function. | 556 // Emit the offset table per function. |
| 551 for (auto function : functions_) { | 557 for (auto function : functions_) { |
| 552 function->WriteAsmWasmOffsetTable(buffer); | 558 function->WriteAsmWasmOffsetTable(buffer); |
| 553 } | 559 } |
| 554 // Append a 0 to indicate that this is an encoded table. | 560 // Append a 0 to indicate that this is an encoded table. |
| 555 buffer.write_u8(0); | 561 buffer.write_u8(0); |
| 556 } | 562 } |
| 557 } // namespace wasm | 563 } // namespace wasm |
| 558 } // namespace internal | 564 } // namespace internal |
| 559 } // namespace v8 | 565 } // namespace v8 |
| OLD | NEW |