Files
revng-revng/lib/HeadersGeneration/DependencyGraph.h
T
Giacomo Vercesi ab125b35b0 Fix License headers
Change company name to "rev.ng Labs Srl" in all license headers
to reflect changed company name and legal status
Add missing license headers to files that didn't have one
2022-04-19 12:17:59 +02:00

52 lines
1.4 KiB
C++

#pragma once
//
// Copyright (c) rev.ng Labs Srl. See LICENSE.md for details.
//
#include "llvm/Support/DOTGraphTraits.h"
#include "llvm/Support/GraphWriter.h"
#include "revng/ADT/GenericGraph.h"
#include "revng/Model/Type.h"
/// Represents a model::Type in the DependencyGraph
struct TypeNode {
/// A pointer to the associated model::Type
const model::Type *T;
/// For each model::Type we'll have nodes representing the type name or
/// the full type, depending on this enum.
enum Kind { TypeName, FullType } K;
};
using TypeDependencyNode = BidirectionalNode<TypeNode>;
using TypeKindPair = std::pair<const model::Type *, TypeNode::Kind>;
using TypeToDependencyNodeMap = std::map<TypeKindPair, TypeDependencyNode *>;
using TypeVector = SortedVector<UpcastablePointer<model::Type>>;
/// Represents the graph of dependencies among types
struct DependencyGraph : public GenericGraph<TypeDependencyNode> {
void addNode(const model::Type *T);
const TypeToDependencyNodeMap &TypeNodes() const { return TypeToNode; }
private:
TypeToDependencyNodeMap TypeToNode;
};
std::string getNodeLabel(const TypeDependencyNode *N);
template<>
struct llvm::DOTGraphTraits<DependencyGraph *>
: public llvm::DefaultDOTGraphTraits {
using llvm::DefaultDOTGraphTraits::DefaultDOTGraphTraits;
std::string
getNodeLabel(const TypeDependencyNode *N, const DependencyGraph *G);
};
DependencyGraph buildDependencyGraph(const TypeVector &Types);