py_interact.cc revision 11793:ef606668d247
112590Sjason@lowepower.com/* 212590Sjason@lowepower.com * Copyright (c) 2003-2005 The Regents of The University of Michigan 312590Sjason@lowepower.com * All rights reserved. 412590Sjason@lowepower.com * 512590Sjason@lowepower.com * Redistribution and use in source and binary forms, with or without 612590Sjason@lowepower.com * modification, are permitted provided that the following conditions are 712590Sjason@lowepower.com * met: redistributions of source code must retain the above copyright 812590Sjason@lowepower.com * notice, this list of conditions and the following disclaimer; 912590Sjason@lowepower.com * redistributions in binary form must reproduce the above copyright 1012590Sjason@lowepower.com * notice, this list of conditions and the following disclaimer in the 1112590Sjason@lowepower.com * documentation and/or other materials provided with the distribution; 1212590Sjason@lowepower.com * neither the name of the copyright holders nor the names of its 1312590Sjason@lowepower.com * contributors may be used to endorse or promote products derived from 1412590Sjason@lowepower.com * this software without specific prior written permission. 1512590Sjason@lowepower.com * 1612590Sjason@lowepower.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712590Sjason@lowepower.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812590Sjason@lowepower.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912590Sjason@lowepower.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012590Sjason@lowepower.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112590Sjason@lowepower.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212590Sjason@lowepower.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312590Sjason@lowepower.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412590Sjason@lowepower.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512590Sjason@lowepower.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612590Sjason@lowepower.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712590Sjason@lowepower.com * 2812590Sjason@lowepower.com * Authors: Nathan Binkert 2912590Sjason@lowepower.com * Steve Reinhardt 3012590Sjason@lowepower.com */ 3112590Sjason@lowepower.com 3212590Sjason@lowepower.com#include "sim/py_interact.hh" 3312590Sjason@lowepower.com 3412590Sjason@lowepower.com#include <Python.h> 3512590Sjason@lowepower.com 3612590Sjason@lowepower.comvoid 3712590Sjason@lowepower.compy_interact() 3812590Sjason@lowepower.com{ 3912590Sjason@lowepower.com PyObject *globals; 4012590Sjason@lowepower.com PyObject *locals; 4112590Sjason@lowepower.com 4212590Sjason@lowepower.com globals = PyEval_GetGlobals(); 4312590Sjason@lowepower.com Py_INCREF(globals); 4412590Sjason@lowepower.com locals = PyDict_New(); 4512590Sjason@lowepower.com PyRun_String("import code", Py_file_input, globals, locals); 4612590Sjason@lowepower.com PyRun_String("code.interact(local=globals())", Py_file_input, 4712590Sjason@lowepower.com globals, locals); 4812590Sjason@lowepower.com Py_DECREF(globals); 4912590Sjason@lowepower.com Py_DECREF(locals); 5012590Sjason@lowepower.com} 5112590Sjason@lowepower.com 5212590Sjason@lowepower.com