1//===- AnalysisRegistry.cpp -----------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include "clang/ScalableStaticAnalysis/Core/WholeProgramAnalysis/AnalysisRegistry.h"
10#include "clang/ScalableStaticAnalysis/Core/Support/ErrorBuilder.h"
11#include "llvm/ADT/STLExtras.h"
12
13using namespace clang;
14using namespace ssaf;
15
16namespace clang::ssaf {
17// NOLINTNEXTLINE(misc-use-internal-linkage)
18volatile int AnalysisRegistryAnchorSource = 0;
19} // namespace clang::ssaf
20
21LLVM_DEFINE_REGISTRY(llvm::Registry<AnalysisBase>)
22
23std::vector<AnalysisName> &AnalysisRegistry::getAnalysisNames() {
24 static std::vector<AnalysisName> Names;
25 return Names;
26}
27
28bool AnalysisRegistry::contains(const AnalysisName &Name) {
29 return llvm::is_contained(Range&: getAnalysisNames(), Element: Name);
30}
31
32const std::vector<AnalysisName> &AnalysisRegistry::names() {
33 return getAnalysisNames();
34}
35
36llvm::Expected<std::unique_ptr<AnalysisBase>>
37AnalysisRegistry::instantiate(const AnalysisName &Name) {
38 for (const auto &Entry : llvm::Registry<AnalysisBase>::entries()) {
39 if (Entry.getName() == Name.str()) {
40 return std::unique_ptr<AnalysisBase>(Entry.instantiate());
41 }
42 }
43 return ErrorBuilder::create(EC: std::errc::invalid_argument,
44 Fmt: "no analysis registered for '{0}'", ArgVals: Name)
45 .build();
46}
47