* ./vlsisapd/dtr:

- Change: Completly remove Name as std::string are shared, in library,
        boost::python, doxygen documentation & examples.
This commit is contained in:
Jean-Paul Chaput 2012-03-26 15:39:08 +00:00
parent 4c876122d1
commit 5c593f4161
18 changed files with 547 additions and 583 deletions

View File

@ -1,47 +0,0 @@
// -*- C++ -*-
namespace DTR {
/*! \class Name
*
* This class provides an automatic management of shared name.
*/
/*! \fn Name::Name(std::string str)
* \brief gets a shared Name, creates it if it does not exist.
*
* \param str the string associated to the name.
*/
/*! \fn Name::Name(const char* cstr)
* \brief gets a shared Name, creates it if it does not exist.
*
* \param cstr the character string associated to the name.
*
* \note this method is not yet available in python
*/
/*! \fn bool Name::operator==(const Name&)
* \brief redifines the '==' operator.
*/
/*! \fn bool Name::operator==(const std::string&)
* \brief redifines the '==' operator.
*/
/*! \fn bool Name::operator!=(const Name&)
* \brief redifines the '!=' operator.
*/
/*! \fn bool Name::operator!=(const std::string&)
* \brief redifines the '!=' operator.
*/
/*! \fn bool Name::operator<(const Name) const
* \brief redifines the '<' operator.
*/
/*! \fn inline const std::string& Name::getString() const
* \brief returns the string associated to the Name.
*/
}

View File

@ -22,7 +22,7 @@ namespace DTR {
*
*/
/*! \fn Rule::Rule(Name name, double value, Name ref, Name layer1, Name layer2)
/*! \fn Rule::Rule(const char* name, double value, const char* ref, const char* layer1, const char* layer2)
* \brief creates a new rule.
*
* \param name the name of the rule.
@ -32,11 +32,11 @@ namespace DTR {
* \param layer2 the second layer.
*/
/*! \fn inline Name Rule::getName()
/*! \fn inline const std::string& Rule::getName()
* \brief returns the name of the rule.
*/
/*! \fn inline Name Rule::getType()
/*! \fn inline const std::string& Rule::getType()
* \brief returns the type of the rule.
*
* Rule's type allows to set a specific type for a rule especially the 'area' type to take into account that the value of the rule is to be considered in unit^2.
@ -50,24 +50,24 @@ namespace DTR {
* \brief returns the string corresponding to the value of the rule.
*/
/*! \fn inline Name Rule::getRef()
/*! \fn inline const std::string& Rule::getRef()
* \brief returns the reference of the rule.
*/
/*! \fn inline Name Rule::getLayer1()
/*! \fn inline const std::string& Rule::getLayer1()
* \brief returns the first layer of the rule.
*/
/*! \fn inline Name Rule::getLayer2()
/*! \fn inline const std::string& Rule::getLayer2()
* \brief returns the second layer of the rule.
*/
/*! \fn inline void Rule::setType(Name type)
/*! \fn inline void Rule::setType(const char* type)
* \brief sets the type of a rule.
*
* \param type the type of the rule.
*
* \note By default the type of a rule is Name("").
* \note By default the type of a rule is "".
*/
/*! \class ARule

View File

@ -6,18 +6,19 @@ namespace DTR {
* This class contains generic informations such as the name of the technology and the unit used, and the list of all technologic rules.
*/
/*! \fn Techno::Techno(Name name, Name unit)
/*! \fn Techno::Techno(const char* name, const char* unit, const char* version)
* \brief creates a new technology
*
* \param name the name of the technology.
* \param unit the unit used for all values.
* \param version the technology version/revision.
*/
/*! \fn inline Name Techno::getName()
/*! \fn inline const std::string& Techno::getName() const
* \brief returns the name of the technology.
*/
/*! \fn inline Name Techno::getUnit()
/*! \fn inline const std::string& Techno::getUnit() const
* \brief returns the unit.
*/
@ -27,19 +28,19 @@ namespace DTR {
* \note this method is not yet available in python
*/
/*! \fn Rule* Techno::addRule(Name name, double value, Name ref, Name layer1, Name layer2)
/*! \fn Rule* Techno::addRule(const char* name, double value, const char* ref, const char* layer1, const char* layer2)
* \brief creates a new Rule and adds it the to Techno object.
*
* \param name the name of the rule.
* \param value the value of the rule.
* \param ref the reference of the rule (helpful to find the rule in design kit).
* \param layer1 the first layer. This is an optionnal argument, default value is Name("").
* \param layer2 the second layer. This is an optionnal argument, default value is Name("").
* \param layer1 the first layer. This is an optionnal argument, default value is "".
* \param layer2 the second layer. This is an optionnal argument, default value is "".
*
* \return the newly created Rule object.
*/
/*! \fn Arule* Techno::addARule(Name name, double value, Name ref, Name layer1, Name layer2)
/*! \fn Arule* Techno::addARule(const char* name, double value, const char* ref, const char* layer1, const char* layer2)
* \brief creates a new ARule and adds it to the Techno object.
*
* \param name the name of the rule.
@ -51,45 +52,45 @@ namespace DTR {
* \return the newly created ARule object.
*/
/*! \fn Rule* Techno::getRule(Name name, Name layer1, Name layer2)
/*! \fn Rule* Techno::getRule(const char* name, const char* layer1, const char* layer2)
* \brief returns the rule uniquely identified by its name and layers.
*
* \param name the name of the rule.
* \param layer1 the first layer. This is an optionnal argument, default value is Name("").
* \param layer2 the second layer. This is an optionnal argument, default value is Name("").
* \param layer1 the first layer. This is an optionnal argument, default value is "".
* \param layer2 the second layer. This is an optionnal argument, default value is "".
*
* \return the rule.
*/
/*! \fn double Techno::getValue(Name name, Name layer1, Name layer2)
/*! \fn double Techno::getValue(const char* name, const char* layer1, const char* layer2)
* \brief returns the value of a rule uniquely identified by its name and layers.
*
* \param name the name of the rule.
* \param layer1 the first layer. This is an optionnal argument, default value is Name("").
* \param layer2 the second layer. This is an optionnal argument, default value is Name("").
* \param layer1 the first layer. This is an optionnal argument, default value is "".
* \param layer2 the second layer. This is an optionnal argument, default value is "".
*
* \return the value of the rule.
*/
/*! \fn std::string Techno::getValueAsString(Name name, Name layer1, Name layer2)
/*! \fn std::string Techno::getValueAsString(const char* name, const char* layer1, const char* layer2)
* \brief returns a string corresponding to the value of a rule uniquely identified by its name and layers.
*
* \param name the name of the rule.
* \param layer1 the first layer. This is an optionnal argument, default value is Name("").
* \param layer2 the second layer. This is an optionnal argument, default value is Name("").
* \param layer1 the first layer. This is an optionnal argument, default value is "".
* \param layer2 the second layer. This is an optionnal argument, default value is "".
*
* \return the string corresponding to the value of the rule.
*
* \note this method is important for python module since to avoid rounding problems it is necessary to use Decimal object which is build based on a string.
*/
/*! \fn bool Techno::writeToFile(std::string filename)
/*! \fn bool Techno::writeToFile(const char* filename)
* \brief writes the database to file.
*
* \param filename the destination file name.
*/
/*! \fn static Techno* Techno::readFromFile(const std::string filename)
/*! \fn static Techno* Techno::readFromFile(const char* filename)
* \brief creates and returns a Techno object based on a database source file.
*
* \param filename the source file name.

View File

@ -13,7 +13,6 @@
The database contains four object :
- DTR::Techno contains generic informations such as the name of the technology and the unit used, and the list of all technologic rules.
- DTR::Rule & DTR::ARule respectively describe a symmetrical and an asymmetrical rule.
- DTR::Name provides an automatic management of shared name.
The library also use the DTR::DTRException class to throw excptions.

View File

@ -3,20 +3,19 @@ using namespace std;
#include "vlsisapd/dtr/Techno.h"
#include "vlsisapd/dtr/Rules.h"
#include "vlsisapd/dtr/Name.h"
int main(int argc, char * argv[]) {
DTR::Techno* techno = new DTR::Techno(DTR::Name("MyTech"), DTR::Name("micro"), DTR::Name("rev.A"));
DTR::Techno* techno = new DTR::Techno("MyTech", "micro", "rev.A");
techno->addRule (DTR::Name("transistorMinL"), 0.1 , DTR::Name("ref1"));
techno->addRule (DTR::Name("transistorMinW"), 0.2 , DTR::Name("ref2"));
techno->addRule (DTR::Name("minWidth") , 0.15, DTR::Name("ref3"), DTR::Name("metal1"));
techno->addRule (DTR::Name("minSpacing") , 0.2 , DTR::Name("ref4"), DTR::Name("metal1"));
techno->addRule (DTR::Name("minSpacing") , 0.1 , DTR::Name("ref5"), DTR::Name("active"), DTR::Name("poly"));
techno->addARule(DTR::Name("minExtension") , 0.2 , DTR::Name("ref6"), DTR::Name("poly") , DTR::Name("active"));
techno->addRule ("transistorMinL", 0.1 , "ref1");
techno->addRule ("transistorMinW", 0.2 , "ref2");
techno->addRule ("minWidth" , 0.15, "ref3", "metal1");
techno->addRule ("minSpacing" , 0.2 , "ref4", "metal1");
techno->addRule ("minSpacing" , 0.1 , "ref5", "active", "poly");
techno->addARule("minExtension" , 0.2 , "ref6", "poly" , "active");
DTR::Rule* rule = techno->addRule(DTR::Name("minArea"), 0.1, DTR::Name("ref7"), DTR::Name("metal1"));
rule->setType(DTR::Name("area"));
DTR::Rule* rule = techno->addRule("minArea", 0.1, "ref7", "metal1");
rule->setType("area");
techno->writeToFile("./out.dtr.xml");

View File

@ -3,24 +3,23 @@
using namespace std;
#include "vlsisapd/dtr/Techno.h"
#include "vlsisapd/dtr/Name.h"
int main(int argc, char * argv[]) {
DTR::Techno* techno = DTR::Techno::readFromFile("./example.dtr.xml");
cerr << "+-----------------------------+" << endl
<< "| technology: " << techno->getName().getString() << " |" << endl
<< "| units: " << techno->getUnit().getString() << " |" << endl
<< "| version: " << techno->getVersion().getString() << " |" << endl
<< "| technology: " << techno->getName() << " |" << endl
<< "| units: " << techno->getUnit() << " |" << endl
<< "| version: " << techno->getVersion() << " |" << endl
<< "+-----------------------------+" << endl << endl;
cerr << "transistorMinL = " << techno->getValue(DTR::Name("transistorMinL")) << endl
<< "transistorMinW = " << techno->getValueAsString(DTR::Name("transistorMinW")) << endl
<< "minWidth of metal1 = " << techno->getValue(DTR::Name("minWidth"), DTR::Name("metal1")) << endl
<< "minSpacing of metal1 = " << techno->getValue(DTR::Name("minWidth"), DTR::Name("metal1")) << endl
<< "minSpacing of active vs poly = " << techno->getValue(DTR::Name("minSpacing"), DTR::Name("active"), DTR::Name("poly")) << endl
<< "minExtension active over poly = " << techno->getValue(DTR::Name("minExtension"), DTR::Name("poly"), DTR::Name("active")) << endl
<< "minArea of metal1 = " << techno->getValue(DTR::Name("minArea"), DTR::Name("metal1")) << endl;
cerr << "transistorMinL = " << techno->getValue("transistorMinL") << endl
<< "transistorMinW = " << techno->getValueAsString("transistorMinW") << endl
<< "minWidth of metal1 = " << techno->getValue("minWidth", "metal1") << endl
<< "minSpacing of metal1 = " << techno->getValue("minWidth", "metal1") << endl
<< "minSpacing of active vs poly = " << techno->getValue("minSpacing", "active", "poly") << endl
<< "minExtension active over poly = " << techno->getValue("minExtension", "poly", "active") << endl
<< "minArea of metal1 = " << techno->getValue("minArea", "metal1") << endl;
return 0;
}

View File

@ -1,15 +1,15 @@
from DTR import *
techno = Techno(Name("myTech"), Name("micro"), Name("rev.A"))
techno = Techno("myTech", "micro", "rev.A")
techno.addRule (Name("transistorMinL"), 0.1 , Name("ref1"))
techno.addRule (Name("transistorMinW"), 0.2 , Name("ref2"))
techno.addRule (Name("minWidth") , 0.15, Name("ref3"), Name("metal1"))
techno.addRule (Name("minSpacing") , 0.2 , Name("ref4"), Name("metal1"))
techno.addRule (Name("minSpacing") , 0.1 , Name("ref5"), Name("active"), Name("poly"))
techno.addARule(Name("minExtension") , 0.2 , Name("ref6"), Name("poly"), Name("active"))
techno.addRule ("transistorMinL", 0.1 , "ref1")
techno.addRule ("transistorMinW", 0.2 , "ref2")
techno.addRule ("minWidth" , 0.15, "ref3", "metal1")
techno.addRule ("minSpacing" , 0.2 , "ref4", "metal1")
techno.addRule ("minSpacing" , 0.1 , "ref5", "active", "poly")
techno.addARule("minExtension" , 0.2 , "ref6", "poly", "active")
rule = techno.addRule(Name("minArea"), 0.1, Name("ref7"), Name("metal1"))
rule.setType(Name("area"))
rule = techno.addRule("minArea", 0.1, "ref7", "metal1")
rule.setType("area")
techno.writeToFile("./out.dtr.xml")

View File

@ -4,19 +4,19 @@ from decimal import Decimal
techno = Techno.readFromFile("./example.dtr.xml")
print "+-----------------------------+"
print "| technology: "+techno.getName().getString()+" |"
print "| units: "+techno.getUnit().getString()+" |"
print "| version: "+techno.getVersion().getString()+" |"
print "| technology: "+techno.get) + " |"
print "| units: "+techno.getUnit() +" |"
print "| version: "+techno.getVersion()+" |"
print "+-----------------------------+\n\n"
print "transistorMinL = %s"%techno.getValue(Name("transistorMinL"))
print "transistorMinW = %s"%Decimal(techno.getValueAsString(Name("transistorMinW")))
print "minWidth of metal1 = %s"%techno.getValue(Name("minWidth"), Name("metal1"))
print "minSpacing of metal1 = %s"%techno.getValue(Name("minWidth"), Name("metal1"))
print "minSpacing of active vs poly = %s"%techno.getValue(Name("minSpacing"), Name("active"), Name("poly"))
print "minExtension active over poly = %s"%techno.getValue(Name("minExtension"), Name("poly"), Name("active"))
print "minArea of metal1 = %s"%techno.getValue(Name("minArea"), Name("metal1"))
print "transistorMinL = %s"%techno.getValue("transistorMinL")
print "transistorMinW = %s"%Decimal(techno.getValueAsString("transistorMinW"))
print "minWidth of metal1 = %s"%techno.getValue("minWidth", "metal1")
print "minSpacing of metal1 = %s"%techno.getValue("minWidth", "metal1")
print "minSpacing of active vs poly = %s"%techno.getValue("minSpacing", "active", "poly")
print "minExtension active over poly = %s"%techno.getValue("minExtension", "poly", "active")
print "minArea of metal1 = %s"%techno.getValue("minArea", "metal1")
# an example of why it is important to use Decimal in python:
print techno.getValue(Name("minArea"), Name("metal1"))*3-0.3 # returns 5.55111512313e-17
print Decimal(techno.getValueAsString(Name("minArea"), Name("metal1")))*3-Decimal('0.3') # returns 0.000
print techno.getValue("minArea", "metal1")*3-0.3 # returns 5.55111512313e-17
print Decimal(techno.getValueAsString("minArea", "metal1"))*3-Decimal('0.3') # returns 0.000

View File

@ -18,12 +18,12 @@ using namespace std;
int main(int argc, char * argv[]) {
OpenChams::Circuit* circuit = new OpenChams::Circuit(OpenChams::Name("design"), OpenChams::Name("myTech"));
// value parameters
circuit->addParameter(OpenChams::Name("temp"), 27.0 );
circuit->addParameter(OpenChams::Name("Vdd") , 1.2 );
circuit->addParameter(OpenChams::Name("Vss") , 0.0 );
circuit->addParameter(OpenChams::Name("L") , 0.1e-6);
circuit->addParameter(OpenChams::Name("Ids") , 30e-6 );
circuit->addParameter(OpenChams::Name("Veg") , 0.12 );
circuit->addParameter(OpenChams::Name("temp"), "27.0" );
circuit->addParameter(OpenChams::Name("Vdd") , "1.2" );
circuit->addParameter(OpenChams::Name("Vss") , "0.0" );
circuit->addParameter(OpenChams::Name("L") , "0.1e-6");
circuit->addParameter(OpenChams::Name("Ids") , "30e-6" );
circuit->addParameter(OpenChams::Name("Veg") , "0.12" );
// equation parameters
circuit->addParameter(OpenChams::Name("complex"), "myEq");

View File

@ -90,10 +90,7 @@ int main(int argc, char * argv[]) {
cerr << " + parameters" << endl;
OpenChams::Parameters params = circuit->getParameters();
if (!params.isEmpty()) {
for (map<OpenChams::Name, double>::const_iterator it = params.getValues().begin() ; it != params.getValues().end() ; ++it) {
cerr << " | | " << ((*it).first).getString() << " : " << (*it).second << endl;
}
for (map<OpenChams::Name, string>::const_iterator it = params.getEqValues().begin() ; it != params.getEqValues().end() ; ++it) {
for (map<OpenChams::Name, string>::const_iterator it = params.getValues().begin() ; it != params.getValues().end() ; ++it) {
cerr << " | | " << ((*it).first).getString() << " : " << (*it).second << endl;
}
}

View File

@ -2,12 +2,10 @@ INCLUDE_DIRECTORIES(${VLSISAPD_SOURCE_DIR}/src/dtr/src ${LIBXML2_INCLUDE_DIR} ${
SET ( hpps vlsisapd/dtr/Techno.h
vlsisapd/dtr/Rules.h
vlsisapd/dtr/Name.h
vlsisapd/dtr/DTRException.h
)
SET ( cpps Techno.cpp
Name.cpp
)
SET ( pycpps PyDtr.cpp

View File

@ -1,65 +0,0 @@
/*
* Name.cpp
* DTR
*
* Created by damien dupuis on 01/04/10.
* Copyright 2010 UPMC / LIP6. All rights reserved.
*
*/
using namespace std;
#include "vlsisapd/dtr/Name.h"
namespace DTR {
unsigned long Name::_globalId = 0;
map<string, unsigned long> Name::_dict;
Name::Name(string str) : _str(NULL) {
map<string, unsigned long>::iterator it = _dict.find(str);
if (it != _dict.end()) {
_id = (*it).second;
_str = &((*it).first);
} else {
_id = _globalId++;
it = _dict.insert(_dict.begin(), make_pair(str, _id));
_str = &((*it).first);
}
}
Name::Name(const char* c) : _str(NULL) {
string str(c);
map<string, unsigned long>::iterator it = _dict.find(str);
if (it != _dict.end()) {
_id = (*it).second;
_str = &((*it).first);
} else {
_id = _globalId++;
it = _dict.insert(_dict.begin(), make_pair(str, _id));
_str = &((*it).first);
}
}
bool Name::operator==(const Name& n) {
return (_id == n._id);
}
bool Name::operator==(const string& str) {
Name n(str);
return (_id == n._id);
}
bool Name::operator!=(const Name& n) {
return (_id != n._id);
}
bool Name::operator!=(const string& str) {
Name n(str);
return (_id != n._id);
}
bool Name::operator<(const Name n) const {
return (_id < n._id);
}
} // namespace

View File

@ -1,3 +1,4 @@
using namespace std;
#include <boost/python.hpp>
@ -7,71 +8,62 @@ using namespace boost::python;
#include "vlsisapd/dtr/Rules.h"
#include "vlsisapd/dtr/DTRException.h"
namespace DTR {
void translator(DTRException const& e) {
void translator(DTRException const& e) {
PyErr_SetString(PyExc_UserWarning, e.what());
}
}
// specify that Techno::getRule & Techno::getValue & Techno::getValueAsString methods have optional arguments
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getRule_overloads , getRule , 1, 3);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getValue_overloads , getValue , 1, 3);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getValueAsString_overloads, getValueAsString, 1, 3);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getRule_overloads , getRule , 1, 3);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getValue_overloads , getValue , 1, 3);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getValueAsString_overloads, getValueAsString, 1, 3);
// specify that Techno::addRule method has optional arguments
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(addRule_overloads, addRule, 3, 5);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(addRule_overloads, addRule, 3, 5);
BOOST_PYTHON_MODULE(DTR) {
// class DTR::Name
class_<Name>("Name", init<std::string>())
.def("getString", &Name::getString, return_value_policy<copy_const_reference>()) // return_value_policy because this method return a reference on string
.def(self == self)
.def(self == std::string())
.def(self != self)
.def(self != std::string())
.def(self < self)
;
implicitly_convertible<std::string, Name>();
BOOST_PYTHON_MODULE(DTR) {
// class DTR::Rule
class_<Rule>("Rule", init<Name, double, Name, Name, Name>())
// accessors
.def("getName" , &Rule::getName )
.def("getType" , &Rule::getType )
class_<Rule>("Rule", init<const char*, double, const char*, const char*, const char*>())
// Accessors.
.def("getName" , &Rule::getName , return_value_policy<copy_const_reference>())
.def("getType" , &Rule::getType , return_value_policy<copy_const_reference>())
.def("getValue" , &Rule::getValue )
.def("getValueAsString", &Rule::getValueAsString, return_value_policy<copy_const_reference>())
.def("getRef" , &Rule::getRef )
.def("getLayer1" , &Rule::getLayer1 )
.def("getLayer2" , &Rule::getLayer2 )
// modifiers
.def("getRef" , &Rule::getRef , return_value_policy<copy_const_reference>())
.def("getLayer1" , &Rule::getLayer1 , return_value_policy<copy_const_reference>())
.def("getLayer2" , &Rule::getLayer2 , return_value_policy<copy_const_reference>())
// Mutators.
.def("setType" , &Rule::setType )
.def("setValue" , &Rule::setValue )
.def("setRef" , &Rule::setRef )
;
// class DTR::ARule derived from DTR::Rule
class_<ARule, bases<Rule> >("ARule", init<Name, double, Name, Name, Name>())
class_<ARule,bases<Rule> >("ARule", init<const char*, double, const char*, const char*, const char*>())
;
// class DTR::Techno
class_<Techno>("Techno", init<Name, Name, Name>())
// accessors
.def("getName" , &Techno::getName)
.def("getUnit" , &Techno::getUnit)
.def("getVersion" , &Techno::getVersion)
class_<Techno>("Techno", init<const char*, const char*, const char*>())
// Accessors
.def("getName" , &Techno::getName , return_value_policy<copy_const_reference>())
.def("getUnit" , &Techno::getUnit , return_value_policy<copy_const_reference>())
.def("getVersion" , &Techno::getVersion , return_value_policy<copy_const_reference>())
.def("getRule" , &Techno::getRule , getRule_overloads()[return_value_policy<reference_existing_object>()])
.def("getValue" , &Techno::getValue , getValue_overloads())
.def("getValueAsString", &Techno::getValueAsString, getValueAsString_overloads()[return_value_policy<copy_const_reference>()])
// modifiers
// Mutators.
.def("setName" , &Techno::setName)
.def("setUnit" , &Techno::setUnit)
.def("setVersion" , &Techno::setVersion)
.def("addRule" , &Techno::addRule , addRule_overloads()[return_value_policy<reference_existing_object>()])
.def("addARule" , &Techno::addARule, return_value_policy<reference_existing_object>())
// others
// Miscellaneous.
.def("readFromFile", &Techno::readFromFile, return_value_policy<reference_existing_object>())
.staticmethod("readFromFile")
.def("writeToFile" , &Techno::writeToFile)
@ -80,5 +72,8 @@ BOOST_PYTHON_MODULE(DTR) {
// DTRException translator
register_exception_translator<DTRException>(translator)
;
}
}
} // DTR boost::python module.
} // DTR namespace.

View File

@ -1,11 +1,19 @@
/*
* Techno.cpp
* DTR
*
* Created by damien dupuis on 01/04/10.
* Copyright 2010 UPMC / LIP6. All rights reserved.
*
*/
// -*- C++ -*-
//
// This file is part of the VLSI SAPD Software.
// Copyright (c) UPMC/LIP6 2010-2012, All Rights Reserved
//
// +-----------------------------------------------------------------+
// | V L S I S A P D |
// | Design Technological Rules (DTR) |
// | |
// | Author : Damien Dupuis |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Module : "./Techno.cpp" |
// +-----------------------------------------------------------------+
#include <iostream>
#include <iomanip>
@ -23,8 +31,12 @@ using namespace std;
#include "vlsisapd/dtr/Rules.h"
#include "vlsisapd/dtr/DTRException.h"
namespace {
template<class T> T getValue(xmlChar* str) {
template<class T> T getValue(xmlChar* str)
{
if (string((const char*)str).empty())
return numeric_limits<T>::quiet_NaN();
std::istringstream iss;
@ -33,59 +45,101 @@ namespace {
iss >> res;
return res;
}
}
} // Anonymous namespace.
namespace DTR {
Techno::Techno(Name name, Name unit, Name version) : _name(name), _unit(unit), _version(version) {}
Rule* Techno::addRule (Name name, double value, Name ref, Name layer1, Name layer2) {
Techno::Techno ( const string& name, const string& unit, const string& version )
: _name (name)
, _unit (unit)
, _version(version)
{ }
Techno::Techno ( const char* name, const char* unit, const char* version )
: _name (name)
, _unit (unit)
, _version((version) ? version : "")
{
// Cannot initialize a std::string from a NULL pointer.
}
Rule* Techno::addRule ( const char* name
, double value
, const char* ref
, const char* layer1
, const char* layer2 )
{
Rule* rule = new Rule(name, value, ref, layer1, layer2);
_rules.push_back(rule);
return rule;
}
}
ARule* Techno::addARule (Name name, double value, Name ref, Name layer1, Name layer2) {
ARule* Techno::addARule ( const char* name
, double value
, const char* ref
, const char* layer1
, const char* layer2 )
{
ARule* arule = new ARule(name, value, ref, layer1, layer2);
_rules.push_back(arule);
return arule;
}
}
Rule* Techno::getRule(Name name, Name layer1, Name layer2) {
Rule* Techno::getRule ( const char* name, const char* layer1, const char* layer2 )
{
for (size_t i = 0 ; i < _rules.size() ; i++) {
Rule* rule = _rules[i];
if ((rule->getName() == name) && (rule->getLayer1() == layer1) && (rule->getLayer2() == layer2))
return rule;
}
return NULL;
}
}
double Techno::getValue(Name name, Name layer1, Name layer2) {
double Techno::getValue ( const char* name, const char* layer1, const char* layer2 )
{
Rule* r = getRule(name, layer1, layer2);
if(!r) {
string error = "[ERROR] Could not find rule: " + name.getString() + "." + layer1.getString() + "." + layer2.getString() + ".";
throw DTRException(error);
ostringstream error;
error << "[ERROR] Could not find rule: " << name << "." << layer1 << "." << layer2 << ".";
throw DTRException(error.str());
}
return r->getValue();
}
}
const string& Techno::getValueAsString(Name name, Name layer1, Name layer2) {
const string& Techno::getValueAsString ( const char* name, const char* layer1, const char* layer2 )
{
Rule* r = getRule(name, layer1, layer2);
if(!r) {
string error = "[ERROR] Could not find rule: " + name.getString() + "." + layer1.getString() + "." + layer2.getString() + ".";
throw DTRException(error);
ostringstream error;
error << "[ERROR] Could not find rule: " << name << "." << layer1 << "." << layer2 << ".";
throw DTRException(error.str());
}
return r->getValueAsString();
}
}
Techno* Techno::readFromFile(const string filePath) {
Techno* Techno::readFromFile ( const char* filePath )
{
LIBXML_TEST_VERSION;
Techno* techno = NULL;
xmlDoc* doc = xmlReadFile(filePath.c_str(), NULL, 0);
xmlDoc* doc = xmlReadFile(filePath, NULL, 0);
if (doc == NULL) {
string error ("[ERROR] Failed to parse: ");
error += filePath;
throw DTRException(error);
}
xmlNode* rootElement = xmlDocGetRootElement(doc);
if (rootElement->type == XML_ELEMENT_NODE && xmlStrEqual(rootElement->name, (xmlChar*)"technology")) {
xmlChar* technoNameC = xmlGetProp(rootElement, (xmlChar*)"name");
@ -93,18 +147,12 @@ Techno* Techno::readFromFile(const string filePath) {
xmlChar* technoVersC = xmlGetProp(rootElement, (xmlChar*)"version");
if (technoNameC && technoUnitC) {
Name name ((const char*)technoNameC);
Name unit ((const char*)technoUnitC);
Name vers = Name("");
if (technoVersC)
vers = Name((const char*)technoVersC);
techno = new Techno(name, unit, vers);
techno = new Techno((char*)technoNameC, (char*)technoUnitC, (char*)technoVersC);
} else {
throw DTRException("[ERROR] 'technology' node must have 'name' and 'unit' properties.");
return NULL;
}
xmlNode* child = rootElement->children;
for (xmlNode* node = child; node; node = node->next) {
if (node->type == XML_ELEMENT_NODE) {
@ -112,6 +160,7 @@ Techno* Techno::readFromFile(const string filePath) {
throw DTRException("[ERROR] only 'physical_rules' node is allowed under 'technology' node.");
return NULL;
}
for (xmlNode* subnode = node->children ; subnode ; subnode = subnode->next) {
if (subnode->type == XML_ELEMENT_NODE) {
if (xmlStrEqual(subnode->name, (xmlChar*)"rule")) {
@ -124,31 +173,32 @@ Techno* Techno::readFromFile(const string filePath) {
xmlChar* typeC = xmlGetProp(subnode, (xmlChar*)"type" );
Rule* rule = NULL;
if (nameC && layer1C && layer2C && valueC && refC) { // rule with two layers
Name name ((const char*)nameC);
Name ref ((const char*)refC);
Name layer1 ((const char*)layer1C);
Name layer2 ((const char*)layer2C);
double value = ::getValue<double>(valueC);
rule = techno->addRule(name, value, ref, layer1, layer2);
} else if (nameC && layerC && valueC && refC) {// rule with only one layer
Name name ((const char*)nameC);
Name ref ((const char*)refC);
Name layer ((const char*)layerC);
double value = ::getValue<double>(valueC);
rule = techno->addRule(name, value, ref, layer);
} else if (nameC && valueC && refC) { // rule without layer
Name name ((const char*)nameC);
Name ref ((const char*)refC);
double value = ::getValue<double>(valueC);
rule = techno->addRule(name, value, ref);
} else { // invalid case
if (nameC and layer1C and layer2C and valueC and refC) {
// Rule with two layers
rule = techno->addRule( (char*)nameC
, ::getValue<double>(valueC)
, (char*)refC
, (char*)layer1C
, (char*)layer2C );
} else if (nameC and layerC and valueC and refC) {
// Rule with only one layer
rule = techno->addRule( (char*)nameC
, ::getValue<double>(valueC)
, (char*)refC
, (char*)layerC );
} else if (nameC and valueC and refC) {
// Rule without layer
rule = techno->addRule( (char*)nameC
, ::getValue<double>(valueC)
, (char*)refC );
} else {
// Invalid case
throw DTRException("[ERROR] properties of 'rule' node must be ('name', 'value', 'ref') or ('name', 'layer', 'value', 'ref') or ('name', 'layer1', 'layer2', 'value', 'ref').");
return NULL;
}
if (typeC) {
Name type ((const char*)typeC);
rule->setType(type);
rule->setType((const char*)typeC);
}
} else if (xmlStrEqual(subnode->name, (xmlChar*)"arule")) {
xmlChar* nameC = xmlGetProp(subnode, (xmlChar*)"name" );
@ -156,13 +206,13 @@ Techno* Techno::readFromFile(const string filePath) {
xmlChar* layer2C = xmlGetProp(subnode, (xmlChar*)"layer2");
xmlChar* valueC = xmlGetProp(subnode, (xmlChar*)"value" );
xmlChar* refC = xmlGetProp(subnode, (xmlChar*)"ref" );
if (nameC && layer1C && layer2C && valueC && refC) {
Name name ((const char*)nameC);
Name layer1 ((const char*)layer1C);
Name layer2 ((const char*)layer2C);
Name ref ((const char*)refC);
double value = ::getValue<double>(valueC);
techno->addARule(name, value, ref, layer1, layer2);
techno->addARule( (char*)nameC
, ::getValue<double>(valueC)
, (char*)refC
, (char*)layer1C
, (char*)layer2C );
} else {
throw DTRException("[ERROR] 'arule' node must have 'name', 'layer1', 'layer2', 'value' and 'ref' properties.");
return NULL;
@ -176,44 +226,47 @@ Techno* Techno::readFromFile(const string filePath) {
}
}
return techno;
}
}
bool Techno::writeToFile(string filePath) {
bool Techno::writeToFile ( const char* filePath )
{
ofstream file;
file.open(filePath.c_str());
file.open(filePath);
if (!file.is_open()) {
string error("[ERROR] Cannot open file ");
error += filePath;
error += " for writting.";
throw DTRException(error);
}
// checks before do anything
if (_rules.size() == 0) {
throw DTRException("[ERROR] Cannot writeToFile since no rule is defined!");
}
file << "<technology name=\"" << _name.getString() << "\" unit=\"" << _unit.getString() << "\" version=\"" << _version.getString() << "\">" << endl
file << "<technology name=\"" << _name << "\" unit=\"" << _unit << "\" version=\"" << _version << "\">" << endl
<< " <physical_rules>" << endl;
file.setf(ios::left, ios::adjustfield);
for (size_t i = 0 ; i < _rules.size() ; i++) {
Rule* rule = _rules[i];
string name = "\""+rule->getName().getString()+"\"";
string name = "\""+rule->getName()+"\"";
if (dynamic_cast<ARule*>(rule)) {
file << " <arule name=" << setw(20) << name << " ";
} else {
file << " <rule name=" << setw(20) << name << " ";
}
int spacing = 18;
if (rule->getType() != Name("")) {
string type = "\""+rule->getType().getString()+"\"";
if (not rule->getType().empty()) {
string type = "\""+rule->getType()+"\"";
file << "type=" << setw(12) << type << " ";
spacing = 0;
}
if (rule->getLayer1() != Name("")) {
string l1 = "\""+rule->getLayer1().getString()+"\"";
if (rule->getLayer2() != Name("")) {
string l2 = "\""+rule->getLayer2().getString()+"\"";
if (not rule->getLayer1().empty()) {
string l1 = "\""+rule->getLayer1()+"\"";
if (not rule->getLayer2().empty()) {
string l2 = "\""+rule->getLayer2()+"\"";
file << "layer1=" << setw(10) << l1 << " layer2=" << setw(10) << l2 << " ";
} else {
file << "layer=" << setw(11+spacing) << l1 << " ";
@ -221,15 +274,17 @@ bool Techno::writeToFile(string filePath) {
} else {
file << setw(36) << " ";
}
ostringstream oss;
oss << "\"" << rule->getValue() <<"\"";
file << "value=" << setw(7) << oss.str() << " ref=\"" << rule->getRef().getString() << "\"/>" << endl;
file << "value=" << setw(7) << oss.str() << " ref=\"" << rule->getRef() << "\"/>" << endl;
}
file << " </physical_rules>" << endl
<< "</technology>" << endl;
file.close();
return true;
}
}
}
} // DTR namespace.

View File

@ -1,11 +1,19 @@
/*
* DTRException.h
* DTR
*
* Created by damien dupuis on 01/04/10.
* Copyright 2010 UPMC / LIP6. All rights reserved.
*
*/
// -*- C++ -*-
//
// This file is part of the VLSI SAPD Software.
// Copyright (c) UPMC/LIP6 2010-2012, All Rights Reserved
//
// +-----------------------------------------------------------------+
// | V L S I S A P D |
// | Design Technological Rules (DTR) |
// | |
// | Author : Damien Dupuis |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Header : "./vlsisapd/dtr/Rule.h" |
// +-----------------------------------------------------------------+
#ifndef __DTR_EXCEPTION_H__
#define __DTR_EXCEPTION_H__
@ -13,16 +21,26 @@
#include <exception>
#include <string>
namespace DTR {
class DTRException {
public:
DTRException(const std::string& what) throw() : _what(what) {}
virtual const char* what() const throw() { return _what.c_str(); }
virtual ~DTRException() throw() {}
namespace DTR {
class DTRException {
public:
inline DTRException (const std::string& what) throw();
inline virtual ~DTRException () throw();
inline virtual const char* what () const throw();
private:
std::string _what;
};
} // namespace
};
inline DTRException::DTRException ( const std::string& what ) throw() : _what(what) {}
inline DTRException::~DTRException () throw() {}
inline const char* DTRException::what () const throw() { return _what.c_str(); }
} // DTR namespace.
#endif

View File

@ -1,49 +0,0 @@
/*
* Name.h
* DTR
*
* Created by damien dupuis on 01/04/10.
* Copyright 2010 UPMC / LIP6. All rights reserved.
*
*/
#ifndef __DTR_NAME_H__
#define __DTR_NAME_H__
#include <string>
#include <map>
#include "vlsisapd/dtr/DTRException.h"
namespace DTR {
class Name {
public:
Name(std::string);
Name(const char*);
bool operator==(const Name&);
bool operator==(const std::string&);
bool operator!=(const Name&);
bool operator!=(const std::string&);
bool operator<(const Name) const;
inline const std::string& getString() const;
private:
unsigned long _id;
const std::string *_str;
static std::map<std::string, unsigned long> _dict;
static unsigned long _globalId;
};
inline const std::string& Name::getString() const{
if (!_str) {
throw DTRException("[ERROR] Name object has no string");
}
return *_str;
}
} // namespace
#endif

View File

@ -1,11 +1,19 @@
/*
* Rules.h
* DTR
*
* Created by damien dupuis on 01/04/10.
* Copyright 2010 UPMC / LIP6 All rights reserved.
*
*/
// -*- C++ -*-
//
// This file is part of the VLSI SAPD Software.
// Copyright (c) UPMC/LIP6 2010-2012, All Rights Reserved
//
// +-----------------------------------------------------------------+
// | V L S I S A P D |
// | Design Technological Rules (DTR) |
// | |
// | Author : Damien Dupuis |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Header : "./vlsisapd/dtr/Rule.h" |
// +-----------------------------------------------------------------+
#ifndef __DTR_RULES_H__
#define __DTR_RULES_H__
@ -13,67 +21,99 @@
#include <string>
#include <sstream>
#include "vlsisapd/dtr/Name.h"
namespace DTR {
template <typename T>
std::string to_string(T const& value) {
std::stringstream sstr;
sstr << value;
return sstr.str();
}
class Rule {
template<typename T>
inline std::string asString ( T value )
{ std::ostringstream output; output << value; return output.str(); }
class Rule {
public:
Rule(Name name, double value, Name ref, Name layer1, Name layer2)
: _name(name), _type(Name("")), _value(value), _valueStr(to_string(value)), _ref(ref), _layer1(layer1), _layer2(layer2) {};
// CTOR & DTOR.
inline Rule ( const char* name
, double value
, const char* ref
, const char* layer1
, const char* layer2 );
inline virtual ~Rule ();
// Accessors.
inline const std::string& getName ();
inline const std::string& getType ();
inline double getValue ();
inline const std::string& getValueAsString ();
inline const std::string& getRef ();
inline const std::string& getLayer1 ();
inline virtual const std::string& getLayer2 ();
// Modifiers
inline void setType ( const char* );
inline void setValue ( double );
inline void setRef ( const char* );
virtual ~Rule() {}
// accessors
inline Name getName();
inline Name getType();
inline double getValue();
inline const std::string& getValueAsString();
inline Name getRef();
inline Name getLayer1();
virtual inline Name getLayer2(); // add virtual so the Rule object is polymorphic
// modifiers
inline void setType(Name);
inline void setValue(double);
inline void setRef(Name);
// members
// Attributes.
private:
Name _name;
Name _type;
std::string _name;
std::string _type;
double _value;
Name _valueStr;
Name _ref;
Name _layer1;
Name _layer2;
};
std::string _valueStr;
std::string _ref;
std::string _layer1;
std::string _layer2;
};
class ARule : public Rule {
class ARule : public Rule {
public:
ARule(Name name, double value, Name ref, Name layer1, Name layer2)
: Rule(name, value, ref, layer1, layer2) {};
inline ARule ( const char* name
, double value
, const char* ref
, const char* layer1
, const char* layer2 );
inline virtual ~ARule ();
};
virtual ~ARule() {}
};
inline Name Rule::getName() { return _name; };
inline Name Rule::getType() { return _type; };
inline double Rule::getValue() { return _value; };
inline Name Rule::getRef() { return _ref; };
inline Name Rule::getLayer1() { return _layer1; };
inline Name Rule::getLayer2() { return _layer2; };
inline const std::string& Rule::getValueAsString() { return _valueStr.getString(); };
inline Rule::Rule ( const char* name
, double value
, const char* ref
, const char* layer1
, const char* layer2 )
: _name (name)
, _type ("")
, _value (value)
, _valueStr(asString(value))
, _ref (ref)
, _layer1 (layer1)
, _layer2 (layer2)
{ }
inline Rule::~Rule ()
{ }
inline const std::string& Rule::getName () { return _name; };
inline const std::string& Rule::getType () { return _type; };
inline double Rule::getValue () { return _value; };
inline const std::string& Rule::getRef () { return _ref; };
inline const std::string& Rule::getLayer1 () { return _layer1; };
inline const std::string& Rule::getLayer2 () { return _layer2; };
inline const std::string& Rule::getValueAsString () { return _valueStr; };
inline void Rule::setType ( const char* type ) { _type=type; };
inline void Rule::setValue ( double value ) { _value=value; _valueStr=asString(value); };
inline void Rule::setRef ( const char* ref ) { _ref=ref; };
inline ARule::ARule ( const char* name
, double value
, const char* ref
, const char* layer1
, const char* layer2 )
: Rule(name, value, ref, layer1, layer2)
{ }
inline ARule::~ARule ()
{ }
inline void Rule::setType(Name type) { _type = type; };
inline void Rule::setValue(double value) { _value = value; _valueStr = to_string(value); };
inline void Rule::setRef(Name ref) { _ref = ref; };
} // namespace DTR
#endif

View File

@ -1,63 +1,87 @@
/*
* Techno.h
* DTR
*
* Created by damien dupuis on 01/04/10.
* Copyright 2010 UPMC / LIP6 All rights reserved.
*
*/
// -*- C++ -*-
//
// This file is part of the VLSI SAPD Software.
// Copyright (c) UPMC/LIP6 2010-2012, All Rights Reserved
//
// +-----------------------------------------------------------------+
// | V L S I S A P D |
// | Design Technological Rules (DTR) |
// | |
// | Author : Damien Dupuis |
// | E-mail : Jean-Paul.Chaput@lip6.fr |
// | =============================================================== |
// | C++ Header : "./vlsisapd/dtr/Techno.h" |
// +-----------------------------------------------------------------+
#ifndef __DTR_TECHNO_H__
#define __DTR_TECHNO_H__
#include <vector>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "vlsisapd/dtr/Name.h"
namespace DTR {
class Rule;
class ARule;
class Techno {
class Rule;
class ARule;
class Techno {
public:
Techno(Name name, Name unit, Name version);
Techno ( const std::string& name
, const std::string& unit
, const std::string& version );
Techno ( const char* name
, const char* unit
, const char* version );
inline const std::string& getName () const;
inline const std::string& getUnit () const;
inline const std::string& getVersion () const;
inline std::vector<Rule*>& getRules ();
inline Name getName();
inline Name getUnit();
inline Name getVersion();
inline std::vector<Rule*>& getRules();
inline void setName(Name);
inline void setUnit(Name);
inline void setVersion(Name);
Rule* addRule (Name name, double value, Name ref, Name layer1=Name(""), Name layer2=Name(""));
ARule* addARule(Name name, double value, Name ref, Name layer1 , Name layer2);
Rule* getRule(Name name, Name layer1=Name(""), Name layer2=Name(""));
double getValue(Name name, Name layer1=Name(""), Name layer2=Name(""));
const std::string& getValueAsString(Name name, Name layer1=Name(""), Name layer2=Name(""));
bool writeToFile(std::string filePath);
static Techno* readFromFile(const std::string filePath);
Name _name;
Name _unit;
Name _version;
inline void setName ( const std::string&);
inline void setUnit ( const std::string&);
inline void setVersion ( const std::string&);
Rule* addRule ( const char* name
, double value
, const char* ref
, const char* layer1=""
, const char* layer2="" );
ARule* addARule ( const char* name
, double value
, const char* ref
, const char* layer1
, const char* layer2 );
Rule* getRule ( const char* name
, const char* layer1=""
, const char* layer2="" );
double getValue ( const char* name
, const char* layer1=""
, const char* layer2="" );
const std::string& getValueAsString ( const char* name
, const char* layer1=""
, const char* layer2="" );
bool writeToFile ( const char* filePath );
static Techno* readFromFile ( const char* filePath );
private:
std::string _name;
std::string _unit;
std::string _version;
std::vector<Rule*> _rules;
};
};
inline Name Techno::getName() { return _name; };
inline Name Techno::getUnit() { return _unit; };
inline Name Techno::getVersion() { return _version; };
inline std::vector<Rule*>& Techno::getRules() { return _rules; };
inline void Techno::setName (Name name) { _name = name; };
inline void Techno::setUnit (Name unit) { _unit = unit; };
inline void Techno::setVersion(Name version) { _version = version; };
inline const std::string& Techno::getName () const { return _name; };
inline const std::string& Techno::getUnit () const { return _unit; };
inline const std::string& Techno::getVersion() const { return _version; };
inline std::vector<Rule*>& Techno::getRules () { return _rules; };
inline void Techno::setName (const std::string& name) { _name = name; };
inline void Techno::setUnit (const std::string& unit) { _unit = unit; };
inline void Techno::setVersion(const std::string& version) { _version = version; };
} // namespace DTR.
} // namespace DTR
#endif