OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_WASM_SIGNATURE_MAP_H_ | 5 #ifndef V8_WASM_SIGNATURE_MAP_H_ |
6 #define V8_WASM_SIGNATURE_MAP_H_ | 6 #define V8_WASM_SIGNATURE_MAP_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "src/signature.h" | 10 #include "src/signature.h" |
11 #include "src/wasm/wasm-opcodes.h" | 11 #include "src/wasm/wasm-opcodes.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 namespace wasm { | 15 namespace wasm { |
16 | 16 |
17 // A signature map canonicalizes signatures into a range of indices so that | 17 // A signature map canonicalizes signatures into a range of indices so that |
18 // two different {FunctionSig} instances with the same contents map to the | 18 // two different {FunctionSig} instances with the same contents map to the |
19 // same index. | 19 // same index. |
20 class SignatureMap { | 20 class SignatureMap { |
21 public: | 21 public: |
22 // Gets the index for a signature, assigning a new index if necessary. | 22 // Gets the index for a signature, assigning a new index if necessary. |
23 uint32_t FindOrInsert(FunctionSig* sig); | 23 uint32_t FindOrInsert(FunctionSig* sig); |
24 | 24 |
25 // Gets the index for a signature, returning {-1} if not found. | 25 // Gets the index for a signature, returning {-1} if not found. |
26 int32_t Find(FunctionSig* sig) const; | 26 int32_t Find(FunctionSig* sig) const; |
27 | 27 |
28 // Compares two signatures for equality. | |
rossberg
2016/10/19 09:19:15
Shouldn't this better be a method of Signature?
| |
29 static bool Equal(FunctionSig* a, FunctionSig* b); | |
Mircea Trofin
2016/10/19 05:28:55
Did you mean "Equals" (or maybe "Is" or "AreEqual"
| |
30 | |
28 private: | 31 private: |
29 // TODO(wasm): use a hashmap instead of an ordered map? | 32 // TODO(wasm): use a hashmap instead of an ordered map? |
30 struct CompareFunctionSigs { | 33 struct CompareFunctionSigs { |
31 bool operator()(FunctionSig* a, FunctionSig* b) const; | 34 bool operator()(FunctionSig* a, FunctionSig* b) const; |
32 }; | 35 }; |
33 uint32_t next_ = 0; | 36 uint32_t next_ = 0; |
34 std::map<FunctionSig*, uint32_t, CompareFunctionSigs> map_; | 37 std::map<FunctionSig*, uint32_t, CompareFunctionSigs> map_; |
35 }; | 38 }; |
36 | 39 |
37 } // namespace wasm | 40 } // namespace wasm |
38 } // namespace internal | 41 } // namespace internal |
39 } // namespace v8 | 42 } // namespace v8 |
40 | 43 |
41 #endif // V8_WASM_SIGNATURE_MAP_H_ | 44 #endif // V8_WASM_SIGNATURE_MAP_H_ |
OLD | NEW |