11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_CODEGEN_EXTERNAL_REFERENCE_ENCODER_H_ 61cb0ef41Sopenharmony_ci#define V8_CODEGEN_EXTERNAL_REFERENCE_ENCODER_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/base/bit-field.h" 91cb0ef41Sopenharmony_ci#include "src/common/globals.h" 101cb0ef41Sopenharmony_ci#include "src/utils/address-map.h" 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cinamespace v8 { 131cb0ef41Sopenharmony_cinamespace internal { 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciclass Isolate; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciclass ExternalReferenceEncoder { 181cb0ef41Sopenharmony_ci public: 191cb0ef41Sopenharmony_ci class Value { 201cb0ef41Sopenharmony_ci public: 211cb0ef41Sopenharmony_ci explicit Value(uint32_t raw) : value_(raw) {} 221cb0ef41Sopenharmony_ci Value() : value_(0) {} 231cb0ef41Sopenharmony_ci static uint32_t Encode(uint32_t index, bool is_from_api) { 241cb0ef41Sopenharmony_ci return Index::encode(index) | IsFromAPI::encode(is_from_api); 251cb0ef41Sopenharmony_ci } 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci bool is_from_api() const { return IsFromAPI::decode(value_); } 281cb0ef41Sopenharmony_ci uint32_t index() const { return Index::decode(value_); } 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci private: 311cb0ef41Sopenharmony_ci using Index = base::BitField<uint32_t, 0, 31>; 321cb0ef41Sopenharmony_ci using IsFromAPI = base::BitField<bool, 31, 1>; 331cb0ef41Sopenharmony_ci uint32_t value_; 341cb0ef41Sopenharmony_ci }; 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci explicit ExternalReferenceEncoder(Isolate* isolate); 371cb0ef41Sopenharmony_ci ExternalReferenceEncoder(const ExternalReferenceEncoder&) = delete; 381cb0ef41Sopenharmony_ci ExternalReferenceEncoder& operator=(const ExternalReferenceEncoder&) = delete; 391cb0ef41Sopenharmony_ci#ifdef DEBUG 401cb0ef41Sopenharmony_ci ~ExternalReferenceEncoder(); 411cb0ef41Sopenharmony_ci#endif // DEBUG 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci Value Encode(Address key); 441cb0ef41Sopenharmony_ci Maybe<Value> TryEncode(Address key); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci const char* NameOfAddress(Isolate* isolate, Address address) const; 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci private: 491cb0ef41Sopenharmony_ci AddressToIndexHashMap* map_; 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci#ifdef DEBUG 521cb0ef41Sopenharmony_ci std::vector<int> count_; 531cb0ef41Sopenharmony_ci const intptr_t* api_references_; 541cb0ef41Sopenharmony_ci#endif // DEBUG 551cb0ef41Sopenharmony_ci}; 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci} // namespace internal 581cb0ef41Sopenharmony_ci} // namespace v8 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ci#endif // V8_CODEGEN_EXTERNAL_REFERENCE_ENCODER_H_ 61