xref: /freebsd/contrib/llvm-project/compiler-rt/lib/scudo/standalone/flags_parser.h (revision 18054d0220cfc8df9c9568c437bd6fbb59d53c3c)
1 //===-- flags_parser.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 #ifndef SCUDO_FLAGS_PARSER_H_
10 #define SCUDO_FLAGS_PARSER_H_
11 
12 #include "report.h"
13 #include "string_utils.h"
14 
15 #include <stddef.h>
16 
17 namespace scudo {
18 
19 enum class FlagType : u8 {
20   FT_bool,
21   FT_int,
22 };
23 
24 class FlagParser {
25 public:
26   void registerFlag(const char *Name, const char *Desc, FlagType Type,
27                     void *Var);
28   void parseString(const char *S);
29   void printFlagDescriptions();
30 
31 private:
32   static const u32 MaxFlags = 20;
33   struct Flag {
34     const char *Name;
35     const char *Desc;
36     FlagType Type;
37     void *Var;
38   } Flags[MaxFlags];
39 
40   u32 NumberOfFlags = 0;
41   const char *Buffer = nullptr;
42   uptr Pos = 0;
43 
44   void reportFatalError(const char *Error);
45   void skipWhitespace();
46   void parseFlags();
47   void parseFlag();
48   bool runHandler(const char *Name, const char *Value);
49 };
50 
51 void reportUnrecognizedFlags();
52 
53 } // namespace scudo
54 
55 #endif // SCUDO_FLAGS_PARSER_H_
56