xref: /freebsd/contrib/llvm-project/llvm/lib/TextAPI/SymbolSet.cpp (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1*06c3fb27SDimitry Andric //===- lib/TextAPI/SymbolSet.cpp - TAPI Symbol Set ------------*- C++-*----===//
2*06c3fb27SDimitry Andric //
3*06c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*06c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*06c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*06c3fb27SDimitry Andric //
7*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
8*06c3fb27SDimitry Andric 
9*06c3fb27SDimitry Andric #include "llvm/TextAPI/SymbolSet.h"
10*06c3fb27SDimitry Andric 
11*06c3fb27SDimitry Andric using namespace llvm;
12*06c3fb27SDimitry Andric using namespace llvm::MachO;
13*06c3fb27SDimitry Andric 
14*06c3fb27SDimitry Andric Symbol *SymbolSet::addGlobalImpl(SymbolKind Kind, StringRef Name,
15*06c3fb27SDimitry Andric                                  SymbolFlags Flags) {
16*06c3fb27SDimitry Andric   Name = copyString(Name);
17*06c3fb27SDimitry Andric   auto Result = Symbols.try_emplace(SymbolsMapKey{Kind, Name}, nullptr);
18*06c3fb27SDimitry Andric   if (Result.second)
19*06c3fb27SDimitry Andric     Result.first->second =
20*06c3fb27SDimitry Andric         new (Allocator) Symbol{Kind, Name, TargetList(), Flags};
21*06c3fb27SDimitry Andric   return Result.first->second;
22*06c3fb27SDimitry Andric }
23*06c3fb27SDimitry Andric 
24*06c3fb27SDimitry Andric Symbol *SymbolSet::addGlobal(SymbolKind Kind, StringRef Name, SymbolFlags Flags,
25*06c3fb27SDimitry Andric                              const Target &Targ) {
26*06c3fb27SDimitry Andric   auto *Sym = addGlobalImpl(Kind, Name, Flags);
27*06c3fb27SDimitry Andric   Sym->addTarget(Targ);
28*06c3fb27SDimitry Andric   return Sym;
29*06c3fb27SDimitry Andric }
30*06c3fb27SDimitry Andric 
31*06c3fb27SDimitry Andric const Symbol *SymbolSet::findSymbol(SymbolKind Kind, StringRef Name) const {
32*06c3fb27SDimitry Andric   auto It = Symbols.find({Kind, Name});
33*06c3fb27SDimitry Andric   if (It != Symbols.end())
34*06c3fb27SDimitry Andric     return It->second;
35*06c3fb27SDimitry Andric   return nullptr;
36*06c3fb27SDimitry Andric }
37