CompileDES  3.13
Executable-Code Generation from Synchronised libFAUDES Automata

Implementation of primitives by IEC 61131 ST. More...

#include <cgp_iec61131st.h>

Inheritance diagram for Iec61131stCodeGenerator:
Inheritance graph

Public Types

enum  IECVariableType {
  LOCAL , TEMP , INPUT , OUTPUT ,
  INOUT , EXTERNAL , GLOBAL , ACCESS ,
  NONE
}
 
- Public Types inherited from CodeGenerator
enum  OutSink { CONSOLE , FILE , STRING }
 
typedef std::vector< TimedGenerator >::const_iterator Iterator
 Iterator for read-only access of generators.
 
typedef unsigned long word_t
 Code-generator internal data type of target words.
 
typedef std::map< std::string, LineAddress >::iterator LineIterator
 Access to line records by iterator.
 
typedef std::map< std::string, FlagExpression >::iterator FlagIterator
 Access to flag records by iterator.
 
typedef std::map< std::string, TimerConfiguration >::iterator TimerIterator
 Access to timer records by iterator.
 
typedef std::map< std::string, ActionAddress >::iterator ActionAddressIterator
 Access to action record by iterator.
 
typedef std::map< std::string, TimerAction >::iterator TimerActionIterator
 Access to timer records by iterator.
 

Protected Member Functions

void DoCompile (void)
 add my preferences to DoCompile
 
void DoGenerate (void)
 code generation hook (overall)
 
virtual void DoGenerateFunction (void)
 code generation hook (function block)
 
virtual void DoGenerateLookups (void)
 code generation hook (lookup functions)
 
virtual void DecrementTimers (void)
 code snippet
 
void BeginCyclicCode (void)
 reimplemented code snippets
 
void EndCyclicCode (void)
 reimplemented code snippets
 
virtual std::string TargetAddress (const AA &address)
 abstract address conversion
 
virtual AX TargetExpression (const AA &address)
 abstract address conversion
 
virtual void DoReadTargetConfiguration (TokenReader &rTr)
 File i/o. More...
 
virtual void DoWriteTargetConfiguration (TokenWriter &rTw) const
 File i/o. More...
 
void CurrentVariableType (const IECVariableType &type)
 
IECVariableType CurrentVariableType (void)
 
- Protected Member Functions inherited from CodePrimitives
virtual void DoGenerateDeclarations (void)
 cut-and-paste template for code snippet assembly

 
virtual void DoGenerateResetCode (void)
 cut-and-paste template for code snippet assembly

 
virtual void DoGenerateCyclicCode (void)
 cut-and-paste template for code snippet assembly

 
virtual void LiteralPrepend (void)
 Cosmetic: prepend literally from configuration data.
 
virtual void DeclareStatus (void)
 Declare "status".
 
virtual void DeclareReset (void)
 Declare "reset".
 
virtual void DeclareRecentEvent (void)
 Declare "recent_event".
 
virtual void DeclareParallelState (void)
 Declare "parallel_state".
 
virtual void DeclarePendingEvents (void)
 Declare "pending_events" and "enabled_events".
 
virtual void DeclareLoopState (void)
 Declare loop state, i.e. line levels, loop flag.
 
virtual void DeclareAux (void)
 Declare variables local to the provided snippets, e.g. helpers for bit-mask computation.
 
virtual void DeclareLargeCarray (void)
 Declare compiled transition relations.
 
virtual void DeclareSmallCarray (void)
 Declare bit-mask loop-ups.
 
virtual void DeclareEventNameLookup (void)
 Declare symbolic name lookup tables.
 
virtual void DeclareStateNameLookup (void)
 Declare symbolic name lookup tables.
 
virtual void ResetReturn (void)
 Reset bail out.
 
virtual void SenseInputs (void)
 Sense input events and add to "pending_events".
 
virtual void SenseTimerElapse (void)
 Sense timer elapse vents and add to "pending_events".
 
virtual void BeginExecutionLoop (void)
 Execution Loop, begin.
 
virtual void UpdateEnabled (void)
 Update "enabled_events" from "parallel_state" if "exec_event" was set.
 
virtual void ScheduleEvent (void)
 Select event to execute from "pending_and_enabled_events" or "enabled_events".
 
virtual void BreakExecutionLoop (void)
 Execution Loop, break.
 
virtual void ExecuteEvent (void)
 Take transition and figure new state.
 
virtual void OperateTimers (void)
 Start/stop/reset timers w.r.t. "exec_event".
 
virtual void OperateOutputs (void)
 Operate output lines w.r.t. "exec_event".
 
virtual void EndExecutionLoop (void)
 Loop end.
 
virtual void LiteralAppend (void)
 Cosmetic: append literally from configuration.
 
virtual void ExecuteEventBySwitching (void)
 Alternative implementation of ExecuteEvent()
 
virtual void ExecuteEventByInterpreter (void)
 Alternative implementation of ExecuteEventBy()
 
virtual void UpdateEnabledBySwitching (void)
 Alternative implementations UpdateEnabled()
 
virtual void UpdateEnabledByInterpreter (void)
 Alternative implementations UpdateEnabled()
 
virtual std::string TargetSymbol (const std::string &str)
 Mangle string to valid target symbol.
 
virtual void IntegerDecrement (const AA &address, int val=1)
 
virtual void BitarrayDeclare (const AA &address, int blen)
 
virtual void BitarrayDeclare (const AA &address, const std::vector< bool > &val)
 
virtual void BitarrayAssign (const AA &address, const std::vector< bool > &val)
 
virtual void BitarrayAssign (const AA &address, const AA &otherarray)
 
virtual void BitarrayClear (const AA &address)
 
virtual void BitarrayFull (const AA &address)
 
virtual void BitarraySetBit (const AA &address, int bitaddr)
 
virtual void BitarraySetBit (const AA &address, const AA &indexaddr, int offset=0, const std::vector< bool > &hint=std::vector< bool >())
 
virtual void BitarrayClrBit (const AA &address, int bitaddr)
 
virtual void BitarrayClrBit (const AA &address, const AA &indexaddr, int offset=0, const std::vector< bool > &hint=std::vector< bool >())
 
virtual void BitarrayIsBitSet (const AA &address, const AA &indexaddr, const AA &result, int offset=0, const std::vector< bool > &hint=std::vector< bool >())
 
virtual void BitarrayOr (const AA &address, const std::vector< bool > &val)
 
virtual void BitarrayOr (const AA &address, const AA &op1, const std::vector< bool > &op2)
 
virtual void BitarrayOrAllWords (const AA &address, const AA &result)
 
virtual void BitarrayAnd (const AA &address, const std::vector< bool > &val)
 
virtual void BitarrayAnd (const AA &address, const AA &otherarray)
 
virtual void BitarrayAnd (const AA &address, const AA &op1, const AA &op2)
 
virtual void BitarrayAnd (const AA &address, const AA &op1, const std::vector< bool > &op2)
 
virtual void BitarrayFindFirst (const AA &address, const AA &result, int offset=0)
 
virtual void EventSetDeclare (const AA &address)
 
virtual void EventSetDeclare (const AA &address, const EventSet &evset)
 
virtual void EventSetAssign (const AA &address, const EventSet &evset)
 
virtual void EventSetInsert (const AA &address, const EventSet &evset)
 
virtual void EventSetInsert (const AA &address, Idx ev)
 
virtual void EventSetInsert (const AA &address, const AA &evaddr)
 
virtual void EventSetInsert (const AA &address, const AA &evaddr, const EventSet &hint)
 
virtual void EventSetErase (const AA &address, const EventSet &evset)
 
virtual void EventSetErase (const AA &address, Idx ev)
 
virtual void EventSetErase (const AA &address, const AA &evaddr)
 
virtual void EventSetErase (const AA &address, const AA &evaddr, const EventSet &hint)
 
virtual void EventSetExists (const AA &address, const AA &evaddr, const AA &result, const EventSet &hint)
 
virtual void EventSetRestrict (const AA &address, const AA &otherset)
 
virtual void EventSetUnion (const AA &address, const AA &op1, const EventSet &op2)
 
virtual void EventSetIntersection (const AA &address, const AA &op1, const EventSet &op2)
 
virtual void EventSetClear (const AA &address)
 
virtual void EventSetFull (const AA &address)
 
virtual void EventSetIsNotEmpty (const AA &address, const AA &result)
 
virtual void EventSetFindHighestPriority (const AA &address, const AA &result)
 
virtual AX ReadInputLine (const std::string &address)
 
virtual AX InputExpression (const std::string &expression)
 
virtual int StateTargetIdx (size_t git, Idx idx)
 Overload base class to use the vector address only if the respective code option is active)
 
virtual Idx StateFaudesIdx (size_t git, int idx)
 Overload base class to use the vector address only if the respective code option is active)
 
- Protected Member Functions inherited from CodeGenerator
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Read the configuration from TokenReader, see faudes Type for public wrappers. More...
 
virtual void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Writes the configuration to TokenWriter, see faudes Type for public wrappers. More...
 

Protected Attributes

std::string mIecDeclarePhysical
 option: formal declaration of io lines
 
bool mHasIecTimeOperators
 option: overloaded operators for time maths
 
std::string mLiteralCyclic
 option: extra cyclic code
 
- Protected Attributes inherited from CodePrimitives
std::string mWordType
 target data type for word

 
std::string mIntegerType
 target data type for integer

 
std::string mPrefix
 universal prefix (pseudo name space)
 
bool mArrayForTransitions
 code option: use const array to represent transitions
 
bool mMaintainStateIndices
 code option: use state indices as provided
 
bool mBitAddressArithmetic
 code option: compute bit and word address on target
 
bool mArrayForBitmasks
 code option: use const array to represent bit-masks
 
bool mArrayForBitarray
 code option: use const array to represent bit-masks
 
bool mBisectionForBitfind
 code option: use bisection to fing lowest set bit
 
bool mArrayForState
 code option: use int arrays to represent that overall state
 
bool mEventsetsForPerformance
 code option: eventsets for performance
 
bool mLoopPendingInputs
 code option: loop until all inputs are resolved
 
bool mLoopEnabledOutputs
 code option: loop until all enabled outputs are executed
 
bool mStrictEventSynchronisation
 code option: strict event synchronisation
 
bool mEventNameLookup
 code option: event name lookup
 
bool mStateNameLookup
 code option: state name lookup
 
std::vector< bool > mHasStateNames
 record per generator whether there is a lookup table
 
bool mExistStateNames
 record whether there exist statenames at all
 
std::string mEventExecutionHook
 code option: event exec hook
 
std::string mStateUpdateHook
 code option: state change hook
 
std::string mLiteralPrepend
 extra code to prepend
 
std::string mLiteralAppend
 extra code to prepend
 
std::map< std::string, bitarray_recmBitarrays
 Record of all declared bit-arrays.
 
- Protected Attributes inherited from CodeGenerator
std::string mName
 faudes object name (aka project name)
 
std::vector< TimedGenerator > mGenerators
 list of executors
 
std::vector< std::string > mGeneratorNames
 list of filenames when generator are read from file
 
cgEventSet mAlphabet
 event configuration by attributes
 
int mWordSize
 compressed boolean capacity of target type word
 
int mIntegerSize
 compressed boolean capacity of target type integer
 
std::map< Idx, int > mEventBitAddress
 mapping from faudes event idx to bit address (descending priority, range 0 . More...
 
std::map< int, Idx > mEventFaudesIdx
 mapping from bit address to faudes event idx

 
int mLastInputEvent
 highest bit-address with input (or timer) event (-1 for none)
 
int mLastOutputEvent
 highest bit-address with output event (-1 for none)
 
std::vector< std::map< Idx, int > > mStateVectorAddress
 mapping from faudes state idx to vector index
 
std::vector< std::map< int, Idx > > mStateFaudesIndex
 mapping from vector state idx to faudes index
 
std::vector< bool > mUsingVectorAddressStates
 configuration of state indexing per generator
 
std::vector< std::vector< int > > mTransitionVector
 compiled transition-sets, represented as vectors of integers with 0 as separator
 
EventSet mUsedEvents
 configured events that are referred to by some generator
 
EventSet mOutputEvents
 used events that are configured as outputs
 
EventSet mInputEvents
 used events that are configured as inputs (incl timer)
 
EventSet mInternalEvents
 used events that are configured as internal events (excl. More...
 
std::map< std::string, LineAddressmLines
 input event generation
 
std::map< std::string, FlagExpressionmFlags
 input event generation
 
std::map< std::string, TimerConfigurationmTimers
 timer definitions
 
std::map< std::string, ActionAddressmActionAddresses
 action addresses
 
std::map< std::string, TimerActionmTimerActions
 timer actions by event name
 
int mVerbLevel
 diagnpstic-output level

 
std::string mOutMode
 output file name (base)
 
char mMuteMode
 current output mode
 
bool mMuteComments
 mute comments
 
std::string mRecentMutedComment
 recent muted comment

 
std::ostream * pOutStream
 output stream
 
std::ostream * pErrStream
 error stream
 

Basic Class Maintenance

 Iec61131stCodeGenerator (void)
 Constructor.
 
virtual ~Iec61131stCodeGenerator (void)
 Explicit destructor.
 
virtual void Clear (void)
 Clear all data.
 

Implement Primitives

virtual void Comment (const std::string &text)
 generate code: conditionals
 
virtual void VariableDeclare (const std::string &laddr, const std::string &ltype)
 generate code: conditionals
 
virtual void VariableDeclare (const std::string &laddr, const std::string &ltype, const std::string &lval)
 generate code: conditionals
 
virtual void IntegerDeclare (const AA &address)
 generate code: conditionals
 
virtual void IntegerDeclare (const AA &address, int val)
 generate code: conditionals
 
virtual void IntegerAssign (const AA &address, int val)
 generate code: conditionals
 
virtual void IntegerAssign (const AA &address, const AX &expression)
 generate code: conditionals
 
virtual void IntegerIncrement (const AA &address, int val)
 generate code: conditionals
 
virtual AX IntegerQuotient (const AX &expression, int val)
 generate code: conditionals
 
virtual AX IntegerRemainder (const AX &expression, int val)
 generate code: conditionals
 
virtual AX IntegerBitmask (const AX &expression)
 generate code: conditionals
 
virtual AX IntegerIsEq (const AA &address, int val)
 generate code: conditionals
 
virtual AX IntegerIsEq (const AA &address, const AX &expression)
 generate code: conditionals
 
virtual AX IntegerIsNotEq (const AA &address, int val)
 generate code: conditionals
 
virtual AX IntegerIsNotEq (const AA &address, const AX &expression)
 generate code: conditionals
 
virtual AX IntegerIsGreater (const AA &address, int val)
 generate code: conditionals
 
virtual AX IntegerIsLess (const AA &address, int val)
 generate code: conditionals
 
virtual AX IntegerConstant (int val)
 generate code: conditionals
 
virtual bool HasIntmaths (void)
 generate code: conditionals
 
virtual void WordDeclare (const AA &address)
 generate code: conditionals
 
virtual void WordDeclare (const AA &address, word_t val)
 generate code: conditionals
 
virtual void WordAssign (const AA &address, word_t val)
 generate code: conditionals
 
virtual void WordAssign (const AA &address, const AX &expression)
 generate code: conditionals
 
virtual void WordOr (const AA &address, word_t val)
 generate code: conditionals
 
virtual void WordOr (const AA &address, const AX &expression)
 generate code: conditionals
 
virtual void WordOr (const AA &address, const AA &op1, const AA &op2)
 generate code: conditionals
 
virtual void WordOr (const AA &address, const AA &op1, word_t op2)
 generate code: conditionals
 
virtual void WordAnd (const AA &address, word_t val)
 generate code: conditionals
 
virtual void WordAnd (const AA &address, const AX &expression)
 generate code: conditionals
 
virtual void WordAnd (const AA &address, const AA &op1, const AA &op2)
 generate code: conditionals
 
virtual void WordAnd (const AA &address, const AA &op1, word_t op2)
 generate code: conditionals
 
virtual void WordNand (const AA &address, const AX &expression)
 generate code: conditionals
 
virtual AX WordIsBitSet (const AA &address, int idx)
 generate code: conditionals
 
virtual AX WordIsBitClr (const AA &address, int idx)
 generate code: conditionals
 
virtual AX WordIsMaskSet (const AA &address, word_t mask)
 generate code: conditionals
 
virtual AX WordIsEq (const AA &address, word_t val)
 generate code: conditionals
 
virtual AX WordIsNotEq (const AA &address, word_t val)
 generate code: conditionals
 
virtual AX WordConstant (word_t val)
 generate code: conditionals
 
virtual void BooleanDeclare (const AA &address)
 generate code: conditionals
 
virtual void BooleanDeclare (const AA &address, int val)
 generate code: conditionals
 
virtual void BooleanAssign (const AA &address, int val)
 generate code: conditionals
 
virtual void BooleanAssign (const AA &address, const AX &expression)
 generate code: conditionals
 
virtual AX BooleanIsEq (const AA &op1, const AA &op2)
 generate code: conditionals
 
virtual AX BooleanIsNotEq (const AA &op1, const AA &op2)
 generate code: conditionals
 
virtual void CintarrayDeclare (const AA &address, int offset, const std::vector< int > &val)
 generate code: conditionals
 
virtual AA CintarrayAccess (const AA &address, int index)
 generate code: conditionals
 
virtual AA CintarrayAccess (const AA &address, const AA &indexaddr)
 generate code: conditionals
 
virtual bool HasCintarray (void)
 generate code: conditionals
 
virtual void CwordarrayDeclare (const AA &address, int offset, const std::vector< word_t > &val)
 generate code: conditionals
 
virtual AA CwordarrayAccess (const AA &address, int index)
 generate code: conditionals
 
virtual AA CwordarrayAccess (const AA &address, const AA &indexaddr)
 generate code: conditionals
 
virtual bool HasCwordarray (void)
 generate code: conditionals
 
virtual void CstrarrayDeclare (const AA &address, int offset, const std::vector< std::string > &val)
 generate code: conditionals
 
virtual AA CstrarrayAccess (const AA &address, int index)
 generate code: conditionals
 
virtual AA CstrarrayAccess (const AA &address, const AA &indexaddr)
 generate code: conditionals
 
virtual bool HasCstrarray (void)
 generate code: conditionals
 
virtual void IntarrayDeclare (const AA &address, int offset, int len)
 generate code: conditionals
 
virtual void IntarrayDeclare (const AA &address, int offset, const std::vector< int > &val)
 generate code: conditionals
 
virtual AA IntarrayAccess (const AA &address, int index)
 generate code: conditionals
 
virtual AA IntarrayAccess (const AA &address, const AA &indexaddr)
 generate code: conditionals
 
virtual bool HasIntarray (void)
 generate code: conditionals
 
virtual void WordarrayDeclare (const AA &address, int offset, int len)
 generate code: conditionals
 
virtual void WordarrayDeclare (const AA &address, int offset, const std::vector< word_t > &val)
 generate code: conditionals
 
virtual AA WordarrayAccess (const AA &address, int index)
 generate code: conditionals
 
virtual AA WordarrayAccess (const AA &address, const AA &indexaddr)
 generate code: conditionals
 
virtual bool HasWordarray (void)
 generate code: conditionals
 
virtual void IfTrue (const AX &expression)
 generate code: conditionals
 
virtual void IfFalse (const AX &expression)
 generate code: conditionals
 
virtual void IfWord (const AX &expression)
 generate code: conditionals
 
virtual void IfElse (void)
 generate code: conditionals
 
virtual void IfElseIfTrue (const AX &expression)
 generate code: conditionals
 
virtual void IfEnd (void)
 generate code: conditionals
 
virtual void SwitchBegin (const AA &address)
 generate code: conditionals
 
virtual void SwitchCase (const AA &address, int val)
 generate code: conditionals
 
virtual void SwitchCases (const AA &address, int from, int to)
 generate code: conditionals
 
virtual void SwitchCases (const AA &address, const std::set< int > &vals)
 generate code: conditionals
 
virtual void SwitchBreak (void)
 generate code: conditionals
 
virtual void SwitchEnd (void)
 generate code: conditionals
 
virtual bool HasMultiCase (void)
 generate code: conditionals
 
virtual void LoopBegin (void)
 generate code: conditionals
 
virtual void LoopBreak (const AX &expression)
 generate code: conditionals
 
virtual void LoopEnd (void)
 generate code: conditionals
 
virtual void FunctionReturn (void)
 generate code: conditionals
 
virtual void RunActionSet (const std::string &address)
 generate code: conditionals
 
virtual void RunActionClr (const std::string &address)
 generate code: conditionals
 
virtual void RunActionExe (const AX &expression)
 generate code: conditionals
 
virtual void TimerDeclare (const AA &address, const std::string &val)
 generate code: conditionals
 
virtual void TimerStart (const AA &address)
 generate code: conditionals
 
virtual void TimerStop (const AA &address)
 generate code: conditionals
 
virtual void TimerReset (const AA &address, const std::string &val)
 generate code: conditionals
 
virtual AX TimerIsElapsed (const AA &address)
 generate code: conditionals
 
virtual void DeclareTimers (void)
 generate code: conditionals
 
virtual void ResetState (void)
 generate code: conditionals
 
virtual AX TimeConstant (int val)
 generate code: conditionals
 
virtual AX IntarrayConstant (const std::vector< int > &val)
 generate code: conditionals
 
virtual AX WordarrayConstant (const std::vector< word_t > &val)
 generate code: conditionals
 
virtual AX StringConstant (const std::string &val)
 generate code: conditionals
 
virtual AX StrarrayConstant (const std::vector< std::string > &val)
 generate code: conditionals
 
virtual void DeclareImportPhysicalIo (void)
 generate code: conditionals
 
virtual void DeclareImportSymbolicIo (void)
 generate code: conditionals
 
virtual int CountImportPhysicalIo (void)
 generate code: conditionals
 
virtual int CountImportSymbolicIo (void)
 generate code: conditionals
 
virtual void LiteralCyclic (void)
 generate code: conditionals
 
virtual void DeclareSystime (void)
 generate code: conditionals
 
virtual void UpdateSystime (void)
 generate code: conditionals
 
virtual void InsertExecHooks (void)
 generate code: conditionals
 

Additional Inherited Members

- Public Member Functions inherited from CodePrimitives
 CodePrimitives (void)
 Constructor.
 
virtual ~CodePrimitives (void)
 Explicit destructor.
 
- Public Member Functions inherited from CodeGenerator
Idx Size (void) const
 Number of generators.
 
void Insert (const std::string &file)
 Add a Generator from file. More...
 
void Insert (const TimedGenerator &rGen)
 Add a generator by reference. More...
 
const TimedGenerator & At (int i) const
 Direct access for read-only access of generators.
 
Iterator Begin (void) const
 Begin-iterator for read-only access of generators.
 
Iterator End (void) const
 End-iterator for read-only access of generators.
 
virtual int EventTargetIdx (Idx idx)
 Get target event Idx from faudes Idx (use bit-address + 1)
 
virtual int EventTargetIdx (const std::string &ev)
 Get target event Idx from faudes name (use bit-address + 1)
 
int EventBitAddress (Idx idx)
 Get event bit-address from faudes Idx (consecutive, starts at 0)
 
Idx EventFaudesIdx (int idx)
 Get faudes Idx from target Idx (aka from bit-address + 1)
 
std::vector< bool > EventBitMask (Idx idx)
 Get vector representation for a single faudes event Idx.
 
std::vector< bool > EventBitMask (const EventSet &eset)
 Get vector representation for faudes event set.
 
int EventBitMaskSize (void)
 Get overall number of events.
 
word_t WordFromBitVector (const std::vector< bool > &vect, int wordindex)
 Extract individual word from boolean vector.
 
std::vector< word_tWordVectorFromBitVector (const std::vector< bool > &vect)
 Convert boolean vector to word array.
 
LineIterator LinesBegin ()
 Access to line records by iterator.
 
LineIterator LinesEnd ()
 Access to line records by iterator.
 
FlagIterator FlagsBegin ()
 Access to flag records by iterator.
 
FlagIterator FlagsEnd ()
 Access to flag records by iterator.
 
TimerIterator TimersBegin ()
 Access to timer records by iterator.
 
TimerIterator TimersEnd ()
 Access to timer records by iterator.
 
ActionAddressIterator ActionAddressesBegin ()
 Access to action addresses by iterator.
 
ActionAddressIterator ActionAddressesEnd ()
 Access to action addresses by iterator.
 
TimerActionIterator TimerActionsBegin ()
 Access to timer records by iterator.
 
TimerActionIterator TimerActionsEnd ()
 Access to timer records by iterator.
 
 CodeGenerator (void)
 Constructor.
 
virtual ~CodeGenerator (void)
 Destructor.
 
virtual void Name (const std::string &rName)
 Set objects's name (reimplementing base faudes::Type) More...
 
virtual const std::string & Name (void) const
 Get objects's name (reimplementing base faudes::Type) More...
 
virtual void Compile (void)
 Compile input data for alternative representation. More...
 
Idx EventIndex (const std::string &rName) const
 Faudes-event index lookup. More...
 
std::string EventName (Idx index) const
 Faudes-event name lookup. More...
 
const AttributeCodeGeneratorEventEventAttribute (Idx ev) const
 Event configuration attribute lookup. More...
 
void EventAttribute (Idx ev, const AttributeCodeGeneratorEvent &attr)
 Set event attribute. More...
 
void Alphabet (const cgEventSet &rAlphabet)
 Set all event attributes. More...
 
const cgEventSetAlphabet (void) const
 Access alphabet (incl event attributes) More...
 
const std::vector< int > & TransitionVector (size_t git)
 Get target state index (refer to vector representation as default, overload in CodePrimitives)
 
virtual void Generate (void)
 Generate code. More...
 
void Verbose (int level, std::ostream *altout=0)
 Set verbosity level. More...
 
virtual void OutputMode (const std::string &mode)
 Set code output mode. More...
 
std::string OutputMode (void)
 Report code output mode. More...
 
virtual std::ostream & Output (void)
 Output stream. More...
 
const std::string & OutputString (void)
 Get accumulated output as string. More...
 
void OutputString (const std::string &strbuf)
 Set output to string. More...
 
virtual void MuteMode (char mode)
 Set current mute mode. More...
 
virtual void MuteCond (char mode)
 Set mode condition. More...
 
virtual void LineFeed (int lines=1)
 LineFeed (convenience support for derived classes)
 
virtual std::string LineCount (void)
 LineFeed (convenience support for derived classes)
 
virtual void IndentInc ()
 Indentation (convenience support for derived classes)
 
virtual void IndentDec ()
 Indentation (convenience support for derived classes)
 
std::string RecentComment (void)
 Recent muted comment (convenience support for derived classes)
 
virtual void XmlTextEscape (bool on)
 XmlTextEscape (escape "<", ">", "&", "\"" and "'")
 
virtual void XmlCdataEscape (bool on)
 XmlCdataEscape (escape "]]>")
 
virtual void MuteComments (bool on)
 Mute comments (convenience support for derived classes)
 
virtual void MuteVspace (bool on)
 Mute empty lines (convenience support for derived classes)
 
- Static Public Member Functions inherited from CodeGenerator
static std::string VersionString (void)
 Version (refers to macro COMPILEDES_VERSION, defined in cgp_codegenerator.h)
 
static void Register (const std::string &type, CodeGenerator *(*newcg)(void))
 Insert derived class in the registry. More...
 
static std::vector< std::string > Registry (void)
 Access registry contents. More...
 
static CodeGeneratorNew (const std::string &type)
 Instantiate by identifier (returns 0 on unknown class) More...
 
- Public Attributes inherited from CodeGenerator
std::vector< int > mWordAddressVector
 Look-up table to map a bit-address to the word-index.
 
std::vector< word_tmBitMaskVector
 Look-up table to map a bit-address to the word-bitmask.
 

Detailed Description

This class generates code for generic IEC 61131-3 Structured Text targets. Since ST is a high-level language and offers all relevant constructs natively, implementation of individual code primitives is straight forward.

The generated output consists of a single ASCII-encoded file, intended for cut-and-paste insertion into an IEC IDE. The derived class PlcoxmlCodeGenerator provides an alternative XML-encoded output.

Regarding top-level code organisation, Iec61131stCodeGenerator produces one IEC FUNCTION_BLOCK for cyclic invocation by the host application. It accepts the optional input RESET for manual reset and it provides the output variable STATUS with bit 0 for busy and bit 1 for event synchronisation error, respectively. Optionally, there are the additional output variables RECENT_EVENT and PARALLEL_STATE for diagnosis purposes.

The following additional code-options are supported.

IecIncludeCyclic. This option specifies additional code to be inserted just after the variable declarations of the cyclic function block. The intended use case is to instantiate function blocks used in execute actions. Note also the inherited options IncludeBefore and IecIncludeAfter if you want to add additional program organisation units, e.g., an IEC PROGRAM that invokes the cyclic function block.

   <IecIncludeCyclic>
   <![CDATA[
    [... insert code here ...]
   ]]>
   </IecIncludeCyclic>

IecDeclarePhysical. This option specifies the declaration keyword for the import of physical i/o addresses. The default is VAR_EXTERNAL, however, some compilers insist in a plain VAR. To disable explicit declaration of physical i/o alltogether, set this option to the empty string.

   <IecDeclarePhysical val="VAR_EXTERNAL"/>

IecTimeOperators. The default is to use explicit functions for artithmetic with time date, i.e., SUB_TIME and ADD_TIME. This is IEC compliant. However, some target platforms do not provide these functions but insist in appropriatly overloaded binary operators + and -. Corresponding code will be generated by setting this option true.

   <IecTimeOperators val="true"/>

Example of generated code

(* code inserted by configuration via IncludeBefore *)
PROGRAM main
VAR
stat : INT :=0;
cyclic : PREFIX_cyclic_fb;
END_VAR
cyclic(STATUS => stat);
END_PROGRAM
(* end of configuration code *)
FUNCTION_BLOCK PREFIX_cyclic_fb
(* local variables *)
VAR
[.. generated variables, all with PREFIX_ ..]
END_VAR
(* declare physical addresses relevant for io *)
VAR
[.. generated, all of the form AT %xyz.a.b.c ..]
END_VAR
(* code inserted via IncludeCyclic goes here*)
[.. generated core cyclic code by code primitives ..]
END_FUNCTION_BLOCK (* end of fcg_cyclic_fb *)

See blink_geb.cgc for an self-contained example.

Definition at line 118 of file cgp_iec61131st.h.

Member Function Documentation

◆ DoReadTargetConfiguration()

void Iec61131stCodeGenerator::DoReadTargetConfiguration ( TokenReader &  rTr)
protectedvirtual

Reads global configuration from TokenReader, excl. label

Parameters
rTrTokenReader to read from
Exceptions
Exception
  • token mismatch (id 502)
  • IO error (id 1)

Reimplemented from CodePrimitives.

Reimplemented in PlcoxmlCodeGenerator, and GebtoolsCodeGenerator.

Definition at line 59 of file cgp_iec61131st.cpp.

◆ DoWriteTargetConfiguration()

void Iec61131stCodeGenerator::DoWriteTargetConfiguration ( TokenWriter &  rTw) const
protectedvirtual

Write global configuration to TokenWriter, excl. label

Parameters
rTwReference to TokenWriter
Exceptions
Exception
  • IO errors (id 2)

Reimplemented from CodePrimitives.

Reimplemented in PlcoxmlCodeGenerator, and GebtoolsCodeGenerator.

Definition at line 81 of file cgp_iec61131st.cpp.


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