From c1da7661a5d4dc2669db77912a8f81fa8095f1fa Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Tue, 14 Jan 2014 18:56:29 +0100 Subject: [PATCH 1/4] Added "+" to list of liberty token characters --- passes/techmap/libparse.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/passes/techmap/libparse.cc b/passes/techmap/libparse.cc index 8fc03b5c9..2be3c586b 100644 --- a/passes/techmap/libparse.cc +++ b/passes/techmap/libparse.cc @@ -87,11 +87,11 @@ int LibertyParer::lexer(std::string &str) c = fgetc(f); } while (c == ' ' || c == '\t' || c == '\r'); - if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-' || c == '.') { + if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-' || c == '+' || c == '.') { str = c; while (1) { c = fgetc(f); - if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-' || c == '.') + if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-' || c == '+' || c == '.') str += c; else break; From 9a00980129268dee9ad3bc44468045164cff787a Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Tue, 14 Jan 2014 18:57:47 +0100 Subject: [PATCH 2/4] renamed LibertyParer to LibertyParser --- passes/techmap/dfflibmap.cc | 2 +- passes/techmap/libparse.cc | 10 +++++----- passes/techmap/libparse.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/passes/techmap/dfflibmap.cc b/passes/techmap/dfflibmap.cc index 40caf7801..23d93353f 100644 --- a/passes/techmap/dfflibmap.cc +++ b/passes/techmap/dfflibmap.cc @@ -470,7 +470,7 @@ struct DfflibmapPass : public Pass { FILE *f = fopen(liberty_file.c_str(), "r"); if (f == NULL) log_cmd_error("Can't open liberty file `%s': %s\n", liberty_file.c_str(), strerror(errno)); - LibertyParer libparser(f); + LibertyParser libparser(f); fclose(f); find_cell(libparser.ast, "$_DFF_N_", false, false, false, false); diff --git a/passes/techmap/libparse.cc b/passes/techmap/libparse.cc index 2be3c586b..8f4a1a5fa 100644 --- a/passes/techmap/libparse.cc +++ b/passes/techmap/libparse.cc @@ -79,7 +79,7 @@ void LibertyAst::dump(FILE *f, std::string indent, std::string path, bool path_o fprintf(f, " ;\n"); } -int LibertyParer::lexer(std::string &str) +int LibertyParser::lexer(std::string &str) { int c; @@ -154,7 +154,7 @@ int LibertyParer::lexer(std::string &str) return c; } -LibertyAst *LibertyParer::parse() +LibertyAst *LibertyParser::parse() { std::string str; @@ -219,14 +219,14 @@ LibertyAst *LibertyParer::parse() #ifndef FILTERLIB -void LibertyParer::error() +void LibertyParser::error() { log_error("Syntax error in line %d.\n", line); } #else -void LibertyParer::error() +void LibertyParser::error() { fprintf(stderr, "Syntax error in line %d.\n", line); exit(1); @@ -611,7 +611,7 @@ int main(int argc, char **argv) } } - LibertyParer parser(f); + LibertyParser parser(f); if (parser.ast) { if (flag_verilogsim) gen_verilogsim(parser.ast); diff --git a/passes/techmap/libparse.h b/passes/techmap/libparse.h index 8c4a2f5ca..eff268bbb 100644 --- a/passes/techmap/libparse.h +++ b/passes/techmap/libparse.h @@ -39,13 +39,13 @@ namespace PASS_DFFLIBMAP static std::set whitelist; }; - struct LibertyParer + struct LibertyParser { FILE *f; int line; LibertyAst *ast; - LibertyParer(FILE *f) : f(f), line(1), ast(parse()) {} - ~LibertyParer() { if (ast) delete ast; } + LibertyParser(FILE *f) : f(f), line(1), ast(parse()) {} + ~LibertyParser() { if (ast) delete ast; } int lexer(std::string &str); LibertyAst *parse(); void error(); From 0c5b1f32d49540b8cbbfbd610e9dca82d75a7893 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Tue, 14 Jan 2014 19:28:20 +0100 Subject: [PATCH 3/4] Added hierarchy -libdir option --- passes/hierarchy/hierarchy.cc | 52 ++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/passes/hierarchy/hierarchy.cc b/passes/hierarchy/hierarchy.cc index d46757029..f77ded9d2 100644 --- a/passes/hierarchy/hierarchy.cc +++ b/passes/hierarchy/hierarchy.cc @@ -133,22 +133,56 @@ static void generate(RTLIL::Design *design, const std::vector &cell } } -static bool expand_module(RTLIL::Design *design, RTLIL::Module *module, bool flag_check) +static bool expand_module(RTLIL::Design *design, RTLIL::Module *module, bool flag_check, std::vector &libdirs) { bool did_something = false; + std::string filename; - for (auto &cell_it : module->cells) { + for (auto &cell_it : module->cells) + { RTLIL::Cell *cell = cell_it.second; - if (design->modules.count(cell->type) == 0) { + + if (design->modules.count(cell->type) == 0) + { + if (cell->type[0] == '$') + continue; + + for (auto &dir : libdirs) + { + filename = dir + "/" + RTLIL::unescape_id(cell->type) + ".v"; + if (access(filename.c_str(), F_OK) == 0) { + std::vector args; + args.push_back(filename); + Frontend::frontend_call(design, NULL, filename, "verilog"); + goto loaded_module; + } + + filename = dir + "/" + RTLIL::unescape_id(cell->type) + ".il"; + if (access(filename.c_str(), F_OK) == 0) { + std::vector args; + args.push_back(filename); + Frontend::frontend_call(design, NULL, filename, "ilang"); + goto loaded_module; + } + } + if (flag_check && cell->type[0] != '$') log_error("Module `%s' referenced in module `%s' in cell `%s' is not part of the design.\n", cell->type.c_str(), module->name.c_str(), cell->name.c_str()); continue; + + loaded_module: + if (design->modules.count(cell->type) == 0) + log_error("File `%s' from libdir does not declare module `%s'.\n", filename.c_str(), cell->type.c_str()); + did_something = true; } + if (cell->parameters.size() == 0) continue; + if (design->modules.at(cell->type)->get_bool_attribute("\\blackbox")) continue; + RTLIL::Module *mod = design->modules[cell->type]; cell->type = mod->derive(design, cell->parameters); cell->parameters.clear(); @@ -212,6 +246,11 @@ struct HierarchyPass : public Pass { log(" also check the design hierarchy. this generates an error when\n"); log(" an unknown module is used as cell type.\n"); log("\n"); + log(" -libdir \n"); + log(" search for files named .v in the specified directory\n"); + log(" for unkown modules and automatically run read_verilog for each\n"); + log(" unknown module.\n"); + log("\n"); log(" -keep_positionals\n"); log(" per default this pass also converts positional arguments in cells\n"); log(" to arguments using port names. this option disables this behavior.\n"); @@ -247,6 +286,7 @@ struct HierarchyPass : public Pass { bool flag_check = false; RTLIL::Module *top_mod = NULL; + std::vector libdirs; bool generate_mode = false; bool keep_positionals = false; @@ -303,6 +343,10 @@ struct HierarchyPass : public Pass { keep_positionals = true; continue; } + if (args[argidx] == "-libdir" && argidx+1 < args.size()) { + libdirs.push_back(args[++argidx]); + continue; + } if (args[argidx] == "-top") { if (++argidx >= args.size()) log_cmd_error("Option -top requires an additional argument!\n"); @@ -344,7 +388,7 @@ struct HierarchyPass : public Pass { for (auto &modname : modnames) { if (design->modules.count(modname) == 0) continue; - if (expand_module(design, design->modules[modname], flag_check)) + if (expand_module(design, design->modules[modname], flag_check, libdirs)) did_something = true; } if (did_something) From aa17f16fecbdb758c50d45e500e03b4fbf177186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schm=C3=B6lzer?= Date: Tue, 14 Jan 2014 20:12:45 +0100 Subject: [PATCH 4/4] Include unistd.h in passes/hierarchy/hierarchy.cc (required for access(3)) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes compilation errors on Arch Linux. Signed-off-by: Martin Schmölzer --- passes/hierarchy/hierarchy.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/passes/hierarchy/hierarchy.cc b/passes/hierarchy/hierarchy.cc index f77ded9d2..01e287e94 100644 --- a/passes/hierarchy/hierarchy.cc +++ b/passes/hierarchy/hierarchy.cc @@ -23,6 +23,7 @@ #include #include #include +#include namespace { struct generate_port_decl_t {