2014-11-24 03:06:10 +01:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: verilator_coverage: Source file to annotate with line coverage
|
|
|
|
|
//
|
2019-11-08 04:33:59 +01:00
|
|
|
// Code available from: https://verilator.org
|
2014-11-24 03:06:10 +01:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2024-01-01 09:19:59 +01:00
|
|
|
// Copyright 2003-2024 by Wilson Snyder. This program is free software; you
|
2020-03-21 16:24:24 +01:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2014-11-24 03:06:10 +01:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2020-03-21 16:24:24 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2014-11-24 03:06:10 +01:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
2019-10-05 02:17:11 +02:00
|
|
|
|
2021-03-04 03:57:07 +01:00
|
|
|
#ifndef VERILATOR_VLCSOURCE_H_
|
|
|
|
|
#define VERILATOR_VLCSOURCE_H_
|
2014-11-24 03:06:10 +01:00
|
|
|
|
|
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2018-10-14 19:43:24 +02:00
|
|
|
|
2024-07-14 23:05:58 +02:00
|
|
|
#include <limits>
|
2014-11-24 03:06:10 +01:00
|
|
|
#include <map>
|
2023-02-09 02:15:11 +01:00
|
|
|
#include <set>
|
2022-01-08 18:01:39 +01:00
|
|
|
#include <utility>
|
2014-11-24 03:06:10 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
2023-02-09 02:15:11 +01:00
|
|
|
class VlcPoint;
|
|
|
|
|
|
2014-11-24 03:06:10 +01:00
|
|
|
//********************************************************************
|
|
|
|
|
// VlcColumnCount - count at specific source file, line and column
|
|
|
|
|
|
2020-11-19 03:32:16 +01:00
|
|
|
class VlcSourceCount final {
|
2023-02-09 02:15:11 +01:00
|
|
|
// TYPES
|
|
|
|
|
using PointsSet = std::set<const VlcPoint*>;
|
|
|
|
|
|
2014-11-24 03:06:10 +01:00
|
|
|
// MEMBERS
|
2023-10-28 14:38:02 +02:00
|
|
|
const int m_lineno; ///< Line number
|
2024-07-14 23:05:58 +02:00
|
|
|
uint64_t m_count = std::numeric_limits<uint64_t>::max(); ///< Count
|
2020-08-15 19:11:27 +02:00
|
|
|
bool m_ok = false; ///< Coverage is above threshold
|
2023-02-09 02:15:11 +01:00
|
|
|
PointsSet m_points; // Points on this line
|
2014-11-24 03:06:10 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// CONSTRUCTORS
|
2023-03-19 00:28:48 +01:00
|
|
|
explicit VlcSourceCount(int lineno)
|
2023-02-09 02:15:11 +01:00
|
|
|
: m_lineno{lineno} {}
|
2020-11-17 01:56:16 +01:00
|
|
|
~VlcSourceCount() = default;
|
2014-11-24 03:06:10 +01:00
|
|
|
|
|
|
|
|
// ACCESSORS
|
|
|
|
|
int lineno() const { return m_lineno; }
|
2022-03-27 21:27:40 +02:00
|
|
|
uint64_t count() const { return m_count; }
|
2014-11-24 03:06:10 +01:00
|
|
|
bool ok() const { return m_ok; }
|
|
|
|
|
|
|
|
|
|
// METHODS
|
2022-03-27 21:27:40 +02:00
|
|
|
void incCount(uint64_t count, bool ok) {
|
2024-07-14 23:05:58 +02:00
|
|
|
if (m_count == std::numeric_limits<uint64_t>::max())
|
2023-02-09 02:15:11 +01:00
|
|
|
m_ok = ok;
|
2024-07-14 23:05:58 +02:00
|
|
|
else
|
|
|
|
|
m_ok = m_ok && ok;
|
|
|
|
|
m_count = std::min(m_count, count);
|
2014-11-24 03:06:10 +01:00
|
|
|
}
|
2023-02-09 02:15:11 +01:00
|
|
|
void insertPoint(const VlcPoint* pointp) { m_points.emplace(pointp); }
|
|
|
|
|
PointsSet& points() { return m_points; }
|
2014-11-24 03:06:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//********************************************************************
|
|
|
|
|
// VlcSource - source file to annotate
|
|
|
|
|
|
2020-11-19 03:32:16 +01:00
|
|
|
class VlcSource final {
|
2014-11-24 03:06:10 +01:00
|
|
|
public:
|
|
|
|
|
// TYPES
|
2023-02-09 02:15:11 +01:00
|
|
|
using LinenoMap = std::map<int, VlcSourceCount>; // Map of {column}
|
2014-11-24 03:06:10 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// MEMBERS
|
2019-05-08 05:00:52 +02:00
|
|
|
string m_name; //< Name of the source file
|
|
|
|
|
LinenoMap m_lines; //< Map of each annotated line
|
2022-11-13 15:26:46 +01:00
|
|
|
bool m_needed = false; //< Need to annotate; has low coverage
|
2014-11-24 03:06:10 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// CONSTRUCTORS
|
2020-08-16 15:55:36 +02:00
|
|
|
explicit VlcSource(const string& name)
|
|
|
|
|
: m_name{name} {}
|
2020-11-17 01:56:16 +01:00
|
|
|
~VlcSource() = default;
|
2014-11-24 03:06:10 +01:00
|
|
|
|
|
|
|
|
// ACCESSORS
|
|
|
|
|
const string& name() const { return m_name; }
|
|
|
|
|
bool needed() const { return m_needed; }
|
2024-06-23 01:50:46 +02:00
|
|
|
void needed(bool flag) { m_needed = flag; }
|
2014-11-24 03:06:10 +01:00
|
|
|
LinenoMap& lines() { return m_lines; }
|
|
|
|
|
|
|
|
|
|
// METHODS
|
2023-02-09 02:15:11 +01:00
|
|
|
void lineIncCount(int lineno, uint64_t count, bool ok, const VlcPoint* pointp) {
|
2023-10-28 14:38:02 +02:00
|
|
|
VlcSourceCount& sc = m_lines.emplace(lineno, lineno).first->second;
|
2019-05-08 05:00:52 +02:00
|
|
|
sc.incCount(count, ok);
|
2023-02-09 02:15:11 +01:00
|
|
|
sc.insertPoint(pointp);
|
2014-11-24 03:06:10 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//********************************************************************
|
|
|
|
|
// VlcSources - Container of all source files
|
|
|
|
|
|
2020-11-19 03:32:16 +01:00
|
|
|
class VlcSources final {
|
2014-11-24 03:06:10 +01:00
|
|
|
public:
|
|
|
|
|
// TYPES
|
2021-03-13 00:10:45 +01:00
|
|
|
using NameMap = std::map<const std::string, VlcSource>;
|
2019-11-10 02:35:12 +01:00
|
|
|
|
2014-11-24 03:06:10 +01:00
|
|
|
private:
|
|
|
|
|
// MEMBERS
|
2019-05-08 05:00:52 +02:00
|
|
|
NameMap m_sources; //< List of all sources
|
2014-11-24 03:06:10 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// ITERATORS
|
2021-03-13 00:10:45 +01:00
|
|
|
using iterator = NameMap::iterator;
|
2014-11-24 03:06:10 +01:00
|
|
|
NameMap::iterator begin() { return m_sources.begin(); }
|
|
|
|
|
NameMap::iterator end() { return m_sources.end(); }
|
|
|
|
|
|
|
|
|
|
// CONSTRUCTORS
|
2020-11-17 01:56:16 +01:00
|
|
|
VlcSources() = default;
|
|
|
|
|
~VlcSources() = default;
|
2014-11-24 03:06:10 +01:00
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
VlcSource& findNewSource(const string& name) {
|
2019-05-08 05:00:52 +02:00
|
|
|
NameMap::iterator iter = m_sources.find(name);
|
|
|
|
|
if (iter != m_sources.end()) {
|
|
|
|
|
return iter->second;
|
2019-11-10 02:35:12 +01:00
|
|
|
} else {
|
2023-10-28 12:24:04 +02:00
|
|
|
iter = m_sources.emplace(name, VlcSource{name}).first;
|
2019-05-08 05:00:52 +02:00
|
|
|
return iter->second;
|
|
|
|
|
}
|
2014-11-24 03:06:10 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
2019-05-08 05:00:52 +02:00
|
|
|
#endif // Guard
|