示例#1
0
        public object ReadRegisterPrimitiveValue(Type t, uint offset)
        {
            if (!t.IsPrimitive)
            {
                throw new ArgumentException("t");
            }

            Converter.Position = offset;

            AccCIL.KnownObjectTypes objt = AccCIL.AccCIL.GetObjType(t);
            switch (objt)
            {
            case AccCIL.KnownObjectTypes.Boolean:
                return(((uint)Serializers[typeof(uint)].Deserialize(Converter, null, null)) == 0 ? false : true);

            case AccCIL.KnownObjectTypes.SByte:
                return((sbyte)(int)Serializers[typeof(int)].Deserialize(Converter, null, null));

            case AccCIL.KnownObjectTypes.Short:
                return((short)(int)Serializers[typeof(int)].Deserialize(Converter, null, null));

            case AccCIL.KnownObjectTypes.Byte:
                return((byte)(uint)Serializers[typeof(uint)].Deserialize(Converter, null, null));

            case AccCIL.KnownObjectTypes.UShort:
                return((ushort)(uint)Serializers[typeof(uint)].Deserialize(Converter, null, null));

            default:
                return(Serializers[t].Deserialize(Converter, null, null));
            }
        }
示例#2
0
        /// <summary>
        /// Gets the size factor of an array element as a factor of two.
        /// i.e. the element size is 2^n where n is the returned value
        ///
        /// Even though this function is loaded onto the SPE,
        /// it is also used when performing the JIT compilation and
        /// when transfering objects.
        /// </summary>
        /// <param name="objtype">The array element type</param>
        /// <returns>The size of the array element as a factor of two</returns>
        internal static uint get_array_elem_len_mult(uint t)
        {
            AccCIL.KnownObjectTypes objtype = (AccCIL.KnownObjectTypes)(t & 0xff);

            switch (objtype)
            {
            case AccCIL.KnownObjectTypes.Boolean:
            case AccCIL.KnownObjectTypes.Byte:
            case AccCIL.KnownObjectTypes.SByte:
                return(0);

            case AccCIL.KnownObjectTypes.Short:
            case AccCIL.KnownObjectTypes.UShort:
                return(1);

            case AccCIL.KnownObjectTypes.Int:
            case AccCIL.KnownObjectTypes.UInt:
            case AccCIL.KnownObjectTypes.Float:
            case AccCIL.KnownObjectTypes.Object:
            case AccCIL.KnownObjectTypes.String:
                return(2);

            case AccCIL.KnownObjectTypes.Long:
            case AccCIL.KnownObjectTypes.ULong:
            case AccCIL.KnownObjectTypes.Double:
                return(3);

            default:
                //TODO: Throw exception?
                return(0);
            }
        }
示例#3
0
        internal static uint malloc(uint[] objtable, AccCIL.KnownObjectTypes type, uint size, uint typestring_index)
        {
            if (objtable[1] >= objtable[0])
            {
                //TODO: Do garbage collection and re-check space
                //NOTE: When GC is done, re-visit the ldelema instruction
                //TODO: throw new OutOfMemoryException();
                return(0);
            }

            uint nextoffset    = objtable[2];
            uint requiredSpace = (size + 15 >> 4) << 4;

            //TODO: Do not rely on SPE mem size, but rather $SP
            if (nextoffset + requiredSpace >= objtable[3])
            {
                //TODO: Do garbage collection and re-check space
                //NOTE: When GC is done, re-visit the ldelema instruction
                //TODO: throw new OutOfMemoryException();
                return(0);
            }

            uint nextel = objtable[1];

            objtable[2] = nextoffset + requiredSpace;

            uint realtype;

            //For objects, we use the upper 16 bits to encode the typestring index
            if (typestring_index == 0)
            {
                realtype = (uint)type & 0xffu;
            }
            else
            {
                realtype = (typestring_index << 16) | ((uint)type & 0xffu);
                objtable[typestring_index * 4 + 3]++; //Increment refcount
            }

            uint n = nextel * 4;

            objtable[1] = objtable[n + 3];

            objtable[n]     = realtype;
            objtable[n + 1] = size;
            objtable[n + 2] = nextoffset;
            objtable[n + 3] = 1;

            return(nextel);
        }
示例#4
0
        public uint AddObject(AccCIL.KnownObjectTypes type, uint size, string typestring)
        {
            if (this.NextFree == this.Size)
            {
                throw new Exception("Out of space in object table");
            }

            ObjectTableEntry e = this[this.NextFree];

            System.Diagnostics.Debug.Assert(e.KnownType == AccCIL.KnownObjectTypes.Free);

            uint alignedSize = (size + 15 >> 4) << 4;

            if (alignedSize + this.NextOffset > this.Memsize)
            {
                throw new Exception("Out of memory one SPE");
            }

            uint n = e.Refcount;

            e.KnownType = type;
            e.Type      = 0;

            e.Offset   = this.NextOffset;
            e.Size     = size;
            e.Refcount = 0;

            this.NextOffset += alignedSize;
            this.NextFree    = n;

            if (typestring != null)
            {
                if (!m_strings.ContainsKey(typestring))
                {
                    m_strings.Add(typestring, AddObject(AccCIL.KnownObjectTypes.String, (uint)System.Text.Encoding.UTF8.GetByteCount(typestring), null));
                }

                e.Type = m_strings[typestring];
                this[e.Type].Refcount++;
            }

            return(e.Index);
        }