Executable.h 2.6 KB

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