xref: /freebsd/contrib/llvm-project/clang/lib/Basic/XRayInstr.cpp (revision 02e9120893770924227138ba49df1edb3896112a)
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 
13 #include "clang/Basic/XRayInstr.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringSwitch.h"
16 
17 namespace clang {
18 
19 XRayInstrMask parseXRayInstrValue(StringRef Value) {
20   XRayInstrMask ParsedKind =
21       llvm::StringSwitch<XRayInstrMask>(Value)
22           .Case("all", XRayInstrKind::All)
23           .Case("custom", XRayInstrKind::Custom)
24           .Case("function",
25                 XRayInstrKind::FunctionEntry | XRayInstrKind::FunctionExit)
26           .Case("function-entry", XRayInstrKind::FunctionEntry)
27           .Case("function-exit", XRayInstrKind::FunctionExit)
28           .Case("typed", XRayInstrKind::Typed)
29           .Case("none", XRayInstrKind::None)
30           .Default(XRayInstrKind::None);
31   return ParsedKind;
32 }
33 
34 void serializeXRayInstrValue(XRayInstrSet Set,
35                              SmallVectorImpl<StringRef> &Values) {
36   if (Set.Mask == XRayInstrKind::All) {
37     Values.push_back("all");
38     return;
39   }
40 
41   if (Set.Mask == XRayInstrKind::None) {
42     Values.push_back("none");
43     return;
44   }
45 
46   if (Set.has(XRayInstrKind::Custom))
47     Values.push_back("custom");
48 
49   if (Set.has(XRayInstrKind::Typed))
50     Values.push_back("typed");
51 
52   if (Set.has(XRayInstrKind::FunctionEntry) &&
53       Set.has(XRayInstrKind::FunctionExit))
54     Values.push_back("function");
55   else if (Set.has(XRayInstrKind::FunctionEntry))
56     Values.push_back("function-entry");
57   else if (Set.has(XRayInstrKind::FunctionExit))
58     Values.push_back("function-exit");
59 }
60 } // namespace clang
61