v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-arguments.h
Go to the documentation of this file.
1// Copyright 2019 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#ifndef V8_WASM_WASM_ARGUMENTS_H_
6#define V8_WASM_WASM_ARGUMENTS_H_
7
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
10#endif // !V8_ENABLE_WEBASSEMBLY
11
12#include <stdint.h>
13#include <vector>
14
15#include "src/base/memory.h"
17#include "src/common/globals.h"
18#include "src/wasm/value-type.h"
19
20namespace v8 {
21namespace internal {
22namespace wasm {
23
24// Helper class for {Push}ing Wasm value arguments onto the stack in the format
25// that the CWasmEntryStub expects, as well as for {Pop}ping return values.
26// {Reset} must be called if a packer instance used for pushing is then
27// reused for popping: it resets the internal pointer to the beginning of
28// the stack region.
30 public:
31 explicit CWasmArgumentsPacker(size_t buffer_size)
32 : heap_buffer_(buffer_size <= kMaxOnStackBuffer ? 0 : buffer_size),
34 : heap_buffer_.data()) {}
35 i::Address argv() const { return reinterpret_cast<i::Address>(buffer_); }
36 void Reset() { offset_ = 0; }
37
38 template <typename T>
39 void Push(T val) {
40 Address address = reinterpret_cast<Address>(buffer_ + offset_);
41 offset_ += sizeof(val);
42 base::WriteUnalignedValue(address, val);
43 }
44
45 template <typename T>
46 T Pop() {
47 Address address = reinterpret_cast<Address>(buffer_ + offset_);
48 offset_ += sizeof(T);
49 return base::ReadUnalignedValue<T>(address);
50 }
51
52 static int TotalSize(const CanonicalSig* sig) {
53 int return_size = 0;
54 for (CanonicalValueType t : sig->returns()) {
55 return_size += t.value_kind_full_size();
56 }
57 int param_size = 0;
58 for (CanonicalValueType t : sig->parameters()) {
59 param_size += t.value_kind_full_size();
60 }
61 return std::max(return_size, param_size);
62 }
63
64 private:
65 static const size_t kMaxOnStackBuffer = 10 * i::kSystemPointerSize;
66
68 std::vector<uint8_t> heap_buffer_;
69 uint8_t* buffer_;
70 size_t offset_ = 0;
71};
72
73} // namespace wasm
74} // namespace internal
75} // namespace v8
76
77#endif // V8_WASM_WASM_ARGUMENTS_H_
#define T
static int TotalSize(const CanonicalSig *sig)
uint8_t on_stack_buffer_[kMaxOnStackBuffer]
static V ReadUnalignedValue(Address p)
Definition memory.h:28
static void WriteUnalignedValue(Address p, V value)
Definition memory.h:41
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig
constexpr int kSystemPointerSize
Definition globals.h:410
Definition c-api.cc:87