30 FD_DCG(
"CodePrimitives(" <<
this <<
")::CodePrimitives()");
35 FD_DCG(
"CodePrimitives(" <<
this <<
")::~CodePrimitives()");
41 FD_DCG(
"CodePrimitives(" <<
this <<
")::Clear()");
72 FD_DCG(
"CodePrimitives::DoReadTargetConfiguration()");
77 if(rTr.ExistsBegin(
"Prefix")) {
78 rTr.ReadBegin(
"Prefix",token);
79 mPrefix=token.AttributeStringValue(
"val");
83 rTr.ReadEnd(
"Prefix");
86 if(rTr.ExistsBegin(
"WordType")) {
87 rTr.ReadBegin(
"WordType",token);
88 mWordType=token.AttributeStringValue(
"val");
89 rTr.ReadEnd(
"WordType");
92 if(rTr.ExistsBegin(
"WordSize")) {
93 rTr.ReadBegin(
"WordSize",token);
94 mWordSize=token.AttributeIntegerValue(
"val");
95 rTr.ReadEnd(
"WordSize");
98 if(rTr.ExistsBegin(
"IntegerType")) {
99 rTr.ReadBegin(
"IntegerType",token);
101 rTr.ReadEnd(
"IntegerType");
104 if(rTr.ExistsBegin(
"IntegerSize")) {
105 rTr.ReadBegin(
"IntegerSize",token);
107 rTr.ReadEnd(
"IntegerSize");
110 if(rTr.ExistsBegin(
"ArrayForTransitions")) {
111 rTr.ReadBegin(
"ArrayForTransitions",token);
113 rTr.ReadEnd(
"ArrayForTransitions");
116 if(rTr.ExistsBegin(
"MaintainStateIndices")) {
117 rTr.ReadBegin(
"MaintainStateIndices",token);
119 rTr.ReadEnd(
"MaintainStateindices");
122 if(rTr.ExistsBegin(
"ArrayForBitmasks")) {
123 rTr.ReadBegin(
"ArrayForBitmasks",token);
125 rTr.ReadEnd(
"ArrayForBitmasks");
128 if(rTr.ExistsBegin(
"ArrayForBitarray")) {
129 rTr.ReadBegin(
"ArrayForBitarray",token);
131 rTr.ReadEnd(
"ArrayForBitarray");
134 if(rTr.ExistsBegin(
"BitAddressArithmetic")) {
135 rTr.ReadBegin(
"BitAddressArithmetic",token);
137 rTr.ReadEnd(
"BitAddressArithmetic");
140 if(rTr.ExistsBegin(
"BisectionForBitfind")) {
141 rTr.ReadBegin(
"BisectionForBitfind",token);
143 rTr.ReadEnd(
"BisectionForBitfind");
146 if(rTr.ExistsBegin(
"ArrayForState")) {
147 rTr.ReadBegin(
"ArrayForState",token);
149 rTr.ReadEnd(
"ArrayForState");
152 if(rTr.ExistsBegin(
"EventsetsForPerformance")) {
153 rTr.ReadBegin(
"EventsetsForPerformance",token);
155 rTr.ReadEnd(
"EventsetsForPerformance");
158 if(rTr.ExistsBegin(
"LoopPendingInputs")) {
159 rTr.ReadBegin(
"LoopPendingInputs",token);
161 rTr.ReadEnd(
"LoopPendingInputs");
164 if(rTr.ExistsBegin(
"LoopEnabledOutputs")) {
165 rTr.ReadBegin(
"LoopEnabledOutputs",token);
167 rTr.ReadEnd(
"LoopEnabledOutputs");
170 if(rTr.ExistsBegin(
"StrictEventSynchronisation")) {
171 rTr.ReadBegin(
"StrictEventSynchronisation",token);
173 rTr.ReadEnd(
"StrictEventSynchronisation");
176 if(rTr.ExistsBegin(
"EventNameLookup")) {
177 rTr.ReadBegin(
"EventNameLookup",token);
179 rTr.ReadEnd(
"EventNameLookup");
182 if(rTr.ExistsBegin(
"StateNameLookup")) {
183 rTr.ReadBegin(
"StateNameLookup",token);
185 rTr.ReadEnd(
"StateNameLookup");
188 if(rTr.ExistsBegin(
"EventExecutionHook")) {
189 rTr.ReadBegin(
"EventExecutionHook",token);
191 rTr.ReadEnd(
"EventExecutionHook");
194 if(rTr.ExistsBegin(
"StateUpdateHook")) {
195 rTr.ReadBegin(
"StateUpdateHook",token);
197 rTr.ReadEnd(
"StateUpdateHook");
200 if(rTr.ExistsBegin(
"IncludeBefore"))
203 if(rTr.ExistsBegin(
"IncludeAfter"))
205 FD_DCG(
"CodePrimitives::DoReadTargetConfiguration(): done");
217 token.SetEmpty(
"Prefix");
218 token.InsAttributeString(
"val",
mPrefix);
221 token.SetEmpty(
"WordType");
222 token.InsAttributeString(
"val",
mWordType);
225 token.SetEmpty(
"WordSize");
226 token.InsAttributeInteger(
"val",
mWordSize);
229 token.SetEmpty(
"IntegerType");
233 token.SetEmpty(
"IntegerSize");
237 token.SetEmpty(
"ArrayForTransitions");
241 token.SetEmpty(
"MaintainStateIndices");
245 token.SetEmpty(
"ArrayForBitmasks");
248 token.SetEmpty(
"ArrayForBitarray");
252 token.SetEmpty(
"BitAddressArithmetic");
256 token.SetEmpty(
"BisectionForBitfind");
260 token.SetEmpty(
"ArrayForState");
264 token.SetEmpty(
"EventsetsForPerformance");
268 token.SetEmpty(
"LoopPendingInputs");
272 token.SetEmpty(
"LoopEnabledOutputs");
276 token.SetEmpty(
"StrictEventSynchronisation");
280 token.SetEmpty(
"EventNameLookup");
284 token.SetEmpty(
"StateNameLookup");
287 token.SetEmpty(
"EventExecutionHook");
291 token.SetEmpty(
"StateUpdateHook");
306 for(
size_t gid=0; gid<
Size(); ++gid) {
307 const faudes::Generator& gen=
At(gid);
309 faudes::StateSet::Iterator sit=gen.StatesBegin();
310 for(;sit!=gen.StatesEnd();++sit)
311 mem += (
int) gen.StateName(*sit).size();
318 FCG_VERB0(
"CodeGenerator::Compile(): [" << gen.Name() <<
"] state names amount to #"
324 FCG_VERB1(
"CodePrimitives::Compile(): state update hook implies to maintain state indices as provided");
328 FCG_VERB1(
"CodePrimitives::Compile(): cannot generate lookup tables for the specified platforms");
332 FCG_VERB1(
"CodePrimitives::Compile(): no state names found --- will generate dummy loopkups only");
337 for(
size_t gid=0; gid<
Size(); ++gid) {
346 for(
size_t git=0; git<
Size(); ++git) {
347 if(
At(git).MaxStateIndex()==
At(git).States().Size())
continue;
349 FCG_VERB0(
"CodeGenerator::Generator(): generator [" <<
At(git).
Name() <<
"] " <<
350 "has non-consecutive state indices --- applying MinStateIndex()");
355 for(
size_t git=0; git<
Size(); ++git) {
356 int gap =
At(git).MaxStateIndex() -
At(git).States().Size();
359 FCG_VERB0(
"CodeGenerator::Generator(): generator [" <<
At(git).
Name() <<
"] " <<
360 "has non-consecutive state indices --- this will introduce an inefficient address table with #"
361 << gap <<
" dummy entries");
364 FCG_VERB0(
"CodeGenerator::Generator(): generator [" <<
At(git).
Name() <<
"] " <<
365 "has non-consecutive state indices --- this will introduce an inefficient symboltable with #"
366 << gap <<
" dummy entries");
continue;
374 FD_DCG(
"CodePrimitives(" <<
this <<
")::DoCompile()");
377 FCG_VERB1(
"CodePrimitives::Compile(): cannot generate compiled arrays for the specified target");
381 FCG_VERB1(
"CodePrimitives::Compile(): cannot generate compiled bit-masks for the specified target");
385 FCG_VERB1(
"CodePrimitives::Compile(): compiled bitmasks not recommended for word-size #" <<
mWordSize);
387 FCG_VERB1(
"CodePrimitives::Compile(): reject compiled bitmasks for word-size #" <<
mWordSize);
391 FCG_VERB1(
"CodePrimitives::Compile(): bit address-maths not available for the specified target");
395 FCG_VERB1(
"CodePrimitives::Compile(): reject option eventsets-for-performance for specified target");
404 FCG_VERB1(
"CodePrimitives::Compile(): option loop-enabled-outputs implies loop-enabled-inputs");
408 FCG_ERR(
"CodePrimitives::Compile(): option loop-enabled-outputs requires high priority for output events");
412 FCG_VERB1(
"CodePrimitives::Compile(): cannot generate lookup tables for the specified platform");
416 FCG_VERB1(
"CodePrimitives::Compile(): cannot implement state-update hook for the specified platform");
420 FCG_VERB1(
"CodePrimitives::Compile(): state-update hook implies array representation of overall state");
442 std::string::const_iterator sit=str.begin();
443 for(;sit!=str.end();++sit){
444 if(std::isalpha(*sit)) { res.push_back(*sit);
continue; };
445 if(std::isdigit(*sit) && res.size()>0) { res.push_back(*sit);
continue; }
446 if(res.size()>0) res.push_back(
'_');
486 Comment(
"************************************************");
487 Comment(
"* prepend code snippet from configuration *");
496 Comment(
"status (0x00 <> waiting, 0x01<>executing, 0x02<>err)");
497 WordDeclare(
AA(
"status"));
504 BooleanDeclare(
AA(
"reset"),
false);
510 Comment(
"recent event (0<>none)");
511 IntegerDeclare(
AA(
"recent_event"));
522 for(Idx gid=0; gid<
Size(); gid++)
523 IntegerDeclare(
AA(
"parallel_state").Sub(gid));
531 Comment(
"pending input events incl timer elapse");
532 EventSetDeclare(
AA(
"pending_events"));
534 Comment(
"events enabled by all generators");
535 EventSetDeclare(
AA(
"enabled_events"));
542 Comment(
"executed event (-1<>init, 0<>none)");
543 IntegerDeclare(
AA(
"exec_event"),-1);
546 Comment(
"scheduled event (0<>none)");
547 IntegerDeclare(
AA(
"sched_event"));
554 AA baddr =
AA(
"line_level").Sub(lit->second.mBitAddress);
555 BooleanDeclare(baddr);
562 BooleanDeclare(
AA(
"first_loop"));
573 TimerDeclare(
AA(tit->second.mAddress),tit->second.mInitialValue);
583 EventSetDeclare(
AA(
"aux_locenabled"));
584 IntegerDeclare(
AA(
"aux_parsetrans"));
585 IntegerDeclare(
AA(
"aux_parseevent"));
589 Comment(
"enabled events that can be executed");
590 EventSetDeclare(
AA(
"aux_executables"));
593 Comment(
"aux maths and stack variables ");
594 WordDeclare(
AA(
"aux_wordret"));
596 BooleanDeclare(
AA(
"aux_edge"));
599 IntegerDeclare(
AA(
"aux_wordaddr"));
600 IntegerDeclare(
AA(
"aux_bitaddr"));
603 WordDeclare(
AA(
"aux_bitmask"));
612 for(
size_t git=0; git<
Size(); ++git) {
613 const Generator& gen =
At(git);
614 Comment(
"generator [" + gen.Name() +
"]");
617 std::vector< int > statevect(gen.MaxStateIndex(),0);
618 IndexSet::Iterator sit= gen.StatesBegin();
619 for(;sit!=gen.StatesEnd();++sit)
622 CintarrayDeclare(
AA(
"generator_states").Sub(git),1,statevect);
646 std::vector<std::string> evlookup;\
648 faudes::EventSet::Iterator eit=
mUsedEvents.Begin();
651 if(((
int) evlookup.size())<tidx) evlookup.resize(tidx);
654 Comment(
"event name lookup table");
655 CstrarrayDeclare(
AA(
"event_lookup"),1,evlookup);
662 for(
size_t gid=0; gid<
Size(); ++gid) {
664 const faudes::Generator& gen=
At(gid);
665 std::vector<std::string> stlookup;\
666 faudes::StateSet::Iterator sit=gen.StatesBegin();
667 for(;sit!=gen.StatesEnd();++sit) {
669 if(((
int) stlookup.size())<tidx) stlookup.resize(tidx);
670 std::string name=gen.StateName(*sit);
671 if(name==
"") name=
"#"+ToStringInteger(tidx);
672 stlookup[tidx-1]=name;
675 Comment(
"state name lookup for generator [" +
At(gid).
Name() +
"]");
676 CstrarrayDeclare(
AA(
"state_lookup").Sub(gid),1,stlookup);
684 Comment(
"************************************************");
685 Comment(
"* reset internal state *");
687 Comment(
"set internal reset flag");
690 IntegerAssign(
AA(
"exec_event"),-1);
695 IfTrue(IntegerIsEq(
AA(
"exec_event"),-1));
697 IntegerAssign(
AA(
"status"),0);
699 for(Idx gid=0; gid<
Size(); gid++) {
704 statevar=
AA(
"parallel_state").Sub(gid);
707 Comment(
"clear scheduled event");
708 IntegerAssign(
AA(
"sched_event"),0);
710 IntegerAssign(
AA(
"recent_event"),0);
711 Comment(
"clear pending/enabled events");
712 EventSetClear(
AA(
"pending_events"));
713 EventSetClear(
AA(
"enabled_events"));
718 TimerStop(
AA(tit->second.mAddress));
719 TimerReset(
AA(tit->second.mAddress) ,tit->second.mInitialValue);
730 Comment(
"************************************************");
731 Comment(
"* bail out on external reset *");
748 Comment(
"************************************************");
749 Comment(
"* sense input events *");
752 EventSet::Iterator eit;
757 Comment(
"init: reset all line data and generate statics");
758 IfTrue(IntegerIsEq(
AA(
"exec_event"),-1));
761 AA baddr =
AA(
"line_level").Sub(lit->second.mBitAddress);
762 BooleanAssign(baddr,ReadInputLine(
AA(lit->second.mAddress)));
763 if(lit->second.mPosStatics.Empty() && lit->second.mNegStatics.Empty())
continue;
764 if(!lit->second.mPosStatics.Empty())
766 eit=lit->second.mPosStatics.Begin();
767 for(;eit!=lit->second.mPosStatics.End();++eit) {
769 EventSetInsert(
AA(
"pending_events"),*eit);
771 if(!lit->second.mPosStatics.Empty())
772 if(lit->second.mNegStatics.Empty())
774 if(!lit->second.mPosStatics.Empty())
775 if(!lit->second.mNegStatics.Empty())
777 if(lit->second.mPosStatics.Empty())
778 if(!lit->second.mNegStatics.Empty())
780 eit=lit->second.mNegStatics.Begin();
781 for(;eit!=lit->second.mNegStatics.End();++eit) {
783 EventSetInsert(
AA(
"pending_events"),*eit);
785 if(!lit->second.mNegStatics.Empty())
790 Comment(
"normal operation: read lines and detect edges");
791 IfTrue(IntegerIsNotEq(
AA(
"exec_event"),-1));
794 AA baddr =
AA(
"line_level").Sub(lit->second.mBitAddress);
795 Comment(
"read line [" + lit->second.mAddress +
"]");
796 BooleanAssign(
AA(
"aux_edge"),ReadInputLine(lit->second.mAddress));
797 IfTrue(BooleanIsNotEq(
AA(
"aux_edge"),baddr));
798 if(!lit->second.mPosEvents.Empty()) {
800 eit=lit->second.mPosEvents.Begin();
801 for(;eit!=lit->second.mPosEvents.End();++eit) {
803 EventSetInsert(
AA(
"pending_events"),*eit);
804 IntegerAssign(
AA(
"sched_event"),0);
808 if(!lit->second.mNegEvents.Empty()) {
810 eit=lit->second.mNegEvents.Begin();
811 for(;eit!=lit->second.mNegEvents.End();++eit) {
813 EventSetInsert(
AA(
"pending_events"),*eit);
814 IntegerAssign(
AA(
"sched_event"),0);
829 Comment(
"testing flag [" + fit->second.mAddress +
"]");
830 IfTrue(InputExpression(fit->second.mAddress));
831 eit=fit->second.mEvents.Begin();
832 for(;eit!=fit->second.mEvents.End();++eit) {
834 EventSetInsert(
AA(
"pending_events"),*eit);
835 IntegerAssign(
AA(
"sched_event"),0);
850 Comment(
"************************************************");
851 Comment(
"* sense timer elapse *");
856 IfTrue(TimerIsElapsed(
AA(tit->second.mAddress)));
857 TimerStop(
AA(tit->second.mAddress));
858 EventSetInsert(
AA(
"pending_events"),
EventIndex(tit->second.mElapseEvent));
859 IntegerAssign(
AA(
"sched_event"),0);
869 Comment(
"************************************************");
870 Comment(
"* event execution loop *");
872 Comment(
"clear status to waiting");
873 IntegerAssign(
AA(
"status"),0);
875 IntegerAssign(
AA(
"recent_event"),0);
877 BooleanAssign(
AA(
"first_loop"),
true);
886 Comment(
"************************************************");
887 Comment(
"* update enabled events after execution *");
890 Comment(
"if event was executed (and on initialisation)");
891 IfTrue(IntegerIsNotEq(
AA(
"exec_event"),0));
893 EventSetFull(
AA(
"enabled_events"));
896 for(Idx gid=0; gid<
Size(); gid++) {
897 Comment(
"restricting enabled events by [" +
At(gid).
Name() +
"]");
902 statevar=
AA(
"parallel_state").Sub(gid);
903 SwitchBegin(statevar);
905 StateSet::Iterator sit;
906 for(sit=
At(gid).StatesBegin(); sit!=
At(gid).StatesEnd(); sit++) {
907 EventSet disset=
At(gid).Alphabet();
908 disset.EraseSet(
At(gid).ActiveEventSet(*sit));
909 if(disset.Empty())
continue;
910 SwitchCase(statevar,*sit);
911 EventSetErase(
AA(
"enabled_events"),disset);
918 IntegerAssign(
AA(
"exec_event"),0);
919 IntegerAssign(
AA(
"sched_event"),0);
928 FCG_ERR(
"CodePrimitives::UpdateEnabledByInterpreter(): vector representation not available");
929 Comment(
"************************************************");
930 Comment(
"* update enabled events after execution *");
933 Comment(
"if event was executed (and on init)");
934 IfTrue(IntegerIsNotEq(
AA(
"exec_event"),0));
944 statevar=
AA(
"parallel_state").Sub(0);
945 AA gentrans=
AA(
"generator_transitions").Sub(0);
946 AA genstates=
AA(
"generator_states").Sub(0);
947 EventSetAssign(
AA(
"enabled_events"),empty);
951 IntegerAssign(
AA(
"aux_parsetrans"),
TargetExpression(CintarrayAccess(genstates,statevar)));
954 IntegerAssign(
AA(
"aux_parseevent"),
TargetExpression(CintarrayAccess(gentrans,
AA(
"aux_parsetrans"))));
955 LoopBreak(IntegerIsEq(
AA(
"aux_parseevent"),0));
956 EventSetInsert(
AA(
"enabled_events"),
AA(
"aux_parseevent"),
At(0).
Alphabet());
957 IntegerIncrement(
AA(
"aux_parsetrans"),2);
967 for(Idx gid=0; gid<
Size(); gid++) {
973 statevar=
AA(
"parallel_state").Sub(gid);
974 AA gentrans=
AA(
"generator_transitions").Sub(gid);
975 AA genstates=
AA(
"generator_states").Sub(gid);
980 IntegerAssign(
AA(
"aux_parsetrans"),
TargetExpression(CintarrayAccess(genstates,statevar)));
983 IntegerAssign(
AA(
"aux_parseevent"),
TargetExpression(CintarrayAccess(gentrans,
AA(
"aux_parsetrans"))));
984 LoopBreak(IntegerIsEq(
AA(
"aux_parseevent"),0));
985 EventSetInsert(
AA(
"aux_locenabled"),
AA(
"aux_parseevent"),
At(gid).
Alphabet());
986 IntegerIncrement(
AA(
"aux_parsetrans"),2);
988 Comment(
"restrict enabled events");
989 EventSetRestrict(
AA(
"enabled_events"),
AA(
"aux_locenabled"));
994 IntegerAssign(
AA(
"exec_event"),0);
995 IntegerAssign(
AA(
"sched_event"),0);
1011 Comment(
"************************************************");
1012 Comment(
"* schedule next event to execute *");
1014 IfTrue(IntegerIsEq(
AA(
"sched_event"),0));
1016 Comment(
"setup candidate set to \"pending or internal\"");
1018 Comment(
"restrict candidate set by \"enabled\"");
1019 EventSetRestrict(
AA(
"aux_executables"),
AA(
"enabled_events"));
1021 Comment(
"find highest priority event (lowest bitaddress)");
1022 EventSetFindHighestPriority(
AA(
"aux_executables"),
AA(
"sched_event"));
1024 Comment(
"remove scheduled event from pending events");
1025 IfTrue(IntegerIsGreater(
AA(
"sched_event"),0));
1026 EventSetErase(
AA(
"pending_events"),
AA(
"sched_event"));
1030 IfTrue(IntegerIsEq(
AA(
"sched_event"),0));
1031 EventSetIsNotEmpty(
AA(
"pending_events"),
AA(
"aux_wordret"));
1032 IfTrue(WordIsNotEq(
AA(
"aux_wordret"),0));
1033 WordOr(
AA(
"status"),WordConstant(0x02));
1038 Comment(
"cancel pending events if no event could be scheduled ");
1039 IfTrue(IntegerIsEq(
AA(
"sched_event"),0));
1040 EventSetClear(
AA(
"pending_events"));
1052 Comment(
"************************************************");
1053 Comment(
"* break execution loop *");
1055 LoopBreak(IntegerIsEq(
AA(
"sched_event"),0));
1060 LoopBreak(IntegerIsGreater(
AA(
"sched_event"),max));
1063 BooleanAssign(
AA(
"first_loop"),
false);
1070 FCG_ERR(
"CodePrimitives::InsertExecHooks(): no hooks supported by target platform");
1076 Comment(
"************************************************");
1077 Comment(
"* execute scheduled event *");
1079 IfTrue(IntegerIsNotEq(
AA(
"sched_event"),0));
1082 IntegerAssign(
AA(
"sched_event"),0);
1083 WordOr(
AA(
"status"),WordConstant(0x01));
1085 for(Idx gid=0; gid<
Size(); gid++) {
1092 statevar=
AA(
"parallel_state").Sub(gid);
1093 SwitchBegin(statevar);
1094 StateSet::Iterator sit;
1095 for(sit=
At(gid).StatesBegin(); sit!=
At(gid).StatesEnd(); sit++) {
1097 SwitchCase(statevar,*sit);
1099 std::map< int , int > casedata;
1100 std::set< std::set< int > > casesets;
1101 TransSet::Iterator tit;
1102 for(tit=
At(gid).TransRelBegin(*sit); tit!=
At(gid).TransRelEnd(*sit); tit++)
1104 ConsolidateCaseSets<int>(casedata,casesets);
1106 SwitchBegin(
AA(
"exec_event"));
1107 std::set< std::set<int> >::iterator cit=casesets.begin();
1108 for(; cit!=casesets.end(); ++cit) {
1109 SwitchCases(
AA(
"exec_event"),*cit);
1110 IntegerAssign(statevar,casedata[*cit->begin()]);
1131 Comment(
"************************************************");
1132 Comment(
"* execute scheduled event *");
1135 FCG_ERR(
"CodePrimitives::ExecuteByInterpreter(): vector representation not available");
1138 IfTrue(IntegerIsNotEq(
AA(
"sched_event"),0));
1141 IntegerAssign(
AA(
"sched_event"),0);
1142 WordOr(
AA(
"status"),WordConstant(0x01));
1144 for(Idx gid=0; gid<
Size(); gid++) {
1151 statevar=
AA(
"parallel_state").Sub(gid);
1152 AA gentrans=
AA(
"generator_transitions").Sub(gid);
1153 AA genstates=
AA(
"generator_states").Sub(gid);
1158 IntegerAssign(
AA(
"aux_parsetrans"),
TargetExpression(CintarrayAccess(genstates,statevar)));
1161 IntegerAssign(
AA(
"aux_parseevent"),
TargetExpression(CintarrayAccess(gentrans,
AA(
"aux_parsetrans"))));
1163 LoopBreak(IntegerIsEq(
AA(
"aux_parseevent"),0));
1164 IntegerIncrement(
AA(
"aux_parsetrans"),2);
1166 IfTrue(IntegerIsGreater(
AA(
"aux_parseevent"),0));
1167 IntegerIncrement(
AA(
"aux_parsetrans"));
1168 IntegerAssign(statevar,
TargetExpression(CintarrayAccess(gentrans,
AA(
"aux_parsetrans"))));
1194 Comment(
"************************************************");
1195 Comment(
"* operate timers *");
1198 std::map< int , TimerAction> casedata;
1199 std::set< std::set< int > > casesets;
1206 casedata[tev]= eit->second;
1208 ConsolidateCaseSets<TimerAction>(casedata,casesets);
1210 IfTrue(IntegerIsGreater(
AA(
"exec_event"),0));
1212 SwitchBegin(
AA(
"exec_event"));
1214 std::set< std::set< int > >::iterator cit;
1215 for(cit=casesets.begin(); cit!=casesets.end(); ++cit) {
1216 SwitchCases(
AA(
"exec_event"),*cit);
1218 std::set< std::string >::iterator ait;
1221 TimerStop(
AA(*ait));
1227 FCG_ERR(
"CodePrimitives: internal error on timer records -- sorry");
1229 TimerReset(
AA(*ait),tit->second.mInitialValue);
1233 TimerStart(
AA(*ait));
1245 Comment(
"************************************************");
1246 Comment(
"* operate outputs *");
1252 SwitchBegin(
AA(
"exec_event"));
1254 const std::vector<AttributeCodeGeneratorEvent::OutputAction>& actions =
mAlphabet.Attribute(*eit).mActions;
1255 if(actions.size()==0)
continue;
1258 for(
size_t i=0; i<actions.size(); i++) {
1259 if(actions[i].mSet) RunActionSet(actions[i].mAddress);
1260 if(actions[i].mClr) RunActionClr(actions[i].mAddress);
1261 if(actions[i].mExe) RunActionExe(
AX(actions[i].mAddress));
1276 Comment(
"************************************************");
1277 Comment(
"* end execution loop *");
1288 Comment(
"************************************************");
1289 Comment(
"* append code snippet from configuration *");
1298 FD_DCG(
"CodePrimitives(" <<
this <<
")::DoGenerateDeclarations()");
1299 Comment(
"************************************************");
1300 Comment(
"* declaration of variables and constants *");
1318 FD_DCG(
"CodePrimitives(" <<
this <<
")::DoGenerateResetCode()");
1319 Comment(
"************************************************");
1320 Comment(
"* executor core cyclic code: reset/initialise *");
1321 Comment(
"************************************************");
1330 FD_DCG(
"CodePrimitives(" <<
this <<
")::DoGenerateCyclicCode()");
1331 Comment(
"************************************************");
1332 Comment(
"* executor core cyclic code: begin *");
1333 Comment(
"************************************************");
1346 Comment(
"************************************************");
1347 Comment(
"* executor core cyclic code: end *");
1348 Comment(
"************************************************");
1387 FCG_ERR(
"CodePrimitives::VariableDeclare(): not implemented");
1395 FCG_ERR(
"CodePrimitives::VariableDeclare(): not implemented");
1399 void CodePrimitives::IntegerDecrement(
const AA& address,
int val) {
1400 IntegerIncrement(address,-val);
1407 FCG_ERR(
"CodePrimitives::Integer(): maths not available");
1413 FCG_ERR(
"CodePrimitives::Integer(): maths not available");
1418 FCG_ERR(
"CodePrimitives::Integer(): maths not available");
1421 bool CodePrimitives::HasIntmaths(
void) {
1427 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
1430 CodePrimitives::AX CodePrimitives::IntegerIsEq(
const AA& address,
const AX& expression) {
1433 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
1439 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
1442 CodePrimitives::AX CodePrimitives::IntegerIsNotEq(
const AA& address,
const AX& expression) {
1445 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
1451 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
1457 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
1463 void CodePrimitives::WordDeclare(
const AA& address) {
1465 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1467 void CodePrimitives::WordDeclare(
const AA& address, word_t val) {
1470 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1472 void CodePrimitives::WordAssign(
const AA& address, word_t val) {
1475 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1477 void CodePrimitives::WordAssign(
const AA& address,
const AX& expression) {
1480 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1482 void CodePrimitives::WordOr(
const AA& address, word_t val) {
1485 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1487 void CodePrimitives::WordOr(
const AA& address,
const AX& expression) {
1490 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1492 void CodePrimitives::WordOr(
const AA& address,
const AA& op1,
const AA& op2) {
1496 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1498 void CodePrimitives::WordOr(
const AA& address,
const AA& op1, word_t op2) {
1502 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1504 void CodePrimitives::WordAnd(
const AA& address, word_t val) {
1507 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1509 void CodePrimitives::WordAnd(
const AA& address,
const AX& expression) {
1512 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1514 void CodePrimitives::WordAnd(
const AA& address,
const AA& op1,
const AA& op2) {
1518 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1520 void CodePrimitives::WordAnd(
const AA& address,
const AA& op1, word_t op2) {
1524 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1526 void CodePrimitives::WordNand(
const AA& address,
const AX& expression) {
1529 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1534 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
1540 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
1546 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
1552 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
1558 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
1563 FCG_ERR(
"CodePrimitives::Word(): word-of-bits type not available");
1569 void CodePrimitives::BooleanDeclare(
const AA& address) {
1570 IntegerDeclare(address);
1572 void CodePrimitives::BooleanDeclare(
const AA& address,
int val) {
1573 IntegerDeclare(address,val ? 1 : 0);
1575 void CodePrimitives::BooleanAssign(
const AA& address,
const AX& expression) {
1576 IntegerAssign(address,expression);
1578 void CodePrimitives::BooleanAssign(
const AA& address,
int val) {
1579 IntegerAssign(address, val ? 1 : 0);
1593 void CodePrimitives::CintarrayDeclare(
const AA& address,
int offset,
const std::vector<int>& val) {
1597 FCG_ERR(
"CodePrimitives::Cintarray(): constant-int-arrays not defined");
1602 FCG_ERR(
"CodePrimitives::Cintarray(): constant-int-arrays not defined");
1605 CodePrimitives::AA CodePrimitives::CintarrayAccess(
const AA& address,
const AA& indexaddr){
1608 FCG_ERR(
"CodePrimitives::Cintarray(): constant-int-arrays not defined");
1611 bool CodePrimitives::HasCintarray(
void) {
1616 void CodePrimitives::CwordarrayDeclare(
const AA& address,
int offset,
const std::vector<word_t>& val) {
1620 FCG_ERR(
"CodePrimitives::Cwordarray(): constant-word-arrays not defined");
1625 FCG_ERR(
"CodePrimitives::Cwordarray(): constant-word-arrays not defined");
1628 CodePrimitives::AA CodePrimitives::CwordarrayAccess(
const AA& address,
const AA& indexaddr){
1631 FCG_ERR(
"CodePrimitives::Cwordarray(): constant-word-arrays not defined");
1634 bool CodePrimitives::HasCwordarray(
void) {
1640 void CodePrimitives::WordarrayDeclare(
const AA& address,
int offset,
int len) {
1644 FCG_ERR(
"CodePrimitives::Wordarray(): word-arrays not available");
1646 void CodePrimitives::WordarrayDeclare(
const AA& address,
int offset,
const std::vector<word_t>& val) {
1650 FCG_ERR(
"CodePrimitives::Wordarray(): word-arrays not available");
1655 FCG_ERR(
"CodePrimitives::Wordarray(): word-arrays not available");
1658 CodePrimitives::AA CodePrimitives::WordarrayAccess(
const AA& address,
const AA& indexaddr){
1661 FCG_ERR(
"CodePrimitives::Wordarray(): word-arrays not available");
1664 bool CodePrimitives::HasWordarray(
void) {
1674 FCG_ERR(
"CodePrimitives::Intarray(): int-arrays not available");
1680 FCG_ERR(
"CodePrimitives::Intarray(): int-arrays not available");
1685 FCG_ERR(
"CodePrimitives::Intarray(): int-arrays not available");
1691 FCG_ERR(
"CodePrimitives::Intarray(): int-arrays not available");
1701 FCG_ERR(
"CodePrimitives::Cstrarray(): constant-str-arrays not defined");
1704 void CodePrimitives::CstrarrayDeclare(
const AA& address,
int offset,
const std::vector<std::string>& val) {
1708 FCG_ERR(
"CodePrimitives::Cstrarray(): constant-str-arrays not defined");
1713 FCG_ERR(
"CodePrimitives::Cstrarray(): constant-str-arrays not defined");
1716 CodePrimitives::AA CodePrimitives::CstrarrayAccess(
const AA& address,
const AA& indexaddr){
1719 FCG_ERR(
"CodePrimitives::Cstrarray(): constant-str-arrays not defined");
1722 bool CodePrimitives::HasCstrarray(
void) {
1728 void CodePrimitives::BitarrayDeclare(
const AA& address,
int blen) {
1733 WordarrayDeclare(address, 0, wlen);
1737 for(
int i=0; i<wlen; i++) {
1738 AA baddr= address.Sub(i);
1743 bitarray_rec newbitarray;
1744 newbitarray.blen= blen;
1749 void CodePrimitives::BitarrayDeclare(
const AA& address,
const std::vector<bool>& val) {
1751 int blen = (int) val.size();
1759 for(
int i=0; i<wlen; i++) {
1760 AA baddr = address.Sub(i);
1765 bitarray_rec newbitarray;
1766 newbitarray.blen= blen;
1767 newbitarray.value= val;
1772 void CodePrimitives::BitarrayAssign(
const AA& address,
const std::vector<bool>& val) {
1777 for(
int i=0; i<wlen; ++i) {
1780 else waddr = address.Sub(i);
1782 WordAssign(waddr,wval);
1787 void CodePrimitives::BitarrayAssign(
const AA& address,
const AA& otherarray) {
1793 FCG_ERR(
"CodePrimitives(): BitarrayAssign(): internal error");
1796 for(
int i=0; i<wlen; ++i) {
1799 else waddr = address.Sub(i);
1802 else oaddr = address.Sub(i);
1808 void CodePrimitives::BitarrayClear(
const AA& address){
1813 for(
int i=0; i<wlen; i++) {
1816 else waddr = address.Sub(i);
1817 WordAssign(waddr, 0x0UL);
1822 void CodePrimitives::BitarrayFull(
const AA& address){
1826 int bllen = blen - (wlen-1) *
mWordSize;
1828 for(
int i=0; i<wlen; i++) {
1831 else waddr = address.Sub(i);
1833 if(i==wlen-1) val= (1ULL<<bllen)-1;
1834 WordAssign(waddr, val);
1839 void CodePrimitives::BitarrayOrAllWords(
const AA& address,
const AA& result) {
1843 int bllen = blen - (wlen-1) *
mWordSize;
1848 else waddr = address.Sub(0);
1853 for(
int i=0; i<wlen; i++) {
1856 else waddr = address.Sub(i);
1857 if(i==wlen-1) WordAnd(waddr,WordConstant((1ULL<<bllen)-1));
1864 void CodePrimitives::BitarraySetBit(
const AA& address,
int index){
1871 else waddr = address.Sub(windex);
1872 WordOr(waddr,WordConstant( 1UL << bindex));
1876 void CodePrimitives::BitarraySetBit(
const AA& address,
const AA& indexaddr,
int offset,
const std::vector<bool>& hint){
1880 bool gotaddress=
false;
1884 IntegerDecrement(AA(
"aux_bitaddr"));
1885 IntegerAssign(AA(
"aux_wordaddr"),
TargetExpression(CintarrayAccess(AA(
"wordaddr_vector"),AA(
"aux_bitaddr"))));
1886 IntegerAssign(AA(
"aux_bitmask"),
TargetExpression(CwordarrayAccess(AA(
"bitmask_vector"),AA(
"aux_bitaddr"))));
1892 IntegerDecrement(AA(
"aux_bitaddr"),offset);
1895 IntegerAssign(AA(
"aux_bitmask"),IntegerBitmask(
TargetExpression(AA(
"aux_bitaddr"))));
1901 IntegerDecrement(AA(
"aux_bitaddr"),offset);
1902 IntegerAssign(AA(
"aux_bitmask"),
TargetExpression(CwordarrayAccess(AA(
"bitmask_vector"),AA(
"aux_bitaddr"))));
1908 IntegerDecrement(AA(
"aux_bitaddr"),offset);
1911 IntegerAssign(AA(
"aux_bitmask"),IntegerBitmask(
TargetExpression(AA(
"aux_bitaddr"))));
1916 WordOr(WordarrayAccess(address, AA(
"aux_wordaddr")),
TargetExpression(AA(
"aux_bitmask")));
1920 if(gotaddress && (wlen > 1)) {
1921 SwitchBegin(AA(
"aux_wordaddr"));
1922 for(
int i=0; i<wlen; i++) {
1925 SwitchCase(AA(
"aux_wordadd"),i);
1926 AA waddr = address.Sub(i);
1934 if(gotaddress && (wlen == 1)) {
1935 AA waddr = address.Sub(0);
1940 SwitchBegin(indexaddr);
1942 for(baddr=0;baddr<blen;baddr++) {
1946 SwitchCase(indexaddr,baddr+offset);
1947 BitarraySetBit(address,baddr);
1954 void CodePrimitives::BitarrayIsBitSet(
const AA& address,
const AA& indexaddr,
const AA& result,
int offset,
const std::vector<bool>& hint){
1958 bool gotaddress=
false;
1962 IntegerDecrement(AA(
"aux_bitaddr"),offset);
1963 IntegerAssign(AA(
"aux_wordaddr"),
TargetExpression(CintarrayAccess(AA(
"wordaddr_vector"),AA(
"aux_bitaddr"))));
1964 IntegerAssign(AA(
"aux_bitmask"),
TargetExpression(CwordarrayAccess(AA(
"bitmask_vector"),AA(
"aux_bitaddr"))));
1970 IntegerDecrement(AA(
"aux_bitaddr"),offset);
1973 IntegerAssign(AA(
"aux_bitmask"),IntegerBitmask(
TargetExpression(AA(
"aux_bitaddr"))));
1979 IntegerDecrement(AA(
"aux_bitaddr"),offset);
1980 IntegerAssign(AA(
"aux_bitmask"),
TargetExpression(CwordarrayAccess(AA(
"bitmask_vector"),AA(
"aux_bitaddr"))));
1986 IntegerDecrement(AA(
"aux_bitaddr"),offset);
1989 IntegerAssign(AA(
"aux_bitmask"),IntegerBitmask(
TargetExpression(AA(
"aux_bitaddr"))));
1994 WordAnd(result,WordarrayAccess(address, AA(
"aux_wordaddr")),AA(
"aux_bitmask"));
1997 if(gotaddress && (wlen > 1)) {
1998 SwitchBegin(AA(
"aux_wordaddr"));
1999 for(
int i=0; i<wlen; i++) {
2002 SwitchCase(AA(
"aux_wordadd"),i);
2003 AA waddr = address.Sub(i);
2004 WordAnd(result,waddr,AA(
"aux_bitmask"));
2011 if(gotaddress && (wlen == 1)) {
2012 AA waddr = address.Sub(0);
2013 WordAnd(result,waddr,AA(
"aux_bitmask"));
2017 FCG_ERR(
"CodePrimitives::Bitarray(): BitAddressArithmetic or ArrayForBitmasks required for test by variable");
2021 void CodePrimitives::BitarrayClrBit(
const AA& address,
int index){
2028 else waddr = address.Sub(windex);
2029 WordNand(waddr,WordConstant( 1UL << bindex));
2033 void CodePrimitives::BitarrayClrBit(
const AA& address,
const AA& indexaddr,
int offset,
const std::vector<bool>& hint){
2037 bool gotaddress=
false;
2041 IntegerDecrement(AA(
"aux_bitaddr"),offset);
2042 IntegerAssign(AA(
"aux_wordaddr"),
TargetExpression(CintarrayAccess(AA(
"wordaddr_vector"),AA(
"aux_bitaddr"))));
2043 IntegerAssign(AA(
"aux_bitmask"),
TargetExpression(CwordarrayAccess(AA(
"bitmask_vector"),AA(
"aux_bitaddr"))));
2049 IntegerDecrement(AA(
"aux_bitaddr"),offset);
2052 IntegerAssign(AA(
"aux_bitmask"),IntegerBitmask(
TargetExpression(AA(
"aux_bitaddr"))));
2058 IntegerDecrement(AA(
"aux_bitaddr"),offset);
2059 IntegerAssign(AA(
"aux_bitmask"),
TargetExpression(CwordarrayAccess(AA(
"bitmask_vector"),AA(
"aux_bitaddr"))));
2065 IntegerDecrement(AA(
"aux_bitaddr"),offset);
2068 IntegerAssign(AA(
"aux_bitmask"),IntegerBitmask(
TargetExpression(AA(
"aux_bitaddr"))));
2073 WordNand(WordarrayAccess(address, AA(
"aux_wordaddr")),
TargetExpression(AA(
"aux_bitmask")));
2077 if(gotaddress && (wlen > 1)) {
2078 SwitchBegin(AA(
"aux_wordaddr"));
2079 for(
int i=0; i<wlen; i++) {
2082 SwitchCase(AA(
"aux_wordadd"),i);
2083 AA waddr = address.Sub(i);
2091 if(gotaddress && (wlen == 1)) {
2092 AA waddr = address.Sub(0);
2097 SwitchBegin(indexaddr);
2099 for(baddr=0;baddr<blen;baddr++) {
2103 SwitchCase(indexaddr,baddr+offset);
2104 BitarrayClrBit(address,baddr);
2111 void CodePrimitives::BitarrayOr(
const AA& address,
const std::vector<bool>& val) {
2116 for(
int w=0; w<wlen; ++w) {
2118 if(wval==0)
continue;
2121 else waddr = address.Sub(w);
2128 void CodePrimitives::BitarrayOr(
const AA& address,
const AA &op1,
const std::vector<bool>& op2) {
2133 for(
int w=0; w<wlen; ++w) {
2138 else waddr = address.Sub(w);
2140 else wop1 = op1.Sub(w);
2142 WordOr(waddr,wop1,wval);
2149 void CodePrimitives::BitarrayAnd(
const AA& address,
const std::vector<bool>& val) {
2154 for(
int w=0; w<wlen; ++w) {
2156 if(wval== (1UL <<
mWordSize) - 1)
continue;
2159 else waddr = address.Sub(w);
2160 WordAnd(waddr,wval);
2165 void CodePrimitives::BitarrayAnd(
const AA& address,
const AA& otherarray) {
2170 for(
int w=0; w<wlen; ++w) {
2173 else waddr = address.Sub(w);
2176 else oaddr = otherarray.Sub(w);
2182 void CodePrimitives::BitarrayAnd(
const AA& address,
const AA &op1,
const std::vector<bool>& op2) {
2187 for(
int w=0; w<wlen; ++w) {
2192 else waddr = address.Sub(w);
2194 else wop1 = op1.Sub(w);
2196 WordAnd(waddr,wop1,wval);
2203 void CodePrimitives::BitarrayAnd(
const AA& address,
const AA& op1,
const AA& op2) {
2208 for(
int w=0; w<wlen; ++w) {
2211 else waddr = address.Sub(w);
2214 else op1addr = op1.Sub(w);
2217 else op2addr = op2.Sub(w);
2218 WordAnd(waddr,op1addr,op2addr);
2223 void CodePrimitives::BitarrayFindFirst(
const AA& address,
const AA& result,
int offset) {
2225 IntegerAssign(result,offset-1);
2232 else waddr = address.Sub(w);
2236 IfTrue(IntegerIsEq(result,offset-1));
2240 IfTrue(WordIsNotEq(waddr,0));
2244 IntegerAssign(result,w*
mWordSize+offset);
2245 for(;ifcnt>0;--ifcnt) IfEnd();
2252 if(index>=blen)
break;
2254 IfTrue(WordIsBitSet(waddr,b));
2257 IfElseIfTrue(WordIsBitSet(waddr,b));
2259 IntegerAssign(result,index+offset);
2266 if(bleft>wsize) bleft=wsize;
2267 while(wsize/2>=bleft) wsize=wsize/2;
2271 while(size<=wsize) {
2273 if(!(pos<bleft))
break;
2277 while(pos+size/2>=bleft) size=size/2;
2282 if(hl && (size>2)) {
2283 word_t ltest= (1UL << size/2) -1;
2285 IfTrue(WordIsMaskSet(waddr,ltest));
2291 if(hl && (size==2)) {
2292 IfTrue(WordIsMaskSet(waddr,(1UL << pos)));
2293 IntegerAssign(result, w*
mWordSize + pos + offset);
2295 IntegerAssign(result,w*
mWordSize + pos + 1 + offset);
2302 if(hl && (size==1)) {
2303 IntegerAssign(result, w*
mWordSize + pos + offset);
2309 if((!hl) && ((pos % size) == 0)) {
2313 if(pos<bleft) IfElse();
2317 if((!hl) && ((pos % size) != 0)) {
2326 for(;ifcnt>0;--ifcnt)
2333 void CodePrimitives::EventSetDeclare(
const AA& address) {
2338 void CodePrimitives::EventSetDeclare(
const AA& address,
const EventSet& evset) {
2340 BitarrayDeclare(address,evmask);
2344 void CodePrimitives::EventSetClear(
const AA& address) {
2345 BitarrayClear(address);
2349 void CodePrimitives::EventSetFull(
const AA& address) {
2350 BitarrayFull(address);
2354 void CodePrimitives::EventSetIsNotEmpty(
const AA& address,
const AA& result) {
2355 BitarrayOrAllWords(address,result);
2359 void CodePrimitives::EventSetAssign(
const AA& address,
const EventSet& evset) {
2361 BitarrayAssign(address,evmask);
2365 void CodePrimitives::EventSetInsert(
const AA& address,
const EventSet& evset) {
2367 BitarrayOr(address,evmask);
2371 void CodePrimitives::EventSetInsert(
const AA& address,
const AA& evaddrexpr) {
2372 BitarraySetBit(address,evaddrexpr,1);
2376 void CodePrimitives::EventSetInsert(
const AA& address,
const AA& evaddrexpr,
const EventSet& hint) {
2378 BitarraySetBit(address,evaddrexpr,1,evmask);
2382 void CodePrimitives::EventSetInsert(
const AA& address, Idx ev) {
2387 void CodePrimitives::EventSetErase(
const AA& address,
const EventSet& evset) {
2389 for(
size_t i=0; i<evmask.size(); i++) evmask[i]= ! evmask[i];
2390 BitarrayAnd(address,evmask);
2394 void CodePrimitives::EventSetErase(
const AA& address, Idx ev) {
2399 void CodePrimitives::EventSetErase(
const AA& address,
const AA& evaddr) {
2400 BitarrayClrBit(address,evaddr,1);
2404 void CodePrimitives::EventSetExists(
const AA& address,
const AA& evaddr,
const AA& result,
const EventSet& hint) {
2406 BitarrayIsBitSet(address,evaddr,result,1,evmask);
2410 void CodePrimitives::EventSetErase(
const AA& address,
const AA& evaddr,
const EventSet& hint) {
2412 BitarrayClrBit(address,evaddr,1,evmask);
2416 void CodePrimitives::EventSetRestrict(
const AA& address,
const AA& otherset) {
2417 BitarrayAnd(address,otherset);
2421 void CodePrimitives::EventSetUnion(
const AA& address,
const AA& op1,
const EventSet& op2) {
2423 BitarrayOr(address,op1,evmask);
2427 void CodePrimitives::EventSetIntersection(
const AA& address,
const AA& op1,
const EventSet& op2) {
2429 BitarrayAnd(address,op1,evmask);
2433 void CodePrimitives::EventSetFindHighestPriority(
const AA& address,
const AA& result) {
2434 BitarrayFindFirst(address,result,1);
2440 void CodePrimitives::IfTrue(
const AX& expression) {
2442 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
2445 void CodePrimitives::IfFalse(
const AX& expression) {
2447 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
2450 void CodePrimitives::IfWord(
const AX& expression) {
2452 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
2454 void CodePrimitives::IfElse(
void) {
2455 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
2458 void CodePrimitives::IfElseIfTrue(
const AX& expression) {
2460 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
2462 void CodePrimitives::IfEnd(
void) {
2463 FCG_ERR(
"CodePrimitives::Conditionals(): construct not available");
2465 void CodePrimitives::LoopBegin(
void) {
2466 FCG_ERR(
"CodePrimitives::Loops(): construct not available");
2468 void CodePrimitives::LoopBreak(
const AX& expression) {
2470 FCG_ERR(
"CodePrimitives::Loops(): construct not available");
2472 void CodePrimitives::LoopEnd(
void) {
2473 FCG_ERR(
"CodePrimitives::Loops(): construct not available");
2475 void CodePrimitives::FunctionReturn(
void) {
2476 FCG_ERR(
"CodePrimitives::FunctionReturn(): construct not available");
2480 void CodePrimitives::SwitchBegin(
const AA& address){
2482 FCG_ERR(
"CodePrimitives::Conditionals(): switch not available");
2484 void CodePrimitives::SwitchCase(
const AA& address,
int val){
2487 FCG_ERR(
"CodePrimitives::Conditionals(): switch not available");
2489 void CodePrimitives::SwitchCases(
const AA& address,
int from,
int to){
2493 FCG_ERR(
"CodePrimitives::Conditionals(): switch not available");
2495 void CodePrimitives::SwitchCases(
const AA& address,
const std::set< int > & vals){
2498 FCG_ERR(
"CodePrimitives::Conditionals(): switch not available");
2500 void CodePrimitives::SwitchBreak(
void){
2501 FCG_ERR(
"CodePrimitives::Conditionals(): switch not available");
2503 void CodePrimitives::SwitchEnd(
void){
2504 FCG_ERR(
"CodePrimitives::Conditionals(): switch not available");
2506 bool CodePrimitives::HasMultiCase(
void){
2512 void CodePrimitives::RunActionSet(
const std::string& address) {
2514 FCG_ERR(
"CodePrimitives::RunAction(): action not available");
2516 void CodePrimitives::RunActionClr(
const std::string& address) {
2518 FCG_ERR(
"CodePrimitives::RunAction(): action not available");
2520 void CodePrimitives::RunActionExe(
const AX& expression) {
2522 FCG_ERR(
"CodePrimitives::RunAction(): action not available");
2531 return AX(expression);
2536 void CodePrimitives::TimerDeclare(
const AA& address,
const std::string &litval) {
2539 FCG_ERR(
"CodePrimitives::Timer(): not available");
2541 void CodePrimitives::TimerStart(
const AA& address) {
2543 FCG_ERR(
"CodePrimitives::Timer(): not available");
2545 void CodePrimitives::TimerStop(
const AA& address) {
2547 FCG_ERR(
"CodePrimitives::Timer(): not available");
2549 void CodePrimitives::TimerReset(
const AA& address,
const std::string &litval) {
2552 FCG_ERR(
"CodePrimitives::Timer(): not available");
2556 FCG_ERR(
"CodePrimitives::Timer(): not available");
Code-generator with abstract types and operations.
Compiled record per event on how it affects timers.
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 EventName(Idx index) const
Faudes-event name lookup.
virtual void LineFeed(int lines=1)
LineFeed (convenience support for derived classes)
int EventBitAddress(Idx idx)
Get event bit-address from faudes Idx (consecutive, starts at 0)
LineIterator LinesEnd()
Access to line records by iterator.
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 DoReadTargetConfiguration(TokenReader &rTr)
Reads global configuration from TokenReader, excl.
std::map< std::string, LineAddress >::iterator LineIterator
Access to line records by iterator.
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)
FlagIterator FlagsBegin()
Access to flag records by iterator.
int EventBitMaskSize(void)
Get overall number of events.
TimerIterator TimersBegin()
Access to timer records by iterator.
virtual void IndentInc()
Indentation (convenience support for derived classes)
EventSet mOutputEvents
used events that are configured as outputs
TimerIterator TimersEnd()
Access to timer records by iterator.
Idx EventIndex(const std::string &rName) const
Faudes-event index lookup.
std::map< std::string, TimerConfiguration >::iterator TimerIterator
Access to timer records by iterator.
Idx EventFaudesIdx(int idx)
Get faudes Idx from target Idx (aka from bit-address + 1)
TimerActionIterator TimerActionsBegin()
Access to timer records by iterator.
int mWordSize
compressed boolean capacity of target type word
std::vector< TimedGenerator > mGenerators
list of executors
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 mIntegerSize
compressed boolean capacity of target type integer
FlagIterator FlagsEnd()
Access to flag records by iterator.
const cgEventSet & Alphabet(void) const
Access alphabet (incl event attributes)
virtual std::ostream & Output(void)
Output stream.
std::map< std::string, TimerAction > mTimerActions
timer actions by event name
std::map< std::string, FlagExpression >::iterator FlagIterator
Access to flag records by iterator.
std::vector< word_t > WordVectorFromBitVector(const std::vector< bool > &vect)
Convert boolean vector to word array.
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
cgEventSet mAlphabet
event configuration by attributes
virtual void Comment(const std::string &text)
Write a comment (reimplement in derived classes, call base)
word_t WordFromBitVector(const std::vector< bool > &vect, int wordindex)
Extract individual word from boolean vector.
virtual const std::string & Name(void) const
Get objects's name (reimplementing base faudes::Type)
virtual void Clear(void)
Clear all data.
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
const TimedGenerator & At(int i) const
Direct access for read-only access of generators.
virtual void IndentDec()
Indentation (convenience support for derived classes)
TimerActionIterator TimerActionsEnd()
Access to timer records by iterator.
virtual void DoWriteTargetConfiguration(TokenWriter &rTw) const
Write global configuration to TokenWriter, excl.
unsigned long word_t
Code-generator internal data type of target words.
EventSet mUsedEvents
configured events that are referred to by some generator
std::map< std::string, TimerAction >::iterator TimerActionIterator
Access to timer records by iterator.
Abstract address; see also Absstract_Addresses.
Abstract expression; see also Absstract_Addresses.
virtual void DeclareTimers(void)
Use target implementation to declare timers, typically "timer_run_*" and "timer_cnt_*".
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
virtual void DoGenerateDeclarations(void)
cut-and-paste template for code snippet assembly
virtual void DeclareSmallCarray(void)
Declare bit-mask loop-ups.
virtual void DoGenerateResetCode(void)
cut-and-paste template for code snippet assembly
bool mArrayForState
code option: use int arrays to represent that overall state
virtual void UpdateEnabledByInterpreter(void)
Alternative implementations UpdateEnabled()
virtual std::string TargetSymbol(const std::string &str)
Mangle string to valid target symbol.
virtual void ScheduleEvent(void)
Select event to execute from "pending_and_enabled_events" or "enabled_events".
virtual void DeclareReset(void)
Declare "reset".
virtual void LiteralAppend(void)
Cosmetic: append literally from configuration.
virtual void DeclareStatus(void)
Declare "status".
bool mArrayForBitarray
code option: use const array to represent bit-masks
std::string mLiteralPrepend
extra code to prepend
virtual void DeclareRecentEvent(void)
Declare "recent_event".
virtual void UpdateEnabledBySwitching(void)
Alternative implementations UpdateEnabled()
virtual void Comment(const std::string &text)
Target comments (see EmbeddedcCodeGenerator for consistent reimplementation pattern)
bool mExistStateNames
record whether there exist statenames at all
virtual void DeclareAux(void)
Declare variables local to the provided snippets, e.g. helpers for bit-mask computation.
bool mEventNameLookup
code option: event name lookup
bool mEventsetsForPerformance
code option: eventsets for performance
virtual void DeclareEventNameLookup(void)
Declare symbolic name lookup tables.
std::map< std::string, bitarray_rec > mBitarrays
Record of all declared bit-arrays.
virtual AA IntarrayAccess(const AA &address, int index)
default int-array: not supported
virtual void OperateTimers(void)
Start/stop/reset timers w.r.t. "exec_event".
virtual void ExecuteEvent(void)
Take transition and figure new state.
virtual void ResetReturn(void)
Reset bail out.
virtual void VariableDeclare(const std::string &laddr, const std::string <ype)
declaration template (optional to facilitate declaration constructs)
virtual void OperateOutputs(void)
Operate output lines w.r.t. "exec_event".
bool mStateNameLookup
code option: state name lookup
virtual void BeginExecutionLoop(void)
Execution Loop, begin.
virtual void DoReadTargetConfiguration(TokenReader &rTr)
re-implement token i/o for extra configuration
virtual void DeclareParallelState(void)
Declare "parallel_state".
std::string mIntegerType
target data type for integer
virtual void UpdateEnabled(void)
Update "enabled_events" from "parallel_state" if "exec_event" was set.
virtual void IntarrayDeclare(const AA &address, int offset, int len)
default int-array: not supported
virtual AX TargetExpression(const AA &address)=0
Convert abstract address to target expression of the respective value.
virtual void DeclareLoopState(void)
Declare loop state, i.e. line levels, loop flag.
virtual void DoGenerateCyclicCode(void)
cut-and-paste template for code snippet assembly
virtual void SenseTimerElapse(void)
Sense timer elapse vents and add to "pending_events".
virtual ~CodePrimitives(void)
Explicit destructor.
virtual Idx StateFaudesIdx(size_t git, int idx)
Overload base class to use the vector address only if the respective code option is active)
virtual void Clear(void)
Clear all data.
std::string mWordType
target data type for word
virtual void DoWriteTargetConfiguration(TokenWriter &rTw) const
re-implement token i/o for extra configuration
virtual void ExecuteEventBySwitching(void)
Alternative implementation of ExecuteEvent()
virtual void DeclareLargeCarray(void)
Declare compiled transition relations.
bool mArrayForTransitions
code option: use const array to represent transitions
virtual void ResetState(void)
Reset state.
bool mArrayForBitmasks
code option: use const array to represent bit-masks
virtual void InsertExecHooks(void)
Helper to insert target code for execution hooks.
CodePrimitives(void)
Constructor.
virtual void DeclareStateNameLookup(void)
Declare symbolic name lookup tables.
bool mStrictEventSynchronisation
code option: strict event synchronisation
virtual void EndExecutionLoop(void)
Loop end.
virtual void DoCompile(void)
virtual hook to extend compiled data
std::string mLiteralAppend
extra code to prepend
virtual void LiteralPrepend(void)
Cosmetic: prepend literally from configuration data.
virtual void BreakExecutionLoop(void)
Execution Loop, break.
virtual void ExecuteEventByInterpreter(void)
Alternative implementation of ExecuteEventBy()
virtual void SenseInputs(void)
Sense input events and add to "pending_events".
std::vector< bool > mHasStateNames
record per generator whether there is a lookup table
bool mMaintainStateIndices
code option: use state indices as provided
virtual void DeclarePendingEvents(void)
Declare "pending_events" and "enabled_events".
bool mLoopPendingInputs
code option: loop until all inputs are resolved
virtual void DoGenerate(void)
cut-and-paste template for code snippet assembly
virtual int StateTargetIdx(size_t git, Idx idx)
Overload base class to use the vector address only if the respective code option is active)
std::string mPrefix
universal prefix (pseudo name space)
virtual bool HasIntarray(void)
default int-array: not supported
std::string mEventExecutionHook
code option: event exec hook
bool mBisectionForBitfind
code option: use bisection to fing lowest set bit