Skip to content

Commit 0c2f903

Browse files
committed
W27b python#2: emitFormatSimple → C body + delegation stub
FORMAT_VALUE/FORMAT_SIMPLE (mainline) opcode handler. Per W27b Step A scope. C body: hir_builder_emit_format_simple_c (~38 lines). Block-creation pattern: cond-branch on TUnicodeExact → format_with_spec (slow path) OR refine_type (pass-through fast path) → done. C primitives used: hir_cfg_alloc_block + hir_c_create_cond_branch_check_type_cpp + hir_c_create_load_const + hir_c_create_format_with_spec_reg + hir_c_create_refine_type_reg + hir_c_create_branch_cpp + hir_builder_temps_alloc_stack (all existing). C++ HIRBuilder::emitFormatSimple → 4-line delegation stub (cfg arg unused, marked maybe_unused). Verification: cmake --build target jit/phoenix_jit clean (BUILD_EXIT=0). Sole-path coverage: FORMAT_VALUE/FORMAT_SIMPLE is mainline-tested per theologian L2515 coverage observation.
1 parent 526ec72 commit 0c2f903

2 files changed

Lines changed: 43 additions & 23 deletions

File tree

Python/jit/hir/builder.cpp

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5054,30 +5054,11 @@ void HIRBuilder::emitConvertValue(
50545054
static_cast<void*>(&tc), static_cast<void*>(current_func_), bc_instr.oparg());
50555055
}
50565056

5057-
void HIRBuilder::emitFormatSimple(CFG& cfg, TranslationContext& tc) {
5058-
PhxPtrArray& stack = tc.frame.stack;
5059-
Register* value = static_cast<Register*>(phx_ptr_arr_pop(&stack));
5060-
5061-
BasicBlock* done_block = cfg.AllocateBlock();
5062-
BasicBlock* do_fmt_block = cfg.AllocateBlock();
5063-
BasicBlock* pass_through_block = cfg.AllocateBlock();
5064-
5065-
tc.emitCondBranchCheckType(
5066-
value, TUnicodeExact, pass_through_block, do_fmt_block);
5067-
Register* out = temps_.AllocateStack();
5068-
5069-
tc.block = do_fmt_block;
5070-
Register* fmt_spec = temps_.AllocateStack();
5071-
tc.emitLoadConst(fmt_spec, TNullptr);
5072-
tc.emitFormatWithSpec(out, value, fmt_spec, tc.frame);
5073-
tc.emitBranch(done_block);
5074-
5075-
tc.block = pass_through_block;
5076-
tc.emitRefineType(out, TUnicodeExact, value);
5077-
tc.emitBranch(done_block);
5057+
extern "C" void hir_builder_emit_format_simple_c(
5058+
void *tc, void *func, void *builder);
50785059

5079-
tc.block = done_block;
5080-
phx_ptr_arr_push(&stack, out);
5060+
void HIRBuilder::emitFormatSimple(CFG& /*cfg*/, TranslationContext& tc) {
5061+
hir_builder_emit_format_simple_c(&tc, current_func_, this);
50815062
}
50825063

50835064
extern "C" void hir_builder_emit_load_common_constant_c(

Python/jit/hir/builder_emit_c.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,4 +3924,43 @@ void hir_builder_emit_load_special_c(
39243924
phx_ptr_arr_push(&tc->frame.stack, null_or_self);
39253925
}
39263926

3927+
/* W27b #2: emitFormatSimple (FORMAT_VALUE/FORMAT_SIMPLE mainline opcode).
3928+
* Mirrors C++ HIRBuilder::emitFormatSimple @ builder.cpp:5057.
3929+
* Block-creation pattern: cond-branch on TUnicodeExact → format-with-spec
3930+
* (slow path) OR refine-type (pass-through fast path) → done. */
3931+
void hir_builder_emit_format_simple_c(
3932+
PhxTranslationContext *tc,
3933+
void *func,
3934+
void *builder) {
3935+
void *value = phx_ptr_arr_pop(&tc->frame.stack);
3936+
3937+
void *done_block = hir_cfg_alloc_block(func);
3938+
void *do_fmt_block = hir_cfg_alloc_block(func);
3939+
void *pass_through_block = hir_cfg_alloc_block(func);
3940+
3941+
HirType t_unicode_exact = HIR_TYPE_UNICODEEXACT;
3942+
phx_tc_emit(tc, hir_c_create_cond_branch_check_type_cpp(
3943+
value, t_unicode_exact, pass_through_block, do_fmt_block));
3944+
3945+
void *out = hir_builder_temps_alloc_stack(builder);
3946+
3947+
/* do_fmt_block: load null fmt_spec + emit format_with_spec + branch done. */
3948+
tc->block = do_fmt_block;
3949+
void *fmt_spec = hir_builder_temps_alloc_stack(builder);
3950+
HirType t_nullptr = HIR_TYPE_NULLPTR;
3951+
phx_tc_emit(tc, hir_c_create_load_const(fmt_spec, t_nullptr));
3952+
phx_tc_emit(tc, hir_c_create_format_with_spec_reg(
3953+
out, value, fmt_spec, &tc->frame));
3954+
phx_tc_emit(tc, hir_c_create_branch_cpp(done_block));
3955+
3956+
/* pass_through_block: refine value type + branch done. */
3957+
tc->block = pass_through_block;
3958+
phx_tc_emit(tc, hir_c_create_refine_type_reg(out, t_unicode_exact, value));
3959+
phx_tc_emit(tc, hir_c_create_branch_cpp(done_block));
3960+
3961+
/* done_block: continue with out on stack. */
3962+
tc->block = done_block;
3963+
phx_ptr_arr_push(&tc->frame.stack, out);
3964+
}
3965+
39273966

0 commit comments

Comments
 (0)