public static INamedTypeSymbol GetTypeByName(TypeDescriptor typeDescriptor, Compilation compilation)
        {
            //return GetTypeByName(typeDescriptor.TypeName, compilation);
            var type = compilation.GetTypeByMetadataName(typeDescriptor.QualifiedMetadataTypeName);

            // Another way to access the info
            if (type == null)
            {
                //var references = compilation.References
                //					.OfType<CompilationReference>()
                //					.ToDictionary(r => r.Compilation.AssemblyName, r => r.Compilation);

                //if (references.ContainsKey(typeDescriptor.AssemblyName))
                //{
                //	compilation = references[typeDescriptor.AssemblyName];
                //}

                Func <string, bool> pred = s => s.Equals(typeDescriptor.ClassName);
                var symbols = compilation.GetSymbolsWithName(pred, SymbolFilter.Type).OfType <INamedTypeSymbol>();

                if (symbols.Count() > 0)
                {
                    type = symbols.SingleOrDefault(t => typeDescriptor.Equals(Utils.CreateTypeDescriptor(t)));
                }
            }

            return(type);
        }
Example #2
0
        /// <summary>
        /// Emits a XIL-S instruction and assigns an index to it.
        /// </summary>
        /// <param name="xilsi">instruction to emit</param>
        protected virtual void Emit(XILSInstr xilsi)
        {
            xilsi.Index = NextOutputInstructionIndex;
            if (CurInstr != null)
            {
                xilsi.CILRef = CurInstr.CILRef;
            }
            int numOperands = xilsi.OperandTypes.Length;

            for (int i = numOperands - 1; i >= 0; i--)
            {
                TypeDescriptor t = _typeStack.Pop();
                if (!t.Equals(xilsi.OperandTypes[i]))
                {
                    throw new ArgumentException("Incompatible operand types");
                }
            }
            foreach (TypeDescriptor result in xilsi.ResultTypes)
            {
                _typeStack.Push(result);
            }
            OutInstructions.Add(xilsi);
            if (xilsi.Name == InstructionCodes.BranchIfFalse ||
                xilsi.Name == InstructionCodes.BranchIfTrue ||
                xilsi.Name == InstructionCodes.Goto)
            {
                _curBB.Clear();
            }
            else
            {
                _curBB.Add(xilsi);
            }
        }
Example #3
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (value is Type && TypeDescriptor.Equals(destinationType, typeof(string)))
            {
                return(((Type)value).FullName);
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Example #4
0
        public IEnumerable <IXILMapping> TryMap(ITransactionSite taSite, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes)
        {
            var fu = taSite.Host;
            //if (fu != _host)
            //    yield break;

            var taNop = taSite as NopTASite;

            if (taNop == null)
            {
                yield break;
            }

            switch (instr.Name)
            {
            case InstructionCodes.Nop:
            case InstructionCodes.Barrier:
                if (instr.Operand is int)
                {
                    yield return(new NopXILMapping(taNop, (int)instr.Operand));
                }
                else
                {
                    yield return(new NopXILMapping(taNop, 0));
                }
                break;

            case InstructionCodes.Convert:
                if (TypeLowering.Instance.HasWireType(operandTypes[0]) &&
                    TypeLowering.Instance.HasWireType(resultTypes[0]) &&
                    !operandTypes[0].CILType.Equals(resultTypes[0].CILType))
                {
                    TypeDescriptor owt = TypeLowering.Instance.GetWireType(operandTypes[0]);
                    TypeDescriptor rwt = TypeLowering.Instance.GetWireType(resultTypes[0]);
                    if (!owt.Equals(rwt))
                    {
                        yield break;
                    }

                    yield return(new IdXILMapping(taNop));
                }
                else
                {
                    yield break;
                }
                break;

            default:
                yield break;
            }
        }
Example #5
0
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }

            if (TypeDescriptor.Equals(destinationType, typeof(Type)))
            {
                return(true);
            }

            return(base.CanConvertTo(context, destinationType));
        }
Example #6
0
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            if (sourceType == null)
            {
                throw new ArgumentNullException("sourceType");
            }

            if (TypeDescriptor.Equals(sourceType, typeof(string)))
            {
                return(true);
            }

            return(base.CanConvertFrom(context, sourceType));
        }
Example #7
0
        private void MakeStringArray(Expression[] elements)
        {
            TypeDescriptor stype = (TypeDescriptor)typeof(string);

            for (int i = 0; i < elements.Length; i++)
            {
                TypeDescriptor rtype = elements[i].ResultType;
                if (!rtype.Equals(stype))
                {
                    elements[i] = IntrinsicFunctions.Cast(
                        elements[i],
                        rtype.CILType, typeof(string));
                }
            }
        }
        public virtual async Task <bool> IsSubtypeAsync(TypeDescriptor typeDescriptor1, TypeDescriptor typeDescriptor2)
        {
            var result = false;

            if (typeDescriptor1.Equals(typeDescriptor2))
            {
                result = true;
            }
            else
            {
                var roslynType1 = RoslynSymbolFactory.GetTypeByName(typeDescriptor1, this.Compilation);

                if (roslynType1 == null && typeDescriptor1.AssemblyName != this.Project.AssemblyName)
                {
                    // We assume if T1 <= T2, then the project (compilation) where T1 is declared must know T2 also
                    var projectProvider = await this.solutionManager.GetProjectCodeProviderAsync(typeDescriptor1.AssemblyName);

                    result = await projectProvider.IsSubtypeAsync(typeDescriptor1, typeDescriptor2);
                }
                else
                {
                    var roslynType2 = RoslynSymbolFactory.GetTypeByName(typeDescriptor2, this.Compilation);

                    if (roslynType2 == null)
                    {
                        // We assume if this project (compilation) knows T1 but don't know T2,
                        // then it cannot be T1 <= T2
                        result = false;
                    }
                    else
                    {
                        result = TypeHelper.InheritsByName(roslynType1, roslynType2);
                    }
                }
            }

            return(result);
        }
Example #9
0
        public IXILMapping TryAllocate(Component host, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes, IProject proj)
        {
            switch (instr.Name)
            {
            case InstructionCodes.Nop:
            case InstructionCodes.Barrier:
                if (instr.Operand is int)
                {
                    return(new NopXILMapping(new NopTASite(host), (int)instr.Operand));
                }
                else
                {
                    return(new NopXILMapping(new NopTASite(host), 0));
                }

            case InstructionCodes.Convert:
                if (TypeLowering.Instance.HasWireType(operandTypes[0]) &&
                    TypeLowering.Instance.HasWireType(resultTypes[0]) &&
                    !operandTypes[0].CILType.Equals(resultTypes[0].CILType))
                {
                    TypeDescriptor owt = TypeLowering.Instance.GetWireType(operandTypes[0]);
                    TypeDescriptor rwt = TypeLowering.Instance.GetWireType(resultTypes[0]);
                    if (!owt.Equals(rwt))
                    {
                        return(null);
                    }

                    return(new IdXILMapping(new NopTASite(host)));
                }
                else
                {
                    return(null);
                }

            default:
                return(null);
            }
        }
        public void TestClass()
        {
            var c2 = new TestClass2();

            Assert.AreEqual(
                BuildResult(
                    "!YamlSerializerTest.YamlRepresenterTest%2BTestClass2",
                    "Items: ",
                    "  Capacity: 0"
                    ),
                YamlSerializer.Serialize(c2)
                );

            c2.Items.Add(new TestClass1());
            Assert.AreEqual(
                BuildResult(
                    "!YamlSerializerTest.YamlRepresenterTest%2BTestClass2",
                    "Items: ",
                    "  Capacity: 4",
                    "  ICollection.Items: ",
                    "    - {}"
                    ),
                YamlSerializer.Serialize(c2)
                );

            c2.Items[0].a = 1;
            Assert.AreEqual(
                BuildResult(
                    "!YamlSerializerTest.YamlRepresenterTest%2BTestClass2",
                    "Items: ",
                    "  Capacity: 4",
                    "  ICollection.Items: ",
                    "    - a: 1"
                    ),
                YamlSerializer.Serialize(c2)
                );

            // Identical values in different numeric types can not be compared
            // after being boxed.
            Assert.IsTrue((0.0).Equals(0));                                  // double.Equals(double) converts int to double before comparison
            Assert.IsFalse(0.0.Equals((object)0));
            Assert.IsFalse(((object)0.0).Equals(0));                         // !!
            Assert.IsFalse(((object)(float)0.0).Equals(0.0));                // !!
            Assert.IsFalse(((object)0.0) == ((object)0));                    // !!
            Assert.IsFalse(ValueType.Equals((object)0.0, (object)0));        // !!
            Assert.IsFalse(ValueType.Equals((object)0.0, (object)(float)0)); // !!
            Assert.IsFalse(((ValueType)0.0) == ((ValueType)0));              // !!
            Assert.IsFalse(((ValueType)0.0) == ((ValueType)0));              // !!
            Assert.IsFalse(Math.Equals((object)0, (object)0.0));             // !!!!
            Assert.IsFalse(TypeDescriptor.Equals((object)0.0, (object)0));
//            Assert.Throws<ArgumentException>(()=> 0.0.CompareTo( (object)0));
//            Assert.Throws<InvalidCastException>(()=> ((double)(object)0).CompareTo((double)(object)(float)0.0));
            Assert.IsTrue(0.0 == (double)(int)(object)0);
            Assert.IsTrue(0.0 == (double)(decimal)(object)(decimal)0);
            Assert.IsTrue(0 == (int)0.0);
            Assert.IsFalse(0 == (int)(double)(object)double.NaN); // !!
            object nan       = double.NaN;
            object doubleNan = (double)nan;

//            Assert.Throws<InvalidCastException>(() => 0.CompareTo((int)doubleNan)); // !!
            Assert.IsFalse(double.NaN == double.NaN);



            Assert.IsTrue(typeof(bool).IsPrimitive);
            Assert.IsTrue(typeof(bool).IsValueType);
            Assert.IsFalse(typeof(bool).IsPointer);
            Assert.IsTrue(typeof(bool).IsSubclassOf(typeof(ValueType)));
            Assert.IsTrue(typeof(bool).IsSerializable);
            Assert.IsFalse(typeof(bool).IsClass);

            Assert.IsTrue(typeof(char).IsPrimitive);
            Assert.IsTrue(typeof(char).IsValueType);
            Assert.IsFalse(typeof(char).IsPointer);
            Assert.IsTrue(typeof(char).IsSubclassOf(typeof(ValueType)));
            Assert.IsTrue(typeof(char).IsSerializable);
            Assert.IsFalse(typeof(char).IsClass);

            Assert.IsTrue(typeof(int).IsPrimitive);
            Assert.IsTrue(typeof(int).IsValueType);
            Assert.IsFalse(typeof(int).IsPointer);
            Assert.IsTrue(typeof(int).IsSubclassOf(typeof(ValueType)));
            Assert.IsTrue(typeof(int).IsSerializable);
            Assert.IsFalse(typeof(int).IsClass);

            Assert.IsTrue(typeof(double).IsPrimitive);
            Assert.IsTrue(typeof(double).IsValueType);
            Assert.IsFalse(typeof(double).IsPointer);
            Assert.IsTrue(typeof(double).IsSubclassOf(typeof(ValueType)));
            Assert.IsTrue(typeof(double).IsSerializable);
            Assert.IsFalse(typeof(double).IsClass);

            Assert.IsFalse(typeof(void *).IsPrimitive);
            Assert.IsFalse(typeof(void *).IsValueType);
            Assert.IsTrue(typeof(void *).IsPointer);
            Assert.IsFalse(typeof(void *).IsSubclassOf(typeof(ValueType)));
            Assert.IsFalse(typeof(void *).IsSerializable);
            Assert.IsTrue(typeof(void *).IsClass);

            Assert.IsTrue(typeof(IntPtr).IsPrimitive);
            Assert.IsTrue(typeof(IntPtr).IsValueType);
            Assert.IsFalse(typeof(IntPtr).IsPointer);     // !
            Assert.IsTrue(typeof(IntPtr).IsSubclassOf(typeof(ValueType)));
            Assert.IsTrue(typeof(IntPtr).IsSerializable); // !
            Assert.IsFalse(typeof(IntPtr).IsClass);

            Assert.IsFalse(typeof(Test1).IsPrimitive);
            Assert.IsTrue(typeof(Test1).IsValueType);
            Assert.IsFalse(typeof(Test1).IsPointer);
            Assert.IsTrue(typeof(Test1).IsSubclassOf(typeof(ValueType)));
            Assert.IsFalse(typeof(Test1).IsSerializable); // !
            Assert.IsFalse(typeof(Test1).IsClass);

            Assert.IsFalse(typeof(string).IsPrimitive);
            Assert.IsFalse(typeof(string).IsValueType);
            Assert.IsFalse(typeof(string).IsPointer);
            Assert.IsFalse(typeof(string).IsSubclassOf(typeof(ValueType)));
            Assert.IsTrue(typeof(string).IsSerializable);
            Assert.IsTrue(typeof(string).IsClass);

            Assert.IsFalse(typeof(decimal).IsPrimitive);
            Assert.IsTrue(typeof(decimal).IsValueType);
            Assert.IsFalse(typeof(decimal).IsPointer);
            Assert.IsTrue(typeof(decimal).IsSubclassOf(typeof(ValueType)));
            Assert.IsTrue(typeof(decimal).IsSerializable);
            Assert.IsFalse(typeof(decimal).IsClass);

            Assert.IsFalse(typeof(Enum).IsPrimitive);
            Assert.IsFalse(typeof(Enum).IsValueType);
            Assert.IsFalse(typeof(Enum).IsPointer);
            Assert.IsTrue(typeof(Enum).IsSubclassOf(typeof(ValueType)));
            Assert.IsTrue(typeof(Enum).IsSerializable);
            Assert.IsFalse(typeof(Enum).IsClass);

            Assert.IsFalse(typeof(Test2).IsPrimitive);
            Assert.IsTrue(typeof(Test2).IsValueType);
            Assert.IsFalse(typeof(Test2).IsPointer);
            Assert.IsTrue(typeof(Test2).IsSubclassOf(typeof(ValueType)));
            Assert.IsTrue(typeof(Test2).IsSerializable);
            Assert.IsFalse(typeof(Test2).IsClass);

            Assert.IsFalse(typeof(Array).IsPrimitive);
            Assert.IsFalse(typeof(Array).IsValueType);
            Assert.IsFalse(typeof(Array).IsPointer);
            Assert.IsFalse(typeof(Array).IsSubclassOf(typeof(ValueType)));
            Assert.IsTrue(typeof(Array).IsSerializable);
            Assert.IsTrue(typeof(Array).IsClass);

            Assert.IsFalse(typeof(int[]).IsPrimitive);
            Assert.IsFalse(typeof(int[]).IsValueType);
            Assert.IsFalse(typeof(int[]).IsPointer);
            Assert.IsFalse(typeof(int[]).IsSubclassOf(typeof(ValueType)));
            Assert.IsTrue(typeof(int[]).IsSerializable);
            Assert.IsTrue(typeof(int[]).IsClass);

            Assert.IsFalse(typeof(Test3).IsPrimitive);
            Assert.IsFalse(typeof(Test3).IsValueType);
            Assert.IsFalse(typeof(Test3).IsPointer);
            Assert.IsFalse(typeof(Test3).IsSubclassOf(typeof(ValueType)));
            Assert.IsFalse(typeof(Test3).IsSerializable);
            Assert.IsTrue(typeof(Test3).IsClass);

            Assert.IsFalse(typeof(Test4).IsNotPublic);

            ShowTypeProperties(typeof(int));
            ShowTypeProperties(typeof(IntPtr));
            ShowTypeProperties(typeof(void *));
            ShowTypeProperties(typeof(decimal));
            ShowTypeProperties(typeof(Test1));
            ShowTypeProperties(typeof(Enum));
            ShowTypeProperties(typeof(Test2));
            ShowTypeProperties(typeof(string));
            ShowTypeProperties(typeof(Array));
            ShowTypeProperties(typeof(int[]));
            ShowTypeProperties(typeof(string[]));
            ShowTypeProperties(typeof(Test3));
            ShowTypeProperties(typeof(Test4));
        }
Example #11
0
        /// <summary>
        /// Returns a type which is able to represent either of two given types without loss of precision
        /// </summary>
        /// <param name="td1">first given type</param>
        /// <param name="td2">second given type</param>
        /// <returns></returns>
        private static TypeDescriptor GetCommonType(TypeDescriptor td1, TypeDescriptor td2)
        {
            if (td1.Equals(td2))
            {
                return(td1);
            }

            if (IsSFix(td1) && IsUFix(td2))
            {
                var fmt1 = SFix.GetFormat(td1);
                var fmt2 = UFix.GetFormat(td2);
                return(SFix.MakeType(
                           Math.Max(fmt1.IntWidth, fmt2.IntWidth + 1),
                           Math.Max(fmt1.FracWidth, fmt2.FracWidth)));
            }
            else if (IsUFix(td1) && IsSFix(td2))
            {
                return(GetCommonType(td2, td1));
            }
            else if (IsSFix(td1) && IsSFix(td2))
            {
                var fmt1 = SFix.GetFormat(td1);
                var fmt2 = SFix.GetFormat(td2);
                return(SFix.MakeType(
                           Math.Max(fmt1.IntWidth, fmt2.IntWidth),
                           Math.Max(fmt1.FracWidth, fmt2.FracWidth)));
            }
            else if (IsUFix(td1) && IsUFix(td2))
            {
                var fmt1 = UFix.GetFormat(td1);
                var fmt2 = UFix.GetFormat(td2);
                return(UFix.MakeType(
                           Math.Max(fmt1.IntWidth, fmt2.IntWidth),
                           Math.Max(fmt1.FracWidth, fmt2.FracWidth)));
            }
            else if (IsSigned(td1))
            {
                var fmt  = SFix.GetFormat(td1);
                var td1x = SFix.MakeType(fmt.IntWidth, fmt.FracWidth);
                return(GetCommonType(td1x, td2));
            }
            else if (IsSigned(td2))
            {
                return(GetCommonType(td2, td1));
            }
            else if (IsUnsigned(td1))
            {
                var fmt  = UFix.GetFormat(td1);
                var td1x = UFix.MakeType(fmt.IntWidth, fmt.FracWidth);
                return(GetCommonType(td1x, td2));
            }
            else if (IsUnsigned(td2))
            {
                return(GetCommonType(td2, td1));
            }
            else
            {
                throw new NotSupportedException(
                          "Cannot determine common type between " +
                          td1.ToString() + " and " + td2.ToString());
            }
        }
Example #12
0
 private InstructionDependency[] Convert(InstructionDependency[] preds, TypeDescriptor from, TypeDescriptor to)
 {
     if (from.Equals(to))
     {
         // nothing to do
         return(preds);
     }
     else if (IsSFix(from) && IsUFix(to))
     {
         var fromFmt = SFix.GetFormat(from);
         var toFmt   = UFix.GetFormat(to);
         int interIW = toFmt.IntWidth + 1;
         int interFW = toFmt.FracWidth;
         if (interIW != fromFmt.IntWidth ||
             interFW != fromFmt.FracWidth)
         {
             var interType = SFix.MakeType(interIW, interFW);
             Emit(DefaultInstructionSet.Instance.Convert().CreateStk(preds, 1, from, interType));
             Emit(DefaultInstructionSet.Instance.Convert().CreateStk(1, interType, to));
         }
         else
         {
             Emit(DefaultInstructionSet.Instance.Convert().CreateStk(preds, 1, from, to));
         }
         return(new InstructionDependency[0]);
     }
     else if (IsUFix(from) && IsSFix(to))
     {
         var fromFmt = UFix.GetFormat(from);
         var toFmt   = SFix.GetFormat(to);
         int interIW = toFmt.IntWidth - 1;
         int interFW = toFmt.FracWidth;
         if (interIW != fromFmt.IntWidth ||
             interFW != fromFmt.FracWidth)
         {
             var interType = UFix.MakeType(interIW, interFW);
             Emit(DefaultInstructionSet.Instance.Convert().CreateStk(preds, 1, from, interType));
             Emit(DefaultInstructionSet.Instance.Convert().CreateStk(1, interType, to));
         }
         else
         {
             Emit(DefaultInstructionSet.Instance.Convert().CreateStk(preds, 1, from, to));
         }
         return(new InstructionDependency[0]);
     }
     else if (IsSLV(from))
     {
         int wfrom = TypeLowering.Instance.GetWireWidth(from);
         int wto   = TypeLowering.Instance.GetWireWidth(to);
         if (wfrom == wto)
         {
             Emit(DefaultInstructionSet.Instance.Convert().CreateStk(preds, 1, from, to));
         }
         else
         {
             var interType = StdLogicVector.MakeType(wto);
             Emit(DefaultInstructionSet.Instance.Convert().CreateStk(preds, 1, from, interType));
             Convert(interType, to);
         }
         return(new InstructionDependency[0]);
     }
     else if (IsSLV(to))
     {
         int wfrom = TypeLowering.Instance.GetWireWidth(from);
         int wto   = TypeLowering.Instance.GetWireWidth(to);
         if (wfrom == wto)
         {
             Emit(DefaultInstructionSet.Instance.Convert().CreateStk(preds, 1, from, to));
         }
         else
         {
             var interType = StdLogicVector.MakeType(wfrom);
             Emit(DefaultInstructionSet.Instance.Convert().CreateStk(preds, 1, from, interType));
             Convert(interType, to);
         }
         return(new InstructionDependency[0]);
     }
     else
     {
         Emit(DefaultInstructionSet.Instance.Convert().CreateStk(preds, 1, from, to));
         return(new InstructionDependency[0]);
     }
 }
Example #13
0
        private void HandleStelemFixAFixI(XILSInstr xilsi)
        {
            FixedArrayRef far   = (FixedArrayRef)xilsi.StaticOperand;
            Array         array = far.ArrayObj;

            long[] indices             = far.Indices;
            var    preds               = RemapPreds(xilsi.Preds);
            MemoryMappedStorage mms    = GetDataLayout(array);
            ArrayMemoryLayout   layout = mms.Layout as ArrayMemoryLayout;

            if (layout.ElementsPerWord > 1)
            {
                throw new NotImplementedException("Multiple elements per word not yet implemented");
            }
            MemoryRegion region = mms.Region;
            IMarshalInfo minfo  = region.MarshalInfo;

            TypeDescriptor elemType    = layout.ElementLayout.LayoutedType;
            TypeDescriptor rawElemType = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s((long)layout.ElementLayout.SizeInBits));

            if (!elemType.Equals(rawElemType))
            {
                Emit(_iset.Convert().CreateStk(1, elemType, rawElemType));
            }

            uint           concatSize = layout.WordsPerElement * minfo.WordSize;
            TypeDescriptor concatType = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s(concatSize));

            if (!concatType.Equals(rawElemType))
            {
                Emit(_iset.Convert().CreateStk(1, rawElemType, concatType));
            }

            TypeDescriptor rawWordType = minfo.GetRawWordType();
            int            shiftSize   = MathExt.CeilLog2(concatSize);

            if (layout.WordsPerElement > 1)
            {
                Emit(_iset.Dup().CreateStk(1, concatType, concatType, concatType));
            }
            Unsigned       shift     = Unsigned.FromULong(minfo.WordSize, shiftSize);
            TypeDescriptor shiftType = TypeDescriptor.GetTypeOf(shift);
            TypeDescriptor dwType    = minfo.GetRawWordType();

            for (uint i = 0; i < layout.WordsPerElement; i++)
            {
                Unsigned addr = ComputeConstAddress(array, indices, i);
                Emit(_iset.LdConst(addr)
                     .CreateStk(0, TypeDescriptor.GetTypeOf(addr)));
                Emit(_iset.WrMem(region)
                     .CreateStk(preds, 2, dwType, TypeDescriptor.GetTypeOf(addr)));
                if (i < layout.WordsPerElement - 1)
                {
                    Emit(_iset.LdConst(shift).CreateStk(0, shiftType));
                    Emit(_iset.RShift().CreateStk(2, concatType, shiftType, concatType));
                    if (i + 1 < layout.WordsPerElement - 1)
                    {
                        Emit(_iset.Dup().CreateStk(1, concatType, concatType, concatType));
                    }
                }
            }
        }
Example #14
0
        private void HandleStelemFixA(XILSInstr xilsi)
        {
            Array array                = (Array)xilsi.StaticOperand;
            var   preds                = RemapPreds(xilsi.Preds);
            MemoryMappedStorage mms    = GetDataLayout(array);
            ArrayMemoryLayout   layout = mms.Layout as ArrayMemoryLayout;

            if (layout.ElementsPerWord > 1)
            {
                throw new NotImplementedException("Multiple elements per word not yet implemented");
            }
            MemoryRegion region = mms.Region;
            IMarshalInfo minfo  = region.MarshalInfo;

            EmitIndexComputation(array);

            TypeDescriptor indexType = TypeDescriptor.GetTypeOf(mms.BaseAddress);
            TypeDescriptor elemType  = layout.ElementLayout.LayoutedType;

            Emit(_iset.Swap().CreateStk(2, elemType, indexType, indexType, elemType));

            TypeDescriptor rawElemType = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s((long)layout.ElementLayout.SizeInBits));

            if (!elemType.Equals(rawElemType))
            {
                Emit(_iset.Convert().CreateStk(1, elemType, rawElemType));
            }

            uint           concatSize = layout.WordsPerElement * minfo.WordSize;
            TypeDescriptor concatType = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s(concatSize));

            if (!concatType.Equals(rawElemType))
            {
                Emit(_iset.Convert().CreateStk(1, rawElemType, concatType));
            }

            TypeDescriptor rawWordType = minfo.GetRawWordType();
            int            shiftSize   = MathExt.CeilLog2(concatSize);

            if (layout.WordsPerElement > 1)
            {
                Emit(_iset.Swap().CreateStk(2, indexType, rawElemType, rawElemType, indexType));
                Emit(_iset.Dup().CreateStk(1, indexType, indexType, indexType));
                Emit(_iset.Dig(2).CreateStk(3, concatType, indexType, indexType, indexType, indexType, concatType));
                Emit(_iset.Dup().CreateStk(1, concatType, concatType, concatType));
            }
            for (uint i = 0; i < layout.WordsPerElement; i++)
            {
                Emit(_iset.Convert().CreateStk(1, concatType, rawWordType));
                if (i < layout.WordsPerElement - 1)
                {
                    Emit(_iset.Dig(2).CreateStk(3, indexType, concatType, rawWordType, concatType, rawWordType, indexType));
                }
                else
                {
                    Emit(_iset.Swap().CreateStk(2, indexType, rawWordType, rawWordType, indexType));
                }
                Emit(_iset.WrMem(region).CreateStk(preds, 2, rawWordType, indexType));
                if (i < layout.WordsPerElement - 1)
                {
                    Unsigned       shift     = Unsigned.FromULong(minfo.WordSize, shiftSize);
                    TypeDescriptor shiftType = TypeDescriptor.GetTypeOf(shift);
                    Emit(_iset.LdConst(shift).CreateStk(0, shiftType));
                    Emit(_iset.RShift().CreateStk(2, concatType, shiftType, concatType));
                    Emit(_iset.Swap().CreateStk(2, indexType, concatType, concatType, indexType));
                    if (minfo.UseStrongPow2Alignment)
                    {
                        if (i + 1 < layout.WordsPerElement)
                        {
                            Emit(_iset.Dup().CreateStk(1, indexType, indexType, indexType));
                        }
                        Unsigned inc = Unsigned.FromULong(i + 1, region.AddressWidth);
                        Emit(_iset.Or().CreateStk(2, indexType, indexType, indexType));
                        if (i + 1 < layout.WordsPerElement)
                        {
                            Emit(_iset.Dig(2).CreateStk(1, concatType, indexType, indexType, indexType, indexType, concatType));
                            Emit(_iset.Swap().CreateStk(2, concatType, indexType, indexType, concatType));
                        }
                    }
                    else
                    {
                        Unsigned inc = Unsigned.FromULong(1, region.AddressWidth);
                        Emit(_iset.LdConst(inc).CreateStk(0, indexType));
                        Emit(_iset.Add().CreateStk(2, indexType, indexType, indexType));
                        Emit(_iset.Swap().CreateStk(2, concatType, indexType, indexType, concatType));
                    }
                }
            }
        }