00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "torc/packer/WritePrimitive.hpp"
00017
00018 namespace torc {
00019 namespace physical {
00020
00021
00022 void WritePrimitive::WritePrimitiveFile(const char *name, PrimitiveSetSharedPtr primitives) {
00023
00024 outFileName = name;
00025
00026 if (!(outFile = fopen(outFileName, "w")))
00027 printf("Cannot open file '%s'.\n", outFileName);
00028
00029 fprintf(outFile, "(primitive_defs %i\n", (int)(primitives->getPrimitiveCount()));
00030
00031 for(PrimitiveSet::PrimitiveSharedPtrConstIterator it = primitives->primitivesBegin(); it != primitives->primitivesEnd(); ++it){
00032 fprintf(outFile, "\t(primitive_def %s %d %d\n", (*it)->getName().c_str(), ((int)((*it)->getPrimitivePinCount())), ((int)((*it)->getElementCount())));
00033
00034 for(Primitive::PrimitivePinSharedPtrConstIterator pp = (*it)->PrimitivePinsBegin(); pp != (*it)->PrimitivePinsEnd(); ++pp){
00035 string sTmp = ((*pp)->getType()==OutputP) ? "output" : "input";
00036 fprintf(outFile, "\t\t(pin %s %s %s)\n", (*pp)->getElementName().c_str(), (*pp)->getName().c_str(), sTmp.c_str());
00037 }
00038
00039 for(Primitive::ElementSharedPtrConstIterator ep = (*it)->elementsBegin(); ep != (*it)->elementsEnd(); ++ep){
00040 fprintf(outFile, "\t\t(element %s %d\n", (*ep)->getName().c_str(), (int)((*ep)->getPrimitivePinCount()));
00041
00042 for(Element::PrimitivePinSharedPtrConstIterator pp = (*ep)->PrimitivePinsBegin(); pp != (*ep)->PrimitivePinsEnd(); ++pp){
00043 string sTmp = ((*pp)->getType()==OutputP) ? "output" : "input";
00044 fprintf(outFile, "\t\t\t(pin %s %s)\n", (*pp)->getName().c_str(), sTmp.c_str());
00045 }
00046
00047 if((*ep)->getConfigCount()>0){
00048 fprintf(outFile, "\t\t\t(cfg");
00049 for(Element::ConfigConstIterator cp = (*ep)->confsBegin(); cp != (*ep)->confsEnd(); ++cp)
00050 fprintf(outFile, " %s", (*cp).c_str());
00051 fprintf(outFile,")\n");
00052 }
00053
00054 for(Element::ConnectionSharedPtrConstIterator cp = (*ep)->connectionsBegin(); cp != (*ep)->connectionsEnd(); ++cp){
00055 Connection::ConnectionPinSharedPtrConstIterator src = (*cp)->getSource();
00056 Connection::ConnectionPinSharedPtrConstIterator dst = (*cp)->getSink();
00057 fprintf(outFile,"\t\t\t(conn %s %s ==> %s %s)\n", (*src).getElementName().c_str(), (*src).getPinName().c_str(),
00058 (*dst).getElementName().c_str(), (*dst).getPinName().c_str());
00059 }
00060 fprintf(outFile, "\t\t)\n");
00061 }
00062 fprintf(outFile, ")\n");
00063 }
00064
00065 fclose(outFile);
00066
00067 return;
00068 }
00069
00070 }
00071 }
00072