Skip to content
This repository
tag: s19991110
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 246 lines (207 sloc) 6.507 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
/*
* Copyright (c) 1999 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: synth.cc,v 1.2 1999/11/02 04:55:34 steve Exp $"
#endif

/*
* The synth function searches the behavioral description for
* patterns that are known to represent LPM library components. This
* is especially interesting for the sequential components such as
* flip flops and latches. As threads are transformed into components,
* the design is rewritten.
*
* Currently, this transform recognizes the following patterns:
*
* always @(posedge CLK) Q = D
* always @(negedge CLK) Q = D
*
* always @(posedge CLK) if (CE) Q = D;
* always @(negedge CLK) if (CE) Q = D;
*
* The r-value of the assignments must be identifiers (i.e. wires or
* registers) and the CE must be single-bit identifiers. The generated
* device will be wide enough to accomodate Q and D.
*/
# include "functor.h"
# include "netlist.h"

class synth_f : public functor_t {

    public:
      void process(class Design*, class NetProcTop*);

    private:
      void proc_always_(class Design*);
      void proc_casn_(class Design*);
      void proc_ccon_(class Design*);

// The matcher does something like a recursive descent search
// for the templates. These variables are filled in as the
// searcher finds them.

      class NetProcTop*top_;

      class NetPEvent *pclk_;
      class NetNEvent *nclk_;

      class NetCondit *con_;
      class NetAssign *asn_;
};


/*
* Look at a process, and divide the problem into always and initial
* threads.
*/
void synth_f::process(class Design*des, class NetProcTop*top)
{
      switch (top->type()) {
case NetProcTop::KALWAYS:
top_ = top;
proc_always_(des);
break;
      }
}

/*
* An "always ..." statement has been found.
*/
void synth_f::proc_always_(class Design*des)
{
// The statement must be a NetPEvent, ...
      pclk_ = dynamic_cast<class NetPEvent*>(top_->statement());
      if (pclk_ == 0)
return;

// ... there must be a single event source, ...
      svector<class NetNEvent*>*neb = pclk_->back_list();
      if (neb == 0)
return;
      if (neb->count() != 1) {
delete neb;
return;
      }
      nclk_ = (*neb)[0];
      delete neb;

// ... the event must be an edge, ...
      switch (nclk_->type()) {
case NetNEvent::POSEDGE:
case NetNEvent::NEGEDGE:
break;
default:
return;
      }

// Is this a clocked assignment?
      asn_ = dynamic_cast<NetAssign*>(pclk_->statement());
      if (asn_) {
proc_casn_(des);
return;
      }

      con_ = dynamic_cast<NetCondit*>(pclk_->statement());
      if (con_) {
proc_ccon_(des);
return;
      }
}

/*
* The process so far has been matched as:
*
* always @(posedge nclk_) asn_ = <r>;
* always @(negedge nclk_) asn_ = <r>;
*/
void synth_f::proc_casn_(class Design*des)
{
// Turn the r-value into gates.
      NetNet*sig = asn_->rval()->synthesize(des);
      assert(sig);

// The signal and the assignment must be the same width...
      assert(asn_->pin_count() == sig->pin_count());

      NetFF*ff = new NetFF(asn_->name(), asn_->pin_count());
      ff->attribute("LPM_FFType", "DFF");

      for (unsigned idx = 0 ; idx < ff->width() ; idx += 1) {
connect(ff->pin_Data(idx), sig->pin(idx));
connect(ff->pin_Q(idx), asn_->pin(idx));
      }

      switch (nclk_->type()) {
case NetNEvent::POSEDGE:
connect(ff->pin_Clock(), nclk_->pin(0));
break;

case NetNEvent::NEGEDGE:
connect(ff->pin_Clock(), nclk_->pin(0));
ff->attribute("Clock:LPM_Polarity", "INVERT");
break;
      }

      des->add_node(ff);

// This process is matched and replaced with a DFF. Get
// rid of the now useless NetProcTop.
      des->delete_process(top_);
}

/*
* The process so far has been matched as:
*
* always @(posedge nclk_) if ...;
* always @(negedge nclk_) if ...;
*/
void synth_f::proc_ccon_(class Design*des)
{
      if (con_->else_clause())
return;

      asn_ = dynamic_cast<NetAssign*>(con_->if_clause());
      if (asn_ == 0)
return;

      NetNet*sig = asn_->rval()->synthesize(des);
      assert(sig);

// The signal and the assignment must be the same width...
      assert(asn_->pin_count() == sig->pin_count());

      NetESignal*ce = dynamic_cast<NetESignal*>(con_->expr());
      if (ce == 0)
return;
      if (ce->pin_count() != 1)
return;

      NetFF*ff = new NetFF(asn_->name(), asn_->pin_count());
      ff->attribute("LPM_FFType", "DFF");

      for (unsigned idx = 0 ; idx < ff->width() ; idx += 1) {
connect(ff->pin_Data(idx), sig->pin(idx));
connect(ff->pin_Q(idx), asn_->pin(idx));
      }

      switch (nclk_->type()) {
case NetNEvent::POSEDGE:
connect(ff->pin_Clock(), nclk_->pin(0));
connect(ff->pin_Enable(), ce->pin(0));
break;

case NetNEvent::NEGEDGE:
connect(ff->pin_Clock(), nclk_->pin(0));
connect(ff->pin_Enable(), ce->pin(0));
ff->attribute("Clock:LPM_Polarity", "INVERT");
break;
      }

      des->add_node(ff);


// This process is matched and replaced with a DFF. Get
// rid of the now useless NetProcTop.
      des->delete_process(top_);
}

void synth(Design*des)
{
      synth_f synth_obj;
      des->functor(&synth_obj);
}

/*
* $Log: synth.cc,v $
* Revision 1.2 1999/11/02 04:55:34 steve
* Add the synthesize method to NetExpr to handle
* synthesis of expressions, and use that method
* to improve r-value handling of LPM_FF synthesis.
*
* Modify the XNF target to handle LPM_FF objects.
*
* Revision 1.1 1999/11/01 02:07:41 steve
* Add the synth functor to do generic synthesis
* and add the LPM_FF device to handle rows of
* flip-flops.
*
*/

Something went wrong with that request. Please try again.