Beispiel #1
0
        public GpfProgram(ProgramSet set)
        {
            RuleProgram   = set.GetRuleProgram();
            FilterProgram = set.GetFilterProgram();
            ProgramMemory = MemoryCoordinator.GetProgramMemory();

            DataStart   = set.RecordStartByte;
            DataLength  = set.RecordLengthByte + slackBytes;
            DataLength += (DataLength % 4 != 0 ? (4 - DataStart % 4) : 0);
            LayerCount  = set.RuleProgram.Count;

            Root = ProtocolLibrary.GetRoot().Identifier;
            //update root start / end
            //ensure records are multiples of 4 bytes
            if (DataLength < 16)
            {
                DataLength = 16;
            }
            if (DataLength % 4 != 0)
            {
                DataLength += 4 - (DataLength % 4);
            }

            FilterNames  = set.Filters.Select(f => f.ID).ToList();
            IntegerNames = set.Reads.Select(f => f.ID).ToList();
        }
Beispiel #2
0
 public int StoreAsRule()
 {
     if (RuleIndex == -1)
     {
         RuleIndex = MemoryCoordinator.GetBoolRuleIndex();
     }
     return(RuleIndex);
 }
Beispiel #3
0
 public int StoreAsResult()
 {
     if (ResultIndex == -1)
     {
         ResultIndex = MemoryCoordinator.GetIntResultIndex();
     }
     return(ResultIndex);
 }
Beispiel #4
0
 public static void Clear()
 {
     MemoryCoordinator.Reset();
     GpfProgramCompiler.Clear();
     Protocols.Clear();
     Kernels.Clear();
     head = null;
 }
Beispiel #5
0
        public int StoreAsRule()
        {
            if (RuleIndex != -1)
            {
                return(RuleIndex);
            }

            //get a new bool rule index
            //get the fields referenced in the parents switch statements, store them, and then set
            //their relevant filter(s) to the rule index generagted above

            //get a lis of parent protocols -> those protocols that have a switch statement connecting them to this protocol
            var parents = ProtocolLibrary.Protocols.Values.Where(p => p.Switch != null && p.Switch.Cases.Exists(s => s.Protocol == Name)).ToList();

            //var test = new List<int>();
            ////check parents to ensure a rule id doesnt already exit (by accidentally or intentionally referencing the full path to the protocol
            ////from a field filter of the previous protocol (unlikely, but possible);
            ////if single alternative exists, use that value. otherwise write new value if 0 or many defined.

            //foreach (var parent in parents)
            //{
            //    var cases = parent.Switch.Cases.Where(f => f.Protocol == Name).ToList();
            //    foreach (var c in cases)
            //    {
            //        var filters = parent.Switch.Target.Filters.FindAll(f => f.ID == c.Filter).Select(i => i.RuleIndex);
            //        test.AddRange(filters);
            //    }
            //}

            //                                    //.Select(f => f.RuleIndex);
            //test.Remove(-1);

            RuleIndex = MemoryCoordinator.GetBoolRuleIndex();

            //for each of these parent protocols, set the field targeted by the switch statement to a rule field
            foreach (var tmp in parents.Select(parent => parent.Switch))
            {
                RuleFields.Add(tmp.Target);

                //get the name(s) of the relevant filter(s)
                var filterIds = new HashSet <string>(tmp.Cases.FindAll(f => f.Protocol == Name).Select(s => s.Filter));

                //get a list of the relevant filters from their string ids
                var filters = tmp.Target.Filters.FindAll(f => filterIds.Contains(f.ID));

                //for each of these filters, set their result index to the result index of the protocol
                filters.ForEach(f => f.StoreAsProtocolResult(RuleIndex));
            }
            return(RuleIndex);
        }
Beispiel #6
0
        public PredicateTransactionSet(Predicate predicate)
        {
            this.Transactions = new List <PredicateTransaction>();
            if (predicate.Layer > 0)
            {
                predicate.Subpredicates.Sort();

                foreach (var s in predicate.Subpredicates)
                {
                    s.WriteIndex = MemoryCoordinator.GetBoolRuleIndex();
                    Transactions.Add(s.WriteTransaction(PredOutLoc.BoolRuleMemory));
                }
            }
            predicate.WriteIndex = MemoryCoordinator.GetBoolResultIndex();
            Transactions.Add(predicate.WriteTransaction(PredOutLoc.BoolResultMemory));
        }
Beispiel #7
0
        public FilterRecord(FieldFilter filter)
        {
            Name        = filter.ID;
            Comparison  = filter.Comparison;
            LookupIndex = MemoryCoordinator.RegisterStaticInteger(filter.Value);
            RuleIndex   = filter.RuleIndex;
            SwitchValue = 0;

            var protocolSwitch = filter.Parent.Parent.Switch;

            if (protocolSwitch == null)
            {
                return;
            }

            //need to check for empty protocols, and give these a switch of 0
            if (protocolSwitch.Cases.Select(c => c.Filter).ToList().Contains(Name))
            {
                SwitchValue = ProtocolLibrary.GetProtocol(protocolSwitch.Cases.Find(switchCase => switchCase.Filter == Name).Protocol).Identifier;
            }
        }
        public MultTransaction(MultiplicationString input)
        {
            this.Transactions = new List <ExpressionReadTransaction>();
            foreach (var a in input.List)
            {
                if (a.List.Count == 1)
                {
                    ExpressionAtom            atom = a.List[0];
                    ExpressionReadTransaction tmp;
                    switch (atom.AtomType)
                    {
                    case ExpressionAtomType.Static:
                        var stat = (StaticAtom)atom;
                        tmp = new ExpressionReadTransaction(ExprInLoc.Lookup, MemoryCoordinator.RegisterStaticInteger(stat.Value));
                        break;

                    case ExpressionAtomType.Register:
                        var sysreg = (RegisterAtom)atom;
                        tmp = new ExpressionReadTransaction(ExprInLoc.SystemReg, sysreg.RegisterValue);
                        break;

                    case ExpressionAtomType.SubExpression:
                        var sub = (SubExpressionAtom)atom;
                        tmp = new ExpressionReadTransaction(ExprInLoc.RegisterBank, sub.Expression.RegisterIndex);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    Transactions.Add(tmp);
                }
                else
                {
                    throw new Exception("AddTransaction Error: Subtraction not supported in simple strings");
                }
            }
        }