예제 #1
0
        // -------------------------------------------------------------------
        /// Resolves code dependencies.
        public override void ResolveDependencies()
        {
            // -- Ask our children to resolve their dependencies. --
            base.ResolveDependencies();

            // -- Don't generate code if all enables are false. --
            if (ControlFlow.IsAllEnablesAlwaysFalse(myEnablePorts))
            {
                Parent.Remove(this);
                return;
            }
            // -- Merge with parent if one of the enables is always true. --
            if (ControlFlow.IsAtLeastOneEnableAlwaysTrue(myEnablePorts))
            {
                (Parent as ExecutionBlockDefinition).Replace(this, myExecutionList);
                return;
            }

            // -- Determine if enable producers where optimized out. --
            var  enableLen   = myEnablePorts.Length;
            bool hasProducer = false;

            for (int i = 0; i < enableLen; ++i)
            {
                var enable       = myEnablePorts[i];
                var producerPort = GraphInfo.GetProducerPort(enable);
                if (FindCodeBase(producerPort) != null || producerPort.ParentNode.IsConstructor)
                {
                    hasProducer = true;
                    break;
                }
            }
            if (!hasProducer)
            {
                (Parent as ExecutionBlockDefinition).Replace(this, myExecutionList);
                return;
            }

            // -- Reposition code for simple trigger->enable --
            CodeBase commonParent = null;

            if (AreAllInSameExecutionContext(out commonParent))
            {
                var parentAsExecBlock = commonParent as ExecutionBlockDefinition;
                if (AreAllProducersTriggers())
                {
                    if (parentAsExecBlock != null)
                    {
                        Debug.Log("Removing enable for=> " + myEnablePorts[0].FullName);
                        parentAsExecBlock.Replace(this, myExecutionList);
                        return;
                    }
                }
                else if (parentAsExecBlock != null)
                {
                    if (Parent != parentAsExecBlock)
                    {
                        Parent.Remove(this);
                        parentAsExecBlock.AddExecutable(this);
                    }
                }
            }

            // -- Determine best enable order for code optimization. --
            if (enableLen > 1)
            {
                for (int i = 0; i < enableLen; ++i)
                {
                    var enable = myEnablePorts[i];
                    if (enable.IsTheOnlyConsumer && !enable.SegmentProducerPort.IsTriggerPort)
                    {
                        if (i != 0)
                        {
                            var t = myEnablePorts[0];
                            myEnablePorts[0] = enable;
                            myEnablePorts[i] = t;
                        }
                        break;
                    }
                }
            }

            // -- Verify if we can optimize parameter ports. --
            myEnableCode[0] = Context.GetCodeFor(GraphInfo.GetProducerPort(myEnablePorts[0]));
            if (myEnableCode[0] != null)
            {
                myEnableCode[0] = OptimizeInputParameter(myEnableCode[0], myParent);
                if (myEnableCode[0] != null)
                {
                    myEnableCode[0].Parent = this;
                }
            }
        }