scc 2025.09
SystemC components library
configurer.h
1/*******************************************************************************
2 * Copyright 2017-2022 MINRES Technologies GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16
17#ifndef _SYSC_CONFIGURER_H_
18#define _SYSC_CONFIGURER_H_
19
20#include "report.h"
21#include "utilities.h"
22#include <cci_configuration>
23#include <regex>
24
30namespace scc {
31
32bool init_cci(std::string name = "Global Broker");
41class configurer : public sc_core::sc_module {
42 struct ConfigHolder;
43
44public:
45 using base_type = sc_core::sc_module;
46 using broker_t = cci::cci_broker_handle;
47 using cci_param_cln = std::vector<std::pair<cci::cci_param_post_write_callback_untyped, std::unique_ptr<cci::cci_param_untyped>>>;
48 enum { NEVER = 0, BEFORE_END_OF_ELABORATION = 1, END_OF_ELABORATION = 2, START_OF_SIMULATION = 4 };
54 configurer(std::string const& filename, unsigned sc_attr_config_phases = BEFORE_END_OF_ELABORATION);
55
56 configurer() = delete;
57
58 configurer(const configurer&) = delete;
59
60 configurer(configurer&&) = delete;
61
63
64 configurer& operator=(const configurer&) = delete;
65
66 configurer& operator=(configurer&&) = delete;
67
68 void read_input_file(std::string const& filename);
73 void configure();
84 void dump_configuration(std::string const& file_name, bool with_description = false, bool complete = true,
85 std::vector<std::string> stop_list = std::vector<std::string>{}) {
86 dump_file_name = file_name;
87 this->with_description = with_description;
88 this->stop_list = stop_list;
89 this->complete = complete;
90 }
91
102 void dump_configuration(std::ostream& os = std::cout, bool as_yaml = true, bool with_description = false, bool complete = true,
103 sc_core::sc_object* obj = nullptr);
113 template <typename T> void set_value(std::string const& hier_name, T value) { set_value(hier_name, cci::cci_value(value)); }
125 void set_value_from_str(const std::string& hier_name, const std::string& value);
133 void set_configuration_value(sc_core::sc_attr_base* attr_base, sc_core::sc_object* owner);
139 static configurer& get() {
140 configurer* inst = dynamic_cast<configurer*>(sc_core::sc_find_object("$$$configurer$$$"));
141 if(!inst)
142 SCCFATAL() << "No configurer instantiated when using it";
143 return *inst;
144 }
145
146protected:
147 unsigned const config_phases;
148 std::string dump_file_name{""};
149 bool with_description{false};
150 bool complete{true};
151 std::vector<std::string> stop_list{};
152 configurer(std::string const& filename, unsigned sc_attr_config_phases, sc_core::sc_module_name nm);
153 void config_check();
154 void before_end_of_elaboration() override {
155 if(config_phases & BEFORE_END_OF_ELABORATION)
156 configure();
157 }
158 void end_of_elaboration() override {
159 if(config_phases & END_OF_ELABORATION)
160 configure();
161 }
162 void start_of_simulation() override;
163 broker_t cci_broker;
164 void set_value(const std::string& hier_name, cci::cci_value value);
165 cci_param_cln cci2sc_attr;
166 cci::cci_originator cci_originator;
167 std::unique_ptr<ConfigHolder> root;
168};
169
170} // namespace scc // end of scc-sysc
172#endif /* _SYSC_CONFIGURER_H_ */
void set_configuration_value(sc_core::sc_attr_base *attr_base, sc_core::sc_object *owner)
void dump_configuration(std::string const &file_name, bool with_description=false, bool complete=true, std::vector< std::string > stop_list=std::vector< std::string >{})
Definition configurer.h:84
void set_value_from_str(const std::string &hier_name, const std::string &value)
configurer(std::string const &filename, unsigned sc_attr_config_phases=BEFORE_END_OF_ELABORATION)
void set_value(std::string const &hier_name, T value)
Definition configurer.h:113
static configurer & get()
Definition configurer.h:139
SCC TLM utilities.