private void DeclareComponentInstance(IComponentDescriptor cd, IndentedTextWriter tw) { string name = GetComponentName(cd); string rname = GetComponentName(((ComponentDescriptor)cd).Instance.Representant.Descriptor); if (_curComponent != null && // may happen if called prior to actual VHDL generation in OnSynthesis() method of a component GetLibrary(_curComponent) != GetLibrary(cd)) rname = "entity " + GetLibrary(cd) + "." + rname; tw.WriteLine("inst_" + name + ": " + rname); tw.Indent++; tw.WriteLine("port map("); tw.Indent++; IComponentDescriptor owner = (IComponentDescriptor)cd.Owner; bool first = true; var xsim = _sim.Fork(); xsim.PushScope(); foreach (IPortDescriptor pd in cd.GetPorts()) { if (first) first = false; else tw.WriteLine(","); var ownerRef = pd .BoundSignal .AsSignalRef(SignalRef.EReferencedProperty.Cur); if (ownerRef == null) throw new InvalidOperationException("Bound signal unknown to instantiating component"); var litstr = new LiteralStringifier(this, LiteralReference.EMode.Direct); var temp = _curComponent; _curComponent = owner; litstr.VisitSignalRef(ownerRef); var rhs = litstr.Result; _curComponent = temp; string pid = MakeIDName(pd.Name, pd.BoundSignal.RemoveIndex(), xsim); /*string sigExpr = MakeIDName(spd.Name, pd.BoundSignal.RemoveIndex()); if (pd.BoundSignal is InstanceDescriptor && ((InstanceDescriptor)pd.BoundSignal).Index != null) sigExpr += ((InstanceDescriptor)pd.BoundSignal).Index.ToString(); tw.Write(pid + " => " + sigExpr);*/ tw.Write(pid + " => " + rhs); } tw.WriteLine(");"); tw.Indent--; tw.Indent--; }
private void DeclareProcess(ProcessDescriptor pd, IndentedTextWriter tw) { bool simuOnly = pd.HasAttribute<SimulationOnly>(); if (simuOnly) SwitchOffSynthesis(tw); List<ConcurrentStatement> cstmts; if (pd.Implementation .MakeIntegerIndices() .TryAsConcurrentStatements(out cstmts)) { foreach (var cstmt in cstmts) { var ls = new LiteralStringifier(this, LiteralReference.EMode.Direct); ls.VisitSignalRef(cstmt.TargetSignal); tw.Write(ls.Result); tw.Write(" <= "); tw.Write(cstmt.SourceExpression.ToString(this)); tw.WriteLine(";"); } tw.WriteLine(); } else { string pname = MakeIDName(pd.Name, pd); tw.Write(pname + ": process"); if (pd.Kind == Components.Process.EProcessKind.Triggered && pd.Sensitivity.Length > 0) { tw.Write("("); bool first = true; var sens = pd.Sensitivity.Select(spd => DieWithUnknownSensitivityIfNull(spd .AsSignalRef(SignalRef.EReferencedProperty.Instance) .RelateToComponent(_curComponent)) .AssimilateIndices() .Desc) .Distinct(); foreach (var spd in sens) { if (first) first = false; else tw.Write(", "); tw.Write(MakeIDName(spd.Name, spd.GetBoundSignal())); } tw.Write(")"); } tw.WriteLine(); GenerateMethodBody(pd, tw); tw.WriteLine(" process;"); } if (simuOnly) SwitchOnSynthesis(tw); }
// ADDED private void PortBinding(IComponentDescriptor cd, IndentedTextWriter tw) { //string rname = GetComponentName(((ComponentDescriptor)cd).Instance.Representant.Descriptor); string rname = MakeIDName(GetComponentName(cd), cd) + "_"; // Alternative 1 if (cd.GetPorts() != null) { IComponentDescriptor owner = (IComponentDescriptor)cd.Owner; //bool first = true; var xsim = _sim.Fork(); xsim.PushScope(); foreach (IPortDescriptor pd in cd.GetPorts()) { tw.Write(rname + "."); var ownerRef = pd .BoundSignal .AsSignalRef(SignalRef.EReferencedProperty.Instance); if (ownerRef == null) throw new InvalidOperationException("Bound signal unknown to instantiating component"); var litstr = new LiteralStringifier(this, LiteralReference.EMode.Direct); var temp = _curComponent; _curComponent = owner; litstr.VisitSignalRef(ownerRef); var rhs = litstr.Result; _curComponent = temp; string pid = MakeIDName(pd.Name, pd.BoundSignal.RemoveIndex(), xsim); tw.WriteLine(pid + ".bind(" + rhs + ");"); } tw.WriteLine(); } //// Alternative 2 //if (cd.GetPorts() != null) //{ // tw.Write(rname + "("); // IComponentDescriptor owner = (IComponentDescriptor)cd.Owner; // bool first = true; // var xsim = _sim.Fork(); // xsim.PushScope(); // foreach (IPortDescriptor pd in cd.GetPorts()) // { // if (first) // first = false; // else // tw.Write(","); // var ownerRef = pd // .BoundSignal // .AsSignalRef(SignalRef.EReferencedProperty.Instance); // if (ownerRef == null) // throw new InvalidOperationException("Bound signal unknown to instantiating component"); // var litstr = new LiteralStringifier(this, LiteralReference.EMode.Direct); // var temp = _curComponent; // _curComponent = owner; // litstr.VisitSignalRef(ownerRef); // var rhs = litstr.Result; // _curComponent = temp; // string pid = MakeIDName(pd.Name, pd.BoundSignal.RemoveIndex(), xsim); // tw.Write(rhs); // } // tw.WriteLine(");"); //} }