1 //===- DebugSupport.cpp -----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines functions which generate more readable forms of data
10 // structures used in the dataflow analyses, for debugging purposes.
12 //===----------------------------------------------------------------------===//
16 #include "clang/Analysis/FlowSensitive/DebugSupport.h"
17 #include "clang/Analysis/FlowSensitive/Solver.h"
18 #include "clang/Analysis/FlowSensitive/Value.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/ErrorHandling.h"
25 llvm::StringRef
debugString(Value::Kind Kind
) {
27 case Value::Kind::Integer
:
29 case Value::Kind::Pointer
:
31 case Value::Kind::AtomicBool
:
33 case Value::Kind::TopBool
:
35 case Value::Kind::FormulaBool
:
38 llvm_unreachable("Unhandled value kind");
41 llvm::raw_ostream
&operator<<(llvm::raw_ostream
&OS
,
42 Solver::Result::Assignment Assignment
) {
44 case Solver::Result::Assignment::AssignedFalse
:
46 case Solver::Result::Assignment::AssignedTrue
:
49 llvm_unreachable("Booleans can only be assigned true/false");
52 llvm::StringRef
debugString(Solver::Result::Status Status
) {
54 case Solver::Result::Status::Satisfiable
:
56 case Solver::Result::Status::Unsatisfiable
:
57 return "Unsatisfiable";
58 case Solver::Result::Status::TimedOut
:
61 llvm_unreachable("Unhandled SAT check result status");
64 llvm::raw_ostream
&operator<<(llvm::raw_ostream
&OS
, const Solver::Result
&R
) {
65 OS
<< debugString(R
.getStatus()) << "\n";
66 if (auto Solution
= R
.getSolution()) {
67 std::vector
<std::pair
<Atom
, Solver::Result::Assignment
>> Sorted
= {
68 Solution
->begin(), Solution
->end()};
70 for (const auto &Entry
: Sorted
)
71 OS
<< Entry
.first
<< " = " << Entry
.second
<< "\n";
76 } // namespace dataflow