Esempio n. 1
0
        internal virtual Tuple <DataTypeBase, DataTypeBase> transform(DataProcessorConfig config)
        {
            switch (config.id)
            {
            case DataProcessorConfig.BufferConfig.ID:
                return(Tuple.Create(
                           new IntegralDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY, new DataAttributes(new byte[] { }, 0, 0, false)) as DataTypeBase,
                           dataProcessorStateCopy(this, this.attributes)
                           ));

            case DataProcessorConfig.AccumulatorConfig.ID: {
                DataProcessorConfig.AccumulatorConfig casted = (DataProcessorConfig.AccumulatorConfig)config;
                DataAttributes attributes = new DataAttributes(new byte[] { casted.output }, 1, 0, !casted.counter && this.attributes.signed);

                return(Tuple.Create(
                           casted.counter ? new IntegralDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY, attributes) : dataProcessorCopy(this, attributes),
                           casted.counter ? new IntegralDataType(null, DATA_PROCESSOR, Util.setRead(DataProcessor.STATE), NO_ID, attributes) :
                           dataProcessorStateCopy(this, attributes)
                           ));
            }

            case DataProcessorConfig.AverageConfig.ID:
            case DataProcessorConfig.DelayConfig.ID:
            case DataProcessorConfig.TimeConfig.ID:
                return(Tuple.Create <DataTypeBase, DataTypeBase>(dataProcessorCopy(this, this.attributes.dataProcessorCopy()), null));

            case DataProcessorConfig.PassthroughConfig.ID:
                return(Tuple.Create(
                           dataProcessorCopy(this, this.attributes.dataProcessorCopy()),
                           new IntegralDataType(DATA_PROCESSOR, Util.setRead(DataProcessor.STATE), NO_ID, new DataAttributes(new byte[] { 2 }, 1, 0, false)) as DataTypeBase
                           ));

            case DataProcessorConfig.MathConfig.ID: {
                DataProcessorConfig.MathConfig casted = (DataProcessorConfig.MathConfig)config;
                DataTypeBase processor = null;
                switch (casted.op)
                {
                case Add:
                    processor = dataProcessorCopy(this, this.attributes.dataProcessorCopySize(4));
                    break;

                case Multiply:
                    processor = dataProcessorCopy(this, this.attributes.dataProcessorCopySize(Math.Abs(casted.rhs) < 1 ? this.attributes.sizes[0] : (byte)4));
                    break;

                case Divide:
                    processor = dataProcessorCopy(this, this.attributes.dataProcessorCopySize(Math.Abs(casted.rhs) < 1 ? (byte)4 : this.attributes.sizes[0]));
                    break;

                case Subtract:
                    processor = dataProcessorCopy(this, this.attributes.dataProcessorCopySigned(true));
                    break;

                case AbsValue:
                    processor = dataProcessorCopy(this, this.attributes.dataProcessorCopySigned(false));
                    break;

                case Modulus:
                    processor = dataProcessorCopy(this, this.attributes.dataProcessorCopy());
                    break;

                case Exponent:
                    processor = new ByteArrayDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY, this.attributes.dataProcessorCopySize(4));
                    break;

                case LeftShift:
                    processor = new ByteArrayDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY,
                                                      this.attributes.dataProcessorCopySize((byte)Math.Min(this.attributes.sizes[0] + (casted.rhs / 8), 4)));
                    break;

                case RightShift:
                    processor = new ByteArrayDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY,
                                                      this.attributes.dataProcessorCopySize((byte)Math.Max(this.attributes.sizes[0] - (casted.rhs / 8), 1)));
                    break;

                case Sqrt:
                    processor = new ByteArrayDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY, this.attributes.dataProcessorCopySigned(false));
                    break;

                case Constant:
                    DataAttributes attributes = new DataAttributes(new byte[] { 4 }, (byte)1, (byte)0, casted.rhs >= 0);
                    processor = new IntegralDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY, attributes);
                    break;
                }
                if (processor != null)
                {
                    return(Tuple.Create <DataTypeBase, DataTypeBase>(processor, null));
                }
                break;
            }

            case DataProcessorConfig.PulseConfig.ID: {
                DataProcessorConfig.PulseConfig casted = (DataProcessorConfig.PulseConfig)config;
                DataTypeBase processor = null;
                switch (casted.mode)
                {
                case Width:
                    processor = new IntegralDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY, new DataAttributes(new byte[] { 2 }, 1, 0, false));
                    break;

                case Area:
                    processor = dataProcessorCopy(this, attributes.dataProcessorCopySize(4));
                    break;

                case Peak:
                    processor = dataProcessorCopy(this, attributes.dataProcessorCopy());
                    break;

                case OnDetect:
                    processor = new IntegralDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY, new DataAttributes(new byte[] { 1 }, 1, 0, false));
                    break;
                }
                if (processor != null)
                {
                    return(Tuple.Create <DataTypeBase, DataTypeBase>(processor, null));
                }
                break;
            }

            case DataProcessorConfig.ComparisonConfig.ID: {
                DataTypeBase processor = null;
                if (config is DataProcessorConfig.SingleValueComparisonConfig)
                {
                    processor = dataProcessorCopy(this, attributes.dataProcessorCopy());
                }
                else if (config is DataProcessorConfig.MultiValueComparisonConfig)
                {
                    DataProcessorConfig.MultiValueComparisonConfig casted = (DataProcessorConfig.MultiValueComparisonConfig)config;
                    if (casted.mode == ComparisonOutput.PassFail || casted.mode == ComparisonOutput.Zone)
                    {
                        processor = new IntegralDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY, new DataAttributes(new byte[] { 1 }, 1, 0, false));
                    }
                    else
                    {
                        processor = dataProcessorCopy(this, attributes.dataProcessorCopy());
                    }
                }
                if (processor != null)
                {
                    return(Tuple.Create <DataTypeBase, DataTypeBase>(processor, null));
                }
                break;
            }

            case DataProcessorConfig.ThresholdConfig.ID: {
                DataProcessorConfig.ThresholdConfig casted = (DataProcessorConfig.ThresholdConfig)config;
                switch (casted.mode)
                {
                case Threshold.Absolute:
                    return(Tuple.Create <DataTypeBase, DataTypeBase>(dataProcessorCopy(this, attributes.dataProcessorCopy()), null));

                case Threshold.Binary:
                    return(Tuple.Create <DataTypeBase, DataTypeBase>(new IntegralDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY,
                                                                                          new DataAttributes(new byte[] { 1 }, 1, 0, true)), null));
                }
                break;
            }

            case DataProcessorConfig.DifferentialConfig.ID: {
                DataProcessorConfig.DifferentialConfig casted = (DataProcessorConfig.DifferentialConfig)config;
                switch (casted.mode)
                {
                case Differential.Absolute:
                    return(Tuple.Create <DataTypeBase, DataTypeBase>(dataProcessorCopy(this, attributes.dataProcessorCopy()), null));

                case Differential.Differential:
                    throw new InvalidOperationException("Differential processor in 'difference' mode must be handled by subclasses");

                case Differential.Binary:
                    return(Tuple.Create <DataTypeBase, DataTypeBase>(new IntegralDataType(this, DATA_PROCESSOR, DataProcessor.NOTIFY, new DataAttributes(new byte[] { 1 }, 1, 0, true)), null));
                }
                break;
            }

            case DataProcessorConfig.PackerConfig.ID: {
                DataProcessorConfig.PackerConfig casted = (DataProcessorConfig.PackerConfig)config;
                return(Tuple.Create <DataTypeBase, DataTypeBase>(dataProcessorCopy(this, attributes.dataProcessorCopyCopies(casted.count)), null));
            }

            case DataProcessorConfig.AccounterConfig.ID: {
                DataProcessorConfig.AccounterConfig casted = (DataProcessorConfig.AccounterConfig)config;
                return(Tuple.Create <DataTypeBase, DataTypeBase>(dataProcessorCopy(this, new DataAttributes(new byte[] { casted.length, attributes.length() }, 1, 0, attributes.signed)), null));
            }
            }
            throw new InvalidOperationException("Unable to determine the DataTypeBase object for config: " + Util.arrayToHexString(config.Build()));
        }
Esempio n. 2
0
 internal EditorImplBase(DataProcessorConfig configObj, DataTypeBase source, IModuleBoardBridge bridge) : base(bridge)
 {
     config         = configObj.Build();
     this.source    = source;
     this.configObj = configObj;
 }