protected static IBreakpointInfo CreateBreakpoint(string hitCondition, string filterCondition)
        {
            var breakpoint = new BreakpointInfo
            {
                IsCpuBreakpoint = true,
                HitType         = BreakpointHitType.None
            };

            if (hitCondition != null)
            {
                var condStart = 1;
                if (hitCondition.StartsWith("<="))
                {
                    breakpoint.HitType = BreakpointHitType.LessOrEqual;
                    condStart          = 2;
                }
                else if (hitCondition.StartsWith(">="))
                {
                    breakpoint.HitType = BreakpointHitType.GreaterOrEqual;
                    condStart          = 2;
                }
                else if (hitCondition.StartsWith("<"))
                {
                    breakpoint.HitType = BreakpointHitType.Less;
                }
                else if (hitCondition.StartsWith(">"))
                {
                    breakpoint.HitType = BreakpointHitType.Greater;
                }
                else if (hitCondition.StartsWith("="))
                {
                    breakpoint.HitType = BreakpointHitType.Equal;
                }
                else if (hitCondition.StartsWith("*"))
                {
                    breakpoint.HitType = BreakpointHitType.Multiple;
                }
                breakpoint.HitConditionValue = ushort.Parse(hitCondition.Substring(condStart));
            }

            if (filterCondition != null)
            {
                breakpoint.FilterCondition = filterCondition;
                var inputStream = new AntlrInputStream(filterCondition);
                var lexer       = new Z80EvalLexer(inputStream);
                var tokenStream = new CommonTokenStream(lexer);
                var evalParser  = new Z80EvalParser(tokenStream);
                var context     = evalParser.compileUnit();
                var visitor     = new Z80EvalVisitor();
                var z80Expr     = (Z80ExpressionNode)visitor.Visit(context);
                breakpoint.FilterExpression = z80Expr.Expression;
            }
            return(breakpoint);
        }
예제 #2
0
        /// <summary>
        /// Returns a visitor with the results of a single parsing pass
        /// </summary>
        /// <param name="textToParse">Z80 assembly code to parse</param>
        /// <returns>
        /// Visitor with the syntax tree
        /// </returns>
        protected virtual List <Z80EvalParserErrorInfo> ParseWithErrors(string textToParse)
        {
            var inputStream = new AntlrInputStream(textToParse);
            var lexer       = new Z80EvalLexer(inputStream);
            var tokenStream = new CommonTokenStream(lexer);
            var parser      = new Z80EvalParser(tokenStream);
            var context     = parser.compileUnit();
            var visitor     = new Z80EvalVisitor();

            visitor.Visit(context);
            return(parser.SyntaxErrors);
        }
예제 #3
0
        /// <summary>
        /// Returns a visitor with the results of a single parsing pass
        /// </summary>
        /// <param name="textToParse">Z80 assembly code to parse</param>
        /// <param name="expectedErrors">Number of errors expected</param>
        /// <returns>
        /// Visitor with the syntax tree
        /// </returns>
        protected virtual ExpressionNode ParseExpr(string textToParse, int expectedErrors = 0)
        {
            var inputStream = new AntlrInputStream(textToParse);
            var lexer       = new Z80EvalLexer(inputStream);
            var tokenStream = new CommonTokenStream(lexer);
            var parser      = new Z80EvalParser(tokenStream);
            var context     = parser.expr();
            var visitor     = new Z80EvalVisitor();

            parser.SyntaxErrors.Count.ShouldBe(expectedErrors);
            return((ExpressionNode)visitor.VisitExpr(context));
        }
예제 #4
0
        private void TestFormat(string expression, string result)
        {
            var inputStream = new AntlrInputStream(expression);
            var lexer       = new Z80EvalLexer(inputStream);
            var tokenStream = new CommonTokenStream(lexer);
            var evalParser  = new Z80EvalParser(tokenStream);
            var context     = evalParser.compileUnit();
            var visitor     = new Z80EvalVisitor();
            var z80Expr     = (Z80ExpressionNode)visitor.Visit(context);

            evalParser.SyntaxErrors.Count.ShouldBe(0);
            var value     = z80Expr.Expression.Evaluate(new FakeEvaluationContext());
            var formatted =
                WatchToolWindowViewModel.FormatWatchExpression(z80Expr.Expression, value,
                                                               z80Expr.FormatSpecifier?.Format);

            formatted.ShouldBe(result);
        }
        /// <summary>
        /// Us this method to prepare the breakpoints when running the
        /// virtual machine in debug mode
        /// </summary>
        public void PrepareBreakpoints()
        {
            // --- No compiled code, no VS breakpoints to merge
            if (CompiledOutput == null)
            {
                return;
            }

            var currentVsBreakpoints = new HashSet <Breakpoint>();
            var newVsBreakpoints     = new HashSet <Breakpoint>();

            // --- Identify new breakpoints
            foreach (Breakpoint bp in Package.ApplicationObject.Debugger.Breakpoints)
            {
                if (!_previousVsBreakpoints.ContainsKey(bp))
                {
                    newVsBreakpoints.Add(bp);
                }
                currentVsBreakpoints.Add(bp);
            }

            var oldBreakpoints = new HashSet <Breakpoint>();

            // --- Identify breakpoints to remove
            foreach (var bp in _previousVsBreakpoints.Keys)
            {
                if (!currentVsBreakpoints.Contains(bp))
                {
                    oldBreakpoints.Add(bp);
                }
            }

            // --- In there any change?
            if (newVsBreakpoints.Count == 0 && oldBreakpoints.Count == 0)
            {
                // --- No change, use existing breakpoints
                return;
            }

            // --- Remove old breakpoints
            foreach (var oldBp in oldBreakpoints)
            {
                _previousVsBreakpoints.Remove(oldBp);
            }

            // --- Start assembling the new breakpoint collection
            var newBreakpointCollection = new BreakpointCollection();

            // --- Keep CPU breakpoints set through the Disassembler tool
            foreach (var pair in Breakpoints.Where(bp => bp.Value.IsCpuBreakpoint))
            {
                newBreakpointCollection.Add(pair.Key, pair.Value);
            }

            // --- Add existing VS breakpoints
            foreach (var existingBp in _previousVsBreakpoints.Values)
            {
                foreach (var bp in existingBp)
                {
                    newBreakpointCollection.Add(bp.Key, bp.Value);
                }
            }

            // --- Create new breakpoints
            foreach (var newBp in newVsBreakpoints)
            {
                // --- Check for the file
                var fileIndex = -1;
                for (var i = 0; i < CompiledOutput.SourceFileList.Count; i++)
                {
                    if (string.Compare(newBp.File, CompiledOutput.SourceFileList[i].Filename,
                                       StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        fileIndex = i;
                        break;
                    }
                }
                if (fileIndex < 0)
                {
                    continue;
                }

                var newVsBreakpoint = new BreakpointInfo
                {
                    File     = CompiledOutput.SourceFileList[fileIndex].Filename,
                    FileLine = newBp.FileLine,
                    HitType  = BreakpointHitType.None
                };

                // --- Set hit condition
                if (newBp.HitCountType != dbgHitCountType.dbgHitCountTypeNone)
                {
                    if (newBp.HitCountType == dbgHitCountType.dbgHitCountTypeEqual)
                    {
                        newVsBreakpoint.HitType = BreakpointHitType.Equal;
                    }
                    else if (newBp.HitCountType == dbgHitCountType.dbgHitCountTypeGreaterOrEqual)
                    {
                        newVsBreakpoint.HitType = BreakpointHitType.GreaterOrEqual;
                    }
                    else if (newBp.HitCountType == dbgHitCountType.dbgHitCountTypeMultiple)
                    {
                        newVsBreakpoint.HitType = BreakpointHitType.Multiple;
                    }
                    newVsBreakpoint.HitConditionValue = (ushort)(newBp.HitCountTarget >= 0 ? newBp.HitCountTarget : 0);
                }

                // --- Set filter condition
                if (!string.IsNullOrWhiteSpace(newBp.Condition))
                {
                    var inputStream = new AntlrInputStream(newBp.Condition);
                    var lexer       = new Z80EvalLexer(inputStream);
                    var tokenStream = new CommonTokenStream(lexer);
                    var evalParser  = new Z80EvalParser(tokenStream);
                    var context     = evalParser.compileUnit();
                    var visitor     = new Z80EvalVisitor();
                    var z80Expr     = (Z80ExpressionNode)visitor.Visit(context);
                    if (evalParser.SyntaxErrors.Count == 0)
                    {
                        newVsBreakpoint.FilterExpression = z80Expr.Expression;
                    }
                }

                // --- Check the breakpoint address
                if (CompiledOutput.AddressMap.TryGetValue((fileIndex, newBp.FileLine), out var addresses))
                {
                    foreach (var addr in addresses)
                    {
                        // --- Set up breakpoints

                        newBreakpointCollection.Add(addr, newVsBreakpoint);
                    }
                }
            }

            // --- Set the new collection of breakpoints
            Breakpoints = newBreakpointCollection;
        }