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// LLVM_INSTANTIATE_REGISTRY(llvm::Registry<MyFormat::FormatInfo>)
28//
29// static SerializationFormatRegistry::Add<MyFormat>
30// RegisterFormat("MyFormat", "My awesome serialization format");
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//===----------------------------------------------------------------------===//
53
54#ifndef CLANG_ANALYSIS_SCALABLE_SERIALIZATION_SERIALIZATION_FORMAT_REGISTRY_H
55#define CLANG_ANALYSIS_SCALABLE_SERIALIZATION_SERIALIZATION_FORMAT_REGISTRY_H
56
59#include "llvm/ADT/StringRef.h"
60#include "llvm/Support/Registry.h"
61
62namespace clang::ssaf {
63
64/// Check if a SerializationFormat was registered with a given name.
65bool isFormatRegistered(llvm::StringRef FormatName);
66
67/// Try to instantiate a SerializationFormat with a given name.
68/// This might return null if the construction of the desired
69/// SerializationFormat failed.
70/// It's a fatal error if there is no format registered with the name.
71std::unique_ptr<SerializationFormat> makeFormat(llvm::StringRef FormatName);
72
73// Registry for adding new SerializationFormat implementations.
74using SerializationFormatRegistry = llvm::Registry<SerializationFormat>;
75
76} // namespace clang::ssaf
77
78namespace llvm {
79extern template class CLANG_TEMPLATE_ABI
80 Registry<clang::ssaf::SerializationFormat>;
81} // namespace llvm
82
83#endif // CLANG_ANALYSIS_SCALABLE_SERIALIZATION_SERIALIZATION_FORMAT_REGISTRY_H
std::unique_ptr< SerializationFormat > makeFormat(llvm::StringRef FormatName)
Try to instantiate a SerializationFormat with a given name.
llvm::Registry< SerializationFormat > SerializationFormatRegistry
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