MCPcopy Create free account
hub / github.com/devosoft/avida / FindLabel

Method FindLabel

avida-core/source/cpu/cHardwareCPU.cc:1177–1212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1175/////////////////////////////////////////////////////////////////////////
1176
1177cHeadCPU cHardwareCPU::FindLabel(int direction)
1178{
1179 cHeadCPU & inst_ptr = getIP();
1180
1181 // Start up a search head at the position of the instruction pointer.
1182 cHeadCPU search_head(inst_ptr);
1183 cCodeLabel & search_label = GetLabel();
1184
1185 // Make sure the label is of size > 0.
1186
1187 if (search_label.GetSize() == 0) {
1188 return inst_ptr;
1189 }
1190
1191 // Call special functions depending on if jump is forwards or backwards.
1192 int found_pos = 0;
1193 if ( direction < 0 ) {
1194 found_pos = FindLabel_Backward(search_label, m_memory, inst_ptr.GetPosition() - search_label.GetSize());
1195 }
1196
1197 // Jump forward.
1198 else if (direction > 0) {
1199 found_pos = FindLabel_Forward(search_label, m_memory, inst_ptr.GetPosition());
1200 }
1201
1202 // Jump forward from the very beginning.
1203 else {
1204 found_pos = FindLabel_Forward(search_label, m_memory, 0);
1205 }
1206
1207 // Return the last line of the found label, if it was found.
1208 if (found_pos >= 0) search_head.Set(found_pos - 1);
1209
1210 // Return the found position (still at start point if not found).
1211 return search_head;
1212}
1213
1214
1215// Search forwards for search_label from _after_ position pos in the

Callers

nothing calls this directly

Calls 9

AbsSetMethod · 0.80
GetSizeMethod · 0.45
GetPositionMethod · 0.45
SetMethod · 0.45
InMemoryMethod · 0.45
IsNopMethod · 0.45
GetInstMethod · 0.45
GetNopModMethod · 0.45
AbsJumpMethod · 0.45

Tested by

no test coverage detected