Esempio n. 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();
        }
Esempio n. 2
0
        public void Connect()
        {
            if (DefaultLength == -1)
            {
                if (Fields.Count != 0)
                {
                    DefaultLength = Fields.Select(f => f.Range.EndOffset).ToList().Max();
                }
                else
                {
                    DefaultLength = 0;
                }
            }

            if (Switch == null)
            {
                return;
            }

            foreach (var protocol in Switch.Cases.Select(tmp => ProtocolLibrary.GetProtocol(tmp.Protocol)).Where(protocol => protocol != null))
            {
                protocol.AddParent(this);
                Children.Add(protocol);

                protocol.Connect();

                Dependants.Add(protocol);
                Dependants.UnionWith(protocol.Dependants);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Resolves the field from string Name using library. Should only be involked after redundancy pruning.
 /// </summary>
 /// <param name="library"></param>
 public void ResolveField()
 {
     Target = ProtocolLibrary.GetField(Parent.Name, FieldID);
     if (Parent.Switch.Cases.Count > 0)
     {
         Target.RequiredInBackground = true;
     }
 }
Esempio n. 4
0
 private int MaxDistanceToRoot()
 {
     if (ProtocolLibrary.GetRoot().Equals(this))
     {
         return(0);
     }
     return(Parents.Select(parent => parent.MaxDistanceToRoot()).Max() + 1);
 }
Esempio n. 5
0
        public GpfProgram GetProgram()
        {
            var length = 0;

            foreach (var layer in RuleProgram)
            {
                var protocols = layer.Records.Select(s => s.Protocol);

                var lengths = new List <int>();
                foreach (var protocol in protocols)
                {
                    //if protocol has dependents then whole default length must be included
                    if (protocol.Dependants.Count > 0)
                    {
                        lengths.Add(protocol.DefaultLength);
                    }
                    else
                    {
                        //terminal protocol - dont need full length
                        int max = int.MinValue;
                        foreach (Field w in protocol.Fields)
                        {
                            if (w.IsResult || w.Filters.Count > 0)
                            {
                                max = Math.Max(max, w.Range.EndOffset);
                            }
                        }
                        lengths.Add(max);
                    }
                }
                length += lengths.Max();
            }

            length = length - RuleProgram[0].Cache.Buckets[0].BitOffset;
            length = length / 8 + (length % 8 == 0 ? 0 : 1);

            //update root to shift off unused start bytes
            var start = RuleProgram[0].Cache.Buckets[0].ByteOffset;

            ProtocolLibrary.RealignRoot(start);
            RuleProgram[0].Cache.Buckets.ForEach(b => b.BitOffset -= start * 8);

            RecordStartByte  = start;
            RecordLengthByte = length;
            return(new GpfProgram(this));
        }
Esempio n. 6
0
        public static void Compile(List <Protocol> protocols)
        {
            Layers.Clear();
            ProgramSet.RuleProgram.Clear();

            var rootLayer = new ProgramLayer();

            rootLayer.AddProtocol(ProtocolLibrary.GetRoot());
            Layers.Add(rootLayer);

            foreach (var p in protocols)
            {
                AddProtocol(p);
            }

            Validate();

            //generate the program set beased on statically available Layers var
            ProgramSet.Generate();
        }
Esempio n. 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;
            }
        }
Esempio n. 8
0
        public AndTransaction(AndString input)
        {
            this.Transactions = new List <PredicateReadTransaction>();
            for (int index = 0; index < input.List.Count; index++)
            {
                var  atom   = input.List[index];
                bool invert = false;
                PredicateReadTransaction tmp;
                if (atom.AtomType == PredicateAtomType.Not)
                {
                    atom   = ((NotAtom)atom).Operand;
                    invert = true;
                }

                switch (atom.AtomType)
                {
                case PredicateAtomType.SubPredicate:
                    var pred = ((SubPredicateAtom)atom);
                    tmp = new PredicateReadTransaction(PredInLoc.BoolRuleMemory, pred.Predicate.WriteIndex, invert);
                    break;

                case PredicateAtomType.Protocol:
                    var proto = ProtocolLibrary.GetProtocol(((ProtocolAtom)atom).Protocol);
                    tmp = new PredicateReadTransaction(PredInLoc.BoolRuleMemory, proto.RuleIndex);
                    break;

                case PredicateAtomType.Filter:
                    var filter = ((FilterAtom)atom);
                    var f      = ProtocolLibrary.GetFieldFilter(filter.Protocol, filter.Field, filter.Filter);
                    tmp = new PredicateReadTransaction(PredInLoc.BoolRuleMemory, f.RuleIndex);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                Transactions.Add(tmp);
            }
        }
Esempio n. 9
0
        public void GenerateTargets(Kernel kernel)
        {
            switch (kernel.Type)
            {
            case KernelType.Field:
                var field = ProtocolLibrary.GetField(((FieldKernel)kernel).Protocol,
                                                     ((FieldKernel)kernel).Field);
                field.StoreAsResult();
                Fields.Add(field);
                break;

            case KernelType.Filter:
                var k         = (FilterKernel)kernel;
                var protocols = ProtocolLibrary.GetProtocols(k.Filter.ProtocolTargets);
                protocols.ForEach(p => p.StoreAsRule());
                Protocols.UnionWith(protocols);

                var filters = ProtocolLibrary.GetFieldFilters(k.Filter.FilterTargets);
                filters.ForEach(ff => ff.StoreAsRule());
                Filters.UnionWith(filters);

                break;
            }
        }
Esempio n. 10
0
 public KernelReadRecord(FieldKernel kernel)
 {
     ID             = kernel.ID;
     IntResultIndex = ProtocolLibrary.GetField(kernel.Protocol, kernel.Field).ResultIndex;
 }