From: Marcelina Koƛcielnicka Date: Sat, 10 Jul 2021 12:33:16 +0000 (+0200) Subject: cxxrtl: Add support for mem read port initial data. X-Git-Tag: yosys-0.10~113 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=be5cf296997a203cdf195d7355426fa4cd187b49;p=yosys.git cxxrtl: Add support for mem read port initial data. --- diff --git a/backends/cxxrtl/cxxrtl_backend.cc b/backends/cxxrtl/cxxrtl_backend.cc index e6941fda1..b312878c3 100644 --- a/backends/cxxrtl/cxxrtl_backend.cc +++ b/backends/cxxrtl/cxxrtl_backend.cc @@ -686,6 +686,7 @@ struct CxxrtlWorker { dict sigmaps; dict> mod_memories; pool edge_wires; + dict wire_init; dict edge_types; dict> schedule, debug_schedule; dict wire_types, debug_wire_types; @@ -1681,17 +1682,17 @@ struct CxxrtlWorker { f << "<" << wire->width << ">"; } f << " " << mangle(wire); - if (wire->has_attribute(ID::init)) { + if (wire_init.count(wire)) { f << " "; - dump_const_init(wire->attributes.at(ID::init)); + dump_const_init(wire_init.at(wire)); } f << ";\n"; if (edge_wires[wire]) { if (!wire_type.is_buffered()) { f << indent << "value<" << wire->width << "> prev_" << mangle(wire); - if (wire->has_attribute(ID::init)) { + if (wire_init.count(wire)) { f << " "; - dump_const_init(wire->attributes.at(ID::init)); + dump_const_init(wire_init.at(wire)); } f << ";\n"; } @@ -2447,6 +2448,10 @@ struct CxxrtlWorker { continue; } + for (auto wire : module->wires()) + if (wire->has_attribute(ID::init)) + wire_init[wire] = wire->attributes.at(ID::init); + // Construct a flow graph where each node is a basic computational operation generally corresponding // to a fragment of the RTLIL netlist. FlowGraph flow; @@ -2491,6 +2496,19 @@ struct CxxrtlWorker { if (is_valid_clock(port.clk)) register_edge_signal(sigmap, port.clk, port.clk_polarity ? RTLIL::STp : RTLIL::STn); + // For read ports, also move initial value to wire_init (if any). + for (int i = 0; i < GetSize(port.data); i++) { + if (port.init_value[i] != State::Sx) { + SigBit bit = port.data[i]; + if (bit.wire) { + auto &init = wire_init[bit.wire]; + if (init == RTLIL::Const()) { + init = RTLIL::Const(State::Sx, GetSize(bit.wire)); + } + init[bit.offset] = port.init_value[i]; + } + } + } } for (auto &port : mem.wr_ports) { if (port.clk_enable)