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(uint32_t val) { | 65 void WasmFunctionBuilder::EmitVarUint(uint32_t val) { |
66 byte buffer[8]; | 66 byte buffer[8]; |
67 byte* ptr = buffer; | 67 byte* ptr = buffer; |
68 LEBHelper::write_u32v(&ptr, val); | 68 LEBHelper::write_u32v(&ptr, val); |
69 for (byte* p = buffer; p < ptr; p++) { | 69 for (byte* p = buffer; p < ptr; p++) { |
70 body_.push_back(*p); | 70 body_.push_back(*p); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 void WasmFunctionBuilder::SetSignature(FunctionSig* sig) { | 74 void WasmFunctionBuilder::SetSignature(FunctionSig* sig) { |
75 DCHECK(!locals_.has_sig()); | 75 DCHECK(!locals_.has_sig()); |
76 locals_.set_sig(sig); | 76 locals_.set_sig(sig); |
77 signature_index_ = builder_->AddSignature(sig); | 77 signature_index_ = builder_->AddSignature(sig); |
78 } | 78 } |
79 | 79 |
80 uint32_t WasmFunctionBuilder::AddLocal(ValueType type) { | 80 uint32_t WasmFunctionBuilder::AddLocal(ValueType type) { |
81 DCHECK(locals_.has_sig()); | 81 DCHECK(locals_.has_sig()); |
82 return locals_.AddLocals(1, type); | 82 return locals_.AddLocals(1, type); |
83 } | 83 } |
84 | 84 |
85 void WasmFunctionBuilder::EmitGetLocal(uint32_t local_index) { | 85 void WasmFunctionBuilder::EmitGetLocal(uint32_t local_index) { |
86 EmitWithVarInt(kExprGetLocal, local_index); | 86 EmitWithVarUint(kExprGetLocal, local_index); |
87 } | 87 } |
88 | 88 |
89 void WasmFunctionBuilder::EmitSetLocal(uint32_t local_index) { | 89 void WasmFunctionBuilder::EmitSetLocal(uint32_t local_index) { |
90 EmitWithVarInt(kExprSetLocal, local_index); | 90 EmitWithVarUint(kExprSetLocal, local_index); |
91 } | 91 } |
92 | 92 |
93 void WasmFunctionBuilder::EmitTeeLocal(uint32_t local_index) { | 93 void WasmFunctionBuilder::EmitTeeLocal(uint32_t local_index) { |
94 EmitWithVarInt(kExprTeeLocal, local_index); | 94 EmitWithVarUint(kExprTeeLocal, local_index); |
95 } | 95 } |
96 | 96 |
97 void WasmFunctionBuilder::EmitCode(const byte* code, uint32_t code_size) { | 97 void WasmFunctionBuilder::EmitCode(const byte* code, uint32_t code_size) { |
98 for (size_t i = 0; i < code_size; ++i) { | 98 for (size_t i = 0; i < code_size; ++i) { |
99 body_.push_back(code[i]); | 99 body_.push_back(code[i]); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 void WasmFunctionBuilder::Emit(WasmOpcode opcode) { | 103 void WasmFunctionBuilder::Emit(WasmOpcode opcode) { |
104 body_.push_back(static_cast<byte>(opcode)); | 104 body_.push_back(static_cast<byte>(opcode)); |
105 } | 105 } |
106 | 106 |
107 void WasmFunctionBuilder::EmitWithU8(WasmOpcode opcode, const byte immediate) { | 107 void WasmFunctionBuilder::EmitWithU8(WasmOpcode opcode, const byte immediate) { |
108 body_.push_back(static_cast<byte>(opcode)); | 108 body_.push_back(static_cast<byte>(opcode)); |
109 body_.push_back(immediate); | 109 body_.push_back(immediate); |
110 } | 110 } |
111 | 111 |
112 void WasmFunctionBuilder::EmitWithU8U8(WasmOpcode opcode, const byte imm1, | 112 void WasmFunctionBuilder::EmitWithU8U8(WasmOpcode opcode, const byte imm1, |
113 const byte imm2) { | 113 const byte imm2) { |
114 body_.push_back(static_cast<byte>(opcode)); | 114 body_.push_back(static_cast<byte>(opcode)); |
115 body_.push_back(imm1); | 115 body_.push_back(imm1); |
116 body_.push_back(imm2); | 116 body_.push_back(imm2); |
117 } | 117 } |
118 | 118 |
119 void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode, | 119 void WasmFunctionBuilder::EmitWithVarUint(WasmOpcode opcode, |
120 uint32_t immediate) { | 120 uint32_t immediate) { |
121 body_.push_back(static_cast<byte>(opcode)); | 121 body_.push_back(static_cast<byte>(opcode)); |
122 EmitVarInt(immediate); | 122 EmitVarUint(immediate); |
123 } | 123 } |
124 | 124 |
125 void WasmFunctionBuilder::EmitI32Const(int32_t value) { | 125 void WasmFunctionBuilder::EmitI32Const(int32_t value) { |
126 if (-64 <= value && value <= 63) { | 126 if (-64 <= value && value <= 63) { |
127 EmitWithU8(kExprI32Const, static_cast<byte>(value & 0x7F)); | 127 EmitWithU8(kExprI32Const, static_cast<byte>(value & 0x7F)); |
128 } else { | 128 } else { |
129 // TODO(titzer): variable-length signed and unsigned i32 constants. | 129 // TODO(titzer): variable-length signed and unsigned i32 constants. |
130 byte code[] = {WASM_I32V_5(value)}; | 130 byte code[] = {WASM_I32V_5(value)}; |
131 EmitCode(code, sizeof(code)); | 131 EmitCode(code, sizeof(code)); |
132 } | 132 } |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 // Emit the offset table per function. | 550 // Emit the offset table per function. |
551 for (auto function : functions_) { | 551 for (auto function : functions_) { |
552 function->WriteAsmWasmOffsetTable(buffer); | 552 function->WriteAsmWasmOffsetTable(buffer); |
553 } | 553 } |
554 // Append a 0 to indicate that this is an encoded table. | 554 // Append a 0 to indicate that this is an encoded table. |
555 buffer.write_u8(0); | 555 buffer.write_u8(0); |
556 } | 556 } |
557 } // namespace wasm | 557 } // namespace wasm |
558 } // namespace internal | 558 } // namespace internal |
559 } // namespace v8 | 559 } // namespace v8 |
OLD | NEW |