예제 #1
0
        ///
        /// <summary>
        /// Use when the boolen constant is used as expression: a = true
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public override ExpressionBDDEncoding TranslateIntExpToBDD(Model model)
        {
            string channelName          = Arguments[0].ToString();
            string countChannelVariable = Model.GetCountVarChannel(channelName);
            string topChannelVariable   = Model.GetTopVarChannel(channelName);

            switch (MethodName)
            {
            case Constants.cfull:
                Expression            isFull     = Expression.EQ(new Variable(countChannelVariable), new IntConstant(model.mapChannelToSize[channelName]));
                ExpressionBDDEncoding isFullTemp = isFull.TranslateBoolExpToBDD(model);
                isFullTemp.ExpressionDDs = new List <CUDDNode>(isFullTemp.GuardDDs);
                isFullTemp.GuardDDs      = new List <CUDDNode>()
                {
                    CUDD.Constant(1)
                };
                return(isFullTemp);

            case Constants.cempty:
                Expression            isEmpty     = Expression.EQ(new Variable(countChannelVariable), new IntConstant(0));
                ExpressionBDDEncoding isEmptyTemp = isEmpty.TranslateBoolExpToBDD(model);
                isEmptyTemp.ExpressionDDs = new List <CUDDNode>(isEmptyTemp.GuardDDs);
                isEmptyTemp.GuardDDs      = new List <CUDDNode>()
                {
                    CUDD.Constant(1)
                };
                return(isEmptyTemp);

            case Constants.ccount:
                return(new Variable(countChannelVariable).TranslateIntExpToBDD(model));

            case Constants.csize:
                return(new IntConstant(model.mapChannelToSize[channelName]).TranslateIntExpToBDD(model));

            case Constants.cpeek:
                //(top_a - count_a) % L
                Expression popedElementPosition = new PrimitiveApplication(PrimitiveApplication.MOD,
                                                                           Expression.MINUS(new Variable(topChannelVariable), new Variable(countChannelVariable)),
                                                                           new IntConstant(model.mapChannelToSize[channelName]));

                //a[top_a - count_a % L][i]
                return(new PrimitiveApplication(PrimitiveApplication.ARRAY, new Variable(channelName), Expression.TIMES(
                                                    popedElementPosition,
                                                    new IntConstant(Model.MAX_MESSAGE_LENGTH))
                                                ).TranslateIntExpToBDD(model));
            }

            throw new Exception("Static call can not be encoded in BDD");
        }