From 525e5688f69f474240fe5a21d6210beb04cfef29 Mon Sep 17 00:00:00 2001 From: Jim Lawson Date: Fri, 19 Aug 2016 14:46:53 -0700 Subject: Restore immutability of direction overrides. Input, Output, and Flipped clone their inputs. --- chiselFrontend/src/main/scala/chisel3/core/Data.scala | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'chiselFrontend/src') diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala index cb6d427d..ce7b58b4 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala @@ -31,27 +31,28 @@ object DataMirror { /** * Input, Output, and Flipped are used to define the directions of Module IOs. * -* Note that they do not currently call target to be a newType or cloneType. -* This is nominally for performance reasons to avoid too many extra copies when -* something is flipped multiple times. +* Note that they currently clone their source argument, including its bindings. * * Thus, an error will be thrown if these are used on bound Data */ object Input { - def apply[T<:Data](target: T): T = { + def apply[T<:Data](source: T): T = { + val target = source.chiselCloneType Data.setFirrtlDirection(target, Direction.Input) Binding.bind(target, InputBinder, "Error: Cannot set as input ") } } object Output { - def apply[T<:Data](target: T): T = { + def apply[T<:Data](source: T): T = { + val target = source.chiselCloneType Data.setFirrtlDirection(target, Direction.Output) Binding.bind(target, OutputBinder, "Error: Cannot set as output ") } } object Flipped { - def apply[T<:Data](target: T): T = { - Data.setFirrtlDirection(target, Data.getFirrtlDirection(target).flip) + def apply[T<:Data](source: T): T = { + val target = source.chiselCloneType + Data.setFirrtlDirection(target, Data.getFirrtlDirection(source).flip) Binding.bind(target, FlippedBinder, "Error: Cannot flip ") } } -- cgit v1.2.3