2011-03-02 18:43:20 +01:00
|
|
|
/*
|
2025-07-22 08:30:57 +02:00
|
|
|
* Copyright (C) 2011-2025 Cary R. (cygcary@yahoo.com)
|
2011-03-02 18:43:20 +01:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "compile.h"
|
|
|
|
|
# include "vpi_priv.h"
|
|
|
|
|
|
2021-01-02 22:52:25 +01:00
|
|
|
class __vpiFileLine : public __vpiHandle {
|
|
|
|
|
public:
|
|
|
|
|
explicit __vpiFileLine(const char*desc_, long file_idx_, long lineno_);
|
2025-07-22 08:30:57 +02:00
|
|
|
int get_type_code(void) const override;
|
|
|
|
|
int vpi_get(int code) override;
|
|
|
|
|
char* vpi_get_str(int code) override;
|
2012-01-19 19:16:39 +01:00
|
|
|
|
2021-01-02 22:52:25 +01:00
|
|
|
const char* get_description() const { return description; };
|
|
|
|
|
unsigned get_file_idx() const { return file_idx; };
|
|
|
|
|
unsigned get_lineno() const { return lineno; };
|
|
|
|
|
|
|
|
|
|
private:
|
2011-03-02 18:43:20 +01:00
|
|
|
const char *description;
|
|
|
|
|
unsigned file_idx;
|
|
|
|
|
unsigned lineno;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool show_file_line = false;
|
2011-03-04 03:54:46 +01:00
|
|
|
bool code_is_instrumented = false;
|
2011-03-02 18:43:20 +01:00
|
|
|
|
|
|
|
|
static int file_line_get(int type, vpiHandle ref)
|
|
|
|
|
{
|
2021-01-02 22:52:25 +01:00
|
|
|
__vpiFileLine*rfp = dynamic_cast<__vpiFileLine*>(ref);
|
2012-01-19 19:16:39 +01:00
|
|
|
assert(rfp);
|
2011-03-02 18:43:20 +01:00
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case vpiLineNo:
|
2021-01-02 22:52:25 +01:00
|
|
|
return rfp->get_lineno();
|
2011-03-02 18:43:20 +01:00
|
|
|
default:
|
|
|
|
|
return vpiUndefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *file_line_get_str(int type, vpiHandle ref)
|
|
|
|
|
{
|
2021-01-02 22:52:25 +01:00
|
|
|
__vpiFileLine*rfp = dynamic_cast<__vpiFileLine*>(ref);
|
2012-01-19 19:16:39 +01:00
|
|
|
assert(rfp);
|
2011-03-02 18:43:20 +01:00
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case vpiFile:
|
2021-01-02 22:52:25 +01:00
|
|
|
assert(rfp->get_file_idx() < file_names.size());
|
|
|
|
|
return simple_set_rbuf_str(file_names[rfp->get_file_idx()]);
|
2011-03-02 18:43:20 +01:00
|
|
|
case _vpiDescription:
|
2021-01-02 22:52:25 +01:00
|
|
|
if (rfp->get_description()) {
|
|
|
|
|
return simple_set_rbuf_str(rfp->get_description());
|
|
|
|
|
} else return simple_set_rbuf_str("Procedural tracing.");
|
2011-03-02 18:43:20 +01:00
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 22:52:25 +01:00
|
|
|
inline __vpiFileLine::__vpiFileLine(const char*desc_, long file_idx_,
|
|
|
|
|
long lineno_)
|
|
|
|
|
{
|
|
|
|
|
if (desc_) description = vpip_name_string(desc_);
|
|
|
|
|
else description = 0;
|
|
|
|
|
file_idx = (unsigned) file_idx_;
|
|
|
|
|
lineno = (unsigned) lineno_;
|
|
|
|
|
}
|
2012-01-19 19:16:39 +01:00
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
int __vpiFileLine::get_type_code(void) const
|
|
|
|
|
{ return _vpiFileLine; }
|
|
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
int __vpiFileLine::vpi_get(int code)
|
|
|
|
|
{ return file_line_get(code, this); }
|
|
|
|
|
|
|
|
|
|
char* __vpiFileLine::vpi_get_str(int code)
|
|
|
|
|
{ return file_line_get_str(code, this); }
|
|
|
|
|
|
|
|
|
|
|
2011-03-02 18:43:20 +01:00
|
|
|
vpiHandle vpip_build_file_line(char*description, long file_idx, long lineno)
|
|
|
|
|
{
|
2021-01-02 22:52:25 +01:00
|
|
|
__vpiFileLine*obj = new __vpiFileLine(description, file_idx, lineno);
|
2011-03-02 18:43:20 +01:00
|
|
|
|
2020-08-11 06:57:50 +02:00
|
|
|
/* You can turn on the diagnostic output if we find a %file_line. */
|
2011-03-04 03:54:46 +01:00
|
|
|
code_is_instrumented = true;
|
2011-03-02 18:43:20 +01:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
return obj;
|
2011-03-02 18:43:20 +01:00
|
|
|
}
|