ChartToVHDL.h
Go to the documentation of this file.
1 
20 #ifndef CHARTOVHDL_H
21 #define CHARTOVHDL_H
22 
23 #include "uscxml/util/DOM.h"
24 #include "uscxml/transform/Trie.h"
25 #include "Transformer.h"
26 #include "ChartToC.h"
27 
28 #include <xercesc/dom/DOM.hpp>
29 #include <ostream>
30 #include <vector>
31 
32 namespace uscxml {
33 
34 class USCXML_API ChartToVHDL : public ChartToC {
35 public:
36 
37  virtual ~ChartToVHDL();
38 
39  static Transformer transform(const Interpreter &other);
40 
41  void writeTo(std::ostream &stream);
42 
43 
44  struct VNode {
45  virtual void print(std::ostream &stream, const std::string padding = "") = 0;
46 
47  virtual ~VNode() { };
48  };
49 
50  struct VBranch : VNode {
51  std::vector<VNode *> v;
52 
53  virtual ~VBranch() {
54  for (unsigned i = 0; i < v.size(); i++)
55  delete v[i];
56  }
57 
58  VBranch &operator+=(VNode *p) {
59  v.push_back(p);
60  return *this;
61  }
62  };
63 
64  struct VPointer {
65  VNode *ptr;
66 
67  operator VNode *() {
68  return ptr;
69  }
70 
71  operator VBranch *() {
72  return static_cast<VBranch *> (ptr);
73  }
74 
75  VPointer &operator/(VNode *p) {
76  ptr = p;
77  return *this;
78  }
79  };
80 
81  struct VContainer {
82  VBranch *ptr;
83 
84  operator VBranch *() {
85  return ptr;
86  }
87 
88  VContainer &operator/(VBranch *p) {
89  ptr = p;
90  return *this;
91  }
92 
93  VContainer &operator,(VPointer p) {
94  if (ptr) ptr->v.push_back(p.ptr);
95  return *this;
96  }
97 
98  VContainer &operator,(VContainer c) {
99  if (ptr) ptr->v.push_back(c.ptr);
100  return *this;
101  }
102  };
103 
104  struct VLine : VNode {
105  VLine(const std::string &name) : name(name) { }
106 
107  virtual void print(std::ostream &stream, const std::string padding = "") {
108  stream << " " << name;
109  }
110 
111  std::string name;
112  };
113 
114  struct VAssign : VBranch {
115  virtual void print(std::ostream &stream, const std::string padding = "") {
116  v[0]->print(stream, padding);
117  stream << padding << " <=";
118  v[1]->print(stream, padding + " ");
119  }
120  };
121 
122  struct VAnd : VBranch {
123  virtual void print(std::ostream &stream, const std::string padding = "") {
124  stream << std::endl << padding << "( '1' ";
125  for (unsigned i = 0; i < v.size(); i++) {
126  stream << std::endl << padding << " and";
127  v[i]->print(stream, padding + " ");
128  }
129  stream << padding << ")" << std::endl;
130  }
131  };
132 
133  struct VOr : VBranch {
134  virtual void print(std::ostream &stream, const std::string padding = "") {
135  stream << std::endl << padding << "( '0' ";
136  for (unsigned i = 0; i < v.size(); i++) {
137  stream << std::endl << padding << " or";
138  v[i]->print(stream, padding + " ");
139  }
140  stream << std::endl << padding << ")" << std::endl;
141  }
142  };
143 
144  struct VNot : VBranch {
145  virtual void print(std::ostream &stream, const std::string padding = "") {
146  stream << " ( not";
147  v[0]->print(stream, padding + " ");
148  stream << " )";
149  }
150  };
151 
152  struct VNop : VBranch {
153  virtual void print(std::ostream &stream, const std::string padding = "") {
154  v[0]->print(stream, padding);
155  }
156  };
157 
158 //TODO can we create the macros without IDE errors ?!
159 #define VLINE VPointer()/new VLine
160 #define VASSIGN VContainer()/new VAssign
161 #define VOR VContainer()/new VOr
162 #define VAND VContainer()/new VAnd
163 #define VNOT VContainer()/new VNot
164 #define VNOP VContainer()/new VNop
165 
166 
167 protected:
168  ChartToVHDL(const Interpreter &other);
169 
170  void findEvents();
171 
172 
173  void writeIncludes(std::ostream &stream);
174 
175  // top layer components
176  void writeFiFo(std::ostream &stream);
177 
178  void writeEventController(std::ostream &stream);
179 
180  void writeConditionSolver(std::ostream &stream);
181 
182  void writeMicroStepper(std::ostream &stream);
183 
184  void writeTestbench(std::ostream &stream);
185 
186  void writeTopLevel(std::ostream &stream);
187 
188  // system
189  void writeSignalsAndComponents(std::ostream &stream);
190 
191  void writeSystemSignalMapping(std::ostream &stream);
192 
193  void writeModuleInstantiation(std::ostream &stream);
194 
195  // combinatorial logic
196  void writeOptimalTransitionSetSelection(std::ostream &stream);
197 
198  void writeExitSet(std::ostream &stream);
199 
200  void writeEntrySet(std::ostream &stream);
201 
202  void writeCompleteEntrySet(std::ostream &stream);
203 
204  void writeActiveStateNplusOne(std::ostream &stream);
205 
206  // handler
207  void writeStateHandler(std::ostream &stream);
208 
209  void writeResetHandler(std::ostream &stream);
210 
211  void writeSpontaneousHandler(std::ostream &stream);
212 
213  void writeInternalEventHandler(std::ostream &stream);
214 
215  void writeErrorHandler(std::ostream &stream);
216 
217 
218  Trie _eventTrie;
219  std::list<TrieNode *> _eventNames;
220  size_t _eventBitSize = 0;
221  std::map<std::string, std::string> _eventsOnBus;
222  std::list<XERCESC_NS::DOMElement *> _execContent;
223 
224 private:
225  std::string getLineForExecContent(const XERCESC_NS::DOMNode *elem);
226 
227  bool isSupportedExecContent(XERCESC_NS::DOMElement *execContentElement);
228 };
229 
230 }
231 
232 #endif /* end of include guard: FSMTOCPP_H_201672B0 */
Definition: ChartToVHDL.h:104
Definition: ChartToVHDL.h:44
Definition: Breakpoint.cpp:26
Definition: ChartToVHDL.h:114
Definition: ChartToVHDL.h:133
Central class to interpret and process SCXML documents.
Definition: Interpreter.h:79
Definition: ChartToVHDL.h:81
Definition: ChartToVHDL.h:122
Definition: ChartToVHDL.h:34
Definition: ChartToVHDL.h:64
Definition: ChartToVHDL.h:152
Definition: ChartToC.h:33
Definition: Trie.h:42
Definition: ChartToVHDL.h:50
Definition: ChartToVHDL.h:144
Definition: Transformer.h:67