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