Executable.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. Executable::Executable(
  12. NonnullOwnPtr<IdentifierTable> identifier_table,
  13. NonnullOwnPtr<StringTable> string_table,
  14. NonnullOwnPtr<RegexTable> regex_table,
  15. NonnullRefPtr<SourceCode const> source_code,
  16. size_t number_of_property_lookup_caches,
  17. size_t number_of_global_variable_caches,
  18. size_t number_of_environment_variable_caches,
  19. size_t number_of_registers,
  20. Vector<NonnullOwnPtr<BasicBlock>> basic_blocks,
  21. bool is_strict_mode)
  22. : basic_blocks(move(basic_blocks))
  23. , string_table(move(string_table))
  24. , identifier_table(move(identifier_table))
  25. , regex_table(move(regex_table))
  26. , source_code(move(source_code))
  27. , number_of_registers(number_of_registers)
  28. , is_strict_mode(is_strict_mode)
  29. {
  30. property_lookup_caches.resize(number_of_property_lookup_caches);
  31. global_variable_caches.resize(number_of_global_variable_caches);
  32. environment_variable_caches.resize(number_of_environment_variable_caches);
  33. }
  34. Executable::~Executable() = default;
  35. void Executable::dump() const
  36. {
  37. dbgln("\033[33;1mJS::Bytecode::Executable\033[0m ({})", name);
  38. for (auto& block : basic_blocks)
  39. block->dump(*this);
  40. if (!string_table->is_empty()) {
  41. outln();
  42. string_table->dump();
  43. }
  44. if (!identifier_table->is_empty()) {
  45. outln();
  46. identifier_table->dump();
  47. }
  48. }
  49. }