qualcomm/qbox
Loading...
Searching...
No Matches
cciutils.h
1/*
2 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 * Author: GreenSocs 2022
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef CCIUTILS_H
9#define CCIUTILS_H
10
11#include <scp/report.h>
12#include <iostream>
13#include <list>
14#include <regex>
15#include <cstdint>
16#include <type_traits>
17#include <unordered_map>
18#include <unordered_set>
19
20#include "luafile_tool.h"
21#include <cci_configuration>
22#define SC_INCLUDE_DYNAMIC_PROCESSES
23#include <systemc>
24#include <tlm>
25#include <tuple>
26
27/*********************
28 * CCI Convenience
29 *********************/
30
31namespace gs {
32using namespace cci;
33
34// Marks modules that construct child modules through ContainerBase.
36{
37public:
38 virtual ~container_module() = default;
39};
40
47template <typename, typename... U>
48class cci_function; // undefined
49template <typename T, typename... U>
50class cci_function<T(U...)> : public std::function<T(U...)>
51{
52 using std::function<T(U...)>::function;
53
54public:
55 // add operater== as required by CCI
56 bool operator==(const cci_function& rhs) const
57 {
58 assert(false);
59 return false;
60 }
61};
62
68class cci_constructor_vl : public std::function<sc_core::sc_module*(sc_core::sc_module_name, cci::cci_value_list)>
69{
70 using std::function<sc_core::sc_module*(sc_core::sc_module_name, cci::cci_value_list)>::function;
71
72 /* local 'apply' helper */
73 template <typename _T, typename... U, size_t... I>
74 static _T* new_t(sc_core::sc_module_name name, std::tuple<U...> tuple, std::index_sequence<I...>)
75 {
76 (void)tuple; // mark tupal as used for older compilers.
77 return new _T(name, std::get<I>(tuple)...);
78 }
79
80 template <typename... U>
81 static std::tuple<U...> convert_arguments(sc_core::sc_module_name name, cci::cci_value_list values)
82 {
83 int n = 0;
84 try {
85 return { values[n++].get<U>()... };
86 } catch (...) {
87 SC_REPORT_ERROR("GS CCI UTILS", ("CCI argument types dont match for module " + std::string(name)).c_str());
88 throw;
89 }
90 }
91
92public:
98 template <typename T, typename... U>
99 class FactoryMaker
100 {
101 public:
102 const char* type;
103 FactoryMaker<T, U...>(const char* _t): type(_t) {}
104 };
105
106 const char* type = ""; // maintain a string representation of the type.
107 bool m_is_container = false;
108
109 bool is_container() const { return m_is_container; }
110
118 template <typename _T, typename... U>
120 : std::function<sc_core::sc_module*(sc_core::sc_module_name name, cci::cci_value_list v)>(
121 [](sc_core::sc_module_name name, cci::cci_value_list v) -> sc_core::sc_module* {
122 if (sizeof...(U) != v.size()) {
123 SC_REPORT_ERROR("GS CCI UTILS",
124 ("Wrong number of CCI arguments for module " + std::string(name)).c_str());
125 return nullptr;
126 }
127 auto tuple = convert_arguments<U...>(name, std::move(v));
128 auto is = std::make_index_sequence<sizeof...(U)>{};
129 return new_t<_T, U...>(name, std::move(tuple), is);
130 })
131 {
132 type = fm.type;
133 m_is_container = std::is_base_of_v<container_module, _T>;
134 }
135
136 // add operater== as required by CCI
137 bool operator==(const cci_constructor_vl& rhs) const
138 {
139 SCP_FATAL("cciutils.operator") << "Operator required by CCI";
140 return false;
141 }
142};
143
151sc_core::sc_object* find_sc_obj(sc_core::sc_object* m, std::string name, bool test = false);
152
159template <typename T>
160std::vector<T*> find_sc_objects(sc_core::sc_object* m = nullptr)
161{
162 std::vector<T*> res;
163 if (m) {
164 T* o = dynamic_cast<T*>(m);
165 if (o) res.push_back(o);
166 }
167 std::vector<sc_core::sc_object*> children;
168 if (m) {
169 children = m->get_child_objects();
170 } else {
171 children = sc_core::sc_get_top_level_objects();
172 }
173 for (auto o : children) {
174 auto c = find_sc_objects<T>(o);
175 res.insert(res.end(), std::make_move_iterator(c.begin()), std::make_move_iterator(c.end()));
176 }
177 return res;
178}
179
186std::string sc_cci_leaf_name(std::string name);
187
195std::list<std::string> sc_cci_children(sc_core::sc_module_name name);
196
206std::list<std::string> sc_cci_list_items(sc_core::sc_module_name module_name, std::string list_name);
207
208std::string get_parent_name(sc_core::sc_module_name n);
209
210cci::cci_value cci_get(cci::cci_broker_handle broker, std::string name);
211
212template <typename T>
213T cci_get(cci::cci_broker_handle broker, std::string name)
214{
215 T ret{};
216 cci_value v = cci_get(broker, name);
217
218 if (!v.template try_get<T>(ret)) {
219 SCP_ERR("cciutils.cci_get") << "Unable to get parameter " << name << "\nIs your config file up-to-date?";
220 }
221 return ret;
222}
223
224template <typename T>
225T cci_get_d(cci::cci_broker_handle broker, std::string name, T default_val)
226{
227 T ret{};
228 cci_value v = cci_get(broker, name);
229
230 if (!v.template try_get<T>(ret)) {
231 return default_val;
232 }
233 return ret;
234}
235
236template <typename T>
237bool cci_get(cci::cci_broker_handle broker, std::string name, T& param)
238{
239 return cci_get(broker, name).try_get<T>(param);
240}
241
242class HelpSingleton : public sc_core::sc_module
243{
244public:
245 static HelpSingleton* GetInstance();
246 std::set<std::string> m_unused;
247 std::set<std::string> m_used;
248 std::set<std::string> m_capture;
249
250 void start_of_simulation()
251 {
252 if (!m_unused.empty()) {
253 SCP_WARN("Param check") << "";
254 SCP_WARN("Param check") << "Unused Parameters:";
255 SCP_WARN("Param check") << "===================================";
256 for (auto p : m_unused) {
257 SCP_WARN("Param check") << "Params: Unused parameter : " << p;
258 }
259 }
260 }
261
262 std::vector<std::tuple<std::string, std::string, std::string>> get_used_parameters(cci::cci_broker_handle broker,
263 std::string path = "",
264 bool print_params = true)
265 {
266 std::vector<std::tuple<std::string, std::string, std::string>> ret; // tuple<param_name, param_val, param_desc>
267 bool found_match = false;
268 for (auto v : m_used) {
269 if (v.rfind(path, 0) == 0) {
270 cci::cci_value c = cci_get(broker, v);
271 if (c.to_json() == "null") {
272 if (print_params) std::cout << "Configurable Parameters: " << v << " the value is not set";
273 } else {
274 if (print_params) std::cout << "Configurable Parameters: " << v << " the value is: " << c.to_json();
275 }
276 auto h = broker.get_param_handle(v);
277 std::string param_desc = "null";
278 if (h.is_valid()) {
279 param_desc = h.get_description();
280 if (print_params) std::cout << " (" << param_desc << ")";
281 }
282 if (print_params) std::cout << std::endl;
283 found_match = true;
284 ret.push_back(std::make_tuple(v, c.to_json(), param_desc));
285 }
286 }
287 if (!path.empty() && !found_match) {
288 SCP_FATAL("cciutils") << "No parameter matching '" << path << "'.";
289 }
290 return ret;
291 }
292
293 void set_unused(const std::string& parname, const cci_originator& originator)
294 {
295 if (m_capture.find(originator.name()) != m_capture.end()) m_unused.insert(parname);
296 }
297
298 void capture_originator(std::string name) { m_capture.insert(name); }
299
300 void clear_unused(const std::string& parname)
301 {
302 m_used.insert(parname);
303 auto iter = m_unused.find(parname);
304 if (iter != m_unused.end()) {
305 m_unused.erase(iter);
306 }
307 }
308
309private:
310 HelpSingleton();
311 static HelpSingleton* pHelpSingleton;
312};
313
320class ConfigurableBroker : public cci_utils::consuming_broker
321{
322private:
323 std::set<std::string> m_unignored; // before conf_file
324 // Retain locally preset values with their names. Repeated filtered
325 // enumeration otherwise performs a broker lookup for every parameter,
326 // and re-exposed parameters retain their value after being consumed.
327 std::unordered_map<std::string, cci_value> m_unignored_values;
328
329public:
330 // a set of perameters that should be exposed up the broker stack
331 HelpSingleton* m_help_helper;
332 std::set<std::string> hide;
333 friend class PrivateConfigurableBroker;
334
335 static cci_broker_if& get_broker_interface(cci_broker_handle broker) { return unwrap_broker(broker); }
336
337 std::vector<std::string> get_unconsumed_preset_names_with_prefix(const std::string& prefix) const
338 {
339 std::vector<std::string> names;
340 auto current = m_unignored.lower_bound(prefix);
341 while (current != m_unignored.end() && current->compare(0, prefix.length(), prefix) == 0) {
342 names.emplace_back(*current++);
343 }
344 return names;
345 }
346
347protected:
348 std::string m_orig_name;
349 cci_originator m_originator;
350 bool has_parent;
351 cci_broker_if& m_parent;
352 cci_param<ConfigurableBroker*>* m_child_ref;
353
354 std::unordered_set<std::string> m_initialized;
355 std::function<void(std::string)> m_uninitialized_cb;
356
357 friend class cci_value_converter<ConfigurableBroker>;
358
359 // convenience function for constructor
360 cci_broker_if& get_parent_broker()
361 {
362 if (sc_core::sc_get_current_object()) {
363 has_parent = true;
364 return unwrap_broker(cci_get_broker());
365 } else {
366 // We ARE the global broker
367 has_parent = false;
368 return *this;
369 }
370 }
371 std::string hierarchical_name()
372 {
373 if (!sc_core::sc_get_current_object()) {
374 return std::string("");
375 } else {
376 return cci_originator().name();
377 }
378 }
379 cci_originator get_cci_originator(const char* n)
380 {
381 if (!sc_core::sc_get_current_object()) {
382 return cci_originator(n);
383 } else {
384 return cci_originator();
385 }
386 }
387 inline bool is_log_param(const std::string& parname) const
388 {
389 std::string s_SCP_LOG_LEVEL_PARAM_NAME = SCP_LOG_LEVEL_PARAM_NAME;
390 int s_SCP_LOG_LEVEL_PARAM_NAME_length = s_SCP_LOG_LEVEL_PARAM_NAME.length();
391 int p_len = parname.length();
392 if (p_len >= s_SCP_LOG_LEVEL_PARAM_NAME_length) {
393 return (parname.compare(p_len - s_SCP_LOG_LEVEL_PARAM_NAME_length, s_SCP_LOG_LEVEL_PARAM_NAME_length,
394 s_SCP_LOG_LEVEL_PARAM_NAME) == 0);
395 } else {
396 return false;
397 }
398 }
403 virtual bool sendToParent(const std::string& parname) const
404 {
405 if (m_uninitialized_cb && (!is_log_param(parname))) {
406 while (1) {
407 auto pos = std::string::npos;
408 pos = parname.find_last_of('.', pos);
409 if (pos == std::string::npos) break;
410 auto parent = parname.substr(0, pos);
411 if (m_initialized.count(parent) != 0) break;
412 const_cast<ConfigurableBroker*>(this)->m_initialized.insert(parent);
413 m_uninitialized_cb(parent);
414 }
415 }
416 return ((hide.find(parname) == hide.end()) && (!is_global_broker()));
417 }
418
424 void initialize_params(const std::initializer_list<cci_name_value_pair>& list)
425 {
426 using namespace cci;
427
428 for (auto& p : list) {
429 hide.insert(relname(p.first));
430 if (!p.second.is_null()) {
431 set_preset_cci_value(relname(p.first), p.second, m_originator);
432 }
433 }
434 }
435
436 void alias_params(const std::initializer_list<std::pair<std::string, std::string>>& list)
437 {
438 // handle aliases
439 for (auto& p : list) {
440 std::string aliasname = relname(p.second);
441 set_preset_cci_value(relname(p.first), get_preset_cci_value(aliasname), m_originator);
442 alias_param(relname(p.first), aliasname);
443 }
444 }
451 void untyped_post_write_callback(const cci::cci_param_write_event<>& ev, cci::cci_param_handle synced_handle)
452 {
453 synced_handle.set_cci_value(ev.new_value);
454 }
464 void sync_values(cci::cci_param_handle _param_handle_1, cci::cci_param_handle _param_handle_2)
465 {
466 // In order to synchronize even the default values of the owner modules,
467 // use cci_base_param of one parameter as reference, write the same value
468 // to the other pararmeter's cci_base_param using JSON
469 _param_handle_1.set_cci_value(_param_handle_2.get_cci_value());
470
471 post_write_cb_vec.push_back(_param_handle_1.register_post_write_callback(
472 sc_bind(&ConfigurableBroker::untyped_post_write_callback, this, sc_unnamed::_1, _param_handle_2)));
473
474 post_write_cb_vec.push_back(_param_handle_2.register_post_write_callback(
475 sc_bind(&ConfigurableBroker::untyped_post_write_callback, this, sc_unnamed::_1, _param_handle_1)));
476 }
477
478 std::vector<cci::cci_callback_untyped_handle> post_write_cb_vec;
479
480 cci_param_create_callback_handle register_cb;
481 std::vector<std::pair<std::string, std::string>> alias_list;
482
483 void alias_param(std::string a, std::string b)
484 {
485 alias_list.push_back(std::make_pair(a, b));
486 if (register_cb == cci_param_create_callback_handle()) {
487 register_cb = register_create_callback(
488 sc_bind(&ConfigurableBroker::alias_param_callback, this, sc_unnamed::_1), m_originator);
489 }
490 alias_param_callback(cci::cci_param_handle());
491 }
492
493 void alias_param_callback(const cci_param_untyped_handle& ph)
494 {
495 alias_list.erase(std::remove_if(alias_list.begin(), alias_list.end(),
496 [&](auto a) {
497 cci_param_untyped_handle h_a = get_param_handle(a.first, m_originator);
498 if (h_a.is_valid() && h_a.get_mutable_type() == cci::CCI_IMMUTABLE_PARAM) {
499 return true;
500 }
501 cci_param_untyped_handle h_b = get_param_handle(a.second, m_originator);
502 if (h_b.is_valid() && !h_a.is_valid()) {
503 set_preset_cci_value(a.first, h_b.get_cci_value(), m_originator);
504 return false; // maybe it'll be mutable when it arrives?
505 }
506 if (h_a.is_valid() && h_b.is_valid()) {
507 sync_values(h_a, h_b);
508 return true;
509 }
510 return false;
511 }),
512 alias_list.end());
513
514 if (alias_list.size() == 0) {
515 unregister_create_callback(register_cb, m_originator);
516 }
517 }
518
519public:
520 /*
521 * public interface functions
522 */
523
524 std::vector<cci_name_value_pair> get_consumed_preset_values() const
525 {
526 std::vector<cci_name_value_pair> consumed_preset_cci_values;
527 std::map<std::string, cci_value>::const_iterator iter;
528 std::vector<cci_preset_value_predicate>::const_iterator pred;
529
530 for (iter = m_unused_value_registry.begin(); iter != m_unused_value_registry.end(); ++iter) {
531 for (pred = m_ignored_unconsumed_predicates.begin(); pred != m_ignored_unconsumed_predicates.end();
532 ++pred) {
533 const cci_preset_value_predicate& p = *pred; // get the actual predicate
534 if (p(std::make_pair(iter->first, iter->second))) {
535 break;
536 }
537 }
538 if (pred != m_ignored_unconsumed_predicates.end()) {
539 consumed_preset_cci_values.push_back(std::make_pair(iter->first, iter->second));
540 }
541 }
542 return consumed_preset_cci_values;
543 }
544
552#define BROKERNAME "gs::ConfigurableBroker"
553 ConfigurableBroker(const std::string& name = BROKERNAME,
554 std::function<void(std::string)> uninitialized_cb = nullptr)
555 : consuming_broker(hierarchical_name() + "." + name)
556 , m_help_helper(HelpSingleton::GetInstance())
557 , m_orig_name(hierarchical_name())
558 , m_originator(get_cci_originator(name.c_str()))
559 , m_parent(get_parent_broker()) // local convenience function
560 , m_child_ref(NULL)
561 , m_uninitialized_cb(uninitialized_cb)
562
563 {
564 if (has_parent) {
565 m_child_ref = new cci_param<ConfigurableBroker*>((name + ".childbroker").c_str(), (this), "");
566 }
567
568 cci_register_broker(this);
569 }
570
577 ConfigurableBroker(std::initializer_list<cci_name_value_pair> list,
578 std::initializer_list<std::pair<std::string, std::string>> alias_list = {},
579 std::function<void(std::string)> uninitialized_cb = nullptr)
580 : ConfigurableBroker(BROKERNAME, uninitialized_cb)
581 {
582 initialize_params(list);
583 alias_params(alias_list);
584 }
585
586 std::string relname(const std::string& n) const
587 {
588 return (m_orig_name.empty()) ? n : m_orig_name + std::string(".") + n;
589 }
590
592 {
593 if (m_child_ref) {
594 delete m_child_ref;
595 }
596 }
597
598 void set_uninitialized_cb(std::function<void(std::string)> uninitialized_cb)
599 {
600 m_uninitialized_cb = uninitialized_cb;
601 }
602 void clear_uninitialized_cb() { m_uninitialized_cb = nullptr; }
603
604 cci_originator get_value_origin(const std::string& parname) const override
605 {
606 if (sendToParent(parname)) {
607 return m_parent.get_value_origin(parname);
608 } else {
609 return consuming_broker::get_value_origin(parname);
610 }
611 }
612
613 /* NB missing from upstream CCI 'broker' see
614 * https://github.com/OSCI-WG/cci/issues/258 */
615 bool has_preset_value(const std::string& parname) const override
616 {
617 if (sendToParent(parname)) {
618 return m_parent.has_preset_value(parname);
619 } else {
620 return consuming_broker::has_preset_value(parname);
621 }
622 }
623
624 cci_value get_preset_cci_value(const std::string& parname) const override
625 {
626 if (sendToParent(parname)) {
627 return m_parent.get_preset_cci_value(parname);
628 } else {
629 return consuming_broker::get_preset_cci_value(parname);
630 }
631 }
632
633 void lock_preset_value(const std::string& parname) override
634 {
635 if (sendToParent(parname)) {
636 return m_parent.lock_preset_value(parname);
637 } else {
638 return consuming_broker::lock_preset_value(parname);
639 }
640 }
641
642 cci_value get_cci_value(const std::string& parname,
643 const cci::cci_originator& originator = cci::cci_originator()) const override
644 {
645 if (sendToParent(parname)) {
646 return m_parent.get_cci_value(parname, originator);
647 } else {
648 return consuming_broker::get_cci_value(parname, originator);
649 }
650 }
651
652 void add_param(cci_param_if* par) override
653 {
654 m_help_helper->clear_unused(par->name());
655 if (sendToParent(par->name())) {
656 return m_parent.add_param(par);
657 } else {
658 m_unignored.erase(par->name());
659 return consuming_broker::add_param(par);
660 }
661 }
662
663 void remove_param(cci_param_if* par) override
664 {
665 if (sendToParent(par->name())) {
666 return m_parent.remove_param(par);
667 } else {
668 m_unignored.insert(par->name());
669 return consuming_broker::remove_param(par);
670 }
671 }
672
673 // Upstream consuming broker fails to pass get_unconsumed_preset_value to parent
674 std::vector<cci_name_value_pair> get_unconsumed_preset_values() const override
675 {
676 std::vector<cci_name_value_pair> r;
677 for (const auto& u : m_unignored) {
678 auto value_it = m_unignored_values.find(u);
679 r.emplace_back(u, value_it != m_unignored_values.end() ? value_it->second : get_preset_cci_value(u));
680 }
681 if (has_parent) {
682 std::vector<cci_name_value_pair> p = m_parent.get_unconsumed_preset_values();
683 r.insert(r.end(), p.begin(), p.end());
684 }
685 return r;
686 }
687
688 // Upstream consuming broker fails to pass ignore_unconsumed_preset_values
689 void ignore_unconsumed_preset_values(const cci_preset_value_predicate& pred) override
690 {
691 if (has_parent) {
692 m_parent.ignore_unconsumed_preset_values(pred);
693 }
694 for (auto u = m_unignored.begin(); u != m_unignored.end();) {
695 if (pred(make_pair(*u, cci_value(0)))) {
696 m_help_helper->clear_unused(*u);
697 u = m_unignored.erase(u);
698 } else {
699 ++u;
700 }
701 }
702 }
703
704 cci_preset_value_range get_unconsumed_preset_values(const cci_preset_value_predicate& pred) const override
705 {
706 std::vector<cci_name_value_pair> values;
707 for (const auto& name : m_unignored) {
708 auto value_it = m_unignored_values.find(name);
709 cci_name_value_pair value(
710 name, value_it != m_unignored_values.end() ? value_it->second : get_preset_cci_value(name));
711 values.emplace_back(std::move(value));
712 }
713 if (has_parent) {
714 for (const auto& value : m_parent.get_unconsumed_preset_values()) {
715 values.emplace_back(value);
716 }
717 }
718 return cci_preset_value_range(pred, values);
719 }
720
721 // Functions below here require an orriginator to be passed to the local
722 // method variant.
723
724 void set_preset_cci_value(const std::string& parname, const cci_value& cci_value,
725 const cci_originator& originator) override
726 {
727 m_help_helper->set_unused(parname, originator);
728 if (sendToParent(parname)) {
729 return m_parent.set_preset_cci_value(parname, cci_value, originator);
730 } else {
731 // consuming_broker rejects writes to locked preset values. Keep the
732 // enumeration cache consistent with the value it retains.
733 if (locked.find(parname) == locked.end()) {
734 m_unignored.insert(parname);
735 m_unignored_values[parname] = cci_value;
736 }
737 return consuming_broker::set_preset_cci_value(parname, cci_value, originator);
738 }
739 }
740
741 cci_param_untyped_handle get_param_handle(const std::string& parname,
742 const cci_originator& originator) const override
743 {
744 if (sendToParent(parname)) {
745 return m_parent.get_param_handle(parname, originator);
746 }
747 cci_param_if* orig_param = get_orig_param(parname);
748 if (orig_param) {
749 return cci_param_untyped_handle(*orig_param, originator);
750 }
751 if (has_parent) {
752 return m_parent.get_param_handle(parname, originator);
753 }
754 return cci_param_untyped_handle(originator);
755 }
756
757 std::vector<cci_param_untyped_handle> get_param_handles(const cci_originator& originator) const override
758 {
759 if (has_parent) {
760 std::vector<cci_param_untyped_handle> p_param_handles = m_parent.get_param_handles();
761 std::vector<cci_param_untyped_handle> param_handles = consuming_broker::get_param_handles(originator);
762 // this is likely to be more efficient the other way round, but it keeps
763 // things consistent and means the local (more useful) params will be at
764 // the head of the list.
765 param_handles.insert(param_handles.end(), p_param_handles.begin(), p_param_handles.end());
766 return param_handles;
767 } else {
768 return consuming_broker::get_param_handles(originator);
769 }
770 }
771
772 bool is_global_broker() const override { return (!has_parent); }
773}; // namespace gs
774
775class PrivateConfigurableBroker : public gs::ConfigurableBroker
776{
777 std::string m_name;
778 unsigned m_name_length;
779 std::set<std::string> parent;
780 bool sendToParent(const std::string& parname) const override
781 {
782 if (m_uninitialized_cb) {
783 auto pos = parname.find_last_of('.');
784 if (pos != std::string::npos) {
785 auto p = parname.substr(0, pos);
786 if (m_uninitialized_cb && m_initialized.count(p) == 0) {
787 const_cast<PrivateConfigurableBroker*>(this)->m_initialized.insert(p);
788 m_uninitialized_cb(p);
789 }
790 }
791 }
792
793 if (parent.count(parname) > 0) {
794 return true;
795 }
796 if (parname.substr(0, m_name_length) == m_name) {
797 return false;
798 } else {
799 return true;
800 }
801 }
802
803public:
804 PrivateConfigurableBroker(std::string name): gs::ConfigurableBroker(name)
805 {
806 m_name = hierarchical_name();
807 m_name_length = m_name.length();
808
809 auto uncon = m_parent.get_unconsumed_preset_values(
810 [&](const std::pair<std::string, cci_value>& iv) { return iv.first.find(m_name + ".") == 0; });
811 for (auto p : uncon) {
812 parent.insert(p.first);
813 }
814 }
815
816 virtual std::vector<cci_name_value_pair> get_unconsumed_preset_values() const override
817 {
818 std::vector<cci_name_value_pair> r;
819 for (const auto& u : m_unignored) {
820 auto value_it = m_unignored_values.find(u);
821 r.emplace_back(u, value_it != m_unignored_values.end() ? value_it->second : get_preset_cci_value(u));
822 }
823 return r;
824 }
825 cci_preset_value_range get_unconsumed_preset_values(const cci_preset_value_predicate& pred) const override
826 {
827 std::vector<cci_name_value_pair> values;
828 for (const auto& name : m_unignored) {
829 auto value_it = m_unignored_values.find(name);
830 cci_name_value_pair value(
831 name, value_it != m_unignored_values.end() ? value_it->second : get_preset_cci_value(name));
832 values.emplace_back(std::move(value));
833 }
834 return cci_preset_value_range(pred, values);
835 }
836};
837
838void cci_clear_unused(cci::cci_broker_handle broker, std::string name);
839
840template <typename T>
841std::vector<T> cci_get_vector(cci::cci_broker_handle broker, const std::string base)
842{
843 std::vector<T> ret;
844 for (std::string s : sc_cci_children(base.c_str())) {
845 if (std::count_if(s.begin(), s.end(), [](unsigned char c) { return std::isdigit(c); })) {
846 ret.push_back(cci_get<T>(broker, base + "." + s));
847 }
848 }
849 return ret;
850}
851
852} // namespace gs
853
858template <>
859struct cci::cci_value_converter<sc_core::sc_object*> {
860 typedef sc_core::sc_object* type;
861 static bool pack(cci::cci_value::reference dst, type const& src)
862 {
863 dst.set_string(src->name());
864 return true;
865 }
866 static bool unpack(type& dst, cci::cci_value::const_reference src)
867 {
868 if (!src.is_string()) {
869 return false;
870 }
871 std::string name;
872 if (!src.try_get(name)) {
873 return false;
874 }
875 sc_assert(name[0] == '&');
876 dst = gs::find_sc_obj(nullptr, name.substr(1));
877 return true;
878 }
879};
880
886template <typename T, typename... U>
887struct cci::cci_value_converter<gs::cci_function<T(U...)>> {
888 typedef gs::cci_function<T(U...)> type;
889 static bool pack(cci::cci_value::reference dst, type const& src)
890 {
891 // unimplemented
892 return false;
893 }
894 static bool unpack(type& dst, cci::cci_value::const_reference src)
895 {
896 // unimplemented
897 return false;
898 }
899};
900
901template <>
902struct cci::cci_value_converter<gs::ConfigurableBroker*> {
903 typedef gs::ConfigurableBroker* type;
904 static bool pack(cci_value::reference dst, type const& src)
905 {
906 dst.set_string(src->name());
907 return true;
908 }
909 static bool unpack(type& dst, cci_value::const_reference src) { return false; }
910};
911
912#endif // CCIUTILS_H
Configurable Broker class, inherits from the 'standard' cci_utils broker, but adds 1/ The ability to ...
Definition cciutils.h:321
ConfigurableBroker(std::initializer_list< cci_name_value_pair > list, std::initializer_list< std::pair< std::string, std::string > > alias_list={}, std::function< void(std::string)> uninitialized_cb=nullptr)
Construct a new Configurable Broker object from list. When constructed with a list of initialised par...
Definition cciutils.h:577
void initialize_params(const std::initializer_list< cci_name_value_pair > &list)
Expose all params that have not been configured.
Definition cciutils.h:424
std::vector< cci::cci_callback_untyped_handle > post_write_cb_vec
Callback Adaptor Objects.
Definition cciutils.h:478
virtual bool sendToParent(const std::string &parname) const
private function to determine if we send to the parent broker or not
Definition cciutils.h:403
void sync_values(cci::cci_param_handle _param_handle_1, cci::cci_param_handle _param_handle_2)
Function for synchronizing the values of cci_parameter of OWNER modules via the PARAM_VALUE_SYNC.
Definition cciutils.h:464
Definition cciutils.h:243
The FactoryMaker carries the type infomation into the constructor functor.
Definition cciutils.h:100
cci_constructor_vl(FactoryMaker< _T, U... > fm)
Construct a new cci constructor vl object The FactoryMaker carries the type info into this constructo...
Definition cciutils.h:119
Basic function container for CCI Packing and unpacking are not supported.
Definition cciutils.h:48
Definition cciutils.h:36
Tool which reads a Lua configuration file and sets parameters.
Definition biflow.cc:10
std::list< std::string > sc_cci_children(sc_core::sc_module_name name)
return a list of 'unconsumed' children from the given module name, can be used inside or outside the ...
Definition cciutils.cc:63
std::vector< T * > find_sc_objects(sc_core::sc_object *m=nullptr)
Helper function to find a sc_objects of a given type.
Definition cciutils.h:160
std::string sc_cci_leaf_name(std::string name)
return the leaf name of the given systemc hierarchical name
Definition cciutils.cc:54
sc_core::sc_object * find_sc_obj(sc_core::sc_object *m, std::string name, bool test=false)
Helper function to find a sc_object by fully qualified name throws SC_ERROR if nothing found.
Definition cciutils.cc:18
std::list< std::string > sc_cci_list_items(sc_core::sc_module_name module_name, std::string list_name)
return a list of 'unconsumed' items in the module matching the base name given, plus '_' and a numeri...
Definition cciutils.cc:90