Merge branch 'lefdef-out' into 'devel'

Bind DEF/LEF export to Python and make it useful for real processes

See merge request vlsi-eda/coriolis!14
This commit is contained in:
Jean-Paul Chaput 2022-01-14 13:42:39 +00:00
commit 1d839711ad
9 changed files with 456 additions and 26 deletions

View File

@ -32,6 +32,9 @@
#include "hurricane/Cell.h"
#include "hurricane/Library.h"
#include "hurricane/UpdateSession.h"
#include "hurricane/ViaLayer.h"
#include "hurricane/Rectilinear.h"
#include "crlcore/Utilities.h"
#include "crlcore/ToolBox.h"
#include "crlcore/RoutingGauge.h"
@ -108,6 +111,7 @@ namespace {
inline unsigned int getFlags () const;
inline int getStatus () const;
int checkStatus ( int status );
static int writeRouting ( Net*, bool special );
private:
static int _designCbk ( defwCallbackType_e, defiUserData );
static int _designEndCbk ( defwCallbackType_e, defiUserData );
@ -150,7 +154,7 @@ namespace {
int DefDriver::getUnits () { return _units; }
int DefDriver::toDefUnits ( DbU::Unit u ) { return (int)round(DbU::getLambda(u)*getUnits()); }
int DefDriver::toDefUnits ( DbU::Unit u ) { return (int)round(DbU::getGrid(u)); }
DbU::Unit DefDriver::getSliceHeight () { return _sliceHeight; }
DbU::Unit DefDriver::getPitchWidth () { return _pitchWidth; };
inline Cell* DefDriver::getCell () { return _cell; }
@ -178,12 +182,13 @@ namespace {
void DefDriver::toDefCoordinates ( Instance* instance, Transformation transf, int& statusX, int& statusY, int& statusOrient )
{
instance->getTransformation().applyOn( transf );
statusX = toDefUnits ( transf.getTx() );
statusY = toDefUnits ( transf.getTy() );
statusOrient = toDefOrient( transf.getOrientation() );
Transformation inst_transf = instance->getTransformation();
transf.applyOn( inst_transf );
statusX = toDefUnits ( inst_transf.getTx() );
statusY = toDefUnits ( inst_transf.getTy() );
statusOrient = toDefOrient( inst_transf.getOrientation() );
switch ( transf.getOrientation() ) {
switch ( inst_transf.getOrientation() ) {
case Transformation::Orientation::ID: break;
case Transformation::Orientation::R1: break;
case Transformation::Orientation::R2:
@ -218,6 +223,7 @@ namespace {
_sliceHeight = cg->getSliceHeight ();
_pitchWidth = cg->getPitch ();
_units = DbU::toGrid(DbU::fromMicrons(1.0));
_status = defwInitCbk ( _defStream );
if ( _status != 0 ) return;
@ -331,7 +337,7 @@ namespace {
int DefDriver::_technologyCbk ( defwCallbackType_e, defiUserData udata )
{
DefDriver* driver = (DefDriver*)udata;
return driver->checkStatus ( defwTechnology("symbolic") );
return driver->checkStatus ( defwTechnology( getString(driver->getCell()->getLibrary()->getName()).c_str() ) );
}
@ -571,6 +577,73 @@ namespace {
}
int DefDriver::writeRouting ( Net* net, bool special )
{
int status = 0;
int i = 0;
for ( Component *component : net->getComponents() ) {
std::string layer = component->getLayer() ? getString(component->getLayer()->getName()) : "";
if (layer.size() >= 4 && layer.substr(layer.size() - 4) == ".pin")
continue;
if (layer.size() >= 6 && layer.substr(layer.size() - 6) == ".block")
continue;
Segment *seg = dynamic_cast<Segment*>(component);
if (seg) {
status = (special ? defwSpecialNetPathStart : defwNetPathStart)((i++) ? "NEW" : "ROUTED");
if (special) {
status = defwSpecialNetPathLayer(layer.c_str());
status = defwSpecialNetPathWidth(int(toDefUnits(seg->getWidth())));
} else {
status = defwNetPathLayer(layer.c_str(), 0, nullptr);
}
double x[2], y[2];
x[0] = toDefUnits(seg->getSourceX());
y[0] = toDefUnits(seg->getSourceY());
x[1] = toDefUnits(seg->getTargetX());
y[1] = toDefUnits(seg->getTargetY());
status = (special ? defwSpecialNetPathPoint : defwNetPathPoint)(2, x, y);
} else {
Contact *contact = dynamic_cast<Contact*>(component);
if (contact) {
const ViaLayer *viaLayer = dynamic_cast<const ViaLayer*>(contact->getLayer());
if (viaLayer) {
status = (special ? defwSpecialNetPathStart : defwNetPathStart)((i++) ? "NEW" : "ROUTED");
if (special)
status = defwSpecialNetPathLayer(getString(viaLayer->getBottom()->getName()).c_str());
else
status = defwNetPathLayer(getString(viaLayer->getBottom()->getName()).c_str(), 0, nullptr);
double x[1], y[1];
x[0] = toDefUnits(contact->getX());
y[0] = toDefUnits(contact->getY());
status = (special ? defwSpecialNetPathPoint : defwNetPathPoint)(1, x, y);
status = (special ? defwSpecialNetPathVia : defwNetPathVia)(getString(viaLayer->getName()).c_str());
}
} else {
Rectilinear *rl = dynamic_cast<Rectilinear*>(component);
if (rl) {
Box box = rl->getBoundingBox();
status = (special ? defwSpecialNetPathStart : defwNetPathStart)((i++) ? "NEW" : "ROUTED");
if (special)
status = defwSpecialNetPathLayer(layer.c_str());
else
status = defwNetPathLayer(layer.c_str(), 0, nullptr);
double x[1], y[1];
x[0] = toDefUnits(box.getXMin());
y[0] = toDefUnits(box.getYMin());
status = (special ? defwSpecialNetPathPoint : defwNetPathPoint)(1, x, y);
defwNetPathRect(0, 0, toDefUnits(box.getWidth()), toDefUnits(box.getHeight()));
}
}
}
}
if (i > 0)
status = (special ? defwSpecialNetPathEnd : defwNetPathEnd)();
return status;
}
int DefDriver::_netCbk ( defwCallbackType_e, defiUserData udata )
{
DefDriver* driver = (DefDriver*)udata;
@ -600,13 +673,22 @@ namespace {
if ( status != 0 ) return driver->checkStatus(status);
for ( RoutingPad* rp : net->getRoutingPads() ) {
Plug *plug = dynamic_cast<Plug*>(rp->getPlugOccurrence().getEntity());
if (plug) {
status = defwNetConnection ( extractInstanceName(rp).c_str()
, getString(static_cast<Plug*>(rp->getPlugOccurrence().getEntity())->getMasterNet()->getName()).c_str()
, getString(plug->getMasterNet()->getName()).c_str()
, 0
);
} else {
Pin *pin = dynamic_cast<Pin*>(rp->getPlugOccurrence().getEntity());
if (!pin)
throw Error("RP PlugOccurrence neither a plug nor a pin!");
// TODO: do we need to write something ?
}
if ( status != 0 ) return driver->checkStatus(status);
}
status = writeRouting(net, false);
status = defwNetEndOneNet ();
if ( status != 0 ) return driver->checkStatus(status);
}
@ -648,6 +730,9 @@ namespace {
status = defwSpecialNetUse ( netUse );
if ( status != 0 ) return driver->checkStatus(status);
status = writeRouting(*inet, true);
if ( status != 0 ) return driver->checkStatus(status);
status = defwSpecialNetEndOneNet ();
if ( status != 0 ) return driver->checkStatus(status);
}

View File

@ -119,7 +119,7 @@ namespace {
int LefDriver::getUnits () { return _units; }
double LefDriver::toLefUnits ( DbU::Unit u ) { return DbU::getLambda(u)/**getUnits()*/; }
double LefDriver::toLefUnits ( DbU::Unit u ) { return DbU::toMicrons(u)/**getUnits()*/; }
DbU::Unit LefDriver::getSliceHeight () { return _sliceHeight; }
DbU::Unit LefDriver::getPitchWidth () { return _pitchWidth; };
inline AllianceFramework* LefDriver::getFramework () { return _framework; }
@ -144,9 +144,13 @@ namespace {
_pitchWidth = cg->getPitch ();
}
_units = DbU::toGrid(DbU::fromMicrons(1.0));
_status = lefwInitCbk ( _lefStream );
if ( _status != 0 ) return;
lefwSetVersionCbk ( _versionCbk );
lefwSetBusBitCharsCbk ( _busBitCharsCbk );
lefwSetDividerCharCbk ( _dividerCharCbk );
@ -207,7 +211,7 @@ namespace {
_status = lefwLayerRoutingPitch ( toLefUnits(lg->getPitch()) );
if ( _status != 0 ) return _status;
_status = lefwLayerRoutingSpacing ( toLefUnits(lg->getPitch()-lg->getWireWidth()-DbU::lambda(1.0)) );
_status = lefwLayerRoutingSpacing ( toLefUnits(lg->getPitch()-lg->getWireWidth()/*-DbU::lambda(1.0)*/) );
if ( _status != 0 ) return _status;
return _status = lefwEndLayerRouting ( layerName.c_str() );
@ -477,7 +481,13 @@ namespace {
);
if ( status != 0 ) return driver->checkStatus(status);
return driver->checkStatus ( lefwEndUnits() );
status = lefwEndUnits();
status = lefwManufacturingGrid ( LefDriver::toLefUnits(DbU::fromGrid(1.0)) );
if ( status != 0 ) return driver->checkStatus(status);
return driver->checkStatus ( status );
}
@ -491,7 +501,7 @@ namespace {
int status = 0;
for ( size_t ilayer=0 ; ilayer<rg.size() ; ++ilayer ) {
if ( ilayer > 0 ) {
status = driver->_driveCutLayer ( technology->getCutBelow(rg[ilayer]->getLayer()) );
status = driver->_driveCutLayer ( technology->getCutBelow(rg[ilayer]->getLayer(), false) );
if ( status != 0 ) return driver->checkStatus(status);
}
@ -562,14 +572,7 @@ namespace {
int LefDriver::_manufacturingGridCbk ( lefwCallbackType_e, lefiUserData udata )
{
#if 1
// The driver puts it before UNITS, which seems to displease Cadence Encounter.
// So, as long as it doesn't prevent Encounter to works, disable it.
LefDriver* driver = (LefDriver*)udata;
return driver->checkStatus ( lefwManufacturingGrid ( LefDriver::toLefUnits(DbU::fromLambda(0.5)) ) );
#else
return 0;
#endif
}
@ -604,10 +607,12 @@ namespace {
int status = 0;
for ( size_t ilayer=1 ; ilayer<rg.size() ; ++ilayer ) {
const Layer* topLayer = rg[ilayer]->getLayer();
const Layer* bottomLayer = topLayer->getMetalBelow();
const Layer* cutLayer = topLayer->getCutBelow();
const Layer* bottomLayer = topLayer->getMetalBelow(false);
const Layer* cutLayer = topLayer->getCutBelow(false);
const Layer* viaLayer = technology->getViaBetween ( topLayer, bottomLayer );
if ( !viaLayer ) continue;
status = lefwStartVia ( getString(viaLayer->getName()).c_str(), "DEFAULT" );
if ( status != 0 ) return driver->checkStatus(status);

View File

@ -50,6 +50,8 @@
PyGds.cpp
PyLefImport.cpp
PyDefImport.cpp
PyLefExport.cpp
PyDefExport.cpp
)
set( pyIncludes crlcore/PySystem.h
crlcore/PyBanner.h
@ -72,6 +74,8 @@
crlcore/PyGds.h
crlcore/PyLefImport.h
crlcore/PyDefImport.h
crlcore/PyLefExport.h
crlcore/PyDefExport.h
)
# target_link_libraries ( crlcore ${HURRICANE_PYTHON_NEW_LIBRARIES}
# ${HURRICANE_PYTHON_LIBRARIES}

View File

@ -36,7 +36,9 @@
#include "crlcore/PyBlif.h"
#include "crlcore/PyGds.h"
#include "crlcore/PyLefImport.h"
#include "crlcore/PyLefExport.h"
#include "crlcore/PyDefImport.h"
#include "crlcore/PyDefExport.h"
#include "crlcore/VhdlEntity.h"
@ -146,6 +148,8 @@ extern "C" {
PyGds_LinkPyType ();
PyLefImport_LinkPyType ();
PyDefImport_LinkPyType ();
PyLefExport_LinkPyType ();
PyDefExport_LinkPyType ();
PYTYPE_READY ( System );
PYTYPE_READY ( Banner );
@ -169,6 +173,8 @@ extern "C" {
PYTYPE_READY ( Gds );
PYTYPE_READY ( LefImport );
PYTYPE_READY ( DefImport );
PYTYPE_READY ( LefExport );
PYTYPE_READY ( DefExport );
// Identifier string can take up to 10 characters.
__cs.addType ( "alcLib" , &PyTypeAllianceLibrary , "<AllianceLibrary>" , false );
@ -229,6 +235,10 @@ extern "C" {
PyModule_AddObject ( module, "LefImport", (PyObject*)&PyTypeLefImport );
Py_INCREF ( &PyTypeDefImport );
PyModule_AddObject ( module, "DefImport", (PyObject*)&PyTypeDefImport );
Py_INCREF ( &PyTypeLefExport );
PyModule_AddObject ( module, "LefExport", (PyObject*)&PyTypeLefExport );
Py_INCREF ( &PyTypeDefExport );
PyModule_AddObject ( module, "DefExport", (PyObject*)&PyTypeDefExport );
PyCatalog_postModuleInit ();
PyEnvironment_postModuleInit ();

View File

@ -0,0 +1,108 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC 2017-2018, All Rights Reserved
//
// +-----------------------------------------------------------------+
// | C O R I O L I S |
// | Alliance / Hurricane Interface |
// | |
// | Author : Jean-Paul CHAPUT |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Module : "./PyDefExport.cpp" |
// +-----------------------------------------------------------------+
#include "crlcore/PyDefExport.h"
#include "hurricane/isobar/PyCell.h"
#include <string>
#include <sstream>
namespace CRL {
using std::cerr;
using std::endl;
using std::hex;
using std::string;
using std::ostringstream;
using Hurricane::tab;
using Hurricane::Exception;
using Hurricane::Bug;
using Hurricane::Error;
using Hurricane::Warning;
using Hurricane::Cell;
using Isobar::ProxyProperty;
using Isobar::ProxyError;
using Isobar::ConstructorError;
using Isobar::HurricaneError;
using Isobar::HurricaneWarning;
using Isobar::getPyHash;
using Isobar::ParseOneArg;
using Isobar::ParseTwoArg;
using Isobar::__cs;
using Isobar::PyTypeCell;
using Isobar::PyCell;
extern "C" {
#if defined(__PYTHON_MODULE__)
// +=================================================================+
// | "PyDefExport" Python Module Code Part |
// +=================================================================+
static PyObject* PyDefExport_drive ( PyObject*, PyObject* args )
{
cdebug_log(30,0) << "PyDefExport_drive()" << endl;
PyCell* pyCell = NULL;
HTRY
unsigned int flags = 0;
if (PyArg_ParseTuple( args, "O!I:DefExport.drive", &PyTypeCell, &pyCell, &flags)) {
DefExport::drive( PYCELL_O(pyCell) , flags );
} else {
PyErr_SetString ( ConstructorError, "DefExport.drive(): Bad type or bad number of parameters." );
return NULL;
}
HCATCH
Py_RETURN_NONE;
}
// Standart Destroy (Attribute).
PyMethodDef PyDefExport_Methods[] =
{ { "drive" , (PyCFunction)PyDefExport_drive , METH_VARARGS|METH_STATIC
, "Save a complete Cadence DEF design." }
, {NULL, NULL, 0, NULL} /* sentinel */
};
NoObjectDeleteMethod(DefExport)
PyTypeObjectLinkPyTypeWithoutObject(DefExport,DefExport)
#else // End of Python Module Code Part.
// +=================================================================+
// | "PyDefExport" Shared Library Code Part |
// +=================================================================+
// Type Definition.
PyTypeObjectDefinitionsOfModule(CRL,DefExport)
#endif // End of Shared Library Code Part.
} // extern "C".
} // CRL namespace.

View File

@ -0,0 +1,108 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC 2017-2018, All Rights Reserved
//
// +-----------------------------------------------------------------+
// | C O R I O L I S |
// | Alliance / Hurricane Interface |
// | |
// | Author : Jean-Paul CHAPUT |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Module : "./PyLefExport.cpp" |
// +-----------------------------------------------------------------+
#include "crlcore/PyLefExport.h"
#include "hurricane/isobar/PyLibrary.h"
#include <string>
#include <sstream>
namespace CRL {
using std::cerr;
using std::endl;
using std::hex;
using std::string;
using std::ostringstream;
using Hurricane::tab;
using Hurricane::Exception;
using Hurricane::Bug;
using Hurricane::Error;
using Hurricane::Warning;
using Hurricane::Library;
using Isobar::ProxyProperty;
using Isobar::ProxyError;
using Isobar::ConstructorError;
using Isobar::HurricaneError;
using Isobar::HurricaneWarning;
using Isobar::getPyHash;
using Isobar::ParseOneArg;
using Isobar::ParseTwoArg;
using Isobar::__cs;
using Isobar::PyTypeLibrary;
using Isobar::PyLibrary;
extern "C" {
#if defined(__PYTHON_MODULE__)
// +=================================================================+
// | "PyLefExport" Python Module Code Part |
// +=================================================================+
static PyObject* PyLefExport_drive ( PyObject*, PyObject* args )
{
cdebug_log(30,0) << "PyLefExport_drive()" << endl;
PyLibrary* pyLibrary = NULL;
HTRY
unsigned int flags = 0;
if (PyArg_ParseTuple( args, "O!I:LefExport.drive", &PyTypeLibrary, &pyLibrary, &flags)) {
LefExport::drive( PYLIBRARY_O(pyLibrary) , flags );
} else {
PyErr_SetString ( ConstructorError, "LefExport.drive(): Bad type or bad number of parameters." );
return NULL;
}
HCATCH
Py_RETURN_NONE;
}
// Standart Destroy (Attribute).
PyMethodDef PyLefExport_Methods[] =
{ { "drive" , (PyCFunction)PyLefExport_drive , METH_VARARGS|METH_STATIC
, "Save a complete Cadence LEF library." }
, {NULL, NULL, 0, NULL} /* sentinel */
};
NoObjectDeleteMethod(LefExport)
PyTypeObjectLinkPyTypeWithoutObject(LefExport,LefExport)
#else // End of Python Module Code Part.
// +=================================================================+
// | "PyLefExport" Shared Library Code Part |
// +=================================================================+
// Type Definition.
PyTypeObjectDefinitionsOfModule(CRL,LefExport)
#endif // End of Shared Library Code Part.
} // extern "C".
} // CRL namespace.

View File

@ -0,0 +1,55 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC 2017-2018, All Rights Reserved
//
// +-----------------------------------------------------------------+
// | C O R I O L I S |
// | Alliance / Hurricane Interface |
// | |
// | Author : Jean-Paul CHAPUT |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Header : "./crlcore/PyDefExport.h" |
// +-----------------------------------------------------------------+
#ifndef CRL_PY_DEF_EXPORT_H
#define CRL_PY_DEF_EXPORT_H
#include "hurricane/isobar/PyHurricane.h"
#include "crlcore/DefExport.h"
namespace CRL {
extern "C" {
// -------------------------------------------------------------------
// Python Object : "PyDefExport".
typedef struct {
PyObject_HEAD
} PyDefExport;
// -------------------------------------------------------------------
// Functions & Types exported to "PyCRL.ccp".
extern PyTypeObject PyTypeDefExport;
extern PyMethodDef PyDefExport_Methods[];
extern void PyDefExport_LinkPyType();
#define IsPyDefExport(v) ( (v)->ob_type == &PyTypeDefExport )
#define PY_DEFEXPORT(v) ( (PyDefExport*)(v) )
} // extern "C".
} // CRL namespace.
#endif // CRL_PY_DEF_EXPORT_H

View File

@ -0,0 +1,55 @@
// -*- C++ -*-
//
// This file is part of the Coriolis Software.
// Copyright (c) UPMC 2017-2018, All Rights Reserved
//
// +-----------------------------------------------------------------+
// | C O R I O L I S |
// | Alliance / Hurricane Interface |
// | |
// | Author : Jean-Paul CHAPUT |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Header : "./crlcore/PyLefExport.h" |
// +-----------------------------------------------------------------+
#ifndef CRL_PY_LEF_EXPORT_H
#define CRL_PY_LEF_EXPORT_H
#include "hurricane/isobar/PyHurricane.h"
#include "crlcore/LefExport.h"
namespace CRL {
extern "C" {
// -------------------------------------------------------------------
// Python Object : "PyLefExport".
typedef struct {
PyObject_HEAD
} PyLefExport;
// -------------------------------------------------------------------
// Functions & Types exported to "PyCRL.ccp".
extern PyTypeObject PyTypeLefExport;
extern PyMethodDef PyLefExport_Methods[];
extern void PyLefExport_LinkPyType();
#define IsPyLefExport(v) ( (v)->ob_type == &PyTypeLefExport )
#define PY_LEFEXPORT(v) ( (PyLefExport*)(v) )
} // extern "C".
} // CRL namespace.
#endif // CRL_PY_LEF_EXPORT_H

View File

@ -3127,7 +3127,7 @@ defwSpecialNetPathStart(const char *typ)
if (strcmp(typ, "NEW") == 0) {
if (defwState != DEFW_PATH)
return DEFW_BAD_DATA;
fprintf(defwFile, " NEW");
fprintf(defwFile, "\n NEW");
} else if (strcmp(typ, "SHIELD") == 0) {
fprintf(defwFile, "\n + %s", typ);
defwSpNetShield = 1;