1488f7c2bSDean Michael Berris //===--- XRayInstr.cpp ------------------------------------------*- C++ -*-===//
2488f7c2bSDean Michael Berris //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6488f7c2bSDean Michael Berris //
7488f7c2bSDean Michael Berris //===----------------------------------------------------------------------===//
8488f7c2bSDean Michael Berris //
9488f7c2bSDean Michael Berris // This is part of XRay, a function call instrumentation system.
10488f7c2bSDean Michael Berris //
11488f7c2bSDean Michael Berris //===----------------------------------------------------------------------===//
12488f7c2bSDean Michael Berris
13488f7c2bSDean Michael Berris #include "clang/Basic/XRayInstr.h"
14*e721bc9eSJan Svoboda #include "llvm/ADT/SmallVector.h"
15488f7c2bSDean Michael Berris #include "llvm/ADT/StringSwitch.h"
16488f7c2bSDean Michael Berris
17488f7c2bSDean Michael Berris namespace clang {
18488f7c2bSDean Michael Berris
parseXRayInstrValue(StringRef Value)19488f7c2bSDean Michael Berris XRayInstrMask parseXRayInstrValue(StringRef Value) {
2097ba4830SIan Levesque XRayInstrMask ParsedKind =
2197ba4830SIan Levesque llvm::StringSwitch<XRayInstrMask>(Value)
22488f7c2bSDean Michael Berris .Case("all", XRayInstrKind::All)
23488f7c2bSDean Michael Berris .Case("custom", XRayInstrKind::Custom)
2497ba4830SIan Levesque .Case("function",
2597ba4830SIan Levesque XRayInstrKind::FunctionEntry | XRayInstrKind::FunctionExit)
2697ba4830SIan Levesque .Case("function-entry", XRayInstrKind::FunctionEntry)
2797ba4830SIan Levesque .Case("function-exit", XRayInstrKind::FunctionExit)
28f437e356SKeith Wyss .Case("typed", XRayInstrKind::Typed)
29488f7c2bSDean Michael Berris .Case("none", XRayInstrKind::None)
30488f7c2bSDean Michael Berris .Default(XRayInstrKind::None);
31488f7c2bSDean Michael Berris return ParsedKind;
32488f7c2bSDean Michael Berris }
33488f7c2bSDean Michael Berris
serializeXRayInstrValue(XRayInstrSet Set,SmallVectorImpl<StringRef> & Values)34*e721bc9eSJan Svoboda void serializeXRayInstrValue(XRayInstrSet Set,
35*e721bc9eSJan Svoboda SmallVectorImpl<StringRef> &Values) {
36*e721bc9eSJan Svoboda if (Set.Mask == XRayInstrKind::All) {
37*e721bc9eSJan Svoboda Values.push_back("all");
38*e721bc9eSJan Svoboda return;
39*e721bc9eSJan Svoboda }
40*e721bc9eSJan Svoboda
41*e721bc9eSJan Svoboda if (Set.Mask == XRayInstrKind::None) {
42*e721bc9eSJan Svoboda Values.push_back("none");
43*e721bc9eSJan Svoboda return;
44*e721bc9eSJan Svoboda }
45*e721bc9eSJan Svoboda
46*e721bc9eSJan Svoboda if (Set.has(XRayInstrKind::Custom))
47*e721bc9eSJan Svoboda Values.push_back("custom");
48*e721bc9eSJan Svoboda
49*e721bc9eSJan Svoboda if (Set.has(XRayInstrKind::Typed))
50*e721bc9eSJan Svoboda Values.push_back("typed");
51*e721bc9eSJan Svoboda
52*e721bc9eSJan Svoboda if (Set.has(XRayInstrKind::FunctionEntry) &&
53*e721bc9eSJan Svoboda Set.has(XRayInstrKind::FunctionExit))
54*e721bc9eSJan Svoboda Values.push_back("function");
55*e721bc9eSJan Svoboda else if (Set.has(XRayInstrKind::FunctionEntry))
56*e721bc9eSJan Svoboda Values.push_back("function-entry");
57*e721bc9eSJan Svoboda else if (Set.has(XRayInstrKind::FunctionExit))
58*e721bc9eSJan Svoboda Values.push_back("function-exit");
59*e721bc9eSJan Svoboda }
60488f7c2bSDean Michael Berris } // namespace clang
61