int compareByChannelPriority(StateTransition x, StateTransition y) { SyncRule xr = (SyncRule)x.Rules.SingleOrDefault(r => r is SyncRule); SyncRule yr = (SyncRule)y.Rules.SingleOrDefault(r => r is SyncRule); // no sync rules are last if (xr == null && yr == null) { return(x.Name.CompareTo(y.Name)); } if (xr == null) { return(-1); } if (yr == null) { return(1); } // both have sync rules int xp = _decls.getChannelPriority(xr.Expr); int yp = _decls.getChannelPriority(yr.Expr); return(xp.CompareTo(yp)); }
private string getSyncChannel(Template t, StateTransition st, SyncRule.Direction dir) { SyncRule r = (SyncRule)st.Rules.SingleOrDefault(x => x is SyncRule); if (r == null) { return(NULL); } if (r.Dir != dir) { return(NULL); } return(getSyncChannelCode(getUniqueName, t, r)); }
public static string getSyncChannelCode(GetNameDelegate getname, Template t, SyncRule r) { VarDecl vd; switch (r.Expr.Type) { case Expression.ExpType.Func: // might be array/range if (r.Expr.Func != Expression.Funcs.ArrayIndex) { throw new CodeGenException("Only array dereferencing allowed on channels!"); } if (r.Expr.First.Type != Expression.ExpType.Var) { throw new CodeGenException("Synchronization rule must be a channel!"); } int idx; if (t.Declarations.getExprValue(r.Expr.Second, out idx)) { vd = t.Declarations.getVar(r.Expr.First.Var); if (vd == null || vd.Type.Type != VarType.Channel) { throw new CodeGenException(String.Format("Could not find '{0}' in declarations for template '{1}' or GLOBALly!", r.Expr.First.Var, t.Name)); } return(String.Format("{0}_ARRAY[{1}]", getname(vd), idx - vd.ArrLow)); } else { // add support for this later throw new CodeGenException("Channel array index must be a constant, dynamic channel index not yet support (but will be)!"); } case Expression.ExpType.Var: vd = t.Declarations.getVar(r.Expr.Var); if (vd == null || vd.Type.Type != VarType.Channel) { throw new CodeGenException(String.Format("Could not find '{0}' in declarations for template '{1}' or GLOBALly!", r.Expr.Var, t.Name)); } return(String.Format("&{0}", getname(vd))); default: throw new CodeGenException("Synchronization rule must be a channel"); } }