v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
constant-expression-interface.h
Go to the documentation of this file.
1// Copyright 2021 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_CONSTANT_EXPRESSION_INTERFACE_H_
6#define V8_WASM_CONSTANT_EXPRESSION_INTERFACE_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 "src/wasm/decoder.h"
14#include "src/wasm/wasm-value.h"
15
16namespace v8 {
17namespace internal {
18
20class JSArrayBuffer;
21
22namespace wasm {
23
24// An interface for WasmFullDecoder used to decode constant expressions.
25// This interface has two modes: only validation (when {isolate_ == nullptr}),
26// and code-generation (when {isolate_ != nullptr}). We merge two distinct
27// functionalities in one class to reduce the number of WasmFullDecoder
28// instantiations, and thus V8 binary code size.
29// In code-generation mode, the result can be retrieved with {computed_value()}
30// if {!has_error()}, or with {error()} otherwise.
32 public:
34 static constexpr DecodingMode decoding_mode = kConstantExpression;
35 static constexpr bool kUsesPoppedArgs = true;
36
37 struct Value : public ValueBase<ValidationTag> {
39
40 template <typename... Args>
41 explicit Value(Args&&... args) V8_NOEXCEPT
42 : ValueBase(std::forward<Args>(args)...) {}
43 };
44
48 decoding_mode>;
49
51 const WasmModule* module, Isolate* isolate,
52 DirectHandle<WasmTrustedInstanceData> trusted_instance_data,
53 DirectHandle<WasmTrustedInstanceData> shared_trusted_instance_data)
54 : module_(module),
55 outer_module_(nullptr),
56 isolate_(isolate),
57 trusted_instance_data_(trusted_instance_data),
58 shared_trusted_instance_data_(shared_trusted_instance_data) {
59 DCHECK_NOT_NULL(isolate);
60 }
61
63 : module_(nullptr), outer_module_(outer_module), isolate_(nullptr) {}
64
65#define EMPTY_INTERFACE_FUNCTION(name, ...) \
66 V8_INLINE void name(FullDecoder* decoder, ##__VA_ARGS__) {}
68#undef EMPTY_INTERFACE_FUNCTION
69#define UNREACHABLE_INTERFACE_FUNCTION(name, ...) \
70 V8_INLINE void name(FullDecoder* decoder, ##__VA_ARGS__) { UNREACHABLE(); }
72#undef UNREACHABLE_INTERFACE_FUNCTION
73
74#define DECLARE_INTERFACE_FUNCTION(name, ...) \
75 void name(FullDecoder* decoder, ##__VA_ARGS__);
77#undef DECLARE_INTERFACE_FUNCTION
78
80 DCHECK(generate_value());
81 // The value has to be initialized.
82 DCHECK_NE(computed_value_.type(), kWasmVoid);
83 return computed_value_;
84 }
85 bool end_found() const { return end_found_; }
86 bool has_error() const { return error_ != MessageTemplate::kNone; }
88 DCHECK(has_error());
89 DCHECK_EQ(computed_value_.type(), kWasmVoid);
90 return error_;
91 }
92
93 private:
94 bool generate_value() const { return isolate_ != nullptr && !has_error(); }
95 DirectHandle<WasmTrustedInstanceData> GetTrustedInstanceDataForTypeIndex(
96 ModuleTypeIndex index);
97
99 ModuleTypeIndex index, const TypeDefinition& type,
100 const Value& descriptor);
101
102 bool end_found_ = false;
104 MessageTemplate error_ = MessageTemplate::kNone;
110};
111
112} // namespace wasm
113} // namespace internal
114} // namespace v8
115
116#endif // V8_WASM_CONSTANT_EXPRESSION_INTERFACE_H_
Isolate * isolate_
DirectHandle< WasmTrustedInstanceData > trusted_instance_data_
ConstantExpressionInterface(const WasmModule *module, Isolate *isolate, DirectHandle< WasmTrustedInstanceData > trusted_instance_data, DirectHandle< WasmTrustedInstanceData > shared_trusted_instance_data)
DirectHandle< WasmTrustedInstanceData > shared_trusted_instance_data_
#define UNREACHABLE_INTERFACE_FUNCTION(name,...)
#define DECLARE_INTERFACE_FUNCTION(name,...)
#define EMPTY_INTERFACE_FUNCTION(name,...)
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
#define INTERFACE_META_FUNCTIONS(F)
#define INTERFACE_NON_CONSTANT_FUNCTIONS(F)
#define INTERFACE_CONSTANT_FUNCTIONS(F)
static constexpr bool kUsesPoppedArgs
constexpr IndependentHeapType kWasmVoid
kWasmInternalFunctionIndirectPointerTag WasmTrustedInstanceData
Definition c-api.cc:87
RegExpError error_
#define V8_NOEXCEPT
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_EXPORT_PRIVATE
Definition macros.h:460
const wasm::WasmModule * module_