Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of <see cref="RuntimeMember"/>.
 /// </summary>
 /// <param name="token">Holds the token of this runtime metadata.</param>
 /// <param name="module">The module.</param>
 /// <param name="declaringType">The declaring type of the member.</param>
 /// <param name="attributes">Holds the attributes of the member.</param>
 protected RuntimeMember(int token, IMetadataModule module, RuntimeType declaringType, RuntimeAttribute[] attributes) :
     base(token)
 {
     this.module        = module;
     this.declaringType = declaringType;
     this.attributes    = attributes;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RuntimeParameter"/> class.
 /// </summary>
 /// <param name="module">The module.</param>
 /// <param name="param">The param.</param>
 public RuntimeParameter(IMetadataModule module, ParamRow param)
 {
     _module     = module;
     _attributes = param.Flags;
     _nameIdx    = param.NameIdx;
     _position   = param.Sequence;
 }
 private void CompileAssembly(IMetadataModule assembly)
 {
     using (AotAssemblyCompiler assemblyCompiler = new AotAssemblyCompiler(this.outputAssemblyCompiler.Architecture, assembly, this.typeInitializerSchedulerStage, this.linker))
     {
         assemblyCompiler.Run();
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Parses an SZArray attribute value.
        /// </summary>
        /// <param name="module">The metadata module, which contains the attribute blob.</param>
        /// <param name="reader">The binary reader used to read From the attribute blob.</param>
        /// <param name="sigType">Type of the SZArray.</param>
        /// <returns>An Array, which represents the SZArray definition.</returns>
        private static object ParseSZArrayArg(IMetadataModule module, BinaryReader reader, SZArraySigType sigType)
        {
            // Return value
            Array result;

            // Determine the number of elements
            int numElements = reader.ReadInt32();

            if (-1 == numElements)
            {
                return(null);
            }

            // Retrieve the array element type
            Type elementType = GetTypeFromSigType(sigType);

            Debug.Assert(null != elementType, "Failed to get System.Type for SigType.");
            result = Array.CreateInstance(elementType, numElements);
            for (int idx = 0; idx < numElements; idx++)
            {
                object item = ParseElem(module, reader, sigType.ElementType);
                result.SetValue(item, idx);
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Runs a test case.
        /// </summary>
        /// <typeparam name="TDelegate">The delegate used to run the test case.</typeparam>
        /// <param name="ns">The namespace of the test.</param>
        /// <param name="type">The type, which contains the test.</param>
        /// <param name="method">The name of the method of the test.</param>
        /// <param name="parameters">The parameters to pass to the test.</param>
        /// <returns>The result of the test.</returns>
        public object Run <TDelegate>(string ns, string type, string method, params object[] parameters)
        {
            // Do we need to compile the code?
            if (this.needCompile == true)
            {
                if (module != null)
                {
                    RuntimeBase.Instance.AssemblyLoader.Unload(module);
                }
                this.assembly = this.CompileTestCode <TDelegate>(ns, type, method);
                Console.WriteLine("Executing MOSA compiler...");
                module           = RunMosaCompiler(this.assembly);
                this.needCompile = false;
            }

            // Find the test method to execute
            RuntimeMethod runtimeMethod = FindMethod(
                ns,
                type,
                method
                );

            // Create a delegate for the test method
            Delegate fn = Marshal.GetDelegateForFunctionPointer(
                runtimeMethod.Address,
                typeof(TDelegate)
                );

            // Execute the test method
            return(fn.DynamicInvoke(parameters));
        }
 public TestCaseMethodCompiler(IAssemblyLinker linker, IArchitecture architecture, IMetadataModule module, RuntimeType type, RuntimeMethod method)
     : base(linker, architecture, module, type, method)
 {
     // Populate the pipeline
     this.Pipeline.AddRange(new IMethodCompilerStage[] {
         new DecodingStage(),
         new BasicBlockBuilderStage(),
         new OperandDeterminationStage(),
         new InstructionLogger(),
         //new ConstantFoldingStage(),
         new CILTransformationStage(),
         //new InstructionLogger(),
         //InstructionStatisticsStage.Instance,
         //new DominanceCalculationStage(),
         //new EnterSSA(),
         //new ConstantPropagationStage(),
         //new ConstantFoldingStage(),
         //new LeaveSSA(),
         new StackLayoutStage(),
         new PlatformStubStage(),
         new InstructionLogger(),
         //new BlockReductionStage(),
         new LoopAwareBlockOrderStage(),
         //new SimpleTraceBlockOrderStage(),
         //new ReverseBlockOrderStage(),  // reverse all the basic blocks and see if it breaks anything
         //new BasicBlockOrderStage()
         new CodeGenerationStage(),
         //new InstructionLogger(),
     });
 }
Exemplo n.º 7
0
        /// <summary>
        /// Loads all custom attributes From the assembly.
        /// </summary>
        /// <param name="module">The module to load attributes From.</param>
        /// <param name="modOffset">The module offset.</param>
        private void LoadCustomAttributes(IMetadataModule module, ModuleOffsets modOffset)
        {
            IMetadataProvider         metadata = module.Metadata;
            TokenTypes                token, owner = 0, maxAttrs = metadata.GetMaxTokenValue(TokenTypes.CustomAttribute);
            CustomAttributeRow        car;
            List <CustomAttributeRow> attributes = new List <CustomAttributeRow>();

            for (token = TokenTypes.CustomAttribute + 1; token <= maxAttrs; token++)
            {
                metadata.Read(token, out car);

                // Do we need to commit generic parameters?
                if (owner != car.ParentTableIdx)
                {
                    // Yes, commit them to the last type
                    if (0 != owner && 0 != attributes.Count)
                    {
                        SetAttributes(module, owner, attributes);
                        attributes.Clear();
                    }

                    owner = car.ParentTableIdx;
                }

                // Save this attribute
                attributes.Add(car);
            }

            // Set the generic parameters of the last type, if we have them
            if (0 != attributes.Count)
            {
                SetAttributes(module, owner, attributes);
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of <see cref="RuntimeMember"/>.
 /// </summary>
 /// <param name="token">Holds the token of this runtime metadata.</param>
 /// <param name="module">The module.</param>
 /// <param name="declaringType">The declaring type of the member.</param>
 /// <param name="attributes">Holds the attributes of the member.</param>
 protected RuntimeMember(int token, IMetadataModule module, RuntimeType declaringType, RuntimeAttribute[] attributes)
     : base(token)
 {
     this.module = module;
     this.declaringType = declaringType;
     this.attributes = attributes;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Verify"/> class.
 /// </summary>
 /// <param name="options">The options.</param>
 public VerifyAssembly(Verify verify, VerificationOptions options, IMetadataModule module)
 {
     this.Verify = verify;
     this.Options = options;
     this.Module = module;
     this.Metadata = Module.Metadata;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Loads all methods From the given metadata module.
        /// </summary>
        /// <param name="module">The metadata module to load methods From.</param>
        /// <param name="declaringType">The type, which declared the method.</param>
        /// <param name="first">The first method token to load.</param>
        /// <param name="last">The last method token to load (non-inclusive.)</param>
        /// <param name="offset">The offset into the method table to start loading methods From.</param>
        private void LoadMethods(IMetadataModule module, RuntimeType declaringType, TokenTypes first, TokenTypes last, ref int offset)
        {
            IMetadataProvider md = module.Metadata;
            MethodDefRow      methodDef, nextMethodDef = new MethodDefRow();
            TokenTypes        maxParam, maxMethod = md.GetMaxTokenValue(TokenTypes.MethodDef);

            if (first < last)
            {
                md.Read(first, out methodDef);
                for (TokenTypes token = first; token < last; token++)
                {
                    if (token < maxMethod)
                    {
                        md.Read(token + 1, out nextMethodDef);
                        maxParam = nextMethodDef.ParamList;
                    }
                    else
                    {
                        maxParam = md.GetMaxTokenValue(TokenTypes.Param) + 1;
                    }

                    Debug.Assert(offset < _methods.Length, @"Invalid method index.");
                    _methods[offset++] = new CilRuntimeMethod(offset, module, ref methodDef, maxParam, declaringType);
                    methodDef          = nextMethodDef;
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Populates the <see cref="RuntimeAttribute"/> with the values in <paramref name="car"/>.
 /// </summary>
 /// <param name="module">The metadata module, which defines the attribute.</param>
 /// <param name="car">The custom attribute row From metadata.</param>
 public RuntimeAttribute(IMetadataModule module, CustomAttributeRow car)
 {
     _attribute     = null;
     _attributeBlob = car.ValueBlobIdx;
     _ctor          = car.TypeIdx;
     _module        = module;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (_pipeline == null)
            {
                throw new ObjectDisposedException("MethodCompilerBase");
            }

            foreach (IMethodCompilerStage mcs in _pipeline)
            {
                IDisposable d = mcs as IDisposable;
                if (null != d)
                {
                    d.Dispose();
                }
            }

            _pipeline.Clear();
            _pipeline = null;

            _architecture   = null;
            _linker         = null;
            _method         = null;
            _module         = null;
            _type           = null;
            _instructionSet = null;
            _basicBlocks    = null;
        }
Exemplo n.º 13
0
        RuntimeType ITypeSystem.GetType(IMetadataModule module, TokenTypes token)
        {
            TokenTypes table = (TokenTypes.TableMask & token);

            if (TokenTypes.TypeRef == table)
            {
                return(ResolveTypeRef(module, token));
            }
            else
            {
                int typeIdx = _moduleOffsets[module.LoadOrder].TypeOffset;
                int row     = (int)(token & TokenTypes.RowIndexMask);
                if (row == 0)
                {
                    return(null);
                }

                if (table == TokenTypes.TypeDef)
                {
                    typeIdx += row - 2;
                }
                else if (table == TokenTypes.TypeSpec)
                {
                    typeIdx += (int)(module.Metadata.GetMaxTokenValue(TokenTypes.TypeDef) & TokenTypes.RowIndexMask) + row;
                }
                else
                {
                    throw new ArgumentException(@"Not a type token.", @"token");
                }

                return(_types[typeIdx]);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Finds the type index From token.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public int FindTypeIndexFromToken(IMetadataModule module, TokenTypes token)
        {
            // FIXME: Calculate the index of the sought token:
            // - If it is a typedef, return the module offset + row index.
            // - If it is a typeref, resolve it to the referenced typedef and return its type index
            // - If it is a typespec, resolve it to the referenced typespec
            int result   = 0;
            int tokenRow = (int)(token & TokenTypes.RowIndexMask);

            switch (TokenTypes.TableMask & token)
            {
            case TokenTypes.TypeDef:
                if (tokenRow != 0)
                {
                    result = _moduleOffsets[module.LoadOrder].TypeOffset + tokenRow - 2;
                }
                break;

            case TokenTypes.TypeRef:
            {
                TypeRefRow typeRef;
                module.Metadata.Read(token, out typeRef);
                switch (typeRef.ResolutionScopeIdx & TokenTypes.TableMask)
                {
                case TokenTypes.Module:
                    // FIXME: Invalid for CIL compressed modules, but we'll support it for completeness
                    result = -5;
                    break;

                case TokenTypes.ModuleRef:
                    // FIXME: Use the type From the referenced module
                    result = -4;
                    break;

                case TokenTypes.AssemblyRef:
                    // FIXME: Resolve the assembly and use it
                    result = ResolveAssemblyRef(module, ref typeRef);
                    break;

                case TokenTypes.TypeRef:
                    // Nested type within the current assembly...
                    result = FindTypeIndexFromToken(module, typeRef.ResolutionScopeIdx);
                    break;

                default:
                    throw new ArgumentException(@"Invalid type reference.", @"token");
                }
            }
            break;

            case TokenTypes.TypeSpec:
                result = -2;
                break;

            default:
                throw new ArgumentException(@"Invalid token table.", @"tokenTypes");
            }

            return(result);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Populates the <see cref="RuntimeAttribute"/> with the values in <paramref name="car"/>.
 /// </summary>
 /// <param name="module">The metadata module, which defines the attribute.</param>
 /// <param name="car">The custom attribute row From metadata.</param>
 public RuntimeAttribute(IMetadataModule module, CustomAttributeRow car)
 {
     _attribute = null;
     _attributeBlob = car.ValueBlobIdx;
     _ctor = car.TypeIdx;
     _module = module;
 }
        /// <summary>
        /// Initializes static data members of the type loader.
        /// </summary>
        /// <param name="typeSystem">The type system.</param>
        /// <param name="metadataModule">The metadata module.</param>
        public DefaultModuleTypeSystem(ITypeSystem typeSystem, IMetadataModule metadataModule)
        {
            Debug.Assert(typeSystem != null);
            Debug.Assert(metadataModule != null);
            Debug.Assert(metadataModule.Metadata != null);

            this.typeSystem = typeSystem;
            this.metadataModule = metadataModule;
            this.metadata = metadataModule.Metadata;

            methods = new RuntimeMethod[GetTableRows(TokenTypes.MethodDef)];
            fields = new RuntimeField[GetTableRows(TokenTypes.Field)];
            types = new RuntimeType[GetTableRows(TokenTypes.TypeDef)];
            parameters = new RuntimeParameter[GetTableRows(TokenTypes.Param)];

            typeSpecs = new RuntimeType[GetTableRows(TokenTypes.TypeSpec)];
            methodSpecs = new RuntimeMethod[GetTableRows(TokenTypes.MethodSpec)];

            // Load all types from the assembly into the type array
            LoadTypes();
            LoadGenerics();
            LoadTypeSpecs();
            LoadParameters();
            LoadCustomAttributes();
        }
Exemplo n.º 17
0
        public MethodCompiler(IAssemblyLinker linker, IArchitecture architecture, IMetadataModule module, RuntimeType type, RuntimeMethod method, Stream codeStream)
            : base(linker, architecture, module, type, method)
        {
            if (null == codeStream)
                throw new ArgumentNullException(@"codeStream");

            _codeStream = codeStream;
        }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CilRuntimeField"/> class.
 /// </summary>
 /// <param name="module">The module.</param>
 /// <param name="field">The field.</param>
 /// <param name="offset">The offset.</param>
 /// <param name="rva">The rva.</param>
 /// <param name="declaringType">Type of the declaring.</param>
 public CilRuntimeField(IMetadataModule module, ref FieldRow field, IntPtr offset, IntPtr rva, RuntimeType declaringType) : base(module, declaringType)
 {
     this.nameIdx    = field.NameStringIdx;
     this.signature  = field.SignatureBlobIdx;
     base.Attributes = field.Flags;
     base.RVA        = rva;
     //base.Offset = offset; ?
 }
Exemplo n.º 19
0
        protected void LoadAssembly(string filename)
        {
            metadataModule = new PortableExecutableImage(new FileStream(filename, FileMode.Open, FileAccess.Read));

            UpdateTree();

            this.toolStripStatusLabel1.Text = filename;
        }
Exemplo n.º 20
0
        protected void LoadAssembly(string filename)
        {
            IAssemblyLoader assemblyLoader = new AssemblyLoader();
            assemblyLoader.AddPrivatePath(System.IO.Path.GetDirectoryName(filename));

            metadataModule = assemblyLoader.LoadModule(filename);

            UpdateTree();
        }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RuntimeParameter"/> class.
 /// </summary>
 /// <param name="module">The module.</param>
 /// <param name="name">The name.</param>
 /// <param name="position">The position.</param>
 /// <param name="attributes">The attributes.</param>
 public RuntimeParameter(IMetadataModule module, string name, int position, ParameterAttributes attributes)
 {
     _module     = module;
     _nameIdx    = (TokenTypes)0;
     _token      = (TokenTypes)0;
     _attributes = attributes;
     _name       = name;
     _position   = position;
 }
Exemplo n.º 22
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="assembly">The assembly of this compiler.</param>
        /// <exception cref="System.ArgumentNullException">Either <paramref name="architecture"/> or <paramref name="assembly"/> is null.</exception>
        protected AssemblyCompiler(IArchitecture architecture, IMetadataModule assembly)
        {
            if (architecture == null)
                throw new ArgumentNullException(@"architecture");

            _architecture = architecture;
            _assembly = assembly;
            _pipeline = new CompilerPipeline();
        }
Exemplo n.º 23
0
        /// <summary>
        /// Parses the specified attribute blob and instantiates the attribute.
        /// </summary>
        /// <param name="module">The metadata module, which contains the attribute blob.</param>
        /// <param name="attributeBlob">The attribute blob token.</param>
        /// <param name="attributeCtor">The constructor of the attribute.</param>
        /// <returns>The fully instantiated and initialized attribute.</returns>
        /// <exception cref="System.ArgumentException"><paramref name="attributeBlob"/> is invalid.</exception>
        /// <exception cref="System.ArgumentNullException"><paramref name="module"/> is null or <paramref name="attributeCtor"/> is null.</exception>
        public static object Parse(IMetadataModule module, TokenTypes attributeBlob, RuntimeMethod attributeCtor)
        {
            // Return value
            object result;

            // The blob data
            byte[] blob = null;

            // Try to load the blob From the module
            module.Metadata.Read(attributeBlob, out blob);
            if (null != blob)
            {
                if (0 != blob.Length)
                {
                    // Create a binary reader for the blob
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(blob), Encoding.UTF8))
                    {
                        ushort prologue = reader.ReadUInt16();
                        Debug.Assert(ATTRIBUTE_BLOB_PROLOGUE == prologue, "Attribute prologue doesn't match.");
                        if (prologue != ATTRIBUTE_BLOB_PROLOGUE)
                        {
                            throw new ArgumentException("Invalid custom attribute blob.", "attributeBlob");
                        }

                        // Fixed argument list of the ctor
                        SigType[] paramSig = attributeCtor.Signature.Parameters;
                        IList <RuntimeParameter> parameters = attributeCtor.Parameters;
                        object[] args = new object[parameters.Count];
                        for (int idx = 0; idx < parameters.Count; idx++)
                        {
                            args[idx] = ParseFixedArg(module, reader, paramSig[idx]);
                        }

                        // Create the attribute instance
                        result = CreateAttribute(attributeCtor, args);

                        // Are there any named args?
                        ushort numNamed = reader.ReadUInt16();
                        for (ushort idx = 0; idx < numNamed; idx++)
                        {
                            // FIXME: Process the named arguments
                            Trace.WriteLine("Skipping named argument of an attribute.");
                        }
                    }
                }
                else
                {
                    result = CreateAttribute(attributeCtor, null);
                }
            }
            else
            {
                throw new ArgumentException("Invalid attribute blob token.", "attributeBlob");
            }

            return(result);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompilerGeneratedMethod"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="name">The name of the method.</param>
        /// <param name="declaringType">Type of the declaring.</param>
        public CompilerGeneratedMethod(IMetadataModule module, string name, RuntimeType declaringType)
            : base(0, module, declaringType)
        {
            if (name == null)
                throw new ArgumentNullException(@"name");

            this.name = name;
            this.Parameters = new List<RuntimeParameter>();
        }
Exemplo n.º 25
0
        /// <summary>
        /// Unloads the given module.
        /// </summary>
        /// <param name="module">The module to unload.</param>
        public void Unload(IMetadataModule module)
        {
            IDisposable disp = module as IDisposable;

            if (null != disp)
            {
                disp.Dispose();
            }
        }
Exemplo n.º 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CilRuntimeField"/> class.
 /// </summary>
 /// <param name="module">The module.</param>
 /// <param name="field">The field.</param>
 /// <param name="offset">The offset.</param>
 /// <param name="rva">The rva.</param>
 /// <param name="declaringType">Type of the declaring.</param>
 public CilRuntimeField(IMetadataModule module, ref FieldRow field, IntPtr offset, IntPtr rva, RuntimeType declaringType)
     : base(module, declaringType)
 {
     this.nameIdx = field.NameStringIdx;
     this.signature = field.SignatureBlobIdx;
     base.Attributes = field.Flags;
     base.RVA = rva;
     //base.Offset = offset; ?
 }
Exemplo n.º 27
0
        public MethodCompiler(IAssemblyLinker linker, IArchitecture architecture, IMetadataModule module, RuntimeType type, RuntimeMethod method, Stream codeStream) :
            base(linker, architecture, module, type, method)
        {
            if (null == codeStream)
            {
                throw new ArgumentNullException(@"codeStream");
            }

            _codeStream = codeStream;
        }
Exemplo n.º 28
0
        public CilRuntimeField(RuntimeField genericField, IMetadataModule module, FieldSignature signature)
            : base(module, genericField.DeclaringType)
        {
            this.Name = genericField.Name;
            this.Attributes = genericField.Attributes;
            this.RVA = genericField.RVA;
            this.Signature = signature;

            this.SetAttributes(genericField.CustomAttributes);
        }
Exemplo n.º 29
0
        protected void LoadAssembly(string filename)
        {
            IAssemblyLoader assemblyLoader = new AssemblyLoader();

            assemblyLoader.AddPrivatePath(System.IO.Path.GetDirectoryName(filename));

            metadataModule = assemblyLoader.LoadModule(filename);

            UpdateTree();
        }
Exemplo n.º 30
0
        public CilGenericType(RuntimeType type, IMetadataModule referencingModule, GenericInstSigType genericTypeInstanceSignature, ISignatureContext signatureContext)
            : base(type.Token, type.Module)
        {
            this.signature = genericTypeInstanceSignature;
            this.signatureContext = signatureContext;
            this.signatureModule = referencingModule;

            this.Methods = this.GetMethods();
            this.Fields = this.GetFields();
        }
Exemplo n.º 31
0
        /// <summary>
        /// Initializes a new compiler instance.
        /// </summary>
        /// <param name="architecture">The compiler target architecture.</param>
        /// <param name="assembly">The assembly of this compiler.</param>
        /// <exception cref="System.ArgumentNullException">Either <paramref name="architecture"/> or <paramref name="assembly"/> is null.</exception>
        protected AssemblyCompiler(IArchitecture architecture, IMetadataModule assembly)
        {
            if (architecture == null)
            {
                throw new ArgumentNullException("architecture");
            }

            _architecture = architecture;
            _assembly     = assembly;
            _pipeline     = new CompilerPipeline();
        }
Exemplo n.º 32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompilerGeneratedMethod"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="name">The name of the method.</param>
        /// <param name="declaringType">Type of the declaring.</param>
        public CompilerGeneratedMethod(IMetadataModule module, string name, RuntimeType declaringType) :
            base(0, module, declaringType)
        {
            if (name == null)
            {
                throw new ArgumentNullException(@"name");
            }

            this.name       = name;
            this.Parameters = new List <RuntimeParameter>();
        }
Exemplo n.º 33
0
        /// <summary>
        /// Loads the specified assembly into the mosa runtime and executes the mosa compiler.
        /// </summary>
        /// <param name="assemblyFile">The assembly file name.</param>
        /// <returns>The metadata module, which represents the loaded assembly.</returns>
        private IMetadataModule RunMosaCompiler(string assemblyFile)
        {
            IMetadataModule rtModule = RuntimeBase.Instance.AssemblyLoader.Load(
                typeof(RuntimeBase).Module.FullyQualifiedName
                );
            IMetadataModule module = RuntimeBase.Instance.AssemblyLoader.Load(
                assemblyFile
                );

            TestCaseAssemblyCompiler.Compile(module);
            return(module);
        }
Exemplo n.º 34
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompilerGeneratedType"/> class.
        /// </summary>
        /// <param name="module">The metadata module owning the type.</param>
        /// <param name="namespace">The namespace.</param>
        /// <param name="name">The name.</param>
        public CompilerGeneratedType(IMetadataModule module, string @namespace, string name)
            : base(0, module)
        {
            if (null == @namespace)
                throw new ArgumentNullException(@"namespace");
            if (null == name)
                throw new ArgumentNullException(@"name");

            base.Namespace = @namespace;
            base.Name = name;
            base.Methods = new List<RuntimeMethod>();
        }
Exemplo n.º 35
0
        /// <summary>
        /// Loads the named assembly.
        /// </summary>
        /// <param name="file">The file path of the assembly to load.</param>
        /// <returns>
        /// The assembly image of the loaded assembly.
        /// </returns>
        IMetadataModule IAssemblyLoader.LoadModule(string file)
        {
            lock (loaderLock)
            {
                IMetadataModule module = LoadDependencies(file);

                Debug.Assert(module != null);
                Debug.Assert(module.Metadata != null);

                return(module);
            }
        }
Exemplo n.º 36
0
        /// <summary>
        /// Loads all parameters From the given metadata module.
        /// </summary>
        /// <param name="module">The metadata module to load methods From.</param>
        /// <param name="offset">The offset into the parameter table to start loading methods From.</param>
        private void LoadParameters(IMetadataModule module, int offset)
        {
            IMetadataProvider md = module.Metadata;
            TokenTypes        token, maxParam = md.GetMaxTokenValue(TokenTypes.Param);
            ParamRow          paramDef;

            token = TokenTypes.Param + 1;
            while (token <= maxParam)
            {
                md.Read(token++, out paramDef);
                _parameters[offset++] = new RuntimeParameter(module, paramDef);
            }
        }
 private TestCaseAssemblyCompiler(IArchitecture architecture, IMetadataModule module)
     : base(architecture, module)
 {
     // Build the assembly compiler pipeline
     CompilerPipeline pipeline = this.Pipeline;
     pipeline.AddRange(new IAssemblyCompilerStage[] {
         new TypeLayoutStage(),
         new AssemblyMemberCompilationSchedulerStage(),
         new MethodCompilerSchedulerStage(),
         new TestAssemblyLinker(),
     });
     architecture.ExtendAssemblyCompilerPipeline(pipeline);
 }
Exemplo n.º 38
0
 public AotAssemblyCompiler(IArchitecture architecture, IMetadataModule assembly, ITypeInitializerSchedulerStage typeInitializerSchedulerStage, IAssemblyLinker linker)
     : base(architecture, assembly)
 {
     this.Pipeline.AddRange(
             new IAssemblyCompilerStage[]
             {
                 new TypeLayoutStage(),
                 new AssemblyMemberCompilationSchedulerStage(),
                 new MethodCompilerSchedulerStage(),
                 new TypeInitializerSchedulerStageProxy(typeInitializerSchedulerStage),
                 new LinkerProxy(linker)
             });
 }
Exemplo n.º 39
0
        private IMetadataModule GetLoadedAssembly(string name)
        {
            IMetadataModule result = null;

            foreach (IMetadataModule image in _loadedImages)
            {
                if (name.Equals(image.Name))
                {
                    result = image;
                    break;
                }
            }
            return(result);
        }
        /// <summary>
        /// Parses the specified attribute blob and instantiates the attribute.
        /// </summary>
        /// <param name="module">The metadata module, which contains the attribute blob.</param>
        /// <param name="attributeBlob">The attribute blob token.</param>
        /// <param name="attributeCtor">The constructor of the attribute.</param>
        /// <returns>The fully instantiated and initialized attribute.</returns>
        /// <exception cref="System.ArgumentException"><paramref name="attributeBlob"/> is invalid.</exception>
        /// <exception cref="System.ArgumentNullException"><paramref name="module"/> is null or <paramref name="attributeCtor"/> is null.</exception>
        public static object Parse(IMetadataModule module, TokenTypes attributeBlob, RuntimeMethod attributeCtor)
        {
            // Return value
            object result;

            // Try to load the blob from the module
            byte[] blob = module.Metadata.ReadBlob(attributeBlob);
            if (null != blob)
            {
                if (0 != blob.Length)
                {
                    // Create a binary reader for the blob
                    using (BinaryReader reader = new BinaryReader(new MemoryStream(blob), Encoding.UTF8))
                    {
                        ushort prologue = reader.ReadUInt16();
                        Debug.Assert(ATTRIBUTE_BLOB_PROLOGUE == prologue, @"Attribute prologue doesn't match.");
                        if (prologue != ATTRIBUTE_BLOB_PROLOGUE)
                            throw new ArgumentException(@"Invalid custom attribute blob.", "attributeBlob");

                        // Fixed argument list of the ctor
                        SigType[] paramSig = attributeCtor.Signature.Parameters;
                        IList<RuntimeParameter> parameters = attributeCtor.Parameters;
                        object[] args = new object[parameters.Count];
                        for (int idx = 0; idx < parameters.Count; idx++)
                            args[idx] = ParseFixedArg(module, reader, paramSig[idx]);

                        // Create the attribute instance
                        result = CreateAttribute(attributeCtor, args);

                        // Are there any named args?
                        ushort numNamed = reader.ReadUInt16();
                        for (ushort idx = 0; idx < numNamed; idx++)
                        {
                            // FIXME: Process the named arguments
                            Trace.WriteLine(@"Skipping named argument of an attribute.");
                        }
                    }
                }
                else
                {
                    result = CreateAttribute(attributeCtor, null);
                }
            }
            else
            {
                throw new ArgumentException(@"Invalid attribute blob token.", @"attributeBlob");
            }

            return result;
        }
Exemplo n.º 41
0
        /// <summary>
        /// Resolves the given assembly reference and loads the associated IMetadataModule.
        /// </summary>
        /// <param name="provider">The metadata provider, which contained the assembly reference.</param>
        /// <param name="assemblyRef">The assembly reference to resolve.</param>
        /// <returns>
        /// An instance of IMetadataModule representing the resolved assembly.
        /// </returns>
        public IMetadataModule Resolve(IMetadataProvider provider, AssemblyRefRow assemblyRef)
        {
            string name;

            provider.Read(assemblyRef.NameIdx, out name);

            IMetadataModule result = GetLoadedAssembly(name) ?? DoLoadAssembly(name + ".dll");

            if (result == null)
            {
                throw new TypeLoadException();
            }

            return(result);
        }
Exemplo n.º 42
0
        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        /// <param name="compiler">The compiler context to perform processing in.</param>
        public void Run(AssemblyCompiler compiler)
        {
            IAssemblyLinker linker = compiler.Pipeline.Find <IAssemblyLinker>();

            if (linker == null)
            {
                throw new InvalidOperationException(@"Can't run without a linker.");
            }

            // FIXME: Retrieve the compilation target assembly
            // HACK: Using Metadata From source assembly, rather than re-create it From scratch From the target assembly
            IMetadataModule module = compiler.Assembly;

            ExportCilMetadata(module, linker);
        }
Exemplo n.º 43
0
 private TestCaseAssemblyCompiler(IArchitecture architecture, IMetadataModule module)
     : base(architecture, module)
 {
     // Build the assembly compiler pipeline
     CompilerPipeline pipeline = this.Pipeline;
     pipeline.AddRange(new IAssemblyCompilerStage[] {
         new TypeLayoutStage(),
         new MethodCompilerBuilderStage(),
         new MethodCompilerRunnerStage(),
         // __grover, 01/02/2009: No object files in test!
         // new ObjectFileLayoutStage()
         new TestAssemblyLinker(),
     });
     architecture.ExtendAssemblyCompilerPipeline(pipeline);
 }
Exemplo n.º 44
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CompilerGeneratedType"/> class.
        /// </summary>
        /// <param name="module">The metadata module owning the type.</param>
        /// <param name="namespace">The namespace.</param>
        /// <param name="name">The name.</param>
        public CompilerGeneratedType(IMetadataModule module, string @namespace, string name) :
            base(0, module)
        {
            if (null == @namespace)
            {
                throw new ArgumentNullException(@"namespace");
            }
            if (null == name)
            {
                throw new ArgumentNullException(@"name");
            }

            base.Namespace = @namespace;
            base.Name      = name;
            base.Methods   = new List <RuntimeMethod>();
        }
Exemplo n.º 45
0
        private TestCaseAssemblyCompiler(IArchitecture architecture, IMetadataModule module) :
            base(architecture, module)
        {
            // Build the assembly compiler pipeline
            CompilerPipeline pipeline = this.Pipeline;

            pipeline.AddRange(new IAssemblyCompilerStage[] {
                new TypeLayoutStage(),
                new MethodCompilerBuilderStage(),
                new MethodCompilerRunnerStage(),
                // __grover, 01/02/2009: No object files in test!
                // new ObjectFileLayoutStage()
                new TestAssemblyLinker(),
            });
            architecture.ExtendAssemblyCompilerPipeline(pipeline);
        }
Exemplo n.º 46
0
        /// <summary>
        /// Gets the types From module.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <returns></returns>
        ReadOnlyRuntimeTypeListView ITypeSystem.GetTypesFromModule(IMetadataModule module)
        {
            if (null == module)
            {
                throw new ArgumentNullException(@"module");
            }

            // Determine the offsets of the module
            ModuleOffsets offsets = GetModuleOffset(module);

            // Calculate the number of types defined in this module
            int count = ((int)(TokenTypes.RowIndexMask & module.Metadata.GetMaxTokenValue(TokenTypes.TypeDef)) - 1 + 0);

            // FIXME: (int)(TokenTypes.RowIndexMask & module.Metadata.GetMaxTokenValue(TokenTypes.TypeSpec)));

            return(new ReadOnlyRuntimeTypeListView(offsets.TypeOffset, count));
        }
Exemplo n.º 47
0
        RuntimeMethod ITypeSystem.GetMethod(IMetadataModule scope, TokenTypes token)
        {
            if (null == scope)
            {
                throw new ArgumentNullException(@"scope");
            }

            switch (TokenTypes.TableMask & token)
            {
            case TokenTypes.MethodDef:
            {
                ModuleOffsets offsets = GetModuleOffset(scope);
                return(_methods[offsets.MethodOffset + (int)(TokenTypes.RowIndexMask & token) - 1]);
            }

            case TokenTypes.MemberRef:
            {
                MemberRefRow row;
                scope.Metadata.Read(token, out row);
                RuntimeType type = this.ResolveTypeRef(scope, row.ClassTableIdx);
                string      nameString;
                scope.Metadata.Read(row.NameStringIdx, out nameString);
                MethodSignature sig = (MethodSignature)Signature.FromMemberRefSignatureToken(scope.Metadata, row.SignatureBlobIdx);
                foreach (RuntimeMethod method in type.Methods)
                {
                    if (method.Name != nameString)
                    {
                        continue;
                    }
                    if (!method.Signature.Matches(sig))
                    {
                        continue;
                    }
                    return(method);
                }
                throw new MissingMethodException(type.Name, nameString);
            }

            case TokenTypes.MethodSpec:
                throw new NotImplementedException();

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 48
0
        /// <summary>
        /// Exports the CIL metadata.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="linker">The linker.</param>
        private void ExportCilMetadata(IMetadataModule module, IAssemblyLinker linker)
        {
            /*
             * FIXME:
             * - Obtain CIL & MOSA metadata tables
             * - Write metadata root
             * - Write the CIL tables (modified)
             * - Write the MOSA tables (new)
             * - Write the strings, guid and blob heap (unchanged From original module)
             */

            // Metadata is in the .text section in order to make it relocatable everywhere.
            using (Stream stream = linker.Allocate(Runtime.Metadata.Symbol.Name, SectionKind.Text, module.Metadata.Metadata.Length, 0))

                using (BinaryWriter bw = new BinaryWriter(stream, Encoding.ASCII)) {
                    bw.Write(module.Metadata.Metadata);
                }
        }
Exemplo n.º 49
0
        private IMetadataModule LoadAssembly(string file)
        {
            if (Path.IsPathRooted(file))
            {
                return(LoadPEAssembly(file));
            }

            file = Path.GetFileName(file);

            if (!file.EndsWith(".dll"))
            {
                file = file + ".dll";
            }

            IMetadataModule result = TryAssemblyLoadFromPaths(file, privatePaths);

            return(result);
        }
Exemplo n.º 50
0
        /// <summary>
        /// Exports the CIL metadata.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="linker">The linker.</param>
        private void ExportCilMetadata(IMetadataModule module, IAssemblyLinker linker)
        {
            /*
             * FIXME:
             * - Obtain CIL & MOSA metadata tables
             * - Write metadata root
             * - Write the CIL tables (modified)
             * - Write the MOSA tables (new)
             * - Write the strings, guid and blob heap (unchanged From original module)
             */

            // Metadata is in the .text section in order to make it relocatable everywhere.
            using (Stream stream = linker.Allocate(Runtime.Metadata.Symbol.Name, SectionKind.Text, module.Metadata.Metadata.Length, 0))

            using (BinaryWriter bw = new BinaryWriter(stream, Encoding.ASCII)) {
                bw.Write(module.Metadata.Metadata);
            }
        }
Exemplo n.º 51
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CilRuntimeMethod"/> class.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="module">The module.</param>
        /// <param name="method">The method.</param>
        /// <param name="maxParam">The max param.</param>
        /// <param name="declaringType">Type of the declaring.</param>
        public CilRuntimeMethod(int token, IMetadataModule module, ref MethodDefRow method, TokenTypes maxParam, RuntimeType declaringType)
            : base((int)token, module, declaringType)
        {
            this.nameIdx = method.NameStringIdx;
            this.signatureBlobIdx = method.SignatureBlobIdx;
            base.Attributes = method.Flags;
            base.ImplAttributes = method.ImplFlags;
            base.Rva = method.Rva;

            if (method.ParamList < maxParam)
            {
                int count = maxParam - method.ParamList;
                int p = (int)(method.ParamList & TokenTypes.RowIndexMask) - 1 + RuntimeBase.Instance.TypeLoader.GetModuleOffset(module).ParameterOffset;
                base.Parameters = new ReadOnlyRuntimeParameterListView(p, count);
            }
            else
            {
                base.Parameters = ReadOnlyRuntimeParameterListView.Empty;
            }
        }
Exemplo n.º 52
0
        private static void Process(Encoding encoding, IMetadataModule al, Dictionary<string, object> result, FileInfo file)
        {
            using (var memStream = new MemoryStream())
            {
                using (var stream = file.Open(FileMode.Open))
                {
                    stream.CopyTo(memStream);

                    memStream.Flush();

                    memStream.Position = 0;
                }

                using (var sr = new StreamReader(memStream, encoding))
                {
                    var content = sr.ReadToEnd();

                    al.OnProcess(result, content);
                }
            }
        }
Exemplo n.º 53
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CilRuntimeType"/> class.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="module">The module.</param>
        /// <param name="typeDefRow">The type def row.</param>
        /// <param name="maxField">The max field.</param>
        /// <param name="maxMethod">The max method.</param>
        /// <param name="packing">The packing.</param>
        /// <param name="size">The size.</param>
        public CilRuntimeType(TokenTypes token, IMetadataModule module, ref TypeDefRow typeDefRow, TokenTypes maxField, TokenTypes maxMethod, int packing, int size)
            : base((int)token, module)
        {
            this.baseTypeToken = typeDefRow.Extends;
            this.module = module;
            this.nameIdx = typeDefRow.TypeNameIdx;
            this.namespaceIdx = typeDefRow.TypeNamespaceIdx;

            base.Attributes = typeDefRow.Flags;
            base.Pack = packing;
            base.Size = size;

            // Load all fields of the type
            int members = maxField - typeDefRow.FieldList;
            if (0 < members)
            {
                int i = (int)(typeDefRow.FieldList & TokenTypes.RowIndexMask) - 1 + RuntimeBase.Instance.TypeLoader.GetModuleOffset(module).FieldOffset;
                base.Fields = new ReadOnlyRuntimeFieldListView(i, members);
            }
            else
            {
                base.Fields = ReadOnlyRuntimeFieldListView.Empty;
            }

            // Load all methods of the type
            members = maxMethod - typeDefRow.MethodList;
            if (0 < members)
            {
                int i = (int)(typeDefRow.MethodList & TokenTypes.RowIndexMask) - 1 + RuntimeBase.Instance.TypeLoader.GetModuleOffset(module).MethodOffset;
                base.Methods = new ReadOnlyRuntimeMethodListView(i, members);
            }
            else
            {
                base.Methods = ReadOnlyRuntimeMethodListView.Empty;
            }
        }
Exemplo n.º 54
0
 public static TableRow GetTableRow(IMetadataModule metadataModule, Token token)
 {
     switch (token.Table)
     {
         case TableType.File: return new FileRowExt(metadataModule, metadataModule.Metadata.ReadFileRow(token));
         case TableType.TypeDef: return new TypeDefRowExt(metadataModule, metadataModule.Metadata.ReadTypeDefRow(token));
         case TableType.TypeSpec: return new TypeSpecRowExt(metadataModule, metadataModule.Metadata.ReadTypeSpecRow(token));
         case TableType.TypeRef: return new TypeRefRowExt(metadataModule, metadataModule.Metadata.ReadTypeRefRow(token));
         case TableType.Field: return new FieldRowExt(metadataModule, metadataModule.Metadata.ReadFieldRow(token));
         case TableType.MethodDef: return new MethodDefRowExt(metadataModule, metadataModule.Metadata.ReadMethodDefRow(token));
         case TableType.ImplMap: return new ImplMapRowExt(metadataModule, metadataModule.Metadata.ReadImplMapRow(token));
         case TableType.MemberRef: return new MemberRefRowExt(metadataModule, metadataModule.Metadata.ReadMemberRefRow(token));
         case TableType.InterfaceImpl: return new InterfaceImplRowExt(metadataModule, metadataModule.Metadata.ReadInterfaceImplRow(token));
         case TableType.CustomAttribute: return new CustomAttributeRowExt(metadataModule, metadataModule.Metadata.ReadCustomAttributeRow(token));
         case TableType.Assembly: return new AssemblyRowExt(metadataModule, metadataModule.Metadata.ReadAssemblyRow(token));
         case TableType.AssemblyRef: return new AssemblyRefRowExt(metadataModule, metadataModule.Metadata.ReadAssemblyRefRow(token));
         case TableType.GenericParam: return new GenericParamRowExt(metadataModule, metadataModule.Metadata.ReadGenericParamRow(token));
         case TableType.Param: return new ParamRowExt(metadataModule, metadataModule.Metadata.ReadParamRow(token));
         case TableType.StandAloneSig: return new StandAloneSigExt(metadataModule, metadataModule.Metadata.ReadStandAloneSigRow(token));
         case TableType.MethodSpec: return new MethodSpecExt(metadataModule, metadataModule.Metadata.ReadMethodSpecRow(token));
         case TableType.NestedClass: return new NestedClassExt(metadataModule, metadataModule.Metadata.ReadNestedClassRow(token));
         default: return null;
     }
 }
Exemplo n.º 55
0
 private static Token GetLocalTypeRefToken(IMetadataModule module, Token ctorToken)
 {
     MemberRefRow memberRef = module.Metadata.ReadMemberRefRow(ctorToken);
     return memberRef.Class;
 }
Exemplo n.º 56
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MetadataRoot"/> class.
 /// </summary>
 /// <param name="assemblyImage">The assembly image.</param>
 public MetadataRoot(IMetadataModule assemblyImage)
 {
     _assemblyImage = assemblyImage;
 }
Exemplo n.º 57
0
        /// <summary>
        /// Parses an SZArray attribute value.
        /// </summary>
        /// <param name="module">The metadata module, which contains the attribute blob.</param>
        /// <param name="reader">The binary reader used to read From the attribute blob.</param>
        /// <param name="sigType">Type of the SZArray.</param>
        /// <returns>An Array, which represents the SZArray definition.</returns>
        private static object ParseSZArrayArg(IMetadataModule module, BinaryReader reader, SZArraySigType sigType)
        {
            // Return value
            Array result;

            // Determine the number of elements
            int numElements = reader.ReadInt32();
            if (-1 == numElements)
                return null;

            // Retrieve the array element type
            Type elementType = GetTypeFromSigType(sigType);
            Debug.Assert(null != elementType, @"Failed to get System.Type for SigType.");
            result = Array.CreateInstance(elementType, numElements);
            for (int idx = 0; idx < numElements; idx++) {
                object item = ParseElem(module, reader, sigType.ElementType);
                result.SetValue(item, idx);
            }

            return result;
        }
Exemplo n.º 58
0
        /// <summary>
        /// Parses a fixed argument in an attribute blob definition.
        /// </summary>
        /// <param name="module">The metadata module, which contains the attribute blob.</param>
        /// <param name="reader">The binary reader to read it From.</param>
        /// <param name="sigType">The signature type of the value to read.</param>
        /// <returns></returns>
        private static object ParseFixedArg(IMetadataModule module, BinaryReader reader, SigType sigType)
        {
            // Return value
            object result = null;

            // A vector?
            SZArraySigType arraySigType = sigType as SZArraySigType;
            if (arraySigType != null)
                result = ParseSZArrayArg(module, reader, arraySigType);
            else
                result = ParseElem(module, reader, sigType);

            return result;
        }
Exemplo n.º 59
0
        /// <summary>
        /// Parses an elementary field, parameter or property definition.
        /// </summary>
        /// <param name="module">The metadata module, which contains the attribute blob.</param>
        /// <param name="reader">The binary reader to read data From.</param>
        /// <param name="sigType">The signature type of the field, parameter or property to read.</param>
        /// <returns>An object, which represents the value read From the attribute blob.</returns>
        /// <exception cref="System.NotSupportedException"><paramref name="sigType"/> is not yet supported.</exception>
        private static object ParseElem(IMetadataModule module, BinaryReader reader, SigType sigType)
        {
            object result;

            switch (sigType.Type) {
                case CilElementType.Boolean:
                    result = (1 == reader.ReadByte());
                    break;

                case CilElementType.Char:
                    result = (char)reader.ReadUInt16();
                    break;

                case CilElementType.I1:
                    result = reader.ReadSByte();
                    break;

                case CilElementType.I2:
                    result = reader.ReadInt16();
                    break;

                case CilElementType.I4:
                    result = reader.ReadInt32();
                    break;

                case CilElementType.I8:
                    result = reader.ReadInt64();
                    break;

                case CilElementType.U1:
                    result = reader.ReadByte();
                    break;

                case CilElementType.U2:
                    result = reader.ReadUInt16();
                    break;

                case CilElementType.U4:
                    result = reader.ReadUInt32();
                    break;

                case CilElementType.U8:
                    result = reader.ReadUInt64();
                    break;

                case CilElementType.R4:
                    result = reader.ReadSingle();
                    break;

                case CilElementType.R8:
                    result = reader.ReadDouble();
                    break;

                case CilElementType.String:
                    result = ParseSerString(reader);
                    break;

                case CilElementType.Type: {
                        string typeName = ParseSerString(reader);
                        result = Type.GetType(typeName);
                    }
                    break;

                case CilElementType.Class: {
                        string typeName = ParseSerString(reader);
                        string[] type = typeName.Split(',');
                        if (type.Length > 1)
                        {
                            result = Type.GetType(typeName);
                        }
                        else
                        {
                            result = Type.GetType(typeName + ", " + module.Name);
                        }
                    }
                    break;

                case CilElementType.ValueType: {
                        ValueTypeSigType vtSigType = sigType as ValueTypeSigType;
                        ITypeSystem ts = RuntimeBase.Instance.TypeLoader;
                        RuntimeType type = ts.GetType(module, vtSigType.Token);
                        RuntimeType baseType = type.BaseType;
                        if (@"System" == baseType.Namespace && "Enum" == baseType.Name) {
                            // Retrieve the value__ field to get the enums integer type
                            Debug.Assert(type.Fields.Count == 1, @"More than one field in the enum.");
                            RuntimeField value = type.Fields[0];
                            Debug.Assert(value.Name == @"value__", @"First field of enum not named value__");
                            result = ParseElem(module, reader, value.Type);
                            Type enumType = Type.GetType(type.Namespace + "." + type.Name);
                            result = Enum.ToObject(enumType, result);
                        }
                        else {
                            throw new NotSupportedException();
                        }
                    }
                    break;

                case CilElementType.Object:
                    throw new NotSupportedException();

                default:
                    throw new NotSupportedException();
            }

            return result;
        }
Exemplo n.º 60
0
        private SigType CreateSignatureTypeFor(IMetadataModule module, Token ctorToken, RuntimeType declaringType)
        {
            Token typeToken = declaringType.Token;
            if (IsMemberRef(ctorToken) == true)
            {
                typeToken = GetLocalTypeRefToken(module, ctorToken);
            }

            //if (declaringType.IsValueType)
            //{
            //    // TODO
            //    var typeSpecRow = module.Metadata.ReadTypeSpecRow(typeToken);
            //    var typeSpecSignature = new TypeSpecSignature(module.Metadata, typeSpecRow.SignatureBlobIdx);
            //    return typeSpecSignature.Type;
            //    //return new ValueTypeSigType(typeToken);
            //}

            return new ClassSigType(typeToken);
        }