SILICON
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
19
20#include <format>
21#include <stdexcept>
22
24#include <core/memory.hpp>
27
28namespace SILICON::project {
29
35
37ProjectCircuitResolver::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
ProjectCircuitResolver(const ProjectContext &project, const SILICON::core::ComponentRegistry &registry)
SILICON::core::SubcircuitDefinition resolve(std::string_view slug) const override
const SILICON::core::ComponentRegistry & registry
SubcircuitDefinition parseCircuitDocument(const std::string_view contents, const ComponentRegistry &registry, const CircuitResolver *resolver)
std::string documentPathForSlug(const DocumentType type, const std::string_view slug)
std::shared_ptr< const std::string > binaryContentsSnapshot(const DocumentStore &documents, const std::string_view slug)