[This email is in response to a question Andreas asked me off list, but I
wanted to answer it here for posterity and in case anyone (like Nate) wants
to chime in, or in particular can answer what the mysterious code below is
for.]
The original question was whether we can provide the names of ports to the
C++ object constructor (presumably as part of some improved port handling
Andreas has in mind). So the goal is to add something like this to the C++
param struct:
class MemObjectParams {
std::vector<std::string> ports;
std::vector<std::pair<std::string, int> > vectorPorts;
[… other params …]
}
There are two parts to doing this: (1) getting the port fields declared in
the C++ param struct, and (2) populating them with the right information.
The first part is easy, since (at least for what we outlined below) the
declaration is independent of the actual SimObject subclass. The key piece
of code here is the cxx_param_decl() method on the MetaSimObject class in
src/python/m5/SimObject.py. That’s where we iterate through the parameters
defined on the Python SimObject to generate the C++ version of the param
struct. You could just add the ‘ports’ and ‘vectorPorts’ declarations in
the fixed part of that struct, after ‘name’, ‘pyobj’, and ‘eventq’.
The second part is a little more work but still not too bad. The
getCCParams() method on SimObject (in the same file) is where the C++
struct gets populated (via its SWIG wrapper, which is what the ‘%sParams’
thing is about). Strangely it looks like we already add attributes to the
SWIG wrapper for the port names at the end of that function:
port_names = self._ports.keys()
port_names.sort()
for port_name in port_names:
port = self._port_refs.get(port_name, None)
if port != None:
setattr(cc_params, port_name, port)
I have no idea why we do this. It would be interesting to take this code
out and see if anything breaks.
Anyway, you just want to add (or replace) that code with something that
populates the ‘ports’ and ‘vectorPorts’ fields of the cc_params object with
appropriate lists, and then SWIG should take care of packaging that up for
the C++ struct appropriately.
Steve
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev