diff options
| author | Aditya Naik | 2024-08-06 07:51:25 -0700 |
|---|---|---|
| committer | Aditya Naik | 2024-08-06 07:51:25 -0700 |
| commit | 315923aa09101f6c6ffc58a445bd7411b3b23fca (patch) | |
| tree | b8533ceaf9b291a718a4b7f505cf5d4b1f0e7803 /core/src/main/scala/chisel3/Data.scala | |
| parent | 276d7261208d640ea57a48cb592775c677726fb0 (diff) | |
Fix more misc fileschisel6-scala3-0.1
Diffstat (limited to 'core/src/main/scala/chisel3/Data.scala')
| -rw-r--r-- | core/src/main/scala/chisel3/Data.scala | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/src/main/scala/chisel3/Data.scala b/core/src/main/scala/chisel3/Data.scala index 0b05eb69..0beaa3ef 100644 --- a/core/src/main/scala/chisel3/Data.scala +++ b/core/src/main/scala/chisel3/Data.scala @@ -824,6 +824,25 @@ abstract class Data extends HasId with NamedComponent { /** Default pretty printing */ def toPrintable: Printable + + implicit class AsReadOnly[T <: Data](self: T) { + + /** Returns a read-only view of this Data + * + * It is illegal to connect to the return value of this method. + * This Data this method is called on must be a hardware type. + */ + def readOnly: T = { + val alreadyReadOnly = self.isLit || self.topBindingOpt.exists(_.isInstanceOf[ReadOnlyBinding]) + if (alreadyReadOnly) { + self + } else { + self + // todo fix when adding dataview + // self.viewAsReadOnly(_ => "Cannot connect to read-only value") + } + } + } } object Data { |
