clang 23.0.0git
SerializationFormatRegistry.h
Go to the documentation of this file.
1//===- SerializationFormatRegistry.h ----------------------------*- C++ -*-===//
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// Registry for SerializationFormats, and some helper functions.
10//
11// To register some custom serialization format, you will need to add some
12// declarations and defintions.
13//
14// Insert this code to the header file:
15//
16// namespace llvm {
17// extern template class CLANG_TEMPLATE_ABI
18// Registry<clang::ssaf::MyFormat::FormatInfo>;
19// } // namespace llvm
20//
21// Insert this declaration to the MyFormat class:
22//
23// using FormatInfo = FormatInfoEntry<SerializerFn, DeserializerFn>;
24//
25// Insert this code to the cpp file:
26//
27// // NOLINTNEXTLINE(misc-use-internal-linkage)
28// volatile int SSAFMyFormatAnchorSource = 0;
29// static SerializationFormatRegistry::Add<MyFormat>
30// RegisterFormat("MyFormat", "My awesome serialization format");
31// LLVM_INSTANTIATE_REGISTRY(llvm::Registry<MyFormat::FormatInfo>)
32//
33// Then implement the formatter for the specific analysis and register the
34// format info for it:
35//
36// namespace {
37// using FormatInfo = MyFormat::FormatInfo;
38// struct MyAnalysisFormatInfo final : FormatInfo {
39// MyAnalysisFormatInfo() : FormatInfo{
40// SummaryName("MyAnalysis"),
41// serializeMyAnalysis,
42// deserializeMyAnalysis,
43// } {}
44// };
45// } // namespace
46//
47// static llvm::Registry<FormatInfo>::Add<MyAnalysisFormatInfo>
48// RegisterFormatInfo(
49// "MyAnalysisFormatInfo",
50// "The MyFormat format info implementation for MyAnalysis"
51// );
52//
53// Finally, insert a use of the new anchor symbol into the force-linker header:
54// clang/include/clang/ScalableStaticAnalysisFramework/SSAFBuiltinForceLinker.h:
55//
56// This anchor is used to force the linker to link the MyFormat registration.
57//
58// extern volatile int SSAFMyFormatAnchorSource;
59// [[maybe_unused]] static int SSAFMyFormatAnchorDestination =
60// SSAFMyFormatAnchorSource;
61//
62//===----------------------------------------------------------------------===//
63
64#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_SERIALIZATION_SERIALIZATIONFORMATREGISTRY_H
65#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_SERIALIZATION_SERIALIZATIONFORMATREGISTRY_H
66
69#include "llvm/ADT/StringRef.h"
70#include "llvm/Support/Registry.h"
71#include "llvm/Support/raw_ostream.h"
72
73namespace clang::ssaf {
74
75/// Check if a SerializationFormat was registered with a given name.
76bool isFormatRegistered(llvm::StringRef FormatName);
77
78/// Try to instantiate a SerializationFormat with a given name.
79/// This might return null if the construction of the desired
80/// SerializationFormat failed.
81/// It's a fatal error if there is no format registered with the name.
82std::unique_ptr<SerializationFormat> makeFormat(llvm::StringRef FormatName);
83
84/// Print the list of available serialization formats.
85void printAvailableFormats(llvm::raw_ostream &OS);
86
87// Registry for adding new SerializationFormat implementations.
88using SerializationFormatRegistry = llvm::Registry<SerializationFormat>;
89
90} // namespace clang::ssaf
91
92namespace llvm {
93extern template class CLANG_TEMPLATE_ABI
94 Registry<clang::ssaf::SerializationFormat>;
95} // namespace llvm
96
97#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_SERIALIZATION_SERIALIZATIONFORMATREGISTRY_H
std::unique_ptr< SerializationFormat > makeFormat(llvm::StringRef FormatName)
Try to instantiate a SerializationFormat with a given name.
llvm::Registry< SerializationFormat > SerializationFormatRegistry
void printAvailableFormats(llvm::raw_ostream &OS)
Print the list of available serialization formats.
bool isFormatRegistered(llvm::StringRef FormatName)
Check if a SerializationFormat was registered with a given name.
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30