Skip to content

Commit

Permalink
Added support for AT&T (nasm) syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
HJLebbink committed Jun 16, 2017
1 parent 28e6dae commit c46281a
Show file tree
Hide file tree
Showing 21 changed files with 742 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private IEnumerable<Completion> Mnemonic_Operand_Completions(bool useCapitals, I
SortedSet<Completion> completions = new SortedSet<Completion>(new CompletionComparer());
foreach (string keyword in this._asmDudeTools.Get_Keywords())
{
AsmTokenType type = this._asmDudeTools.Get_Token_Type(keyword);
AsmTokenType type = this._asmDudeTools.Get_Token_Type_Intel(keyword);

Arch arch = this._asmDudeTools.Get_Architecture(keyword);
bool selected = Is_Register_Switched_On(arch);
Expand Down Expand Up @@ -431,7 +431,7 @@ private IEnumerable<Completion> Selected_Completions(bool useCapitals, ISet<AsmT
//Add the completions that are defined in the xml file
foreach (string keyword in this._asmDudeTools.Get_Keywords())
{
AsmTokenType type = this._asmDudeTools.Get_Token_Type(keyword);
AsmTokenType type = this._asmDudeTools.Get_Token_Type_Intel(keyword);
if (selectedTypes.Contains(type))
{
Arch arch = Arch.NONE;
Expand All @@ -444,9 +444,9 @@ private IEnumerable<Completion> Selected_Completions(bool useCapitals, ISet<AsmT
{
if (!usedAssember.HasFlag(AssemblerEnum.MASM)) selected = false;
}
else if (assembler.HasFlag(AssemblerEnum.NASM))
else if (assembler.HasFlag(AssemblerEnum.NASM_INTEL) || assembler.HasFlag(AssemblerEnum.NASM_ATT))
{
if (!usedAssember.HasFlag(AssemblerEnum.NASM)) selected = false;
if (!usedAssember.HasFlag(AssemblerEnum.NASM_INTEL)) selected = false;
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions VS/CSHARP/asm-dude-vsix/CodeFolding/CodeFoldingTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private TextBlock Get_Hover_Text_TextBlock(int beginLineNumber, int endLineNumbe
{
return Is_Start_Masm_Keyword(lineContent, lineNumber);
}
else if (usedAssember.HasFlag(AssemblerEnum.NASM))
else if (usedAssember.HasFlag(AssemblerEnum.NASM_INTEL) || usedAssember.HasFlag(AssemblerEnum.NASM_ATT))
{
return Is_Start_Nasm_Keyword(lineContent, lineNumber);
}
Expand Down Expand Up @@ -330,7 +330,7 @@ private int Is_End_Keyword(string lineContent, int lineNumber)
{
return Is_End_Masm_Keyword(lineContent, lineNumber);
}
else if (usedAssember.HasFlag(AssemblerEnum.NASM))
else if (usedAssember.HasFlag(AssemblerEnum.NASM_INTEL) || usedAssember.HasFlag(AssemblerEnum.NASM_ATT))
{
return Is_End_Nasm_Keyword(lineContent, lineNumber);
}
Expand Down
11 changes: 6 additions & 5 deletions VS/CSHARP/asm-dude-vsix/OptionsPage/AsmDudeOptionPageUI.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
<ScrollViewer>
<StackPanel>
<Label x:Name="version_UI" Content="AsmDude version" />
<Grid>
<Label Content="Flavor:" HorizontalAlignment="Left"/>
<RadioButton x:Name="usedAssemblerMasm_UI" GroupName="usedAssembler_UI" ToolTip="Configure AsmDude for Intel syntax MASM" Content="Intel Masm" Margin="140,5,0,0" HorizontalAlignment="Left" Width="Auto" />
<RadioButton x:Name="usedAssemblerNasm_UI" GroupName="usedAssembler_UI" ToolTip="Configure AsmDude for Intel syntax NASM" Content="Intel Nasm" Margin="240,5,0,0" HorizontalAlignment="Left" Width="Auto" />
<RadioButton x:Name="usedAssemblerAtt_UI" GroupName="usedAssembler_UI" ToolTip="Configure AsmDude for AT&amp;T syntax NASM" Content="AT&amp;T Nasm" Margin="340,5,0,0" HorizontalAlignment="Left" Width="Auto" />
</Grid>
<GroupBox Header="Syntax Highlighting" BorderBrush="DarkGray">
<Grid>
<StackPanel>
<CheckBox x:Name="SyntaxHighlighting_On_UI" ToolTip="Syntax highlighting enabled" Content="Enable syntax highlighting" Margin="0,4,0,4" HorizontalAlignment="Left" Width="Auto" />
<Grid>
<Label Content="Compiler:" HorizontalAlignment="Left"/>
<RadioButton x:Name="usedAssemblerMasm_UI" GroupName="usedAssembler_UI" ToolTip="Enable syntax highlighting for MASM" Content="Masm" Margin="140,5,0,0" HorizontalAlignment="Left" Width="Auto" />
<RadioButton x:Name="usedAssemblerNasm_UI" GroupName="usedAssembler_UI" ToolTip="Enable syntax highlighting for NASM" Content="Nasm" Margin="240,5,0,0" HorizontalAlignment="Left" Width="Auto" />
</Grid>
<Grid>
<Label Content="Mnemonic:" HorizontalAlignment="Left"/>
<CheckBox x:Name="ColorMnemonic_Italic_UI" Content="Italic" Margin="130,6,0,2" HorizontalAlignment="Left" Width="Auto" />
Expand Down
62 changes: 33 additions & 29 deletions VS/CSHARP/asm-dude-vsix/OptionsPage/AsmDudeOptionPageUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public AsmDudeOptionsPageUI()
}

#region Event Handlers to disable options

private void SyntaxHighlighting_Update(bool value)
{
this.ColorMnemonic_UI.IsEnabled = value;
Expand All @@ -76,8 +75,7 @@ private void SyntaxHighlighting_Update(bool value)
this.ColorUserDefined3_UI.IsEnabled = value;
this.ColorUserDefined3_Italic_UI.IsEnabled = value;
}

private void AsmDoc_Update(bool value)
private void AsmDoc_Update(bool value)
{
this.AsmDoc_Url_UI.IsEnabled = value;
}
Expand Down Expand Up @@ -118,25 +116,54 @@ public string AsmDoc_Url
}
#endregion Asm Documentation

public AssemblerEnum UsedAssembler
{
get
{
if (this.usedAssemblerMasm_UI.IsChecked.HasValue && this.usedAssemblerMasm_UI.IsChecked.Value) return AssemblerEnum.MASM;
if (this.usedAssemblerNasm_UI.IsChecked.HasValue && this.usedAssemblerNasm_UI.IsChecked.Value) return AssemblerEnum.NASM_INTEL;
if (this.usedAssemblerAtt_UI.IsChecked.HasValue && this.usedAssemblerAtt_UI.IsChecked.Value) return AssemblerEnum.NASM_ATT;
return AssemblerEnum.MASM; // if nothing is checked somehow return MASM
}
set
{
if (value.HasFlag(AssemblerEnum.MASM))
{
this.usedAssemblerMasm_UI.IsChecked = true;
this.usedAssemblerNasm_UI.IsChecked = false;
this.usedAssemblerAtt_UI.IsChecked = false;
}
else if (value.HasFlag(AssemblerEnum.NASM_INTEL))
{
this.usedAssemblerMasm_UI.IsChecked = false;
this.usedAssemblerNasm_UI.IsChecked = true;
this.usedAssemblerAtt_UI.IsChecked = false;
}
else if (value.HasFlag(AssemblerEnum.NASM_ATT))
{
this.usedAssemblerMasm_UI.IsChecked = false;
this.usedAssemblerNasm_UI.IsChecked = false;
this.usedAssemblerAtt_UI.IsChecked = true;
}
}
}

#region Code Folding
public bool CodeFolding_On
{
get { return this.CodeFolding_On_UI.IsChecked ?? false; }
set { this.CodeFolding_On_UI.IsChecked = value; }
}

public bool CodeFolding_IsDefaultCollaped
{
get { return this.CodeFolding_IsDefaultCollaped_UI.IsChecked ?? false; }
set { this.CodeFolding_IsDefaultCollaped_UI.IsChecked = value; }
}

public string CodeFolding_BeginTag
{
get { return this.CodeFolding_BeginTag_UI.Text; }
set { this.CodeFolding_BeginTag_UI.Text = value; }
}

public string CodeFolding_EndTag
{
get { return this.CodeFolding_EndTag_UI.Text; }
Expand All @@ -152,29 +179,6 @@ public bool SyntaxHighlighting_On
set { this.SyntaxHighlighting_On_UI.IsChecked = value; }
}

public AssemblerEnum UsedAssembler
{
get
{
if (this.usedAssemblerMasm_UI.IsChecked.HasValue && this.usedAssemblerMasm_UI.IsChecked.Value) return AssemblerEnum.MASM;
if (this.usedAssemblerNasm_UI.IsChecked.HasValue && this.usedAssemblerNasm_UI.IsChecked.Value) return AssemblerEnum.NASM;
return AssemblerEnum.MASM;
}
set
{
if (value.HasFlag(AssemblerEnum.MASM))
{
this.usedAssemblerMasm_UI.IsChecked = true;
this.usedAssemblerNasm_UI.IsChecked = false;
}
else if (value.HasFlag(AssemblerEnum.NASM))
{
this.usedAssemblerMasm_UI.IsChecked = false;
this.usedAssemblerNasm_UI.IsChecked = true;
}
}
}

public System.Drawing.Color ColorMnemonic
{
get { return (this.ColorMnemonic_UI.SelectedColor.HasValue) ? AsmDudeToolsStatic.ConvertColor(this.ColorMnemonic_UI.SelectedColor.Value) : System.Drawing.Color.Blue; }
Expand Down
35 changes: 19 additions & 16 deletions VS/CSHARP/asm-dude-vsix/OptionsPage/AsmDudeOptionsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ protected override void OnActivate(CancelEventArgs e)
{
base.OnActivate(e);

this._asmDudeOptionsPageUI.UsedAssembler = AsmDudeToolsStatic.Used_Assembler;

#region AsmDoc
this._asmDudeOptionsPageUI.AsmDoc_On = Settings.Default.AsmDoc_On;
this._asmDudeOptionsPageUI.AsmDoc_Url = Settings.Default.AsmDoc_url;
Expand All @@ -78,8 +80,6 @@ protected override void OnActivate(CancelEventArgs e)

#region Syntax Highlighting
this._asmDudeOptionsPageUI.SyntaxHighlighting_On = Settings.Default.SyntaxHighlighting_On;
this._asmDudeOptionsPageUI.UsedAssembler = AsmDudeToolsStatic.Used_Assembler;

this._asmDudeOptionsPageUI.ColorMnemonic = Settings.Default.SyntaxHighlighting_Opcode;
this._asmDudeOptionsPageUI.ColorMnemonic_Italic = Settings.Default.SyntaxHighlighting_Opcode_Italic;
this._asmDudeOptionsPageUI.ColorRegister = Settings.Default.SyntaxHighlighting_Register;
Expand Down Expand Up @@ -330,6 +330,12 @@ protected override void OnDeactivate(CancelEventArgs e)
{
bool changed = false;

if (AsmDudeToolsStatic.Used_Assembler != this._asmDudeOptionsPageUI.UsedAssembler)
{
if (logInfo) AsmDudeToolsStatic.Output("INFO: AsmDudeOptionsPage: OnDeactivate: change detected: usedAssembler=" + this._asmDudeOptionsPageUI.UsedAssembler);
changed = true;
}

#region AsmDoc
if (Settings.Default.AsmDoc_On != this._asmDudeOptionsPageUI.AsmDoc_On)
{
Expand Down Expand Up @@ -372,11 +378,6 @@ protected override void OnDeactivate(CancelEventArgs e)
if (logInfo) AsmDudeToolsStatic.Output("INFO: AsmDudeOptionsPage: OnDeactivate: change detected: useSyntaxHighlighting=" + this._asmDudeOptionsPageUI.SyntaxHighlighting_On);
changed = true;
}
if (AsmDudeToolsStatic.Used_Assembler != this._asmDudeOptionsPageUI.UsedAssembler)
{
if (logInfo) AsmDudeToolsStatic.Output("INFO: AsmDudeOptionsPage: OnDeactivate: change detected: usedAssembler=" + this._asmDudeOptionsPageUI.UsedAssembler);
changed = true;
}
if (Settings.Default.SyntaxHighlighting_Opcode.ToArgb() != this._asmDudeOptionsPageUI.ColorMnemonic.ToArgb())
{
if (logInfo) AsmDudeToolsStatic.Output("INFO: AsmDudeOptionsPage: OnDeactivate: change detected: stored=" + Settings.Default.SyntaxHighlighting_Opcode + "; new colorMnemonic=" + this._asmDudeOptionsPageUI.ColorMnemonic);
Expand Down Expand Up @@ -904,8 +905,8 @@ protected override void OnDeactivate(CancelEventArgs e)
if (!this._asmDudeOptionsPageUI.AsmSim_On)
{
string title = null;
string message = "I'm sorry "+ Environment.UserName + ", I'm afraid I can't do that";
int result = VsShellUtilities.ShowMessageBox(this.Site, message, title, OLEMSGICON.OLEMSGICON_QUERY, OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
string message = "I'm sorry "+ Environment.UserName + ", I'm afraid I can't do that.";
int result = VsShellUtilities.ShowMessageBox(this.Site, message, title, OLEMSGICON.OLEMSGICON_QUERY, OLEMSGBUTTON.OLEMSGBUTTON_ABORTRETRYIGNORE, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
}
}
if (Settings.Default.AsmSim_Number_Of_Steps != this._asmDudeOptionsPageUI.AsmSim_Number_Of_Steps)
Expand Down Expand Up @@ -1004,6 +1005,14 @@ private void Save()
//Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO:{0}:save", this.ToString()));
bool changed = false;
bool restartNeeded = false;

if (AsmDudeToolsStatic.Used_Assembler != this._asmDudeOptionsPageUI.UsedAssembler)
{
AsmDudeToolsStatic.Used_Assembler = this._asmDudeOptionsPageUI.UsedAssembler;
changed = true;
restartNeeded = true;
}

#region AsmDoc
if (Settings.Default.AsmDoc_On != this._asmDudeOptionsPageUI.AsmDoc_On)
{
Expand Down Expand Up @@ -1052,12 +1061,6 @@ private void Save()
changed = true;
restartNeeded = true;
}
if (AsmDudeToolsStatic.Used_Assembler != this._asmDudeOptionsPageUI.UsedAssembler)
{
AsmDudeToolsStatic.Used_Assembler = this._asmDudeOptionsPageUI.UsedAssembler;
changed = true;
restartNeeded = true;
}
if (Settings.Default.SyntaxHighlighting_Opcode.ToArgb() != this._asmDudeOptionsPageUI.ColorMnemonic.ToArgb())
{
Settings.Default.SyntaxHighlighting_Opcode = this._asmDudeOptionsPageUI.ColorMnemonic;
Expand Down Expand Up @@ -1685,7 +1688,7 @@ private void Save()
if (restartNeeded)
{
string title = null;
string message = "You may need to restart visual studio for the changes to take effect.";
string message = "You may need to close and open assembly files, or \nrestart visual studio for the changes to take effect.";
int result = VsShellUtilities.ShowMessageBox(this.Site, message, title, OLEMSGICON.OLEMSGICON_QUERY, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
}
}
Expand Down
17 changes: 10 additions & 7 deletions VS/CSHARP/asm-dude-vsix/QuickInfo/AsmQuickInfoSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,12 @@ private void Handle(IQuickInfoSession session, IList<object> quickInfoContent, o
}
case AsmTokenType.Register:
{
if (keywordUpper.StartsWith("%")) keywordUpper = keywordUpper.Substring(1); // remove the preceding % in AT&T syntax
Rn reg = RegisterTools.ParseRn(keywordUpper, true);

description = new TextBlock();
description.Inlines.Add(Make_Run1("Register ", this._foreground));
description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Register))));
description.Inlines.Add(Make_Run2(reg.ToString(), new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Register))));

string descr = this._asmDudeTools.Get_Description(keywordUpper);
if (descr.Length > 0)
Expand All @@ -192,7 +195,6 @@ private void Handle(IQuickInfoSession session, IList<object> quickInfoContent, o

if (this._asmSimulator.Enabled & Settings.Default.AsmSim_Decorate_Registers)
{
Rn reg = RegisterTools.ParseRn(keywordUpper, true);
string reg_Content_Before = this._asmSimulator.Get_Register_Value(reg, lineNumber, true, false, false).Value;
string reg_Content_After = this._asmSimulator.Get_Register_Value(reg, lineNumber, false, false, false).Value;
string msg = "\n" + reg + " before: " + reg_Content_Before + "\n" + reg + " after: " + reg_Content_After;
Expand All @@ -206,22 +208,23 @@ private void Handle(IQuickInfoSession session, IList<object> quickInfoContent, o
case AsmTokenType.Mnemonic:
case AsmTokenType.Jump:
{
Mnemonic mnemonic = AsmSourceTools.ParseMnemonic_Att(keywordUpper, true);

description = new TextBlock();
description.Inlines.Add(Make_Run1("Mnemonic ", this._foreground));
description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor((type == AsmTokenType.Mnemonic) ? Settings.Default.SyntaxHighlighting_Opcode : Settings.Default.SyntaxHighlighting_Jump))));
description.Inlines.Add(Make_Run2(mnemonic.ToString(), new SolidColorBrush(AsmDudeToolsStatic.ConvertColor((type == AsmTokenType.Mnemonic) ? Settings.Default.SyntaxHighlighting_Opcode : Settings.Default.SyntaxHighlighting_Jump))));

Mnemonic mmemonic = AsmSourceTools.ParseMnemonic(keywordUpper, true);
{
string archStr = ":" + ArchTools.ToString(this._asmDudeTools.Mnemonic_Store.GetArch(mmemonic)) + " ";
string descr = this._asmDudeTools.Mnemonic_Store.GetDescription(mmemonic);
string archStr = ":" + ArchTools.ToString(this._asmDudeTools.Mnemonic_Store.GetArch(mnemonic)) + " ";
string descr = this._asmDudeTools.Mnemonic_Store.GetDescription(mnemonic);
if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) descr = "\n" + descr;
description.Inlines.Add(new Run(AsmSourceTools.Linewrap(archStr + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
{
Foreground = this._foreground
});
}
// add performance information
this.Add_Performance_Description(description, mmemonic);
this.Add_Performance_Description(description, mnemonic);
break;
}
case AsmTokenType.Label:
Expand Down
19 changes: 19 additions & 0 deletions VS/CSHARP/asm-dude-vsix/Resources/examples/example_att.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.text
LC0:
.ascii "Hello, world!\12\0"
.globl _main
_main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
call __alloca
call ___main
movl $LC0, (%esp)
call _printf
movl $0, %eax
leave
ret
Loading

0 comments on commit c46281a

Please sign in to comment.