Unverified Commit 785736f3 by Enkelmann Committed by GitHub

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

parent e8251916
......@@ -141,46 +141,49 @@ impl Def {
pub fn into_ir_def(self, generic_pointer_size: ByteSize) -> IrDef {
use super::ExpressionType::*;
match self.rhs.mnemonic {
LOAD => IrDef::Load {
var: self.lhs.unwrap().into(),
address: self.rhs.input1.unwrap().into(),
},
STORE => IrDef::Store {
address: self.rhs.input1.unwrap().into(),
value: self.rhs.input2.unwrap().into(),
},
SUBPIECE => IrDef::Assign {
var: self.lhs.clone().unwrap().into(),
value: IrExpression::Subpiece {
low_byte: self.rhs.input1.unwrap().parse_to_bytesize(),
size: self.lhs.unwrap().size,
arg: Box::new(self.rhs.input0.unwrap().into()),
},
LOAD => {
return IrDef::Load {
var: self.lhs.unwrap().into(),
address: self.rhs.input1.unwrap().into(),
}
}
STORE => {
return IrDef::Store {
address: self.rhs.input1.unwrap().into(),
value: self.rhs.input2.unwrap().into(),
}
}
_ => (),
}
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(),
size: target_var.size,
arg: Box::new(self.rhs.input0.unwrap().into()),
},
INT_ZEXT | INT_SEXT | INT2FLOAT | FLOAT2FLOAT | TRUNC | POPCOUNT => IrDef::Assign {
var: self.lhs.clone().unwrap().into(),
value: IrExpression::Cast {
INT_ZEXT | INT_SEXT | INT2FLOAT | FLOAT2FLOAT | TRUNC | POPCOUNT => {
IrExpression::Cast {
op: self.rhs.mnemonic.into(),
size: self.lhs.unwrap().size,
size: target_var.size,
arg: Box::new(self.rhs.input0.unwrap().into()),
},
},
_ => {
let target_var = self.lhs.unwrap();
if target_var.address.is_some() {
IrDef::Store {
address: IrExpression::Const(
target_var.parse_address_to_bitvector(generic_pointer_size),
),
value: self.rhs.into(),
}
} else {
IrDef::Assign {
var: target_var.into(),
value: self.rhs.into(),
}
}
}
_ => self.rhs.into(),
};
if target_var.address.is_some() {
IrDef::Store {
address: IrExpression::Const(
target_var.parse_address_to_bitvector(generic_pointer_size),
),
value,
}
} else {
IrDef::Assign {
var: target_var.into(),
value,
}
}
}
}
......
......@@ -438,6 +438,29 @@ fn def_deserialization() {
}
#[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() {
let _: Label = serde_json::from_str(
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