106c3fb27SDimitry Andric //===- lib/TextAPI/SymbolSet.cpp - TAPI Symbol Set ------------*- C++-*----===//
206c3fb27SDimitry Andric //
306c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
406c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
506c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
606c3fb27SDimitry Andric //
706c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
806c3fb27SDimitry Andric
906c3fb27SDimitry Andric #include "llvm/TextAPI/SymbolSet.h"
1006c3fb27SDimitry Andric
1106c3fb27SDimitry Andric using namespace llvm;
1206c3fb27SDimitry Andric using namespace llvm::MachO;
1306c3fb27SDimitry Andric
addGlobalImpl(EncodeKind Kind,StringRef Name,SymbolFlags Flags)14*0fca6ea1SDimitry Andric Symbol *SymbolSet::addGlobalImpl(EncodeKind Kind, StringRef Name,
1506c3fb27SDimitry Andric SymbolFlags Flags) {
1606c3fb27SDimitry Andric Name = copyString(Name);
1706c3fb27SDimitry Andric auto Result = Symbols.try_emplace(SymbolsMapKey{Kind, Name}, nullptr);
1806c3fb27SDimitry Andric if (Result.second)
1906c3fb27SDimitry Andric Result.first->second =
2006c3fb27SDimitry Andric new (Allocator) Symbol{Kind, Name, TargetList(), Flags};
2106c3fb27SDimitry Andric return Result.first->second;
2206c3fb27SDimitry Andric }
2306c3fb27SDimitry Andric
addGlobal(EncodeKind Kind,StringRef Name,SymbolFlags Flags,const Target & Targ)24*0fca6ea1SDimitry Andric Symbol *SymbolSet::addGlobal(EncodeKind Kind, StringRef Name, SymbolFlags Flags,
2506c3fb27SDimitry Andric const Target &Targ) {
2606c3fb27SDimitry Andric auto *Sym = addGlobalImpl(Kind, Name, Flags);
2706c3fb27SDimitry Andric Sym->addTarget(Targ);
2806c3fb27SDimitry Andric return Sym;
2906c3fb27SDimitry Andric }
3006c3fb27SDimitry Andric
findSymbol(EncodeKind Kind,StringRef Name,ObjCIFSymbolKind ObjCIF) const31*0fca6ea1SDimitry Andric const Symbol *SymbolSet::findSymbol(EncodeKind Kind, StringRef Name,
32*0fca6ea1SDimitry Andric ObjCIFSymbolKind ObjCIF) const {
33*0fca6ea1SDimitry Andric if (auto result = Symbols.lookup({Kind, Name}))
34*0fca6ea1SDimitry Andric return result;
35*0fca6ea1SDimitry Andric if ((ObjCIF == ObjCIFSymbolKind::None) || (ObjCIF > ObjCIFSymbolKind::EHType))
36*0fca6ea1SDimitry Andric return nullptr;
37*0fca6ea1SDimitry Andric assert(ObjCIF <= ObjCIFSymbolKind::EHType &&
38*0fca6ea1SDimitry Andric "expected single ObjCIFSymbolKind enum value");
39*0fca6ea1SDimitry Andric // Non-complete ObjC Interfaces are represented as global symbols.
40*0fca6ea1SDimitry Andric if (ObjCIF == ObjCIFSymbolKind::Class)
41*0fca6ea1SDimitry Andric return Symbols.lookup(
42*0fca6ea1SDimitry Andric {EncodeKind::GlobalSymbol, (ObjC2ClassNamePrefix + Name).str()});
43*0fca6ea1SDimitry Andric if (ObjCIF == ObjCIFSymbolKind::MetaClass)
44*0fca6ea1SDimitry Andric return Symbols.lookup(
45*0fca6ea1SDimitry Andric {EncodeKind::GlobalSymbol, (ObjC2MetaClassNamePrefix + Name).str()});
46*0fca6ea1SDimitry Andric return Symbols.lookup(
47*0fca6ea1SDimitry Andric {EncodeKind::GlobalSymbol, (ObjC2EHTypePrefix + Name).str()});
4806c3fb27SDimitry Andric }
49