SILICON
Toggle main menu visibility
Loading...
Searching...
No Matches
projectCircuitResolver.cpp
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
#include "
projectCircuitResolver.hpp
"
19
20
#include <format>
21
#include <stdexcept>
22
23
#include <
core/activeKeyGuard.hpp
>
24
#include <
core/memory.hpp
>
25
#include <
core/projectContext.hpp
>
26
#include <
core/serialization/component_registry.hpp
>
27
28
namespace
SILICON::project
{
29
30
ProjectCircuitResolver::ProjectCircuitResolver
(
31
const
ProjectContext
&
project
,
const
SILICON::core::ComponentRegistry
&
registry
)
32
:
project
(
project
),
registry
(
registry
)
33
{
34
}
35
36
SILICON::core::SubcircuitDefinition
37
ProjectCircuitResolver::resolve
(
const
std::string_view slug)
const
38
{
39
SILICON::core::ActiveKeyGuard
activeSlug(
activeSlugs
, std::string(slug),
40
"Recursive subcircuit dependency detected: "
);
41
42
const
auto
path =
documentPathForSlug
(
DocumentType::Circuit
, slug);
43
const
auto
* document =
project
.documents().find(path);
44
if
(!document)
45
throw
std::runtime_error(std::format(
"Unknown subcircuit slug '{}'"
, slug));
46
47
auto
definition =
48
SILICON::core::parseCircuitDocument
(document->getContents(),
registry
,
this
);
49
for
(
const
auto
& [_component, vertex] : definition.circuit.getComponentToVertex()) {
50
const
auto
rom = std::dynamic_pointer_cast<SILICON::core::ROM>(
51
definition.circuit.getComponentByVertexId(vertex));
52
if
(!rom)
53
continue
;
54
55
const
auto
binarySlug = rom->getPropertyValue<std::string>(
"binaryContents"
);
56
rom->refreshBinaryContents(
57
binarySlug ?
binaryContentsSnapshot
(
project
.documents(), *binarySlug) :
nullptr
);
58
}
59
return
definition;
60
}
61
62
}
// namespace SILICON::project
activeKeyGuard.hpp
SILICON::core::ActiveKeyGuard
Definition
activeKeyGuard.hpp:30
SILICON::core::ComponentRegistry
Definition
component_registry.hpp:35
SILICON::project::ProjectCircuitResolver::project
const ProjectContext & project
Definition
projectCircuitResolver.hpp:42
SILICON::project::ProjectCircuitResolver::ProjectCircuitResolver
ProjectCircuitResolver(const ProjectContext &project, const SILICON::core::ComponentRegistry ®istry)
Definition
projectCircuitResolver.cpp:30
SILICON::project::ProjectCircuitResolver::activeSlugs
std::vector< std::string > activeSlugs
Definition
projectCircuitResolver.hpp:44
SILICON::project::ProjectCircuitResolver::resolve
SILICON::core::SubcircuitDefinition resolve(std::string_view slug) const override
Definition
projectCircuitResolver.cpp:37
SILICON::project::ProjectCircuitResolver::registry
const SILICON::core::ComponentRegistry & registry
Definition
projectCircuitResolver.hpp:43
SILICON::project::ProjectContext
Definition
projectContext.hpp:30
component_registry.hpp
memory.hpp
SILICON::core::parseCircuitDocument
SubcircuitDefinition parseCircuitDocument(const std::string_view contents, const ComponentRegistry ®istry, const CircuitResolver *resolver)
Definition
circuitDocument.cpp:75
SILICON::project
Definition
circuitDependencyGraph.cpp:30
SILICON::project::documentPathForSlug
std::string documentPathForSlug(const DocumentType type, const std::string_view slug)
Definition
projectDocument.cpp:191
SILICON::project::DocumentType::Circuit
@ Circuit
Definition
projectDocument.hpp:37
SILICON::project::binaryContentsSnapshot
std::shared_ptr< const std::string > binaryContentsSnapshot(const DocumentStore &documents, const std::string_view slug)
Definition
projectDocument.cpp:309
projectCircuitResolver.hpp
projectContext.hpp
SILICON::core::SubcircuitDefinition
Definition
circuitDocument.hpp:39
src
core
projectCircuitResolver.cpp
Generated by
1.17.0