Article #1019

既に発行済みのブログであっても適宜修正・追加することがあります。
We may make changes and additions to blogs already published.
posted by sakurai on September 10, 2025 #1019

既存の consume を崩したくないなら、薄いラッパーで Put#(T) を包んで中で consume を呼ぶだけでもOKとのことだが、このラッパーを提供してください。

了解です。 既存のConsumer4モジュールを一切壊さず、外部からはPut#(UInt#(4))に見える薄いラッパーを提供します。 中で単にconsume()を呼び出すだけなので、既存のテストや内部ロジックには手を入れません。

ラッパーモジュール例

import GetPut::*;

interface Consumer4PutIfc;
  interface Put#(UInt#(4)) in;   // 外部から見えるのはPut
endinterface

module mkConsumer4PutWrapper #(Consumer4Ifc cons) (Consumer4PutIfc);
  // Putインタフェースを定義
  interface Put in;
    method Action put(UInt#(4) x);
      cons.consume(x);   // 既存のconsumeを呼び出すだけ
    endmethod
  endinterface
endmodule

Top 側での使い方

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

module mkTopDirect(...);
  Producer4Ifc     prod <- mkProducer4;
  Consumer4Ifc     cons <- mkConsumer4;
  Consumer4PutIfc  consP <- mkConsumer4PutWrapper(cons);

  // ProducerとConsumerを接続
  mkConnection(prod.out, consP.in);

  // 他のTop内ロジック(recvCntなど)が必要ならここに
endmodule

ポイント

  • 既存の Consumer4はそのまま使う
  • Put#(T)の形に変換するのは外部ラッパーが担当
  • mkConnectionGet#(T)Put#(T)のみを接続できるため、この変換が必要
  • recvCnt$displayをTopでやりたい場合は、Consumer4側でRWirePulseWireを使って通知できます

この構成なら、Topのrule connectは不要で、元のConsumer4のメソッド構造もそのままにできます。 もしこれに加えてProducer側もラッパー化した例も欲しいですか?


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

Leave a Comment

Your email address will not be published.

You may use Markdown syntax. If you include an ad such as http://, it will be invalidated by our AI system.

Please enter the numbers as they are shown in the image above.