BasicBlock.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Badge.h>
  8. #include <AK/DeprecatedString.h>
  9. #include <LibJS/Forward.h>
  10. #include <LibJS/Heap/Handle.h>
  11. namespace JS::Bytecode {
  12. struct UnwindInfo {
  13. Executable const* executable;
  14. BasicBlock const* handler;
  15. BasicBlock const* finalizer;
  16. JS::GCPtr<Environment> lexical_environment;
  17. bool handler_called { false };
  18. };
  19. class BasicBlock {
  20. AK_MAKE_NONCOPYABLE(BasicBlock);
  21. public:
  22. static NonnullOwnPtr<BasicBlock> create(DeprecatedString name);
  23. ~BasicBlock();
  24. void dump(Executable const&) const;
  25. ReadonlyBytes instruction_stream() const { return m_buffer.span(); }
  26. u8* data() { return m_buffer.data(); }
  27. u8 const* data() const { return m_buffer.data(); }
  28. size_t size() const { return m_buffer.size(); }
  29. void grow(size_t additional_size);
  30. void terminate(Badge<Generator>) { m_terminated = true; }
  31. bool is_terminated() const { return m_terminated; }
  32. DeprecatedString const& name() const { return m_name; }
  33. // ==============================================================
  34. // FIXME: This is JIT state and shouldn't be part of BasicBlock itself.
  35. // Offset into the instruction stream where this code block starts.
  36. size_t offset { 0 };
  37. // Offsets into the instruction stream where we have RIP-relative jump offsets to here that need patching.
  38. Vector<size_t> jumps_to_here;
  39. // Offsets into the instruction stream where we have absolute 64-bit references to here that need patching.
  40. Vector<size_t> absolute_references_to_here;
  41. // ==============================================================
  42. private:
  43. explicit BasicBlock(DeprecatedString name);
  44. Vector<u8> m_buffer;
  45. DeprecatedString m_name;
  46. bool m_terminated { false };
  47. };
  48. }