-
Notifications
You must be signed in to change notification settings - Fork 649
Expand file tree
/
Copy pathModuleChoiceIntf.scala
More file actions
44 lines (38 loc) · 1.44 KB
/
ModuleChoiceIntf.scala
File metadata and controls
44 lines (38 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier: Apache-2.0
package chisel3.choice
import scala.language.experimental.macros
import chisel3.{Data, FixedIOBaseModule, SourceInfoDoc}
import chisel3.experimental.SourceInfo
import chisel3.internal.sourceinfo.InstChoiceTransform
private[chisel3] trait ModuleChoiceObjIntf extends SourceInfoDoc { self: ModuleChoice.type =>
/** A wrapper method for Module instantiation based on option choices.
* (necessary to help Chisel track internal state).
* @see [[chisel3.choice.Group]] on how to declare the options for the alternatives.
*
* Example:
* ```
* val module = ModuleChoice(new DefaultModule)(Seq(
* Platform.FPGA -> new FPGATarget,
* Platform.ASIC -> new ASICTarget
* ))
* ```
*
* @param default the Module to instantiate if no module is specified
* @param choices the mapping from cases to module generators
*
* @return the input module `m` with Chisel metadata properly set
*
* @throws java.lang.IllegalArgumentException if the cases do not belong to the same option.
*/
def apply[T](
default: => FixedIOBaseModule[T]
)(choices: => Seq[(Case, () => FixedIOBaseModule[T])]): T =
macro InstChoiceTransform.apply[T]
/** @group SourceInfoTransformMacro */
def do_apply[T](
default: => FixedIOBaseModule[T],
choices: Seq[(Case, () => FixedIOBaseModule[T])]
)(
implicit sourceInfo: SourceInfo
): T = _applyImpl(default, choices)
}