7 const char *arg_types
[][2] = {
8 { "{dir} [3:0] {name}", "{name}" }, // 00
9 { "{dir} [4:0] {name}", "{name}" }, // 01
10 { "{dir} [5:0] {name}", "{name}" }, // 02
11 { "{dir} signed [3:0] {name}", "{name}" }, // 03
12 { "{dir} signed [4:0] {name}", "{name}" }, // 04
13 { "{dir} signed [5:0] {name}", "{name}" } // 05
31 void strsubst(std::string
&str
, const std::string
&match
, const std::string
&replace
)
34 while ((pos
= str
.find(match
)) != std::string::npos
)
35 str
.replace(pos
, match
.size(), replace
);
41 for (int ai
= 0; ai
< sizeof(arg_types
)/sizeof(arg_types
[0]); ai
++)
42 for (int bi
= 0; bi
< sizeof(arg_types
)/sizeof(arg_types
[0]); bi
++)
43 for (int yi
= 0; yi
< sizeof(arg_types
)/sizeof(arg_types
[0]); yi
++)
44 for (int oi
= 0; oi
< sizeof(ops
)/sizeof(ops
[0]); oi
++)
46 std::string a_decl
= arg_types
[ai
][0];
47 strsubst(a_decl
, "{dir}", "input");
48 strsubst(a_decl
, "{name}", "a");
50 std::string b_decl
= arg_types
[bi
][0];
51 strsubst(b_decl
, "{dir}", "input");
52 strsubst(b_decl
, "{name}", "b");
54 std::string y_decl
= arg_types
[yi
][0];
55 strsubst(y_decl
, "{dir}", "output");
56 strsubst(y_decl
, "{name}", "y");
58 std::string a_ref
= arg_types
[ai
][1];
59 strsubst(a_ref
, "{dir}", "input");
60 strsubst(a_ref
, "{name}", "a");
62 std::string b_ref
= arg_types
[bi
][1];
63 strsubst(b_ref
, "{dir}", "input");
64 strsubst(b_ref
, "{name}", "b");
66 std::string y_ref
= arg_types
[yi
][1];
67 strsubst(y_ref
, "{dir}", "output");
68 strsubst(y_ref
, "{name}", "y");
71 snprintf(buffer
, 1024, "rtl/binary_ops_%02d%02d%02d%02d.v", ai
, bi
, yi
, oi
);
73 FILE *f
= fopen(buffer
, "w");
74 fprintf(f
, "module binary_ops_%02d%02d%02d%02d(a, b, y);\n", ai
, bi
, yi
, oi
);
75 fprintf(f
, "%s;\n", a_decl
.c_str());
76 fprintf(f
, "%s;\n", b_decl
.c_str());
77 fprintf(f
, "%s;\n", y_decl
.c_str());
78 fprintf(f
, "assign %s = %s %s %s;\n", y_ref
.c_str(),
79 a_ref
.c_str(), ops
[oi
], b_ref
.c_str());
80 fprintf(f
, "endmodule\n");