|
| 1 | +#include "kernel/yosys.h" |
| 2 | +#include "kernel/drivertools.h" |
| 3 | +#include "kernel/topo_scc.h" |
| 4 | +#include "kernel/functional.h" |
| 5 | +#include "libs/json11/json11.hpp" |
| 6 | + |
| 7 | +USING_YOSYS_NAMESPACE |
| 8 | +PRIVATE_NAMESPACE_BEGIN |
| 9 | + |
| 10 | +using namespace json11; |
| 11 | + |
| 12 | +struct ExampleFn { |
| 13 | + IdString name; |
| 14 | + dict<IdString, Const> parameters; |
| 15 | + |
| 16 | + ExampleFn(IdString name) : name(name) {} |
| 17 | + ExampleFn(IdString name, dict<IdString, Const> parameters) : name(name), parameters(parameters) {} |
| 18 | + |
| 19 | + bool operator==(ExampleFn const &other) const { |
| 20 | + return name == other.name && parameters == other.parameters; |
| 21 | + } |
| 22 | + |
| 23 | + unsigned int hash() const { |
| 24 | + return mkhash(name.hash(), parameters.hash()); |
| 25 | + } |
| 26 | +}; |
| 27 | + |
| 28 | +typedef ComputeGraph<ExampleFn, int, IdString, IdString> ExampleGraph; |
| 29 | +struct ExampleWorker |
| 30 | +{ |
| 31 | + DriverMap dm; |
| 32 | + Module *module; |
| 33 | + |
| 34 | + ExampleWorker(Module *module) : module(module) { |
| 35 | + dm.celltypes.setup(); |
| 36 | + } |
| 37 | +}; |
| 38 | + |
| 39 | +struct NetlistFromComputeGraphPass : public Pass |
| 40 | +{ |
| 41 | + NetlistFromComputeGraphPass() : Pass("netlist_from_compute_graph", "drivertools example") {} |
| 42 | + |
| 43 | + void help() override |
| 44 | + { |
| 45 | + // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| |
| 46 | + log("\n"); |
| 47 | + } |
| 48 | + |
| 49 | + void execute(std::vector<std::string> args, RTLIL::Design *design) override |
| 50 | + { |
| 51 | + // std::ifstream file(filename); |
| 52 | + // std::string file_contents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); |
| 53 | + // std::string err; |
| 54 | + // json11::Json json = json11::Json::parse(file_contents, err); |
| 55 | + // if (!err.empty()) { |
| 56 | + // log_error("JSON parsing error: %s\n", err.c_str()); |
| 57 | + // return; |
| 58 | + // } |
| 59 | + |
| 60 | + // // Example assumes JSON has a nodes array and outputs array |
| 61 | + // json11::Json::array nodes = json["nodes"].array_items(); |
| 62 | + // json11::Json::array outputs = json["outputs"].array_items(); |
| 63 | + |
| 64 | + // // Process nodes |
| 65 | + // for (auto &node : nodes) { |
| 66 | + // std::string node_type = node["type"].string_value(); |
| 67 | + // std::string node_id = node["id"].string_value(); |
| 68 | + // json11::Json::object parameters = node["parameters"].object_items(); |
| 69 | + |
| 70 | + // if (node_type == "$$input") { |
| 71 | + // // Create an input port in RTLIL |
| 72 | + // RTLIL::Wire *wire = new RTLIL::Wire(); |
| 73 | + // wire->name = RTLIL::IdString(node_id); |
| 74 | + // wire->port_input = true; |
| 75 | + // design->add(wire); |
| 76 | + // } |
| 77 | + // // Handle other node types similarly |
| 78 | + // } |
| 79 | + |
| 80 | + // // Outputs handling could involve setting certain wires as outputs based on the JSON |
| 81 | + |
| 82 | + // log("Imported design from %s\n", filename.c_str()); |
| 83 | + } |
| 84 | +} ExampleDtPass; |
| 85 | + |
| 86 | +PRIVATE_NAMESPACE_END |
0 commit comments