Executable.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2021-2024, 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::Bytecode {
  20. struct PropertyLookupCache {
  21. WeakPtr<Shape> shape;
  22. Optional<u32> property_offset;
  23. };
  24. struct GlobalVariableCache : public PropertyLookupCache {
  25. u64 environment_serial_number { 0 };
  26. };
  27. using EnvironmentVariableCache = Optional<EnvironmentCoordinate>;
  28. struct SourceRecord {
  29. u32 source_start_offset {};
  30. u32 source_end_offset {};
  31. };
  32. class Executable final : public Cell {
  33. JS_CELL(Executable, Cell);
  34. JS_DECLARE_ALLOCATOR(Executable);
  35. public:
  36. Executable(
  37. NonnullOwnPtr<IdentifierTable>,
  38. NonnullOwnPtr<StringTable>,
  39. NonnullOwnPtr<RegexTable>,
  40. Vector<Value> constants,
  41. NonnullRefPtr<SourceCode const>,
  42. size_t number_of_property_lookup_caches,
  43. size_t number_of_global_variable_caches,
  44. size_t number_of_environment_variable_caches,
  45. size_t number_of_registers,
  46. Vector<NonnullOwnPtr<BasicBlock>>,
  47. bool is_strict_mode);
  48. virtual ~Executable() override;
  49. DeprecatedFlyString name;
  50. Vector<PropertyLookupCache> property_lookup_caches;
  51. Vector<GlobalVariableCache> global_variable_caches;
  52. Vector<EnvironmentVariableCache> environment_variable_caches;
  53. Vector<NonnullOwnPtr<BasicBlock>> basic_blocks;
  54. NonnullOwnPtr<StringTable> string_table;
  55. NonnullOwnPtr<IdentifierTable> identifier_table;
  56. NonnullOwnPtr<RegexTable> regex_table;
  57. Vector<Value> constants;
  58. NonnullRefPtr<SourceCode const> source_code;
  59. size_t number_of_registers { 0 };
  60. bool is_strict_mode { false };
  61. ByteString const& get_string(StringTableIndex index) const { return string_table->get(index); }
  62. DeprecatedFlyString const& get_identifier(IdentifierTableIndex index) const { return identifier_table->get(index); }
  63. void dump() const;
  64. private:
  65. virtual void visit_edges(Visitor&) override;
  66. };
  67. }