OLD | NEW |
(Empty) | |
| 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 #include "src/wasm/signature-map.h" |
| 6 |
| 7 namespace v8 { |
| 8 namespace internal { |
| 9 namespace wasm { |
| 10 |
| 11 uint32_t SignatureMap::FindOrInsert(FunctionSig* sig) { |
| 12 auto pos = map_.find(sig); |
| 13 if (pos != map_.end()) { |
| 14 return pos->second; |
| 15 } else { |
| 16 uint32_t index = next_++; |
| 17 map_[sig] = index; |
| 18 return index; |
| 19 } |
| 20 } |
| 21 |
| 22 int32_t SignatureMap::Find(FunctionSig* sig) const { |
| 23 auto pos = map_.find(sig); |
| 24 if (pos != map_.end()) { |
| 25 return static_cast<int32_t>(pos->second); |
| 26 } else { |
| 27 return -1; |
| 28 } |
| 29 } |
| 30 |
| 31 bool SignatureMap::CompareFunctionSigs::operator()(FunctionSig* a, |
| 32 FunctionSig* b) const { |
| 33 if (a == b) return false; |
| 34 if (a->return_count() < b->return_count()) return true; |
| 35 if (a->return_count() > b->return_count()) return false; |
| 36 if (a->parameter_count() < b->parameter_count()) return true; |
| 37 if (a->parameter_count() > b->parameter_count()) return false; |
| 38 for (size_t r = 0; r < a->return_count(); r++) { |
| 39 if (a->GetReturn(r) < b->GetReturn(r)) return true; |
| 40 if (a->GetReturn(r) > b->GetReturn(r)) return false; |
| 41 } |
| 42 for (size_t p = 0; p < a->parameter_count(); p++) { |
| 43 if (a->GetParam(p) < b->GetParam(p)) return true; |
| 44 if (a->GetParam(p) > b->GetParam(p)) return false; |
| 45 } |
| 46 return false; |
| 47 } |
| 48 |
| 49 } // namespace wasm |
| 50 } // namespace internal |
| 51 } // namespace v8 |
OLD | NEW |