flags_parser.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #ifndef SCUDO_FLAGS_PARSER_H_
  9. #define SCUDO_FLAGS_PARSER_H_
  10. #include "report.h"
  11. #include "string_utils.h"
  12. #include <stddef.h>
  13. namespace scudo {
  14. enum class FlagType : u8 {
  15. FT_bool,
  16. FT_int,
  17. };
  18. class FlagParser {
  19. public:
  20. void registerFlag(const char *Name, const char *Desc, FlagType Type,
  21. void *Var);
  22. void parseString(const char *S);
  23. void printFlagDescriptions();
  24. private:
  25. static const u32 MaxFlags = 20;
  26. struct Flag {
  27. const char *Name;
  28. const char *Desc;
  29. FlagType Type;
  30. void *Var;
  31. } Flags[MaxFlags];
  32. u32 NumberOfFlags = 0;
  33. const char *Buffer = nullptr;
  34. uptr Pos = 0;
  35. void reportFatalError(const char *Error);
  36. void skipWhitespace();
  37. void parseFlags();
  38. void parseFlag();
  39. bool runHandler(const char *Name, const char *Value);
  40. };
  41. void reportUnrecognizedFlags();
  42. } // namespace scudo
  43. #endif // SCUDO_FLAGS_PARSER_H_