CIRCT 22.0.0git
Loading...
Searching...
No Matches
VerilogIndex.h
Go to the documentation of this file.
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// VerilogIndex
9//===----------------------------------------------------------------------===//
10
11#ifndef LIB_CIRCT_TOOLS_CIRCT_VERILOG_LSP_SERVER_VERILOGINDEX_H_
12#define LIB_CIRCT_TOOLS_CIRCT_VERILOG_LSP_SERVER_VERILOGINDEX_H_
13
14#include "slang/ast/Compilation.h"
15
16#include "mlir/IR/Attributes.h"
17#include "mlir/IR/MLIRContext.h"
18
19#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/IntervalMap.h"
21#include "llvm/ADT/PointerUnion.h"
22#include "llvm/ADT/SmallVector.h"
23
24namespace circt {
25namespace lsp {
26
28 llvm::PointerUnion<const slang::ast::Symbol *, mlir::Attribute>;
29using ReferenceMap = llvm::SmallDenseMap<const slang::ast::Symbol *,
30 llvm::SmallVector<slang::SourceRange>>;
31using SlangBufferPointer = char const *;
32using MapT =
33 llvm::IntervalMap<SlangBufferPointer, VerilogIndexSymbol,
34 llvm::IntervalMapImpl::NodeSizer<
36 llvm::IntervalMapHalfOpenInfo<const SlangBufferPointer>>;
37
39public:
40 VerilogIndex(const slang::BufferID &slangBufferID,
41 const slang::SourceManager &sourceManager)
42 : mlirContext(mlir::MLIRContext::Threading::DISABLED),
43 intervalMap(allocator), bufferId(slangBufferID),
45
46 /// Initialize the index with the given compilation unit.
47 void initialize(slang::ast::Compilation &compilation);
48
49 /// Register a reference to a symbol `symbol` from `from`.
50 void insertSymbol(const slang::ast::Symbol *symbol, slang::SourceRange from,
51 bool isDefinition = false);
52 void insertSymbolDefinition(const slang::ast::Symbol *symbol);
53
54 const slang::SourceManager &getSlangSourceManager() const {
55 return sourceManager;
56 }
57 const slang::BufferID &getBufferId() const { return bufferId; }
58
59 // Half open interval map containing paired pointers into Slang's buffer
61
62 /// A mapping from a symbol to their references.
63 const ReferenceMap &getReferences() const { return references; }
64
65private:
66 /// Parse source location emitted by ExportVerilog.
68 void parseSourceLocation(llvm::StringRef toParse);
69
70 // MLIR context used for generating location attr.
71 mlir::MLIRContext mlirContext;
72
73 /// An allocator for the interval map.
74 MapT::Allocator allocator;
75
76 /// An interval map containing a corresponding definition mapped to a source
77 /// interval.
79
80 /// References of symbols.
82
83 // The parent document's buffer ID.
84 const slang::BufferID &bufferId;
85 // The parent document's source manager.
86 const slang::SourceManager &sourceManager;
87};
88}; // namespace lsp
89}; // namespace circt
90
91#endif
const ReferenceMap & getReferences() const
A mapping from a symbol to their references.
MapT::Allocator allocator
An allocator for the interval map.
ReferenceMap references
References of symbols.
void parseSourceLocation()
Parse source location emitted by ExportVerilog.
const slang::BufferID & bufferId
VerilogIndex(const slang::BufferID &slangBufferID, const slang::SourceManager &sourceManager)
void parseSourceLocation(llvm::StringRef toParse)
const slang::SourceManager & sourceManager
void insertSymbolDefinition(const slang::ast::Symbol *symbol)
mlir::MLIRContext mlirContext
void insertSymbol(const slang::ast::Symbol *symbol, slang::SourceRange from, bool isDefinition=false)
Register a reference to a symbol symbol from from.
const slang::BufferID & getBufferId() const
MapT intervalMap
An interval map containing a corresponding definition mapped to a source interval.
void initialize(slang::ast::Compilation &compilation)
Initialize the index with the given compilation unit.
const slang::SourceManager & getSlangSourceManager() const
char const * SlangBufferPointer
llvm::PointerUnion< const slang::ast::Symbol *, mlir::Attribute > VerilogIndexSymbol
llvm::IntervalMap< SlangBufferPointer, VerilogIndexSymbol, llvm::IntervalMapImpl::NodeSizer< SlangBufferPointer, VerilogIndexSymbol >::LeafSize, llvm::IntervalMapHalfOpenInfo< const SlangBufferPointer > > MapT
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.