internal NasmAttDisassemblyTokenTagger(ITextBuffer buffer) { AsmDudeToolsStatic.Output_INFO("NasmAttDisassemblyTokenTagger:constructor"); this.buffer_ = buffer ?? throw new ArgumentNullException(nameof(buffer)); this.asmDudeTools_ = AsmDudeTools.Instance; this.mnemonic_ = new AsmTokenTag(AsmTokenType.Mnemonic); this.register_ = new AsmTokenTag(AsmTokenType.Register); this.remark_ = new AsmTokenTag(AsmTokenType.Remark); this.directive_ = new AsmTokenTag(AsmTokenType.Directive); this.constant_ = new AsmTokenTag(AsmTokenType.Constant); this.jump_ = new AsmTokenTag(AsmTokenType.Jump); this.label_ = new AsmTokenTag(AsmTokenType.Label); this.labelDef_ = new AsmTokenTag(AsmTokenType.LabelDef); this.misc_ = new AsmTokenTag(AsmTokenType.Misc); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { ThreadHelper.ThrowIfNotOnUIThread(); //AsmDudeToolsStatic.Output_INFO(string.Format("{0}:QueryStatus", this.ToString())); if (pguidCmdGroup == VSConstants.VSStd2K) { switch ((VSConstants.VSStd2KCmdID)prgCmds[0].cmdID) { case VSConstants.VSStd2KCmdID.AUTOCOMPLETE: case VSConstants.VSStd2KCmdID.COMPLETEWORD: AsmDudeToolsStatic.Output_INFO(string.Format("{0}:QueryStatus", this.ToString())); //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO: {0}:QueryStatus", this.ToString())); prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED; return(VSConstants.S_OK); } } return(this.NextCommandHandler.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText)); }
//private readonly AsmTokenTag _userDefined1; //private readonly AsmTokenTag _userDefined2; //private readonly AsmTokenTag _userDefined3; //private readonly AsmTokenTag _UNKNOWN; internal MasmDisassemblyTokenTagger(ITextBuffer buffer) { AsmDudeToolsStatic.Output_INFO("MasmDisassemblyTokenTagger:constructor"); this._buffer = buffer ?? throw new ArgumentNullException(nameof(buffer)); this._asmDudeTools = AsmDudeTools.Instance; this._mnemonic = new AsmTokenTag(AsmTokenType.Mnemonic); this._register = new AsmTokenTag(AsmTokenType.Register); this._remark = new AsmTokenTag(AsmTokenType.Remark); this._directive = new AsmTokenTag(AsmTokenType.Directive); this._constant = new AsmTokenTag(AsmTokenType.Constant); this._jump = new AsmTokenTag(AsmTokenType.Jump); this._label = new AsmTokenTag(AsmTokenType.Label); this._labelDef = new AsmTokenTag(AsmTokenType.LabelDef); this._misc = new AsmTokenTag(AsmTokenType.Misc); //this._userDefined1 = new AsmTokenTag(AsmTokenType.UserDefined1); //this._userDefined2 = new AsmTokenTag(AsmTokenType.UserDefined2); //this._userDefined3 = new AsmTokenTag(AsmTokenType.UserDefined3); //this._UNKNOWN = new AsmTokenTag(AsmTokenType.UNKNOWN); }
/// <summary> /// Singleton pattern: use AsmDudeTools.Instance for the instance of this class /// </summary> private AsmDudeTools() { //AsmDudeToolsStatic.Output_INFO("AsmDudeTools constructor"); ThreadHelper.ThrowIfNotOnUIThread(); #region Initialize ErrorListProvider IServiceProvider serviceProvider = new ServiceProvider(Package.GetGlobalService(typeof(Microsoft.VisualStudio.OLE.Interop.IServiceProvider)) as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); this._errorListProvider = new ErrorListProvider(serviceProvider) { ProviderName = "Asm Errors", ProviderGuid = new Guid(EnvDTE.Constants.vsViewKindCode), }; #endregion this._threadPool = new SmartThreadPool(); #region load Signature Store and Performance Store string path = AsmDudeToolsStatic.Get_Install_Path() + "Resources" + Path.DirectorySeparatorChar; { string filename_Regular = path + "signature-may2019.txt"; string filename_Hand = path + "signature-hand-1.txt"; this._mnemonicStore = new MnemonicStore(filename_Regular, filename_Hand); } { this._performanceStore = new PerformanceStore(path + "Performance" + Path.DirectorySeparatorChar); } #endregion this.Init_Data(); this._mnemonics_switched_on = new HashSet <Mnemonic>(); this.UpdateMnemonicSwitchedOn(); this._register_switched_on = new HashSet <Rn>(); this.UpdateRegisterSwitchedOn(); #region Experiments if (false) { string filename2 = AsmDudeToolsStatic.Get_Install_Path() + "Resources" + Path.DirectorySeparatorChar + "mnemonics-nasm.txt"; MnemonicStore store2 = new MnemonicStore(filename2, null); ISet <string> archs = new SortedSet <string>(); IDictionary <string, string> signaturesIntel = new Dictionary <string, string>(); IDictionary <string, string> signaturesNasm = new Dictionary <string, string>(); foreach (Mnemonic mnemonic in Enum.GetValues(typeof(Mnemonic))) { IEnumerable <AsmSignatureElement> intel = this._mnemonicStore.GetSignatures(mnemonic); IEnumerable <AsmSignatureElement> nasm = store2.GetSignatures(mnemonic); signaturesIntel.Clear(); signaturesNasm.Clear(); int intelCount = 0; foreach (AsmSignatureElement e in intel) { intelCount++; string instruction = e.Mnemonic.ToString() + " " + e.Operands_Str; if (signaturesIntel.ContainsKey(instruction)) { AsmDudeToolsStatic.Output_WARNING("Intel " + instruction + ": is already present with arch " + signaturesIntel[instruction] + "; new arch " + e.Arch_Str); } else { signaturesIntel.Add(instruction, e.Arch_Str); } } int nasmCount = 0; foreach (AsmSignatureElement e in nasm) { nasmCount++; string instruction = e.Mnemonic.ToString() + " " + e.Operands_Str; if (signaturesNasm.ContainsKey(instruction)) { // AsmDudeToolsStatic.Output_WARNING("Nasm " + instruction + ": is already present with arch " + signaturesNasm[instruction] + "; new arch " + e.archStr); } else { signaturesNasm.Add(instruction, e.Arch_Str); } } foreach (AsmSignatureElement e in intel) { string instruction = e.Mnemonic.ToString() + " " + e.Operands_Str; //AsmDudeToolsStatic.Output_INFO("Intel " + instruction + ": arch" + e.archStr); if ((e.Arch_Str == null) || (e.Arch_Str.Length == 0)) { if (signaturesNasm.ContainsKey(instruction)) { AsmDudeToolsStatic.Output_INFO("Intel " + instruction + " has no arch, but NASM has \"" + signaturesNasm[instruction] + "\"."); } else { if (signaturesNasm.Count == 1) { AsmDudeToolsStatic.Output_INFO("Intel " + instruction + " has no arch, but NASM has \"" + signaturesNasm.GetEnumerator().Current + "\"."); } else { AsmDudeToolsStatic.Output_INFO("Intel " + instruction + " has no arch:"); foreach (KeyValuePair <string, string> pair in signaturesNasm) { AsmDudeToolsStatic.Output_INFO("\tNASM has " + pair.Key + ": \"" + pair.Value + "\"."); } AsmDudeToolsStatic.Output_INFO(" ----"); } } } } if (false) { if (intelCount != nasmCount) { foreach (AsmSignatureElement e in intel) { AsmDudeToolsStatic.Output_INFO("INTEL " + mnemonic + ": " + e); } foreach (AsmSignatureElement e in nasm) { AsmDudeToolsStatic.Output_INFO("NASM " + mnemonic + ": " + e); } } } } foreach (string str in archs) { AsmDudeToolsStatic.Output_INFO("INTEL arch " + str); } } if (false) { foreach (Arch arch in Enum.GetValues(typeof(Arch))) { int counter = 0; ISet <Mnemonic> usedMnemonics = new HashSet <Mnemonic>(); foreach (Mnemonic mnemonic in Enum.GetValues(typeof(Mnemonic))) { if (this.Mnemonic_Store.GetArch(mnemonic).Contains(arch)) { //AsmDudeToolsStatic.Output_INFO("AsmDudeTools constructor: arch="+arch+"; mnemonic=" + mnemonic); counter++; usedMnemonics.Add(mnemonic); } } string str = string.Empty; foreach (Mnemonic mnemonic in usedMnemonics) { str += mnemonic.ToString() + ","; } AsmDudeToolsStatic.Output_INFO("AsmDudeTools constructor: Architecture Option " + arch + " enables mnemonics " + str); } } if (false) { foreach (Mnemonic mnemonic in Enum.GetValues(typeof(Mnemonic))) { string keyword = mnemonic.ToString().ToUpper(); if (this._description.ContainsKey(keyword)) { string description = this._description[keyword]; string reference = this.Get_Url(mnemonic); this.Mnemonic_Store.SetHtmlRef(mnemonic, reference); } } AsmDudeToolsStatic.Output_INFO(this.Mnemonic_Store.ToString()); } if (false) { ISet <string> archs = new HashSet <string>(); foreach (Mnemonic mnemonic in Enum.GetValues(typeof(Mnemonic))) { if (!this._mnemonicStore.HasElement(mnemonic)) { AsmDudeToolsStatic.Output_INFO("AsmDudeTools constructor: mnemonic " + mnemonic + " is not present"); } foreach (AsmSignatureElement e in this._mnemonicStore.GetSignatures(mnemonic)) { foreach (string s in e.Arch_Str.Split(',')) { archs.Add(s.Trim()); } } } foreach (string s in archs) { AsmDudeToolsStatic.Output_INFO(s + ","); } } #endregion }
public AsmDudePackage() { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "=========================================\nINFO: AsmDudePackage: Entering constructor")); AsmDudeToolsStatic.Output_INFO("AsmDudePackage: Entering constructor"); }
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 SortedSet <Completion> Selected_Completions(bool useCapitals, ISet <AsmTokenType> selectedTypes) { SortedSet <Completion> completions = new SortedSet <Completion>(new CompletionComparer()); //Add the completions of AsmDude directives (such as code folding directives) #region if (Settings.Default.CodeFolding_On) { { string insertionText = Settings.Default.CodeFolding_BeginTag; //the characters that start the outlining region string description = insertionText + " - keyword to start code folding"; completions.Add(new Completion(description, insertionText, null, this._icons[AsmTokenType.Directive], "")); } { string insertionText = Settings.Default.CodeFolding_EndTag; //the characters that end the outlining region string description = insertionText + " - keyword to end code folding"; completions.Add(new Completion(description, insertionText, null, this._icons[AsmTokenType.Directive], "")); } } #endregion AssemblerEnum usedAssember = AsmDudeToolsStatic.Used_Assembler; #region if (selectedTypes.Contains(AsmTokenType.Mnemonic)) { ISet <Arch> selectedArchs = AsmDudeToolsStatic.Get_Arch_Swithed_On(); IList <Mnemonic> allowedMnemonics = Get_Allowed_Mnemonics(selectedArchs); //AsmDudeToolsStatic.Output("INFO: CodeCompletionSource:selectedCompletions; allowedMnemonics.Count=" + allowedMnemonics.Count + "; selectedArchs="+ArchTools.ToString(selectedArchs)); foreach (Mnemonic mnemonic in allowedMnemonics) { string keyword = mnemonic.ToString(); string insertionText = (useCapitals) ? keyword : keyword.ToLower(); string archStr = ArchTools.ToString(this._asmDudeTools.Mnemonic_Store.GetArch(mnemonic)); string descriptionStr = this._asmDudeTools.Mnemonic_Store.GetDescription(mnemonic); descriptionStr = (descriptionStr.Length == 0) ? "" : " - " + descriptionStr; String displayText = keyword + archStr + descriptionStr; //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr; this._icons.TryGetValue(AsmTokenType.Mnemonic, out var imageSource); completions.Add(new Completion(displayText, insertionText, null, imageSource, "")); } } //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); if (selectedTypes.Contains(type)) { Arch arch = Arch.NONE; bool selected = true; if (type == AsmTokenType.Directive) { AssemblerEnum assembler = this._asmDudeTools.Get_Assembler(keyword); if (assembler.HasFlag(AssemblerEnum.MASM)) { if (!usedAssember.HasFlag(AssemblerEnum.MASM)) { selected = false; } } else if (assembler.HasFlag(AssemblerEnum.NASM)) { if (!usedAssember.HasFlag(AssemblerEnum.NASM)) { selected = false; } } } else { arch = this._asmDudeTools.Get_Architecture(keyword); selected = AsmDudeToolsStatic.Is_Arch_Switched_On(arch); } AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:Selected_Completions; keyword=" + keyword + "; arch=" + arch + "; selected=" + selected); if (selected) { //Debug.WriteLine("INFO: CompletionSource:AugmentCompletionSession: name keyword \"" + entry.Key + "\""); // by default, the entry.Key is with capitals string insertionText = (useCapitals) ? keyword : keyword.ToLower(); string archStr = (arch == Arch.NONE) ? "" : " [" + ArchTools.ToString(arch) + "]"; string descriptionStr = this._asmDudeTools.Get_Description(keyword); descriptionStr = (descriptionStr.Length == 0) ? "" : " - " + descriptionStr; String displayText = keyword + archStr + descriptionStr; //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr; this._icons.TryGetValue(type, out var imageSource); completions.Add(new Completion(displayText, insertionText, null, imageSource, "")); } } } #endregion return(completions); }