SILICON
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <core/component.hpp>
21#include <core/wire.hpp>
22#include <string>
23#include <string_view>
24#include <utility>
25#include <vector>
26
27namespace SILICON::extra {
28using namespace SILICON::core;
29
30class WireSplitter : public Component {
31private:
33 std::vector<std::pair<unsigned int, unsigned int>> slices;
34
35public:
36 static constexpr std::string_view Type = "WireSplitter";
37 std::string_view typeName() const override { return Type; }
38 ComponentMetadata metadata() const override
39 {
40 return {"Wire Splitter", "Splits a bus into bits or bus slices.",
42 }
43
45 WireSplitter(Bus input, const std::vector<Bus>& outputs);
46
47 int setSize(int newSize);
48
52 std::string setSlices(const std::string& specification);
53 [[nodiscard]] std::vector<std::pair<unsigned int, unsigned int>> outputSlices() const;
54
55 void simulate(SILICON::simulation::Simulator& sim) override;
56 void serializeYosys(SILICON::yosys::SerializationContext& context) const override;
57};
58
59class WireMerger : public Component {
60private:
62 std::vector<unsigned int> widths;
63
64public:
65 static constexpr std::string_view Type = "WireMerger";
66 std::string_view typeName() const override { return Type; }
67 ComponentMetadata metadata() const override
68 {
69 return {"Wire Merger", "Concatenates bits or buses, least-significant input first.",
71 }
72
73 WireMerger();
74 WireMerger(const std::vector<Bus>& inputs, Bus output);
75
76 int setSize(int newSize);
77
79 std::string setWidths(const std::string& specification);
80
81 void simulate(SILICON::simulation::Simulator& sim) override;
82 void serializeYosys(SILICON::yosys::SerializationContext& context) const override;
83};
84
85} // namespace SILICON::extra
std::vector< Bus > outputs
Output buses produced by this component.
std::vector< Bus > inputs
Input buses connected to this component.
static constexpr std::string_view Type
Definition utils.hpp:65
int setSize(int newSize)
Definition utils.cpp:215
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition utils.hpp:67
void serializeYosys(SILICON::yosys::SerializationContext &context) const override
Lower this component into native Yosys netlist cells.
std::string setWidths(const std::string &specification)
Definition utils.cpp:228
std::string_view typeName() const override
Gets the component type name.
Definition utils.hpp:66
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
Definition utils.cpp:244
std::vector< unsigned int > widths
Definition utils.hpp:62
static constexpr std::string_view Type
Definition utils.hpp:36
int setSize(int newSize)
Definition utils.cpp:109
std::vector< std::pair< unsigned int, unsigned int > > outputSlices() const
Definition utils.cpp:148
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition utils.hpp:38
void serializeYosys(SILICON::yosys::SerializationContext &context) const override
Lower this component into native Yosys netlist cells.
std::string setSlices(const std::string &specification)
Definition utils.cpp:128
std::string_view typeName() const override
Gets the component type name.
Definition utils.hpp:37
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
Definition utils.cpp:160
std::vector< std::pair< unsigned int, unsigned int > > slices
Definition utils.hpp:33
Executes event-driven simulation of a Circuit.
Definition simulator.hpp:74
Mutable module-building interface passed to component serializers.
Definition netlist.hpp:174