1 //===--- XRayInstr.cpp ------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This is part of XRay, a function call instrumentation system.
11 //===----------------------------------------------------------------------===//
13 #include "clang/Basic/XRayInstr.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringSwitch.h"
19 XRayInstrMask
parseXRayInstrValue(StringRef Value
) {
20 XRayInstrMask ParsedKind
=
21 llvm::StringSwitch
<XRayInstrMask
>(Value
)
22 .Case("all", XRayInstrKind::All
)
23 .Case("custom", XRayInstrKind::Custom
)
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
);
34 void serializeXRayInstrValue(XRayInstrSet Set
,
35 SmallVectorImpl
<StringRef
> &Values
) {
36 if (Set
.Mask
== XRayInstrKind::All
) {
37 Values
.push_back("all");
41 if (Set
.Mask
== XRayInstrKind::None
) {
42 Values
.push_back("none");
46 if (Set
.has(XRayInstrKind::Custom
))
47 Values
.push_back("custom");
49 if (Set
.has(XRayInstrKind::Typed
))
50 Values
.push_back("typed");
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");