summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorMichael Krasnitski <michael.krasnitski@gmail.com>2023-01-06 02:21:40 -0500
committerKyle Martin <krm504@nyu.edu>2023-01-10 00:11:27 -0500
commit64713cd5b5550c5b8c61a05cc26d89d464d45bb3 (patch)
tree3fc035eab9b9ee91a953ca804aa5298aa5a5c895 /rust/src
parent5b51a4ff188c426d8f90ac71ee6dde0fa3b5a495 (diff)
Introduce `Expression::new` to avoid writing `PhantomData` everywhere
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/llil/expression.rs8
-rw-r--r--rust/src/llil/instruction.rs8
-rw-r--r--rust/src/llil/lifting.rs84
-rw-r--r--rust/src/llil/operation.rs138
4 files changed, 46 insertions, 192 deletions
diff --git a/rust/src/llil/expression.rs b/rust/src/llil/expression.rs
index 4c6d784b..2898d89f 100644
--- a/rust/src/llil/expression.rs
+++ b/rust/src/llil/expression.rs
@@ -58,6 +58,14 @@ where
F: FunctionForm,
R: ExpressionResultType,
{
+ pub(crate) fn new(function: &'func Function<A, M, F>, expr_idx: usize) -> Self {
+ Self {
+ function,
+ expr_idx,
+ _ty: PhantomData,
+ }
+ }
+
pub fn index(&self) -> usize {
self.expr_idx
}
diff --git a/rust/src/llil/instruction.rs b/rust/src/llil/instruction.rs
index 20cc545b..e5ae508b 100644
--- a/rust/src/llil/instruction.rs
+++ b/rust/src/llil/instruction.rs
@@ -16,8 +16,6 @@ use binaryninjacore_sys::BNGetLowLevelILByIndex;
use binaryninjacore_sys::BNGetLowLevelILIndexForInstruction;
use binaryninjacore_sys::BNLowLevelILInstruction;
-use std::marker::PhantomData;
-
use super::operation;
use super::operation::Operation;
use super::*;
@@ -119,11 +117,7 @@ where
// Hopefully this is a bare value. If it isn't (expression
// from wrong function form or similar) it won't really cause
// any problems as it'll come back as undefined when queried.
- let expr = Expression {
- function: self.function,
- expr_idx,
- _ty: PhantomData,
- };
+ let expr = Expression::new(self.function, expr_idx);
let info = unsafe { expr.info_from_op(op) };
diff --git a/rust/src/llil/lifting.rs b/rust/src/llil/lifting.rs
index a4d3c560..eb7b36fd 100644
--- a/rust/src/llil/lifting.rs
+++ b/rust/src/llil/lifting.rs
@@ -383,11 +383,7 @@ where
)
};
- Expression {
- function: il,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(il, expr_idx)
}
pub fn get_default_flag_cond_llil<'func, A>(
@@ -408,11 +404,7 @@ where
let expr_idx =
BNGetDefaultArchitectureFlagConditionLowLevelIL(handle.0, cond, class_id, il.handle);
- Expression {
- function: il,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(il, expr_idx)
}
}
@@ -635,11 +627,7 @@ where
)
};
- Expression {
- function: self.function,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self.function, expr_idx)
}
pub fn with_source_operand(
@@ -709,11 +697,7 @@ macro_rules! no_arg_lifter {
let expr_idx = unsafe { BNLowLevelILAddExpr(self.handle, $op, 0, 0, 0, 0, 0, 0) };
- Expression {
- function: self,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self, expr_idx)
}
};
}
@@ -756,11 +740,7 @@ macro_rules! unsized_unary_op_lifter {
BNLowLevelILAddExpr(self.handle, $op, 0, 0, expr.expr_idx as u64, 0, 0, 0)
};
- Expression {
- function: self,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self, expr_idx)
}
};
}
@@ -932,11 +912,7 @@ where
let expr_idx =
unsafe { BNLowLevelILAddExpr(self.handle, LLIL_CONST, size, 0, val, 0, 0, 0) };
- Expression {
- function: self,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self, expr_idx)
}
pub fn const_ptr_sized(
@@ -950,11 +926,7 @@ where
let expr_idx =
unsafe { BNLowLevelILAddExpr(self.handle, LLIL_CONST_PTR, size, 0, val, 0, 0, 0) };
- Expression {
- function: self,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self, expr_idx)
}
pub fn const_ptr(&self, val: u64) -> Expression<A, Mutable, NonSSA<LiftedNonSSA>, ValueExpr> {
@@ -967,11 +939,7 @@ where
let expr_idx = unsafe { BNLowLevelILAddExpr(self.handle, LLIL_TRAP, 0, 0, val, 0, 0, 0) };
- Expression {
- function: self,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self, expr_idx)
}
no_arg_lifter!(unimplemented, LLIL_UNIMPL, ValueExpr);
@@ -1009,11 +977,7 @@ where
)
};
- Expression {
- function: self,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self, expr_idx)
}
pub fn goto<'a: 'b, 'b>(
@@ -1024,11 +988,7 @@ where
let expr_idx = unsafe { BNLowLevelILGoto(self.handle, &l.0 as *const _ as *mut _) };
- Expression {
- function: self,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self, expr_idx)
}
pub fn reg<R: Into<Register<A::Register>>>(
@@ -1048,11 +1008,7 @@ where
let expr_idx =
unsafe { BNLowLevelILAddExpr(self.handle, LLIL_REG, size, 0, reg as u64, 0, 0, 0) };
- Expression {
- function: self,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self, expr_idx)
}
pub fn set_reg<'a, R, E>(
@@ -1137,11 +1093,7 @@ where
let expr_idx =
unsafe { BNLowLevelILAddExpr(self.handle, LLIL_FLAG, 0, 0, flag.id() as u64, 0, 0, 0) };
- Expression {
- function: self,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self, expr_idx)
}
pub fn flag_cond(
@@ -1155,11 +1107,7 @@ where
let expr_idx =
unsafe { BNLowLevelILAddExpr(self.handle, LLIL_FLAG_COND, 0, 0, cond as u64, 0, 0, 0) };
- Expression {
- function: self,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self, expr_idx)
}
pub fn flag_group(
@@ -1183,11 +1131,7 @@ where
)
};
- Expression {
- function: self,
- expr_idx,
- _ty: PhantomData,
- }
+ Expression::new(self, expr_idx)
}
pub fn set_flag<'a, E>(
diff --git a/rust/src/llil/operation.rs b/rust/src/llil/operation.rs
index 296a45db..b998cce3 100644
--- a/rust/src/llil/operation.rs
+++ b/rust/src/llil/operation.rs
@@ -120,11 +120,7 @@ where
}
pub fn source_expr(&self) -> Expression<'func, A, M, NonSSA<V>, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[1] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[1] as usize)
}
}
@@ -184,11 +180,7 @@ where
}
pub fn source_expr(&self) -> Expression<'func, A, M, NonSSA<V>, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[2] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[2] as usize)
}
}
@@ -202,11 +194,7 @@ where
V: NonSSAVariant,
{
pub fn source_expr(&self) -> Expression<'func, A, M, NonSSA<V>, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[1] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[1] as usize)
}
}
@@ -224,11 +212,7 @@ where
}
pub fn source_mem_expr(&self) -> Expression<'func, A, M, NonSSA<V>, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
}
@@ -246,19 +230,11 @@ where
}
pub fn dest_mem_expr(&self) -> Expression<'func, A, M, NonSSA<V>, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
pub fn source_expr(&self) -> Expression<'func, A, M, NonSSA<V>, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[1] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[1] as usize)
}
}
@@ -313,11 +289,7 @@ where
F: FunctionForm,
{
pub fn target(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
}
@@ -331,11 +303,7 @@ where
F: FunctionForm,
{
pub fn target(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
// TODO target list
}
@@ -350,11 +318,7 @@ where
V: NonSSAVariant,
{
pub fn target(&self) -> Expression<'func, A, M, NonSSA<V>, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
pub fn stack_adjust(&self) -> Option<u64> {
@@ -378,11 +342,7 @@ where
F: FunctionForm,
{
pub fn target(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
}
@@ -396,11 +356,7 @@ where
F: FunctionForm,
{
pub fn condition(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
pub fn true_target(&self) -> Instruction<'func, A, M, F> {
@@ -535,19 +491,11 @@ where
}
pub fn left(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
pub fn right(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[1] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[1] as usize)
}
}
@@ -565,27 +513,15 @@ where
}
pub fn left(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
pub fn right(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[1] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[1] as usize)
}
pub fn carry(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[2] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[2] as usize)
}
}
@@ -603,27 +539,15 @@ where
}
pub fn high(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
pub fn low(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[1] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[1] as usize)
}
pub fn right(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[2] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[2] as usize)
}
}
@@ -642,11 +566,7 @@ where
}
pub fn operand(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
}
@@ -664,19 +584,11 @@ where
}
pub fn left(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
pub fn right(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[1] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[1] as usize)
}
}
@@ -694,11 +606,7 @@ where
}
pub fn mem_expr(&self) -> Expression<'func, A, M, F, ValueExpr> {
- Expression {
- function: self.function,
- expr_idx: self.op.operands[0] as usize,
- _ty: PhantomData,
- }
+ Expression::new(self.function, self.op.operands[0] as usize)
}
}