1 /*
2 * Copyright (C) 2011-2020 Cary R. (cygcary@yahoo.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 # include "compile.h"
20 # include "vpi_priv.h"
21
22 struct __vpiFileLine : public __vpiHandle {
23 __vpiFileLine();
24 int get_type_code(void) const;
25 int vpi_get(int code);
26 char* vpi_get_str(int code);
27
28 const char *description;
29 unsigned file_idx;
30 unsigned lineno;
31 };
32
33 bool show_file_line = false;
34 bool code_is_instrumented = false;
35
file_line_get(int type,vpiHandle ref)36 static int file_line_get(int type, vpiHandle ref)
37 {
38 struct __vpiFileLine*rfp = dynamic_cast<__vpiFileLine*>(ref);
39 assert(rfp);
40
41 switch (type) {
42 case vpiLineNo:
43 return rfp->lineno;
44 default:
45 return vpiUndefined;
46 }
47 }
48
file_line_get_str(int type,vpiHandle ref)49 static char *file_line_get_str(int type, vpiHandle ref)
50 {
51 struct __vpiFileLine*rfp = dynamic_cast<__vpiFileLine*>(ref);
52 assert(rfp);
53
54 switch (type) {
55 case vpiFile:
56 assert(rfp->file_idx < file_names.size());
57 return simple_set_rbuf_str(file_names[rfp->file_idx]);
58 case _vpiDescription:
59 if (rfp->description) return simple_set_rbuf_str(rfp->description);
60 else return simple_set_rbuf_str("Procedural tracing.");
61 default:
62 return 0;
63 }
64 }
65
__vpiFileLine()66 inline __vpiFileLine::__vpiFileLine()
67 { }
68
get_type_code(void) const69 int __vpiFileLine::get_type_code(void) const
70 { return _vpiFileLine; }
71
vpi_get(int code)72 int __vpiFileLine::vpi_get(int code)
73 { return file_line_get(code, this); }
74
vpi_get_str(int code)75 char* __vpiFileLine::vpi_get_str(int code)
76 { return file_line_get_str(code, this); }
77
78
vpip_build_file_line(char * description,long file_idx,long lineno)79 vpiHandle vpip_build_file_line(char*description, long file_idx, long lineno)
80 {
81 struct __vpiFileLine*obj = new struct __vpiFileLine;
82
83 /* You can turn on the diagnostic output if we find a %file_line. */
84 code_is_instrumented = true;
85
86 if (description) obj->description = vpip_name_string(description);
87 else obj->description = 0;
88 obj->file_idx = (unsigned) file_idx;
89 obj->lineno = (unsigned) lineno;
90
91 return obj;
92 }
93