Ejemplo n.º 1
0
        protected override void BeginProcessing()
        {
            //Initialize dictionaries for speeding up searches
            foreach (var inputVar in CodeBlock.InputVariables)
            {
                _inputVars.Add(inputVar.LowLevelName, inputVar);
            }

            foreach (var tempVar in CodeBlock.TempVariables)
            {
                _oldTempVars.Add(tempVar.LowLevelName, tempVar);
            }

            //Add output variables and create new temp variables
            foreach (var outputVar in CodeBlock.OutputVariables)
            {
                AddOutputVariable(outputVar);
            }

            CodeBlock.ComputedVariables.Clear();

            CodeBlock.ComputedVariables.AddRange(_newTempVars.Select(pair => pair.Value));

            CodeBlock.ComputedVariables.AddRange(_outputVars);

            TcbDependencyUpdate.Process(CodeBlock);
        }
Ejemplo n.º 2
0
        internal static GMacCodeBlock Process(GMacCodeBlock codeBlock)
        {
            var processor = new TcbDependencyUpdate(codeBlock);

            processor.BeginProcessing();

            return(codeBlock);
        }
Ejemplo n.º 3
0
        protected override void BeginProcessing()
        {
            _lastUsedVarName = String.Empty;

            AddInputVariables();

            AddComputedVariables();

            CodeBlock.SetLastUsedVarName(_lastUsedVarName);

            TcbDependencyUpdate.Process(CodeBlock);
        }
Ejemplo n.º 4
0
        protected override void BeginProcessing()
        {
            //Fill dictionary of RHS expressions uses
            foreach (var tempVar in CodeBlock.TempVariables)
            {
                AddRhsExprUse(tempVar);
            }

            //Select sub-expressions with multiple uses
            var selectedLists =
                _rhsExprUseDictionary
                .Select(pair => pair.Value)
                .Where(list => list.Count > 1);

            //A list for marking duplicate temp variables to be deleted from code block
            var removedTempsList = new List <GMacCbTempVariable>();

            foreach (var tempVarList in selectedLists)
            {
                //The temp variable to keep
                var tempVarNew = tempVarList[0];

                //Iterate over all duplicate temp variables to be replaced and removed
                foreach (var tempVarOld in tempVarList.Skip(1))
                {
                    //Mark the duplicate for removal
                    removedTempsList.Add(tempVarOld);

                    //Replace the duplicate temp by the temp variable to keep
                    foreach (var computedVar in tempVarOld.UserVariables)
                    {
                        computedVar.ReplaceRhsTempVariable(tempVarOld, tempVarNew);
                    }
                }
            }

            //Remove all duplicate temps from code block
            for (var j = removedTempsList.Count - 1; j >= 0; j--)
            {
                CodeBlock.ComputedVariables.RemoveAt(removedTempsList[j].ComputationOrder);
            }

            //Update dependency information if needed
            if (removedTempsList.Count > 0)
            {
                TcbDependencyUpdate.Process(CodeBlock);
            }
        }
Ejemplo n.º 5
0
        protected override void BeginProcessing()
        {
            //Add all RHS expressions and subexpressions of all computed variables to a list
            foreach (var computedVar in CodeBlock.ComputedVariables)
            {
                AddSubExpressions(computedVar);
            }

            //Select which temp variables to add to the final computations list
            UpdateRelevantComputations();

            //Replace sub-expressions used multiple times in computations by their temp variables
            PropagateSubExpressions();

            //Update code block
            CodeBlock.ComputedVariables = _computedVarsList;

            TcbDependencyUpdate.Process(CodeBlock);
        }