1 //===-- DebugSupport.h ------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines functions which generate more readable forms of data 10 // structures used in the dataflow analyses, for debugging purposes. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_DEBUGSUPPORT_H_ 15 #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_DEBUGSUPPORT_H_ 16 17 #include <string> 18 #include <vector> 19 20 #include "clang/Analysis/FlowSensitive/Solver.h" 21 #include "clang/Analysis/FlowSensitive/Value.h" 22 #include "llvm/ADT/DenseMap.h" 23 24 namespace clang { 25 namespace dataflow { 26 27 /// Returns a string representation of a boolean assignment to true or false. 28 std::string debugString(Solver::Result::Assignment Assignment); 29 30 /// Returns a string representation of the result status of a SAT check. 31 std::string debugString(Solver::Result::Status Status); 32 33 /// Returns a string representation for the boolean value `B`. 34 /// 35 /// Atomic booleans appearing in the boolean value `B` are assigned to labels 36 /// either specified in `AtomNames` or created by default rules as B0, B1, ... 37 /// 38 /// Requirements: 39 /// 40 /// Names assigned to atoms should not be repeated in `AtomNames`. 41 std::string debugString( 42 const BoolValue &B, 43 llvm::DenseMap<const AtomicBoolValue *, std::string> AtomNames = {{}}); 44 45 /// Returns a string representation for `Constraints` - a collection of boolean 46 /// formulas. 47 /// 48 /// Atomic booleans appearing in the boolean value `Constraints` are assigned to 49 /// labels either specified in `AtomNames` or created by default rules as B0, 50 /// B1, ... 51 /// 52 /// Requirements: 53 /// 54 /// Names assigned to atoms should not be repeated in `AtomNames`. 55 std::string debugString( 56 const llvm::DenseSet<BoolValue *> &Constraints, 57 llvm::DenseMap<const AtomicBoolValue *, std::string> AtomNames = {{}}); 58 59 /// Returns a string representation for `Constraints` - a collection of boolean 60 /// formulas and the `Result` of satisfiability checking. 61 /// 62 /// Atomic booleans appearing in `Constraints` and `Result` are assigned to 63 /// labels either specified in `AtomNames` or created by default rules as B0, 64 /// B1, ... 65 /// 66 /// Requirements: 67 /// 68 /// Names assigned to atoms should not be repeated in `AtomNames`. 69 std::string debugString( 70 ArrayRef<BoolValue *> Constraints, const Solver::Result &Result, 71 llvm::DenseMap<const AtomicBoolValue *, std::string> AtomNames = {{}}); 72 inline std::string debugString( 73 const llvm::DenseSet<BoolValue *> &Constraints, 74 const Solver::Result &Result, 75 llvm::DenseMap<const AtomicBoolValue *, std::string> AtomNames = {{}}) { 76 std::vector<BoolValue *> ConstraintsVec(Constraints.begin(), 77 Constraints.end()); 78 return debugString(ConstraintsVec, Result, std::move(AtomNames)); 79 } 80 81 } // namespace dataflow 82 } // namespace clang 83 84 #endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_DEBUGSUPPORT_H_ 85