summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-03-14 11:45:44 +0100
committerClifford Wolf <clifford@clifford.at>2014-03-14 11:45:44 +0100
commit77e5968323e76dd8f5dec431cadd95c69d77dc94 (patch)
tree0aa9e971cc4773fb62eb0107fe49714988311eb5
parent9a1accf692adfb9f0f505a1f7e7646731fff10d7 (diff)
Added RTLIL::Module::Add{Inv,And,Or,Xor,Mux}Gate API
-rw-r--r--kernel/rtlil.cc42
-rw-r--r--kernel/rtlil.h6
2 files changed, 48 insertions, 0 deletions
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc
index 7259845a..420f528a 100644
--- a/kernel/rtlil.cc
+++ b/kernel/rtlil.cc
@@ -932,6 +932,48 @@ DEF_METHOD(addPmux, "$pmux", 1)
DEF_METHOD(addSafePmux, "$safe_pmux", 1)
#undef DEF_METHOD
+#define DEF_METHOD_2(_func, _type, _P1, _P2) \
+ RTLIL::Cell* RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2) { \
+ RTLIL::Cell *cell = new RTLIL::Cell; \
+ cell->name = name; \
+ cell->type = _type; \
+ cell->connections["\\" #_P1] = sig1; \
+ cell->connections["\\" #_P2] = sig2; \
+ add(cell); \
+ return cell; \
+ }
+#define DEF_METHOD_3(_func, _type, _P1, _P2, _P3) \
+ RTLIL::Cell* RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2, RTLIL::SigSpec sig3) { \
+ RTLIL::Cell *cell = new RTLIL::Cell; \
+ cell->name = name; \
+ cell->type = _type; \
+ cell->connections["\\" #_P1] = sig1; \
+ cell->connections["\\" #_P2] = sig2; \
+ cell->connections["\\" #_P3] = sig3; \
+ add(cell); \
+ return cell; \
+ }
+#define DEF_METHOD_4(_func, _type, _P1, _P2, _P3, _P4) \
+ RTLIL::Cell* RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2, RTLIL::SigSpec sig3, RTLIL::SigSpec sig4) { \
+ RTLIL::Cell *cell = new RTLIL::Cell; \
+ cell->name = name; \
+ cell->type = _type; \
+ cell->connections["\\" #_P1] = sig1; \
+ cell->connections["\\" #_P2] = sig2; \
+ cell->connections["\\" #_P3] = sig3; \
+ cell->connections["\\" #_P4] = sig4; \
+ add(cell); \
+ return cell; \
+ }
+DEF_METHOD_2(addInvGate, "$_INV_", A, Y)
+DEF_METHOD_3(addAndGate, "$_AND_", A, B, Y)
+DEF_METHOD_3(addOrGate, "$_OR_", A, B, Y)
+DEF_METHOD_3(addXorGate, "$_XOR_", A, B, Y)
+DEF_METHOD_4(addMuxGate, "$_MUX_", A, B, S, Y)
+#undef DEF_METHOD_2
+#undef DEF_METHOD_3
+#undef DEF_METHOD_4
+
RTLIL::Cell* RTLIL::Module::addPow(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool a_signed, bool b_signed)
{
RTLIL::Cell *cell = new RTLIL::Cell;
diff --git a/kernel/rtlil.h b/kernel/rtlil.h
index 48f3e392..e55a88eb 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -351,6 +351,12 @@ struct RTLIL::Module {
RTLIL::Cell* addAdff (RTLIL::IdString name, RTLIL::SigSpec sig_clk, RTLIL::SigSpec sig_arst, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q,
RTLIL::Const arst_value, bool clk_polarity = true, bool arst_polarity = true);
RTLIL::Cell* addDlatch (RTLIL::IdString name, RTLIL::SigSpec sig_en, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool en_polarity = true);
+
+ RTLIL::Cell* addInvGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y);
+ RTLIL::Cell* addAndGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y);
+ RTLIL::Cell* addOrGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y);
+ RTLIL::Cell* addXorGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y);
+ RTLIL::Cell* addMuxGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s, RTLIL::SigSpec sig_y);
};
struct RTLIL::Wire {