2 * Copyright (c) 2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
35 #include "base/inifile.hh"
36 #include "base/output.hh"
37 #include "mem/mem_object.hh"
38 #include "mem/port.hh"
39 #include "sim/builder.hh"
40 #include "sim/sim_object.hh"
45 * Look up a MemObject port. Helper function for connectPorts().
48 lookupPort(SimObject
*so
, const std::string
&name
, int i
)
50 MemObject
*mo
= dynamic_cast<MemObject
*>(so
);
52 warn("error casting SimObject %s to MemObject", so
->name());
56 Port
*p
= mo
->getPort(name
, i
);
58 warn("error looking up port %s on object %s", name
, so
->name());
64 * Connect the described MemObject ports. Called from Python via SWIG.
67 connectPorts(SimObject
*o1
, const std::string
&name1
, int i1
,
68 SimObject
*o2
, const std::string
&name2
, int i2
)
70 Port
*p1
= lookupPort(o1
, name1
, i1
);
71 Port
*p2
= lookupPort(o2
, name2
, i2
);
73 if (p1
== NULL
|| p2
== NULL
) {
74 warn("connectPorts: port lookup error");
87 static IniFile inifile
;
92 createSimObject(const string
&name
)
94 return SimObjectClass::createObject(inifile(), name
);
98 * Pointer to the Python function that maps names to SimObjects.
100 PyObject
*resolveFunc
= NULL
;
103 * Convert a pointer to the Python object that SWIG wraps around a C++
104 * SimObject pointer back to the actual C++ pointer. See main.i.
106 extern "C" SimObject
*convertSwigSimObjectPtr(PyObject
*);
109 resolveSimObject(const string
&name
)
111 PyObject
*pyPtr
= PyEval_CallFunction(resolveFunc
, "(s)", name
.c_str());
114 panic("resolveSimObject: failure on call to Python for %s", name
);
117 SimObject
*simObj
= convertSwigSimObjectPtr(pyPtr
);
119 panic("resolveSimObject: failure on pointer conversion for %s", name
);
125 * Load config.ini into C++ database. Exported to Python via SWIG;
126 * invoked from m5.instantiate().
129 loadIniFile(PyObject
*_resolveFunc
)
131 resolveFunc
= _resolveFunc
;
132 configStream
= simout
.find("config.out");
134 // The configuration database is now complete; start processing it.
135 inifile().load(simout
.resolve("config.ini"));