13 #ifndef FAUDES_CODEGENERATOR_H
14 #define FAUDES_CODEGENERATOR_H
16 #include "libfaudes.h"
20 using namespace faudes;
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;
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;
565 if(!(mTimerStops==other.
mTimerStops))
return false;
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);
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;
Event attributes (execution semantics)
TaNameSet< AttributeCodeGeneratorEvent > cgEventSet
Convenience typedef: eventset with code-generator config attributes.
Event attributes for the purpose of code generation.
Compiled record per event on how it affects timers.
bool operator==(const TimerAction &other)
need equality operator for STL
bool operator<(const TimerAction &other) const
need compare operator for STL (should perhaps use hashes for performance)
std::set< std::string > mTimerResets
timers to reset
std::set< std::string > mTimerStarts
timers to start
std::set< std::string > mTimerStops
timers to stop
Code-generation common base.
std::string mOutMode
output file name (base)
char mMuteMode
current output mode
std::string mAddress
target expression to represent the line value
std::string EventName(Idx index) const
Faudes-event name lookup.
std::map< Idx, int > mEventBitAddress
mapping from faudes event idx to bit address (descending priority, range 0 .
std::vector< TimedGenerator >::const_iterator Iterator
Iterator for read-only access of generators.
std::string OutputMode(void)
Report code output mode.
EventSet mStartEvents
start events as in AttributeCodeGeneratorEvent
std::vector< int > mWordAddressVector
Look-up table to map a bit-address to the word-index.
std::vector< word_t > mBitMaskVector
Look-up table to map a bit-address to the word-bitmask.
int mLastInputEvent
highest bit-address with input (or timer) event (-1 for none)
std::vector< std::map< int, Idx > > mStateFaudesIndex
mapping from vector state idx to faudes index
const AttributeCodeGeneratorEvent & EventAttribute(Idx ev) const
Event configuration attribute lookup.
std::string RecentComment(void)
Recent muted comment (convenience support for derived classes)
virtual void OutputMode(const std::string &mode)
Set code output mode.
std::map< std::string, LineAddress >::iterator LineIterator
Access to line records by iterator.
virtual void DoGenerate(void)=0
pure virtual interface to code generation
EventSet mPosEvents
bit-address of buffer for edge detection (consecutive)
std::ostream * pErrStream
error stream
std::string mRecentMutedComment
recent muted comment
std::vector< std::vector< int > > mTransitionVector
compiled transition-sets, represented as vectors of integers with 0 as separator
EventSet mInternalEvents
used events that are configured as internal events (excl.
int mLastOutputEvent
highest bit-address with output event (-1 for none)
std::string mAddress
target address as specified in configuration
static void Register(const std::string &type, CodeGenerator *(*newcg)(void))
Insert derived class in the registry.
void Alphabet(const cgEventSet &rAlphabet)
Set all event attributes.
bool mStatic
events to trigger on low power on
EventSet mStopEvents
stop events as in AttributeCodeGeneratorEvent
bool mExe
is an executable type of address
EventSet mOutputEvents
used events that are configured as outputs
std::string mInitialValue
target representation of initial value
Idx EventIndex(const std::string &rName) const
Faudes-event index lookup.
std::map< std::string, TimerConfiguration >::iterator TimerIterator
Access to timer records by iterator.
std::map< std::string, LineAddress > mLines
input event generation
std::string mElapseEvent
event to trigger on timer elapse
int mWordSize
compressed boolean capacity of target type word
std::map< int, Idx > mEventFaudesIdx
mapping from bit address to faudes event idx
EventSet mEvents
events to trigger on positive evaluation
EventSet mPosStatics
events to trigger on negative edge
std::ostream * pOutStream
output stream
std::vector< TimedGenerator > mGenerators
list of executors
bool mMuteComments
mute comments
int mVerbLevel
diagnpstic-output level
int mIntegerSize
compressed boolean capacity of target type integer
std::map< std::string, ActionAddress > mActionAddresses
action addresses
EventSet mInputEvents
used events that are configured as inputs (incl timer)
const cgEventSet & Alphabet(void) const
Access alphabet (incl event attributes)
std::map< std::string, TimerAction > mTimerActions
timer actions by event name
std::map< std::string, FlagExpression >::iterator FlagIterator
Access to flag records by iterator.
Iterator Begin(void) const
Begin-iterator for read-only access of generators.
std::vector< std::map< Idx, int > > mStateVectorAddress
mapping from faudes state idx to vector index
cgEventSet mAlphabet
event configuration by attributes
bool mSetClr
is a set/clr type of address
EventSet mResetEvents
reset events as in AttributeCodeGeneratorEvent
Iterator End(void) const
End-iterator for read-only access of generators.
virtual void Name(const std::string &rName)
Set objects's name (reimplementing base faudes::Type)
virtual const std::string & Name(void) const
Get objects's name (reimplementing base faudes::Type)
EventSet mNegEvents
events to trigger on positive edge
void EventAttribute(Idx ev, const AttributeCodeGeneratorEvent &attr)
Set event attribute.
EventSet mNegStatics
events to trigger on high power on
std::vector< std::string > mGeneratorNames
list of filenames when generator are read from file
std::vector< bool > mUsingVectorAddressStates
configuration of state indexing per generator
std::map< std::string, TimerConfiguration > mTimers
timer definitions
const TimedGenerator & At(int i) const
Direct access for read-only access of generators.
int mBitAddress
target expression to represent line value
std::map< std::string, ActionAddress >::iterator ActionAddressIterator
Access to action record by iterator.
std::string mName
faudes object name (aka project name)
std::map< std::string, FlagExpression > mFlags
input event generation
unsigned long word_t
Code-generator internal data type of target words.
EventSet mUsedEvents
configured events that are referred to by some generator
std::string mAddress
target address prefix to maintain timer state
std::map< std::string, TimerAction >::iterator TimerActionIterator
Access to timer records by iterator.
Compiled record per action-address.
Compiled record per input flag-expression.
Compiled record per input line.
Compiled record per timer acting.