2016-05-20 2 views
0

私は、Yosysの与えられたモジュールの逐次深度と複雑さを計算するために新しいパスを実装しようとしています。そうするために、私はsccパスに触発されています。 これを実装するには、モジュールの入力ポートからDFSを開始する必要があります。これを行うために、私はすぐに入力ポートに接続されているすべてのセルを見つけることを試みています。そこではありません(モジュール内のポートから深さ優先検索(DFS)を実行するにはどうすればよいですか?

SigPool inputPorts; 
for (auto &it : module->ports) 
    if (module->wires_[it]->port_input) 
    inputPorts.add((sigmap(RTLIL::SigSpec(module->wires_[it])))); 

が、私が持っている問題は、私はすぐにそこからの入力ポートに接続されているセルを見つけることができませんよということです:私は、モジュールのポートから始まり、準線を見つけていますワイヤ/ sigspec/sigpoolタイプのその目的のためのAPR)。

助けてください/ヒントは非常に高く評価されるでしょう。

答えて

1

(ないDFSがが)あなたが必要があると思い、関連するすべての慣用的Yosysコードスニペット含まれている必要があり、私は次のコード例を考える:

// create canonical versions of all sigbits 
    SigMap sigmap(module); 

    // first layer of bits 
    pool<SigBit> input_bits; 

    for (auto wire : module->wires()) 
     if (wire->port_input) 
      for (auto bit : sigmap(wire)) 
       input_bits.insert(bit); 

    // index: from sigbit to driven cells 
    dict<SigBit, pool<Cell*>> bit2cells; 

    // index: from cell to driven sigbits 
    dict<Cell*, pool<SigBit>> cell2bits; 

    for (auto cell : module->cells()) 
    for (auto &conn : cell->connections()) { 
     if (cell->input(conn.first)) { 
      for (auto bit : sigmap(conn.second)) 
       bit2cells[bit].insert(cell); 
     } 
     if (cell->output(conn.first)) { 
      for (auto bit : sigmap(conn.second)) 
       cell2bits[cell].insert(bit); 
     } 
    } 

    pool<SigBit> queue = input_bits; 
    pool<Cell*> visited_cells; 

    while (!queue.empty()) 
    { 
     log("------\n"); 

     pool<Cell*> this_iter_cells; 

     for (auto bit : queue) 
     for (auto cell : bit2cells[bit]) 
      if (!visited_cells.count(cell)) { 
       log(" %s\n", log_id(cell)); 
       visited_cells.insert(cell); 
       this_iter_cells.insert(cell); 
      } 

     queue.clear(); 
     for (auto cell : this_iter_cells) 
     for (auto bit : cell2bits[cell]) 
      queue.insert(bit); 
    } 

離れているから取るべき最も重要なことを:信号ビットの正規表現を作成するため

  • 使用SigMap(場合2本のワイヤが互いに接続され、同一の実際のBのちょうど「別名」されていますそれ)。

  • 2つの段階でアルゴリズムを分割します。(1)必要なインデックス構造を作成し、(2)実際のアルゴリズムを実行します。

またthisthis質問有益な答えを見つけるかもしれません。

(私は急いでこの答えを書いて...何かが不明である場合は、以下のコメントで、さらに質問をしてください。)

1

私は以下のようにその部分を実装することができましたが、それがうまくいくかどうかわかりません。どんなアドバイス/コメントも高く評価されます。

// for all input the cells of the module find its incoming signals (inputSignals in this code), and for each bit of them do the following: 
for (auto &bit : inputSignals) 
    if (bit.wire != NULL) { 
    if (inputPortsSet.count(bit.wire->port_id)) { 
     log ("found an input port\n"); 
     log ("%s :",cell->name.c_str()); 
     log(" %s ", bit.wire->name.c_str()); 
     log(" %d \n", bit.wire->port_id);  
     break; 
    } 
    } 
関連する問題