Executable.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Bytecode/BasicBlock.h>
  7. #include <LibJS/Bytecode/Executable.h>
  8. #include <LibJS/Bytecode/RegexTable.h>
  9. #include <LibJS/SourceCode.h>
  10. namespace JS::Bytecode {
  11. JS_DEFINE_ALLOCATOR(Executable);
  12. Executable::Executable(
  13. NonnullOwnPtr<IdentifierTable> identifier_table,
  14. NonnullOwnPtr<StringTable> string_table,
  15. NonnullOwnPtr<RegexTable> regex_table,
  16. Vector<Value> constants,
  17. NonnullRefPtr<SourceCode const> source_code,
  18. size_t number_of_property_lookup_caches,
  19. size_t number_of_global_variable_caches,
  20. size_t number_of_environment_variable_caches,
  21. size_t number_of_registers,
  22. Vector<NonnullOwnPtr<BasicBlock>> basic_blocks,
  23. bool is_strict_mode)
  24. : basic_blocks(move(basic_blocks))
  25. , string_table(move(string_table))
  26. , identifier_table(move(identifier_table))
  27. , regex_table(move(regex_table))
  28. , constants(move(constants))
  29. , source_code(move(source_code))
  30. , number_of_registers(number_of_registers)
  31. , is_strict_mode(is_strict_mode)
  32. {
  33. property_lookup_caches.resize(number_of_property_lookup_caches);
  34. global_variable_caches.resize(number_of_global_variable_caches);
  35. environment_variable_caches.resize(number_of_environment_variable_caches);
  36. }
  37. Executable::~Executable() = default;
  38. void Executable::dump() const
  39. {
  40. warnln("\033[37;1mJS bytecode executable\033[0m \"{}\"", name);
  41. for (auto& block : basic_blocks)
  42. block->dump(*this);
  43. warnln("");
  44. }
  45. void Executable::visit_edges(Visitor& visitor)
  46. {
  47. Base::visit_edges(visitor);
  48. visitor.visit(constants);
  49. }
  50. }