ControlFlowGraph.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/RefCounted.h>
  8. #include <AK/RefPtr.h>
  9. #include <AK/Vector.h>
  10. #include "Forward.h"
  11. namespace JSSpecCompiler {
  12. class BasicBlock : public RefCounted<BasicBlock> {
  13. public:
  14. BasicBlock(size_t index, NonnullRefPtr<ControlFlowOperator> continuation)
  15. : m_index(index)
  16. , m_continuation(move(continuation))
  17. {
  18. }
  19. size_t m_index;
  20. Vector<Tree> m_expressions;
  21. NonnullRefPtr<ControlFlowOperator> m_continuation;
  22. };
  23. class ControlFlowGraph : public RefCounted<ControlFlowGraph> {
  24. public:
  25. ControlFlowGraph() { }
  26. size_t blocks_count() const { return blocks.size(); }
  27. Vector<NonnullRefPtr<BasicBlock>> blocks;
  28. BasicBlockRef start_block;
  29. BasicBlockRef end_block;
  30. };
  31. }
  32. namespace AK {
  33. template<>
  34. struct Formatter<JSSpecCompiler::ControlFlowGraph> : Formatter<StringView> {
  35. ErrorOr<void> format(FormatBuilder& builder, JSSpecCompiler::ControlFlowGraph const& control_flow_graph);
  36. };
  37. }