Minres / SystemC-Components

A SystemC productivity library: https://minres.github.io/SystemC-Components/
https://www.minres.com/#opensource
Apache License 2.0
81 stars 21 forks source link

tlm_target: Allow assigning custom name to socket #46

Closed tk-ka closed 11 months ago

tk-ka commented 11 months ago

When creating multiple tlm_target instances inside one sc_module, all socket member variables will have the same name in the object hierarchy, leading to the warning:

Warning: (W505) object already exists: <some_path>.socket. Latter declaration will be renamed to <some_path>.socket_0
In file: kernel/sc_object_manager.cpp:153

It would be an easy fix to extend the existing constructor with a _socketname argument: https://github.com/Minres/SystemC-Components/blob/7d8a0173b219d684c80ba268086b31027d4a7402/src/components/scc/tlm_target.h#L53 By adding a default value for "socket", the code will remain compatible to existing usages.

tk-ka commented 11 months ago

I attached a reproducer. With pull request #47, use line 13 instead of Line 12 to see the improved behavior (no more warning).

#include "scc/tlm_target.h"
#include <tlm>
#include <tlm_utils/simple_initiator_socket.h>

class TestTarget : sc_core::sc_module {
public:
    scc::tlm_target<32> target1;
    scc::tlm_target<32> target2;
    sc_core::sc_time tlm_target_clk;

    TestTarget(sc_core::sc_module_name name, sc_core::sc_time clk = sc_core::sc_time(0, sc_core::SC_NS))
        : sc_core::sc_module(name), target1(tlm_target_clk), target2(tlm_target_clk), tlm_target_clk(clk) {}
        //: sc_core::sc_module(name), target1(tlm_target_clk, "target1"), target2(tlm_target_clk, "target2"), tlm_target_clk(clk) {}
};

class TestInitiator : sc_core::sc_module {
public:
    tlm_utils::simple_initiator_socket<TestInitiator, 32> isocket1{"isocket1"};
    tlm_utils::simple_initiator_socket<TestInitiator, 32> isocket2{"isocket2"};

    TestInitiator(sc_core::sc_module_name name) : sc_core::sc_module(name) {}
};

int sc_main(int argc, char *argv[]) {
    TestTarget targetmodule("target_module");
    TestInitiator initiatormodule("initiator_module");
    initiatormodule.isocket1.bind(targetmodule.target1.socket);
    initiatormodule.isocket2.bind(targetmodule.target2.socket);
    sc_core::sc_start();
    return 0;
}
eyck commented 11 months ago

Many THX for the report, the PR and the reproducer!