xilinx/ecp5/ice40: add (* abc9_flop *) to bypass-able cells
[yosys.git] / examples / cxx-api / evaldemo.cc
1 /* A simple Yosys plugin. (Copy&paste from http://stackoverflow.com/questions/32093541/how-does-the-yosys-consteval-api-work)
2
3 Usage example:
4
5 $ cat > evaldemo.v <<EOT
6 module main(input [1:0] A, input [7:0] B, C, D, output [7:0] Y);
7 assign Y = A == 0 ? B : A == 1 ? C : A == 2 ? D : 42;
8 endmodule
9 EOT
10
11 $ yosys-config --build evaldemo.so evaldemo.cc
12 $ yosys -m evaldemo.so -p evaldemo evaldemo.v
13 */
14
15 #include "kernel/yosys.h"
16 #include "kernel/consteval.h"
17
18 USING_YOSYS_NAMESPACE
19 PRIVATE_NAMESPACE_BEGIN
20
21 struct EvalDemoPass : public Pass
22 {
23 EvalDemoPass() : Pass("evaldemo") { }
24
25 void execute(vector<string>, Design *design) YS_OVERRIDE
26 {
27 Module *module = design->top_module();
28
29 if (module == nullptr)
30 log_error("No top module found!\n");
31
32 Wire *wire_a = module->wire(ID::A);
33 Wire *wire_y = module->wire(ID::Y);
34
35 if (wire_a == nullptr)
36 log_error("No wire A found!\n");
37
38 if (wire_y == nullptr)
39 log_error("No wire Y found!\n");
40
41 ConstEval ce(module);
42 for (int v = 0; v < 4; v++) {
43 ce.push();
44 ce.set(wire_a, Const(v, GetSize(wire_a)));
45 SigSpec sig_y = wire_y, sig_undef;
46 if (ce.eval(sig_y, sig_undef))
47 log("Eval results for A=%d: Y=%s\n", v, log_signal(sig_y));
48 else
49 log("Eval failed for A=%d: Missing value for %s\n", v, log_signal(sig_undef));
50 ce.pop();
51 }
52 }
53 } EvalDemoPass;
54
55 PRIVATE_NAMESPACE_END