From 792d3c1bda971f555426112d70152509b65b3c88 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 25 Feb 2025 10:56:21 +0100 Subject: [PATCH] Print opcode count and total size in debug output Fixes: https://github.com/quickjs-ng/quickjs/issues/777 --- quickjs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/quickjs.c b/quickjs.c index 9d39e9008..f8d5f402e 100644 --- a/quickjs.c +++ b/quickjs.c @@ -28814,6 +28814,7 @@ static __maybe_unused void js_dump_function_bytecode(JSContext *ctx, JSFunctionB int i; char atom_buf[ATOM_GET_STR_BUF_SIZE]; const char *str; + const uint8_t *op; if (b->filename != JS_ATOM_NULL) { str = JS_AtomGetStr(ctx, atom_buf, sizeof(atom_buf), b->filename); @@ -28860,7 +28861,11 @@ static __maybe_unused void js_dump_function_bytecode(JSContext *ctx, JSFunctionB } } printf(" stack_size: %d\n", b->stack_size); - printf(" opcodes:\n"); + printf(" byte_code_len: %d\n", b->byte_code_len); + op = b->byte_code_buf; + for (i = 0; op < &b->byte_code_buf[b->byte_code_len]; i++) + op += short_opcode_info(*op).size; + printf(" opcodes: %d\n", i); dump_byte_code(ctx, 3, b->byte_code_buf, b->byte_code_len, b->vardefs, b->arg_count, b->vardefs ? b->vardefs + b->arg_count : NULL, b->var_count,