Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compat compile options macro #1253

Merged
merged 3 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/main/scala/chisel3/compatibility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ package object Chisel { // scalastyle:ignore package.object.name number.of.t
import chisel3.internal.firrtl.Width

import scala.language.experimental.macros
import scala.annotation.StaticAnnotation
import scala.annotation.compileTimeOnly
import scala.reflect.macros.blackbox.Context
import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.language.implicitConversions

implicit val defaultCompileOptions = chisel3.ExplicitCompileOptions.NotStrict

/** Default NotStrict CompileOptions for compatibility code
*
* No longer implicit, materialization macro below provides a low-priority default
*/
@deprecated("Use chisel3.ExplicitCompileOptions.NotStrict", "3.3")
val defaultCompileOptions = chisel3.ExplicitCompileOptions.NotStrict

abstract class Direction
case object INPUT extends Direction
Expand Down Expand Up @@ -584,6 +590,16 @@ package object Chisel { // scalastyle:ignore package.object.name number.of.t
val Pipe = chisel3.util.Pipe
type Pipe[T <: Data] = chisel3.util.Pipe[T]

/** Provides a low priority NotStrict default. Can be overridden by providing a custom implicit
* val in lexical scope (ie. imported)
* Implemented as a macro to provide a low-priority default
*/
implicit def materializeCompileOptions: CompileOptions = macro materializeCompileOptions_impl

def materializeCompileOptions_impl(c: Context): c.Tree = {
import c.universe._
q"_root_.chisel3.ExplicitCompileOptions.NotStrict"
}

/** Package for experimental features, which may have their API changed, be removed, etc.
*
Expand Down
13 changes: 13 additions & 0 deletions src/test/scala/chiselTests/CompatibilitySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ class CompatibiltySpec extends ChiselFlatSpec with GeneratorDrivenPropertyChecks
}
elaborate { new Dummy }
}

it should "be able to provide custom CompileOptions" in {
implicit val CustomCompileOptions = chisel3.ExplicitCompileOptions.NotStrict.copy(inferModuleReset = true)
// Top-level Module always uses Bool so needs to be an inner Module
elaborate(new Module {
val io = IO(new Bundle {})
val inst = Module(new Module {
val io = IO(new Bundle {})
assert(reset.isInstanceOf[chisel3.ResetType])
})
})
}

// Verify we can elaborate a design expressed in Chisel2
class Chisel2CompatibleRisc extends Module {
val io = new Bundle {
Expand Down