Skip to content

Commit c89f38c

Browse files
committed
WIP
1 parent a0e2126 commit c89f38c

File tree

6 files changed

+107
-6
lines changed

6 files changed

+107
-6
lines changed

kernel/drivertools.h

+2
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,8 @@ struct DriveChunk
10251025
return marker_.size();
10261026
case DriveType::MULTIPLE:
10271027
return multiple_.size();
1028+
default:
1029+
log_assert(false && "unsupported type");
10281030
}
10291031
}
10301032
};

lol.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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": []}

passes/cmds/Makefile.inc

+1
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ OBJS += passes/cmds/xprop.o
4949
OBJS += passes/cmds/dft_tag.o
5050
OBJS += passes/cmds/future.o
5151
OBJS += passes/cmds/example_dt.o
52+
OBJS += passes/cmds/netlist_from_compute_graph.o

passes/cmds/example_dt.cc

+16-6
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct ExampleDtPass : public Pass
4646
log("\n");
4747
}
4848

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

5252
for (int i = 0; i < compute_graph.size(); ++i) {
@@ -83,14 +83,23 @@ struct ExampleDtPass : public Pass
8383
{"nodes", json_nodes},
8484
{"outputs", json_outputs}
8585
};
86+
std::ofstream outfile(filename);
87+
outfile << json.dump() << std::endl;
8688

87-
return json.dump();
89+
// return json.dump();
8890
}
89-
90-
91+
9192
void execute(std::vector<std::string> args, RTLIL::Design *design) override
92-
{
93-
size_t argidx = 1;
93+
{
94+
size_t argidx;
95+
std::string filename;
96+
for (argidx = 1; argidx < args.size(); argidx++)
97+
{
98+
if (args[argidx] == "-o" && argidx+1 < args.size()) {
99+
filename = args[++argidx];
100+
continue;
101+
}
102+
}
94103
extra_args(args, argidx, design);
95104

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

300+
generate_json(compute_graph, filename);
291301
}
292302
log("Plugin test passed!\n");
293303
}
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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

result

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/nix/store/kxi3i88z8rq3dgywk1p6l5slnp84dyjf-yosys-sanitized

0 commit comments

Comments
 (0)