Executable.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/DeprecatedFlyString.h>
  8. #include <AK/HashMap.h>
  9. #include <AK/NonnullOwnPtr.h>
  10. #include <AK/OwnPtr.h>
  11. #include <AK/WeakPtr.h>
  12. #include <LibJS/Bytecode/IdentifierTable.h>
  13. #include <LibJS/Bytecode/Label.h>
  14. #include <LibJS/Bytecode/StringTable.h>
  15. #include <LibJS/Forward.h>
  16. #include <LibJS/Runtime/EnvironmentCoordinate.h>
  17. namespace JS::JIT {
  18. class NativeExecutable;
  19. }
  20. namespace JS::Bytecode {
  21. struct PropertyLookupCache {
  22. WeakPtr<Shape> shape;
  23. Optional<u32> property_offset;
  24. u64 unique_shape_serial_number { 0 };
  25. };
  26. struct GlobalVariableCache : public PropertyLookupCache {
  27. u64 environment_serial_number { 0 };
  28. };
  29. using EnvironmentVariableCache = Optional<EnvironmentCoordinate>;
  30. struct SourceRecord {
  31. u32 source_start_offset {};
  32. u32 source_end_offset {};
  33. };
  34. class Executable final : public RefCounted<Executable> {
  35. public:
  36. Executable(
  37. NonnullOwnPtr<IdentifierTable>,
  38. NonnullOwnPtr<StringTable>,
  39. NonnullOwnPtr<RegexTable>,
  40. NonnullRefPtr<SourceCode const>,
  41. size_t number_of_property_lookup_caches,
  42. size_t number_of_global_variable_caches,
  43. size_t number_of_environment_variable_caches,
  44. size_t number_of_registers,
  45. Vector<NonnullOwnPtr<BasicBlock>>,
  46. bool is_strict_mode);
  47. ~Executable();
  48. DeprecatedFlyString name;
  49. Vector<PropertyLookupCache> property_lookup_caches;
  50. Vector<GlobalVariableCache> global_variable_caches;
  51. Vector<EnvironmentVariableCache> environment_variable_caches;
  52. Vector<NonnullOwnPtr<BasicBlock>> basic_blocks;
  53. NonnullOwnPtr<StringTable> string_table;
  54. NonnullOwnPtr<IdentifierTable> identifier_table;
  55. NonnullOwnPtr<RegexTable> regex_table;
  56. NonnullRefPtr<SourceCode const> source_code;
  57. size_t number_of_registers { 0 };
  58. bool is_strict_mode { false };
  59. DeprecatedString const& get_string(StringTableIndex index) const { return string_table->get(index); }
  60. DeprecatedFlyString const& get_identifier(IdentifierTableIndex index) const { return identifier_table->get(index); }
  61. void dump() const;
  62. JIT::NativeExecutable const* get_or_create_native_executable();
  63. JIT::NativeExecutable const* native_executable() const { return m_native_executable; }
  64. private:
  65. OwnPtr<JIT::NativeExecutable> m_native_executable;
  66. bool m_did_try_jitting { false };
  67. };
  68. }