From 38acd7644c64a5f0a65bf4ab67b9f6c53f723e9d Mon Sep 17 00:00:00 2001 From: aisuneko icecat Date: Wed, 6 May 2026 23:04:11 +0800 Subject: [PATCH 1/2] svf_jtag: fix incorrect handling of spaces and newlines --- src/svf_jtag.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/svf_jtag.cpp b/src/svf_jtag.cpp index 38d0fb0..f21dc50 100644 --- a/src/svf_jtag.cpp +++ b/src/svf_jtag.cpp @@ -7,6 +7,7 @@ #include "svf_jtag.hpp" +#include #include #include @@ -23,8 +24,11 @@ void SVF_jtag::split_str(std::string const &str, std::vector &vpars { std::string token; std::istringstream tokenStream(str); - while (getline(tokenStream, token, ' ')) - vparse.push_back(token); + while (tokenStream >> token){ + if(!token.empty()){ + vparse.push_back(token); + } + } } void SVF_jtag::clear_XYR(svf_XYR &t) @@ -90,6 +94,11 @@ void SVF_jtag::parse_XYR(std::vector const &vstr, svf_XYR &t) for (size_t pos = 2; pos < vstr.size(); pos++) { s = vstr[pos]; + if (s.empty()){ + throw std::runtime_error("Error parsing instruction: extraneous spaces"); + return; + } + if (!s.compare("TDO")) { mode = 1; continue; @@ -372,6 +381,9 @@ void SVF_jtag::parse(std::string filename) unsigned int lineno = 0; try { while (getline(fs, str)) { + if(str.empty()){ + continue; + } /* sanity check: DOS CR */ if (str.back() == '\r') str.pop_back(); From f0e0f3a3f9f482b83abf8ae204604dc69be89eb6 Mon Sep 17 00:00:00 2001 From: aisuneko icecat Date: Wed, 6 May 2026 23:04:39 +0800 Subject: [PATCH 2/2] svf_jtag: add progressbar --- src/svf_jtag.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/svf_jtag.cpp b/src/svf_jtag.cpp index f21dc50..ab857a3 100644 --- a/src/svf_jtag.cpp +++ b/src/svf_jtag.cpp @@ -18,6 +18,7 @@ #include #include "jtag.hpp" +#include "progressBar.hpp" void SVF_jtag::split_str(std::string const &str, std::vector &vparse) @@ -379,6 +380,14 @@ void SVF_jtag::parse(std::string filename) return; } unsigned int lineno = 0; + int lines_total = std::count(std::istreambuf_iterator(fs), + std::istreambuf_iterator(), '\n') + 1; + fs.clear(); + fs.seekg(0,std::ios::beg); + printf("Reading %s with %d lines", filename.c_str(), lines_total); + + ProgressBar progress("Writing SVF " + filename, lines_total, 50, _verbose); + try { while (getline(fs, str)) { if(str.empty()){ @@ -409,13 +418,16 @@ void SVF_jtag::parse(std::string filename) handle_instruction(vstr); vstr.clear(); } + progress.display(lineno); } } catch (std::exception &e) { - std::cerr << "Cannot proceed because of error(s) at line " << lineno << std::endl; + std::cerr << "Cannot proceed because of error(s) at line " << std::dec << lineno << std::endl; + progress.fail(); throw; } + progress.done(); std::cout << "end of SVF file" << std::endl; }