LLVM 24.0.0git
SymbolNameSpec.h
Go to the documentation of this file.
1//===- SymbolNameSpec.h - A symbol name plus its mangling kind --*- 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// A symbol name paired with the naming level it is expressed in.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_SYMBOLNAMESPEC_H
14#define LLVM_EXECUTIONENGINE_ORC_SHARED_SYMBOLNAMESPEC_H
15
16#include "llvm/ADT/StringRef.h"
17
18namespace llvm::orc {
19
20/// The naming level a symbol name is expressed in, which determines how it is
21/// mangled before being interned for lookup.
22enum class SymbolNameKind {
23 Verbatim, // Use the name as given, with no mangling.
24 Linker, // An already-decorated linker name; a synonym for Verbatim.
25 IR, // An IR global name; mangled to linker level for the target.
26 C, // A C source name; handled identically to IR.
27};
28
29/// A symbol name together with the naming level (SymbolNameKind) it is
30/// expressed in, so that a Mangler / MangleAndInterner can mangle it to linker
31/// level rather than requiring callers to pre-mangle.
32///
33/// The name is not copied: a SymbolNameSpec must not outlive the string it
34/// refers to.
35///
36/// Implicitly constructible from a StringRef, defaulting to Verbatim, so that
37/// APIs taking a SymbolNameSpec stay drop-in replacements for ones that
38/// previously took an already-mangled StringRef.
40public:
41 constexpr SymbolNameSpec(StringRef Name,
43 : Name(Name), Kind(Kind) {}
44
45 static constexpr SymbolNameSpec verbatim(StringRef Name) {
46 return {Name, SymbolNameKind::Verbatim};
47 }
48 static constexpr SymbolNameSpec linker(StringRef Name) {
49 return {Name, SymbolNameKind::Linker};
50 }
51 static constexpr SymbolNameSpec ir(StringRef Name) {
52 return {Name, SymbolNameKind::IR};
53 }
54 static constexpr SymbolNameSpec c(StringRef Name) {
55 return {Name, SymbolNameKind::C};
56 }
57
58 constexpr StringRef getName() const { return Name; }
59 constexpr SymbolNameKind getKind() const { return Kind; }
60
61private:
62 StringRef Name;
63 SymbolNameKind Kind;
64};
65
66} // namespace llvm::orc
67
68#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_SYMBOLNAMESPEC_H
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static constexpr SymbolNameSpec c(StringRef Name)
constexpr StringRef getName() const
constexpr SymbolNameSpec(StringRef Name, SymbolNameKind Kind=SymbolNameKind::Verbatim)
static constexpr SymbolNameSpec linker(StringRef Name)
static constexpr SymbolNameSpec ir(StringRef Name)
static constexpr SymbolNameSpec verbatim(StringRef Name)
constexpr SymbolNameKind getKind() const
SymbolNameKind
The naming level a symbol name is expressed in, which determines how it is mangled before being inter...