src/svf_jtag: cppcheck/lint

This commit is contained in:
Gwenhael Goavec-Merou 2022-11-06 18:33:43 +01:00
parent 0b0055495c
commit e595953546
2 changed files with 38 additions and 35 deletions

View File

@ -1,19 +1,23 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
/* /*
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com> * Copyright (C) 2019-2022 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
* Copyright (C) 2022 phdussud
*
*/ */
#include "svf_jtag.hpp"
#include <unistd.h>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <map> #include <map>
#include <vector> #include <vector>
#include <unistd.h>
#include "jtag.hpp" #include "jtag.hpp"
#include "svf_jtag.hpp"
using namespace std; using namespace std;
void SVF_jtag::split_str(string const &str, vector<string> &vparse) void SVF_jtag::split_str(string const &str, vector<string> &vparse)
@ -33,15 +37,16 @@ void SVF_jtag::clear_XYR(svf_XYR &t)
t.smask.clear(); t.smask.clear();
} }
static unsigned char *parse_hex(string const &in, size_t byte_length, bool default_value) static unsigned char *parse_hex(string const &in, size_t byte_length,
bool default_value)
{ {
unsigned char *txbuf = new unsigned char[byte_length]; unsigned char *txbuf = new unsigned char[byte_length];
char c; char c;
int last_iter = ((int)in.size() - (int)(2 * byte_length)); size_t last_iter = in.size() - (2 * byte_length);
for (int i = (in.size() - 1), pos = 0; i >= last_iter; i--, pos++) { for (size_t i = (in.size() - 1), pos = 0; i >= last_iter; i--, pos++) {
if (i < 0) if (i < 0) {
c = default_value ? 0x0f : 0x00; c = default_value ? 0x0f : 0x00;
else { } else {
if (in[i] <= '9') if (in[i] <= '9')
c = 0x0f & (in[i] - '0'); c = 0x0f & (in[i] - '0');
else else
@ -83,7 +88,7 @@ void SVF_jtag::parse_XYR(vector<string> const &vstr, svf_XYR &t)
t.tdo.clear(); t.tdo.clear();
if (t.len == 0) if (t.len == 0)
return; return;
for (long unsigned int pos = 2; pos < vstr.size(); pos++) { for (size_t pos = 2; pos < vstr.size(); pos++) {
s = vstr[pos]; s = vstr[pos];
if (!s.compare("TDO")) { if (!s.compare("TDO")) {
@ -149,8 +154,9 @@ void SVF_jtag::parse_XYR(vector<string> const &vstr, svf_XYR &t)
if (!t.tdo.empty()) { if (!t.tdo.empty()) {
read_buffer = new unsigned char[byte_len]; read_buffer = new unsigned char[byte_len];
read_buffer[byte_len - 1] = 0; // clear the last byte which may not be full; read_buffer[byte_len - 1] = 0; // clear the last byte which may not be full;
} else } else {
read_buffer = NULL; read_buffer = NULL;
}
if (write_data == 0) if (write_data == 0)
_jtag->shiftIR(write_buffer, read_buffer, t.len, _endir); _jtag->shiftIR(write_buffer, read_buffer, t.len, _endir);
else else
@ -206,21 +212,18 @@ void SVF_jtag::parse_runtest(vector<string> const &vstr)
} }
} }
auto res = find(begin(vstr) + pos, end(vstr), "ENDSTATE"); auto res = find(begin(vstr) + pos, end(vstr), "ENDSTATE");
if (res != end(vstr)) if (res != end(vstr)) {
{
res++; res++;
end_state = fsm_state[*res]; end_state = fsm_state[*res];
} }
if (run_state != -1) if (run_state != -1) {
{
_run_state = run_state; _run_state = run_state;
} }
if (end_state != -1) if (end_state != -1) {
{
_end_state = end_state; _end_state = end_state;
} } else if (run_state != -1) {
else if (run_state != -1)
_end_state = run_state; _end_state = run_state;
}
_jtag->set_state(_run_state); _jtag->set_state(_run_state);
_jtag->toggleClk(nb_iter); _jtag->toggleClk(nb_iter);
if (min_duration > 0) { if (min_duration > 0) {
@ -398,5 +401,4 @@ void SVF_jtag::parse(string filename)
} }
cout << "end of SVF file" << endl; cout << "end of SVF file" << endl;
} }

View File

@ -1,11 +1,12 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
/* /*
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com> * Copyright (C) 2019-2022 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
*/ */
#ifndef SVF_JTAG_HPP #ifndef SRC_SVF_JTAG_HPP_
#define SVF_JTAG_HPP #define SRC_SVF_JTAG_HPP_
#include <iostream> #include <iostream>
#include <string>
#include <vector> #include <vector>
#include <map> #include <map>
@ -68,4 +69,4 @@ class SVF_jtag {
svf_XYR tdr; svf_XYR tdr;
svf_XYR tir; svf_XYR tir;
}; };
#endif #endif // SRC_SVF_JTAG_HPP_