yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
VERILOG_FRONTEND Namespace Reference

Functions

AST::AstNodeconst2ast (std::string code, char case_type=0, bool warn_z=false)
 

Variables

struct AST::AstNodecurrent_ast
 
bool default_nettype_wire
 
bool sv_mode
 
std::istream * lexin
 
std::vector< std::string > fn_stack
 
std::vector< int > ln_stack
 
int port_counter
 
std::map< std::string, int > port_stubs
 
std::map< std::string, AstNode * > attr_list
 
std::map< std::string, AstNode * > default_attr_list
 
std::map< std::string, AstNode * > * albuf
 
std::vector< AstNode * > ast_stack
 
struct AstNodeastbuf1
 
struct AstNodeastbuf2
 
struct AstNodeastbuf3
 
struct AstNodecurrent_function_or_task
 
struct AstNodecurrent_ast_mod
 
int current_function_or_task_port_id
 
std::vector< char > case_type_stack
 
bool do_not_require_port_stubs
 

Function Documentation

AstNode * VERILOG_FRONTEND::const2ast ( std::string  code,
char  case_type = 0,
bool  warn_z = false 
)

Definition at line 135 of file const2ast.cc.

136 {
137  if (warn_z) {
138  AstNode *ret = const2ast(code, case_type);
139  if (std::find(ret->bits.begin(), ret->bits.end(), RTLIL::State::Sz) != ret->bits.end())
140  log_warning("Yosys does not support tri-state logic at the moment. (%s:%d)\n",
142  return ret;
143  }
144 
145  const char *str = code.c_str();
146 
147  // Strings
148  if (*str == '"') {
149  int len = strlen(str) - 2;
150  std::vector<RTLIL::State> data;
151  data.reserve(len * 8);
152  for (int i = 0; i < len; i++) {
153  unsigned char ch = str[len - i];
154  for (int j = 0; j < 8; j++) {
155  data.push_back((ch & 1) ? RTLIL::S1 : RTLIL::S0);
156  ch = ch >> 1;
157  }
158  }
159  AstNode *ast = AstNode::mkconst_bits(data, false);
160  ast->str = code;
161  return ast;
162  }
163 
164  for (size_t i = 0; i < code.size(); i++)
165  if (code[i] == '_' || code[i] == ' ' || code[i] == '\t' || code[i] == '\r' || code[i] == '\n')
166  code.erase(code.begin()+(i--));
167  str = code.c_str();
168 
169  char *endptr;
170  long len_in_bits = strtol(str, &endptr, 10);
171 
172  // Simple base-10 integer
173  if (*endptr == 0) {
174  std::vector<RTLIL::State> data;
175  my_strtobin(data, str, -1, 10, case_type);
176  if (data.back() == RTLIL::S1)
177  data.push_back(RTLIL::S0);
178  return AstNode::mkconst_bits(data, true);
179  }
180 
181  // unsized constant
182  if (str == endptr)
183  len_in_bits = -1;
184 
185  // The "<bits>'s?[bodhBODH]<digits>" syntax
186  if (*endptr == '\'')
187  {
188  std::vector<RTLIL::State> data;
189  bool is_signed = false;
190  if (*(endptr+1) == 's') {
191  is_signed = true;
192  endptr++;
193  }
194  switch (*(endptr+1))
195  {
196  case 'b':
197  case 'B':
198  my_strtobin(data, endptr+2, len_in_bits, 2, case_type);
199  break;
200  case 'o':
201  case 'O':
202  my_strtobin(data, endptr+2, len_in_bits, 8, case_type);
203  break;
204  case 'd':
205  case 'D':
206  my_strtobin(data, endptr+2, len_in_bits, 10, case_type);
207  break;
208  case 'h':
209  case 'H':
210  my_strtobin(data, endptr+2, len_in_bits, 16, case_type);
211  break;
212  default:
213  return NULL;
214  }
215  if (len_in_bits < 0) {
216  if (is_signed && data.back() == RTLIL::S1)
217  data.push_back(RTLIL::S0);
218  while (data.size() < 32)
219  data.push_back(RTLIL::S0);
220  }
221  return AstNode::mkconst_bits(data, is_signed);
222  }
223 
224  return NULL;
225 }
void log_warning(const char *format,...)
Definition: log.cc:196
int frontend_verilog_yyget_lineno(void)
std::string current_filename
Definition: ast.cc:49
#define NULL
std::string str
Definition: ast.h:156
AST::AstNode * const2ast(std::string code, char case_type=0, bool warn_z=false)
Definition: const2ast.cc:135
static bool find(V &ts, const T &t)
Definition: Alg.h:47
std::vector< RTLIL::State > bits
Definition: ast.h:157
static void my_strtobin(std::vector< RTLIL::State > &data, const char *str, int len_in_bits, int base, char case_type)
Definition: const2ast.cc:73

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

std::map<std::string, AstNode*>* VERILOG_FRONTEND::albuf

Definition at line 89 of file verilog_parser.tab.cc.

std::vector<AstNode*> VERILOG_FRONTEND::ast_stack

Definition at line 90 of file verilog_parser.tab.cc.

struct AstNode* VERILOG_FRONTEND::astbuf1

Definition at line 91 of file verilog_parser.tab.cc.

struct AstNode * VERILOG_FRONTEND::astbuf2

Definition at line 91 of file verilog_parser.tab.cc.

struct AstNode * VERILOG_FRONTEND::astbuf3

Definition at line 91 of file verilog_parser.tab.cc.

std::map<std::string, AstNode*> VERILOG_FRONTEND::attr_list

Definition at line 88 of file verilog_parser.tab.cc.

std::vector<char> VERILOG_FRONTEND::case_type_stack

Definition at line 95 of file verilog_parser.tab.cc.

struct AstNode * VERILOG_FRONTEND::current_ast

Definition at line 93 of file verilog_parser.tab.cc.

struct AstNode * VERILOG_FRONTEND::current_ast_mod

Definition at line 93 of file verilog_parser.tab.cc.

struct AstNode* VERILOG_FRONTEND::current_function_or_task

Definition at line 92 of file verilog_parser.tab.cc.

int VERILOG_FRONTEND::current_function_or_task_port_id

Definition at line 94 of file verilog_parser.tab.cc.

std::map<std::string, AstNode*> VERILOG_FRONTEND::default_attr_list

Definition at line 88 of file verilog_parser.tab.cc.

bool VERILOG_FRONTEND::default_nettype_wire

Definition at line 97 of file verilog_parser.tab.cc.

bool VERILOG_FRONTEND::do_not_require_port_stubs

Definition at line 96 of file verilog_parser.tab.cc.

std::vector<std::string> VERILOG_FRONTEND::fn_stack

Definition at line 998 of file verilog_lexer.cc.

std::istream * VERILOG_FRONTEND::lexin

Definition at line 99 of file verilog_parser.tab.cc.

std::vector<int> VERILOG_FRONTEND::ln_stack

Definition at line 999 of file verilog_lexer.cc.

int VERILOG_FRONTEND::port_counter

Definition at line 86 of file verilog_parser.tab.cc.

std::map<std::string, int> VERILOG_FRONTEND::port_stubs

Definition at line 87 of file verilog_parser.tab.cc.

bool VERILOG_FRONTEND::sv_mode

Definition at line 98 of file verilog_parser.tab.cc.