clang 20.0.0git
InterpStack.h
Go to the documentation of this file.
1//===--- InterpStack.h - Stack implementation for the VM --------*- 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 upwards-growing stack used by the interpreter.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_INTERP_INTERPSTACK_H
14#define LLVM_CLANG_AST_INTERP_INTERPSTACK_H
15
16#include "FixedPoint.h"
17#include "FunctionPointer.h"
18#include "IntegralAP.h"
19#include "MemberPointer.h"
20#include "PrimType.h"
21#include <memory>
22#include <vector>
23
24namespace clang {
25namespace interp {
26
27/// Stack frame storing temporaries and parameters.
28class InterpStack final {
29public:
31
32 /// Destroys the stack, freeing up storage.
34
35 /// Constructs a value in place on the top of the stack.
36 template <typename T, typename... Tys> void push(Tys &&...Args) {
37 new (grow(aligned_size<T>())) T(std::forward<Tys>(Args)...);
38#ifndef NDEBUG
39 ItemTypes.push_back(toPrimType<T>());
40#endif
41 }
42
43 /// Returns the value from the top of the stack and removes it.
44 template <typename T> T pop() {
45#ifndef NDEBUG
46 assert(!ItemTypes.empty());
47 assert(ItemTypes.back() == toPrimType<T>());
48 ItemTypes.pop_back();
49#endif
50 T *Ptr = &peekInternal<T>();
51