13 #ifndef FAUDES_CODEGENERATOR_H 14 #define FAUDES_CODEGENERATOR_H 16 #include "libfaudes.h" 23 #define FCG_VERB0(msg) { if(mVerbLevel>=0) *pErrStream << msg << std::endl; } 24 #define FCG_VERB1(msg) { if(mVerbLevel>=1) *pErrStream << msg << std::endl; } 25 #define FCG_VERB2(msg) { if(mVerbLevel>=2) *pErrStream << msg << std::endl; } 26 #define FCG_ERR(msg) { *pErrStream << msg << std::endl; throw Exception("CodeGenerator()","internal error", 500); } 29 #ifndef COMPILEDES_VERSION 30 #define COMPILEDES_VERSION "3.0x" 116 enum OutSink { CONSOLE, FILE, STRING };
147 virtual void Clear(
void);
156 virtual void Name(
const std::string& rName) { mName=rName;};
164 virtual const std::string&
Name(
void)
const {
return mName;};
173 virtual void Compile(
void);
179 static std::string VersionString(
void);
206 Idx Size(
void)
const;
222 void Insert(
const std::string& file);
234 void Insert(
const TimedGenerator& rGen);
237 const TimedGenerator& At(
int i)
const {
return mGenerators.at(i); };
240 typedef std::vector<TimedGenerator>::const_iterator
Iterator;
243 Iterator
Begin(
void)
const {
return mGenerators.begin(); };
246 Iterator
End(
void)
const {
return mGenerators.end(); };
278 Idx
EventIndex(
const std::string& rName)
const {
return mAlphabet.Index(rName); };
289 std::string
EventName(Idx index)
const {
return mAlphabet.SymbolicName(index); };
373 virtual int EventTargetIdx(Idx idx);
376 virtual int EventTargetIdx(
const std::string& ev);
379 int EventBitAddress(Idx idx);
382 Idx EventFaudesIdx(
int idx);
385 std::vector<bool> EventBitMask(Idx idx);
388 std::vector<bool> EventBitMask(
const EventSet& eset);
391 int EventBitMaskSize(
void);
397 word_t WordFromBitVector(
const std::vector<bool>& vect,
int wordindex);
400 std::vector< word_t > WordVectorFromBitVector(
const std::vector<bool>& vect);
451 const std::vector<int>& TransitionVector(
size_t git);
454 virtual int StateTargetIdx(
size_t git, Idx idx);
457 virtual Idx StateFaudesIdx(
size_t git,
int idx);
473 std::string mAddress;
484 LineIterator LinesBegin();
486 LineIterator LinesEnd();
499 FlagIterator FlagsBegin();
501 FlagIterator FlagsEnd();
521 TimerIterator TimersBegin();
523 TimerIterator TimersEnd();
549 ActionAddressIterator ActionAddressesBegin();
551 ActionAddressIterator ActionAddressesEnd();
565 if(!(mTimerStops==other.
mTimerStops))
return false;
582 TimerActionIterator TimerActionsBegin();
584 TimerActionIterator TimerActionsEnd();
621 virtual void Generate(
void);
632 void Verbose(
int level, std::ostream* altout=0);
651 virtual void OutputMode(
const std::string& mode) {mOutMode=mode;};
676 virtual std::ostream& Output(
void);
690 const std::string& OutputString(
void);
700 void OutputString(
const std::string& strbuf);
716 virtual void MuteMode(
char mode);
725 virtual void MuteCond(
char mode);
728 virtual void LineFeed(
int lines=1);
731 virtual std::string LineCount(
void);
734 virtual void IndentInc();
737 virtual void IndentDec();
740 virtual void Comment(
const std::string& text);
746 virtual void XmlTextEscape(
bool on);
749 virtual void XmlCdataEscape(
bool on);
752 virtual void MuteComments(
bool on);
755 virtual void MuteVspace(
bool on);
798 static void Register(
const std::string& type,
CodeGenerator* (*newcg)(
void));
806 static std::vector< std::string > Registry(
void);
831 #define FAUDES_REGISTERCODEGENERATOR(ftype,ctype) static CodeGenerator::Registration<ctype> gRegister(ftype) 898 std::map<std::string, LineAddress>
mLines;
901 std::map<std::string, FlagExpression>
mFlags;
904 std::map<std::string, TimerConfiguration>
mTimers;
934 virtual void DoCompile(
void);
937 virtual void DoGenerate(
void) = 0;
957 virtual void DoRead(TokenReader& rTr,
const std::string& rLabel=
"",
const Type* pContext=0);
979 virtual void DoWrite(TokenWriter& rTw,
const std::string& rLabel=
"",
const Type* pContext=0)
const;
991 virtual void DoReadTargetConfiguration(TokenReader& rTr);
1002 virtual void DoWriteTargetConfiguration(TokenWriter& rTw)
const;
1007 static std::map< std::string, CodeGenerator* (*)(void) >* mpsRegistry;
1010 void DoReadGenerators(TokenReader& rTr);
1013 void DoWriteGenerators(TokenWriter& rTw)
const;
1017 class cgp_streambuf :
public std::streambuf {
1020 cgp_streambuf(std::string mode);
1031 void MuteVspace(
bool on);
1032 void XmlTextEscape(
bool on);
1033 void XmlCdataEscape(
bool on);
1036 const std::string& Buffer();
1043 virtual int_type overflow (int_type c);
1045 std::string mBuffer;
1046 std::ostream* pOutStream;
1047 std::ofstream* mpFOutStream;
1048 std::stringstream* mpSOutStream;
1061 cgp_streambuf* pOutBuffer;
std::map< std::string, FlagExpression > mFlags
input event generation
std::string mInitialValue
target representation of initial value
Event attributes for the purpose of code generation.
std::vector< std::string > mGeneratorNames
list of filenames when generator are read from file
EventSet mUsedEvents
configured events that are referred to by some generator
EventSet mPosEvents
bit-address of buffer for edge detection (consecutive)
std::string mOutMode
output file name (base)
EventSet mStopEvents
stop events as in AttributeCodeGeneratorEvent
int mWordSize
compressed boolean capacity of target type word
bool mExe
is an executable type of address
bool operator<(const TimerAction &other) const
need compare operator for STL (should perhaps use hashes for performance)
EventSet mPosStatics
events to trigger on negative edge
std::string mRecentMutedComment
recent muted comment
std::string mName
faudes object name (aka project name)
std::vector< bool > mUsingVectorAddressStates
configuration of state indexing per generator
std::ostream * pOutStream
output stream
cgEventSet mAlphabet
event configuration by attributes
TaNameSet< AttributeCodeGeneratorEvent > cgEventSet
Convenience typedef: eventset with code-generator config attributes.
std::string mAddress
target address prefix to maintain timer state
const cgEventSet & Alphabet(void) const
Access alphabet (incl event attributes)
std::string mAddress
target address as specified in configuration
EventSet mOutputEvents
used events that are configured as outputs
EventSet mNegEvents
events to trigger on positive edge
std::map< std::string, TimerConfiguration >::iterator TimerIterator
Access to timer records by iterator.
std::string mAddress
target expression to represent the line value
EventSet mEvents
events to trigger on positive evaluation
Iterator End(void) const
End-iterator for read-only access of generators.
std::vector< word_t > mBitMaskVector
Look-up table to map a bit-address to the word-bitmask.
std::vector< int > mWordAddressVector
Look-up table to map a bit-address to the word-index.
Idx EventIndex(const std::string &rName) const
Faudes-event index lookup.
EventSet mStartEvents
start events as in AttributeCodeGeneratorEvent
std::set< std::string > mTimerStarts
timers to start
std::map< std::string, TimerAction >::iterator TimerActionIterator
Access to timer records by iterator.
std::map< std::string, FlagExpression >::iterator FlagIterator
Access to flag records by iterator.
std::map< std::string, TimerAction > mTimerActions
timer actions by event name
std::vector< std::map< Idx, int > > mStateVectorAddress
mapping from faudes state idx to vector index
std::map< Idx, int > mEventBitAddress
mapping from faudes event idx to bit address (descending priority, range 0 .
virtual const std::string & Name(void) const
Get objects's name (reimplementing base faudes::Type)
bool operator==(const TimerAction &other)
need equality operator for STL
int mIntegerSize
compressed boolean capacity of target type integer
std::ostream * pErrStream
error stream
std::map< std::string, ActionAddress >::iterator ActionAddressIterator
Access to action record by iterator.
std::string OutputMode(void)
Report code output mode.
int mVerbLevel
diagnpstic-output level
int mLastInputEvent
highest bit-address with input (or timer) event (-1 for none)
std::string RecentComment(void)
Recent muted comment (convenience support for derived classes)
EventSet mResetEvents
reset events as in AttributeCodeGeneratorEvent
std::vector< std::map< int, Idx > > mStateFaudesIndex
mapping from vector state idx to faudes index
unsigned long word_t
Code-generator internal data type of target words.
std::vector< std::vector< int > > mTransitionVector
compiled transition-sets, represented as vectors of integers with 0 as separator
std::string mElapseEvent
event to trigger on timer elapse
virtual void OutputMode(const std::string &mode)
Set code output mode.
EventSet mInputEvents
used events that are configured as inputs (incl timer)
EventSet mNegStatics
events to trigger on high power on
char mMuteMode
current output mode
Event attributes (execution semantics)
int mBitAddress
target expression to represent line value
std::map< std::string, ActionAddress > mActionAddresses
action addresses
virtual void Name(const std::string &rName)
Set objects's name (reimplementing base faudes::Type)
Iterator Begin(void) const
Begin-iterator for read-only access of generators.
std::vector< TimedGenerator >::const_iterator Iterator
Iterator for read-only access of generators.
std::map< std::string, LineAddress >::iterator LineIterator
Access to line records by iterator.
EventSet mInternalEvents
used events that are configured as internal events (excl.
std::map< int, Idx > mEventFaudesIdx
mapping from bit address to faudes event idx
std::set< std::string > mTimerResets
timers to reset
bool mStatic
events to trigger on low power on
std::map< std::string, TimerConfiguration > mTimers
timer definitions
std::string EventName(Idx index) const
Faudes-event name lookup.
std::map< std::string, LineAddress > mLines
input event generation
Code-generation common base.
std::set< std::string > mTimerStops
timers to stop
Compiled record per action-address.
Compiled record per input line.
Compiled record per input flag-expression.
Compiled record per timer acting.
static void Register(const std::string &type, CodeGenerator *(*newcg)(void))
Insert derived class in the registry.
int mLastOutputEvent
highest bit-address with output event (-1 for none)
bool mMuteComments
mute comments
bool mSetClr
is a set/clr type of address
std::vector< TimedGenerator > mGenerators
list of executors
Compiled record per event on how it affects timers.