Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
RCoeurjoly committed May 22, 2024
1 parent a0e2126 commit c89f38c
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 6 deletions.
2 changes: 2 additions & 0 deletions kernel/drivertools.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,8 @@ struct DriveChunk
return marker_.size();
case DriveType::MULTIPLE:
return multiple_.size();
default:
log_assert(false && "unsupported type");
}
}
};
Expand Down
1 change: 1 addition & 0 deletions lol.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"nodes": [{"connections": [], "id": "0", "parameters": {}, "type": "$$input"}, {"connections": [], "id": "1", "parameters": {}, "type": "$$input"}, {"connections": ["0", "1"], "id": "2", "parameters": {}, "type": "$add"}, {"connections": ["2"], "id": "3", "parameters": {}, "type": "$$cell_output"}, {"connections": ["3"], "id": "4", "parameters": {}, "type": "$$buf"}], "outputs": []}
1 change: 1 addition & 0 deletions passes/cmds/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ OBJS += passes/cmds/xprop.o
OBJS += passes/cmds/dft_tag.o
OBJS += passes/cmds/future.o
OBJS += passes/cmds/example_dt.o
OBJS += passes/cmds/netlist_from_compute_graph.o
22 changes: 16 additions & 6 deletions passes/cmds/example_dt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct ExampleDtPass : public Pass
log("\n");
}

std::string generate_json(const ComputeGraph<ExampleFn, int, IdString, IdString>& compute_graph) {
void generate_json(const ComputeGraph<ExampleFn, int, IdString, IdString>& compute_graph, const std::string& filename) {
Json::array json_nodes;

for (int i = 0; i < compute_graph.size(); ++i) {
Expand Down Expand Up @@ -83,14 +83,23 @@ struct ExampleDtPass : public Pass
{"nodes", json_nodes},
{"outputs", json_outputs}
};
std::ofstream outfile(filename);
outfile << json.dump() << std::endl;

return json.dump();
// return json.dump();
}



void execute(std::vector<std::string> args, RTLIL::Design *design) override
{
size_t argidx = 1;
{
size_t argidx;
std::string filename;
for (argidx = 1; argidx < args.size(); argidx++)
{
if (args[argidx] == "-o" && argidx+1 < args.size()) {
filename = args[++argidx];
continue;
}
}
extra_args(args, argidx, design);

for (auto module : design->selected_modules()) {
Expand Down Expand Up @@ -288,6 +297,7 @@ struct ExampleDtPass : public Pass
log("return %d as %s \n", key.second, log_id(key.first));
}

generate_json(compute_graph, filename);
}
log("Plugin test passed!\n");
}
Expand Down
86 changes: 86 additions & 0 deletions passes/cmds/netlist_from_compute_graph.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "kernel/yosys.h"
#include "kernel/drivertools.h"
#include "kernel/topo_scc.h"
#include "kernel/functional.h"
#include "libs/json11/json11.hpp"

USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN

using namespace json11;

struct ExampleFn {
IdString name;
dict<IdString, Const> parameters;

ExampleFn(IdString name) : name(name) {}
ExampleFn(IdString name, dict<IdString, Const> parameters) : name(name), parameters(parameters) {}

bool operator==(ExampleFn const &other) const {
return name == other.name && parameters == other.parameters;
}

unsigned int hash() const {
return mkhash(name.hash(), parameters.hash());
}
};

typedef ComputeGraph<ExampleFn, int, IdString, IdString> ExampleGraph;
struct ExampleWorker
{
DriverMap dm;
Module *module;

ExampleWorker(Module *module) : module(module) {
dm.celltypes.setup();
}
};

struct NetlistFromComputeGraphPass : public Pass
{
NetlistFromComputeGraphPass() : Pass("netlist_from_compute_graph", "drivertools example") {}

void help() override
{
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
log("\n");
}

void execute(std::vector<std::string> args, RTLIL::Design *design) override

Check warning on line 49 in passes/cmds/netlist_from_compute_graph.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-22.04, clang-11)

unused parameter 'args' [-Wunused-parameter]

Check warning on line 49 in passes/cmds/netlist_from_compute_graph.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-22.04, clang-11)

unused parameter 'design' [-Wunused-parameter]

Check warning on line 49 in passes/cmds/netlist_from_compute_graph.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, clang-14)

unused parameter 'args' [-Wunused-parameter]

Check warning on line 49 in passes/cmds/netlist_from_compute_graph.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, clang-14)

unused parameter 'design' [-Wunused-parameter]

Check warning on line 49 in passes/cmds/netlist_from_compute_graph.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, clang)

unused parameter 'args' [-Wunused-parameter]

Check warning on line 49 in passes/cmds/netlist_from_compute_graph.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, clang)

unused parameter 'design' [-Wunused-parameter]
{
// std::ifstream file(filename);
// std::string file_contents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
// std::string err;
// json11::Json json = json11::Json::parse(file_contents, err);
// if (!err.empty()) {
// log_error("JSON parsing error: %s\n", err.c_str());
// return;
// }

// // Example assumes JSON has a nodes array and outputs array
// json11::Json::array nodes = json["nodes"].array_items();
// json11::Json::array outputs = json["outputs"].array_items();

// // Process nodes
// for (auto &node : nodes) {
// std::string node_type = node["type"].string_value();
// std::string node_id = node["id"].string_value();
// json11::Json::object parameters = node["parameters"].object_items();

// if (node_type == "$$input") {
// // Create an input port in RTLIL
// RTLIL::Wire *wire = new RTLIL::Wire();
// wire->name = RTLIL::IdString(node_id);
// wire->port_input = true;
// design->add(wire);
// }
// // Handle other node types similarly
// }

// // Outputs handling could involve setting certain wires as outputs based on the JSON

// log("Imported design from %s\n", filename.c_str());
}
} ExampleDtPass;

PRIVATE_NAMESPACE_END
1 change: 1 addition & 0 deletions result

0 comments on commit c89f38c

Please sign in to comment.