Commit 07f91a14 by Enkelmann Committed by Enkelmann

convert 1-bit-sized bitvectors to 1-byte-sized bitvectors.

parent 2a56a719
...@@ -176,23 +176,23 @@ impl RegisterDomain for BitvectorDomain { ...@@ -176,23 +176,23 @@ impl RegisterDomain for BitvectorDomain {
IntXOr | BoolXOr => BitvectorDomain::Value(lhs_bitvec ^ rhs_bitvec), IntXOr | BoolXOr => BitvectorDomain::Value(lhs_bitvec ^ rhs_bitvec),
IntEqual => { IntEqual => {
assert_eq!(lhs_bitvec.width(), rhs_bitvec.width()); assert_eq!(lhs_bitvec.width(), rhs_bitvec.width());
BitvectorDomain::Value(Bitvector::from(lhs_bitvec == rhs_bitvec)) BitvectorDomain::Value(Bitvector::from((lhs_bitvec == rhs_bitvec) as u8))
} }
IntNotEqual => { IntNotEqual => {
assert_eq!(lhs_bitvec.width(), rhs_bitvec.width()); assert_eq!(lhs_bitvec.width(), rhs_bitvec.width());
BitvectorDomain::Value(Bitvector::from(lhs_bitvec != rhs_bitvec)) BitvectorDomain::Value(Bitvector::from((lhs_bitvec != rhs_bitvec) as u8))
} }
IntLess => BitvectorDomain::Value(Bitvector::from( IntLess => BitvectorDomain::Value(Bitvector::from(
lhs_bitvec.checked_ult(rhs_bitvec).unwrap(), lhs_bitvec.checked_ult(rhs_bitvec).unwrap() as u8,
)), )),
IntLessEqual => BitvectorDomain::Value(Bitvector::from( IntLessEqual => BitvectorDomain::Value(Bitvector::from(
lhs_bitvec.checked_ule(rhs_bitvec).unwrap(), lhs_bitvec.checked_ule(rhs_bitvec).unwrap() as u8,
)), )),
IntSLess => BitvectorDomain::Value(Bitvector::from( IntSLess => BitvectorDomain::Value(Bitvector::from(
lhs_bitvec.checked_slt(rhs_bitvec).unwrap(), lhs_bitvec.checked_slt(rhs_bitvec).unwrap() as u8,
)), )),
IntSLessEqual => BitvectorDomain::Value(Bitvector::from( IntSLessEqual => BitvectorDomain::Value(Bitvector::from(
lhs_bitvec.checked_sle(rhs_bitvec).unwrap(), lhs_bitvec.checked_sle(rhs_bitvec).unwrap() as u8,
)), )),
FloatEqual | FloatNotEqual | FloatLess | FloatLessEqual => { FloatEqual | FloatNotEqual | FloatLess | FloatLessEqual => {
// TODO: Implement floating point comparison operators! // TODO: Implement floating point comparison operators!
...@@ -368,11 +368,11 @@ mod tests { ...@@ -368,11 +368,11 @@ mod tests {
assert_eq!( assert_eq!(
sixteen.bin_op(IntEqual, &bv(16)), sixteen.bin_op(IntEqual, &bv(16)),
BitvectorDomain::Value(Bitvector::from_bit(true)) BitvectorDomain::Value(Bitvector::from_u8(true as u8))
); );
assert_eq!( assert_eq!(
sixteen.bin_op(IntNotEqual, &bv(16)), sixteen.bin_op(IntNotEqual, &bv(16)),
BitvectorDomain::Value(Bitvector::from_bit(false)) BitvectorDomain::Value(Bitvector::from_u8(false as u8))
); );
assert_eq!(sixteen.un_op(Int2Comp), bv(-16)); assert_eq!(sixteen.un_op(Int2Comp), bv(-16));
......
...@@ -243,7 +243,11 @@ impl From<Expression> for IrExpression { ...@@ -243,7 +243,11 @@ impl From<Expression> for IrExpression {
use Expression::*; use Expression::*;
match expr { match expr {
Var(var) => IrExpression::Var(var.into()), Var(var) => IrExpression::Var(var.into()),
Const(bitvector) => IrExpression::Const(bitvector), Const(bitvector) => {
// The internal IR expects everything to be byte-sized, so we have to extend the bitvector if necessary.
let size: ByteSize = bitvector.width().into();
IrExpression::Const(bitvector.into_zero_extend(apint::BitWidth::from(size)).unwrap())
},
Load { .. } | Store { .. } | Let { .. } => panic!(), Load { .. } | Store { .. } | Let { .. } => panic!(),
IfThenElse { true_exp, .. } => IrExpression::Unknown { IfThenElse { true_exp, .. } => IrExpression::Unknown {
description: "BAP-IfThenElse-expression".into(), description: "BAP-IfThenElse-expression".into(),
......
...@@ -62,7 +62,21 @@ impl From<Jmp> for IrJmp { ...@@ -62,7 +62,21 @@ impl From<Jmp> for IrJmp {
target: unwrap_label_direct(jmp.goto.unwrap()), target: unwrap_label_direct(jmp.goto.unwrap()),
condition: jmp.condition.unwrap().into(), condition: jmp.condition.unwrap().into(),
}, },
BRANCHIND => IrJmp::BranchInd(unwrap_label_indirect(jmp.goto.unwrap()).into()), BRANCHIND => {
let target = unwrap_label_indirect(jmp.goto.unwrap());
if let Some(address) = target.address {
// Sometimes there are entries in jump tables that have no associated symbol,
// i.e. jumping there means jumping to nowhere.
// Usually the jump ends up jumping to address 0.
IrJmp::CallOther {
description: format!("Unresolved jump: Jump to value read from address {}", address),
return_: None,
}
} else {
IrJmp::BranchInd(target.into())
}
}
CALL => { CALL => {
let call = jmp.call.unwrap(); let call = jmp.call.unwrap();
IrJmp::Call { IrJmp::Call {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment