Posts Issued on September 11, 2025

posted by sakurai on September 11, 2025 #1020

Producer側もラッパー化も提供してください。

了解です。 では、Producer 側も既存のproduceメソッドを壊さずにGet#(UInt#(4))インタフェースに変換するラッパーを作ります。

Producer 側ラッパー

import GetPut::*;

interface Producer4GetIfc;
  interface Get#(UInt#(4)) out;   // 外部から見えるのはGet
endinterface

module mkProducer4GetWrapper #(Producer4Ifc prod) (Producer4GetIfc);
  interface Get out;
    method ActionValue#(UInt#(4)) get;
      let x <- prod.produce;   // 既存のproduceを呼び出すだけ
      return x;
    endmethod
  endinterface
endmodule

これで両方ラッパー化したTop

import GetPut::*;
import Connectable::*;

module mkTopDirect(...);
  // 元のインスタンス
  Producer4Ifc prod_orig <- mkProducer4;
  Consumer4Ifc cons_orig <- mkConsumer4;

  // ラッパーを通してGet/Put化
  Producer4GetIfc prod <- mkProducer4GetWrapper(prod_orig);
  Consumer4PutIfc cons <- mkConsumer4PutWrapper(cons_orig);

  // 2行版:元をインライン生成してラップ
  Producer4GetIfc prod <- mkProducer4GetWrapper(mkProducer4);
  Consumer4PutIfc cons <- mkConsumer4PutWrapper(mkConsumer4);

  // 直結(rule connect不要)
  mkConnection(prod.out, cons.in);

  // 必要ならここにTopの他の処理(recvCntなど)
endmodule

この構成のメリット

  • 元の Producer4 / Consumer4 を一切改造しない
  • Top では mkConnection だけでシンプルに接続
  • Get/Put標準インタフェースなので、他のモジュールやパイプライン部品と直結可能
  • 将来、GameFSM / SoundFSM のように直接接続できる構造に発展しやすい

左矢前のブログ 次のブログ右矢