11cb0ef41Sopenharmony_ci// Copyright 2015 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/wasm/wasm-opcodes.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include <array>
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci#include "src/codegen/signature.h"
101cb0ef41Sopenharmony_ci#include "src/wasm/wasm-features.h"
111cb0ef41Sopenharmony_ci#include "src/wasm/wasm-module.h"
121cb0ef41Sopenharmony_ci#include "src/wasm/wasm-opcodes-inl.h"
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_cinamespace v8 {
151cb0ef41Sopenharmony_cinamespace internal {
161cb0ef41Sopenharmony_cinamespace wasm {
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_cistd::ostream& operator<<(std::ostream& os, const FunctionSig& sig) {
191cb0ef41Sopenharmony_ci  if (sig.return_count() == 0) os << "v";
201cb0ef41Sopenharmony_ci  for (auto ret : sig.returns()) {
211cb0ef41Sopenharmony_ci    os << ret.short_name();
221cb0ef41Sopenharmony_ci  }
231cb0ef41Sopenharmony_ci  os << "_";
241cb0ef41Sopenharmony_ci  if (sig.parameter_count() == 0) os << "v";
251cb0ef41Sopenharmony_ci  for (auto param : sig.parameters()) {
261cb0ef41Sopenharmony_ci    os << param.short_name();
271cb0ef41Sopenharmony_ci  }
281cb0ef41Sopenharmony_ci  return os;
291cb0ef41Sopenharmony_ci}
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci// TODO(7748): Once we have a story for JS interaction of structs/arrays, this
321cb0ef41Sopenharmony_ci// function should become independent of module. Remove 'module' parameter in
331cb0ef41Sopenharmony_ci// this function as well as all transitive callees that no longer need it
341cb0ef41Sopenharmony_ci// (In essence, revert
351cb0ef41Sopenharmony_ci// https://chromium-review.googlesource.com/c/v8/v8/+/2413251).
361cb0ef41Sopenharmony_cibool IsJSCompatibleSignature(const FunctionSig* sig, const WasmModule* module,
371cb0ef41Sopenharmony_ci                             const WasmFeatures& enabled_features) {
381cb0ef41Sopenharmony_ci  for (auto type : sig->all()) {
391cb0ef41Sopenharmony_ci    // TODO(7748): Allow structs, arrays, and rtts when their JS-interaction is
401cb0ef41Sopenharmony_ci    // decided on.
411cb0ef41Sopenharmony_ci    if (type == kWasmS128 || type.is_rtt() ||
421cb0ef41Sopenharmony_ci        (type.has_index() && !module->has_signature(type.ref_index()))) {
431cb0ef41Sopenharmony_ci      return false;
441cb0ef41Sopenharmony_ci    }
451cb0ef41Sopenharmony_ci  }
461cb0ef41Sopenharmony_ci  return true;
471cb0ef41Sopenharmony_ci}
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci// Define constexpr arrays.
501cb0ef41Sopenharmony_ciconstexpr uint8_t LoadType::kLoadSizeLog2[];
511cb0ef41Sopenharmony_ciconstexpr ValueType LoadType::kValueType[];
521cb0ef41Sopenharmony_ciconstexpr MachineType LoadType::kMemType[];
531cb0ef41Sopenharmony_ciconstexpr uint8_t StoreType::kStoreSizeLog2[];
541cb0ef41Sopenharmony_ciconstexpr ValueType StoreType::kValueType[];
551cb0ef41Sopenharmony_ciconstexpr MachineRepresentation StoreType::kMemRep[];
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci}  // namespace wasm
581cb0ef41Sopenharmony_ci}  // namespace internal
591cb0ef41Sopenharmony_ci}  // namespace v8
60