2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2020 whitequark <whitequark@whitequark.org>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 // This file is a part of the CXXRTL C API. It should be used together with `cxxrtl_vcd_capi.h`.
21 #include <backends/cxxrtl/cxxrtl_vcd.h>
22 #include <backends/cxxrtl/cxxrtl_vcd_capi.h>
24 extern const cxxrtl::debug_items
&cxxrtl_debug_items_from_handle(cxxrtl_handle handle
);
27 cxxrtl::vcd_writer writer
;
31 cxxrtl_vcd
cxxrtl_vcd_create() {
32 return new _cxxrtl_vcd
;
35 void cxxrtl_vcd_destroy(cxxrtl_vcd vcd
) {
39 void cxxrtl_vcd_timescale(cxxrtl_vcd vcd
, int number
, const char *unit
) {
40 vcd
->writer
.timescale(number
, unit
);
43 void cxxrtl_vcd_add(cxxrtl_vcd vcd
, const char *name
, cxxrtl_object
*object
) {
44 // Note the copy. We don't know whether `object` came from a design (in which case it is
45 // an instance of `debug_item`), or from user code (in which case it is an instance of
46 // `cxxrtl_object`), so casting the pointer wouldn't be safe.
47 vcd
->writer
.add(name
, debug_item(*object
));
50 void cxxrtl_vcd_add_from(cxxrtl_vcd vcd
, cxxrtl_handle handle
) {
51 vcd
->writer
.add(cxxrtl_debug_items_from_handle(handle
));
54 void cxxrtl_vcd_add_from_if(cxxrtl_vcd vcd
, cxxrtl_handle handle
, void *data
,
55 int (*filter
)(void *data
, const char *name
,
56 const cxxrtl_object
*object
)) {
57 vcd
->writer
.add(cxxrtl_debug_items_from_handle(handle
),
58 [=](const std::string
&name
, const debug_item
&item
) {
59 return filter(data
, name
.c_str(), static_cast<const cxxrtl_object
*>(&item
));
63 void cxxrtl_vcd_add_from_without_memories(cxxrtl_vcd vcd
, cxxrtl_handle handle
) {
64 vcd
->writer
.add_without_memories(cxxrtl_debug_items_from_handle(handle
));
67 void cxxrtl_vcd_sample(cxxrtl_vcd vcd
, uint64_t time
) {
69 vcd
->writer
.buffer
.clear();
72 vcd
->writer
.sample(time
);
75 void cxxrtl_vcd_read(cxxrtl_vcd vcd
, const char **data
, size_t *size
) {
77 vcd
->writer
.buffer
.clear();
80 *data
= vcd
->writer
.buffer
.c_str();
81 *size
= vcd
->writer
.buffer
.size();