clang 23.0.0git
Utils.h
Go to the documentation of this file.
1//===- Utils.h - Shared utilities for SSAF tools ----------------*- 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// Shared error-handling, format-registry cache, and summary-file abstraction
10// used by clang-ssaf-linker and clang-ssaf-format.
11//
12// All declarations live in the clang::ssaf namespace.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_TOOL_UTILS_H
17#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_TOOL_UTILS_H
18
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/CommandLine.h"
23#include "llvm/Support/Error.h"
24#include "llvm/Support/FormatVariadic.h"
25#include <string>
26
27namespace clang::ssaf {
28
29//===----------------------------------------------------------------------===//
30// Tool Identity
31//===----------------------------------------------------------------------===//
32
33/// Returns the name of the running tool, as set by initTool().
34llvm::StringRef getToolName();
35
36//===----------------------------------------------------------------------===//
37// Error Messages
38//===----------------------------------------------------------------------===//
39
40namespace ErrorMessages {
41
42constexpr const char *CannotValidateSummary =
43 "failed to validate summary '{0}': {1}";
44
45constexpr const char *ExtensionNotSupplied = "Extension not supplied";
46
47constexpr const char *NoFormatForExtension =
48 "Format not registered for extension '{0}'";
49
50constexpr const char *OutputDirectoryMissing =
51 "Parent directory does not exist";
52
53constexpr const char *FailedToLoadPlugin = "failed to load plugin '{0}': {1}";
54
55} // namespace ErrorMessages
56
57//===----------------------------------------------------------------------===//
58// Diagnostic Utilities
59//===----------------------------------------------------------------------===//
60
61[[noreturn]] void fail(const char *Msg);
62
63template <typename... Ts>
64[[noreturn]] inline void fail(const char *Fmt, Ts &&...Args) {
65 std::string Message = llvm::formatv(Fmt, std::forward<Ts>(Args)...);
66 fail(Message.data());
67}
68
69[[noreturn]] void fail(llvm::Error Err);
70
71//===----------------------------------------------------------------------===//
72// Plugin Loading
73//===----------------------------------------------------------------------===//
74
76
77//===----------------------------------------------------------------------===//
78// Initialization
79//===----------------------------------------------------------------------===//
80
81/// Sets ToolName, ToolVersion, and the version printer, hides unrelated
82/// command-line options, and parses arguments. Must be called after InitLLVM.
83void initTool(int argc, const char **argv, llvm::StringRef Version,
84 llvm::cl::OptionCategory &Category, llvm::StringRef ToolHeading);
85
86//===----------------------------------------------------------------------===//
87// Data Structures
88//===----------------------------------------------------------------------===//
89
91 std::string Path;
93
94 /// Constructs a SummaryFile by resolving the serialization format from the
95 /// file extension. Calls fail() and exits if the extension is missing or
96 /// unregistered.
97 static SummaryFile fromPath(llvm::StringRef Path);
98};
99
100} // namespace clang::ssaf
101
102#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_TOOL_UTILS_H
Abstract base class for serialization formats.
constexpr const char * ExtensionNotSupplied
Definition Utils.h:45
constexpr const char * CannotValidateSummary
Definition Utils.h:42
constexpr const char * NoFormatForExtension
Definition Utils.h:47
constexpr const char * OutputDirectoryMissing
Definition Utils.h:50
constexpr const char * FailedToLoadPlugin
Definition Utils.h:53
llvm::StringRef getToolName()
Returns the name of the running tool, as set by initTool().
Definition Utils.cpp:77
void fail(const char *Msg)
Definition Utils.cpp:79
void initTool(int argc, const char **argv, llvm::StringRef Version, llvm::cl::OptionCategory &Category, llvm::StringRef ToolHeading)
Sets ToolName, ToolVersion, and the version printer, hides unrelated command-line options,...
Definition Utils.cpp:99
void loadPlugins(llvm::ArrayRef< std::string > Paths)
Definition Utils.cpp:89
#define noreturn
Definition stdnoreturn.h:17
SerializationFormat * Format
Definition Utils.h:92
static SummaryFile fromPath(llvm::StringRef Path)
Constructs a SummaryFile by resolving the serialization format from the file extension.
Definition Utils.cpp:119
std::string Path
Definition Utils.h:91