2018-04-13 10:31:58 +08:00
|
|
|
//===--- XRayInstr.cpp ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-04-13 10:31:58 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is part of XRay, a function call instrumentation system.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Basic/XRayInstr.h"
|
2021-02-09 18:42:01 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2018-04-13 10:31:58 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
XRayInstrMask parseXRayInstrValue(StringRef Value) {
|
2020-01-18 05:24:27 +08:00
|
|
|
XRayInstrMask ParsedKind =
|
|
|
|
llvm::StringSwitch<XRayInstrMask>(Value)
|
|
|
|
.Case("all", XRayInstrKind::All)
|
|
|
|
.Case("custom", XRayInstrKind::Custom)
|
|
|
|
.Case("function",
|
|
|
|
XRayInstrKind::FunctionEntry | XRayInstrKind::FunctionExit)
|
|
|
|
.Case("function-entry", XRayInstrKind::FunctionEntry)
|
|
|
|
.Case("function-exit", XRayInstrKind::FunctionExit)
|
|
|
|
.Case("typed", XRayInstrKind::Typed)
|
|
|
|
.Case("none", XRayInstrKind::None)
|
|
|
|
.Default(XRayInstrKind::None);
|
2018-04-13 10:31:58 +08:00
|
|
|
return ParsedKind;
|
|
|
|
}
|
|
|
|
|
2021-02-09 18:42:01 +08:00
|
|
|
void serializeXRayInstrValue(XRayInstrSet Set,
|
|
|
|
SmallVectorImpl<StringRef> &Values) {
|
|
|
|
if (Set.Mask == XRayInstrKind::All) {
|
|
|
|
Values.push_back("all");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Set.Mask == XRayInstrKind::None) {
|
|
|
|
Values.push_back("none");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Set.has(XRayInstrKind::Custom))
|
|
|
|
Values.push_back("custom");
|
|
|
|
|
|
|
|
if (Set.has(XRayInstrKind::Typed))
|
|
|
|
Values.push_back("typed");
|
|
|
|
|
|
|
|
if (Set.has(XRayInstrKind::FunctionEntry) &&
|
|
|
|
Set.has(XRayInstrKind::FunctionExit))
|
|
|
|
Values.push_back("function");
|
|
|
|
else if (Set.has(XRayInstrKind::FunctionEntry))
|
|
|
|
Values.push_back("function-entry");
|
|
|
|
else if (Set.has(XRayInstrKind::FunctionExit))
|
|
|
|
Values.push_back("function-exit");
|
|
|
|
}
|
2018-04-13 10:31:58 +08:00
|
|
|
} // namespace clang
|