LLVM  8.0.1
SymbolRemappingReader.cpp
Go to the documentation of this file.
1 //===- SymbolRemappingReader.cpp - Read symbol remapping file -------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains definitions needed for reading and applying symbol
11 // remapping files.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/ADT/Twine.h"
19 
20 using namespace llvm;
21 
23 
24 /// Load a set of name remappings from a text file.
25 ///
26 /// See the documentation at the top of the file for an explanation of
27 /// the expected format.
29  line_iterator LineIt(B, /*SkipBlanks=*/true, '#');
30 
31  auto ReportError = [&](Twine Msg) {
32  return llvm::make_error<SymbolRemappingParseError>(
33  B.getBufferIdentifier(), LineIt.line_number(), Msg);
34  };
35 
36  for (; !LineIt.is_at_eof(); ++LineIt) {
37  StringRef Line = *LineIt;
38  Line = Line.ltrim(' ');
39  // line_iterator only detects comments starting in column 1.
40  if (Line.startswith("#") || Line.empty())
41  continue;
42 
44  Line.split(Parts, ' ', /*MaxSplits*/-1, /*KeepEmpty*/false);
45 
46  if (Parts.size() != 3)
47  return ReportError("Expected 'kind mangled_name mangled_name', "
48  "found '" + Line + "'");
49 
51  Optional<FK> FragmentKind = StringSwitch<Optional<FK>>(Parts[0])
52  .Case("name", FK::Name)
53  .Case("type", FK::Type)
54  .Case("encoding", FK::Encoding)
55  .Default(None);
56  if (!FragmentKind)
57  return ReportError("Invalid kind, expected 'name', 'type', or 'encoding',"
58  " found '" + Parts[0] + "'");
59 
61  switch (Canonicalizer.addEquivalence(*FragmentKind, Parts[1], Parts[2])) {
62  case EE::Success:
63  break;
64 
65  case EE::ManglingAlreadyUsed:
66  return ReportError("Manglings '" + Parts[1] + "' and '" + Parts[2] + "' "
67  "have both been used in prior remappings. Move this "
68  "remapping earlier in the file.");
69 
70  case EE::InvalidFirstMangling:
71  return ReportError("Could not demangle '" + Parts[1] + "' "
72  "as a <" + Parts[0] + ">; invalid mangling?");
73 
74  case EE::InvalidSecondMangling:
75  return ReportError("Could not demangle '" + Parts[2] + "' "
76  "as a <" + Parts[0] + ">; invalid mangling?");
77  }
78  }
79 
80  return Error::success();
81 }
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition: MemoryBuffer.h:70
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:49
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:32
LLVM_NODISCARD StringRef ltrim(char Char) const
Return string with consecutive Char characters starting from the the left removed.
Definition: StringRef.h:820
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
Definition: StringSwitch.h:203
bool is_at_eof() const
Return true if we&#39;ve reached EOF or are an "end" iterator.
Definition: LineIterator.h:50
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
int64_t line_number() const
Return the current line number. May return any number at EOF.
Definition: LineIterator.h:56
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Error read(MemoryBuffer &B)
Read remappings from the given buffer, which must live as long as the remapper.
size_t size() const
Definition: SmallVector.h:53
static ErrorSuccess success()
Create a success value.
Definition: Error.h:327
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:727
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:42
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:70
#define Success
EquivalenceError addEquivalence(FragmentKind Kind, StringRef First, StringRef Second)
Add an equivalence between First and Second.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static void LLVM_ATTRIBUTE_NORETURN ReportError(uint32_t StartOffset, const char *ErrorMsg)