|
4 | 4 | #include "backend/wasm/wasm.h" |
5 | 5 | #include "connectionMachineParser.h" |
6 | 6 | #include "scrapMechanicParser.h" |
| 7 | +#include "wasmCompiler.h" |
7 | 8 |
|
8 | 9 | CircuitFileManager::CircuitFileManager(CircuitManager& circuitManager) : circuitManager(circuitManager) { } |
9 | 10 |
|
10 | 11 | std::vector<circuit_id_t> CircuitFileManager::loadFromFile(const std::string& path) { |
11 | 12 | auto iter = filePathToFile.find(path); |
12 | 13 | if (iter != filePathToFile.end()) { |
13 | | - logInfo("Duplicate import detected. skipping file: " + path, "CircuitFileManager"); |
14 | | - std::vector<circuit_id_t> circuitIds; |
15 | | - for (const std::string& uuid : iter->second.UUIDs) { |
16 | | - SharedCircuit circuit = circuitManager.getCircuit(uuid); |
17 | | - if (circuit) { |
18 | | - circuitIds.push_back(circuit->getCircuitId()); |
| 14 | + if (!( |
| 15 | + ((path.size() >= 4 && path.substr(path.size() - 4) == ".wat") || (path.size() >= 5 && path.substr(path.size() - 5) == ".wasm")) || |
| 16 | + ((path.size() >= 4 && path.substr(path.size() - 4) == ".cpp") || (path.size() >= 4 && path.substr(path.size() - 4) == ".zig") || (path.size() >= 3 && path.substr(path.size() - 3) == ".rs")) |
| 17 | + )) { |
| 18 | + logInfo("Duplicate import detected. skipping file: " + path, "CircuitFileManager"); |
| 19 | + std::vector<circuit_id_t> circuitIds; |
| 20 | + for (const std::string& uuid : iter->second.UUIDs) { |
| 21 | + SharedCircuit circuit = circuitManager.getCircuit(uuid); |
| 22 | + if (circuit) { |
| 23 | + circuitIds.push_back(circuit->getCircuitId()); |
| 24 | + } |
19 | 25 | } |
| 26 | + return circuitIds; |
20 | 27 | } |
21 | | - return circuitIds; |
22 | 28 | } |
23 | 29 |
|
24 | 30 | if (path.size() >= 4 && path.substr(path.size() - 4) == ".cir") { |
@@ -47,6 +53,16 @@ std::vector<circuit_id_t> CircuitFileManager::loadFromFile(const std::string& pa |
47 | 53 | } else { |
48 | 54 | logError("Failed to load wasm module", "CircuitFileManager"); |
49 | 55 | } |
| 56 | + } else if ((path.size() >= 4 && path.substr(path.size() - 4) == ".cpp") || (path.size() >= 4 && path.substr(path.size() - 4) == ".zig") || (path.size() >= 3 && path.substr(path.size() - 3) == ".rs")) { |
| 57 | + std::optional<wasmtime::Module> module = WasmCompiler::compileFile(path); |
| 58 | + if (module) { |
| 59 | + const std::string* UUID = circuitManager.getProceduralCircuitManager().createWasmProceduralCircuit(module.value()); |
| 60 | + if (UUID) { |
| 61 | + setSaveFilePath(*UUID, std::filesystem::absolute(std::filesystem::path(path)).generic_string()); |
| 62 | + } |
| 63 | + } else { |
| 64 | + logError("Failed to compile/load wasm module", "CircuitFileManager"); |
| 65 | + } |
50 | 66 | } else if (path.size() >= 5 && path.substr(path.size() - 5) == ".json") { |
51 | 67 | // SM circuit file parser function |
52 | 68 | ScrapMechanicParser parser(*this, circuitManager); |
|
0 commit comments