From 81d4d455bd54c198390ded63d22974103418dd73 Mon Sep 17 00:00:00 2001 From: Sophie Belloeil Date: Fri, 15 Oct 2010 11:13:53 +0000 Subject: [PATCH] - Improvment of parsing examples with examples of maps and vectors. - No more pprint method in Python, now __repr__method encapsuling new c++ method getString. --- .../liberty/cplusplus/parseLiberty.cpp | 18 ++- .../examples/liberty/python/parseLiberty.py | 18 ++- vlsisapd/src/liberty/src/Cell.cpp | 35 +++-- vlsisapd/src/liberty/src/FlipFlop.cpp | 19 ++- vlsisapd/src/liberty/src/Library.cpp | 125 +++++++++--------- vlsisapd/src/liberty/src/Pin.cpp | 26 +++- vlsisapd/src/liberty/src/PyLiberty.cpp | 30 ++--- vlsisapd/src/liberty/src/Timing.cpp | 17 ++- vlsisapd/src/liberty/src/WireLoad.cpp | 23 ++-- .../src/liberty/src/WireLoadSelection.cpp | 19 ++- .../src/liberty/src/vlsisapd/liberty/Cell.h | 1 + .../liberty/src/vlsisapd/liberty/FlipFlop.h | 1 + .../liberty/src/vlsisapd/liberty/Library.h | 1 + .../src/liberty/src/vlsisapd/liberty/Pin.h | 1 + .../src/liberty/src/vlsisapd/liberty/Timing.h | 1 + .../liberty/src/vlsisapd/liberty/WireLoad.h | 1 + .../src/vlsisapd/liberty/WireLoadSelection.h | 2 + 17 files changed, 216 insertions(+), 122 deletions(-) diff --git a/vlsisapd/examples/liberty/cplusplus/parseLiberty.cpp b/vlsisapd/examples/liberty/cplusplus/parseLiberty.cpp index e000f6b1..72b578ad 100644 --- a/vlsisapd/examples/liberty/cplusplus/parseLiberty.cpp +++ b/vlsisapd/examples/liberty/cplusplus/parseLiberty.cpp @@ -14,9 +14,21 @@ int main ( int argc, char * argv[] ) { if ( library ) { // print of the library library->print(); - // print of one attribute in particular - cout << "| area of inv_x1= " << library->getCell(LIB::Name("inv_x1"))->getAttribute(LIB::Name("area"))->valueAsString() << endl; - cout << "| timing intrinsic_rise of nq of inv_x1= " << library->getCell(LIB::Name("inv_x1"))->getPin(LIB::Name("nq"))->getTiming(LIB::Name("i"))->getAttribute(LIB::Name("intrinsic_rise"))->valueAsString() << endl; + // print of one attribute in particular of a cell + cout << "Area of inv_x1 : " << library->getCell(LIB::Name("inv_x1"))->getAttribute(LIB::Name("area"))->valueAsString() << endl; + cout << "Timing intrinsic_rise of nq of inv_x1 : " << library->getCell(LIB::Name("inv_x1"))->getPin(LIB::Name("nq"))->getTiming(LIB::Name("i"))->getAttribute(LIB::Name("intrinsic_rise"))->valueAsString() << endl; + // print of all the attributes of a cell + cout << "Attributes of no2_x1 :" << endl; + for(map::const_iterator it=library->getCell(LIB::Name("no2_x1"))->getAttributes().begin() ; it!=library->getCell(LIB::Name("no2_x1"))->getAttributes().end() ; ++it) { + cout << " name= " << (*it).first.getString() + << ", type= " << (*it).second->typeToString() + << ", value= " << (*it).second->valueAsString() << endl; + } + // print of all the timings of a pin + cout << "Timing's atributes of pin nq of no2_x1 :" << endl; + for (size_t i = 0 ; i < library->getCell(LIB::Name("no2_x1"))->getPin(LIB::Name("nq"))->getTimings().size() ; i++) { + library->getCell(LIB::Name("no2_x1"))->getPin(LIB::Name("nq"))->getTimings()[i]->print(); + } } else { cerr << "library is NULL" << endl; } diff --git a/vlsisapd/examples/liberty/python/parseLiberty.py b/vlsisapd/examples/liberty/python/parseLiberty.py index 77132bc1..922f999f 100644 --- a/vlsisapd/examples/liberty/python/parseLiberty.py +++ b/vlsisapd/examples/liberty/python/parseLiberty.py @@ -4,10 +4,20 @@ library = Library.readFromFile("./testParse.lib") if ( library ) : # print of the library - library.pprint() - # print of one attribute in particular - print "| area of inv_x1= ", library.getCell("inv_x1").getAttribute("area").valueAsString() - print "| timing intrinsic_rise of nq of inv_x1= ", library.getCell("inv_x1").getPin("nq").getTiming("i").getAttribute("intrinsic_rise").valueAsString() + print library + # print of one attribute in particular of a cell + print "Area of inv_x1 :", library.getCell("inv_x1").getAttribute("area").valueAsString() + print "Timing intrinsic_rise of nq of inv_x1 :", library.getCell("inv_x1").getPin("nq").getTiming("i").getAttribute("intrinsic_rise").valueAsString() + # print of all the attributes of a cell + print "Attributes of no2_x1 :" + for attr in library.getCell("no2_x1").getAttributes() : + print " name=", attr.key, \ + ", type=", attr.value.typeToString(), \ + ", value=", attr.value.valueAsString() + # print of all the timings of a pin + print "Timing's attributes of pin nq of no2_x1 :" + for timing in library.getCell("no2_x1").getPin("nq").getTimings() : + print timing else : raise ( "library is NULL" ) diff --git a/vlsisapd/src/liberty/src/Cell.cpp b/vlsisapd/src/liberty/src/Cell.cpp index 6e36b4b6..8c38e561 100644 --- a/vlsisapd/src/liberty/src/Cell.cpp +++ b/vlsisapd/src/liberty/src/Cell.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace std; #include "vlsisapd/liberty/Cell.h" @@ -60,26 +61,42 @@ void Cell::setTestCell(Cell *cell) { _testCell = cell; } -void Cell::print() { - cout << "| Cell name= " << _name.getString() << endl; +const string Cell::getString() const{ + ostringstream chaine; + chaine << "| Cell name= " << _name.getString() << endl; // Cell's attributes - cout << "| Attributes :" << endl; + chaine << "| Attributes :" << endl; 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; + chaine << "| name= " << (*it).first.getString() + << ", type= " << (*it).second->typeToString() + << ", value= " << (*it).second->valueAsString() << endl; } // Cell's pins for(map::const_iterator it=_pins.begin() ; it!=_pins.end() ; ++it) { (*it).second->print(); } // FF - if(_ff) - _ff->print(); + if(_ff) { + chaine << "| FF noninverting= " << _ff->getNonInverting().getString() << ", inverting= " << _ff->getInverting().getString() << endl; + + // FlipFlop's attributes + chaine << "| Attributes :" << endl; + for(map::const_iterator it=_ff->getAttributes().begin() ; it!=_ff->getAttributes().end() ; ++it) { + chaine << "| name= " << (*it).first.getString() + << ", type= " << (*it).second->typeToString() + << ", value= " << (*it).second->valueAsString() << endl; + } + } // test_cell if(_testCell) - _testCell->print(); + chaine << _testCell->getString(); + + return chaine.str(); +} + +void Cell::print() { + cout << Cell::getString(); } bool Cell::write(ofstream &file, bool test) { diff --git a/vlsisapd/src/liberty/src/FlipFlop.cpp b/vlsisapd/src/liberty/src/FlipFlop.cpp index b83e7106..68c5bfbd 100644 --- a/vlsisapd/src/liberty/src/FlipFlop.cpp +++ b/vlsisapd/src/liberty/src/FlipFlop.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace std; #include "vlsisapd/liberty/FlipFlop.h" @@ -28,16 +29,22 @@ void FlipFlop::addAttribute(Name attrName, Attribute::Type attrType, const strin _attributes[attrName] = attr; } -void FlipFlop::print() { - cout << "| FF noninverting= " << _noninverting.getString() << ", inverting= " << _inverting.getString() << endl; +const string FlipFlop::getString() const{ + ostringstream chaine; + chaine << "| FF noninverting= " << _noninverting.getString() << ", inverting= " << _inverting.getString() << endl; // FlipFlop's attributes - cout << "| Attributes :" << endl; + chaine << "| Attributes :" << endl; 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; + chaine << "| name= " << (*it).first.getString() + << ", type= " << (*it).second->typeToString() + << ", value= " << (*it).second->valueAsString() << endl; } + return chaine.str(); +} + +void FlipFlop::print() { + cout << FlipFlop::getString(); } bool FlipFlop::write(ofstream &file) { diff --git a/vlsisapd/src/liberty/src/Library.cpp b/vlsisapd/src/liberty/src/Library.cpp index 71be63cc..4bb53916 100644 --- a/vlsisapd/src/liberty/src/Library.cpp +++ b/vlsisapd/src/liberty/src/Library.cpp @@ -1,5 +1,6 @@ #include #include +#include #include using namespace std; @@ -84,84 +85,85 @@ void Library::addCell(Name cellName) { _cells[cellName] = cell; } -void Library::print() { - cout << "+-----------------------------+" << endl - << "| Library : " << _name.getString() << endl; +const string Library::getString() const{ + ostringstream chaine; + chaine << "+-----------------------------+" << endl + << "| Library : " << _name.getString() << endl; // Library's attributes - cout << "| Attributes :" << endl; + chaine << "| Attributes :" << endl; for(map::const_iterator it=_attributes.begin() ; it!=_attributes.end() ; ++it) { - cout << "| name=" << (*it).first.getString() - << ", type=" << (*it).second->typeToString() - << ", value=" << (*it).second->valueAsString(); + chaine << "| name=" << (*it).first.getString() + << ", type=" << (*it).second->typeToString() + << ", value=" << (*it).second->valueAsString(); string unit = (*it).second->getUnit(); if(!unit.empty()) - cout << ", unit=" << unit; - cout << endl; + chaine << ", unit=" << unit; + chaine << endl; } // WireLoad for(map::const_iterator it=_wires_load.begin() ; it!=_wires_load.end() ; ++it) { // (*it).second->print(); - cout << "| Wireload : " << (*it).first.getString() << endl; + chaine << "| Wireload : " << (*it).first.getString() << endl; // Wireload's attributes - cout << "| Attributes :" << endl; + chaine << "| Attributes :" << endl; 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); } - cout << "| name=" << (*it2).first.getString() + chaine << "| name=" << (*it2).first.getString() << ", type=" << (*it2).second->typeToString() << ", value=" << (*it2).second->valueAsString(); string value2=(*it2).second->secondValueAsString(); if(!value2.empty()) - cout << ", value2=" << value2; - cout << endl; + chaine << ", value2=" << value2; + chaine << endl; } } // WireLoadSelection // _wire_load_selection->print(); - cout << "| WireLoadSection name= " << _wire_load_selection->getName().getString() << endl; + chaine << "| WireLoadSection name= " << _wire_load_selection->getName().getString() << endl; vector wires_load_area = _wire_load_selection->getWiresLoadArea(); for(size_t i = 0 ; i < wires_load_area.size() ; i++) { - cout << "| wire_load_from_area name= " << wires_load_area[i]->getName().getString() - << ", min= " << wires_load_area[i]->getMin() - << ", max= " << wires_load_area[i]->getMax() - << endl; + chaine << "| wire_load_from_area name= " << wires_load_area[i]->getName().getString() + << ", min= " << wires_load_area[i]->getMin() + << ", max= " << wires_load_area[i]->getMax() + << endl; } // Cell for(map::const_iterator it=_cells.begin() ; it!=_cells.end() ; ++it) { // (*it).second->print(); - cout << "| Cell name= " << (*it).first.getString() << endl; + chaine << "| Cell name= " << (*it).first.getString() << endl; // Cell's attributes - cout << "| Attributes :" << endl; + chaine << "| Attributes :" << endl; 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; + chaine << "| name= " << (*it2).first.getString() + << ", type= " << (*it2).second->typeToString() + << ", value= " << (*it2).second->valueAsString() << endl; } // Cell's pins 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; + chaine << "| Pin name= " << (*it2).first.getString() << endl; // Pin's attributes - cout << "| Attributes :" << endl; + chaine << "| Attributes :" << endl; 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; + chaine << "| name= " << (*it3).first.getString() + << ", type= " << (*it3).second->typeToString() + << ", value= " << (*it3).second->valueAsString() << endl; } // Timing for (size_t i = 0 ; i < (*it2).second->getTimings().size() ; i++) { // Timing's attributes - cout << "| Timing's attributes :" << endl; + chaine << "| Timing's attributes :" << endl; 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; + chaine << "| name= " << (*it3).first.getString() + << ", type= " << (*it3).second->typeToString() + << ", value= " << (*it3).second->valueAsString() << endl; } } } @@ -169,12 +171,12 @@ void Library::print() { // if(_ff) // _ff->print(); if((*it).second->getFF()) { - cout << "| FF noninverting= " << (*it).second->getFF()->getNonInverting().getString() << ", inverting= " << (*it).second->getFF()->getInverting().getString() << endl; - cout << "| Attributes :" << endl; + chaine << "| FF noninverting= " << (*it).second->getFF()->getNonInverting().getString() << ", inverting= " << (*it).second->getFF()->getInverting().getString() << endl; + chaine << "| Attributes :" << 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; + chaine << "| name= " << (*it2).first.getString() + << ", type= " << (*it2).second->typeToString() + << ", value= " << (*it2).second->valueAsString() << endl; } } // test_cell @@ -182,34 +184,34 @@ void Library::print() { // _testCell->print(); Cell* testCell = (*it).second->getTestCell(); if(testCell) { - cout << "| Test Cell" << endl; + chaine << "| Test Cell" << endl; // Cell's attributes - cout << "| Attributes :" << endl; + chaine << "| Attributes :" << endl; 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; + chaine << "| name= " << (*it2).first.getString() + << ", type= " << (*it2).second->typeToString() + << ", value= " << (*it2).second->valueAsString() << endl; } // Cell's pins 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; + chaine << "| Pin name= " << (*it2).first.getString() << endl; // Pin's attributes - cout << "| Attributes :" << endl; + chaine << "| Attributes :" << endl; 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; + chaine << "| name= " << (*it3).first.getString() + << ", type= " << (*it3).second->typeToString() + << ", value= " << (*it3).second->valueAsString() << endl; } // Timing for (size_t i = 0 ; i < (*it2).second->getTimings().size() ; i++) { // Timing's attributes - cout << "| Timing's attributes :" << endl; + chaine << "| Timing's attributes :" << endl; 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; + chaine << "| name= " << (*it3).first.getString() + << ", type= " << (*it3).second->typeToString() + << ", value= " << (*it3).second->valueAsString() << endl; } } } @@ -217,18 +219,23 @@ void Library::print() { // if(_ff) // _ff->print(); if((*it).second->getFF()) { - cout << "| FF noninverting= " << (*it).second->getFF()->getNonInverting().getString() << ", inverting= " << (*it).second->getFF()->getInverting().getString() << endl; - cout << "| Attributes :" << endl; + chaine << "| FF noninverting= " << (*it).second->getFF()->getNonInverting().getString() << ", inverting= " << (*it).second->getFF()->getInverting().getString() << endl; + chaine << "| Attributes :" << 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; + chaine << "| name= " << (*it2).first.getString() + << ", type= " << (*it2).second->typeToString() + << ", value= " << (*it2).second->valueAsString() << endl; } } } } - cout << "+-----------------------------+" << endl; -}; + chaine << "+-----------------------------+" << endl; + return chaine.str(); +} + +void Library::print() { + cout << Library::getString(); +} bool Library::writeToFile(string filename) { time_t curtime = time(0); diff --git a/vlsisapd/src/liberty/src/Pin.cpp b/vlsisapd/src/liberty/src/Pin.cpp index 7dc29378..8c213063 100644 --- a/vlsisapd/src/liberty/src/Pin.cpp +++ b/vlsisapd/src/liberty/src/Pin.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace std; #include "vlsisapd/liberty/Timing.h" @@ -44,20 +45,31 @@ void Pin::addTiming() { _timings.push_back(timing); } -void Pin::print() { - cout << "| Pin name= " << _name.getString() << endl; +const string Pin::getString() const{ + ostringstream chaine; + chaine << "| Pin name= " << _name.getString() << endl; // Pin's attributes - cout << "| Attributes :" << endl; + chaine << "| Attributes :" << endl; 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; + chaine << "| name= " << (*it).first.getString() + << ", type= " << (*it).second->typeToString() + << ", value= " << (*it).second->valueAsString() << endl; } // Timing for (size_t i = 0 ; i < _timings.size() ; i++) { - _timings[i]->print(); + chaine << "| Timing's attributes :" << endl; + for(map::const_iterator it=_timings[i]->getAttributes().begin() ; it!=_timings[i]->getAttributes().end() ; ++it) { + chaine << "| name= " + (*it).first.getString() + << ", type= " + (*it).second->typeToString() + << ", value= " + (*it).second->valueAsString() << endl; + } } + return chaine.str(); +} + +void Pin::print() { + cout << Pin::getString(); } bool Pin::write(ofstream &file) { diff --git a/vlsisapd/src/liberty/src/PyLiberty.cpp b/vlsisapd/src/liberty/src/PyLiberty.cpp index c037c5da..86c36d87 100644 --- a/vlsisapd/src/liberty/src/PyLiberty.cpp +++ b/vlsisapd/src/liberty/src/PyLiberty.cpp @@ -88,7 +88,7 @@ BOOST_PYTHON_MODULE(LIBERTY) { // class Liberty::WireLoad ////////////////////////// - class_("WireLoad", init()) + class_("WireLoad", init()) // properties .add_property("name", &WireLoad::getName) // no setter => readonly // accessors @@ -97,13 +97,13 @@ BOOST_PYTHON_MODULE(LIBERTY) { // modifiers .def("addAttribute", &WireLoad::addAttribute, addAttribute_overloads()) // miscellaneous - .def("pprint", &WireLoad::print) + .def("__repr__", &WireLoad::getString) .def("write", &WireLoad::write) ; // class Liberty::WireLoadArea ////////////////////////////// - class_("WireLoadArea", init()) + class_("WireLoadArea", init()) // properties .add_property("min", &WireLoadArea::getMin) // no setter => readonly .add_property("max", &WireLoadArea::getMax) // no setter => readonly @@ -114,7 +114,7 @@ BOOST_PYTHON_MODULE(LIBERTY) { // class Liberty::WireLoadSelection /////////////////////////////////// - class_("WireLoadSelection", init()) + class_("WireLoadSelection", init()) // properties .add_property("name", &WireLoadSelection::getName) // no setter => readonly // accessors @@ -122,13 +122,13 @@ BOOST_PYTHON_MODULE(LIBERTY) { // modifiers .def("addWireLoadArea", &WireLoadSelection::addWireLoadArea) // miscellaneous - .def("pprint", &WireLoadSelection::print) + .def("__repr__", &WireLoadSelection::getString) .def("write", &WireLoadSelection::write) ; // class Liberty::Cell ////////////////////// - class_("Cell", init()) + class_("Cell", init()) // properties .add_property("name", &Cell::getName) // no setter => readonly // accessors @@ -144,13 +144,13 @@ BOOST_PYTHON_MODULE(LIBERTY) { .def("addFF", &Cell::addFF) .def("setTestCell", &Cell::setTestCell) // miscellaneous - .def("pprint", &Cell::print) + .def("__repr__", &Cell::getString) .def("write", &Cell::write) ; // class Liberty::Pin ///////////////////// - class_("Pin", init()) + class_("Pin", init()) // properties .add_property("name", &Pin::getName) // no setter => readonly // accessors @@ -162,26 +162,26 @@ BOOST_PYTHON_MODULE(LIBERTY) { .def("addAttribute", &Pin::addAttribute) .def("addTiming", &Pin::addTiming) // miscellaneous - .def("pprint", &Pin::print) + .def("__repr__", &Pin::getString) .def("write", &Pin::write) ; // class Liberty::Timing //////////////////////// - class_("Timing", init<>()) + class_("Timing", init<>()) // accessors .def("getAttributes", &Timing::getAttributes, return_internal_reference<>()) .def("getAttribute", &Timing::getAttribute, return_value_policy()) // modifiers .def("addAttribute", &Timing::addAttribute) // miscellaneous - .def("pprint", &Timing::print) + .def("__repr__", &Timing::getString) .def("write", &Timing::write) ; // class Liberty::FlipFlop ////////////////////////// - class_("FlipFlop", init()) + class_("FlipFlop", init()) // properties .add_property("noninverting", &FlipFlop::getNonInverting) // no setter => readonly .add_property("inverting", &FlipFlop::getInverting) // no setter => readonly @@ -191,13 +191,13 @@ BOOST_PYTHON_MODULE(LIBERTY) { // modifiers .def("addAttribute", &FlipFlop::addAttribute) // miscellaneous - .def("pprint", &FlipFlop::print) + .def("__repr__", &FlipFlop::getString) .def("write", &FlipFlop::write) ; // class Liberty::Library ///////////////////////// - class_("Library", init()) + class_("Library", init()) // properties .add_property("name", &Library::getName) // no setter => readonly // accessors @@ -214,7 +214,7 @@ BOOST_PYTHON_MODULE(LIBERTY) { .def("addWireLoadSelection", &Library::addWireLoadSelection) .def("addCell", &Library::addCell) // miscellaneous - .def("pprint", &Library::print ) // "print" does not work in Python + .def("__repr__", &Library::getString) .def("readFromFile", &Library::readFromFile, return_value_policy()) .staticmethod("readFromFile") .def("writeToFile", &Library::writeToFile) diff --git a/vlsisapd/src/liberty/src/Timing.cpp b/vlsisapd/src/liberty/src/Timing.cpp index 7f731be5..56ca9418 100644 --- a/vlsisapd/src/liberty/src/Timing.cpp +++ b/vlsisapd/src/liberty/src/Timing.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace std; #include "vlsisapd/liberty/Timing.h" @@ -28,14 +29,20 @@ void Timing::addAttribute(Name attrName, Attribute::Type attrType, const string& _attributes[attrName] = attr; } -void Timing::print() { +const string Timing::getString() const{ // Timing's attributes - cout << "| Timing's attributes :" << endl; + ostringstream chaine; + chaine << "| Timing's attributes :" << endl; 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; + chaine << "| name= " + (*it).first.getString() + << ", type= " + (*it).second->typeToString() + << ", value= " + (*it).second->valueAsString() << endl; } + return chaine.str(); +} + +void Timing::print() { + cout << Timing::getString(); } bool Timing::write(ofstream &file) { diff --git a/vlsisapd/src/liberty/src/WireLoad.cpp b/vlsisapd/src/liberty/src/WireLoad.cpp index 0a77efca..d6b7ca52 100644 --- a/vlsisapd/src/liberty/src/WireLoad.cpp +++ b/vlsisapd/src/liberty/src/WireLoad.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace std; #include "vlsisapd/liberty/WireLoad.h" @@ -28,19 +29,25 @@ void WireLoad::addAttribute(Name attrName, Attribute::Type attrType, const strin _attributes[attrName] = attr; } -void WireLoad::print() { +const string WireLoad::getString() const{ + ostringstream chaine; // WireLoad's attributes - cout << "| Wireload : " << _name.getString() << endl; - cout << "| Attributes :" << endl; + chaine << "| Wireload : " << _name.getString() << endl + << "| Attributes :" << endl; for(map::const_iterator it=_attributes.begin() ; it!=_attributes.end() ; ++it) { - cout << "| name= " << (*it).first.getString() - << ", type= " << (*it).second->typeToString() - << ", value= " << (*it).second->valueAsString(); + chaine << "| name= " << (*it).first.getString() + << ", type= " << (*it).second->typeToString() + << ", value= " << (*it).second->valueAsString(); string value2=(*it).second->secondValueAsString(); if(!value2.empty()) - cout << ", value2= " << value2; - cout << endl; + chaine << ", value2= " << value2; + chaine << endl; } + return chaine.str(); +} + +void WireLoad::print() { + cout << WireLoad::getString(); } bool WireLoad::write(ofstream &file) { diff --git a/vlsisapd/src/liberty/src/WireLoadSelection.cpp b/vlsisapd/src/liberty/src/WireLoadSelection.cpp index 50f198b0..bc8d9146 100644 --- a/vlsisapd/src/liberty/src/WireLoadSelection.cpp +++ b/vlsisapd/src/liberty/src/WireLoadSelection.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace std; #include "vlsisapd/liberty/WireLoadArea.h" @@ -13,14 +14,20 @@ void WireLoadSelection::addWireLoadArea(double min, double max, Name name) { _wires_load_area.push_back(area); } -void WireLoadSelection::print() { - cout << "| WireLoadSection name= " << _name.getString() << endl; +const string WireLoadSelection::getString() const{ + ostringstream chaine; + chaine << "| WireLoadSection name= " << _name.getString() << endl; for(size_t i = 0 ; i < _wires_load_area.size() ; i++) { - cout << "| wire_load_from_area name= " << _wires_load_area[i]->getName().getString() - << ", min= " << _wires_load_area[i]->getMin() - << ", max= " << _wires_load_area[i]->getMax() - << endl; + chaine << "| wire_load_from_area name= " << _wires_load_area[i]->getName().getString() + << ", min= " << _wires_load_area[i]->getMin() + << ", max= " << _wires_load_area[i]->getMax() + << endl; } + return chaine.str(); +} + +void WireLoadSelection::print() { + cout << WireLoadSelection::getString(); } bool WireLoadSelection::write(ofstream& file) { diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/Cell.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/Cell.h index 1531918c..9dff8f6a 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/Cell.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/Cell.h @@ -26,6 +26,7 @@ class Cell { void addFF(Name noninverting, Name inverting); void setTestCell(Cell *cell); + const std::string getString()const; void print(); bool write(std::ofstream &file, bool test=false); diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/FlipFlop.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/FlipFlop.h index eda28b6b..0cec777b 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/FlipFlop.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/FlipFlop.h @@ -18,6 +18,7 @@ class FlipFlop { void addAttribute(Name attrName, Attribute::Type attrType, const std::string& attrValue); + const std::string getString()const; void print(); bool write(std::ofstream &file); diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/Library.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/Library.h index 5343f278..2b6d9a9c 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/Library.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/Library.h @@ -26,6 +26,7 @@ class Library { void addWireLoadSelection(Name wireLoadSelectionName); void addCell(Name cellName); + const std::string getString()const; void print(); static Library* readFromFile(std::string); diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/Pin.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/Pin.h index c38dc747..5d8f2c3e 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/Pin.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/Pin.h @@ -22,6 +22,7 @@ class Pin { void addAttribute(Name attrName, Attribute::Type attrType, const std::string& attrValue); void addTiming(); + const std::string getString()const; void print(); bool write(std::ofstream &file); diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/Timing.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/Timing.h index 10cce4f8..810aba8f 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/Timing.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/Timing.h @@ -16,6 +16,7 @@ class Timing { void addAttribute(Name attrName, Attribute::Type attrType, const std::string& attrValue); + const std::string getString() const; void print(); bool write(std::ofstream &file); diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoad.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoad.h index 201eb0d8..37fff525 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoad.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoad.h @@ -15,6 +15,7 @@ class WireLoad { void addAttribute(Name attrName, Attribute::Type attrType, const std::string& attrValue, const std::string& attrValue2 = ""); + const std::string getString()const; void print(); bool write(std::ofstream &file); diff --git a/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoadSelection.h b/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoadSelection.h index 51a0f117..704aca9a 100644 --- a/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoadSelection.h +++ b/vlsisapd/src/liberty/src/vlsisapd/liberty/WireLoadSelection.h @@ -17,6 +17,8 @@ class WireLoadSelection { inline std::vector& getWiresLoadArea(); void addWireLoadArea(double min, double max, Name name); + + const std::string getString()const; void print(); bool write(std::ofstream& file);