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