SILICON
Loading...
Searching...
No Matches
memory.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 <cstddef>
21#include <memory>
22#include <string>
23#include <string_view>
24
25#include <core/component.hpp>
26
27namespace SILICON::core {
28
30class ROM final : public Component {
31public:
32 static constexpr std::string_view Type = "ROM";
33
34 enum class Inputs : unsigned int {
36 CS = 1,
37 OE = 2,
38 };
39
40 enum class Outputs : unsigned int {
41 Data = 0,
42 };
43
44 ROM();
45 ROM(Bus address, Wire_ptr chipSelect, Wire_ptr outputEnable, Bus data);
46
47 [[nodiscard]] std::string_view typeName() const override { return Type; }
48 [[nodiscard]] ComponentMetadata metadata() const override
49 {
50 return {"ROM", "Reads packed words from a project binary document.",
52 }
53
54 void simulate(SILICON::simulation::Simulator& sim) override;
55 void serializeYosys(SILICON::yosys::SerializationContext& context) const override;
56
63 void setBinaryDocument(std::string slug, std::shared_ptr<const std::string> contents);
64
71 void refreshBinaryContents(std::shared_ptr<const std::string> contents);
72
74 void refreshBinaryContents(std::shared_ptr<const std::string> contents,
75 std::size_t words);
76
78 [[nodiscard]] std::shared_ptr<const std::string>
79 binaryContentsSnapshot() const noexcept;
80 [[nodiscard]] std::size_t resolvedWordCount() const noexcept { return wordCount; }
81
82private:
83 std::shared_ptr<const std::string> content;
84 bool contentResolved = false;
85 std::size_t wordCount = 0;
88
89 void configure(int dataWidth, std::shared_ptr<const std::string> contents,
90 bool rejectInvalid, bool reshape, bool preferAddressDepth = false,
91 std::size_t explicitWords = 0);
92 void reshapeBuses(int dataWidth, std::size_t words);
94 [[nodiscard]] int configuredDataWidth() const;
95 [[nodiscard]] std::string configuredBinaryContents() const;
96};
97
98} // namespace SILICON::core
static constexpr std::string_view Type
Definition memory.hpp:32
bool settingBinaryDocument
Definition memory.hpp:87
void configure(int dataWidth, std::shared_ptr< const std::string > contents, bool rejectInvalid, bool reshape, bool preferAddressDepth=false, std::size_t explicitWords=0)
Definition memory.cpp:91
int configuredDataWidth() const
Definition memory.cpp:81
std::string configuredBinaryContents() const
Definition memory.cpp:86
std::size_t resolvedWordCount() const noexcept
Definition memory.hpp:80
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition memory.hpp:48
void serializeYosys(SILICON::yosys::SerializationContext &context) const override
Lower this component into native Yosys netlist cells.
std::size_t wordCount
Definition memory.hpp:85
bool initializingProperties
Definition memory.hpp:86
void reshapeBuses(int dataWidth, std::size_t words)
Definition memory.cpp:130
std::string_view typeName() const override
Gets the component type name.
Definition memory.hpp:47
void driveState(SILICON::simulation::Simulator &sim, State state)
Definition memory.cpp:186
std::shared_ptr< const std::string > binaryContentsSnapshot() const noexcept
Definition memory.cpp:181
std::shared_ptr< const std::string > content
Definition memory.hpp:83
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
Definition memory.cpp:192
void refreshBinaryContents(std::shared_ptr< const std::string > contents)
Definition memory.cpp:170
void setBinaryDocument(std::string slug, std::shared_ptr< const std::string > contents)
Definition memory.cpp:145
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