yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ast.cc File Reference
#include "kernel/log.h"
#include "libs/sha1/sha1.h"
#include "ast.h"
#include <sstream>
#include <stdarg.h>
#include <math.h>
+ Include dependency graph for ast.cc:

Go to the source code of this file.

Namespaces

 AST
 
 AST_INTERNAL
 

Macros

#define X(_item)   case _item: return #_item;
 

Functions

static std::string id2vl (std::string txt)
 
static AstModuleprocess_module (AstNode *ast, bool defer)
 

Variables

std::string AST::current_filename
 
void(* AST::set_line_num )(int) = NULL
 
int(* AST::get_line_num )() = NULL
 
bool AST_INTERNAL::flag_dump_ast1
 
bool AST_INTERNAL::flag_dump_ast2
 
bool AST_INTERNAL::flag_dump_vlog
 
bool AST_INTERNAL::flag_nolatches
 
bool AST_INTERNAL::flag_nomem2reg
 
bool AST_INTERNAL::flag_mem2reg
 
bool AST_INTERNAL::flag_lib
 
bool AST_INTERNAL::flag_noopt
 
bool AST_INTERNAL::flag_icells
 
bool AST_INTERNAL::flag_autowire
 
AstNodeAST_INTERNAL::current_ast
 
AstNodeAST_INTERNAL::current_ast_mod
 
std::map< std::string, AstNode * > AST_INTERNAL::current_scope
 
const std::map< RTLIL::SigBit,
RTLIL::SigBit > * 
AST_INTERNAL::genRTLIL_subst_ptr = NULL
 
RTLIL::SigSpec AST_INTERNAL::ignoreThisSignalsInInitial
 
AstNodeAST_INTERNAL::current_top_block
 
AstNodeAST_INTERNAL::current_block
 
AstNodeAST_INTERNAL::current_block_child
 
AstModuleAST_INTERNAL::current_module
 

Macro Definition Documentation

#define X (   _item)    case _item: return #_item;

Function Documentation

static std::string id2vl ( std::string  txt)
static

Definition at line 311 of file ast.cc.

312 {
313  if (txt.size() > 1 && txt[0] == '\\')
314  txt = txt.substr(1);
315  for (size_t i = 0; i < txt.size(); i++) {
316  if ('A' <= txt[i] && txt[i] <= 'Z') continue;
317  if ('a' <= txt[i] && txt[i] <= 'z') continue;
318  if ('0' <= txt[i] && txt[i] <= '9') continue;
319  if (txt[i] == '_') continue;
320  txt = "\\" + txt + " ";
321  break;
322  }
323  return txt;
324 }

+ Here is the caller graph for this function:

static AstModule* process_module ( AstNode ast,
bool  defer 
)
static

Definition at line 873 of file ast.cc.

874 {
875  log_assert(ast->type == AST_MODULE);
876 
877  if (defer)
878  log("Storing AST representation for module `%s'.\n", ast->str.c_str());
879  else
880  log("Generating RTLIL representation for module `%s'.\n", ast->str.c_str());
881 
883  current_module->ast = NULL;
884  current_module->name = ast->str;
885  current_module->attributes["\\src"] = stringf("%s:%d", ast->filename.c_str(), ast->linenum);
886 
887  current_ast_mod = ast;
888  AstNode *ast_before_simplify = ast->clone();
889 
890  if (flag_dump_ast1) {
891  log("Dumping verilog AST before simplification:\n");
892  ast->dumpAst(NULL, " ");
893  log("--- END OF AST DUMP ---\n");
894  }
895 
896  if (!defer)
897  {
898  while (ast->simplify(!flag_noopt, false, false, 0, -1, false, false)) { }
899 
900  if (flag_dump_ast2) {
901  log("Dumping verilog AST after simplification:\n");
902  ast->dumpAst(NULL, " ");
903  log("--- END OF AST DUMP ---\n");
904  }
905 
906  if (flag_dump_vlog) {
907  log("Dumping verilog AST (as requested by dump_vlog option):\n");
908  ast->dumpVlog(NULL, " ");
909  log("--- END OF AST DUMP ---\n");
910  }
911 
912  if (flag_lib) {
913  std::vector<AstNode*> new_children;
914  for (auto child : ast->children) {
915  if (child->type == AST_WIRE && (child->is_input || child->is_output))
916  new_children.push_back(child);
917  else
918  delete child;
919  }
920  ast->children.swap(new_children);
921  ast->attributes["\\blackbox"] = AstNode::mkconst_int(1, false);
922  }
923 
925 
926  for (auto &attr : ast->attributes) {
927  if (attr.second->type != AST_CONSTANT)
928  log_error("Attribute `%s' with non-constant value at %s:%d!\n",
929  attr.first.c_str(), ast->filename.c_str(), ast->linenum);
930  current_module->attributes[attr.first] = attr.second->asAttrConst();
931  }
932  for (size_t i = 0; i < ast->children.size(); i++) {
933  AstNode *node = ast->children[i];
934  if (node->type == AST_WIRE || node->type == AST_MEMORY)
935  node->genRTLIL();
936  }
937  for (size_t i = 0; i < ast->children.size(); i++) {
938  AstNode *node = ast->children[i];
939  if (node->type != AST_WIRE && node->type != AST_MEMORY && node->type != AST_INITIAL)
940  node->genRTLIL();
941  }
942 
944 
945  for (size_t i = 0; i < ast->children.size(); i++) {
946  AstNode *node = ast->children[i];
947  if (node->type == AST_INITIAL)
948  node->genRTLIL();
949  }
950 
952  }
953 
954  current_module->ast = ast_before_simplify;
955  current_module->nolatches = flag_nolatches;
956  current_module->nomem2reg = flag_nomem2reg;
957  current_module->mem2reg = flag_mem2reg;
958  current_module->lib = flag_lib;
959  current_module->noopt = flag_noopt;
960  current_module->icells = flag_icells;
961  current_module->autowire = flag_autowire;
962  current_module->fixup_ports();
963  return current_module;
964 }
bool flag_lib
Definition: ast.cc:56
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
void dumpAst(FILE *f, std::string indent)
Definition: ast.cc:250
RTLIL::SigSpec genRTLIL(int width_hint=-1, bool sign_hint=false)
Definition: genrtlil.cc:762
std::map< RTLIL::IdString, AstNode * > attributes
Definition: ast.h:152
void dumpVlog(FILE *f, std::string indent)
Definition: ast.cc:327
bool flag_dump_ast1
Definition: ast.cc:56
void log_error(const char *format,...)
Definition: log.cc:204
RTLIL::SigSpec ignoreThisSignalsInInitial
Definition: ast.cc:60
bool flag_autowire
Definition: ast.cc:56
#define log_assert(_assert_expr_)
Definition: log.h:85
bool flag_dump_ast2
Definition: ast.cc:56
bool flag_noopt
Definition: ast.cc:56
AstNodeType type
Definition: ast.h:146
AstNode * ast
Definition: ast.h:268
void sort_and_unify()
Definition: rtlil.cc:2291
AstNode * clone()
Definition: ast.cc:208
#define NULL
bool simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage, int width_hint, bool sign_hint, bool in_param)
Definition: simplify.cc:50
std::string filename
Definition: ast.h:175
AstNode * current_ast_mod
Definition: ast.cc:57
void log(const char *format,...)
Definition: log.cc:180
std::string str
Definition: ast.h:156
bool flag_nolatches
Definition: ast.cc:56
std::vector< AstNode * > children
Definition: ast.h:149
bool flag_mem2reg
Definition: ast.cc:56
int linenum
Definition: ast.h:176
AstModule * current_module
Definition: ast.cc:62
bool flag_icells
Definition: ast.cc:56
bool flag_nomem2reg
Definition: ast.cc:56
bool flag_dump_vlog
Definition: ast.cc:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function: