llvm-project
60 строк · 2.0 Кб
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) {20XRayInstrMask ParsedKind =21llvm::StringSwitch<XRayInstrMask>(Value)22.Case("all", XRayInstrKind::All)23.Case("custom", XRayInstrKind::Custom)24.Case("function",25XRayInstrKind::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);31return ParsedKind;32}
33
34void serializeXRayInstrValue(XRayInstrSet Set,35SmallVectorImpl<StringRef> &Values) {36if (Set.Mask == XRayInstrKind::All) {37Values.push_back("all");38return;39}40
41if (Set.Mask == XRayInstrKind::None) {42Values.push_back("none");43return;44}45
46if (Set.has(XRayInstrKind::Custom))47Values.push_back("custom");48
49if (Set.has(XRayInstrKind::Typed))50Values.push_back("typed");51
52if (Set.has(XRayInstrKind::FunctionEntry) &&53Set.has(XRayInstrKind::FunctionExit))54Values.push_back("function");55else if (Set.has(XRayInstrKind::FunctionEntry))56Values.push_back("function-entry");57else if (Set.has(XRayInstrKind::FunctionExit))58Values.push_back("function-exit");59}
60} // namespace clang61