torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VerilogExporterVisitor.hpp
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 /// \file
17 /// \brief Header for the VerilogExporterVisitor class.
18 
19 #ifndef TORC_GENERIC_VERILOG_VERILOGEXPORTERVISITOR_HPP
20 #define TORC_GENERIC_VERILOG_VERILOGEXPORTERVISITOR_HPP
21 
23 #include <string>
24 #include <vector>
25 
26 namespace torc {
27 namespace generic {
28 
29 namespace generic { class VerilogExporterUnitTest; }
30 
31  /// \brief Generic netlist object visitor for output as structural Verilog.
33  public Root::Visitor, public Design::Visitor, public Library::Visitor,
34  public Cell::Visitor, public View::Visitor, public ScalarPort::Visitor,
46  public WaveValue::Visitor, public Timing::Visitor, public Event::Visitor,
48  {
49  protected:
50  // friends
51  /// \brief The unit test class has access to our internals.
53  // typedefs
54  /// \brief Imported type name.
56  /// \brief Vector of port shared pointers.
57  typedef std::vector<PortSharedPtr> PortSharedPtrVector;
58  /// \brief Vector of port reference shared pointers.
59  typedef std::vector<PortReferenceSharedPtr> PortReferenceSharedPtrVector;
60  /// \brief Vector of net shared pointers.
61  typedef std::vector<NetSharedPtr> NetSharedPtrVector;
62  // members
63  /// \brief The root shared pointer.
65  /// \brief Generic netlist visitor.
67  /// \brief The output stream.
68  std::ostream& mOut;
69  /// \brief The tab character.
70  string mTab;
71  /// \brief The current property container name.
73  // functions
74  void visit(Root& inroot) throw (Error);
75  void visit(Design& inDesign) throw (Error);
76  void visit(Library& inLibrary) throw (Error);
77  void visit(Cell& inCell) throw (Error);
78  void visit(View& inView) throw (Error);
79  void visit(ScalarPort& inScalarPort) throw (Error);
80  void visit(VectorPort& inVectorPort) throw (Error);
81  void visit(VectorPortBit& inVectorPortBit) throw (Error);
82  void visit(PortBundle& inPortBundle) throw (Error);
83  void visit(ScalarNet& inScalarNet) throw (Error);
84  void visit(VectorNet& inVectorNet) throw (Error);
85  void visit(VectorNetBit& inVectorNetBit) throw (Error);
86  void visit(NetBundle& inNetBundle) throw (Error);
87  void visit(SingleInstance& inSingleInstance) throw (Error);
88  void visit(InstanceArray& inInstanceArray) throw (Error);
89  void visit(InstanceArrayMember& inInstanceArrayMember) throw (Error);
90  void visit(ScalarPortReference& inScalarPortRef) throw (Error);
91  void visit(VectorPortReference& inVectorPortRef) throw (Error);
92  void visit(VectorPortBitReference& inVectorPortBitRef) throw (Error);
93  void visit(PortBundleReference& inPortBundleRef) throw (Error);
94  void visit(SingleParameter& inSingleParameter) throw (Error);
95  void visit(ParameterArray& inParameterArray) throw (Error);
96  void visit(ParameterArrayElement& inParameterArrayElement) throw (Error);
97  void visit(Property& inProperty) throw (Error);
98  void visit(PortList& inPortList) throw (Error);
99  void visit(PortListAlias& inPortListAlias) throw (Error);
100  void visit(Status& inStatus) throw (Error);
101  void visit(Permutable& inPermutable) throw (Error);
102  void visit(InterfaceJoinedInfo& inInterfaceJoinedInfo) throw (Error);
103  void visit(SimulationInfo& inSimulationInfo) throw (Error);
104  void visit(Simulate& inSimulate) throw (Error);
105  void visit(Apply& inApply) throw (Error);
106  void visit(LogicalResponse& inLogicalResponse) throw (Error);
107  void visit(LogicValue& inLogicValue) throw (Error);
108  void visit(LogicElement& inLogicElement) throw (Error);
109  void visit(WaveValue& inWaveValue) throw (Error);
110  void visit(Timing& inTiming) throw (Error);
111  void visit(Event& inEvent) throw (Error);
112  void visit(ForbiddenEvent& inForbiddenEvent) throw (Error);
113  /// \brief Return the original or renamed name of the given netlist object.
114  /// \param inNameable A Nameable or Renamable object to obtain the name of.
115  string getName(Nameable& inNameable) {
116  string name;
117  try {
118  // try to obtain the original name, if appropriate and available
119  Renamable& renamable = dynamic_cast<Renamable&>(inNameable);
120  name = renamable.getOriginalName();
121  // if we found an original name, we're done
122  if(name.length()) return name;
123  } catch(std::bad_cast bc) {
124  /* don't need to do anything here */
125  }
126  // return the object name
127  return inNameable.getName();
128  }
129  /// \brief Return a string indicating the direction of a port.
130  /// \param inPort The port of interest.
131  /// \return "input", "output", or "inout".
132  string getDirection(Port& inPort) {
133  switch(inPort.getDirection()) {
134  case ePortDirectionIn: return "input";
135  case ePortDirectionOut: return "output";
136  case ePortDirectionInOut: return "inout";
137  default: break;
138  }
139  /// \todo Throw an exception.
140  return "";
141  }
142  /// \brief Return a string describing the range of a vector port. The range is expressed
143  /// in the form "[start:end]".
144  /// \param inVectorPort The vector port of interest.
145  string getRange(VectorPort& inVectorPort);
146  public:
147  // constructors
148  /// \brief Public constructor.
149  VerilogExporterVisitor(RootSharedPtr inRootPtr, std::ostream& inStream = std::cout)
150  : mRootPtr(inRootPtr), mVisitor(*this), mOut(inStream), mTab("\t"),
152  /// \brief Virtual destructor.
153  virtual ~VerilogExporterVisitor(void) throw() {}
154  };
155 
156 } // namespace generic
157 } // namespace torc
158 
159 #endif // TORC_GENERIC_VERILOG_VERILOGEXPORTERVISITOR_HPP
An acyclic inoutVisitor implementation.
Definition: VisitorType.hpp:57
Represents an EDIF cell.
Definition: Cell.hpp:55
Represents a bit of a net array.
Represents areference to a standalone port.
Represents a reference to a port array.
string mPropertyContainerName
The current property container name.
const EPortDirection getDirection() const
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
string getDirection(Port &inPort)
Return a string indicating the direction of a port.
VerilogExporterVisitor(RootSharedPtr inRootPtr, std::ostream &inStream=std::cout)
Public constructor.
std::ostream & mOut
The output stream.
Represents and EDIF View.
Definition: View.hpp:61
Represents a bit of a port.
Represents a member of an instance array.
An EDIF cell library.
Definition: Library.hpp:60
Permutable is used to describe a relationship in which ports are interchangeable. ...
Definition: Permutable.hpp:40
void visit(Root &inroot)
Visit the top-level netlist.
string getName(Nameable &inNameable)
Return the original or renamed name of the given netlist object.
Represents a single instance of the view of a cell.
This class is used to hold all information about the logic values used within a library.
This class is used within simulationInfo construct to define a logic value to use for modeling in the...
Definition: LogicValue.hpp:42
RootSharedPtr mRootPtr
The root shared pointer.
std::string string
Imported type name.
std::string string
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
Represents a port array.
Definition: VectorPort.hpp:45
Represents a parameter array.
Represents a net array.
Definition: VectorNet.hpp:42
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
virtual ~VerilogExporterVisitor(void)
Virtual destructor.
Represents an array of instances.
Represents a standalone net.
Definition: ScalarNet.hpp:42
std::vector< PortSharedPtr > PortSharedPtrVector
Vector of port shared pointers.
ForbiddenEvent class lists events which are forbidden during a period of times which is specified by ...
Represents different logic elements which holds array of logic values.
Represents an ordered list of port references with a name aliased.
Represents a reference to a bit of a port.
Represents an ordered list of port references.
Definition: PortList.hpp:43
Generic netlist object visitor for output as structural Verilog.
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...
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
Interface for an EDIF port object.
virtual const std::string getName() const
Definition: Nameable.hpp:89
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
An object that has a name.
Definition: Nameable.hpp:34
std::vector< NetSharedPtr > NetSharedPtrVector
Vector of net shared pointers.
Represents objects that can be renamed.
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.
VisitorApplier< VerilogExporterVisitor > mVisitor
Generic netlist visitor.
boost::shared_ptr< Root > RootSharedPtr
friend class torc::generic::generic::VerilogExporterUnitTest
The unit test class has access to our internals.
string getRange(VectorPort &inVectorPort)
Return a string describing the range of a vector port. The range is expressed in the form "[start:end...
virtual Name getOriginalName() const
std::vector< PortReferenceSharedPtr > PortReferenceSharedPtrVector
Vector of port reference shared pointers.