1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-11-17 09:04:43 +00:00

Fix a couple of obscure bugs

The code that checked to see if a data target was inside a data
operand wasn't going all the way back to the start of the file.
It was also failing to stop when it should, wasting time.

The anattrib validation method has code that avoids a false-positive
on certain complex embedded instruction arrangements.  This was also
preventing it from seeing a transition from a data area to the
middle of an instruction (caused by issue #45).
This commit is contained in:
Andy McFadden 2019-09-04 17:48:55 -07:00
parent 431ad94d95
commit ee6e5d7fb6
4 changed files with 26 additions and 6 deletions

View File

@ -303,11 +303,15 @@ namespace SourceGen {
// (Note the uncategorized data pass hasn't run yet, so only instructions
// and offsets identified by users or scripts have been categorized.)
int scanOffset = targetOffset;
while (--scanOffset > 0) {
while (--scanOffset >= 0) {
FormatDescriptor dfd = mAnattribs[scanOffset].DataDescriptor;
if (dfd != null && scanOffset + dfd.Length > targetOffset) {
// Descriptor encompasses target offset. Adjust target.
targetOffset = scanOffset;
if (dfd != null) {
if (scanOffset + dfd.Length > targetOffset) {
// Found a descriptor that encompasses target offset. Adjust
// target to point at the start of the region.
targetOffset = scanOffset;
}
// Descriptors aren't allowed to overlap, so either way we're done.
break;
}
}

View File

@ -1308,6 +1308,7 @@ namespace SourceGen {
int offset = 0;
while (offset < mFileData.Length) {
Anattrib attr = mAnattribs[offset];
bool thisIsCode = attr.IsInstructionStart;
Debug.Assert(attr.IsStart);
Debug.Assert(attr.Length != 0);
offset += attr.Length;
@ -1321,6 +1322,12 @@ namespace SourceGen {
extraInstrBytes++;
offset++;
}
// Make sure the extra code bytes were part of an instruction. Otherwise it
// means we moved from the end of a data area to the middle of an instruction,
// which is very bad.
Debug.Assert(extraInstrBytes == 0 || thisIsCode);
//if (extraInstrBytes > 0) { Debug.WriteLine("EIB=" + extraInstrBytes); }
// Max instruction len is 4, so the stray part must be shorter.
Debug.Assert(extraInstrBytes < 4);

View File

@ -231,8 +231,10 @@ value. If it's not checked, anything that isn't detected as code or
explicitly formatted as data will be shown as individual byte values.</p>
<p>If "seek nearby targets" is checked, the analyzer will try to use
nearby labels for data loads and stores, adjusting them to fit
(e.g. <code>LDA LABEL+1</code>). If not enabled, labels are only used
when they match exactly.</p>
(e.g. <code>LDA LABEL+1</code>). If not enabled, labels are not applied
unless they match exactly. Note that references into the middle of an
instruction or formatted data area are always adjusted, regardless of
how this is set. This setting has no effect on local variables.</p>
<p>If "smart PLP handling" is checked, the analyzer will try to use
the processor status flags from a nearby <code>PHP</code> when a
<code>PLP</code> is encountered. If not enabled, all flags are set to

View File

@ -109,6 +109,9 @@
<Compile Include="WpfGui\EditInstructionOperand.xaml.cs">
<DependentUpon>EditInstructionOperand.xaml</DependentUpon>
</Compile>
<Compile Include="WpfGui\EditInstructionOperand2.xaml.cs">
<DependentUpon>EditInstructionOperand2.xaml</DependentUpon>
</Compile>
<Compile Include="WpfGui\EditLabel.xaml.cs">
<DependentUpon>EditLabel.xaml</DependentUpon>
</Compile>
@ -266,6 +269,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="WpfGui\EditInstructionOperand2.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="WpfGui\EditLabel.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>