Chisel3 - bind - Data

 
介绍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类型;
b. getter: private[core] def binding = _binding.get
 
因为_binding是一个Option,所以_binding.get报错或者target。
 
c. setter: protected def binding_=(target: Binding)
 
Scala的特性,名称如"binding_="的方法,可以直接使用“binding = xxx”的方式调用和赋值。
 
 
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方法定义如下:
a. 调用"binding_="方法,赋值binding:binding = target
 
b. 把Aggregate中的数据成员也逐个进行绑定,其绑定是Aggregate的子绑定
 
当获取topBinding的时候,Aggregate会直接返回target;而Aggregate中的数据成员,会先拆开ChildBinding,最终获取到target。
 
 
 

猜你喜欢

转载自www.cnblogs.com/wjcdx/p/10203567.html