예제 #1
0
        /// <summary>
        /// Parses the generic instance.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        private static SigType ParseGenericInstance(byte[] buffer, ref int index)
        {
            SigType        originalType;
            CilElementType type = (CilElementType)buffer[index++];

            switch (type)
            {
            case CilElementType.Class:
                originalType = ParseClassSignature(buffer, ref index);
                break;

            case CilElementType.ValueType:
                originalType = ParseValueType(buffer, ref index);
                break;

            default:

                throw new InvalidOperationException("Invalid signature type.");
            }

            int genArgCount = Utilities.ReadCompressedInt32(buffer, ref index);

            SigType[] genArgs = new SigType[genArgCount];
            for (int i = 0; i < genArgCount; i++)
            {
                genArgs[i] = ParseTypeSignature(buffer, ref index);
            }

            return(new GenericInstSigType(originalType, genArgs));
        }
예제 #2
0
        /// <summary>
        /// Parses the generic instance.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static SigType ParseGenericInstance(SignatureReader reader)
        {
            TypeSigType    originalType;
            CilElementType type = (CilElementType)reader.ReadByte();

            switch (type)
            {
            case CilElementType.Class:
                originalType = ParseClassSignature(reader);
                break;

            case CilElementType.ValueType:
                originalType = ParseValueType(reader);
                break;

            default:
                throw new InvalidOperationException(@"Invalid signature type.");
            }

            int genArgCount = reader.ReadCompressedInt32();

            SigType[] genArgs = new SigType[genArgCount];
            for (int i = 0; i < genArgCount; i++)
            {
                genArgs[i] = ParseTypeSignature(reader);
            }

            return(new GenericInstSigType(originalType, genArgs));
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VariableSignature"/> class.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="token">The token.</param>
 public VariableSignature(VariableSignature signature)
     : base(signature)
 {
     this.customMods = signature.customMods;
     this.modifier = signature.modifier;
     this.type = signature.type;
 }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VariableSignature"/> class.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="token">The token.</param>
 public VariableSignature(VariableSignature signature)
     : base(signature)
 {
     this.customMods = signature.customMods;
     this.modifier   = signature.modifier;
     this.type       = signature.type;
 }
예제 #5
0
        /// <summary>
        /// Parses the modifier.
        /// </summary>
        /// <param name="reader">The reader.</param>
        private void ParseModifier(SignatureReader reader)
        {
            CilElementType value = (CilElementType)reader.PeekByte();

            if (value == CilElementType.Pinned)
            {
                Modifier = value;
                reader.SkipByte();
            }
        }
예제 #6
0
파일: TableHeap.cs 프로젝트: djlw78/Mosa
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="result">The result.</param>
        public void Read(TokenTypes token, out ConstantRow result)
        {
            if ((token & TokenTypes.TableMask) != TokenTypes.Constant)
            {
                throw new ArgumentException("Invalid token type for ConstantRow.", "token");
            }

            using (BinaryReader reader = CreateReaderForToken(token))
            {
                CilElementType cet = (CilElementType)reader.ReadByte();
                reader.ReadByte();

                result = new ConstantRow(cet, ReadIndexValue(reader, IndexType.HasConstant), ReadIndexValue(reader, IndexType.BlobHeap));
            }
        }
예제 #7
0
파일: CustomMod.cs 프로젝트: djlw78/Mosa
        /// <summary>
        /// Parses the custom mods.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public static CustomMod[] ParseCustomMods(byte[] buffer, ref int index)
        {
            List <CustomMod> mods = new List <CustomMod>();

            for (int i = index; i < buffer.Length; i++)
            {
                CilElementType type = (CilElementType)buffer[i++];
                if (type != CilElementType.Optional && type != CilElementType.Required)
                {
                    break;
                }

                index++;
                TokenTypes modType = SigType.ReadTypeDefOrRefEncoded(buffer, ref index);
                mods.Add(new CustomMod((CustomModType)(type - CilElementType.Required + 1), modType));
            }

            return(mods.ToArray());
        }
예제 #8
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public ConstantRow ReadConstantRow(Token token)
        {
            if (token.Table != TableType.Constant)
            {
                throw new ArgumentException("Invalid token type for ConstantRow.", @"token");
            }

            using (BinaryReader reader = CreateReaderForToken(token))
            {
                CilElementType cet = (CilElementType)reader.ReadByte();
                reader.ReadByte();

                return(new ConstantRow(
                           cet,
                           ReadMetadataToken(reader, IndexType.HasConstant),
                           ReadHeapToken(reader, IndexType.BlobHeap)
                           ));
            }
        }
예제 #9
0
        /// <summary>
        /// Parses the custom mods.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public static CustomMod[] ParseCustomMods(SignatureReader reader)
        {
            List <CustomMod> mods = new List <CustomMod>();

            while (reader.Index != reader.Length)
            {
                CilElementType type = (CilElementType)reader.PeekByte();
                if (type != CilElementType.Optional && type != CilElementType.Required)
                {
                    break;
                }

                reader.SkipByte();

                Token modType = reader.ReadEncodedTypeDefOrRef();
                mods.Add(new CustomMod((CustomModType)(type - CilElementType.Required + 1), modType));
            }

            return(mods.ToArray());
        }
예제 #10
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ConstantRow" /> struct.
		/// </summary>
		/// <param name="type">The type.</param>
		/// <param name="parent">The parent.</param>
		/// <param name="value">The value.</param>
		public ConstantRow(CilElementType type, Token parent, HeapIndexToken value)
		{
			Type = type;
			Parent = parent;
			Value = value;
		}
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SigType"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 public SigType(CilElementType type)
 {
     _type = type;
 }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConstantRow" /> struct.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="value">The value.</param>
 public ConstantRow(CilElementType type, Token parent, HeapIndexToken value)
 {
     Type   = type;
     Parent = parent;
     Value  = value;
 }
예제 #13
0
        /// <summary>
        /// Parses the type signature.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public static SigType ParseTypeSignature(byte[] buffer, ref int index)
        {
            SigType        result;
            CilElementType type = (CilElementType)buffer[index++];

            switch (type)
            {
            case CilElementType.Void:
                result = new SigType(type);
                break;

            case CilElementType.Boolean:
                goto case CilElementType.Void;

            case CilElementType.Char:
                goto case CilElementType.Void;

            case CilElementType.I1:
                goto case CilElementType.Void;

            case CilElementType.U1:
                goto case CilElementType.Void;

            case CilElementType.I2:
                goto case CilElementType.Void;

            case CilElementType.U2:
                goto case CilElementType.Void;

            case CilElementType.I4:
                goto case CilElementType.Void;

            case CilElementType.U4:
                goto case CilElementType.Void;

            case CilElementType.I8:
                goto case CilElementType.Void;

            case CilElementType.U8:
                goto case CilElementType.Void;

            case CilElementType.R4:
                goto case CilElementType.Void;

            case CilElementType.R8:
                goto case CilElementType.Void;

            case CilElementType.String:
                goto case CilElementType.Void;

            case CilElementType.Object:
                goto case CilElementType.Void;

            case CilElementType.I:
                goto case CilElementType.Void;

            case CilElementType.U:
                goto case CilElementType.Void;

            case CilElementType.TypedByRef:
                goto case CilElementType.Void;

            case CilElementType.Array:
                result = ParseArraySignature(buffer, ref index);
                break;

            case CilElementType.Class:
                result = ParseClassSignature(buffer, ref index);
                break;

            case CilElementType.FunctionPtr:
                result = ParseFunctionPointer(buffer, ref index);
                break;

            case CilElementType.GenericInst:
                result = ParseGenericInstance(buffer, ref index);
                break;

            case CilElementType.MVar:
                result = ParseMVar(buffer, ref index);
                break;

            case CilElementType.Ptr:
                result = ParsePointer(buffer, ref index);
                break;

            case CilElementType.SZArray:
                result = ParseSZArraySignature(buffer, ref index);
                break;

            case CilElementType.ValueType:
                result = ParseValueType(buffer, ref index);
                break;

            case CilElementType.Var:
                result = ParseVar(buffer, ref index);
                break;

            case CilElementType.ByRef:
                result = ParseReference(buffer, ref index);
                break;

            default:

                throw new NotSupportedException("Unsupported CIL element type: " + type);
            }

            return(result);
        }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConstantRow"/> struct.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="value">The value BLOB idx.</param>
 public ConstantRow(CilElementType type, Token parent, HeapIndexToken value)
 {
     this.type   = type;
     this.parent = parent;
     this.value  = value;
 }
예제 #15
0
 private void ParseModifier(SignatureReader reader)
 {
     CilElementType value = (CilElementType)reader.PeekByte();
     if (value == CilElementType.Pinned)
     {
         this.modifier = value;
         reader.SkipByte();
     }
 }
예제 #16
0
 public TypeSigType(Token token, CilElementType type) :
     base(type)
 {
     this.token = token;
 }
예제 #17
0
        //public static readonly BuiltInSigType Ptr = new BuiltInSigType(CilElementType.Ptr);

        internal BuiltInSigType(CilElementType type) :
            base(type)
        {
        }
예제 #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SigType"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 public SigType(CilElementType type)
 {
     this.Type = type;
 }
예제 #19
0
 //public static readonly BuiltInSigType Ptr = new BuiltInSigType(CilElementType.Ptr);
 internal BuiltInSigType(CilElementType type)
     : base(type)
 {
 }
 /// <summary>
 /// Gets the return registers.
 /// </summary>
 /// <param name="returnType">Type of the return.</param>
 /// <returns></returns>
 Register[] ICallingConvention.GetReturnRegisters(CilElementType returnType)
 {
     return null;
 }
예제 #21
0
        /// <summary>
        /// Converts a <see cref="CilElementType"/> to <see cref="ConvType"/>.
        /// </summary>
        /// <param name="cet">The CilElementType to convert.</param>
        /// <returns>The equivalent ConvType.</returns>
        /// <exception cref="T:System.NotSupportedException"><paramref name="cet"/> can't be converted.</exception>
        private ConvType ConvTypeFromCilType(CilElementType cet)
        {
            switch (cet) {
                case CilElementType.Char:
                    return ConvType.U2;
                case CilElementType.I1:
                    return ConvType.I1;
                case CilElementType.I2:
                    return ConvType.I2;
                case CilElementType.I4:
                    return ConvType.I4;
                case CilElementType.I8:
                    return ConvType.I8;
                case CilElementType.U1:
                    return ConvType.U1;
                case CilElementType.U2:
                    return ConvType.U2;
                case CilElementType.U4:
                    return ConvType.U4;
                case CilElementType.U8:
                    return ConvType.U8;
                case CilElementType.R4:
                    return ConvType.R4;
                case CilElementType.R8:
                    return ConvType.R8;
                case CilElementType.I:
                    return ConvType.I;
                case CilElementType.U:
                    return ConvType.U;
                case CilElementType.Ptr:
                    return ConvType.Ptr;
            }

            // Requested CilElementType is not supported
            throw new NotSupportedException ();
        }
예제 #22
0
 public TypeSigType(Token token, CilElementType type)
     : base(type)
 {
     this.token = token;
 }
예제 #23
0
파일: ConstantRow.cs 프로젝트: djlw78/Mosa
 /// <summary>
 /// Initializes a new instance of the <see cref="ConstantRow"/> struct.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="valueBlobIdx">The value BLOB idx.</param>
 public ConstantRow(CilElementType type, TokenTypes parent, TokenTypes valueBlobIdx)
 {
     _type         = type;
     _parent       = parent;
     _valueBlobIdx = valueBlobIdx;
 }
예제 #24
0
 private static bool MustSignExtendOnLoad(CilElementType elementType)
 {
     return (elementType == CilElementType.I1 || elementType == CilElementType.I2);
 }
예제 #25
0
 public BuiltInSigType(string typeName, CilElementType type) :
     base(type)
 {
     this.typeName = typeName;
 }
예제 #26
0
 private static bool MustZeroExtendOnLoad(CilElementType elementType)
 {
     return (elementType == CilElementType.U1 || elementType == CilElementType.U2 || elementType == CilElementType.Char);
 }
예제 #27
0
 public BuiltInSigType(string typeName, CilElementType type)
     : base(type)
 {
     this.typeName = typeName;
 }
예제 #28
0
        /// <summary>
        /// Parses the type signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public static SigType ParseTypeSignature(SignatureReader reader)
        {
            CilElementType type = (CilElementType)reader.ReadByte();

            switch (type)
            {
            case CilElementType.Void:
                return(BuiltInSigType.Void);

            case CilElementType.Boolean:
                return(BuiltInSigType.Boolean);

            case CilElementType.Char:
                return(BuiltInSigType.Char);

            case CilElementType.I1:
                return(BuiltInSigType.SByte);

            case CilElementType.U1:
                return(BuiltInSigType.Byte);

            case CilElementType.I2:
                return(BuiltInSigType.Int16);

            case CilElementType.U2:
                return(BuiltInSigType.UInt16);

            case CilElementType.I4:
                return(BuiltInSigType.Int32);

            case CilElementType.U4:
                return(BuiltInSigType.UInt32);

            case CilElementType.I8:
                return(BuiltInSigType.Int64);

            case CilElementType.U8:
                return(BuiltInSigType.UInt64);

            case CilElementType.R4:
                return(BuiltInSigType.Single);

            case CilElementType.R8:
                return(BuiltInSigType.Double);

            case CilElementType.String:
                return(BuiltInSigType.String);

            case CilElementType.Object:
                return(BuiltInSigType.Object);

            case CilElementType.I:
                return(BuiltInSigType.IntPtr);

            case CilElementType.U:
                return(BuiltInSigType.UIntPtr);

            case CilElementType.TypedByRef:
                return(BuiltInSigType.TypedByRef);

            case CilElementType.Array:
                return(ParseArraySignature(reader));

            case CilElementType.Class:
                return(ParseClassSignature(reader));

            case CilElementType.FunctionPtr:
                return(ParseFunctionPointer(reader));

            case CilElementType.GenericInst:
                return(ParseGenericInstance(reader));

            case CilElementType.MVar:
                return(ParseMVar(reader));

            case CilElementType.Ptr:
                return(ParsePointer(reader));

            case CilElementType.SZArray:
                return(ParseSZArraySignature(reader));

            case CilElementType.ValueType:
                return(ParseValueType(reader));

            case CilElementType.Var:
                return(ParseVar(reader));

            case CilElementType.ByRef:
                return(ParseReference(reader));

            default:
                throw new NotSupportedException(@"Unsupported CIL element type: " + type);
            }
        }
예제 #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConstantRow"/> struct.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="value">The value BLOB idx.</param>
 public ConstantRow(CilElementType type, Token parent, HeapIndexToken value)
 {
     this.type = type;
     this.parent = parent;
     this.value = value;
 }
예제 #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SigType"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 public SigType(CilElementType type)
 {
     this.type = type;
 }
 private static bool MustSignExtendOnLoad(CilElementType elementType)
 {
     return(elementType == CilElementType.I1 || elementType == CilElementType.I2);
 }
예제 #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConstantRow"/> struct.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="valueBlobIdx">The value BLOB idx.</param>
 public ConstantRow(CilElementType type, TokenTypes parent, TokenTypes valueBlobIdx)
 {
     _type = type;
     _parent = parent;
     _valueBlobIdx = valueBlobIdx;
 }
 private static bool MustZeroExtendOnLoad(CilElementType elementType)
 {
     return(elementType == CilElementType.U1 || elementType == CilElementType.U2 || elementType == CilElementType.Char);
 }
예제 #34
0
        /// <summary>
        /// Gets the return registers.
        /// </summary>
        /// <param name="returnType">Type of the return.</param>
        /// <returns></returns>
        Register[] ICallingConvention.GetReturnRegisters(CilElementType returnType)
        {
            if (returnType == CilElementType.Void)
                return ReturnVoidRegisters;

            if (returnType == CilElementType.R4 || returnType == CilElementType.R8)
                return ReturnFPRegisters;

            if (returnType == CilElementType.I8 || returnType == CilElementType.U8)
                return Return64BitRegisters;

            return Return32BitRegisters;
        }
        private StackTypeCode FromSigType(CilElementType type)
        {
            switch (type)
            {
                case CilElementType.I1: goto case CilElementType.U4;
                case CilElementType.I2: goto case CilElementType.U4;
                case CilElementType.I4: goto case CilElementType.U4;
                case CilElementType.U1: goto case CilElementType.U4;
                case CilElementType.U2: goto case CilElementType.U4;
                case CilElementType.U4: return StackTypeCode.Int32;
            }

            throw new NotSupportedException();
        }