SILICON
Toggle main menu visibility
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
27
namespace
SILICON::extra
{
28
using namespace
SILICON::core;
29
30
class
WireSplitter
:
public
Component
{
31
private
:
32
void
initializeProperties
();
33
std::vector<std::pair<unsigned int, unsigned int>>
slices
;
34
35
public
:
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."
,
41
ComponentCategory::Utils
};
42
}
43
44
WireSplitter
();
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
59
class
WireMerger
:
public
Component
{
60
private
:
61
void
initializeProperties
();
62
std::vector<unsigned int>
widths
;
63
64
public
:
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."
,
70
ComponentCategory::Utils
};
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
SILICON::core::Bus
Definition
wire.hpp:138
SILICON::core::Component::outputs
std::vector< Bus > outputs
Output buses produced by this component.
Definition
component.hpp:216
SILICON::core::Component::inputs
std::vector< Bus > inputs
Input buses connected to this component.
Definition
component.hpp:213
SILICON::core::Component::Component
Component()=default
SILICON::extra::WireMerger::Type
static constexpr std::string_view Type
Definition
utils.hpp:65
SILICON::extra::WireMerger::setSize
int setSize(int newSize)
Definition
utils.cpp:215
SILICON::extra::WireMerger::metadata
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition
utils.hpp:67
SILICON::extra::WireMerger::serializeYosys
void serializeYosys(SILICON::yosys::SerializationContext &context) const override
Lower this component into native Yosys netlist cells.
Definition
components.cpp:602
SILICON::extra::WireMerger::setWidths
std::string setWidths(const std::string &specification)
Definition
utils.cpp:228
SILICON::extra::WireMerger::typeName
std::string_view typeName() const override
Gets the component type name.
Definition
utils.hpp:66
SILICON::extra::WireMerger::initializeProperties
void initializeProperties()
Definition
utils.cpp:188
SILICON::extra::WireMerger::simulate
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
Definition
utils.cpp:244
SILICON::extra::WireMerger::widths
std::vector< unsigned int > widths
Definition
utils.hpp:62
SILICON::extra::WireMerger::WireMerger
WireMerger()
Definition
utils.cpp:174
SILICON::extra::WireSplitter::Type
static constexpr std::string_view Type
Definition
utils.hpp:36
SILICON::extra::WireSplitter::setSize
int setSize(int newSize)
Definition
utils.cpp:109
SILICON::extra::WireSplitter::outputSlices
std::vector< std::pair< unsigned int, unsigned int > > outputSlices() const
Definition
utils.cpp:148
SILICON::extra::WireSplitter::metadata
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition
utils.hpp:38
SILICON::extra::WireSplitter::serializeYosys
void serializeYosys(SILICON::yosys::SerializationContext &context) const override
Lower this component into native Yosys netlist cells.
Definition
components.cpp:582
SILICON::extra::WireSplitter::setSlices
std::string setSlices(const std::string &specification)
Definition
utils.cpp:128
SILICON::extra::WireSplitter::typeName
std::string_view typeName() const override
Gets the component type name.
Definition
utils.hpp:37
SILICON::extra::WireSplitter::initializeProperties
void initializeProperties()
Definition
utils.cpp:83
SILICON::extra::WireSplitter::simulate
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
Definition
utils.cpp:160
SILICON::extra::WireSplitter::slices
std::vector< std::pair< unsigned int, unsigned int > > slices
Definition
utils.hpp:33
SILICON::extra::WireSplitter::WireSplitter
WireSplitter()
Definition
utils.cpp:70
SILICON::simulation::Simulator
Executes event-driven simulation of a Circuit.
Definition
simulator.hpp:74
SILICON::yosys::SerializationContext
Mutable module-building interface passed to component serializers.
Definition
netlist.hpp:174
component.hpp
SILICON::core::ComponentCategory::Utils
@ Utils
Definition
component.hpp:57
SILICON::extra
Definition
components.cpp:288
SILICON::core::ComponentMetadata
Definition
component.hpp:72
wire.hpp
src
extraComponents
utils.hpp
Generated by
1.17.0