Executable.h 2.4 KB

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