SILICON
Toggle main menu visibility
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
27
namespace
SILICON::core
{
28
30
class
ROM
final :
public
Component
{
31
public
:
32
static
constexpr
std::string_view
Type
=
"ROM"
;
33
34
enum class
Inputs
:
unsigned
int
{
35
Address
= 0,
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."
,
51
ComponentCategory::Memory
};
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
82
private
:
83
std::shared_ptr<const std::string>
content
;
84
bool
contentResolved
=
false
;
85
std::size_t
wordCount
= 0;
86
bool
initializingProperties
=
true
;
87
bool
settingBinaryDocument
=
false
;
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);
93
void
driveState
(
SILICON::simulation::Simulator
& sim,
State
state);
94
[[nodiscard]]
int
configuredDataWidth
()
const
;
95
[[nodiscard]] std::string
configuredBinaryContents
()
const
;
96
};
97
98
}
// namespace SILICON::core
SILICON::core::Bus
Definition
wire.hpp:138
SILICON::core::Component::Component
Component()=default
SILICON::core::ROM::Type
static constexpr std::string_view Type
Definition
memory.hpp:32
SILICON::core::ROM::contentResolved
bool contentResolved
Definition
memory.hpp:84
SILICON::core::ROM::settingBinaryDocument
bool settingBinaryDocument
Definition
memory.hpp:87
SILICON::core::ROM::configure
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
SILICON::core::ROM::configuredDataWidth
int configuredDataWidth() const
Definition
memory.cpp:81
SILICON::core::ROM::Outputs
Outputs
Definition
memory.hpp:40
SILICON::core::ROM::Outputs::Data
@ Data
Definition
memory.hpp:41
SILICON::core::ROM::Inputs
Inputs
Definition
memory.hpp:34
SILICON::core::ROM::Inputs::OE
@ OE
Definition
memory.hpp:37
SILICON::core::ROM::Inputs::CS
@ CS
Definition
memory.hpp:36
SILICON::core::ROM::Inputs::Address
@ Address
Definition
memory.hpp:35
SILICON::core::ROM::configuredBinaryContents
std::string configuredBinaryContents() const
Definition
memory.cpp:86
SILICON::core::ROM::resolvedWordCount
std::size_t resolvedWordCount() const noexcept
Definition
memory.hpp:80
SILICON::core::ROM::metadata
ComponentMetadata metadata() const override
Gets catalog metadata for this component type.
Definition
memory.hpp:48
SILICON::core::ROM::serializeYosys
void serializeYosys(SILICON::yosys::SerializationContext &context) const override
Lower this component into native Yosys netlist cells.
Definition
components.cpp:111
SILICON::core::ROM::ROM
ROM()
Definition
memory.cpp:50
SILICON::core::ROM::wordCount
std::size_t wordCount
Definition
memory.hpp:85
SILICON::core::ROM::initializingProperties
bool initializingProperties
Definition
memory.hpp:86
SILICON::core::ROM::reshapeBuses
void reshapeBuses(int dataWidth, std::size_t words)
Definition
memory.cpp:130
SILICON::core::ROM::typeName
std::string_view typeName() const override
Gets the component type name.
Definition
memory.hpp:47
SILICON::core::ROM::driveState
void driveState(SILICON::simulation::Simulator &sim, State state)
Definition
memory.cpp:186
SILICON::core::ROM::binaryContentsSnapshot
std::shared_ptr< const std::string > binaryContentsSnapshot() const noexcept
Definition
memory.cpp:181
SILICON::core::ROM::content
std::shared_ptr< const std::string > content
Definition
memory.hpp:83
SILICON::core::ROM::simulate
void simulate(SILICON::simulation::Simulator &sim) override
Executes the component's logic.
Definition
memory.cpp:192
SILICON::core::ROM::refreshBinaryContents
void refreshBinaryContents(std::shared_ptr< const std::string > contents)
Definition
memory.cpp:170
SILICON::core::ROM::setBinaryDocument
void setBinaryDocument(std::string slug, std::shared_ptr< const std::string > contents)
Definition
memory.cpp:145
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
Definition
activeKeyGuard.hpp:28
SILICON::core::Wire_ptr
std::shared_ptr< Wire > Wire_ptr
Definition
wire.hpp:116
SILICON::core::ComponentCategory::Memory
@ Memory
Definition
component.hpp:53
SILICON::core::State
State
Definition
wire.hpp:37
SILICON::core::ComponentMetadata
Definition
component.hpp:72
src
core
memory.hpp
Generated by
1.17.0