diff --git a/SourceGen/Anattrib.cs b/SourceGen/Anattrib.cs index ad85e55..944bf44 100644 --- a/SourceGen/Anattrib.cs +++ b/SourceGen/Anattrib.cs @@ -218,8 +218,8 @@ namespace SourceGen { public int Address { get; set; } /// - /// Instructions: length of the instruction (for InstrStart). If a FormatDescriptor - /// is assigned, the length must match. + /// Instructions: length of the instruction (for InstrStart). If a FormatDescriptor is + /// assigned, the length must match, or the dfd will be ignored. /// Inline data: FormatDescriptor length, or zero if no descriptor is defined. /// Data: FormatDescriptor length, or zero if no descriptor is defined. /// diff --git a/SourceGen/DisasmProject.cs b/SourceGen/DisasmProject.cs index c61fd26..260cf53 100644 --- a/SourceGen/DisasmProject.cs +++ b/SourceGen/DisasmProject.cs @@ -581,6 +581,58 @@ namespace SourceGen { return sb.ToString(); } + /// + /// Checks some stuff. Problems are handled with assertions, so this is only + /// useful in debug builds. + /// + public void Validate() { + // Confirm that we can walk through the file, stepping directly from the start + // of one thing to the start of the next. + 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; + + // Sometimes embedded instructions continue past the "outer" instruction, + // usually because we're misinterpreting the code. We need to deal with + // that here. + int extraInstrBytes = 0; + while (offset < mFileData.Length && mAnattribs[offset].IsInstruction && + !mAnattribs[offset].IsInstructionStart) { + 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); + } + Debug.Assert(offset == mFileData.Length); + + // Confirm that all bytes are tagged as code, data, or inline data. The Asserts + // in Anattrib should confirm that nothing is tagged as more than one thing. + for (offset = 0; offset < mAnattribs.Length; offset++) { + Anattrib attr = mAnattribs[offset]; + Debug.Assert(attr.IsInstruction || attr.IsInlineData || attr.IsData); + } + + // Confirm that there are no Default format entries in OperandFormats. + foreach (KeyValuePair kvp in OperandFormats) { + Debug.Assert(kvp.Value.FormatType != FormatDescriptor.Type.Default); + Debug.Assert(kvp.Value.FormatType != FormatDescriptor.Type.REMOVE); + } + } + + #region Analysis + /// /// Analyzes the file data. This is the main entry point for code/data analysis. /// @@ -1298,55 +1350,10 @@ namespace SourceGen { }); } - /// - /// Checks some stuff. Problems are handled with assertions, so this is only - /// useful in debug builds. - /// - public void Validate() { - // Confirm that we can walk through the file, stepping directly from the start - // of one thing to the start of the next. - 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; + #endregion Analysis - // Sometimes embedded instructions continue past the "outer" instruction, - // usually because we're misinterpreting the code. We need to deal with - // that here. - int extraInstrBytes = 0; - while (offset < mFileData.Length && mAnattribs[offset].IsInstruction && - !mAnattribs[offset].IsInstructionStart) { - 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); - } - Debug.Assert(offset == mFileData.Length); - - // Confirm that all bytes are tagged as code, data, or inline data. The Asserts - // in Anattrib should confirm that nothing is tagged as more than one thing. - for (offset = 0; offset < mAnattribs.Length; offset++) { - Anattrib attr = mAnattribs[offset]; - Debug.Assert(attr.IsInstruction || attr.IsInlineData || attr.IsData); - } - - // Confirm that there are no Default format entries in OperandFormats. - foreach (KeyValuePair kvp in OperandFormats) { - Debug.Assert(kvp.Value.FormatType != FormatDescriptor.Type.Default); - Debug.Assert(kvp.Value.FormatType != FormatDescriptor.Type.REMOVE); - } - } + #region Change Management /// /// Generates a ChangeSet that merges the FormatDescriptors in the new list into @@ -1978,6 +1985,8 @@ namespace SourceGen { } } + #endregion Change Management + /// /// Finds a label by name. SymbolTable must be populated. /// diff --git a/SourceGen/MainController.cs b/SourceGen/MainController.cs index 8205017..8c2e969 100644 --- a/SourceGen/MainController.cs +++ b/SourceGen/MainController.cs @@ -3267,6 +3267,12 @@ namespace SourceGen { // If the descriptor has a weak reference to an unknown symbol, should we // call that out here? sb.AppendFormat(Res.Strings.INFO_FD_SUM_FMT, dfd.ToUiString()); + + // If the format descriptor for an instruction has the wrong length, it will + // be ignored. Call that out. + if (attr.IsInstructionStart && attr.Length != dfd.Length) { + sb.AppendFormat(" [incorrect format length]"); + } } sb.Append("\r\n");