torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WritePrimitive.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
17 
18 namespace torc {
19 namespace physical {
20 
21 
22  void WritePrimitive::WritePrimitiveFile(const char *name, PrimitiveSetSharedPtr primitives) {
23 
24  outFileName = name;
25 
26  if (!(outFile = fopen(outFileName, "w")))
27  printf("Cannot open file '%s'.\n", outFileName);
28 
29  fprintf(outFile, "(primitive_defs %i\n", (int)(primitives->getPrimitiveCount()));
30  //write primitives
31  for(PrimitiveSet::PrimitiveSharedPtrConstIterator it = primitives->primitivesBegin(); it != primitives->primitivesEnd(); ++it){
32  fprintf(outFile, "\t(primitive_def %s %d %d\n", (*it)->getName().c_str(), ((int)((*it)->getPrimitivePinCount())), ((int)((*it)->getElementCount())));
33  //write PrimitivePins
34  for(Primitive::PrimitivePinSharedPtrConstIterator pp = (*it)->PrimitivePinsBegin(); pp != (*it)->PrimitivePinsEnd(); ++pp){
35  string sTmp = ((*pp)->getType()==OutputP) ? "output" : "input";
36  fprintf(outFile, "\t\t(pin %s %s %s)\n", (*pp)->getElementName().c_str(), (*pp)->getName().c_str(), sTmp.c_str());
37  }
38  //write elements
39  for(Primitive::ElementSharedPtrConstIterator ep = (*it)->elementsBegin(); ep != (*it)->elementsEnd(); ++ep){
40  fprintf(outFile, "\t\t(element %s %d\n", (*ep)->getName().c_str(), (int)((*ep)->getPrimitivePinCount()));
41  //write element PrimitivePins
42  for(Element::PrimitivePinSharedPtrConstIterator pp = (*ep)->PrimitivePinsBegin(); pp != (*ep)->PrimitivePinsEnd(); ++pp){
43  string sTmp = ((*pp)->getType()==OutputP) ? "output" : "input";
44  fprintf(outFile, "\t\t\t(pin %s %s)\n", (*pp)->getName().c_str(), sTmp.c_str());
45  }
46  //write element confs
47  if((*ep)->getConfigCount()>0){
48  fprintf(outFile, "\t\t\t(cfg");
49  for(Element::ConfigConstIterator cp = (*ep)->confsBegin(); cp != (*ep)->confsEnd(); ++cp)
50  fprintf(outFile, " %s", (*cp).c_str());
51  fprintf(outFile,")\n");
52  }
53  //write element connections
54  for(Element::ConnectionSharedPtrConstIterator cp = (*ep)->connectionsBegin(); cp != (*ep)->connectionsEnd(); ++cp){
55  Connection::ConnectionPinSharedPtrConstIterator src = (*cp)->getSource();
57  fprintf(outFile,"\t\t\t(conn %s %s ==> %s %s)\n", (*src).getElementName().c_str(), (*src).getPinName().c_str(),
58  (*dst).getElementName().c_str(), (*dst).getPinName().c_str());
59  }
60  fprintf(outFile, "\t\t)\n");
61  }
62  fprintf(outFile, ")\n");
63  }
64 
65  fclose(outFile);
66 
67  return;
68 }
69 
70 } // namespace physical
71 } // namespace torc
72 
ConnectionPinVector::const_iterator ConnectionPinSharedPtrConstIterator
Definition: Connection.hpp:40
boost::shared_ptr< PrimitiveSet > PrimitiveSetSharedPtr
Shared pointer encapsulation of a PrimitiveSet.
void WritePrimitiveFile(const char *outFileName, PrimitiveSetSharedPtr primitives)
write an XDLRC file
Header for primitive parser.
ConnectionSharedPtrVector::const_iterator ConnectionSharedPtrConstIterator
Definition: Element.hpp:54
ConfigVector::const_iterator ConfigConstIterator
Definition: Element.hpp:57
PrimitiveSharedPtrVector::const_iterator PrimitiveSharedPtrConstIterator
Constant iterator for Primitive shared pointers.
ElementSharedPtrVector::const_iterator ElementSharedPtrConstIterator
Constant iterator for Element shared pointers.
Definition: Primitive.hpp:53
PrimitivePinSharedPtrVector::const_iterator PrimitivePinSharedPtrConstIterator
Definition: Component.hpp:39