From 77e5968323e76dd8f5dec431cadd95c69d77dc94 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Fri, 14 Mar 2014 11:45:44 +0100 Subject: Added RTLIL::Module::Add{Inv,And,Or,Xor,Mux}Gate API --- kernel/rtlil.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ kernel/rtlil.h | 6 ++++++ 2 files changed, 48 insertions(+) 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 { -- cgit v1.2.3