public void SetDescription(Rn reg, AsmDudeTools asmDudeTools)
        {
            string regStr = reg.ToString();

            this.Description.Inlines.Add(new Run("Register ")
            {
                FontWeight = FontWeights.Bold, Foreground = this._foreground
            });
            this.Description.Inlines.Add(new Run(regStr)
            {
                FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Register))
            });

            Arch   arch    = RegisterTools.GetArch(reg);
            string archStr = (arch == Arch.ARCH_NONE) ? "" : " [" + ArchTools.ToString(arch) + "] ";
            string descr   = asmDudeTools.Get_Description(regStr);

            if (regStr.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2))
            {
                descr = "\n" + descr;
            }
            string full_Descr = AsmSourceTools.Linewrap(":" + archStr + descr, AsmDudePackage.maxNumberOfCharsInToolTips);

            this.Description.Inlines.Add(new Run(full_Descr)
            {
                Foreground = this._foreground
            });
        }
示例#2
0
 public void Test_AsmSourceTools_parseArch()
 {
     foreach (Arch x in Enum.GetValues(typeof(Arch)))
     {
         Assert.AreEqual(ArchTools.ParseArch(ArchTools.ToString(x), true, true), x,
                         "Parsing string " + x.ToString() + " does not yield the same enumeration.");
     }
 }
示例#3
0
 private Arch Retrieve_Arch(XmlNode node)
 {
     try
     {
         XmlAttribute archAttribute = node.Attributes["arch"];
         return((archAttribute == null) ? Arch.ARCH_NONE : ArchTools.ParseArch(archAttribute.Value.ToUpper()));
     }
     catch (Exception)
     {
         return(Arch.ARCH_NONE);
     }
 }
示例#4
0
        static IList <Arch> Parse_Archs(string str)
        {
            IList <Arch> Results = new List <Arch>();

            foreach (string s in str.Replace(",", " ").Split(' '))
            {
                Arch a = ArchTools.ParseArch(s.Trim(), false);
                if (a != Arch.NONE)
                {
                    Results.Add(a);
                }
            }
            return(Results);
        }
        private AsmSignature Create_Signature(ITextBuffer textBuffer, AsmSignatureElement signatureElement, ITrackingSpan span)
        {
            int nOperands = signatureElement.Operands.Count;

            Span[] locus = new Span[nOperands];

            StringBuilder sb = new StringBuilder();

            sb.Append(signatureElement.Mnemonic.ToString());
            sb.Append(" ");
            //AsmDudeToolsStatic.Output_INFO("AsmSignatureHelpSource: createSignature: sb=" + sb.ToString());

            for (int i = 0; i < nOperands; ++i)
            {
                int locusStart = sb.Length;
                sb.Append(signatureElement.Get_Operand_Doc(i));
                //AsmDudeToolsStatic.Output_INFO("AsmSignatureHelpSource: createSignature: i="+i+"; sb=" + sb.ToString());
                locus[i] = new Span(locusStart, sb.Length - locusStart);
                if (i < nOperands - 1)
                {
                    sb.Append(", ");
                }
            }

            sb.Append(ArchTools.ToString(signatureElement.Arch));
            AsmSignature sig = new AsmSignature(textBuffer, sb.ToString(), signatureElement.Documentation, null);

            textBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(sig.OnSubjectBufferChanged);

            IList <IParameter> paramList = new List <IParameter>();

            for (int i = 0; i < nOperands; ++i)
            {
                string documentation = AsmSignatureElement.Make_Doc(signatureElement.Operands[i]);
                string operandName   = signatureElement.Get_Operand_Str(i);
                paramList.Add(new AsmParameter(documentation, locus[i], operandName, sig));
            }

            sig.Parameters       = new ReadOnlyCollection <IParameter>(paramList);
            sig.ApplicableToSpan = span;
            sig.Compute_Current_Parameter();
            return(sig);
        }
示例#6
0
            public string ToString()
            {
                StringBuilder sb = new StringBuilder();

                sb.Append(this.mnemonic.ToString() + "\t");
                sb.Append(this.parameters + "\t");

                for (int i = 0; i < this.archs.Count; ++i)
                {
                    sb.Append(ArchTools.ToString(this.archs[i]));
                    if (i < (this.archs.Count - 1))
                    {
                        sb.Append(",");
                    }
                }
                sb.Append("\t");
                sb.Append(this.parameter_descriptions + "\t");

                sb.Append(this.description);
                return(sb.ToString());
            }
        public void SetDescription(Mnemonic mnemonic, AsmDudeTools asmDudeTools)
        {
            string mnemonicStr = mnemonic.ToString();

            this.Description.Inlines.Add(new Run("Mnemonic ")
            {
                FontWeight = FontWeights.Bold, Foreground = this._foreground
            });
            this.Description.Inlines.Add(new Run(mnemonicStr)
            {
                FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(AsmDudeToolsStatic.ConvertColor((AsmSourceTools.IsJump(mnemonic) ? Settings.Default.SyntaxHighlighting_Jump : Settings.Default.SyntaxHighlighting_Opcode)))
            });

            string archStr    = ":" + ArchTools.ToString(asmDudeTools.Mnemonic_Store.GetArch(mnemonic)) + " ";
            string descr      = asmDudeTools.Mnemonic_Store.GetDescription(mnemonic);
            string full_Descr = AsmSourceTools.Linewrap(archStr + descr, AsmDudePackage.maxNumberOfCharsInToolTips);

            this.Description.Inlines.Add(new Run(full_Descr)
            {
                Foreground = this._foreground
            });
        }
示例#8
0
        static string Get_Arch_Str(IDictionary <Arch, ISet <Mnemonic> > dictionary, Mnemonic m)
        {
            ISet <Arch> archs = new HashSet <Arch>();

            foreach (Arch a in dictionary.Keys)
            {
                foreach (Mnemonic m2 in dictionary[a])
                {
                    if (m == m2)
                    {
                        archs.Add(a);
                    }
                }
            }
            string archStr = "";

            foreach (Arch a in archs)
            {
                archStr += ArchTools.ToString(a) + " ";
            }
            return(archStr);
        }
示例#9
0
        static string Get_Arch_Str(IList <Signature> Signatures, Mnemonic m)
        {
            ISet <Arch> archs = new HashSet <Arch>();

            foreach (Signature s in Signatures)
            {
                if (s.mnemonic == m)
                {
                    foreach (Arch a in s.archs)
                    {
                        archs.Add(a);
                    }
                }
            }
            string archStr = "";

            foreach (Arch a in archs)
            {
                archStr += ArchTools.ToString(a) + " ";
            }
            return(archStr.TrimEnd());
        }
示例#10
0
        private IEnumerable <Completion> Selected_Completions(bool useCapitals, ISet <AsmTokenType> selectedTypes, bool addSpecialKeywords)
        {
            SortedSet <Completion> completions = new SortedSet <Completion>(new CompletionComparer());

            //Add the completions of AsmDude directives (such as code folding directives)
            #region
            if (addSpecialKeywords && Settings.Default.CodeFolding_On)
            {
                this.icons_.TryGetValue(AsmTokenType.Directive, out ImageSource imageSource);
                {
                    string insertionText   = Settings.Default.CodeFolding_BeginTag;   //the characters that start the outlining region
                    string displayTextFull = insertionText + " - keyword to start code folding";
                    string displayText     = Truncat(displayTextFull);
                    completions.Add(new Completion(displayText, insertionText, displayTextFull, imageSource, string.Empty));
                }
                {
                    string insertionText   = Settings.Default.CodeFolding_EndTag;     //the characters that end the outlining region
                    string displayTextFull = insertionText + " - keyword to end code folding";
                    string displayText     = Truncat(displayTextFull);
                    completions.Add(new Completion(displayText, insertionText, displayTextFull, imageSource, string.Empty));
                }
            }
            #endregion
            AssemblerEnum usedAssember = AsmDudeToolsStatic.Used_Assembler;

            #region Add completions

            if (selectedTypes.Contains(AsmTokenType.Mnemonic))
            {
                this.icons_.TryGetValue(AsmTokenType.Mnemonic, out ImageSource imageSource);
                foreach (Mnemonic mnemonic in this.asmDudeTools_.Get_Allowed_Mnemonics())
                {
                    string keyword_upcase = mnemonic.ToString();
                    string description    = this.asmDudeTools_.Mnemonic_Store.GetSignatures(mnemonic).First().Documentation;
                    string insertionText  = useCapitals ? keyword_upcase : keyword_upcase.ToLowerInvariant();
                    string archStr        = ArchTools.ToString(this.asmDudeTools_.Mnemonic_Store.GetArch(mnemonic));
                    string descriptionStr = this.asmDudeTools_.Mnemonic_Store.GetDescription(mnemonic);
                    descriptionStr = (string.IsNullOrEmpty(descriptionStr)) ? string.Empty : " - " + descriptionStr;
                    string displayText = Truncat(keyword_upcase + archStr + descriptionStr);
                    //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr;
                    completions.Add(new Completion(displayText, insertionText, description, imageSource, string.Empty));
                }
            }

            //Add the completions that are defined in the xml file
            foreach (string keyword_upcase in this.asmDudeTools_.Get_Keywords())
            {
                AsmTokenType type = this.asmDudeTools_.Get_Token_Type_Intel(keyword_upcase);
                if (selectedTypes.Contains(type))
                {
                    Arch arch     = Arch.ARCH_NONE;
                    bool selected = true;

                    if (type == AsmTokenType.Directive)
                    {
                        AssemblerEnum assembler = this.asmDudeTools_.Get_Assembler(keyword_upcase);
                        if (assembler.HasFlag(AssemblerEnum.MASM))
                        {
                            if (!usedAssember.HasFlag(AssemblerEnum.MASM))
                            {
                                selected = false;
                            }
                        }
                        else if (assembler.HasFlag(AssemblerEnum.NASM_INTEL) || assembler.HasFlag(AssemblerEnum.NASM_ATT))
                        {
                            if (!usedAssember.HasFlag(AssemblerEnum.NASM_INTEL))
                            {
                                selected = false;
                            }
                        }
                    }
                    else
                    {
                        arch     = this.asmDudeTools_.Get_Architecture(keyword_upcase);
                        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_upcase : keyword_upcase.ToLowerInvariant();
                        string archStr        = (arch == Arch.ARCH_NONE) ? string.Empty : " [" + ArchTools.ToString(arch) + "]";
                        string descriptionStr = this.asmDudeTools_.Get_Description(keyword_upcase);
                        descriptionStr = (string.IsNullOrEmpty(descriptionStr)) ? string.Empty : " - " + descriptionStr;
                        string displayTextFull = keyword_upcase + archStr + descriptionStr;
                        string displayText     = Truncat(displayTextFull);
                        //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr;
                        this.icons_.TryGetValue(type, out ImageSource imageSource);
                        completions.Add(new Completion(displayText, insertionText, displayTextFull, imageSource, string.Empty));
                    }
                }
            }
            #endregion

            return(completions);
        }
示例#11
0
        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);
        }
示例#12
0
        static void Payload()
        {
            string        path = "../../../../asm-dude.wiki/doc";
            StringBuilder sb   = new StringBuilder();
            StringBuilder sb2  = new StringBuilder();

            IDictionary <Arch, ISet <Mnemonic> > dictionary = new Dictionary <Arch, ISet <Mnemonic> >();

            sb2.AppendLine("<table>");

            foreach (string filename in Directory.EnumerateFiles(path, "*.md", SearchOption.TopDirectoryOnly).OrderBy(f => f))
            {
                //Console.WriteLine(filename);
                StreamReader file_Stream  = File.OpenText(filename);
                string       file_Content = file_Stream.ReadToEnd();
                (string Description, IList <Signature> Signatures) = Parse(file_Content);
                file_Stream.Close();

                sb.AppendLine(";--------------------------------------------------------");

                ISet <Mnemonic> mnemonics = new HashSet <Mnemonic>();
                foreach (Signature s in Signatures)
                {
                    mnemonics.Add(s.mnemonic);
                    foreach (Arch a in s.archs)
                    {
                        if (!dictionary.ContainsKey(a))
                        {
                            dictionary.Add(a, new HashSet <Mnemonic>());
                        }
                        dictionary[a].Add(s.mnemonic);
                    }
                }

                foreach (Mnemonic m in mnemonics)
                {
                    sb2.AppendLine("<tr><td><a href=\"https://github.com/HJLebbink/asm-dude/wiki/" + Path.GetFileNameWithoutExtension(filename) + "\">" + m.ToString() + "</a></td><td>" + Description + "</td><td>" + Get_Arch_Str(Signatures, m) + "</td></tr>");

                    #region Handle Signature File
                    sb.AppendLine("GENERAL\t" + m.ToString() + "\t" + Description + "\t" + Path.GetFileNameWithoutExtension(filename));
                    foreach (Signature s in Signatures)
                    {
                        if (s.mnemonic == m)
                        {
                            sb.AppendLine(s.ToString());
                        }
                    }
                    #endregion
                }
                System.IO.File.WriteAllText(@"C:\Temp\VS\signature-dec2018.txt", sb.ToString());
            }
            sb2.AppendLine("</table>");
            System.IO.File.WriteAllText(@"C:\Temp\VS\overview.txt", sb2.ToString());

            foreach (Arch a in dictionary.Keys.OrderBy(f => f))
            {
                Console.WriteLine("#region " + ArchTools.ToString(a));
                foreach (Mnemonic m in dictionary[a].OrderBy(f => f))
                {
                    Console.WriteLine("    " + m.ToString() + "   ; " + Get_Arch_Str(dictionary, m));
                }
                Console.WriteLine("#endregion " + ArchTools.ToString(a));
            }
        }
示例#13
0
        /// <summary>
        /// Determine which pieces of Quickinfo content should be displayed
        /// </summary>
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession");
            applicableToSpan = null;
            try
            {
                DateTime time1 = DateTime.Now;

                ITextSnapshot snapshot     = this._sourceBuffer.CurrentSnapshot;
                var           triggerPoint = (SnapshotPoint)session.GetTriggerPoint(snapshot);
                if (triggerPoint == null)
                {
                    AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: trigger point is null");
                    return;
                }
                string keyword = "";

                IEnumerable <IMappingTagSpan <AsmTokenTag> > enumerator = this._aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint));
                //AsmDudeToolsStatic.Output("INFO: AsmQuickInfoSource:AugmentQuickInfoSession: enumerator.Count="+ enumerator.Count());

                if (enumerator.Count() > 0)
                {
                    if (false)
                    {
                        // TODO: multiple tags at the provided triggerPoint is most likely the result of a bug in AsmTokenTagger, but it seems harmless...
                        if (enumerator.Count() > 1)
                        {
                            foreach (IMappingTagSpan <AsmTokenTag> v in enumerator)
                            {
                                AsmDudeToolsStatic.Output(string.Format("WARNING: {0}:AugmentQuickInfoSession. more than one tag! \"{1}\"", ToString(), v.Span.GetSpans(this._sourceBuffer).First().GetText()));
                            }
                        }
                    }

                    IMappingTagSpan <AsmTokenTag> asmTokenTag = enumerator.First();
                    SnapshotSpan tagSpan = asmTokenTag.Span.GetSpans(this._sourceBuffer).First();
                    keyword = tagSpan.GetText();
                    int lineNumber = tagSpan.Snapshot.GetLineNumberFromPosition(tagSpan.Start);

                    //AsmDudeToolsStatic.Output("INFO: AsmQuickInfoSource:AugmentQuickInfoSession: keyword=\""+ keyword + "\"; type=" + asmTokenTag.Tag.type +"; file="+AsmDudeToolsStatic.GetFileName(session.TextView.TextBuffer));
                    string keywordUpper = keyword.ToUpper();
                    applicableToSpan = snapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);

                    TextBlock description = null;

                    switch (asmTokenTag.Tag.Type)
                    {
                    case AsmTokenType.Misc:
                    {
                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("Keyword ", this._foreground));
                        description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Misc))));

                        string descr = this._asmDudeTools.Get_Description(keywordUpper);
                        if (descr.Length > 0)
                        {
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = this._foreground
                                });
                        }
                        break;
                    }

                    case AsmTokenType.Directive:
                    {
                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("Directive ", this._foreground));
                        description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Directive))));

                        string descr = this._asmDudeTools.Get_Description(keywordUpper);
                        if (descr.Length > 0)
                        {
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = this._foreground
                                });
                        }
                        break;
                    }

                    case AsmTokenType.Register:
                    {
                        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))));

                        string register_Descr = this._asmDudeTools.Get_Description(keywordUpper);
                        if (register_Descr.Length > 0)
                        {
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + register_Descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = this._foreground
                                });
                        }

                        if (this._asmSimulator.Is_Enabled)
                        {
                            IState_R state = this._asmSimulator.GetState(lineNumber, true);
                            string   msg   = this._asmSimulator.GetRegisterValue(RegisterTools.ParseRn(keyword), state);
                            if (msg.Length == 0)
                            {
                                msg = "Calculating register content";
                            }

                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap("\n" + msg, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = this._foreground
                                });
                        }
                        break;
                    }

                    case AsmTokenType.Mnemonic:
                    case AsmTokenType.Jump:
                    {
                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("Mnemonic ", this._foreground));
                        description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Opcode))));

                        Mnemonic mmemonic = AsmSourceTools.ParseMnemonic(keywordUpper);
                        {
                            string archStr = ":" + ArchTools.ToString(this._asmDudeTools.Mnemonic_Store.GetArch(mmemonic)) + " ";
                            string descr   = this._asmDudeTools.Mnemonic_Store.GetDescription(mmemonic);

                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(archStr + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = this._foreground
                                });
                        }
                        {           // show performance information
                            MicroArch selectedMicroarchitures = AsmDudeToolsStatic.Get_MicroArch_Switched_On();
                            IReadOnlyList <PerformanceItem> performanceData = this._asmDudeTools.Performance_Store.GetPerformance(mmemonic, selectedMicroarchitures);
                            if (performanceData.Count > 0)
                            {
                                FontFamily  family = new FontFamily("Consolas");
                                IList <Run> list   = new List <Run>();

                                description.Inlines.Add(new Run(string.Format("\n\n{0,-15}{1,-24}{2,-10}{3,-10}\n", "Architecture", "Instruction", "Latency", "Throughput"))
                                    {
                                        FontFamily = family,
                                        FontStyle  = FontStyles.Italic,
                                        FontWeight = FontWeights.Bold,
                                        Foreground = this._foreground
                                    });
                                foreach (PerformanceItem item in performanceData)
                                {
                                    description.Inlines.Add(new Run(string.Format("{0,-15}{1,-24}{2,-10}{3,-10}{4,-10}\n", item._microArch, item._instr + " " + item._args, item._latency, item._throughput, item._remark))
                                        {
                                            FontFamily = family,
                                            Foreground = this._foreground
                                        });
                                }
                            }
                        }
                        break;
                    }

                    case AsmTokenType.Label:
                    {
                        string label                = keyword;
                        string labelPrefix          = asmTokenTag.Tag.Misc;
                        string full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(labelPrefix, label, AsmDudeToolsStatic.Used_Assembler);

                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("Label ", this._foreground));
                        description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label))));

                        string descr = Get_Label_Description(full_Qualified_Label);
                        if (descr.Length == 0)
                        {
                            descr = Get_Label_Description(label);
                        }
                        if (descr.Length > 0)
                        {
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = this._foreground
                                });
                        }
                        break;
                    }

                    case AsmTokenType.LabelDef:
                    {
                        string label          = keyword;
                        string extra_Tag_Info = asmTokenTag.Tag.Misc;
                        string full_Qualified_Label;
                        if ((extra_Tag_Info != null) && extra_Tag_Info.Equals(AsmTokenTag.MISC_KEYWORD_PROTO))
                        {
                            full_Qualified_Label = label;
                        }
                        else
                        {
                            full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(extra_Tag_Info, label, AsmDudeToolsStatic.Used_Assembler);
                        }

                        AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: found label def " + full_Qualified_Label);

                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("Label ", this._foreground));
                        description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label))));

                        string descr = Get_Label_Def_Description(full_Qualified_Label, label);
                        if (descr.Length > 0)
                        {
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = this._foreground
                                });
                        }
                        break;
                    }

                    case AsmTokenType.Constant:
                    {
                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("Constant ", this._foreground));
                        description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Constant))));
                        break;
                    }

                    default:
                        //description = new TextBlock();
                        //description.Inlines.Add(makeRun1("Unused tagType " + asmTokenTag.Tag.type));
                        break;
                    }
                    if (description != null)
                    {
                        description.FontSize   = AsmDudeToolsStatic.Get_Font_Size() + 2;
                        description.FontFamily = AsmDudeToolsStatic.Get_Font_Type();
                        //AsmDudeToolsStatic.Output(string.Format("INFO: {0}:AugmentQuickInfoSession; setting description fontSize={1}; fontFamily={2}", this.ToString(), description.FontSize, description.FontFamily));
                        quickInfoContent.Add(description);
                    }
                }
                //AsmDudeToolsStatic.Output("INFO: AsmQuickInfoSource:AugmentQuickInfoSession: applicableToSpan=\"" + applicableToSpan + "\"; quickInfoContent,Count=" + quickInfoContent.Count);
                AsmDudeToolsStatic.Print_Speed_Warning(time1, "QuickInfo");
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output(string.Format("ERROR: {0}:AugmentQuickInfoSession; e={1}", ToString(), e.ToString()));
            }
        }
示例#14
0
        private SortedSet <Completion> selectedCompletions(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.usedAssembler;

            #region

            if (selectedTypes.Contains(AsmTokenType.Mnemonic))
            {
                ISet <Arch>      selectedArchs    = AsmDudeToolsStatic.getArchSwithedOn();
                IList <Mnemonic> allowedMnemonics = this.getAllowedMnemonics(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.mnemonicStore.getArch(mnemonic));
                    string descriptionStr = this._asmDudeTools.mnemonicStore.getDescription(mnemonic);
                    descriptionStr = (descriptionStr.Length == 0) ? "" : " - " + descriptionStr;
                    String displayText = keyword + archStr + descriptionStr;
                    //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr;

                    ImageSource imageSource = null;
                    this._icons.TryGetValue(AsmTokenType.Mnemonic, out 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.getKeywords())
            {
                AsmTokenType type = this._asmDudeTools.getTokenType(keyword);
                if (selectedTypes.Contains(type))
                {
                    Arch arch     = this._asmDudeTools.getArchitecture(keyword);
                    bool selected = AsmDudeToolsStatic.isArchSwitchedOn(arch);

                    if (selected && (type == AsmTokenType.Directive))
                    {
                        AssemblerEnum assembler = this._asmDudeTools.getAssembler(keyword);
                        switch (assembler)
                        {
                        case AssemblerEnum.MASM: if (usedAssember != AssemblerEnum.MASM)
                            {
                                selected = false;
                            }
                            break;

                        case AssemblerEnum.NASM: if (usedAssember != AssemblerEnum.NASM)
                            {
                                selected = false;
                            }
                            break;

                        case AssemblerEnum.UNKNOWN:
                        default:
                            break;
                        }
                    }
                    //AsmDudeToolsStatic.Output(string.Format(CultureInfo.CurrentCulture, "INFO:{0}:selectedCompletions; keyword={1}; arch={2}; selected={3}", this.ToString(), keyword, arch, 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.getDescription(keyword);
                        descriptionStr = (descriptionStr.Length == 0) ? "" : " - " + descriptionStr;
                        String displayText = keyword + archStr + descriptionStr;
                        //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr;

                        ImageSource imageSource = null;
                        this._icons.TryGetValue(type, out imageSource);
                        completions.Add(new Completion(displayText, insertionText, null, imageSource, ""));
                    }
                }
            }
            #endregion

            return(completions);
        }
示例#15
0
        private SortedSet <Completion> mnemonicOperandCompletions(bool useCapitals, ISet <AsmSignatureEnum> allowedOperands)
        {
            SortedSet <Completion> completions = new SortedSet <Completion>(new CompletionComparer());

            foreach (string keyword in this._asmDudeTools.getKeywords())
            {
                Arch         arch = this._asmDudeTools.getArchitecture(keyword);
                AsmTokenType type = this._asmDudeTools.getTokenType(keyword);

                bool selected = AsmDudeToolsStatic.isArchSwitchedOn(arch);
                //AsmDudeToolsStatic.Output("INFO: AsmCompletionSource:mnemonicOperandCompletions; keyword=" + keyword +"; selected="+selected +"; arch="+arch);

                if (selected)
                {
                    switch (type)
                    {
                    case AsmTokenType.Register:
                        //AsmDudeToolsStatic.Output("INFO: AsmCompletionSource:mnemonicOperandCompletions; rn=" + keyword);
                        Rn regName = RegisterTools.parseRn(keyword);
                        if (AsmSignatureTools.isAllowedReg(regName, allowedOperands))
                        {
                            //AsmDudeToolsStatic.Output(string.Format("INFO: AsmCompletionSource:mnemonicOperandCompletions; rn="+ keyword + " is selected"));
                        }
                        else
                        {
                            selected = false;
                        }
                        break;

                    case AsmTokenType.Misc:
                        if (AsmSignatureTools.isAllowedMisc(keyword, allowedOperands))
                        {
                            //AsmDudeToolsStatic.Output(string.Format("INFO: AsmCompletionSource:mnemonicOperandCompletions; rn="+ keyword + " is selected"));
                        }
                        else
                        {
                            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) ? keyword : keyword.ToLower();
                    string archStr        = (arch == Arch.NONE) ? "" : " [" + ArchTools.ToString(arch) + "]";
                    string descriptionStr = this._asmDudeTools.getDescription(keyword);
                    descriptionStr = (descriptionStr.Length == 0) ? "" : " - " + descriptionStr;
                    String displayText = keyword + archStr + descriptionStr;
                    //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr;

                    ImageSource imageSource = null;
                    this._icons.TryGetValue(type, out imageSource);
                    completions.Add(new Completion(displayText, insertionText, null, imageSource, ""));
                }
            }
            return(completions);
        }
示例#16
0
        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);
        }