llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
symbolic_approx.h
1 // This file if part of the llir-opt project.
2 // Licensing information can be found in the LICENSE file.
3 // (C) 2018 Nandor Licker. All rights reserved.
4 
5 #pragma once
6 
7 #include <set>
8 
9 #include "core/inst_visitor.h"
10 #include "passes/pre_eval/symbolic_value.h"
11 
12 class SymbolicContext;
13 class SymbolicHeap;
14 class ReferenceGraph;
15 class DAGBlock;
16 class SymbolicFrame;
17 
18 
19 
23 bool IsAllocation(Func &func);
24 
28 class SymbolicApprox final {
29 public:
31  : refs_(refs)
32  , heap_(heap)
33  , ctx_(ctx)
34  {
35  }
36 
38  bool Approximate(CallSite &call);
39 
41  void Approximate(
42  SymbolicFrame &frame,
43  const std::set<DAGBlock *> &bypassed,
44  const std::set<SymbolicContext *> &contexts
45  );
46 
47 private:
49  bool ApproximateCall(CallSite &call);
50 
52  struct Approximation {
53  bool Changed;
54  bool Raises;
55  SymbolicValue Taint;
56  SymbolicValue Tainted;
57  };
58 
60  Approximation ApproximateNodes(
61  const std::set<CallSite *> &calls,
62  const std::set<CallSite *> &allocs,
63  SymbolicValue &refs,
64  SymbolicContext &ctx
65  );
66 
68  bool Raise(SymbolicContext &ctx, const SymbolicValue &taint);
69 
71  void Resolve(SymbolicFrame &frame, MovInst &mov, const SymbolicValue &taint);
72 
74  bool Malloc(CallSite &call, const std::optional<APInt> &size);
75 
77  bool Realloc(
78  CallSite &call,
79  const SymbolicValue &ptr,
80  const std::optional<APInt> &size
81  );
82 
83 private:
85  ReferenceGraph &refs_;
87  SymbolicHeap &heap_;
89  SymbolicContext &ctx_;
90 };
ReferenceGraph
Definition: reference_graph.h:32
SymbolicContext
Definition: symbolic_context.h:28
Func
Definition: func.h:30
SymbolicValue
Definition: symbolic_value.h:24
SymbolicApprox
Definition: symbolic_approx.h:28
MovInst
Definition: mov.h:17
SymbolicFrame
Definition: symbolic_frame.h:29
SymbolicApprox::Approximate
bool Approximate(CallSite &call)
Over-approximate the effects of a call.
Definition: symbolic_approx.cpp:43
DAGBlock
Definition: dag.h:20
SymbolicHeap
Definition: symbolic_heap.h:21