CompileDES  3.13
Executable-Code Generation from Synchronised libFAUDES Automata
cgp_iec61131st.h
Go to the documentation of this file.
1 
3 /*
4  FAU Discrete Event Systems Library (libFAUDES)
5 
6  Copyright (C) 2010, 2016, 2017 Thomas Moor
7 
8 */
9 
10 
11 
12 #ifndef FAUDES_IEC61131stCode_H
13 #define FAUDES_IEC61131stCode_H
14 
15 #include "libfaudes.h"
16 #include "cgp_codeprimitives.h"
17 
18 using namespace faudes;
19 
20 
21 
119 
120 public:
121 
122  /*****************************************
123  *****************************************
124  *****************************************
125  *****************************************/
126  enum IECVariableType { LOCAL, TEMP, INPUT, OUTPUT, INOUT, EXTERNAL, GLOBAL, ACCESS, NONE };
127 
128 
136 
140  virtual ~Iec61131stCodeGenerator(void);
141 
142 
147  virtual void Clear(void);
148 
149 
152 protected:
153 
155  std::string mIecDeclarePhysical;
156 
159 
161  std::string mLiteralCyclic;
162 
164  void DoCompile(void);
165 
167  void DoGenerate(void);
168 
170  virtual void DoGenerateFunction(void);
171 
173  virtual void DoGenerateLookups(void);
174 
176  virtual void DecrementTimers(void);
177 
179  void BeginCyclicCode(void);
180 
182  void EndCyclicCode(void);
183 
185  virtual std::string TargetAddress(const AA& address);
186 
188  virtual AX TargetExpression(const AA& address);
189 
190 
196  /* re-implement primitives */
197  virtual void Comment(const std::string& text);
198 
199  /* re-implement primitives */
200  virtual void VariableDeclare(const std::string& laddr, const std::string& ltype);
201  virtual void VariableDeclare(const std::string& laddr, const std::string& ltype, const std::string& lval);
202 
203  /* re-implement primitives */
204  virtual void IntegerDeclare(const AA& address);
205  virtual void IntegerDeclare(const AA& address, int val);
206  virtual void IntegerAssign(const AA& address, int val);
207  virtual void IntegerAssign(const AA& address, const AX& expression);
208  virtual void IntegerIncrement(const AA& address, int val);
209  virtual AX IntegerQuotient(const AX& expression, int val);
210  virtual AX IntegerRemainder(const AX& expression, int val);
211  virtual AX IntegerBitmask(const AX& expression);
212  virtual AX IntegerIsEq(const AA& address, int val);
213  virtual AX IntegerIsEq(const AA& address, const AX& expression);
214  virtual AX IntegerIsNotEq(const AA& address, int val);
215  virtual AX IntegerIsNotEq(const AA& address, const AX& expression);
216  virtual AX IntegerIsGreater(const AA& address, int val);
217  virtual AX IntegerIsLess(const AA& address, int val);
218  virtual AX IntegerConstant(int val);
219 
220  /* re-implement primitives */
221  virtual bool HasIntmaths(void);
222  virtual void WordDeclare(const AA& address);
223  virtual void WordDeclare(const AA& address, word_t val);
224  virtual void WordAssign(const AA& address, word_t val);
225  virtual void WordAssign(const AA& address, const AX& expression);
226  virtual void WordOr(const AA& address, word_t val);
227  virtual void WordOr(const AA& address, const AX& expression);
228  virtual void WordOr(const AA& address, const AA& op1, const AA& op2);
229  virtual void WordOr(const AA& address, const AA& op1, word_t op2);
230  virtual void WordAnd(const AA& address, word_t val);
231  virtual void WordAnd(const AA& address, const AX& expression);
232  virtual void WordAnd(const AA& address, const AA& op1, const AA& op2);
233  virtual void WordAnd(const AA& address, const AA& op1, word_t op2);
234  virtual void WordNand(const AA& address, const AX& expression);
235  virtual AX WordIsBitSet(const AA& address, int idx);
236  virtual AX WordIsBitClr(const AA& address, int idx);
237  virtual AX WordIsMaskSet(const AA& address, word_t mask);
238  virtual AX WordIsEq(const AA& address, word_t val);
239  virtual AX WordIsNotEq(const AA& address, word_t val);
240  virtual AX WordConstant(word_t val);
241 
242  /* re-implement primitives */
243  virtual void BooleanDeclare(const AA& address);
244  virtual void BooleanDeclare(const AA& address, int val);
245  virtual void BooleanAssign(const AA& address, int val);
246  virtual void BooleanAssign(const AA& address, const AX& expression);
247  virtual AX BooleanIsEq(const AA& op1, const AA& op2);
248  virtual AX BooleanIsNotEq(const AA& op1, const AA& op2);
249 
250  /* re-implement primitives */
251  virtual void CintarrayDeclare(const AA& address, int offset, const std::vector<int>& val);
252  virtual AA CintarrayAccess(const AA& address, int index);
253  virtual AA CintarrayAccess(const AA& address, const AA& indexaddr);
254  virtual bool HasCintarray(void);
255  virtual void CwordarrayDeclare(const AA& address, int offset, const std::vector<word_t>& val);
256  virtual AA CwordarrayAccess(const AA& address, int index);
257  virtual AA CwordarrayAccess(const AA& address, const AA& indexaddr);
258  virtual bool HasCwordarray(void);
259  virtual void CstrarrayDeclare(const AA& address, int offset, const std::vector<std::string>& val);
260  virtual AA CstrarrayAccess(const AA& address, int index);
261  virtual AA CstrarrayAccess(const AA& address, const AA& indexaddr);
262  virtual bool HasCstrarray(void);
263  virtual void IntarrayDeclare(const AA& address, int offset, int len);
264  virtual void IntarrayDeclare(const AA& address, int offset, const std::vector<int>& val);
265  virtual AA IntarrayAccess(const AA& address, int index);
266  virtual AA IntarrayAccess(const AA& address, const AA& indexaddr);
267  virtual bool HasIntarray(void);
268  virtual void WordarrayDeclare(const AA& address, int offset, int len);
269  virtual void WordarrayDeclare(const AA& address, int offset, const std::vector<word_t>& val);
270  virtual AA WordarrayAccess(const AA& address, int index);
271  virtual AA WordarrayAccess(const AA& address, const AA& indexaddr);
272  virtual bool HasWordarray(void);
273 
274 
275  /* re-implement primitives */
276  virtual void IfTrue(const AX& expression);
277  virtual void IfFalse(const AX& expression);
278  virtual void IfWord(const AX& expression);
279  virtual void IfElse(void);
280  virtual void IfElseIfTrue(const AX& expression);
281  virtual void IfEnd(void);
282 
283  /* re-implement primitives */
284  virtual void SwitchBegin(const AA& address);
285  virtual void SwitchCase(const AA& address, int val);
286  virtual void SwitchCases(const AA& address, int from, int to);
287  virtual void SwitchCases(const AA& address, const std::set< int >& vals);
288  virtual void SwitchBreak(void);
289  virtual void SwitchEnd(void);
290  virtual bool HasMultiCase(void);
291 
292  /* re-implement primitives */
293  virtual void LoopBegin(void);
294  virtual void LoopBreak(const AX& expression);
295  virtual void LoopEnd(void);
296  virtual void FunctionReturn(void);
297 
298 
299  /* re-implement primitives */
300  virtual void RunActionSet(const std::string& address);
301  virtual void RunActionClr(const std::string& address);
302  virtual void RunActionExe(const AX& expression);
303 
304  /* re-implement primitives */
305  virtual void TimerDeclare(const AA& address, const std::string& val);
306  virtual void TimerStart(const AA& address);
307  virtual void TimerStop(const AA& address);
308  virtual void TimerReset(const AA& address, const std::string& val);
309  virtual AX TimerIsElapsed(const AA& address);
310 
311  /* re-implement primitives */
312  virtual void DeclareTimers(void);
313  virtual void ResetState(void);
314 
315 
316  /* code generator primitives, iec-specific helper */
317  virtual AX TimeConstant(int val);
318  virtual AX IntarrayConstant(const std::vector<int>& val);
319  virtual AX WordarrayConstant(const std::vector<word_t>& val);
320  virtual AX StringConstant(const std::string& val);
321  virtual AX StrarrayConstant(const std::vector<std::string>& val);
322 
323  virtual void DeclareImportPhysicalIo(void);
324  virtual void DeclareImportSymbolicIo(void);
325  virtual int CountImportPhysicalIo(void);
326  virtual int CountImportSymbolicIo(void);
327  virtual void LiteralCyclic(void);
328  virtual void DeclareSystime(void);
329  virtual void UpdateSystime(void);
330  virtual void InsertExecHooks(void);
331 
332 
333 
349  virtual void DoReadTargetConfiguration(TokenReader& rTr);
350 
362  virtual void DoWriteTargetConfiguration(TokenWriter& rTw) const;
363 
364  void CurrentVariableType(const IECVariableType& type);
365  IECVariableType CurrentVariableType(void);
366 
367 private:
368  IECVariableType mCurrentVariableType;
369  bool mDeclareIOVars;
370 
371 };
372 
373 
374 #endif
Code-generator with abstract types and operations.
unsigned long word_t
Code-generator internal data type of target words.
Abstract address; see also Absstract_Addresses.
Abstract expression; see also Absstract_Addresses.
Execution semantics in terms of code primitives.
Implementation of primitives by IEC 61131 ST.
void EndCyclicCode(void)
reimplemented code snippets
void BeginCyclicCode(void)
reimplemented code snippets
std::string mLiteralCyclic
option: extra cyclic code
bool mHasIecTimeOperators
option: overloaded operators for time maths
std::string mIecDeclarePhysical
option: formal declaration of io lines