coriolis/hurricane/src/isobar/PyHurricane.cpp

793 lines
35 KiB
C++
Raw Normal View History

2008-03-06 10:46:43 -06:00
// -*- C++ -*-
//
// This file is part of the Coriolis Project.
// Copyright (C) Laboratoire LIP6 - Departement ASIM
// Universite Pierre et Marie Curie
//
// Main contributors :
// Christophe Alexandre <Christophe.Alexandre@lip6.fr>
// Sophie Belloeil <Sophie.Belloeil@lip6.fr>
// Hugo Cl<43>ment <Hugo.Clement@lip6.fr>
// Jean-Paul Chaput <Jean-Paul.Chaput@lip6.fr>
// Damien Dupuis <Damien.Dupuis@lip6.fr>
// Christian Masson <Christian.Masson@lip6.fr>
// Marek Sroka <Marek.Sroka@lip6.fr>
//
// 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
//
// +-----------------------------------------------------------------+
2008-03-06 10:46:43 -06:00
// | 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@lip6.fr |
2008-03-06 10:46:43 -06:00
// | =============================================================== |
// | C++ Module : "./PyHurricane.cpp" |
// +-----------------------------------------------------------------+
2008-03-06 10:46:43 -06:00
#include "hurricane/isobar/PyHurricane.h"
#include "hurricane/isobar/PyBreakpoint.h"
#include "hurricane/isobar/PyUpdateSession.h"
#include "hurricane/isobar/PyDbU.h"
#include "hurricane/isobar/PyPoint.h"
#include "hurricane/isobar/PyBox.h"
#include "hurricane/isobar/PyTransformation.h"
#include "hurricane/isobar/PyDataBase.h"
#include "hurricane/isobar/PyLibrary.h"
#include "hurricane/isobar/PyEntity.h"
#include "hurricane/isobar/PyCell.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyCellCollection.h"
#include "hurricane/isobar/PyLayer.h"
#include "hurricane/isobar/PyLayerMask.h"
#include "hurricane/isobar/PyMaterial.h"
#include "hurricane/isobar/PyBasicLayer.h"
#include "hurricane/isobar/PyRegularLayer.h"
#include "hurricane/isobar/PyContactLayer.h"
#include "hurricane/isobar/PyDiffusionLayer.h"
#include "hurricane/isobar/PyTransistorLayer.h"
#include "hurricane/isobar/PyViaLayer.h"
#include "hurricane/isobar/PyLayerCollection.h"
#include "hurricane/isobar/PyBasicLayerCollection.h"
#include "hurricane/isobar/PyRegularLayerCollection.h"
#include "hurricane/isobar/PyViaLayerCollection.h"
#include "hurricane/isobar/PyPin.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyPinCollection.h"
#include "hurricane/isobar/PyInstance.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyInstanceCollection.h"
#include "hurricane/isobar/PyReference.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyReferenceCollection.h"
#include "hurricane/isobar/PyNet.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyNetCollection.h"
#include "hurricane/isobar/PyNetExternalComponents.h"
#include "hurricane/isobar/PyHyperNet.h"
#include "hurricane/isobar/PyComponent.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyComponentCollection.h"
#include "hurricane/isobar/PyPlug.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyPlugCollection.h"
#include "hurricane/isobar/PySegment.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PySegmentCollection.h"
#include "hurricane/isobar/PyContact.h"
#include "hurricane/isobar/PyHorizontal.h"
#include "hurricane/isobar/PyVertical.h"
2008-11-20 04:56:11 -06:00
#include "hurricane/isobar/PyPad.h"
#include "hurricane/isobar/PyPath.h"
#include "hurricane/isobar/PyOccurrence.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyOccurrenceCollection.h"
#include "hurricane/isobar/PyTechnology.h"
#include "hurricane/isobar/PyQueryMask.h"
#include "hurricane/isobar/PyQuery.h"
#include "hurricane/NetExternalComponents.h"
#include <stddef.h>
2008-03-06 10:46:43 -06:00
namespace Isobar {
2008-03-17 08:54:33 -05:00
#if !defined(__PYTHON_MODULE__)
2008-03-06 10:46:43 -06:00
// +=================================================================+
2008-03-06 10:46:43 -06:00
// | "PyHurricane" Shared Library Code Part |
// +=================================================================+
2008-03-06 10:46:43 -06:00
// +-----------------------------------------------------------------+
2008-03-06 10:46:43 -06:00
// | "PyHurricane" C++ Local Variables |
// +-----------------------------------------------------------------+
2008-03-06 10:46:43 -06:00
namespace {
using namespace std;
// ---------------------------------------------------------------
// Local Variables.
const char* objectTypeRedefinition =
"ConverterState::AddType () :\n\n"
" Attempt to add twice a type with identifier \n";
} // Anonymous namespace.
2008-03-06 10:46:43 -06:00
2008-03-28 04:48:47 -05:00
using namespace Hurricane;
2008-03-06 10:46:43 -06:00
// +-----------------------------------------------------------------+
2008-03-06 10:46:43 -06:00
// | "PyHurricane" C++ Global Variables |
// +-----------------------------------------------------------------+
2008-03-06 10:46:43 -06:00
const char* ConverterState::ObjectType::_inheritStop
2008-03-06 10:46:43 -06:00
= "comp";
ConverterState __cs = ConverterState ();
int __objectOffset = offsetof ( PyPoint, _object );
// +-----------------------------------------------------------------+
2008-03-06 10:46:43 -06:00
// | "PyHurricane" C++ Functions |
// +-----------------------------------------------------------------+
2008-03-06 10:46:43 -06:00
// -------------------------------------------------------------------
// Method : "::ConverterState::ObjectType::PyEqual ()"
bool ConverterState::ObjectType::PyEqual ( PyTypeObject* pyType ) {
if ( _pyType == pyType ) return true;
if ( _idBase[0] == '\0' ) return false;
2008-03-17 08:54:33 -05:00
return ( __cs.getObject(_idBase)->PyEqual(pyType) );
2008-03-06 10:46:43 -06:00
}
// -------------------------------------------------------------------
// Method : "::ConverterState::ObjectType::PyBase ()"
ConverterState::ObjectType* ConverterState::ObjectType::PyBase ( PyTypeObject* pyType )
{
if ( _pyType != pyType ) return NULL;
return ( PyBase() );
}
ConverterState::ObjectType* ConverterState::ObjectType::PyBase ()
{
if ( _idBase[0] == '\0' ) return this;
if ( ! strcmp(_id,_inheritStop) ) return this;
2008-03-17 08:54:33 -05:00
return ( __cs.getObject(_idBase)->PyBase() );
2008-03-06 10:46:43 -06:00
}
// -------------------------------------------------------------------
// Method : "::ConverterState::ObjectType::PyBaseId ()"
char* ConverterState::ObjectType::PyBaseId ( PyTypeObject* pyType )
{
if ( _idBase[0] == '\0' ) return _id;
if ( ! strcmp(_id,_inheritStop) ) return _id;
2008-03-17 08:54:33 -05:00
return ( __cs.getObject(_idBase)->PyBase(pyType)->_id );
2008-03-06 10:46:43 -06:00
}
// -------------------------------------------------------------------
// Destructor : "::ConverterState::~ConverterState ()"
ConverterState::~ConverterState () {
for ( unsigned i=0 ; i < _types.size() ; i++ )
delete _types [ i ];
}
// -------------------------------------------------------------------
2008-11-17 15:55:03 -06:00
// Method : "::ConverterState::addType ()"
2008-03-06 10:46:43 -06:00
void ConverterState::addType ( const char* id
2008-03-06 10:46:43 -06:00
, PyTypeObject* pyType
, const char* name
2008-03-06 10:46:43 -06:00
, bool isPythonType
, const char* idBase ) {
2008-03-06 10:46:43 -06:00
for ( unsigned i=0 ; i < _types.size() ; i++ ) {
if ( ! strcmp ( _types[i]->_id, id ) ) {
//throw Error ( objectTypeRedefinition ); // 04.09.2009 d2 modification so Pharos can run several scripts during one execution
trace << objectTypeRedefinition << endl;
return;
}
2008-03-06 10:46:43 -06:00
}
assert ( strlen ( id ) < 11 );
ObjectType* otype = new ObjectType;
strcpy ( otype->_id, id );
otype->_pyType = pyType;
otype->_name = name;
otype->_isPythonType = isPythonType;
strcpy ( otype->_idBase, idBase );
otype->_index = _types.size();
_types.push_back ( otype );
}
// -------------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Method : "::ConverterState::getObjectType ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
string ConverterState::getObjectType ( string objectsTypes, unsigned n ) {
2008-03-06 10:46:43 -06:00
string temp;
size_t end, head, tail, start;
unsigned element = 0;
end = objectsTypes.size();
if ( end > 0 ) {
for ( head=0 ; head <= end ; head=tail ) {
tail = objectsTypes.find ( ':' , head+1 );
start = head+1;
temp = objectsTypes.substr ( start, tail-start );
if ( n == element )
return temp;
element++;
}
}
return "";
}
// -------------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Method : "::ConverterState::getObjectId ()"
2008-03-06 10:46:43 -06:00
const char* ConverterState::getObjectId ( PyObject* object ) const {
2008-03-06 10:46:43 -06:00
for ( unsigned i=0 ; i < _types.size() ; i++ ) {
if ( ( ! strcmp ( _types[i]->_id, "function" ) ) && ( PyCallable_Check(object) ) )
return ( _types[i]->_id );
if ( ( ! strcmp ( _types[i]->_id, "none" ) ) && ( object == Py_None ) )
return ( _types[i]->_id );
if ( object->ob_type == _types[i]->_pyType ) return ( _types[i]->_id );
}
return ( "unknown" ); // return 'X'
}
// -------------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Method : "::ConverterState::getObject ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
ConverterState::ObjectType* ConverterState::getObject ( char* id ) {
2008-03-06 10:46:43 -06:00
for ( unsigned i=0 ; i < _types.size() ; i++ ) {
if ( ! strcmp ( id, _types[i]->_id ) ) return ( _types[i] );
}
return ( NULL );
}
2008-03-06 10:46:43 -06:00
// -------------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Method : "::ConverterState::getObjectName ()"
2008-03-06 10:46:43 -06:00
const char *ConverterState::getObjectName ( string id ) const {
2008-03-06 10:46:43 -06:00
for ( unsigned i=0 ; i < _types.size() ; i++ ) {
if ( ! strcmp ( id.c_str(), _types[i]->_id ) ) return ( _types[i]->_name );
}
return ( "<Unknown>" );
}
// -------------------------------------------------------------------
2008-11-17 15:55:03 -06:00
// Method : "::ConverterState::init ()"
2008-03-06 10:46:43 -06:00
void ConverterState::init ( const char* function, const char* inheritStop ) {
2008-03-06 10:46:43 -06:00
_objectIds = "";
2008-11-17 15:55:03 -06:00
setFunction ( function );
2008-03-06 10:46:43 -06:00
ObjectType::_inheritStop = inheritStop;
};
2008-03-06 10:46:43 -06:00
// -------------------------------------------------------------------
// Function : "Converter ()"
int Converter ( PyObject* object, void** pArg ) {
ostringstream message;
string unboundObject = "";
ConverterState::ObjectType* baseType;
2008-03-17 08:54:33 -05:00
for ( unsigned i=0 ; i < __cs.getTypes().size() ; i++ ) {
baseType = __cs.getTypes()[i]->PyBase ( object->ob_type );
2008-03-06 10:46:43 -06:00
if ( PyCallable_Check(object) || baseType ) {
*pArg = object;
i = baseType->_index;
2008-11-17 15:55:03 -06:00
__cs.addId ( baseType->_id );
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
if ( ! __cs.getTypes()[i]->_isPythonType ) {
2008-03-06 10:46:43 -06:00
void** member = ( (void**)( (unsigned long)object + __objectOffset ) );
if ( *member == NULL ) {
2008-03-17 08:54:33 -05:00
unboundObject = __cs.getTypes()[i]->_name;
2008-03-06 10:46:43 -06:00
break;
}
}
return ( 1 );
}
}
if ( unboundObject.size() ) {
2008-03-17 08:54:33 -05:00
message << "Attempt to call " << __cs.getFunction()
2008-03-06 10:46:43 -06:00
<< "() with an unbound " << unboundObject << " argument";
PyErr_SetString ( ProxyError, message.str().c_str() );
return ( 0 );
}
2008-03-17 08:54:33 -05:00
message << "Argument " << __cs.getSize() + 1
<< " of call to " << __cs.getFunction()
2008-03-06 10:46:43 -06:00
<< "() is of unmanaged type " << object->ob_type->tp_name;
PyErr_SetString ( ProxyError, message.str().c_str() );
return ( 0 );
}
// -------------------------------------------------------------------
// Function : "ParseOneArg ()"
2008-11-19 11:36:30 -06:00
bool ParseOneArg ( const char* function, PyObject* args, string format, PyObject** arg ) {
2008-03-06 10:46:43 -06:00
ostringstream message;
2008-11-17 15:55:03 -06:00
__cs.init ( function );
if (not PyArg_ParseTuple(args,"O&",Converter,arg)) {
ostringstream m;
m << function << ": Take exactly one argument.";
PyErr_SetString(ConstructorError, m.str().c_str());
return false;
}
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
string firstArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 0 );
string firstArgTypeExp = ConverterState::getObjectType ( format , 0 );
2008-03-06 10:46:43 -06:00
if ( firstArgType != firstArgTypeExp ) {
ostringstream m;
m << function << ": Argument type mismatch, should be:<" << firstArgTypeExp
<< "> not <" << firstArgType << ">";
PyErr_SetString(ConstructorError, m.str().c_str());
return false;
2008-03-06 10:46:43 -06:00
}
return true;
2008-03-06 10:46:43 -06:00
}
// -------------------------------------------------------------------
// Function : "ParseTwoArg ()"
2008-11-19 11:36:30 -06:00
bool ParseTwoArg ( const char* function, PyObject* args, string format, PyObject** arg0, PyObject** arg1 ) {
2008-03-06 10:46:43 -06:00
ostringstream message;
2008-11-17 15:55:03 -06:00
__cs.init ( function );
if (not PyArg_ParseTuple(args,"O&O&",Converter,arg0,Converter,arg1)) {
ostringstream m;
m << function << ": Take exactly two argument.";
PyErr_SetString(ConstructorError, m.str().c_str());
return false;
}
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
string firstArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 0 );
string firstArgTypeExp = ConverterState::getObjectType ( format , 0 );
2008-03-06 10:46:43 -06:00
if ( firstArgType != firstArgTypeExp ) {
ostringstream m;
m << function << ": First argument type mismatch, should be:<" << firstArgTypeExp
<< "> not <" << firstArgType << ">";
PyErr_SetString(ConstructorError, m.str().c_str());
return false;
2008-03-06 10:46:43 -06:00
}
2008-03-17 08:54:33 -05:00
string secondArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 1 );
string secondArgTypeExp = ConverterState::getObjectType ( format , 1 );
2008-03-06 10:46:43 -06:00
if ( secondArgType != secondArgTypeExp ) {
ostringstream m;
m << function << ": Second argument type mismatch, should be:<" << secondArgTypeExp
<< "> not <" << secondArgType << ">";
PyErr_SetString(ConstructorError, m.str().c_str());
return false;
2008-03-06 10:46:43 -06:00
}
return true;
2008-03-06 10:46:43 -06:00
}
// -------------------------------------------------------------------
// Function : "ParseThreeArg ()"
2008-11-19 11:36:30 -06:00
bool ParseThreeArg ( const char* function, PyObject* args, string format, PyObject** arg0, PyObject** arg1, PyObject** arg2 ) {
2008-03-06 10:46:43 -06:00
ostringstream message;
2008-11-17 15:55:03 -06:00
__cs.init ( function );
2008-03-06 10:46:43 -06:00
if ( ! PyArg_ParseTuple(args,"O&O&O&",Converter,arg0,Converter,arg1,Converter,arg2) ) return ( false );
2008-03-17 08:54:33 -05:00
string firstArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 0 );
string firstArgTypeExp = ConverterState::getObjectType ( format , 0 );
2008-03-06 10:46:43 -06:00
if ( firstArgType != firstArgTypeExp ) {
return ( false );
}
2008-03-17 08:54:33 -05:00
string secondArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 1 );
string secondArgTypeExp = ConverterState::getObjectType ( format , 1 );
2008-03-06 10:46:43 -06:00
if ( secondArgType != secondArgTypeExp ) {
PyErr_SetString ( ProxyError, message.str().c_str() );
return ( false );
}
2008-03-17 08:54:33 -05:00
string thirdArgType = ConverterState::getObjectType ( __cs.getObjectIds(), 2 );
string thirdArgTypeExp = ConverterState::getObjectType ( format , 2 );
2008-03-06 10:46:43 -06:00
if ( thirdArgType != thirdArgTypeExp ) {
2008-03-17 08:54:33 -05:00
message << "Third argument of call to " << __cs.getFunction()
2008-03-06 10:46:43 -06:00
<< "() is of unexpected type " << (*arg2)->ob_type->tp_name
2008-03-17 08:54:33 -05:00
<< ", must be of type " << __cs.getObjectName( thirdArgTypeExp );
2008-03-06 10:46:43 -06:00
PyErr_SetString ( ProxyError, message.str().c_str() );
return ( false );
}
return ( true );
}
// +-----------------------------------------------------------------+
2008-03-06 10:46:43 -06:00
// | "PyHurricane" C Global Variables |
// +-----------------------------------------------------------------+
2008-03-06 10:46:43 -06:00
extern "C" {
PyObject* ConstructorError = NULL;
PyObject* ProxyError = NULL;
PyObject* HurricaneError = NULL;
PyObject* CoriolisError = NULL;
PyObject* HurricaneWarning = NULL;
}
# else // End of PyHurricane Shared Library Code Part.
// +=================================================================+
2008-03-06 10:46:43 -06:00
// | "PyHurricane" Python Module Code Part |
// +=================================================================+
2008-03-06 10:46:43 -06:00
extern "C" {
// +-------------------------------------------------------------+
2008-03-06 10:46:43 -06:00
// | "PyHurricane" Module Methods |
// +-------------------------------------------------------------+
static PyObject* PyCommons_trace ( PyObject* self, PyObject* args )
{
HTRY
PyObject* state = NULL;
if (PyArg_ParseTuple(args , "O:Hurricane.trace()", &state)) {
if (PyObject_IsTrue(state)) trace_on ();
else trace_off();
} else {
PyErr_SetString ( ConstructorError, "Bad parameters given to BasicLayer.create()." );
return NULL;
}
HCATCH
Py_RETURN_NONE;
}
2008-03-06 10:46:43 -06:00
static PyMethodDef PyHurricane_Methods[] =
{ { "trace" , PyCommons_trace , METH_VARARGS, "Switch on/off the trace mode (for debugging)." }
, { "DbU_db" , PyDbU_fromDb , METH_VARARGS, "Converts an integer to DbU::Unit (no scale factor)." }
, { "DbU_grid" , PyDbU_fromGrid , METH_VARARGS, "Converts a founder grid to DbU::Unit." }
, { "DbU_lambda" , PyDbU_fromLambda , METH_VARARGS, "Converts a symbolic (lambda) to DbU::Unit." }
, { "DbU_getDb" , PyDbU_toDb , METH_VARARGS, "Converts a DbU::Unit to an integer value (no scale factor)." }
, { "DbU_getGrid" , PyDbU_toGrid , METH_VARARGS, "Converts a DbU::Unit to a to grid founder." }
, { "DbU_getLambda" , PyDbU_toLambda , METH_VARARGS, "Converts a DbU::Unit to a symbolic value (to lambda)." }
, { "DbU_getPhysical" , PyDbU_toPhysical , METH_VARARGS, "Converts a DbU::Unit to a physical value." }
, { "DbU_getOnPhysicalGrid" , PyDbU_getOnPhysicalGrid , METH_VARARGS, "Adjusts a DbU::Unit to physical grid." }
, { "Point" , PyPoint_create , METH_VARARGS, "Creates a new Point." }
, { "Box" , PyBox_create , METH_VARARGS, "Creates a new Box." }
, { "Transformation" , PyTransformation_create , METH_VARARGS, "Creates a new Transformation." }
, { "DataBase" , (PyCFunction)PyDataBase_create , METH_NOARGS , "Creates the DataBase." }
, { "getDataBase" , (PyCFunction)PyDataBase_getDataBase , METH_NOARGS , "Gets the current DataBase." }
, { "Library" , (PyCFunction)PyLibrary_create , METH_VARARGS, "Creates a new Library." }
2010-07-06 05:10:50 -05:00
// , { "getLibrary" , (PyCFunction)PyLibrary_getLibrary , METH_NOARGS , "Gets the current Library." }
, { "Reference" , (PyCFunction)PyReference_create , METH_VARARGS, "Creates a new Reference." }
, { "Cell" , (PyCFunction)PyCell_create , METH_VARARGS, "Creates a new Cell." }
, { "Instance" , (PyCFunction)PyInstance_create , METH_VARARGS, "Creates a new Instance." }
, { "Net" , (PyCFunction)PyNet_create , METH_VARARGS, "Creates a new Net." }
, { "HyperNet" , (PyCFunction)PyHyperNet_create , METH_VARARGS, "Creates a new HyperNet." }
, { "Horizontal" , (PyCFunction)PyHorizontal_create , METH_VARARGS, "Creates a new Horizontal." }
, { "Vertical" , (PyCFunction)PyVertical_create , METH_VARARGS, "Creates a new Vertical." }
, { "Contact" , (PyCFunction)PyContact_create , METH_VARARGS, "Creates a new Contact." }
, { "Pin" , (PyCFunction)PyPin_create , METH_VARARGS, "Creates a new Pin." }
, { "Pad" , (PyCFunction)PyPad_create , METH_VARARGS, "Creates a new Pad." }
, { "Path" , (PyCFunction)PyPath_create , METH_VARARGS, "Creates a new Path." }
, { "Occurrence" , (PyCFunction)PyOccurrence_create , METH_VARARGS, "Creates a new Occurrence." }
, {NULL, NULL, 0, NULL} /* sentinel */
2008-03-06 10:46:43 -06:00
};
// ---------------------------------------------------------------
// Module Initialization : "initHurricane ()"
DL_EXPORT(void) initHurricane () {
trace << "initHurricane()" << endl;
PyUpdateSession_LinkPyType ();
PyDbU_LinkPyType ();
2008-03-06 10:46:43 -06:00
PyPoint_LinkPyType ();
PyBox_LinkPyType ();
PyTransformation_LinkPyType ();
PyDataBase_LinkPyType ();
PyTechnology_LinkPyType ();
PyLibrary_LinkPyType ();
PyEntity_LinkPyType ();
PyLayer_LinkPyType ();
PyLayerMask_LinkPyType ();
PyBasicLayer_LinkPyType ();
PyRegularLayer_LinkPyType ();
PyDiffusionLayer_LinkPyType ();
PyTransistorLayer_LinkPyType ();
PyContactLayer_LinkPyType ();
PyViaLayer_LinkPyType ();
PyLayerCollection_LinkPyType ();
PyBasicLayerCollection_LinkPyType ();
PyRegularLayerCollection_LinkPyType ();
PyViaLayerCollection_LinkPyType ();
PyMaterial_LinkPyType ();
2008-03-06 10:46:43 -06:00
PyPath_LinkPyType ();
PyOccurrence_LinkPyType ();
2008-10-17 12:27:20 -05:00
PyInstanceCollection_LinkPyType ();
PyPlugCollection_LinkPyType ();
PyNetCollection_LinkPyType ();
PyNetExternalComponents_LinkPyType ();
2008-10-17 12:27:20 -05:00
PyCellCollection_LinkPyType ();
PyPinCollection_LinkPyType ();
PySegmentCollection_LinkPyType ();
PyOccurrenceCollection_LinkPyType ();
PyComponentCollection_LinkPyType ();
PyReferenceCollection_LinkPyType ();
2008-03-06 10:46:43 -06:00
PyCell_LinkPyType ();
PyInstance_LinkPyType ();
PyReference_LinkPyType ();
PyNet_LinkPyType ();
PyHyperNet_LinkPyType ();
PyComponent_LinkPyType ();
PySegment_LinkPyType ();
2008-11-20 04:56:11 -06:00
PyPad_LinkPyType ();
2008-03-06 10:46:43 -06:00
PyVertical_LinkPyType ();
PyHorizontal_LinkPyType ();
PyContact_LinkPyType ();
PyPin_LinkPyType ();
PyPlug_LinkPyType ();
PyBreakpoint_LinkPyType ();
PyQuery_LinkPyType ();
PyQueryMask_LinkPyType ();
2008-03-06 10:46:43 -06:00
PYTYPE_READY ( UpdateSession )
PYTYPE_READY ( Point )
PYTYPE_READY ( DbU )
PYTYPE_READY ( Box )
PYTYPE_READY ( Transformation )
PYTYPE_READY ( DataBase )
PYTYPE_READY ( Technology )
PYTYPE_READY ( Library )
PYTYPE_READY ( Entity )
PYTYPE_READY ( Material )
PYTYPE_READY ( Layer )
PYTYPE_READY ( LayerMask )
PYTYPE_READY ( BasicLayerCollection )
PYTYPE_READY ( BasicLayerCollectionLocator )
PYTYPE_READY ( LayerCollection )
PYTYPE_READY ( LayerCollectionLocator )
PYTYPE_READY ( RegularLayerCollection )
PYTYPE_READY ( RegularLayerCollectionLocator )
PYTYPE_READY ( ViaLayerCollection )
PYTYPE_READY ( ViaLayerCollectionLocator )
PYTYPE_READY ( Path )
PYTYPE_READY ( Occurrence )
PYTYPE_READY ( InstanceCollection )
PYTYPE_READY ( InstanceCollectionLocator )
PYTYPE_READY ( PlugCollection )
PYTYPE_READY ( PlugCollectionLocator )
PYTYPE_READY ( NetCollection )
PYTYPE_READY ( NetCollectionLocator )
PYTYPE_READY ( CellCollection )
PYTYPE_READY ( CellCollectionLocator )
PYTYPE_READY ( PinCollection )
PYTYPE_READY ( PinCollectionLocator )
PYTYPE_READY ( SegmentCollection )
PYTYPE_READY ( SegmentCollectionLocator )
PYTYPE_READY ( ComponentCollection )
PYTYPE_READY ( ComponentCollectionLocator )
PYTYPE_READY ( OccurrenceCollection )
PYTYPE_READY ( OccurrenceCollectionLocator )
PYTYPE_READY ( ReferenceCollection )
PYTYPE_READY ( ReferenceCollectionLocator )
PYTYPE_READY ( HyperNet )
PYTYPE_READY ( NetExternalComponents )
PYTYPE_READY ( Breakpoint )
PYTYPE_READY ( Query )
PYTYPE_READY ( QueryMask )
PYTYPE_READY_SUB ( BasicLayer , Layer )
PYTYPE_READY_SUB ( RegularLayer , Layer )
PYTYPE_READY_SUB ( ContactLayer , Layer )
PYTYPE_READY_SUB ( DiffusionLayer , Layer )
PYTYPE_READY_SUB ( TransistorLayer, Layer )
PYTYPE_READY_SUB ( ViaLayer , Layer )
PYTYPE_READY_SUB ( Cell , Entity )
PYTYPE_READY_SUB ( Instance , Entity )
PYTYPE_READY_SUB ( Reference , Entity )
PYTYPE_READY_SUB ( Net , Entity )
PYTYPE_READY_SUB ( Component , Entity )
PYTYPE_READY_SUB ( Segment , Component)
PYTYPE_READY_SUB ( Horizontal , Segment )
PYTYPE_READY_SUB ( Vertical , Segment )
PYTYPE_READY_SUB ( Contact , Component)
PYTYPE_READY_SUB ( Pin , Contact )
PYTYPE_READY_SUB ( Plug , Component)
PYTYPE_READY_SUB ( Pad , Component)
2008-03-06 10:46:43 -06:00
// Identifier string can take up to 10 characters !
__cs.addType ( "box" , &PyTypeBox , "<Box>" , false );
__cs.addType ( "ent" , &PyTypeEntity , "<Entity>" , false );
__cs.addType ( "cell" , &PyTypeCell , "<Cell>" , false, "ent" );
__cs.addType ( "cellCol" , &PyTypeCellCollection , "<CellCollection>" , false );
__cs.addType ( "comp" , &PyTypeComponent , "<Component>" , false, "ent" );
__cs.addType ( "compCol" , &PyTypeComponentCollection , "<ComponentCollection>" , false );
__cs.addType ( "contact" , &PyTypeContact , "<Contact>" , false, "comp" );
2010-07-06 05:10:50 -05:00
// Do not change the "none" string. It's hardwired to the None object.
__cs.addType ( "none" , Py_None->ob_type , "<None>" , true );
__cs.addType ( "float" , &PyFloat_Type , "<Float>" , true );
__cs.addType ( "int" , &PyInt_Type , "<Int>" , true );
__cs.addType ( "bool" , &PyBool_Type , "<Bool>" , true );
__cs.addType ( "string" , &PyString_Type , "<String>" , true );
__cs.addType ( "list" , &PyList_Type , "<List>" , true );
2008-03-06 10:46:43 -06:00
// Do not change the "function" string. It's hardwired to callable (function) objects.
__cs.addType ( "function" , NULL , "<Function>" , true );
__cs.addType ( "horiz" , &PyTypeHorizontal , "<Horizontal>" , false, "segment" );
__cs.addType ( "inst" , &PyTypeInstance , "<Instance>" , false, "ent" );
__cs.addType ( "instCol" , &PyTypeInstanceCollection , "<InstanceCollection>" , false );
__cs.addType ( "mat" , &PyTypeMaterial , "<Material>" , false );
__cs.addType ( "basicLayer" , &PyTypeBasicLayer , "<BasicLayer>" , false, "layer" );
__cs.addType ( "regLayer" , &PyTypeRegularLayer , "<RegularLayer>" , false, "layer" );
__cs.addType ( "contLayer" , &PyTypeContactLayer , "<ContactLayer>" , false, "layer" );
__cs.addType ( "diffLayer" , &PyTypeDiffusionLayer , "<DiffusionLayer>" , false, "layer" );
__cs.addType ( "tranLayer" , &PyTypeTransistorLayer , "<TransistorLayer>" , false, "layer" );
__cs.addType ( "viaLayer" , &PyTypeViaLayer , "<ViaLayer>" , false, "layer" );
__cs.addType ( "layerColl" , &PyTypeLayerCollection , "<LayerCollection>" , false );
__cs.addType ( "blayerColl" , &PyTypeBasicLayerCollection , "<BasicLayerCollection>" , false );
__cs.addType ( "rlayerColl" , &PyTypeRegularLayerCollection, "<RegularLayerCollection>", false );
__cs.addType ( "vlayerColl" , &PyTypeViaLayerCollection , "<ViaLayerCollection>" , false );
__cs.addType ( "layer" , &PyTypeLayer , "<Layer>" , false );
__cs.addType ( "lmask" , &PyTypeLayerMask , "<Layer::Mask>" , false );
__cs.addType ( "library" , &PyTypeLibrary , "<Library>" , false );
__cs.addType ( "ref" , &PyTypeReference , "<Reference>" , false, "ent" );
__cs.addType ( "refCol" , &PyTypeReferenceCollection , "<ReferenceCollection>" , false );
__cs.addType ( "net" , &PyTypeNet , "<Net>" , false, "ent" );
__cs.addType ( "netCol" , &PyTypeNetCollection , "<NetCollection>" , false );
__cs.addType ( "hyperNet" , &PyTypeHyperNet , "<HyperNet>" , false );
__cs.addType ( "pin" , &PyTypePin , "<Pin>" , false, "contact" );
__cs.addType ( "pinCol" , &PyTypePinCollection , "<PinCollection>" , false );
__cs.addType ( "plug" , &PyTypePlug , "<Plug>" , false, "comp" );
__cs.addType ( "plugCol" , &PyTypePlugCollection , "<PlugCollection>" , false );
__cs.addType ( "point" , &PyTypePoint , "<Point>" , false );
__cs.addType ( "segment" , &PyTypeSegment , "<Segment>" , false, "comp" );
__cs.addType ( "pad " , &PyTypePad , "<Pad>" , false, "comp" );
__cs.addType ( "segmentCol" , &PyTypeSegmentCollection , "<SegmentCollection>" , false );
__cs.addType ( "db" , &PyTypeDataBase , "<DataBase>" , false );
__cs.addType ( "techno" , &PyTypeTechnology , "<Technology>" , false );
__cs.addType ( "transfo" , &PyTypeTransformation , "<Transformation>" , false );
__cs.addType ( "vert" , &PyTypeVertical , "<Vertical>" , false, "segment" );
__cs.addType ( "path" , &PyTypePath , "<Path>" , false );
__cs.addType ( "occur" , &PyTypeOccurrence , "<Occurrence>" , false );
__cs.addType ( "occurCol" , &PyTypeOccurrenceCollection , "<OccurrenceCollection>" , false );
__cs.addType ( "query" , &PyTypeQuery , "<Query>" , false );
__cs.addType ( "qmask" , &PyTypeQueryMask , "<Query::Mask>" , false );
2008-03-06 10:46:43 -06:00
PyObject* module = Py_InitModule ( "Hurricane", PyHurricane_Methods );
if ( module == NULL ) {
cerr << "[ERROR]\n"
<< " Failed to initialize Hurricane module." << endl;
return;
}
Py_INCREF ( &PyTypeDbU );
PyModule_AddObject ( module, "DbU" , (PyObject*)&PyTypeDbU );
Py_INCREF ( &PyTypeTechnology );
PyModule_AddObject ( module, "Technology" , (PyObject*)&PyTypeTechnology );
Py_INCREF ( &PyTypeLayer );
PyModule_AddObject ( module, "Layer" , (PyObject*)&PyTypeLayer );
Py_INCREF ( &PyTypeBasicLayer );
PyModule_AddObject ( module, "BasicLayer" , (PyObject*)&PyTypeBasicLayer );
Py_INCREF ( &PyTypeRegularLayer );
PyModule_AddObject ( module, "RegularLayer" , (PyObject*)&PyTypeRegularLayer );
Py_INCREF ( &PyTypeContactLayer );
PyModule_AddObject ( module, "ContactLayer" , (PyObject*)&PyTypeContactLayer );
Py_INCREF ( &PyTypeDiffusionLayer );
PyModule_AddObject ( module, "DiffusionLayer" , (PyObject*)&PyTypeDiffusionLayer );
Py_INCREF ( &PyTypeTransistorLayer );
PyModule_AddObject ( module, "TransistorLayer" , (PyObject*)&PyTypeTransistorLayer );
Py_INCREF ( &PyTypeViaLayer );
PyModule_AddObject ( module, "ViaLayer" , (PyObject*)&PyTypeViaLayer );
Py_INCREF ( &PyTypeContactLayer );
PyModule_AddObject ( module, "ContactLayer" , (PyObject*)&PyTypeContactLayer );
Py_INCREF ( &PyTypeNetExternalComponents );
PyModule_AddObject ( module, "NetExternalComponents", (PyObject*)&PyTypeNetExternalComponents );
Py_INCREF ( &PyTypeUpdateSession );
PyModule_AddObject ( module, "UpdateSession" , (PyObject*)&PyTypeUpdateSession );
Py_INCREF ( &PyTypeBreakpoint );
PyModule_AddObject ( module, "Breakpoint" , (PyObject*)&PyTypeBreakpoint );
Py_INCREF ( &PyTypeQuery );
PyModule_AddObject ( module, "Query" , (PyObject*)&PyTypeQuery );
Py_INCREF ( &PyTypeVertical );
PyModule_AddObject ( module, "PyVertical" , (PyObject*)&PyTypeVertical );
Py_INCREF ( &PyTypeHorizontal );
PyModule_AddObject ( module, "PyHorizontal" , (PyObject*)&PyTypeHorizontal );
Py_INCREF ( &PyTypeContact );
PyModule_AddObject ( module, "PyContact" , (PyObject*)&PyTypeContact );
Py_INCREF ( &PyTypePlug );
PyModule_AddObject ( module, "PyPlug" , (PyObject*)&PyTypePlug );
Py_INCREF ( &PyTypePad );
PyModule_AddObject ( module, "PyPad" , (PyObject*)&PyTypePad );
2008-03-06 10:46:43 -06:00
PyObject* dictionnary = PyModule_GetDict ( module );
ConstructorError = PyErr_NewException ( "hurricane.ConstructorError", NULL, NULL );
ProxyError = PyErr_NewException ( "hurricane.ProxyError" , NULL, NULL );
HurricaneError = PyErr_NewException ( "hurricane.HurricaneError" , NULL, NULL );
HurricaneWarning = PyErr_NewException ( "hurricane.HurricaneWarning", PyExc_Warning, NULL );
PyDict_SetItemString ( dictionnary, "ConstructorError", ConstructorError );
PyDict_SetItemString ( dictionnary, "ProxyError" , ProxyError );
PyDict_SetItemString ( dictionnary, "HurricaneError" , HurricaneError );
DbULoadConstants ( dictionnary );
2008-03-06 10:46:43 -06:00
TransformationLoadConstants ( dictionnary );
NetLoadConstants ( dictionnary );
InstanceLoadConstants ( dictionnary );
PinLoadConstants ( dictionnary );
PyDbU_postModuleInit ();
PyLayer_postModuleInit ();
PyBasicLayer_postModuleInit ();
trace << "Hurricane.so loaded " << (void*)&typeid(string) << endl;
2008-03-06 10:46:43 -06:00
}
} // extern "C".
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
#endif // End of Python Module Code Part.
2008-03-06 10:46:43 -06:00
} // Isobar namespace.