Executable.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. JS_DEFINE_ALLOCATOR(Executable);
  14. Executable::Executable(
  15. NonnullOwnPtr<IdentifierTable> identifier_table,
  16. NonnullOwnPtr<StringTable> string_table,
  17. NonnullOwnPtr<RegexTable> regex_table,
  18. NonnullRefPtr<SourceCode const> source_code,
  19. size_t number_of_property_lookup_caches,
  20. size_t number_of_global_variable_caches,
  21. size_t number_of_environment_variable_caches,
  22. size_t number_of_registers,
  23. Vector<NonnullOwnPtr<BasicBlock>> basic_blocks,
  24. bool is_strict_mode)
  25. : basic_blocks(move(basic_blocks))
  26. , string_table(move(string_table))
  27. , identifier_table(move(identifier_table))
  28. , regex_table(move(regex_table))
  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. dbgln("\033[33;1mJS::Bytecode::Executable\033[0m ({})", name);
  41. for (auto& block : basic_blocks)
  42. block->dump(*this);
  43. if (!string_table->is_empty()) {
  44. outln();
  45. string_table->dump();
  46. }
  47. if (!identifier_table->is_empty()) {
  48. outln();
  49. identifier_table->dump();
  50. }
  51. }
  52. JIT::NativeExecutable const* Executable::get_or_create_native_executable()
  53. {
  54. if (!m_did_try_jitting) {
  55. m_did_try_jitting = true;
  56. m_native_executable = JIT::Compiler::compile(*this);
  57. }
  58. return m_native_executable;
  59. }
  60. }