1 /* Copyright (c) 2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SIMGRID_MC_DWARF_EXPRESSION_HPP
8 #define SIMGRID_MC_DWARF_EXPRESSION_HPP
14 #include "src/mc/AddressSpace.hpp"
19 class evaluation_error : std::runtime_error {
21 evaluation_error(const char* what): std::runtime_error(what) {}
22 ~evaluation_error() noexcept(true);
25 struct ExpressionContext {
27 cursor(nullptr), frame_base(nullptr), address_space(nullptr),
28 object_info(nullptr), process_index(simgrid::mc::ProcessIndexMissing) {}
32 simgrid::mc::AddressSpace* address_space;
33 simgrid::mc::ObjectInformation* object_info;
37 typedef std::vector<Dwarf_Op> DwarfExpression;
39 class ExpressionStack {
41 typedef std::uintptr_t value_type;
42 static const std::size_t max_size = 64;
44 uintptr_t stack_[max_size];
47 ExpressionStack() : size_(0) {}
50 std::size_t size() const { return size_; }
51 bool empty() const { return size_ == 0; }
52 void clear() { size_ = 0; }
53 uintptr_t& operator[](int i) { return stack_[i]; }
54 uintptr_t const& operator[](int i) const { return stack_[i]; }
58 throw evaluation_error("Empty stack");
59 return stack_[size_ - 1];
61 value_type& top(unsigned i)
64 throw evaluation_error("Invalid element");
65 return stack_[size_ - 1 - i];
69 void push(value_type value)
71 if (size_ == max_size)
72 throw evaluation_error("Dwarf stack overflow");
73 stack_[size_++] = value;
78 throw evaluation_error("Stack underflow");
79 return stack_[--size_];
83 void dup() { push(top()); }
86 void execute(const Dwarf_Op* ops, std::size_t n,
87 ExpressionContext const& context, ExpressionStack& stack);
90 void execute(simgrid::dwarf::DwarfExpression const& expression,
91 ExpressionContext const& context, ExpressionStack& stack)
93 execute(expression.data(), expression.size(), context, stack);