Executable.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/Heap/Cell.h>
  17. #include <LibJS/Heap/CellAllocator.h>
  18. #include <LibJS/Runtime/EnvironmentCoordinate.h>
  19. namespace JS::JIT {
  20. class NativeExecutable;
  21. }
  22. namespace JS::Bytecode {
  23. struct PropertyLookupCache {
  24. static FlatPtr shape_offset() { return OFFSET_OF(PropertyLookupCache, shape); }
  25. static FlatPtr property_offset_offset() { return OFFSET_OF(PropertyLookupCache, property_offset); }
  26. WeakPtr<Shape> shape;
  27. Optional<u32> property_offset;
  28. };
  29. struct GlobalVariableCache : public PropertyLookupCache {
  30. static FlatPtr environment_serial_number_offset() { return OFFSET_OF(GlobalVariableCache, environment_serial_number); }
  31. u64 environment_serial_number { 0 };
  32. };
  33. using EnvironmentVariableCache = Optional<EnvironmentCoordinate>;
  34. struct SourceRecord {
  35. u32 source_start_offset {};
  36. u32 source_end_offset {};
  37. };
  38. class Executable final : public Cell {
  39. JS_CELL(Executable, Cell);
  40. JS_DECLARE_ALLOCATOR(Executable);
  41. public:
  42. Executable(
  43. NonnullOwnPtr<IdentifierTable>,
  44. NonnullOwnPtr<StringTable>,
  45. NonnullOwnPtr<RegexTable>,
  46. NonnullRefPtr<SourceCode const>,
  47. size_t number_of_property_lookup_caches,
  48. size_t number_of_global_variable_caches,
  49. size_t number_of_environment_variable_caches,
  50. size_t number_of_registers,
  51. Vector<NonnullOwnPtr<BasicBlock>>,
  52. bool is_strict_mode);
  53. virtual ~Executable() override;
  54. DeprecatedFlyString name;
  55. Vector<PropertyLookupCache> property_lookup_caches;
  56. Vector<GlobalVariableCache> global_variable_caches;
  57. Vector<EnvironmentVariableCache> environment_variable_caches;
  58. Vector<NonnullOwnPtr<BasicBlock>> basic_blocks;
  59. NonnullOwnPtr<StringTable> string_table;
  60. NonnullOwnPtr<IdentifierTable> identifier_table;
  61. NonnullOwnPtr<RegexTable> regex_table;
  62. NonnullRefPtr<SourceCode const> source_code;
  63. size_t number_of_registers { 0 };
  64. bool is_strict_mode { false };
  65. ByteString const& get_string(StringTableIndex index) const { return string_table->get(index); }
  66. DeprecatedFlyString const& get_identifier(IdentifierTableIndex index) const { return identifier_table->get(index); }
  67. void dump() const;
  68. JIT::NativeExecutable const* get_or_create_native_executable();
  69. JIT::NativeExecutable const* native_executable() const { return m_native_executable; }
  70. private:
  71. OwnPtr<JIT::NativeExecutable> m_native_executable;
  72. bool m_did_try_jitting { false };
  73. };
  74. }