Path: blob/main/contrib/llvm-project/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
35266 views
//===- DebugSupport.cpp -----------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines functions which generate more readable forms of data9// structures used in the dataflow analyses, for debugging purposes.10//11//===----------------------------------------------------------------------===//1213#include <utility>1415#include "clang/Analysis/FlowSensitive/DebugSupport.h"16#include "clang/Analysis/FlowSensitive/Solver.h"17#include "clang/Analysis/FlowSensitive/Value.h"18#include "llvm/ADT/StringRef.h"19#include "llvm/Support/ErrorHandling.h"2021namespace clang {22namespace dataflow {2324llvm::StringRef debugString(Value::Kind Kind) {25switch (Kind) {26case Value::Kind::Integer:27return "Integer";28case Value::Kind::Pointer:29return "Pointer";30case Value::Kind::AtomicBool:31return "AtomicBool";32case Value::Kind::TopBool:33return "TopBool";34case Value::Kind::FormulaBool:35return "FormulaBool";36}37llvm_unreachable("Unhandled value kind");38}3940llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,41Solver::Result::Assignment Assignment) {42switch (Assignment) {43case Solver::Result::Assignment::AssignedFalse:44return OS << "False";45case Solver::Result::Assignment::AssignedTrue:46return OS << "True";47}48llvm_unreachable("Booleans can only be assigned true/false");49}5051llvm::StringRef debugString(Solver::Result::Status Status) {52switch (Status) {53case Solver::Result::Status::Satisfiable:54return "Satisfiable";55case Solver::Result::Status::Unsatisfiable:56return "Unsatisfiable";57case Solver::Result::Status::TimedOut:58return "TimedOut";59}60llvm_unreachable("Unhandled SAT check result status");61}6263llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Solver::Result &R) {64OS << debugString(R.getStatus()) << "\n";65if (auto Solution = R.getSolution()) {66std::vector<std::pair<Atom, Solver::Result::Assignment>> Sorted = {67Solution->begin(), Solution->end()};68llvm::sort(Sorted);69for (const auto &Entry : Sorted)70OS << Entry.first << " = " << Entry.second << "\n";71}72return OS;73}7475} // namespace dataflow76} // namespace clang777879