1. 程式人生 > >Chisel3 - model - Builder

Chisel3 - model - Builder

https://mp.weixin.qq.com/s/THqyhoLbbuXXAtdQXRQDdA   介紹構建硬體模型的Builder。   1. DynamicContext   動態上下文,供構建硬體模型時,存放上下文狀態資訊。     2. Builder     Builder使用DynamicContext儲存資料。供其他類獲取和儲存資訊使用。   3. ClockAndReset
  這裡以clock和reset為例。   1) DynamicContext中,定義了currentClockAndReset var currentClockAndReset: Option[ClockAndReset] = None   Builder中為: 可以用這些進行獲取和設定。   2) 在模組例項化的時候賦值     3) 臨時更換clock或reset   在MultiClock.scala中,定義瞭如下方法:
a. 臨時更換clock, withClock: b. 臨時更換reset, withReset: c. 臨時更換clock和reset, withClockAndReset:   更換clock和reset之後,再執行block所代表的程式碼塊。   4) 使用Builder中的clock和reset   a. 建立暫存器Reg(): 構建硬體模型時,DefReg中包含了從Builder中獲取的clock。  
b. 建立帶初始值的RegInit(): 這裡構建這個暫存器的命令DefRegInit裡,包含了從Builder中獲取的clock和reset。   所以3)中,臨時更換Builder.clockAndReset然後在執行block時,如果有建立暫存器,則其使用的clock/reset即為臨時更改後的。     4. 附錄   private[chisel3] class DynamicContext() { val idGen = new IdGen val globalNamespace = Namespace.empty val components = ArrayBuffer[Component]() val annotations = ArrayBuffer[ChiselAnnotation]() var currentModule: Option[BaseModule] = None // Set by object Module.apply before calling class Module constructor // Used to distinguish between no Module() wrapping, multiple wrappings, and rewrapping var readyForModuleConstr: Boolean = false var whenDepth: Int = 0 // Depth of when nesting var currentClockAndReset: Option[ClockAndReset] = None val errors = new ErrorLog val namingStack = new internal.naming.NamingStack // Record the Bundle instance, class name, method name, and reverse stack trace position of open Bundles val bundleStack: ArrayBuffer[(Bundle, String, String, Int)] = ArrayBuffer() }