private void ScanDefineArchitecture()
        {
            tokenizer.Match(TokenTypes.TextIdentifier, "architecture");
            MathIdentifier architectureId = ScanEntityMathIdentifierOrLabel(true);
            MathIdentifier entityId       = ScanEntityMathIdentifierOrLabel(true);
            IEntity        entity         = library.LookupEntity(entityId);

            tokenizer.Match("{");
            IMathSystem originalSystem = system;
            IMathSystem tempSystem     = Binder.CreateSystem();

            system = tempSystem;
            while (tokenizer.LookaheadFistToken.Text != "}")
            {
                NextStatement();
            }
            foreach (string input in entity.InputSignals)
            {
                tempSystem.PromoteAsInput(tempSystem.LookupNamedSignal(input));
            }
            foreach (string output in entity.OutputSignals)
            {
                tempSystem.AddSignalTree(tempSystem.LookupNamedSignal(output), tempSystem.GetAllInputs(), true, false);
            }
            ReadOnlySignalSet leafs = tempSystem.GetAllLeafSignals();

            foreach (Signal s in leafs)
            {
                Signal so;
                if (originalSystem.TryLookupNamedSignal(s.Label, out so) && so.Value != null)
                {
                    s.PostNewValue(so.Value);
                }
            }
            Service <ISimulationMediator> .Instance.SimulateInstant();

            system = originalSystem;
            tokenizer.Match("}");
            tempSystem.RemoveUnusedObjects();
            tempSystem.PublishToLibrary(architectureId, entity.EntityId);
        }
示例#2
0
        private void InitializeObserverWithCurrentSystem(ISystemObserver observer)
        {
            if (_system == null)
            {
                return;
            }

            observer.BeginInitialize();

            ReadOnlySignalSet allSignals = _system.GetAllSignals();

            for (int i = 0; i < allSignals.Count; i++)
            {
                observer.OnSignalAdded(allSignals[i], i);
            }

            ReadOnlyBusSet allBuses = _system.GetAllBuses();

            for (int i = 0; i < allBuses.Count; i++)
            {
                observer.OnBusAdded(allBuses[i], i);
            }

            ReadOnlyPortSet allPorts = _system.GetAllPorts();

            for (int i = 0; i < allPorts.Count; i++)
            {
                observer.OnPortAdded(allPorts[i], i);
            }

            for (int i = 0; i < allSignals.Count; i++)
            {
                Signal s = allSignals[i];
                if (s.IsDriven && allPorts.Contains(s.DrivenByPort))
                {
                    observer.OnPortDrivesSignal(s, s.DrivenByPort, s.DrivenByPort.OutputSignals.IndexOf(s));
                }
            }
            for (int i = 0; i < allPorts.Count; i++)
            {
                Port p = allPorts[i];
                for (int j = 0; j < p.InputSignalCount; j++)
                {
                    Signal s = p.InputSignals[j];
                    if (allSignals.Contains(s))
                    {
                        observer.OnSignalDrivesPort(s, p, j);
                    }
                }
            }

            ReadOnlySignalSet inputs = _system.GetAllInputs();

            for (int i = 0; i < inputs.Count; i++)
            {
                observer.OnInputAdded(inputs[i], i);
            }

            ReadOnlySignalSet outputs = _system.GetAllOutputs();

            for (int i = 0; i < outputs.Count; i++)
            {
                observer.OnOutputAdded(outputs[i], i);
            }

            observer.EndInitialize();
        }