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