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:
42 : Name(Name), Kind(Kind) {}
43
44 static constexpr SymbolNameSpec verbatim(StringRef Name) {
45 return {Name, SymbolNameKind::Verbatim};
46 }
47 static constexpr SymbolNameSpec linker(StringRef Name) {
48 return {Name, SymbolNameKind::Linker};
49 }
50 static constexpr SymbolNameSpec ir(StringRef Name) {
51 return {Name, SymbolNameKind::IR};
52 }
53 static constexpr SymbolNameSpec c(StringRef Name) {
54 return {Name, SymbolNameKind::C};
55 }
56
57 constexpr StringRef getName() const { return Name; }
58 constexpr SymbolNameKind getKind() const { return Kind; }
59
60private:
61 StringRef Name;
62 SymbolNameKind Kind;
63};
64
65} // namespace llvm::orc
66
67#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
static constexpr SymbolNameSpec linker(StringRef Name)
static constexpr SymbolNameSpec ir(StringRef Name)
constexpr SymbolNameSpec(StringRef Name, SymbolNameKind Kind)
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...