Skip to content

Commit 234bb7e

Browse files
committed
Pretty print LLIL sub-exprs in Rust API
1 parent c40a5f0 commit 234bb7e

File tree

6 files changed

+35
-31
lines changed

6 files changed

+35
-31
lines changed

arch/msp430/src/architecture.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use log::error;
2525

2626
const MIN_MNEMONIC: usize = 9;
2727

28+
#[derive(Debug)]
2829
pub struct Msp430 {
2930
handle: CoreArchitecture,
3031
custom_handle: CustomArchitectureHandle<Msp430>,

arch/riscv/disasm/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl FloatRegType for () {}
291291
impl FloatRegType for f32 {}
292292
impl FloatRegType for f64 {}
293293

294-
pub trait RegFile: Debug + Sized + Copy + Clone {
294+
pub trait RegFile: Debug + Sized + Copy + Clone + Send + Sync + 'static {
295295
type Int: IntRegType;
296296
type Float: FloatRegType;
297297

@@ -2331,7 +2331,7 @@ impl StandardExtension for ExtensionSupported {
23312331
}
23322332
}
23332333

2334-
pub trait RiscVDisassembler: Debug + Sized + Copy + Clone {
2334+
pub trait RiscVDisassembler: 'static + Debug + Sized + Copy + Clone + Send + Sync {
23352335
type RegFile: RegFile;
23362336
type MulDivExtension: StandardExtension;
23372337
type AtomicExtension: StandardExtension;
@@ -3175,6 +3175,7 @@ pub trait RiscVDisassembler: Debug + Sized + Copy + Clone {
31753175

31763176
#[derive(Copy, Clone, Debug)]
31773177
pub struct RiscVIMACDisassembler<RF: RegFile>(PhantomData<RF>);
3178+
31783179
impl<RF: RegFile> RiscVDisassembler for RiscVIMACDisassembler<RF> {
31793180
type RegFile = RF;
31803181
type MulDivExtension = ExtensionSupported;

arch/riscv/src/lib.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,18 @@ enum Intrinsic {
8888
}
8989

9090
#[derive(Copy, Clone)]
91-
struct Register<D: 'static + RiscVDisassembler> {
91+
struct Register<D: RiscVDisassembler> {
9292
id: RegisterId,
9393
_dis: PhantomData<D>,
9494
}
9595

9696
#[derive(Debug, Copy, Clone)]
97-
struct RiscVIntrinsic<D: 'static + RiscVDisassembler> {
97+
struct RiscVIntrinsic<D: RiscVDisassembler> {
9898
id: Intrinsic,
9999
_dis: PhantomData<D>,
100100
}
101101

102-
impl<D: 'static + RiscVDisassembler> Register<D> {
102+
impl<D: RiscVDisassembler> Register<D> {
103103
fn new(id: RegisterId) -> Self {
104104
Self {
105105
id,
@@ -118,7 +118,7 @@ impl<D: 'static + RiscVDisassembler> Register<D> {
118118
}
119119
}
120120

121-
impl<D: 'static + RiscVDisassembler> From<riscv_dis::IntReg<D>> for Register<D> {
121+
impl<D: RiscVDisassembler> From<riscv_dis::IntReg<D>> for Register<D> {
122122
fn from(reg: riscv_dis::IntReg<D>) -> Self {
123123
Self {
124124
id: RegisterId(reg.id()),
@@ -127,7 +127,7 @@ impl<D: 'static + RiscVDisassembler> From<riscv_dis::IntReg<D>> for Register<D>
127127
}
128128
}
129129

130-
impl<D: 'static + RiscVDisassembler> From<FloatReg<D>> for Register<D> {
130+
impl<D: RiscVDisassembler> From<FloatReg<D>> for Register<D> {
131131
fn from(reg: FloatReg<D>) -> Self {
132132
let int_reg_count = <D::RegFile as RegFile>::int_reg_count();
133133

@@ -138,13 +138,13 @@ impl<D: 'static + RiscVDisassembler> From<FloatReg<D>> for Register<D> {
138138
}
139139
}
140140

141-
impl<D: 'static + RiscVDisassembler> From<Register<D>> for LowLevelILRegister<Register<D>> {
141+
impl<D: RiscVDisassembler> From<Register<D>> for LowLevelILRegister<Register<D>> {
142142
fn from(reg: Register<D>) -> Self {
143143
LowLevelILRegister::ArchReg(reg)
144144
}
145145
}
146146

147-
impl<D: 'static + RiscVDisassembler> RegisterInfo for Register<D> {
147+
impl<D: RiscVDisassembler> RegisterInfo for Register<D> {
148148
type RegType = Self;
149149

150150
fn parent(&self) -> Option<Self> {
@@ -166,7 +166,7 @@ impl<D: 'static + RiscVDisassembler> RegisterInfo for Register<D> {
166166
}
167167
}
168168

169-
impl<D: 'static + RiscVDisassembler> architecture::Register for Register<D> {
169+
impl<D: RiscVDisassembler> architecture::Register for Register<D> {
170170
type InfoType = Self;
171171

172172
fn name(&self) -> Cow<str> {
@@ -204,7 +204,7 @@ impl<D: 'static + RiscVDisassembler> architecture::Register for Register<D> {
204204
}
205205
}
206206

207-
impl<'a, D: 'static + RiscVDisassembler + Send + Sync> LiftableLowLevelIL<'a, RiscVArch<D>>
207+
impl<'a, D: RiscVDisassembler> LiftableLowLevelIL<'a, RiscVArch<D>>
208208
for Register<D>
209209
{
210210
type Result = ValueExpr;
@@ -221,7 +221,7 @@ impl<'a, D: 'static + RiscVDisassembler + Send + Sync> LiftableLowLevelIL<'a, Ri
221221
}
222222
}
223223

224-
impl<'a, D: 'static + RiscVDisassembler + Send + Sync> LiftableLowLevelILWithSize<'a, RiscVArch<D>>
224+
impl<'a, D: RiscVDisassembler> LiftableLowLevelILWithSize<'a, RiscVArch<D>>
225225
for Register<D>
226226
{
227227
fn lift_with_size(
@@ -257,21 +257,21 @@ impl<'a, D: 'static + RiscVDisassembler + Send + Sync> LiftableLowLevelILWithSiz
257257
}
258258
}
259259

260-
impl<D: 'static + RiscVDisassembler> Hash for Register<D> {
260+
impl<D: RiscVDisassembler> Hash for Register<D> {
261261
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
262262
self.id.hash(state);
263263
}
264264
}
265265

266-
impl<D: 'static + RiscVDisassembler> PartialEq for Register<D> {
266+
impl<D: RiscVDisassembler> PartialEq for Register<D> {
267267
fn eq(&self, other: &Self) -> bool {
268268
self.id == other.id
269269
}
270270
}
271271

272-
impl<D: 'static + RiscVDisassembler> Eq for Register<D> {}
272+
impl<D: RiscVDisassembler> Eq for Register<D> {}
273273

274-
impl<D: 'static + RiscVDisassembler> fmt::Debug for Register<D> {
274+
impl<D: RiscVDisassembler> fmt::Debug for Register<D> {
275275
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
276276
f.write_str(self.name().as_ref())
277277
}
@@ -636,13 +636,14 @@ impl<D: RiscVDisassembler> architecture::Intrinsic for RiscVIntrinsic<D> {
636636
}
637637
}
638638

639-
struct RiscVArch<D: 'static + RiscVDisassembler + Send + Sync> {
639+
#[derive(Debug)]
640+
struct RiscVArch<D: RiscVDisassembler> {
640641
handle: CoreArchitecture,
641642
custom_handle: CustomArchitectureHandle<RiscVArch<D>>,
642643
_dis: PhantomData<D>,
643644
}
644645

645-
impl<D: 'static + RiscVDisassembler + Send + Sync> architecture::Architecture for RiscVArch<D> {
646+
impl<D: RiscVDisassembler> Architecture for RiscVArch<D> {
646647
type Handle = CustomArchitectureHandle<Self>;
647648

648649
type RegisterInfo = Register<D>;
@@ -2652,25 +2653,25 @@ impl<D: 'static + RiscVDisassembler + Send + Sync> RelocationHandler
26522653
}
26532654
}
26542655

2655-
impl<D: 'static + RiscVDisassembler + Send + Sync> AsRef<CoreRelocationHandler>
2656+
impl<D: RiscVDisassembler> AsRef<CoreRelocationHandler>
26562657
for RiscVELFRelocationHandler<D>
26572658
{
26582659
fn as_ref(&self) -> &CoreRelocationHandler {
26592660
&self.handle
26602661
}
26612662
}
26622663

2663-
struct RiscVCC<D: 'static + RiscVDisassembler + Send + Sync> {
2664+
struct RiscVCC<D: RiscVDisassembler> {
26642665
_dis: PhantomData<D>,
26652666
}
26662667

2667-
impl<D: 'static + RiscVDisassembler + Send + Sync> RiscVCC<D> {
2668+
impl<D: RiscVDisassembler> RiscVCC<D> {
26682669
fn new() -> Self {
26692670
RiscVCC { _dis: PhantomData }
26702671
}
26712672
}
26722673

2673-
impl<D: 'static + RiscVDisassembler + Send + Sync> CallingConvention for RiscVCC<D> {
2674+
impl<D: RiscVDisassembler> CallingConvention for RiscVCC<D> {
26742675
fn caller_saved_registers(&self) -> Vec<RegisterId> {
26752676
let mut regs = Vec::with_capacity(36);
26762677
let int_reg_count = <D::RegFile as RegFile>::int_reg_count();

rust/src/architecture.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ pub trait Intrinsic: Debug + Sized + Clone + Copy {
418418
fn outputs(&self) -> Vec<Conf<Ref<Type>>>;
419419
}
420420

421-
pub trait Architecture: 'static + Sized + AsRef<CoreArchitecture> {
421+
pub trait Architecture: 'static + Sized + AsRef<CoreArchitecture> + Debug {
422422
type Handle: Borrow<Self> + Clone;
423423

424424
type RegisterInfo: RegisterInfo<RegType = Self::Register>;
@@ -3234,6 +3234,7 @@ where
32343234
}
32353235
}
32363236

3237+
#[derive(Debug)]
32373238
pub struct CustomArchitectureHandle<A>
32383239
where
32393240
A: 'static + Architecture<Handle = CustomArchitectureHandle<A>> + Send + Sync,

rust/src/low_level_il/expression.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::VisitorAction;
2121
use super::*;
2222
use crate::architecture::Architecture;
2323
use std::fmt;
24-
use std::fmt::{Display, Formatter};
24+
use std::fmt::{Debug, Display, Formatter};
2525
use std::marker::PhantomData;
2626

2727
/// Used as a marker for an [`LowLevelILExpression`] that **can** produce a value.
@@ -32,7 +32,7 @@ pub struct ValueExpr;
3232
#[derive(Copy, Clone, Debug)]
3333
pub struct VoidExpr;
3434

35-
pub trait ExpressionResultType: 'static {}
35+
pub trait ExpressionResultType: 'static + Debug {}
3636
impl ExpressionResultType for ValueExpr {}
3737
impl ExpressionResultType for VoidExpr {}
3838

@@ -102,9 +102,9 @@ where
102102
R: ExpressionResultType,
103103
{
104104
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
105-
f.debug_struct("Expression")
106-
.field("index", &self.index)
107-
.finish()
105+
let op = unsafe { BNGetLowLevelILByIndex(self.function.handle, self.index.0) };
106+
let t = unsafe { LowLevelILExpressionKind::from_raw(self.function, op) };
107+
t.fmt(f)
108108
}
109109
}
110110

rust/src/low_level_il/function.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct Mutable;
3535
#[derive(Copy, Clone, Debug)]
3636
pub struct Finalized;
3737

38-
pub trait FunctionMutability: 'static {}
38+
pub trait FunctionMutability: 'static + Debug {}
3939
impl FunctionMutability for Mutable {}
4040
impl FunctionMutability for Finalized {}
4141

@@ -44,7 +44,7 @@ pub struct LiftedNonSSA;
4444
#[derive(Copy, Clone, Debug)]
4545
pub struct RegularNonSSA;
4646

47-
pub trait NonSSAVariant: 'static {}
47+
pub trait NonSSAVariant: 'static + Debug {}
4848
impl NonSSAVariant for LiftedNonSSA {}
4949
impl NonSSAVariant for RegularNonSSA {}
5050

@@ -53,7 +53,7 @@ pub struct SSA;
5353
#[derive(Copy, Clone, Debug)]
5454
pub struct NonSSA<V: NonSSAVariant>(V);
5555

56-
pub trait FunctionForm: 'static {}
56+
pub trait FunctionForm: 'static + Debug {}
5757
impl FunctionForm for SSA {}
5858
impl<V: NonSSAVariant> FunctionForm for NonSSA<V> {}
5959

0 commit comments

Comments
 (0)