Executable.cpp 1.9 KB

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