/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/SymbolRemappingReader.cpp
Line | Count | Source |
1 | | //===- SymbolRemappingReader.cpp - Read symbol remapping file -------------===// |
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 | | // This file contains definitions needed for reading and applying symbol |
10 | | // remapping files. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "llvm/Support/SymbolRemappingReader.h" |
15 | | #include "llvm/ADT/StringSwitch.h" |
16 | | #include "llvm/ADT/Twine.h" |
17 | | #include "llvm/Support/LineIterator.h" |
18 | | |
19 | | using namespace llvm; |
20 | | |
21 | | char SymbolRemappingParseError::ID; |
22 | | |
23 | | /// Load a set of name remappings from a text file. |
24 | | /// |
25 | | /// See the documentation at the top of the file for an explanation of |
26 | | /// the expected format. |
27 | 19 | Error SymbolRemappingReader::read(MemoryBuffer &B) { |
28 | 19 | line_iterator LineIt(B, /*SkipBlanks=*/true, '#'); |
29 | 19 | |
30 | 19 | auto ReportError = [&](Twine Msg) { |
31 | 7 | return llvm::make_error<SymbolRemappingParseError>( |
32 | 7 | B.getBufferIdentifier(), LineIt.line_number(), Msg); |
33 | 7 | }; |
34 | 19 | |
35 | 64 | for (; !LineIt.is_at_eof(); ++LineIt45 ) { |
36 | 52 | StringRef Line = *LineIt; |
37 | 52 | Line = Line.ltrim(' '); |
38 | 52 | // line_iterator only detects comments starting in column 1. |
39 | 52 | if (Line.startswith("#") || Line.empty()43 ) |
40 | 14 | continue; |
41 | 38 | |
42 | 38 | SmallVector<StringRef, 4> Parts; |
43 | 38 | Line.split(Parts, ' ', /*MaxSplits*/-1, /*KeepEmpty*/false); |
44 | 38 | |
45 | 38 | if (Parts.size() != 3) |
46 | 1 | return ReportError("Expected 'kind mangled_name mangled_name', " |
47 | 1 | "found '" + Line + "'"); |
48 | 37 | |
49 | 37 | using FK = ItaniumManglingCanonicalizer::FragmentKind; |
50 | 37 | Optional<FK> FragmentKind = StringSwitch<Optional<FK>>(Parts[0]) |
51 | 37 | .Case("name", FK::Name) |
52 | 37 | .Case("type", FK::Type) |
53 | 37 | .Case("encoding", FK::Encoding) |
54 | 37 | .Default(None); |
55 | 37 | if (!FragmentKind) |
56 | 1 | return ReportError("Invalid kind, expected 'name', 'type', or 'encoding'," |
57 | 1 | " found '" + Parts[0] + "'"); |
58 | 36 | |
59 | 36 | using EE = ItaniumManglingCanonicalizer::EquivalenceError; |
60 | 36 | switch (Canonicalizer.addEquivalence(*FragmentKind, Parts[1], Parts[2])) { |
61 | 36 | case EE::Success: |
62 | 31 | break; |
63 | 36 | |
64 | 36 | case EE::ManglingAlreadyUsed: |
65 | 1 | return ReportError("Manglings '" + Parts[1] + "' and '" + Parts[2] + "' " |
66 | 1 | "have both been used in prior remappings. Move this " |
67 | 1 | "remapping earlier in the file."); |
68 | 36 | |
69 | 36 | case EE::InvalidFirstMangling: |
70 | 1 | return ReportError("Could not demangle '" + Parts[1] + "' " |
71 | 1 | "as a <" + Parts[0] + ">; invalid mangling?"); |
72 | 36 | |
73 | 36 | case EE::InvalidSecondMangling: |
74 | 3 | return ReportError("Could not demangle '" + Parts[2] + "' " |
75 | 3 | "as a <" + Parts[0] + ">; invalid mangling?"); |
76 | 36 | } |
77 | 36 | } |
78 | 19 | |
79 | 19 | return Error::success()12 ; |
80 | 19 | } |