https://mp.weixin.qq.com/s/ENJVkz88sGgyODRNCu9jhQ
介绍Data类中的binding的定义和用法。
Binding stores information about this node's position in the hardware graph.
This information is supplemental (more than is necessary to generate FIRRTL) and is used to
perform checks in Chisel, where more informative error messages are possible.
1. Data类的成员binding
a. binding基于另一个数据成员:_binding,这是一个Option类型;
.get
因为_binding是一个Option,所以_binding.get报错或者target。
binding_=(target: Binding)
2. Data类中的topBinding
从提示可以看出,这是一个递归调用的方法。
topBinding返回最顶层的Binding。如果是一个ChildBinding,则向上回溯继续获取上一层的topBinding。
3. Data子类中的bind
Data中的bind方法是一个抽象方法,需要在子类中加以实现。
1) Element中的bind方法
这个方法把传入的Binding赋值给自己的binding成员(调用binding_=方法)。
2) Aggregate中的bind方法
Aggregate是Bundle的父父类。Bundle被用来定义各种自定义的数据类型,如:
Aggregate的bind方法定义如下:
binding = target
其绑定是Aggregate的子绑定
当获取topBinding的时候,Aggregate会直接返回target;而Aggregate中的数据成员,会先拆开ChildBinding,最终获取到target。