Ejemplo n.º 1
0
        RuntimeMethod ITypeSystem.GetImplementationForInternalCall(RuntimeMethod internalCall)
        {
            Debug.Assert(internalCall != null, @"internalCall is null.");
            if (null == internalCall)
            {
                throw new ArgumentNullException(@"internalCall");
            }

            // Return value
            RuntimeMethod result = null;

            // Shortcut: If the call was resolved previously, scan it there
            if (this.internalCallTargets.TryGetValue(internalCall, out result))
            {
                return(result);
            }

            /*
             * FIXME:
             * - The following sequence requires that mscorlib is available in the test runtime.
             * - Maybe we should be smarter about its use though.
             * - Commented out right now, as we don't load assembly dependencies yet.
             */

            ITypeSystem ts = (ITypeSystem)this;
            // FIXME: Include this when we're loading mscorlib
            //RuntimeType rtMia = ts.GetType(@"System.Runtime.CompilerServices.MethodImplAttribute");
            //MethodImplAttribute mia = (MethodImplAttribute)internalCall.GetAttributes(rtMia, true);
            //Debug.Assert(MethodImplOptions.InternalCall == (mia.Value & MethodImplOptions.InternalCall), @"Method is not InternalCall.");
            //if (MethodImplOptions.InternalCall != (mia.Value & MethodImplOptions.InternalCall))
            //    throw new ArgumentException(@"Method not marked as an InternalCall.", @"internalCall");

            RuntimeType callImplType = ts.GetType("Mosa.Runtime.Vm.InternalCallImplAttribute");

            object[] callDefAttrs = internalCall.GetCustomAttributes(callImplType);
            Debug.Assert(0 != callDefAttrs.Length, @"No runtime call definition for icall!");
            Debug.Assert(1 == callDefAttrs.Length, @"Only one call definition for icall supported! Additional ones ignored!");
            InternalCallImplAttribute callDef = (InternalCallImplAttribute)callDefAttrs[0];

            // Scan all known types for icalls
            foreach (RuntimeType rType in internalTypes)
            {
                foreach (RuntimeMethod rMethod in rType.Methods)
                {
                    object[] callImpls = rMethod.GetCustomAttributes(callImplType);
                    foreach (InternalCallImplAttribute callImpl in callImpls)
                    {
                        if (callDef.Match(callImpl) == true)
                        {
                            // We found the sought icall, save it and return it
                            this.internalCallTargets[internalCall] = rMethod;
                            return(rMethod);
                        }
                    }
                }
            }

            throw new NotImplementedException(@"Requested InternalCall not loaded or not implemented.");
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Locates the attribute ctor method.
 /// </summary>
 private void LocateAttributeCtorMethod()
 {
     _ctorMethod = RuntimeBase.Instance.TypeLoader.GetMethod(_module, _ctor);
     Debug.Assert(null != _ctorMethod);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets the attributes.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="owner">The owner.</param>
        /// <param name="attributes">The attributes.</param>
        private void SetAttributes(IMetadataModule module, TokenTypes owner, List <CustomAttributeRow> attributes)
        {
            ITypeSystem ts = (ITypeSystem)this;

            // Convert the custom attribute rows to RuntimeAttribute instances
            RuntimeAttribute[] ra = new RuntimeAttribute[attributes.Count];
            for (int i = 0; i < attributes.Count; i++)
            {
                ra[i] = new RuntimeAttribute(module, attributes[i]);
            }

            // The following switch matches the AttributeTargets enumeration against
            // metadata tables, which make valid targets for an attribute.
            switch (owner & TokenTypes.TableMask)
            {
            case TokenTypes.Assembly:
                // AttributeTargets.Assembly
                break;

            case TokenTypes.TypeDef:
                // AttributeTargets.Class
                // AttributeTargets.Delegate
                // AttributeTargets.Enum
                // AttributeTargets.Interface
                // AttributeTargets.Struct
                RuntimeType type = ts.GetType(module, owner);
                type.SetAttributes(ra);
                if (rtCallTypeAttribute != null)
                {
                    if (type.IsDefined(rtCallTypeAttribute) == true)
                    {
                        this.internalTypes.Add(type);
                    }
                }
                break;

            case TokenTypes.MethodDef:
                // AttributeTargets.Constructor
                // AttributeTargets.Method
                RuntimeMethod method = ts.GetMethod(module, owner);
                method.SetAttributes(ra);
                break;

            case TokenTypes.Event:
                // AttributeTargets.Event
                break;

            case TokenTypes.Field:
                // AttributeTargets.Field
                break;

            case TokenTypes.GenericParam:
                // AttributeTargets.GenericParameter
                break;

            case TokenTypes.Module:
                // AttributeTargets.Module
                break;

            case TokenTypes.Param:
                // AttributeTargets.Parameter
                // AttributeTargets.ReturnValue
                break;

            case TokenTypes.Property:
                // AttributeTargets.StackFrameIndex
                break;
            }
        }