1
//! \file
2
/*
3
**  Copyright (C) - Triton
4
**
5
**  This program is under the terms of the Apache License 2.0.
6
*/
7

8
#include <triton/exceptions.hpp>
9
#include <triton/pathConstraint.hpp>
10

11

12

13
namespace triton {
14
  namespace engines {
15
    namespace symbolic {
16

17 1
      PathConstraint::PathConstraint() {
18 1
        this->tid = static_cast<triton::uint32>(-1);
19
      }
20

21

22 1
      PathConstraint::PathConstraint(const PathConstraint &other) {
23 1
        this->branches = other.branches;
24 1
        this->tid = other.tid;
25
      }
26

27

28 1
      PathConstraint::~PathConstraint() {
29
        /* See #828: Release ownership before calling container destructor */
30 1
        this->branches.clear();
31
      }
32

33

34 0
      PathConstraint& PathConstraint::operator=(const PathConstraint &other) {
35 0
        this->branches = other.branches;
36 0
        this->tid = other.tid;
37 0
        return *this;
38
      }
39

40

41 1
      void PathConstraint::addBranchConstraint(bool taken, triton::uint64 srcAddr, triton::uint64 dstAddr, const triton::ast::SharedAbstractNode& pc) {
42 1
        if (pc == nullptr)
43 0
          throw triton::exceptions::PathConstraint("PathConstraint::addBranchConstraint(): The PC node cannot be null.");
44 1
        this->branches.push_back(std::make_tuple(taken, srcAddr, dstAddr, pc));
45
      }
46

47

48 1
      const std::vector<std::tuple<bool, triton::uint64, triton::uint64, triton::ast::SharedAbstractNode>>& PathConstraint::getBranchConstraints(void) const {
49 1
        return this->branches;
50
      }
51

52

53 1
      triton::uint64 PathConstraint::getTakenAddress(void) const {
54 1
        for (auto it = this->branches.begin(); it != this->branches.end(); it++) {
55 1
          if (std::get<0>(*it) == true)
56 1
            return std::get<2>(*it);
57
        }
58 0
        throw triton::exceptions::PathConstraint("PathConstraint::getTakenAddress(): Something wrong, no branch taken.");
59
      }
60

61

62 1
      triton::ast::SharedAbstractNode PathConstraint::getTakenPredicate(void) const {
63 1
        for (auto it = this->branches.begin(); it != this->branches.end(); it++) {
64 1
          if (std::get<0>(*it) == true)
65 1
            return std::get<3>(*it);
66
        }
67 0
        throw triton::exceptions::PathConstraint("PathConstraint::getTakenPredicate(): Something wrong, no branch taken.");
68
      }
69

70

71 1
      bool PathConstraint::isMultipleBranches(void) const {
72 1
        if (this->branches.size() == 0)
73 0
          throw triton::exceptions::PathConstraint("PathConstraint::isMultipleBranches(): Path Constraint is empty.");
74 1
        else if (this->branches.size() == 1)
75
          return false;
76 1
        return true;
77
      }
78

79

80 0
      triton::uint32 PathConstraint::getThreadId(void) const {
81 0
        return this->tid;
82
      }
83

84

85 1
      void PathConstraint::setThreadId(triton::uint32 tid) {
86 1
        this->tid = tid;
87
      }
88

89
    }; /* symbolic namespace */
90
  }; /* engines namespace */
91 1
}; /*triton namespace */

Read our documentation on viewing source code .

Loading