diff options
| author | grebe | 2017-01-13 09:51:18 -0800 |
|---|---|---|
| committer | Chick Markley | 2017-01-13 09:51:18 -0800 |
| commit | f19653fbe9d2e1b49c49c31ddb98a758c390ba94 (patch) | |
| tree | cd295142ab5a0040c4beb5606fc1c2cdc2901e28 /chiselFrontend/src/main/scala/chisel3/core/Data.scala | |
| parent | 3215df07a97b58babb1deb3fab0928198b1daad2 (diff) | |
Make fromBits work with types other than UInt (#424)
* Make fromBits work with types other than UInt
* Oops, left in a println
* Add test for truncation/expansion
* Fix stuff that broke when FixedPoint fromBits PR was merged.
* Use .BP shorthand added in previous PR
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/core/Data.scala')
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Data.scala | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala index 57ed0c59..6e80f045 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala @@ -238,21 +238,7 @@ abstract class Data extends HasId { */ def fromBits(that: Bits): this.type = macro CompileOptionsTransform.thatArg - def do_fromBits(that: Bits)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): this.type = { - var i = 0 - val wire = Wire(this.chiselCloneType) - val bits = - if (that.width.known && that.width.get >= wire.width.get) { - that - } else { - Wire(that.cloneTypeWidth(wire.width), init = that) - } - for (x <- wire.flatten) { - x := bits(i + x.getWidth-1, i) - i += x.getWidth - } - wire.asInstanceOf[this.type] - } + def do_fromBits(that: Bits)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): this.type /** Packs the value of this object as plain Bits. * @@ -337,4 +323,9 @@ sealed class Clock extends Element(Width(1)) { def toPrintable: Printable = PString("CLOCK") override def do_asUInt(implicit sourceInfo: SourceInfo): UInt = pushOp(DefPrim(sourceInfo, UInt(this.width), AsUIntOp, ref)) + override def do_fromBits(that: Bits)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): this.type = { + val ret = Wire(this.cloneType) + ret := that + ret.asInstanceOf[this.type] + } } |
