Skip to content

Commit

Permalink
Merge branch 'main' into 4.0.0-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TollyH committed May 31, 2024
2 parents c49f412 + 937d844 commit 242c03a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions AssemblerWarnings.Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public partial class AssemblerWarnings
{ 0022, Strings_AssemblerWarnings.Suggestion_0022 },
{ 0023, Strings_AssemblerWarnings.Suggestion_0023 },
{ 0024, Strings_AssemblerWarnings.Suggestion_0024 },
{ 0025, Strings_AssemblerWarnings.Suggestion_0025 },
};

public static Dictionary<int, string> GetMessagesForSeverity(WarningSeverity severity)
Expand Down
34 changes: 26 additions & 8 deletions AssemblerWarnings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public void NewLabel(string labelName, FilePosition filePosition, string? macroN
{
UpdateDisabledPositions(filePosition);
labelDefinitionPositions[labelName] = (filePosition, macroName);
consecutiveDatCount = 0;
}

/// <summary>
Expand Down Expand Up @@ -289,6 +290,7 @@ public AssemblerWarnings(bool usingV1Format)
{ 0023, Analyzer_Rolling_Suggestion_0023 },
#endif
{ 0024, Analyzer_Rolling_Suggestion_0024 },
{ 0025, Analyzer_Rolling_Suggestion_0025 },
};

nonFatalErrorFinalAnalyzers = new Dictionary<int, FinalWarningAnalyzer>();
Expand Down Expand Up @@ -345,6 +347,7 @@ public AssemblerWarnings(bool usingV1Format)
private string? lastMacroName;
private int lastMacroLineDepth;
private Stack<Assembler.ImportStackFrame> lastImportStack = new();
private int consecutiveDatCount = 0;

private void PreAnalyzeStateUpdate()
{
Expand Down Expand Up @@ -383,25 +386,34 @@ private void PreAnalyzeStateUpdate()
if (instructionIsData)
{
dataInsertionLines.Add((filePosition, macroName, macroLineDepth));
if (operands[0][0] == '"' && (
mnemonic.Equals("%DAT", StringComparison.OrdinalIgnoreCase)
|| mnemonic.Equals("DAT", StringComparison.OrdinalIgnoreCase)))
if (mnemonic.Equals("%DAT", StringComparison.OrdinalIgnoreCase)
|| mnemonic.Equals("DAT", StringComparison.OrdinalIgnoreCase))
{
instructionIsString = true;
if (lastInstructionWasString)
if (operands[0][0] == '"')
{
consecutiveDatCount = 0;
instructionIsString = true;
if (lastInstructionWasString)
{
// Only store the last in a chain of string insertions
endingStringInsertionLines.RemoveAt(endingStringInsertionLines.Count - 1);
}
endingStringInsertionLines.Add((filePosition, macroName, macroLineDepth));
}
else
{
// Only store the last in a chain of string insertions
endingStringInsertionLines.RemoveAt(endingStringInsertionLines.Count - 1);
consecutiveDatCount++;
}
endingStringInsertionLines.Add((filePosition, macroName, macroLineDepth));
}
}
else if (instructionIsImport)
{
consecutiveDatCount = 0;
importLines.Add((filePosition, macroName, macroLineDepth));
}
else if (newBytes.Length > 0)
{
consecutiveDatCount = 0;
lastExecutableLine[filePosition.File] = filePosition.Line;
_ = executableAddresses.Add(currentAddress);
instructionIsExecutable = true;
Expand Down Expand Up @@ -1227,6 +1239,12 @@ private bool Analyzer_Rolling_Suggestion_0024()
&& !operands[1].Contains('[');
}

private bool Analyzer_Rolling_Suggestion_0025()
{
// Suggestion 0025: Use the %NUM directive instead of 8 consecutive %DAT directives.
return newBytes.Length > 0 && consecutiveDatCount > 0 && consecutiveDatCount % 8 == 0;
}

#if DISPLACEMENT
[GeneratedRegex(@"\[.*(?:[0-9]?\.[0-9]|[0-9]\.[0-9]?)")]
private static partial Regex FloatingPointDisplacementRegex();
Expand Down
9 changes: 9 additions & 0 deletions Resources/Localization/Strings.AssemblerWarnings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Resources/Localization/Strings.AssemblerWarnings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,7 @@
<data name="Warning_0036" xml:space="preserve">
<value>Pointer size other than 8 bits (`B*`) used in a context where a single byte will always be read.</value>
</data>
<data name="Suggestion_0025" xml:space="preserve">
<value>Use the %NUM directive instead of 8 consecutive %DAT directives.</value>
</data>
</root>
2 changes: 2 additions & 0 deletions Test/KitchenSink.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
; The exact binary output that this program should produce
; is located in KitchenSink.bin

%ANALYZER suggestion, 0025, 0

:ENTRY
MVQ rg0, 69.0

Expand Down

0 comments on commit 242c03a

Please sign in to comment.