yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RTLIL::Const Struct Reference

#include <rtlil.h>

Public Member Functions

 Const ()
 
 Const (std::string str)
 
 Const (int val, int width=32)
 
 Const (RTLIL::State bit, int width=1)
 
 Const (const std::vector< RTLIL::State > &bits)
 
 Const (const std::vector< bool > &bits)
 
bool operator< (const RTLIL::Const &other) const
 
bool operator== (const RTLIL::Const &other) const
 
bool operator!= (const RTLIL::Const &other) const
 
bool as_bool () const
 
int as_int (bool is_signed=false) const
 
std::string as_string () const
 
std::string decode_string () const
 
int size () const
 

Data Fields

int flags
 
std::vector< RTLIL::Statebits
 

Detailed Description

Definition at line 435 of file rtlil.h.

Constructor & Destructor Documentation

RTLIL::Const::Const ( )

Definition at line 36 of file rtlil.cc.

RTLIL::Const::Const ( std::string  str)

Definition at line 41 of file rtlil.cc.

42 {
44  for (int i = str.size()-1; i >= 0; i--) {
45  unsigned char ch = str[i];
46  for (int j = 0; j < 8; j++) {
47  bits.push_back((ch & 1) != 0 ? RTLIL::S1 : RTLIL::S0);
48  ch = ch >> 1;
49  }
50  }
51 }
int flags
Definition: rtlil.h:437
std::vector< RTLIL::State > bits
Definition: rtlil.h:438
RTLIL::Const::Const ( int  val,
int  width = 32 
)

Definition at line 53 of file rtlil.cc.

54 {
56  for (int i = 0; i < width; i++) {
57  bits.push_back((val & 1) != 0 ? RTLIL::S1 : RTLIL::S0);
58  val = val >> 1;
59  }
60 }
int flags
Definition: rtlil.h:437
std::vector< RTLIL::State > bits
Definition: rtlil.h:438
RTLIL::Const::Const ( RTLIL::State  bit,
int  width = 1 
)

Definition at line 62 of file rtlil.cc.

63 {
65  for (int i = 0; i < width; i++)
66  bits.push_back(bit);
67 }
int flags
Definition: rtlil.h:437
std::vector< RTLIL::State > bits
Definition: rtlil.h:438
RTLIL::Const::Const ( const std::vector< RTLIL::State > &  bits)
inline

Definition at line 444 of file rtlil.h.

444 : bits(bits) { flags = CONST_FLAG_NONE; };
int flags
Definition: rtlil.h:437
std::vector< RTLIL::State > bits
Definition: rtlil.h:438
RTLIL::Const::Const ( const std::vector< bool > &  bits)

Definition at line 69 of file rtlil.cc.

70 {
72  for (auto b : bits)
73  this->bits.push_back(b ? RTLIL::S1 : RTLIL::S0);
74 }
int flags
Definition: rtlil.h:437
std::vector< RTLIL::State > bits
Definition: rtlil.h:438

Member Function Documentation

bool RTLIL::Const::as_bool ( ) const

Definition at line 96 of file rtlil.cc.

97 {
98  for (size_t i = 0; i < bits.size(); i++)
99  if (bits[i] == RTLIL::S1)
100  return true;
101  return false;
102 }
std::vector< RTLIL::State > bits
Definition: rtlil.h:438

+ Here is the caller graph for this function:

int RTLIL::Const::as_int ( bool  is_signed = false) const

Definition at line 104 of file rtlil.cc.

105 {
106  int32_t ret = 0;
107  for (size_t i = 0; i < bits.size() && i < 32; i++)
108  if (bits[i] == RTLIL::S1)
109  ret |= 1 << i;
110  if (is_signed && bits.back() == RTLIL::S1)
111  for (size_t i = bits.size(); i < 32; i++)
112  ret |= 1 << i;
113  return ret;
114 }
std::vector< RTLIL::State > bits
Definition: rtlil.h:438

+ Here is the caller graph for this function:

std::string RTLIL::Const::as_string ( ) const

Definition at line 116 of file rtlil.cc.

117 {
118  std::string ret;
119  for (size_t i = bits.size(); i > 0; i--)
120  switch (bits[i-1]) {
121  case S0: ret += "0"; break;
122  case S1: ret += "1"; break;
123  case Sx: ret += "x"; break;
124  case Sz: ret += "z"; break;
125  case Sa: ret += "-"; break;
126  case Sm: ret += "m"; break;
127  }
128  return ret;
129 }
std::vector< RTLIL::State > bits
Definition: rtlil.h:438

+ Here is the caller graph for this function:

std::string RTLIL::Const::decode_string ( ) const

Definition at line 131 of file rtlil.cc.

132 {
133  std::string string;
134  std::vector <char> string_chars;
135  for (int i = 0; i < int (bits.size()); i += 8) {
136  char ch = 0;
137  for (int j = 0; j < 8 && i + j < int (bits.size()); j++)
138  if (bits[i + j] == RTLIL::State::S1)
139  ch |= 1 << j;
140  if (ch != 0)
141  string_chars.push_back(ch);
142  }
143  for (int i = int (string_chars.size()) - 1; i >= 0; i--)
144  string += string_chars[i];
145  return string;
146 }
std::vector< RTLIL::State > bits
Definition: rtlil.h:438

+ Here is the caller graph for this function:

bool RTLIL::Const::operator!= ( const RTLIL::Const other) const

Definition at line 91 of file rtlil.cc.

92 {
93  return bits != other.bits;
94 }
std::vector< RTLIL::State > bits
Definition: rtlil.h:438
bool RTLIL::Const::operator< ( const RTLIL::Const other) const

Definition at line 76 of file rtlil.cc.

77 {
78  if (bits.size() != other.bits.size())
79  return bits.size() < other.bits.size();
80  for (size_t i = 0; i < bits.size(); i++)
81  if (bits[i] != other.bits[i])
82  return bits[i] < other.bits[i];
83  return false;
84 }
std::vector< RTLIL::State > bits
Definition: rtlil.h:438
bool RTLIL::Const::operator== ( const RTLIL::Const other) const

Definition at line 86 of file rtlil.cc.

87 {
88  return bits == other.bits;
89 }
std::vector< RTLIL::State > bits
Definition: rtlil.h:438
int RTLIL::Const::size ( ) const
inline

Definition at line 457 of file rtlil.h.

457 { return bits.size(); }
std::vector< RTLIL::State > bits
Definition: rtlil.h:438

Field Documentation

std::vector<RTLIL::State> RTLIL::Const::bits

Definition at line 438 of file rtlil.h.

int RTLIL::Const::flags

Definition at line 437 of file rtlil.h.


The documentation for this struct was generated from the following files: