Skip to content

Commit 23ef186

Browse files
committed
sdc: Extract and add SDC file name and line number to error messages
Signed-off-by: Tomasz Michalak <[email protected]>
1 parent c7aa6cb commit 23ef186

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

sdc-plugin/sdc.cc

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ USING_YOSYS_NAMESPACE
3333
PRIVATE_NAMESPACE_BEGIN
3434

3535
struct ReadSdcCmd : public Frontend {
36-
ReadSdcCmd() : Frontend("sdc", "Read SDC file") {}
36+
ReadSdcCmd(std::string &file_name, size_t &line_number) : Frontend("sdc", "Read SDC file"), file_name(file_name), line_number(line_number) {}
37+
38+
std::string &file_name;
39+
size_t &line_number;
3740

3841
void help() override
3942
{
@@ -52,11 +55,16 @@ struct ReadSdcCmd : public Frontend {
5255
log("\nReading clock constraints file(SDC)\n\n");
5356
size_t argidx = 1;
5457
extra_args(f, filename, args, argidx);
55-
std::string content{std::istreambuf_iterator<char>(*f), std::istreambuf_iterator<char>()};
56-
log("%s\n", content.c_str());
58+
file_name = filename;
59+
line_number = 0;
5760
Tcl_Interp *interp = yosys_get_tcl_interp();
58-
if (Tcl_EvalFile(interp, args[argidx].c_str()) != TCL_OK) {
59-
log_cmd_error("TCL interpreter returned an error: %s\n", Tcl_GetStringResult(interp));
61+
while (!f->eof()) {
62+
std::string line;
63+
std::getline(*f, line);
64+
line_number++;
65+
if (Tcl_Eval(interp, line.c_str()) != TCL_OK) {
66+
log_cmd_error("TCL interpreter returned an error: %s\n", Tcl_GetStringResult(interp));
67+
}
6068
}
6169
}
6270
};
@@ -100,7 +108,13 @@ struct WriteSdcCmd : public Backend {
100108
};
101109

102110
struct CreateClockCmd : public Pass {
103-
CreateClockCmd() : Pass("create_clock", "Create clock object") {}
111+
CreateClockCmd(const std::string &file_name, size_t &line_number)
112+
: Pass("create_clock", "Create clock object"), file_name(file_name), line_number(line_number)
113+
{
114+
}
115+
116+
const std::string &file_name;
117+
const size_t &line_number;
104118

105119
void help() override
106120
{
@@ -127,7 +141,7 @@ struct CreateClockCmd : public Pass {
127141
float falling_edge(0);
128142
float period(0);
129143
if (args.size() < 4) {
130-
log_file_error(__FILE__, __LINE__, "%s: Found only %ld arguments, but a minimum of 3 are required.\n", pass_name.c_str(),
144+
log_file_error(file_name, line_number, "%s: Found only %ld arguments, but a minimum of 3 are required.\n", pass_name.c_str(),
131145
args.size() - 1);
132146
}
133147
for (argidx = 1; argidx < args.size(); argidx++) {
@@ -151,10 +165,10 @@ struct CreateClockCmd : public Pass {
151165
break;
152166
}
153167
if (argidx == args.size()) {
154-
log_file_error(__FILE__, __LINE__, "%s: No target signal was provided.\n", pass_name.c_str());
168+
log_file_error(file_name, line_number, "%s: No target signal was provided.\n", pass_name.c_str());
155169
}
156170
if (period <= 0) {
157-
log_file_error(__FILE__, __LINE__, "%s: Found non-positive period value of %f, periods must be positive and greater than zero.\n",
171+
log_file_error(file_name, line_number, "%s: Found non-positive period value of %f, periods must be positive and greater than zero.\n",
158172
pass_name.c_str(), period);
159173
}
160174
if (!is_waveform_specified) {
@@ -336,7 +350,9 @@ struct PropagateClocksCmd : public Pass {
336350
class SdcPlugin
337351
{
338352
public:
339-
SdcPlugin() : write_sdc_cmd_(sdc_writer_), set_false_path_cmd_(sdc_writer_), set_max_delay_cmd_(sdc_writer_), set_clock_groups_cmd_(sdc_writer_)
353+
SdcPlugin()
354+
: read_sdc_cmd_(file_name, line_number), write_sdc_cmd_(sdc_writer_), create_clock_cmd_(file_name, line_number),
355+
set_false_path_cmd_(sdc_writer_), set_max_delay_cmd_(sdc_writer_), set_clock_groups_cmd_(sdc_writer_)
340356
{
341357
log("Loaded SDC plugin\n");
342358
}
@@ -350,6 +366,9 @@ class SdcPlugin
350366
SetMaxDelay set_max_delay_cmd_;
351367
SetClockGroups set_clock_groups_cmd_;
352368

369+
std::string file_name;
370+
size_t line_number;
371+
353372
private:
354373
SdcWriter sdc_writer_;
355374
} SdcPlugin;

0 commit comments

Comments
 (0)