diff --git a/hurricane/src/hurricane/hurricane/DebugSession.h b/hurricane/src/hurricane/hurricane/DebugSession.h index b193063b..7eb61a86 100644 --- a/hurricane/src/hurricane/hurricane/DebugSession.h +++ b/hurricane/src/hurricane/hurricane/DebugSession.h @@ -1,7 +1,6 @@ - // -*- C++ -*- // -// Copyright (c) BULL S.A. 2000-2009, All Rights Reserved +// Copyright (c) BULL S.A. 2000-2014, All Rights Reserved // // This file is part of Hurricane. // @@ -19,12 +18,7 @@ // License along with Hurricane. If not, see // . // -// =================================================================== -// -// $Id$ -// -// x-----------------------------------------------------------------x -// | | +// +-----------------------------------------------------------------+ // | H U R R I C A N E | // | V L S I B a c k e n d D a t a - B a s e | // | | @@ -32,25 +26,19 @@ // | E-mail : Jean-Paul.Chaput@lip6.fr | // | =============================================================== | // | C++ Header : "./hurricane/DebugSession.h" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// +-----------------------------------------------------------------+ -#ifndef __HURRICANE_DEBUG_SESSION_H__ -#define __HURRICANE_DEBUG_SESSION_H__ +#ifndef HURRICANE_DEBUG_SESSION_H +#define HURRICANE_DEBUG_SESSION_H - -#include -#include - -#include "hurricane/Commons.h" +#include +#include +#include "hurricane/Commons.h" namespace Hurricane { - class Name; class Net; class Cell; @@ -61,7 +49,6 @@ namespace Hurricane { // ------------------------------------------------------------------- // Class : "Hurricane::DebugSession". - class DebugSession { @@ -104,7 +91,6 @@ namespace Hurricane { // Inline Functions. - void DebugSession::open ( const void* symbol, unsigned int traceLevel ) { if ( _singleton->_isTraced(symbol) ) @@ -136,10 +122,10 @@ namespace Hurricane { -} // End of Hurricane namespace. +} // Hurricane namespace. INSPECTOR_P_SUPPORT(Hurricane::DebugSession); -#endif // __HURRICANE_DEBUG_SESSION__ +#endif // HURRICANE_DEBUG_SESSION_H diff --git a/hurricane/src/isobar/CMakeLists.txt b/hurricane/src/isobar/CMakeLists.txt index 1a2e22c7..5af6dd11 100644 --- a/hurricane/src/isobar/CMakeLists.txt +++ b/hurricane/src/isobar/CMakeLists.txt @@ -65,6 +65,7 @@ PyOrientation.cpp PyDbU.cpp PyUpdateSession.cpp + PyDebugSession.cpp PyVertical.cpp PyQueryMask.cpp PyQuery.cpp @@ -127,6 +128,7 @@ hurricane/isobar/PyOrientation.h hurricane/isobar/PyDbU.h hurricane/isobar/PyUpdateSession.h + hurricane/isobar/PyDebugSession.h hurricane/isobar/PyVertical.h hurricane/isobar/PyQueryMask.h hurricane/isobar/PyQuery.h diff --git a/hurricane/src/isobar/PyDebugSession.cpp b/hurricane/src/isobar/PyDebugSession.cpp new file mode 100644 index 00000000..5d9693dd --- /dev/null +++ b/hurricane/src/isobar/PyDebugSession.cpp @@ -0,0 +1,153 @@ +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC 2014-2014, All Rights Reserved +// +// +-----------------------------------------------------------------+ +// | C O R I O L I S | +// | I s o b a r - Hurricane / Python Interface | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | =============================================================== | +// | C++ Module : "./PyDebugSession.cpp" | +// +-----------------------------------------------------------------+ + + +#include "hurricane/isobar/PyDebugSession.h" +#include "hurricane/isobar/PyEntity.h" +#include "hurricane/isobar/PyCell.h" + + +namespace Isobar { + +using namespace Hurricane; + +extern "C" { + + +#define METHOD_HEAD(function) GENERIC_METHOD_HEAD(DebugSession,session,function) + + +// +=================================================================+ +// | "PyDebugSession" Python Module Code Part | +// +=================================================================+ + +#if defined(__PYTHON_MODULE__) + + + static void* PyObject_AsHurricaneSymbol ( PyObject* object ) + { + return (void*)EntityCast( object ); + } + + + static void PyDebugSession_DeAlloc ( PyDebugSession* self ) + { + trace << "PyDebugSession_DeAlloc(" << hex << self << ")" << endl; + } + + + static PyObject* PyDebugSession_open ( PyObject*, PyObject* args ) + { + trace << "PyDebugSession_open()" << endl; + + HTRY + PyObject* pySymbol = NULL; + unsigned int traceLevel = 10000; + if (PyArg_ParseTuple( args + , "OI:DebugSession.open" + , &pySymbol + , &traceLevel + )) { + void* symbol = PyObject_AsHurricaneSymbol( pySymbol ); + if (not symbol) { + Py_RETURN_NONE; + } + DebugSession::open( symbol, traceLevel ); + } else { + PyErr_SetString( ConstructorError, "Bad parameters given to DebugSession.open()." ); + return NULL; + } + HCATCH + + Py_RETURN_NONE; + } + + + static PyObject* PyDebugSession_close ( PyObject* ) + { + trace << "PyDebugSession_close()" << endl; + + HTRY + DebugSession::close (); + HCATCH + + Py_RETURN_NONE; + } + + + static PyObject* PyDebugSession_addToTrace ( PyObject*, PyObject* args ) + { + trace << "PyDebugSession_addToTrace()" << endl; + + HTRY + PyObject* pySymbol = NULL; + char* netName = NULL; + if (PyArg_ParseTuple( args + , "O|s:DebugSession.addToTrace" + , &pySymbol + , &netName + )) { + if (netName) { + if (not IsPyCell(pySymbol)) Py_RETURN_NONE; + Cell* cell = PYCELL_O( pySymbol ); + DebugSession::addToTrace( cell, netName ); + } else { + void* symbol = PyObject_AsHurricaneSymbol( pySymbol ); + if (not symbol) { + Py_RETURN_NONE; + } + DebugSession::addToTrace( symbol ); + } + } else { + PyErr_SetString( ConstructorError, "Bad parameters given to DebugSession.addToTrace()." ); + return NULL; + } + HCATCH + + Py_RETURN_NONE; + } + + + PyMethodDef PyDebugSession_Methods[] = + { { "open" , (PyCFunction)PyDebugSession_open , METH_VARARGS|METH_CLASS + , "Opens a new Debug Session, tracing the given symbol." } + , { "close" , (PyCFunction)PyDebugSession_close , METH_NOARGS|METH_CLASS + , "Closes an Update Session." } + , { "addToTrace", (PyCFunction)PyDebugSession_addToTrace, METH_VARARGS|METH_CLASS + , "Adds a new object to be traced." } + , {NULL, NULL, 0, NULL} /* sentinel */ + }; + + + PyTypeObjectLinkPyTypeWithoutObject(DebugSession,DebugSession) + + +#else // End of Python Module Code Part. + + +// +=================================================================+ +// | "PyDebugSession" Shared Library Code Part | +// +=================================================================+ + + + PyTypeObjectDefinitions(DebugSession) + + +# endif // Shared Library Code Part. + +} // extern "C". + +} // Isobar namespace. + diff --git a/hurricane/src/isobar/PyEntity.cpp b/hurricane/src/isobar/PyEntity.cpp index bbc93b2d..895ec5a5 100644 --- a/hurricane/src/isobar/PyEntity.cpp +++ b/hurricane/src/isobar/PyEntity.cpp @@ -1,8 +1,9 @@ +// -*- C++ -*- // -// $Id: PyEntity.cpp,v 1.8 2007/04/26 13:38:47 d2 Exp $ +// This file is part of the Coriolis Software. +// Copyright (c) UPMC 2010-2014, All Rights Reserved // -// x-----------------------------------------------------------------x -// | | +// +-----------------------------------------------------------------+ // | C O R I O L I S | // | I s o b a r - Hurricane / Python Interface | // | | @@ -10,10 +11,8 @@ // | E-mail : Jean-Paul.Chaput@asim.lip6.fr | // | =============================================================== | // | C++ Module : "./PyEntity.cpp" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// +-----------------------------------------------------------------+ + #include "hurricane/isobar/PyNet.h" #include "hurricane/isobar/PyLayer.h" @@ -34,25 +33,24 @@ namespace Isobar { - using namespace Hurricane; extern "C" { -// x=================================================================x +// +=================================================================+ // | "PyEntity" Python Module Code Part | -// x=================================================================x +// +=================================================================+ #if defined(__PYTHON_MODULE__) #define METHOD_HEAD(function) GENERIC_METHOD_HEAD(Entity,entity,function) - // x-------------------------------------------------------------x + // +-------------------------------------------------------------+ // | "PyEntity" Attribute Methods | - // x-------------------------------------------------------------x + // +-------------------------------------------------------------+ // Standart destroy (Attribute). DBoDestroyAttribute(PyEntity_destroy ,PyEntity) @@ -74,8 +72,6 @@ extern "C" { } - - // --------------------------------------------------------------- // PyEntity Attribute Method table. @@ -87,11 +83,9 @@ extern "C" { }; - - - // x-------------------------------------------------------------x + // +-------------------------------------------------------------+ // | "PyEntity" Object Methods | - // x-------------------------------------------------------------x + // +-------------------------------------------------------------+ DBoDeleteMethod(Entity) PyTypeObjectLinkPyType(Entity) @@ -100,9 +94,9 @@ extern "C" { #else // End of Python Module Code Part. -// x=================================================================x +// +=================================================================+ // | "PyEntity" Shared Library Code Part | -// x=================================================================x +// +=================================================================+ // --------------------------------------------------------------- @@ -156,16 +150,19 @@ extern "C" { PyTypeRootObjectDefinitions(Entity) + // --------------------------------------------------------------- // PyEntity Object Definitions. -#endif // End of Shared Library Code Part. - - -} // End of extern "C". +#endif // Shared Library Code Part. + +} // extern "C". +// +=================================================================+ +// | "PyEntity" Shared Library Code Part | +// +=================================================================+ # if !defined(__PYTHON_MODULE__) @@ -187,5 +184,4 @@ Hurricane::Entity* EntityCast ( PyObject* derivedObject ) { #endif - -} // End of Isobar namespace. +} // Isobar namespace. diff --git a/hurricane/src/isobar/PyHurricane.cpp b/hurricane/src/isobar/PyHurricane.cpp index 67134736..81808d0e 100644 --- a/hurricane/src/isobar/PyHurricane.cpp +++ b/hurricane/src/isobar/PyHurricane.cpp @@ -16,6 +16,7 @@ #include "hurricane/isobar/PyHurricane.h" #include "hurricane/isobar/PyBreakpoint.h" +#include "hurricane/isobar/PyDebugSession.h" #include "hurricane/isobar/PyUpdateSession.h" #include "hurricane/isobar/PyDbU.h" #include "hurricane/isobar/PyPoint.h" @@ -496,6 +497,7 @@ extern "C" { DL_EXPORT(void) initHurricane () { trace << "initHurricane()" << endl; + PyDebugSession_LinkPyType (); PyUpdateSession_LinkPyType (); PyDbU_LinkPyType (); PyPoint_LinkPyType (); @@ -556,6 +558,7 @@ extern "C" { PyQuery_LinkPyType (); PyQueryMask_LinkPyType (); + PYTYPE_READY ( DebugSession ) PYTYPE_READY ( UpdateSession ) PYTYPE_READY ( Point ) PYTYPE_READY ( DbU ) @@ -745,6 +748,8 @@ extern "C" { PyModule_AddObject ( module, "ContactLayer" , (PyObject*)&PyTypeContactLayer ); Py_INCREF ( &PyTypeNetExternalComponents ); PyModule_AddObject ( module, "NetExternalComponents", (PyObject*)&PyTypeNetExternalComponents ); + Py_INCREF ( &PyTypeDebugSession ); + PyModule_AddObject ( module, "DebugSession" , (PyObject*)&PyTypeDebugSession ); Py_INCREF ( &PyTypeUpdateSession ); PyModule_AddObject ( module, "UpdateSession" , (PyObject*)&PyTypeUpdateSession ); Py_INCREF ( &PyTypeBreakpoint ); diff --git a/hurricane/src/isobar/hurricane/isobar/PyDebugSession.h b/hurricane/src/isobar/hurricane/isobar/PyDebugSession.h new file mode 100644 index 00000000..d37c277e --- /dev/null +++ b/hurricane/src/isobar/hurricane/isobar/PyDebugSession.h @@ -0,0 +1,54 @@ +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC 2014-2014, All Rights Reserved +// +// +-----------------------------------------------------------------+ +// | C O R I O L I S | +// | I s o b a r - Hurricane / Python Interface | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | =============================================================== | +// | C++ Header : "./PyDebugSession.h" | +// +-----------------------------------------------------------------+ + + +#ifndef ISOBAR_PY_DEBUG_SESSION_H +#define ISOBAR_PY_DEBUG_SESSION_H + +#include "hurricane/isobar/PyHurricane.h" +#include "hurricane/DebugSession.h" + + +namespace Isobar { + + extern "C" { + +// ------------------------------------------------------------------- +// Python Object : "PyDebugSession". + + typedef struct { + PyObject_HEAD + } PyDebugSession; + + +// ------------------------------------------------------------------- +// Functions & Types exported to "PyHurricane.cpp". + + extern PyTypeObject PyTypeDebugSession; + extern PyMethodDef PyDebugSession_Methods[]; + + extern void PyDebugSession_LinkPyType (); + + +#define IsPyDebugSession(v) ( (v)->ob_type == &PyTypeDebugSession ) +#define PYUPDATESESSION(v) ( (PyDebugSession*)(v) ) +#define PYUPDATESESSION_O(v) ( PY_UPDATE_SESSION(v)->_object ) + + + } // extern "C". + +} // Isobar namespace. + +# endif diff --git a/hurricane/src/isobar/hurricane/isobar/PyEntity.h b/hurricane/src/isobar/hurricane/isobar/PyEntity.h index 0570110e..06279fc7 100644 --- a/hurricane/src/isobar/hurricane/isobar/PyEntity.h +++ b/hurricane/src/isobar/hurricane/isobar/PyEntity.h @@ -1,88 +1,43 @@ - // -*- C++ -*- // -// This file is part of the Coriolis Project. -// Copyright (C) Laboratoire LIP6 - Departement ASIM -// Universite Pierre et Marie Curie +// This file is part of the Coriolis Software. +// Copyright (c) UPMC 2010-2014, All Rights Reserved // -// Main contributors : -// Christophe Alexandre -// Sophie Belloeil -// Hugo Clément -// Jean-Paul Chaput -// Damien Dupuis -// Christian Masson -// Marek Sroka -// -// The Coriolis Project is free software; you can redistribute it -// and/or modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// The Coriolis Project is distributed in the hope that it will be -// useful, but WITHOUT ANY WARRANTY; without even the implied warranty -// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with the Coriolis Project; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -// USA -// -// License-Tag -// Authors-Tag -// =================================================================== -// -// $Id: PyEntity.h,v 1.3 2006/05/03 14:00:02 jpc Exp $ -// -// x-----------------------------------------------------------------x -// | | +// +-----------------------------------------------------------------+ // | C O R I O L I S | // | I s o b a r - Hurricane / Python Interface | // | | -// | Author : Sophie BELLOEIL | -// | E-mail : Sophie.Belloeil@asim.lip6.fr | +// | Author : Sophie BELLOEIL | +// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | // | =============================================================== | -// | C++ Header : "./PyEntity.h" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// | C++ Header : "./hurricane/isobar/PyEntity.h" | +// +-----------------------------------------------------------------+ - - - -#ifndef __PYENTITY__ -#define __PYENTITY__ - +#ifndef ISOBAR_PY_ENTITY_H +#define ISOBAR_PY_ENTITY_H #include "hurricane/isobar/PyHurricane.h" - #include "hurricane/Entity.h" namespace Isobar { - -extern "C" { + extern "C" { // ------------------------------------------------------------------- // Python Object : "PyEntity". - typedef struct { - PyObject_HEAD - Hurricane::Entity* _object; - } PyEntity; - - + typedef struct { + PyObject_HEAD + Hurricane::Entity* _object; + } PyEntity; // ------------------------------------------------------------------- // Functions & Types exported to "PyHurricane.ccp". - extern PyObject* PyEntity_NEW ( Hurricane::Entity* entity ); extern void PyEntity_LinkPyType (); @@ -95,17 +50,12 @@ extern "C" { #define PYENTITY_O(v) ( PYENTITY(v)->_object ) -} // End of extern "C". + } // extern "C". -Hurricane::Entity* EntityCast ( PyObject* derivedObject ); + Hurricane::Entity* EntityCast ( PyObject* derivedObject ); +} // Isobar namespace. - -} // End of Isobar namespace. - - - - -#endif +#endif // ISOBAR_PY_ENTITY_H diff --git a/kite/src/CMakeLists.txt b/kite/src/CMakeLists.txt index e319312b..9ede98c0 100644 --- a/kite/src/CMakeLists.txt +++ b/kite/src/CMakeLists.txt @@ -114,4 +114,7 @@ install ( FILES ${includes} ${mocIncludes} ${pyIncludes} DESTINATION include/coriolis2/kite ) + install ( FILES init/kiteInit.py + DESTINATION ${PYTHON_SITE_PACKAGES}/kite ) + diff --git a/kite/src/KiteEngine.cpp b/kite/src/KiteEngine.cpp index 278555e2..3d2c99e4 100644 --- a/kite/src/KiteEngine.cpp +++ b/kite/src/KiteEngine.cpp @@ -14,9 +14,11 @@ // +-----------------------------------------------------------------+ +#include #include #include #include +#include "vlsisapd/utilities/Path.h" #include "hurricane/DebugSession.h" #include "hurricane/Bug.h" #include "hurricane/Error.h" @@ -30,6 +32,7 @@ #include "hurricane/Instance.h" #include "hurricane/Vertical.h" #include "hurricane/Horizontal.h" +#include "hurricane/viewer/Script.h" #include "crlcore/Measures.h" #include "knik/Vertex.h" #include "knik/Edge.h" @@ -43,6 +46,7 @@ #include "kite/TrackSegment.h" #include "kite/NegociateWindow.h" #include "kite/KiteEngine.h" +#include "kite/PyKiteEngine.h" namespace Kite { @@ -58,6 +62,7 @@ namespace Kite { using std::setprecision; using std::vector; using std::make_pair; + using Hurricane::dbo_ptr; using Hurricane::DebugSession; using Hurricane::tab; using Hurricane::inltrace; @@ -72,6 +77,7 @@ namespace Kite { using Hurricane::Torus; using Hurricane::Layer; using Hurricane::Cell; + using CRL::System; using CRL::addMeasure; using CRL::Measures; using CRL::MeasuresSet; @@ -119,6 +125,27 @@ namespace Kite { } + void KiteEngine::_runKiteInit () + { + Utilities::Path pythonSitePackages = System::getPath("pythonSitePackages"); + Utilities::Path systemConfDir = pythonSitePackages / "kite"; + Utilities::Path systemConfFile = systemConfDir / "kiteInit.py"; + + if (systemConfFile.exists()) { + Isobar::Script::addPath( systemConfDir.string() ); + + dbo_ptr script = Isobar::Script::create( systemConfFile.stem().string() ); + script->addKwArgument( "kite" , (PyObject*)PyKiteEngine_Link(this) ); + script->runFunction ( "kiteHook", getCell() ); + + Isobar::Script::removePath( systemConfDir.string() ); + } else { + cerr << Warning("Kite system configuration file:\n <%s> not found." + ,systemConfFile.string().c_str()) << endl; + } + } + + void KiteEngine::_initDataBase () { ltrace(90) << "KiteEngine::_initDataBase()" << endl; @@ -132,6 +159,7 @@ namespace Kite { buildPowerRails(); protectRoutingPads(); Session::close(); + _runKiteInit(); ltraceout(90); } diff --git a/kite/src/init/kiteInit.py b/kite/src/init/kiteInit.py new file mode 100644 index 00000000..8dc5afac --- /dev/null +++ b/kite/src/init/kiteInit.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +try: + import sys + import os.path + from helpers import ErrorMessage + from helpers import WarningMessage + import Viewer +except ImportError, e: + module = str(e).split()[-1] + + print '[ERROR] The <%s> python module or symbol cannot be loaded.' % module + print ' Please check the integrity of the package.' + sys.exit(1) +except Exception, e: + print '[ERROR] A strange exception occurred while loading the basic Coriolis/Python' + print ' modules. Something may be wrong at Python/C API level.\n' + print ' %s' % e + sys.exit(2) + + +def kiteHook ( **kw ): + kite = None + if kw.has_key('kite'): + kite = kw['kite'] + else: + print ErrorMessage( 3, 'kiteHook(): Must be run from a KiteEngine.' ) + return + + userInit = os.path.join( os.getcwd(), '.coriolis2.kite.py' ) + if (os.path.exists(userInit)): + execfile( userInit ) + return diff --git a/kite/src/kite/KiteEngine.h b/kite/src/kite/KiteEngine.h index 166d4131..2b30afe0 100644 --- a/kite/src/kite/KiteEngine.h +++ b/kite/src/kite/KiteEngine.h @@ -110,6 +110,7 @@ namespace Kite { void runGlobalRouter ( unsigned int mode ); virtual void loadGlobalRouting ( unsigned int method ); virtual void finalizeLayout (); + void _runKiteInit (); void _gutKite (); void _computeCagedConstraints (); TrackElement* _lookup ( Segment* ) const; diff --git a/unicorn/src/UnicornGui.cpp b/unicorn/src/UnicornGui.cpp index 03595f35..21387a98 100644 --- a/unicorn/src/UnicornGui.cpp +++ b/unicorn/src/UnicornGui.cpp @@ -90,7 +90,7 @@ namespace Unicorn { Isobar::Script::removePath( systemConfDir.string() ); } else { - cerr << Warning("System configuration file:\n <%s> not found." + cerr << Warning("Unicorn system configuration file:\n <%s> not found." ,systemConfFile.string().c_str()) << endl; } }