Configuration.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWasm/AbstractMachine/AbstractMachine.h>
  8. namespace Wasm {
  9. class Configuration {
  10. public:
  11. explicit Configuration(Store& store)
  12. : m_store(store)
  13. {
  14. }
  15. Optional<Label> nth_label(size_t);
  16. void set_frame(Frame&& frame)
  17. {
  18. m_current_frame_index = m_stack.size();
  19. Label label(frame.arity(), frame.expression().instructions().size());
  20. m_stack.push(move(frame));
  21. m_stack.push(label);
  22. }
  23. auto& frame() const { return m_stack.entries()[m_current_frame_index].get<Frame>(); }
  24. auto& frame() { return m_stack.entries()[m_current_frame_index].get<Frame>(); }
  25. auto& ip() const { return m_ip; }
  26. auto& ip() { return m_ip; }
  27. auto& depth() const { return m_depth; }
  28. auto& depth() { return m_depth; }
  29. auto& stack() const { return m_stack; }
  30. auto& stack() { return m_stack; }
  31. auto& store() const { return m_store; }
  32. auto& store() { return m_store; }
  33. Result call(FunctionAddress, Vector<Value> arguments);
  34. Result execute();
  35. void dump_stack();
  36. Function<bool(Configuration&, InstructionPointer&, const Instruction&)>* pre_interpret_hook { nullptr };
  37. Function<bool(Configuration&, InstructionPointer&, const Instruction&, const Interpreter&)>* post_interpret_hook { nullptr };
  38. private:
  39. Store& m_store;
  40. size_t m_current_frame_index { 0 };
  41. Stack m_stack;
  42. size_t m_depth { 0 };
  43. InstructionPointer m_ip;
  44. };
  45. }