mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
f4d63759de
Adds missing API functions to PipelineC that will be needed by the GraphQL API: * Kinds enumeration * Get Rank and parent of a Kind * Enumerate and inspect Ranks * Get a Step's parent Included are some docstring fixes
66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
#pragma once
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "revng/ADT/STLExtras.h"
|
|
#include "revng/Pipeline/Kind.h"
|
|
#include "revng/Pipeline/Target.h"
|
|
#include "revng/Support/Assert.h"
|
|
|
|
namespace pipeline {
|
|
|
|
/// A KindsRegistry is a simple vector used to keep track of which kinds are
|
|
/// available in a particular pipeline
|
|
class KindsRegistry {
|
|
public:
|
|
using Container = llvm::SmallVector<Kind *, 4>;
|
|
|
|
private:
|
|
Container Kinds;
|
|
|
|
public:
|
|
KindsRegistry(llvm::SmallVector<Kind *, 4> Kinds = {}) :
|
|
Kinds(std::move(Kinds)) {}
|
|
|
|
void registerKind(Kind &K) {
|
|
revng_assert(not contains(K.name()));
|
|
Kinds.push_back(&K);
|
|
}
|
|
|
|
public:
|
|
auto begin() { return revng::dereferenceIterator(Kinds.begin()); }
|
|
auto end() { return revng::dereferenceIterator(Kinds.end()); }
|
|
auto begin() const { return revng::dereferenceIterator(Kinds.begin()); }
|
|
auto end() const { return revng::dereferenceIterator(Kinds.end()); }
|
|
|
|
const Kind *find(llvm::StringRef Name) const {
|
|
auto Iter = llvm::find_if(Kinds, [Name](const auto *Kind) {
|
|
return Kind->name() == Name;
|
|
});
|
|
if (Iter == Kinds.end())
|
|
return nullptr;
|
|
return *Iter;
|
|
}
|
|
|
|
bool contains(llvm::StringRef Name) { return find(Name) != nullptr; }
|
|
|
|
size_t size() const { return Kinds.size(); }
|
|
|
|
public:
|
|
template<typename OS>
|
|
void dump(OS &OStream) const {
|
|
for (const auto &K : *this)
|
|
OStream << K.name().str() << "\n";
|
|
}
|
|
|
|
void dump() const debug_function { dump(dbg); }
|
|
};
|
|
|
|
} // namespace pipeline
|