XRayInstr.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //===--- XRayInstr.cpp ------------------------------------------*- 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. // This is part of XRay, a function call instrumentation system.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/Basic/XRayInstr.h"
  13. #include "llvm/ADT/SmallVector.h"
  14. #include "llvm/ADT/StringSwitch.h"
  15. namespace clang {
  16. XRayInstrMask parseXRayInstrValue(StringRef Value) {
  17. XRayInstrMask ParsedKind =
  18. llvm::StringSwitch<XRayInstrMask>(Value)
  19. .Case("all", XRayInstrKind::All)
  20. .Case("custom", XRayInstrKind::Custom)
  21. .Case("function",
  22. XRayInstrKind::FunctionEntry | XRayInstrKind::FunctionExit)
  23. .Case("function-entry", XRayInstrKind::FunctionEntry)
  24. .Case("function-exit", XRayInstrKind::FunctionExit)
  25. .Case("typed", XRayInstrKind::Typed)
  26. .Case("none", XRayInstrKind::None)
  27. .Default(XRayInstrKind::None);
  28. return ParsedKind;
  29. }
  30. void serializeXRayInstrValue(XRayInstrSet Set,
  31. SmallVectorImpl<StringRef> &Values) {
  32. if (Set.Mask == XRayInstrKind::All) {
  33. Values.push_back("all");
  34. return;
  35. }
  36. if (Set.Mask == XRayInstrKind::None) {
  37. Values.push_back("none");
  38. return;
  39. }
  40. if (Set.has(XRayInstrKind::Custom))
  41. Values.push_back("custom");
  42. if (Set.has(XRayInstrKind::Typed))
  43. Values.push_back("typed");
  44. if (Set.has(XRayInstrKind::FunctionEntry) &&
  45. Set.has(XRayInstrKind::FunctionExit))
  46. Values.push_back("function");
  47. else if (Set.has(XRayInstrKind::FunctionEntry))
  48. Values.push_back("function-entry");
  49. else if (Set.has(XRayInstrKind::FunctionExit))
  50. Values.push_back("function-exit");
  51. }
  52. } // namespace clang