예제 #1
0
 public DirectiveP()
 {
     DisplayName     = "directive"; //human readable version of the name
     ForegroundColor = AsmDudeToolsStatic.convertColor(Settings.Default.SyntaxHighlighting_Directive);
     IsItalic        = true;
 }
예제 #2
0
 public static string getLabelDescription(string label, ITextBuffer text)
 {
     return(AsmDudeToolsStatic.getLabelDescription(label, text.CurrentSnapshot.GetText()));
 }
        public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            DateTime time1 = DateTime.Now;

            if (spans.Count == 0)
            {  //there is no content in the buffer
                yield break;
            }

            foreach (SnapshotSpan curSpan in spans)
            {
                ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine();

                string line_capitals = containingLine.GetText().ToUpper();
                List <(int BeginPos, int Length, bool IsLabel)> pos = new List <(int BeginPos, int Length, bool IsLabel)>(AsmSourceTools.SplitIntoKeywordPos(line_capitals));

                int offset    = containingLine.Start.Position;
                int nKeywords = pos.Count;

                // if the line does not contain a Mnemonic, assume it is a source code line and make it a remark
                #region Check source code line
                if (IsSourceCode(line_capitals, pos))
                {
                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span((0, line_capitals.Length, false), offset, curSpan), this._remark));

                    continue; // go to the next line
                }
                #endregion

                for (int k = 0; k < nKeywords; k++)
                {
                    string asmToken = AsmSourceTools.Keyword(pos[k], line_capitals);

                    // keyword k is a label definition
                    if (pos[k].IsLabel)
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._labelDef));

                        continue;
                    }

                    AsmTokenType keywordType = this._asmDudeTools.Get_Token_Type_Intel(asmToken);
                    switch (keywordType)
                    {
                    case AsmTokenType.Jump:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._jump));

                        k++;         // goto the next word
                        if (k == nKeywords)
                        {
                            break;         // there are no next words
                        }

                        string asmToken2 = AsmSourceTools.Keyword(pos[k], line_capitals);
                        switch (asmToken2)
                        {
                        case "WORD":
                        case "DWORD":
                        case "QWORD":
                        case "SHORT":
                        case "NEAR":
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._misc));

                            k++;
                            if (k == nKeywords)
                            {
                                break;
                            }

                            string asmToken3 = AsmSourceTools.Keyword(pos[k], line_capitals);
                            switch (asmToken3)
                            {
                            case "PTR":
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._misc));

                                break;
                            }
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._label));

                                break;
                            }

                            break;
                        }

                        default:
                        {
                            if (RegisterTools.IsRegister(asmToken2))
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._register));
                            }
                            else
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._label));
                            }
                            break;
                        }
                        }
                        break;
                    }

                    case AsmTokenType.UNKNOWN:     // asmToken is not a known keyword, check if it is numerical
                    {
                        if (asmToken.Equals("OFFSET"))

                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._directive));

                            k++;         // goto the next word
                            if (k == nKeywords)
                            {
                                break;
                            }

                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._label));
                        }
                        else if (IsConstant(asmToken))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._constant));
                        }
                        else if (asmToken.StartsWith("\"") && asmToken.EndsWith("\""))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._constant));
                        }
                        else
                        {
                            //yield return new TagSpan<AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._UNKNOWN);
                        }
                        break;
                    }

                    case AsmTokenType.Directive:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._directive));

                        break;
                    }

                    case AsmTokenType.Mnemonic:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._mnemonic));

                        break;
                    }

                    case AsmTokenType.Register:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._register));

                        break;
                    }

                    default: break;
                    }
                }
            }
            AsmDudeToolsStatic.Print_Speed_Warning(time1, "MasmDisassemblyTokenTagger");
        }
예제 #4
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);
        }
예제 #5
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            Contract.Requires(session != null);
            Contract.Requires(completionSets != null);

            try
            {
                //AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:AugmentCompletionSession", this.ToString()));

                if (!Settings.Default.CodeCompletion_On)
                {
                    return;
                }

                DateTime      time1        = DateTime.Now;
                ITextSnapshot snapshot     = this.buffer_.CurrentSnapshot;
                SnapshotPoint triggerPoint = (SnapshotPoint)session.GetTriggerPoint(snapshot);
                if (triggerPoint == null)
                {
                    return;
                }
                ITextSnapshotLine line = triggerPoint.GetContainingLine();

                //1] check if current position is in a remark; if we are in a remark, no code completion
                #region
                if (triggerPoint.Position > 1)
                {
                    char currentTypedChar = (triggerPoint - 1).GetChar();
                    //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession: current char = "+ currentTypedChar);
                    if (!currentTypedChar.Equals('#'))
                    { //TODO UGLY since the user can configure this starting character
                        int pos = triggerPoint.Position - line.Start;
                        if (AsmSourceTools.IsInRemark(pos, line.GetText()))
                        {
                            //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession: currently in a remark section");
                            return;
                        }
                        else
                        {
                            // AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession: not in a remark section");
                        }
                    }
                }
                #endregion

                //2] find the start of the current keyword
                #region
                SnapshotPoint start = triggerPoint;
                while ((start > line.Start) && !AsmSourceTools.IsSeparatorChar((start - 1).GetChar()))
                {
                    start -= 1;
                }
                #endregion

                //3] get the word that is currently being typed
                #region
                ITrackingSpan applicableTo   = snapshot.CreateTrackingSpan(new SnapshotSpan(start, triggerPoint), SpanTrackingMode.EdgeInclusive);
                string        partialKeyword = applicableTo.GetText(snapshot);
                bool          useCapitals    = AsmDudeToolsStatic.Is_All_upcase(partialKeyword);

                string lineStr = line.GetText();
                (string label, Mnemonic mnemonic, string[] args, string remark)t = AsmSourceTools.ParseLine(lineStr);
                Mnemonic mnemonic = t.mnemonic;
                string   previousKeyword_upcase = AsmDudeToolsStatic.Get_Previous_Keyword(line.Start, start).ToUpperInvariant();

                //AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:AugmentCompletionSession. lineStr=\"{1}\"; previousKeyword=\"{2}\"", this.ToString(), lineStr, previousKeyword));

                if (mnemonic == Mnemonic.NONE)
                {
                    if (previousKeyword_upcase.Equals("INVOKE", StringComparison.Ordinal)) //TODO INVOKE is a MASM keyword not a NASM one...
                    {
                        // Suggest a label
                        IEnumerable <Completion> completions = this.Label_Completions(useCapitals, false);
                        if (completions.Any())
                        {
                            completionSets.Add(new CompletionSet("Labels", "Labels", applicableTo, completions, Enumerable.Empty <Completion>()));
                        }
                    }
                    else
                    {
                        {
                            ISet <AsmTokenType> selected1 = new HashSet <AsmTokenType> {
                                AsmTokenType.Directive, AsmTokenType.Jump, AsmTokenType.Misc, AsmTokenType.Mnemonic
                            };
                            IEnumerable <Completion> completions1 = this.Selected_Completions(useCapitals, selected1, true);
                            if (completions1.Any())
                            {
                                completionSets.Add(new CompletionSet("All", "All", applicableTo, completions1, Enumerable.Empty <Completion>()));
                            }
                        }
                        if (false)
                        {
                            ISet <AsmTokenType> selected2 = new HashSet <AsmTokenType> {
                                AsmTokenType.Jump, AsmTokenType.Mnemonic
                            };
                            IEnumerable <Completion> completions2 = this.Selected_Completions(useCapitals, selected2, false);
                            if (completions2.Any())
                            {
                                completionSets.Add(new CompletionSet("Instr", "Instr", applicableTo, completions2, Enumerable.Empty <Completion>()));
                            }
                        }
                        if (false)
                        {
                            ISet <AsmTokenType> selected3 = new HashSet <AsmTokenType> {
                                AsmTokenType.Directive, AsmTokenType.Misc
                            };
                            IEnumerable <Completion> completions3 = this.Selected_Completions(useCapitals, selected3, true);
                            if (completions3.Any())
                            {
                                completionSets.Add(new CompletionSet("Directive", "Directive", applicableTo, completions3, Enumerable.Empty <Completion>()));
                            }
                        }
                    }
                }
                else
                { // the current line contains a mnemonic
                  //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession; mnemonic=" + mnemonic+ "; previousKeyword="+ previousKeyword);

                    if (AsmSourceTools.IsJump(AsmSourceTools.ParseMnemonic(previousKeyword_upcase, true)))
                    {
                        //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession; previous keyword is a jump mnemonic");
                        // previous keyword is jump (or call) mnemonic. Suggest "SHORT" or a label
                        IEnumerable <Completion> completions = this.Label_Completions(useCapitals, true);
                        if (completions.Any())
                        {
                            completionSets.Add(new CompletionSet("Labels", "Labels", applicableTo, completions, Enumerable.Empty <Completion>()));
                        }
                    }
                    else if (previousKeyword_upcase.Equals("SHORT", StringComparison.Ordinal) || previousKeyword_upcase.Equals("NEAR", StringComparison.Ordinal))
                    {
                        // Suggest a label
                        IEnumerable <Completion> completions = this.Label_Completions(useCapitals, false);
                        if (completions.Any())
                        {
                            completionSets.Add(new CompletionSet("Labels", "Labels", applicableTo, completions, Enumerable.Empty <Completion>()));
                        }
                    }
                    else
                    {
                        IList <Operand>         operands = AsmSourceTools.MakeOperands(t.args);
                        ISet <AsmSignatureEnum> allowed  = new HashSet <AsmSignatureEnum>();
                        int commaCount = AsmSignature.Count_Commas(lineStr);
                        IEnumerable <AsmSignatureElement> allSignatures = this.asmDudeTools_.Mnemonic_Store.GetSignatures(mnemonic);

                        ISet <Arch> selectedArchitectures = AsmDudeToolsStatic.Get_Arch_Swithed_On();
                        foreach (AsmSignatureElement se in AsmSignatureHelpSource.Constrain_Signatures(allSignatures, operands, selectedArchitectures))
                        {
                            if (commaCount < se.Operands.Count)
                            {
                                foreach (AsmSignatureEnum s in se.Operands[commaCount])
                                {
                                    allowed.Add(s);
                                }
                            }
                        }
                        IEnumerable <Completion> completions = this.Mnemonic_Operand_Completions(useCapitals, allowed, line.LineNumber);
                        if (completions.Any())
                        {
                            completionSets.Add(new CompletionSet("All", "All", applicableTo, completions, Enumerable.Empty <Completion>()));
                        }
                    }
                }
                #endregion
                AsmDudeToolsStatic.Print_Speed_Warning(time1, "Code Completion");
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:AugmentCompletionSession; e={1}", this.ToString(), e.ToString()));
            }
        }
 public DirectiveP()
 {
     DisplayName     = "AsmDude - Syntax Highlighting - Directive"; //human readable version of the name found in Tools>Options>Environment>Fonts and Colors>Text Editor
     ForegroundColor = AsmDudeToolsStatic.convertColor(Settings.Default.SyntaxHighlighting_Directive);
     IsItalic        = true;
 }
예제 #7
0
 public AsmTokenTag(TokenType type)
 {
     this.type = type;
     AsmDudeToolsStatic.getCompositionContainer().SatisfyImportsOnce(this);
 }
 public MiscP()
 {
     this.DisplayName     = "AsmDude - Syntax Highlighting - Misc"; //human readable version of the name found in Tools>Options>Environment>Fonts and Colors>Text Editor
     this.ForegroundColor = AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Misc);
 }
 public RemarkP()
 {
     this.DisplayName     = "AsmDude - Syntax Highlighting - Remark"; //human readable version of the name found in Tools>Options>Environment>Fonts and Colors>Text Editor
     this.ForegroundColor = AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Remark);
     this.IsItalic        = true;
 }
예제 #10
0
 public UserDefined3P()
 {
     this.DisplayName     = "AsmDude - Syntax Highlighting - Userdefined 3"; //human readable version of the name found in Tools>Options>Environment>Fonts and Colors>Text Editor
     this.ForegroundColor = AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined3);
     this.IsItalic        = Settings.Default.SyntaxHighlighting_Userdefined3_Italic;
 }
예제 #11
0
 public JumpP()
 {
     this.DisplayName     = "AsmDude - Syntax Highlighting - Jump"; //human readable version of the name
     this.ForegroundColor = AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Jump);
     this.IsItalic        = Settings.Default.SyntaxHighlighting_Jump_Italic;
 }
예제 #12
0
        public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            DateTime time1 = DateTime.Now;

            if (spans.Count == 0)
            {  //there is no content in the buffer
                yield break;
            }

            foreach (SnapshotSpan curSpan in spans)
            {
                ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine();

                string line = containingLine.GetText().ToUpper();
                IList <(int, int, bool)> pos = AsmSourceTools.SplitIntoKeywordPos(line);

                int offset    = containingLine.Start.Position;
                int nKeywords = pos.Count;

                for (int k = 0; k < nKeywords; k++)
                {
                    string asmToken = NasmTokenTagger.Keyword(pos[k], line);
                    // keyword starts with a remark char
                    if (AsmSourceTools.IsRemarkChar(asmToken[0]))
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), this._remark));

                        continue;
                    }

                    // keyword k is a label definition
                    if (pos[k].Item3)
                    {
                        //AsmDudeToolsStatic.Output_INFO("NasmTokenTagger:GetTags: found label " +asmToken);
                        if (IsProperLabelDef(asmToken, containingLine.LineNumber, out AsmTokenTag asmTokenTag))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), asmTokenTag));

                            continue;
                        }
                    }

                    AsmTokenType keywordType = this._asmDudeTools.Get_Token_Type(asmToken);
                    switch (keywordType)
                    {
                    case AsmTokenType.Jump:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), this._jump));

                        k++;     // goto the next word
                        if (k == nKeywords)
                        {
                            break;                     // there are no next words
                        }
                        string asmToken2 = NasmTokenTagger.Keyword(pos[k], line);
                        switch (asmToken2)
                        {
                        case "WORD":
                        case "DWORD":
                        case "QWORD":
                        case "SHORT":
                        case "NEAR":
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), this._misc));

                            k++;
                            if (k == nKeywords)
                            {
                                break;
                            }
                            string asmToken3 = NasmTokenTagger.Keyword(pos[k], line);
                            if (asmToken3.Equals("PTR"))
                            {
                                yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._misc));
                            }
                            else
                            {
                                if (IsProperLabel(asmToken3, containingLine.LineNumber, out AsmTokenTag asmTokenTag))
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), asmTokenTag));
                                }
                            }
                            break;
                        }

                        default:
                        {
                            if (RegisterTools.IsRegister(asmToken2))
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), this._register));
                            }
                            else
                            {
                                if (IsProperLabel(asmToken2, containingLine.LineNumber, out AsmTokenTag asmTokenTag))
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), asmTokenTag));
                                }
                            }
                            break;
                        }
                        }
                        break;
                    }

                    case AsmTokenType.UNKNOWN:     // asmToken is not a known keyword, check if it is numerical
                    {
                        if (AsmTools.AsmSourceTools.IsConstant(asmToken))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), this._constant));
                        }
                        else if (asmToken.StartsWith("\"") && asmToken.EndsWith("\""))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), this._constant));
                        }
                        else
                        {
                            bool isUnknown = true;

                            // do one word lookahead; see whether we can understand the current unknown word
                            if ((k + 1) < nKeywords)
                            {
                                k++;
                                string nextKeyword = NasmTokenTagger.Keyword(pos[k], line);
                                switch (nextKeyword)
                                {
                                case "LABEL":
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k - 1], offset, curSpan), this._labelDef));

                                    yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), this._directive));

                                    isUnknown = false;
                                    break;
                                }

                                default:
                                {
                                    k--;
                                    break;
                                }
                                }
                            }

                            // do one word look back; see whether we can understand the current unknown word
                            if (k > 0)
                            {
                                string previousKeyword = NasmTokenTagger.Keyword(pos[k - 1], line);
                                switch (previousKeyword)
                                {
                                case "ALIAS":
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), this._labelDef));

                                    isUnknown = false;
                                    break;
                                }

                                default:
                                {
                                    break;
                                }
                                }
                            }

                            if (isUnknown)
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), this._UNKNOWN));
                            }
                        }
                        break;
                    }

                    case AsmTokenType.Directive:
                    {
                        AssemblerEnum assember = this._asmDudeTools.Get_Assembler(asmToken);
                        if (assember.HasFlag(AssemblerEnum.NASM))     // this NASM token-tagger only tags NASM directives
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), this._directive));
                        }
                        break;
                    }

                    default:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmTokenTagger.New_Span(pos[k], offset, curSpan), new AsmTokenTag(keywordType)));

                        break;
                    }
                    }
                }
            }
            AsmDudeToolsStatic.Print_Speed_Warning(time1, "NasmTokenTagger");
        }
        public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            DateTime time1 = DateTime.Now;

            if (spans.Count == 0)
            { //there is no content in the buffer
                yield break;
            }

            foreach (SnapshotSpan curSpan in spans)
            {
                ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine();

                string line_upcase = containingLine.GetText().ToUpperInvariant();
                List <(int beginPos, int length, bool isLabel)> pos = new List <(int beginPos, int length, bool isLabel)>(AsmSourceTools.SplitIntoKeywordPos(line_upcase));

                int offset    = containingLine.Start.Position;
                int nKeywords = pos.Count;

                #region Check if the current line is a line of source code
                if (IsSourceCode(line_upcase, pos))
                {
                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span((0, line_upcase.Length, false), offset, curSpan), this.remark_));

                    continue; // go to the next line
                }
                #endregion

                for (int k = 0; k < nKeywords; k++)
                {
                    string asmToken = AsmSourceTools.Keyword(pos[k], line_upcase);
                    // keyword starts with a remark char
                    if (AsmSourceTools.IsRemarkChar(asmToken[0]))
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.remark_));

                        continue;
                    }

                    // keyword k is a label definition
                    if (pos[k].isLabel)
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.labelDef_));

                        continue;
                    }

                    AsmTokenType keywordType = this.asmDudeTools_.Get_Token_Type_Att(asmToken);
                    switch (keywordType)
                    {
                    case AsmTokenType.Jump:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.jump_));

                        k++;         // goto the next word
                        if (k == nKeywords)
                        {
                            break;         // there are no next words
                        }

                        string asmToken2 = AsmSourceTools.Keyword(pos[k], line_upcase);
                        switch (asmToken2)
                        {
                        case "WORD":
                        case "DWORD":
                        case "QWORD":
                        case "SHORT":
                        case "NEAR":
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.misc_));

                            k++;
                            if (k == nKeywords)
                            {
                                break;
                            }

                            string asmToken3 = AsmSourceTools.Keyword(pos[k], line_upcase);
                            switch (asmToken3)
                            {
                            case "PTR":
                            {
                                yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this.misc_));

                                break;
                            }
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.label_));

                                break;
                            }
                            break;
                        }

                        default:
                        {
                            if (RegisterTools.IsRegister(asmToken2))
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.register_));
                            }
                            else if (AsmSourceTools.Evaluate_Constant(asmToken2, true).valid)
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_));
                            }
                            else
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.label_));
                            }
                            break;
                        }
                        }
                        break;
                    }

                    case AsmTokenType.UNKNOWN:     // asmToken is not a known keyword, check if it is numerical
                    {
                        if (AsmSourceTools.Evaluate_Constant(asmToken, true).valid)
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_));
                        }
                        else if (asmToken.StartsWith("$", StringComparison.Ordinal))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_));
                        }
                        else if (asmToken.StartsWith("\"", StringComparison.Ordinal) && asmToken.EndsWith("\"", StringComparison.Ordinal))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_));
                        }
                        else
                        {
                            //yield return new TagSpan<AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._UNKNOWN);
                        }
                        break;
                    }

                    case AsmTokenType.Directive:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.directive_));

                        break;
                    }

                    case AsmTokenType.Mnemonic:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.mnemonic_));

                        break;
                    }

                    case AsmTokenType.Register:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.register_));

                        break;
                    }

                    default: break;
                    }
                }
            }
            AsmDudeToolsStatic.Print_Speed_Warning(time1, "NasmAttDisassemblyTokenTagger");
        }
예제 #14
0
        /// <summary>
        /// Singleton pattern: use AsmDudeTools.Instance for the instance of this class
        /// </summary>
        private AsmDudeTools()
        {
            //AsmDudeToolsStatic.Output(string.Format("INFO: AsmDudeTools constructor"));

            #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._smartThreadPool = new SmartThreadPool();
            //this._smartThreadPool.Start(); // There seems no need to start this threadpool

            #region load Signature Store and Performance Store
            string path = AsmDudeToolsStatic.Get_Install_Path() + "Resources" + Path.DirectorySeparatorChar;
            {
                //string filename = path + "mnemonics-nasm.txt";
                string filename_Regular = path + "signature-june2016.txt";
                string filename_Hand    = path + "signature-hand-1.txt";
                this._mnemonicStore = new MnemonicStore(filename_Regular, filename_Hand);
            }
            {
                this._performanceStore = new PerformanceStore();
                this._performanceStore.AddData(MicroArch.Broadwell, path + "Performance" + Path.DirectorySeparatorChar + "Broadwell.tsv");
                this._performanceStore.AddData(MicroArch.Skylake, path + "Performance" + Path.DirectorySeparatorChar + "Skylake.tsv");
            }
            #endregion

            Init_Data();

            #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)))
                {
                    IList <AsmSignatureElement> intel = this._mnemonicStore.GetSignatures(mnemonic);
                    IList <AsmSignatureElement> nasm  = store2.GetSignatures(mnemonic);

                    signaturesIntel.Clear();
                    signaturesNasm.Clear();

                    foreach (AsmSignatureElement e in intel)
                    {
                        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);
                        }
                    }
                    foreach (AsmSignatureElement e in nasm)
                    {
                        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("Intel " + instruction + ": arch" + e.archStr);
                        if ((e.Arch_Str == null) || (e.Arch_Str.Length == 0))
                        {
                            if (signaturesNasm.ContainsKey(instruction))
                            {
                                AsmDudeToolsStatic.Output("Intel " + instruction + " has no arch, but NASM has \"" + signaturesNasm[instruction] + "\".");
                            }
                            else
                            {
                                if (signaturesNasm.Count == 1)
                                {
                                    AsmDudeToolsStatic.Output("Intel " + instruction + " has no arch, but NASM has \"" + signaturesNasm.GetEnumerator().Current + "\".");
                                }
                                else
                                {
                                    AsmDudeToolsStatic.Output("Intel " + instruction + " has no arch:");
                                    foreach (KeyValuePair <string, string> pair in signaturesNasm)
                                    {
                                        AsmDudeToolsStatic.Output("\tNASM has " + pair.Key + ": \"" + pair.Value + "\".");
                                    }
                                    AsmDudeToolsStatic.Output("    ----");
                                }
                            }
                        }
                    }

                    if (false)
                    {
                        if (intel.Count != nasm.Count)
                        {
                            foreach (AsmSignatureElement e in intel)
                            {
                                AsmDudeToolsStatic.Output("INTEL " + mnemonic + ": " + e);
                            }
                            foreach (AsmSignatureElement e in nasm)
                            {
                                AsmDudeToolsStatic.Output("NASM " + mnemonic + ": " + e);
                            }
                        }
                    }
                }
                foreach (String str in archs)
                {
                    AsmDudeToolsStatic.Output("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 = "";
                    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   = Get_Url(keyword);

                        this.Mnemonic_Store.SetHtmlRef(mnemonic, reference);
                    }
                }
                AsmDudeToolsStatic.Output(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(s + ",");
                }
            }
            #endregion
        }
 public OpcodeP()
 {
     //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO: Entering constructor for: {0}", this.ToString()));
     DisplayName     = "AsmDude - Syntax Highlighting - Mnemonic"; //human readable version of the name found in Tools>Options>Environment>Fonts and Colors>Text Editor
     ForegroundColor = AsmDudeToolsStatic.convertColor(Settings.Default.SyntaxHighlighting_Opcode);
 }
예제 #16
0
        public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            DateTime time1 = DateTime.Now;

            if (spans.Count == 0)
            {  //there is no content in the buffer
                yield break;
            }

            foreach (SnapshotSpan curSpan in spans)
            {
                ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine();

                string line = containingLine.GetText().ToUpper();
                IList <Tuple <int, int, bool> > pos = AsmSourceTools.splitIntoKeywordPos(line);

                int offset    = containingLine.Start.Position;
                int nKeywords = pos.Count;

                for (int k = 0; k < nKeywords; k++)
                {
                    if (pos[k].Item3)
                    {
                        SnapshotSpan label       = newSpan(pos[k], offset, curSpan);
                        string       labelString = label.GetText();
                        //AsmDudeToolsStatic.Output(string.Format("INFO: found label {0}", labelString));
                        if (labelString.StartsWith("."))
                        {
                            // TODO: special NASM local labels, for the moment, ignore them.
                        }
                        else
                        {
                            yield return(new TagSpan <AsmTokenTag>(label, this._labelDef));
                        }
                        continue;
                    }

                    string asmToken = keyword(pos[k], line);
                    if (AsmSourceTools.isRemarkChar(asmToken[0]))
                    {
                        yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._remark));

                        continue;
                    }

                    AsmTokenType keywordType = this._asmDudeTools.getTokenType(asmToken);
                    switch (keywordType)
                    {
                    case AsmTokenType.Jump:
                        #region Jump
                        yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._jump));

                        k++;
                        if (k == nKeywords)
                        {
                            break;
                        }

                        string asmToken2 = keyword(pos[k], line);
                        if (!asmToken2[0].Equals('.'))
                        {
                            switch (asmToken2)
                            {
                            case "WORD":
                            case "DWORD":
                            case "QWORD":
                            case "SHORT":
                            case "NEAR":
                                yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._misc));

                                k++;
                                if (k == nKeywords)
                                {
                                    break;
                                }
                                string asmToken3 = keyword(pos[k], line);
                                if (!asmToken3[0].Equals('.'))
                                {
                                    switch (asmToken3)
                                    {
                                    case "PTR":
                                        yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._misc));

                                        break;

                                    default:
                                        yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._label));

                                        break;
                                    }
                                }
                                break;

                            default:
                                if (RegisterTools.isRegister(asmToken2))
                                {
                                    yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._register));
                                }
                                else
                                {
                                    yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._label));
                                }
                                break;
                            }
                        }
                        break;

                        #endregion Jump
                    case AsmTokenType.UNKNOWN:     // asmToken is not a known keyword, check if it is numerical
                        #region UNKNOWN
                        if (AsmTools.AsmSourceTools.isConstant(asmToken))
                        {
                            yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._constant));
                        }
                        else if (asmToken.StartsWith("\"") && asmToken.EndsWith("\""))
                        {
                            yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._constant));
                        }
                        else
                        {
                            bool isUnknown = true;

                            // do one word lookahead; see whether we can understand the current unknown word
                            if ((k + 1) < nKeywords)
                            {
                                k++;
                                string nextKeyword = keyword(pos[k], line);

                                switch (nextKeyword)
                                {
                                case "LABEL":
                                    yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k - 1], offset, curSpan), this._labelDef));

                                    yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._directive));

                                    isUnknown = false;
                                    break;

                                default:
                                    k--;
                                    break;
                                }
                            }

                            // do one word look back; see whether we can understand the current unknown word
                            if (k > 0)
                            {
                                string previousKeyword = keyword(pos[k - 1], line);
                                switch (previousKeyword)
                                {
                                case "ALIAS":
                                    yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._labelDef));

                                    isUnknown = false;
                                    break;

                                default:
                                    break;
                                }
                            }

                            if (isUnknown)
                            {
                                yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._UNKNOWN));
                            }
                        }
                        break;

                        #endregion UNKNOWN
                    case AsmTokenType.Directive:
                        #region Directive
                        switch (this._asmDudeTools.getAssembler(asmToken))
                        {
                        case AssemblerEnum.NASM:
                        case AssemblerEnum.UNKNOWN:
                            yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._directive));

                            break;

                        default:
                            break;
                        }
                        break;

                        #endregion Directive
                    default:
                        yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), new AsmTokenTag(keywordType)));

                        break;
                    }
                }
            }
            AsmDudeToolsStatic.printSpeedWarning(time1, "NasmTokenTagger");
        }
 public RegisterP()
 {
     DisplayName     = "AsmDude - Syntax Highlighting - Register"; //human readable version of the name found in Tools>Options>Environment>Fonts and Colors>Text Editor
     ForegroundColor = AsmDudeToolsStatic.convertColor(Settings.Default.SyntaxHighlighting_Register);
 }
예제 #18
0
        public IEnumerable <ITagSpan <AsmTokenTag> > GetTags_NEW(NormalizedSnapshotSpanCollection spans)
        {
            DateTime time1 = DateTime.Now;

            if (spans.Count == 0)
            { //there is no content in the buffer
                yield break;
            }

            foreach (SnapshotSpan curSpan in spans)
            {
                ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine();

                string line_upcase = containingLine.GetText().ToUpper(CultureInfo.InvariantCulture);
                int    offset      = containingLine.Start.Position;
                IEnumerator <(int beginPos, int length, bool isLabel)> enumerator = AsmSourceTools.SplitIntoKeywordPos(line_upcase).GetEnumerator();

                bool needToAdvance = false;
                bool hasNext       = enumerator.MoveNext();
                if (!hasNext)
                {
                    break;
                }

                (int beginPos, int length, bool isLabel)prev    = (0, 0, false);
                (int beginPos, int length, bool isLabel)current = enumerator.Current;

                while (hasNext)
                {
                    string asmToken = AsmSourceTools.Keyword(current, line_upcase);
                    // keyword starts with a remark char
                    if (AsmSourceTools.IsRemarkChar(asmToken[0]))
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.remark_));

                        continue;
                    }

                    // keyword k is a label definition
                    if (current.isLabel)
                    {
                        SnapshotSpan labelDefSpan = NasmIntelTokenTagger.New_Span(current, offset, curSpan);
                        //AsmDudeToolsStatic.Output_INFO("MasmTokenTagger:GetTags: found label " + asmToken +" at line "+containingLine.LineNumber);
                        if (asmToken.Equals("@@", StringComparison.Ordinal))
                        {
                            // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc.
                        }
                        else
                        {
                            yield return(new TagSpan <AsmTokenTag>(labelDefSpan, this.Make_AsmTokenTag_LabelDef(containingLine.LineNumber)));
                        }
                        continue;
                    }

                    AsmTokenType keywordType = this.asmDudeTools_.Get_Token_Type_Intel(asmToken);
                    switch (keywordType)
                    {
                    case AsmTokenType.Jump:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.jump_));

                        {         // go to the next word
                            if (needToAdvance)
                            {
                                hasNext = enumerator.MoveNext();
                                prev    = current;
                                current = enumerator.Current;
                            }
                            needToAdvance = true;
                        }
                        string asmToken2 = AsmSourceTools.Keyword(current, line_upcase);
                        switch (asmToken2)
                        {
                        case "$":
                        case "@B":
                        case "@F":
                        {
                            // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc.
                            break;
                        }

                        case "WORD":
                        case "DWORD":
                        case "QWORD":
                        case "SHORT":
                        case "NEAR":
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.misc_));

                            {                 // go to the next word
                                if (needToAdvance)
                                {
                                    hasNext = enumerator.MoveNext();
                                    prev    = current;
                                    current = enumerator.Current;
                                }
                                needToAdvance = true;
                            }
                            switch (AsmSourceTools.Keyword(current, line_upcase))
                            {
                            case "$":
                            case "@B":
                            case "@F":
                            {
                                // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc.
                                break;
                            }

                            case "PTR":
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.misc_));

                                break;
                            }

                            default:
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.Make_AsmTokenTag_Label(containingLine.LineNumber)));

                                break;
                            }
                            }
                            break;
                        }

                        default:
                        {
                            if (RegisterTools.IsRegister(asmToken2))
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.register_));
                            }
                            else
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.Make_AsmTokenTag_Label(containingLine.LineNumber)));
                            }
                            break;
                        }
                        }
                        break;
                    }

                    case AsmTokenType.UNKNOWN:     // asmToken is not a known keyword, check if it is numerical
                    {
                        //if (AsmTools.AsmSourceTools.Evaluate_Constant(asmToken, true).valid)
                        if (AsmSourceTools.Parse_Constant(asmToken, true).valid)
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.constant_));
                        }
                        else if (asmToken.StartsWith("\"", StringComparison.Ordinal) && asmToken.EndsWith("\"", StringComparison.Ordinal))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.constant_));
                        }
                        else
                        {
                            // do one word look back; see whether we can understand the current unknown word
                            string previousKeyword = AsmSourceTools.Keyword(prev, line_upcase);
                            switch (previousKeyword)
                            {
                            case "ALIAS":
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.labelDef_));

                                break;
                            }

                            default:
                            {
                                break;
                            }
                            }

                            // do one word lookahead; see whether we can understand the current unknown word
                            // go to the next word
                            needToAdvance = false;

                            if (enumerator.MoveNext())
                            {
                                prev    = current;
                                current = enumerator.Current;

                                string nextKeyword = AsmSourceTools.Keyword(current, line_upcase);
                                switch (nextKeyword)
                                {
                                case "PROC":
                                case "EQU":
                                case "LABEL":
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(prev, offset, curSpan), this.labelDef_));

                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.directive_));

                                    break;
                                }

                                case "PROTO":
                                {                 // a proto is considered a label definition but it should not clash with other label definitions
                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(prev, offset, curSpan), this.labelDef_PROTO_));

                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.directive_));

                                    break;
                                }

                                default:
                                    break;
                                }
                            }
                            else
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.UNKNOWN_));
                            }
                        }
                        break;
                    }

                    case AsmTokenType.Directive:
                    {
                        AssemblerEnum assember = this.asmDudeTools_.Get_Assembler(asmToken);
                        if (assember.HasFlag(AssemblerEnum.MASM))         // this MASM token-tagger only tags MASM directives
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.directive_));

                            if (asmToken.Equals("INVOKE", StringComparison.Ordinal))
                            {
                                {         // go to the next word
                                    if (needToAdvance)
                                    {
                                        hasNext = enumerator.MoveNext();
                                        prev    = current;
                                        current = enumerator.Current;
                                    }
                                    needToAdvance = true;
                                }
                                //string asmToken2 = NasmTokenTagger.Keyword(current, line);
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.Make_AsmTokenTag_Label(containingLine.LineNumber)));
                            }
                        }
                        break;
                    }

                    default:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), new AsmTokenTag(keywordType)));

                        break;
                    }
                    }
                    { // go to the next word
                        if (needToAdvance)
                        {
                            hasNext = enumerator.MoveNext();
                            prev    = current;
                            current = enumerator.Current;
                        }
                        needToAdvance = true;
                    }
                }
            }
            AsmDudeToolsStatic.Print_Speed_Warning(time1, "MasmTokenTagger");
        }
 public JumpP()
 {
     DisplayName     = "AsmDude - Syntax Highlighting - Jump"; //human readable version of the name
     ForegroundColor = AsmDudeToolsStatic.convertColor(Settings.Default.SyntaxHighlighting_Jump);
 }
예제 #20
0
        public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            DateTime time1 = DateTime.Now;

            if (spans.Count == 0)
            {  //there is no content in the buffer
                yield break;
            }

            foreach (SnapshotSpan curSpan in spans)
            {
                ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine();

                string line = containingLine.GetText().ToUpper();
                var    pos  = new List <(int BeginPos, int Length, bool IsLabel)>(AsmSourceTools.SplitIntoKeywordPos(line));

                int offset    = containingLine.Start.Position;
                int nKeywords = pos.Count;

                for (int k = 0; k < nKeywords; k++)
                {
                    string asmToken = NasmIntelTokenTagger.Keyword(pos[k], line);
                    // keyword starts with a remark char
                    if (AsmSourceTools.IsRemarkChar(asmToken[0]))
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._remark));

                        continue;
                    }

                    // keyword k is a label definition
                    if (pos[k].IsLabel)
                    {
                        SnapshotSpan labelDefSpan = NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan);
                        //AsmDudeToolsStatic.Output_INFO("MasmTokenTagger:GetTags: found label " + asmToken +" at line "+containingLine.LineNumber);
                        if (asmToken.Equals("@@"))
                        {
                            // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc.
                        }
                        else
                        {
                            var v = Make_AsmTokenTag_LabelDef(containingLine.LineNumber);
                            yield return(new TagSpan <AsmTokenTag>(labelDefSpan, v));
                        }
                        continue;
                    }

                    AsmTokenType keywordType = this._asmDudeTools.Get_Token_Type_Intel(asmToken);
                    switch (keywordType)
                    {
                    case AsmTokenType.Jump:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._jump));

                        k++;         // goto the next word
                        if (k == nKeywords)
                        {
                            break;
                        }

                        string asmToken2 = NasmIntelTokenTagger.Keyword(pos[k], line);
                        switch (asmToken2)
                        {
                        case "$":
                        case "@B":
                        case "@F":
                        {
                            // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc.
                            break;
                        }

                        case "WORD":
                        case "DWORD":
                        case "QWORD":
                        case "SHORT":
                        case "NEAR":
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._misc));

                            k++;
                            if (k == nKeywords)
                            {
                                break;
                            }
                            string asmToken3 = NasmIntelTokenTagger.Keyword(pos[k], line);
                            switch (asmToken3)
                            {
                            case "$":
                            case "@B":
                            case "@F":
                            {
                                // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc.
                                break;
                            }

                            case "PTR":
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._misc));

                                break;
                            }

                            default:
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), Make_AsmTokenTag_Label(containingLine.LineNumber)));

                                break;
                            }
                            }
                            break;
                        }

                        default:
                        {
                            if (RegisterTools.IsRegister(asmToken2))
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._register));
                            }
                            else
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), Make_AsmTokenTag_Label(containingLine.LineNumber)));
                            }
                            break;
                        }
                        }
                        break;
                    }

                    case AsmTokenType.UNKNOWN:     // asmToken is not a known keyword, check if it is numerical
                    {
                        if (AsmTools.AsmSourceTools.Evaluate_Constant(asmToken, true).Valid)
                        //if (AsmTools.AsmSourceTools.Parse_Constant(asmToken, true).Valid)
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._constant));
                        }
                        else if (asmToken.StartsWith("\"") && asmToken.EndsWith("\""))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._constant));
                        }
                        else
                        {
                            bool isUnknown = true;

                            // do one word lookahead; see whether we can understand the current unknown word
                            if ((k + 1) < nKeywords)
                            {
                                k++;
                                string nextKeyword = NasmIntelTokenTagger.Keyword(pos[k], line);
                                switch (nextKeyword)
                                {
                                case "PROC":
                                case "EQU":
                                case "LABEL":
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k - 1], offset, curSpan), this._labelDef));

                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._directive));

                                    isUnknown = false;
                                    break;
                                }

                                case "PROTO":
                                {                 // a proto is considered a label definition but it should not clash with other label definitions
                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k - 1], offset, curSpan), this._labelDef_PROTO));

                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._directive));

                                    isUnknown = false;
                                    break;
                                }

                                default:
                                {
                                    k--;
                                    break;
                                }
                                }
                            }

                            // do one word look back; see whether we can understand the current unknown word
                            if (k > 0)
                            {
                                string previousKeyword = NasmIntelTokenTagger.Keyword(pos[k - 1], line);
                                switch (previousKeyword)
                                {
                                case "ALIAS":
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._labelDef));

                                    isUnknown = false;
                                    break;
                                }

                                case "INCLUDE":
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._constant));

                                    isUnknown = false;
                                    break;
                                }

                                default:
                                {
                                    break;
                                }
                                }
                            }

                            if (isUnknown)
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._UNKNOWN));
                            }
                        }
                        break;
                    }

                    case AsmTokenType.Directive:
                    {
                        AssemblerEnum assember = this._asmDudeTools.Get_Assembler(asmToken);
                        if (assember.HasFlag(AssemblerEnum.MASM))         // this MASM token-tagger only tags MASM directives
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._directive));

                            switch (asmToken)
                            {
                            case "INVOKE":
                            {
                                k++;                 // goto the next word
                                if (k == nKeywords)
                                {
                                    break;
                                }

                                string asmToken2 = NasmIntelTokenTagger.Keyword(pos[k], line);
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), Make_AsmTokenTag_Label(containingLine.LineNumber)));

                                break;
                            }

                            case "EXTRN":
                            case "EXTERN":
                            {
                                k++;                 // goto the next word
                                if (k == nKeywords)
                                {
                                    break;
                                }

                                string asmToken2 = NasmIntelTokenTagger.Keyword(pos[k], line);
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._labelDef_PROTO));

                                break;
                            }
                            }
                        }
                    }
                    break;

                    default:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), new AsmTokenTag(keywordType)));

                        break;
                    }
                    }
                }
            }
            AsmDudeToolsStatic.Print_Speed_Warning(time1, "MasmTokenTagger");
        }
예제 #21
0
        static char[] splitChars = { ' ', ',', '\t', '+', '-', '*', '[', ']' }; //TODO remove this to AsmDudeTools

        internal AsmTokenTagger(ITextBuffer buffer)
        {
            this._buffer = buffer;
            AsmDudeToolsStatic.getCompositionContainer().SatisfyImportsOnce(this);
        }
예제 #22
0
 public AsmDudePackage()
 {
     Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "=========================================\nINFO: AsmDudePackage: Entering constructor"));
     AsmDudeToolsStatic.Output_INFO("AsmDudePackage: Entering constructor");
 }
예제 #23
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);
        }
예제 #24
0
        private void Init_Data()
        {
            this.type_        = new Dictionary <string, AsmTokenType>();
            this.arch_        = new Dictionary <string, Arch>();
            this.assembler_   = new Dictionary <string, AssemblerEnum>();
            this.description_ = new Dictionary <string, string>();
            // fill the dictionary with keywords
            XmlDocument xmlDoc = this.Get_Xml_Data();

            foreach (XmlNode node in xmlDoc.SelectNodes("//misc"))
            {
                XmlAttribute nameAttribute = node.Attributes["name"];
                if (nameAttribute == null)
                {
                    AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found misc with no name");
                }
                else
                {
                    string name = nameAttribute.Value.ToUpperInvariant();
                    this.type_[name]        = AsmTokenType.Misc;
                    this.arch_[name]        = Retrieve_Arch(node);
                    this.description_[name] = Retrieve_Description(node);
                }
            }

            foreach (XmlNode node in xmlDoc.SelectNodes("//directive"))
            {
                XmlAttribute nameAttribute = node.Attributes["name"];
                if (nameAttribute == null)
                {
                    AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found directive with no name");
                }
                else
                {
                    string name = nameAttribute.Value.ToUpperInvariant();
                    this.type_[name]        = AsmTokenType.Directive;
                    this.arch_[name]        = Retrieve_Arch(node);
                    this.assembler_[name]   = Retrieve_Assembler(node);
                    this.description_[name] = Retrieve_Description(node);
                }
            }
            foreach (XmlNode node in xmlDoc.SelectNodes("//register"))
            {
                XmlAttribute nameAttribute = node.Attributes["name"];
                if (nameAttribute == null)
                {
                    AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found register with no name");
                }
                else
                {
                    string name = nameAttribute.Value.ToUpperInvariant();
                    //this._type[name] = AsmTokenType.Register;
                    this.arch_[name]        = Retrieve_Arch(node);
                    this.description_[name] = Retrieve_Description(node);
                }
            }
            foreach (XmlNode node in xmlDoc.SelectNodes("//userdefined1"))
            {
                XmlAttribute nameAttribute = node.Attributes["name"];
                if (nameAttribute == null)
                {
                    AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found userdefined1 with no name");
                }
                else
                {
                    string name = nameAttribute.Value.ToUpperInvariant();
                    this.type_[name]        = AsmTokenType.UserDefined1;
                    this.description_[name] = Retrieve_Description(node);
                }
            }
            foreach (XmlNode node in xmlDoc.SelectNodes("//userdefined2"))
            {
                XmlAttribute nameAttribute = node.Attributes["name"];
                if (nameAttribute == null)
                {
                    AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found userdefined2 with no name");
                }
                else
                {
                    string name = nameAttribute.Value.ToUpperInvariant();
                    this.type_[name]        = AsmTokenType.UserDefined2;
                    this.description_[name] = Retrieve_Description(node);
                }
            }
            foreach (XmlNode node in xmlDoc.SelectNodes("//userdefined3"))
            {
                XmlAttribute nameAttribute = node.Attributes["name"];
                if (nameAttribute == null)
                {
                    AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found userdefined3 with no name");
                }
                else
                {
                    string name = nameAttribute.Value.ToUpperInvariant();
                    this.type_[name]        = AsmTokenType.UserDefined3;
                    this.description_[name] = Retrieve_Description(node);
                }
            }
        }
예제 #25
0
 /// <summary>
 /// Get all labels with context info containing in the provided text
 /// </summary>
 public static IDictionary <string, string> getLabels(ITextBuffer text)
 {
     return(AsmDudeToolsStatic.getLabels(text.CurrentSnapshot.GetText()));
 }
예제 #26
0
        /// <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

            //this._errorListProvider = new ErrorListProvider(new ServiceProvider(Package.GetGlobalService(typeof(Microsoft.VisualStudio.OLE.Interop.IServiceProvider)) as Microsoft.VisualStudio.OLE.Interop.IServiceProvider))
            //{
            //    ProviderName = "Asm Errors",
            //    ProviderGuid = new Guid(EnvDTE.Constants.vsViewKindCode),
            //};

            IServiceProvider a = Package.GetGlobalService(typeof(System.IServiceProvider)) as IServiceProvider;

            this.errorListProvider_ = new ErrorListProvider(a)
            {
                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 (string.IsNullOrEmpty(e.Arch_Str))
                        {
                            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();
                    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
        }
예제 #27
0
        private void initData()
        {
            this._type        = new Dictionary <string, TokenType>();
            this._arch        = new Dictionary <string, Arch>();
            this._description = new Dictionary <string, string>();

            // fill the dictionary with keywords
            AsmDudeToolsStatic.getCompositionContainer().SatisfyImportsOnce(this);
            XmlDocument xmlDoc = this.getXmlData();

            foreach (XmlNode node in xmlDoc.SelectNodes("//misc"))
            {
                var nameAttribute = node.Attributes["name"];
                if (nameAttribute == null)
                {
                    Debug.WriteLine("WARNING: AsmTokenTagger: found misc with no name");
                }
                else
                {
                    string name = nameAttribute.Value.ToUpper();
                    //Debug.WriteLine("INFO: AsmTokenTagger: found misc " + name);
                    this._type[name]        = TokenType.Misc;
                    this._arch[name]        = this.retrieveArch(node);
                    this._description[name] = retrieveDescription(node);
                }
            }

            foreach (XmlNode node in xmlDoc.SelectNodes("//directive"))
            {
                var nameAttribute = node.Attributes["name"];
                if (nameAttribute == null)
                {
                    Debug.WriteLine("WARNING: AsmTokenTagger: found directive with no name");
                }
                else
                {
                    string name = nameAttribute.Value.ToUpper();
                    //Debug.WriteLine("INFO: AsmTokenTagger: found directive " + name);
                    this._type[name]        = TokenType.Directive;
                    this._arch[name]        = this.retrieveArch(node);
                    this._description[name] = retrieveDescription(node);
                }
            }
            foreach (XmlNode node in xmlDoc.SelectNodes("//mnemonic"))
            {
                var nameAttribute = node.Attributes["name"];
                if (nameAttribute == null)
                {
                    Debug.WriteLine("WARNING: AsmTokenTagger: found mnemonic with no name");
                }
                else
                {
                    string name = nameAttribute.Value.ToUpper();
                    //Debug.WriteLine("INFO: AsmTokenTagger: found mnemonic " + name);

                    var typeAttribute = node.Attributes["type"];
                    if (typeAttribute == null)
                    {
                        this._type[name] = TokenType.Mnemonic;
                    }
                    else
                    {
                        if (typeAttribute.Value.ToUpper().Equals("JUMP"))
                        {
                            this._type[name] = TokenType.Jump;
                        }
                        else
                        {
                            this._type[name] = TokenType.Mnemonic;
                        }
                    }
                    this._arch[name]        = this.retrieveArch(node);
                    this._description[name] = retrieveDescription(node);
                }
            }
            foreach (XmlNode node in xmlDoc.SelectNodes("//register"))
            {
                var nameAttribute = node.Attributes["name"];
                if (nameAttribute == null)
                {
                    Debug.WriteLine("WARNING: AsmTokenTagger: found register with no name");
                }
                else
                {
                    string name = nameAttribute.Value.ToUpper();
                    //Debug.WriteLine("INFO: AsmTokenTagger: found register " + name);
                    this._type[name]        = TokenType.Register;
                    this._arch[name]        = this.retrieveArch(node);
                    this._description[name] = retrieveDescription(node);
                }
            }
        }
 public LabelDefP()
 {
     DisplayName     = "AsmDude - Syntax Highlighting - Label Definition"; //human readable version of the name found in Tools>Options>Environment>Fonts and Colors>Text Editor
     ForegroundColor = AsmDudeToolsStatic.convertColor(Settings.Default.SyntaxHighlighting_Label);
     //TextDecorations = System.Windows.TextDecorations.Underline;
 }
예제 #29
0
        public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            DateTime time1 = DateTime.Now;

            if (spans.Count == 0)
            { //there is no content in the buffer
                yield break;
            }

            foreach (SnapshotSpan curSpan in spans)
            {
                ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine();

                string line_upcase = containingLine.GetText().ToUpperInvariant();
                List <(int beginPos, int length, bool isLabel)> pos = new List <(int beginPos, int length, bool isLabel)>(AsmSourceTools.SplitIntoKeywordPos(line_upcase));

                int offset    = containingLine.Start.Position;
                int nKeywords = pos.Count;

                for (int k = 0; k < nKeywords; k++)
                {
                    string asmToken = AsmSourceTools.Keyword(pos[k], line_upcase);

                    // keyword starts with a remark char
                    if (AsmSourceTools.IsRemarkChar(asmToken[0]))
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.remark_));

                        continue;
                    }

                    // keyword k is a label definition
                    if (pos[k].isLabel)
                    {
                        //AsmDudeToolsStatic.Output_INFO("NasmTokenTagger:GetTags: found label " +asmToken);
                        if (this.IsProperLabelDef(asmToken, containingLine.LineNumber, out AsmTokenTag asmTokenTag))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), asmTokenTag));

                            continue;
                        }
                    }
                    AsmTokenType keywordType = this.asmDudeTools_.Get_Token_Type_Att(asmToken);
                    switch (keywordType)
                    {
                    case AsmTokenType.Jump:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.jump_));

                        k++;         // goto the next word
                        if (k == nKeywords)
                        {
                            break;         // there are no next words
                            //TODO HJ 01-06-19 should be a warning that there is no label
                        }

                        string asmToken2 = AsmSourceTools.Keyword(pos[k], line_upcase);

                        if (AsmSourceTools.IsRemarkChar(asmToken2[0]))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.remark_));

                            continue;
                            //TODO HJ 01-06-19 should be a warning that there is no label
                        }

                        switch (asmToken2)
                        {
                        case "WORD":
                        case "DWORD":
                        case "QWORD":
                        case "SHORT":
                        case "NEAR":
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.misc_));

                            k++;
                            if (k == nKeywords)
                            {
                                break;
                            }

                            string asmToken3 = AsmSourceTools.Keyword(pos[k], line_upcase);
                            if (asmToken3.Equals("PTR", StringComparison.Ordinal))
                            {
                                yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this.misc_));
                            }
                            else
                            {
                                if (this.IsProperLabel(asmToken3, containingLine.LineNumber, out AsmTokenTag asmTokenTag))
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), asmTokenTag));
                                }
                            }
                            break;
                        }

                        default:
                        {
                            if (RegisterTools.IsRegister(asmToken2, true))
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.register_));
                            }
                            else if (AsmSourceTools.Evaluate_Constant(asmToken2, true).valid)
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_));
                            }
                            else if (this.IsProperLabel(asmToken2, containingLine.LineNumber, out AsmTokenTag asmTokenTag))
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), asmTokenTag));
                            }
                            break;
                        }
                        }
                        break;
                    }

                    case AsmTokenType.UNKNOWN:     // asmToken is not a known keyword, check if it is numerical
                    {
                        if (AsmSourceTools.Evaluate_Constant(asmToken, true).valid)
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_));
                        }
                        else if (asmToken.StartsWith("\"", StringComparison.Ordinal) && asmToken.EndsWith("\"", StringComparison.Ordinal))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_));
                        }
                        else if (asmToken.StartsWith("$", StringComparison.Ordinal))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset + 1, curSpan), this.constant_));
                        }
                        else
                        {
                            bool isUnknown = true;

                            // do one word lookahead; see whether we can understand the current unknown word
                            if ((k + 1) < nKeywords)
                            {
                                k++;
                                string nextKeyword = AsmSourceTools.Keyword(pos[k], line_upcase);
                                switch (nextKeyword)
                                {
                                case "LABEL":
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k - 1], offset, curSpan), this.labelDef_));

                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.directive_));

                                    isUnknown = false;
                                    break;
                                }

                                default:
                                {
                                    k--;
                                    break;
                                }
                                }
                            }

                            // do one word look back; see whether we can understand the current unknown word
                            if (k > 0)
                            {
                                string previousKeyword = AsmSourceTools.Keyword(pos[k - 1], line_upcase);
                                switch (previousKeyword)
                                {
                                case "ALIAS":
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.labelDef_));

                                    isUnknown = false;
                                    break;
                                }

                                case "INCLUDE":
                                {
                                    yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_));

                                    isUnknown = false;
                                    break;
                                }

                                default:
                                {
                                    break;
                                }
                                }
                            }
                            if (isUnknown)
                            {
                                yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.UNKNOWN_));
                            }
                        }
                        break;
                    }

                    case AsmTokenType.Directive:
                    {
                        AssemblerEnum assember = this.asmDudeTools_.Get_Assembler(asmToken);
                        if (assember.HasFlag(AssemblerEnum.NASM_INTEL) || assember.HasFlag(AssemblerEnum.NASM_ATT))
                        {
                            yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.directive_));
                        }
                        break;
                    }

                    default:
                    {
                        yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), new AsmTokenTag(keywordType)));

                        break;
                    }
                    }
                }
            }
            AsmDudeToolsStatic.Print_Speed_Warning(time1, "NasmAttTokenTagger");
        }
예제 #30
0
 public RemarkP()
 {
     DisplayName     = "remark"; //human readable version of the name
     ForegroundColor = AsmDudeToolsStatic.convertColor(Settings.Default.SyntaxHighlighting_Remark);
     IsItalic        = true;
 }