Пример #1
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    = Keyword(pos[k], line);
                    AsmTokenType keywordType = this._asmDudeTools.Get_Token_Type(asmToken);
                    if ((keywordType == AsmTokenType.Mnemonic) ||
                        (keywordType == AsmTokenType.Jump))
                    {
                        yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), new AsmTokenTag(keywordType)));
                    }
                }
            }
            AsmDudeToolsStatic.Print_Speed_Warning(time1, "DebugTokenTagger");
        }
Пример #2
0
        public override void PreprocessMouseUp(MouseButtonEventArgs e)
        {
            if (Settings.Default.AsmDoc_On)
            {
                try
                {
                    if (this.mouseDownAnchorPoint_.HasValue && this.state_.Enabled)
                    {
                        Point currentMousePosition = this.RelativeToView(e.GetPosition(this.view_.VisualElement));

                        if (!this.InDragOperation(this.mouseDownAnchorPoint_.Value, currentMousePosition))
                        {
                            this.state_.Enabled = false;

                            ITextViewLine line           = this.view_.TextViewLines.GetTextViewLineContainingYCoordinate(currentMousePosition.Y);
                            SnapshotPoint?bufferPosition = line.GetBufferPositionFromXCoordinate(currentMousePosition.X);
                            string        keyword        = AsmDudeToolsStatic.Get_Keyword_Str(bufferPosition);
                            if (keyword != null)
                            {
                                (Mnemonic mnemonic, AttType type) = AsmSourceTools.ParseMnemonic_Att(keyword, false);
                                System.Runtime.CompilerServices.ConfiguredTaskAwaitable <bool> result = this.Dispatch_Goto_DocAsync(mnemonic).ConfigureAwait(false); // use .ConfigureAwait(false) to signal your intention for continuation.
                            }
                            this.Set_Highlight_Span(null);
                            this.view_.Selection.Clear();
                            e.Handled = true;
                        }
                    }
                    this.mouseDownAnchorPoint_ = null;
                }
                catch (Exception ex)
                {
                    AsmDudeToolsStatic.Output_ERROR(string.Format(AsmDudeToolsStatic.CultureUI, "{0} PreprocessMouseUp; e={1}", this.ToString(), ex.ToString()));
                }
            }
        }
Пример #3
0
        /// <summary>Perform onestep forward and return the state of the regular branch</summary>
        public static State SimpleStep_Backward(string line, State state)
        {
            string prevKey = Tools.CreateKey(state.Tools.Rand);
            var    content = AsmSourceTools.ParseLine(line);

            using (var opcodeBase = Runner.InstantiateOpcode(content.Mnemonic, content.Args, (prevKey, state.TailKey, state.TailKey), state.Tools))
            {
                if (opcodeBase == null)
                {
                    return(null);
                }
                if (opcodeBase.IsHalted)
                {
                    return(null);
                }

                opcodeBase.Execute();
                State stateOut = new State(state);
                stateOut.Update_Backward(opcodeBase.Updates.Regular, prevKey);

                opcodeBase.Updates.Regular?.Dispose();
                opcodeBase.Updates.Branch?.Dispose();

                if (!state.Tools.Quiet)
                {
                    Console.WriteLine("INFO: Runner:SimpleStep_Backward: after \"" + line + "\" we know:");
                }
                if (!state.Tools.Quiet)
                {
                    Console.WriteLine(stateOut);
                }
                return(stateOut);
            }
        }
Пример #4
0
        public void Test_AsmSourceTools_splitIntoKeywordsPos()
        {
            {
                const string line = "    db \"This string contains the word jmp inside of it\",0";

                IList <(int, int, bool)> result = new List <(int, int, bool)>(AsmSourceTools.SplitIntoKeywordPos(line));
                for (int i = 0; i < result.Count; ++i)
                {
                    Console.WriteLine(line.Substring(result[i].Item1, result[i].Item2 - result[i].Item1));
                }
                Assert.AreEqual(3, result.Count);
                Assert.AreEqual("db", line.Substring(result[0].Item1, result[0].Item2 - result[0].Item1));
                Assert.AreEqual("\"This string contains the word jmp inside of it\"", line.Substring(result[1].Item1, result[1].Item2 - result[1].Item1));
                Assert.AreEqual("0", line.Substring(result[2].Item1, result[2].Item2 - result[2].Item1));
            }
            {
                const string line = "	call		??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z";

                IList <(int, int, bool)> result = new List <(int, int, bool)>(AsmSourceTools.SplitIntoKeywordPos(line));
                for (int i = 0; i < result.Count; ++i)
                {
                    Console.WriteLine(line.Substring(result[i].Item1, result[i].Item2 - result[i].Item1));
                }
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual("call", line.Substring(result[0].Item1, result[0].Item2 - result[0].Item1));
                Assert.AreEqual("??$?6U?$char_traits@D@std@@@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@PEBD@Z", line.Substring(result[1].Item1, result[1].Item2 - result[1].Item1));
            }
        }
Пример #5
0
        /// <summary>Guess whether the provided buffer has assembly in Masm syntax (return true) or Gas syntax (return false)</summary>
        public static bool Guess_Masm_Syntax(ITextBuffer buffer, int nLinesMax = 30)
        {
            //AsmDudeToolsStatic.Output_INFO(string.Format("{0}:Guess_Masm_Syntax. file=\"{1}\"", "AsmDudeToolsStatic", AsmDudeToolsStatic.GetFilename(buffer)));
            ITextSnapshot snapshot      = buffer.CurrentSnapshot;
            int           evidence_masm = 0;

            for (int i = 0; i < Math.Min(snapshot.LineCount, nLinesMax); ++i)
            {
                string line_capitals = snapshot.GetLineFromLineNumber(i).GetText().ToUpper();
                //AsmDudeToolsStatic.Output_INFO(string.Format("{0}:Guess_Masm_Syntax {1}:\"{2}\"", "AsmDudeToolsStatic", i, line_capitals));

                List <string> keywords = AsmSourceTools.SplitIntoKeywordsList(line_capitals);

                foreach (string word in keywords)
                {
                    switch (word)
                    {
                    case "PTR":
                    case "@B":
                    case "@F":
                        evidence_masm++;
                        break;

                    case ".INTEL_SYNTAX":
                    case ".ATT_SYNTAX":
                        return(false);    // we know for sure
                    }
                }
            }
            bool result = (evidence_masm > 0);

            AsmDudeToolsStatic.Output_INFO(string.Format("{0}:Guess_Masm_Syntax; result {1}; file=\"{2}\"; evidence_masm {3}", "AsmDudeToolsStatic", result, AsmDudeToolsStatic.GetFilename(buffer), evidence_masm));
            return(result);
        }
        public void SetDescription(Rn reg, AsmDudeTools asmDudeTools)
        {
            string regStr = reg.ToString();

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

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

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

            this.Description.Inlines.Add(new Run(full_Descr)
            {
                Foreground = this._foreground
            });
        }
Пример #7
0
 public void Test_AsmSourceTools_parseMnemonic()
 {
     foreach (Mnemonic x in Enum.GetValues(typeof(Mnemonic)))
     {
         Assert.AreEqual(AsmSourceTools.ParseMnemonic(x.ToString(), true), x,
                         "Parsing string " + x.ToString() + " does not yield the same enumeration.");
     }
 }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                SnapshotPoint currentPoint = this._textView.Caret.Position.BufferPosition;
                if ((currentPoint != null) && (currentPoint > 0))
                {
                    SnapshotPoint point = currentPoint - 1;
                    if (point.Position > 1)
                    {
                        ITextSnapshotLine line    = point.Snapshot.GetLineFromPosition(point.Position);
                        string            lineStr = line.GetText();

                        int pos = point.Position - line.Start;
                        if (!AsmSourceTools.IsInRemark(pos, lineStr))
                        { //check if current position is in a remark; if we are in a remark, no signature help
                            if ((pguidCmdGroup == VSConstants.VSStd2K) && (nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR))
                            {
                                char typedChar = this.GetTypeChar(pvaIn);
                                if (char.IsWhiteSpace(typedChar) || typedChar.Equals(','))
                                {
                                    (string Label, Mnemonic Mnemonic, string[] Args, string Remark)t = AsmSourceTools.ParseLine(lineStr);
                                    if (this._session != null)
                                    {
                                        this._session.Dismiss(); // cleanup previous session
                                    }

                                    if (t.Mnemonic != Mnemonic.NONE)
                                    {
                                        this._session = this._broker.TriggerSignatureHelp(this._textView);
                                    }
                                }
                                else if (AsmSourceTools.IsRemarkChar(typedChar) && (this._session != null))
                                {
                                    this._session.Dismiss();
                                    this._session = null;
                                }
                            }
                            else
                            {
                                bool enterPressed = nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN;
                                if (enterPressed && (this._session != null))
                                {
                                    this._session.Dismiss();
                                    this._session = null;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR(string.Format("{0}:Exec; e={1}", this.ToString(), e.ToString()));
            }
            return(this._nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Пример #9
0
        public void AddData(MicroArch microArch, string filename)
        {
            AsmDudeToolsStatic.Output_INFO("PerformanceStore:AddData: microArch=" + microArch + "; filename=" + filename);
            try
            {
                System.IO.StreamReader file = new System.IO.StreamReader(filename);
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    if ((line.Trim().Length > 0) && (!line.StartsWith(";")))
                    {
                        string[] columns = line.Split('\t');
                        if (columns.Length == 5)
                        {
                            { // handle instruction
                                foreach (string mnemonicStr in columns[0].Split(' '))
                                {
                                    if (mnemonicStr.Length > 0)
                                    {
                                        Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(mnemonicStr);
                                        if (mnemonic == Mnemonic.UNKNOWN)
                                        {
                                            AsmDudeToolsStatic.Output_WARNING("PerformanceStore:LoadData: microArch=" + microArch + ": unknown mnemonic " + mnemonicStr + " in line: " + line);
                                        }
                                        else
                                        {
                                            PerformanceItem item = new PerformanceItem();
                                            item._microArch  = microArch;
                                            item._instr      = mnemonic;
                                            item._args       = columns[1];
                                            item._latency    = columns[2];
                                            item._throughput = columns[3];
                                            item._remark     = columns[4];

                                            this._data.Add(item);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            AsmDudeToolsStatic.Output_WARNING("PerformanceStore:AddData: found " + columns.Length + " columns; funky line" + line);
                        }
                    }
                }
                file.Close();
            }
            catch (FileNotFoundException)
            {
                AsmDudeToolsStatic.Output_ERROR("PerformanceStore:LoadData: could not find file \"" + filename + "\".");
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR("PerformanceStore:LoadData: error while reading file \"" + filename + "\"." + e);
            }
        }
Пример #10
0
        public void Test_AsmSourceTools_Get_Related_Constant()
        {
            int nBits = 64;

            ulong  value    = 3352562;
            string original = value.ToString(Culture);
            string related  = AsmSourceTools.Get_Related_Constant(original, value, nBits);

            Console.WriteLine(related);
        }
Пример #11
0
        private IDictionary <string, IList <Mnemonic> > Load_Instruction_Translation(string filename)
        {
            IDictionary <string, IList <Mnemonic> > translations = new Dictionary <string, IList <Mnemonic> >();

            try
            {
                StreamReader file = new StreamReader(filename);
                string       line;
                while ((line = file.ReadLine()) != null)
                {
                    if ((line.Trim().Length > 0) && (!line.StartsWith(";")))
                    {
                        string[] columns = line.Split('\t');
                        if (columns.Length == 2)
                        {
                            string key = columns[0].Trim();

                            IList <Mnemonic> values = new List <Mnemonic>();
                            foreach (string mnemonicStr in columns[1].Trim().Split(' '))
                            {
                                Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(mnemonicStr);
                                if (mnemonic == Mnemonic.NONE)
                                {
                                    AsmDudeToolsStatic.Output_WARNING("PerformanceStore:Load_Instruction_Translation: key=" + columns[0] + ": unknown mnemonic " + mnemonicStr + " in line: " + line);
                                }
                                else
                                {
                                    values.Add(mnemonic);
                                }
                            }
                            //AsmDudeToolsStatic.Output_INFO("PerformanceStore:Load_Instruction_Translation: key=" + key + " = " + String.Join(",", values));
                            if (translations.ContainsKey(key))
                            {
                                AsmDudeToolsStatic.Output_WARNING("PerformanceStore:Load_Instruction_Translation: key=" + key + " in line: " + line + " already used");
                            }
                            else
                            {
                                translations.Add(key, values);
                            }
                        }
                    }
                }
                file.Close();
            }
            catch (FileNotFoundException)
            {
                AsmDudeToolsStatic.Output_ERROR("PerformanceStore:Load_Instruction_Translation: could not find file \"" + filename + "\".");
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR("PerformanceStore:Load_Instruction_Translation: error while reading file \"" + filename + "\"." + e);
            }
            return(translations);
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            try {
                SnapshotPoint currentPoint = _textView.Caret.Position.BufferPosition;
                if ((currentPoint != null) && (currentPoint > 0))
                {
                    SnapshotPoint point = currentPoint - 1;
                    if (point.Position > 1)
                    {
                        ITextSnapshotLine line    = point.Snapshot.GetLineFromPosition(point.Position);
                        string            lineStr = line.GetText();

                        int pos = point.Position - line.Start;
                        if (!AsmSourceTools.isInRemark(pos, lineStr))   //check if current position is in a remark; if we are in a remark, no signature help

                        {
                            if ((pguidCmdGroup == VSConstants.VSStd2K) && (nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR))
                            {
                                char typedChar = this.GetTypeChar(pvaIn);
                                if (char.IsWhiteSpace(typedChar) || typedChar.Equals(','))
                                {
                                    var t = AsmSourceTools.parseLine(lineStr);
                                    if (this._session != null)
                                    {
                                        this._session.Dismiss();                        // cleanup previous session
                                    }
                                    if (t.Item2 != Mnemonic.UNKNOWN)
                                    {
                                        this._session = _broker.TriggerSignatureHelp(_textView);
                                    }
                                }
                                else if (AsmSourceTools.isRemarkChar(typedChar) && (this._session != null))
                                {
                                    this._session.Dismiss();
                                    this._session = null;
                                }
                            }
                            else
                            {
                                bool enterPressed = (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN);
                                if (enterPressed && (this._session != null))
                                {
                                    this._session.Dismiss();
                                    this._session = null;
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                AsmDudeToolsStatic.Output(string.Format("ERROR: {0}:Exec; e={1}", this.ToString(), e.ToString()));
            }
            return(_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Пример #13
0
 public void Test_AsmSourceTools_OperandType()
 {
     foreach (Ot1 x1 in Enum.GetValues(typeof(Ot1)))
     {
         foreach (Ot1 x2 in Enum.GetValues(typeof(Ot1)))
         {
             (Ot1, Ot1)t = AsmSourceTools.SplitOt(AsmSourceTools.MergeOt(x1, x2));
             Assert.AreEqual(t.Item1, x1, string.Empty);
             Assert.AreEqual(t.Item2, x2, string.Empty);
         }
     }
 }
Пример #14
0
 private AssemblerEnum Retrieve_Assembler(XmlNode node)
 {
     try
     {
         XmlAttribute archAttribute = node.Attributes["tool"];
         return((archAttribute == null) ? AssemblerEnum.UNKNOWN : AsmSourceTools.ParseAssembler(archAttribute.Value));
     }
     catch (Exception)
     {
         return(AssemblerEnum.UNKNOWN);
     }
 }
Пример #15
0
 public void Test_AsmSourceTools_OperandType()
 {
     foreach (Ot x1 in Enum.GetValues(typeof(Ot)))
     {
         foreach (Ot x2 in Enum.GetValues(typeof(Ot)))
         {
             Tuple <Ot, Ot> t = AsmSourceTools.splitOt(AsmSourceTools.mergeOt(x1, x2));
             Assert.AreEqual(t.Item1, x1, "");
             Assert.AreEqual(t.Item2, x2, "");
         }
     }
 }
Пример #16
0
        /// <summary>Perform one step forward and return the regular branch</summary>
        public static State SimpleStep_Forward(string line, State state)
        {
            if (state == null)
            {
                Console.WriteLine("WARNING: Runner:SimpleStep_Forward: provided state is null");
                return(null);
            }
            try
            {
                Tools  tools         = state.Tools;
                string nextKey       = Tools.CreateKey(tools.Rand);
                string nextKeyBranch = "DUMMY_NOT_USED";
                (string label, Mnemonic mnemonic, string[] args, string remark) = AsmSourceTools.ParseLine(line);
                using (OpcodeBase opcodeBase = InstantiateOpcode(mnemonic, args, (state.HeadKey, nextKey, nextKeyBranch), tools))
                {
                    if (opcodeBase == null)
                    {
                        return(null);
                    }

                    if (opcodeBase.IsHalted)
                    {
                        Console.WriteLine("WARNING: Runner:SimpleStep_Forward: line: " + line + " is halted. Message: " + opcodeBase.SyntaxError);
                        return(null);
                    }
                    opcodeBase.Execute();
                    State stateOut = new State(state);
                    stateOut.Update_Forward(opcodeBase.Updates.regular);
                    stateOut.Frozen = true;

                    opcodeBase.Updates.regular?.Dispose();
                    opcodeBase.Updates.branch?.Dispose();

                    if (!tools.Quiet)
                    {
                        Console.WriteLine("INFO: Runner:SimpleStep_Forward: after \"" + line + "\" we know:");
                    }

                    if (!tools.Quiet)
                    {
                        Console.WriteLine(stateOut);
                    }

                    return(stateOut);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("WARNING: Runner:SimpleStep_Forward: Exception at line: " + line + "; e=" + e.Message);
                return(new State(state));
            }
        }
Пример #17
0
        /// <summary>
        /// Find the previous keyword (if any) that exists BEFORE the provided triggerPoint, and the provided start.
        /// Eg. qqqq xxxxxx yyyyyyy zzzzzz
        ///     ^             ^
        ///     |begin        |end
        /// the previous keyword is xxxxxx
        /// </summary>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public static string getPreviousKeyword(SnapshotPoint begin, SnapshotPoint end)
        {
            // return getPreviousKeyword(begin.GetContainingLine.)
            if (end == 0)
            {
                return("");
            }

            int beginLine = begin.GetContainingLine().Start;
            int beginPos  = begin.Position - beginLine;
            int endPos    = end.Position - beginLine;

            return(AsmSourceTools.getPreviousKeyword(beginPos, endPos, begin.GetContainingLine().GetText()));
        }
Пример #18
0
 public void Test_AsmSourceTools_GetPreviousKeyword()
 {
     const string line = "    mov rax, rbx;bla";
     {
         int    begin  = 0;
         int    end    = 8;
         string result = AsmSourceTools.GetPreviousKeyword(begin, end, line);
         string msg    = "line=\"" + line + "\"; result=\"" + result + "\"; begin=" + begin + "; end=" + end;
         Assert.AreEqual("mov", result, msg);
     }
     {
         int    begin  = 4;
         int    end    = 8;
         string result = AsmSourceTools.GetPreviousKeyword(begin, end, line);
         string msg    = "line=\"" + line + "\"; result=\"" + result + "\"; begin=" + begin + "; end=" + end;
         Assert.AreEqual("mov", result, msg);
     }
     {
         int    begin  = 5;
         int    end    = 8;
         string result = AsmSourceTools.GetPreviousKeyword(begin, end, line);
         string msg    = "line=\"" + line + "\"; result=\"" + result + "\"; begin=" + begin + "; end=" + end;
         Assert.AreEqual("ov", result, msg);
     }
     {
         int    begin  = 0;
         int    end    = 7;
         string result = AsmSourceTools.GetPreviousKeyword(begin, end, line);
         string msg    = "line=\"" + line + "\"; result=\"" + result + "\"; begin=" + begin + "; end=" + end;
         Assert.AreEqual("mov", result, msg);
     }
     {
         int    begin  = 0;
         int    end    = 6;
         string result = AsmSourceTools.GetPreviousKeyword(begin, end, line);
         string msg    = "line=\"" + line + "\"; result=\"" + result + "\"; begin=" + begin + "; end=" + end;
         Assert.AreEqual(string.Empty, result, msg);
     }
     {
         int    begin  = 0;
         int    end    = 11;
         string result = AsmSourceTools.GetPreviousKeyword(begin, end, line);
         string msg    = "line=\"" + line + "\"; result=\"" + result + "\"; begin=" + begin + "; end=" + end;
         Assert.AreEqual("rax", result, msg);
     }
 }
Пример #19
0
        static Tuple <Mnemonic, List <IformRegister>, int, bool, float, float> ParseLine(string line)
        {
            var x = line.Split(',');

            if (x.Length != 5)
            {
                Console.WriteLine("ERROR: could not parse " + line);
            }
            var      y        = x[0].Split('_');
            Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(y[0], true);

            List <IformRegister> args = new List <IformRegister>();

            for (int i = 1; i < y.Length; ++i)
            {
                var z = ParseIformRegister(y[i], false);

                if (z == IformRegister.UNKNOWN)
                {
                    //Console.WriteLine("WARNING: could not parse " + line);
                }
                else if (z == IformRegister.IGNORE)
                {
                }
                else
                {
                    args.Add(z);
                }
            }

            int n_bits = -1;

            Int32.TryParse(x[1], out n_bits);
            bool use_mask = (x[2] == "yes");

            float throughput = -1;

            float.TryParse(x[3], out throughput);

            float latency = -1;

            float.TryParse(x[4], out latency);

            return(Tuple.Create(mnemonic, args, n_bits, use_mask, throughput, latency));
        }
Пример #20
0
        public void SetAsmSim(AsmSimulator asmSimulator, Rn reg, int lineNumber, bool isExpanded)
        {
            Contract.Requires(asmSimulator != null);

            this.asmSimulator_ = asmSimulator;
            this.lineNumber_   = lineNumber;

            bool empty = true;

            if (this.asmSimulator_.Enabled & Settings.Default.AsmSim_Show_Register_In_Register_Tooltip)
            {
                this.AsmSimGridExpander.IsExpanded     = isExpanded;
                this.AsmSimGridExpanderNumeration.Text = Settings.Default.AsmSim_Show_Register_In_Register_Tooltip_Numeration;

                this.Generate(true, reg);
                this.Generate(false, reg);
                empty = false;
            }

            this.AsmSimGridExpander.Visibility = empty ? Visibility.Collapsed : Visibility.Visible;
            this.AsmSimGridBorder.Visibility   = empty ? Visibility.Collapsed : Visibility.Visible;

            this.AsmSimGridExpanderNumeration.SelectionChanged += (sender, i) =>
            {
                string         numerationStr = ((sender as ComboBox).SelectedItem as ComboBoxItem).Content.ToString();
                NumerationEnum numeration    = AsmSourceTools.ParseNumeration(numerationStr, false);
                if (numeration == NumerationEnum.UNKNOWN)
                {
                    AsmDudeToolsStatic.Output_WARNING("SetAsmSim:smSimGridExpanderNumeration.SelectionChanged: unknown numerationStr=" + numerationStr);
                }
                //AsmDudeToolsStatic.Output_INFO("AsmSimGridExpanderNumeration:SelectionChanged: numeration="+ numeration);

                string content_before = this.asmSimulator_.Get_Register_Value_If_Already_Computed(reg, this.lineNumber_, true, numeration);
                if (content_before != null)
                {
                    this.textBox_before_.Text = content_before;
                }

                string content_after = this.asmSimulator_.Get_Register_Value_If_Already_Computed(reg, this.lineNumber_, false, numeration);
                if (content_after != null)
                {
                    this.textBox_after_.Text = content_after;
                }
            };
        }
Пример #21
0
 /// <summary>
 /// get url for the provided keyword. Returns empty string if the keyword does not exist or the keyword does not have an url.
 /// </summary>
 public string Get_Url(string keyword)
 {
     // no need to pre-process this information.
     try {
         string   keywordUpper = keyword.ToUpper();
         Mnemonic mnemonic     = AsmSourceTools.ParseMnemonic(keyword);
         if (mnemonic != Mnemonic.UNKNOWN)
         {
             string url = this.Mnemonic_Store.GetHtmlRef(mnemonic);
             //AsmDudeToolsStatic.Output(string.Format("INFO: {0}:getUrl: keyword {1}; url {2}.", this.ToString(), keyword, url));
             return(url);
         }
         return("");
     } catch (Exception e) {
         AsmDudeToolsStatic.Output(string.Format("ERROR: {0}:getUrl: exception {1}.", ToString(), e.ToString()));
         return("");
     }
 }
Пример #22
0
        public AsmTokenType Get_Token_Type_Att(string keyword)
        {
            Debug.Assert(keyword == keyword.ToUpper());
            int length = keyword.Length;

            Debug.Assert(length > 0);

            char firstChar = keyword[0];

            #region Test if keyword is a register
            if (firstChar == '%')
            {
                string keyword2 = keyword.Substring(1);
                Rn     reg      = RegisterTools.ParseRn(keyword2, true);
                if (reg != Rn.NOREG)
                {
                    if (RegisterSwitchedOn(reg))
                    {
                        return(AsmTokenType.Register);
                    }
                }
            }
            #endregion
            #region Test if keyword is an imm
            if (firstChar == '$')
            {
                return(AsmTokenType.Constant);
            }
            #endregion
            #region Test if keyword is an instruction
            {
                Mnemonic mnemonic = AsmSourceTools.ParseMnemonic_Att(keyword, true);
                if (mnemonic != Mnemonic.NONE)
                {
                    if (MnemonicSwitchedOn(mnemonic))
                    {
                        return((AsmSourceTools.IsJump(mnemonic)) ? AsmTokenType.Jump : AsmTokenType.Mnemonic);
                    }
                }
            }
            #endregion

            return((this._type.TryGetValue(keyword, out var tokenType)) ? tokenType : AsmTokenType.UNKNOWN);
        }
Пример #23
0
        public AsmTokenType Get_Token_Type_Att(string keyword)
        {
            Contract.Requires(keyword != null);
            Contract.Requires(keyword == keyword.ToUpperInvariant());

            int length = keyword.Length;

            Contract.Requires(length > 0);

            char firstChar = keyword[0];

            #region Test if keyword is a register
            if (firstChar == '%')
            {
                string keyword2 = keyword.Substring(1);
                Rn     reg      = RegisterTools.ParseRn(keyword2, true);
                if (reg != Rn.NOREG)
                {
                    return((this.RegisterSwitchedOn(reg))
                       ? AsmTokenType.Register
                       : AsmTokenType.Register); //TODO
                }
            }
            #endregion
            #region Test if keyword is an imm
            if (firstChar == '$')
            {
                return(AsmTokenType.Constant);
            }
            #endregion
            #region Test if keyword is an instruction
            {
                (Mnemonic mnemonic, AttType type) = AsmSourceTools.ParseMnemonic_Att(keyword, true);
                if (mnemonic != Mnemonic.NONE)
                {
                    return((this.MnemonicSwitchedOn(mnemonic))
                        ? AsmSourceTools.IsJump(mnemonic) ? AsmTokenType.Jump : AsmTokenType.Mnemonic
                        : AsmSourceTools.IsJump(mnemonic) ? AsmTokenType.Jump : AsmTokenType.MnemonicOff);
                }
            }
            #endregion

            return(this.type_.TryGetValue(keyword, out AsmTokenType tokenType) ? tokenType : AsmTokenType.UNKNOWN);
        }
Пример #24
0
        public AsmTokenType Get_Token_Type(string keyword)
        {
            Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(keyword);

            if (mnemonic != Mnemonic.UNKNOWN)
            {
                if (AsmSourceTools.IsJump(mnemonic))
                {
                    return(AsmTokenType.Jump);
                }
                return(AsmTokenType.Mnemonic);
            }

            if (this._type.TryGetValue(keyword.ToUpper(), out var tokenType))
            {
                return(tokenType);
            }
            return(AsmTokenType.UNKNOWN);
        }
Пример #25
0
        /// <summary>Perform one step forward and return states for both branches</summary>
        public static (State Regular, State Branch) Step_Forward(string line, State state)
        {
            try
            {
                string nextKey       = Tools.CreateKey(state.Tools.Rand);
                string nextKeyBranch = nextKey + "!BRANCH";
                var    content       = AsmSourceTools.ParseLine(line);
                using (var opcodeBase = Runner.InstantiateOpcode(content.Mnemonic, content.Args, (state.HeadKey, nextKey, nextKeyBranch), state.Tools))
                {
                    if (opcodeBase == null)
                    {
                        return(Regular : null, Branch : null);
                    }
                    if (opcodeBase.IsHalted)
                    {
                        return(Regular : null, Branch : null);
                    }

                    opcodeBase.Execute();
                    State stateRegular = null;
                    if (opcodeBase.Updates.Regular != null)
                    {
                        stateRegular = new State(state);
                        stateRegular.Update_Forward(opcodeBase.Updates.Regular);
                        opcodeBase.Updates.Regular.Dispose();
                    }
                    State stateBranch = null;
                    if (opcodeBase.Updates.Branch != null)
                    {
                        stateBranch = new State(state);
                        stateBranch.Update_Forward(opcodeBase.Updates.Branch);
                        opcodeBase.Updates.Branch.Dispose();
                    }
                    return(Regular : stateRegular, Branch : stateBranch);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("WARNING: Runner:Step_Forward: Exception at line: " + line + "; e=" + e.Message);
                return(null, null);
            }
        }
Пример #26
0
        public AsmTokenType getTokenType(string keyword)
        {
            string   keyword2 = keyword.ToUpper();
            Mnemonic mnemonic = AsmSourceTools.parseMnemonic(keyword2);

            if (mnemonic != Mnemonic.UNKNOWN)
            {
                if (AsmSourceTools.isJump(mnemonic))
                {
                    return(AsmTokenType.Jump);
                }
                return(AsmTokenType.Mnemonic);
            }
            AsmTokenType tokenType;

            if (this._type.TryGetValue(keyword2, out tokenType))
            {
                return(tokenType);
            }
            return(AsmTokenType.UNKNOWN);
        }
Пример #27
0
        private Span Get_Keyword_Span_At_Point(SnapshotPoint triggerPoint)
        {
            ITextSnapshotLine line = triggerPoint.GetContainingLine();

            //1] find the start of the current keyword
            SnapshotPoint start = triggerPoint;

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

            while (((end + 1) < line.End) && !AsmSourceTools.IsSeparatorChar((end + 1).GetChar()))
            {
                end += 1;
            }
            //3] get the word under the mouse
            return(new SnapshotSpan(start, end + 1));
        }
        public void SetDescription(Mnemonic mnemonic, AsmDudeTools asmDudeTools)
        {
            string mnemonicStr = mnemonic.ToString();

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

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

            this.Description.Inlines.Add(new Run(full_Descr)
            {
                Foreground = this._foreground
            });
        }
Пример #29
0
        public AsmTokenType Get_Token_Type_Intel(string keyword)
        {
            Debug.Assert(keyword == keyword.ToUpper());

            Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(keyword, true);

            if (mnemonic != Mnemonic.NONE)
            {
                return((this.MnemonicSwitchedOn(mnemonic))
                    ? AsmSourceTools.IsJump(mnemonic) ? AsmTokenType.Jump : AsmTokenType.Mnemonic
                    : AsmSourceTools.IsJump(mnemonic) ? AsmTokenType.Jump : AsmTokenType.MnemonicOff);
            }
            Rn reg = RegisterTools.ParseRn(keyword, true);

            if (reg != Rn.NOREG)
            {
                return((this.RegisterSwitchedOn(reg))
                    ? AsmTokenType.Register
                    : AsmTokenType.Register); //TODO
            }
            return(this._type.TryGetValue(keyword, out AsmTokenType tokenType) ? tokenType : AsmTokenType.UNKNOWN);
        }
Пример #30
0
        public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures)
        {
            //AsmDudeToolsStatic.Output_INFO("AsmSignatureHelpSource: AugmentSignatureHelpSession");

            //if (true) return;
            if (!Settings.Default.SignatureHelp_On)
            {
                return;
            }

            try
            {
                DateTime      time1            = DateTime.Now;
                ITextSnapshot snapshot         = this._buffer.CurrentSnapshot;
                int           position         = session.GetTriggerPoint(this._buffer).GetPosition(snapshot);
                ITrackingSpan applicableToSpan = this._buffer.CurrentSnapshot.CreateTrackingSpan(new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0);

                ITextSnapshotLine line    = snapshot.GetLineFromPosition(position);
                string            lineStr = line.GetText();
                //AsmDudeToolsStatic.Output_INFO("AsmSignatureHelpSource: AugmentSignatureHelpSession: lineStr=" + lineStr+ "; positionInLine=" + positionInLine);

                var             t        = AsmSourceTools.ParseLine(lineStr);
                IList <Operand> operands = AsmSourceTools.MakeOperands(t.Args);
                Mnemonic        mnemonic = t.Mnemonic;

                ISet <Arch> selectedArchitectures = AsmDudeToolsStatic.Get_Arch_Swithed_On();
                //AsmDudeToolsStatic.Output_INFO("AsmSignatureHelpSource: AugmentSignatureHelpSession: selected architectures=" + ArchTools.ToString(selectedArchitectures));

                foreach (AsmSignatureElement se in AsmSignatureHelpSource.Constrain_Signatures(this._store.GetSignatures(mnemonic), operands, selectedArchitectures))
                {
                    signatures.Add(Create_Signature(this._buffer, se, applicableToSpan));
                }
                AsmDudeToolsStatic.Print_Speed_Warning(time1, "Signature Help");
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR(string.Format("{0}:AugmentSignatureHelpSession; e={1}", ToString(), e.ToString()));
            }
        }