-
Notifications
You must be signed in to change notification settings - Fork 0
/
PreliminaryAnalysis.fs
77 lines (67 loc) · 2.81 KB
/
PreliminaryAnalysis.fs
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
74
75
76
77
open System.Collections.Generic;;
// Some mutable global vars are defined into preliminary analysis, in that they're used in some routines;
// because of the static binding they cannot be redefined, so they're mutable.
// The values will be overwritten in Main routine.
// list of all MRs and them ID, in order to initialize them value with ⊥
// if the MRs list will become dynamic in the future (AR1, AR2,... ARi,..., ARn; Heap1,..., Heapi,... Heapn),
// then we will simply do a preliminary analysis to become aware of all possible memory regions.
let availableMRs = [new MemoryRegion(RegionType.AR,0);new MemoryRegion(RegionType.Global,1);] ;;
// list of every defined var
let mutable availableVars : aloc list = [] ;;
let availableVarsAnalysis (cfg : ICFG<Exp>) : (aloc list) =
// if statm = {HeapDec/GlobalDec} -> add new defined vars to ls
let h statm ls =
match statm with
|GlobalDec(l) -> ls@l
|HeapDec(l) -> ls@(List.map fst l)
|Array(a,size,n) ->
let mutable newl = [] in
for i=0 to (size-1) do
if i%4=0 then newl<-newl@[(a+"+"+(string i))] else ignore()
ls@newl
|_ -> ls
let rec f nodes l =
match (nodes : INode<Exp> list) with
|[] -> l
|x::xs -> f xs (h (x.Statm()) l)
in (f (cfg.Nodes()) []) |> List.distinct
;;
// map: aloc -> sizeOf(aloc)
let mutable SizeOf = new Dictionary<aloc,int>() ;;
let SizeOfAnalysis (cfg : ICFG<Exp>) =
let nodes = cfg.Nodes()
let map = new Dictionary<aloc,int>()
let rec f (ns : INode<Exp> list) =
match ns with
|[] -> map
|x::xs ->
match (x.Statm()) with
|GlobalDec(v) -> v |> List.map (fun x -> map.TryAdd(x,4) ) |> ignore ; f xs
|HeapDec(v) -> v |> List.map (fun (x,s) -> map.TryAdd(x,s) ) |> ignore ; f xs
|Array(a,size,n) ->
map.TryAdd(a,size) |> ignore
for i=0 to (size-1) do
if i%4=0 then (map.TryAdd(a+"+"+(string i),4) |> ignore) else ignore()
f xs
|_ -> f xs
in f nodes
;;
// A dummy estimate of #iterations to do before widening
let WideningDefaultValue = 15
let mutable WideningThreshold = WideningDefaultValue;;
let ThresholdCalc (cfg : ICFG<Exp>) =
let nodes = cfg.Nodes()
let rec f (ns : INode<Exp> list) l =
match ns with
|[] -> l
|x::xs ->
match (x.Statm()) with
|LeqConst(_,s) -> f xs l@[s]
|GeqConst(_,s) -> f xs l@[s]
|ArrayLeqConst(_,_,s) -> f xs l@[s]
|ArrayGeqConst(_,_,s) -> f xs l@[s]
|_ -> f xs l
let g l = if l |> List.isEmpty then 0 else l |> List.max
in g (f nodes [])+1
;;
(* Other todo analysis: #Malloc for counting #HeapRegs; #Procs for counting #ARRegs *)