CIRCT  20.0.0git
Namespace.h
Go to the documentation of this file.
1 //===- Namespace.h - A symbol table for FIRRTL ops --------------*- C++ -*-===//
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 implements the FIRRTL CircuitNamespace, a symbol table for
10 // `firrtl.circuit` operations that allows for name collision resolution.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef CIRCT_DIALECT_FIRRTL_NAMESPACE_H
15 #define CIRCT_DIALECT_FIRRTL_NAMESPACE_H
16 
19 
20 namespace circt {
21 namespace firrtl {
22 
23 /// The namespace of a `CircuitOp`, generally inhabited by modules.
24 struct CircuitNamespace : public Namespace {
26  CircuitNamespace(CircuitOp circuit) { add(circuit); }
27 
28  /// Populate the namespace from a circuit operation. This namespace will be
29  /// composed of any operation in the first level of the circuit that contains
30  /// a symbol.
31  void add(CircuitOp circuit) {
32  for (auto &op : *circuit.getBodyBlock())
33  if (auto symbol = op.getAttrOfType<mlir::StringAttr>(
34  SymbolTable::getSymbolAttrName()))
35  nextIndex.insert({symbol.getValue(), 0});
36  }
37 };
38 
39 } // namespace firrtl
40 } // namespace circt
41 
42 #endif // CIRCT_DIALECT_FIRRTL_NAMESPACE_H
A namespace that is used to store existing names and generate new names in some scope within the IR.
Definition: Namespace.h:30
llvm::StringMap< size_t > nextIndex
Definition: Namespace.h:159
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
The namespace of a CircuitOp, generally inhabited by modules.
Definition: Namespace.h:24
void add(CircuitOp circuit)
Populate the namespace from a circuit operation.
Definition: Namespace.h:31
CircuitNamespace(CircuitOp circuit)
Definition: Namespace.h:26