1. 程式人生 > >Chisel3 - model - UserModule commands

Chisel3 - model - UserModule commands

 https://mp.weixin.qq.com/s/0ECca6XyFyEri0B4ckOZ4A   介紹UserModule類中,如何管理構建硬體模型所需的命令。     1. _commands   private val _commands = ArrayBuffer[Command]()   _commands中存放了構建模組所需的全部命令。     1) 新增命令:addCommand  
a. 需要沒有close:_closed意為模組構建所需已經齊備,不能再向其中新增內部資料和邏輯定義; b. 把c新增到_commands中;   2) 獲取所有命令:getCommands     a. 需要已經close,意為模組構建所需已經齊備; b. 返回全部命令:_commands.toSeq   2. Builder.pushCommand()     addCommand()通過pushCommand()呼叫,將命令c新增到正在構建的模組(forcedUserModule)之中。
  3. _closed     _closed定義與BaseModule類中,為該類資料成員,protected表明子類可以直接讀寫訪問。   _closed是一個標誌:標誌著模組定義是否已經完成,即所需的各個內部資料變數、內部邏輯是否已經全部新增到模組中。亦即構建模組的硬體模型所需的所有命令已經齊備,可以開始構建了。   總結並簡而言之,即過程分為兩個階段:定義、構建。而_closed標誌著模組定義階段的結束。也可以用來表明可以開始構建階段了。  
  4. forcedUserModule   pushCommand()呼叫forcedUserModule.addCommand(c)把命令c加入到forcedUserModule中。   forcedUserModule定義如下: 可知,其為Option包裹著的UserModule,即currentModule拆包而來;   currentModule定義如下: currentModule基於動態上下文(dynamicContext)中定義的變數currentModule。其賦值可以直接使用“currentModule = xxx”的形式。   currentModule定義與Builder類中,其賦值的地方為:   直接定義在BaseModule的類體中,每一個BaseModule類的子類例項化時,都要執行這個程式碼。所以Builder.currentModule的值即為當前例項化的模組。   如下程式碼中FullAdder即為Module的子類,亦即BaseModule的子類:   所以new FullAdder()時,會執行到Builder.currentModule = Some(this)這行程式碼,而把currentModule設定為正在建立(new)的這個FullAdder模組。   所以後續pushCommand()時,都是新增到這個FullAdder模組中。