18#include "llvm/ADT/STLFunctionalExtras.h"
19#include "llvm/ADT/iterator_range.h"
20#include "llvm/Support/Error.h"
21#include "llvm/Support/JSON.h"
40 for (
const auto &[Id, EntityEdges] :
R.Edges) {
41 Content.push_back(IdToJSON(Id));
42 Content.push_back(json::Value(
edgeSetToJSON(EntityEdges, IdToJSON)));
59 if (Content->size() % 2 != 0)
61 "an even number of elements, got %lu",
62 static_cast<size_t>(Content->size()));
64 std::map<EntityId, EdgeSet> Edges;
66 for (
size_t I = 0; I < Content->size(); I += 2) {
67 const json::Object *IdData = (*Content)[I].getAsObject();
71 "an object representing EntityId");
73 auto Id = IdFromJSON(*IdData);
76 return Id.takeError();
78 const json::Array *EdgesData = (*Content)[I + 1].getAsArray();
82 "an array of arrays representing EdgeSet");
87 return EntityEdges.takeError();
88 Edges[*Id] = std::move(*EntityEdges);
91 auto Ret = std::make_unique<PointerFlowAnalysisResult>();
93 Ret->Edges = std::move(Edges);
97JSONFormat::AnalysisResultRegistry::Add<PointerFlowAnalysisResult>
98 RegisterPointerFlowResultForJSON(serializePointerFlowAnalysisResult,
99 deserializePointerFlowAnalysisResult);
101class PointerFlowAnalysis final
103 PointerFlowEntitySummary> {
105 llvm::Error add(EntityId Id,
106 const PointerFlowEntitySummary &Summary)
override {
107 auto EdgesOfEntity = getEdges(Summary);
109 getResult().Edges[Id] =
EdgeSet(EdgesOfEntity.begin(), EdgesOfEntity.end());
110 return llvm::Error::success();
115 RegisterPointerFlowAnalysis(
"Whole-program pointer flow analysis");
Result
Implement __builtin_bit_cast and related operations.
volatile int PointerFlowAnalysisAnchorSource
Typed intermediate that concrete summary analyses inherit from.
PRESERVE_NONE bool Ret(InterpState &S, CodePtr &PC)
llvm::json::Array edgeSetToJSON(llvm::iterator_range< EdgeSet::const_iterator > Edges, JSONFormat::EntityIdToJSONFn IdToJSON)
Serialize an EdgeSet {(src1, dest1), (src1, dest2), (src2, dest3), (src2, dest4), ....
std::map< EntityPointerLevel, EntityPointerLevelSet > EdgeSet
Maps each source node to its destination nodes:
llvm::Error makeSawButExpectedError(const JSONTy &Saw, llvm::StringRef Expected, const Ts &...ExpectedArgs)
llvm::Expected< EdgeSet > edgeSetFromJSON(const llvm::json::Array &EdgesData, JSONFormat::EntityIdFromJSONFn IdFromJSON)
Deserialize an EdgeSet from the array format produced by edgeSetToJSON.
constexpr llvm::StringLiteral PointerFlowAnalysisResultName
Diagnostic wrappers for TextAPI types for error reporting.
Registers AnalysisT with the unified registry.
A PointerFlowAnalysisResult is a set of pointer-flow edges, i.e., a pointer-flow graph.