summaryrefslogtreecommitdiff
path: root/deps/v8/src/wasm/value-type.cc
blob: da184941a6163a341e52d134d78c382bf547f958 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/wasm/value-type.h"

#include "src/codegen/signature.h"

namespace v8 {
namespace internal {
namespace wasm {

base::Optional<wasm::ValueKind> WasmReturnTypeFromSignature(
    const FunctionSig* wasm_signature) {
  if (wasm_signature->return_count() == 0) {
    return {};
  } else {
    DCHECK_EQ(wasm_signature->return_count(), 1);
    ValueType return_type = wasm_signature->GetReturn(0);
    switch (return_type.kind()) {
      case kI32:
      case kI64:
      case kF32:
      case kF64:
        return {return_type.kind()};
      default:
        UNREACHABLE();
    }
  }
}

#if DEBUG
V8_EXPORT_PRIVATE extern void PrintFunctionSig(const wasm::FunctionSig* sig) {
  std::ostringstream os;
  os << sig->parameter_count() << " parameters:\n";
  for (size_t i = 0; i < sig->parameter_count(); i++) {
    os << "  " << i << ": " << sig->GetParam(i) << "\n";
  }
  os << sig->return_count() << " returns:\n";
  for (size_t i = 0; i < sig->return_count(); i++) {
    os << "  " << i << ": " << sig->GetReturn() << "\n";
  }
  PrintF("%s", os.str().c_str());
}
#endif

}  // namespace wasm
}  // namespace internal
}  // namespace v8