SILICON
Loading...
Searching...
No Matches
register.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 <string_view>
21#include <vector>
22
23#include <core/component.hpp>
24#include <core/simulator.hpp>
25#include <core/wire.hpp>
26
27namespace SILICON::core {
28
29class Register : public Component {
30public:
31 static constexpr std::string_view Type = "Register";
32 static constexpr std::string_view PARALLEL_TYPE = "Parallel";
33 static constexpr std::string_view SERIAL_TYPE = "Serial";
34
35 enum class Inputs : unsigned int {
36 Data = 0,
37 Clock = 1,
38 Enable = 2,
39 Clear = 3,
40 Load = 4,
41 };
42
43 enum class Outputs : unsigned int {
44 Out = 0,
45 };
46
47 Register();
48 Register(Bus data, Wire_ptr clock, Wire_ptr enable, Wire_ptr clear, Bus output);
49
50 std::string_view typeName() const override { return Type; }
51 ComponentMetadata metadata() const override
52 {
53 return {"Register", "Stores and shifts data while enabled on a positive clock edge.",
55 }
56
57 [[nodiscard]] bool usesStagedSequentialOutputs() const override { return true; }
58
59 int setSize(int size);
60 std::string setInputType(std::string inputType);
61 std::string setOutputType(std::string outputType);
62
64 const SILICON::simulation::Context& context) override;
65 void serializeYosys(SILICON::yosys::SerializationContext& context) const override;
66
67private:
69 void reshapeBuses();
70 void reshapeBuses(int size, const std::string& inputType,
71 const std::string& outputType);
73 void clearState();
74
75 [[nodiscard]] int configuredSize() const;
76 [[nodiscard]] std::string configuredInputType() const;
77 [[nodiscard]] std::string configuredOutputType() const;
78 [[nodiscard]] bool parallelInput() const;
79 [[nodiscard]] bool parallelOutput() const;
80
81 std::vector<State> state;
82};
83
84} // namespace SILICON::core
static constexpr std::string_view Type
Definition register.hpp:31
bool usesStagedSequentialOutputs() const override
Whether zero-delay output writes should be staged during reactive passes.
Definition register.hpp:57
std::string setInputType(std::string inputType)
Definition register.cpp:147
std::vector< State > state
Definition register.hpp:81
void driveOutput(SILICON::simulation::Simulator &sim)
Definition register.cpp:191
int configuredSize() const
Definition register.cpp:79
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition register.hpp:51
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 register.hpp:50
void simulate(SILICON::simulation::Simulator &sim, const SILICON::simulation::Context &context) override
Executes the component's logic with simulator scheduling context.
Definition register.cpp:210
static constexpr std::string_view SERIAL_TYPE
Definition register.hpp:33
std::string setOutputType(std::string outputType)
Definition register.cpp:153
bool parallelOutput() const
Definition register.cpp:99
bool parallelInput() const
Definition register.cpp:94
int setSize(int size)
Definition register.cpp:138
static constexpr std::string_view PARALLEL_TYPE
Definition register.hpp:32
std::string configuredOutputType() const
Definition register.cpp:89
std::string configuredInputType() const
Definition register.cpp:84
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
Context describing why a component is being evaluated.
Definition component.hpp:90