protected override void TryCreateGizmos(IComponentDescriptor componentDescriptor, List <Component> gizmos, RuntimeWindow window) { if (m_isEditing) { base.TryCreateGizmos(componentDescriptor, gizmos, window); } }
protected override void TryCreateGizmo(IComponentDescriptor componentDescriptor) { if (m_isEditing) { base.TryCreateGizmo(componentDescriptor); } }
static void ResolveTypeDependencies(this IComponentDescriptor component, DesignDescriptor design) { foreach (var child in component.GetChildComponents()) { ResolveTypeDependencies(child, design); } var processes = component.GetProcesses().ToArray(); var str = new StmtTypeResolver(design, component); foreach (var process in processes) { ResolveTypeDependencies(process, str); } foreach (var port in component.GetPorts()) { str.RequireType(port.ElementType, design); } foreach (var signal in component.GetSignals()) { str.RequireType(signal.ElementType, design); } foreach (var field in component.GetFields()) { str.RequireType(field.Type, design); } }
public DefaultSynthesisContext(DesignContext simCtx, IProject project, IComponentDescriptor top, ICodeGenerator codeGen) { ModelContext = simCtx; Project = project; CodeGen = codeGen; _componentSet = top.GetAllAncestors(); }
protected override void BuildEditor(IComponentDescriptor componentDescriptor, PropertyDescriptor[] descriptors) { base.BuildEditor(componentDescriptor, descriptors); m_editColliderButton = Instantiate(ToggleButton).GetComponent <Toggle>(); m_editColliderButton.transform.SetParent(EditorsPanel, false); m_editColliderButton.onValueChanged.RemoveListener(OnEditCollider); m_editColliderButton.isOn = m_isEditing; m_editColliderButton.onValueChanged.AddListener(OnEditCollider); }
public void BuildEditor() { IComponentDescriptor componentDescriptor = GetComponentDescriptor(); if (componentDescriptor != null) { m_converter = componentDescriptor.CreateConverter(this); } PropertyDescriptor[] descriptors = GetDescriptors(m_converter); if (descriptors == null || descriptors.Length == 0) { if (ExpanderGraphics != null) { ExpanderGraphics.SetActive(false); } return; } if (ResetButton != null) { ResetButton.gameObject.SetActive(componentDescriptor != null ? componentDescriptor.GetHeaderDescriptor(m_editor).ShowResetButton : m_editor.ComponentEditorSettings.ShowResetButton); } if (EnabledEditor != null) { EnabledEditor.gameObject.SetActive(componentDescriptor != null ? componentDescriptor.GetHeaderDescriptor(m_editor).ShowEnableButton : m_editor.ComponentEditorSettings.ShowEnableButton); } if (Expander == null) { BuildEditor(componentDescriptor, descriptors); } else { if (componentDescriptor != null ? !componentDescriptor.GetHeaderDescriptor(m_editor).ShowExpander : !m_editor.ComponentEditorSettings.ShowExpander) { Expander.isOn = true; Expander.enabled = false; } if (Expander.isOn) { if (ExpanderGraphics != null) { ExpanderGraphics.SetActive(componentDescriptor != null ? componentDescriptor.GetHeaderDescriptor(m_editor).ShowExpander : m_editor.ComponentEditorSettings.ShowExpander); } BuildEditor(componentDescriptor, descriptors); } } }
/// <summary> /// Creates and adds a new port. /// </summary> /// <param name="me">component descriptor to host the new port</param> /// <param name="name">name of new port</param> /// <param name="dir">data-flow direction</param> /// <param name="usage">usage hint</param> /// <param name="dataType">type descriptor of exchanged data</param> /// <returns>the descriptor of the newly created port</returns> public static PortBuilder CreatePort(this IComponentDescriptor me, string name, EFlowDirection dir, EPortUsage usage, TypeDescriptor dataType) { Contract.Requires <ArgumentNullException>(me != null); Contract.Requires <ArgumentNullException>(name != null); Contract.Requires <ArgumentNullException>(dataType != null); PortBuilder result = new PortBuilder(dir, usage, null, dataType); me.AddChild(result, name); return(result); }
/// <inheritdoc /> public ComponentHandle ResolveHandle(Type serviceType) { if (serviceType == null) { throw new ArgumentNullException("serviceType"); } IComponentDescriptor descriptor = ResolveNonDisabledDescriptor(serviceType); return(ComponentHandle.CreateInstance(descriptor)); }
/// <inheritdoc /> public ComponentHandle ResolveHandleByComponentId(string componentId) { if (componentId == null) { throw new ArgumentNullException("componentId"); } IComponentDescriptor descriptor = ResolveNonDisabledDescriptorByComponentId(componentId); return(ComponentHandle.CreateInstance(descriptor)); }
/// <inheritdoc /> public object ResolveByComponentId(string componentId) { if (componentId == null) { throw new ArgumentNullException("componentId"); } IComponentDescriptor descriptor = ResolveNonDisabledDescriptorByComponentId(componentId); return(descriptor.ResolveComponent()); }
/// <inheritdoc /> public bool HasComponent(string componentId) { if (componentId == null) { throw new ArgumentNullException("componentId"); } IComponentDescriptor descriptor = registry.Components[componentId]; return(descriptor != null && !descriptor.IsDisabled); }
private void CreateOrDestroyGizmos(IComponentDescriptor componentDescriptor) { if (IsComponentEnabled) { TryCreateGizmos(componentDescriptor); } else { DestroyGizmos(); } }
public Registration( IComponentDescriptor descriptor, IComponentActivator activator, IEnumerable <IParameter> parameters, ComponentLifestyle lifestyle) { _descriptor = Enforce.ArgumentNotNull(descriptor, "descriptor"); _activator = Enforce.ArgumentNotNull(activator, "activator"); _lifestyle = lifestyle; _scope = scope.InstanceScopeFactory.ToScope(lifestyle); }
protected virtual void TryCreateGizmo(IComponentDescriptor componentDescriptor) { if (componentDescriptor != null && componentDescriptor.GizmoType != null && IsComponentEnabled) { m_gizmo = Component.gameObject.GetComponent(componentDescriptor.GizmoType); if (m_gizmo == null) { m_gizmo = Component.gameObject.AddComponent(componentDescriptor.GizmoType); } m_gizmo.SendMessageUpwards("Reset", SendMessageOptions.DontRequireReceiver); } }
private void VerifyComponentTraits(IComponentDescriptor component, ref bool success) { try { component.ResolveTraits(); } catch (Exception ex) { success = false; dispatchLogger.Log(LogSeverity.Error, "Unresolvable component traits.", ex); } }
/// <summary> /// Creates and adds a new field. /// </summary> /// <param name="me">component descriptor to host the new field</param> /// <param name="type">type descriptor of the new field</param> /// <param name="name">name of the new field</param> /// <returns>the descriptor of the new field</returns> public static DOMFieldBuilder CreateField(this IComponentDescriptor me, TypeDescriptor type, string name) { Contract.Requires <ArgumentNullException>(me != null); Contract.Requires <ArgumentNullException>(type != null); Contract.Requires <ArgumentNullException>(name != null); var fb = new DOMFieldBuilder(type); me.AddChild(fb, name); return(fb); }
/// <summary> /// Creates and adds a new signal, including its implementation-level instance. /// </summary> /// <param name="me">component descriptor to host the new signal</param> /// <param name="name">name of new signal</param> /// <param name="initialValue">initial value of new signal</param> /// <returns>the descriptor for the newly created signal</returns> public static SignalDescriptor CreateSignalInstance(this IComponentDescriptor me, string name, object initialValue) { Contract.Requires <ArgumentNullException>(me != null); Contract.Requires <ArgumentNullException>(initialValue != null); Contract.Requires <ArgumentNullException>(name != null); SignalBase sinst = Signals.CreateInstance(initialValue); SignalDescriptor result = sinst.Descriptor; me.AddChild(result, name); return(result); }
/// <summary> /// Creates and adds a new SysDOM-only signal descriptor. /// </summary> /// <param name="me">component descriptor to host the new signal</param> /// <param name="name">name of new signal</param> /// <param name="dataType">type of signal value</param> /// <returns>the descriptor for the newly created signal</returns> public static SignalBuilder CreateSignal(this IComponentDescriptor me, string name, Type dataType) { Contract.Requires <ArgumentNullException>(me != null); Contract.Requires <ArgumentNullException>(name != null); Contract.Requires <ArgumentNullException>(dataType != null); object initialValue = Activator.CreateInstance(dataType); SignalBuilder result = new SignalBuilder(dataType, initialValue); me.AddChild(result, name); return(result); }
protected override void BuildEditor(IComponentDescriptor componentDescriptor, PropertyDescriptor[] descriptors) { base.BuildEditor(componentDescriptor, descriptors); if (NotNullComponents.Any() && NotNullComponents.All(component => (component.gameObject.hideFlags & HideFlags.HideInHierarchy) == 0)) { m_editColliderButton = Instantiate(ToggleButton).GetComponent <Toggle>(); m_editColliderButton.transform.SetParent(EditorsPanel, false); m_editColliderButton.onValueChanged.RemoveListener(OnEditCollider); m_editColliderButton.isOn = m_isEditing; m_editColliderButton.onValueChanged.AddListener(OnEditCollider); } }
/// <summary> /// Creates and adds a new field. /// </summary> /// <param name="me">component descriptor to host the new field</param> /// <param name="type">type descriptor of the new field</param> /// <param name="initialValue">initial field value</param> /// <param name="name">name of the new field</param> /// <returns>the descriptor of the new field</returns> public static DOMFieldBuilder CreateField(this IComponentDescriptor me, TypeDescriptor type, object initialValue, string name) { Contract.Requires <ArgumentNullException>(me != null); Contract.Requires <ArgumentNullException>(type != null); Contract.Requires <ArgumentNullException>(name != null); Contract.Requires <ArgumentException>(initialValue == null || TypeDescriptor.GetTypeOf(initialValue).Equals(type), "Field type must match type of initial value"); var fb = new DOMFieldBuilder(type, initialValue); me.AddChild(fb, name); return(fb); }
/// <summary> /// Looks up the VHDL file path of a VHDL-generated component. /// </summary> /// <param name="desc">component descriptor</param> /// <returns>its VHDL file path</returns> public static string GetInstancePath(IComponentDescriptor desc) { var cur = (DescriptorBase)desc; string path = ""; while (cur.Owner is IComponentDescriptor) { var gi = cur.QueryAttribute<VHDLGenInfo>(); path = "/" + gi.InstanceName + path; cur = cur.Owner; } var git = cur.QueryAttribute<VHDLGenInfo>(); path = "/" + git.EntityName; return path; }
private void Awake() { IOC.RegisterFallback <IEditorsMap>(this); var type = typeof(IComponentDescriptor); #if !UNITY_WSA || UNITY_EDITOR var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => type.IsAssignableFrom(p) && p.IsClass && !p.IsAbstract); #else var types = type.GetTypeInfo().Assembly.GetTypes(). Where(p => type.IsAssignableFrom(p) && p.GetTypeInfo().IsClass&& !p.IsAbstract); #endif m_componentDescriptors = new Dictionary <Type, IComponentDescriptor>(); foreach (Type t in types) { IComponentDescriptor descriptor = (IComponentDescriptor)Activator.CreateInstance(t); if (descriptor == null) { Debug.LogWarningFormat("Unable to instantiate descriptor of type " + t.FullName); continue; } if (descriptor.ComponentType == null) { Debug.LogWarningFormat("ComponentType is null. Descriptor Type {0}", t.FullName); continue; } if (m_componentDescriptors.ContainsKey(descriptor.ComponentType)) { IComponentDescriptor alreadyAddedDescriptor = m_componentDescriptors[descriptor.ComponentType]; if (IsBulitIn(alreadyAddedDescriptor.GetType())) { //Overwrite built-in component descriptor m_componentDescriptors[descriptor.ComponentType] = descriptor; } else if (!IsBulitIn(descriptor.GetType())) { Debug.LogWarningFormat("Duplicate descriptor for {0} found. Type name {1}. Using {2} instead", descriptor.ComponentType.FullName, descriptor.GetType().FullName, m_componentDescriptors[descriptor.ComponentType].GetType().FullName); } } else { m_componentDescriptors.Add(descriptor.ComponentType, descriptor); } } LoadMap(); }
/// <summary> /// Creates an instance of a typed component handle for the specified descriptor. /// </summary> /// <param name="componentDescriptor">The component descriptor.</param> /// <returns>The appropriately typed component handle.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="componentDescriptor"/> is null.</exception> /// <exception cref="RuntimeException">Thrown if the described component's service type or traits type cannot be resolved.</exception> public static ComponentHandle CreateInstance(IComponentDescriptor componentDescriptor) { if (componentDescriptor == null) { throw new ArgumentNullException("componentDescriptor"); } Type serviceType = componentDescriptor.Service.ResolveServiceType(); Type traitsType = componentDescriptor.Service.ResolveTraitsType(); Type handleType = typeof(ComponentHandle <,>).MakeGenericType(serviceType, traitsType); ConstructorInfo constructor = handleType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(IComponentDescriptor) }, null); return((ComponentHandle)constructor.Invoke(new[] { componentDescriptor })); }
protected virtual void BuildEditor(IComponentDescriptor componentDescriptor, PropertyDescriptor[] descriptors) { DestroyEditor(); TryCreateGizmo(componentDescriptor); for (int i = 0; i < descriptors.Length; ++i) { PropertyDescriptor descriptor = descriptors[i]; if (descriptor.MemberInfo == EnabledProperty) { continue; } BuildPropertyEditor(descriptor); } }
private void OnExpanded(bool expanded) { IsComponentExpanded = expanded; if (expanded) { IComponentDescriptor componentDescriptor = GetComponentDescriptor(); PropertyDescriptor[] descriptors = GetDescriptors(m_converter); ExpanderGraphics.SetActive(true); BuildEditor(componentDescriptor, descriptors); } else { DestroyEditor(); } }
private IComponentDescriptor ResolveNonDisabledDescriptorByComponentId(string componentId) { IComponentDescriptor descriptor = registry.Components[componentId]; if (descriptor == null) { throw new RuntimeException(string.Format("Could not resolve component with id '{0}' because it does not appear to be registered.", componentId)); } if (descriptor.IsDisabled) { throw new RuntimeException(string.Format("Could not resolve component with id '{0}' because it has been disabled. Reason: {1}", componentId, descriptor.DisabledReason)); } return(descriptor); }
/// <summary> /// Looks up the VHDL file path of a VHDL-generated component. /// </summary> /// <param name="desc">component descriptor</param> /// <returns>its VHDL file path</returns> public static string GetInstancePath(IComponentDescriptor desc) { var cur = (DescriptorBase)desc; string path = ""; while (cur.Owner is IComponentDescriptor) { var gi = cur.QueryAttribute <VHDLGenInfo>(); path = "/" + gi.InstanceName + path; cur = cur.Owner; } var git = cur.QueryAttribute <VHDLGenInfo>(); path = "/" + git.EntityName; return(path); }
/// <summary> /// Creates and adds a new symbolic process (i.e. without specification of behavior). /// </summary> /// <param name="me">component descriptor to host the new process</param> /// <param name="kind">kind of process</param> /// <param name="name">name of the new process</param> /// <param name="sensitivity">sensitivity list of the new process</param> /// <returns>the descriptor of the new process</returns> public static ProcessDescriptor CreateProcess(this IComponentDescriptor me, Process.EProcessKind kind, string name, params ISignalOrPortDescriptor[] sensitivity) { Contract.Requires <ArgumentNullException>(me != null); Contract.Requires <ArgumentNullException>(name != null); Contract.Requires <ArgumentNullException>(sensitivity != null); ProcessDescriptor pd = new ProcessDescriptor(name) { Kind = kind, Sensitivity = sensitivity }; me.AddChild(pd, pd.Name); return(pd); }
private void ComponentDFS(IComponentDescriptor component) { IDependencyOrdered ordered = component as IDependencyOrdered; if (ordered.DependencyOrder >= 0) { return; } foreach (IComponentDescriptor child in component.GetChildComponents()) { ComponentDFS(child); } ordered.DependencyOrder = _curOrder++; }
public void GenerateComponent(IProject project, IComponentDescriptor cdesc) { var docproj = project as DocumentationProject; if (docproj == null) throw new ArgumentException("Expected a documentation project"); var docs = ((DescriptorBase)cdesc).GetDocumentation(); string prefix = cdesc.GetFullName().Replace(".", "/"); foreach (var doc in docs.Documents) { string legalName = doc.Name.Replace('<', '_').Replace('>', '_'); string name = prefix + "/" + legalName; string path = docproj.AddFile(name); var fs = LongPathFile.Open(path, FileMode.Create, FileAccess.Write); var wr = new StreamWriter(fs); wr.WriteLine(doc.Content.ToString()); wr.Close(); } }
protected virtual void TryCreateGizmos(IComponentDescriptor componentDescriptor) { if (componentDescriptor != null && componentDescriptor.GizmoType != null && IsComponentEnabled) { List <Component> gizmos = new List <Component>(); RuntimeWindow[] windows = m_editor.Windows; for (int i = 0; i < windows.Length; ++i) { RuntimeWindow window = windows[i]; if (window.WindowType == RuntimeWindowType.Scene) { TryCreateGizmos(componentDescriptor, gizmos, window); } } m_gizmos = gizmos.ToArray(); } }
private void OnExpanded(bool expanded) { IsComponentExpanded = expanded; if (expanded) { IComponentDescriptor componentDescriptor = GetComponentDescriptor(); PropertyDescriptor[] descriptors = m_editorsMap.GetPropertyDescriptors(Component.GetType(), this, m_converter); if (ExpanderGraphics != null) { ExpanderGraphics.SetActive(true); } BuildEditor(componentDescriptor, descriptors); } else { DestroyEditor(); } }
public void GenerateComponent(IProject project, IComponentDescriptor cd) { string name = GetComponentName(cd); string fname = MakeVHDSourceFileName(name); string path = project.AddFile(fname); project.AddFileAttribute(fname, cd); if (cd.Library != null) project.SetFileLibrary(fname, cd.Library); _sim.PushScope(); MemoryStream ms = new MemoryStream(); StreamWriter sw = new StreamWriter(ms); IndentedTextWriter tw = new IndentedTextWriter(sw, " "); _curComponent = cd; ClearDependencies(); DeclareEntity(cd, tw); tw.WriteLine(); GenerateArchitecture(cd, tw); tw.Flush(); sw = new StreamWriter(path); tw = new IndentedTextWriter(sw, " "); CreateFileHeader(new GeneratorInfo(name), tw); GenerateDependencies((IPackageOrComponentDescriptor)cd, tw); tw.Flush(); ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(sw.BaseStream); ms.Close(); tw.Close(); sw.Close(); _curComponent = null; _sim.PopScope(); InstanceDescriptor icd = cd as InstanceDescriptor; if (icd != null) { object[] attrs = icd.Instance.GetType().GetCustomAttributes(typeof(ComponentPurpose), true); if (attrs.Length > 0) { ComponentPurpose purpose = (ComponentPurpose)attrs.First(); project.AddFileAttribute(fname, purpose.Purpose); } } var gi = new VHDLGenInfo(name, "inst_" + name, "behavioral", fname); var d = (DescriptorBase)cd; d.AddAttribute(gi); }
// 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(");"); //} }
private void GenerateArchitecture(IComponentDescriptor cd, IndentedTextWriter tw) { string name = GetComponentName(cd); tw.WriteLine("architecture behavioral of " + name + " is"); tw.Indent++; foreach (TypeDescriptor td in cd.GetTypes()) { GenerateTypeDecl(td, tw); } if (cd.GetTypes().Count() > 0) tw.WriteLine(); var components = cd.GetChildComponents() .Cast<ComponentDescriptor>() .Select(c => c.Instance.Representant) .Distinct() .Select(c => c.Descriptor); foreach (ComponentDescriptor scd in components) { DeclareComponent(scd, tw); tw.WriteLine(); } foreach (FieldDescriptor field in cd.GetConstants()) { DeclareField(field, tw); } if (cd.GetConstants().Count() > 0) tw.WriteLine(); foreach (FieldDescriptor field in cd.GetVariables()) { DeclareField(field, tw); } if (cd.GetVariables().Count() > 0) tw.WriteLine(); foreach (ISignalOrPortDescriptor sd in cd.GetSignals()) { object initVal = sd.InitialValue; string initSuffix = ""; if (initVal != null) initSuffix = " := " + GetValueID(initVal); string sname = MakeIDName(sd.Name, sd); tw.WriteLine("signal " + sname + ": " + GetTypeDescriptorCompletedName(sd.ElementType) + initSuffix + ";"); } if (cd.GetSignals().Count() > 0) tw.WriteLine(); foreach (MethodDescriptor md in cd.GetActiveMethods()) { GenerateMethodImpl(md, tw); tw.WriteLine(); } if (cd.GetActiveMethods().Count() > 0) tw.WriteLine(); tw.Indent--; tw.WriteLine("begin"); tw.Indent++; foreach (IComponentDescriptor scd in cd.GetChildComponents()) { DeclareComponentInstance(scd, tw); tw.WriteLine(); } foreach (ProcessDescriptor pd in cd.GetProcesses()) { DeclareProcess(pd, tw); tw.WriteLine(); } tw.Indent--; tw.WriteLine("end behavioral;"); }
public ComponentDetailsTreeModel(IComponentDescriptor componentDescriptor) { this.componentDescriptor = componentDescriptor; }
// ALTERADA public void GenerateComponent(IProject project, IComponentDescriptor cd) { string name = GetComponentName(cd); string fname = MakeSysCHeaderFileName(name); string path = project.AddFile(fname); bool IsTopComponent = (name == "top0") ? true : false; project.AddFileAttribute(fname, cd); if (cd.Library != null) project.SetFileLibrary(fname, cd.Library); _sim.PushScope(); MemoryStream ms = new MemoryStream(); StreamWriter sw = new StreamWriter(ms); IndentedTextWriter tw = new IndentedTextWriter(sw, " "); _curComponent = cd; ClearDependencies(); DeclareAndGenerateModule(cd, tw); tw.Flush(); sw = new StreamWriter(path); tw = new IndentedTextWriter(sw, " "); CreateFileHeader(new GeneratorInfo(fname), tw); GeneratePreProcDir(cd, tw); GenerateDependencies(cd, tw, null); tw.Flush(); ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(sw.BaseStream); ms.Close(); tw.Close(); sw.Close(); _curComponent = null; _sim.PopScope(); InstanceDescriptor icd = cd as InstanceDescriptor; if (icd != null) { object[] attrs = icd.Instance.GetType().GetCustomAttributes(typeof(ComponentPurpose), true); if (attrs.Length > 0) { ComponentPurpose purpose = (ComponentPurpose)attrs.First(); project.AddFileAttribute(fname, purpose.Purpose); } } if (IsTopComponent) { GenerateMainFile(project, cd); } }
// ADDED private void GenerateMainFile(IProject project, IComponentDescriptor cd) { string fname = MakeSysCSourceFileName("main"); string path = project.AddFile(fname); StreamWriter sw = new StreamWriter(path); IndentedTextWriter tw = new IndentedTextWriter(sw, " "); string SimTimeUnit; CreateFileHeader(new GeneratorInfo(fname), tw); GenerateDependencies(null, tw, GetComponentName(cd)); // Get Simulation Time switch (SimTime.Unit) { case ETimeUnit.fs: SimTimeUnit = "SC_FS"; break; case ETimeUnit.ps: SimTimeUnit = "SC_PS"; break; case ETimeUnit.ns: SimTimeUnit = "SC_NS"; break; case ETimeUnit.us: SimTimeUnit = "SC_US"; break; case ETimeUnit.ms: SimTimeUnit = "SC_MS"; break; case ETimeUnit.sec: SimTimeUnit = "SC_SEC"; break; default: throw new NotImplementedException(); } tw.WriteLine(); tw.WriteLine("int sc_main(int argc, char* argv[])"); tw.WriteLine("{"); tw.Indent++; tw.WriteLine("sc_report_handler::set_actions (SC_WARNING, SC_DO_NOTHING);"); tw.WriteLine(); tw.WriteLine(GetComponentName(cd) + " " + GetComponentName(((ComponentDescriptor)cd).Instance.Representant.Descriptor) + "(\"" + GetComponentName(cd) + "\");"); tw.WriteLine(); tw.WriteLine("sc_start(" + SimTime.Value + ", " + SimTimeUnit + ");"); tw.WriteLine(); tw.WriteLine("return 0;"); tw.Indent--; tw.WriteLine("}"); tw.Flush(); tw.Close(); sw.Close(); }
// ALTERADA private void DeclareComponentInstance(IComponentDescriptor cd, IndentedTextWriter tw) { string name = MakeIDName(GetComponentName(cd), cd) + "_"; //string subcompname = GetComponentName(((ComponentDescriptor)cd).Instance.Representant.Descriptor); tw.Write(name + "(" + "\"" + name + "\"" + ")"); }
private void DeclareComponent(IComponentDescriptor cd, IndentedTextWriter tw) { string name = GetComponentName(cd); tw.WriteLine("component " + name + " is"); tw.Indent++; DeclarePortList(cd, tw, true); tw.Indent--; tw.Indent--; tw.WriteLine("end component;"); }
private void ComponentDFS(IComponentDescriptor component) { IDependencyOrdered ordered = component as IDependencyOrdered; if (ordered.DependencyOrder >= 0) return; foreach (IComponentDescriptor child in component.GetChildComponents()) ComponentDFS(child); ordered.DependencyOrder = _curOrder++; }
public StmtTypeResolver(DesignDescriptor design, IComponentDescriptor component) { _design = design; CurComponent = component; _stack.Push((IPackageOrComponentDescriptor)component); }
public string GetComponentID(IComponentDescriptor cdesc) { return cdesc.Name; }
private void DeclareEntity(IComponentDescriptor cd, IndentedTextWriter tw) { string name = GetComponentName(cd); tw.WriteLine("entity " + name + " is"); tw.Indent++; DeclarePortList(cd, tw, false); tw.Indent--; tw.Indent--; tw.WriteLine("end " + name + ";"); }
// ADDED private void GeneratePreProcDir(IComponentDescriptor cd, IndentedTextWriter tw) { string name = GetComponentName(cd).ToUpper() + "_H"; tw.WriteLine("#ifndef " + name); tw.WriteLine("#define " + name); }
private void DeclarePortList(IComponentDescriptor cd, IndentedTextWriter tw, bool extScope) { if (cd.GetPorts().Count() == 0) return; tw.WriteLine("port ("); tw.Indent++; bool first = true; ScopedIdentifierManager xsim = _sim; if (extScope) { xsim = _sim.Fork(); xsim.PushScope(); } foreach (IPortDescriptor pd in cd.GetPorts()) { if (first) first = false; else tw.WriteLine(";"); string pid = MakeIDName(pd.Name, pd.BoundSignal, xsim); tw.Write(pid + ": " + PortDirectionToString(pd.Direction) + " " + GetTypeDescriptorCompletedName(pd.ElementType)); if (pd.Direction != EFlowDirection.In && pd.InitialValue != null) { tw.Write(" := "); tw.Write(GetValueID(pd.InitialValue)); } } tw.WriteLine(");"); }
// ADDED private void GenerateCtor(IComponentDescriptor cd, IndentedTextWriter tw) { string name = GetComponentName(cd); bool first = true; tw.Write("SC_CTOR(" + name + ")"); tw.Indent++; // Initialization List foreach (ISignalDescriptor signal in cd.GetSignals()) { if (signal.ElementType.CILType.IsArray) { if (first) { first = false; tw.Write(": "); } else tw.Write(", "); DeclareSignalVecInstance(signal, tw); } } if (cd.GetPorts() != null) { var xsim = _sim.Fork(); xsim.PushScope(); foreach (IPortDescriptor pd in cd.GetPorts()) { if (pd.ElementType.CILType.IsArray) { if (first) { first = false; tw.Write(": "); } else tw.Write(", "); string pname = MakeIDName(pd.Name, pd.BoundSignal.RemoveIndex(), xsim); tw.Write(pname + "(" + "\"" + pname + "\", " + pd.ElementType.TypeParams[0] + ")"); } } } var components = cd.GetChildComponents(); //.Cast<ComponentDescriptor>() //.Select(c => c.Instance.Representant) //.Distinct() //.Select(c => c.Descriptor); foreach (IComponentDescriptor scd in components) { if (first) { first = false; tw.Write(": "); } else tw.Write(", "); DeclareComponentInstance(scd, tw); } tw.WriteLine(); tw.Indent--; tw.WriteLine("{"); tw.Indent++; // Initialize Ports if (cd.GetPorts() != null) { var xsim = _sim.Fork(); xsim.PushScope(); foreach (IPortDescriptor pd in cd.GetPorts()) { if ((pd.Direction == EFlowDirection.Out) && (pd.InitialValue != null) && !pd.ElementType.CILType.IsArray) { string pname = MakeIDName(pd.Name, pd.BoundSignal.RemoveIndex(), xsim); tw.WriteLine(pname + ".initialize(" + SystemCifyConstant(pd.InitialValue) + ");"); } } } tw.WriteLine(); // Process Registration and Sensitivity List foreach (ProcessDescriptor pd in cd.GetProcesses()) { InitializeProcess(pd, tw); } if (cd.GetProcesses().Count() > 0) tw.WriteLine(); // Module Variable/Constant Initialization foreach (FieldDescriptor field in cd.GetVariables()) { InitializeField(field, tw); } if (cd.GetVariables().Count() > 0) tw.WriteLine(); foreach (FieldDescriptor field in cd.GetConstants()) { InitializeField(field, tw); } if (cd.GetVariables().Count() > 0) tw.WriteLine(); // Signals Initialization foreach (ISignalDescriptor signal in cd.GetSignals()) { InitializeSignal(signal, tw); } if (cd.GetSignals().Count() > 0) tw.WriteLine(); // Port Binding foreach (IComponentDescriptor scd in cd.GetChildComponents()) { PortBinding(scd, tw); } tw.Indent--; tw.WriteLine("}"); }
public string GetComponentID(IComponentDescriptor cd) { return GetComponentName(cd); }
private void GenerateDependencies(IComponentDescriptor desc, IndentedTextWriter tw, string top) { // Due to their compile-time overhead, fixed-point data types are omitted from the // default SystemC include file. To enable fixed-point data types, SC_INCLUDE_FX // must be defined prior to including the SystemC header file tw.WriteLine("#define SC_INCLUDE_FX"); foreach (SysCLib lib in _stdLibraries) { if (lib.Name != "#define SC_INCLUDE_FX") tw.WriteLine("#include " + "\"" + lib.Name + "\""); } IPackageOrComponentDescriptor aux = (IPackageOrComponentDescriptor)desc; if (aux != null) { var pds = aux.Dependencies .Where(pd => pd != aux && !pd.IsEmpty) .GroupBy(pd => GetLibrary(pd)); foreach (var grp in pds) { //tw.WriteLine("library {0};", grp.Key); foreach (var pd in grp) { tw.WriteLine("#include \"" + MakeIDName(pd.PackageName, pd) + ".h\""); } } //foreach (PackageDescriptor pack in ((DescriptorBase)desc).GetDesign().GetPackages()) //{ // tw.WriteLine("// " + pack.PackageName); //} var components = desc.GetChildComponents() .Cast<ComponentDescriptor>() .Select(c => c.Instance.Representant) .Distinct() .Select(c => c.Descriptor); foreach (ComponentDescriptor scd in components) { tw.WriteLine("#include " + "\"" + GetComponentName(scd) + ".h" + "\""); } } else { tw.WriteLine("#include " + "\"" + top + ".h" + "\""); } tw.WriteLine("#include <iostream>"); tw.WriteLine("#include \"sc_lv_add_ons.h\""); tw.WriteLine("#include \"sc_logic_add_ons.h\""); tw.WriteLine("using namespace sc_core;"); tw.WriteLine("using namespace sc_dt;"); tw.WriteLine("using namespace std;"); tw.WriteLine(); }
private string GetComponentName(IComponentDescriptor cd) { string name; if (cd.Name != null && cd.Name.Length > 0) name = cd.Name; else name = "top"; name = MakeIDName(name, cd, true); return name; }
// ALTERADA - equivalent to "DeclareEntity()" and "GenerateArchitecture()" in VHDLGen.cs private void DeclareAndGenerateModule(IComponentDescriptor cd, IndentedTextWriter tw) { string name = GetComponentName(cd); // Module Declaration tw.WriteLine("SC_MODULE(" + name + ")"); tw.WriteLine("{"); tw.Indent++; tw.WriteLine(); tw.WriteLine("// Port List" ); // Port Declarations DeclarePortList(cd, tw, false); tw.WriteLine(); tw.WriteLine("// Sub-Components"); // Sub-Components Declaration var components = cd.GetChildComponents(); // .Cast<ComponentDescriptor>() // .Select(c => c.Instance.Representant) // .Distinct() // .Select(c => c.Descriptor); foreach (IComponentDescriptor scd in components) { DeclareComponent(scd, tw); } if (cd.GetChildComponents().Count() > 0) tw.WriteLine(); tw.WriteLine("// Local Channels"); // Local Channel Declaration foreach (ISignalOrPortDescriptor sd in cd.GetSignals()) { //object initVal = sd.InitialValue; //string initSuffix = ""; //if (initVal != null) // initSuffix = ".write( " + GetValueID(initVal); string sname = MakeIDName(sd.Name, sd); if (sd.ElementType.CILType.IsEnum) { tw.WriteLine("sc_signal<int> " + sname + ";"); } else if (sd.ElementType.CILType.IsArray) { tw.WriteLine("sc_vector< sc_signal<" + GetTypeDescriptorCompletedName(sd.ElementType.Element0Type) + "> > " + sname + ";"); } else { tw.WriteLine("sc_signal<" + GetTypeDescriptorCompletedName(sd.ElementType) + "> " + sname + ";"); } } if (cd.GetSignals().Count() > 0) tw.WriteLine(); tw.WriteLine("// Constants"); // Constant Declarations foreach (FieldDescriptor field in cd.GetConstants()) { DeclareField(field, tw); } if (cd.GetConstants().Count() > 0) tw.WriteLine(); tw.WriteLine("// Variables"); // Variables Declaration foreach (FieldDescriptor field in cd.GetVariables()) { DeclareField(field, tw); } if (cd.GetVariables().Count() > 0) tw.WriteLine(); tw.WriteLine("// Processes"); // Process Declaration foreach (ProcessDescriptor pd in cd.GetProcesses()) { DeclareProcess(pd, tw); tw.WriteLine(); } // Other Methods Declaration //tw.WriteLine("// Funcoes/Procedimentos: "); //foreach (MethodDescriptor md in cd.GetMethods()) //{ // GenerateMethodImpl(md, tw); // tw.WriteLine(); //} //if (cd.GetMethods().Count() > 0) // tw.WriteLine(); tw.WriteLine("// Active functions/methods "); foreach (MethodDescriptor md in cd.GetActiveMethods()) { GenerateMethodImpl(md, tw); tw.WriteLine(); } if (cd.GetMethods().Count() > 0) tw.WriteLine(); // Constructors tw.WriteLine("// Constructor"); GenerateCtor(cd, tw); tw.Indent--; tw.WriteLine("};"); tw.WriteLine("#endif"); }
// ALTERADA private void DeclarePortList(IComponentDescriptor cd, IndentedTextWriter tw, bool extScope) { if (cd.GetPorts().Count() == 0) return; ScopedIdentifierManager xsim = _sim; if (extScope) { xsim = _sim.Fork(); xsim.PushScope(); } foreach (IPortDescriptor pd in cd.GetPorts()) { string pid = MakeIDName(pd.Name, pd.BoundSignal, xsim); if (!pd.ElementType.CILType.IsArray) { tw.WriteLine("sc_" + PortDirectionToString(pd.Direction) + "<" + GetTypeDescriptorCompletedName(pd.ElementType) + "> " + pid + ";"); } else { tw.WriteLine("sc_vector< sc_" + PortDirectionToString(pd.Direction) + "<" + GetTypeDescriptorCompletedName(pd.ElementType.Element0Type) + "> > " + pid + ";"); } } }
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--; }