Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
internal_call_stack_manager.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4
5namespace bb::avm2::simulation {
6
16void InternalCallStackManager::push(PC caller_pc, PC return_pc)
17{
18 // Add the current call id & return_pc to the stack
19 internal_call_stack.push_back({ .return_call_id = return_call_id, .caller_pc = caller_pc, .return_pc = return_pc });
20
23 .entered_call_id = next_call_id,
24 .call_id = call_id,
25 .return_call_id = return_call_id,
26 .return_pc = return_pc,
27 });
28
29 // Update id values
33}
34
45{
46 if (internal_call_stack.empty()) {
47 throw InternalCallStackException("Internal call stack is empty. Cannot pop.");
48 }
49 // We need to restore the call ptr info to the previous call
50 const auto& prev_call_ptr = internal_call_stack.back();
51
52 // Reset the id values
54 return_call_id = prev_call_ptr.return_call_id;
55
56 internal_call_stack.pop_back();
57
58 // Return the next pc of the previous call
59 return prev_call_ptr.return_pc;
60}
61
71
81
91
98{
99 std::vector<PC> call_stack;
100 std::ranges::transform(internal_call_stack, std::back_inserter(call_stack), [](const InternalCallPtr& call_ptr) {
101 return call_ptr.caller_pc;
102 });
103 return call_stack;
104}
105
106} // namespace bb::avm2::simulation
InternalCallId get_call_id() const override
Get the current call id.
void push(PC caller_pc, PC return_pc) override
Push a new call onto the internal call stack. This is called when an internal call is executed....
InternalCallId get_next_call_id() const override
Get the next call id.
EventEmitterInterface< InternalCallStackEvent > & internal_call_stack_events
InternalCallId get_return_call_id() const override
Get the return call id.
PC pop() override
Pop the top call from the internal call stack. This is called when an internal return is executed....
std::vector< PC > get_current_call_stack() const override
Get the current call stack.
uint32_t PC
uint32_t InternalCallId
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13