From e2c01dff615c0df4d65ed545e4a80ad40b94ea28 Mon Sep 17 00:00:00 2001 From: Fabrice Bellard Date: Wed, 3 Jun 2026 15:19:05 +0200 Subject: [PATCH] add optional define to add asm labels for each opcode to ease code inspection and profiling --- quickjs.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/quickjs.c b/quickjs.c index 89cd3e3..f694fdf 100644 --- a/quickjs.c +++ b/quickjs.c @@ -107,6 +107,8 @@ //#define DUMP_PROMISE //#define DUMP_READ_OBJECT //#define DUMP_ROPE_REBALANCE +/* add asm labels to each opcode so that it is easier to see the generated code */ +//#define OPCODE_ASM_LABEL /* test the GC by forcing it before each object allocation */ //#define FORCE_GC_AT_MALLOC @@ -17761,6 +17763,11 @@ typedef enum { #define FUNC_RET_YIELD_STAR 2 #define FUNC_RET_INITIAL_YIELD 3 +#ifdef OPCODE_ASM_LABEL +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-label" +#endif + /* argv[] is modified if (flags & JS_CALL_FLAG_COPY_ARGV) = 0. */ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSValueConst this_obj, JSValueConst new_target, @@ -17794,7 +17801,11 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, [ OP_COUNT ... 255 ] = &&case_default }; #define SWITCH(pc) goto *dispatch_table[opcode = *pc++]; +#ifdef OPCODE_ASM_LABEL +#define CASE(op) case_ ## op: asm volatile("label_" #op ":\n.globl label_" #op); dummy_case_ ## op +#else #define CASE(op) case_ ## op +#endif #define DEFAULT case_default #define BREAK SWITCH(pc) #endif @@ -20535,6 +20546,10 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, return ret_val; } +#ifdef OPCODE_ASM_LABEL +#pragma GCC diagnostic pop +#endif + JSValue JS_Call(JSContext *ctx, JSValueConst func_obj, JSValueConst this_obj, int argc, JSValueConst *argv) {