flags_parser.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. void parseStringPair(const char *Name, const char *Value);
  25. private:
  26. static const u32 MaxFlags = 20;
  27. struct Flag {
  28. const char *Name;
  29. const char *Desc;
  30. FlagType Type;
  31. void *Var;
  32. } Flags[MaxFlags];
  33. u32 NumberOfFlags = 0;
  34. const char *Buffer = nullptr;
  35. uptr Pos = 0;
  36. void reportFatalError(const char *Error);
  37. void skipWhitespace();
  38. void parseFlags();
  39. void parseFlag();
  40. bool runHandler(const char *Name, const char *Value, char Sep);
  41. };
  42. void reportUnrecognizedFlags();
  43. } // namespace scudo
  44. #endif // SCUDO_FLAGS_PARSER_H_