torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::physical::ParsePrimitive Class Reference

Pare Primitives. More...

#include <ParsePrimitive.hpp>

Public Member Functions

 ParsePrimitive ()
 
PrimitiveSetSharedPtr ParsePrimitiveFile (const char *inFileName)
 parse an XDLRC file More...
 

Protected Member Functions

void readCurrentLine ()
 Reads the current line. More...
 
void printError (const char *format,...)
 Print printError. More...
 

Protected Attributes

FILE * inFile
 
const char * inFileName
 
char * line
 
unsigned lineSize
 
unsigned lineNumber
 

Detailed Description

Pare Primitives.

Definition at line 35 of file ParsePrimitive.hpp.

Constructor & Destructor Documentation

torc::physical::ParsePrimitive::ParsePrimitive ( )
inline

Definition at line 56 of file ParsePrimitive.hpp.

56 { lineSize = 2048; line = new char[2048];}

Member Function Documentation

PrimitiveSetSharedPtr torc::physical::ParsePrimitive::ParsePrimitiveFile ( const char *  inFileName)

parse an XDLRC file

Definition at line 78 of file ParsePrimitive.cpp.

78  {
79 
80  inFileName = name;
81 
82  lineNumber = 0;
83  if (!(inFile = fopen(inFileName, "r")))
84  printError("Cannot open file '%s'.\n", inFileName);
85  lineNumber = 1;
86 
87  int site_no, pin_no, element_no;
88  string strTmp;
89  string typeTmp;
90  string compName;
91  string element1;
92  string element2;
93  string PrimitivePin1;
94  string PrimitivePin2;
95 
96 
98 
99  readCurrentLine();
100 
101  for (;;) {
102  string token = strtok(line, delimiters);
103  if (token[0] == '(') {
104  if (token == "(xdl_resource_report") {
105  string model = strtok(NULL, delimiters);
106  model = strtok(NULL, delimiters);
108  readCurrentLine();
109  continue;
110  }
111  else
112  if (token =="(tiles") {
113  readCurrentLine();
114  continue;
115  }
116  else
117  if (token =="(tile") {
118  for(int i=0; i<5; ++i)
119  strTmp = strtok(NULL, delimiters);
120  site_no = atoi(strTmp.c_str());
121  for(int i=0; i<site_no; ++i)
122  readCurrentLine();
123  readCurrentLine();
124  continue;
125  }
126  else
127  if (token == "(primitive_defs") {
128  readCurrentLine();
129  continue;
130  }
131  else
132  if (token == "(primitive_def") {
133  compName = strtok(NULL, delimiters);
134  strTmp = strtok(NULL, delimiters);
135  pin_no = atoi (strTmp.c_str());
136  strTmp = strtok(NULL, delimiters);
137  element_no=atoi(strTmp.c_str());
139  p->addPrimitive(pp);
140 
141  for(int i=0; i<pin_no; ++i){
142  readCurrentLine();
143  strTmp = strtok(line, delimiters);
144  strTmp = strtok(NULL, delimiters);
145  compName = strtok(NULL, delimiters);
146  typeTmp = strtok(NULL, delimiters);
147  typeTmp.resize(typeTmp.length() - 1);
148  PrimitivePinSharedPtr newPrimitivePin = RcFactory::newPrimitivePinPtr (strTmp, compName, ((typeTmp == "input") ? InputP : OutputP));
149  pp->addPrimitivePin(newPrimitivePin);
150  }
151 
152  for(int i=0; i<element_no; ++i){
153  readCurrentLine();
154  strTmp = strtok(line, delimiters);
155  compName = strtok(NULL, delimiters);
156  strTmp = strtok(NULL, delimiters);
157  pin_no = atoi(strTmp.c_str());
159  pp->addElement(ep);
160 
161  // read element pins
162  for(int i=0; i<pin_no; ++i){
163  readCurrentLine();
164  strTmp = strtok(line, delimiters);
165  compName = strtok(NULL, delimiters);
166  typeTmp = strtok(NULL, delimiters);
167  typeTmp.resize(typeTmp.length() - 1);
168  PrimitivePinSharedPtr newPrimitivePin = RcFactory::newPrimitivePinPtr (strTmp, compName, ((typeTmp == "input") ? InputP : OutputP));
169  ep->addPrimitivePin(newPrimitivePin);
170  }
171  readCurrentLine();
172  strTmp = strtok(line, delimiters);
173 
174  // read element configs
175  if (strTmp == "(cfg"){
176  for(;;){
177  string confTmp = strtok(NULL, delimiters);
178  if(confTmp[confTmp.size()-1]==')'){
179  confTmp.resize(confTmp.length() - 1);
180  ep->addConfig(confTmp);
181  break;
182  }
183  ep->addConfig(confTmp);
184  }
185  readCurrentLine();
186 
187  strTmp = strtok(line, delimiters);
188  }
189 
190  // read element connections
191  while(strTmp[0]!=')'){
192  element1 = strtok(NULL, delimiters);
193  PrimitivePin1 = strtok(NULL, delimiters);
194  strTmp = strtok(NULL, delimiters);
195  element2 = strtok(NULL, delimiters);
196  PrimitivePin2 = strtok(NULL, delimiters);
197  PrimitivePin2.resize(PrimitivePin2.length() - 1);
198  if(strTmp == "<=="){
199  swap(element1,element2);
200  swap(PrimitivePin1,PrimitivePin2);
201  }
202 
203  ConnectionPin pin1 = RcFactory::newConnectionPin(element1,PrimitivePin1);
204  ConnectionPin pin2 = RcFactory::newConnectionPin(element2,PrimitivePin2);
206  newConn->addConnectionPin(pin1);
207  newConn->addConnectionPin(pin2);
208  ep->addConnection(newConn);
209  readCurrentLine();
210  strTmp = strtok(line, delimiters);
211  }
212 
213  }
214  continue;
215  }
216  else
217  if ((token == "(end") || (token == "(summary")){
218  cout<<'(';
219  for(int i=0; i<3; ++i){
220  strTmp = strtok(NULL, delimiters);
221  cout<<strTmp<<" ";
222  }
223  cout<<endl;
224  break;
225  }
226  }
227  else
228  if (token[0] != '\n' && token[0] != '#' && token[0] != ')') printError("`.' expected.\n");
229 
230  readCurrentLine(); /* get next line */
231  }
232 
233  lineSize = 0;
234  if (line) delete [] line;
235  line = NULL;
236  fclose(inFile);
237 
238  return p;
239 }
static PrimitiveSetSharedPtr newPrimitiveSetPtr(const string &inName)
Create and return a new PrimitiveSet object.
Definition: RcFactory.hpp:42
void readCurrentLine()
Reads the current line.
boost::shared_ptr< Primitive > PrimitiveSharedPtr
Shared pointer encapsulation of a Primitive.
Definition: Primitive.hpp:171
boost::shared_ptr< Element > ElementSharedPtr
Shared pointer encapsulation of a element.
Definition: Element.hpp:119
void printError(const char *format,...)
Print printError.
static const char delimiters[]
boost::shared_ptr< PrimitiveSet > PrimitiveSetSharedPtr
Shared pointer encapsulation of a PrimitiveSet.
static ElementSharedPtr newElementPtr(const string &inName)
Create and return a new Element object.
Definition: RcFactory.hpp:49
static ConnectionPin newConnectionPin(string inElementName, const string &inPinName)
Construct an ConnectionPin and return a constant reference.
Definition: RcFactory.hpp:77
boost::shared_ptr< Connection > ConnectionSharedPtr
Shared pointer encapsulation of a componenet.
Definition: Connection.hpp:82
static ConnectionSharedPtr newConnectionPtr(const string &inName)
Create and return a new Element object.
Definition: RcFactory.hpp:83
boost::shared_ptr< PrimitivePin > PrimitivePinSharedPtr
Shared pointer encapsulation of a componenet.
static PrimitivePinSharedPtr newPrimitivePinPtr(string inElementName, string inPinName, const PinType inType)
Create and return a new PrimitivePin shared pointer.
Definition: RcFactory.hpp:92
static PrimitiveSharedPtr newPrimitivePtr(const string &inName)
Create and return a new Element object.
Definition: RcFactory.hpp:68

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void torc::physical::ParsePrimitive::printError ( const char *  format,
  ... 
)
protected

Print printError.

Definition at line 64 of file ParsePrimitive.cpp.

64  {
65  va_list args;
66 
67  if (lineNumber)
68  fprintf(stderr, "Parse printError in %s:%d: ", inFileName, lineNumber);
69  else fprintf(stderr, "Parse printError: ");
70 
71  va_start(args, format);
72  vfprintf(stderr, format, args);
73  va_end(args);
74 
75  exit(1);
76  }

+ Here is the caller graph for this function:

void torc::physical::ParsePrimitive::readCurrentLine ( )
protected

Reads the current line.

Definition at line 26 of file ParsePrimitive.cpp.

26  {
27  static const unsigned initial_size = 1024;
28 
29  if (!line) {
30  lineSize = initial_size;
31  line = new char[lineSize];
32  }
33 
34  unsigned offset = 0;
35 
36  for (;;) {
37 
38  if (!fgets(line + offset, lineSize - offset, inFile)) { if
39  (ferror(inFile)) { perror("read error"); exit(1); } if (!offset)
40  strcpy(line, ".end\n"); break; }
41 
42  unsigned len = offset + strlen(line + offset);
43 
44  if (line[len-1] == '\n') {
45  ++lineNumber;
46  if (line[len-2] == '\\') len -= 2; else break;
47  }
48  else {
49  if (len != lineSize - 1) break;
50 
51  char *new_line = new char[lineSize << 1];
52  for (unsigned i = 0; i < lineSize; ++i)
53  new_line[i] = line[i];
54  delete [] line;
55  line = new_line;
56  lineSize <<= 1;
57  }
58 
59  offset = len;
60  }
61 
62 }

+ Here is the caller graph for this function:

Field Documentation

FILE* torc::physical::ParsePrimitive::inFile
protected

Definition at line 39 of file ParsePrimitive.hpp.

const char* torc::physical::ParsePrimitive::inFileName
protected

Definition at line 41 of file ParsePrimitive.hpp.

char* torc::physical::ParsePrimitive::line
protected

Definition at line 43 of file ParsePrimitive.hpp.

unsigned torc::physical::ParsePrimitive::lineNumber
protected

Definition at line 47 of file ParsePrimitive.hpp.

unsigned torc::physical::ParsePrimitive::lineSize
protected

Definition at line 45 of file ParsePrimitive.hpp.


The documentation for this class was generated from the following files: