Executable.h 2.7 KB

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