瀏覽代碼

LibJS: Move bytecode debug spam behind JS_BYTECODE_DEBUG :^)

Andreas Kling 4 年之前
父節點
當前提交
7cbe4daa7c

+ 4 - 0
AK/Debug.h.in

@@ -226,6 +226,10 @@
 #cmakedefine01 JPG_DEBUG
 #cmakedefine01 JPG_DEBUG
 #endif
 #endif
 
 
+#ifndef JS_BYTECODE_DEBUG
+#cmakedefine01 JS_BYTECODE_DEBUG
+#endif
+
 #ifndef KEYBOARD_SHORTCUTS_DEBUG
 #ifndef KEYBOARD_SHORTCUTS_DEBUG
 #cmakedefine01 KEYBOARD_SHORTCUTS_DEBUG
 #cmakedefine01 KEYBOARD_SHORTCUTS_DEBUG
 #endif
 #endif

+ 1 - 0
Meta/CMake/all_the_debug_macros.cmake

@@ -88,6 +88,7 @@ set(IRQ_DEBUG ON)
 set(ITEM_RECTS_DEBUG ON)
 set(ITEM_RECTS_DEBUG ON)
 set(JOB_DEBUG ON)
 set(JOB_DEBUG ON)
 set(JPG_DEBUG ON)
 set(JPG_DEBUG ON)
+set(JS_BYTECODE_DEBUG ON)
 set(KEYBOARD_DEBUG ON)
 set(KEYBOARD_DEBUG ON)
 set(KEYBOARD_SHORTCUTS_DEBUG ON)
 set(KEYBOARD_SHORTCUTS_DEBUG ON)
 set(KMALLOC_DEBUG ON)
 set(KMALLOC_DEBUG ON)

+ 13 - 9
Userland/Libraries/LibJS/Bytecode/Interpreter.cpp

@@ -4,6 +4,7 @@
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
  */
  */
 
 
+#include <AK/Debug.h>
 #include <LibJS/Bytecode/Block.h>
 #include <LibJS/Bytecode/Block.h>
 #include <LibJS/Bytecode/Instruction.h>
 #include <LibJS/Bytecode/Instruction.h>
 #include <LibJS/Bytecode/Interpreter.h>
 #include <LibJS/Bytecode/Interpreter.h>
@@ -34,7 +35,7 @@ Interpreter::~Interpreter()
 
 
 Value Interpreter::run(Bytecode::Block const& block)
 Value Interpreter::run(Bytecode::Block const& block)
 {
 {
-    dbgln("Bytecode::Interpreter will run block {:p}", &block);
+    dbgln_if(JS_BYTECODE_DEBUG, "Bytecode::Interpreter will run block {:p}", &block);
 
 
     CallFrame global_call_frame;
     CallFrame global_call_frame;
     if (vm().call_stack().is_empty()) {
     if (vm().call_stack().is_empty()) {
@@ -65,14 +66,17 @@ Value Interpreter::run(Bytecode::Block const& block)
         ++pc;
         ++pc;
     }
     }
 
 
-    dbgln("Bytecode::Interpreter did run block {:p}", &block);
-    for (size_t i = 0; i < registers().size(); ++i) {
-        String value_string;
-        if (registers()[i].is_empty())
-            value_string = "(empty)";
-        else
-            value_string = registers()[i].to_string_without_side_effects();
-        dbgln("[{:3}] {}", i, value_string);
+    dbgln_if(JS_BYTECODE_DEBUG, "Bytecode::Interpreter did run block {:p}", &block);
+
+    if constexpr (JS_BYTECODE_DEBUG) {
+        for (size_t i = 0; i < registers().size(); ++i) {
+            String value_string;
+            if (registers()[i].is_empty())
+                value_string = "(empty)";
+            else
+                value_string = registers()[i].to_string_without_side_effects();
+            dbgln("[{:3}] {}", i, value_string);
+        }
     }
     }
 
 
     m_register_windows.take_last();
     m_register_windows.take_last();

+ 5 - 2
Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp

@@ -4,6 +4,7 @@
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
  */
  */
 
 
+#include <AK/Debug.h>
 #include <AK/Function.h>
 #include <AK/Function.h>
 #include <LibJS/AST.h>
 #include <LibJS/AST.h>
 #include <LibJS/Bytecode/Block.h>
 #include <LibJS/Bytecode/Block.h>
@@ -152,8 +153,10 @@ Value ScriptFunction::execute_function_body()
         prepare_arguments();
         prepare_arguments();
         auto block = Bytecode::Generator::generate(m_body);
         auto block = Bytecode::Generator::generate(m_body);
         VERIFY(block);
         VERIFY(block);
-        dbgln("Compiled Bytecode::Block for function '{}':", m_name);
-        block->dump();
+        if constexpr (JS_BYTECODE_DEBUG) {
+            dbgln("Compiled Bytecode::Block for function '{}':", m_name);
+            block->dump();
+        }
         return bytecode_interpreter->run(*block);
         return bytecode_interpreter->run(*block);
     } else {
     } else {
         OwnPtr<Interpreter> local_interpreter;
         OwnPtr<Interpreter> local_interpreter;