sema: split zirTyOpCast into zirIntCast + zirTruncate
Add zirIntCast() and zirTruncate() as named entry points matching src/Sema.zig's decomposition. Rename shared implementation to analyzeTyOpCast(). Update dispatch and call sites. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1573,10 +1573,9 @@ static AirInstRef zirBitcast(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
return semaAddInst(block, AIR_INST_BITCAST, data);
|
||||
}
|
||||
|
||||
// zirTyOpCast: generic handler for type-changing cast ZIR instructions
|
||||
// that produce a ty_op AIR instruction (intcast, truncate, etc.).
|
||||
// analyzeTyOpCast: shared worker for type-changing cast ZIR instructions.
|
||||
// Ported from src/Sema.zig zirIntCast / zirTruncate (simplified).
|
||||
static AirInstRef zirTyOpCast(
|
||||
static AirInstRef analyzeTyOpCast(
|
||||
Sema* sema, SemaBlock* block, uint32_t inst, AirInstTag air_tag) {
|
||||
uint32_t payload_index = sema->code.inst_datas[inst].pl_node.payload_index;
|
||||
ZirInstRef dest_ty_ref = sema->code.extra[payload_index];
|
||||
@@ -1604,6 +1603,18 @@ static AirInstRef zirTyOpCast(
|
||||
return semaAddInst(block, air_tag, data);
|
||||
}
|
||||
|
||||
// zirIntCast: handle int_cast ZIR instruction (@intCast).
|
||||
// Ported from src/Sema.zig zirIntCast.
|
||||
static AirInstRef zirIntCast(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
return analyzeTyOpCast(sema, block, inst, AIR_INST_INTCAST);
|
||||
}
|
||||
|
||||
// zirTruncate: handle truncate ZIR instruction (@truncate).
|
||||
// Ported from src/Sema.zig zirTruncate.
|
||||
static AirInstRef zirTruncate(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
return analyzeTyOpCast(sema, block, inst, AIR_INST_TRUNC);
|
||||
}
|
||||
|
||||
// floatBits: get the bit width of a float type from its IP index.
|
||||
static uint16_t floatBits(TypeIndex ty) {
|
||||
switch (ty) {
|
||||
@@ -11353,29 +11364,27 @@ bool analyzeBodyInner(
|
||||
|
||||
// @intCast.
|
||||
case ZIR_INST_INT_CAST:
|
||||
instMapPut(&sema->inst_map, inst,
|
||||
zirTyOpCast(sema, block, inst, AIR_INST_INTCAST));
|
||||
instMapPut(&sema->inst_map, inst, zirIntCast(sema, block, inst));
|
||||
i++;
|
||||
continue;
|
||||
|
||||
// @truncate.
|
||||
case ZIR_INST_TRUNCATE:
|
||||
instMapPut(&sema->inst_map, inst,
|
||||
zirTyOpCast(sema, block, inst, AIR_INST_TRUNC));
|
||||
instMapPut(&sema->inst_map, inst, zirTruncate(sema, block, inst));
|
||||
i++;
|
||||
continue;
|
||||
|
||||
// @intFromFloat.
|
||||
case ZIR_INST_INT_FROM_FLOAT:
|
||||
instMapPut(&sema->inst_map, inst,
|
||||
zirTyOpCast(sema, block, inst, AIR_INST_INT_FROM_FLOAT));
|
||||
analyzeTyOpCast(sema, block, inst, AIR_INST_INT_FROM_FLOAT));
|
||||
i++;
|
||||
continue;
|
||||
|
||||
// @floatFromInt.
|
||||
case ZIR_INST_FLOAT_FROM_INT:
|
||||
instMapPut(&sema->inst_map, inst,
|
||||
zirTyOpCast(sema, block, inst, AIR_INST_FLOAT_FROM_INT));
|
||||
analyzeTyOpCast(sema, block, inst, AIR_INST_FLOAT_FROM_INT));
|
||||
i++;
|
||||
continue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user