@@ -27,6 +27,15 @@ namespace lean_export {
2727namespace {
2828using livehd::graph_util::create_typed_node;
2929using livehd::graph_util::set_bits;
30+
31+ // A Memory node as pass.bitwidth leaves it: every port address proven inside
32+ // [0, size) (Bitwidth::check_mem_address). pass.lean writes no certificate for a
33+ // memory without that mark (UnprovenMemoryIsRefused).
34+ auto create_proven_memory (auto & g) {
35+ auto m = create_typed_node (g, Ntype_op::Memory);
36+ m.attr (livehd::attrs::mem_address_proven).set (uint32_t {1 });
37+ return m;
38+ }
3039TEST (DesignScan, OwnsPinsAndPreservesPortDeclarationRoots) {
3140 DesignScan design;
3241 {
@@ -865,7 +874,7 @@ TEST(DesignScan, SynchronousRomRetainsContentsAndEnable) {
865874 io->add_output (" data" , 1 );
866875 io->set_bits (" data" , 8 );
867876 auto g = io->create_graph ();
868- auto memory = create_typed_node (*g, Ntype_op::Memory );
877+ auto memory = create_proven_memory (*g);
869878 set_bits (memory.create_driver_pin (0 ), 8 );
870879 auto policy = [&](std::string_view name, int64_t value) {
871880 auto pin = livehd::graph_util::create_const (*g, *Dlop::create_integer (value));
@@ -886,6 +895,43 @@ TEST(DesignScan, SynchronousRomRetainsContentsAndEnable) {
886895 EXPECT_EQ (cert.sources [0 ].rom_contents , (std::vector<std::string>{" 1" , " 2" , " 3" }));
887896 EXPECT_EQ (cert.nodes .back ().op .kind , Operation::MuxBool);
888897}
898+
899+ // The same ROM WITHOUT pass.bitwidth's address proof (what `--set
900+ // sim.debug=true` leaves): no certificate is written, and the refusal says why.
901+ TEST (DesignScan, UnprovenMemoryIsRefused) {
902+ auto & lib = livehd::Hhds_graph_library::instance (" lgdb_scan_unproven" );
903+ auto io = lib.create_io (" unproven_rom" );
904+ io->add_input (" address" , 1 );
905+ io->set_bits (" address" , 2 );
906+ io->add_input (" enable" , 2 );
907+ io->set_bits (" enable" , 1 );
908+ io->add_output (" data" , 1 );
909+ io->set_bits (" data" , 8 );
910+ auto g = io->create_graph ();
911+ auto memory = create_typed_node (*g, Ntype_op::Memory);
912+ set_bits (memory.create_driver_pin (0 ), 8 );
913+ auto policy = [&](std::string_view name, int64_t value) {
914+ auto pin = livehd::graph_util::create_const (*g, *Dlop::create_integer (value));
915+ pin.connect_sink (memory.create_sink_pin (Ntype::get_sink_pid (Ntype_op::Memory, name)));
916+ };
917+ policy (" bits" , 8 );
918+ policy (" size" , 3 );
919+ policy (" type" , 1 );
920+ policy (" rdport" , 1 );
921+ policy (" initial" , 0x030201 );
922+ g->get_input_pin (" address" ).connect_sink (memory.create_sink_pin (Ntype::get_sink_pid (Ntype_op::Memory, " addr" )));
923+ g->get_input_pin (" enable" ).connect_sink (memory.create_sink_pin (Ntype::get_sink_pid (Ntype_op::Memory, " enable" )));
924+ memory.create_driver_pin (0 ).connect_sink (g->get_output_pin (" data" ));
925+ try {
926+ const auto design = scan_design (*g, {});
927+ (void )build_certificate (design, {});
928+ FAIL () << " a memory pass.bitwidth did not prove was exported" ;
929+ } catch (const std::exception& e) {
930+ EXPECT_NE (std::string (e.what ()).find (" pass.bitwidth did not prove every port address inside [0, size)" ),
931+ std::string::npos)
932+ << e.what ();
933+ }
934+ }
889935// Three transparent wrappers may sit between a primary input and an
890936// asynchronous reset pin: the emitter's arity-1 Or resize, a zero-based
891937// Get_mask window covering the source, and a ONE-BIT Sext. The last is what
@@ -1951,7 +1997,7 @@ std::shared_ptr<hhds::Graph> build_mem_fixture(std::string_view lgdb, bool read_
19511997 auto g = io->create_graph ();
19521998
19531999 // -- the RAM: write port 0, synchronous read port 1, both on clk_a ---------
1954- auto ram = create_typed_node (*g, Ntype_op::Memory );
2000+ auto ram = create_proven_memory (*g);
19552001 const uint32_t wport = read_port_first ? 1 : 0 ;
19562002 const uint32_t rport = 1 - wport;
19572003 // The read port's data output: pin (#write ports + read ordinal) = 1, which
@@ -1989,7 +2035,7 @@ std::shared_ptr<hhds::Graph> build_mem_fixture(std::string_view lgdb, bool read_
19892035 ram.create_driver_pin (1 ).connect_sink (g->get_output_pin (" rdata" ));
19902036
19912037 // -- the ROM on the OTHER domain -----------------------------------------
1992- auto rom = create_typed_node (*g, Ntype_op::Memory );
2038+ auto rom = create_proven_memory (*g);
19932039 set_bits (rom.create_driver_pin (0 ), 8 );
19942040 auto osink = [&](std::string_view n) { return rom.create_sink_pin (Ntype::get_sink_pid (Ntype_op::Memory, n)); };
19952041 auto oconst = [&](std::string_view n, int64_t v) {
@@ -3072,7 +3118,7 @@ TEST(DesignScanClocks, PerReadRowForwardingValueOracle) {
30723118 io->add_output (" rd1" , 2 );
30733119 io->set_bits (" rd1" , 8 );
30743120 auto g = io->create_graph ();
3075- auto mem = create_typed_node (*g, Ntype_op::Memory );
3121+ auto mem = create_proven_memory (*g);
30763122 const auto mstride = static_cast <uint32_t >(Ntype::Memory_port_stride);
30773123 auto sink = [&](std::string_view n, uint32_t port) {
30783124 return mem.create_sink_pin (Ntype::get_sink_pid (Ntype_op::Memory, n) + port * mstride);
@@ -3214,7 +3260,7 @@ TEST(DesignScanClocks, TwoWriteTwoReadCollisionValueOracle) {
32143260 io->add_output (" rd1" , 2 );
32153261 io->set_bits (" rd1" , 8 );
32163262 auto g = io->create_graph ();
3217- auto mem = create_typed_node (*g, Ntype_op::Memory );
3263+ auto mem = create_proven_memory (*g);
32183264 const auto mstride = static_cast <uint32_t >(Ntype::Memory_port_stride);
32193265 auto sink = [&](std::string_view n, uint32_t port) {
32203266 return mem.create_sink_pin (Ntype::get_sink_pid (Ntype_op::Memory, n) + port * mstride);
@@ -3385,7 +3431,7 @@ TEST(DesignScanClocks, WideMatrixHighBitForwardingValueOracle) {
33853431 io->add_output (" rd1" , 2 );
33863432 io->set_bits (" rd1" , 8 );
33873433 auto g = io->create_graph ();
3388- auto mem = create_typed_node (*g, Ntype_op::Memory );
3434+ auto mem = create_proven_memory (*g);
33893435 const auto mstride = static_cast <uint32_t >(Ntype::Memory_port_stride);
33903436 auto sink = [&](std::string_view n, uint32_t port) {
33913437 return mem.create_sink_pin (Ntype::get_sink_pid (Ntype_op::Memory, n) + port * mstride);
@@ -3578,7 +3624,7 @@ MemFix build_mem(hhds::GraphLibrary& lib, const std::string& mod, bool sync_read
35783624 MemFix f;
35793625 f.g = io->create_graph ();
35803626 auto * g = f.g .get ();
3581- f.mem = create_typed_node (*g, Ntype_op::Memory );
3627+ f.mem = create_proven_memory (*g);
35823628 const int stride = static_cast <int >(Ntype::Memory_port_stride);
35833629 auto konst = [&](int64_t v) { return livehd::graph_util::create_const (*g, *Dlop::create_integer (v)); };
35843630 auto global = [&](const char * name, int64_t v) {
@@ -3980,7 +4026,7 @@ std::shared_ptr<hhds::Graph> build_chained_memories(hhds::GraphLibrary& lib, con
39804026 const int stride = static_cast <int >(Ntype::Memory_port_stride);
39814027 auto konst = [&](int64_t v) { return livehd::graph_util::create_const (*g, *Dlop::create_integer (v)); };
39824028 auto build = [&](const hhds::Pin_class& wr_data, hhds::Node_class* out_mem) {
3983- auto mem = create_typed_node (*g, Ntype_op::Memory );
4029+ auto mem = create_proven_memory (*g);
39844030 if (out_mem != nullptr ) {
39854031 *out_mem = mem;
39864032 }
0 commit comments