ByteCodeStmtGen.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //===--- ByteCodeStmtGen.h - Code generator for expressions -----*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Defines the constexpr bytecode compiler.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_CLANG_AST_INTERP_BYTECODESTMTGEN_H
  13. #define LLVM_CLANG_AST_INTERP_BYTECODESTMTGEN_H
  14. #include "ByteCodeEmitter.h"
  15. #include "ByteCodeExprGen.h"
  16. #include "EvalEmitter.h"
  17. #include "Pointer.h"
  18. #include "PrimType.h"
  19. #include "Record.h"
  20. #include "clang/AST/Decl.h"
  21. #include "clang/AST/Expr.h"
  22. #include "clang/AST/StmtVisitor.h"
  23. namespace clang {
  24. namespace interp {
  25. template <class Emitter> class LoopScope;
  26. template <class Emitter> class SwitchScope;
  27. template <class Emitter> class LabelScope;
  28. /// Compilation context for statements.
  29. template <class Emitter>
  30. class ByteCodeStmtGen final : public ByteCodeExprGen<Emitter> {
  31. using LabelTy = typename Emitter::LabelTy;
  32. using AddrTy = typename Emitter::AddrTy;
  33. using OptLabelTy = std::optional<LabelTy>;
  34. using CaseMap = llvm::DenseMap<const SwitchCase *, LabelTy>;
  35. public:
  36. template<typename... Tys>
  37. ByteCodeStmtGen(Tys&&... Args)
  38. : ByteCodeExprGen<Emitter>(std::forward<Tys>(Args)...) {}
  39. protected:
  40. bool visitFunc(const FunctionDecl *F) override;
  41. private:
  42. friend class LabelScope<Emitter>;
  43. friend class LoopScope<Emitter>;
  44. friend class SwitchScope<Emitter>;
  45. // Statement visitors.
  46. bool visitStmt(const Stmt *S);
  47. bool visitCompoundStmt(const CompoundStmt *S);
  48. bool visitDeclStmt(const DeclStmt *DS);
  49. bool visitReturnStmt(const ReturnStmt *RS);
  50. bool visitIfStmt(const IfStmt *IS);
  51. bool visitWhileStmt(const WhileStmt *S);
  52. bool visitDoStmt(const DoStmt *S);
  53. bool visitForStmt(const ForStmt *S);
  54. bool visitBreakStmt(const BreakStmt *S);
  55. bool visitContinueStmt(const ContinueStmt *S);
  56. /// Type of the expression returned by the function.
  57. std::optional<PrimType> ReturnType;
  58. /// Switch case mapping.
  59. CaseMap CaseLabels;
  60. /// Point to break to.
  61. OptLabelTy BreakLabel;
  62. /// Point to continue to.
  63. OptLabelTy ContinueLabel;
  64. /// Default case label.
  65. OptLabelTy DefaultLabel;
  66. };
  67. extern template class ByteCodeExprGen<EvalEmitter>;
  68. } // namespace interp
  69. } // namespace clang
  70. #endif