|
1 | | -/****************************************************************************** |
2 | | - * Copyright (c) 2020 Fabian Schiebel. |
3 | | - * All rights reserved. This program and the accompanying materials are made |
4 | | - * available under the terms of LICENSE.txt. |
5 | | - * |
6 | | - * Contributors: |
7 | | - * Fabian Schiebel and others |
8 | | - *****************************************************************************/ |
9 | | - |
10 | | -#include <iostream> |
11 | | - |
12 | | -#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctions.h" |
13 | | -#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEGeneralizedLCA/AllBot.h" |
14 | | -#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEGeneralizedLCA/GenConstant.h" |
15 | | -#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEGeneralizedLCA/JoinEdgeFunction.h" |
16 | | - |
17 | | -namespace psr { |
18 | | - |
19 | | -GenConstant::GenConstant(const IDEGeneralizedLCA::l_t &Val, size_t MaxSize) |
20 | | - : Val(Val), MaxSize(MaxSize) { |
21 | | - // TODO: remove this? |
22 | | - /*std::cout << "GenConstant: {"; |
23 | | - bool First = true; |
24 | | - for (auto &elem : val) { |
25 | | - if (First) |
26 | | - First = false; |
27 | | - else |
28 | | - std::cout << ", "; |
29 | | - std::cout << elem; |
30 | | - } |
31 | | - std::cout << "}" << std::endl;*/ |
32 | | -} |
33 | | -IDEGeneralizedLCA::l_t |
34 | | -GenConstant::computeTarget(IDEGeneralizedLCA::l_t /*Source*/) { |
35 | | - // std::cout << "GenConstant computation (" << source << ")" |
36 | | - // << " = " << val << std::endl; |
37 | | - return Val; |
38 | | -} |
39 | | - |
40 | | -std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> GenConstant::composeWith( |
41 | | - std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> SecondFunction) { |
42 | | - // std::cout << "GenConstant composing" << std::endl; |
43 | | - if (dynamic_cast<EdgeIdentity<IDEGeneralizedLCA::l_t> *>( |
44 | | - SecondFunction.get()) || |
45 | | - dynamic_cast<AllBottom<IDEGeneralizedLCA::l_t> *>(SecondFunction.get())) { |
46 | | - |
47 | | - return shared_from_this(); |
48 | | - } |
49 | | - if (dynamic_cast<GenConstant *>(SecondFunction.get())) { |
| 1 | +/****************************************************************************** |
| 2 | + * Copyright (c) 2020 Fabian Schiebel. |
| 3 | + * All rights reserved. This program and the accompanying materials are made |
| 4 | + * available under the terms of LICENSE.txt. |
| 5 | + * |
| 6 | + * Contributors: |
| 7 | + * Fabian Schiebel and others |
| 8 | + *****************************************************************************/ |
| 9 | + |
| 10 | +#include <iostream> |
| 11 | + |
| 12 | +#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctions.h" |
| 13 | +#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEGeneralizedLCA/AllBot.h" |
| 14 | +#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEGeneralizedLCA/GenConstant.h" |
| 15 | +#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEGeneralizedLCA/JoinEdgeFunction.h" |
| 16 | + |
| 17 | +namespace psr { |
| 18 | + |
| 19 | +GenConstant::GenConstant(const IDEGeneralizedLCA::l_t &Val, size_t MaxSize) |
| 20 | + : Val(Val), MaxSize(MaxSize) { |
| 21 | + // TODO: remove this? |
| 22 | + /*std::cout << "GenConstant: {"; |
| 23 | + bool First = true; |
| 24 | + for (auto &elem : val) { |
| 25 | + if (First) |
| 26 | + First = false; |
| 27 | + else |
| 28 | + std::cout << ", "; |
| 29 | + std::cout << elem; |
| 30 | + } |
| 31 | + std::cout << "}" << std::endl;*/ |
| 32 | +} |
| 33 | +IDEGeneralizedLCA::l_t |
| 34 | +GenConstant::computeTarget(IDEGeneralizedLCA::l_t /*Source*/) { |
| 35 | + // std::cout << "GenConstant computation (" << source << ")" |
| 36 | + // << " = " << val << std::endl; |
| 37 | + return Val; |
| 38 | +} |
| 39 | + |
| 40 | +std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> GenConstant::composeWith( |
| 41 | + std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> SecondFunction) { |
| 42 | + // std::cout << "GenConstant composing" << std::endl; |
| 43 | + if (dynamic_cast<EdgeIdentity<IDEGeneralizedLCA::l_t> *>( |
| 44 | + SecondFunction.get()) || |
| 45 | + dynamic_cast<AllBottom<IDEGeneralizedLCA::l_t> *>(SecondFunction.get())) { |
| 46 | + |
| 47 | + return shared_from_this(); |
| 48 | + } |
| 49 | + if (dynamic_cast<GenConstant *>(SecondFunction.get())) { |
50 | 50 | return SecondFunction; |
51 | | - } |
52 | | - // return std::make_shared<EdgeFunctionComposer>(shared_from_this(), |
53 | | - // secondFunction, MaxSize); |
54 | | - return std::make_shared<GenConstant>(SecondFunction->computeTarget(Val), |
55 | | - MaxSize); |
56 | | -} |
57 | | - |
58 | | -std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> GenConstant::joinWith( |
59 | | - std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> Other) { |
60 | | - if (const auto *OtherConst = dynamic_cast<GenConstant *>(Other.get())) { |
61 | | - switch (compare(Val, OtherConst->Val)) { |
62 | | - case Ordering::Equal: |
| 51 | + } |
| 52 | + // return std::make_shared<EdgeFunctionComposer>(shared_from_this(), |
| 53 | + // secondFunction, MaxSize); |
| 54 | + return std::make_shared<GenConstant>(SecondFunction->computeTarget(Val), |
| 55 | + MaxSize); |
| 56 | +} |
| 57 | + |
| 58 | +std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> GenConstant::joinWith( |
| 59 | + std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> Other) { |
| 60 | + if (const auto *OtherConst = dynamic_cast<GenConstant *>(Other.get())) { |
| 61 | + switch (compare(Val, OtherConst->Val)) { |
| 62 | + case Ordering::Equal: |
63 | 63 | [[fallthrough]]; |
64 | | - case Ordering::Greater: |
65 | | - return shared_from_this(); |
66 | | - case Ordering::Less: |
67 | | - return Other; |
68 | | - default: |
69 | | - return std::make_shared<GenConstant>(join(Val, OtherConst->Val, MaxSize), |
70 | | - MaxSize); |
71 | | - } |
72 | | - } |
73 | | - if (AllBot::isBot(Other)) { |
| 64 | + case Ordering::Greater: |
| 65 | + return shared_from_this(); |
| 66 | + case Ordering::Less: |
| 67 | + return Other; |
| 68 | + default: |
| 69 | + return std::make_shared<GenConstant>(join(Val, OtherConst->Val, MaxSize), |
| 70 | + MaxSize); |
| 71 | + } |
| 72 | + } |
| 73 | + if (AllBot::isBot(Other)) { |
74 | 74 | return AllBot::getInstance(); |
75 | | - } |
76 | | - return std::make_shared<JoinEdgeFunction>(shared_from_this(), Other, MaxSize); |
77 | | -} |
78 | | - |
79 | | -bool GenConstant::equal_to( |
80 | | - std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> Other) const { |
81 | | - if (const auto *OtherConst = dynamic_cast<GenConstant *>(Other.get())) { |
82 | | - return Val == OtherConst->Val && MaxSize == OtherConst->MaxSize; |
83 | | - } |
84 | | - return false; |
| 75 | + } |
| 76 | + return std::make_shared<JoinEdgeFunction>(shared_from_this(), Other, MaxSize); |
| 77 | +} |
| 78 | + |
| 79 | +bool GenConstant::equal_to( |
| 80 | + std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> Other) const { |
| 81 | + if (const auto *OtherConst = dynamic_cast<GenConstant *>(Other.get())) { |
| 82 | + return Val == OtherConst->Val && MaxSize == OtherConst->MaxSize; |
| 83 | + } |
| 84 | + return false; |
| 85 | +} |
| 86 | +void GenConstant::print(std::ostream &OS, bool /*IsForDebug*/) const { |
| 87 | + OS << "GenConstantEdgeFn(" << Val << ")"; |
85 | 88 | } |
86 | | -void GenConstant::print(std::ostream &OS, bool /*IsForDebug*/) const { |
87 | | - OS << "GenConstantEdgeFn(" << Val << ")"; |
88 | | -} |
89 | | - |
90 | | -} // namespace psr |
| 89 | + |
| 90 | +} // namespace psr |
0 commit comments