chromium/v8/src/utils/address-map.h

// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_UTILS_ADDRESS_MAP_H_
#define V8_UTILS_ADDRESS_MAP_H_

#include "src/base/hashmap.h"
#include "src/common/assert-scope.h"
#include "src/objects/heap-object.h"
#include "src/roots/roots.h"

namespace v8 {
namespace internal {

template <typename Type>
class PointerToIndexHashMap
    : public base::TemplateHashMapImpl<uintptr_t, uint32_t,
                                       base::KeyEqualityMatcher<intptr_t>,
                                       base::DefaultAllocationPolicy> {};

template <>
inline uintptr_t PointerToIndexHashMap<Address>::Key(Address value) {
  return static_cast<uintptr_t>(value);
}

template <>
inline uintptr_t PointerToIndexHashMap<Tagged<HeapObject>>::Key(
    Tagged<HeapObject> value) {
  return value.ptr();
}

class AddressToIndexHashMap : public PointerToIndexHashMap<Address> {};
class HeapObjectToIndexHashMap
    : public PointerToIndexHashMap<Tagged<HeapObject>> {};

class RootIndexMap {};

}  // namespace internal
}  // namespace v8

#endif  // V8_UTILS_ADDRESS_MAP_H_