Merge pull request #2133 from dh73/nodev_head
[yosys.git] / backends / cxxrtl / cxxrtl_capi.cc
1 /*
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2020 whitequark <whitequark@whitequark.org>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted.
8 *
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.
16 *
17 */
18
19 // This file is a part of the CXXRTL C API. It should be used together with `cxxrtl_capi.h`.
20
21 #include <backends/cxxrtl/cxxrtl.h>
22 #include <backends/cxxrtl/cxxrtl_capi.h>
23
24 struct _cxxrtl_handle {
25 std::unique_ptr<cxxrtl::module> module;
26 cxxrtl::debug_items objects;
27 };
28
29 // Private function for use by other units of the C API.
30 const cxxrtl::debug_items &cxxrtl_debug_items_from_handle(cxxrtl_handle handle) {
31 return handle->objects;
32 }
33
34 cxxrtl_handle cxxrtl_create(cxxrtl_toplevel design) {
35 cxxrtl_handle handle = new _cxxrtl_handle;
36 handle->module = std::move(design->module);
37 handle->module->debug_info(handle->objects);
38 delete design;
39 return handle;
40 }
41
42 void cxxrtl_destroy(cxxrtl_handle handle) {
43 delete handle;
44 }
45
46 int cxxrtl_eval(cxxrtl_handle handle) {
47 return handle->module->eval();
48 }
49
50 int cxxrtl_commit(cxxrtl_handle handle) {
51 return handle->module->commit();
52 }
53
54 size_t cxxrtl_step(cxxrtl_handle handle) {
55 return handle->module->step();
56 }
57
58 struct cxxrtl_object *cxxrtl_get_parts(cxxrtl_handle handle, const char *name, size_t *parts) {
59 auto it = handle->objects.table.find(name);
60 if (it == handle->objects.table.end())
61 return nullptr;
62 *parts = it->second.size();
63 return static_cast<cxxrtl_object*>(&it->second[0]);
64 }
65
66 void cxxrtl_enum(cxxrtl_handle handle, void *data,
67 void (*callback)(void *data, const char *name,
68 cxxrtl_object *object, size_t parts)) {
69 for (auto &it : handle->objects.table)
70 callback(data, it.first.c_str(), static_cast<cxxrtl_object*>(&it.second[0]), it.second.size());
71 }