rapx/analysis/core/
range_analysis.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#![allow(non_snake_case)]

pub mod PassRunner;
pub mod SSA;
use rustc_hir::def::DefKind;
use rustc_middle::mir::Body;
use rustc_middle::ty::TyCtxt;
// use std::collections::HashMap;
// use std::fs::File;
// use std::io::Write;
// use std::process::Command;
pub struct SSATrans<'tcx> {
    pub tcx: TyCtxt<'tcx>,
    pub debug: bool,
}

impl<'tcx> SSATrans<'tcx> {
    pub fn new(tcx: TyCtxt<'tcx>, debug: bool) -> Self {
        Self { tcx: tcx, debug }
    }

    pub fn start(&mut self) {
        for local_def_id in self.tcx.iter_local_def_id() {
            if matches!(self.tcx.def_kind(local_def_id), DefKind::Fn) {
                let hir_map = self.tcx.hir();
                if hir_map.maybe_body_owned_by(local_def_id).is_some() {
                    let def_id = local_def_id.to_def_id();
                    let mut body: Body<'tcx> = self.tcx.optimized_mir(def_id).clone();
                    let body_mut_ref = &mut body;
                    let passrunner = PassRunner::PassRunner::new(self.tcx);
                    passrunner.run_pass(body_mut_ref);

                    // // passrunner.print_diff(body_mut_ref);
                    // const body_clone  = body.clone();
                    // // let body_clone :Body<'a>=body_mut_ref.clone();
                    // let mut cg: ConstraintGraph< u32> = ConstraintGraph::new();
                    // cg.build_graph(&body);
                }
            }
        }
    }
}
// pub struct RangeAnalyzer<'tcx> {
//     pub tcx: TyCtxt<'tcx>,
//     pub debug: bool,
// }

// impl<'tcx> RangeAnalyzer<'tcx> {
//     pub fn new(tcx: TyCtxt<'tcx>, debug: bool) -> Self {
//         Self { tcx: tcx, debug }
//     }

//     pub fn start(&mut self) {
//         for local_def_id in self.tcx.iter_local_def_id() {
//             if matches!(self.tcx.def_kind(local_def_id), DefKind::Fn) {
//                 let hir_map = self.tcx.hir();
//                 if hir_map.maybe_body_owned_by(local_def_id).is_some() {
//                     let def_id = local_def_id.to_def_id();
//                     let mut body: Body<'tcx> = self.tcx.optimized_mir(def_id).clone();
//                     let body_mut_ref = &mut body;
//                     let passrunner = PassRunner::PassRunner::new(self.tcx);
//                     passrunner.run_pass(body_mut_ref);

//                     // // passrunner.print_diff(body_mut_ref);
//                     // const body_clone  = body.clone();
//                     // // let body_clone :Body<'a>=body_mut_ref.clone();
//                     // let mut cg: ConstraintGraph< u32> = ConstraintGraph::new();
//                     // cg.build_graph(&body);
//                 }
//             }
//         }
//     }
// }