mirror of https://github.com/YosysHQ/yosys.git
Remember global declarations and defines accross read_verilog calls
This commit is contained in:
parent
a2206180d6
commit
a926a6afc2
|
@ -1016,14 +1016,12 @@ void AST::process(RTLIL::Design *design, AstNode *ast, bool dump_ast1, bool dump
|
||||||
flag_icells = icells;
|
flag_icells = icells;
|
||||||
flag_autowire = autowire;
|
flag_autowire = autowire;
|
||||||
|
|
||||||
std::vector<AstNode*> global_decls;
|
|
||||||
|
|
||||||
log_assert(current_ast->type == AST_DESIGN);
|
log_assert(current_ast->type == AST_DESIGN);
|
||||||
for (auto it = current_ast->children.begin(); it != current_ast->children.end(); it++)
|
for (auto it = current_ast->children.begin(); it != current_ast->children.end(); it++)
|
||||||
{
|
{
|
||||||
if ((*it)->type == AST_MODULE)
|
if ((*it)->type == AST_MODULE)
|
||||||
{
|
{
|
||||||
for (auto n : global_decls)
|
for (auto n : design->verilog_globals)
|
||||||
(*it)->children.push_back(n->clone());
|
(*it)->children.push_back(n->clone());
|
||||||
|
|
||||||
for (auto n : design->verilog_packages){
|
for (auto n : design->verilog_packages){
|
||||||
|
@ -1054,7 +1052,7 @@ void AST::process(RTLIL::Design *design, AstNode *ast, bool dump_ast1, bool dump
|
||||||
else if ((*it)->type == AST_PACKAGE)
|
else if ((*it)->type == AST_PACKAGE)
|
||||||
design->verilog_packages.push_back((*it)->clone());
|
design->verilog_packages.push_back((*it)->clone());
|
||||||
else
|
else
|
||||||
global_decls.push_back(*it);
|
design->verilog_globals.push_back((*it)->clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,8 @@ static void input_file(std::istream &f, std::string filename)
|
||||||
input_buffer.insert(it, "\n`file_pop\n");
|
input_buffer.insert(it, "\n`file_pop\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string frontend_verilog_preproc(std::istream &f, std::string filename, const std::map<std::string, std::string> pre_defines_map, const std::list<std::string> include_dirs)
|
std::string frontend_verilog_preproc(std::istream &f, std::string filename, const std::map<std::string, std::string> &pre_defines_map,
|
||||||
|
dict<std::string, std::pair<std::string, bool>> &global_defines_cache, const std::list<std::string> &include_dirs)
|
||||||
{
|
{
|
||||||
std::set<std::string> defines_with_args;
|
std::set<std::string> defines_with_args;
|
||||||
std::map<std::string, std::string> defines_map(pre_defines_map);
|
std::map<std::string, std::string> defines_map(pre_defines_map);
|
||||||
|
@ -222,9 +223,19 @@ std::string frontend_verilog_preproc(std::istream &f, std::string filename, cons
|
||||||
input_buffer_charp = 0;
|
input_buffer_charp = 0;
|
||||||
|
|
||||||
input_file(f, filename);
|
input_file(f, filename);
|
||||||
|
|
||||||
defines_map["YOSYS"] = "1";
|
defines_map["YOSYS"] = "1";
|
||||||
defines_map[formal_mode ? "FORMAL" : "SYNTHESIS"] = "1";
|
defines_map[formal_mode ? "FORMAL" : "SYNTHESIS"] = "1";
|
||||||
|
|
||||||
|
for (auto &it : pre_defines_map)
|
||||||
|
defines_map[it.first] = it.second;
|
||||||
|
|
||||||
|
for (auto &it : global_defines_cache) {
|
||||||
|
if (it.second.second)
|
||||||
|
defines_with_args.insert(it.first);
|
||||||
|
defines_map[it.first] = it.second.first;
|
||||||
|
}
|
||||||
|
|
||||||
while (!input_buffer.empty())
|
while (!input_buffer.empty())
|
||||||
{
|
{
|
||||||
std::string tok = next_token();
|
std::string tok = next_token();
|
||||||
|
@ -379,6 +390,7 @@ std::string frontend_verilog_preproc(std::istream &f, std::string filename, cons
|
||||||
defines_with_args.insert(name);
|
defines_with_args.insert(name);
|
||||||
else
|
else
|
||||||
defines_with_args.erase(name);
|
defines_with_args.erase(name);
|
||||||
|
global_defines_cache[name] = std::pair<std::string, bool>(value, state == 2);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,6 +401,7 @@ std::string frontend_verilog_preproc(std::istream &f, std::string filename, cons
|
||||||
// printf("undef: >>%s<<\n", name.c_str());
|
// printf("undef: >>%s<<\n", name.c_str());
|
||||||
defines_map.erase(name);
|
defines_map.erase(name);
|
||||||
defines_with_args.erase(name);
|
defines_with_args.erase(name);
|
||||||
|
global_defines_cache.erase(name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -345,7 +345,7 @@ struct VerilogFrontend : public Frontend {
|
||||||
std::string code_after_preproc;
|
std::string code_after_preproc;
|
||||||
|
|
||||||
if (!flag_nopp) {
|
if (!flag_nopp) {
|
||||||
code_after_preproc = frontend_verilog_preproc(*f, filename, defines_map, include_dirs);
|
code_after_preproc = frontend_verilog_preproc(*f, filename, defines_map, design->verilog_defines, include_dirs);
|
||||||
if (flag_ppdump)
|
if (flag_ppdump)
|
||||||
log("-- Verilog code after preprocessor --\n%s-- END OF DUMP --\n", code_after_preproc.c_str());
|
log("-- Verilog code after preprocessor --\n%s-- END OF DUMP --\n", code_after_preproc.c_str());
|
||||||
lexin = new std::istringstream(code_after_preproc);
|
lexin = new std::istringstream(code_after_preproc);
|
||||||
|
|
|
@ -68,7 +68,8 @@ namespace VERILOG_FRONTEND
|
||||||
}
|
}
|
||||||
|
|
||||||
// the pre-processor
|
// the pre-processor
|
||||||
std::string frontend_verilog_preproc(std::istream &f, std::string filename, const std::map<std::string, std::string> pre_defines_map, const std::list<std::string> include_dirs);
|
std::string frontend_verilog_preproc(std::istream &f, std::string filename, const std::map<std::string, std::string> &pre_defines_map,
|
||||||
|
dict<std::string, std::pair<std::string, bool>> &global_defines_cache, const std::list<std::string> &include_dirs);
|
||||||
|
|
||||||
YOSYS_NAMESPACE_END
|
YOSYS_NAMESPACE_END
|
||||||
|
|
||||||
|
|
|
@ -306,6 +306,8 @@ RTLIL::Design::~Design()
|
||||||
delete it->second;
|
delete it->second;
|
||||||
for (auto n : verilog_packages)
|
for (auto n : verilog_packages)
|
||||||
delete n;
|
delete n;
|
||||||
|
for (auto n : verilog_globals)
|
||||||
|
delete n;
|
||||||
}
|
}
|
||||||
|
|
||||||
RTLIL::ObjRange<RTLIL::Module*> RTLIL::Design::modules()
|
RTLIL::ObjRange<RTLIL::Module*> RTLIL::Design::modules()
|
||||||
|
|
|
@ -793,7 +793,8 @@ struct RTLIL::Design
|
||||||
|
|
||||||
int refcount_modules_;
|
int refcount_modules_;
|
||||||
dict<RTLIL::IdString, RTLIL::Module*> modules_;
|
dict<RTLIL::IdString, RTLIL::Module*> modules_;
|
||||||
std::vector<AST::AstNode*> verilog_packages;
|
std::vector<AST::AstNode*> verilog_packages, verilog_globals;
|
||||||
|
dict<std::string, std::pair<std::string, bool>> verilog_defines;
|
||||||
|
|
||||||
std::vector<RTLIL::Selection> selection_stack;
|
std::vector<RTLIL::Selection> selection_stack;
|
||||||
dict<RTLIL::IdString, RTLIL::Selection> selection_vars;
|
dict<RTLIL::IdString, RTLIL::Selection> selection_vars;
|
||||||
|
|
Loading…
Reference in New Issue