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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/wasm/asm-types.h" | 7 #include "src/wasm/asm-types.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
11 namespace wasm { | 11 namespace wasm { |
12 | 12 |
13 AsmCallableType* AsmType::AsCallableType() { | 13 AsmCallableType* AsmType::AsCallableType() { |
14 if (AsValueType() != nullptr) { | |
15 return nullptr; | |
16 } | |
17 | |
14 DCHECK(this->AsFunctionType() != nullptr || | 18 DCHECK(this->AsFunctionType() != nullptr || |
15 this->AsOverloadedFunctionType() != nullptr); | 19 this->AsOverloadedFunctionType() != nullptr || |
20 this->AsFFIType() != nullptr || | |
21 this->AsFunctionTableType() != nullptr); | |
16 return reinterpret_cast<AsmCallableType*>(this); | 22 return reinterpret_cast<AsmCallableType*>(this); |
17 } | 23 } |
18 | 24 |
19 std::string AsmType::Name() { | 25 std::string AsmType::Name() { |
20 AsmValueType* avt = this->AsValueType(); | 26 AsmValueType* avt = this->AsValueType(); |
21 if (avt != nullptr) { | 27 if (avt != nullptr) { |
22 switch (avt->Bitset()) { | 28 switch (avt->Bitset()) { |
23 #define RETURN_TYPE_NAME(CamelName, string_name, number, parent_types) \ | 29 #define RETURN_TYPE_NAME(CamelName, string_name, number, parent_types) \ |
24 case AsmValueType::kAsm##CamelName: \ | 30 case AsmValueType::kAsm##CamelName: \ |
25 return string_name; | 31 return string_name; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 }; | 234 }; |
229 } // namespace | 235 } // namespace |
230 | 236 |
231 AsmType* AsmType::MinMaxType(Zone* zone, AsmType* dest, AsmType* src) { | 237 AsmType* AsmType::MinMaxType(Zone* zone, AsmType* dest, AsmType* src) { |
232 DCHECK(dest->AsValueType() != nullptr); | 238 DCHECK(dest->AsValueType() != nullptr); |
233 DCHECK(src->AsValueType() != nullptr); | 239 DCHECK(src->AsValueType() != nullptr); |
234 auto* MinMax = new (zone) AsmMinMaxType(zone, dest, src); | 240 auto* MinMax = new (zone) AsmMinMaxType(zone, dest, src); |
235 return reinterpret_cast<AsmType*>(MinMax); | 241 return reinterpret_cast<AsmType*>(MinMax); |
236 } | 242 } |
237 | 243 |
244 AsmType* AsmFFIType::ValidateCall(AsmType* function_type) { | |
245 auto* callable = function_type->AsFunctionType(); | |
246 if (callable == nullptr) { | |
247 return nullptr; | |
248 } | |
249 | |
250 for (int ii = 0; ii < callable->Arguments().size(); ++ii) { | |
251 if (!callable->Arguments()[ii]->IsA(AsmType::Extern())) { | |
252 return AsmType::None(); | |
253 } | |
254 } | |
255 | |
256 return callable->ReturnType(); | |
257 } | |
258 | |
238 AsmType* AsmFunctionType::ValidateCall(AsmType* function_type) { | 259 AsmType* AsmFunctionType::ValidateCall(AsmType* function_type) { |
239 auto* callable = function_type->AsFunctionType(); | 260 auto* callable = function_type->AsFunctionType(); |
240 if (callable == nullptr) { | 261 if (callable == nullptr) { |
241 return nullptr; | 262 return nullptr; |
242 } | 263 } |
243 | 264 |
244 if (!return_type_->IsExactly(callable->return_type_)) { | 265 if (!return_type_->IsExactly(callable->return_type_)) { |
245 return AsmType::None(); | 266 return AsmType::None(); |
246 } | 267 } |
247 | 268 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 } | 307 } |
287 | 308 |
288 return AsmType::None(); | 309 return AsmType::None(); |
289 } | 310 } |
290 | 311 |
291 void AsmOverloadedFunctionType::AddOverload(AsmType* overload) { | 312 void AsmOverloadedFunctionType::AddOverload(AsmType* overload) { |
292 DCHECK(overload->AsFunctionType() != nullptr); | 313 DCHECK(overload->AsFunctionType() != nullptr); |
293 overloads_.push_back(overload); | 314 overloads_.push_back(overload); |
294 } | 315 } |
295 | 316 |
317 std::string AsmFunctionTableType::Name() { | |
318 std::string base_name = | |
319 signature_ == nullptr ? "[unbound]" : signature_->Name(); | |
320 return base_name + "[" + std::to_string(length_) + "]"; | |
321 } | |
322 | |
323 void AsmFunctionTableType::set_signature(AsmType* function_type) { | |
324 CHECK(function_type->AsFunctionType() != nullptr); | |
325 signature_ = function_type; | |
326 } | |
327 | |
328 AsmType* AsmFunctionTableType::ValidateCall(AsmType* function_type) { | |
329 if (signature_ == nullptr) { | |
bradnelson
2016/06/17 23:38:50
Doesn't this need to check that function_type is a
John
2016/06/20 15:09:52
signature_ is now initialized during the construct
| |
330 set_signature(function_type); | |
331 } | |
332 return signature_->AsCallableType()->ValidateCall(function_type); | |
333 } | |
334 | |
296 } // namespace wasm | 335 } // namespace wasm |
297 } // namespace internal | 336 } // namespace internal |
298 } // namespace v8 | 337 } // namespace v8 |
OLD | NEW |