OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/asmjs/asm-typer.h" | 5 #include "src/asmjs/asm-typer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 // ---------------------------------------------------------------------------- | 121 // ---------------------------------------------------------------------------- |
122 // Implementation of AsmTyper | 122 // Implementation of AsmTyper |
123 | 123 |
124 AsmTyper::AsmTyper(Isolate* isolate, Zone* zone, Script* script, | 124 AsmTyper::AsmTyper(Isolate* isolate, Zone* zone, Script* script, |
125 FunctionLiteral* root) | 125 FunctionLiteral* root) |
126 : isolate_(isolate), | 126 : isolate_(isolate), |
127 zone_(zone), | 127 zone_(zone), |
128 script_(script), | 128 script_(script), |
129 root_(root), | 129 root_(root), |
130 forward_definitions_(zone), | 130 forward_definitions_(zone), |
131 ffi_use_signatures_(zone), | |
131 stdlib_types_(zone), | 132 stdlib_types_(zone), |
132 stdlib_math_types_(zone), | 133 stdlib_math_types_(zone), |
133 module_info_(VariableInfo::ForSpecialSymbol(zone_, kModule)), | 134 module_info_(VariableInfo::ForSpecialSymbol(zone_, kModule)), |
134 global_scope_(ZoneHashMap::PointersMatch, | 135 global_scope_(ZoneHashMap::PointersMatch, |
135 ZoneHashMap::kDefaultHashMapCapacity, | 136 ZoneHashMap::kDefaultHashMapCapacity, |
136 ZoneAllocationPolicy(zone)), | 137 ZoneAllocationPolicy(zone)), |
137 local_scope_(ZoneHashMap::PointersMatch, | 138 local_scope_(ZoneHashMap::PointersMatch, |
138 ZoneHashMap::kDefaultHashMapCapacity, | 139 ZoneHashMap::kDefaultHashMapCapacity, |
139 ZoneAllocationPolicy(zone)), | 140 ZoneAllocationPolicy(zone)), |
140 stack_limit_(isolate->stack_guard()->real_climit()), | 141 stack_limit_(isolate->stack_guard()->real_climit()), |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 | 323 |
323 std::unique_ptr<char[]> aname = key->AsPropertyName()->ToCString(); | 324 std::unique_ptr<char[]> aname = key->AsPropertyName()->ToCString(); |
324 ObjectTypeMap::iterator i = stdlib->find(std::string(aname.get())); | 325 ObjectTypeMap::iterator i = stdlib->find(std::string(aname.get())); |
325 if (i == stdlib->end()) { | 326 if (i == stdlib->end()) { |
326 return nullptr; | 327 return nullptr; |
327 } | 328 } |
328 stdlib_uses_.insert(i->second->standard_member()); | 329 stdlib_uses_.insert(i->second->standard_member()); |
329 return i->second; | 330 return i->second; |
330 } | 331 } |
331 | 332 |
332 AsmTyper::VariableInfo* AsmTyper::Lookup(Variable* variable) { | 333 AsmTyper::VariableInfo* AsmTyper::Lookup(Variable* variable) const { |
333 ZoneHashMap* scope = in_function_ ? &local_scope_ : &global_scope_; | 334 const ZoneHashMap* scope = in_function_ ? &local_scope_ : &global_scope_; |
334 ZoneHashMap::Entry* entry = | 335 ZoneHashMap::Entry* entry = |
335 scope->Lookup(variable, ComputePointerHash(variable)); | 336 scope->Lookup(variable, ComputePointerHash(variable)); |
336 if (entry == nullptr && in_function_) { | 337 if (entry == nullptr && in_function_) { |
337 entry = global_scope_.Lookup(variable, ComputePointerHash(variable)); | 338 entry = global_scope_.Lookup(variable, ComputePointerHash(variable)); |
338 } | 339 } |
339 | 340 |
340 if (entry == nullptr && !module_name_.is_null() && | 341 if (entry == nullptr && !module_name_.is_null() && |
341 module_name_->Equals(*variable->name())) { | 342 module_name_->Equals(*variable->name())) { |
342 return module_info_; | 343 return module_info_; |
343 } | 344 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 } | 417 } |
417 int32_t i; | 418 int32_t i; |
418 if (literal->value()->ToInt32(&i)) { | 419 if (literal->value()->ToInt32(&i)) { |
419 return AsmType::Signed(); | 420 return AsmType::Signed(); |
420 } | 421 } |
421 } | 422 } |
422 | 423 |
423 return AsmType::None(); | 424 return AsmType::None(); |
424 } | 425 } |
425 | 426 |
427 AsmType* AsmTyper::TypeOf(Variable* v) const { return Lookup(v)->type(); } | |
428 | |
426 AsmTyper::StandardMember AsmTyper::VariableAsStandardMember(Variable* var) { | 429 AsmTyper::StandardMember AsmTyper::VariableAsStandardMember(Variable* var) { |
427 auto* var_info = Lookup(var); | 430 auto* var_info = Lookup(var); |
428 if (var_info == nullptr) { | 431 if (var_info == nullptr) { |
429 return kNone; | 432 return kNone; |
430 } | 433 } |
431 StandardMember member = var_info->standard_member(); | 434 StandardMember member = var_info->standard_member(); |
432 return member; | 435 return member; |
433 } | 436 } |
434 | 437 |
435 bool AsmTyper::Validate() { | 438 bool AsmTyper::Validate() { |
(...skipping 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2299 SetTypeOf(call_var_proxy, reinterpret_cast<AsmType*>(call_type)); | 2302 SetTypeOf(call_var_proxy, reinterpret_cast<AsmType*>(call_type)); |
2300 SetTypeOf(call, return_type); | 2303 SetTypeOf(call, return_type); |
2301 return return_type; | 2304 return return_type; |
2302 } | 2305 } |
2303 | 2306 |
2304 auto* callee_type = call_var_info->type()->AsCallableType(); | 2307 auto* callee_type = call_var_info->type()->AsCallableType(); |
2305 if (callee_type == nullptr) { | 2308 if (callee_type == nullptr) { |
2306 FAIL(call, "Calling something that's not a function."); | 2309 FAIL(call, "Calling something that's not a function."); |
2307 } | 2310 } |
2308 | 2311 |
2309 if (callee_type->AsFFIType() != nullptr && | 2312 if (callee_type->AsFFIType() != nullptr) { |
2310 return_type == AsmType::Float()) { | 2313 if (return_type == AsmType::Float()) { |
2311 FAIL(call, "Foreign functions can't return float."); | 2314 FAIL(call, "Foreign functions can't return float."); |
2315 } | |
2316 // Record FFI use signature, since the asm->wasm translator must know | |
2317 // all uses up-front. | |
2318 FFIUseSignature* sig; | |
Mircea Trofin
2016/09/19 16:16:24
please initialize sig
titzer
2016/09/21 08:58:44
Ah, I just moved it down a line, now. Done.
| |
2319 ffi_use_signatures_.emplace_back( | |
2320 FFIUseSignature(call_var_proxy->var(), zone_)); | |
2321 sig = &ffi_use_signatures_.back(); | |
2322 sig->return_type_ = return_type; | |
2323 sig->arg_types_.reserve(args.size()); | |
2324 for (size_t i = 0; i < args.size(); i++) { | |
Mircea Trofin
2016/09/19 16:16:24
++i
titzer
2016/09/21 08:58:44
Google style guide says (https://google.github.io/
Mircea Trofin
2016/09/21 16:38:23
OK, but now we have it sometimes pre and sometimes
titzer
2016/09/21 18:49:28
I've corrected some uses so that the changes in as
| |
2325 sig->arg_types_.emplace_back(args[i]); | |
2326 } | |
2312 } | 2327 } |
2313 | 2328 |
2314 if (!callee_type->CanBeInvokedWith(return_type, args)) { | 2329 if (!callee_type->CanBeInvokedWith(return_type, args)) { |
2315 FAIL(call, "Function invocation does not match function type."); | 2330 FAIL(call, "Function invocation does not match function type."); |
2316 } | 2331 } |
2317 | 2332 |
2318 SetTypeOf(call_var_proxy, call_var_info->type()); | 2333 SetTypeOf(call_var_proxy, call_var_info->type()); |
2319 SetTypeOf(call, return_type); | 2334 SetTypeOf(call, return_type); |
2320 return return_type; | 2335 return return_type; |
2321 } | 2336 } |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2765 return true; | 2780 return true; |
2766 } | 2781 } |
2767 | 2782 |
2768 *error_message = typer.error_message(); | 2783 *error_message = typer.error_message(); |
2769 return false; | 2784 return false; |
2770 } | 2785 } |
2771 | 2786 |
2772 } // namespace wasm | 2787 } // namespace wasm |
2773 } // namespace internal | 2788 } // namespace internal |
2774 } // namespace v8 | 2789 } // namespace v8 |
OLD | NEW |