13#ifndef FAUDES_CODEGENERATOR_H
14#define FAUDES_CODEGENERATOR_H
20using 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.xx"
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;};
206 Idx
Size(
void)
const;
222 void Insert(
const std::string& file);
234 void Insert(
const TimedGenerator& rGen);
240 typedef std::vector<TimedGenerator>::const_iterator
Iterator;
473 std::string mAddress;
632 void Verbose(
int level, std::ostream* altout=0);
676 virtual std::ostream&
Output(
void);
740 virtual void Comment(
const std::string& text);
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;
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;
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)
virtual std::string LineCount(void)
LineFeed (convenience support for derived classes)
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.
virtual void LineFeed(int lines=1)
LineFeed (convenience support for derived classes)
virtual void XmlCdataEscape(bool on)
XmlCdataEscape (escape "]]>")
virtual const std::string & Name(void) const
Get objects's name (reimplementing base faudes::Type)
std::map< Idx, int > mEventBitAddress
mapping from faudes event idx to bit address (descending priority, range 0 .
int EventBitAddress(Idx idx)
Get event bit-address from faudes Idx (consecutive, starts at 0)
const TimedGenerator & At(int i) const
Direct access for read-only access of generators.
LineIterator LinesEnd()
Access to line records by iterator.
static std::vector< std::string > Registry(void)
Access registry contents.
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< bool > EventBitMask(Idx idx)
Get vector representation for a single faudes event Idx.
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)
virtual void XmlTextEscape(bool on)
XmlTextEscape (escape "<", ">", "&", "\"" and "'")
virtual void MuteComments(bool on)
Mute comments (convenience support for derived classes)
std::vector< std::map< int, Idx > > mStateFaudesIndex
mapping from vector state idx to faudes index
virtual void DoReadTargetConfiguration(TokenReader &rTr)
Reads global configuration from TokenReader, excl.
std::map< std::string, ActionAddress >::iterator ActionAddressIterator
Access to action record by iterator.
std::string RecentComment(void)
Recent muted comment (convenience support for derived classes)
virtual void OutputMode(const std::string &mode)
Set code output mode.
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
FlagIterator FlagsBegin()
Access to flag records by iterator.
int EventBitMaskSize(void)
Get overall number of events.
static CodeGenerator * New(const std::string &type)
Instantiate by identifier (returns 0 on unknown class)
TimerIterator TimersBegin()
Access to timer records by iterator.
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.
virtual void IndentInc()
Indentation (convenience support for derived classes)
virtual ~CodeGenerator(void)
Destructor.
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
TimerIterator TimersEnd()
Access to timer records by iterator.
std::string mInitialValue
target representation of initial value
Idx EventIndex(const std::string &rName) const
Faudes-event index lookup.
std::map< std::string, LineAddress > mLines
input event generation
Idx EventFaudesIdx(int idx)
Get faudes Idx from target Idx (aka from bit-address + 1)
std::string mElapseEvent
event to trigger on timer elapse
TimerActionIterator TimerActionsBegin()
Access to timer records by iterator.
int mWordSize
compressed boolean capacity of target type word
const AttributeCodeGeneratorEvent & EventAttribute(Idx ev) const
Event configuration attribute lookup.
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
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.
virtual void MuteMode(char mode)
Set current mute mode.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read the configuration from TokenReader, see faudes Type for public wrappers.
std::ostream * pOutStream
output stream
std::vector< TimedGenerator > mGenerators
list of executors
bool mMuteComments
mute comments
virtual Idx StateFaudesIdx(size_t git, int idx)
Get faudes state index (refer to vector representation as default, overload in CodePrimitives)
virtual int EventTargetIdx(Idx idx)
Get target event Idx from faudes Idx (use bit-address + 1)
LineIterator LinesBegin()
Access to line records by iterator.
int mVerbLevel
diagnpstic-output level
void Insert(const std::string &file)
Add a Generator from file.
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)
FlagIterator FlagsEnd()
Access to flag records by iterator.
std::map< std::string, TimerConfiguration >::iterator TimerIterator
Access to timer records by iterator.
virtual std::ostream & Output(void)
Output stream.
std::map< std::string, TimerAction > mTimerActions
timer actions by event name
virtual void MuteCond(char mode)
Set mode condition.
std::vector< word_t > WordVectorFromBitVector(const std::vector< bool > &vect)
Convert boolean vector to word array.
std::map< std::string, LineAddress >::iterator LineIterator
Access to line records by iterator.
void Verbose(int level, std::ostream *altout=0)
Set verbosity level.
virtual void MuteVspace(bool on)
Mute empty lines (convenience support for derived classes)
Iterator Begin(void) const
Begin-iterator for read-only access of generators.
static std::string VersionString(void)
Version (refers to macro COMPILEDES_VERSION, defined in cgp_codegenerator.h)
virtual void DoCompile(void)
virtual hook to input parameter compilation
std::vector< std::map< Idx, int > > mStateVectorAddress
mapping from faudes state idx to vector index
virtual void Compile(void)
Compile input data for alternative representation.
cgEventSet mAlphabet
event configuration by attributes
virtual void Comment(const std::string &text)
Write a comment (reimplement in derived classes, call base)
bool mSetClr
is a set/clr type of address
word_t WordFromBitVector(const std::vector< bool > &vect, int wordindex)
Extract individual word from boolean vector.
const cgEventSet & Alphabet(void) const
Access alphabet (incl event attributes)
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)
CodeGenerator(void)
Constructor.
const std::string & OutputString(void)
Get accumulated output as string.
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
virtual void Clear(void)
Clear all data.
const std::vector< int > & TransitionVector(size_t git)
Get target state index (refer to vector representation as default, overload in CodePrimitives)
std::vector< std::string > mGeneratorNames
list of filenames when generator are read from file
std::vector< bool > mUsingVectorAddressStates
configuration of state indexing per generator
Idx Size(void) const
Number of generators.
virtual int StateTargetIdx(size_t git, Idx idx)
Get target state index (refer to vector representation as default, overload in CodePrimitives)
std::map< std::string, TimerConfiguration > mTimers
timer definitions
virtual void Generate(void)
Generate code.
int mBitAddress
target expression to represent line value
std::map< std::string, FlagExpression >::iterator FlagIterator
Access to flag records by iterator.
virtual void IndentDec()
Indentation (convenience support for derived classes)
ActionAddressIterator ActionAddressesEnd()
Access to action addresses by iterator.
TimerActionIterator TimerActionsEnd()
Access to timer records by iterator.
virtual void DoWriteTargetConfiguration(TokenWriter &rTw) const
Write global configuration to TokenWriter, excl.
ActionAddressIterator ActionAddressesBegin()
Access to action addresses 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.