CompilationPipeline.h 901 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/Function.h>
  8. #include <AK/StringView.h>
  9. #include "Forward.h"
  10. namespace JSSpecCompiler {
  11. class CompilationStep {
  12. public:
  13. CompilationStep(StringView name)
  14. : m_name(name)
  15. {
  16. }
  17. virtual ~CompilationStep() = default;
  18. virtual void run(TranslationUnitRef translation_unit) = 0;
  19. StringView name() const { return m_name; }
  20. private:
  21. StringView m_name;
  22. };
  23. class NonOwningCompilationStep : public CompilationStep {
  24. public:
  25. template<typename Func>
  26. NonOwningCompilationStep(StringView name, Func&& func)
  27. : CompilationStep(name)
  28. , m_func(func)
  29. {
  30. }
  31. void run(TranslationUnitRef translation_unit) override { m_func(translation_unit); }
  32. private:
  33. AK::Function<void(TranslationUnitRef)> m_func;
  34. };
  35. }