2025-09-17 05:56:33 +09:00
|
|
|
/*!
|
|
|
|
|
* Select & Condition helpers (scaffolding)
|
|
|
|
|
*
|
|
|
|
|
* Placeholder for condition normalization / short-circuit pre-processing
|
|
|
|
|
* to keep `function.rs` focused on structure. Implementations will be
|
|
|
|
|
* added incrementally; for now, this module is documentation-only.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
use crate::mir::{function::MirFunction, ValueId};
|
2025-09-17 06:55:39 +09:00
|
|
|
use crate::mir::MirType;
|
|
|
|
|
use super::super::types; // access mapping helpers if needed later
|
2025-09-17 05:56:33 +09:00
|
|
|
|
|
|
|
|
/// Normalize a branch condition if needed (scaffolding).
|
|
|
|
|
/// Currently returns the input unchanged; provides a single place
|
|
|
|
|
/// to adjust semantics later (e.g., truthy rules, short-circuit pre-pass).
|
2025-09-17 06:55:39 +09:00
|
|
|
pub(crate) fn normalize_branch_condition(func: &MirFunction, cond: &ValueId) -> ValueId {
|
|
|
|
|
// Minimal truthy normalization hook.
|
|
|
|
|
// Strategy (no new instructions here):
|
|
|
|
|
// - If we have a recorded type for `cond` and it is a boolean-like i1/i64 (0/1), return as-is.
|
|
|
|
|
// - Otherwise, return the original cond and let flow/emit handle `!= 0` lowering as today.
|
|
|
|
|
if let Some(ty) = func.metadata.value_types.get(cond) {
|
|
|
|
|
match ty {
|
|
|
|
|
MirType::I1 | MirType::I64 | MirType::Bool => { return *cond; }
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-17 05:56:33 +09:00
|
|
|
*cond
|
|
|
|
|
}
|