@@ -56,30 +56,31 @@ class TAPIOptTable : public opt::GenericOptTable {
56
56
}
57
57
};
58
58
59
+ struct Context {
60
+ std::vector<std::string> Inputs;
61
+ std::unique_ptr<llvm::raw_fd_stream> OutStream;
62
+ FileType WriteFT = FileType::TBD_V5;
63
+ bool Compact = false ;
64
+ Architecture Arch = AK_unknown;
65
+ };
66
+
59
67
// Use unique exit code to differentiate failures not directly caused from
60
68
// TextAPI operations. This is used for wrapping `compare` operations in
61
69
// automation and scripting.
62
70
const int NON_TAPI_EXIT_CODE = 2 ;
63
71
const std::string TOOLNAME = " llvm-readtapi" ;
64
72
ExitOnError ExitOnErr;
73
+ } // anonymous namespace
65
74
66
75
// Handle error reporting in cases where `ExitOnError` is not used.
67
- void reportError (Twine Message, int ExitCode = EXIT_FAILURE) {
76
+ static void reportError (Twine Message, int ExitCode = EXIT_FAILURE) {
68
77
errs () << TOOLNAME << " : error: " << Message << " \n " ;
69
78
errs ().flush ();
70
79
exit (ExitCode);
71
80
}
72
81
73
- struct Context {
74
- std::vector<std::string> Inputs;
75
- std::unique_ptr<llvm::raw_fd_stream> OutStream;
76
- FileType WriteFT = FileType::TBD_V5;
77
- bool Compact = false ;
78
- Architecture Arch = AK_unknown;
79
- };
80
-
81
- std::unique_ptr<InterfaceFile> getInterfaceFile (const StringRef Filename,
82
- bool ResetBanner = true ) {
82
+ static std::unique_ptr<InterfaceFile>
83
+ getInterfaceFile (const StringRef Filename, bool ResetBanner = true ) {
83
84
ExitOnErr.setBanner (TOOLNAME + " : error: '" + Filename.str () + " ' " );
84
85
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
85
86
MemoryBuffer::getFile (Filename);
@@ -94,7 +95,7 @@ std::unique_ptr<InterfaceFile> getInterfaceFile(const StringRef Filename,
94
95
return std::move (*IF);
95
96
}
96
97
97
- bool handleCompareAction (const Context &Ctx) {
98
+ static bool handleCompareAction (const Context &Ctx) {
98
99
if (Ctx.Inputs .size () != 2 )
99
100
reportError (" compare only supports two input files" ,
100
101
/* ExitCode=*/ NON_TAPI_EXIT_CODE);
@@ -109,8 +110,8 @@ bool handleCompareAction(const Context &Ctx) {
109
110
return DiffEngine (LeftIF.get (), RightIF.get ()).compareFiles (OS);
110
111
}
111
112
112
- bool handleWriteAction (const Context &Ctx,
113
- std::unique_ptr<InterfaceFile> Out = nullptr ) {
113
+ static bool handleWriteAction (const Context &Ctx,
114
+ std::unique_ptr<InterfaceFile> Out = nullptr ) {
114
115
if (!Out) {
115
116
if (Ctx.Inputs .size () != 1 )
116
117
reportError (" write only supports one input file" );
@@ -121,7 +122,7 @@ bool handleWriteAction(const Context &Ctx,
121
122
return EXIT_SUCCESS;
122
123
}
123
124
124
- bool handleMergeAction (const Context &Ctx) {
125
+ static bool handleMergeAction (const Context &Ctx) {
125
126
if (Ctx.Inputs .size () < 2 )
126
127
reportError (" merge requires at least two input files" );
127
128
@@ -144,8 +145,8 @@ bool handleMergeAction(const Context &Ctx) {
144
145
using IFOperation =
145
146
std::function<llvm::Expected<std::unique_ptr<InterfaceFile>>(
146
147
const llvm::MachO::InterfaceFile &, Architecture)>;
147
- bool handleSingleFileAction (const Context &Ctx, const StringRef Action,
148
- IFOperation act) {
148
+ static bool handleSingleFileAction (const Context &Ctx, const StringRef Action,
149
+ IFOperation act) {
149
150
if (Ctx.Inputs .size () != 1 )
150
151
reportError (Action + " only supports one input file" );
151
152
if (Ctx.Arch == AK_unknown)
@@ -159,8 +160,6 @@ bool handleSingleFileAction(const Context &Ctx, const StringRef Action,
159
160
return handleWriteAction (Ctx, std::move (*OutIF));
160
161
}
161
162
162
- } // anonymous namespace
163
-
164
163
int main (int Argc, char **Argv) {
165
164
InitLLVM X (Argc, Argv);
166
165
BumpPtrAllocator A;
0 commit comments