public void SetAsmSim(AsmSimulator asmSimulator, Rn reg, int lineNumber, bool isExpanded) { this._asmSimulator = asmSimulator; this._lineNumber = lineNumber; bool empty = true; if (this._asmSimulator.Enabled & Settings.Default.AsmSim_Show_Register_In_Register_Tooltip) { this.AsmSimGridExpander.IsExpanded = isExpanded; this.AsmSimGridExpanderNumeration.Text = Settings.Default.AsmSim_Show_Register_In_Register_Tooltip_Numeration; this.Generate(true, reg); this.Generate(false, reg); empty = false; } this.AsmSimGridExpander.Visibility = empty ? Visibility.Collapsed : Visibility.Visible; this.AsmSimGridBorder.Visibility = empty ? Visibility.Collapsed : Visibility.Visible; this.AsmSimGridExpanderNumeration.SelectionChanged += (sender, i) => { string numerationStr = ((sender as ComboBox).SelectedItem as ComboBoxItem).Content.ToString(); NumerationEnum numeration = AsmSourceTools.ParseNumeration(numerationStr); if (numeration == NumerationEnum.UNKNOWN) { AsmDudeToolsStatic.Output_WARNING("SetAsmSim:smSimGridExpanderNumeration.SelectionChanged: unknown numerationStr=" + numerationStr); } //AsmDudeToolsStatic.Output_INFO("AsmSimGridExpanderNumeration:SelectionChanged: numeration="+ numeration); var content_before = this._asmSimulator.Get_Register_Value_If_Already_Computed(reg, this._lineNumber, true, numeration); if (content_before != null) { this._textBox_before.Text = content_before; } var content_after = this._asmSimulator.Get_Register_Value_If_Already_Computed(reg, this._lineNumber, false, numeration); if (content_after != null) { this._textBox_after.Text = content_after; } }; }
private async void Update_Async(Button button) { await System.Threading.Tasks.Task.Run(() => { try { if (button == null) { return; } if (this._asmSimulator == null) { return; } this.Dispatcher.Invoke((Action)(() => { ButtonInfo info = (ButtonInfo)button.Tag; if (info.reg == Rn.NOREG) { info.text.Text = info.flag.ToString() + " = " + this._asmSimulator.Get_Flag_Value_and_Block(info.flag, this._lineNumber, info.before); } else { info.text.Text = info.reg.ToString() + " = " + this._asmSimulator.Get_Register_Value_and_Block(info.reg, this._lineNumber, info.before, AsmSourceTools.ParseNumeration(Settings.Default.AsmSim_Show_Register_In_Instruction_Tooltip_Numeration)); } info.text.Visibility = Visibility.Visible; button.Visibility = Visibility.Collapsed; })); } catch (Exception e) { AsmDudeToolsStatic.Output_ERROR("InstructionTooltipWindow: Update_Async: e=" + e.ToString()); } }); }
private void Generate(Rn reg, bool isBefore, int row) { FontFamily f = new FontFamily("Consolas"); int column = (isBefore) ? 0 : 1; { var textBox = new TextBox() { FontFamily = f, Foreground = this._foreground, Background = Brushes.Transparent, BorderThickness = new Thickness(0), IsReadOnly = true, TextWrapping = TextWrapping.Wrap, Tag = new ButtonInfo(null, reg, isBefore) }; this._itemsOnPage.Add(textBox); this.AsmSimGrid.Children.Add(textBox); Grid.SetRow(textBox, row); Grid.SetColumn(textBox, column); string register_Content = this._asmSimulator.Get_Register_Value_If_Already_Computed(reg, this._lineNumber, isBefore, AsmSourceTools.ParseNumeration(Settings.Default.AsmSim_Show_Register_In_Instruction_Tooltip_Numeration)); if (register_Content == null) { textBox.Visibility = Visibility.Collapsed; var button = new Button() { Content = "Determine " + reg.ToString(), Foreground = this._foreground, Visibility = Visibility.Visible, Tag = new ButtonInfo(textBox, reg, isBefore) }; this.AsmSimGrid.Children.Add(button); Grid.SetRow(button, row); Grid.SetColumn(button, column); button.Click += (sender, e) => { this.Update_Async(sender as Button); }; } else { textBox.Text = reg.ToString() + " = " + register_Content; textBox.Visibility = Visibility.Visible; } } }
public void SetAsmSim(AsmSimulator asmSimulator, int lineNumber, bool isExpanded) { this._asmSimulator = asmSimulator; this._lineNumber = lineNumber; bool empty = true; if (this._asmSimulator.Enabled & Settings.Default.AsmSim_Show_Register_In_Instruction_Tooltip) { this._itemsOnPage = new List <TextBox>(); this.AsmSimGridExpander.IsExpanded = isExpanded; this.AsmSimGridExpanderNumeration.Text = Settings.Default.AsmSim_Show_Register_In_Instruction_Tooltip_Numeration; var(ReadReg, WriteReg, ReadFlag, WriteFlag, MemRead, MemWrite) = this._asmSimulator.Get_Usage(lineNumber); var readReg = new HashSet <Rn>(ReadReg); var writeReg = new HashSet <Rn>(WriteReg); this.GenerateHeader(); int row = 2; foreach (Rn reg in Enum.GetValues(typeof(Rn))) { bool b1 = readReg.Contains(reg); bool b2 = writeReg.Contains(reg); if (b1 || b2) { empty = false; if (b1) { this.Generate(reg, true, row); } if (b2) { this.Generate(reg, false, row); } row++; } } foreach (Flags flag in FlagTools.GetFlags(ReadFlag | WriteFlag)) { if (flag == Flags.NONE) { continue; } bool b1 = ReadFlag.HasFlag(flag); bool b2 = WriteFlag.HasFlag(flag); if (b1 || b2) { empty = false; if (b1) { this.Generate(flag, true, row); } if (b2) { this.Generate(flag, false, row); } row++; } } } this.AsmSimGridExpander.Visibility = (empty) ? Visibility.Collapsed : Visibility.Visible; this.AsmSimGridBorder.Visibility = (empty) ? Visibility.Collapsed : Visibility.Visible; this.AsmSimGridExpanderNumeration.SelectionChanged += (sender, i) => { string numerationStr = ((sender as ComboBox).SelectedItem as ComboBoxItem).Content.ToString(); NumerationEnum numeration = AsmSourceTools.ParseNumeration(numerationStr); if (numeration == NumerationEnum.UNKNOWN) { AsmDudeToolsStatic.Output_WARNING("SetAsmSim:smSimGridExpanderNumeration.SelectionChanged: unknown numerationStr=" + numerationStr); } //AsmDudeToolsStatic.Output_INFO("AsmSimGridExpanderNumeration:SelectionChanged: numeration="+ numeration); foreach (var textBox in this._itemsOnPage) { var info = textBox.Tag as ButtonInfo; string content = (info.reg == Rn.NOREG) ? this._asmSimulator.Get_Flag_Value_If_Already_Computed(info.flag, this._lineNumber, info.before) : this._asmSimulator.Get_Register_Value_If_Already_Computed(info.reg, this._lineNumber, info.before, numeration); if (content != null) { textBox.Text = info.reg.ToString() + " = " + content; } } }; }
private IEnumerable <Completion> Mnemonic_Operand_Completions(bool useCapitals, ISet <AsmSignatureEnum> allowedOperands, int lineNumber) { bool use_AsmSim_In_Code_Completion = this.asmSimulator_.Enabled && Settings.Default.AsmSim_Show_Register_In_Code_Completion; bool att_Syntax = AsmDudeToolsStatic.Used_Assembler == AssemblerEnum.NASM_ATT; SortedSet <Completion> completions = new SortedSet <Completion>(new CompletionComparer()); foreach (Rn regName in this.asmDudeTools_.Get_Allowed_Registers()) { string additionalInfo = null; if (AsmSignatureTools.Is_Allowed_Reg(regName, allowedOperands)) { string keyword = regName.ToString(); if (use_AsmSim_In_Code_Completion && this.asmSimulator_.Tools.StateConfig.IsRegOn(RegisterTools.Get64BitsRegister(regName))) { (string value, bool bussy) = this.asmSimulator_.Get_Register_Value(regName, lineNumber, true, false, false, AsmSourceTools.ParseNumeration(Settings.Default.AsmSim_Show_Register_In_Code_Completion_Numeration, false)); if (!bussy) { additionalInfo = value; AsmDudeToolsStatic.Output_INFO("AsmCompletionSource:Mnemonic_Operand_Completions; register " + keyword + " is selected and has value " + additionalInfo); } } if (att_Syntax) { keyword = "%" + keyword; } Arch arch = RegisterTools.GetArch(regName); //AsmDudeToolsStatic.Output_INFO("AsmCompletionSource:AugmentCompletionSession: keyword \"" + keyword + "\" is added to the completions list"); // by default, the entry.Key is with capitals string insertionText = useCapitals ? keyword : keyword.ToLowerInvariant(); string archStr = (arch == Arch.ARCH_NONE) ? string.Empty : " [" + ArchTools.ToString(arch) + "]"; string descriptionStr = this.asmDudeTools_.Get_Description(keyword); descriptionStr = (string.IsNullOrEmpty(descriptionStr)) ? string.Empty : " - " + descriptionStr; string displayText = Truncat(keyword + archStr + descriptionStr); this.icons_.TryGetValue(AsmTokenType.Register, out ImageSource imageSource); completions.Add(new Completion(displayText, insertionText, additionalInfo, imageSource, string.Empty)); } } foreach (string keyword in this.asmDudeTools_.Get_Keywords()) { AsmTokenType type = this.asmDudeTools_.Get_Token_Type_Intel(keyword); Arch arch = this.asmDudeTools_.Get_Architecture(keyword); string keyword2 = keyword; bool selected = true; //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:Mnemonic_Operand_Completions; keyword=" + keyword +"; selected="+selected +"; arch="+arch); string additionalInfo = null; switch (type) { case AsmTokenType.Misc: { if (!AsmSignatureTools.Is_Allowed_Misc(keyword, allowedOperands)) { selected = false; } break; } default: { selected = false; break; } } if (selected) { //AsmDudeToolsStatic.Output_INFO("AsmCompletionSource:AugmentCompletionSession: keyword \"" + keyword + "\" is added to the completions list"); // by default, the entry.Key is with capitals string insertionText = useCapitals ? keyword2 : keyword2.ToLowerInvariant(); string archStr = (arch == Arch.ARCH_NONE) ? string.Empty : " [" + ArchTools.ToString(arch) + "]"; string descriptionStr = this.asmDudeTools_.Get_Description(keyword); descriptionStr = (string.IsNullOrEmpty(descriptionStr)) ? string.Empty : " - " + descriptionStr; string displayText = Truncat(keyword2 + archStr + descriptionStr); this.icons_.TryGetValue(type, out ImageSource imageSource); completions.Add(new Completion(displayText, insertionText, additionalInfo, imageSource, string.Empty)); } } return(completions); }
private async System.Threading.Tasks.Task Update_Async(Button button) { if (button == null) { return; } if (this._asmSimulator == null) { return; } try { if (!ThreadHelper.CheckAccess()) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); } ButtonInfo info = (ButtonInfo)button.Tag; info.text.Text = (info.reg == Rn.NOREG) ? this._asmSimulator.Get_Flag_Value_and_Block(info.flag, this._lineNumber, info.before) : this._asmSimulator.Get_Register_Value_and_Block(info.reg, this._lineNumber, info.before, AsmSourceTools.ParseNumeration(this.AsmSimGridExpanderNumeration.Text)); info.text.Visibility = Visibility.Visible; button.Visibility = Visibility.Collapsed; } catch (Exception e) { AsmDudeToolsStatic.Output_ERROR(string.Format("{0}:Update_Async; e={1}", this.ToString(), e.ToString())); } }
private void Generate(bool isBefore, Rn reg) { FontFamily f = new FontFamily("Consolas"); int row = isBefore ? 1 : 2; { var textBlock = new TextBlock() { Text = isBefore ? "Before:" : "After:", FontFamily = f, Foreground = this._foreground }; this.AsmSimGrid.Children.Add(textBlock); Grid.SetRow(textBlock, row); Grid.SetColumn(textBlock, 0); } { var textBox = new TextBox() { FontFamily = f, Foreground = this._foreground, Background = Brushes.Transparent, BorderThickness = new Thickness(0), IsReadOnly = true, TextWrapping = TextWrapping.Wrap }; if (isBefore) { this._textBox_before = textBox; } else { this._textBox_after = textBox; } this.AsmSimGrid.Children.Add(textBox); Grid.SetRow(textBox, row); Grid.SetColumn(textBox, 1); var register_Content = this._asmSimulator.Get_Register_Value_If_Already_Computed(reg, this._lineNumber, isBefore, AsmSourceTools.ParseNumeration(this.AsmSimGridExpanderNumeration.Text)); if (register_Content == null) { textBox.Visibility = Visibility.Collapsed; var button = new Button() { Content = "Determine " + reg.ToString(), Foreground = this._foreground, Visibility = Visibility.Visible, Tag = new ButtonInfo(textBox, reg, isBefore) }; this.AsmSimGrid.Children.Add(button); Grid.SetRow(button, row); Grid.SetColumn(button, 1); button.Click += (sender, e) => this.Update_Async(sender as Button).ConfigureAwait(false); } else { textBox.Text = register_Content; textBox.Visibility = Visibility.Visible; } } }
private async System.Threading.Tasks.Task Update_Async(Button button) { AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:Update_Async", this.ToString())); if (button == null) { return; } if (this.asmSimulator_ == null) { return; } try { if (!ThreadHelper.CheckAccess()) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); } ButtonInfo info = (ButtonInfo)button.Tag; info.Text.Text = (info.Reg == Rn.NOREG) ? info.Flag.ToString() + " = " + this.asmSimulator_.Get_Flag_Value_and_Block(info.Flag, this.lineNumber_, info.Before) : info.Reg.ToString() + " = " + this.asmSimulator_.Get_Register_Value_and_Block(info.Reg, this.lineNumber_, info.Before, AsmSourceTools.ParseNumeration(Settings.Default.AsmSim_Show_Register_In_Instruction_Tooltip_Numeration, false)); info.Text.Visibility = Visibility.Visible; button.Visibility = Visibility.Collapsed; } catch (Exception e) { AsmDudeToolsStatic.Output_ERROR(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:Update_Async; e={1}", this.ToString(), e.ToString())); } }
private void Generate(Rn reg, bool isBefore, int row) { FontFamily f = new FontFamily("Consolas"); int column = isBefore ? 0 : 1; { TextBox textBox = new TextBox() { FontFamily = f, Foreground = this.foreground_, Background = Brushes.Transparent, BorderThickness = new Thickness(0), IsReadOnly = true, TextWrapping = TextWrapping.Wrap, Tag = new ButtonInfo(null, reg, isBefore), }; this.itemsOnPage_.Add(textBox); this.AsmSimGrid.Children.Add(textBox); Grid.SetRow(textBox, row); Grid.SetColumn(textBox, column); string register_Content = this.asmSimulator_.Get_Register_Value_If_Already_Computed(reg, this.lineNumber_, isBefore, AsmSourceTools.ParseNumeration(Settings.Default.AsmSim_Show_Register_In_Instruction_Tooltip_Numeration, false)); if (register_Content == null) { textBox.Visibility = Visibility.Collapsed; Button button = new Button() { Content = "Determine " + reg.ToString(), Foreground = this.foreground_, Visibility = Visibility.Visible, Tag = new ButtonInfo(textBox, reg, isBefore), }; this.AsmSimGrid.Children.Add(button); Grid.SetRow(button, row); Grid.SetColumn(button, column); //TODO: is the following Event handler ever unsubscribed? button.Click += (sender, e) => this.Update_Async(sender as Button).ConfigureAwait(false); } else { textBox.Text = reg.ToString() + " = " + register_Content; textBox.Visibility = Visibility.Visible; } } }