00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <boost/test/unit_test.hpp>
00020 #include "torc/architecture/Sites.hpp"
00021 #include "torc/architecture/DDB.hpp"
00022 #include "torc/architecture/XdlImporter.hpp"
00023 #include "torc/physical/Design.hpp"
00024 #include "torc/common/DirectoryTree.hpp"
00025 #include "torc/physical/ConfigMap.hpp"
00026 #include "torc/physical/Circuit.hpp"
00027 #include "torc/physical/Instance.hpp"
00028 #include "torc/physical/Named.hpp"
00029 #include <boost/regex.hpp>
00030 #include <string>
00031 #include <map>
00032 #include <fstream>
00033 #include <iostream>
00034
00035
00036 namespace torc {
00037 namespace architecture {
00038
00039 BOOST_AUTO_TEST_SUITE(architecture)
00040
00041
00042
00043
00044 BOOST_AUTO_TEST_CASE(iterate_configmaps) {
00045
00046 using namespace torc::physical;
00047
00048
00049 boost::filesystem::path regressionPath
00050 = torc::common::DirectoryTree::getExecutablePath() / "regression";
00051 boost::filesystem::path generatedPath = regressionPath / "DesignUnitTest.generated.xdl";
00052 boost::filesystem::path referencePath = regressionPath / "DesignUnitTest.reference.xdl";
00053
00054
00055 std::fstream fileStream(referencePath.string().c_str());
00056 BOOST_REQUIRE(fileStream.good());
00057 XdlImporter importer;
00058
00059 importer(fileStream, referencePath.string());
00060
00061
00062 torc::physical::DesignSharedPtr designPtr = importer.getDesignPtr();
00063 BOOST_REQUIRE(designPtr.get() != 0);
00064
00065 Circuit::InstanceSharedPtrConstIterator p = designPtr->instancesBegin();
00066 Circuit::InstanceSharedPtrConstIterator e = designPtr->instancesEnd();
00067
00068 while(p < e){
00069 InstanceSharedPtr instancePtr = *p++;
00070 std::cout << "Instance:" << instancePtr->getName() << std::endl;
00071 ConfigMap::const_iterator cp = instancePtr->configBegin();
00072 ConfigMap::const_iterator ce = instancePtr->configEnd();
00073 while (cp != ce){
00074 std::cout << "\tConfig:" << cp->first << "---->" << cp->second.getName() << ":" << cp->second.getValue() << std::endl;
00075 cp++;
00076 }
00077 }
00078 }
00079
00080
00081
00082
00083
00084 bool findLUTbyCfg(const std::string isit);
00085 bool findLUTbyCfg(const std::string isit)
00086 {
00087 static const boost::regex e("(^(<eqn>)|((#LUT:|#RAM:|#ROM:)<eqn>)$)");
00088 return regex_match(isit, e);
00089 }
00090 bool findFFbyCfg(const std::string isit);
00091 bool findFFbyCfg(const std::string isit)
00092 {
00093 static const boost::regex e("(^#(FF|LATCH)$)");
00094 return regex_match(isit, e);
00095 }
00096 bool findINV(const std::string isit);
00097 bool findINV(const std::string isit)
00098 {
00099 static const boost::regex e("^.*_B$");
00100 return regex_match(isit, e);
00101 }
00102 bool findROUTETHROUGH(const std::string isit);
00103 bool findROUTETHROUGH(const std::string isit)
00104 {
00105 static const boost::regex e("^_ROUTETHROUGH.*");
00106 return regex_match(isit, e);
00107 }
00108 bool findAND(const std::string isit);
00109 bool findAND(const std::string isit)
00110 {
00111 static const boost::regex e("^.*AND.*");
00112 return regex_match(isit, e);
00113 }
00114 bool findVCC(const std::string isit);
00115 bool findVCC(const std::string isit)
00116 {
00117 static const boost::regex e("^.*VCC$");
00118 return regex_match(isit, e);
00119 }
00120 bool findGND(const std::string isit);
00121 bool findGND(const std::string isit)
00122 {
00123 static const boost::regex e("^.*GND$");
00124 return regex_match(isit, e);
00125 }
00126
00127
00128
00129
00130 BOOST_AUTO_TEST_CASE(classify_elements){
00131
00132
00133
00134 DDB ddb("xc5vlx30");
00135
00136 const Sites& sites = ddb.getSites();
00137
00138
00139 typedef const Array<const PrimitiveDef> PrimitiveDefArray;
00140 PrimitiveDefArray& primitiveDefs = sites.getSiteTypes();
00141 PrimitiveDefArray::const_iterator p = primitiveDefs.begin();
00142 PrimitiveDefArray::const_iterator e = primitiveDefs.end();
00143
00144
00145 typedef std::map<std::string, PrimitiveElement*> AllElements;
00146 AllElements allElements;
00147
00148 typedef std::map<std::string, PrimitiveElement*> AllTerminals;
00149 AllTerminals allTerminals;
00150
00151 typedef std::map<std::string, PrimitiveElement*> AllSwitches;
00152 AllSwitches allSwitches;
00153
00154 typedef std::map<std::string, PrimitiveElement*> AllOrphans;
00155 AllOrphans allOrphans;
00156
00157 typedef std::map<std::string, PrimitiveElement*> AllMuxes;
00158 AllMuxes allMuxes;
00159
00160 typedef std::map<std::string, PrimitiveElement*> AllInverters;
00161 AllInverters allInverters;
00162
00163 typedef std::map<std::string, PrimitiveElement*> AllLuts;
00164 AllLuts allLuts;
00165
00166 typedef std::map<std::string, PrimitiveElement*> AllFlops;
00167 AllFlops allFlops;
00168
00169 typedef std::map<std::string, PrimitiveElement*> AllMains;
00170 AllMains allMains;
00171
00172 typedef std::map<std::string, PrimitiveElement*> AllAnds;
00173 AllAnds allAnds;
00174
00175 typedef std::map<std::string, PrimitiveElement*> AllVccs;
00176 AllVccs allVccs;
00177
00178 typedef std::map<std::string, PrimitiveElement*> AllGnds;
00179 AllGnds allGnds;
00180
00181
00182
00183 while(p < e) {
00184
00185 const PrimitiveDef& primitiveDef = *p++;
00186
00187 typedef const Array<const PrimitivePin> PrimitivePinArray;
00188
00189 const PrimitivePinArray& primitivePins = primitiveDef.getPins();
00190 PrimitivePinArray::const_iterator sp = primitivePins.begin();
00191 PrimitivePinArray::const_iterator se = primitivePins.end();
00192 const PrimitivePin primitivePin;
00193
00194 std::vector<std::string> primitivePinNames;
00195 std::vector<std::string>::const_iterator spe = unique(primitivePinNames.begin(), primitivePinNames.end());
00196 (void) spe;
00197
00198
00199 if(primitivePins.getSize() > 0) {
00200
00201 while(sp < se) {
00202 const PrimitivePin& primitivePin = *sp++;
00203 primitivePinNames.push_back(primitivePin.getName());
00204 }
00205
00206 }
00207
00208
00209 const PrimitiveElementArray& elements = primitiveDef.getElements();
00210 PrimitiveElementArray::const_iterator ep = elements.begin();
00211 PrimitiveElementArray::const_iterator ee = elements.end();
00212
00213
00214
00215 if(elements.getSize() > 0) {
00216 while(ep < ee) {
00217 const PrimitiveElement& element = *ep++;
00218
00219
00220
00221 allElements[element.getName()] = const_cast <PrimitiveElement*>(&element);
00222
00223
00224 if(primitiveDef.getName() == element.getName()){
00225
00226 allMains[element.getName()] = const_cast <PrimitiveElement*>(&element);
00227 allElements.erase(element.getName());
00228 }
00229
00230 const PrimitiveElementPinArray& elementPins = element.getPins();
00231 PrimitiveElementPinArray::const_iterator pp = elementPins.begin();
00232 PrimitiveElementPinArray::const_iterator pe = elementPins.end();
00233
00234
00235 int countPins = 0;
00236 int isINV = 0;
00237 std::string cfgValue;
00238 int totalPinCount = 0;
00239 int cfgSize = 0;
00240 int notEmpty = 0;
00241 int isLUT = 0;
00242 int isFF = 0;
00243 int isVCC = 0;
00244 int isGND = 0;
00245 int isAND = 0;
00246
00247 std::vector<std::string> elementPinNames;
00248 std::vector<std::string>::const_iterator ppe = unique(elementPinNames.begin(), elementPinNames.end());
00249 (void) ppe;
00250
00251
00252 while(pp < pe) {
00253 const PrimitiveElementPin& elementPin = *pp++;
00254
00255
00256
00257 if(elementPin.isInput() == 1){
00258 typedef std::set<std::string> StringSet;
00259 const StringSet elementCfgs = element.getCfgs();
00260 StringSet::const_iterator cp = elementCfgs.begin();
00261 StringSet::const_iterator ce = elementCfgs.end();
00262
00263
00264 while(cp != ce){
00265
00266 const std::string& isit = *cp++;
00267
00268 if(elementPin.getName() == isit){
00269 if (findINV(isit) == 1){
00270 elementPinNames.push_back(elementPin.getName());
00271 isINV = 1;
00272 countPins++;
00273 }else{
00274 elementPinNames.push_back(elementPin.getName());
00275 countPins++;
00276 }
00277 break;
00278 }
00279 cfgValue = isit;
00280
00281 cfgSize = elementCfgs.size();
00282 if(!elementCfgs.empty()) notEmpty = 1;
00283 if(findLUTbyCfg(isit) == 1){
00284 isLUT = 1;
00285 }else if(findFFbyCfg(isit) == 1){
00286 isFF = 1;
00287 }
00288 }
00289 }
00290 if((findVCC(element.getName()) == 1) && (elementPin.getName() == "1")){
00291 isVCC = 1;
00292 }else if((findGND(element.getName()) == 1) && (elementPin.getName() == "0")){
00293 isGND = 1;
00294 }else if((findAND(element.getName()) == 1) && ((elementPin.getName() == "0") || (elementPin.getName() == "1"))){
00295 isAND = 1;
00296 }
00297 totalPinCount++;
00298 }
00299
00300 if(countPins > 0) {
00301
00302 if(countPins == 1){
00303
00304 allMuxes[element.getName()] = const_cast <PrimitiveElement*>(&element);
00305 allSwitches[element.getName()] = const_cast <PrimitiveElement*>(&element);
00306 allElements.erase(element.getName());
00307 }else if(isINV == 1){
00308
00309 allMuxes[element.getName()] = const_cast <PrimitiveElement*>(&element);
00310 allInverters[element.getName()] = const_cast <PrimitiveElement*>(&element);
00311 allElements.erase(element.getName());
00312 }else if(isINV == 0){
00313
00314 allMuxes[element.getName()] = const_cast <PrimitiveElement*>(&element);
00315 allElements.erase(element.getName());
00316 }
00317
00318
00319 for (std::vector<std::string>::const_iterator b = elementPinNames.begin(); b != elementPinNames.end(); b++) {
00320
00321 }
00322
00323 if(notEmpty == 1){
00324 if(countPins != cfgSize) throw 0;
00325 }
00326
00327 }else if(isLUT == 1){
00328
00329 allLuts[element.getName()] = const_cast <PrimitiveElement*>(&element);
00330 allElements.erase(element.getName());
00331 }else if(isFF == 1){
00332
00333 allFlops[element.getName()] = const_cast <PrimitiveElement*>(&element);
00334 allElements.erase(element.getName());
00335 }
00336 if(totalPinCount == 0){
00337
00338 allOrphans[element.getName()] = const_cast <PrimitiveElement*>(&element);
00339 allElements.erase(element.getName());
00340 }
00341 if(findROUTETHROUGH(element.getName()) == 1){
00342
00343 allElements.erase(element.getName());
00344 }
00345 if(isAND == 1){
00346 allAnds[element.getName()] = const_cast <PrimitiveElement*>(&element);
00347 allElements.erase(element.getName());
00348 }
00349 if(isVCC == 1){
00350 allVccs[element.getName()] = const_cast <PrimitiveElement*>(&element);
00351 allElements.erase(element.getName());
00352 }
00353 if(isGND == 1){
00354 allGnds[element.getName()] = const_cast <PrimitiveElement*>(&element);
00355 allElements.erase(element.getName());
00356 }
00357 for (std::vector<std::string>::const_iterator s = primitivePinNames.begin(); s != primitivePinNames.end(); s++) {
00358 if(element.getName() == *s){
00359
00360 allTerminals[element.getName()] = const_cast <PrimitiveElement*>(&element);
00361 allElements.erase(element.getName());
00362 break;
00363 }
00364 }
00365 }
00366 }
00367
00368
00369
00370 }
00371 std::map<std::string, PrimitiveElement*>::const_iterator pos;
00372 std::cout << "------ UNCLASSIFIED ELEMENTS -------" <<std::endl;
00373 for(pos = allElements.begin(); pos != allElements.end(); ++pos) {
00374 std::cout << "Element: " << pos->first << std::endl;
00375
00376 }
00377 std::cout << std::endl;
00378 std::cout << "------ MUXES -------" <<std::endl;
00379 for(pos = allMuxes.begin(); pos != allMuxes.end(); ++pos) {
00380 std::cout << "Element: " << pos->first << std::endl;
00381
00382 }
00383 std::cout << std::endl;
00384 std::cout << "------ LUTS -------" <<std::endl;
00385 for(pos = allLuts.begin(); pos != allLuts.end(); ++pos) {
00386 std::cout << "Element: " << pos->first << std::endl;
00387
00388 }
00389 std::cout << std::endl;
00390 std::cout << "------ FLOPS -------" <<std::endl;
00391 for(pos = allFlops.begin(); pos != allFlops.end(); ++pos) {
00392 std::cout << "Element: " << pos->first << std::endl;
00393
00394 }
00395 std::cout << std::endl;
00396 std::cout << "------ TERMINALS -------" <<std::endl;
00397 for(pos = allTerminals.begin(); pos != allTerminals.end(); ++pos) {
00398 std::cout << "Element: " << pos->first << std::endl;
00399
00400 }
00401 std::cout << std::endl;
00402 std::cout << "------ SWITCHES -------" <<std::endl;
00403 for(pos = allSwitches.begin(); pos != allSwitches.end(); ++pos) {
00404 std::cout << "Element: " << pos->first << std::endl;
00405
00406 }
00407 std::cout << std::endl;
00408 std::cout << "------ ANDS -------" <<std::endl;
00409 for(pos = allAnds.begin(); pos != allAnds.end(); ++pos) {
00410 std::cout << "Element: " << pos->first << std::endl;
00411
00412 }
00413 std::cout << std::endl;
00414 std::cout << "------ VCCS -------" <<std::endl;
00415 for(pos = allVccs.begin(); pos != allVccs.end(); ++pos) {
00416 std::cout << "Element: " << pos->first << std::endl;
00417
00418 }
00419 std::cout << std::endl;
00420 std::cout << "------ GNDS -------" <<std::endl;
00421 for(pos = allGnds.begin(); pos != allGnds.end(); ++pos) {
00422 std::cout << "Element: " << pos->first << std::endl;
00423
00424 }
00425
00426
00427 }
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 BOOST_AUTO_TEST_CASE(SiteTypesUnitTest) {
00439
00440
00441 DDB ddb("xc5vlx30");
00442
00443 const Sites& sites = ddb.getSites();
00444
00445 typedef const Array<const PrimitiveDef> PrimitiveDefArray;
00446 PrimitiveDefArray& primitiveDefs = sites.getSiteTypes();
00447 PrimitiveDefArray::const_iterator p = primitiveDefs.begin();
00448 PrimitiveDefArray::const_iterator e = primitiveDefs.end();
00449 int i = 0;
00450
00451 while(p < e) {
00452
00453 const PrimitiveDef& primitiveDef = *p++;
00454 std::cout << i << ": " << primitiveDef.getName() << std::endl;
00455 typedef const Array<const PrimitivePin> PrimitivePinArray;
00456
00457 const PrimitivePinArray& primitivePins = primitiveDef.getPins();
00458 PrimitivePinArray::const_iterator sp = primitivePins.begin();
00459 PrimitivePinArray::const_iterator se = primitivePins.end();
00460
00461 if(false && primitivePins.getSize() > 0) {
00462 std::cout << " ";
00463
00464 while(sp < se) {
00465 const PrimitivePin& primitivePin = *sp++;
00466 std::cout << primitivePin.getName() << " ";
00467 std::cout << primitivePin.getFlags() << " ";
00468 }
00469 std::cout << std::endl;
00470 }
00471
00472
00473 const PrimitiveElementArray& elements = primitiveDef.getElements();
00474 PrimitiveElementArray::const_iterator ep = elements.begin();
00475 PrimitiveElementArray::const_iterator ee = elements.end();
00476
00477 if(true && elements.getSize() > 0) {
00478
00479 while(ep < ee) {
00480 const PrimitiveElement& element = *ep++;
00481 std::cout << "ELEMENT NAME:" << element.getName() << " "<< std::endl;
00482
00483
00484
00485 const PrimitiveElementPinArray& elementPins = element.getPins();
00486 PrimitiveElementPinArray::const_iterator pp = elementPins.begin();
00487 PrimitiveElementPinArray::const_iterator pe = elementPins.end();
00488
00489 if(elementPins.getSize()> 0) {
00490
00491
00492 while(pp < pe) {
00493
00494 const PrimitiveElementPin& elementPin = *pp++;
00495 std::cout << elementPin.getElementPtr()->getName() << "." << elementPin.getName() << " ";
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514 }
00515 std::cout << std::endl;
00516 }
00517 }
00518 std::cout << std::endl;
00519 }
00520 const PrimitiveConnSharedPtrArray& connections = primitiveDef.getConnections();
00521 PrimitiveConnSharedPtrArray::const_iterator ccp = connections.begin();
00522 PrimitiveConnSharedPtrArray::const_iterator cce = connections.end();
00523
00524 while(true && ccp < cce) {
00525 const PrimitiveConn& connection = *(*ccp++);
00526 const PrimitiveElementPin& source = *connection.getSourcePtr();
00527 const PrimitiveElementPinPtrVector& sinks = connection.getSinks();
00528 std::cout << source.getElementPtr()->getName() << "." << source.getName() << " ==> ";
00529 PrimitiveElementPinPtrVector::const_iterator epp = sinks.begin();
00530 PrimitiveElementPinPtrVector::const_iterator epe = sinks.end();
00531 while(epp < epe) {
00532 const PrimitiveElementPin& sink = **epp++;
00533 std::cout << sink.getElementPtr()->getName() << "." << sink.getName() << " ";
00534 }
00535 std::cout << std::endl;
00536 }
00537 i++;
00538 }
00539 BOOST_REQUIRE(true);
00540
00541 }
00542
00543 BOOST_AUTO_TEST_SUITE_END()
00544
00545 }
00546 }
00547