Unverified Commit 785736f3 by Enkelmann Committed by GitHub

Always check for implicit Stores in P-Code instructions (#251)

parent e8251916
...@@ -141,45 +141,48 @@ impl Def { ...@@ -141,45 +141,48 @@ impl Def {
pub fn into_ir_def(self, generic_pointer_size: ByteSize) -> IrDef { pub fn into_ir_def(self, generic_pointer_size: ByteSize) -> IrDef {
use super::ExpressionType::*; use super::ExpressionType::*;
match self.rhs.mnemonic { match self.rhs.mnemonic {
LOAD => IrDef::Load { LOAD => {
return IrDef::Load {
var: self.lhs.unwrap().into(), var: self.lhs.unwrap().into(),
address: self.rhs.input1.unwrap().into(), address: self.rhs.input1.unwrap().into(),
}, }
STORE => IrDef::Store { }
STORE => {
return IrDef::Store {
address: self.rhs.input1.unwrap().into(), address: self.rhs.input1.unwrap().into(),
value: self.rhs.input2.unwrap().into(), value: self.rhs.input2.unwrap().into(),
}, }
SUBPIECE => IrDef::Assign { }
var: self.lhs.clone().unwrap().into(), _ => (),
value: IrExpression::Subpiece { }
let target_var = self.lhs.unwrap();
let value = match self.rhs.mnemonic {
LOAD | STORE => unreachable!(),
SUBPIECE => IrExpression::Subpiece {
low_byte: self.rhs.input1.unwrap().parse_to_bytesize(), low_byte: self.rhs.input1.unwrap().parse_to_bytesize(),
size: self.lhs.unwrap().size, size: target_var.size,
arg: Box::new(self.rhs.input0.unwrap().into()), arg: Box::new(self.rhs.input0.unwrap().into()),
}, },
}, INT_ZEXT | INT_SEXT | INT2FLOAT | FLOAT2FLOAT | TRUNC | POPCOUNT => {
INT_ZEXT | INT_SEXT | INT2FLOAT | FLOAT2FLOAT | TRUNC | POPCOUNT => IrDef::Assign { IrExpression::Cast {
var: self.lhs.clone().unwrap().into(),
value: IrExpression::Cast {
op: self.rhs.mnemonic.into(), op: self.rhs.mnemonic.into(),
size: self.lhs.unwrap().size, size: target_var.size,
arg: Box::new(self.rhs.input0.unwrap().into()), arg: Box::new(self.rhs.input0.unwrap().into()),
}, }
}, }
_ => { _ => self.rhs.into(),
let target_var = self.lhs.unwrap(); };
if target_var.address.is_some() { if target_var.address.is_some() {
IrDef::Store { IrDef::Store {
address: IrExpression::Const( address: IrExpression::Const(
target_var.parse_address_to_bitvector(generic_pointer_size), target_var.parse_address_to_bitvector(generic_pointer_size),
), ),
value: self.rhs.into(), value,
} }
} else { } else {
IrDef::Assign { IrDef::Assign {
var: target_var.into(), var: target_var.into(),
value: self.rhs.into(), value,
}
}
} }
} }
} }
......
...@@ -438,6 +438,29 @@ fn def_deserialization() { ...@@ -438,6 +438,29 @@ fn def_deserialization() {
} }
#[test] #[test]
fn def_deserialization_issue_247_regression_test() {
let def: Def = serde_json::from_str(
r#"{
"lhs": {
"address": "15f0499e",
"size": 2,
"is_virtual": false
},
"rhs": {
"mnemonic": "TRUNC",
"input0": {
"name": "$U5df80",
"size": 10,
"is_virtual": true
}
}
}"#,
)
.unwrap();
let _: IrDef = def.into_ir_def(ByteSize::new(8));
}
#[test]
fn label_deserialization() { fn label_deserialization() {
let _: Label = serde_json::from_str( let _: Label = serde_json::from_str(
r#" r#"
......
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