torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Decompiler.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 
16 #ifndef HAVE_CONFIG_H
17 #include "torc/generic/config.h"
18 #endif
19 
24 #include "torc/generic/Written.hpp"
28 
29 namespace {
30 
31 using namespace torc::generic;
32 typedef std::vector<LibrarySharedPtr> Libraries;
33 typedef std::vector<CellSharedPtr> Cells;
34 typedef std::vector<ViewSharedPtr> Views;
35 typedef std::vector<InstanceSharedPtr> Instances;
36 
37 std::string trimLeading(const std::string& inBuffer) {
38  const size_t beginStr = inBuffer.find_first_of("(");
39  if(beginStr != std::string::npos) {
40  const size_t endStr = inBuffer.find_last_of(")");
41  const size_t range = endStr - beginStr + 1;
42  return inBuffer.substr(beginStr, range);
43  }
44  return std::string();
45 }
46 
47 // Code for Trim Leading Spaces only
48 std::string trimLeadingSpaces(const std::string& inBuffer) {
49  // Find the first character position after excluding leading blank spaces
50  const size_t startpos = inBuffer.find_first_not_of(" \t");
51  if(std::string::npos != startpos) {
52  return inBuffer.substr(startpos, std::string::npos);
53  }
54  return std::string();
55 }
56 
57 struct CircularDependencyResolver {
58 
59  enum PrintType {
60  ePrintTypeExtern, ePrintTypeConcrete
61  };
62 
63  void resolve(const RootSharedPtr& inRoot) {
65  Libraries libs;
66  inRoot->getLibraries(libs);
67  for(Libraries::iterator lib = libs.begin(); lib != libs.end(); ++lib) {
68  if((*lib)->getIsExtern()) {
69  PrintType type;
70  if(!discoveredLibs.get((*lib)->getName(), type)) {
71  //Extern but not found
72  mExterns.push_back(*lib);
73  discoveredLibs.set((*lib)->getName(), ePrintTypeExtern);
74  }
75  continue;
76  //Views here will most likely have
77  //no bodies anyway
78  }
79  discoveredLibs.set((*lib)->getName(), ePrintTypeConcrete);
80  mConcreteLibs.push_back(*lib);
81  Cells cells;
82  (*lib)->getCells(cells);
83  for(Cells::iterator cell = cells.begin(); cell != cells.end(); ++cell) {
84  Views views;
85  (*cell)->getViews(views);
86  for(Views::iterator view = views.begin(); view != views.end(); ++view) {
87  Instances instances;
88  (*view)->getInstances(instances);
89  for(Instances::iterator inst = instances.begin(); inst != instances.end();
90  ++inst) {
91  switch((*inst)->getCompositionType()) {
93  checkLib(*inst, discoveredLibs);
94  break;
95  }
97  Instances children;
98  (*inst)->getChildren(children);
99  for(Instances::iterator c = children.begin(); c != children.end();
100  ++c) {
101  checkLib(*c, discoveredLibs);
102  }
103  break;
104  }
105  default: {
106  }
107  }
108  }
109  }
110  }
111  }
112  }
113 
114  void checkLib(const InstanceSharedPtr& inInst,
115  SymTab<std::string, PrintType, true>& inDiscoveredLibs) {
116  ViewSharedPtr iV = inInst->getMaster();
117  LibrarySharedPtr targetL = iV->getParent()->getParent();
118  PrintType type;
119  if(!inDiscoveredLibs.get(targetL->getName(), type)) {
120  mExterns.push_back(targetL);
121  inDiscoveredLibs.set(targetL->getName(), ePrintTypeExtern);
122  //We will print extern for this...
123  //concrete may come later...
124  }
125  }
126  std::vector<LibrarySharedPtr> mExterns;
127  std::vector<LibrarySharedPtr> mConcreteLibs;
128 };
129 
130 class Indenter {
131 public:
132  size_t getIndentation() const;
133 
134  Indenter(Decompiler& inPrinter, bool inChangeIndentation = true);
135  ~Indenter();
136 
137 private:
138  Decompiler& mPrinter;
139  bool mChangeIndentation;
140 };
141 
142 size_t Indenter::getIndentation() const {
143  return mPrinter.getIndentation();
144 }
145 
146 Indenter::Indenter(Decompiler& inPrinter, bool inChangeIndentation) :
147  mPrinter(inPrinter), mChangeIndentation(inChangeIndentation) {
148  size_t indentation = getIndentation();
149  indentation += (mChangeIndentation) ? 4 : 0;
150  mPrinter.setIndentation(indentation);
151 }
152 
153 Indenter::~Indenter() {
154  size_t indentation = getIndentation();
155  indentation -= (mChangeIndentation) ? 4 : 0;
156  mPrinter.setIndentation(indentation);
157 }
158 
159 }
160 
161 namespace std {
162 
163 std::ostream& operator<<(std::ostream& outStream, const Indenter& indent);
164 
165 std::ostream& operator<<(std::ostream& outStream, const Indenter& indent) {
166  for(size_t i = 0; i < indent.getIndentation(); i++) {
167  outStream << " ";
168  }
169  return outStream;
170 }
171 
172 } // namespace std
173 
174 namespace torc {
175 namespace generic {
176 
177 // For Root
178 void Decompiler::visit(Root& root) throw (Error) {
179  try {
180  CircularDependencyResolver resolver;
181  resolver.resolve(root.getSharedThis());
182  if(!root.getOriginalName().empty()) {
183  mOut << "(edif (rename " << root.getName() << " " << "\"" << root.getOriginalName()
184  << "\"" << ")" << std::endl;
185  } else {
186  mOut << "(edif " << root.getName() << std::endl;
187  }
188  mOut << " (edifVersion " << (int32_t) root.getVersion().mFirst << " "
189  << (int32_t) root.getVersion().mSecond << " " << (int32_t) root.getVersion().mThird
190  << ")" << std::endl;
191  mOut << " (edifLevel " << root.getLevel() << ")" << std::endl;
192  mOut << " (keywordMap (keywordLevel 0" << "))";
193 
194  //Print Comments
195  std::vector < std::string > comments = root.getComments();
196  printComments(comments);
197 
198  root.applyOnAllStatuses(mApplier);
199 
200  mIsExternContext = true;
201  std::for_each(resolver.mExterns.begin(), resolver.mExterns.end(), mApplier);
202  mIsExternContext = false;
203 
204  std::for_each(resolver.mConcreteLibs.begin(), resolver.mConcreteLibs.end(), mApplier);
205  root.applyOnAllDesigns(mApplier);
206 
207  std::list < std::string > elements;
208  root.getUserData(elements);
209  printUserData(elements);
210 
211  mOut << std::endl << ")" << std::endl;
212  } catch(Error& e) {
213  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
214  throw;
215  }
216 }
217 
218 // For Design
219 void Decompiler::visit(Design& design) throw (Error) {
220  try {
221  Indenter indent(*this);
222  if(!design.getOriginalName().empty()) {
223  mOut << std::endl << indent << "(design " << "(rename " << design.getName() << " "
224  << "\"" << design.getOriginalName() << "\"" << ")";
225  } else {
226  mOut << std::endl << indent << "(design " << design.getName();
227  }
228  mOut << std::endl << indent << " (cellRef " << design.getCellRefName() << " (libraryRef "
229  << design.getLibraryRefName() << "))";
230 
231  //Print Comments
232  std::vector < std::string > comments = design.getComments();
233  printComments(comments);
234 
235  design.applyOnAllStatuses(mApplier);
236  design.applyOnAllProperties(mApplier);
237 
238  std::list < std::string > elements;
239  design.getUserData(elements);
240  printUserData(elements);
241 
242  mOut << std::endl << indent << ")";
243  } catch(Error& e) {
244  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
245  throw;
246  }
247 }
248 
249 // For Library
250 void Decompiler::visit(Library& library) throw (Error) {
251  try {
252  Indenter indent(*this);
253  if(mIsExternContext || library.getIsExtern()) {
254  if(!library.getOriginalName().empty()) {
255  mOut << std::endl << indent << "(external ";
256  mOut << std::endl << indent << " (rename " << library.getName() << " " << "\""
257  << library.getOriginalName() << "\"" << ")";
258  } else {
259  mOut << std::endl << indent << "(external " << library.getName();
260  }
261  } else {
262  if(!library.getOriginalName().empty()) {
263  mOut << std::endl << indent << "(library ";
264  mOut << std::endl << indent << " (rename " << library.getName() << " " << "\""
265  << library.getOriginalName() << "\"" << ")";
266  } else {
267  mOut << std::endl << indent << "(library " << library.getName();
268  }
269  }
270  mOut << std::endl << indent << " (ediflevel " << library.getLevel() << ")"
271  << " (technology (numberDefinition";
272 
273  std::map<Unit, ScaleFactor> outScaleFactors;
274  outScaleFactors = library.getScaleFactors();
275  std::map<Unit, ScaleFactor>::iterator it = outScaleFactors.begin();
276  for(; it != outScaleFactors.end(); ++it) {
277  Unit unit = (*it).first;
278  ScaleFactor scale = (*it).second;
279  mOut << std::endl << indent << " (scale ";
280  printValue(Value(Value::eValueTypeNumber, scale.getSiValue()));
281  printValue(Value(Value::eValueTypeNumber, scale.getEdifValue()));
282  printUnit(unit);
283  mOut << ")";
284  }
285  mOut << ")";
286 
287  SimulationInfoSharedPtr simuInfo = library.getSimulationInfo();
288  if(simuInfo) {
289  simuInfo->accept(*this);
290  }
291  mOut << ")";
292 
293  //Print Comments
294  std::vector < std::string > comments = library.getComments();
295  printComments(comments);
296 
297  library.applyOnAllStatuses(mApplier);
298 
299  std::list < std::string > elements;
300  library.getUserData(elements);
301  printUserData(elements);
302 
303  library.applyOnAllCells(mApplier);
304  mOut << std::endl << indent << ")";
305  } catch(Error& e) {
306  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
307  throw;
308  }
309 }
310 
311 // For Cell
312 void Decompiler::visit(Cell& cell) throw (Error) {
313  try {
314  Indenter indent(*this);
315  std::string cellType;
316  switch(cell.getType()) {
317  case Cell::eTypeTie: {
318  cellType = "TIE";
319  break;
320  }
321  case Cell::eTypeRipper: {
322  cellType = "RIPPER";
323  break;
324  }
325  case Cell::eTypeGeneric: {
326  cellType = "GENERIC";
327  break;
328  }
329  default: {
330  }
331  }
332  if(!cell.getOriginalName().empty()) {
333  mOut << std::endl << indent << "(cell ";
334  mOut << std::endl << indent << " (rename " << cell.getName() << " " << "\""
335  << cell.getOriginalName() << "\"" << ")";
336  } else {
337  mOut << std::endl << indent << "(cell " << cell.getName();
338  }
339  mOut << std::endl << indent << " (cellType " << cellType << ")";
340 
341  //Print Comments
342  std::vector < std::string > comments = cell.getComments();
343  printComments(comments);
344 
345  cell.applyOnAllStatuses(mApplier);
346 
347  std::list < std::string > elements;
348  cell.getUserData(elements);
349  printUserData(elements);
350 
351  cell.applyOnAllViews(mApplier);
352  cell.applyOnAllProperties(mApplier);
353  mOut << std::endl << indent << ")";
354  } catch(Error& e) {
355  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
356  throw;
357  }
358 }
359 
360 // For View
361 void Decompiler::visit(View& view) throw (Error) {
362  try {
363  Indenter indent(*this);
364  std::string viewType;
365  switch(view.getType()) {
366  case View::eTypeMaskLayout: {
367  viewType = "MASKLAYOUT";
368  break;
369  }
370  case View::eTypePCBLayout: {
371  viewType = "PCBLAYOUT";
372  break;
373  }
374  case View::eTypeNetlist: {
375  viewType = "NETLIST";
376  break;
377  }
378  case View::eTypeSchematic: {
379  viewType = "SCHEMATIC";
380  break;
381  }
382  case View::eTypeSymbolic: {
383  viewType = "SYMBOLIC";
384  break;
385  }
386  case View::eTypeBehavior: {
387  viewType = "BEHAVIOR";
388  break;
389  }
390  case View::eTypeLogicModel: {
391  viewType = "LOGICMODEL";
392  break;
393  }
394  case View::eTypeDocument: {
395  viewType = "DOCUMENT";
396  break;
397  }
398  case View::eTypeGraphic: {
399  viewType = "GRAPHIC";
400  break;
401  }
402  case View::eTypeStranger: {
403  viewType = "STRANGER";
404  break;
405  }
406  }
407  if(!view.getOriginalName().empty()) {
408  mOut << std::endl << indent << "(view ";
409  mOut << std::endl << indent << " (rename " << view.getName() << " " << "\""
410  << view.getOriginalName() << "\"" << ")";
411  } else {
412  mOut << std::endl << indent << "(view " << view.getName();
413  }
414  mOut << std::endl << indent << " (viewType " << viewType << ")";
415 
416  if(View::eTypeNetlist != view.getType()) {
417  mOut << view.getNonNetlistViewData();
418  return;
419  }
420 
421  mOut << std::endl << indent << " (interface ";
422  mIsJoiningContext = false;
423  view.applyOnAllPorts(mApplier);
424  printViewInterfaceAttributes(view.getInterfaceAttributes());
425  typedef std::map<std::string, ParameterSharedPtr> Params;
426  ParameterMapSharedPtr params = view.getParameters();
427  ParameterContext context = view.getParameterContext();
428  Params paramMap;
429  params->getAllParameters(context, paramMap);
430  for(Params::iterator it = paramMap.begin(); it != paramMap.end(); it++) {
431  (*it).second->accept(*this);
432  }
433  mIsJoiningContext = true;
434  view.applyOnAllPermutables(mApplier);
435  view.applyOnAllInterfaceJoinedInfos(mApplier);
436  mOut << std::endl << indent << " )";
437  view.applyOnAllProperties(mApplier);
438 
439  //Print Comments
440  std::vector < std::string > comments = view.getComments();
441  printComments(comments);
442 
443  view.applyOnAllStatuses(mApplier);
444 
445  std::list < std::string > elements;
446  view.getUserData(elements);
447  printUserData(elements);
448 
449  if(!mIsExternContext) {
450 
451  std::vector<InstanceSharedPtr> instVec;
452  view.getInstances(instVec);
453 
454  std::vector<NetSharedPtr> netVec;
455  view.getNets(netVec);
456 
457  if(!instVec.empty() || !netVec.empty()) {
458  mOut << std::endl << indent << " (contents ";
459  //Print all instances of the current view
460  mIsJoiningContext = false;
461  view.applyOnAllInstances(mApplier);
462 
463  if(NULL != view.getSimulate()) {
464  view.getSimulate()->accept(*this);
465  }
466 
467  //Print all net info
468  mIsJoiningContext = true;
469  view.applyOnAllNets(mApplier);
470 
471  if(NULL != view.getTiming()) {
472  view.getTiming()->accept(*this);
473  }
474 
475  mOut << std::endl << indent << " )";
476  }
477  }
478  mOut << std::endl << indent << ")";
479  } catch(Error& e) {
480  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
481  throw;
482  }
483 }
484 
485 // For ScalarPort
486 void Decompiler::visit(ScalarPort& port) throw (Error) {
487  try {
488  Indenter indent(*this);
489  if(!mIsJoiningContext) {
490  if(!port.getOriginalName().empty()) {
491  mOut << std::endl << indent << "(port ";
492  mOut << std::endl << indent << " (rename " << port.getName() << " " << "\""
493  << port.getOriginalName() << "\"" << ")";
494  } else {
495  mOut << std::endl << indent << "(port " << port.getName();
496  }
497  switch(port.getDirection()) {
498  case ePortDirectionIn: {
499  mOut << std::endl << indent << " (direction INPUT)";
500  break;
501  }
502  case ePortDirectionOut: {
503  mOut << std::endl << indent << " (direction OUTPUT)";
504  break;
505  }
506  case ePortDirectionInOut: {
507  mOut << std::endl << indent << " (direction INOUT)";
508  break;
509  }
510  default: {
511  }
512  }
513  printPortAttributes(port.getAttributes());
514 
515  //Print Comments
516  std::vector < std::string > comments = port.getComments();
517  printComments(comments);
518 
519  std::list < std::string > elements;
520  port.getUserData(elements);
521  printUserData(elements);
522 
523  port.applyOnAllProperties(mApplier);
524  mOut << std::endl << indent << ")";
525  } else {
526  mOut << std::endl << indent << "(portRef " << port.getName();
527  PortSharedPtr parentCol = port.getParentCollection();
528  if(parentCol) {
529  parentCol->accept(*this);
530  }
531  mOut << ")";
532  }
533  } catch(Error& e) {
534  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
535  throw;
536  }
537 }
538 
539 // For ScalarPortReference
541  try {
542  Indenter indent(*this);
543  if(mIsJoiningContext) {
544  mOut << std::endl << indent << "(portRef " << portRef.getName();
545  PortReferenceSharedPtr parentCol = portRef.getParentCollection();
546  if(parentCol) {
547  parentCol->accept(*this);
548  } else {
549  if(!mIsPortInstanceContext) {
550  portRef.getParent()->accept(*this);
551  }
552  }
553  mOut << ")";
554  } else {
555  }
556  } catch(Error& e) {
557  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
558  throw;
559  }
560 }
561 
562 // For VectorPort
563 void Decompiler::visit(VectorPort& port) throw (Error) {
564  try {
565  Indenter indent(*this);
566  if(mIsJoiningContext) {
567  mOut << std::endl << indent << "(portRef " << port.getName();
568  PortSharedPtr parentCol = port.getParentCollection();
569  if(parentCol) {
570  parentCol->accept(*this);
571  }
572  mOut << ")";
573  } else {
574  if(!port.getOriginalName().empty()) {
575  mOut << std::endl << indent << "(port ";
576  mOut << std::endl << indent << " (array (rename " << port.getName() << " " << "\""
577  << port.getOriginalName() << "\"" << ")" << " ";
578  } else {
579  mOut << std::endl << indent << "(port (array " << port.getName() << " ";
580  }
581  std::vector < size_t > limits;
582  port.getLimits(limits);
583  copy(limits.begin(), limits.end(), std::ostream_iterator < size_t > (mOut, " "));
584  mOut << ")";
585  switch(port.getDirection()) {
586  case ePortDirectionIn: {
587  mOut << std::endl << indent << " (direction INPUT)";
588  break;
589  }
590  case ePortDirectionOut: {
591  mOut << std::endl << indent << " (direction OUTPUT)";
592  break;
593  }
594  case ePortDirectionInOut: {
595  mOut << std::endl << indent << " (direction INOUT)";
596  break;
597  }
598  default: {
599  }
600 
601  }
602  printPortAttributes(port.getAttributes());
603 
604  //Print Comments
605  std::vector < std::string > comments = port.getComments();
606  printComments(comments);
607 
608  std::list < std::string > elements;
609  port.getUserData(elements);
610  printUserData(elements);
611 
612  port.applyOnAllProperties(mApplier);
613  mOut << std::endl << indent << ")";
614  }
615  } catch(Error& e) {
616  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
617  throw;
618  }
619 }
620 
621 // For VectorPortReference
623  try {
624  Indenter indent(*this);
625  if(mIsJoiningContext) {
626  mOut << std::endl << indent << "(portRef " << portRef.getName() << " ";
627  PortReferenceSharedPtr parentCol = portRef.getParentCollection();
628  if(parentCol) {
629  parentCol->accept(*this);
630  } else {
631  if(!mIsPortInstanceContext) {
632  portRef.getParent()->accept(*this);
633  }
634  }
635  mOut << ")";
636  } else {
637  }
638  } catch(Error& e) {
639  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
640  throw;
641  }
642 }
643 
644 // For VectorPortBit
646  try {
647  Indenter indent(*this);
648  if(mIsJoiningContext) {
649  PortSharedPtr parent = bit.getParentCollection();
650  mOut << std::endl << indent << "(portRef (member " << parent->getName() << " ";
651  copy(bit.getIndices().begin(), bit.getIndices().end(),
652  std::ostream_iterator < size_t > (mOut, " "));
653  mOut << ")";
654  PortSharedPtr parentCol = parent->getParentCollection();
655  if(parentCol) {
656  parentCol->accept(*this);
657  }
658  mOut << ")";
659  bit.applyOnAllProperties(mApplier);
660  } else {
661  }
662  } catch(Error& e) {
663  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
664  throw;
665  }
666 }
667 
668 // For VectorPortBitReference
670  try {
671  Indenter indent(*this);
672  if(mIsJoiningContext) {
673  PortReferenceSharedPtr parent = bitRef.getParentCollection();
674  mOut << std::endl << indent << "(portRef (member " << parent->getName() << " ";
675  copy(bitRef.getIndices().begin(), bitRef.getIndices().end(),
676  std::ostream_iterator < size_t > (mOut, " "));
677  mOut << ")";
678  PortReferenceSharedPtr parentCol = parent->getParentCollection();
679  if(parentCol) {
680  parentCol->accept(*this);
681  } else {
682  if(!mIsPortInstanceContext) {
683  parent->getParent()->accept(*this);
684  }
685  }
686  mOut << ")";
687  } else {
688  }
689  } catch(Error& e) {
690  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
691  throw;
692  }
693 }
694 
695 // For PortBundle
696 void Decompiler::visit(PortBundle& port) throw (Error) {
697  try {
698  Indenter indent(*this);
699  if(mIsJoiningContext) {
700  if(mIsPermutableContext) {
701  mOut << std::endl << indent << "(portRef " << port.getName();
702  } else {
703  mOut << " (portRef " << port.getName();
704  }
705  PortSharedPtr parentCol = port.getParentCollection();
706  if(parentCol) {
707  parentCol->accept(*this);
708  }
709  mOut << ")";
710  } else {
711  if(!port.getOriginalName().empty()) {
712  mOut << std::endl << indent << "(portBundle ";
713  mOut << std::endl << indent << " (rename " << port.getName() << " " << "\""
714  << port.getOriginalName() << "\"" << ")";
715  } else {
716  mOut << std::endl << indent << "(portBundle " << port.getName();
717  }
718  {
719  Indenter subIndent(*this);
720  mOut << std::endl << subIndent << "(listOfPorts ";
721  port.applyOnAllChildren(mApplier);
722  mOut << std::endl << subIndent << ")";
723  }
724 
725  //Print Comments
726  std::vector < std::string > comments = port.getComments();
727  printComments(comments);
728 
729  std::list < std::string > elements;
730  port.getUserData(elements);
731  printUserData(elements);
732 
733  mOut << std::endl << indent << ")";
734  }
735  port.applyOnAllProperties(mApplier);
736  } catch(Error& e) {
737  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
738  throw;
739  }
740 }
741 
742 // For PortBundleReference
744  try {
745  Indenter indent(*this);
746  mOut << std::endl << indent << "(portRef " << portRef.getName() << " ";
747  PortReferenceSharedPtr parentCol = portRef.getParentCollection();
748  if(parentCol) {
749  parentCol->accept(*this);
750  } else {
751  portRef.getParent()->accept(*this);
752  }
753  mOut << ")";
754  } catch(Error& e) {
755  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
756  throw;
757  }
758 }
759 
760 // For SingleInstance
761 void Decompiler::visit(SingleInstance& instance) throw (Error) {
762  try {
763 
764  if(mIsJoiningContext) {
765  mOut << " (instanceRef " << instance.getName() << ")";
766  } else {
767  Indenter indent(*this);
768  if(!instance.getOriginalName().empty()) {
769  mOut << std::endl << indent << "(instance ";
770  mOut << std::endl << indent << " (rename " << instance.getName() << " " << "\""
771  << instance.getOriginalName() << "\"" << ")";
772  } else {
773  mOut << std::endl << indent << "(instance " << instance.getName();
774  }
775  mOut << std::endl << indent << " (viewRef " << instance.getMaster()->getName()
776  << " (cellRef " << instance.getMaster()->getParent()->getName() << " (libraryRef "
777  << instance.getMaster()->getParent()->getParent()->getName() << ")))";
778 
779  if(!instance.getDesignator().empty()) {
780  mOut << std::endl << indent << " (designator " << "\"" << instance.getDesignator()
781  << "\"" << ")";
782  }
783 
784  if(NULL != instance.getTiming()) {
785  instance.getTiming()->accept(*this);
786  }
787 
788  //Print Comments
789  std::vector < std::string > comments = instance.getComments();
790  printComments(comments);
791 
792  std::list < std::string > elements;
793  instance.getUserData(elements);
794  printUserData(elements);
795 
796  mParamAssignContext = true;
797  typedef std::map<std::string, ParameterSharedPtr> Params;
798  ParameterMapSharedPtr params = instance.getParameters();
799  ParameterContext context = instance.getParameterContext();
800  params->applyOnOverriddenParameters(context, mApplier);
801  mParamAssignContext = false;
802  instance.applyOnAllProperties(mApplier);
803  std::vector<PortReferenceSharedPtr> portRefs;
804  instance.getPortReferences(portRefs);
805  for(std::vector<PortReferenceSharedPtr>::iterator portRef = portRefs.begin();
806  portRef != portRefs.end(); ++portRef) {
807  PortAttributesSharedPtr attribs = (*portRef)->getAttributes();
808  if(attribs) {
809  mOut << std::endl << indent << " (portInstance ";
810  mIsPortInstanceContext = true;
811  mIsJoiningContext = true;
812  (*portRef)->accept(*this);
813  mIsJoiningContext = false;
814  mIsPortInstanceContext = false;
815  printPortAttributes(attribs);
816  mOut << std::endl << indent << " )";
817  }
818  }
819  mOut << std::endl << indent << ")";
820  }
821  } catch(Error& e) {
822  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
823  throw;
824  }
825 }
826 
827 // For ScalarNet
828 void Decompiler::visit(ScalarNet& net) throw (Error) {
829  try {
830  Indenter indent(*this);
831  if(mIsJoiningContext) {
832  if(!net.getOriginalName().empty()) {
833  mOut << std::endl << indent << "(net ";
834  mOut << std::endl << indent << " (rename " << net.getName() << " " << "\""
835  << net.getOriginalName() << "\"" << ")";
836  } else {
837  mOut << std::endl << indent << "(net " << net.getName();
838  }
839 
840  mOut << std::endl << indent << " (joined ";
841  mIsJoiningContext = true;
842  net.applyOnAllConnectedPorts(mApplier);
843  net.applyOnAllConnectedPortRefs(mApplier);
844  net.applyOnAllConnectedPortLists(mApplier);
845  mOut << std::endl << indent << " )";
846 
847  printNetAttributes(net.getAttributes());
848 
849  //Print Comments
850  std::vector < std::string > comments = net.getComments();
851  printComments(comments);
852 
853  std::list < std::string > elements;
854  net.getUserData(elements);
855  printUserData(elements);
856 
857  net.applyOnAllSubnets(mApplier);
858  net.applyOnAllProperties(mApplier);
859  mOut << std::endl << indent << ")";
860  } else {
861  mOut << std::endl << indent << "(netRef " << net.getName();
862  NetSharedPtr parentCol = net.getParentCollection();
863  if(parentCol) {
864  parentCol->accept(*this);
865  }
866  mOut << ")";
867  }
868  } catch(Error& e) {
869  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
870  throw;
871  }
872 }
873 
874 // For NetBundle
875 void Decompiler::visit(NetBundle& net) throw (Error) {
876  try {
877  Indenter indent(*this);
878  if(mIsJoiningContext) {
879  if(!net.getOriginalName().empty()) {
880  mOut << std::endl << indent << "(netbundle ";
881  mOut << std::endl << indent << " (rename " << net.getName() << " " << "\""
882  << net.getOriginalName() << "\"" << ")";
883  } else {
884  mOut << std::endl << indent << "(netbundle " << net.getName();
885  }
886  mOut << std::endl << indent << " (listOfNets ";
887  net.applyOnAllSubnets(mApplier);
888  net.applyOnAllChildren(mApplier);
889  net.applyOnAllConnectedPorts(mApplier);
890  net.applyOnAllConnectedPortRefs(mApplier);
891  net.applyOnAllConnectedPortLists(mApplier);
892 
893  mOut << std::endl << indent << " )";
894 
895  //Print Comments
896  std::vector < std::string > comments = net.getComments();
897  printComments(comments);
898 
899  std::list < std::string > elements;
900  net.getUserData(elements);
901  printUserData(elements);
902 
903  net.applyOnAllProperties(mApplier);
904  mOut << std::endl << indent << ")";
905  } else {
906  mOut << std::endl << indent << "(netRef " << net.getName();
907  NetSharedPtr parentCol = net.getParentCollection();
908  if(parentCol) {
909  parentCol->accept(*this);
910  }
911  mOut << ")";
912  }
913  } catch(Error& e) {
914  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
915  throw;
916  }
917 }
918 
919 // For VectorNet
920 void Decompiler::visit(VectorNet& net) throw (Error) {
921  try {
922  Indenter indent(*this);
923  if(mIsJoiningContext) {
924  if(!net.getOriginalName().empty()) {
925  mOut << std::endl << indent << "(net ";
926  mOut << std::endl << indent << " (array (rename " << net.getName() << " " << "\""
927  << net.getOriginalName() << "\"" << ")" << " ";
928  } else {
929  mOut << std::endl << indent << "(net (array " << net.getName() << " ";
930  }
931  std::vector < size_t > limits;
932  net.getLimits(limits);
933  copy(limits.begin(), limits.end(), std::ostream_iterator < size_t > (mOut, " "));
934  mOut << ")";
935 
936  mOut << std::endl << indent << " (joined";
937  mIsJoiningContext = true;
938  net.applyOnAllConnectedPorts(mApplier);
939  net.applyOnAllConnectedPortRefs(mApplier);
940  net.applyOnAllConnectedPortLists(mApplier);
941  mOut << std::endl << indent << " )";
942 
943  printNetAttributes(net.getAttributes());
944 
945  //Print Comments
946  std::vector < std::string > comments = net.getComments();
947  printComments(comments);
948 
949  std::list < std::string > elements;
950  net.getUserData(elements);
951  printUserData(elements);
952 
953  net.applyOnAllSubnets(mApplier);
954  net.applyOnAllProperties(mApplier);
955  mOut << std::endl << indent << ")";
956  } else {
957  mOut << std::endl << indent << "(netRef " << net.getName();
958  NetSharedPtr parentCol = net.getParentCollection();
959  if(parentCol) {
960  parentCol->accept(*this);
961  }
962  mOut << ")";
963  }
964 
965  } catch(Error& e) {
966  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
967  throw;
968  }
969 }
970 
971 // For VectorNetBit
973  try {
974  //mIsJoiningContext = true;
975 #if 0
976  mOut << " VectorNetBit name : " << net.getName() << std::endl;
977  mOut << " Size : " << net.getSize() << std::endl;
978  net.applyOnAllSubnets(mApplier);
979  net.applyOnAllConnectedPorts(mApplier);
980  net.applyOnAllConnectedPortRefs(mApplier);
981  net.applyOnAllProperties(mApplier);
982 #endif
983  //TBD
984  //mIsJoiningContext = false;
985  } catch(Error& e) {
986  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
987  throw;
988  }
989 }
990 
991 // For InstanceArray
992 void Decompiler::visit(InstanceArray& instanceArray) throw (Error) {
993  try {
994  Indenter indent(*this);
995  if(!instanceArray.getOriginalName().empty()) {
996  mOut << std::endl << indent << "(instance ";
997  mOut << std::endl << indent << " (array (rename " << instanceArray.getName() << " "
998  << "\"" << instanceArray.getOriginalName() << "\"" << ")" << " ";
999  } else {
1000  mOut << std::endl << indent << "(instance (array " << instanceArray.getName() << " ";
1001  }
1002  std::vector < size_t > limits;
1003  instanceArray.getLimits(limits);
1004  copy(limits.begin(), limits.end(), std::ostream_iterator < size_t > (mOut, " "));
1005  mOut << ")";
1006  mOut << std::endl << indent << " (viewRef " << instanceArray.getMaster()->getName()
1007  << " (cellRef " << instanceArray.getMaster()->getParent()->getName() << " (libraryRef "
1008  << instanceArray.getMaster()->getParent()->getParent()->getName() << ")))";
1009 
1010  if(!instanceArray.getDesignator().empty()) {
1011  mOut << std::endl << indent << " (designator " << "\"" << instanceArray.getDesignator()
1012  << "\"" << ")";
1013  }
1014 
1015  //Print Comments
1016  std::vector < std::string > comments = instanceArray.getComments();
1017  printComments(comments);
1018 
1019  std::list < std::string > elements;
1020  instanceArray.getUserData(elements);
1021  printUserData(elements);
1022 
1023  mParamAssignContext = true;
1024  typedef std::map<std::string, ParameterSharedPtr> Params;
1025  ParameterMapSharedPtr params = instanceArray.getParameters();
1026  ParameterContext context = instanceArray.getParameterContext();
1027  params->applyOnOverriddenParameters(context, mApplier);
1028  mParamAssignContext = false;
1029  instanceArray.applyOnAllProperties(mApplier);
1030  mOut << std::endl << indent << ")";
1031  } catch(Error& e) {
1032  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1033  throw;
1034  }
1035 }
1036 
1037 // For InstanceArrayMember
1039  try {
1040  if(mIsJoiningContext) {
1041  mOut << "(instanceRef (member " << instance.getParentCollection()->getName() << " ";
1042  copy(instance.getIndices().begin(), instance.getIndices().end(),
1043  std::ostream_iterator < size_t > (mOut, " "));
1044  mOut << "))";
1045  } else {
1046  }
1047  } catch(Error& e) {
1048  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1049  throw;
1050  }
1051 }
1052 
1053 // For SingleParameter
1054 void Decompiler::visit(SingleParameter& inSingleParameter) throw (Error) {
1055  try {
1056  Indenter indent(*this);
1057  if(!mParamAssignContext) {
1058  if(!inSingleParameter.getOriginalName().empty()) {
1059  mOut << std::endl << indent << "(parameter ";
1060  mOut << std::endl << indent << " (rename " << inSingleParameter.getName() << " "
1061  << "\"" << inSingleParameter.getOriginalName() << "\"" << ")";
1062  } else {
1063  mOut << std::endl << indent << "(parameter " << inSingleParameter.getName() << " ";
1064  }
1065  printValueType(inSingleParameter.getValue());
1066  printValue(inSingleParameter.getValue());
1067  mOut << ")";
1068  printUnit(inSingleParameter.getUnit());
1069  mOut << ")";
1070  } else {
1071  mOut << std::endl << indent << " (parameterAssign " << inSingleParameter.getName()
1072  << " ";
1073  printValueType(inSingleParameter.getValue());
1074  printValue(inSingleParameter.getValue());
1075  mOut << "))";
1076  }
1077  } catch(Error& e) {
1078  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1079  throw;
1080  }
1081 }
1082 
1083 // For ParameterArray
1084 void Decompiler::visit(ParameterArray& inparamArray) throw (Error) {
1085  try {
1086  Indenter indent(*this);
1087  if(!mParamAssignContext) {
1088  if(!inparamArray.getOriginalName().empty()) {
1089  mOut << std::endl << indent << "(parameter ";
1090  mOut << std::endl << indent << " (array (rename " << inparamArray.getName() << " "
1091  << "\"" << inparamArray.getOriginalName() << "\"" << ")" << " ";
1092  } else {
1093  mOut << std::endl << indent << "(parameter (array " << inparamArray.getName()
1094  << " ";
1095  }
1096  std::vector < size_t > limits;
1097  inparamArray.getLimits(limits);
1098  copy(limits.begin(), limits.end(), std::ostream_iterator < size_t > (mOut, " "));
1099  mOut << ")" << std::endl << indent << " ";
1100  std::vector<ParameterSharedPtr> children;
1101  inparamArray.getChildren(children);
1102  std::vector<ParameterSharedPtr>::iterator start = children.begin();
1103  std::vector<ParameterSharedPtr>::iterator end = children.end();
1104  printValueType((*start)->getValue());
1105  printArray(limits, limits.size(), start, end);
1106  mOut << ")";
1107  printUnit(inparamArray.getUnit());
1108  mOut << std::endl << indent << ")";
1109  } else {
1110  mOut << std::endl << indent << " (parameterAssign " << inparamArray.getName();
1111  std::vector<ParameterSharedPtr> children;
1112  inparamArray.getChildren(children);
1113  if(!children.empty()) {
1114  std::vector < size_t > limits;
1115  inparamArray.getLimits(limits);
1116  std::vector<ParameterSharedPtr>::iterator start = children.begin();
1117  std::vector<ParameterSharedPtr>::iterator end = children.end();
1118  mOut << std::endl << indent << " ";
1119  printValueType((*start)->getValue());
1120  printArray(limits, limits.size(), start, end);
1121  mOut << ")";
1122  mOut << std::endl << indent << " )";
1123  }
1124  }
1125  } catch(Error& e) {
1126  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1127  throw;
1128  }
1129 }
1130 
1132  try {
1133  printValue(bit.getValue());
1134  printUnit(bit.getUnit());
1135  mOut << " ";
1136  } catch(Error& e) {
1137  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1138  throw;
1139  }
1140 }
1141 
1142 //For Property
1143 void Decompiler::visit(Property& inProperty) throw (Error) {
1144  try {
1145  Indenter indent(*this);
1146  if(!inProperty.getOriginalName().empty()) {
1147  mOut << std::endl << indent << "(property ";
1148  mOut << std::endl << indent << " (rename " << inProperty.getName() << " " << "\""
1149  << inProperty.getOriginalName() << "\"" << ")";
1150  } else {
1151  mOut << std::endl << indent << "(property " << inProperty.getName();
1152  }
1153  printValueType(inProperty.getValue());
1154  printValue(inProperty.getValue());
1155  mOut << ")";
1156 
1157  if(!inProperty.getOwner().empty()) {
1158  mOut << std::endl << indent << " (owner " << "\"" << inProperty.getOwner() << "\""
1159  << ")";
1160  }
1161 
1162  //Print Comments
1163  std::vector < std::string > comments = inProperty.getComments();
1164  printComments(comments);
1165 
1166  inProperty.applyOnAllChildren(mApplier);
1167  mOut << ")";
1168  } catch(Error& e) {
1169  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1170  throw;
1171  }
1172 }
1173 
1174 // For PortList
1175 void Decompiler::visit(PortList& inPortList) throw (Error) {
1176  try {
1177  Indenter indent(*this);
1178  if(mIsJoiningContext) {
1179  std::list<PortList::PortListElement> elements;
1180  inPortList.getChildren(elements);
1181  mOut << std::endl << indent << "(portList ";
1182  for(std::list<PortList::PortListElement>::iterator it = elements.begin();
1183  it != elements.end(); ++it) {
1184  switch((*it).getType()) {
1186  (*it).getPort()->accept(*this);
1187  break;
1188  }
1190  (*it).getPortReference()->accept(*this);
1191  break;
1192  }
1193  }
1194  }
1195  mOut << std::endl << indent << ")";
1196  } else {
1197  }
1198  } catch(Error& e) {
1199  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1200  throw;
1201  }
1202 }
1203 
1204 // For PortListAlias
1205 void Decompiler::visit(PortListAlias& inPortListAlias) throw (Error) {
1206  try {
1207  Indenter indent(*this);
1208  mOut << std::endl << indent << "(portListAlias " << inPortListAlias.getName();
1209  mIsJoiningContext = true;
1210  inPortListAlias.getPortList()->accept(*this);
1211  mOut << std::endl << indent << ")";
1212  } catch(Error& e) {
1213  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1214  throw;
1215  }
1216 }
1217 
1218 //For Status
1219 void Decompiler::visit(Status& status) throw (Error) {
1220  try {
1221  Indenter indent(*this);
1222  mOut << std::endl << indent << "(status ";
1223  std::vector<WrittenSharedPtr> elements;
1224  status.getWrittens(elements);
1225 
1226  for(std::vector<WrittenSharedPtr>::iterator it = elements.begin(); it != elements.end();
1227  ++it) {
1228  mOut << std::endl << indent << " (written ";
1229  mOut << std::endl << indent << " (timeStamp ";
1230  WrittenSharedPtr written = *it;
1231  TimeStamp timestamp = written->getTimeStamp();
1232  mOut << timestamp.getYear() << " " << timestamp.getMonth() << " " << timestamp.getDay()
1233  << " " << timestamp.getHour() << " " << timestamp.getMinute() << " "
1234  << timestamp.getSecond() << ")";
1235  if(!written->getAuthorName().empty()) {
1236  mOut << std::endl << indent << " (author " << "\"" << written->getAuthorName()
1237  << "\"" << ")";
1238  }
1239  if(!written->getProgramName().empty()) {
1240  mOut << std::endl << indent << " (program " << "\"" << written->getProgramName()
1241  << "\"";
1242  if(!written->getProgramVersion().empty()) {
1243  mOut << std::endl << indent << " (version " << "\""
1244  << written->getProgramVersion() << "\"" << ")";
1245  }
1246  mOut << ")";
1247  }
1248 
1249  if(!written->getDataOriginLocationName().empty()) {
1250  mOut << std::endl << indent << " (dataOrigin " << "\""
1251  << written->getDataOriginLocationName() << "\"";
1252  if(!written->getDataOriginVersion().empty()) {
1253  mOut << std::endl << indent << " (version " << "\""
1254  << written->getDataOriginVersion() << "\"" << ")";
1255  }
1256  mOut << ")";
1257  }
1258 
1259  //Print Comments
1260  std::vector < std::string > comments = written->getComments();
1261  printComments(comments);
1262 
1263  std::list < std::string > userDatas;
1264  written->getUserData(userDatas);
1265  printUserData(userDatas);
1266 
1267  written->applyOnAllProperties(mApplier);
1268 
1269  mOut << std::endl << indent << " )";
1270  }
1271  //Print Comments
1272  std::vector < std::string > comments = status.getComments();
1273  printComments(comments);
1274 
1275  std::list < std::string > userDatas;
1276  status.getUserData(userDatas);
1277  printUserData(userDatas);
1278 
1279  mOut << std::endl << indent << ")";
1280  } catch(Error& e) {
1281  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1282  throw;
1283  }
1284 }
1285 
1286 //For Permutable
1287 void Decompiler::visit(Permutable& inPermutable) throw (Error) {
1288  try {
1289  mIsPermutableContext = true;
1290  Indenter indent(*this);
1291  if(mIsJoiningContext) {
1292  std::vector<PortSharedPtr> outPorts;
1293  inPermutable.getPorts(outPorts);
1294  if(!inPermutable.getIsNonPermutable()) {
1295  mOut << std::endl << indent << "(permutable ";
1296  } else {
1297  mOut << std::endl << indent << "(nonPermutable ";
1298  }
1299  std::vector<PortSharedPtr>::iterator port = outPorts.begin();
1300  std::vector<PortSharedPtr>::iterator end = outPorts.end();
1301  for(; port != end; ++port) {
1302  (*port)->accept(*this);
1303  }
1304  inPermutable.applyOnAllChildren(mApplier);
1305  mOut << std::endl << indent << ")";
1306  } else {
1307  }
1308  mIsPermutableContext = false;
1309  } catch(Error& e) {
1310  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1311  throw;
1312  }
1313 }
1314 
1315 //For InterfaceJoinedInfo
1316 void Decompiler::visit(InterfaceJoinedInfo& inInterfaceJoinedInfo) throw (Error) {
1317  try {
1318  mIsPermutableContext = true;
1319  Indenter indent(*this);
1320  if(mIsJoiningContext) {
1321  std::string joinedType;
1322  switch(inInterfaceJoinedInfo.getJoinedType()) {
1324  joinedType = "joined";
1325  break;
1326  }
1328  joinedType = "weakJoined";
1329  break;
1330  }
1332  joinedType = "mustJoin";
1333  break;
1334  }
1335  }
1336  mOut << std::endl << indent << "(" << joinedType;
1337  std::list<PortSharedPtr> outPorts;
1338  inInterfaceJoinedInfo.getPorts(outPorts);
1339 
1340  if(!outPorts.empty()) {
1341  std::list<PortSharedPtr>::iterator port = outPorts.begin();
1342  std::list<PortSharedPtr>::iterator end = outPorts.end();
1343  for(; port != end; ++port) {
1344  (*port)->accept(*this);
1345  }
1346  }
1347 
1348  std::list<PortListSharedPtr> outPortLists;
1349  inInterfaceJoinedInfo.getPortLists(outPortLists);
1350  if(!outPortLists.empty()) {
1351  std::list<PortListSharedPtr>::iterator portList = outPortLists.begin();
1352  std::list<PortListSharedPtr>::iterator end = outPortLists.end();
1353  for(; portList != end; ++portList) {
1354  (*portList)->accept(*this);
1355  }
1356  }
1357 
1358  inInterfaceJoinedInfo.applyOnAllChildren(mApplier);
1359  mOut << std::endl << indent << ")";
1360  } else {
1361  }
1362  mIsPermutableContext = false;
1363  } catch(Error& e) {
1364  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1365  throw;
1366  }
1367 }
1368 
1369 // For SimulationInfo
1370 void Decompiler::visit(SimulationInfo& simuInfo) throw (Error) {
1371  try {
1372  Indenter indent(*this);
1373  mOut << std::endl << indent << "(simulationInfo";
1374  simuInfo.applyOnAllLogicValues(mApplier);
1375 
1376  //Print Comments
1377  std::vector < std::string > comments = simuInfo.getComments();
1378  printComments(comments);
1379 
1380  //Print UserData
1381  std::list < std::string > elements;
1382  simuInfo.getUserData(elements);
1383  printUserData(elements);
1384 
1385  mOut << std::endl << indent << ")";
1386  } catch(Error& e) {
1387  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1388  throw;
1389  }
1390 }
1391 
1392 // For Simulate
1393 void Decompiler::visit(Simulate& simulate) throw (Error) {
1394  try {
1395  Indenter indent(*this);
1396  if(!simulate.getOriginalName().empty()) {
1397  mOut << std::endl << indent << "(simulate (rename " << simulate.getName() << " " << "\""
1398  << simulate.getOriginalName() << "\"" << ")";
1399  } else {
1400  mOut << std::endl << indent << "(simulate " << simulate.getName();
1401  }
1402 
1403  simulate.applyOnAllPortListAlias(mApplier);
1404  simulate.applyOnAllWaveValues(mApplier);
1405 
1406  std::vector<ApplySharedPtr> outAllApply;
1407  simulate.getAllApply(outAllApply);
1408  std::vector<ApplySharedPtr>::iterator it = outAllApply.begin();
1409  for(; it != outAllApply.end(); it++) {
1410  (*it)->accept(*this);
1411  }
1412 
1413  //Print Comments
1414  std::vector < std::string > comments = simulate.getComments();
1415  printComments(comments);
1416 
1417  //Print UserData
1418  std::list < std::string > elements;
1419  simulate.getUserData(elements);
1420  printUserData(elements);
1421 
1422  mOut << std::endl << indent << ")";
1423  } catch(Error& e) {
1424  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1425  throw;
1426  }
1427 }
1428 
1429 // For Apply
1430 void Decompiler::visit(Apply& apply) throw (Error) {
1431  try {
1432  Indenter indent(*this);
1433  mOut << std::endl << indent << "(apply " << "(cycle " << apply.getNoOfCycle()
1434  << " (duration ";
1435  printValue(apply.getCycleDuration());
1436  mOut << "))";
1437 
1438  std::list<LogicalResponseSharedPtr> outLogicResponces;
1439  apply.getLogicResponses(outLogicResponces);
1440  std::list<LogicalResponseSharedPtr>::iterator logicIt = outLogicResponces.begin();
1441  for(; logicIt != outLogicResponces.end(); logicIt++) {
1442  (*logicIt)->accept(*this);
1443  }
1444 
1445  //Print Comments
1446  std::vector < std::string > comments = apply.getComments();
1447  printComments(comments);
1448 
1449  //Print UserData
1450  std::list < std::string > elements;
1451  apply.getUserData(elements);
1452  printUserData(elements);
1453 
1454  mOut << std::endl << indent << ")";
1455  } catch(Error& e) {
1456  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1457  throw;
1458  }
1459 }
1460 
1461 // For LogicalResponse logicInput/logicOutput()
1462 void Decompiler::visit(LogicalResponse& logicalResponse) throw (Error) {
1463  try {
1464  Indenter indent(*this);
1465  std::string responseType;
1466  switch(logicalResponse.getResponseType()) {
1468  responseType = "logicInput";
1469  break;
1470  }
1472  responseType = "logicOutput";
1473  break;
1474  }
1475  }
1476  mOut << std::endl << indent << "(" << responseType;
1477  if(NULL != logicalResponse.getConnectedPort()) {
1478  mOut << " " << logicalResponse.getConnectedPort()->getName();
1479  }
1480  if(NULL != logicalResponse.getConnectedPortListAlias()) {
1481  mOut << " " << logicalResponse.getConnectedPortListAlias()->getName();
1482  }
1483  if(NULL != logicalResponse.getConnectedPortList()) {
1484  logicalResponse.getConnectedPortList()->accept(*this);
1485  }
1486  LogicElementSharedPtr logicElement = logicalResponse.getLogicWaveForm();
1487  if(logicElement) {
1488  logicElement->accept(*this);
1489  }
1490  mOut << ")";
1491  } catch(Error& e) {
1492  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1493  throw;
1494  }
1495 }
1496 
1497 // For LogicElement
1498 void Decompiler::visit(LogicElement& logicElem) throw (Error) {
1499  try {
1500  Indenter indent(*this);
1501  std::string type;
1502  std::string logicValueName;
1503  switch(logicElem.getType()) {
1505  type = "";
1506  logicValueName = logicElem.getName();
1507  break;
1508  }
1509  case LogicElement::eTypeList: {
1510  type = "logicList";
1511  break;
1512  }
1513  case LogicElement::eTypeOneOf: {
1514  type = "logicOneOf";
1515  break;
1516  }
1518  type = "logicWaveForm";
1519  break;
1520  }
1522  type = "ignore";
1523  break;
1524  }
1526  type = "transition";
1527  break;
1528  }
1530  type = "becomes";
1531  break;
1532  }
1533  }
1534 
1535  if(LogicElement::eTypeSingle == logicElem.getType()) {
1536  mOut << " " << logicValueName;
1537  } else {
1538  mOut << std::endl << indent << "(" << type;
1539  logicElem.applyOnAllChildren(mApplier);
1540  mOut << ")";
1541  }
1542  } catch(Error& e) {
1543  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1544  throw;
1545  }
1546 }
1547 
1548 //For WaveValue
1549 void Decompiler::visit(WaveValue& waveValue) throw (Error) {
1550  try {
1551  Indenter indent(*this);
1552  mOut << std::endl << indent << "(waveValue " << waveValue.getName() << " ";
1553  printValue(waveValue.getDeltaTimeDuration());
1554  if(NULL != waveValue.getLogicWaveform()) {
1555  waveValue.getLogicWaveform()->accept(*this);
1556  }
1557  mOut << ")";
1558  } catch(Error& e) {
1559  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1560  throw;
1561  }
1562 }
1563 
1564 // For LogicValue
1565 void Decompiler::visit(LogicValue& logicVal) throw (Error) {
1566  try {
1567  Indenter indent(*this);
1568  if(!logicVal.getOriginalName().empty()) {
1569  mOut << std::endl << indent << "(logicValue ";
1570  mOut << std::endl << indent << " (rename " << logicVal.getName() << " " << "\""
1571  << logicVal.getOriginalName() << "\"" << ")";
1572  } else {
1573  mOut << std::endl << indent << "(logicValue " << logicVal.getName();
1574  }
1575 
1576  //TBD
1577  //Print attributes
1578  printLogicValueAttributes(logicVal.getAttributes());
1579 
1580  //Print Comments
1581  std::vector < std::string > comments = logicVal.getComments();
1582  printComments(comments);
1583 
1584  logicVal.applyOnAllProperties(mApplier);
1585 
1586  //Print UserData
1587  std::list < std::string > elements;
1588  logicVal.getUserData(elements);
1589  printUserData(elements);
1590 
1591  mOut << std::endl << indent << ")";
1592  } catch(Error& e) {
1593  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1594  throw;
1595  }
1596 }
1597 
1598 // For Timing
1599 void Decompiler::visit(Timing& timing) throw (Error) {
1600  try {
1601  Indenter indent(*this);
1602  mOut << std::endl << indent << "(timing " << std::endl;
1603  mOut << indent;
1604  printDerivation(timing.getDerivation());
1605 
1606  std::list<PathDelaySharedPtr> outPathDelays;
1607  timing.getPathDelays(outPathDelays);
1608  std::list<PathDelaySharedPtr>::iterator pathDelayIt = outPathDelays.begin();
1609  for(; pathDelayIt != outPathDelays.end(); pathDelayIt++) {
1610  mOut << indent << " (pathDelay " << std::endl;
1611  mOut << indent << " (delay ";
1612  PathDelaySharedPtr pathDelay = *pathDelayIt;
1613  Value::MiNoMax mnm = pathDelay->getDelay();
1614  Value val(Value::eValueTypeMiNoMax, mnm);
1615  printValue(val);
1616  mOut << ")" << std::endl;
1617 
1618  //Print event
1619  std::list<EventSharedPtr> outEvents;
1620  pathDelay->getEvents(outEvents);
1621  std::list<EventSharedPtr>::iterator eventIt = outEvents.begin();
1622  for(; eventIt != outEvents.end(); eventIt++) {
1623  mOut << " ";
1624  (*eventIt)->accept(*this);
1625  }
1626  mOut << indent << " )" << std::endl;
1627  }
1628 
1629  //Print forbiddenEvent
1630  std::list<ForbiddenEventSharedPtr> outForbiddentEvents;
1631  timing.getForbiddentEvents(outForbiddentEvents);
1632  std::list<ForbiddenEventSharedPtr>::iterator forbiddentEventIt =
1633  outForbiddentEvents.begin();
1634  for(; forbiddentEventIt != outForbiddentEvents.end(); forbiddentEventIt++) {
1635  (*forbiddentEventIt)->accept(*this);
1636  }
1637 
1638  //Print Comments
1639  std::vector < std::string > comments = timing.getComments();
1640  printComments(comments);
1641 
1642  //Print UserData
1643  std::list < std::string > elements;
1644  timing.getUserData(elements);
1645  printUserData(elements);
1646 
1647  mOut << std::endl << indent << ")";
1648  } catch(Error& e) {
1649  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1650  throw;
1651  }
1652 }
1653 
1654 //For Event
1655 void Decompiler::visit(Event& event) throw (Error) {
1656  try {
1657  Indenter indent(*this);
1658  std::string type;
1659  switch(event.getType()) {
1660  case Event::eTypeEvent: {
1661  type = "(event";
1662  break;
1663  }
1664  case Event::eTypeOffsetEvent: {
1665  type = "(offsetEvent (event";
1666  break;
1667  }
1668  }
1669 
1670  mOut << indent << type;
1671 
1672  //Print port or portGroup
1673  mIsJoiningContext = true;
1674  std::list<PortElement> outPortElements;
1675  event.getPortElements(outPortElements);
1676  std::list<PortElement>::iterator portElem = outPortElements.begin();
1677  std::list<PortElement>::iterator end = outPortElements.end();
1678  if(outPortElements.size() > 1) {
1679  (*this).setIndentation((*this).getIndentation() + 8);
1680  mOut << std::endl << indent << "(portGroup";
1681  }
1682  if(outPortElements.size() == 1) {
1683  (*this).setIndentation((*this).getIndentation() + 4);
1684  }
1685 
1686  for(; portElem != end; ++portElem) {
1687  switch((*portElem).getType()) {
1689  (*portElem).getPort()->accept(*this);
1690  break;
1691  }
1693  (*portElem).getPortReference()->accept(*this);
1694  break;
1695  }
1696  }
1697  }
1698 
1699  if(outPortElements.size() > 1) {
1700  mOut << ")";
1701  (*this).setIndentation((*this).getIndentation() - 8);
1702  }
1703  if(outPortElements.size() == 1) {
1704  (*this).setIndentation((*this).getIndentation() - 4);
1705  }
1706  //Print portList
1707  if(NULL != event.getPortList()) {
1708  (*this).setIndentation((*this).getIndentation() + 4);
1709  event.getPortList()->accept(*this);
1710  (*this).setIndentation((*this).getIndentation() - 4);
1711  }
1712  //Print net or netGroup
1713  mIsJoiningContext = false;
1714  std::list<NetSharedPtr> outNets;
1715  event.getNets(outNets);
1716  std::list<NetSharedPtr>::iterator net = outNets.begin();
1717  if(outNets.size() > 1) {
1718  (*this).setIndentation((*this).getIndentation() + 8);
1719  mOut << std::endl << indent << "(netGroup";
1720  }
1721  if(outNets.size() == 1) {
1722  (*this).setIndentation((*this).getIndentation() + 4);
1723  }
1724 
1725  for(; net != outNets.end(); ++net) {
1726  (*net)->accept(*this);
1727  }
1728 
1729  if(outNets.size() > 1) {
1730  mOut << ")";
1731  (*this).setIndentation((*this).getIndentation() - 8);
1732  }
1733  if(outNets.size() == 1) {
1734  (*this).setIndentation((*this).getIndentation() - 4);
1735  }
1736 
1737  //Print transition/becomes
1738  if(NULL != event.getTransition()) {
1739  (*this).setIndentation((*this).getIndentation() + 4);
1740  event.getTransition()->accept(*this);
1741  (*this).setIndentation((*this).getIndentation() - 4);
1742  }
1743 
1744  switch(event.getType()) {
1745  case Event::eTypeEvent: {
1746  mOut << ")" << std::endl;
1747  break;
1748  }
1749  case Event::eTypeOffsetEvent: {
1750  mOut << ") "; //end of event
1751  printValue(event.getOffsetTime());
1752  mOut << ")" << std::endl;
1753  break;
1754  }
1755  }
1756  } catch(Error& e) {
1757  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1758  throw;
1759  }
1760 }
1761 
1762 //For ForbiddenEvent
1763 void Decompiler::visit(ForbiddenEvent& forbiddenevent) throw (Error) {
1764  try {
1765  Indenter indent(*this);
1766  mOut << indent << "(forbiddenEvent" << std::endl;
1767  mOut << indent << " (timeInterval" << std::endl;
1768  if(NULL != forbiddenevent.getStartTimeInterval()) {
1769  mOut << " ";
1770  forbiddenevent.getStartTimeInterval()->accept(*this);
1771  }
1772  if(NULL != forbiddenevent.getEndTimeInterval()) {
1773  mOut << " ";
1774  forbiddenevent.getEndTimeInterval()->accept(*this);
1775  } else {
1776  mOut << " ";
1777  mOut << indent << " (duration ";
1778  printValue(forbiddenevent.getDuration());
1779  mOut << ")" << std::endl;
1780  }
1781  mOut << indent << " )" << std::endl;
1782 
1783  std::list<EventSharedPtr> outEvents;
1784  forbiddenevent.getEvents(outEvents);
1785  std::list<EventSharedPtr>::iterator eventIt = outEvents.begin();
1786  for(; eventIt != outEvents.end(); eventIt++) {
1787  (*eventIt)->accept(*this);
1788  }
1789  mOut << indent << ")";
1790  } catch(Error& e) {
1791  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1792  throw;
1793  }
1794 }
1795 
1796 // For UserData
1797 void Decompiler::printUserData(std::list<std::string> inElements) throw (Error) {
1798  try {
1799  Indenter indent(*this);
1800  if(!inElements.empty()) {
1801  for(std::list<std::string>::iterator it = inElements.begin(); it != inElements.end();
1802  ++it) {
1803  mOut << std::endl << indent << "(userData " << trimLeadingSpaces(*it);
1804  }
1805  }
1806  } catch(Error& e) {
1807  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1808  throw;
1809  }
1810 }
1811 
1812 // For Comment
1813 void Decompiler::printComments(std::vector<std::string>& inElements) throw (Error) {
1814  try {
1815  Indenter indent(*this);
1816  if(!inElements.empty()) {
1817  for(std::vector<std::string>::iterator it = inElements.begin(); it != inElements.end();
1818  ++it) {
1819  mOut << std::endl << indent << "(comment " << "\"" << trimLeadingSpaces(*it) << "\""
1820  << ")";
1821  }
1822  }
1823  } catch(Error& e) {
1824  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
1825  throw;
1826  }
1827 }
1828 void Decompiler::printValueType(const Value& value) throw (Error) {
1829  switch(value.getType()) {
1830  case Value::eValueTypeBoolean: {
1831  mOut << " (boolean ";
1832  break;
1833  }
1834  case Value::eValueTypeInteger: {
1835  mOut << " (integer ";
1836  break;
1837  }
1838  case Value::eValueTypeMiNoMax: {
1839  mOut << " (minomax ";
1840  break;
1841  }
1842  case Value::eValueTypeNumber: {
1843  mOut << " (number ";
1844  break;
1845  }
1846  case Value::eValueTypePoint: {
1847  mOut << " (point ";
1848  break;
1849  }
1850  case Value::eValueTypeString: {
1851  mOut << " (string ";
1852  break;
1853  }
1854  default: {
1855  }
1856  }
1857 }
1858 
1859 void Decompiler::printValue(const Value& value) throw (Error) {
1860  if(!value.getIsSet()) {
1861  return;
1862  }
1863  switch(value.getType()) {
1864  case Value::eValueTypeBoolean: {
1865  mOut << ((value.get<Value::Boolean>()) ? "(true)" : "(false)");
1866  break;
1867  }
1868  case Value::eValueTypeInteger: {
1869  mOut << value.get<Value::Integer>();
1870  break;
1871  }
1872  case Value::eValueTypeMiNoMax: {
1873  Value::MiNoMax mnm = value.get<Value::MiNoMax>();
1874  mOut << "(mnm ";
1875  if(!mnm.getMinUndefined()) {
1876  Value val(Value::eValueTypeNumber, mnm.getMin());
1877  printValue(val);
1878  mOut << " ";
1879  } else {
1880  mOut << "(undefined) ";
1881  }
1882 
1884  printValue(val);
1885  mOut << " ";
1886 
1887  if(!mnm.getMinUndefined()) {
1888  Value val(Value::eValueTypeNumber, mnm.getMax());
1889  printValue(val);
1890  } else {
1891  mOut << "(undefined)";
1892  }
1893  mOut << ")";
1894  break;
1895  }
1896  case Value::eValueTypeNumber: {
1897  Value::Number num = value.get<Value::Number>();
1898  mOut << "(e " << num.getMantissa() << " " << num.getExponent() << ")";
1899  break;
1900  }
1901  case Value::eValueTypePoint: {
1902  Value::Point pt = value.get<Value::Point>();
1903  mOut << "(pt " << pt.getX() << " " << pt.getY() << ")";
1904  break;
1905  }
1906  case Value::eValueTypeString: {
1907  mOut << "\"" << value.get<Value::String>() << "\"";
1908  break;
1909  }
1910  default: {
1911  }
1912  }
1913 }
1914 
1915 void Decompiler::printUnit(const Unit unit) throw (Error) {
1916  switch(unit) {
1917  case eUnitAngle: {
1918  mOut << " (unit ANGLE )";
1919  break;
1920  }
1921  case eUnitCapacitance: {
1922  mOut << " (unit CAPACITANCE )";
1923  break;
1924  }
1925  case eUnitConductance: {
1926  mOut << " (unit CONDUCTANCE )";
1927  break;
1928  }
1929  case eUnitCharge: {
1930  mOut << " (unit CHARGE )";
1931  break;
1932  }
1933  case eUnitCurrent: {
1934  mOut << " (unit CURRENT )";
1935  break;
1936  }
1937  case eUnitDistance: {
1938  mOut << " (unit DISTANCE )";
1939  break;
1940  }
1941  case eUnitEnergy: {
1942  mOut << " (unit ENERGY )";
1943  break;
1944  }
1945  case eUnitFlux: {
1946  mOut << " (unit FLUX )";
1947  break;
1948  }
1949  case eUnitFrequency: {
1950  mOut << " (unit FREQUENCY )";
1951  break;
1952  }
1953  case eUnitInductance: {
1954  mOut << " (unit INDUCTANCE )";
1955  break;
1956  }
1957  case eUnitMass: {
1958  mOut << " (unit MASS )";
1959  break;
1960  }
1961  case eUnitPower: {
1962  mOut << " (unit POWER )";
1963  break;
1964  }
1965  case eUnitResistance: {
1966  mOut << " (unit RESISTANCE )";
1967  break;
1968  }
1969  case eUnitTemperature: {
1970  mOut << " (unit TEMPERATURE )";
1971  break;
1972  }
1973  case eUnitTime: {
1974  mOut << " (unit TIME )";
1975  break;
1976  }
1977  case eUnitVoltage: {
1978  mOut << " (unit VOLTAGE )";
1979  break;
1980  }
1981  default: {
1982  }
1983  }
1984 }
1985 
1986 void Decompiler::printDerivation(const Derivation derivation) throw (Error) {
1987  mOut << " (derivation ";
1988  switch(derivation) {
1989  case eDerivationCalculated: {
1990  mOut << "CALCULATED";
1991  break;
1992  }
1993  case eDerivationMeasured: {
1994  mOut << "MEASURED";
1995  break;
1996  }
1997  case eDerivationRequired: {
1998  mOut << "REQUIRED";
1999  break;
2000  }
2001  default: {
2002  }
2003  }
2004  mOut << ")" << std::endl;
2005 }
2006 
2007 void Decompiler::printArray(const std::vector<size_t>& outVector, size_t depth,
2008  std::vector<ParameterSharedPtr>::iterator& itStart,
2009  std::vector<ParameterSharedPtr>::iterator& itEnd) throw (Error) {
2010  Indenter indent(*this);
2011 
2012  size_t array_size = outVector.size();
2013  /*std::vector<size_t>::const_iterator it = outVector.begin();*/
2014  for(size_t i = 0; i < outVector.at(array_size - depth); i++) {
2015  if(depth == 1) {
2016  printValue((*itStart)->getValue());
2017  mOut << " ";
2018  if(itStart != itEnd) {
2019  ++itStart;
2020  }
2021  } else {
2022  mOut << std::endl << indent << " ";
2023  printValueType((*itStart)->getValue());
2024  printArray(outVector, depth - 1, itStart, itEnd);
2025  mOut << ")";
2026  }
2027  }
2028 }
2029 
2031  if(!inAttrib)
2032  return;
2033 
2034  Indenter indent(*this);
2035  try {
2036  {
2037  Value unused = inAttrib->getUnused();
2038  if(unused.getIsSet()) {
2039  mOut << std::endl << indent << "(unused)";
2040  }
2041  }
2042  {
2043  Value designator = inAttrib->getDesignator();
2044  if(designator.getIsSet()) {
2045  mOut << std::endl << indent << "(designator " << "\""
2046  << designator.get<Value::String>() << "\"" << ")";
2047  }
2048  }
2049  {
2050  Value val = inAttrib->getDcFaninLoad();
2051  if(val.getIsSet()) {
2052  mOut << std::endl << indent << "(dcFaninLoad ";
2053  printValue(val);
2054  mOut << ")";
2055  }
2056  }
2057  {
2058  Value val = inAttrib->getDcFanoutLoad();
2059  if(val.getIsSet()) {
2060  mOut << std::endl << indent << "(dcFanoutLoad ";
2061  printValue(val);
2062  mOut << ")";
2063  }
2064  }
2065  {
2066  Value val = inAttrib->getDcMaxFanin();
2067  if(val.getIsSet()) {
2068  mOut << std::endl << indent << "(dcMaxFanin ";
2069  printValue(val);
2070  mOut << ")";
2071  }
2072  }
2073  {
2074  Value val = inAttrib->getDcMaxFanout();
2075  if(val.getIsSet()) {
2076  mOut << std::endl << indent << "(dcMaxFanout ";
2077  printValue(val);
2078  mOut << ")";
2079  }
2080  }
2081  {
2082  Value val = inAttrib->getAcLoad();
2083  if(val.getIsSet()) {
2084  mOut << std::endl << indent << "(acLoad ";
2085  printValue(val);
2086  mOut << ")";
2087  }
2088  }
2089  if(inAttrib->getIsPortDelaySet()) {
2090  PortDelay delay = inAttrib->getPortDelay();
2091  mOut << std::endl << indent << "(portDelay " << std::endl;
2092  mOut << indent;
2093  printDerivation(delay.getDerivation());
2094  switch(delay.getType()) {
2095  case PortDelay::eTypeDelay: {
2096  mOut << indent << " (delay ";
2097  Value::MiNoMax mnm = delay.getDelay();
2098  Value val(Value::eValueTypeMiNoMax, mnm);
2099  printValue(val);
2100  mOut << ")";
2101  break;
2102  }
2104  mOut << indent << " (loadDelay ";
2105  {
2106  Value::MiNoMax mnm = delay.getDelay();
2107  Value val(Value::eValueTypeMiNoMax, mnm);
2108  printValue(val);
2109  }
2110  {
2111  Value::MiNoMax mnm = delay.getAcLoad();
2112  Value val(Value::eValueTypeMiNoMax, mnm);
2113  printValue(val);
2114  }
2115  mOut << ")";
2116  break;
2117  }
2118  }
2119  //Print transition/becomes
2120  if(NULL != delay.getTransition()) {
2121  delay.getTransition()->accept(*this);
2122  }
2123  mOut << ")";
2124  }
2125  } catch(Error& e) {
2126  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
2127  throw;
2128  }
2129 }
2130 
2132  if(!inAttrib)
2133  return;
2134 
2135  Indenter indent(*this);
2136  try {
2137  (*this).setIndentation((*this).getIndentation() - 2);
2138  if(inAttrib->getIsCriticalitySet()) {
2139  int32_t criticality = inAttrib->getCriticality();
2140  mOut << std::endl << indent << "(criticality " << criticality << ")";
2141  }
2142  if(inAttrib->getIsNetDelaySet()) {
2143  NetDelay netDelay = inAttrib->getNetDelay();
2144  mOut << std::endl << indent << "(netDelay " << std::endl;
2145  mOut << indent;
2146  printDerivation(netDelay.getDerivation());
2147 
2148  mOut << indent << " (delay ";
2149  Value::MiNoMax mnm = netDelay.getDelay();
2150  Value val(Value::eValueTypeMiNoMax, mnm);
2151  printValue(val);
2152  mOut << ")";
2153 
2154  //Print transition/becomes
2155  if(NULL != netDelay.getTransition()) {
2156  netDelay.getTransition()->accept(*this);
2157  }
2158  mOut << std::endl << indent << ")";
2159  }
2160  (*this).setIndentation((*this).getIndentation() + 2);
2161  } catch(Error& e) {
2162  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
2163  throw;
2164  }
2165 }
2166 
2168  throw (Error) {
2169  if(!inAttrib)
2170  return;
2171 
2172  Indenter indent(*this);
2173  try {
2174  if(!inAttrib->getDesignator().empty()) {
2175  mOut << std::endl << indent << " (designator " << "\"" << inAttrib->getDesignator()
2176  << "\"" << ")";
2177  }
2178 
2179  if(NULL != inAttrib->getSimulate()) {
2180  (*this).setIndentation((*this).getIndentation() - 4);
2181  inAttrib->getSimulate()->accept(*this);
2182  (*this).setIndentation((*this).getIndentation() + 4);
2183  }
2184 
2185  if(NULL != inAttrib->getTiming()) {
2186  (*this).setIndentation((*this).getIndentation() - 4);
2187  inAttrib->getTiming()->accept(*this);
2188  (*this).setIndentation((*this).getIndentation() + 4);
2189  }
2190 
2191  //Print Comments
2192  std::vector < std::string > comments = inAttrib->getComments();
2193  printComments(comments);
2194 
2195  std::list < std::string > userDatas;
2196  inAttrib->getUserData(userDatas);
2197  printUserData(userDatas);
2198  } catch(Error& e) {
2199  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
2200  throw;
2201  }
2202 }
2203 
2204 //For LogicValueAttributes
2206  throw (Error) {
2207 
2208  if(!inAttrib)
2209  return;
2210 
2211  Indenter indent(*this);
2212  try {
2213  {
2214  if(inAttrib->getIsVoltageMapSet()) {
2215  Value::MiNoMax mnm = inAttrib->getVoltageMap();
2216  Value val(Value::eValueTypeMiNoMax, mnm);
2217  mOut << std::endl << indent << "(voltageMap ";
2218  printValue(val);
2219  mOut << ")";
2220  }
2221  }
2222  {
2223  if(inAttrib->getIsCurrentMapSet()) {
2224  Value::MiNoMax mnm = inAttrib->getCurrentMap();
2225  Value val(Value::eValueTypeMiNoMax, mnm);
2226  mOut << std::endl << indent << "(currentMap ";
2227  printValue(val);
2228  mOut << ")";
2229  }
2230  }
2231  {
2232  if(inAttrib->getIsBooleanMapSet()) {
2233  Value::Boolean boolean = inAttrib->getBooleanMap();
2234  Value val(Value::eValueTypeBoolean, boolean);
2235  mOut << std::endl << indent << "(booleanMap ";
2236  printValue(val);
2237  mOut << ")";
2238  }
2239  }
2240  {
2241  LogicValueSharedPtr logicVal = inAttrib->getWeakLogicValue();
2242  if(logicVal) {
2243  mOut << std::endl << indent << "(weak " << logicVal->getName() << ")";
2244  }
2245  }
2246  {
2247  LogicValueSharedPtr logicVal = inAttrib->getStrongLogicValue();
2248  if(logicVal) {
2249  mOut << std::endl << indent << "(strong " << logicVal->getName() << ")";
2250  }
2251  }
2252  {
2253  std::list<LogicValueSharedPtr> outLogicValues;
2254  inAttrib->getCompoundLogicValues(outLogicValues);
2255  if(!outLogicValues.empty()) {
2256  mOut << std::endl << indent << "(compound";
2257  std::list<LogicValueSharedPtr>::iterator it = outLogicValues.begin();
2258  for(; it != outLogicValues.end(); it++) {
2259  mOut << " " << (*it)->getName();
2260  }
2261  mOut << ")";
2262  } else {
2263  }
2264  }
2265  {
2266  std::list<LogicValueSharedPtr> outLogicValues;
2267  inAttrib->getDominatedLogicValues(outLogicValues);
2268  if(!outLogicValues.empty()) {
2269  mOut << std::endl << indent << "(dominates";
2270  std::list<LogicValueSharedPtr>::iterator it = outLogicValues.begin();
2271  for(; it != outLogicValues.end(); it++) {
2272  mOut << " " << (*it)->getName();
2273  }
2274  mOut << ")";
2275  } else {
2276  }
2277  }
2278  {
2279  std::list<LogicValueSharedPtr> outLogicValues;
2280  inAttrib->getResolvedLogicValues(outLogicValues);
2281  if(!outLogicValues.empty()) {
2282  mOut << std::endl << indent << "(resolves";
2283  std::list<LogicValueSharedPtr>::iterator it = outLogicValues.begin();
2284  for(; it != outLogicValues.end(); it++) {
2285  mOut << " " << (*it)->getName();
2286  }
2287  mOut << ")";
2288  } else {
2289  }
2290  }
2291  {
2292  bool isolated = inAttrib->getIsIsolated();
2293  if(isolated) {
2294  mOut << std::endl << indent << "(isolated)";
2295  }
2296  }
2297  {
2298  typedef LogicValueAttributes::LogicMap LogicMap;
2299  std::list<LogicMap*> outLogicMaps;
2300  inAttrib->getLogicMaps(outLogicMaps);
2301  if(!outLogicMaps.empty()) {
2302  std::list<LogicMap*>::iterator it = outLogicMaps.begin();
2303 
2304  for(; it != outLogicMaps.end(); it++) {
2305  if((*it)->mLogicMapType == LogicMap::eLogicMapTypeInput) {
2306  mOut << std::endl << indent << "(logicMapInput ";
2307  } else {
2308  mOut << std::endl << indent << "(logicMapOutput ";
2309  }
2310  mOut << "(logicRef " << (*it)->mLogicRef;
2311  mOut << " (libraryRef " << (*it)->mLibraryRef << ")";
2312  mOut << "))";
2313  }
2314  } else {
2315  }
2316  }
2317  } catch(Error& e) {
2318  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
2319  throw;
2320  }
2321 }
2323 try {
2324  decompile();
2325 }
2326 catch(Error& e) {
2327  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
2328  throw;
2329 }
2330 
2331 /**
2332  * Decompile the tree.
2333  *
2334  * @param[in] root Root of the OM tree.
2335  */
2337  try {
2338  mRoot->accept(*this);
2339  } catch(Error& e) {
2340  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
2341  throw;
2342  }
2343 }
2344 
2345 void Decompiler::setIndentation(size_t inIndentation) {
2346  mIndentation = inIndentation;
2347 }
2348 
2349 Decompiler::Decompiler(const RootSharedPtr& inRoot, std::ostream& outStream) : mRoot(inRoot),
2350  mOut(outStream), mIsJoiningContext(false), mIsPermutableContext(false),
2351  mIsExternContext(false), mParamAssignContext(false), mIsPortInstanceContext(false),
2352  mIndentation(0), mApplier(*this) {}
2353 
2355 
2357  mRoot(inSource.mRoot), mOut(inSource.mOut), mIsJoiningContext(inSource.mIsJoiningContext), mIsExternContext(
2358  inSource.mIsExternContext), mParamAssignContext(inSource.mParamAssignContext), mIsPortInstanceContext(
2359  inSource.mIsPortInstanceContext), mIndentation(inSource.mIndentation), mApplier(*this) {}
2360 
2362  if(this != &inSource) {
2363  mRoot = inSource.mRoot;
2368  mIndentation = inSource.mIndentation;
2369  }
2370  return *this;
2371 }
2372 
2373 } // namespace generic
2374 } // namespace torc
boost::shared_ptr< LogicValue > LogicValueSharedPtr
Represents an EDIF cell.
Definition: Cell.hpp:55
Represents a bit of a net array.
boost::shared_ptr< Instance > InstanceSharedPtr
Represents areference to a standalone port.
void setIndentation(size_t inIndentation)
Represents a reference to a port array.
const bool getIsSet() const
Definition: Value.hpp:357
const Value::Number getSiValue() const
Definition: ScaleFactor.hpp:94
void printUserData(std::list< std::string > inElements)
This class is used within simulate to describe input stimuli and expected responces over a certain ti...
Definition: Apply.hpp:37
Represents a bundle of ports.
Definition: PortBundle.hpp:44
boost::shared_ptr< NetAttributes > NetAttributesSharedPtr
const Value::Number getNominal() const
Definition: Value.hpp:323
Represents and EDIF View.
Definition: View.hpp:61
Represents a bit of a port.
Decompiler & operator=(const Decompiler &inSource)
boost::shared_ptr< LogicElement > LogicElementSharedPtr
void printComments(std::vector< std::string > &inElements)
const bool getMinUndefined() const
Definition: Value.hpp:311
void printViewInterfaceAttributes(const InterfaceAttributesSharedPtr &inAttrib)
Represents a member of an instance array.
const Value::MiNoMax getDelay() const
Definition: PortDelay.hpp:148
void printDerivation(const Derivation derivation)
const LogicElementSharedPtr getTransition() const
Definition: NetDelay.hpp:113
An EDIF cell library.
Definition: Library.hpp:60
This structure is for logicRef and libraryRef used in logicMapInput/logicMapOutput.
Permutable is used to describe a relationship in which ports are interchangeable. ...
Definition: Permutable.hpp:40
Represents the portDelay attribute on Port or PortReference.
Definition: PortDelay.hpp:36
const Value::Number getEdifValue() const
Definition: ScaleFactor.hpp:85
uint32_t getSecond() const
Definition: TimeStamp.hpp:185
Represents the netDelay attribute of Net.
Definition: NetDelay.hpp:32
Represents a single instance of the view of a cell.
Decompiler(const RootSharedPtr &inRoot, std::ostream &outStream=std::cout)
This class is used to hold all information about the logic values used within a library.
boost::shared_ptr< Written > WrittenSharedPtr
bool set(const KeyType &inKey, const ValueType &inValue)
Definition: SymTab.hpp:132
This class is used within simulationInfo construct to define a logic value to use for modeling in the...
Definition: LogicValue.hpp:42
std::string String
Definition: Value.hpp:61
std::string string
uint32_t getHour() const
Definition: TimeStamp.hpp:167
const int32_t getY() const
Definition: Value.hpp:339
boost::shared_ptr< PortAttributes > PortAttributesSharedPtr
size_t getIndentation() const
Definition: Decompiler.hpp:173
const Value::MiNoMax getAcLoad() const
Definition: PortDelay.hpp:152
const Value::Number getMax() const
Definition: Value.hpp:307
uint32_t getMonth() const
Definition: TimeStamp.hpp:149
const int32_t getX() const
Definition: Value.hpp:335
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
uint32_t getYear() const
Definition: TimeStamp.hpp:140
Represents a port array.
Definition: VectorPort.hpp:45
boost::shared_ptr< Net > NetSharedPtr
Represents a parameter array.
void printUnit(const Unit unit)
Represents the time in Universal Time Coordinate (year, month, day, hour, minute, second) ...
Definition: TimeStamp.hpp:29
boost::shared_ptr< Library > LibrarySharedPtr
boost::shared_ptr< PortReference > PortReferenceSharedPtr
Represents a net array.
Definition: VectorNet.hpp:42
boost::shared_ptr< SimulationInfo > SimulationInfoSharedPtr
Represents a standalone port.
Definition: ScalarPort.hpp:42
Represents the Interface joining information.
This class is used to provide a set of path delays or timing constrains (forbidden events) ...
Definition: Timing.hpp:40
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
void visit(Root &inroot)
Definition: Decompiler.cpp:178
Represents an array of instances.
Represents a standalone net.
Definition: ScalarNet.hpp:42
ForbiddenEvent class lists events which are forbidden during a period of times which is specified by ...
const Derivation getDerivation() const
Definition: PortDelay.hpp:140
uint32_t getMinute() const
Definition: TimeStamp.hpp:176
Represents different logic elements which holds array of logic values.
void printValueType(const Value &value)
const LogicElementSharedPtr getTransition() const
Definition: PortDelay.hpp:161
boost::shared_ptr< InterfaceAttributes > InterfaceAttributesSharedPtr
Represents an ordered list of port references with a name aliased.
Represents a reference to a bit of a port.
uint32_t getDay() const
Definition: TimeStamp.hpp:158
Represents an ordered list of port references.
Definition: PortList.hpp:43
Root of the EDIF Object Model.
Definition: Root.hpp:66
This class is used to model logicInput/logicOutput construct. This class holds information of logical...
const Value::Number getMin() const
Definition: Value.hpp:319
This class is used within simulate to describe input stimuli and expected responces over a certain ti...
Definition: WaveValue.hpp:35
Represents a bundle of nets.
Definition: NetBundle.hpp:43
boost::shared_ptr< View > ViewSharedPtr
void printArray(const std::vector< size_t > &outVector, size_t depth, std::vector< ParameterSharedPtr >::iterator &itStart, std::vector< ParameterSharedPtr >::iterator &itEnd)
Event is used to describe an event on a port or a net using logic state transitions. Events can also be described for unordered groups of ports or nets using portGroup or netGroup. An ordered list of ports may also be used using a portList.
Definition: Event.hpp:45
const int32_t getExponent() const
Definition: Value.hpp:331
boost::shared_ptr< Port > PortSharedPtr
boost::shared_ptr< PathDelay > PathDelaySharedPtr
const Value::MiNoMax getDelay() const
Definition: NetDelay.hpp:104
void printValue(const Value &value)
const PortDelay::Type getType() const
Definition: PortDelay.hpp:144
A symbol table.
Definition: SymTab.hpp:38
std::ostream & operator<<(std::ostream &outStream, const Indenter &indent)
Definition: Decompiler.cpp:165
boost::shared_ptr< LogicValueAttributes > LogicValueAttributesSharedPtr
void printLogicValueAttributes(const LogicValueAttributesSharedPtr &inAttrib)
void printNetAttributes(const NetAttributesSharedPtr &inAttrib)
This class is to model simulate construct which is a named collection of simulation stimulus and resp...
Definition: Simulate.hpp:46
Represents EDIF status construct.
Definition: Status.hpp:42
Represents a reference to a bundle of ports.
const int32_t getMantissa() const
Definition: Value.hpp:327
_ValueType get() const
Definition: Value.hpp:386
void printPortAttributes(const PortAttributesSharedPtr &inAttrib)
boost::shared_ptr< Root > RootSharedPtr
boost::shared_ptr< ParameterMap > ParameterMapSharedPtr
const Derivation getDerivation() const
Definition: NetDelay.hpp:95
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73