NativeExecutable.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Noncopyable.h>
  8. #include <AK/Types.h>
  9. #include <LibJS/Runtime/Completion.h>
  10. namespace JS::JIT {
  11. struct BytecodeMapping {
  12. size_t native_offset;
  13. size_t block_index;
  14. size_t bytecode_offset;
  15. // Special block index for labels outside any blocks.
  16. static constexpr auto EXECUTABLE = NumericLimits<size_t>::max();
  17. static constexpr auto EXECUTABLE_LABELS = AK::Array { "entry"sv, "common_exit"sv };
  18. };
  19. class NativeExecutable {
  20. AK_MAKE_NONCOPYABLE(NativeExecutable);
  21. AK_MAKE_NONMOVABLE(NativeExecutable);
  22. public:
  23. NativeExecutable(void* code, size_t size, Vector<BytecodeMapping>);
  24. ~NativeExecutable();
  25. void run(VM&) const;
  26. void dump_disassembly(Bytecode::Executable const& executable) const;
  27. BytecodeMapping const& find_mapping_entry(size_t native_offset) const;
  28. ReadonlyBytes code_bytes() const { return { m_code, m_size }; }
  29. private:
  30. void* m_code { nullptr };
  31. size_t m_size { 0 };
  32. Vector<BytecodeMapping> m_mapping;
  33. };
  34. }