コード例 #1
0
        /// <summary>
        /// Visits an assignment of a TestSet
        /// </summary>
        /// <param name="plan">Test file plan</param>
        /// <param name="testSetPlan">TestSetPlan to visit</param>
        /// <param name="asgn">Assignment syntax node</param>
        /// <returns>Assignment plan</returns>
        private AssignmentPlanBase VisitAssignment(TestFilePlan plan, TestSetPlan testSetPlan, AssignmentNode asgn)
        {
            if (asgn is RegisterAssignmentNode regAsgn)
            {
                var value = Eval(plan, testSetPlan, regAsgn.Expr);
                return(value != null
                    ? new RegisterAssignmentPlan(regAsgn.RegisterName, value.AsWord())
                    : null);
            }

            if (asgn is FlagAssignmentNode flagAsgn)
            {
                return(new FlagAssignmentPlan(flagAsgn.FlagName));
            }

            if (asgn is MemoryAssignmentNode memAsgn)
            {
                var address = Eval(plan, testSetPlan, memAsgn.Address);
                var value   = Eval(plan, testSetPlan, memAsgn.Value);
                if (address == null || value == null)
                {
                    return(null);
                }
                ExpressionValue length = null;
                if (memAsgn.Length != null)
                {
                    length = Eval(plan, testSetPlan, memAsgn.Length);
                    if (length == null)
                    {
                        return(null);
                    }
                }

                return(length == null
                    ? new MemoryAssignmentPlan(address.AsWord(), value.AsByteArray())
                    : new MemoryAssignmentPlan(address.AsWord(), value.AsByteArray().Take(length.AsWord()).ToArray()));
            }

            return(null);
        }