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

source code of clang/lib/Basic/XRayInstr.cpp