|
| 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-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#ifndef LLVM_ASMPARSER_ASMPARSERCONTEXT_H |
| 10 | +#define LLVM_ASMPARSER_ASMPARSERCONTEXT_H |
| 11 | + |
| 12 | +#include "llvm/ADT/DenseMap.h" |
| 13 | +#include "llvm/AsmParser/FileLoc.h" |
| 14 | +#include "llvm/IR/Value.h" |
| 15 | +#include <optional> |
| 16 | + |
| 17 | +namespace llvm { |
| 18 | + |
| 19 | +/// Registry of file location information for LLVM IR constructs. |
| 20 | +/// |
| 21 | +/// This class provides access to the file location information |
| 22 | +/// for various LLVM IR constructs. Currently, it supports Function, |
| 23 | +/// BasicBlock and Instruction locations. |
| 24 | +/// |
| 25 | +/// When available, it can answer queries about what is at a given |
| 26 | +/// file location, as well as where in a file a given IR construct |
| 27 | +/// is. |
| 28 | +/// |
| 29 | +/// This information is optionally emitted by the LLParser while |
| 30 | +/// it reads LLVM textual IR. |
| 31 | +class AsmParserContext { |
| 32 | + DenseMap<Function *, FileLocRange> Functions; |
| 33 | + DenseMap<BasicBlock *, FileLocRange> Blocks; |
| 34 | + DenseMap<Instruction *, FileLocRange> Instructions; |
| 35 | + |
| 36 | +public: |
| 37 | + std::optional<FileLocRange> getFunctionLocation(const Function *) const; |
| 38 | + std::optional<FileLocRange> getBlockLocation(const BasicBlock *) const; |
| 39 | + std::optional<FileLocRange> getInstructionLocation(const Instruction *) const; |
| 40 | + /// Get the function at the requested location range. |
| 41 | + /// If no single function occupies the queried range, or the record is |
| 42 | + /// missing, a nullptr is returned. |
| 43 | + Function *getFunctionAtLocation(const FileLocRange &) const; |
| 44 | + /// Get the function at the requested location. |
| 45 | + /// If no function occupies the queried location, or the record is missing, a |
| 46 | + /// nullptr is returned. |
| 47 | + Function *getFunctionAtLocation(const FileLoc &) const; |
| 48 | + /// Get the block at the requested location range. |
| 49 | + /// If no single block occupies the queried range, or the record is missing, a |
| 50 | + /// nullptr is returned. |
| 51 | + BasicBlock *getBlockAtLocation(const FileLocRange &) const; |
| 52 | + /// Get the block at the requested location. |
| 53 | + /// If no block occupies the queried location, or the record is missing, a |
| 54 | + /// nullptr is returned. |
| 55 | + BasicBlock *getBlockAtLocation(const FileLoc &) const; |
| 56 | + /// Get the instruction at the requested location range. |
| 57 | + /// If no single instruction occupies the queried range, or the record is |
| 58 | + /// missing, a nullptr is returned. |
| 59 | + Instruction *getInstructionAtLocation(const FileLocRange &) const; |
| 60 | + /// Get the instruction at the requested location. |
| 61 | + /// If no instruction occupies the queried location, or the record is missing, |
| 62 | + /// a nullptr is returned. |
| 63 | + Instruction *getInstructionAtLocation(const FileLoc &) const; |
| 64 | + bool addFunctionLocation(Function *, const FileLocRange &); |
| 65 | + bool addBlockLocation(BasicBlock *, const FileLocRange &); |
| 66 | + bool addInstructionLocation(Instruction *, const FileLocRange &); |
| 67 | +}; |
| 68 | +} // namespace llvm |
| 69 | + |
| 70 | +#endif |
0 commit comments