protected override void VisitBranchOnEqualShortInstruction(BranchOnEqualShortInstruction instruction)
        {
            ControlState.EvaluationStack.Pop(out var stackVal1, out var stackVal2);
            var branch = ComputeBinaryBranchOperation(
                stackVal1,
                stackVal2,
                (a, b) => a.Value == b.Value,
                (a, b) => a.Value == b.Value,
                (a, b) => a.Value == b.Value
                );

            if (branch)
            {
                ControlState.Move(instruction.Offset, instruction.Label);
            }
            else
            {
                ControlState.MoveToNextInstruction();
            }
        }
        public override CILInstructionBranchTarget BuildNode(ParseTreeNode node)
        {
            var instructionBranchTargetParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_BRTARGET);

            CILInstructionBranchTarget result = null;

            var beqsParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_beqs);

            if (beqsParseTreeNode != null)
            {
                result = new BranchOnEqualShortInstruction();
            }

            var bgesParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_bges);

            if (bgesParseTreeNode != null)
            {
                result = new BranchOnGreaterOrEqualShortInstruction();
            }

            var blesParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_bles);

            if (blesParseTreeNode != null)
            {
                result = new BranchOnLessOrEqualShortInstruction();
            }

            var bltsParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_blts);

            if (bltsParseTreeNode != null)
            {
                result = new BranchOnLessShortInstruction();
            }

            var bneunsParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_bneuns);

            if (bneunsParseTreeNode != null)
            {
                result = new BranchOnNotEqualOrUnorderedShortInstruction();
            }

            var brParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_br);

            if (brParseTreeNode != null)
            {
                result = new BranchInstruction();
            }

            var brfalsesParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_brfalses);

            if (brfalsesParseTreeNode != null)
            {
                result = new BranchOnFalseShortInstruction();
            }

            var brsParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_brs);

            if (brsParseTreeNode != null)
            {
                result = new BranchShortInstruction();
            }

            var brtruesParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_brtrues);

            if (brtruesParseTreeNode != null)
            {
                result = new BranchOnTrueShortInstruction();
            }

            if (result != null)
            {
                var idParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.id);
                result.Label = IdParseTreeNodeHelper.GetValue(idParseTreeNode);

                return(result);
            }

            throw new ArgumentException("Cannot recognize CIL instruction branch target.");
        }
Esempio n. 3
0
 protected abstract void VisitBranchOnEqualShortInstruction(BranchOnEqualShortInstruction instruction);