1pub mod ranalyzer;
2
3use crate::analysis::{
4 core::heap::{default::DefaultHeapAnalysis, AdtOwner, HeapAnalysis},
5 Analysis,
6};
7use ranalyzer::{FlowAnalysis, IcxSliceFroBlock, IntraFlowContext, MirGraph};
8use rustc_middle::ty::TyCtxt;
9use std::collections::HashMap;
10
11#[allow(non_camel_case_types)]
12#[derive(Clone)]
13pub struct rCanary<'tcx> {
14 tcx: TyCtxt<'tcx>,
15 adt_owner: AdtOwner,
16 mir_graph: MirGraph,
17}
18
19impl<'tcx> rCanary<'tcx> {
20 pub fn new(tcx: TyCtxt<'tcx>, adt_owner: AdtOwner) -> Self {
21 Self {
22 tcx,
23 adt_owner: adt_owner,
24 mir_graph: HashMap::default(),
25 }
26 }
27
28 pub fn start(&mut self) {
29 let mut heap = DefaultHeapAnalysis::new(self.tcx);
30 heap.run();
31 let adt_owner = heap.get_all_items();
32 let rcx_boxed = Box::new(rCanary::new(self.tcx, adt_owner));
33 let rcx = Box::leak(rcx_boxed);
34 FlowAnalysis::new(rcx).start();
35 }
36
37 pub fn tcx(&self) -> TyCtxt<'tcx> {
38 self.tcx
39 }
40
41 pub fn adt_owner(&self) -> &AdtOwner {
42 &self.adt_owner
43 }
44
45 pub fn adt_owner_mut(&mut self) -> &mut AdtOwner {
46 &mut self.adt_owner
47 }
48
49 pub fn mir_graph(&self) -> &MirGraph {
50 &self.mir_graph
51 }
52
53 pub fn mir_graph_mut(&mut self) -> &mut MirGraph {
54 &mut self.mir_graph
55 }
56}
57
58pub trait Tcx<'tcx, 'o, 'a> {
59 fn tcx(&'o self) -> TyCtxt<'tcx>;
60}
61
62pub trait Rcx<'tcx, 'o, 'a> {
63 fn rcx(&'o self) -> &'a rCanary<'tcx>;
64
65 fn tcx(&'o self) -> TyCtxt<'tcx>;
66}
67
68pub trait RcxMut<'tcx, 'o, 'a> {
69 fn rcx(&'o self) -> &'o rCanary<'tcx>;
70
71 fn rcx_mut(&'o mut self) -> &'o mut rCanary<'tcx>;
72
73 fn tcx(&'o self) -> TyCtxt<'tcx>;
74}
75
76pub trait IcxMut<'tcx, 'ctx, 'o> {
77 fn icx(&'o self) -> &'o IntraFlowContext<'tcx, 'ctx>;
78
79 fn icx_mut(&'o mut self) -> &'o mut IntraFlowContext<'tcx, 'ctx>;
80}
81
82pub trait IcxSliceMut<'tcx, 'ctx, 'o> {
83 fn icx_slice(&'o self) -> &'o IcxSliceFroBlock<'tcx, 'ctx>;
84
85 fn icx_slice_mut(&'o mut self) -> &'o mut IcxSliceFroBlock<'tcx, 'ctx>;
86}