NativeExecutable.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/FixedArray.h>
  8. #include <AK/Noncopyable.h>
  9. #include <AK/Types.h>
  10. #include <LibJS/Bytecode/Instruction.h>
  11. #include <LibJS/Runtime/Completion.h>
  12. namespace JS::JIT {
  13. struct BytecodeMapping {
  14. size_t native_offset;
  15. size_t block_index;
  16. size_t bytecode_offset;
  17. // Special block index for labels outside any blocks.
  18. static constexpr auto EXECUTABLE = NumericLimits<size_t>::max();
  19. static constexpr auto EXECUTABLE_LABELS = AK::Array { "entry"sv, "common_exit"sv };
  20. };
  21. class NativeExecutable {
  22. AK_MAKE_NONCOPYABLE(NativeExecutable);
  23. AK_MAKE_NONMOVABLE(NativeExecutable);
  24. public:
  25. NativeExecutable(void* code, size_t size, Vector<BytecodeMapping>, Optional<FixedArray<u8>> gdb_object = {});
  26. ~NativeExecutable();
  27. void run(VM&, size_t entry_point) const;
  28. void dump_disassembly(Bytecode::Executable const& executable) const;
  29. BytecodeMapping const& find_mapping_entry(size_t native_offset) const;
  30. Optional<UnrealizedSourceRange> get_source_range(Bytecode::Executable const& executable, FlatPtr address) const;
  31. ReadonlyBytes code_bytes() const { return { m_code, m_size }; }
  32. private:
  33. void* m_code { nullptr };
  34. size_t m_size { 0 };
  35. Vector<BytecodeMapping> m_mapping;
  36. Vector<FlatPtr> m_block_entry_points;
  37. mutable OwnPtr<Bytecode::InstructionStreamIterator> m_instruction_stream_iterator;
  38. Optional<FixedArray<u8>> m_gdb_object;
  39. };
  40. }