/// <summary> /// Performs some checks to see if the network uses features that are not supported by the CPP render /// </summary> /// <param name="network">The network to validate.</param> private static void ValidateNetwork(AST.Network network) { var sp = network.Processes.SelectMany(x => x.InternalBusses).FirstOrDefault(x => x.IsTopLevelInput || x.IsTopLevelOutput); if (sp != null) { throw new Exception($"Cannot have an internal bus that is also toplevel input or output: {sp.Name}"); } }
/// <summary> /// Performs all transformations on a the given network /// </summary> /// <param name="network">The network to transform.</param> /// <param name="directapply">A sequence of visitor classes that are applied without restarting the transformation. This can be used to add metdata or control logic before the actual transformations</param> /// <param name="preapply">Method that returns a sequence of transformations to perform before the main transformations</param> /// <param name="apply">Method that returns a sequence of transformations to perform</param> /// <param name="preapply">Method that returns a sequence of transformations to perform after the main transformations</param> public static void Transform( this AST.Network network, IEnumerable <IASTTransform> directapply = null, Func <Method, IASTTransform[]> preapply = null, Func <Method, IASTTransform[]> apply = null, Func <Method, IASTTransform[]> postapply = null ) { directapply = directapply ?? new IASTTransform[0]; preapply = preapply ?? (x => new IASTTransform[0]); apply = apply ?? (x => new IASTTransform[0]); postapply = postapply ?? (x => new IASTTransform[0]); var methods = new List <Method>(); foreach (var n in network.All((el, direction) => { if (direction == VisitorState.Enter && el is Method) { methods.Add(el as Method); return(true); } return(true); })) { foreach (var f in directapply) { f.Transform(n); } } // Pre-transforms are in Pre-Order foreach (var m in methods) { RepeatedApply(preapply(m), () => m.All()); } // Main transforms are in Post-Order foreach (var m in methods) { RepeatedApply(apply(m), () => m.DepthFirstPostOrder()); } // Post transforms are in Pre-order foreach (var m in methods) { RepeatedApply(postapply(m), () => m.All()); } }
/// <summary> /// Creates all sub-instances for a network /// </summary> /// <param name="state">The state to use</param> /// <param name="network">The parent network instance</param> private Instance.Network CreateAndRegisterInstance(ValidationState state, AST.InstanceDeclaration instDecl, AST.Network network) { // Create the network instance var netinstance = new Instance.Network(instDecl, network); // We have registered the network by this name already //state.TryAddSymbol(netinstance.Name, netinstance); using (state.StartScope(network, netinstance)) CreateAndRegisterInstances(state, netinstance.NetworkDefinition.Declarations, netinstance.Instances); return(netinstance); }
/// <summary> /// Constructs a new instance of the bus /// </summary> /// <param name="source">The process declaration</param> /// <param name="network">The resolved network definition</param> public Network(AST.InstanceDeclaration source, AST.Network network) { Source = source ?? throw new ArgumentNullException(nameof(source)); NetworkDefinition = network ?? throw new ArgumentNullException(nameof(network)); }
public BusImplementations(RenderState rs) { RS = rs; Network = rs.Network; }
public ProcessHeader(RenderState rs, RenderStateProcess process) { RS = rs; Network = rs.Network; RSP = process; }
public SimulationImplementation(RenderState rs) { RS = rs; Network = rs.Network; Graph = new DependencyGraph(RS.Simulation.Processes.Select(x => x.Instance)); }
public BusDefinitions(RenderState rs) { RS = rs; Network = rs.Network; }
public SimulationHeader(RenderState rs) { RS = rs; Network = rs.Network; }
public SharedTypes(RenderState rs) { RS = rs; Network = rs.Network; }
public Makefile(RenderState rs) { RS = rs; Network = rs.Network; }
public CustomTypes(RenderState rs) { RS = rs; Network = RS.Network; }
public TopLevel(RenderState rs) { RS = rs; Network = rs.Network; }