V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
signature-map.h
1 // Copyright 2016 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_SIGNATURE_MAP_H_
6 #define V8_WASM_SIGNATURE_MAP_H_
7 
8 #include <unordered_map>
9 
10 #include "src/signature.h"
11 #include "src/wasm/value-type.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 namespace wasm {
17 
18 // A signature map canonicalizes signatures into a range of indices so that
19 // two different {FunctionSig} instances with the same contents map to the
20 // same index.
21 class V8_EXPORT_PRIVATE SignatureMap {
22  public:
23  // Allow default construction and move construction (because we have vectors
24  // of objects containing SignatureMaps), but disallow copy or assign. It's
25  // too easy to get security bugs by accidentally updating a copy of the map.
26  MOVE_ONLY_WITH_DEFAULT_CONSTRUCTORS(SignatureMap);
27 
28  // Gets the index for a signature, assigning a new index if necessary.
29  uint32_t FindOrInsert(const FunctionSig& sig);
30 
31  // Gets the index for a signature, returning {-1} if not found.
32  int32_t Find(const FunctionSig& sig) const;
33 
34  // Disallows further insertions to this signature map.
35  void Freeze() { frozen_ = true; }
36 
37  private:
38  bool frozen_ = false;
39  std::unordered_map<FunctionSig, uint32_t, base::hash<FunctionSig>> map_;
40 };
41 
42 } // namespace wasm
43 } // namespace internal
44 } // namespace v8
45 
46 #endif // V8_WASM_SIGNATURE_MAP_H_
Definition: libplatform.h:13