From 40a6d2e0da68715f7fa75a106d0b6f832f60f3ea Mon Sep 17 00:00:00 2001 From: Sophie Belloeil Date: Thu, 14 Oct 2010 11:01:16 +0000 Subject: [PATCH] Python wrapper. (without example it seems ?) --- vlsisapd/examples/liberty/CMakeLists.txt | 2 +- .../liberty/cplusplus/driveLiberty.cpp | 13 +- .../liberty/cplusplus/parseLiberty.cpp | 3 + vlsisapd/src/liberty/src/CMakeLists.txt | 128 ++++++++++-------- vlsisapd/src/liberty/src/Cell.cpp | 4 +- vlsisapd/src/liberty/src/FlipFlop.cpp | 4 +- .../src/liberty/src/LibertyParserGrammar.yy | 9 +- vlsisapd/src/liberty/src/Library.cpp | 83 ++++++------ vlsisapd/src/liberty/src/Pin.cpp | 5 +- vlsisapd/src/liberty/src/Timing.cpp | 4 +- vlsisapd/src/liberty/src/WireLoad.cpp | 4 +- vlsisapd/src/liberty/src/WireLoadArea.cpp | 1 - .../src/liberty/src/WireLoadSelection.cpp | 2 +- .../liberty/src/vlsisapd/liberty/Attribute.h | 1 + .../src/liberty/src/vlsisapd/liberty/Cell.h | 15 +- .../liberty/src/vlsisapd/liberty/FlipFlop.h | 7 +- .../liberty/src/vlsisapd/liberty/Library.h | 24 ++-- .../src/liberty/src/vlsisapd/liberty/Pin.h | 15 +- .../src/vlsisapd/liberty/PySTLMapWrapper.h | 87 ++++++++++++ .../src/liberty/src/vlsisapd/liberty/Timing.h | 7 +- .../liberty/src/vlsisapd/liberty/WireLoad.h | 9 +- .../src/vlsisapd/liberty/WireLoadSelection.h | 8 +- 22 files changed, 261 insertions(+), 174 deletions(-) create mode 100644 vlsisapd/src/liberty/src/vlsisapd/liberty/PySTLMapWrapper.h diff --git a/vlsisapd/examples/liberty/CMakeLists.txt b/vlsisapd/examples/liberty/CMakeLists.txt index 61790812..1ce01521 100644 --- a/vlsisapd/examples/liberty/CMakeLists.txt +++ b/vlsisapd/examples/liberty/CMakeLists.txt @@ -1,4 +1,4 @@ ADD_SUBDIRECTORY(cplusplus) -#ADD_SUBDIRECTORY(python) +ADD_SUBDIRECTORY(python) INSTALL ( FILES testParse.lib DESTINATION share/doc/coriolis2/examples/vlsisapd/liberty ) diff --git a/vlsisapd/examples/liberty/cplusplus/driveLiberty.cpp b/vlsisapd/examples/liberty/cplusplus/driveLiberty.cpp index 90c7a115..a0a9dbbc 100644 --- a/vlsisapd/examples/liberty/cplusplus/driveLiberty.cpp +++ b/vlsisapd/examples/liberty/cplusplus/driveLiberty.cpp @@ -35,7 +35,7 @@ int main ( int argc, char * argv[] ) { // Cells library->addCell(LIB::Name("inv")); LIB::Cell* cell = library->getCell(LIB::Name("inv")); - valeur="1"; cell->addAttribute(LIB::Name("area"), LIB::Attribute::Double, valeur); + valeur="1"; cell->addAttribute(LIB::Name("area"), LIB::Attribute::Double, valeur); valeur="inv"; cell->addAttribute(LIB::Name("cell_footprint"), LIB::Attribute::String, valeur); LIB::Pin* pin; @@ -44,21 +44,20 @@ int main ( int argc, char * argv[] ) { cell->addPin(LIB::Name("e")); pin = cell->getPin(LIB::Name("e")); valeur="0.008"; pin->addAttribute(LIB::Name("capacitance"), LIB::Attribute::Double, valeur); - valeur="input"; pin->addAttribute(LIB::Name("direction"), LIB::Attribute::String, valeur); + valeur="input"; pin->addAttribute(LIB::Name("direction"), LIB::Attribute::String, valeur); cell->addPin(LIB::Name("s")); pin = cell->getPin(LIB::Name("s")); - valeur="i'"; pin->addAttribute(LIB::Name("function"), LIB::Attribute::String, valeur); + valeur="i'"; pin->addAttribute(LIB::Name("function"), LIB::Attribute::String, valeur); valeur="output"; pin->addAttribute(LIB::Name("direction"), LIB::Attribute::String, valeur); // Timing LIB::Timing * timing; pin->addTiming(); timing = pin->getTimings().back(); - valeur="negative_unate"; timing->addAttribute(LIB::Name("timing_sense"), LIB::Attribute::String, valeur); - valeur="e"; timing->addAttribute(LIB::Name("related_pin"), LIB::Attribute::String, valeur); - valeur="0.101"; timing->addAttribute(LIB::Name("intrinsic_rise"), LIB::Attribute::Double, valeur); - + valeur="negative_unate"; timing->addAttribute(LIB::Name("timing_sense"), LIB::Attribute::String, valeur); + valeur="e"; timing->addAttribute(LIB::Name("related_pin"), LIB::Attribute::String, valeur); + valeur="0.101"; timing->addAttribute(LIB::Name("intrinsic_rise"), LIB::Attribute::Double, valeur); // Write valeur="testDrive.lib"; library->writeToFile(valeur); diff --git a/vlsisapd/examples/liberty/cplusplus/parseLiberty.cpp b/vlsisapd/examples/liberty/cplusplus/parseLiberty.cpp index d14499f6..e000f6b1 100644 --- a/vlsisapd/examples/liberty/cplusplus/parseLiberty.cpp +++ b/vlsisapd/examples/liberty/cplusplus/parseLiberty.cpp @@ -4,6 +4,9 @@ using namespace std; #include "vlsisapd/liberty/Name.h" #include "vlsisapd/liberty/Library.h" +#include "vlsisapd/liberty/Cell.h" +#include "vlsisapd/liberty/Pin.h" +#include "vlsisapd/liberty/Timing.h" int main ( int argc, char * argv[] ) { LIB::Library* library = LIB::Library::readFromFile("./testParse.lib"); diff --git a/vlsisapd/src/liberty/src/CMakeLists.txt b/vlsisapd/src/liberty/src/CMakeLists.txt index 30cfe9ca..0cc6cefe 100644 --- a/vlsisapd/src/liberty/src/CMakeLists.txt +++ b/vlsisapd/src/liberty/src/CMakeLists.txt @@ -1,63 +1,73 @@ - - include_directories ( ${VLSISAPD_SOURCE_DIR}/src/liberty/src - ${PYTHON_INCLUDE_PATH} - ${Boost_INCLUDE_DIRS} - ) +include_directories ( ${VLSISAPD_SOURCE_DIR}/src/liberty/src + ${PYTHON_INCLUDE_PATH} + ${Boost_INCLUDE_DIRS} + ) - set ( includes vlsisapd/liberty/Attribute.h - vlsisapd/liberty/Cell.h - vlsisapd/liberty/FlipFlop.h - vlsisapd/liberty/Library.h - vlsisapd/liberty/Name.h - vlsisapd/liberty/Pin.h - vlsisapd/liberty/Timing.h - vlsisapd/liberty/WireLoad.h - vlsisapd/liberty/WireLoadArea.h - vlsisapd/liberty/WireLoadSelection.h - ) - set ( cpps Attribute.cpp - Cell.cpp - FlipFlop.cpp - Library.cpp - Name.cpp - Pin.cpp - Timing.cpp - WireLoad.cpp - WireLoadArea.cpp - WireLoadSelection.cpp - ) - set ( LibertyParserScanner ${VLSISAPD_SOURCE_DIR}/src/liberty/src/LibertyParserScanner.ll ) - set ( LibertyParserGrammar ${VLSISAPD_SOURCE_DIR}/src/liberty/src/LibertyParserGrammar.yy ) - set ( LibertyParserScannerCpp LibertyParserScanner.cpp ) - set ( LibertyParserGrammarCpp LibertyParserGrammar.cpp ) - add_custom_target ( LibertyParser echo "Creating Liberty parser" ) - add_custom_command ( SOURCE ${LibertyParserScanner} - COMMAND ${FLEX_EXECUTABLE} - ARGS -PLiberty_ -o${LibertyParserScannerCpp} ${LibertyParserScanner} - TARGET LibertyParser - OUTPUTS ${LibertyParserScannerCpp} - ) - add_custom_command ( SOURCE ${LibertyParserGrammar} - COMMAND ${BISON_EXECUTABLE} - ARGS -d -v -p Liberty_ -y ${LibertyParserGrammar} -o ${LibertyParserGrammarCpp} - TARGET LibertyParser - DEPENDS ${LibertyParserScannerCpp} - OUTPUTS ${LibertyParserGrammarCpp} - ) - set ( liberty_parser_cpps ${LibertyParserScannerCpp} - ${LibertyParserGrammarCpp} - ) - set_source_files_properties ( ${LibertyParserScannerCpp} GENERATED ) - set_source_files_properties ( ${LibertyParserGrammarCpp} GENERATED ) +set ( includes vlsisapd/liberty/Attribute.h + vlsisapd/liberty/Cell.h + vlsisapd/liberty/FlipFlop.h + vlsisapd/liberty/Library.h + vlsisapd/liberty/Name.h + vlsisapd/liberty/Pin.h + vlsisapd/liberty/Timing.h + vlsisapd/liberty/WireLoad.h + vlsisapd/liberty/WireLoadArea.h + vlsisapd/liberty/WireLoadSelection.h + ) +set ( cpps Attribute.cpp + Cell.cpp + FlipFlop.cpp + Library.cpp + Name.cpp + Pin.cpp + Timing.cpp + WireLoad.cpp + WireLoadArea.cpp + WireLoadSelection.cpp + ) +set ( pycpps PyLiberty.cpp + ) +set ( LibertyParserScanner ${VLSISAPD_SOURCE_DIR}/src/liberty/src/LibertyParserScanner.ll ) +set ( LibertyParserGrammar ${VLSISAPD_SOURCE_DIR}/src/liberty/src/LibertyParserGrammar.yy ) +set ( LibertyParserScannerCpp LibertyParserScanner.cpp ) +set ( LibertyParserGrammarCpp LibertyParserGrammar.cpp ) - add_library ( liberty ${cpps} - ${liberty_parser_cpps} - ) - target_link_libraries ( liberty ${HURRICANE_PYTHON_LIBRARIES} - ${Boost_LIBRARIES} - ${PYTHON_LIBRARIES} - ) +add_custom_target ( LibertyParser echo "Creating Liberty parser" ) +add_custom_command ( SOURCE ${LibertyParserScanner} + COMMAND ${FLEX_EXECUTABLE} + ARGS -PLiberty_ -o${LibertyParserScannerCpp} ${LibertyParserScanner} + TARGET LibertyParser + OUTPUTS ${LibertyParserScannerCpp} + ) +add_custom_command ( SOURCE ${LibertyParserGrammar} + COMMAND ${BISON_EXECUTABLE} + ARGS -d -v -p Liberty_ -y ${LibertyParserGrammar} -o ${LibertyParserGrammarCpp} + TARGET LibertyParser + DEPENDS ${LibertyParserScannerCpp} + OUTPUTS ${LibertyParserGrammarCpp} + ) +set ( liberty_parser_cpps ${LibertyParserScannerCpp} + ${LibertyParserGrammarCpp} + ) +set_source_files_properties ( ${LibertyParserScannerCpp} GENERATED ) +set_source_files_properties ( ${LibertyParserGrammarCpp} GENERATED ) - install ( TARGETS liberty DESTINATION lib${LIB_SUFFIX} ) - install ( FILES ${includes} DESTINATION include/vlsisapd/liberty ) +add_library ( liberty ${cpps} + ${liberty_parser_cpps} + ) +target_link_libraries ( liberty ${Boost_LIBRARIES} + ) + +install ( TARGETS liberty DESTINATION lib${LIB_SUFFIX} ) +install ( FILES ${includes} DESTINATION include/vlsisapd/liberty ) + +if ( Boost_FOUND ) + add_library ( pyLIBERTY MODULE ${pycpps} ) + set_target_properties ( pyLIBERTY PROPERTIES + OUTPUT_NAME "LIBERTY" + PREFIX "" + ) + target_link_libraries ( pyLIBERTY liberty ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ) + install ( TARGETS pyLIBERTY DESTINATION ${PYTHON_SITE_PACKAGES} ) +endif ( Boost_FOUND ) diff --git a/vlsisapd/src/liberty/src/Cell.cpp b/vlsisapd/src/liberty/src/Cell.cpp index 9fa88c5c..6e36b4b6 100644 --- a/vlsisapd/src/liberty/src/Cell.cpp +++ b/vlsisapd/src/liberty/src/Cell.cpp @@ -2,8 +2,6 @@ #include using namespace std; -#include "vlsisapd/liberty/Name.h" -#include "vlsisapd/liberty/Attribute.h" #include "vlsisapd/liberty/Cell.h" #include "vlsisapd/liberty/Pin.h" #include "vlsisapd/liberty/FlipFlop.h" @@ -33,7 +31,7 @@ Pin* Cell::getPin(Name pinName) { return pin; } -void Cell::addAttribute(Name attrName, Attribute::Type attrType, string& attrValue) { +void Cell::addAttribute(Name attrName, Attribute::Type attrType, const string& attrValue) { Attribute* attr = new Attribute(attrName, attrType, attrValue); map::iterator it = _attributes.find(attrName); if (it != _attributes.end()) { diff --git a/vlsisapd/src/liberty/src/FlipFlop.cpp b/vlsisapd/src/liberty/src/FlipFlop.cpp index 60b98086..b83e7106 100644 --- a/vlsisapd/src/liberty/src/FlipFlop.cpp +++ b/vlsisapd/src/liberty/src/FlipFlop.cpp @@ -2,8 +2,6 @@ #include using namespace std; -#include "vlsisapd/liberty/Name.h" -#include "vlsisapd/liberty/Attribute.h" #include "vlsisapd/liberty/FlipFlop.h" namespace LIB { @@ -20,7 +18,7 @@ Attribute* FlipFlop::getAttribute(Name attrName) { return attr; } -void FlipFlop::addAttribute(Name attrName, Attribute::Type attrType, string& attrValue) { +void FlipFlop::addAttribute(Name attrName, Attribute::Type attrType, const string& attrValue) { Attribute* attr = new Attribute(attrName, attrType, attrValue); map::iterator it = _attributes.find(attrName); if (it != _attributes.end()) { diff --git a/vlsisapd/src/liberty/src/LibertyParserGrammar.yy b/vlsisapd/src/liberty/src/LibertyParserGrammar.yy index f4c252fa..7fb96f91 100644 --- a/vlsisapd/src/liberty/src/LibertyParserGrammar.yy +++ b/vlsisapd/src/liberty/src/LibertyParserGrammar.yy @@ -6,10 +6,13 @@ using namespace std; #include #include -#include "vlsisapd/liberty/Name.h" -#include "vlsisapd/liberty/Library.h" -#include "vlsisapd/liberty/Attribute.h" +#include "vlsisapd/liberty/WireLoad.h" +#include "vlsisapd/liberty/WireLoadSelection.h" +#include "vlsisapd/liberty/Cell.h" +#include "vlsisapd/liberty/Pin.h" #include "vlsisapd/liberty/Timing.h" +#include "vlsisapd/liberty/FlipFlop.h" +#include "vlsisapd/liberty/Library.h" using namespace LIB; int Liberty_error ( const char* message ); diff --git a/vlsisapd/src/liberty/src/Library.cpp b/vlsisapd/src/liberty/src/Library.cpp index 1c2330f5..71be63cc 100644 --- a/vlsisapd/src/liberty/src/Library.cpp +++ b/vlsisapd/src/liberty/src/Library.cpp @@ -3,21 +3,35 @@ #include using namespace std; -#include "vlsisapd/liberty/Name.h" -#include "vlsisapd/liberty/Attribute.h" #include "vlsisapd/liberty/WireLoad.h" #include "vlsisapd/liberty/WireLoadSelection.h" +#include "vlsisapd/liberty/WireLoadArea.h" #include "vlsisapd/liberty/Cell.h" +#include "vlsisapd/liberty/Pin.h" +#include "vlsisapd/liberty/Timing.h" +#include "vlsisapd/liberty/FlipFlop.h" + #include "vlsisapd/liberty/Library.h" namespace LIB { Library::Library(Name name): _name(name), _attributes(), _wires_load(), _wire_load_selection(NULL), _cells() {}; +Attribute* Library::getAttribute(Name attrName) { + Attribute* attr = NULL; + map::iterator it = _attributes.find(attrName); + if (it == _attributes.end()) { + cerr << "[ERROR] Library " << _name.getString() << " has no attribute named " << attrName.getString() << endl; + exit(1); + } + attr= (*it).second; + return attr; +} + Cell* Library::getCell(Name cellName) { Cell* cell = NULL; map::iterator it = _cells.find(cellName); if (it == _cells.end()) { - cerr << "[ERROR] No cell named " << cellName.getString() << endl; + cerr << "[ERROR] Library : No cell named " << cellName.getString() << endl; exit(1); } cell= (*it).second; @@ -35,7 +49,7 @@ WireLoad* Library::getWireLoad(Name wireLoadName) { return wire; } -void Library::addAttribute(Name attrName, Attribute::Type attrType, string& attrValue, const string& attrUnit) { +void Library::addAttribute(Name attrName, Attribute::Type attrType, const string& attrValue, const string& attrUnit) { Attribute* attr = new Attribute(attrName, attrType, attrValue, attrUnit); map::iterator it = _attributes.find(attrName); if (it != _attributes.end()) { @@ -73,7 +87,6 @@ void Library::addCell(Name cellName) { void Library::print() { cout << "+-----------------------------+" << endl << "| Library : " << _name.getString() << endl; - // Library's attributes cout << "| Attributes :" << endl; for(map::const_iterator it=_attributes.begin() ; it!=_attributes.end() ; ++it) { @@ -86,19 +99,13 @@ void Library::print() { cout << endl; } - map attributes; - map pins; - vector timings; - FlipFlop* ff; - // WireLoad for(map::const_iterator it=_wires_load.begin() ; it!=_wires_load.end() ; ++it) { // (*it).second->print(); cout << "| Wireload : " << (*it).first.getString() << endl; // Wireload's attributes cout << "| Attributes :" << endl; - attributes = (*it).second->getAttributes(); - for(map::const_iterator it2=attributes.begin() ; it2 != attributes.end() ; ++it2) { + for(map::const_iterator it2=(*it).second->getAttributes().begin() ; it2 != (*it).second->getAttributes().end() ; ++it2) { if ((*it2).second == NULL) { cerr << "NULL attribute !" << endl; exit(12); @@ -131,32 +138,27 @@ void Library::print() { // Cell's attributes cout << "| Attributes :" << endl; - attributes=(*it).second->getAttributes(); - for(map::const_iterator it2=attributes.begin() ; it2!=attributes.end() ; ++it2) { + for(map::const_iterator it2=(*it).second->getAttributes().begin() ; it2!=(*it).second->getAttributes().end() ; ++it2) { cout << "| name= " << (*it2).first.getString() << ", type= " << (*it2).second->typeToString() << ", value= " << (*it2).second->valueAsString() << endl; } // Cell's pins - pins=(*it).second->getPins(); - for(map::const_iterator it2=pins.begin() ; it2!=pins.end() ; ++it2) { + for(map::const_iterator it2=(*it).second->getPins().begin() ; it2!=(*it).second->getPins().end() ; ++it2) { // (*it2).second->print(); cout << "| Pin name= " << (*it2).first.getString() << endl; // Pin's attributes cout << "| Attributes :" << endl; - attributes=(*it2).second->getAttributes(); - for(map::const_iterator it3=attributes.begin() ; it3!=attributes.end() ; ++it3) { + for(map::const_iterator it3=(*it2).second->getAttributes().begin() ; it3!=(*it2).second->getAttributes().end() ; ++it3) { cout << "| name= " << (*it3).first.getString() << ", type= " << (*it3).second->typeToString() << ", value= " << (*it3).second->valueAsString() << endl; } // Timing - timings=(*it2).second->getTimings(); - for (size_t i = 0 ; i < timings.size() ; i++) { - attributes=timings[i]->getAttributes(); + for (size_t i = 0 ; i < (*it2).second->getTimings().size() ; i++) { // Timing's attributes cout << "| Timing's attributes :" << endl; - for(map::const_iterator it3=attributes.begin() ; it3!=attributes.end() ; ++it3) { + for(map::const_iterator it3=(*it2).second->getTimings()[i]->getAttributes().begin() ; it3!=(*it2).second->getTimings()[i]->getAttributes().end() ; ++it3) { cout << "| name= " << (*it3).first.getString() << ", type= " << (*it3).second->typeToString() << ", value= " << (*it3).second->valueAsString() << endl; @@ -166,15 +168,13 @@ void Library::print() { // FF // if(_ff) // _ff->print(); - ff = (*it).second->getFF(); - if(ff) { - cout << "| FF noninverting= " << ff->getNonInverting().getString() << ", inverting= " << ff->getInverting().getString() << endl; + if((*it).second->getFF()) { + cout << "| FF noninverting= " << (*it).second->getFF()->getNonInverting().getString() << ", inverting= " << (*it).second->getFF()->getInverting().getString() << endl; cout << "| Attributes :" << endl; - attributes=ff->getAttributes(); - for(map::const_iterator it=attributes.begin() ; it!=attributes.end() ; ++it) { - cout << "| name= " << (*it).first.getString() - << ", type= " << (*it).second->typeToString() - << ", value= " << (*it).second->valueAsString() << endl; + for(map::const_iterator it2=(*it).second->getFF()->getAttributes().begin() ; it2!=(*it).second->getFF()->getAttributes().end() ; ++it2) { + cout << "| name= " << (*it2).first.getString() + << ", type= " << (*it2).second->typeToString() + << ", value= " << (*it2).second->valueAsString() << endl; } } // test_cell @@ -186,32 +186,27 @@ void Library::print() { // Cell's attributes cout << "| Attributes :" << endl; - attributes=testCell->getAttributes(); - for(map::const_iterator it2=attributes.begin() ; it2!=attributes.end() ; ++it2) { + for(map::const_iterator it2=testCell->getAttributes().begin() ; it2!=testCell->getAttributes().end() ; ++it2) { cout << "| name= " << (*it2).first.getString() << ", type= " << (*it2).second->typeToString() << ", value= " << (*it2).second->valueAsString() << endl; } // Cell's pins - pins=(*it).second->getPins(); - for(map::const_iterator it2=pins.begin() ; it2!=pins.end() ; ++it2) { + for(map::const_iterator it2=(*it).second->getPins().begin() ; it2!=(*it).second->getPins().end() ; ++it2) { // (*it2).second->print(); cout << "| Pin name= " << (*it2).first.getString() << endl; // Pin's attributes cout << "| Attributes :" << endl; - attributes=(*it2).second->getAttributes(); - for(map::const_iterator it3=attributes.begin() ; it3!=attributes.end() ; ++it3) { + for(map::const_iterator it3=(*it2).second->getAttributes().begin() ; it3!=(*it2).second->getAttributes().end() ; ++it3) { cout << "| name= " << (*it3).first.getString() << ", type= " << (*it3).second->typeToString() << ", value= " << (*it3).second->valueAsString() << endl; } // Timing - timings=(*it2).second->getTimings(); - for (size_t i = 0 ; i < timings.size() ; i++) { - attributes=timings[i]->getAttributes(); + for (size_t i = 0 ; i < (*it2).second->getTimings().size() ; i++) { // Timing's attributes cout << "| Timing's attributes :" << endl; - for(map::const_iterator it3=attributes.begin() ; it3!=attributes.end() ; ++it3) { + for(map::const_iterator it3=(*it2).second->getTimings()[i]->getAttributes().begin() ; it3!=(*it2).second->getTimings()[i]->getAttributes().end() ; ++it3) { cout << "| name= " << (*it3).first.getString() << ", type= " << (*it3).second->typeToString() << ", value= " << (*it3).second->valueAsString() << endl; @@ -221,12 +216,10 @@ void Library::print() { // FF // if(_ff) // _ff->print(); - ff = (*it).second->getFF(); - if(ff) { - cout << "| FF noninverting= " << ff->getNonInverting().getString() << ", inverting= " << ff->getInverting().getString() << endl; + if((*it).second->getFF()) { + cout << "| FF noninverting= " << (*it).second->getFF()->getNonInverting().getString() << ", inverting= " << (*it).second->getFF()->getInverting().getString() << endl; cout << "| Attributes :" << endl; - attributes=ff->getAttributes(); - for(map::const_iterator it2=attributes.begin() ; it2!=attributes.end() ; ++it2) { + for(map::const_iterator it2=(*it).second->getFF()->getAttributes().begin() ; it2!=(*it).second->getFF()->getAttributes().end() ; ++it2) { cout << "| name= " << (*it2).first.getString() << ", type= " << (*it2).second->typeToString() << ", value= " << (*it2).second->valueAsString() << endl; diff --git a/vlsisapd/src/liberty/src/Pin.cpp b/vlsisapd/src/liberty/src/Pin.cpp index 37a737c3..7dc29378 100644 --- a/vlsisapd/src/liberty/src/Pin.cpp +++ b/vlsisapd/src/liberty/src/Pin.cpp @@ -2,8 +2,7 @@ #include using namespace std; -#include "vlsisapd/liberty/Name.h" -#include "vlsisapd/liberty/Attribute.h" +#include "vlsisapd/liberty/Timing.h" #include "vlsisapd/liberty/Pin.h" namespace LIB { @@ -30,7 +29,7 @@ Timing* Pin::getTiming(Name pinName) { exit(1); } -void Pin::addAttribute(Name attrName, Attribute::Type attrType, string& attrValue) { +void Pin::addAttribute(Name attrName, Attribute::Type attrType, const string& attrValue) { Attribute* attr = new Attribute(attrName, attrType, attrValue); map::iterator it = _attributes.find(attrName); if (it != _attributes.end()) { diff --git a/vlsisapd/src/liberty/src/Timing.cpp b/vlsisapd/src/liberty/src/Timing.cpp index 15c1ef0f..7f731be5 100644 --- a/vlsisapd/src/liberty/src/Timing.cpp +++ b/vlsisapd/src/liberty/src/Timing.cpp @@ -2,8 +2,6 @@ #include using namespace std; -#include "vlsisapd/liberty/Name.h" -#include "vlsisapd/liberty/Attribute.h" #include "vlsisapd/liberty/Timing.h" namespace LIB { @@ -20,7 +18,7 @@ Attribute* Timing::getAttribute(Name attrName) { return attr; } -void Timing::addAttribute(Name attrName, Attribute::Type attrType, string& attrValue) { +void Timing::addAttribute(Name attrName, Attribute::Type attrType, const string& attrValue) { Attribute* attr = new Attribute(attrName, attrType, attrValue); map::iterator it = _attributes.find(attrName); if (it != _attributes.end()) { diff --git a/vlsisapd/src/liberty/src/WireLoad.cpp b/vlsisapd/src/liberty/src/WireLoad.cpp index 47c5d6cc..0a77efca 100644 --- a/vlsisapd/src/liberty/src/WireLoad.cpp +++ b/vlsisapd/src/liberty/src/WireLoad.cpp @@ -2,8 +2,6 @@ #include using namespace std; -#include "vlsisapd/liberty/Name.h" -#include "vlsisapd/liberty/Attribute.h" #include "vlsisapd/liberty/WireLoad.h" namespace LIB { @@ -20,7 +18,7 @@ Attribute* WireLoad::getAttribute(Name attrName) { return attr; } -void WireLoad::addAttribute(Name attrName, Attribute::Type attrType, string& attrValue, const string& attrValue2) { +void WireLoad::addAttribute(Name attrName, Attribute::Type attrType, const string& attrValue, const string& attrValue2) { Attribute* attr = new Attribute(attrName, attrType, attrValue, "", attrValue2); map::iterator it = _attributes.find(attrName); if (it != _attributes.end()) { diff --git a/vlsisapd/src/liberty/src/WireLoadArea.cpp b/vlsisapd/src/liberty/src/WireLoadArea.cpp index 0d315de9..739e6763 100644 --- a/vlsisapd/src/liberty/src/WireLoadArea.cpp +++ b/vlsisapd/src/liberty/src/WireLoadArea.cpp @@ -1,6 +1,5 @@ #include -#include "vlsisapd/liberty/Name.h" #include "vlsisapd/liberty/WireLoadArea.h" namespace LIB { diff --git a/vlsisapd/src/liberty/src/WireLoadSelection.cpp b/vlsisapd/src/liberty/src/WireLoadSelection.cpp index 60d601bf..50f198b0 100644 --- a/vlsisapd/src/liberty/src/WireLoadSelection.cpp +++ b/vlsisapd/src/liberty/src/WireLoadSelection.cpp @@ -2,7 +2,7 @@ #include using namespace std; -#include "vlsisapd/liberty/Name.h" +#include "vlsisapd/liberty/WireLoadArea.h" #include "vlsisapd/liberty/WireLoadSelection.h" namespace LIB { diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/Attribute.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/Attribute.h index b4310838..d261fca2 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/Attribute.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/Attribute.h @@ -3,6 +3,7 @@ #include #include + #include "Name.h" namespace LIB { diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/Cell.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/Cell.h index e33d961c..1531918c 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/Cell.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/Cell.h @@ -3,26 +3,25 @@ #include -#include "vlsisapd/liberty/Name.h" #include "vlsisapd/liberty/Attribute.h" -#include "vlsisapd/liberty/Pin.h" -#include "vlsisapd/liberty/FlipFlop.h" namespace LIB { +class Pin; +class FlipFlop; class Cell { public: Cell(Name name); inline Name getName(); - inline std::map getAttributes(); - inline std::map getPins(); + inline std::map& getAttributes(); + inline std::map& getPins(); inline FlipFlop* getFF(); inline Cell* getTestCell(); Attribute* getAttribute(Name attrName); Pin* getPin(Name pinName); - void addAttribute(Name attrName, Attribute::Type attrType, std::string& attrValue); + void addAttribute(Name attrName, Attribute::Type attrType, const std::string& attrValue); void addPin(Name pinName); void addFF(Name noninverting, Name inverting); void setTestCell(Cell *cell); @@ -39,8 +38,8 @@ class Cell { }; inline Name Cell::getName() { return _name; }; -inline std::map Cell::getPins() { return _pins; }; -inline std::map Cell::getAttributes() { return _attributes; }; +inline std::map& Cell::getPins() { return _pins; }; +inline std::map& Cell::getAttributes() { return _attributes; }; inline FlipFlop* Cell::getFF() { return _ff; }; inline Cell* Cell::getTestCell() { return _testCell; }; diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/FlipFlop.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/FlipFlop.h index 17cc9566..eda28b6b 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/FlipFlop.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/FlipFlop.h @@ -3,7 +3,6 @@ #include -#include "vlsisapd/liberty/Name.h" #include "vlsisapd/liberty/Attribute.h" namespace LIB { @@ -14,10 +13,10 @@ class FlipFlop { inline Name getNonInverting(); inline Name getInverting(); - inline std::map getAttributes(); + inline std::map& getAttributes(); Attribute* getAttribute(Name attrName); - void addAttribute(Name attrName, Attribute::Type attrType, std::string& attrValue); + void addAttribute(Name attrName, Attribute::Type attrType, const std::string& attrValue); void print(); bool write(std::ofstream &file); @@ -30,7 +29,7 @@ class FlipFlop { inline Name FlipFlop::getNonInverting() { return _noninverting; }; inline Name FlipFlop::getInverting() { return _inverting; }; -inline std::map FlipFlop::getAttributes() { return _attributes; }; +inline std::map& FlipFlop::getAttributes() { return _attributes; }; } // namespace LIB #endif diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/Library.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/Library.h index e9f3e334..5343f278 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/Library.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/Library.h @@ -1,24 +1,27 @@ #ifndef __LIB_LIBRARY_H__ #define __LIB_LIBRARY_H__ -#include "vlsisapd/liberty/Name.h" #include "vlsisapd/liberty/Attribute.h" -#include "vlsisapd/liberty/WireLoad.h" -#include "vlsisapd/liberty/WireLoadSelection.h" -#include "vlsisapd/liberty/Cell.h" namespace LIB { +class WireLoad; +class WireLoadSelection; +class Cell; class Library { public: Library(Name name); inline Name getName(); - Cell* getCell(Name cellName); - WireLoad* getWireLoad(Name wireLoadName); + inline std::map& getAttributes(); + inline std::map& getWiresLoad(); inline WireLoadSelection* getWireLoadSelection(); + inline std::map& getCells(); + Attribute* getAttribute(Name attrName); + WireLoad* getWireLoad(Name wireLoadName); + Cell* getCell(Name cellName); - void addAttribute(Name attrName, Attribute::Type attrType, std::string& attrValue, const std::string& attrUnit=""); + void addAttribute(Name attrName, Attribute::Type attrType, const std::string& attrValue, const std::string& attrUnit=""); void addWireLoad(Name wireLoadName); void addWireLoadSelection(Name wireLoadSelectionName); void addCell(Name cellName); @@ -36,8 +39,11 @@ class Library { std::map _cells; }; -inline Name Library::getName() { return _name; }; -inline WireLoadSelection* Library::getWireLoadSelection() { return _wire_load_selection; }; +inline Name Library::getName() { return _name; }; +inline std::map& Library::getAttributes() { return _attributes; }; +inline std::map& Library::getWiresLoad() { return _wires_load; }; +inline WireLoadSelection* Library::getWireLoadSelection() { return _wire_load_selection; }; +inline std::map& Library::getCells() { return _cells; }; } // namespace LIB #endif diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/Pin.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/Pin.h index 1368eedf..c38dc747 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/Pin.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/Pin.h @@ -4,23 +4,22 @@ #include #include -#include "vlsisapd/liberty/Name.h" #include "vlsisapd/liberty/Attribute.h" -#include "vlsisapd/liberty/Timing.h" namespace LIB { +class Timing; class Pin { public: Pin(Name name); inline Name getName(); - inline std::map getAttributes(); - inline std::vector getTimings(); + inline std::map& getAttributes(); + inline std::vector& getTimings(); Attribute* getAttribute(Name attrName); Timing* getTiming(Name pinName); - void addAttribute(Name attrName, Attribute::Type attrType, std::string& attrValue); + void addAttribute(Name attrName, Attribute::Type attrType, const std::string& attrValue); void addTiming(); void print(); @@ -32,9 +31,9 @@ class Pin { std::vector _timings; }; -inline Name Pin::getName() { return _name; }; -inline std::map Pin::getAttributes() { return _attributes; }; -inline std::vector Pin::getTimings() { return _timings; }; +inline Name Pin::getName() { return _name; }; +inline std::map& Pin::getAttributes() { return _attributes; }; +inline std::vector& Pin::getTimings() { return _timings; }; } // namespace LIB #endif diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/PySTLMapWrapper.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/PySTLMapWrapper.h new file mode 100644 index 00000000..e886549c --- /dev/null +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/PySTLMapWrapper.h @@ -0,0 +1,87 @@ +#include + +#include + +namespace LIB { +// since we want to wrap std::map with cimple pointers (no boost::shared_ptr), +// we cannot use map_indexing_suite which has not the right return_value_policy. +// std::maps with no points value are wrapped using map_indexing_suite technique. +// +// This templated map_item struct is intended to be used for 'manual' wrapping: +template +struct map_item { + typedef std::map Map; + + static Val get(Map & self, const Key idx) { + if (self.find(idx) == self.end()) { + PyErr_SetString(PyExc_KeyError,"Map key not found"); + throw_error_already_set(); + } + return self[idx]; + } + + static void set(Map& self, const Key idx, const Val val) { self[idx]=val; } + static void del(Map& self, const Key n) { self.erase(n); } + static bool in (Map const& self, const Key n) { return self.find(n) != self.end(); } + + static list keys(Map const& self) { + list t; + for(typename Map::const_iterator it = self.begin() ; it!=self.end() ; ++it) + t.append(it->first); + return t; + } + + static list values(Map const& self) { + list t; + for(typename Map::const_iterator it=self.begin(); it!=self.end(); ++it) + t.append(it->second); + return t; + } + + static list items(Map const& self) { + list t; + for(typename Map::const_iterator it=self.begin(); it!=self.end(); ++it) + t.append( make_tuple(it->first, it->second) ); + return t; + } +}; + +#define STL_MAP_WRAPPING_PTR(KEY_TYPE, VALUE_TYPE, PYTHON_TYPE_NAME) \ + class_ >((std::string(PYTHON_TYPE_NAME)+std::string("DATA")).c_str()) \ + .def_readonly ("key" , &std::pair::first ) \ + .def_readwrite("value", &std::pair::second) \ + ; \ + class_ >(PYTHON_TYPE_NAME) \ + .def("__len__" , &std::map::size) \ + .def("__iter__" , boost::python::iterator, return_internal_reference<> >()) \ + .def("__getitem__" , &map_item().get, return_internal_reference<>()) \ + .def("__setitem__" , &map_item().set ) \ + .def("__delitem__" , &map_item().del ) \ + .def("__contains__", &map_item().in ) \ + .def("clear" , &std::map::clear ) \ + .def("has_key" , &map_item().in ) \ + .def("keys" , &map_item().keys ) \ + .def("values" , &map_item().values) \ + .def("items" , &map_item().items ) \ + ; + +#define STL_MAP_WRAPPING(KEY_TYPE, VALUE_TYPE, PYTHON_TYPE_NAME) \ + class_ >((std::string(PYTHON_TYPE_NAME)+std::string("DATA")).c_str()) \ + .def_readonly ("key" , &std::pair::first ) \ + .def_readwrite("value", &std::pair::second) \ + ; \ + class_ >(PYTHON_TYPE_NAME) \ + .def("__len__" , &std::map::size) \ + .def("__iter__" , boost::python::iterator, return_internal_reference<> >()) \ + .def("__getitem__" , &map_item().get ) \ + .def("__setitem__" , &map_item().set ) \ + .def("__delitem__" , &map_item().del ) \ + .def("__contains__", &map_item().in ) \ + .def("clear" , &std::map::clear ) \ + .def("has_key" , &map_item().in ) \ + .def("keys" , &map_item().keys ) \ + .def("values" , &map_item().values) \ + .def("items" , &map_item().items ) \ + ; + +} // namespace diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/Timing.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/Timing.h index 071796b7..10cce4f8 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/Timing.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/Timing.h @@ -3,7 +3,6 @@ #include -#include "vlsisapd/liberty/Name.h" #include "vlsisapd/liberty/Attribute.h" namespace LIB { @@ -12,10 +11,10 @@ class Timing { public: Timing(); - inline std::map getAttributes(); + inline std::map& getAttributes(); Attribute* getAttribute(Name attrName); - void addAttribute(Name attrName, Attribute::Type attrType, std::string& attrValue); + void addAttribute(Name attrName, Attribute::Type attrType, const std::string& attrValue); void print(); bool write(std::ofstream &file); @@ -24,7 +23,7 @@ class Timing { std::map _attributes; }; -inline std::map Timing::getAttributes() { return _attributes; }; +inline std::map& Timing::getAttributes() { return _attributes; }; } // namespace LIB #endif diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoad.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoad.h index e1f0aaff..201eb0d8 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoad.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoad.h @@ -1,7 +1,6 @@ #ifndef __LIB_WIRE_LOAD_H__ #define __LIB_WIRE_LOAD_H__ -#include "vlsisapd/liberty/Name.h" #include "vlsisapd/liberty/Attribute.h" namespace LIB { @@ -11,10 +10,10 @@ class WireLoad { WireLoad(Name name); inline Name getName(); - inline std::map getAttributes(); + inline std::map& getAttributes(); Attribute* getAttribute(Name attrName); - void addAttribute(Name attrName, Attribute::Type attrType, std::string& attrValue, const std::string& attrValue2 = ""); + void addAttribute(Name attrName, Attribute::Type attrType, const std::string& attrValue, const std::string& attrValue2 = ""); void print(); bool write(std::ofstream &file); @@ -24,8 +23,8 @@ class WireLoad { std::map _attributes; }; -inline Name WireLoad::getName() { return _name; }; -inline std::map WireLoad::getAttributes() { return _attributes; }; +inline Name WireLoad::getName() { return _name; }; +inline std::map& WireLoad::getAttributes() { return _attributes; }; } // namespace LIB #endif diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoadSelection.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoadSelection.h index 3fa2c789..51a0f117 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoadSelection.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoadSelection.h @@ -5,16 +5,16 @@ #include #include "vlsisapd/liberty/Name.h" -#include "vlsisapd/liberty/WireLoadArea.h" namespace LIB { +class WireLoadArea; class WireLoadSelection { public: WireLoadSelection(Name name); inline Name getName(); - inline std::vector getWiresLoadArea(); + inline std::vector& getWiresLoadArea(); void addWireLoadArea(double min, double max, Name name); void print(); @@ -25,8 +25,8 @@ class WireLoadSelection { std::vector _wires_load_area; }; -inline Name WireLoadSelection::getName() { return _name; }; -inline std::vector WireLoadSelection::getWiresLoadArea() { return _wires_load_area; }; +inline Name WireLoadSelection::getName() { return _name; }; +inline std::vector& WireLoadSelection::getWiresLoadArea() { return _wires_load_area; }; } // namespace #endif