OpenASIP  2.0
HDLGenerator.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2017 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25 * @file HDLGenerator.hh
26 *
27 * @author Lasse Lehtonen 2017 (lasse.lehtonen-no.spam-tut.fi)
28 */
29 #pragma once
30 #include "IPXact.hh"
31 #include "HWGenTools.hh"
32 #include "LHSValue.hh"
33 #include "HDLRegister.hh"
34 #include "Generatable.hh"
35 #include "HDLPort.hh"
36 #include "StringTools.hh"
37 #include <boost/format.hpp>
38 #include <chrono>
39 #include <cmath>
40 #include <ctime>
41 #include <deque>
42 #include <iomanip>
43 #include <iostream>
44 #include <memory>
45 #include <sstream>
46 #include <string>
47 #include <unordered_map>
48 #include <unordered_set>
49 #include <vector>
50 #include <type_traits>
51 
52 namespace HDLGenerator {
53 
54  /** @page hdl_generator HDLGenerator
55  *
56  * <pre>
57  * Basic idea of HDLGenerator is to construct objects (modules, ports,
58  * behavioral code constructs, etc), assign them to the object wich they
59  * logically belong to, and finally call implement for the module.
60  * Calling implement builds the code, does some limited validity checks,
61  * and spits either Verilog or VHDL.
62  *
63  * Only a limited subset of code constructs are present as not all were
64  * relevant for efficient hdl.
65  *
66  * Some options can be used to guide the generation:
67  * "asynchronous reset" - Self-explanatory.
68  * "synchronous reset" - Self-explanatory.
69  * "reset everything" - Without this only registers with
70  * ResetOption::Mandatory will be assigned a value
71  * in reset.
72  *
73  * What can be assigned to:
74  * Module << Register / Wire / InPort / OutPort / Parameter / Option
75  * Module << (std::string comment) / BinaryConstant / IntegerConstant
76  * Module << Behaviour / Module
77  * Behaviour << Assign / Asynchronous / Synchronous
78  * Asynchronous / Synchronous << SequentialStatement / Variable
79  * If << Else / SequentialStatement
80  * Switch << Case / DefaultCase
81  * Case / DefaultCase << HDLOperation / Assign / If
82  *
83  * Case clauses:
84  * Case / DefaultCase << BinaryLiteral / (int) / (std::string)
85  * </pre>
86  *
87  *
88  *
89  */
90 
91  class Module;
92  class Behaviour;
93  class Synchronous;
94  class Asynchronous;
95  class Option;
96  class Assign;
97  class Wire;
98  class LogicVariable;
99  class SignedVariable;
100  class UnsignedVariable;
101  class IntegerConstant;
102  class CastLogicToUnsigned;
103  class CastLogicToSigned;
104  class BinaryConstant;
105  class Parameter;
106  class InPort;
107  class OutPort;
108  class If;
109  class Else;
110  class Switch;
111  class Case;
112  class DefaultCase;
113  class Splice;
114  class RawCodeLine;
115  class HDLOperation;
116  class CodeBlock;
117 
118  /**
119  * Base class for concurrent statements and code blocks
120  */
122  public:
124 
125  virtual void hdl(std::ostream& stream, Language lang, int level) {
126  (void)stream;
127  (void)lang;
128  (void)level;
129  std::string err =
130  std::string("Attempted to generate virtual class");
131  throw std::runtime_error(err);
132  }
133  private:
134  std::string altname;
135  };
136 
137  /**
138  * Represents VHDL operation snippet.
139  */
141  public:
143  HDLOperation(std::string name, std::deque<std::string> impl,
144  Language lang)
145  : SequentialStatement(name), impl_(std::move(impl)), lang_(lang) {}
146 
147  HDLOperation& operator<<(const std::string& rhs) {
148  readList_.emplace_back(rhs);
149  return *this;
150  }
151 
152  HDLOperation& operator<<(const std::string&& rhs) {
153  readList_.emplace_back(rhs);
154  return *this;
155  }
156 
157  void build() override {
159  for (auto&& r : readList_) {
160  reads(r);
161  }
162  }
163 
164  void hdl(std::ostream& stream, Language lang, int level) override {
165  if (lang != lang_)
166  throw std::runtime_error(__PRETTY_FUNCTION__);
167 
168  for (auto&& line : impl_) {
169  stream << StringTools::indent(level) << line << "\n";
170  }
171  }
172 
173  private:
174  std::deque<std::string> impl_;
175  std::vector<std::string> readList_;
177  };
178 
179 
180  /**
181  * Raw code.
182  */
184  public:
185  RawCodeLine(std::string vhdl, std::string verilog)
186  : SequentialStatement("raw code line"),
187  vhdl_(vhdl), verilog_(verilog) {}
188 
189  void hdl(std::ostream& stream, Language lang, int level) final {
190  if (lang == Language::VHDL) {
191  stream << StringTools::indent(level) << vhdl_ << "\n";
192  } else if (lang == Language::Verilog) {
193  stream << StringTools::indent(level) << verilog_ << "\n";
194  } else {
195  throw std::runtime_error(__PRETTY_FUNCTION__);
196  }
197  }
198 
199  private:
200  std::string vhdl_;
201  std::string verilog_;
202  };
203 
204  /**
205  * Option.
206  */
207  class Option : public Generatable {
208  public:
209  Option(std::string name) : Generatable(name) {}
210  };
211 
212  /**
213  * Generic/parameter.
214  */
215  class Parameter : public Generatable {
216  public:
217  Parameter(std::string name, int value = -1)
218  : Generatable(name), value_(value) {}
219  Parameter(std::string name, std::string value)
220  : Generatable(name), value_(-1), strValue_(value) {}
221 
222  Width width() final { return {name(), value_}; }
223  std::string strValue() { return strValue_; }
224 
225  void declare(std::ostream& stream, Language lang, int level = 0) {
226  stream << StringTools::indent(level);
227  if (lang == Language::VHDL) {
228  stream << name() << " : integer";
229  } else if (lang == Language::Verilog) {
230  stream << "parameter integer " << name();
231  } else {
232  throw std::runtime_error(__PRETTY_FUNCTION__);
233  }
234  }
235 
236  private:
237  int value_;
238  std::string strValue_;
239  };
240 
241  /**
242  * Binary constant.
243  */
244  class BinaryConstant : public Generatable {
245  public:
246  BinaryConstant(std::string name, int width, int value)
248 
249  int value() const noexcept { return value_; }
250 
251  Width width() final { return {name(), width_}; }
252 
253  void declare(std::ostream& stream, Language lang, int level) {
254  std::string binVal = "";
255  int tempVal = value_;
256  for (int i = width_ - 1; i >= 0; --i) {
257  long power = static_cast<long>(std::pow(2, i));
258  if (power <= tempVal) {
259  tempVal -= power;
260  binVal += "1";
261  } else {
262  binVal += "0";
263  }
264  }
265 
266  if (lang == Language::VHDL) {
267  stream << StringTools::indent(level) << "constant " << name()
268  << " : std_logic_vector(" << width_ - 1
269  << " downto 0) := \"" << binVal << "\";\n";
270  } else if (lang == Language::Verilog) {
271  stream << StringTools::indent(level)
272  << "localparam [" << width_-1 << ":0] "
273  << name() << " = " << width_ << "'b" << binVal << ";\n";
274  } else {
275  throw std::runtime_error(__PRETTY_FUNCTION__);
276  }
277  }
278 
279  private:
280  int width_;
281  int value_;
282  };
283 
284  /**
285  * Integer constant.
286  */
287  class IntegerConstant : public Generatable {
288  public:
289  IntegerConstant(std::string name, int value)
290  : Generatable(name), value_(value) {}
291 
292  int value() const noexcept { return value_; }
293 
294  Width width() final { return {name(), value_}; }
295 
296  void declare(std::ostream& stream, Language lang, int level) {
297  if (lang == Language::VHDL) {
298  stream << StringTools::indent(level) << "constant " << name()
299  << " : integer := " << value() << ";\n";
300  } else if (lang == Language::Verilog) {
301  stream << StringTools::indent(level) << "localparam integer "
302  << name() << " = " << value() << ";\n";
303  } else {
304  throw std::runtime_error(__PRETTY_FUNCTION__);
305  }
306  }
307 
308  private:
309  int value_;
310  };
311 
312  /**
313  * Async signal/wire.
314  */
315  class Wire : public Generatable {
316  public:
317  Wire(std::string name, int width = 1, WireType wt = WireType::Auto)
318  : Generatable(name), width_(width), wt_(wt) {}
319  Wire(std::string name, std::string width)
320  : Generatable(name), strWidth_(width), width_(-1) {}
321 
322  Width width() final { return {strWidth_, width_}; }
323 
324  void declare(std::ostream& stream, Language lang, int ident) {
325  if (lang == Language::VHDL) {
326  stream << StringTools::indent(ident) << "signal "
327  << name() << " : ";
328  if (width_ < 0 || width_ > 1 || wt_ == WireType::Vector) {
329  if (strWidth_.empty()) {
330  stream << "std_logic_vector("
331  << std::to_string(width_ - 1)
332  << " downto 0);\n";
333  } else {
334  stream << "std_logic_vector(" << strWidth_
335  << "-1 downto 0);\n";
336  }
337  } else {
338  stream << "std_logic;\n";
339  }
340  } else if (lang == Language::Verilog) {
341  stream << StringTools::indent(ident) << "reg ";
342  if (width_ < 0 || width_ > 1) {
343  if (strWidth_.empty()) {
344  stream << "[" << std::to_string(width_ - 1) << ":0] ";
345  } else {
346  stream << "[" << strWidth_ << "-1:0] ";
347  }
348  }
349  stream << name() << ";\n";
350  } else {
351  throw std::runtime_error(__PRETTY_FUNCTION__);
352  }
353  }
354 
355  WireType wireType() const final { return wt_; }
356 
357  private:
358  std::string strWidth_;
359  int width_;
361  };
362 
363  /**
364  * Assign default value.
365  */
367  public:
368  DefaultAssign(std::string name, std::string value)
370  DefaultAssign(std::string name)
371  : SequentialStatement(name), value_(""), dontCare_(true) {}
372 
373  void hdl(std::ostream& stream, Language lang, int level) override {
374  Width w = width(name());
375  WireType t = wireType(name());
376 
377 
378  if (lang == Language::VHDL) {
379  std::string def = "-";
380  if (!dontCare_)
381  def = value_.substr(0, 1);
382 
383  std::string assign = " <= ";
384  if (isVariable(name())) {
385  assign = " := ";
386  }
387  stream << StringTools::indent(level) << name() << assign;
388 
389  if (w.strWidth.empty() && w.intWidth == 1) {
390  char delim = t == WireType::Auto ? '\'' : '"';
391  stream << delim << def << delim << ";\n";
392  } else {
393  stream << "(others => '" << def << "');\n";
394  }
395  } else if (lang == Language::Verilog) {
396  std::string def = "x";
397  if (!dontCare_)
398  def = value_.substr(0, 1);
399 
400  stream << StringTools::indent(level)
401  << name() << " = 'b" << def << ";\n";
402  } else {
403  throw std::runtime_error(__PRETTY_FUNCTION__);
404  }
405  }
406 
407  private:
408  std::string value_;
409  bool dontCare_;
410  };
411 
412 
413  class Variable : public Generatable {
414  public:
415  Variable(std::string name, int width = 1)
416  : Generatable(name), strWidth_(std::to_string(width)),
418  Variable(std::string name, std::string width)
421 
422  Width width() final { return {strWidth_, width_}; }
423 
424  void declare(std::ostream& stream, Language lang, int level) {
425  if (lang == Language::VHDL) {
426  stream << StringTools::indent(level) << "variable " << name()
427  << " : " << vhdlTypeDeclaration() << ";\n";
428  } else if (lang == Language::Verilog) {
429  stream << StringTools::indent(level)
431  << " " << name() << ";\n";
432  } else {
433  throw std::runtime_error(__PRETTY_FUNCTION__);
434  }
435  }
436 
437  std::string vhdlRange() {
438  std::string width = strWidth_;
439  if (width.empty()) {
440  width = std::to_string(width_);
441  }
442  return "(" + width + "-1 downto 0)";
443  }
444 
445  std::string verilogRange() {
446  std::string width = strWidth_;
447  if (width.empty()) {
448  width = std::to_string(width_);
449  }
450  return "[" + width + "-1:0] ";
451  }
452 
453  virtual std::string vhdlTypeDeclaration() {
454  throw std::runtime_error(__PRETTY_FUNCTION__);
455  }
456 
457  std::string verilogTypeDeclaration() {
458  std::string decl = "reg";
459  if (isVector()) {
460  decl += " " + verilogRange();
461  }
462  return decl;
463  }
464 
465  bool isVector() {
466  return wireType_ == WireType::Vector || width_ > 1;
467  }
468 
470  return wireType_;
471  }
472 
473  private:
474  std::string strWidth_;
475  int width_;
477  };
478 
479  /**
480  * Variable/async reg.
481  */
482  class LogicVariable : public Variable {
483  public:
484  LogicVariable(std::string name, int width = 1)
485  : Variable(name, width) {}
486  LogicVariable(std::string name, std::string width)
487  : Variable(name, width) {}
488 
489  std::string vhdlTypeDeclaration() {
490  if (isVector()) {
491  return "std_logic_vector" + vhdlRange();
492  } else {
493  return "std_logic";
494  }
495  }
496  };
497 
498  /**
499  * Unsigned variable/async reg.
500  */
501  class UnsignedVariable : public Variable {
502  public:
503  UnsignedVariable(std::string name, int width = 1)
504  : Variable(name, width) {}
505  UnsignedVariable(std::string name, std::string width)
506  : Variable(name, width) {}
507 
508  std::string vhdlTypeDeclaration() {
509  return "unsigned" + vhdlRange();
510  }
511  };
512 
513  /**
514  * Signed variable/async reg signed.
515  */
516  class SignedVariable : public Variable {
517  public:
518  SignedVariable(std::string name, int width = 1)
519  : Variable(name, width) {}
520  SignedVariable(std::string name, std::string width)
521  : Variable(name, width) {}
522 
523  std::string vhdlTypeDeclaration() {
524  return "signed" + vhdlRange();
525  }
526 
527  std::string verilogTypeDeclaration() {
528  std::string decl = "reg signed";
529  if (isVector()) {
530  decl += " " + verilogRange();
531  }
532  return decl;
533  }
534  };
535 
536  /**
537  * Assignment.
538  */
539  class Assign : public SequentialStatement {
540  public:
541  Assign(std::string var, LHSValue value)
542  : SequentialStatement(var), index_(-1), upperBound_(-1),
543  lowerBound_(-1), value_(value) {}
544  Assign(std::string var, LHSValue value, int idx)
545  : SequentialStatement(var), index_(idx), upperBound_(-1),
546  lowerBound_(-1), value_(value) {}
547  Assign(std::string var, LHSValue value, int ub, int lb)
548  : SequentialStatement(var), index_(-1), upperBound_(ub),
549  lowerBound_(lb), value_(value) {}
550 
551  void build() override {
553  writes(name());
554  reads(value_);
555  }
556 
557  void hdl(std::ostream& stream, Language lang, int level) override {
558  if (isRegister(name()) && !parentIs<Synchronous>()) {
559  throw std::runtime_error(
560  "assigning to register '" + name() +
561  "' is only allowed in synchronous context");
562  } else if (isVariable(name()) && (!parentIs<Synchronous>() ||
563  !parentIs<Asynchronous>())) {
564  throw std::runtime_error("Not allowed to assign to '" +
565  name() + "' in this context.");
566  }
567  if (lang == Language::VHDL) {
568  stream << StringTools::indent(level) << name();
569  if (upperBound_ >= 0) {
570  stream << "(" << upperBound_ << " downto "
571  << lowerBound_ << ")";
572  } else if (index_ >= 0) {
573  stream << "(" << index_ << ")";
574  }
575  if (isVariable(name())) {
576  stream << " := ";
577  } else {
578  stream << " <= ";
579  }
580  } else if (lang == Language::Verilog) {
581  if (!(parentIs<Synchronous>() || parentIs<Asynchronous>())) {
582  stream << StringTools::indent(level) << "always @*\n"
583  << StringTools::indent(level + 1) << name();
584  } else {
585  stream << StringTools::indent(level) << name();
586  }
587  if (upperBound_ >= 0) {
588  stream << "[" << upperBound_ << ":" << lowerBound_ << "]";
589  } else if (index_ >= 0) {
590  stream << "[" << index_ << "]";
591  }
592  if (isRegister(name())) {
593  stream << " <= ";
594  } else {
595  stream << " = ";
596  }
597  } else {
598  throw std::runtime_error(__PRETTY_FUNCTION__);
599  }
600  value_.hdl(stream, lang);
601  stream << ";\n";
602  }
603 
604  private:
605  int index_;
609  };
610 
611  /**
612  * When others/default.
613  */
614  class DefaultCase : public Generatable {
615  public:
616  DefaultCase() : Generatable("defaultCase") {}
617 
619  addComponent(rhs);
620  return *this;
621  }
622 
624  addComponent(rhs);
625  return *this;
626  }
627 
628  void hdl(std::ostream& stream, Language lang, int level) override {
629  if (lang == Language::VHDL) {
630  stream << StringTools::indent(level) << "when others =>\n";
631  implementAll(stream, lang, level);
632  } else if (lang == Language::Verilog) {
633  stream << StringTools::indent(level) << "default: begin\n";
634  implementAll(stream, lang, level);
635  stream << StringTools::indent(level) << "end\n";
636  } else {
637  throw std::runtime_error(__PRETTY_FUNCTION__);
638  }
639  }
640  };
641 
642  /**
643  * Case in a switch-case.
644  */
645  class Case : public Generatable {
646  public:
647  Case() : Generatable("case") {}
648  Case(std::string stringCase) : Generatable("case"),
649  stringCase_(stringCase) {}
650 
651  template<typename SS>
652  Case& operator<<(SS op) {
653  std::shared_ptr<SequentialStatement> ptr = std::make_shared<SS>(op);
654  pushComponent(ptr);
655  return *this;
656  }
657 
659  binaryCases_.emplace_back(rhs);
660  return *this;
661  }
662 
664  binaryCases_.emplace_back(rhs);
665  return *this;
666  }
667 
668  Case& operator<<(int rhs) {
669  intCases_.emplace_back(rhs);
670  return *this;
671  }
672 
673  Case& operator<<(std::string& rhs) {
674  stringCase_ = rhs;
675  return *this;
676  }
677 
678  Case& operator<<(std::string&& rhs) {
679  stringCase_ = rhs;
680  return *this;
681  }
682 
683  void hdl(std::ostream& stream, Language lang, int level) override {
684  if (lang == Language::VHDL) {
685  stream << StringTools::indent(level) << "when ";
686  if (!stringCase_.empty()) {
687  stream << stringCase_;
688  } else if (!intCases_.empty()) {
689  std::string separator = "";
690  for (auto&& c : intCases_) {
691  stream << separator << std::to_string(c);
692  separator = " | ";
693  }
694  } else if (!binaryCases_.empty()) {
695  std::string separator = "";
696  for (auto&& c : binaryCases_) {
697  stream << separator;
698  c.hdl(stream, lang);
699  separator = " | ";
700  }
701  } else {
702  throw std::runtime_error("Case has no case");
703  }
704  stream << " =>\n";
705  implementAll(stream, lang, level + 1);
706  } else if (lang == Language::Verilog) {
707  stream << StringTools::indent(level);
708  if (!stringCase_.empty()) {
709  stream << stringCase_;
710  } else if (!intCases_.empty()) {
711  std::string separator = "";
712  for (auto&& c : intCases_) {
713  stream << separator << std::to_string(c);
714  separator = ", ";
715  }
716  } else if (!binaryCases_.empty()) {
717  std::string separator = "";
718  for (auto&& c : binaryCases_) {
719  stream << separator;
720  c.hdl(stream, lang);
721  separator = ", ";
722  }
723  } else {
724  throw std::runtime_error("Case has no case");
725  }
726  stream << ": begin\n";
727  implementAll(stream, lang, level + 1);
728  stream << StringTools::indent(level) << "end\n";
729  } else {
730  throw std::runtime_error(__PRETTY_FUNCTION__);
731  }
732  }
733 
734  private:
735  std::string stringCase_;
736  std::vector<int> intCases_;
737  std::vector<BinaryLiteral> binaryCases_;
738  };
739 
740  /**
741  * Switch-case switch.
742  */
743  class Switch : public SequentialStatement {
744  public:
745  Switch(LHSValue control) : SequentialStatement("switch"),
746  control_(control) {}
747 
748  void addCase(Case rhs) {
749  addComponent(rhs);
750  }
751 
752  void addCase(DefaultCase rhs) {
753  addComponent(rhs);
754  }
755 
756  void build() override {
758  reads(control_);
759  }
760 
761  void hdl(std::ostream& stream, Language lang, int level) override {
762  if (lang == Language::VHDL) {
763  stream << StringTools::indent(level) << "case ";
764  control_.hdl(stream, lang);
765  stream << " is\n";
766  implementAll(stream, lang, level + 1);
767  stream << StringTools::indent(level) << "end case;\n";
768  } else if (lang == Language::Verilog) {
769  stream << StringTools::indent(level) << "case (";
770  control_.hdl(stream, lang);
771  stream << ")\n";
772  implementAll(stream, lang, level + 1);
773  stream << StringTools::indent(level) << "endcase\n";
774  } else {
775  throw std::runtime_error(__PRETTY_FUNCTION__);
776  }
777  }
778 
779  private:
781  };
782 
783  /**
784  * if/elsif/else.
785  */
786  class If : public SequentialStatement {
787  public:
788  template<typename SS>
789  If(LHSValue cls, SS ifBlock) : SequentialStatement("if"),
790  elseBlock_(nullptr) {
791  std::shared_ptr<SequentialStatement> ptr
792  = std::make_shared<SS>(ifBlock);
793  ifBlocks_.emplace_back(cls, ptr);
794  }
795 
796  template<typename SS>
797  void elseIfClause(LHSValue cls, SS ifBlock) {
798  std::shared_ptr<SequentialStatement> ptr
799  = std::make_shared<SS>(ifBlock);
800  ifBlocks_.emplace_back(cls, ptr);
801  }
802 
803  template<typename SS>
804  void elseClause(SS elseBlock) {
805  if (elseBlock_) {
806  throw std::runtime_error("Cannot to add a second else block.");
807  }
808  std::shared_ptr<SequentialStatement> ptr
809  = std::make_shared<SS>(elseBlock);
810  elseBlock_ = ptr;
811  }
812 
813  virtual void hdl(std::ostream& stream, Language lang, int level)
814  override {
815  if (lang == Language::VHDL) {
816  for (auto iter = ifBlocks_.begin(); iter != ifBlocks_.end();
817  ++iter) {
818  if (iter == ifBlocks_.begin()) {
819  stream << StringTools::indent(level) << "if ";
820  } else {
821  stream << StringTools::indent(level) << "elsif ";
822  }
823  iter->first.hdl(stream, lang);
824  stream << " then\n";
825  iter->second->hdl(stream, lang, level + 1);
826  }
827  if (elseBlock_ != nullptr) {
828  stream << StringTools::indent(level) << "else\n";
829  elseBlock_->hdl(stream, lang, level + 1);
830  }
831  stream << StringTools::indent(level) << "end if;\n";
832  } else if (lang == Language::Verilog) {
833  for (auto iter = ifBlocks_.begin(); iter != ifBlocks_.end();
834  ++iter) {
835  if (iter == ifBlocks_.begin()) {
836  stream << StringTools::indent(level) << "if ";
837  } else {
838  stream << StringTools::indent(level) << "end else if ";
839  }
840  iter->first.hdl(stream, lang);
841  stream << ") begin\n";
842  iter->second->hdl(stream, lang, level + 1);
843  }
844  if (elseBlock_ != nullptr) {
845  stream << StringTools::indent(level) << "end else begin\n";
846  elseBlock_->hdl(stream, lang, level + 1);
847  }
848  stream << StringTools::indent(level) << "end\n";
849  } else {
850  throw std::runtime_error(__PRETTY_FUNCTION__);
851  }
852  }
853 
854  void build() override {
856  for (auto&& block : ifBlocks_) {
857  reads(block.first);
858  block.second->setParent(this);
859  block.second->build();
860  }
861  if (elseBlock_ != nullptr) {
862  elseBlock_->setParent(this);
863  elseBlock_->build();
864  }
865  }
866 
867  private:
868  std::vector<std::pair<LHSValue,std::shared_ptr<SequentialStatement> > >
870  std::shared_ptr<SequentialStatement> elseBlock_;
871  };
872 
873  /**
874  * Code block, i.e., a collection of concurrent statements
875  */
877  public:
878  CodeBlock() : SequentialStatement("codeBlock") {}
879 
880  template<typename SS>
881  void append(SS cc) {
882  std::shared_ptr<SequentialStatement> ptr = std::make_shared<SS>(cc);
883  pushComponent(ptr);
884  }
885 
886  void hdl(std::ostream& stream, Language lang, int level) override {
887  if (lang == Language::VHDL) {
888  implementAll(stream, lang, level);
889  } else if (lang == Language::Verilog) {
890  implementAll(stream, lang, level);
891  } else {
892  throw std::runtime_error(__PRETTY_FUNCTION__);
893  }
894  }
895  };
896 
897  /**
898  * Async process/always.
899  */
900  class Asynchronous : public Generatable {
901  public:
902 
903  Asynchronous(const std::string& name) : Generatable(name) {}
904 
905  template<typename SS>
907  std::shared_ptr<SequentialStatement> ptr = std::make_shared<SS>(op);
908  pushComponent(ptr);
909  return *this;
910  }
911 
912  template<typename Var>
913  void addVariable(Var op) {
914  std::shared_ptr<Variable> ptr = std::make_shared<Var>(op);
915  variables_.push_back(ptr);
916  }
917 
918  virtual void reads(const std::string& var) override {
919  readList_.emplace(var);
920  if (parent() != nullptr) {
921  parent()->reads(var);
922  }
923  }
924 
925  virtual void build() override; // implemented @EOF
926 
927  virtual void
928  hdl(std::ostream& stream, Language lang, int level) override {
929  if (lang == Language::VHDL) {
930  stream << "\n";
931  stream << StringTools::indent(level) << name() << " : process(";
932  std::string separator = "";
933  for (auto&& r : readList_) {
934  if (!isConstant(r)) {
935  stream << separator << r;
936  separator = ", ";
937  }
938  }
939  stream << ")\n";
940  for (auto&& v : variables_) {
941  v->declare(stream, lang, level + 1);
942  }
943  stream << StringTools::indent(level) << "begin\n";
944  implementAll(stream, lang, level + 1);
945  stream << StringTools::indent(level) << "end process "
946  << name() << ";\n";
947  } else if (lang == Language::Verilog) {
948  stream << "\n";
949  stream << StringTools::indent(level) << "// " << name() << "\n";
950  stream << StringTools::indent(level) << "always @*";
951  /**
952  * @lassetodo Sensitivity list implementation here
953  * for verilog if needed.
954  * <pre>
955  * If sensitivity list is needed for verilog replace
956  * @* with @(, uncomment following code, and add ) before
957  * begin
958  *
959  * std::string separator = "";
960  * for (auto&& r : readList_) {
961  * stream << separator << r;
962  * separator = " or ";
963  * }
964  * </pre>
965  */
966  stream << " begin\n";
967  implementAll(stream, lang, level + 1);
968  stream << StringTools::indent(level) << "end\n";
969  } else {
970  throw std::runtime_error(__PRETTY_FUNCTION__);
971  }
972  }
973 
974  private:
975  std::vector< std::shared_ptr<Variable> > variables_;
976  std::unordered_set<std::string> readList_;
977  };
978 
979  /**
980  * Sync process/always.
981  */
982  class Synchronous : public Generatable {
983  public:
984  Synchronous(std::string name) : Generatable(name) {}
985 
986  template<typename SS>
988  std::shared_ptr<SequentialStatement> ptr = std::make_shared<SS>(op);
989  pushComponent(ptr);
990  return *this;
991  }
992 
993  template<typename Var>
994  void addVariable(Var op) {
995  std::shared_ptr<Variable> ptr = std::make_shared<Var>(op);
996  variables_.push_back(op);
997  }
998 
999  virtual void build() override; // implemented @EOF
1000 
1001  virtual void writes(const std::string& var) override {
1002  //Generatable::writes(var);
1003  if (isVariable(var)) {
1004  return;
1005  }
1006  if (!isRegister(var)) {
1007  std::cerr << "Trying to write nonregister " << var << "\n";
1008  throw std::runtime_error(__PRETTY_FUNCTION__);
1009  }
1010  registers_.emplace(var);
1011  }
1012 
1013  virtual void vhdlReset(std::ostream& stream, Language lang, int level) {
1014  if (hasOption("active low reset"))
1015  stream << StringTools::indent(level) << "if rstx = '0' then\n";
1016  if (hasOption("active high reset"))
1017  stream << StringTools::indent(level) << "if rst = '1' then\n";
1018  for (auto&& r : registers_) {
1019  Register& reg = getRegister(r);
1020  if (reg.resetOption() == ResetOption::Mandatory ||
1021  hasOption("reset everything")) {
1022  reg.reset(stream, lang, level + 1);
1023  }
1024  }
1025  // Leaves if clause open for else/elsif
1026  }
1027 
1028  virtual void
1029  hdl(std::ostream& stream, Language lang, int level) override {
1030  if (lang == Language::VHDL) {
1031  stream << "\n"
1032  << StringTools::indent(level) << name() << " : process";
1033  if (hasOption("asynchronous reset")) {
1034  stream << "(clk, rstx)\n";
1035  } else {
1036  stream << "(clk)\n";
1037  }
1038 
1039  for (auto&& v : variables_) {
1040  v->declare(stream, lang, level + 1);
1041  }
1042 
1043  stream << StringTools::indent(level) << "begin\n";
1044  if (hasOption("asynchronous reset")) {
1045  vhdlReset(stream, lang, level + 1);
1046  stream << StringTools::indent(level + 1)
1047  << "elsif clk = '1' and clk'event then\n";
1048  implementAll(stream, lang, level + 2);
1049  } else {
1050  stream << StringTools::indent(level + 1)
1051  << "if clk = '1' and clk'event then\n";
1052  vhdlReset(stream, lang, level + 2);
1053  stream << StringTools::indent(level + 2) << "else\n";
1054  implementAll(stream, lang, level + 3);
1055  stream << StringTools::indent(level + 2) << "end if;\n";
1056  }
1057  stream << StringTools::indent(level + 1) << "end if;\n";
1058  stream << StringTools::indent(level)
1059  << "end process " << name() << ";\n";
1060  } else if (lang == Language::Verilog) {
1061  stream << "\n";
1062  stream << StringTools::indent(level) << "// " << name() << "\n";
1063  if (hasOption("asynchronous reset")) {
1064  stream << StringTools::indent(level)
1065  << "always @(posedge clk or negedge rstx) begin\n";
1066  } else {
1067  stream << StringTools::indent(level)
1068  << "always @(posedge clk) begin\n";
1069  }
1070  stream << StringTools::indent(level + 1)
1071  << "if (~rstx) begin\n";
1072  for (auto&& r : registers_) {
1073  Register& reg = getRegister(r);
1074  if (reg.resetOption() == ResetOption::Mandatory ||
1075  hasOption("reset everything")) {
1076  reg.reset(stream, lang, level + 2);
1077  }
1078  }
1079  stream << StringTools::indent(level + 1) << "end else begin\n";
1080  implementAll(stream, lang, level + 2);
1081  stream << StringTools::indent(level + 1) << "end\n";
1082  stream << StringTools::indent(level) << "end\n";
1083  } else {
1084  throw std::runtime_error(__PRETTY_FUNCTION__);
1085  }
1086  }
1087 
1088  private:
1089  std::vector< std::shared_ptr<Variable> > variables_;
1090  std::unordered_set<std::string> registers_;
1091  };
1092 
1093  /**
1094  * Force newline to hdl.
1095  */
1096  class NewLine : public Generatable {
1097  public:
1099 
1100  void hdl(std::ostream& stream, Language lang, int level) final {
1101  (void)lang;
1102  (void)level;
1103  stream << "\n";
1104  }
1105  };
1106 
1107  /**
1108  * Wrapper for behavioral code constructs.
1109  */
1110  class Behaviour : public Generatable {
1111  public:
1112  Behaviour() : Generatable("behaviour") {}
1113  virtual ~Behaviour() = default;
1114 
1116  addComponent(std::forward<Synchronous>(rhs));
1117  return *this;
1118  }
1119 
1121  addComponent(std::forward<Asynchronous>(rhs));
1122  return *this;
1123  }
1124 
1126  addComponent(rhs);
1127  return *this;
1128  }
1129 
1131  addComponent(rhs);
1132  return *this;
1133  }
1134 
1136  addComponent(rhs);
1137  return *this;
1138  }
1139 
1140  Behaviour& operator<<(Assign& assignment) {
1141  addComponent(assignment);
1142  return *this;
1143  }
1144 
1145  Behaviour& operator<<(Assign&& assignment) {
1146  addComponent(assignment);
1147  return *this;
1148  }
1149 
1150  void behaviour(std::ostream& stream, Language lang,
1151  int level) {
1152  forAll([&](std::shared_ptr<Generatable> c) {
1153  c->hdl(stream, lang, level);
1154  });
1155  }
1156 
1157  private:
1158  };
1159 
1160  /**
1161  * Entity/module.
1162  */
1163  class Module : public Generatable {
1164  public:
1165  Module(std::string name) : Generatable(name), prefix_(name) {
1166  set_header();
1167  }
1168 
1170  prefix_(info.name) {
1171  set_header();
1172  id_ = id;
1173  for (auto&& p : info.parameters) {
1174  parameters_.emplace_back(Parameter{p.name, p.value});
1175  }
1176  for (auto&& p : info.ports) {
1177  Direction dir = p.direction == "in" ?
1179  if (p.vector) {
1180  *this << Port(p.name, dir, p.left + "+1");
1181  } else {
1182  *this << Port(p.name, dir);
1183  }
1184  }
1185  }
1186 
1187  void set_header() {
1188  auto now = std::chrono::system_clock::now();
1189  auto now_c = std::chrono::system_clock::to_time_t(now);
1190  char buffer[31];
1191  std::stringstream ss;
1192  std::strftime(buffer, 30, "%c", std::localtime(&now_c));
1193  ss << buffer; // std::put_time(std::localtime(&now_c), "%c");
1194  headerComment_.emplace_back(
1195  "Module generated by TTA Codesign Environment");
1196  headerComment_.emplace_back("");
1197  headerComment_.emplace_back(
1198  std::string("Generated on ") + ss.str());
1199  headerComment_.emplace_back("");
1200  }
1201 
1202  void set_prefix(std::string prefix) {
1203  prefix_ = prefix;
1204  }
1205 
1207  behaviours_.emplace_back(new Behaviour(rhs));
1208  return *this;
1209  }
1210 
1212  behaviours_.emplace_back(new Behaviour(rhs));
1213  return *this;
1214  }
1215 
1217  ports_.push_back(port);
1218  return *this;
1219  }
1220 
1222  parameters_.emplace_back(param);
1223  return *this;
1224  }
1225 
1227  constants_.emplace_back(constant);
1228  return *this;
1229  }
1230 
1232  binaryConstants_.emplace_back(constant);
1233  return *this;
1234  }
1235 
1237  wires_.emplace_back(new Wire(wire));
1238  return *this;
1239  }
1240 
1242  registers_.emplace_back(reg);
1243  return *this;
1244  }
1245 
1247  registers_.emplace_back(reg);
1248  return *this;
1249  }
1250 
1252  options_.emplace(opt.name());
1253  return *this;
1254  }
1255 
1257  modules_.emplace_back(rhs);
1258  return *this;
1259  }
1260 
1262  modules_.emplace_back(rhs);
1263  return *this;
1264  }
1265 
1266  void build() final {
1267  for (auto&& b : behaviours_) {
1268  b->setParent(this);
1269  b->build();
1270  }
1271  }
1272 
1273  void appendToHeader(const std::string& line) {
1274  headerComment_.emplace_back(line);
1275  }
1276 
1277  virtual bool isRegister(const std::string& name) final {
1278  for (auto&& r : registers_) {
1279  if (r.name() == name) {
1280  return true;
1281  }
1282  }
1283  return false;
1284  }
1285 
1286  virtual bool isConstant(const std::string& name) final {
1287  for (auto&& r : constants_) {
1288  if (r.name() == name) {
1289  return true;
1290  }
1291  }
1292  for (auto&& r : binaryConstants_) {
1293  if (r.name() == name) {
1294  return true;
1295  }
1296  }
1297  return false;
1298  }
1299 
1300  virtual bool isVariable(const std::string& name) final {
1301  for (auto&& v : variables_) {
1302  if (v->name() == name) {
1303  return true;
1304  }
1305  }
1306  return false;
1307  }
1308 
1309  void registerVariable(const std::shared_ptr<Variable> var) {
1310  for (auto&& v : variables_) {
1311  if (v->name() == var->name()) {
1312  throw std::runtime_error("tried to register variable " +
1313  var->name() + " multiple times");
1314  }
1315  }
1316  variables_.push_back(var);
1317  }
1318 
1319  Width width(const std::string& name) final {
1320  for (auto&& v : parameters_) {
1321  if (v.name() == name) {
1322  return v.width();
1323  }
1324  }
1325  for (auto&& v : constants_) {
1326  if (v.name() == name) {
1327  return v.width();
1328  }
1329  }
1330  for (auto&& v : registers_) {
1331  if (v.name() == name) {
1332  return v.width();
1333  }
1334  }
1335  for (auto&& v : wires_) {
1336  if (v->name() == name) {
1337  return v->width();
1338  }
1339  }
1340  for (auto&& v : variables_) {
1341  if (v->name() == name) {
1342  return v->width();
1343  }
1344  }
1345  for (auto&& v : ports_) {
1346  if (v.name() == name) {
1347  return v.width();
1348  }
1349  }
1350  // not finding a thing is an error.
1351  throw std::runtime_error("Couldn't find width for " + name);
1352  }
1353 
1354  WireType wireType(const std::string& name) final {
1355  for (auto&& v : ports_) {
1356  if (v.name() == name) {
1357  return v.wireType();
1358  }
1359  }
1360  for (auto&& v : wires_) {
1361  if (v->name() == name) {
1362  return v->wireType();
1363  }
1364  }
1365  for (auto&& v : variables_) {
1366  if (v->name() == name) {
1367  return v->wireType();
1368  }
1369  }
1370  // not finding a thing is an error.
1371  throw std::runtime_error("Couldn't find wire type for " + name);
1372  }
1373 
1374  void reads(const std::string& var) final { (void)var; }
1375 
1376  void writes(const std::string& var) final { (void)var; }
1377 
1378  void declare(std::ostream& stream, Language lang, int level) {
1379  if (lang == Language::VHDL) {
1380  stream << StringTools::indent(level) << "component "
1381  << name() << " is\n";
1382  // - Generics
1383  if (!parameters_.empty()) {
1384  std::string separator = "";
1385  stream << StringTools::indent(level + 1) << "generic (\n";
1386  for (auto&& parameter : parameters_) {
1387  stream << separator << StringTools::indent(level + 2);
1388  parameter.declare(stream, lang);
1389  separator = ";\n";
1390  }
1391  stream << ");\n";
1392  }
1393  // - Ports
1394  if (!ports_.empty()) {
1395  std::string separator = "";
1396  stream << StringTools::indent(level + 1) << "port (\n";
1397  for (auto&& port : ports_) {
1398  stream << separator << StringTools::indent(level + 2);
1399  port.declare(stream, lang);
1400  separator = ";\n";
1401  }
1402  stream << ");\n";
1403  }
1404  stream << StringTools::indent(level) << "end component "
1405  << name() << ";\n";
1406  } else if (lang == Language::Verilog) {
1407  // no declaration for verilog.
1408  } else {
1409  throw std::runtime_error(__PRETTY_FUNCTION__);
1410  }
1411  }
1412 
1413  void instantiate(std::ostream& stream, Language lang, int level) {
1414  std::string instance = prefix_ + "_" + std::to_string(id_);
1415  if (lang == Language::VHDL) {
1416  stream << StringTools::indent(level)
1417  << instance << " : " << name() << "\n";
1418  if (parameters_.size() > 0) {
1419  stream << StringTools::indent(level + 1) << "generic map (\n";
1420 
1421  std::string separator = "";
1422  for (auto&& p : parameters_) {
1423  stream << separator
1424  << StringTools::indent(level + 2)
1425  << p.name() << " => " << p.strValue();
1426  separator = ",\n";
1427  }
1428  stream << ")\n";
1429  }
1430  std::string separator = "";
1431  stream << StringTools::indent(level + 1) << "port map (\n";
1432  for (auto&& p : ports_) {
1433  stream << separator << StringTools::indent(level + 2)
1434  << p.name() << " => ";
1435  if (p.name() == "clk" || p.name() == "rstx" ||
1436  p.name() == "glock_in") {
1437  stream << p.name();
1438  } else {
1439  stream << instance << "_" << p.name();
1440  }
1441  separator = ",\n";
1442  }
1443  stream << ");\n";
1444  } else if (lang == Language::Verilog) {
1445  stream << StringTools::indent(level) << name() << " ";
1446  if (parameters_.size() > 0) {
1447  stream << "#(";
1448  std::string separator = "";
1449  for (auto&& p : parameters_) {
1450  stream << separator;
1451  stream << "." << p.name() << "(" << p.strValue() << ")";
1452  separator = ", ";
1453  }
1454  stream << ") ";
1455  }
1456  std::string separator = "";
1457  stream << instance << " (\n";
1458  for (auto&& p : ports_) {
1459  stream << separator;
1460  stream << StringTools::indent(level + 2) << "." << p.name()
1461  << "(";
1462  if (p.name() == "clk" || p.name() == "rstx" ||
1463  p.name() == "glock_in") {
1464  stream << p.name() << ")";
1465  } else {
1466  stream << instance << "_" << name() << ")";
1467  }
1468  separator = ",\n";
1469  }
1470  stream << ");\n";
1471  } else {
1472  throw std::runtime_error(__PRETTY_FUNCTION__);
1473  }
1474  }
1475 
1476  void implement(std::ostream& stream, Language lang, int level = 0) {
1477  clear();
1478  build();
1479  if (lang == Language::VHDL) {
1480  std::string ident = StringTools::indent(level);
1481  // Header comment
1482  for (auto&& line : headerComment_) {
1483  stream << ident << "-- " << line << "\n";
1484  }
1485  // Libraries
1486  stream << ident << "\n"
1487  << ident << "library ieee;\n"
1488  << ident << "use ieee.std_logic_1164.all;\n"
1489  << ident << "use ieee.numeric_std.all;\n"
1490  << ident << "use ieee.std_logic_misc.all;\n"
1491  // Entity
1492  << ident << "\n"
1493  << ident << "entity " << name() << " is\n";
1494  // - Generics
1495  if (!parameters_.empty()) {
1496  std::string separator = "";
1497  stream << StringTools::indent(level + 1) << "generic (\n";
1498  for (auto&& parameter : parameters_) {
1499  stream << separator;
1500  parameter.declare(stream, lang, level + 2);
1501  separator = ";\n";
1502  }
1503  stream << ");\n";
1504  }
1505  // - Ports
1506  if (!ports_.empty()) {
1507  std::string separator = "";
1508  stream << StringTools::indent(level + 1) << "port (\n";
1509  for (auto&& port : ports_) {
1510  stream << separator;
1511  port.declare(stream, lang, level + 2);
1512  separator = ";\n";
1513  }
1514  stream << ");\n";
1515  }
1516  stream << ident << "end entity " << name() << ";\n"
1517  // Architecture
1518  << ident << "\n"
1519  << ident << "architecture rtl of "
1520  << name() << " is\n";
1521  // constants
1522  if (!constants_.empty() || !binaryConstants_.empty()) {
1523  stream << "\n";
1524  }
1525  for (auto&& c : constants_) {
1526  c.declare(stream, lang, level + 1);
1527  }
1528  for (auto&& c : binaryConstants_) {
1529  c.declare(stream, lang, level + 1);
1530  }
1531  // wires
1532  if (!wires_.empty()) {
1533  stream << "\n";
1534  }
1535  for (auto&& w : wires_) {
1536  w->declare(stream, lang, level + 1);
1537  }
1538  // registers
1539  if (!registers_.empty()) {
1540  stream << "\n";
1541  }
1542  for (auto&& r : registers_) {
1543  r.declare(stream, lang, level + 1);
1544  }
1545  // declare components
1546  std::vector<std::string> declared;
1547  for (auto&& m : modules_) {
1548  if (std::find(declared.begin(), declared.end(),
1549  m.name()) != declared.end()) {
1550  continue;
1551  }
1552  stream << "\n";
1553  m.declare(stream, lang, level + 1);
1554  declared.emplace_back(m.name());
1555  }
1556  stream << StringTools::indent(level) << "\nbegin\n\n";
1557  // instantiate components
1558  for (auto&& m : modules_) {
1559  m.instantiate(stream, lang, level + 1);
1560  stream << "\n";
1561  }
1562  // actual behavioural code
1563  for (auto&& b : behaviours_) {
1564  b->behaviour(stream, lang, level + 1);
1565  }
1566  stream << "\n";
1567  stream << StringTools::indent(level)
1568  << "end architecture rtl;\n\n";
1569 
1570  } else if (lang == Language::Verilog) {
1571  // Header comment
1572  stream << StringTools::indent(level) << "/*\n";
1573  for (auto&& line : headerComment_) {
1574  stream << StringTools::indent(level)
1575  << " * " << line << "\n";
1576  }
1577  stream << StringTools::indent(level) << " */\n";
1578  // Module
1579  stream << StringTools::indent(level) << "\n";
1580  stream << StringTools::indent(level) << "module " << name();
1581  // - Parameters
1582  if (!parameters_.empty()) {
1583  std::string separator = "";
1584  stream << " #(\n";
1585  for (auto&& parameter : parameters_) {
1586  stream << separator;
1587  parameter.declare(stream, lang, level + 2);
1588  separator = ",\n";
1589  }
1590  stream << ")";
1591  }
1592  // - Ports
1593  if (!ports_.empty()) {
1594  std::string separator = "";
1595  stream << " (\n";
1596  for (auto&& port : ports_) {
1597  stream << separator;
1598  port.declare(stream, lang, level + 2);
1599  separator = ",\n";
1600  }
1601  stream << ")";
1602  }
1603  // end module interface
1604  stream << ";\n";
1605  // constants
1606  if (!constants_.empty() || !binaryConstants_.empty()) {
1607  stream << "\n";
1608  }
1609  for (auto&& c : constants_) {
1610  c.declare(stream, lang, level + 1);
1611  }
1612  for (auto&& c : binaryConstants_) {
1613  c.declare(stream, lang, level + 1);
1614  }
1615  // wires
1616  if (!wires_.empty()) {
1617  stream << "\n";
1618  }
1619  for (auto&& w : wires_) {
1620  w->declare(stream, lang, level + 1);
1621  }
1622  // variables
1623  if (!variables_.empty()) {
1624  stream << "\n";
1625  for (auto&& v : variables_) {
1626  v->declare(stream, lang, level + 1);
1627  }
1628  }
1629  // registers
1630  if (!registers_.empty()) {
1631  stream << "\n";
1632  }
1633  for (auto&& r : registers_) {
1634  r.declare(stream, lang, level + 1);
1635  }
1636  // instantiate stuff
1637  for (auto&& m : modules_) {
1638  stream << "\n";
1639  m.instantiate(stream, lang, level + 1);
1640  }
1641  // actual code
1642  stream << "\n";
1643  for (auto&& b : behaviours_) {
1644  b->behaviour(stream, lang, level + 1);
1645  }
1646  // end module
1647  stream << "\n";
1648  stream << StringTools::indent(level) << "endmodule\n\n";
1649  } else {
1650  throw std::runtime_error(__PRETTY_FUNCTION__);
1651  }
1652  }
1653 
1654  bool hasOption(const std::string& var) final {
1655  return std::find(options_.begin(), options_.end(), var) !=
1656  options_.end();
1657  }
1658 
1659  Register& getRegister(const std::string& var) final {
1660  for (auto&& r : registers_) {
1661  if (r.name() == var) {
1662  return r;
1663  }
1664  }
1665  throw std::runtime_error("Couldn't find register '" + var + "'");
1666  }
1667 
1668  private:
1669  void clear() {
1670  // clear variables.
1671  variables_.clear();
1672  // Remove duplicate registers.
1673  registers_.erase(std::unique(registers_.begin(), registers_.end(),
1674  [](Register l, Register r) {
1675  return l.name() == r.name();
1676  }),
1677  registers_.end());
1678  }
1679  int id_ = 0;
1680  std::string prefix_;
1681  std::unordered_set<std::string> options_;
1682  std::vector<std::string> headerComment_;
1683  std::vector<Parameter> parameters_;
1684  std::vector<Port> ports_;
1685  std::vector<IntegerConstant> constants_;
1686  std::vector<BinaryConstant> binaryConstants_;
1687  std::vector<std::shared_ptr<Wire>> wires_;
1688  std::vector<Register> registers_;
1689  std::vector<std::shared_ptr<Variable> > variables_;
1690  std::vector<std::shared_ptr<Behaviour>> behaviours_;
1691  std::vector<Module> modules_;
1692  };
1693 }
HDLGenerator::Module::behaviours_
std::vector< std::shared_ptr< Behaviour > > behaviours_
Definition: HDLGenerator.hh:1690
HDLGenerator::Generatable::writes
virtual void writes(const std::string &var)
Definition: Generatable.hh:80
HDLGenerator::Option::Option
Option(std::string name)
Definition: HDLGenerator.hh:209
HDLGenerator::Module::isConstant
virtual bool isConstant(const std::string &name) final
Definition: HDLGenerator.hh:1286
HDLGenerator::LHSValue
Definition: LHSValue.hh:39
HDLGenerator::SignedVariable::SignedVariable
SignedVariable(std::string name, std::string width)
Definition: HDLGenerator.hh:520
HDLGenerator::Generatable::pushComponent
void pushComponent(std::shared_ptr< Generatable > c)
Definition: Generatable.hh:230
HDLGenerator::If::elseBlock_
std::shared_ptr< SequentialStatement > elseBlock_
Definition: HDLGenerator.hh:870
HDLGenerator::Behaviour::behaviour
void behaviour(std::ostream &stream, Language lang, int level)
Definition: HDLGenerator.hh:1150
HDLGenerator::If::elseIfClause
void elseIfClause(LHSValue cls, SS ifBlock)
Definition: HDLGenerator.hh:797
HDLGenerator::ResetOption::Mandatory
@ Mandatory
HDLGenerator::Synchronous::build
virtual void build() override
Definition: HDLGenerator.cc:33
HDLGenerator::UnsignedVariable
Definition: HDLGenerator.hh:501
HDLGenerator::Asynchronous::hdl
virtual void hdl(std::ostream &stream, Language lang, int level) override
Definition: HDLGenerator.hh:928
HDLGenerator::IntegerConstant::value_
int value_
Definition: HDLGenerator.hh:309
HDLGenerator::BinaryLiteral
Definition: LHSValue.hh:71
HDLGenerator::HDLOperation::HDLOperation
HDLOperation(std::string name, std::deque< std::string > impl, Language lang)
Definition: HDLGenerator.hh:143
HDLGenerator::CodeBlock
Definition: HDLGenerator.hh:876
HDLGenerator
Definition: BinaryOps.hh:35
HDLGenerator::Module::operator<<
Module & operator<<(Module &rhs)
Definition: HDLGenerator.hh:1261
HDLGenerator::Module::prefix_
std::string prefix_
Definition: HDLGenerator.hh:1680
HDLGenerator::HDLOperation
Definition: HDLGenerator.hh:140
HDLGenerator::If::build
void build() override
Definition: HDLGenerator.hh:854
HDLGenerator::Module::variables_
std::vector< std::shared_ptr< Variable > > variables_
Definition: HDLGenerator.hh:1689
HDLGenerator::Synchronous::vhdlReset
virtual void vhdlReset(std::ostream &stream, Language lang, int level)
Definition: HDLGenerator.hh:1013
HDLGenerator::BinaryConstant::BinaryConstant
BinaryConstant(std::string name, int width, int value)
Definition: HDLGenerator.hh:246
HDLGenerator::DefaultAssign
Definition: HDLGenerator.hh:366
HDLGenerator::Module::operator<<
Module & operator<<(BinaryConstant &&constant)
Definition: HDLGenerator.hh:1231
HDLGenerator::Module::constants_
std::vector< IntegerConstant > constants_
Definition: HDLGenerator.hh:1685
HDLGenerator::SignedVariable
Definition: HDLGenerator.hh:516
HDLGenerator::Assign::index_
int index_
Definition: HDLGenerator.hh:605
HDLGenerator::Module::modules_
std::vector< Module > modules_
Definition: HDLGenerator.hh:1691
HDLGenerator::Asynchronous::addVariable
void addVariable(Var op)
Definition: HDLGenerator.hh:913
HDLGenerator::Switch::control_
LHSValue control_
Definition: HDLGenerator.hh:780
HDLGenerator::Module::appendToHeader
void appendToHeader(const std::string &line)
Definition: HDLGenerator.hh:1273
HDLGenerator::Module::set_header
void set_header()
Definition: HDLGenerator.hh:1187
HDLGenerator::Variable::verilogRange
std::string verilogRange()
Definition: HDLGenerator.hh:445
HDLGenerator::Module::operator<<
Module & operator<<(Register &reg)
Definition: HDLGenerator.hh:1246
HDLGenerator::Module
Definition: HDLGenerator.hh:1163
HDLGenerator::Synchronous::variables_
std::vector< std::shared_ptr< Variable > > variables_
Definition: HDLGenerator.hh:1089
HDLGenerator::Behaviour::~Behaviour
virtual ~Behaviour()=default
HDLGenerator::IntegerConstant::declare
void declare(std::ostream &stream, Language lang, int level)
Definition: HDLGenerator.hh:296
HDLGenerator::Variable::vhdlRange
std::string vhdlRange()
Definition: HDLGenerator.hh:437
HDLGenerator::Behaviour
Definition: HDLGenerator.hh:1110
HDLGenerator::CodeBlock::append
void append(SS cc)
Definition: HDLGenerator.hh:881
HDLGenerator::Module::set_prefix
void set_prefix(std::string prefix)
Definition: HDLGenerator.hh:1202
HDLGenerator::Parameter::declare
void declare(std::ostream &stream, Language lang, int level=0)
Definition: HDLGenerator.hh:225
HDLGenerator::Module::writes
void writes(const std::string &var) final
Definition: HDLGenerator.hh:1376
HDLGenerator::Asynchronous::build
virtual void build() override
Definition: HDLGenerator.cc:47
LHSValue.hh
HDLGenerator::If::elseClause
void elseClause(SS elseBlock)
Definition: HDLGenerator.hh:804
HDLGenerator::Variable::Variable
Variable(std::string name, int width=1)
Definition: HDLGenerator.hh:415
HDLGenerator::DefaultCase::operator<<
DefaultCase & operator<<(DefaultAssign &rhs)
Definition: HDLGenerator.hh:623
HDLGenerator::DefaultAssign::DefaultAssign
DefaultAssign(std::string name)
Definition: HDLGenerator.hh:370
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
HDLGenerator::Register::resetOption
ResetOption resetOption() const noexcept
Definition: HDLRegister.hh:131
HDLGenerator::CodeBlock::hdl
void hdl(std::ostream &stream, Language lang, int level) override
Definition: HDLGenerator.hh:886
HDLGenerator::If::hdl
virtual void hdl(std::ostream &stream, Language lang, int level) override
Definition: HDLGenerator.hh:813
HDLGenerator::Case::operator<<
Case & operator<<(std::string &rhs)
Definition: HDLGenerator.hh:673
HDLGenerator::Generatable::addComponent
void addComponent(Component c)
Definition: Generatable.hh:235
HDLGenerator::Switch::addCase
void addCase(Case rhs)
Definition: HDLGenerator.hh:748
HDLGenerator::BinaryConstant
Definition: HDLGenerator.hh:244
HDLGenerator::Wire::Wire
Wire(std::string name, int width=1, WireType wt=WireType::Auto)
Definition: HDLGenerator.hh:317
HDLGenerator::Switch::build
void build() override
Definition: HDLGenerator.hh:756
HDLGenerator::Assign::hdl
void hdl(std::ostream &stream, Language lang, int level) override
Definition: HDLGenerator.hh:557
HDLGenerator::Case::operator<<
Case & operator<<(SS op)
Definition: HDLGenerator.hh:652
HDLGenerator::CodeBlock::CodeBlock
CodeBlock()
Definition: HDLGenerator.hh:878
HDLGenerator::DefaultAssign::dontCare_
bool dontCare_
Definition: HDLGenerator.hh:409
ipxact::ModuleInfo::ports
std::vector< Port > ports
Definition: IPXact.hh:56
HDLGenerator::BinaryConstant::width_
int width_
Definition: HDLGenerator.hh:280
HDLGenerator::Generatable::getRegister
virtual Register & getRegister(const std::string &var)
Definition: Generatable.hh:89
HDLGenerator::Module::ports_
std::vector< Port > ports_
Definition: HDLGenerator.hh:1684
HDLGenerator::Behaviour::operator<<
Behaviour & operator<<(Synchronous &&rhs)
Definition: HDLGenerator.hh:1125
HDLGenerator::Synchronous::registers_
std::unordered_set< std::string > registers_
Definition: HDLGenerator.hh:1090
HDLGenerator::Case::operator<<
Case & operator<<(BinaryLiteral &&rhs)
Definition: HDLGenerator.hh:658
HDLGenerator::Width::intWidth
int intWidth
Definition: HWGenTools.hh:39
HDLGenerator::Case::Case
Case(std::string stringCase)
Definition: HDLGenerator.hh:648
HDLGenerator::Assign::upperBound_
int upperBound_
Definition: HDLGenerator.hh:606
HDLGenerator::Variable
Definition: HDLGenerator.hh:413
HDLGenerator::Module::operator<<
Module & operator<<(Option &&opt)
Definition: HDLGenerator.hh:1251
HDLGenerator::Module::width
Width width(const std::string &name) final
Definition: HDLGenerator.hh:1319
HDLGenerator::BinaryConstant::width
Width width() final
Definition: HDLGenerator.hh:251
HDLGenerator::Assign::Assign
Assign(std::string var, LHSValue value)
Definition: HDLGenerator.hh:541
HDLGenerator::DefaultAssign::value_
std::string value_
Definition: HDLGenerator.hh:408
HDLGenerator::Parameter::value_
int value_
Definition: HDLGenerator.hh:237
HDLGenerator::DefaultCase::operator<<
DefaultCase & operator<<(DefaultAssign &&rhs)
Definition: HDLGenerator.hh:618
HDLGenerator::Option
Definition: HDLGenerator.hh:207
HDLGenerator::Behaviour::operator<<
Behaviour & operator<<(Asynchronous &rhs)
Definition: HDLGenerator.hh:1120
HDLGenerator::Generatable::hasOption
virtual bool hasOption(const std::string &var)
Definition: Generatable.hh:98
HDLGenerator::Synchronous::writes
virtual void writes(const std::string &var) override
Definition: HDLGenerator.hh:1001
HDLGenerator::Asynchronous::variables_
std::vector< std::shared_ptr< Variable > > variables_
Definition: HDLGenerator.hh:975
HDLGenerator::Wire
Definition: HDLGenerator.hh:315
HDLGenerator::Module::operator<<
Module & operator<<(Behaviour &&rhs)
Definition: HDLGenerator.hh:1211
HDLGenerator::SequentialStatement::hdl
virtual void hdl(std::ostream &stream, Language lang, int level)
Definition: HDLGenerator.hh:125
HDLGenerator::Variable::vhdlTypeDeclaration
virtual std::string vhdlTypeDeclaration()
Definition: HDLGenerator.hh:453
StringTools.hh
HDLGenerator::Direction::In
@ In
HDLGenerator::Variable::isVector
bool isVector()
Definition: HDLGenerator.hh:465
HDLGenerator::Wire::strWidth_
std::string strWidth_
Definition: HDLGenerator.hh:358
HDLGenerator::Parameter::strValue
std::string strValue()
Definition: HDLGenerator.hh:223
HDLGenerator::Module::operator<<
Module & operator<<(Wire &&wire)
Definition: HDLGenerator.hh:1236
HDLGenerator::Generatable::forAll
void forAll(Func func)
Definition: Generatable.hh:195
HDLGenerator::Module::options_
std::unordered_set< std::string > options_
Definition: HDLGenerator.hh:1681
HDLGenerator::HDLOperation::hdl
void hdl(std::ostream &stream, Language lang, int level) override
Definition: HDLGenerator.hh:164
HDLGenerator::Port
Definition: HWGen/HDLPort.hh:38
HDLGenerator::SequentialStatement
Definition: HDLGenerator.hh:121
HDLGenerator::HDLOperation::impl_
std::deque< std::string > impl_
Definition: HDLGenerator.hh:174
HDLGenerator::Synchronous::operator<<
Synchronous & operator<<(SS op)
Definition: HDLGenerator.hh:987
HDLGenerator::Case
Definition: HDLGenerator.hh:645
HDLGenerator::NewLine
Definition: HDLGenerator.hh:1096
HDLGenerator::Case::stringCase_
std::string stringCase_
Definition: HDLGenerator.hh:735
HDLGenerator::NewLine::hdl
void hdl(std::ostream &stream, Language lang, int level) final
Definition: HDLGenerator.hh:1100
HDLGenerator::UnsignedVariable::UnsignedVariable
UnsignedVariable(std::string name, std::string width)
Definition: HDLGenerator.hh:505
HDLGenerator::Width::strWidth
std::string strWidth
Definition: HWGenTools.hh:38
HDLGenerator::Module::reads
void reads(const std::string &var) final
Definition: HDLGenerator.hh:1374
HDLGenerator::Module::headerComment_
std::vector< std::string > headerComment_
Definition: HDLGenerator.hh:1682
HDLGenerator::BinaryConstant::value
int value() const noexcept
Definition: HDLGenerator.hh:249
HDLGenerator::Module::build
void build() final
Definition: HDLGenerator.hh:1266
HDLGenerator::Assign::Assign
Assign(std::string var, LHSValue value, int ub, int lb)
Definition: HDLGenerator.hh:547
HDLGenerator::Asynchronous::reads
virtual void reads(const std::string &var) override
Definition: HDLGenerator.hh:918
HDLGenerator::Case::binaryCases_
std::vector< BinaryLiteral > binaryCases_
Definition: HDLGenerator.hh:737
HDLGenerator::Module::declare
void declare(std::ostream &stream, Language lang, int level)
Definition: HDLGenerator.hh:1378
HDLGenerator::Case::Case
Case()
Definition: HDLGenerator.hh:647
HDLGenerator::Generatable::isConstant
virtual bool isConstant(const std::string &name)
Definition: Generatable.hh:125
HDLGenerator::Module::instantiate
void instantiate(std::ostream &stream, Language lang, int level)
Definition: HDLGenerator.hh:1413
HDLGenerator::Module::registerVariable
void registerVariable(const std::shared_ptr< Variable > var)
Definition: HDLGenerator.hh:1309
HDLGenerator::Variable::Variable
Variable(std::string name, std::string width)
Definition: HDLGenerator.hh:418
HDLGenerator::Parameter::width
Width width() final
Definition: HDLGenerator.hh:222
HDLGenerator::Behaviour::Behaviour
Behaviour()
Definition: HDLGenerator.hh:1112
HDLGenerator::Generatable::isRegister
virtual bool isRegister(const std::string &name)
Definition: Generatable.hh:107
HDLGenerator::SequentialStatement::altname
std::string altname
Definition: HDLGenerator.hh:134
HDLGenerator::Module::operator<<
Module & operator<<(IntegerConstant &&constant)
Definition: HDLGenerator.hh:1226
HDLGenerator::WireType
WireType
Definition: HWGenTools.hh:34
HDLGenerator::SignedVariable::vhdlTypeDeclaration
std::string vhdlTypeDeclaration()
Definition: HDLGenerator.hh:523
HDLGenerator::Parameter::Parameter
Parameter(std::string name, std::string value)
Definition: HDLGenerator.hh:219
HDLGenerator::Synchronous::hdl
virtual void hdl(std::ostream &stream, Language lang, int level) override
Definition: HDLGenerator.hh:1029
HDLGenerator::Module::isVariable
virtual bool isVariable(const std::string &name) final
Definition: HDLGenerator.hh:1300
HDLGenerator::Generatable::parent
Generatable * parent() const noexcept
Definition: Generatable.hh:242
HDLGenerator::Behaviour::operator<<
Behaviour & operator<<(NewLine &&rhs)
Definition: HDLGenerator.hh:1135
HDLGenerator::IntegerConstant::value
int value() const noexcept
Definition: HDLGenerator.hh:292
HDLGenerator::Language::Verilog
@ Verilog
HDLGenerator::Wire::declare
void declare(std::ostream &stream, Language lang, int ident)
Definition: HDLGenerator.hh:324
HDLGenerator::IntegerConstant
Definition: HDLGenerator.hh:287
HDLGenerator::Assign::build
void build() override
Definition: HDLGenerator.hh:551
HDLGenerator::Module::operator<<
Module & operator<<(Module &&rhs)
Definition: HDLGenerator.hh:1256
HDLGenerator::Synchronous
Definition: HDLGenerator.hh:982
HDLGenerator::RawCodeLine::RawCodeLine
RawCodeLine(std::string vhdl, std::string verilog)
Definition: HDLGenerator.hh:185
HDLGenerator::Wire::width
Width width() final
Definition: HDLGenerator.hh:322
HDLGenerator::Parameter::Parameter
Parameter(std::string name, int value=-1)
Definition: HDLGenerator.hh:217
HDLGenerator::Case::operator<<
Case & operator<<(BinaryLiteral &rhs)
Definition: HDLGenerator.hh:663
HDLGenerator::Module::hasOption
bool hasOption(const std::string &var) final
Definition: HDLGenerator.hh:1654
HDLGenerator::BinaryConstant::value_
int value_
Definition: HDLGenerator.hh:281
HDLGenerator::RawCodeLine::verilog_
std::string verilog_
Definition: HDLGenerator.hh:201
HDLGenerator::LogicVariable::LogicVariable
LogicVariable(std::string name, int width=1)
Definition: HDLGenerator.hh:484
HDLGenerator::Variable::width_
int width_
Definition: HDLGenerator.hh:475
HDLGenerator::Module::implement
void implement(std::ostream &stream, Language lang, int level=0)
Definition: HDLGenerator.hh:1476
HDLGenerator::SequentialStatement::SequentialStatement
SequentialStatement(std::string name)
Definition: HDLGenerator.hh:123
IPXact.hh
HDLGenerator::HDLOperation::build
void build() override
Definition: HDLGenerator.hh:157
HDLGenerator::Assign::lowerBound_
int lowerBound_
Definition: HDLGenerator.hh:607
HDLGenerator::Parameter::strValue_
std::string strValue_
Definition: HDLGenerator.hh:238
HDLGenerator::Generatable::build
virtual void build()
Definition: Generatable.hh:56
HDLGenerator::Generatable::implementAll
virtual void implementAll(std::ostream &stream, Language lang)
Definition: Generatable.hh:183
HDLGenerator::Language
Language
Definition: HWGenTools.hh:33
HDLGenerator::Variable::verilogTypeDeclaration
std::string verilogTypeDeclaration()
Definition: HDLGenerator.hh:457
HDLGenerator::If
Definition: HDLGenerator.hh:786
HDLGenerator::Assign::value_
LHSValue value_
Definition: HDLGenerator.hh:608
HDLGenerator::RawCodeLine::hdl
void hdl(std::ostream &stream, Language lang, int level) final
Definition: HDLGenerator.hh:189
HDLGenerator::DefaultCase::DefaultCase
DefaultCase()
Definition: HDLGenerator.hh:616
HDLGenerator::Synchronous::addVariable
void addVariable(Var op)
Definition: HDLGenerator.hh:994
HDLGenerator::Generatable::reads
virtual void reads(const std::string &var)
Definition: Generatable.hh:63
HDLGenerator::Module::operator<<
Module & operator<<(Behaviour &rhs)
Definition: HDLGenerator.hh:1206
HDLGenerator::Variable::width
Width width() final
Definition: HDLGenerator.hh:422
HDLGenerator::Module::isRegister
virtual bool isRegister(const std::string &name) final
Definition: HDLGenerator.hh:1277
HDLGenerator::Behaviour::operator<<
Behaviour & operator<<(Synchronous &rhs)
Definition: HDLGenerator.hh:1115
HDLGenerator::LogicVariable::vhdlTypeDeclaration
std::string vhdlTypeDeclaration()
Definition: HDLGenerator.hh:489
HDLPort.hh
HDLGenerator::Asynchronous
Definition: HDLGenerator.hh:900
HDLGenerator::IntegerConstant::width
Width width() final
Definition: HDLGenerator.hh:294
HDLGenerator::Module::Module
Module(std::string name)
Definition: HDLGenerator.hh:1165
HDLGenerator::Module::getRegister
Register & getRegister(const std::string &var) final
Definition: HDLGenerator.hh:1659
HDLGenerator::Variable::strWidth_
std::string strWidth_
Definition: HDLGenerator.hh:474
HDLGenerator::Module::wireType
WireType wireType(const std::string &name) final
Definition: HDLGenerator.hh:1354
HDLGenerator::Module::registers_
std::vector< Register > registers_
Definition: HDLGenerator.hh:1688
HDLGenerator::If::ifBlocks_
std::vector< std::pair< LHSValue, std::shared_ptr< SequentialStatement > > > ifBlocks_
Definition: HDLGenerator.hh:869
HDLGenerator::Module::wires_
std::vector< std::shared_ptr< Wire > > wires_
Definition: HDLGenerator.hh:1687
HDLGenerator::DefaultCase
Definition: HDLGenerator.hh:614
HDLGenerator::Case::operator<<
Case & operator<<(std::string &&rhs)
Definition: HDLGenerator.hh:678
HDLGenerator::HDLOperation::operator<<
HDLOperation & operator<<(const std::string &&rhs)
Definition: HDLGenerator.hh:152
HDLGenerator::Generatable::width
virtual Width width()
Definition: Generatable.hh:162
HDLGenerator::Behaviour::operator<<
Behaviour & operator<<(NewLine &rhs)
Definition: HDLGenerator.hh:1130
HDLGenerator::BinaryConstant::declare
void declare(std::ostream &stream, Language lang, int level)
Definition: HDLGenerator.hh:253
HDLGenerator::Switch::addCase
void addCase(DefaultCase rhs)
Definition: HDLGenerator.hh:752
HDLGenerator::Module::id_
int id_
Definition: HDLGenerator.hh:1679
HDLGenerator::Variable::wireType_
WireType wireType_
Definition: HDLGenerator.hh:476
HWGenTools.hh
HDLGenerator::SignedVariable::verilogTypeDeclaration
std::string verilogTypeDeclaration()
Definition: HDLGenerator.hh:527
HDLGenerator::Switch::Switch
Switch(LHSValue control)
Definition: HDLGenerator.hh:745
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
HDLGenerator::Generatable::isVariable
virtual bool isVariable(const std::string &name)
Definition: Generatable.hh:116
HDLGenerator::Direction::Out
@ Out
HDLGenerator::Case::operator<<
Case & operator<<(int rhs)
Definition: HDLGenerator.hh:668
HDLGenerator::LogicVariable
Definition: HDLGenerator.hh:482
ipxact::ModuleInfo
Definition: IPXact.hh:53
HDLGenerator::HDLOperation::HDLOperation
HDLOperation()
Definition: HDLGenerator.hh:142
HDLGenerator::UnsignedVariable::UnsignedVariable
UnsignedVariable(std::string name, int width=1)
Definition: HDLGenerator.hh:503
HDLGenerator::Module::operator<<
Module & operator<<(Port &&port)
Definition: HDLGenerator.hh:1216
HDLGenerator::LHSValue::hdl
void hdl(std::ostream &stream, Language lang, int level)
Definition: LHSValue.cc:37
HDLGenerator::Module::parameters_
std::vector< Parameter > parameters_
Definition: HDLGenerator.hh:1683
HDLGenerator::Switch::hdl
void hdl(std::ostream &stream, Language lang, int level) override
Definition: HDLGenerator.hh:761
HDLGenerator::Parameter
Definition: HDLGenerator.hh:215
HDLGenerator::RawCodeLine
Definition: HDLGenerator.hh:183
HDLGenerator::If::If
If(LHSValue cls, SS ifBlock)
Definition: HDLGenerator.hh:789
HDLGenerator::WireType::Auto
@ Auto
HDLGenerator::Generatable::name
const std::string & name() const noexcept
Definition: Generatable.hh:239
HDLGenerator::Assign
Definition: HDLGenerator.hh:539
HDLGenerator::WireType::Vector
@ Vector
HDLGenerator::Asynchronous::Asynchronous
Asynchronous(const std::string &name)
Definition: HDLGenerator.hh:903
HDLGenerator::Variable::wireType
WireType wireType()
Definition: HDLGenerator.hh:469
HDLGenerator::Wire::wt_
WireType wt_
Definition: HDLGenerator.hh:360
HDLGenerator::Register
Definition: HDLRegister.hh:51
Generatable.hh
HDLGenerator::Generatable::wireType
virtual WireType wireType() const
Definition: Generatable.hh:166
HDLGenerator::Direction
Direction
Definition: HWGenTools.hh:35
HDLGenerator::Behaviour::operator<<
Behaviour & operator<<(Assign &assignment)
Definition: HDLGenerator.hh:1140
HDLGenerator::RawCodeLine::vhdl_
std::string vhdl_
Definition: HDLGenerator.hh:200
HDLGenerator::Asynchronous::readList_
std::unordered_set< std::string > readList_
Definition: HDLGenerator.hh:976
HDLRegister.hh
HDLGenerator::HDLOperation::operator<<
HDLOperation & operator<<(const std::string &rhs)
Definition: HDLGenerator.hh:147
HDLGenerator::Generatable
Definition: Generatable.hh:51
HDLGenerator::Module::operator<<
Module & operator<<(Register &&reg)
Definition: HDLGenerator.hh:1241
HDLGenerator::Switch
Definition: HDLGenerator.hh:743
HDLGenerator::Behaviour::operator<<
Behaviour & operator<<(Assign &&assignment)
Definition: HDLGenerator.hh:1145
HDLGenerator::DefaultAssign::hdl
void hdl(std::ostream &stream, Language lang, int level) override
Definition: HDLGenerator.hh:373
HDLGenerator::Module::operator<<
Module & operator<<(Parameter &&param)
Definition: HDLGenerator.hh:1221
HDLGenerator::Case::hdl
void hdl(std::ostream &stream, Language lang, int level) override
Definition: HDLGenerator.hh:683
HDLGenerator::Module::binaryConstants_
std::vector< BinaryConstant > binaryConstants_
Definition: HDLGenerator.hh:1686
HDLGenerator::IntegerConstant::IntegerConstant
IntegerConstant(std::string name, int value)
Definition: HDLGenerator.hh:289
HDLGenerator::LogicVariable::LogicVariable
LogicVariable(std::string name, std::string width)
Definition: HDLGenerator.hh:486
HDLGenerator::Wire::width_
int width_
Definition: HDLGenerator.hh:359
HDLGenerator::UnsignedVariable::vhdlTypeDeclaration
std::string vhdlTypeDeclaration()
Definition: HDLGenerator.hh:508
HDLGenerator::HDLOperation::lang_
Language lang_
Definition: HDLGenerator.hh:176
HDLGenerator::Language::VHDL
@ VHDL
HDLGenerator::DefaultAssign::DefaultAssign
DefaultAssign(std::string name, std::string value)
Definition: HDLGenerator.hh:368
HDLGenerator::SignedVariable::SignedVariable
SignedVariable(std::string name, int width=1)
Definition: HDLGenerator.hh:518
HDLGenerator::Asynchronous::operator<<
Asynchronous & operator<<(SS op)
Definition: HDLGenerator.hh:906
HDLGenerator::Assign::Assign
Assign(std::string var, LHSValue value, int idx)
Definition: HDLGenerator.hh:544
HDLGenerator::Module::clear
void clear()
Definition: HDLGenerator.hh:1669
HDLGenerator::Synchronous::Synchronous
Synchronous(std::string name)
Definition: HDLGenerator.hh:984
HDLGenerator::HDLOperation::readList_
std::vector< std::string > readList_
Definition: HDLGenerator.hh:175
HDLGenerator::Wire::Wire
Wire(std::string name, std::string width)
Definition: HDLGenerator.hh:319
HDLGenerator::NewLine::NewLine
NewLine()
Definition: HDLGenerator.hh:1098
HDLGenerator::Module::Module
Module(ipxact::ModuleInfo info, int id)
Definition: HDLGenerator.hh:1169
HDLGenerator::Width
Definition: HWGenTools.hh:37
HDLGenerator::Wire::wireType
WireType wireType() const final
Definition: HDLGenerator.hh:355
ipxact::ModuleInfo::parameters
std::vector< Parameter > parameters
Definition: IPXact.hh:55
HDLGenerator::Register::reset
void reset(std::ostream &stream, Language lang, int ident)
Definition: HDLRegister.hh:75
HDLGenerator::Variable::declare
void declare(std::ostream &stream, Language lang, int level)
Definition: HDLGenerator.hh:424
HDLGenerator::DefaultCase::hdl
void hdl(std::ostream &stream, Language lang, int level) override
Definition: HDLGenerator.hh:628
HDLGenerator::Case::intCases_
std::vector< int > intCases_
Definition: HDLGenerator.hh:736