Exemple #1
0
        private void HandleStoreVar(XILSInstr xilsi)
        {
            var      var          = (Variable)xilsi.StaticOperand;
            var      mms          = GetVariableLayout(var);
            Unsigned addr         = mms.BaseAddress;
            var      addrType     = TypeDescriptor.GetTypeOf(addr);
            int      addrSize     = addr.Size;
            var      rawWordType  = Mapper.MarshalInfo.GetRawWordType();
            uint     concatSize   = (uint)(mms.Size * Mapper.MarshalInfo.WordSize);
            var      concatType   = TypeDescriptor.GetTypeOf(StdLogicVector._0s(concatSize));
            var      valueType    = var.Type;
            var      slvValue     = Marshal.SerializeForHW(valueType.GetSampleInstance());
            var      rawValueType = TypeDescriptor.GetTypeOf(slvValue);

            if (!rawValueType.Equals(valueType))
            {
                Emit(_iset.Convert().CreateStk(1, valueType, rawValueType));
            }
            if (!rawValueType.Equals(concatType))
            {
                Emit(_iset.Convert().CreateStk(1, rawValueType, concatType));
            }
            int shiftSize = MathExt.CeilLog2(concatSize);

            if (mms.Layout.Size > 1)
            {
                Emit(_iset.Dup().CreateStk(1, concatType, concatType, concatType));
            }
            Unsigned       shift     = Unsigned.FromULong(Mapper.MarshalInfo.WordSize, shiftSize);
            TypeDescriptor shiftType = TypeDescriptor.GetTypeOf(shift);

            for (ulong i = 0; i < mms.Layout.Size; i++)
            {
                if (!rawWordType.Equals(concatType))
                {
                    Emit(_iset.Convert().CreateStk(1, concatType, rawWordType));
                }
                Emit(_iset.WrMemFix(Mapper.DefaultRegion, addr).CreateStk(1, rawWordType));
                if (i < mms.Layout.Size - 1)
                {
                    if (i + 1 < mms.Layout.Size - 1)
                    {
                        Emit(_iset.Dup().CreateStk(1, concatType, concatType, concatType));
                    }
                    Emit(_iset.LdConst(shift).CreateStk(0, shiftType));
                    Emit(_iset.RShift().CreateStk(1, concatType, concatType));
                }
                addr = (addr + Unsigned.FromULong(1, 1)).Resize(addrSize);
            }
        }