Interpreter.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Bytecode/Block.h>
  7. #include <LibJS/Bytecode/Instruction.h>
  8. #include <LibJS/Bytecode/Interpreter.h>
  9. #include <LibJS/Runtime/GlobalObject.h>
  10. namespace JS::Bytecode {
  11. Interpreter::Interpreter(GlobalObject& global_object)
  12. : m_vm(global_object.vm())
  13. , m_global_object(global_object)
  14. {
  15. }
  16. Interpreter::~Interpreter()
  17. {
  18. }
  19. void Interpreter::run(Bytecode::Block const& block)
  20. {
  21. dbgln("Bytecode::Interpreter will run block {:p}", &block);
  22. m_registers.resize(block.register_count());
  23. for (auto& instruction : block.instructions())
  24. instruction.execute(*this);
  25. dbgln("Bytecode::Interpreter did run block {:p}", &block);
  26. for (size_t i = 0; i < m_registers.size(); ++i) {
  27. String value_string;
  28. if (m_registers[i].is_empty())
  29. value_string = "(empty)";
  30. else
  31. value_string = m_registers[i].to_string_without_side_effects();
  32. dbgln("[{:3}] {}", i, value_string);
  33. }
  34. }
  35. }