12 #ifndef FAUDES_CODEPRIMITIVES_H
13 #define FAUDES_CODEPRIMITIVES_H
15 #include "libfaudes.h"
18 using namespace faudes;
279 virtual void Clear(
void);
296 virtual void LiteralPrepend(
void);
299 virtual void DeclareStatus(
void);
302 virtual void DeclareReset(
void);
305 virtual void DeclareRecentEvent(
void);
308 virtual void DeclareParallelState(
void);
311 virtual void DeclarePendingEvents(
void);
314 virtual void DeclareLoopState(
void);
317 virtual void DeclareTimers(
void);
320 virtual void DeclareAux(
void);
323 virtual void DeclareLargeCarray(
void);
326 virtual void DeclareSmallCarray(
void);
329 virtual void DeclareEventNameLookup(
void);
332 virtual void DeclareStateNameLookup(
void);
335 virtual void ResetState(
void);
338 virtual void ResetReturn(
void);
341 virtual void SenseInputs(
void);
344 virtual void SenseTimerElapse(
void);
347 virtual void BeginExecutionLoop(
void);
350 virtual void UpdateEnabled(
void);
353 virtual void ScheduleEvent(
void);
356 virtual void BreakExecutionLoop(
void);
359 virtual void ExecuteEvent(
void);
362 virtual void OperateTimers(
void);
365 virtual void OperateOutputs(
void);
368 virtual void EndExecutionLoop(
void);
371 virtual void LiteralAppend(
void);
374 virtual void InsertExecHooks(
void);
377 virtual void ExecuteEventBySwitching(
void);
380 virtual void ExecuteEventByInterpreter(
void);
383 virtual void UpdateEnabledBySwitching(
void);
386 virtual void UpdateEnabledByInterpreter(
void);
414 class AA :
public std::string {
416 explicit AA(
void) : std::string() {};
417 explicit AA(std::string src) : std::string(src) {};
418 AA Sub(
int subscript)
const {
return AA(std::string(*
this) +
"_" + ToStringInteger(subscript));};
421 class AX :
public std::string {
423 explicit AX(
void) : std::string() {};
424 explicit AX(std::string src) : std::string(src) {};
431 virtual std::string TargetSymbol(
const std::string& str);
469 virtual void IntegerDeclare(
const AA& address) =0;
470 virtual void IntegerDeclare(
const AA& address,
int val) =0;
471 virtual void IntegerAssign(
const AA& address,
int val) =0;
472 virtual void IntegerAssign(
const AA& address,
const AX& expression)=0;
473 virtual void IntegerIncrement(
const AA& address,
int val=1)=0;
474 virtual void IntegerDecrement(
const AA& address,
int val=1);
475 virtual AX IntegerQuotient(
const AX& expression,
int val);
476 virtual AX IntegerRemainder(
const AX& expression,
int val);
477 virtual AX IntegerBitmask(
const AX& expression);
478 virtual AX IntegerIsEq(
const AA& address,
int val);
479 virtual AX IntegerIsEq(
const AA& address,
const AX& expression);
480 virtual AX IntegerIsNotEq(
const AA& address,
int val);
481 virtual AX IntegerIsNotEq(
const AA& address,
const AX& expression);
482 virtual AX IntegerIsGreater(
const AA& address,
int val);
483 virtual AX IntegerIsLess(
const AA& address,
int val);
484 virtual AX IntegerConstant(
int val)=0;
485 virtual bool HasIntmaths(
void);
501 virtual void WordDeclare(
const AA& address);
502 virtual void WordDeclare(
const AA& address,
word_t val);
503 virtual void WordAssign(
const AA& address,
word_t val);
504 virtual void WordAssign(
const AA& address,
const AX& expression);
505 virtual void WordOr(
const AA& address,
word_t val);
506 virtual void WordOr(
const AA& address,
const AX& expression);
507 virtual void WordOr(
const AA& address,
const AA& op1,
const AA& op2);
508 virtual void WordOr(
const AA& address,
const AA& op1,
word_t op2);
509 virtual void WordAnd(
const AA& address,
word_t val);
510 virtual void WordAnd(
const AA& address,
const AX& expression);
511 virtual void WordAnd(
const AA& address,
const AA& op1,
const AA& op2);
512 virtual void WordAnd(
const AA& address,
const AA& op1,
word_t op2);
513 virtual void WordNand(
const AA& address,
const AX& expresson);
514 virtual AX WordIsBitSet(
const AA& address,
int idx);
515 virtual AX WordIsBitClr(
const AA& address,
int idx);
516 virtual AX WordIsMaskSet(
const AA& address,
word_t mask);
517 virtual AX WordIsEq(
const AA& address,
word_t val);
518 virtual AX WordIsNotEq(
const AA& address,
word_t val);
519 virtual AX WordConstant(
word_t val);
535 virtual void BooleanDeclare(
const AA& address);
536 virtual void BooleanDeclare(
const AA& address,
int val);
537 virtual void BooleanAssign(
const AA& address,
int val);
538 virtual void BooleanAssign(
const AA& address,
const AX& expression);
539 virtual AX BooleanIsEq(
const AA& op1,
const AA& op2);
540 virtual AX BooleanIsNotEq(
const AA& op1,
const AA& op2);
555 virtual void CintarrayDeclare(
const AA& address,
int offset,
const std::vector<int>& val);
556 virtual AA CintarrayAccess(
const AA& address,
int index);
557 virtual AA CintarrayAccess(
const AA& address,
const AA& indexaddr);
558 virtual bool HasCintarray(
void);
573 virtual void CwordarrayDeclare(
const AA& address,
int offset,
const std::vector<word_t>& val);
574 virtual AA CwordarrayAccess(
const AA& address,
int index);
575 virtual AA CwordarrayAccess(
const AA& address,
const AA& indexaddr);
576 virtual bool HasCwordarray(
void);
590 virtual AX StringConstant(
const std::string &val);
591 virtual void CstrarrayDeclare(
const AA& address,
int offset,
const std::vector<std::string>& val);
592 virtual AA CstrarrayAccess(
const AA& address,
int index);
593 virtual AA CstrarrayAccess(
const AA& address,
const AA& indexaddr);
594 virtual bool HasCstrarray(
void);
609 virtual void IntarrayDeclare(
const AA& address,
int offset,
int len);
610 virtual void IntarrayDeclare(
const AA& address,
int offset,
const std::vector<int>& val);
611 virtual AA IntarrayAccess(
const AA& address,
int index);
612 virtual AA IntarrayAccess(
const AA& address,
const AA& indexaddr);
613 virtual bool HasIntarray(
void);
628 virtual void WordarrayDeclare(
const AA& address,
int offset,
int len);
629 virtual void WordarrayDeclare(
const AA& address,
int offset,
const std::vector<word_t>& val);
630 virtual AA WordarrayAccess(
const AA& address,
int index);
631 virtual AA WordarrayAccess(
const AA& address,
const AA& indexaddr);
632 virtual bool HasWordarray(
void);
660 virtual void BitarrayDeclare(
const AA& address,
int blen);
661 virtual void BitarrayDeclare(
const AA& address,
const std::vector<bool>& val);
662 virtual void BitarrayAssign(
const AA& address,
const std::vector<bool>& val);
663 virtual void BitarrayAssign(
const AA& address,
const AA& otherarray);
664 virtual void BitarrayClear(
const AA& address);
665 virtual void BitarrayFull(
const AA& address);
666 virtual void BitarraySetBit(
const AA& address,
int bitaddr);
667 virtual void BitarraySetBit(
const AA& address,
const AA& indexaddr,
int offset=0,
const std::vector<bool>& hint=std::vector<bool>() );
668 virtual void BitarrayClrBit(
const AA& address,
int bitaddr);
669 virtual void BitarrayClrBit(
const AA& address,
const AA& indexaddr,
int offset=0,
const std::vector<bool>& hint=std::vector<bool>() );
670 virtual void BitarrayIsBitSet(
const AA& address,
const AA& indexaddr,
const AA& result,
int offset=0,
const std::vector<bool>& hint=std::vector<bool>() );
671 virtual void BitarrayOr(
const AA& address,
const std::vector<bool>& val);
672 virtual void BitarrayOr(
const AA& address,
const AA& op1,
const std::vector<bool>& op2);
673 virtual void BitarrayOrAllWords(
const AA& address,
const AA& result);
674 virtual void BitarrayAnd(
const AA& address,
const std::vector<bool>& val);
675 virtual void BitarrayAnd(
const AA& address,
const AA& otherarray);
676 virtual void BitarrayAnd(
const AA& address,
const AA& op1,
const AA& op2);
677 virtual void BitarrayAnd(
const AA& address,
const AA& op1,
const std::vector<bool>& op2);
678 virtual void BitarrayFindFirst(
const AA& address,
const AA& result,
int offset=0);
694 virtual void EventSetDeclare(
const AA& address);
695 virtual void EventSetDeclare(
const AA& address,
const EventSet& evset);
696 virtual void EventSetAssign(
const AA& address,
const EventSet& evset);
697 virtual void EventSetInsert(
const AA& address,
const EventSet& evset);
698 virtual void EventSetInsert(
const AA& address, Idx ev);
699 virtual void EventSetInsert(
const AA& address,
const AA& evaddr);
700 virtual void EventSetInsert(
const AA& address,
const AA& evaddr,
const EventSet& hint);
701 virtual void EventSetErase(
const AA& address,
const EventSet& evset);
702 virtual void EventSetErase(
const AA& address, Idx ev);
703 virtual void EventSetErase(
const AA& address,
const AA& evaddr);
704 virtual void EventSetErase(
const AA& address,
const AA& evaddr,
const EventSet& hint);
705 virtual void EventSetExists(
const AA& address,
const AA& evaddr,
const AA& result,
const EventSet& hint);
706 virtual void EventSetRestrict(
const AA& address,
const AA& otherset);
707 virtual void EventSetUnion(
const AA& address,
const AA& op1,
const EventSet& op2);
708 virtual void EventSetIntersection(
const AA& address,
const AA& op1,
const EventSet& op2);
709 virtual void EventSetClear(
const AA& address);
710 virtual void EventSetFull(
const AA& address);
711 virtual void EventSetIsNotEmpty(
const AA& address,
const AA& result);
712 virtual void EventSetFindHighestPriority(
const AA& address,
const AA& result);
728 virtual void IfTrue(
const AX& expression);
729 virtual void IfFalse(
const AX& expression);
730 virtual void IfWord(
const AX& expression);
731 virtual void IfElseIfTrue(
const AX& expression);
732 virtual void IfElse(
void);
733 virtual void IfEnd(
void);
735 virtual void SwitchBegin(
const AA& address);
736 virtual void SwitchCase(
const AA& address,
int val);
737 virtual void SwitchCases(
const AA& address,
int from,
int to);
738 virtual void SwitchCases(
const AA& address,
const std::set< int>& vals);
739 virtual void SwitchBreak(
void);
740 virtual void SwitchEnd(
void);
741 virtual bool HasMultiCase(
void);
743 virtual void LoopBegin(
void);
744 virtual void LoopBreak(
const AX& expression);
745 virtual void LoopEnd(
void);
747 virtual void FunctionReturn(
void);
757 virtual void RunActionSet(
const std::string& address);
758 virtual void RunActionClr(
const std::string& address);
759 virtual void RunActionExe(
const AX& expression);
761 virtual AX ReadInputLine(
const std::string& address);
762 virtual AX InputExpression(
const std::string& expression);
770 virtual void TimerDeclare(
const AA& address,
const std::string& litval);
771 virtual void TimerStart(
const AA& address);
772 virtual void TimerStop(
const AA& address);
773 virtual void TimerReset(
const AA& address,
const std::string& litval);
774 virtual AX TimerIsElapsed(
const AA& address);
782 virtual int StateTargetIdx(
size_t git, Idx idx);
783 virtual Idx StateFaudesIdx(
size_t git,
int idx);
786 virtual void Comment(
const std::string& text);
789 virtual void VariableDeclare(
const std::string& laddr,
const std::string& ltype);
790 virtual void VariableDeclare(
const std::string& laddr,
const std::string& ltype,
const std::string& lval);
883 virtual void DoCompile(
void);
886 virtual void DoGenerate(
void);
889 virtual void DoGenerateDeclarations(
void);
892 virtual void DoGenerateResetCode(
void);
895 virtual void DoGenerateCyclicCode(
void);
898 virtual void DoReadTargetConfiguration(TokenReader& rTr);
901 virtual void DoWriteTargetConfiguration(TokenWriter& rTw)
const;
917 template<
class Data>
void ConsolidateCaseRanges(std::map< int, Data>& caseData, std::map< int, int>& caseFromTo) {
921 if(caseData.empty())
return;
923 int fcase=caseData.begin()->first;
924 int tcase=caseData.begin()->first;
925 caseFromTo[fcase]=tcase;
927 typename std::map< int, Data>::iterator cit=caseData.begin();
928 for(++cit; cit!=caseData.end(); ++cit) {
930 int ccase = cit->first;
934 if(caseData[tcase]==caseData[ccase]) {
937 caseFromTo[fcase]=tcase;
943 caseFromTo[fcase]=tcase;
957 template<
class Data>
void ConsolidateCaseSets(std::map< int, Data>& caseData, std::set< std::set< int > >& caseSets) {
961 if(caseData.empty())
return;
963 if(!HasMultiCase()) {
964 typename std::map< int , Data >::const_iterator dit=caseData.begin();
965 for(; dit!=caseData.end(); ++dit) {
966 std::set< int > sngl;
967 sngl.insert(dit->first);
968 caseSets.insert(sngl);
973 std::map< Data , std::set<int> > rmap;
974 typename std::map< int , Data >::const_iterator dit=caseData.begin();
975 for(; dit!=caseData.end(); ++dit)
976 rmap[dit->second].insert(dit->first);
978 typename std::map< Data , std::set<int> >::iterator rit=rmap.begin();
979 for(; rit!=rmap.end(); ++rit)
980 caseSets.insert(rit->second);
Code-generator common base class.
Code-generation common base.
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.
bool mLoopEnabledOutputs
code option: loop until all enabled outputs are executed
bool mBitAddressArithmetic
code option: compute bit and word address on target
std::string mStateUpdateHook
code option: state change hook
bool mArrayForState
code option: use int arrays to represent that overall state
bool mArrayForBitarray
code option: use const array to represent bit-masks
std::string mLiteralPrepend
extra code to prepend
bool mExistStateNames
record whether there exist statenames at all
bool mEventNameLookup
code option: event name lookup
bool mEventsetsForPerformance
code option: eventsets for performance
std::map< std::string, bitarray_rec > mBitarrays
Record of all declared bit-arrays.
bool mStateNameLookup
code option: state name lookup
std::string mIntegerType
target data type for integer
std::vector< bool > value
initialisation value
virtual AX TargetExpression(const AA &address)=0
Convert abstract address to target expression of the respective value.
virtual std::string TargetAddress(const AA &address)=0
Convert abstract address to target symbolic address.
std::string mWordType
target data type for word
bool mArrayForTransitions
code option: use const array to represent transitions
bool mArrayForBitmasks
code option: use const array to represent bit-masks
bool mStrictEventSynchronisation
code option: strict event synchronisation
std::string mLiteralAppend
extra code to prepend
std::vector< bool > mHasStateNames
record per generator whether there is a lookup table
bool mMaintainStateIndices
code option: use state indices as provided
bool mLoopPendingInputs
code option: loop until all inputs are resolved
std::string mPrefix
universal prefix (pseudo name space)
std::string mEventExecutionHook
code option: event exec hook
bool mBisectionForBitfind
code option: use bisection to fing lowest set bit
Record declared bit-arrays.