diff options
| author | Andrew Waterman | 2016-10-05 15:18:25 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2016-10-05 15:49:59 -0700 |
| commit | b2373ebda5e63fa850de21585307013f8419320a (patch) | |
| tree | 9d155b3f7bbc02421b1b50d52cbbf8c23f7eafab /chiselFrontend | |
| parent | c7ce06493300cf7ffa89ef472cd6a7086443c16f (diff) | |
Make asInput/asOutput/flip deprecation warnings dynamic
Code that imports Chisel._ shouldn't see them.
Not sure if requireIOWrap is the right condition... or if cyan is a
good choice of color for deprecation warnings.
Diffstat (limited to 'chiselFrontend')
4 files changed, 30 insertions, 6 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/CompileOptions.scala b/chiselFrontend/src/main/scala/chisel3/core/CompileOptions.scala index 0e66a241..85aa8cdc 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/CompileOptions.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/CompileOptions.scala @@ -17,6 +17,9 @@ trait CompileOptions { val dontTryConnectionsSwapped: Boolean // If connection directionality is not explicit, do not use heuristics to attempt to determine it. val dontAssumeDirectionality: Boolean + // Issue a deprecation warning if Data.{flip, asInput,asOutput} is used + // instead of Flipped, Input, or Output. + val deprecateOldDirectionMethods: Boolean } object CompileOptions { @@ -34,6 +37,7 @@ object ExplicitCompileOptions { val requireIOWrap = false val dontTryConnectionsSwapped = false val dontAssumeDirectionality = false + val deprecateOldDirectionMethods = false } // Collection of "strict" connection compile options, preferred for new code. @@ -44,5 +48,6 @@ object ExplicitCompileOptions { val requireIOWrap = true val dontTryConnectionsSwapped = true val dontAssumeDirectionality = true + val deprecateOldDirectionMethods = true } } diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala index 3f21a34c..922b33a9 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala @@ -104,12 +104,21 @@ object Data { } implicit class AddDirectionToData[T<:Data](val target: T) extends AnyVal { - @deprecated("Input(Data) should be used over Data.asInput", "gchisel") - def asInput: T = Input(target) - @deprecated("Output(Data) should be used over Data.asOutput", "gchisel") - def asOutput: T = Output(target) - @deprecated("Flipped(Data) should be used over Data.flip", "gchisel") - def flip(): T = Flipped(target) + def asInput(implicit opts: CompileOptions): T = { + if (opts.deprecateOldDirectionMethods) + Builder.deprecated("Input(Data) should be used over Data.asInput") + Input(target) + } + def asOutput(implicit opts: CompileOptions): T = { + if (opts.deprecateOldDirectionMethods) + Builder.deprecated("Output(Data) should be used over Data.asOutput") + Output(target) + } + def flip()(implicit opts: CompileOptions): T = { + if (opts.deprecateOldDirectionMethods) + Builder.deprecated("Flipped(Data) should be used over Data.flip") + Flipped(target) + } } } diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala index 8d376810..12cc840e 100644 --- a/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala +++ b/chiselFrontend/src/main/scala/chisel3/internal/Builder.scala @@ -173,6 +173,8 @@ private[chisel3] object Builder { def errors: ErrorLog = dynamicContext.errors def error(m: => String): Unit = errors.error(m) + def warning(m: => String): Unit = errors.warning(m) + def deprecated(m: => String): Unit = errors.deprecated(m) def build[T <: Module](f: => T): Circuit = { dynamicContextVar.withValue(Some(new DynamicContext())) { diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Error.scala b/chiselFrontend/src/main/scala/chisel3/internal/Error.scala index 7ae0580f..c5c67da4 100644 --- a/chiselFrontend/src/main/scala/chisel3/internal/Error.scala +++ b/chiselFrontend/src/main/scala/chisel3/internal/Error.scala @@ -25,6 +25,10 @@ private[chisel3] class ErrorLog { def warning(m: => String): Unit = errors += new Warning(m, getUserLineNumber) + /** Log a deprecation warning message */ + def deprecated(m: => String): Unit = + errors += new DeprecationWarning(m, getUserLineNumber) + /** Emit an informational message */ def info(m: String): Unit = println(new Info("[%2.3f] %s".format(elapsedTime/1e3, m), None)) // scalastyle:ignore regex @@ -86,6 +90,10 @@ private class Warning(msg: => String, line: Option[StackTraceElement]) extends L def format: String = tag("warn", Console.YELLOW) } +private class DeprecationWarning(msg: => String, line: Option[StackTraceElement]) extends LogEntry(msg, line) { + def format: String = tag("warn", Console.CYAN) +} + private class Info(msg: => String, line: Option[StackTraceElement]) extends LogEntry(msg, line) { def format: String = tag("info", Console.MAGENTA) } |
