Skip to content

Commit d036e0f

Browse files
authored
Merge pull request #2159 from verilog-to-routing/yosys_odin_sv_bug
Fixing a bug in receiving .sv extensions without Yosys plugins installed
2 parents 33c518f + 5e2559f commit d036e0f

File tree

4 files changed

+62
-82
lines changed

4 files changed

+62
-82
lines changed

ODIN_II/SRC/include/odin_error.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,29 @@ extern std::vector<std::pair<std::string, int>> include_file_names;
3939
extern int delayed_errors;
4040
extern const loc_t unknown_location;
4141

42-
#ifdef ODIN_USE_YOSYS
42+
#define SYSTEMVERILOG_PARSER_ERROR \
43+
"The SystemVerilog parser is provided within Yosys. " \
44+
"Please use the Yosys elaborator to synthesize SystemVerilog files.\n"
45+
#define UHDM_PARSER_ERROR \
46+
"The UHDM parser is provided within Yosys. " \
47+
"Please use the Yosys elaborator to synthesize UHDM files.\n"
48+
49+
#ifndef ODIN_USE_YOSYS
50+
# define YOSYS_INSTALLATION_ERROR \
51+
"It seems Yosys is not installed in the VTR repository. " \
52+
"Please compile the VTR with (\" -DODIN_USE_YOSYS=ON \") flag.\n"
53+
#else
4354
# define YOSYS_ELABORATION_ERROR \
4455
"Yosys failed to perform elaboration, " \
4556
"Please look at the log file for the failure cause or pass \'--show_yosys_log\' to Odin-II to see the logs.\n"
4657
# define YOSYS_FORK_ERROR \
4758
"Yosys child process failed to be created\n"
48-
# define YOSYS_PLUGINS_WITH_ODIN_ERROR \
49-
"Utilizing SystemVerilog/UHDM plugins requires activating the Yosys frontend.\
50-
Please recompile the VTR project either with the \"WITH_YOSYS\" or \"ODIN_USE_YOSYS\" flag on."
51-
#else
52-
# define YOSYS_INSTALLATION_ERROR \
53-
"It seems Yosys is not installed in the VTR repository." \
54-
" Please compile the VTR with (\" -DODIN_USE_YOSYS=ON \") flag.\n"
5559
#endif
5660

5761
#ifndef YOSYS_SV_UHDM_PLUGIN
58-
# define YOSYS_PLUGINS_NOT_COMPILED \
59-
"SystemVerilog/UHDM plugins are not compiled.\
60-
Please recompile the VTR project with the \"YOSYS_SV_UHDM_PLUGIN\" flag on."
62+
# define YOSYS_PLUGINS_NOT_COMPILED \
63+
"SystemVerilog/UHDM plugins are not compiled. " \
64+
"Please recompile the VTR project with the \"YOSYS_SV_UHDM_PLUGIN\" flag on."
6165
#endif
6266

6367
// causes an interrupt in GDB

ODIN_II/SRC/include/odin_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ long shift_left_value_with_overflow_check(long input_value, long shift_by, loc_t
1212
std::string get_file_extension(std::string input_file);
1313
std::string get_directory(std::string input_file);
1414
void create_directory(std::string path);
15-
void assert_valid_file_extenstion(std::vector<std::string> name_list, file_type_e type);
15+
void report_frontend_elaborator();
1616
void assert_supported_file_extension(std::string input_file, loc_t loc);
1717
FILE* open_file(const char* file_name, const char* open_type);
1818
void get_current_path();

ODIN_II/SRC/odin_ii.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ netlist_t* start_odin_ii(int argc, char** argv) {
349349
ODIN_ERROR_CODE error_code;
350350

351351
print_input_files_info();
352-
assert_valid_file_extenstion(configuration.list_of_file_names, configuration.input_file_type);
352+
report_frontend_elaborator();
353353

354354
if (configuration.input_file_type != file_type_e::_BLIF || configuration.coarsen) {
355355
try {

ODIN_II/SRC/odin_util.cpp

Lines changed: 45 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -92,80 +92,56 @@ void create_directory(std::string path) {
9292
}
9393

9494
/**
95-
* @brief assert all input files have valid type and extenstion
96-
*
97-
* @param name_list list of input files
98-
* @param type the type to be checked with
95+
* @brief report the frontend elaborator and its parser
9996
*/
100-
void assert_valid_file_extenstion(std::vector<std::string> name_list, file_type_e type) {
101-
for (auto file_name : name_list) {
102-
// lookup the file type string from file extension map
103-
auto file_ext_str = string_to_lower(get_file_extension(file_name));
104-
auto file_ext_it = file_extension_strmap.find(file_ext_str);
105-
106-
// Unsupported file types should be already check.
107-
// However, we double-check here
108-
if (file_ext_it == file_extension_strmap.end()) {
109-
assert_supported_file_extension(file_name, unknown_location);
110-
} else {
111-
file_type_e file_type = file_ext_it->second;
112-
// Check if the file_name extension matches with type
113-
switch (type) {
114-
case (file_type_e::_VERILOG): // fallthrough
115-
case (file_type_e::_VERILOG_HEADER): {
116-
if (file_type != file_type_e::_VERILOG && file_type != file_type_e::_VERILOG_HEADER)
117-
error_message(UTIL, unknown_location,
118-
"File (%s) has an invalid extension (%s), supposed to be a %s or %s file { %s, %s },\
119-
please see ./odin --help",
120-
file_name.c_str(),
121-
file_ext_str.c_str(),
122-
file_type_strmap.find(file_type_e::_VERILOG)->second.c_str(),
123-
file_type_strmap.find(file_type_e::_VERILOG_HEADER)->second.c_str(),
124-
file_extension_strmap.find(file_type_e::_VERILOG)->second.c_str(),
125-
file_extension_strmap.find(file_type_e::_VERILOG_HEADER)->second.c_str());
126-
break;
127-
}
128-
case (file_type_e::_SYSTEM_VERILOG): //fallthrough
129-
case (file_type_e::_UHDM): {
130-
if (configuration.elaborator_type != elaborator_e::_YOSYS) {
131-
#ifndef ODIN_USE_YOSYS
132-
error_message(PARSE_ARGS, unknown_location, "%s", YOSYS_INSTALLATION_ERROR);
97+
void report_frontend_elaborator() {
98+
// Check if the file_name extension matches with type
99+
switch (configuration.input_file_type) {
100+
case (file_type_e::_VERILOG): // fallthrough
101+
case (file_type_e::_VERILOG_HEADER): {
102+
if (configuration.elaborator_type == elaborator_e::_ODIN) {
103+
printf("Using the ODIN_II parser for elaboration\n");
104+
} else if (configuration.elaborator_type == elaborator_e::_YOSYS) {
105+
printf("Using the Yosys elaborator with it's conventional Verilog/SystemVerilog parser\n");
106+
}
107+
break;
108+
}
109+
case (file_type_e::_SYSTEM_VERILOG): {
110+
if (configuration.elaborator_type != elaborator_e::_YOSYS) {
111+
error_message(PARSE_ARGS, unknown_location, "%s", SYSTEMVERILOG_PARSER_ERROR);
112+
}
113+
#ifndef YOSYS_SV_UHDM_PLUGIN
114+
printf("Using the Yosys elaborator with it's conventional Verilog/SystemVerilog parser\n");
133115
#else
134-
error_message(UTIL, unknown_location, "%s", YOSYS_PLUGINS_WITH_ODIN_ERROR);
116+
printf("Using the Yosys elaborator with the Yosys-F4PGA-Plugin parser for SystemVerilog\n");
135117
#endif
136-
} else {
137-
#ifndef YOSYS_SV_UHDM_PLUGIN
138-
error_message(UTIL, unknown_location, "%s", YOSYS_PLUGINS_NOT_COMPILED);
118+
break;
119+
}
120+
case (file_type_e::_UHDM): {
121+
if (configuration.elaborator_type != elaborator_e::_YOSYS) {
122+
error_message(PARSE_ARGS, unknown_location, "%s", UHDM_PARSER_ERROR);
123+
124+
} else if (configuration.elaborator_type == elaborator_e::_YOSYS) {
125+
#ifndef ODIN_USE_YOSYS
126+
error_message(PARSE_ARGS, unknown_location, "%s", YOSYS_INSTALLATION_ERROR);
127+
#else
128+
# ifndef YOSYS_SV_UHDM_PLUGIN
129+
error_message(PARSE_ARGS, unknown_location, "%s", YOSYS_PLUGINS_NOT_COMPILED);
130+
# endif
139131
#endif
140-
}
141-
if (file_type != type && type != file_type_e::_UHDM)
142-
error_message(UTIL, unknown_location,
143-
"File (%s) has an invalid extension (%s), supposed to be a %s file { %s },\
144-
please see ./odin --help",
145-
file_name.c_str(),
146-
file_ext_str.c_str(),
147-
file_type_strmap.find(type)->second.c_str(),
148-
file_extension_strmap.find(type)->second.c_str());
149-
break;
150-
}
151-
case (file_type_e::_BLIF): {
152-
if (file_type != type)
153-
error_message(UTIL, unknown_location,
154-
"File (%s) has an invalid extension (%s), supposed to be a %s file { %s },\
155-
please see ./odin --help",
156-
file_name.c_str(),
157-
file_ext_str.c_str(),
158-
file_type_strmap.find(type)->second.c_str(),
159-
file_extension_strmap.find(type)->second.c_str());
160-
break;
161-
}
162-
case (file_type_e::_EBLIF): //fallthrough
163-
case (file_type_e::_ILANG): // fallthrough
164-
default: {
165-
assert_supported_file_extension(file_name, unknown_location);
166-
break;
167-
}
168132
}
133+
printf("Using the Yosys elaborator with the Surelog parser for UHDM\n");
134+
break;
135+
}
136+
case (file_type_e::_BLIF): {
137+
printf("Using the ODIN_II BLIF parser\n");
138+
break;
139+
}
140+
case (file_type_e::_EBLIF): //fallthrough
141+
case (file_type_e::_ILANG): //fallthrough
142+
default: {
143+
error_message(UTIL, unknown_location, "%s", "Invalid file type");
144+
break;
169145
}
170146
}
171147
}

0 commit comments

Comments
 (0)