Skip to content

Commit 3e9f486

Browse files
committed
[Rust] Add missing LLIL_FLOAT_CONST low level IL expression
1 parent d2347c9 commit 3e9f486

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

rust/src/low_level_il/expression.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ where
348348
Ceil(Operation<'func, M, F, operation::UnaryOp>),
349349
Ftrunc(Operation<'func, M, F, operation::UnaryOp>),
350350

351+
FloatConst(Operation<'func, M, F, operation::FloatConst>),
352+
351353
FcmpE(Operation<'func, M, F, operation::Condition>),
352354
FcmpNE(Operation<'func, M, F, operation::Condition>),
353355
FcmpLT(Operation<'func, M, F, operation::Condition>),
@@ -513,6 +515,10 @@ where
513515
LLIL_FCMP_O => LowLevelILExpressionKind::FcmpO(Operation::new(function, op, index)),
514516
LLIL_FCMP_UO => LowLevelILExpressionKind::FcmpUO(Operation::new(function, op, index)),
515517

518+
LLIL_FLOAT_CONST => {
519+
LowLevelILExpressionKind::FloatConst(Operation::new(function, op, index))
520+
}
521+
516522
LLIL_SEPARATE_PARAM_LIST_SSA => {
517523
LowLevelILExpressionKind::SeparateParamListSsa(Operation::new(function, op, index))
518524
}
@@ -524,7 +530,7 @@ where
524530
LowLevelILExpressionKind::UnimplMem(Operation::new(function, op, index))
525531
}
526532

527-
// TODO TEST_BIT ADD_OVERFLOW LLIL_REG_STACK_PUSH
533+
// TODO TEST_BIT ADD_OVERFLOW LLIL_REG_STACK_PUSH
528534
_ => {
529535
#[cfg(debug_assertions)]
530536
log::error!(
@@ -698,7 +704,7 @@ where
698704
Pop(_) | Reg(_) | RegSsa(_) | RegPartialSsa(_) | RegSplit(_) | RegSplitSsa(_)
699705
| Const(_) | ConstPtr(_) | Flag(_) | FlagBit(_) | ExternPtr(_) | FlagCond(_)
700706
| FlagGroup(_) | Unimpl(_) | Undef(_) | RegStackPop(_) | CallOutputSsa(_)
701-
| CallStackSsa(_) => {}
707+
| CallStackSsa(_) | FloatConst(_) => {}
702708
}
703709

704710
VisitorAction::Sibling
@@ -742,6 +748,8 @@ where
742748

743749
Const(ref op) | ConstPtr(ref op) => &op.op,
744750

751+
FloatConst(ref op) => &op.op,
752+
745753
ExternPtr(ref op) => &op.op,
746754

747755
RegStackPop(ref op) => &op.op,
@@ -812,6 +820,8 @@ impl LowLevelILExpressionKind<'_, Mutable, NonSSA> {
812820

813821
Const(ref op) | ConstPtr(ref op) => op.flag_write(),
814822

823+
FloatConst(ref op) => op.flag_write(),
824+
815825
ExternPtr(ref op) => op.flag_write(),
816826

817827
RegStackPop(ref op) => op.flag_write(),

rust/src/low_level_il/operation.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,61 @@ where
16531653
}
16541654
}
16551655

1656+
// LLIL_FLOAT_CONST
1657+
pub struct FloatConst;
1658+
1659+
impl<M, F> Operation<'_, M, F, FloatConst>
1660+
where
1661+
M: FunctionMutability,
1662+
F: FunctionForm,
1663+
{
1664+
pub fn size(&self) -> usize {
1665+
self.op.size
1666+
}
1667+
1668+
pub fn raw_value(&self) -> u64 {
1669+
self.op.operands[0]
1670+
}
1671+
1672+
pub fn float_value(&self) -> f64 {
1673+
let raw_bits = self.raw_value();
1674+
match self.op.size {
1675+
4 => {
1676+
// For f32, take the lower 32 bits and convert to f32
1677+
let bits32 = (raw_bits & 0xFFFFFFFF) as u32;
1678+
f32::from_bits(bits32) as f64
1679+
}
1680+
8 => {
1681+
// For f64, use all 64 bits
1682+
f64::from_bits(raw_bits)
1683+
}
1684+
_ => {
1685+
// Log error for unexpected sizes
1686+
log::error!(
1687+
"il expr @ {:x} has invalid float size {} (expected 4 or 8 bytes)",
1688+
self.op.address,
1689+
self.op.size
1690+
);
1691+
f64::NAN
1692+
}
1693+
}
1694+
}
1695+
}
1696+
1697+
impl<M, F> Debug for Operation<'_, M, F, FloatConst>
1698+
where
1699+
M: FunctionMutability,
1700+
F: FunctionForm,
1701+
{
1702+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1703+
f.debug_struct("FloatConst")
1704+
.field("size", &self.size())
1705+
.field("float_value", &self.float_value())
1706+
.field("raw_value", &self.raw_value())
1707+
.finish()
1708+
}
1709+
}
1710+
16561711
// LLIL_EXTERN_PTR
16571712
pub struct Extern;
16581713

@@ -2186,6 +2241,7 @@ impl OperationArguments for RegPhi {}
21862241
impl OperationArguments for FlagPhi {}
21872242
impl OperationArguments for MemPhi {}
21882243
impl OperationArguments for Const {}
2244+
impl OperationArguments for FloatConst {}
21892245
impl OperationArguments for Extern {}
21902246
impl OperationArguments for BinaryOp {}
21912247
impl OperationArguments for BinaryOpCarry {}

0 commit comments

Comments
 (0)