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   for (auto type : sig->all()) {
39     // TODO(7748): Allow structs, arrays, and rtts when their JS-interaction is
40     // decided on.
41     if (type == kWasmS128 || type.is_rtt() ||
42         (type.has_index() && !module->has_signature(type.ref_index()))) {
43       return false;
44     }
45   }
46   return true;
47 }
48 
49 // Define constexpr arrays.
50 constexpr uint8_t LoadType::kLoadSizeLog2[];
51 constexpr ValueType LoadType::kValueType[];
52 constexpr MachineType LoadType::kMemType[];
53 constexpr uint8_t StoreType::kStoreSizeLog2[];
54 constexpr ValueType StoreType::kValueType[];
55 constexpr MachineRepresentation StoreType::kMemRep[];
56 
57 }  // namespace wasm
58 }  // namespace internal
59 }  // namespace v8
60