81
81
8: dump stdlib functions
82
82
16: dump bytecode in hex
83
83
32: dump line number table
84
+ 64: dump executed bytecode
84
85
*/
85
86
//#define DUMP_BYTECODE (1)
86
87
/* dump the occurence of the automatic GC */
@@ -14345,6 +14346,12 @@ typedef enum {
14345
14346
#define FUNC_RET_YIELD 1
14346
14347
#define FUNC_RET_YIELD_STAR 2
14347
14348
14349
+ #ifdef DUMP_BYTECODE
14350
+ static void dump_single_byte_code(JSContext *ctx, const uint8_t *pc,
14351
+ JSFunctionBytecode *b);
14352
+ static void print_func_name(JSFunctionBytecode *b);
14353
+ #endif
14354
+
14348
14355
/* argv[] is modified if (flags & JS_CALL_FLAG_COPY_ARGV) = 0. */
14349
14356
static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
14350
14357
JSValueConst this_obj, JSValueConst new_target,
@@ -14362,8 +14369,14 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
14362
14369
size_t alloca_size;
14363
14370
JSInlineCache *ic;
14364
14371
14372
+ #if defined(DUMP_BYTECODE) && (DUMP_BYTECODE & 64)
14373
+ #define DUMP_BYTECODE_OR_DONT(pc) dump_single_byte_code(ctx, pc, b);
14374
+ #else
14375
+ #define DUMP_BYTECODE_OR_DONT(pc)
14376
+ #endif
14377
+
14365
14378
#if !DIRECT_DISPATCH
14366
- #define SWITCH(pc) switch (opcode = *pc++)
14379
+ #define SWITCH(pc) DUMP_BYTECODE_OR_DONT(pc) switch (opcode = *pc++)
14367
14380
#define CASE(op) case op
14368
14381
#define DEFAULT default
14369
14382
#define BREAK break
@@ -14374,7 +14387,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
14374
14387
#include "quickjs-opcode.h"
14375
14388
[ OP_COUNT ... 255 ] = &&case_default
14376
14389
};
14377
- #define SWITCH(pc) goto *dispatch_table[opcode = *pc++];
14390
+ #define SWITCH(pc) DUMP_BYTECODE_OR_DONT(pc) goto *dispatch_table[opcode = *pc++];
14378
14391
#define CASE(op) case_ ## op
14379
14392
#define DEFAULT case_default
14380
14393
#define BREAK SWITCH(pc)
@@ -14465,6 +14478,10 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
14465
14478
ctx = b->realm; /* set the current realm */
14466
14479
ic = b->ic;
14467
14480
14481
+ #if defined(DUMP_BYTECODE) && (DUMP_BYTECODE & 64)
14482
+ print_func_name(b);
14483
+ #endif
14484
+
14468
14485
restart:
14469
14486
for(;;) {
14470
14487
int call_argc;
@@ -27252,6 +27269,38 @@ static void dump_byte_code(JSContext *ctx, int pass,
27252
27269
js_free(ctx, bits);
27253
27270
}
27254
27271
27272
+ // caveat emptor: intended to be called during execution of bytecode
27273
+ // and only works for pass3 bytecode
27274
+ static __maybe_unused void dump_single_byte_code(JSContext *ctx,
27275
+ const uint8_t *pc,
27276
+ JSFunctionBytecode *b)
27277
+ {
27278
+ JSVarDef *args, *vars;
27279
+ int line_num;
27280
+
27281
+ args = vars = b->vardefs;
27282
+ if (vars)
27283
+ vars = &vars[b->arg_count];
27284
+
27285
+ line_num = -1;
27286
+ if (b->has_debug)
27287
+ line_num = b->debug.line_num;
27288
+
27289
+ dump_byte_code(ctx, /*pass*/3, pc, short_opcode_info(*pc).size,
27290
+ args, b->arg_count, vars, b->var_count,
27291
+ b->closure_var, b->closure_var_count,
27292
+ b->cpool, b->cpool_count,
27293
+ NULL, line_num,
27294
+ NULL, b);
27295
+ }
27296
+
27297
+ static __maybe_unused void print_func_name(JSFunctionBytecode *b)
27298
+ {
27299
+ if (b->has_debug)
27300
+ if (b->debug.source)
27301
+ print_lines(b->debug.source, 0, 1);
27302
+ }
27303
+
27255
27304
static __maybe_unused void dump_pc2line(JSContext *ctx, const uint8_t *buf, int len,
27256
27305
int line_num)
27257
27306
{
0 commit comments