GCC Code Coverage Report


Directory: ./
File: Svc/FpySequencer/FpySequencerDirectives.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 975 1138 85.7%
Functions: 116 118 98.3%
Branches: 708 899 78.8%

Line Branch Exec Source
1 #include <algorithm>
2 #include <cmath>
3 #include <cstring>
4 #include <type_traits>
5 #include "Fw/Com/ComPacket.hpp"
6 #include "Svc/FpySequencer/FpySequencer.hpp"
7 #include "config/SerialPortIndexEnumAc.hpp"
8
9 namespace Svc {
10
11 2184 void FpySequencer::sendSignal(Signal signal) {
12
4/5
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2172 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
2184 switch (signal) {
13 4 case Signal::stmtResponse_beginSleep: {
14 4 this->sequencer_sendSignal_stmtResponse_beginSleep();
15 4 break;
16 }
17 2172 case Signal::stmtResponse_success: {
18 2172 this->sequencer_sendSignal_stmtResponse_success();
19 2172 break;
20 }
21 3 case Signal::stmtResponse_failure: {
22 3 this->sequencer_sendSignal_stmtResponse_failure();
23 3 break;
24 }
25 5 case Signal::stmtResponse_keepWaiting: {
26 5 this->sequencer_sendSignal_stmtResponse_keepWaiting();
27 5 break;
28 }
29 default: {
30 FW_ASSERT(false, static_cast<FwAssertArgType>(signal));
31 }
32 }
33 2184 }
34
35 // utility method for updating telemetry based on a directive error code
36 2184 void FpySequencer::handleDirectiveErrorCode(Fpy::DirectiveId id, DirectiveError err) {
37 2184 this->m_tlm.lastDirectiveError = err;
38
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2181 times.
2184 if (err != DirectiveError::NO_ERROR) {
39 3 this->m_tlm.directiveErrorIndex = this->currentStatementIdx();
40 3 this->m_tlm.directiveErrorId = id;
41 }
42 2184 }
43
44 10 Fw::Success FpySequencer::sendCmd(FwOpcodeType opcode, const U8* argBuf, FwSizeType argBufSize) {
45
1/1
✓ Branch 2 taken 10 times.
10 Fw::ComBuffer cmdBuf;
46 Fw::SerializeStatus stat =
47
1/1
✓ Branch 2 taken 10 times.
10 cmdBuf.serializeFrom(static_cast<FwPacketDescriptorType>(Fw::ComPacketType::FW_PACKET_COMMAND));
48 // TODO should I assert here? this really shouldn't fail, I should just add a static assert
49 // on com buf size and then assert here
50
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (stat != Fw::SerializeStatus::FW_SERIALIZE_OK) {
51 return Fw::Success::FAILURE;
52 }
53
1/1
✓ Branch 2 taken 10 times.
10 stat = cmdBuf.serializeFrom(opcode);
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (stat != Fw::SerializeStatus::FW_SERIALIZE_OK) {
55 return Fw::Success::FAILURE;
56 }
57
1/1
✓ Branch 2 taken 10 times.
10 stat = cmdBuf.serializeFrom(argBuf, argBufSize, Fw::Serialization::OMIT_LENGTH);
58
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (stat != Fw::SerializeStatus::FW_SERIALIZE_OK) {
59 return Fw::Success::FAILURE;
60 }
61
62 // calculate the unique command identifier:
63 // cmd UID is formatted like XXYY, where XX are the first two bytes of the m_sequencesStarted counter
64 // and YY are the first two bytes of the m_statementsDispatched counter.
65 // this way, we know when we get a cmd back A) whether or not it's from this sequence (modulo 2^16) and B)
66 // whether or not it's this specific instance of the cmd in the sequence, and not another one with the same opcode
67 // somewhere else in the file.
68 // if we put this uid in the context we send to the cmdDisp, we will get it back when the cmd returns
69 U32 cmdUid =
70 10 static_cast<U32>(((this->m_sequencesStarted & 0xFFFF) << 16) | (this->m_statementsDispatched & 0xFFFF));
71
72
1/1
✓ Branch 5 taken 10 times.
10 this->cmdOut_out(0, cmdBuf, cmdUid);
73
74
1/1
✓ Branch 1 taken 10 times.
10 return Fw::Success::SUCCESS;
75 10 }
76
77 //! Internal interface handler for directive_waitRel
78 3 void FpySequencer::directive_waitRel_internalInterfaceHandler(const FpySequencer_WaitRelDirective& directive) {
79
1/1
✓ Branch 2 taken 3 times.
3 DirectiveError error = DirectiveError::NO_ERROR;
80
2/2
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
3 this->sendSignal(this->waitRel_directiveHandler(directive, error));
81
3/3
✓ Branch 5 taken 3 times.
✓ Branch 9 taken 3 times.
✓ Branch 12 taken 3 times.
3 handleDirectiveErrorCode(Fpy::DirectiveId::WAIT_REL, error);
82 6 }
83
84 //! Internal interface handler for directive_waitAbs
85 1 void FpySequencer::directive_waitAbs_internalInterfaceHandler(const FpySequencer_WaitAbsDirective& directive) {
86
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
87
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->waitAbs_directiveHandler(directive, error));
88
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::WAIT_ABS, error);
89 2 }
90
91 //! Internal interface handler for directive_goto
92 2 void FpySequencer::directive_goto_internalInterfaceHandler(const Svc::FpySequencer_GotoDirective& directive) {
93
1/1
✓ Branch 2 taken 2 times.
2 DirectiveError error = DirectiveError::NO_ERROR;
94
2/2
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 this->sendSignal(this->goto_directiveHandler(directive, error));
95
3/3
✓ Branch 5 taken 2 times.
✓ Branch 9 taken 2 times.
✓ Branch 12 taken 2 times.
2 handleDirectiveErrorCode(Fpy::DirectiveId::GOTO, error);
96 4 }
97
98 //! Internal interface handler for directive_if
99 7 void FpySequencer::directive_if_internalInterfaceHandler(const Svc::FpySequencer_IfDirective& directive) {
100
1/1
✓ Branch 2 taken 7 times.
7 DirectiveError error = DirectiveError::NO_ERROR;
101
2/2
✓ Branch 7 taken 7 times.
✓ Branch 10 taken 7 times.
7 this->sendSignal(this->if_directiveHandler(directive, error));
102
3/3
✓ Branch 5 taken 7 times.
✓ Branch 9 taken 7 times.
✓ Branch 12 taken 7 times.
7 handleDirectiveErrorCode(Fpy::DirectiveId::IF, error);
103 14 }
104
105 //! Internal interface handler for directive_noOp
106 2055 void FpySequencer::directive_noOp_internalInterfaceHandler(const Svc::FpySequencer_NoOpDirective& directive) {
107
1/1
✓ Branch 2 taken 2055 times.
2055 DirectiveError error = DirectiveError::NO_ERROR;
108
1/1
✓ Branch 8 taken 2055 times.
2055 this->sendSignal(this->noOp_directiveHandler(directive, error));
109
3/3
✓ Branch 5 taken 2055 times.
✓ Branch 9 taken 2055 times.
✓ Branch 12 taken 2055 times.
2055 handleDirectiveErrorCode(Fpy::DirectiveId::NO_OP, error);
110 4110 }
111
112 //! Internal interface handler for directive_pushTlmVal
113 6 void FpySequencer::directive_pushTlmVal_internalInterfaceHandler(
114 const Svc::FpySequencer_PushTlmValDirective& directive) {
115
1/1
✓ Branch 2 taken 6 times.
6 DirectiveError error = DirectiveError::NO_ERROR;
116
2/2
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
6 this->sendSignal(this->pushTlmVal_directiveHandler(directive, error));
117
3/3
✓ Branch 5 taken 6 times.
✓ Branch 9 taken 6 times.
✓ Branch 12 taken 6 times.
6 handleDirectiveErrorCode(Fpy::DirectiveId::PUSH_TLM_VAL, error);
118 12 }
119
120 //! Internal interface handler for directive_pushTlmValAndTime
121 1 void FpySequencer::directive_pushTlmValAndTime_internalInterfaceHandler(
122 const Svc::FpySequencer_PushTlmValAndTimeDirective& directive) {
123
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
124
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->pushTlmValAndTime_directiveHandler(directive, error));
125
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::PUSH_TLM_VAL_AND_TIME, error);
126 2 }
127
128 //! Internal interface handler for directive_pushPrm
129 1 void FpySequencer::directive_pushPrm_internalInterfaceHandler(const Svc::FpySequencer_PushPrmDirective& directive) {
130
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
131
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->pushPrm_directiveHandler(directive, error));
132
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::PUSH_PRM, error);
133 2 }
134
135 //! Internal interface handler for directive_constCmd
136 4 void FpySequencer::directive_constCmd_internalInterfaceHandler(const Svc::FpySequencer_ConstCmdDirective& directive) {
137
1/1
✓ Branch 2 taken 4 times.
4 DirectiveError error = DirectiveError::NO_ERROR;
138
2/2
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
4 this->sendSignal(this->constCmd_directiveHandler(directive, error));
139
3/3
✓ Branch 5 taken 4 times.
✓ Branch 9 taken 4 times.
✓ Branch 12 taken 4 times.
4 handleDirectiveErrorCode(Fpy::DirectiveId::CONST_CMD, error);
140 8 }
141
142 //! Internal interface handler for directive_stackOp
143 5 void FpySequencer::directive_stackOp_internalInterfaceHandler(const Svc::FpySequencer_StackOpDirective& directive) {
144
1/1
✓ Branch 2 taken 5 times.
5 DirectiveError error = DirectiveError::NO_ERROR;
145
2/2
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
5 this->sendSignal(this->stackOp_directiveHandler(directive, error));
146
3/3
✓ Branch 5 taken 5 times.
✓ Branch 13 taken 5 times.
✓ Branch 16 taken 5 times.
5 handleDirectiveErrorCode(directive.get__op(), error);
147 10 }
148
149 //! Internal interface handler for directive_exit
150 7 void FpySequencer::directive_exit_internalInterfaceHandler(const Svc::FpySequencer_ExitDirective& directive) {
151
1/1
✓ Branch 2 taken 7 times.
7 DirectiveError error = DirectiveError::NO_ERROR;
152
2/2
✓ Branch 7 taken 7 times.
✓ Branch 10 taken 7 times.
7 this->sendSignal(this->exit_directiveHandler(directive, error));
153
3/3
✓ Branch 5 taken 7 times.
✓ Branch 9 taken 7 times.
✓ Branch 12 taken 7 times.
7 handleDirectiveErrorCode(Fpy::DirectiveId::EXIT, error);
154 14 }
155
156 //! Internal interface handler for directive_allocate
157 5 void FpySequencer::directive_allocate_internalInterfaceHandler(const Svc::FpySequencer_AllocateDirective& directive) {
158
1/1
✓ Branch 2 taken 5 times.
5 DirectiveError error = DirectiveError::NO_ERROR;
159
2/2
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
5 this->sendSignal(this->allocate_directiveHandler(directive, error));
160
3/3
✓ Branch 5 taken 5 times.
✓ Branch 9 taken 5 times.
✓ Branch 12 taken 5 times.
5 handleDirectiveErrorCode(Fpy::DirectiveId::ALLOCATE, error);
161 10 }
162
163 //! Internal interface handler for directive_storeRelConstOffset
164 1 void FpySequencer::directive_storeRelConstOffset_internalInterfaceHandler(
165 const Svc::FpySequencer_StoreRelConstOffsetDirective& directive) {
166
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
167
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->storeRelConstOffset_directiveHandler(directive, error));
168
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::STORE_REL_CONST_OFFSET, error);
169 2 }
170
171 //! Internal interface handler for directive_pushVal
172 45 void FpySequencer::directive_pushVal_internalInterfaceHandler(const Svc::FpySequencer_PushValDirective& directive) {
173
1/1
✓ Branch 2 taken 45 times.
45 DirectiveError error = DirectiveError::NO_ERROR;
174
2/2
✓ Branch 7 taken 45 times.
✓ Branch 10 taken 45 times.
45 this->sendSignal(this->pushVal_directiveHandler(directive, error));
175
3/3
✓ Branch 5 taken 45 times.
✓ Branch 9 taken 45 times.
✓ Branch 12 taken 45 times.
45 handleDirectiveErrorCode(Fpy::DirectiveId::PUSH_VAL, error);
176 90 }
177
178 //! Internal interface handler for directive_loadRel
179 9 void FpySequencer::directive_loadRel_internalInterfaceHandler(const Svc::FpySequencer_LoadRelDirective& directive) {
180
1/1
✓ Branch 2 taken 9 times.
9 DirectiveError error = DirectiveError::NO_ERROR;
181
2/2
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
9 this->sendSignal(this->loadRel_directiveHandler(directive, error));
182
3/3
✓ Branch 5 taken 9 times.
✓ Branch 9 taken 9 times.
✓ Branch 12 taken 9 times.
9 handleDirectiveErrorCode(Fpy::DirectiveId::LOAD_REL, error);
183 18 }
184
185 //! Internal interface handler for directive_discard
186 18 void FpySequencer::directive_discard_internalInterfaceHandler(const Svc::FpySequencer_DiscardDirective& directive) {
187
1/1
✓ Branch 2 taken 18 times.
18 DirectiveError error = DirectiveError::NO_ERROR;
188
2/2
✓ Branch 7 taken 18 times.
✓ Branch 10 taken 18 times.
18 this->sendSignal(this->discard_directiveHandler(directive, error));
189
3/3
✓ Branch 5 taken 18 times.
✓ Branch 9 taken 18 times.
✓ Branch 12 taken 18 times.
18 handleDirectiveErrorCode(Fpy::DirectiveId::DISCARD, error);
190 36 }
191
192 //! Internal interface handler for directive_memCmp
193 1 void FpySequencer::directive_memCmp_internalInterfaceHandler(const Svc::FpySequencer_MemCmpDirective& directive) {
194
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
195
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->memCmp_directiveHandler(directive, error));
196
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::MEMCMP, error);
197 2 }
198
199 //! Internal interface handler for directive_stackCmd
200 1 void FpySequencer::directive_stackCmd_internalInterfaceHandler(const Svc::FpySequencer_StackCmdDirective& directive) {
201
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
202
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->stackCmd_directiveHandler(directive, error));
203
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::STACK_CMD, error);
204 2 }
205
206 //! Internal interface handler for directive_pushTime
207 1 void FpySequencer::directive_pushTime_internalInterfaceHandler(const Svc::FpySequencer_PushTimeDirective& directive) {
208
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
209
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->pushTime_directiveHandler(directive, error));
210
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::PUSH_TIME, error);
211 2 }
212
213 //! Internal interface handler for directive_setSeed
214 1 void FpySequencer::directive_setSeed_internalInterfaceHandler(const Svc::FpySequencer_SetSeedDirective& directive) {
215
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
216
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->setSeed_directiveHandler(directive, error));
217
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::SET_SEED, error);
218 2 }
219
220 //! Internal interface handler for directive_pushRand
221 2 void FpySequencer::directive_pushRand_internalInterfaceHandler(const Svc::FpySequencer_PushRandDirective& directive) {
222
1/1
✓ Branch 2 taken 2 times.
2 DirectiveError error = DirectiveError::NO_ERROR;
223
2/2
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 this->sendSignal(this->pushRand_directiveHandler(directive, error));
224
3/3
✓ Branch 5 taken 2 times.
✓ Branch 9 taken 2 times.
✓ Branch 12 taken 2 times.
2 handleDirectiveErrorCode(Fpy::DirectiveId::PUSH_RAND, error);
225 4 }
226
227 //! Internal interface handler for directive_getField
228 1 void FpySequencer::directive_getField_internalInterfaceHandler(const Svc::FpySequencer_GetFieldDirective& directive) {
229
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
230
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->getField_directiveHandler(directive, error));
231
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::GET_FIELD, error);
232 2 }
233
234 //! Internal interface handler for directive_peek
235 1 void FpySequencer::directive_peek_internalInterfaceHandler(const Svc::FpySequencer_PeekDirective& directive) {
236
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
237
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->peek_directiveHandler(directive, error));
238
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::PEEK, error);
239 2 }
240
241 //! Internal interface handler for directive_storeRel
242 1 void FpySequencer::directive_storeRel_internalInterfaceHandler(const Svc::FpySequencer_StoreRelDirective& directive) {
243
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
244
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->storeRel_directiveHandler(directive, error));
245
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::STORE_REL, error);
246 2 }
247
248 //! Internal interface handler for directive_call
249 1 void FpySequencer::directive_call_internalInterfaceHandler(const Svc::FpySequencer_CallDirective& directive) {
250
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
251
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->call_directiveHandler(directive, error));
252
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::CALL, error);
253 2 }
254
255 //! Internal interface handler for directive_return
256 1 void FpySequencer::directive_return_internalInterfaceHandler(const Svc::FpySequencer_ReturnDirective& directive) {
257
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
258
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->return_directiveHandler(directive, error));
259
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::RETURN, error);
260 2 }
261
262 //! Internal interface handler for directive_loadAbs
263 1 void FpySequencer::directive_loadAbs_internalInterfaceHandler(const Svc::FpySequencer_LoadAbsDirective& directive) {
264
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
265
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->loadAbs_directiveHandler(directive, error));
266
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::LOAD_ABS, error);
267 2 }
268
269 //! Internal interface handler for directive_storeAbs
270 1 void FpySequencer::directive_storeAbs_internalInterfaceHandler(const Svc::FpySequencer_StoreAbsDirective& directive) {
271
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
272
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->storeAbs_directiveHandler(directive, error));
273
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::STORE_ABS, error);
274 2 }
275
276 //! Internal interface handler for directive_storeAbsConstOffset
277 1 void FpySequencer::directive_storeAbsConstOffset_internalInterfaceHandler(
278 const Svc::FpySequencer_StoreAbsConstOffsetDirective& directive) {
279
1/1
✓ Branch 2 taken 1 times.
1 DirectiveError error = DirectiveError::NO_ERROR;
280
2/2
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 this->sendSignal(this->storeAbsConstOffset_directiveHandler(directive, error));
281
3/3
✓ Branch 5 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 12 taken 1 times.
1 handleDirectiveErrorCode(Fpy::DirectiveId::STORE_ABS_CONST_OFFSET, error);
282 2 }
283
284 //! Internal interface handler for directive_popEvent
285 void FpySequencer::directive_popEvent_internalInterfaceHandler(const Svc::FpySequencer_PopEventDirective& directive) {
286 DirectiveError error = DirectiveError::NO_ERROR;
287 this->sendSignal(this->popEvent_directiveHandler(directive, error));
288 handleDirectiveErrorCode(Fpy::DirectiveId::POP_EVENT, error);
289 }
290
291 //! Internal interface handler for directive_popSerializable
292 void FpySequencer::directive_popSerializable_internalInterfaceHandler(
293 const Svc::FpySequencer_PopSerializableDirective& directive) {
294 DirectiveError error = DirectiveError::NO_ERROR;
295 this->sendSignal(this->popSerializable_directiveHandler(directive, error));
296 handleDirectiveErrorCode(Fpy::DirectiveId::POP_SERIALIZABLE, error);
297 }
298
299 //! Internal interface handler for directive_waitRel
300 4 Signal FpySequencer::waitRel_directiveHandler(const FpySequencer_WaitRelDirective& directive, DirectiveError& error) {
301
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 if (this->m_runtime.stack.size < 8) {
302 error = DirectiveError::STACK_UNDERFLOW;
303 return Signal::stmtResponse_failure;
304 }
305
306
1/1
✓ Branch 3 taken 4 times.
4 Fw::Time wakeupTime = this->getTime();
307
308
1/1
✓ Branch 4 taken 4 times.
4 U32 uSeconds = this->m_runtime.stack.pop<U32>();
309
1/1
✓ Branch 4 taken 4 times.
4 U32 seconds = this->m_runtime.stack.pop<U32>();
310
311
1/1
✓ Branch 2 taken 4 times.
4 wakeupTime.add(seconds, uSeconds);
312
1/1
✓ Branch 6 taken 4 times.
4 this->m_runtime.wakeupTime = wakeupTime;
313 4 return Signal::stmtResponse_beginSleep;
314 4 }
315
316 //! Internal interface handler for directive_waitAbs
317 2 Signal FpySequencer::waitAbs_directiveHandler(const FpySequencer_WaitAbsDirective& directive, DirectiveError& error) {
318
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if (this->m_runtime.stack.size < 2 * sizeof(U32) + sizeof(FwTimeContextStoreType) + sizeof(FwTimeBaseStoreType)) {
319 error = DirectiveError::STACK_UNDERFLOW;
320 return Signal::stmtResponse_failure;
321 }
322
323 2 U32 uSeconds = this->m_runtime.stack.pop<U32>();
324 2 U32 seconds = this->m_runtime.stack.pop<U32>();
325 2 FwTimeContextStoreType ctx = this->m_runtime.stack.pop<FwTimeContextStoreType>();
326 2 FwTimeBaseStoreType base = this->m_runtime.stack.pop<FwTimeBaseStoreType>();
327
328
3/3
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 15 taken 2 times.
2 this->m_runtime.wakeupTime = Fw::Time(static_cast<TimeBase::T>(base), ctx, seconds, uSeconds);
329 2 return Signal::stmtResponse_beginSleep;
330 }
331
332 //! Internal interface handler for directive_goto
333 5 Signal FpySequencer::goto_directiveHandler(const FpySequencer_GotoDirective& directive, DirectiveError& error) {
334 // check within sequence bounds, or at EOF (we allow == case cuz this just ends the sequence)
335
2/2
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 4 times.
5 if (directive.get_statementIndex() > m_sequenceObj.get_header().get_statementCount()) {
336 1 error = DirectiveError::STMT_OUT_OF_BOUNDS;
337 1 return Signal::stmtResponse_failure;
338 }
339 4 m_runtime.nextStatementIndex = directive.get_statementIndex();
340 4 return Signal::stmtResponse_success;
341 }
342
343 //! Internal interface handler for directive_if
344 12 Signal FpySequencer::if_directiveHandler(const FpySequencer_IfDirective& directive, DirectiveError& error) {
345
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 11 times.
12 if (this->m_runtime.stack.size < 1) {
346 1 error = DirectiveError::STACK_UNDERFLOW;
347 1 return Signal::stmtResponse_failure;
348 }
349 // check within sequence bounds, or at EOF (we allow == case cuz this just ends the sequence)
350
2/2
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 10 times.
11 if (directive.get_falseGotoStmtIndex() > m_sequenceObj.get_header().get_statementCount()) {
351 1 error = DirectiveError::STMT_OUT_OF_BOUNDS;
352 1 return Signal::stmtResponse_failure;
353 }
354
355
2/2
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 6 times.
10 if (this->m_runtime.stack.pop<U8>() != 0) {
356 // proceed to next instruction
357 4 return Signal::stmtResponse_success;
358 }
359
360 // conditional false case
361 6 this->m_runtime.nextStatementIndex = directive.get_falseGotoStmtIndex();
362 6 return Signal::stmtResponse_success;
363 }
364
365 2056 Signal FpySequencer::noOp_directiveHandler(const FpySequencer_NoOpDirective& directive, DirectiveError& error) {
366 2056 return Signal::stmtResponse_success;
367 }
368
369 9 Signal FpySequencer::pushTlmVal_directiveHandler(const FpySequencer_PushTlmValDirective& directive,
370 DirectiveError& error) {
371
2/3
✓ Branch 5 taken 9 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
9 if (!this->isConnected_getTlmChan_OutputPort(0)) {
372 error = DirectiveError::TLM_GET_NOT_CONNECTED;
373 return Signal::stmtResponse_failure;
374 }
375
1/1
✓ Branch 2 taken 9 times.
9 Fw::Time tlmTime;
376
1/1
✓ Branch 2 taken 9 times.
9 Fw::TlmBuffer tlmValue;
377
1/1
✓ Branch 7 taken 9 times.
9 Fw::TlmValid valid = this->getTlmChan_out(0, directive.get_chanId(), tlmTime, tlmValue);
378
379
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 8 times.
9 if (valid != Fw::TlmValid::VALID) {
380 // could not find this tlm chan
381
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::TLM_CHAN_NOT_FOUND;
382 1 return Signal::stmtResponse_failure;
383 }
384
385
3/3
✓ Branch 2 taken 8 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 7 times.
8 if (Fpy::MAX_STACK_SIZE - tlmValue.getSize() < this->m_runtime.stack.size) {
386
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::STACK_OVERFLOW;
387 1 return Signal::stmtResponse_failure;
388 }
389
2/2
✓ Branch 5 taken 7 times.
✓ Branch 10 taken 7 times.
7 this->m_runtime.stack.push(tlmValue.getBuffAddr(), static_cast<Fpy::StackSizeType>(tlmValue.getSize()));
390 7 return Signal::stmtResponse_success;
391 9 }
392
393 4 Signal FpySequencer::pushTlmValAndTime_directiveHandler(const FpySequencer_PushTlmValAndTimeDirective& directive,
394 DirectiveError& error) {
395
2/3
✓ Branch 5 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
4 if (!this->isConnected_getTlmChan_OutputPort(0)) {
396 error = DirectiveError::TLM_GET_NOT_CONNECTED;
397 return Signal::stmtResponse_failure;
398 }
399
400
1/1
✓ Branch 2 taken 4 times.
4 Fw::Time tlmTime;
401
1/1
✓ Branch 2 taken 4 times.
4 Fw::TlmBuffer tlmValue;
402
1/1
✓ Branch 7 taken 4 times.
4 Fw::TlmValid valid = this->getTlmChan_out(0, directive.get_chanId(), tlmTime, tlmValue);
403
404
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
4 if (valid != Fw::TlmValid::VALID) {
405 // could not find this tlm chan
406
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::TLM_CHAN_NOT_FOUND;
407 1 return Signal::stmtResponse_failure;
408 }
409
410 3 U8 tlmTimeBuf[Fw::Time::SERIALIZED_SIZE] = {};
411
1/1
✓ Branch 2 taken 3 times.
3 Fw::ExternalSerializeBuffer timeEsb(tlmTimeBuf, Fw::Time::SERIALIZED_SIZE);
412
1/1
✓ Branch 2 taken 3 times.
3 Fw::SerializeStatus stat = timeEsb.serializeFrom(tlmTime);
413
414 // coding error if this failed, we should have enough space
415 3 FW_ASSERT(stat == Fw::SerializeStatus::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(stat));
416
417 // check that our stack won't overflow if we put both val and time on it
418
4/4
✓ Branch 2 taken 3 times.
✓ Branch 6 taken 3 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 2 times.
3 if (Fpy::MAX_STACK_SIZE - tlmValue.getSize() - timeEsb.getSize() < this->m_runtime.stack.size) {
419
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::STACK_OVERFLOW;
420 1 return Signal::stmtResponse_failure;
421 }
422
423 // push tlm to end of stack
424
2/2
✓ Branch 5 taken 2 times.
✓ Branch 10 taken 2 times.
2 this->m_runtime.stack.push(tlmValue.getBuffAddr(), static_cast<Fpy::StackSizeType>(tlmValue.getSize()));
425 // now push time to end of stack
426
2/2
✓ Branch 5 taken 2 times.
✓ Branch 10 taken 2 times.
2 this->m_runtime.stack.push(timeEsb.getBuffAddr(), static_cast<Fpy::StackSizeType>(timeEsb.getSize()));
427 2 return Signal::stmtResponse_success;
428 4 }
429
430 4 Signal FpySequencer::pushPrm_directiveHandler(const FpySequencer_PushPrmDirective& directive, DirectiveError& error) {
431
2/3
✓ Branch 5 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
4 if (!this->isConnected_prmGet_OutputPort(0)) {
432 error = DirectiveError::PRM_GET_NOT_CONNECTED;
433 return Signal::stmtResponse_failure;
434 }
435
436
1/1
✓ Branch 2 taken 4 times.
4 Fw::ParamBuffer prmValue;
437
1/1
✓ Branch 7 taken 4 times.
4 Fw::ParamValid valid = this->getParam_out(0, directive.get_prmId(), prmValue);
438
439
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
4 if (valid != Fw::ParamValid::VALID) {
440 // could not find this prm in the DB
441
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::PRM_NOT_FOUND;
442 1 return Signal::stmtResponse_failure;
443 }
444
445
3/3
✓ Branch 2 taken 3 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 2 times.
3 if (Fpy::MAX_STACK_SIZE - prmValue.getSize() < this->m_runtime.stack.size) {
446
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::STACK_OVERFLOW;
447 1 return Signal::stmtResponse_failure;
448 }
449
450
2/2
✓ Branch 5 taken 2 times.
✓ Branch 10 taken 2 times.
2 this->m_runtime.stack.push(prmValue.getBuffAddr(), static_cast<Fpy::StackSizeType>(prmValue.getSize()));
451 2 return Signal::stmtResponse_success;
452 4 }
453
454 9 Signal FpySequencer::constCmd_directiveHandler(const FpySequencer_ConstCmdDirective& directive, DirectiveError& error) {
455 // the cmd response code will be pushed to the stack when it comes back, so make sure
456 // there is room for it now, before the cmd is dispatched
457
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 8 times.
9 if (Fpy::MAX_STACK_SIZE - sizeof(Fw::CmdResponse::SerialType) < this->m_runtime.stack.size) {
458 1 error = DirectiveError::STACK_OVERFLOW;
459 1 return Signal::stmtResponse_failure;
460 }
461
2/3
✓ Branch 14 taken 8 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 8 times.
8 if (this->sendCmd(directive.get_opCode(), directive.get_argBuf(), directive.get__argBufSize()) ==
462 Fw::Success::FAILURE) {
463 return Signal::stmtResponse_failure;
464 } else {
465 // now tell the SM to wait some more until we get the cmd response back
466 // if we've already got the response back this should be harmless
467 8 return Signal::stmtResponse_keepWaiting;
468 }
469 }
470
471 8 DirectiveError FpySequencer::op_or() {
472
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 6 times.
8 if (this->m_runtime.stack.size < sizeof(U8) * 2) {
473 2 return DirectiveError::STACK_UNDERFLOW;
474 }
475 6 this->m_runtime.stack.push(static_cast<U8>(this->m_runtime.stack.pop<U8>() | this->m_runtime.stack.pop<U8>()));
476 6 return DirectiveError::NO_ERROR;
477 }
478 6 DirectiveError FpySequencer::op_and() {
479
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (this->m_runtime.stack.size < sizeof(U8) * 2) {
480 2 return DirectiveError::STACK_UNDERFLOW;
481 }
482 4 this->m_runtime.stack.push(static_cast<U8>(this->m_runtime.stack.pop<U8>() & this->m_runtime.stack.pop<U8>()));
483 4 return DirectiveError::NO_ERROR;
484 }
485 6 DirectiveError FpySequencer::op_ieq() {
486
2/2
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3 times.
6 if (this->m_runtime.stack.size < sizeof(I64) * 2) {
487 3 return DirectiveError::STACK_UNDERFLOW;
488 }
489
2/2
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 1 times.
3 this->m_runtime.stack.push(static_cast<U8>((this->m_runtime.stack.pop<I64>() == this->m_runtime.stack.pop<I64>())
490 ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
491 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
492 3 return DirectiveError::NO_ERROR;
493 }
494 5 DirectiveError FpySequencer::op_ine() {
495
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 3 times.
5 if (this->m_runtime.stack.size < sizeof(I64) * 2) {
496 2 return DirectiveError::STACK_UNDERFLOW;
497 }
498
2/2
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 1 times.
3 this->m_runtime.stack.push(static_cast<U8>((this->m_runtime.stack.pop<I64>() != this->m_runtime.stack.pop<I64>())
499 ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
500 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
501 3 return DirectiveError::NO_ERROR;
502 }
503 6 DirectiveError FpySequencer::op_ult() {
504
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (this->m_runtime.stack.size < sizeof(U64) * 2) {
505 2 return DirectiveError::STACK_UNDERFLOW;
506 }
507 4 U64 rhs = this->m_runtime.stack.pop<U64>();
508 4 U64 lhs = this->m_runtime.stack.pop<U64>();
509
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 times.
4 this->m_runtime.stack.push(static_cast<U8>((lhs < rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
510 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
511 4 return DirectiveError::NO_ERROR;
512 }
513 6 DirectiveError FpySequencer::op_ule() {
514
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (this->m_runtime.stack.size < sizeof(U64) * 2) {
515 2 return DirectiveError::STACK_UNDERFLOW;
516 }
517 4 U64 rhs = this->m_runtime.stack.pop<U64>();
518 4 U64 lhs = this->m_runtime.stack.pop<U64>();
519
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 times.
4 this->m_runtime.stack.push(static_cast<U8>((lhs <= rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
520 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
521 4 return DirectiveError::NO_ERROR;
522 }
523 6 DirectiveError FpySequencer::op_ugt() {
524
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (this->m_runtime.stack.size < sizeof(U64) * 2) {
525 2 return DirectiveError::STACK_UNDERFLOW;
526 }
527 4 U64 rhs = this->m_runtime.stack.pop<U64>();
528 4 U64 lhs = this->m_runtime.stack.pop<U64>();
529
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 times.
4 this->m_runtime.stack.push(static_cast<U8>((lhs > rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
530 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
531 4 return DirectiveError::NO_ERROR;
532 }
533 8 DirectiveError FpySequencer::op_uge() {
534
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 6 times.
8 if (this->m_runtime.stack.size < sizeof(U64) * 2) {
535 2 return DirectiveError::STACK_UNDERFLOW;
536 }
537 6 U64 rhs = this->m_runtime.stack.pop<U64>();
538 6 U64 lhs = this->m_runtime.stack.pop<U64>();
539
2/2
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2 times.
6 this->m_runtime.stack.push(static_cast<U8>((lhs >= rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
540 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
541 6 return DirectiveError::NO_ERROR;
542 }
543 6 DirectiveError FpySequencer::op_slt() {
544
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (this->m_runtime.stack.size < sizeof(I64) * 2) {
545 2 return DirectiveError::STACK_UNDERFLOW;
546 }
547 4 I64 rhs = this->m_runtime.stack.pop<I64>();
548 4 I64 lhs = this->m_runtime.stack.pop<I64>();
549
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 times.
4 this->m_runtime.stack.push(static_cast<U8>((lhs < rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
550 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
551 4 return DirectiveError::NO_ERROR;
552 }
553 5 DirectiveError FpySequencer::op_sle() {
554
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 3 times.
5 if (this->m_runtime.stack.size < sizeof(I64) * 2) {
555 2 return DirectiveError::STACK_UNDERFLOW;
556 }
557 3 I64 rhs = this->m_runtime.stack.pop<I64>();
558 3 I64 lhs = this->m_runtime.stack.pop<I64>();
559
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
3 this->m_runtime.stack.push(static_cast<U8>((lhs <= rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
560 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
561 3 return DirectiveError::NO_ERROR;
562 }
563 5 DirectiveError FpySequencer::op_sgt() {
564
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 3 times.
5 if (this->m_runtime.stack.size < sizeof(I64) * 2) {
565 2 return DirectiveError::STACK_UNDERFLOW;
566 }
567 3 I64 rhs = this->m_runtime.stack.pop<I64>();
568 3 I64 lhs = this->m_runtime.stack.pop<I64>();
569
2/2
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 2 times.
3 this->m_runtime.stack.push(static_cast<U8>((lhs > rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
570 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
571 3 return DirectiveError::NO_ERROR;
572 }
573 5 DirectiveError FpySequencer::op_sge() {
574
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 3 times.
5 if (this->m_runtime.stack.size < sizeof(I64) * 2) {
575 2 return DirectiveError::STACK_UNDERFLOW;
576 }
577 3 I64 rhs = this->m_runtime.stack.pop<I64>();
578 3 I64 lhs = this->m_runtime.stack.pop<I64>();
579
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
3 this->m_runtime.stack.push(static_cast<U8>((lhs >= rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
580 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
581 3 return DirectiveError::NO_ERROR;
582 }
583 6 DirectiveError FpySequencer::op_feq() {
584
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
585 2 return DirectiveError::STACK_UNDERFLOW;
586 }
587 4 F64 rhs = this->m_runtime.stack.pop<F64>();
588 4 F64 lhs = this->m_runtime.stack.pop<F64>();
589 // eq is true if they are equal and neither is nan
590
2/2
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 3 times.
4 this->m_runtime.stack.push(static_cast<U8>((lhs == rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
591 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
592 4 return DirectiveError::NO_ERROR;
593 }
594 6 DirectiveError FpySequencer::op_fne() {
595
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
596 2 return DirectiveError::STACK_UNDERFLOW;
597 }
598 4 F64 rhs = this->m_runtime.stack.pop<F64>();
599 4 F64 lhs = this->m_runtime.stack.pop<F64>();
600 // ne is true if they are not equal or either is nan
601
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 times.
4 this->m_runtime.stack.push(static_cast<U8>((lhs != rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
602 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
603 4 return DirectiveError::NO_ERROR;
604 }
605 7 DirectiveError FpySequencer::op_flt() {
606
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 5 times.
7 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
607 2 return DirectiveError::STACK_UNDERFLOW;
608 }
609 5 F64 rhs = this->m_runtime.stack.pop<F64>();
610 5 F64 lhs = this->m_runtime.stack.pop<F64>();
611
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 3 times.
5 this->m_runtime.stack.push(static_cast<U8>(std::isless(lhs, rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
612 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
613 5 return DirectiveError::NO_ERROR;
614 }
615 6 DirectiveError FpySequencer::op_fle() {
616
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
617 2 return DirectiveError::STACK_UNDERFLOW;
618 }
619 4 F64 rhs = this->m_runtime.stack.pop<F64>();
620 4 F64 lhs = this->m_runtime.stack.pop<F64>();
621
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
4 this->m_runtime.stack.push(static_cast<U8>(std::islessequal(lhs, rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
622 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
623 4 return DirectiveError::NO_ERROR;
624 }
625 6 DirectiveError FpySequencer::op_fgt() {
626
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
627 2 return DirectiveError::STACK_UNDERFLOW;
628 }
629 4 F64 rhs = this->m_runtime.stack.pop<F64>();
630 4 F64 lhs = this->m_runtime.stack.pop<F64>();
631
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
4 this->m_runtime.stack.push(static_cast<U8>(std::isgreater(lhs, rhs) ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
632 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
633 4 return DirectiveError::NO_ERROR;
634 }
635 7 DirectiveError FpySequencer::op_fge() {
636
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 5 times.
7 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
637 2 return DirectiveError::STACK_UNDERFLOW;
638 }
639 5 F64 rhs = this->m_runtime.stack.pop<F64>();
640 5 F64 lhs = this->m_runtime.stack.pop<F64>();
641
2/2
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 2 times.
5 this->m_runtime.stack.push(static_cast<U8>(std::isgreaterequal(lhs, rhs)
642 ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
643 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
644 5 return DirectiveError::NO_ERROR;
645 }
646 3 DirectiveError FpySequencer::op_not() {
647
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
3 if (this->m_runtime.stack.size < sizeof(U8)) {
648 1 return DirectiveError::STACK_UNDERFLOW;
649 }
650
1/2
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
2 this->m_runtime.stack.push(static_cast<U8>((this->m_runtime.stack.pop<U8>() == 0)
651 ? static_cast<U8>(FW_SERIALIZE_TRUE_VALUE)
652 : static_cast<U8>(FW_SERIALIZE_FALSE_VALUE)));
653 2 return DirectiveError::NO_ERROR;
654 }
655 2 DirectiveError FpySequencer::op_fpext() {
656 // convert F32 to F64
657
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 if (this->m_runtime.stack.size < sizeof(F32)) {
658 1 return DirectiveError::STACK_UNDERFLOW;
659 }
660 1 this->m_runtime.stack.push(static_cast<F64>(this->m_runtime.stack.pop<F32>()));
661 1 return DirectiveError::NO_ERROR;
662 }
663 2 DirectiveError FpySequencer::op_fptrunc() {
664 // convert F64 to F32
665
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 if (this->m_runtime.stack.size < sizeof(F64)) {
666 1 return DirectiveError::STACK_UNDERFLOW;
667 }
668 1 this->m_runtime.stack.push(static_cast<F32>(this->m_runtime.stack.pop<F64>()));
669 1 return DirectiveError::NO_ERROR;
670 }
671 8 DirectiveError FpySequencer::op_fptosi() {
672
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 7 times.
8 if (this->m_runtime.stack.size < sizeof(F64)) {
673 1 return DirectiveError::STACK_UNDERFLOW;
674 }
675 7 F64 val = this->m_runtime.stack.pop<F64>();
676 // NaN -> 0, out-of-range clamps, in-range truncates toward
677 // zero. The raw static_cast is UB for NaN and out-of-range values.
678 // 2^63 is exactly representable as F64 and is one past I64 max; -2^63
679 // is exactly I64 min and in range.
680 7 const F64 bound = std::ldexp(1.0, 63);
681 I64 result;
682
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 6 times.
7 if (std::isnan(val)) {
683 1 result = 0;
684
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 } else if (val >= bound) {
685 2 result = std::numeric_limits<I64>::max();
686
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 } else if (val < -bound) {
687 2 result = std::numeric_limits<I64>::min();
688 } else {
689 2 result = static_cast<I64>(val);
690 }
691 7 this->m_runtime.stack.push(result);
692 7 return DirectiveError::NO_ERROR;
693 }
694 2 DirectiveError FpySequencer::op_sitofp() {
695
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 if (this->m_runtime.stack.size < sizeof(I64)) {
696 1 return DirectiveError::STACK_UNDERFLOW;
697 }
698 1 this->m_runtime.stack.push(static_cast<F64>(this->m_runtime.stack.pop<I64>()));
699 1 return DirectiveError::NO_ERROR;
700 }
701 7 DirectiveError FpySequencer::op_fptoui() {
702
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 6 times.
7 if (this->m_runtime.stack.size < sizeof(F64)) {
703 1 return DirectiveError::STACK_UNDERFLOW;
704 }
705 6 F64 val = this->m_runtime.stack.pop<F64>();
706 // NaN -> 0, negatives truncate to at most 0 and clamp there,
707 // 2^64 (one past U64 max) and above clamp to U64 max. The raw
708 // static_cast is UB for NaN and out-of-range values.
709 6 const F64 bound = std::ldexp(1.0, 64);
710 U64 result;
711
6/6
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 3 times.
6 if (std::isnan(val) || val < 0.0) {
712 3 result = 0;
713
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 } else if (val >= bound) {
714 2 result = std::numeric_limits<U64>::max();
715 } else {
716 1 result = static_cast<U64>(val);
717 }
718 6 this->m_runtime.stack.push(result);
719 6 return DirectiveError::NO_ERROR;
720 }
721 2 DirectiveError FpySequencer::op_uitofp() {
722
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 if (this->m_runtime.stack.size < sizeof(U64)) {
723 1 return DirectiveError::STACK_UNDERFLOW;
724 }
725 1 this->m_runtime.stack.push(static_cast<F64>(this->m_runtime.stack.pop<U64>()));
726 1 return DirectiveError::NO_ERROR;
727 }
728 5 DirectiveError FpySequencer::op_add() {
729
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 3 times.
5 if (this->m_runtime.stack.size < sizeof(I64) * 2) {
730 2 return DirectiveError::STACK_UNDERFLOW;
731 }
732 3 I64 rhs = this->m_runtime.stack.pop<I64>();
733 3 I64 lhs = this->m_runtime.stack.pop<I64>();
734 // Check for overflow and underflow and return the appropriate error code
735 // Overflow can only occur with both operands positive and occurs when one operand is greater than the maximum value
736 // less the other operand. If either operand is negative or zero, overflow cannot occur.
737
7/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 2 times.
3 if ((rhs > 0) && (lhs > 0) && ((std::numeric_limits<I64>::max() - rhs) < lhs)) {
738 1 return DirectiveError::ARITHMETIC_OVERFLOW;
739 }
740 // Underflow can only occur with both operands negative and occurs when one operand is less than the minimum value
741 // minus the other operand. If either operand is positive or zero, underflow cannot occur.
742
6/8
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
2 else if ((rhs < 0) && (lhs < 0) && ((std::numeric_limits<I64>::min() - rhs) > lhs)) {
743 1 return DirectiveError::ARITHMETIC_UNDERFLOW;
744 }
745 1 this->m_runtime.stack.push(static_cast<I64>(lhs + rhs));
746 1 return DirectiveError::NO_ERROR;
747 }
748 5 DirectiveError FpySequencer::op_sub() {
749
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 3 times.
5 if (this->m_runtime.stack.size < sizeof(I64) * 2) {
750 2 return DirectiveError::STACK_UNDERFLOW;
751 }
752 3 I64 rhs = this->m_runtime.stack.pop<I64>();
753 3 I64 lhs = this->m_runtime.stack.pop<I64>();
754 // Check for overflow and underflow and return the appropriate error code
755 // Overflow can only occur when the left operand is positive and the right operand is negative. It occurs when the
756 // left (positive) operand is greater than the maximum value plus the other (negative) operand. If the right
757 // operand is positive or zero, overflow cannot occur.
758
6/8
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 2 times.
3 if ((rhs < 0) && (lhs > 0) && ((std::numeric_limits<I64>::max() + rhs) < lhs)) {
759 1 return DirectiveError::ARITHMETIC_OVERFLOW;
760 }
761 // Underflow can only occur when the left operand is negative and the right operand is positive. It occurs when the
762 // left (negative) operand is less than the minimum value plus the other (positive) operand. If the right operand
763 // is negative or zero, underflow cannot occur.
764
6/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
2 else if ((rhs > 0) && (lhs < 0) && ((std::numeric_limits<I64>::min() + rhs) > lhs)) {
765 1 return DirectiveError::ARITHMETIC_UNDERFLOW;
766 }
767 1 this->m_runtime.stack.push(static_cast<I64>(lhs - rhs));
768 1 return DirectiveError::NO_ERROR;
769 }
770 15 DirectiveError FpySequencer::op_mul() {
771
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 13 times.
15 if (this->m_runtime.stack.size < sizeof(I64) * 2) {
772 2 return DirectiveError::STACK_UNDERFLOW;
773 }
774 13 I64 rhs = this->m_runtime.stack.pop<I64>();
775 13 I64 lhs = this->m_runtime.stack.pop<I64>();
776 // Check for overflow and underflow and return the appropriate error code
777 // Overflow can only occur with operands of matching signs and occurs when one operand is greater (or less) than the
778 // maximum value divided by the other operand. Either operand being zero precludes overflow.
779 // Check the both positive case.
780
9/10
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 12 times.
13 if ((rhs > 0) && (lhs > 0) && ((std::numeric_limits<I64>::max() / rhs) < lhs)) {
781 1 return DirectiveError::ARITHMETIC_OVERFLOW;
782 }
783 // Check the both negative case. Compare without negation: negating a value of min is undefined behavior
784
9/10
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✓ Branch 6 taken 7 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 7 times.
✓ Branch 9 taken 5 times.
12 else if ((rhs < 0) && (lhs < 0) && (lhs < (std::numeric_limits<I64>::max() / rhs))) {
785 7 return DirectiveError::ARITHMETIC_OVERFLOW;
786 }
787 // Underflow can occur with operands of differing signs and occurs when one operand is less than the minimum value
788 // divided by the other operand. Either operand being zero precludes underflow.
789 // Check the case where lhs is positive.
790
8/10
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 4 times.
5 else if ((rhs < 0) && (lhs > 0) && ((std::numeric_limits<I64>::min() / lhs) > rhs)) {
791 1 return DirectiveError::ARITHMETIC_UNDERFLOW;
792 }
793 // Check the case where rhs is positive.
794
8/10
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 3 times.
4 else if ((rhs > 0) && (lhs < 0) && ((std::numeric_limits<I64>::min() / rhs) > lhs)) {
795 1 return DirectiveError::ARITHMETIC_UNDERFLOW;
796 }
797 3 this->m_runtime.stack.push(static_cast<I64>(lhs * rhs));
798 3 return DirectiveError::NO_ERROR;
799 }
800 4 DirectiveError FpySequencer::op_udiv() {
801
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
4 if (this->m_runtime.stack.size < sizeof(U64) * 2) {
802 2 return DirectiveError::STACK_UNDERFLOW;
803 }
804 2 U64 rhs = this->m_runtime.stack.pop<U64>();
805 2 U64 lhs = this->m_runtime.stack.pop<U64>();
806 // Prevent division by zero
807
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (rhs == 0) {
808 1 return DirectiveError::DOMAIN_ERROR;
809 }
810
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 this->m_runtime.stack.push(static_cast<U64>(lhs / rhs));
811 1 return DirectiveError::NO_ERROR;
812 }
813 9 DirectiveError FpySequencer::op_sdiv() {
814
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 7 times.
9 if (this->m_runtime.stack.size < sizeof(I64) * 2) {
815 2 return DirectiveError::STACK_UNDERFLOW;
816 }
817
818 7 I64 rhs = this->m_runtime.stack.pop<I64>();
819 7 I64 lhs = this->m_runtime.stack.pop<I64>();
820 // Prevent division by zero
821
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 if (rhs == 0) {
822 1 return DirectiveError::DOMAIN_ERROR;
823 }
824 // The one signed division that can overflow: |I64 min / -1| = 2^63 is not
825 // representable (and the C++ expression is UB, SIGFPE on x86)
826
5/6
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 5 times.
6 if ((lhs == std::numeric_limits<I64>::min()) && (rhs == -1)) {
827 1 return DirectiveError::ARITHMETIC_OVERFLOW;
828 }
829 // C++ / truncates toward zero; adjust to match Python's floored division:
830 // an inexact quotient with differing operand signs floors one below the
831 // truncated result. This mirrors op_smod.
832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 I64 quotient = lhs / rhs;
833
7/8
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 3 times.
5 if (((lhs % rhs) != 0) && ((lhs < 0) != (rhs < 0))) {
834 2 quotient -= 1;
835 }
836 5 this->m_runtime.stack.push(quotient);
837 5 return DirectiveError::NO_ERROR;
838 }
839 4 DirectiveError FpySequencer::op_umod() {
840
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
4 if (this->m_runtime.stack.size < sizeof(U64) * 2) {
841 2 return DirectiveError::STACK_UNDERFLOW;
842 }
843 2 U64 rhs = this->m_runtime.stack.pop<U64>();
844
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (rhs == 0) {
845 1 return DirectiveError::DOMAIN_ERROR;
846 }
847 1 U64 lhs = this->m_runtime.stack.pop<U64>();
848
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 this->m_runtime.stack.push(static_cast<U64>(lhs % rhs));
849 1 return DirectiveError::NO_ERROR;
850 }
851 7 DirectiveError FpySequencer::op_smod() {
852
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 5 times.
7 if (this->m_runtime.stack.size < sizeof(I64) * 2) {
853 2 return DirectiveError::STACK_UNDERFLOW;
854 }
855 5 I64 rhs = this->m_runtime.stack.pop<I64>();
856
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 if (rhs == 0) {
857 1 return DirectiveError::DOMAIN_ERROR;
858 }
859 4 I64 lhs = this->m_runtime.stack.pop<I64>();
860 // I64 min % -1 is 0, the mathematical remainder (matching wasm i64.rem_s),
861 // but the C++ expression is UB (SIGFPE on x86) so it must be special-cased
862
5/6
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 3 times.
4 if ((lhs == std::numeric_limits<I64>::min()) && (rhs == -1)) {
863 1 this->m_runtime.stack.push(static_cast<I64>(0));
864 1 return DirectiveError::NO_ERROR;
865 }
866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 I64 res = static_cast<I64>(lhs % rhs);
867 // in order to match Python's behavior,
868 // if the signs of the remainder and divisor differ, adjust the result.
869 // this happens when the result should be positive but is negative, or vice-versa.
870 // credit Gemini 2.5 pro
871
6/8
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
3 if ((res > 0 && rhs < 0) || (res < 0 && rhs > 0)) {
872 2 res += rhs;
873 }
874 3 this->m_runtime.stack.push(res);
875 3 return DirectiveError::NO_ERROR;
876 }
877 3 DirectiveError FpySequencer::op_fadd() {
878
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
3 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
879 2 return DirectiveError::STACK_UNDERFLOW;
880 }
881 1 F64 rhs = this->m_runtime.stack.pop<F64>();
882 1 F64 lhs = this->m_runtime.stack.pop<F64>();
883 1 this->m_runtime.stack.push(static_cast<F64>(lhs + rhs));
884 1 return DirectiveError::NO_ERROR;
885 }
886 3 DirectiveError FpySequencer::op_fsub() {
887
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
3 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
888 2 return DirectiveError::STACK_UNDERFLOW;
889 }
890 1 F64 rhs = this->m_runtime.stack.pop<F64>();
891 1 F64 lhs = this->m_runtime.stack.pop<F64>();
892 1 this->m_runtime.stack.push(static_cast<F64>(lhs - rhs));
893 1 return DirectiveError::NO_ERROR;
894 }
895 3 DirectiveError FpySequencer::op_fmul() {
896
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
3 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
897 2 return DirectiveError::STACK_UNDERFLOW;
898 }
899 1 F64 rhs = this->m_runtime.stack.pop<F64>();
900 1 F64 lhs = this->m_runtime.stack.pop<F64>();
901 1 this->m_runtime.stack.push(static_cast<F64>(lhs * rhs));
902 1 return DirectiveError::NO_ERROR;
903 }
904 3 DirectiveError FpySequencer::op_fdiv() {
905
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
3 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
906 2 return DirectiveError::STACK_UNDERFLOW;
907 }
908 1 F64 rhs = this->m_runtime.stack.pop<F64>();
909 1 F64 lhs = this->m_runtime.stack.pop<F64>();
910 1 this->m_runtime.stack.push(static_cast<F64>(lhs / rhs));
911 1 return DirectiveError::NO_ERROR;
912 }
913 3 DirectiveError FpySequencer::op_fpow() {
914
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
3 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
915 2 return DirectiveError::STACK_UNDERFLOW;
916 }
917 1 F64 rhs = this->m_runtime.stack.pop<F64>();
918 1 F64 lhs = this->m_runtime.stack.pop<F64>();
919 1 this->m_runtime.stack.push(static_cast<F64>(pow(lhs, rhs)));
920 1 return DirectiveError::NO_ERROR;
921 }
922 4 DirectiveError FpySequencer::op_flog() {
923
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
4 if (this->m_runtime.stack.size < sizeof(F64)) {
924 1 return DirectiveError::STACK_UNDERFLOW;
925 }
926 3 F64 val = this->m_runtime.stack.pop<F64>();
927
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (val <= 0.0) {
928 2 return DirectiveError::DOMAIN_ERROR;
929 }
930 1 this->m_runtime.stack.push(static_cast<F64>(log(val)));
931 1 return DirectiveError::NO_ERROR;
932 }
933 8 DirectiveError FpySequencer::op_fmod() {
934
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 6 times.
8 if (this->m_runtime.stack.size < sizeof(F64) * 2) {
935 2 return DirectiveError::STACK_UNDERFLOW;
936 }
937 6 F64 rhs = this->m_runtime.stack.pop<F64>();
938 6 F64 lhs = this->m_runtime.stack.pop<F64>();
939 // std::fmod computes the exact truncated remainder (sign of lhs) with no
940 // intermediate rounding. A zero divisor yields NaN, matching Rust and C#.
941 6 F64 res = std::fmod(lhs, rhs);
942 // Adjust to match Python's floored-modulo semantics: if the signs of the
943 // remainder and divisor differ, add the divisor once. This mirrors op_smod
944 // and is the exact frem + fadd the VM model computes (at most one rounded add).
945
7/8
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
6 if ((res > 0 && rhs < 0) || (res < 0 && rhs > 0)) {
946 2 res += rhs;
947
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 } else if (res == 0) {
948 // Python normalizes an exact-multiple result so the zero carries the
949 // divisor's sign (CPython float_rem); fmod leaves the dividend's.
950 2 res = std::copysign(0.0, rhs);
951 }
952 6 this->m_runtime.stack.push(res);
953 6 return DirectiveError::NO_ERROR;
954 }
955 4 DirectiveError FpySequencer::op_siext_8_64() {
956
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
4 if (this->m_runtime.stack.size < sizeof(I8)) {
957 1 return DirectiveError::STACK_UNDERFLOW;
958 }
959 3 I8 src = this->m_runtime.stack.pop<I8>();
960 3 this->m_runtime.stack.push(static_cast<I64>(src));
961 3 return DirectiveError::NO_ERROR;
962 }
963 4 DirectiveError FpySequencer::op_siext_16_64() {
964
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
4 if (this->m_runtime.stack.size < sizeof(I16)) {
965 1 return DirectiveError::STACK_UNDERFLOW;
966 }
967 3 I16 src = this->m_runtime.stack.pop<I16>();
968 3 this->m_runtime.stack.push(static_cast<I64>(src));
969 3 return DirectiveError::NO_ERROR;
970 }
971 4 DirectiveError FpySequencer::op_siext_32_64() {
972
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
4 if (this->m_runtime.stack.size < sizeof(I32)) {
973 1 return DirectiveError::STACK_UNDERFLOW;
974 }
975 3 I32 src = this->m_runtime.stack.pop<I32>();
976 3 this->m_runtime.stack.push(static_cast<I64>(src));
977 3 return DirectiveError::NO_ERROR;
978 }
979 4 DirectiveError FpySequencer::op_ziext_8_64() {
980
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
4 if (this->m_runtime.stack.size < sizeof(U8)) {
981 1 return DirectiveError::STACK_UNDERFLOW;
982 }
983 3 U8 src = this->m_runtime.stack.pop<U8>();
984 3 this->m_runtime.stack.push(static_cast<U64>(src));
985 3 return DirectiveError::NO_ERROR;
986 }
987 3 DirectiveError FpySequencer::op_ziext_16_64() {
988
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
3 if (this->m_runtime.stack.size < sizeof(U16)) {
989 1 return DirectiveError::STACK_UNDERFLOW;
990 }
991 2 U16 src = this->m_runtime.stack.pop<U16>();
992 2 this->m_runtime.stack.push(static_cast<U64>(src));
993 2 return DirectiveError::NO_ERROR;
994 }
995 3 DirectiveError FpySequencer::op_ziext_32_64() {
996
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
3 if (this->m_runtime.stack.size < sizeof(U32)) {
997 1 return DirectiveError::STACK_UNDERFLOW;
998 }
999 2 U32 src = this->m_runtime.stack.pop<U32>();
1000 2 this->m_runtime.stack.push(static_cast<U64>(src));
1001 2 return DirectiveError::NO_ERROR;
1002 }
1003 3 DirectiveError FpySequencer::op_itrunc_64_8() {
1004
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
3 if (this->m_runtime.stack.size < sizeof(U64)) {
1005 1 return DirectiveError::STACK_UNDERFLOW;
1006 }
1007 2 U64 src = this->m_runtime.stack.pop<U64>();
1008 2 this->m_runtime.stack.push(static_cast<U8>(src));
1009 2 return DirectiveError::NO_ERROR;
1010 }
1011 3 DirectiveError FpySequencer::op_itrunc_64_16() {
1012
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
3 if (this->m_runtime.stack.size < sizeof(U64)) {
1013 1 return DirectiveError::STACK_UNDERFLOW;
1014 }
1015 2 U64 src = this->m_runtime.stack.pop<U64>();
1016 2 this->m_runtime.stack.push(static_cast<U16>(src));
1017 2 return DirectiveError::NO_ERROR;
1018 }
1019 3 DirectiveError FpySequencer::op_itrunc_64_32() {
1020
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
3 if (this->m_runtime.stack.size < sizeof(U64)) {
1021 1 return DirectiveError::STACK_UNDERFLOW;
1022 }
1023 2 U64 src = this->m_runtime.stack.pop<U64>();
1024 2 this->m_runtime.stack.push(static_cast<U32>(src));
1025 2 return DirectiveError::NO_ERROR;
1026 }
1027 10 DirectiveError FpySequencer::op_ffloor() {
1028
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 8 times.
10 if (this->m_runtime.stack.size < sizeof(F64)) {
1029 2 return DirectiveError::STACK_UNDERFLOW;
1030 }
1031 8 F64 val = this->m_runtime.stack.pop<F64>();
1032 // std::floor implements IEEE 754 roundToIntegralTowardNegative: +-0, +-inf
1033 // and NaN pass through, and the sign of a zero is preserved.
1034 8 this->m_runtime.stack.push(std::floor(val));
1035 8 return DirectiveError::NO_ERROR;
1036 }
1037 6 DirectiveError FpySequencer::op_iabs() {
1038
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (this->m_runtime.stack.size < sizeof(I64)) {
1039 2 return DirectiveError::STACK_UNDERFLOW;
1040 }
1041 4 I64 val = this->m_runtime.stack.pop<I64>();
1042 // abs(I64 min) is not representable in I64 (and -val on it is UB)
1043
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
4 if (val == std::numeric_limits<I64>::min()) {
1044 1 return DirectiveError::ARITHMETIC_OVERFLOW;
1045 }
1046 3 this->m_runtime.stack.push(val < 0 ? -val : val);
1047 3 return DirectiveError::NO_ERROR;
1048 }
1049 7 DirectiveError FpySequencer::op_fabs() {
1050
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 5 times.
7 if (this->m_runtime.stack.size < sizeof(F64)) {
1051 2 return DirectiveError::STACK_UNDERFLOW;
1052 }
1053 5 F64 val = this->m_runtime.stack.pop<F64>();
1054 // IEEE 754 abs: clears the sign bit and changes nothing else, so NaN
1055 // payloads pass through.
1056 5 this->m_runtime.stack.push(std::fabs(val));
1057 5 return DirectiveError::NO_ERROR;
1058 }
1059 15 Signal FpySequencer::stackOp_directiveHandler(const FpySequencer_StackOpDirective& directive, DirectiveError& error) {
1060 // coding error, should not have gotten to this stack op handler
1061 15 FW_ASSERT((directive.get__op() >= Fpy::DirectiveId::OR && directive.get__op() <= Fpy::DirectiveId::ITRUNC_64_32) ||
1062 (directive.get__op() >= Fpy::DirectiveId::FFLOOR && directive.get__op() <= Fpy::DirectiveId::FABS),
1063 static_cast<FwAssertArgType>(directive.get__op()));
1064
1065
11/52
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
15 switch (directive.get__op()) {
1066 3 case Fpy::DirectiveId::OR:
1067
2/2
✓ Branch 2 taken 3 times.
✓ Branch 9 taken 3 times.
3 error = this->op_or();
1068 3 break;
1069 1 case Fpy::DirectiveId::AND:
1070
2/2
✓ Branch 2 taken 1 times.
✓ Branch 9 taken 1 times.
1 error = this->op_and();
1071 1 break;
1072 2 case Fpy::DirectiveId::IEQ:
1073
2/2
✓ Branch 2 taken 2 times.
✓ Branch 9 taken 2 times.
2 error = this->op_ieq();
1074 2 break;
1075 1 case Fpy::DirectiveId::INE:
1076
2/2
✓ Branch 2 taken 1 times.
✓ Branch 9 taken 1 times.
1 error = this->op_ine();
1077 1 break;
1078 1 case Fpy::DirectiveId::ULT:
1079
2/2
✓ Branch 2 taken 1 times.
✓ Branch 9 taken 1 times.
1 error = this->op_ult();
1080 1 break;
1081 case Fpy::DirectiveId::ULE:
1082 error = this->op_ule();
1083 break;
1084 1 case Fpy::DirectiveId::UGT:
1085
2/2
✓ Branch 2 taken 1 times.
✓ Branch 9 taken 1 times.
1 error = this->op_ugt();
1086 1 break;
1087 2 case Fpy::DirectiveId::UGE:
1088
2/2
✓ Branch 2 taken 2 times.
✓ Branch 9 taken 2 times.
2 error = this->op_uge();
1089 2 break;
1090 1 case Fpy::DirectiveId::SLT:
1091
2/2
✓ Branch 2 taken 1 times.
✓ Branch 9 taken 1 times.
1 error = this->op_slt();
1092 1 break;
1093 case Fpy::DirectiveId::SLE:
1094 error = this->op_sle();
1095 break;
1096 case Fpy::DirectiveId::SGT:
1097 error = this->op_sgt();
1098 break;
1099 case Fpy::DirectiveId::SGE:
1100 error = this->op_sge();
1101 break;
1102 case Fpy::DirectiveId::FEQ:
1103 error = this->op_feq();
1104 break;
1105 case Fpy::DirectiveId::FNE:
1106 error = this->op_fne();
1107 break;
1108 1 case Fpy::DirectiveId::FLT:
1109
2/2
✓ Branch 2 taken 1 times.
✓ Branch 9 taken 1 times.
1 error = this->op_flt();
1110 1 break;
1111 case Fpy::DirectiveId::FLE:
1112 error = this->op_fle();
1113 break;
1114 case Fpy::DirectiveId::FGT:
1115 error = this->op_fgt();
1116 break;
1117 1 case Fpy::DirectiveId::FGE:
1118
2/2
✓ Branch 2 taken 1 times.
✓ Branch 9 taken 1 times.
1 error = this->op_fge();
1119 1 break;
1120 1 case Fpy::DirectiveId::NOT:
1121
2/2
✓ Branch 2 taken 1 times.
✓ Branch 9 taken 1 times.
1 error = this->op_not();
1122 1 break;
1123 case Fpy::DirectiveId::FPEXT:
1124 error = this->op_fpext();
1125 break;
1126 case Fpy::DirectiveId::FPTRUNC:
1127 error = this->op_fptrunc();
1128 break;
1129 case Fpy::DirectiveId::FPTOSI:
1130 error = this->op_fptosi();
1131 break;
1132 case Fpy::DirectiveId::FPTOUI:
1133 error = this->op_fptoui();
1134 break;
1135 case Fpy::DirectiveId::SITOFP:
1136 error = this->op_sitofp();
1137 break;
1138 case Fpy::DirectiveId::UITOFP:
1139 error = this->op_uitofp();
1140 break;
1141 case Fpy::DirectiveId::ADD:
1142 error = this->op_add();
1143 break;
1144 case Fpy::DirectiveId::SUB:
1145 error = this->op_sub();
1146 break;
1147 case Fpy::DirectiveId::MUL:
1148 error = this->op_mul();
1149 break;
1150 case Fpy::DirectiveId::UDIV:
1151 error = this->op_udiv();
1152 break;
1153 case Fpy::DirectiveId::SDIV:
1154 error = this->op_sdiv();
1155 break;
1156 case Fpy::DirectiveId::UMOD:
1157 error = this->op_umod();
1158 break;
1159 case Fpy::DirectiveId::SMOD:
1160 error = this->op_smod();
1161 break;
1162 case Fpy::DirectiveId::FADD:
1163 error = this->op_fadd();
1164 break;
1165 case Fpy::DirectiveId::FSUB:
1166 error = this->op_fsub();
1167 break;
1168 case Fpy::DirectiveId::FMUL:
1169 error = this->op_fmul();
1170 break;
1171 case Fpy::DirectiveId::FDIV:
1172 error = this->op_fdiv();
1173 break;
1174 case Fpy::DirectiveId::FPOW:
1175 error = this->op_fpow();
1176 break;
1177 case Fpy::DirectiveId::FLOG:
1178 error = this->op_flog();
1179 break;
1180 case Fpy::DirectiveId::FMOD:
1181 error = this->op_fmod();
1182 break;
1183 case Fpy::DirectiveId::SIEXT_8_64:
1184 error = this->op_siext_8_64();
1185 break;
1186 case Fpy::DirectiveId::SIEXT_16_64:
1187 error = this->op_siext_16_64();
1188 break;
1189 case Fpy::DirectiveId::SIEXT_32_64:
1190 error = this->op_siext_32_64();
1191 break;
1192 case Fpy::DirectiveId::ZIEXT_8_64:
1193 error = this->op_ziext_8_64();
1194 break;
1195 case Fpy::DirectiveId::ZIEXT_16_64:
1196 error = this->op_ziext_16_64();
1197 break;
1198 case Fpy::DirectiveId::ZIEXT_32_64:
1199 error = this->op_ziext_32_64();
1200 break;
1201 case Fpy::DirectiveId::ITRUNC_64_8:
1202 error = this->op_itrunc_64_8();
1203 break;
1204 case Fpy::DirectiveId::ITRUNC_64_16:
1205 error = this->op_itrunc_64_16();
1206 break;
1207 case Fpy::DirectiveId::ITRUNC_64_32:
1208 error = this->op_itrunc_64_32();
1209 break;
1210 case Fpy::DirectiveId::FFLOOR:
1211 error = this->op_ffloor();
1212 break;
1213 case Fpy::DirectiveId::IABS:
1214 error = this->op_iabs();
1215 break;
1216 case Fpy::DirectiveId::FABS:
1217 error = this->op_fabs();
1218 break;
1219 default:
1220 FW_ASSERT(false, directive.get__op());
1221 break;
1222 }
1223
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 14 times.
15 if (error != DirectiveError::NO_ERROR) {
1224 1 return Signal::stmtResponse_failure;
1225 }
1226 14 return Signal::stmtResponse_success;
1227 }
1228
1229 10 Signal FpySequencer::exit_directiveHandler(const FpySequencer_ExitDirective& directive, DirectiveError& error) {
1230
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
10 if (this->m_runtime.stack.size < sizeof(I32)) {
1231 error = DirectiveError::STACK_UNDERFLOW;
1232 return Signal::stmtResponse_failure;
1233 }
1234 10 I32 errorCode = this->m_runtime.stack.pop<I32>();
1235 // exit(0), no error
1236
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (errorCode == 0) {
1237 // just goto the end of the sequence
1238 5 this->m_runtime.nextStatementIndex = this->m_sequenceObj.get_header().get_statementCount();
1239 5 return Signal::stmtResponse_success;
1240 }
1241 // otherwise, kill the sequence here
1242 // raise the user defined error code as an event
1243 5 this->log_WARNING_HI_SequenceExitedWithError(this->m_sequenceFilePath, errorCode);
1244 5 error = DirectiveError::EXIT_WITH_ERROR;
1245 5 return Signal::stmtResponse_failure;
1246 }
1247
1248 8 Signal FpySequencer::allocate_directiveHandler(const FpySequencer_AllocateDirective& directive, DirectiveError& error) {
1249
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 7 times.
8 if (directive.get_size() > Fpy::MAX_STACK_SIZE - this->m_runtime.stack.size) {
1250 1 error = DirectiveError::STACK_OVERFLOW;
1251 1 return Signal::stmtResponse_failure;
1252 }
1253 7 this->m_runtime.stack.pushZeroes(directive.get_size());
1254 7 return Signal::stmtResponse_success;
1255 }
1256
1257 //! Helper to pop value from stack top and store at destOffset
1258 17 Signal FpySequencer::storeHelper(Fpy::StackSizeType destOffset, Fpy::StackSizeType size, DirectiveError& error) {
1259
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 15 times.
17 if (this->m_runtime.stack.size < size) {
1260 2 error = DirectiveError::STACK_UNDERFLOW;
1261 2 return Signal::stmtResponse_failure;
1262 }
1263 // After popping the value, would the write go out of bounds?
1264 15 Fpy::StackSizeType newStackSize = this->m_runtime.stack.size - size;
1265 // Overflow-safe check: destOffset + size > newStackSize
1266 // Rewritten as: check destOffset <= newStackSize first, then size > newStackSize - destOffset
1267
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
15 if (destOffset > newStackSize || size > newStackSize - destOffset) {
1268 4 error = DirectiveError::STACK_ACCESS_OUT_OF_BOUNDS;
1269 4 return Signal::stmtResponse_failure;
1270 }
1271 // Copy value to the destination location
1272 11 this->m_runtime.stack.copy(destOffset, this->m_runtime.stack.size - size, size);
1273 11 this->m_runtime.stack.size = newStackSize;
1274 11 return Signal::stmtResponse_success;
1275 }
1276
1277 //! Helper to load value from srcOffset and push to stack top
1278 19 Signal FpySequencer::loadHelper(Fpy::StackSizeType srcOffset, Fpy::StackSizeType size, DirectiveError& error) {
1279
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 17 times.
19 if (size > Fpy::MAX_STACK_SIZE - this->m_runtime.stack.size) {
1280 2 error = DirectiveError::STACK_OVERFLOW;
1281 2 return Signal::stmtResponse_failure;
1282 }
1283 // Overflow-safe check: srcOffset + size > stack.size
1284 // Rewritten as: check srcOffset <= stack.size first, then size > stack.size - srcOffset
1285
4/4
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 2 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 14 times.
17 if (srcOffset > this->m_runtime.stack.size || size > this->m_runtime.stack.size - srcOffset) {
1286 3 error = DirectiveError::STACK_ACCESS_OUT_OF_BOUNDS;
1287 3 return Signal::stmtResponse_failure;
1288 }
1289 // Copy from source location to top of stack
1290 14 this->m_runtime.stack.copy(this->m_runtime.stack.size, srcOffset, size);
1291 14 this->m_runtime.stack.size += size;
1292 14 return Signal::stmtResponse_success;
1293 }
1294
1295 7 Signal FpySequencer::storeRelConstOffset_directiveHandler(const FpySequencer_StoreRelConstOffsetDirective& directive,
1296 DirectiveError& error) {
1297 7 I64 addr = static_cast<I64>(this->m_runtime.stack.currentFrameStart) + directive.get_lvarOffset();
1298
4/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
7 if (addr < 0 || addr > Fpy::MAX_STACK_SIZE) {
1299 2 error = DirectiveError::STACK_ACCESS_OUT_OF_BOUNDS;
1300 2 return Signal::stmtResponse_failure;
1301 }
1302 5 return this->storeHelper(static_cast<Fpy::StackSizeType>(addr), directive.get_size(), error);
1303 }
1304
1305 16 Signal FpySequencer::loadRel_directiveHandler(const FpySequencer_LoadRelDirective& directive, DirectiveError& error) {
1306 16 I64 addr = static_cast<I64>(this->m_runtime.stack.currentFrameStart) + directive.get_lvarOffset();
1307
4/4
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 14 times.
16 if (addr < 0 || addr > Fpy::MAX_STACK_SIZE) {
1308 2 error = DirectiveError::STACK_ACCESS_OUT_OF_BOUNDS;
1309 2 return Signal::stmtResponse_failure;
1310 }
1311 14 return this->loadHelper(static_cast<Fpy::StackSizeType>(addr), directive.get_size(), error);
1312 }
1313
1314 48 Signal FpySequencer::pushVal_directiveHandler(const FpySequencer_PushValDirective& directive, DirectiveError& error) {
1315
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 47 times.
48 if (directive.get__valSize() > Fpy::MAX_STACK_SIZE - this->m_runtime.stack.size) {
1316 1 error = DirectiveError::STACK_OVERFLOW;
1317 1 return Signal::stmtResponse_failure;
1318 }
1319 // copy from the bytearray in the directive to the stack, add to stack size.
1320 94 this->m_runtime.stack.push(const_cast<U8*>(directive.get_val()),
1321 47 static_cast<Fpy::StackSizeType>(directive.get__valSize()));
1322 47 return Signal::stmtResponse_success;
1323 }
1324
1325 20 Signal FpySequencer::discard_directiveHandler(const FpySequencer_DiscardDirective& directive, DirectiveError& error) {
1326
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 19 times.
20 if (this->m_runtime.stack.size < directive.get_size()) {
1327 1 error = DirectiveError::STACK_UNDERFLOW;
1328 1 return Signal::stmtResponse_failure;
1329 }
1330 // drop the specified amount of bytes off the stack. simple as.
1331 19 this->m_runtime.stack.size -= directive.get_size();
1332 19 return Signal::stmtResponse_success;
1333 }
1334
1335 5 Signal FpySequencer::memCmp_directiveHandler(const FpySequencer_MemCmpDirective& directive, DirectiveError& error) {
1336 // Overflow-safe check: we need size * 2 bytes on the stack
1337 // First check that size * 2 doesn't overflow: size > MAX/2 would overflow
1338 // MAX_STACK_SIZE is the upper bound for stack.size, so if size > MAX_STACK_SIZE/2, we definitely don't have enough
1339
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 4 times.
5 if (directive.get_size() > Fpy::MAX_STACK_SIZE / 2) {
1340 1 error = DirectiveError::STACK_UNDERFLOW;
1341 1 return Signal::stmtResponse_failure;
1342 }
1343 // Now safe to compute size * 2
1344
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 3 times.
4 if (this->m_runtime.stack.size < directive.get_size() * 2) {
1345 1 error = DirectiveError::STACK_UNDERFLOW;
1346 1 return Signal::stmtResponse_failure;
1347 }
1348
1349 // find the starting offsets of the two byte arrays
1350 3 U64 lhsOffset = this->m_runtime.stack.size - directive.get_size() * 2;
1351 3 U64 rhsOffset = this->m_runtime.stack.size - directive.get_size();
1352
1353 // "officially" remove them from the stack
1354 // you have to do this before pushing to the stack, otherwise the result would get placed
1355 // after the byte arrays
1356 3 this->m_runtime.stack.size -= directive.get_size() * 2;
1357
1358 // memcmp the two byte arrays, push FW_SERIALIZE_TRUE_VALUE if they were equal, FW_SERIALIZE_FALSE_VALUE otherwise
1359
2/4
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 3 times.
3 if (memcmp(this->m_runtime.stack.bytes + lhsOffset, this->m_runtime.stack.bytes + rhsOffset,
1360
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
6 directive.get_size()) == 0) {
1361 2 this->m_runtime.stack.push<U8>(static_cast<U8>(FW_SERIALIZE_TRUE_VALUE));
1362 } else {
1363 1 this->m_runtime.stack.push<U8>(static_cast<U8>(FW_SERIALIZE_FALSE_VALUE));
1364 }
1365 3 return Signal::stmtResponse_success;
1366 }
1367
1368 4 Signal FpySequencer::stackCmd_directiveHandler(const FpySequencer_StackCmdDirective& directive, DirectiveError& error) {
1369 // Overflow-safe check: need argsSize + sizeof(FwOpcodeType) bytes
1370 // Check stack.size >= sizeof(FwOpcodeType) first, then stack.size - sizeof(FwOpcodeType) >= argsSize
1371
4/4
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 2 times.
6 if (this->m_runtime.stack.size < sizeof(FwOpcodeType) ||
1372
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
2 this->m_runtime.stack.size - sizeof(FwOpcodeType) < directive.get_argsSize()) {
1373 2 error = DirectiveError::STACK_UNDERFLOW;
1374 2 return Signal::stmtResponse_failure;
1375 }
1376
1377 // pop the opcode of the cmd off the stack
1378 // note this means that, unlike the actual byte array that the dispatcher gets,
1379 // these cmds have opcode after the argument buffer
1380 2 FwOpcodeType opcode = this->m_runtime.stack.pop<FwOpcodeType>();
1381 2 U64 argBufOffset = this->m_runtime.stack.size - directive.get_argsSize();
1382
1383 // update the opcode of the cmd we will await
1384 2 this->m_runtime.currentCmdOpcode = opcode;
1385
1386 // also pop the args off the stack
1387 2 this->m_runtime.stack.size -= directive.get_argsSize();
1388
1389 // the cmd response code will be pushed to the stack when it comes back, so make sure
1390 // there is room for it now, before the cmd is dispatched. popping the opcode above
1391 // frees some room, but FwOpcodeType is configurable so it may not be enough
1392
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if (Fpy::MAX_STACK_SIZE - sizeof(Fw::CmdResponse::SerialType) < this->m_runtime.stack.size) {
1393 error = DirectiveError::STACK_OVERFLOW;
1394 return Signal::stmtResponse_failure;
1395 }
1396
1397
2/3
✓ Branch 9 taken 2 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 2 times.
2 if (this->sendCmd(opcode, this->m_runtime.stack.bytes + argBufOffset, directive.get_argsSize()) ==
1398 Fw::Success::FAILURE) {
1399 return Signal::stmtResponse_failure;
1400 } else {
1401 // now tell the SM to wait some more until we get the cmd response back
1402 // if we've already got the response back this should be harmless
1403 2 return Signal::stmtResponse_keepWaiting;
1404 }
1405
1406 return Signal::stmtResponse_success;
1407 }
1408
1409 4 Signal FpySequencer::pushTime_directiveHandler(const FpySequencer_PushTimeDirective& directive, DirectiveError& error) {
1410
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
4 if (Fpy::MAX_STACK_SIZE - Fw::Time::SERIALIZED_SIZE < this->m_runtime.stack.size) {
1411
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::STACK_OVERFLOW;
1412 1 return Signal::stmtResponse_failure;
1413 }
1414
1415
1/1
✓ Branch 3 taken 3 times.
3 Fw::Time currentTime = this->getTime();
1416
1417 3 U8 currentTimeBuf[Fw::Time::SERIALIZED_SIZE] = {};
1418
1/1
✓ Branch 2 taken 3 times.
3 Fw::ExternalSerializeBuffer timeEsb(currentTimeBuf, Fw::Time::SERIALIZED_SIZE);
1419
1/1
✓ Branch 2 taken 3 times.
3 Fw::SerializeStatus stat = timeEsb.serializeFrom(currentTime);
1420
1421 // coding error if this failed, we should have enough space
1422 3 FW_ASSERT(stat == Fw::SerializeStatus::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(stat));
1423
1424 // push time to end of stack
1425
2/2
✓ Branch 5 taken 3 times.
✓ Branch 10 taken 3 times.
3 this->m_runtime.stack.push(timeEsb.getBuffAddr(), static_cast<Fpy::StackSizeType>(timeEsb.getSize()));
1426 3 return Signal::stmtResponse_success;
1427 3 }
1428
1429 3 Signal FpySequencer::setSeed_directiveHandler(const FpySequencer_SetSeedDirective& directive, DirectiveError& error) {
1430
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
3 if (this->m_runtime.stack.size < sizeof(U32)) {
1431 1 error = DirectiveError::STACK_UNDERFLOW;
1432 1 return Signal::stmtResponse_failure;
1433 }
1434
1435 2 U32 seed = this->m_runtime.stack.pop<U32>();
1436 2 this->m_runtime.rng.seed(seed);
1437 2 this->m_runtime.rngSeeded = true;
1438 2 return Signal::stmtResponse_success;
1439 }
1440
1441 7 Signal FpySequencer::pushRand_directiveHandler(const FpySequencer_PushRandDirective& directive, DirectiveError& error) {
1442
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 6 times.
7 if (Fpy::MAX_STACK_SIZE - sizeof(U32) < this->m_runtime.stack.size) {
1443 1 error = DirectiveError::STACK_OVERFLOW;
1444 1 return Signal::stmtResponse_failure;
1445 }
1446
1447
3/4
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 4 times.
6 if (!this->m_runtime.rngSeeded) {
1448
1/1
✓ Branch 3 taken 2 times.
2 Fw::Time currentTime = this->getTime();
1449
2/2
✓ Branch 3 taken 2 times.
✓ Branch 10 taken 2 times.
8 std::seed_seq seedSeq{static_cast<U32>(currentTime.getTimeBase()), static_cast<U32>(currentTime.getContext()),
1450
3/3
✓ Branch 4 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 11 taken 2 times.
8 currentTime.getSeconds(), currentTime.getUSeconds()};
1451
1/1
✓ Branch 4 taken 2 times.
2 this->m_runtime.rng.seed(seedSeq);
1452 2 this->m_runtime.rngSeeded = true;
1453 2 }
1454
1455 6 U32 randVal = static_cast<U32>(this->m_runtime.rng());
1456 6 this->m_runtime.stack.push(randVal);
1457 6 return Signal::stmtResponse_success;
1458 }
1459
1460 8 Signal FpySequencer::getField_directiveHandler(const FpySequencer_GetFieldDirective& directive, DirectiveError& error) {
1461 // Need sizeof(StackSizeType) for the offset AND parentSize for the parent data
1462 // Check we have enough for the offset first
1463
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 7 times.
8 if (this->m_runtime.stack.size < sizeof(Fpy::StackSizeType)) {
1464 1 error = DirectiveError::STACK_UNDERFLOW;
1465 1 return Signal::stmtResponse_failure;
1466 }
1467 // After popping the offset, we need at least parentSize bytes remaining
1468
2/2
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 5 times.
7 if (this->m_runtime.stack.size - sizeof(Fpy::StackSizeType) < directive.get_parentSize()) {
1469 2 error = DirectiveError::STACK_UNDERFLOW;
1470 2 return Signal::stmtResponse_failure;
1471 }
1472
1473 5 Fpy::StackSizeType offset = this->m_runtime.stack.pop<Fpy::StackSizeType>();
1474
1475 // Overflow-safe check: offset + memberSize > parentSize
1476 // Rewritten as: check offset <= parentSize first, then memberSize > parentSize - offset
1477
6/6
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 1 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 2 times.
✓ Branch 16 taken 3 times.
✓ Branch 17 taken 2 times.
5 if (offset > directive.get_parentSize() || directive.get_memberSize() > directive.get_parentSize() - offset) {
1478 // i think it's somewhat ambiguous whether this is a stack access out of bounds
1479 // but there isn't really an error code that better reflects this, and i guess
1480 // it's technically true
1481 3 error = DirectiveError::STACK_ACCESS_OUT_OF_BOUNDS;
1482 3 return Signal::stmtResponse_failure;
1483 }
1484
1485 // the resulting bytes should move to the start of the parent array
1486
1487 // Calculate the offset of the parent start in the stack
1488 2 Fpy::StackSizeType parentStartOffset = this->m_runtime.stack.size - directive.get_parentSize();
1489 // Overflow-safe: parentStartOffset + offset cannot overflow since offset <= parentSize
1490 // and parentStartOffset + parentSize == stack.size (which is bounded)
1491 2 this->m_runtime.stack.move(parentStartOffset, parentStartOffset + offset, directive.get_memberSize());
1492 // adjust stack size by the diff between the member and the parent
1493 2 this->m_runtime.stack.size -= (directive.get_parentSize() - directive.get_memberSize());
1494 2 return Signal::stmtResponse_success;
1495 }
1496
1497 9 Signal FpySequencer::peek_directiveHandler(const FpySequencer_PeekDirective& directive, DirectiveError& error) {
1498 // must have at least two StackSizeType on stack
1499
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 7 times.
9 if (this->m_runtime.stack.size < sizeof(Fpy::StackSizeType) * 2) {
1500 2 error = DirectiveError::STACK_UNDERFLOW;
1501 2 return Signal::stmtResponse_failure;
1502 }
1503
1504 7 Fpy::StackSizeType offset = this->m_runtime.stack.pop<Fpy::StackSizeType>();
1505 7 Fpy::StackSizeType byteCount = this->m_runtime.stack.pop<Fpy::StackSizeType>();
1506
1507 // Check offset doesn't exceed stack size (after both pops)
1508
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 6 times.
7 if (offset > this->m_runtime.stack.size) {
1509 // would access past the bottom of the stack
1510 // note we allow the equals case because the byteCount might be 0
1511 1 error = DirectiveError::STACK_ACCESS_OUT_OF_BOUNDS;
1512 1 return Signal::stmtResponse_failure;
1513 }
1514
2/2
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (byteCount > Fpy::MAX_STACK_SIZE - this->m_runtime.stack.size) {
1515 // we would overflow the stack if we pushed this many bytes to it
1516 2 error = DirectiveError::STACK_OVERFLOW;
1517 2 return Signal::stmtResponse_failure;
1518 }
1519 // Overflow-safe check: byteCount + offset > stack.size
1520 // Rewritten as: check offset <= stack.size (done above), then byteCount > stack.size - offset
1521
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 if (byteCount > this->m_runtime.stack.size - offset) {
1522 // would access past the bottom of the stack
1523 error = DirectiveError::STACK_ACCESS_OUT_OF_BOUNDS;
1524 return Signal::stmtResponse_failure;
1525 }
1526 // start copying from the lowest byte of the src array
1527 4 U8* src = this->m_runtime.stack.top() - offset - byteCount;
1528 4 this->m_runtime.stack.push(src, byteCount);
1529 4 return Signal::stmtResponse_success;
1530 }
1531
1532 7 Signal FpySequencer::storeRel_directiveHandler(const FpySequencer_StoreRelDirective& directive, DirectiveError& error) {
1533 // Need enough bytes for the value and the offset (SignedStackSizeType = 4 bytes)
1534 // Overflow-safe: check stack.size >= sizeof(SignedStackSizeType) first, then stack.size -
1535 // sizeof(SignedStackSizeType) >= size
1536
4/4
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 5 times.
13 if (this->m_runtime.stack.size < sizeof(Fpy::SignedStackSizeType) ||
1537
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 5 times.
6 this->m_runtime.stack.size - sizeof(Fpy::SignedStackSizeType) < directive.get_size()) {
1538 2 error = DirectiveError::STACK_UNDERFLOW;
1539 2 return Signal::stmtResponse_failure;
1540 }
1541
1542 // Pop the signed offset from the stack
1543 5 Fpy::SignedStackSizeType lvarOffset = this->m_runtime.stack.pop<Fpy::SignedStackSizeType>();
1544
1545 5 I64 addr = static_cast<I64>(this->m_runtime.stack.currentFrameStart) + lvarOffset;
1546
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
5 if (addr < 0 || addr > Fpy::MAX_STACK_SIZE) {
1547 1 error = DirectiveError::STACK_ACCESS_OUT_OF_BOUNDS;
1548 1 return Signal::stmtResponse_failure;
1549 }
1550 4 return this->storeHelper(static_cast<Fpy::StackSizeType>(addr), directive.get_size(), error);
1551 }
1552
1553 5 Signal FpySequencer::call_directiveHandler(const FpySequencer_CallDirective& directive, DirectiveError& error) {
1554 // Need at least 4 bytes for the target address
1555
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 4 times.
5 if (this->m_runtime.stack.size < sizeof(U32)) {
1556 1 error = DirectiveError::STACK_UNDERFLOW;
1557 1 return Signal::stmtResponse_failure;
1558 }
1559
1560 // Pop the target directive index from the stack
1561 4 U32 target = this->m_runtime.stack.pop<U32>();
1562
1563 // Check if we have space to push return address and saved frame pointer (8 bytes total)
1564
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
4 if (this->m_runtime.stack.size + sizeof(Fpy::StackSizeType) + sizeof(U32) > Fpy::MAX_STACK_SIZE) {
1565 1 error = DirectiveError::STACK_OVERFLOW;
1566 1 return Signal::stmtResponse_failure;
1567 }
1568
1569 // Check target is within bounds (will also be checked at execution time)
1570
2/2
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 2 times.
3 if (target > m_sequenceObj.get_header().get_statementCount()) {
1571 1 error = DirectiveError::STMT_OUT_OF_BOUNDS;
1572 1 return Signal::stmtResponse_failure;
1573 }
1574
1575 // Save the return address (next instruction after CALL)
1576 2 U32 returnAddr = this->m_runtime.nextStatementIndex;
1577
1578 // Set the next instruction to the target
1579 2 this->m_runtime.nextStatementIndex = target;
1580
1581 // Push the return address to the stack
1582 2 this->m_runtime.stack.push<U32>(returnAddr);
1583
1584 // Push the current frame pointer to the stack
1585 2 this->m_runtime.stack.push<Fpy::StackSizeType>(this->m_runtime.stack.currentFrameStart);
1586
1587 // Set the new frame pointer to the current top of stack
1588 2 this->m_runtime.stack.currentFrameStart = this->m_runtime.stack.size;
1589
1590 2 return Signal::stmtResponse_success;
1591 }
1592
1593 7 Signal FpySequencer::return_directiveHandler(const FpySequencer_ReturnDirective& directive, DirectiveError& error) {
1594 7 Fpy::StackSizeType returnValSize = directive.get_returnValSize();
1595 7 Fpy::StackSizeType callArgsSize = directive.get_callArgsSize();
1596
1597 // Check we have enough bytes for the return value
1598
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 6 times.
7 if (this->m_runtime.stack.size < returnValSize) {
1599 1 error = DirectiveError::STACK_UNDERFLOW;
1600 1 return Signal::stmtResponse_failure;
1601 }
1602
1603 // Remember where the return value lives; it is moved down the stack below rather than copied
1604 // through a local buffer, which at Fpy::MAX_STACK_SIZE would not fit a typical task stack
1605 6 const Fpy::StackSizeType returnValOffset = this->m_runtime.stack.size - returnValSize;
1606
1607 // Truncate the stack to stack_frame_start (discard all local variables)
1608
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 5 times.
6 if (this->m_runtime.stack.currentFrameStart > this->m_runtime.stack.size) {
1609 1 error = DirectiveError::FRAME_START_OUT_OF_BOUNDS;
1610 1 return Signal::stmtResponse_failure;
1611 }
1612 5 this->m_runtime.stack.size = this->m_runtime.stack.currentFrameStart;
1613
1614 // Check we have enough bytes for saved frame pointer and return address
1615
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
5 if (this->m_runtime.stack.size < sizeof(Fpy::StackSizeType) + sizeof(U32)) {
1616 error = DirectiveError::STACK_UNDERFLOW;
1617 return Signal::stmtResponse_failure;
1618 }
1619
1620 // Pop the saved frame pointer
1621 5 Fpy::StackSizeType savedFramePtr = this->m_runtime.stack.pop<Fpy::StackSizeType>();
1622
1623 // Pop the return address
1624 5 U32 returnAddr = this->m_runtime.stack.pop<U32>();
1625
1626 // Restore the frame pointer
1627
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 4 times.
5 if (savedFramePtr > this->m_runtime.stack.size) {
1628 1 error = DirectiveError::FRAME_START_OUT_OF_BOUNDS;
1629 1 return Signal::stmtResponse_failure;
1630 }
1631 4 this->m_runtime.stack.currentFrameStart = savedFramePtr;
1632
1633 // Validate the return address is within bounds
1634
2/2
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 3 times.
4 if (returnAddr > m_sequenceObj.get_header().get_statementCount()) {
1635 1 error = DirectiveError::STMT_OUT_OF_BOUNDS;
1636 1 return Signal::stmtResponse_failure;
1637 }
1638
1639 // Set the next instruction to the return address
1640 3 this->m_runtime.nextStatementIndex = returnAddr;
1641
1642 // Check that we have enough bytes for the call arguments
1643
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
3 if (this->m_runtime.stack.size < callArgsSize) {
1644 1 error = DirectiveError::STACK_UNDERFLOW;
1645 1 return Signal::stmtResponse_failure;
1646 }
1647 // Discard the function arguments
1648 2 this->m_runtime.stack.size -= callArgsSize;
1649
1650 // Push the return value
1651
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if (returnValSize > Fpy::MAX_STACK_SIZE - this->m_runtime.stack.size) {
1652 error = DirectiveError::STACK_OVERFLOW;
1653 return Signal::stmtResponse_failure;
1654 }
1655
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (returnValSize > 0) {
1656 // Not Stack::move: the source region sits above the truncated stack size, which
1657 // Stack::move rejects. Both regions were bounds-checked above against MAX_STACK_SIZE.
1658
2/4
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
1 (void)memmove(this->m_runtime.stack.top(), &this->m_runtime.stack.bytes[returnValOffset], returnValSize);
1659 1 this->m_runtime.stack.size += returnValSize;
1660 }
1661
1662 2 return Signal::stmtResponse_success;
1663 }
1664
1665 5 Signal FpySequencer::loadAbs_directiveHandler(const FpySequencer_LoadAbsDirective& directive, DirectiveError& error) {
1666 5 return this->loadHelper(directive.get_globalOffset(), directive.get_size(), error);
1667 }
1668
1669 5 Signal FpySequencer::storeAbs_directiveHandler(const FpySequencer_StoreAbsDirective& directive, DirectiveError& error) {
1670 5 Fpy::StackSizeType size = directive.get_size();
1671
1672 // Need enough bytes for the value and the offset
1673 // Overflow-safe: check stack.size >= sizeof(StackSizeType) first, then stack.size - sizeof >= size
1674
2/2
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 1 times.
5 if (this->m_runtime.stack.size < sizeof(Fpy::StackSizeType) ||
1675
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
4 this->m_runtime.stack.size - sizeof(Fpy::StackSizeType) < size) {
1676 2 error = DirectiveError::STACK_UNDERFLOW;
1677 2 return Signal::stmtResponse_failure;
1678 }
1679
1680 // Pop the global offset from the stack
1681 3 Fpy::StackSizeType globalOffset = this->m_runtime.stack.pop<Fpy::StackSizeType>();
1682
1683 3 return this->storeHelper(globalOffset, size, error);
1684 }
1685
1686 5 Signal FpySequencer::storeAbsConstOffset_directiveHandler(const FpySequencer_StoreAbsConstOffsetDirective& directive,
1687 DirectiveError& error) {
1688 5 return this->storeHelper(directive.get_globalOffset(), directive.get_size(), error);
1689 }
1690
1691 12 Signal FpySequencer::popEvent_directiveHandler(const FpySequencer_PopEventDirective& directive, DirectiveError& error) {
1692 // Pop messageSize from the stack
1693
2/2
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 11 times.
12 if (this->m_runtime.stack.size < sizeof(Fpy::StackSizeType)) {
1694
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::STACK_UNDERFLOW;
1695 1 return Signal::stmtResponse_failure;
1696 }
1697
1/1
✓ Branch 5 taken 11 times.
11 Fpy::StackSizeType messageSize = this->m_runtime.stack.pop<Fpy::StackSizeType>();
1698
1699 11 const Fpy::StackSizeType severitySize = static_cast<Fpy::StackSizeType>(sizeof(Fw::LogSeverity::SerialType));
1700
1701 // Need message_size bytes + sizeof(LogSeverity serial type) for severity
1702
3/4
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 9 times.
11 if (this->m_runtime.stack.size < severitySize || this->m_runtime.stack.size - severitySize < messageSize) {
1703
1/1
✓ Branch 4 taken 2 times.
2 error = DirectiveError::STACK_UNDERFLOW;
1704 2 return Signal::stmtResponse_failure;
1705 }
1706
1707 // Pop message bytes first
1708 9 U8 messageBuf[FW_LOG_STRING_MAX_SIZE] = {};
1709 // don't read in more than (log string size) - 1 bytes
1710 9 Fpy::StackSizeType clampedSize = std::min(messageSize, static_cast<Fpy::StackSizeType>(FW_LOG_STRING_MAX_SIZE - 1));
1711 // If message is larger than buffer, discard the excess bytes first (from top of stack, which is the end of the
1712 // message)
1713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (messageSize > clampedSize) {
1714 Fpy::StackSizeType excess = messageSize - clampedSize;
1715 FW_ASSERT(this->m_runtime.stack.size >= excess, static_cast<FwAssertArgType>(this->m_runtime.stack.size),
1716 static_cast<FwAssertArgType>(excess));
1717 this->m_runtime.stack.size -= excess;
1718 }
1719
1/1
✓ Branch 4 taken 9 times.
9 this->m_runtime.stack.pop(messageBuf, clampedSize);
1720 9 messageBuf[clampedSize] = '\0';
1721
1722 // Pop severity
1723
1/1
✓ Branch 4 taken 9 times.
9 Fw::LogSeverity::SerialType severity = this->m_runtime.stack.pop<Fw::LogSeverity::SerialType>();
1724
1725 // Construct the message string
1726
1/1
✓ Branch 2 taken 9 times.
9 Fw::String messageStr(reinterpret_cast<const char*>(messageBuf));
1727
1728 // Emit the appropriate event based on severity
1729
8/8
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
9 switch (severity) {
1730 1 case Fw::LogSeverity::FATAL:
1731
1/1
✓ Branch 8 taken 1 times.
1 this->log_FATAL_LogFatal(this->m_sequenceFilePath, messageStr);
1732 1 break;
1733 1 case Fw::LogSeverity::WARNING_HI:
1734
1/1
✓ Branch 8 taken 1 times.
1 this->log_WARNING_HI_LogWarningHi(this->m_sequenceFilePath, messageStr);
1735 1 break;
1736 1 case Fw::LogSeverity::WARNING_LO:
1737
1/1
✓ Branch 8 taken 1 times.
1 this->log_WARNING_LO_LogWarningLo(this->m_sequenceFilePath, messageStr);
1738 1 break;
1739 1 case Fw::LogSeverity::COMMAND:
1740
1/1
✓ Branch 8 taken 1 times.
1 this->log_COMMAND_LogCommand(this->m_sequenceFilePath, messageStr);
1741 1 break;
1742 2 case Fw::LogSeverity::ACTIVITY_HI:
1743
1/1
✓ Branch 8 taken 2 times.
2 this->log_ACTIVITY_HI_LogActivityHi(this->m_sequenceFilePath, messageStr);
1744 2 break;
1745 1 case Fw::LogSeverity::ACTIVITY_LO:
1746
1/1
✓ Branch 8 taken 1 times.
1 this->log_ACTIVITY_LO_LogActivityLo(this->m_sequenceFilePath, messageStr);
1747 1 break;
1748 1 case Fw::LogSeverity::DIAGNOSTIC:
1749
1/1
✓ Branch 8 taken 1 times.
1 this->log_DIAGNOSTIC_LogDiagnostic(this->m_sequenceFilePath, messageStr);
1750 1 break;
1751 1 default:
1752
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::INVALID_ARG;
1753 1 return Signal::stmtResponse_failure;
1754 }
1755
1756 8 return Signal::stmtResponse_success;
1757 9 }
1758
1759 9 Signal FpySequencer::popSerializable_directiveHandler(const FpySequencer_PopSerializableDirective& directive,
1760 DirectiveError& error) {
1761 // No size assertion here: an oversized size is untrusted sequence content and is rejected by
1762 // the stack check below, since the stack can never hold more than Fpy::MAX_STACK_SIZE bytes
1763
1764 // Validate port index is in range (using enum constant value)
1765 9 constexpr FwIndexType MAX_PORTS = static_cast<FwIndexType>(Svc::Fpy::SerialPortIndex::MAX_SERIAL_PORTS);
1766 9 const FwIndexType portIndex = directive.get_portIndex();
1767
1768 // Check for negative port index or out of bounds
1769
3/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 8 times.
9 if (portIndex < 0 || portIndex >= MAX_PORTS) {
1770
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::SERIAL_PORT_INVALID_INDEX;
1771 1 return Signal::stmtResponse_failure;
1772 }
1773
1774 // Check port is connected
1775
3/3
✓ Branch 5 taken 8 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 7 times.
8 if (!this->isConnected_serialOut_OutputPort(portIndex)) {
1776
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::SERIAL_PORT_NOT_CONNECTED;
1777 1 return Signal::stmtResponse_failure;
1778 }
1779
1780 // Validate data size on stack
1781
2/2
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 6 times.
7 if (this->m_runtime.stack.size < directive.get_size()) {
1782
1/1
✓ Branch 4 taken 1 times.
1 error = DirectiveError::STACK_UNDERFLOW;
1783 1 return Signal::stmtResponse_failure;
1784 }
1785
1786 // Create external buffer referencing stack data (no copy)
1787
1/1
✓ Branch 4 taken 6 times.
6 U8* dataPtr = this->m_runtime.stack.top() - directive.get_size();
1788
1/1
✓ Branch 6 taken 6 times.
6 Fw::ExternalSerializeBuffer buf(dataPtr, directive.get_size());
1789
1790 // Set buffer length and verify success
1791
1/1
✓ Branch 6 taken 6 times.
6 Fw::SerializeStatus stat = buf.setBuffLen(directive.get_size());
1792 6 FW_ASSERT(stat == Fw::SerializeStatus::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(stat));
1793
1794 // Call output port and verify serialization succeeds
1795
1/1
✓ Branch 5 taken 6 times.
6 Fw::SerializeStatus portStatus = this->serialOut_out(portIndex, buf);
1796 6 FW_ASSERT(portStatus == Fw::SerializeStatus::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(portStatus));
1797
1798 // Pop data from stack
1799 6 this->m_runtime.stack.size -= directive.get_size();
1800
1801 6 return Signal::stmtResponse_success;
1802 6 }
1803
1804 } // namespace Svc
1805