OpenASIP  2.0
Public Member Functions | Protected Attributes | List of all members
HDLGenerator::Port Class Reference

#include <HDLPort.hh>

Inheritance diagram for HDLGenerator::Port:
Inheritance graph
Collaboration diagram for HDLGenerator::Port:
Collaboration graph

Public Member Functions

 Port (std::string name, Direction dir, int width=1, WireType wireType=WireType::Auto)
 
 Port (std::string name, Direction dir, std::string parametricWidth, WireType wireType=WireType::Auto)
 
virtual ~Port ()=default
 
void declare (std::ostream &stream, Language lang, int level=0)
 
std::string name ()
 
Width width ()
 
WireType wireType () const
 

Protected Attributes

std::string name_
 
Direction dir_
 
std::string parametricWidth_
 
int width_
 
WireType wireType_
 

Detailed Description

Entity/module port base class.

Definition at line 38 of file HWGen/HDLPort.hh.

Constructor & Destructor Documentation

◆ Port() [1/2]

HDLGenerator::Port::Port ( std::string  name,
Direction  dir,
int  width = 1,
WireType  wireType = WireType::Auto 
)
inline

Definition at line 40 of file HWGen/HDLPort.hh.

42  : name_(name), dir_(dir), width_(width), wireType_(wireType) {}

◆ Port() [2/2]

HDLGenerator::Port::Port ( std::string  name,
Direction  dir,
std::string  parametricWidth,
WireType  wireType = WireType::Auto 
)
inline

Definition at line 43 of file HWGen/HDLPort.hh.

45  : name_(name), dir_(dir), parametricWidth_(parametricWidth),
46  width_(-1), wireType_(wireType) {}

◆ ~Port()

virtual HDLGenerator::Port::~Port ( )
virtualdefault

Member Function Documentation

◆ declare()

void HDLGenerator::Port::declare ( std::ostream &  stream,
Language  lang,
int  level = 0 
)
inline

Definition at line 50 of file HWGen/HDLPort.hh.

50  {
51  stream << StringTools::indent(level);
52  if (lang == Language::VHDL) {
53  stream << name_;
54  if (dir_ == Direction::In) {
55  stream << " : in ";
56  } else {
57  stream << " : out ";
58  }
59  if (!parametricWidth_.empty()) {
60  stream << "std_logic_vector(" << parametricWidth_
61  << "-1 downto 0)";
62  } else if (wireType_ == WireType::Vector || width_ > 1) {
63  stream << "std_logic_vector("
64  << std::to_string(width_) << "-1 downto 0)";
65  } else {
66  stream << "std_logic";
67  }
68  } else if (lang == Language::Verilog) {
69  if (dir_ == Direction::In) {
70  stream << "input ";
71  } else {
72  stream << "output reg ";
73  }
74  if (!parametricWidth_.empty()) {
75  stream << "[" << parametricWidth_ << "-1:0] ";
76  } else if (wireType_ == WireType::Vector || width_ > 1) {
77  stream << "[" << std::to_string(width_ - 1) << ":0] ";
78  }
79  stream << name_;
80  } else {
81  throw std::runtime_error(__PRETTY_FUNCTION__);
82  }
83  };

References dir_, HDLGenerator::In, StringTools::indent(), name_, parametricWidth_, HDLGenerator::Vector, HDLGenerator::Verilog, HDLGenerator::VHDL, width_, and wireType_.

Here is the call graph for this function:

◆ name()

std::string HDLGenerator::Port::name ( )
inline

Definition at line 85 of file HWGen/HDLPort.hh.

85 { return name_; }

References name_.

◆ width()

Width HDLGenerator::Port::width ( )
inline

Definition at line 87 of file HWGen/HDLPort.hh.

87 { return {parametricWidth_, width_}; }

References parametricWidth_, and width_.

◆ wireType()

WireType HDLGenerator::Port::wireType ( ) const
inline

Definition at line 89 of file HWGen/HDLPort.hh.

89 { return wireType_; }

References wireType_.

Member Data Documentation

◆ dir_

Direction HDLGenerator::Port::dir_
protected

Definition at line 93 of file HWGen/HDLPort.hh.

Referenced by declare().

◆ name_

std::string HDLGenerator::Port::name_
protected

Definition at line 92 of file HWGen/HDLPort.hh.

Referenced by declare(), and name().

◆ parametricWidth_

std::string HDLGenerator::Port::parametricWidth_
protected

Definition at line 94 of file HWGen/HDLPort.hh.

Referenced by declare(), and width().

◆ width_

int HDLGenerator::Port::width_
protected

Definition at line 95 of file HWGen/HDLPort.hh.

Referenced by declare(), and width().

◆ wireType_

WireType HDLGenerator::Port::wireType_
protected

Definition at line 96 of file HWGen/HDLPort.hh.

Referenced by declare(), and wireType().


The documentation for this class was generated from the following file:
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
HDLGenerator::Port::dir_
Direction dir_
Definition: HWGen/HDLPort.hh:93
HDLGenerator::Port::wireType
WireType wireType() const
Definition: HWGen/HDLPort.hh:89
HDLGenerator::Direction::In
@ In
HDLGenerator::Port::wireType_
WireType wireType_
Definition: HWGen/HDLPort.hh:96
HDLGenerator::Port::width_
int width_
Definition: HWGen/HDLPort.hh:95
HDLGenerator::Port::width
Width width()
Definition: HWGen/HDLPort.hh:87
HDLGenerator::Language::Verilog
@ Verilog
HDLGenerator::WireType::Vector
@ Vector
HDLGenerator::Port::name
std::string name()
Definition: HWGen/HDLPort.hh:85
HDLGenerator::Port::name_
std::string name_
Definition: HWGen/HDLPort.hh:92
HDLGenerator::Language::VHDL
@ VHDL
HDLGenerator::Port::parametricWidth_
std::string parametricWidth_
Definition: HWGen/HDLPort.hh:94