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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 // Required to get M_E etc. in MSVC. | 7 // Required to get M_E etc. in MSVC. |
8 #if defined(_WIN32) | 8 #if defined(_WIN32) |
9 #define _USE_MATH_DEFINES | 9 #define _USE_MATH_DEFINES |
10 #endif | 10 #endif |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 current_function_builder_->Emit(kExprI32Eq); | 266 current_function_builder_->Emit(kExprI32Eq); |
267 VisitVariableProxy(tag); | 267 VisitVariableProxy(tag); |
268 byte code[] = {WASM_I32V(node->begin)}; | 268 byte code[] = {WASM_I32V(node->begin)}; |
269 current_function_builder_->EmitCode(code, sizeof(code)); | 269 current_function_builder_->EmitCode(code, sizeof(code)); |
270 DCHECK(case_to_block.find(node->begin) != case_to_block.end()); | 270 DCHECK(case_to_block.find(node->begin) != case_to_block.end()); |
271 current_function_builder_->EmitWithVarInt(kExprBr, | 271 current_function_builder_->EmitWithVarInt(kExprBr, |
272 case_to_block.at(node->begin)); | 272 case_to_block.at(node->begin)); |
273 current_function_builder_->Emit(kExprNop); | 273 current_function_builder_->Emit(kExprNop); |
274 } else { | 274 } else { |
275 current_function_builder_->Emit(kExprBrTable); | 275 current_function_builder_->Emit(kExprBrTable); |
276 std::vector<uint8_t> count = | 276 current_function_builder_->EmitVarInt(node->end - node->begin + 1); |
277 UnsignedLEB128From(node->end - node->begin + 1); | |
278 current_function_builder_->EmitCode(&count[0], | |
279 static_cast<uint32_t>(count.size())); | |
280 for (int v = node->begin; v <= node->end; v++) { | 277 for (int v = node->begin; v <= node->end; v++) { |
281 if (case_to_block.find(v) != case_to_block.end()) { | 278 if (case_to_block.find(v) != case_to_block.end()) { |
282 byte break_code[] = {BR_TARGET(case_to_block.at(v))}; | 279 byte break_code[] = {BR_TARGET(case_to_block.at(v))}; |
283 current_function_builder_->EmitCode(break_code, sizeof(break_code)); | 280 current_function_builder_->EmitCode(break_code, sizeof(break_code)); |
284 } else { | 281 } else { |
285 byte break_code[] = {BR_TARGET(default_block)}; | 282 byte break_code[] = {BR_TARGET(default_block)}; |
286 current_function_builder_->EmitCode(break_code, sizeof(break_code)); | 283 current_function_builder_->EmitCode(break_code, sizeof(break_code)); |
287 } | 284 } |
288 if (v == kMaxInt) { | 285 if (v == kMaxInt) { |
289 break; | 286 break; |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 } | 1127 } |
1131 for (int i = 0; i < args->length(); i++) { | 1128 for (int i = 0; i < args->length(); i++) { |
1132 sig.AddParam(TypeOf(args->at(i))); | 1129 sig.AddParam(TypeOf(args->at(i))); |
1133 } | 1130 } |
1134 index = | 1131 index = |
1135 imported_function_table_.GetFunctionIndex(vp->var(), sig.Build()); | 1132 imported_function_table_.GetFunctionIndex(vp->var(), sig.Build()); |
1136 } else { | 1133 } else { |
1137 index = LookupOrInsertFunction(vp->var()); | 1134 index = LookupOrInsertFunction(vp->var()); |
1138 } | 1135 } |
1139 current_function_builder_->Emit(kExprCallFunction); | 1136 current_function_builder_->Emit(kExprCallFunction); |
1140 std::vector<uint8_t> index_arr = UnsignedLEB128From(index); | 1137 current_function_builder_->EmitVarInt(index); |
1141 current_function_builder_->EmitCode( | |
1142 &index_arr[0], static_cast<uint32_t>(index_arr.size())); | |
1143 break; | 1138 break; |
1144 } | 1139 } |
1145 case Call::KEYED_PROPERTY_CALL: { | 1140 case Call::KEYED_PROPERTY_CALL: { |
1146 DCHECK(in_function_); | 1141 DCHECK(in_function_); |
1147 Property* p = expr->expression()->AsProperty(); | 1142 Property* p = expr->expression()->AsProperty(); |
1148 DCHECK_NOT_NULL(p); | 1143 DCHECK_NOT_NULL(p); |
1149 VariableProxy* var = p->obj()->AsVariableProxy(); | 1144 VariableProxy* var = p->obj()->AsVariableProxy(); |
1150 DCHECK_NOT_NULL(var); | 1145 DCHECK_NOT_NULL(var); |
1151 FunctionTableIndices* indices = LookupFunctionTable(var->var()); | 1146 FunctionTableIndices* indices = LookupFunctionTable(var->var()); |
1152 current_function_builder_->EmitWithVarInt(kExprCallIndirect, | 1147 current_function_builder_->EmitWithVarInt(kExprCallIndirect, |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 // that zone in constructor may be thrown away once wasm module is written. | 1590 // that zone in constructor may be thrown away once wasm module is written. |
1596 WasmModuleIndex* AsmWasmBuilder::Run() { | 1591 WasmModuleIndex* AsmWasmBuilder::Run() { |
1597 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); | 1592 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); |
1598 impl.Compile(); | 1593 impl.Compile(); |
1599 WasmModuleWriter* writer = impl.builder_->Build(zone_); | 1594 WasmModuleWriter* writer = impl.builder_->Build(zone_); |
1600 return writer->WriteTo(zone_); | 1595 return writer->WriteTo(zone_); |
1601 } | 1596 } |
1602 } // namespace wasm | 1597 } // namespace wasm |
1603 } // namespace internal | 1598 } // namespace internal |
1604 } // namespace v8 | 1599 } // namespace v8 |
OLD | NEW |