Executable.h 2.3 KB

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