Пример #1
0
        private void AddRhsExpression(GMacCbComputedVariable computedVar)
        {
            var expr     = computedVar.RhsExpr;
            var exprText = expr.ToString();
            var tempVar  = computedVar as GMacCbTempVariable;

            if (tempVar != null)
            {
                //If this whole expression is already assigned to a temp variable add the temp to the output.
                AddTempVariable(exprText, tempVar);

                return;
            }

            //If this whole expression is instead assigned to an output variabe create a factored expression
            //temp variable and add it to the output with use count 1 and add the original output
            //variable to the output
            if (expr.IsSimpleConstantOrLowLevelVariable() == false && _tempVarsDictionary.ContainsKey(exprText) == false)
            {
                tempVar = new GMacCbTempVariable(CodeBlock.GetNewVarName(), expr, true)
                {
                    SubExpressionUseCount = 1
                };

                AddTempVariable(exprText, tempVar);
            }

            AddVariable(computedVar);
        }
Пример #2
0
        /// <summary>
        /// Test if the given temp item is required to be added
        /// </summary>
        /// <param name="item"></param>
        private void TryAddTempVariable(LlDataItem item)
        {
            //If this temp item is not in the list of required items for computation just ignore it
            if (_activeItemsList.Contains(item.ItemName) == false)
            {
                return;
            }

            var rhsExpr =
                item.AssignedRhsSymbolicScalar.ToTextExpressionTree();

            //Create the temp variable and add it to the target language block
            var tempVar =
                new GMacCbTempVariable(
                    item.ItemName,
                    rhsExpr,
                    false
                    )
            {
                ComputationOrder = _computationOrder--
            };

            CodeBlock.ComputedVariables.Add(tempVar);

            //This item is required for computation.
            //All its RHS items must be added to the list of active items
            _activeItemsList.AddRange(rhsExpr.GetLowLevelVariablesNames());

            if (String.Compare(item.ItemName, _lastUsedVarName, StringComparison.Ordinal) > 0)
            {
                _lastUsedVarName = item.ItemName;
            }
        }
Пример #3
0
        private void AddTempVariable(string rhsExprText, GMacCbTempVariable varInfo)
        {
            varInfo.ComputationOrder = _computedVarsList.Count;

            _tempVarsDictionary.Add(rhsExprText, varInfo);

            _computedVarsList.Add(varInfo);
        }
Пример #4
0
        private void AddRhsExprUse(GMacCbTempVariable tempVar)
        {
            var rhsExprText = tempVar.RhsExpr.ToString();

            List <GMacCbTempVariable> rhsExprUseList;

            if (_rhsExprUseDictionary.TryGetValue(rhsExprText, out rhsExprUseList) == false)
            {
                rhsExprUseList = new List <GMacCbTempVariable>();

                _rhsExprUseDictionary.Add(rhsExprText, rhsExprUseList);
            }

            rhsExprUseList.Add(tempVar);
        }
Пример #5
0
        /// <summary>
        /// Find or create a temp variable holding the given expression as its RHS
        /// </summary>
        /// <param name="subExpr"></param>
        /// <returns></returns>
        private GMacCbTempVariable GetTempVariable(SteExpression subExpr)
        {
            GMacCbTempVariable tempVar;
            var subExprText = subExpr.ToString();

            //A temp is found; return it
            if (_subExpressionsDictionary.TryGetValue(subExprText, out tempVar))
            {
                return(tempVar);
            }

            //A temp is not found; create it and return it
            tempVar = new GMacCbTempVariable(CodeBlock.GetNewVarName(), subExpr, true);

            _subExpressionsDictionary.Add(subExprText, tempVar);

            _newTempVars.Add(tempVar.LowLevelName, tempVar);

            return(tempVar);
        }
Пример #6
0
        private void AddSubExpressions(GMacCbComputedVariable computedVar)
        {
            foreach (var subExpr in computedVar.RhsSubExpressions)
            {
                var subExprText = subExpr.ToString();
                GMacCbTempVariable tempVar;

                if (_tempVarsDictionary.TryGetValue(subExprText, out tempVar))
                {
                    tempVar.SubExpressionUseCount++;
                }
                else
                {
                    tempVar = new GMacCbTempVariable(CodeBlock.GetNewVarName(), subExpr, true);

                    AddTempVariable(subExprText, tempVar);
                }
            }

            AddRhsExpression(computedVar);
        }