SILICON
Loading...
Searching...
No Matches
io.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 <cstdint>
21#include <string>
22#include <string_view>
23
24#include <core/component.hpp>
25
26namespace SILICON::core {
27
30public:
31 static constexpr std::string_view Type = "ConstantComponent";
32
34 ConstantComponent(Wire_ptr output, BusValue value);
35 ConstantComponent(Bus output, BusValue value);
36
37 int setSize(int newSize);
38 BusValue setValue(const BusValue& value) const;
39
40 std::string_view typeName() const override { return Type; }
41 ComponentMetadata metadata() const override
42 {
43 return {"Constant", "Drives a fixed binary or unknown logic value.",
45 }
46
47 void simulate(SILICON::simulation::Simulator& sim) override;
48 void serializeYosys(SILICON::yosys::SerializationContext& context) const override;
49};
50
52 uint64_t portIdentity;
53
54protected:
55 BoundaryIoComponent(std::vector<Bus> inputs, std::vector<Bus> outputs,
56 std::string name);
57
58public:
60 [[nodiscard]] uint64_t portId() const { return portIdentity; }
61 void setPortId(uint64_t id);
62 void resetPortId();
63 void serializeYosys(SILICON::yosys::SerializationContext& context) const override;
64};
65
68public:
69 static constexpr std::string_view Type = "DummyInputComponent";
70
72 DummyInputComponent(Bus bus, std::string name);
73
74 void setState(const State s)
75 {
76 (void)outputs[0].forceSetCurrentValue({s}, weak_from_this());
77 }
78
79 std::string_view typeName() const override { return Type; }
80 ComponentMetadata metadata() const override
81 {
82 return {"Input", "Provides a user-toggleable one-bit signal.",
84 }
86};
87
90public:
91 static constexpr std::string_view Type = "DummyBusInputComponent";
92
94 DummyBusInputComponent(Bus bus, std::string name);
95
96 int setSize(int newSize);
97 void setBusValue(const BusValue& value)
98 {
99 (void)outputs[0].forceSetCurrentValue(value, weak_from_this());
100 }
101
102 std::string_view typeName() const override { return Type; }
104 {
105 return {"Bus Input", "Provides an editable multi-bit bus value.",
107 }
109};
110
113public:
114 static constexpr std::string_view Type = "DummyOutputComponent";
115
117 DummyOutputComponent(Bus bus, std::string name);
118
119 std::string_view typeName() const override { return Type; }
121 {
122 return {"Output", "Displays the current state of a one-bit signal.",
124 }
126};
127
130public:
131 static constexpr std::string_view Type = "DummyBusOutputComponent";
132
134 DummyBusOutputComponent(Bus bus, std::string name);
135
136 int setSize(int newSize);
137
138 std::string_view typeName() const override { return Type; }
140 {
141 return {"Bus Output", "Displays the current value of a multi-bit bus.",
143 }
145};
146
147} // namespace SILICON::core
void serializeYosys(SILICON::yosys::SerializationContext &context) const override
Lower this component into native Yosys netlist cells.
BoundaryIoComponent(std::vector< Bus > inputs, std::vector< Bus > outputs, std::string name)
Definition io.cpp:130
uint64_t portId() const
Definition io.hpp:60
void setPortId(uint64_t id)
Definition io.cpp:141
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 io.hpp:31
int setSize(int newSize)
Definition io.cpp:97
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition io.hpp:41
void serializeYosys(SILICON::yosys::SerializationContext &context) const override
Lower this component into native Yosys netlist cells.
std::string_view typeName() const override
Gets the component type name.
Definition io.hpp:40
BusValue setValue(const BusValue &value) const
Definition io.cpp:110
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
Definition io.cpp:119
static constexpr std::string_view Type
Definition io.hpp:91
void simulate(SILICON::simulation::Simulator &) override
Executes the component's logic.
Definition io.hpp:108
void setBusValue(const BusValue &value)
Definition io.hpp:97
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition io.hpp:103
std::string_view typeName() const override
Gets the component type name.
Definition io.hpp:102
static constexpr std::string_view Type
Definition io.hpp:131
void simulate(SILICON::simulation::Simulator &) override
Executes the component's logic.
Definition io.hpp:144
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition io.hpp:139
std::string_view typeName() const override
Gets the component type name.
Definition io.hpp:138
static constexpr std::string_view Type
Definition io.hpp:69
void simulate(SILICON::simulation::Simulator &) override
Executes the component's logic.
Definition io.hpp:85
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition io.hpp:80
std::string_view typeName() const override
Gets the component type name.
Definition io.hpp:79
void setState(const State s)
Definition io.hpp:74
static constexpr std::string_view Type
Definition io.hpp:114
void simulate(SILICON::simulation::Simulator &) override
Executes the component's logic.
Definition io.hpp:125
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition io.hpp:120
std::string_view typeName() const override
Gets the component type name.
Definition io.hpp:119
Executes event-driven simulation of a Circuit.
Definition simulator.hpp:74
Mutable module-building interface passed to component serializers.
Definition netlist.hpp:174
std::shared_ptr< Wire > Wire_ptr
Definition wire.hpp:116
std::vector< State > BusValue
Definition wire.hpp:120