90 lines · cpp
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/AsmParser/AsmParserContext.h"10 11namespace llvm {12 13std::optional<FileLocRange>14AsmParserContext::getFunctionLocation(const Function *F) const {15 if (auto FIt = Functions.find(F); FIt != Functions.end())16 return FIt->second;17 return std::nullopt;18}19 20std::optional<FileLocRange>21AsmParserContext::getBlockLocation(const BasicBlock *BB) const {22 if (auto BBIt = Blocks.find(BB); BBIt != Blocks.end())23 return BBIt->second;24 return std::nullopt;25}26 27std::optional<FileLocRange>28AsmParserContext::getInstructionLocation(const Instruction *I) const {29 if (auto IIt = Instructions.find(I); IIt != Instructions.end())30 return IIt->second;31 return std::nullopt;32}33 34Function *35AsmParserContext::getFunctionAtLocation(const FileLocRange &Query) const {36 for (auto &[F, Loc] : Functions) {37 if (Loc.contains(Query))38 return F;39 }40 return nullptr;41}42 43Function *AsmParserContext::getFunctionAtLocation(const FileLoc &Query) const {44 return getFunctionAtLocation(FileLocRange(Query, Query));45}46 47BasicBlock *48AsmParserContext::getBlockAtLocation(const FileLocRange &Query) const {49 for (auto &[BB, Loc] : Blocks) {50 if (Loc.contains(Query))51 return BB;52 }53 return nullptr;54}55 56BasicBlock *AsmParserContext::getBlockAtLocation(const FileLoc &Query) const {57 return getBlockAtLocation(FileLocRange(Query, Query));58}59 60Instruction *61AsmParserContext::getInstructionAtLocation(const FileLocRange &Query) const {62 for (auto &[I, Loc] : Instructions) {63 if (Loc.contains(Query))64 return I;65 }66 return nullptr;67}68 69Instruction *70AsmParserContext::getInstructionAtLocation(const FileLoc &Query) const {71 return getInstructionAtLocation(FileLocRange(Query, Query));72}73 74bool AsmParserContext::addFunctionLocation(Function *F,75 const FileLocRange &Loc) {76 return Functions.insert({F, Loc}).second;77}78 79bool AsmParserContext::addBlockLocation(BasicBlock *BB,80 const FileLocRange &Loc) {81 return Blocks.insert({BB, Loc}).second;82}83 84bool AsmParserContext::addInstructionLocation(Instruction *I,85 const FileLocRange &Loc) {86 return Instructions.insert({I, Loc}).second;87}88 89} // namespace llvm90