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