-
Notifications
You must be signed in to change notification settings - Fork 615
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
Unify BaseModule.IO and chisel3.experimental.IO into chisel3.IO #2863
Merged
jackkoenig
merged 3 commits into
chipsalliance:master
from
adkian-sifive:relocate-package-io
Dec 1, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package chisel3 | ||
|
||
import chisel3.internal.requireIsChiselType // Fix ambiguous import | ||
import chisel3.internal.Builder | ||
import chisel3.internal.sourceinfo.SourceInfo | ||
|
||
object IO { | ||
|
||
/** Constructs a port for the current Module | ||
* | ||
* This must wrap the datatype used to set the io field of any Module. | ||
* i.e. All concrete modules must have defined io in this form: | ||
* [lazy] val io[: io type] = IO(...[: io type]) | ||
* | ||
* Items in [] are optional. | ||
* | ||
* The granted iodef must be a chisel type and not be bound to hardware. | ||
* | ||
* Also registers a Data as a port, also performing bindings. Cannot be called once ports are | ||
* requested (so that all calls to ports will return the same information). | ||
* Internal API. | ||
*/ | ||
def apply[T <: Data](iodef: => T)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = { | ||
val module = Module.currentModule.get // Impossible to fail | ||
require(!module.isClosed, "Can't add more ports after module close") | ||
val prevId = Builder.idGen.value | ||
val data = iodef // evaluate once (passed by name) | ||
requireIsChiselType(data, "io type") | ||
|
||
// Clone the IO so we preserve immutability of data types | ||
// Note: we don't clone if the data is fresh (to avoid unnecessary clones) | ||
val iodefClone = | ||
if (!data.mustClone(prevId)) data | ||
else | ||
try { | ||
data.cloneTypeFull | ||
} catch { | ||
// For now this is going to be just a deprecation so we don't suddenly break everyone's code | ||
case e: AutoClonetypeException => | ||
Builder.deprecated(e.getMessage, Some(s"${data.getClass}")) | ||
data | ||
} | ||
module.bindIoInPlace(iodefClone) | ||
iodefClone | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this impossible to fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It definitely isn't but note that @adkian-sifive just moved this code. It probably was impossible back when the only way to call
IO
was viaprotected def
defined onModule
.