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