1 //===--- Context.h - Context for the constexpr VM ---------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Defines the constexpr execution context.
11 // The execution context manages cached bytecode and the global context.
12 // It invokes the compiler and interpreter, propagating errors.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_AST_INTERP_CONTEXT_H
17 #define LLVM_CLANG_AST_INTERP_CONTEXT_H
20 #include "InterpStack.h"
21 #include "clang/AST/APValue.h"
22 #include "llvm/ADT/PointerIntPair.h"
35 enum PrimType : unsigned;
37 /// Holds all information required to evaluate constexpr code in a module.
40 /// Initialises the constexpr VM.
41 Context(ASTContext &Ctx);
43 /// Cleans up the constexpr VM.
46 /// Checks if a function is a potential constant expression.
47 bool isPotentialConstantExpr(State &Parent, const FunctionDecl *FnDecl);
49 /// Evaluates a toplevel expression as an rvalue.
50 bool evaluateAsRValue(State &Parent, const Expr *E, APValue &Result);
52 /// Evaluates a toplevel initializer.
53 bool evaluateAsInitializer(State &Parent, const VarDecl *VD, APValue &Result);
55 /// Returns the AST context.
56 ASTContext &getASTContext() const { return Ctx; }
57 /// Returns the language options.
58 const LangOptions &getLangOpts() const;
59 /// Returns the interpreter stack.
60 InterpStack &getStack() { return Stk; }
62 unsigned getCharBit() const;
64 /// Classifies an expression.
65 llvm::Optional<PrimType> classify(QualType T);
69 bool Run(State &Parent, Function *Func, APValue &Result);
71 /// Checks a result fromt the interpreter.
72 bool Check(State &Parent, llvm::Expected<bool> &&R);
75 /// Current compilation context.
77 /// Interpreter stack, shared across invocations.
79 /// Constexpr program.
80 std::unique_ptr<Program> P;