1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/AsmParser/AsmParserContext.h"
namespace llvm {
std::optional<FileLocRange>
AsmParserContext::getFunctionLocation(const Function *F) const {
if (auto FIt = Functions.find(F); FIt != Functions.end())
return FIt->second;
return std::nullopt;
}
std::optional<FileLocRange>
AsmParserContext::getBlockLocation(const BasicBlock *BB) const {
if (auto BBIt = Blocks.find(BB); BBIt != Blocks.end())
return BBIt->second;
return std::nullopt;
}
std::optional<FileLocRange>
AsmParserContext::getInstructionLocation(const Instruction *I) const {
if (auto IIt = Instructions.find(I); IIt != Instructions.end())
return IIt->second;
return std::nullopt;
}
Function *
AsmParserContext::getFunctionAtLocation(const FileLocRange &Query) const {
for (auto &[F, Loc] : Functions) {
if (Loc.contains(Query))
return F;
}
return nullptr;
}
Function *AsmParserContext::getFunctionAtLocation(const FileLoc &Query) const {
return getFunctionAtLocation(FileLocRange(Query, Query));
}
BasicBlock *
AsmParserContext::getBlockAtLocation(const FileLocRange &Query) const {
for (auto &[BB, Loc] : Blocks) {
if (Loc.contains(Query))
return BB;
}
return nullptr;
}
BasicBlock *AsmParserContext::getBlockAtLocation(const FileLoc &Query) const {
return getBlockAtLocation(FileLocRange(Query, Query));
}
Instruction *
AsmParserContext::getInstructionAtLocation(const FileLocRange &Query) const {
for (auto &[I, Loc] : Instructions) {
if (Loc.contains(Query))
return I;
}
return nullptr;
}
Instruction *
AsmParserContext::getInstructionAtLocation(const FileLoc &Query) const {
return getInstructionAtLocation(FileLocRange(Query, Query));
}
bool AsmParserContext::addFunctionLocation(Function *F,
const FileLocRange &Loc) {
return Functions.insert({F, Loc}).second;
}
bool AsmParserContext::addBlockLocation(BasicBlock *BB,
const FileLocRange &Loc) {
return Blocks.insert({BB, Loc}).second;
}
bool AsmParserContext::addInstructionLocation(Instruction *I,
const FileLocRange &Loc) {
return Instructions.insert({I, Loc}).second;
}
} // namespace llvm
|