Executable.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/NonnullOwnPtr.h>
  9. #include <AK/OwnPtr.h>
  10. #include <AK/WeakPtr.h>
  11. #include <LibJS/Bytecode/IdentifierTable.h>
  12. #include <LibJS/Bytecode/StringTable.h>
  13. #include <LibJS/Forward.h>
  14. #include <LibJS/JIT/NativeExecutable.h>
  15. #include <LibJS/Runtime/EnvironmentCoordinate.h>
  16. namespace JS::Bytecode {
  17. struct PropertyLookupCache {
  18. WeakPtr<Shape> shape;
  19. Optional<u32> property_offset;
  20. u64 unique_shape_serial_number { 0 };
  21. };
  22. struct GlobalVariableCache : public PropertyLookupCache {
  23. u64 environment_serial_number { 0 };
  24. };
  25. struct SourceRecord {
  26. u32 source_start_offset {};
  27. u32 source_end_offset {};
  28. };
  29. class Executable final : public RefCounted<Executable> {
  30. public:
  31. Executable(
  32. NonnullOwnPtr<IdentifierTable>,
  33. NonnullOwnPtr<StringTable>,
  34. NonnullOwnPtr<RegexTable>,
  35. NonnullRefPtr<SourceCode const>,
  36. size_t number_of_property_lookup_caches,
  37. size_t number_of_global_variable_caches,
  38. size_t number_of_environment_variable_caches,
  39. size_t number_of_registers,
  40. Vector<NonnullOwnPtr<BasicBlock>>,
  41. bool is_strict_mode);
  42. ~Executable();
  43. DeprecatedFlyString name;
  44. Vector<PropertyLookupCache> property_lookup_caches;
  45. Vector<GlobalVariableCache> global_variable_caches;
  46. Vector<Optional<EnvironmentCoordinate>> environment_variable_caches;
  47. Vector<NonnullOwnPtr<BasicBlock>> basic_blocks;
  48. NonnullOwnPtr<StringTable> string_table;
  49. NonnullOwnPtr<IdentifierTable> identifier_table;
  50. NonnullOwnPtr<RegexTable> regex_table;
  51. NonnullRefPtr<SourceCode const> source_code;
  52. size_t number_of_registers { 0 };
  53. bool is_strict_mode { false };
  54. DeprecatedString const& get_string(StringTableIndex index) const { return string_table->get(index); }
  55. DeprecatedFlyString const& get_identifier(IdentifierTableIndex index) const { return identifier_table->get(index); }
  56. void dump() const;
  57. JIT::NativeExecutable const* get_or_create_native_executable();
  58. private:
  59. OwnPtr<JIT::NativeExecutable> m_native_executable;
  60. bool m_did_try_jitting { false };
  61. };
  62. }