Executable.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/JIT/Compiler.h>
  10. #include <LibJS/SourceCode.h>
  11. namespace JS::Bytecode {
  12. Executable::Executable(
  13. NonnullOwnPtr<IdentifierTable> identifier_table,
  14. NonnullOwnPtr<StringTable> string_table,
  15. NonnullOwnPtr<RegexTable> regex_table,
  16. NonnullRefPtr<SourceCode const> source_code,
  17. size_t number_of_property_lookup_caches,
  18. size_t number_of_global_variable_caches,
  19. size_t number_of_environment_variable_caches,
  20. size_t number_of_registers,
  21. Vector<NonnullOwnPtr<BasicBlock>> basic_blocks,
  22. bool is_strict_mode)
  23. : basic_blocks(move(basic_blocks))
  24. , string_table(move(string_table))
  25. , identifier_table(move(identifier_table))
  26. , regex_table(move(regex_table))
  27. , source_code(move(source_code))
  28. , number_of_registers(number_of_registers)
  29. , is_strict_mode(is_strict_mode)
  30. {
  31. property_lookup_caches.resize(number_of_property_lookup_caches);
  32. global_variable_caches.resize(number_of_global_variable_caches);
  33. environment_variable_caches.resize(number_of_environment_variable_caches);
  34. }
  35. Executable::~Executable() = default;
  36. void Executable::dump() const
  37. {
  38. dbgln("\033[33;1mJS::Bytecode::Executable\033[0m ({})", name);
  39. for (auto& block : basic_blocks)
  40. block->dump(*this);
  41. if (!string_table->is_empty()) {
  42. outln();
  43. string_table->dump();
  44. }
  45. if (!identifier_table->is_empty()) {
  46. outln();
  47. identifier_table->dump();
  48. }
  49. }
  50. JIT::NativeExecutable const* Executable::get_or_create_native_executable()
  51. {
  52. if (!m_did_try_jitting) {
  53. m_did_try_jitting = true;
  54. m_native_executable = JIT::Compiler::compile(*this);
  55. }
  56. return m_native_executable;
  57. }
  58. }