• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "src/wasm/wasm-opcodes.h"
6 
7 #include <array>
8 
9 #include "src/codegen/signature.h"
10 #include "src/wasm/wasm-features.h"
11 #include "src/wasm/wasm-module.h"
12 #include "src/wasm/wasm-opcodes-inl.h"
13 
14 namespace v8 {
15 namespace internal {
16 namespace wasm {
17 
operator <<(std::ostream & os,const FunctionSig & sig)18 std::ostream& operator<<(std::ostream& os, const FunctionSig& sig) {
19   if (sig.return_count() == 0) os << "v";
20   for (auto ret : sig.returns()) {
21     os << ret.short_name();
22   }
23   os << "_";
24   if (sig.parameter_count() == 0) os << "v";
25   for (auto param : sig.parameters()) {
26     os << param.short_name();
27   }
28   return os;
29 }
30 
31 // TODO(7748): Once we have a story for JS interaction of structs/arrays, this
32 // function should become independent of module. Remove 'module' parameter in
33 // this function as well as all transitive callees that no longer need it
34 // (In essence, revert
35 // https://chromium-review.googlesource.com/c/v8/v8/+/2413251).
IsJSCompatibleSignature(const FunctionSig * sig,const WasmModule * module,const WasmFeatures & enabled_features)36 bool IsJSCompatibleSignature(const FunctionSig* sig, const WasmModule* module,
37                              const WasmFeatures& enabled_features) {
38   if (!enabled_features.has_mv() && sig->return_count() > 1) {
39     return false;
40   }
41   for (auto type : sig->all()) {
42     // TODO(7748): Allow structs, arrays, rtts and i31s when their
43     //             JS-interaction is decided on.
44     if ((type == kWasmI64 && !enabled_features.has_bigint()) ||
45         type == kWasmS128 || type.is_reference_to(HeapType::kI31) ||
46         (type.has_index() && !module->has_signature(type.ref_index())) ||
47         type.is_rtt()) {
48       return false;
49     }
50   }
51   return true;
52 }
53 
54 // Define constexpr arrays.
55 constexpr uint8_t LoadType::kLoadSizeLog2[];
56 constexpr ValueType LoadType::kValueType[];
57 constexpr MachineType LoadType::kMemType[];
58 constexpr uint8_t StoreType::kStoreSizeLog2[];
59 constexpr ValueType StoreType::kValueType[];
60 constexpr MachineRepresentation StoreType::kMemRep[];
61 
62 }  // namespace wasm
63 }  // namespace internal
64 }  // namespace v8
65