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_capi.h`.
21 #include <backends/cxxrtl/cxxrtl.h>
22 #include <backends/cxxrtl/cxxrtl_capi.h>
24 struct _cxxrtl_handle
{
25 std::unique_ptr
<cxxrtl::module
> module
;
26 cxxrtl::debug_items objects
;
29 cxxrtl_handle
cxxrtl_create(cxxrtl_toplevel design
) {
30 cxxrtl_handle handle
= new _cxxrtl_handle
;
31 handle
->module
= std::move(design
->module
);
32 handle
->module
->debug_info(handle
->objects
);
37 void cxxrtl_destroy(cxxrtl_handle handle
) {
41 size_t cxxrtl_step(cxxrtl_handle handle
) {
42 return handle
->module
->step();
45 cxxrtl_object
*cxxrtl_get(cxxrtl_handle handle
, const char *name
) {
46 if (handle
->objects
.count(name
) > 0)
47 return static_cast<cxxrtl_object
*>(&handle
->objects
.at(name
));
51 void cxxrtl_enum(cxxrtl_handle handle
, void *data
,
52 void (*callback
)(void *data
, const char *name
, struct cxxrtl_object
*object
)) {
53 for (auto &it
: handle
->objects
)
54 callback(data
, it
.first
.c_str(), static_cast<cxxrtl_object
*>(&it
.second
));