CIRCT 20.0.0git
Loading...
Searching...
No Matches
FIRRTLAttributes.h
Go to the documentation of this file.
1//===- FIRRTLAttributes.h - FIRRTL dialect attributes -----------*- 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 contains the FIRRTL dialect custom attributes.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_DIALECT_FIRRTL_FIRRTLATTRIBUTES_H
14#define CIRCT_DIALECT_FIRRTL_FIRRTLATTRIBUTES_H
15
17#include "circt/Support/LLVM.h"
18
19namespace circt {
20namespace firrtl {
21
22//===----------------------------------------------------------------------===//
23// PortDirections
24//===----------------------------------------------------------------------===//
25
26/// This represents the direction of a single port.
27enum class Direction { In, Out };
28
29/// Prints the Direction to the stream as either "in" or "out".
30llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Direction &dir);
31
32namespace direction {
33
34/// Return an output direction if \p isOutput is true, otherwise return an
35/// input direction.
36static inline Direction get(bool isOutput) { return (Direction)isOutput; }
37
38/// Convert from Direction to bool. The opposite of get;
39static inline bool unGet(Direction dir) { return (bool)dir; }
40
41/// Flip a port direction.
42Direction flip(Direction direction);
43
44static inline StringRef toString(Direction direction) {
45 return direction == Direction::In ? "in" : "out";
46}
47
48static inline StringRef toString(bool direction) {
49 return toString(get(direction));
50}
51
52/// Return a \p DenseBoolArrayAttr containing the packed representation of an
53/// array of directions.
54mlir::DenseBoolArrayAttr packAttribute(MLIRContext *context,
55 ArrayRef<Direction> directions);
56
57/// Return a \p DenseBoolArrayAttr containing the packed representation of an
58/// array of directions.
59mlir::DenseBoolArrayAttr packAttribute(MLIRContext *context,
60 ArrayRef<bool> directions);
61
62/// Turn a packed representation of port attributes into a vector that can
63/// be worked with.
64SmallVector<Direction> unpackAttribute(mlir::DenseBoolArrayAttr directions);
65
66} // namespace direction
67} // namespace firrtl
68} // namespace circt
69
70#define GET_ATTRDEF_CLASSES
71#include "circt/Dialect/FIRRTL/FIRRTLAttributes.h.inc"
72
73#endif // CIRCT_DIALECT_FIRRTL_FIRRTLATTRIBUTES_H
mlir::DenseBoolArrayAttr packAttribute(MLIRContext *context, ArrayRef< Direction > directions)
Return a DenseBoolArrayAttr containing the packed representation of an array of directions.
static bool unGet(Direction dir)
Convert from Direction to bool. The opposite of get;.
Direction flip(Direction direction)
Flip a port direction.
SmallVector< Direction > unpackAttribute(mlir::DenseBoolArrayAttr directions)
Turn a packed representation of port attributes into a vector that can be worked with.
static Direction get(bool isOutput)
Return an output direction if isOutput is true, otherwise return an input direction.
static StringRef toString(Direction direction)
Direction
This represents the direction of a single port.
llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const InstanceInfo::LatticeValue &value)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.