Beispiel #1
0
 public RloLocal(Compiler compiler, HighLocal highLocal, RloInstantiationParameters instParams, bool isArg)
 {
     switch (highLocal.TypeOfType)
     {
         case HighLocal.ETypeOfType.ByRef:
             {
                 RloValueType vt = new RloValueType(compiler, highLocal.Type, instParams);
                 vt = (RloValueType)compiler.InternRloType(vt);
                 RloRefType rt = new RloRefType(vt);
                 rt = (RloRefType)compiler.InternRloType(rt);
                 m_type = rt;
             }
             break;
         case HighLocal.ETypeOfType.TypedByRef:
             m_type = compiler.InternedRloTypedRefType;
             break;
         case HighLocal.ETypeOfType.Value:
             {
                 RloValueType vt = new RloValueType(compiler, highLocal.Type, instParams);
                 vt = (RloValueType)compiler.InternRloType(vt);
                 m_type = vt;
             }
             break;
         default:
             throw new Exception();
     }
 }
 public RloInitExceptionsPass(Compiler compiler, RloMethodBody methodBody)
 {
     m_compiler = compiler;
     m_methodBody = methodBody;
     m_routeCompactionDict = new Dictionary<uint, int>();
     m_terminators = new Dictionary<uint, HighCfgNode>();
 }
Beispiel #3
0
 public RloFindUseDefsPass(Compiler compiler, RloMethodBody methodBody)
     : base(compiler, methodBody)
 {
     m_uses = new Dictionary<HighSsaRegister, HashSet<ISsaUser>>();
     m_defs = new Dictionary<HighSsaRegister, HashSet<ISsaEmitter>>();
     m_useVisitorDelegate = this.VisitForUses;
     m_defVisitorDelegate = this.VisitForDefs;
 }
Beispiel #4
0
        private CliClass(CliClass baseClass, Compiler compiler, TypeSpecTag[] argTypes)
        {
            if (!baseClass.m_isCreated)
                throw new Exception("Can't instantiate an open class that hasn't been processed");

            m_typeName = baseClass.m_typeName;
            m_parentClassSpec = (TypeSpecClassTag)baseClass.m_parentClassSpec.Instantiate(compiler.TagRepository, argTypes);
            m_parentClass = compiler.GetClosedClass(m_parentClassSpec);
            m_isSealed = baseClass.m_isSealed;
            m_isAbstract = baseClass.m_isAbstract;
            m_isStruct = baseClass.m_isStruct;
            m_typeSpec = (TypeSpecClassTag)compiler.TagRepository.InternTypeSpec(new TypeSpecClassTag(m_typeName, argTypes));

            m_isCreated = baseClass.m_isCreated;

            m_numGenericParameters = baseClass.m_numGenericParameters;

            List<HighField> staticFields = new List<HighField>();
            foreach (HighField fld in baseClass.m_staticFields)
                staticFields.Add(fld.Instantiate(compiler.TagRepository, argTypes));

            m_staticFields = staticFields.ToArray();

            List<HighMethod> methods = new List<HighMethod>();
            foreach (HighMethod method in baseClass.m_methods)
                methods.Add(method.Instantiate(compiler.TagRepository, argTypes));
            m_methods = methods.ToArray();

            List<HighField> instanceFields = new List<HighField>();
            foreach (HighField fld in baseClass.m_instanceFields)
                instanceFields.Add(fld.Instantiate(compiler.TagRepository, argTypes));
            m_instanceFields = instanceFields.ToArray();

            List<CliVtableSlot> vtableSlots = new List<CliVtableSlot>();
            foreach (CliVtableSlot slot in baseClass.m_vtable)
                vtableSlots.Add(slot.Instantiate(compiler, argTypes));
            m_vtable = vtableSlots.ToArray();

            List<CliInterfaceImpl> interfaceImpls = new List<CliInterfaceImpl>();
            foreach (CliInterfaceImpl ifcImpl in baseClass.m_interfaceImpls)
                interfaceImpls.Add(ifcImpl.Instantiate(compiler, argTypes));
            m_interfaceImpls = interfaceImpls.ToArray();

            List<TypeSpecClassTag> explicitInterfaces = new List<TypeSpecClassTag>();
            foreach (TypeSpecClassTag ifc in baseClass.m_explicitInterfaceSpecs)
                explicitInterfaces.Add((TypeSpecClassTag)ifc.Instantiate(compiler.TagRepository, argTypes));
            m_explicitInterfaceSpecs = explicitInterfaces.ToArray();

            m_declTagToMethod = baseClass.m_declTagToMethod;
            m_declTagToVTableSlot = baseClass.m_declTagToVTableSlot;
            m_ifcToIfcSlot = baseClass.m_ifcToIfcSlot;
            m_nameToInstanceFieldSlot = baseClass.m_nameToInstanceFieldSlot;
            m_nameToStaticFieldSlot = baseClass.m_nameToStaticFieldSlot;
        }
        public AssignabilityResolver(Compiler compiler)
        {
            m_compiler = compiler;

            m_objectType = ResolveSimpleType("System", "Object");
            m_arrayType = ResolveSimpleType("System", "Array");
            m_refSZArrayName = compiler.TagRepository.InternTypeName(new TypeNameTag("mscorlib", "Clarity", "RefSZArray"));
            m_valueSZArrayName = compiler.TagRepository.InternTypeName(new TypeNameTag("mscorlib", "Clarity", "ValueSZArray`1", 1, null));
            m_nullableSZArrayName = compiler.TagRepository.InternTypeName(new TypeNameTag("mscorlib", "Clarity", "NullableSZArray`1", 1, null));
            m_nullableName = compiler.TagRepository.InternTypeName(new TypeNameTag("mscorlib", "System", "Nullable`1", 1, null));

            m_ilistName = compiler.TagRepository.InternTypeName(new TypeNameTag("mscorlib", "System.Collections.Generic", "IList`1", 1, null));
            m_icollectionName = compiler.TagRepository.InternTypeName(new TypeNameTag("mscorlib", "System.Collections.Generic", "ICollection`1", 1, null));
            m_ienumerableName = compiler.TagRepository.InternTypeName(new TypeNameTag("mscorlib", "System.Collections.Generic", "IEnumerable`1", 1, null));
        }
        public PodFlags GetClassPodFlags(Compiler compiler, CliClass cls)
        {
            PodFlags podFlags = PodFlags.None;
            foreach (HighField fld in cls.InstanceFields)
            {
                TypeSpecTag fldType = fld.Type;

                if (!compiler.TypeIsValueType(fldType))
                    return PodFlags.None;

                CliClass fldClass = compiler.GetClosedClass((TypeSpecClassTag)fldType);

                podFlags &= GetClassPodFlags(compiler, fldClass);
                if (podFlags == PodFlags.None)
                    return PodFlags.None;
            }

            return podFlags;
        }
Beispiel #7
0
        public RloInitPass(Compiler compiler, RloMethodBody methodBody, RloFindPredecessorsAndSuccessorsPass psPass)
            : base(compiler, methodBody)
        {
            m_psPass = psPass;
            m_addTypeVisitor = AddSsaTypes;

            TagRepository repo = compiler.TagRepository;

            m_boolType = GetBuiltinType(repo, "System", "Boolean");
            m_charType = GetBuiltinType(repo, "System", "Char");
            m_int8Type = GetBuiltinType(repo, "System", "SByte");
            m_int16Type = GetBuiltinType(repo, "System", "Int16");
            m_int32Type = GetBuiltinType(repo, "System", "Int32");
            m_int64Type = GetBuiltinType(repo, "System", "Int64");
            m_uint8Type = GetBuiltinType(repo, "System", "Byte");
            m_uint16Type = GetBuiltinType(repo, "System", "UInt16");
            m_uint32Type = GetBuiltinType(repo, "System", "UInt32");
            m_uint64Type = GetBuiltinType(repo, "System", "UInt64");
            m_float32Type = GetBuiltinType(repo, "System", "Single");
            m_float64Type = GetBuiltinType(repo, "System", "Double");
            m_nativeIntType = GetBuiltinType(repo, "System", "IntPtr");
            m_nativeUIntType = GetBuiltinType(repo, "System", "UIntPtr");
            m_objectType = GetBuiltinType(repo, "System", "Object");
            m_runtimeTypeHandleType = GetBuiltinType(repo, "System", "RuntimeTypeHandle");
            m_runtimeFieldHandleType = GetBuiltinType(repo, "System", "RuntimeFieldHandle");

            m_simplifiedNumberType = new Dictionary<TypeSpecTag, TypeSpecClassTag>();
            m_simplifiedNumberType.Add(m_boolType, m_int32Type);
            m_simplifiedNumberType.Add(m_charType, m_int32Type);
            m_simplifiedNumberType.Add(m_int8Type, m_int32Type);
            m_simplifiedNumberType.Add(m_int16Type, m_int32Type);
            m_simplifiedNumberType.Add(m_int32Type, m_int32Type);
            m_simplifiedNumberType.Add(m_int64Type, m_int64Type);
            m_simplifiedNumberType.Add(m_uint8Type, m_int32Type);
            m_simplifiedNumberType.Add(m_uint16Type, m_int32Type);
            m_simplifiedNumberType.Add(m_uint32Type, m_int32Type);
            m_simplifiedNumberType.Add(m_uint64Type, m_int64Type);
            m_simplifiedNumberType.Add(m_nativeIntType, m_nativeIntType);
            m_simplifiedNumberType.Add(m_nativeUIntType, m_nativeIntType);
            m_simplifiedNumberType.Add(m_float32Type, m_float64Type);
            m_simplifiedNumberType.Add(m_float64Type, m_float64Type);
        }
Beispiel #8
0
        private List<MethodSpecTag> GenerateMethodSpecsForClass(Compiler compiler, TypeSpecClassTag typeSpec)
        {
            CliClass cls = compiler.GetClosedClass(typeSpec);

            List<MethodSpecTag> methodSpecs = new List<MethodSpecTag>();
            foreach (CliVtableSlot vtableSlot in cls.VTable)
            {
                if (vtableSlot.MethodSignature.NumGenericParameters > 0)
                {
                    methodSpecs.Add(null);
                    continue;
                }

                CliMethodIndex methodIndex = vtableSlot.MethodIndex;
                if (methodIndex == null)
                    throw new RpaCompileException("Can't generate vtable slot for abstract method");

                methodSpecs.Add(ResolveVirtualMethod(compiler, cls, methodIndex));
            }

            return methodSpecs;
        }
Beispiel #9
0
        public void GenerateFromTypeSpec(Compiler compiler, TypeSpecTag typeSpec, VTableGenerationCache vtCache)
        {
            List<MethodHandle> methodHandles;
            if (typeSpec is TypeSpecClassTag)
                methodHandles = GenerateVTableForClass(compiler, (TypeSpecClassTag)typeSpec);
            else if (typeSpec is TypeSpecBoxTag)
                methodHandles = GenerateVTableForBox(compiler, (TypeSpecBoxTag)typeSpec, vtCache);
            else if (typeSpec is TypeSpecDelegateTag)
                methodHandles = GenerateVTableForDelegate(compiler, (TypeSpecDelegateTag)typeSpec, vtCache);
            else if (typeSpec is TypeSpecArrayTag)
                methodHandles = GenerateVTableForArray(compiler, (TypeSpecArrayTag)typeSpec);
            else if (typeSpec is TypeSpecMulticastDelegateTag)
                methodHandles = GenerateVTableForMulticastDelegate(compiler, (TypeSpecMulticastDelegateTag)typeSpec, vtCache);
            else
                throw new ArgumentException("Invalid typespec to generate an array from");

            List<MethodHandle> finalHandles = new List<MethodHandle>();
            m_instrSlotToRealSlot = new Dictionary<uint, uint>();
            uint realSlot = 0;
            uint instrSlot = 0;
            foreach (MethodHandle hdl in methodHandles)
            {
                if (hdl == null)
                {
                    instrSlot++;
                    continue;
                }

                finalHandles.Add(hdl);

                m_instrSlotToRealSlot.Add(instrSlot, realSlot);

                instrSlot++;
                realSlot++;
            }

            m_methods = finalHandles.ToArray();
        }
        public MethodDeclTag GetCompareFieldsDeclTag(Compiler compiler)
        {
            if (m_fieldsEqualMethodDecl != null)
                return m_fieldsEqualMethodDecl;

            MethodSignatureParam[] sigParams = new MethodSignatureParam[2];

            TypeSpecGenericParamTag m0Type = new TypeSpecGenericParamTag(new TypeSpecGenericParamTypeTag(TypeSpecGenericParamTypeTag.Values.MVar), 0);
            m0Type = (TypeSpecGenericParamTag)compiler.TagRepository.InternTypeSpec(m0Type);

            sigParams[0] = new MethodSignatureParam(m0Type, new MethodSignatureParamTypeOfType(MethodSignatureParamTypeOfType.Values.ByRef));
            sigParams[1] = sigParams[0];

            MethodSignatureTag signature = new MethodSignatureTag(1, GetSystemBoolType(compiler), sigParams);
            signature = compiler.TagRepository.InternMethodSignature(signature);

            MethodDeclTag declTag = new MethodDeclTag("FieldsEqual", signature, GetClarityToolsType(compiler).TypeName);
            declTag = compiler.TagRepository.InternMethodDeclTag(declTag);

            m_fieldsEqualMethodDecl = declTag;

            return declTag;
        }
Beispiel #11
0
        private MethodSpecTag ResolveVirtualMethod(Compiler compiler, CliClass cls, CliMethodIndex methodIndex)
        {
            uint depth = methodIndex.Depth;
            CliClass methodClass = cls;
            while (depth > 0)
            {
                methodClass = methodClass.ParentClass;
                depth--;
            }

            HighMethod method = methodClass.Methods[methodIndex.Index];
            if (method.IsStatic)
                throw new RpaCompileException("Vtable slot implementation is static");

            MethodSpecTag methodSpec = new MethodSpecTag(MethodSlotType.Instance, new TypeSpecTag[0], methodClass.TypeSpec, method.MethodDeclTag);
            return compiler.TagRepository.InternMethodSpec(methodSpec);
        }
Beispiel #12
0
        private List<MethodHandle> GenerateVTableForMulticastDelegate(Compiler compiler, TypeSpecMulticastDelegateTag typeSpec, VTableGenerationCache vtCache)
        {
            TypeSpecClassTag delegateType = typeSpec.DelegateType;
            CliClass cls = compiler.GetClosedClass(delegateType);

            List<MethodHandle> methodHandles = new List<MethodHandle>();

            List<MethodSpecTag> methodSpecs = new List<MethodSpecTag>();
            foreach (CliVtableSlot vtableSlot in cls.VTable)
            {
                CliMethodIndex methodIndex = vtableSlot.MethodIndex;
                if (methodIndex == null)
                    methodSpecs.Add(null);
                else
                    methodSpecs.Add(ResolveVirtualMethod(compiler, cls, methodIndex));
            }

            int numSlots = methodSpecs.Count;
            for (int i = 0; i < numSlots; i++)
                methodHandles.Add(null);

            foreach (KeyValuePair<MethodDeclTag, uint> dtvs in cls.DeclTagToVTableSlot)
            {
                int slot = (int)dtvs.Value;
                MethodDeclTag methodDecl = dtvs.Key;

                if (methodDecl.Name == "Invoke")
                {
                    methodHandles[slot] = compiler.InstantiateMethod(new GeneratedMethods.GMMulticastDelegateInvoke(typeSpec.DelegateType, vtCache), m_instantiationPath);
                    methodSpecs[slot] = null;
                }
            }

            for (int i = 0; i < numSlots; i++)
            {
                MethodSpecTag methodSpec = methodSpecs[i];
                if (methodSpec != null)
                    methodHandles[i] = compiler.InstantiateMethod(new MethodSpecMethodKey(methodSpec), m_instantiationPath);
            }

            return methodHandles;
        }
Beispiel #13
0
        private List<MethodHandle> GenerateVTableForClass(Compiler compiler, TypeSpecClassTag typeSpec)
        {
            List<MethodSpecTag> methodSpecs = GenerateMethodSpecsForClass(compiler, typeSpec);

            List<MethodHandle> methodHandles = new List<MethodHandle>();
            foreach (MethodSpecTag methodSpec in methodSpecs)
            {
                if (methodSpec == null)
                    methodHandles.Add(null);
                else
                    methodHandles.Add(compiler.InstantiateMethod(new MethodSpecMethodKey(methodSpec), m_instantiationPath));
            }

            return methodHandles;
        }
Beispiel #14
0
        private List<MethodHandle> GenerateVTableForBox(Compiler compiler, TypeSpecBoxTag typeSpec, VTableGenerationCache vtCache)
        {
            TypeSpecClassTag containedType = typeSpec.ContainedType;
            List<MethodSpecTag> baseSpecs = GenerateMethodSpecsForClass(compiler, containedType);

            IList<MethodSpecTag> vtMethodSpecs = vtCache.ValueTypeMethodSpecs;

            if (vtMethodSpecs == null)
            {
                TypeNameTag valueTypeName = new TypeNameTag("mscorlib", "System", "ValueType");
                valueTypeName = compiler.TagRepository.InternTypeName(valueTypeName);

                TypeSpecClassTag valueTypeSpec = new TypeSpecClassTag(valueTypeName, new TypeSpecTag[0]);
                valueTypeSpec = (TypeSpecClassTag)compiler.TagRepository.InternTypeSpec(valueTypeSpec);

                vtMethodSpecs = GenerateMethodSpecsForClass(compiler, valueTypeSpec);
                vtCache.ValueTypeMethodSpecs = vtMethodSpecs;
            }

            List<MethodHandle> methodHandles = new List<MethodHandle>();

            for (int slotIndex = 0; slotIndex < baseSpecs.Count; slotIndex++)
            {
                MethodSpecTag methodSpec = baseSpecs[slotIndex];
                if (methodSpec == null)
                {
                    methodHandles.Add(null);
                    continue;
                }

                if (slotIndex < vtMethodSpecs.Count && vtMethodSpecs[slotIndex] == methodSpec)
                {
                    MethodSpecTag slotSpec = vtMethodSpecs[slotIndex];
                    if (slotSpec == methodSpec)
                    {
                        MethodDeclTag slotDecl = vtMethodSpecs[slotIndex].MethodDecl;

                        // Generate implementations for value-sensitive slots
                        if (slotDecl.Name == "Equals")
                        {
                            methodHandles.Add(compiler.InstantiateMethod(new GeneratedMethods.GMBoxedValueTypeEquals(typeSpec, vtCache), m_instantiationPath));
                            continue;
                        }
                        else if (slotDecl.Name == "GetHashCode")
                        {
                            methodHandles.Add(compiler.InstantiateMethod(new GeneratedMethods.GMBoxedValueTypeGetHashCode(typeSpec, vtCache), m_instantiationPath));
                            continue;
                        }
                    }
                }

                // If not sensitive, then use the method spec and generate a box thunk
                methodHandles.Add(compiler.InstantiateMethod(new GeneratedMethods.GMBoxThunk(methodSpec), m_instantiationPath));
            }

            return methodHandles;
        }
        public uint GetEqualsVTableSlot(Compiler compiler)
        {
            if (m_equalsVTableSlot.HasValue)
                return m_equalsVTableSlot.Value;

            MethodSignatureParam[] sigParams = new MethodSignatureParam[1];
            sigParams[0] = new MethodSignatureParam(GetSystemObjectType(compiler), new MethodSignatureParamTypeOfType(MethodSignatureParamTypeOfType.Values.Value));

            MethodSignatureTag signature = new MethodSignatureTag(0, GetSystemBoolType(compiler), sigParams);
            signature = compiler.TagRepository.InternMethodSignature(signature);

            MethodDeclTag declTag = new MethodDeclTag("Equals", signature, GetSystemObjectType(compiler).TypeName);
            declTag = compiler.TagRepository.InternMethodDeclTag(declTag);

            CliClass cls = compiler.GetClosedClass(GetSystemObjectType(compiler));
            uint result = cls.DeclTagToVTableSlot[declTag];

            m_equalsVTableSlot = result;

            return result;
        }
Beispiel #16
0
 public RloReplaceSsaPass(Compiler compiler, RloMethodBody methodBody, IDictionary<HighSsaRegister, HighSsaRegister> replacements)
     : base(compiler, methodBody)
 {
     m_dict = replacements;
     m_visitor = VisitSsa;
 }
 public TypeSpecClassTag GetSystemUIntPtrType(Compiler compiler)
 {
     return GetCachedClass(compiler, ref m_systemUIntPtrType, "System", "UIntPtr");
 }
 public TypeSpecClassTag GetSystemBoolType(Compiler compiler)
 {
     return GetCachedClass(compiler, ref m_systemBoolType, "System", "Boolean");
 }
Beispiel #19
0
        private List<MethodHandle> GenerateVTableForArray(Compiler compiler, TypeSpecArrayTag typeSpec)
        {
            TypeSpecClassTag baseClass;

            if (typeSpec.IsSZArray)
            {
                TypeSpecTag subscriptType = typeSpec.SubscriptType;
                if (compiler.TypeIsValueType(typeSpec.SubscriptType))
                {
                    TypeSpecClassTag subscriptClassTag = (TypeSpecClassTag)subscriptType;
                    TypeNameTag subscriptClassName = subscriptClassTag.TypeName;

                    if (subscriptClassName.FastIs("mscorlib", "System", "Nullable`1", 1, null))
                    {
                        TypeNameTag baseName = new TypeNameTag("mscorlib", "Clarity", "NullableSZArray`1", 1, null);
                        baseName = compiler.TagRepository.InternTypeName(baseName);

                        baseClass = new TypeSpecClassTag(baseName, subscriptClassTag.ArgTypes);
                        baseClass = (TypeSpecClassTag)compiler.TagRepository.InternTypeSpec(baseClass);
                    }
                    else
                    {
                        TypeNameTag baseName = new TypeNameTag("mscorlib", "Clarity", "ValueSZArray`1", 1, null);
                        baseName = compiler.TagRepository.InternTypeName(baseName);

                        baseClass = new TypeSpecClassTag(baseName, new TypeSpecTag[] { subscriptClassTag });
                        baseClass = (TypeSpecClassTag)compiler.TagRepository.InternTypeSpec(baseClass);
                    }
                }
                else
                {
                    TypeNameTag baseName = new TypeNameTag("mscorlib", "Clarity", "RefSZArray");
                    baseName = compiler.TagRepository.InternTypeName(baseName);

                    baseClass = new TypeSpecClassTag(baseName, new TypeSpecTag[0]);
                    baseClass = (TypeSpecClassTag)compiler.TagRepository.InternTypeSpec(baseClass);
                }
            }
            else
                throw new NotImplementedException("Multidimensional arrays not implemented");

            return GenerateVTableForClass(compiler, baseClass);
        }
Beispiel #20
0
 public RloValueType(Compiler compiler, TypeSpecTag type, RloInstantiationParameters instParams)
 {
     m_typeSpec = type.Instantiate(compiler.TagRepository, instParams.TypeParams, instParams.MethodParams);
 }
        public MethodHandle GetSystemObjectGetType(Compiler compiler)
        {
            if (m_objectGetTypeHandle != null)
                return m_objectGetTypeHandle;

            TypeSpecClassTag objectType = GetSystemObjectType(compiler);

            MethodSignatureTag signature = new MethodSignatureTag(0, GetSystemTypeType(compiler), new MethodSignatureParam[0]);
            signature = compiler.TagRepository.InternMethodSignature(signature);

            MethodDeclTag declTag = new MethodDeclTag("GetType", signature, objectType.TypeName);
            declTag = compiler.TagRepository.InternMethodDeclTag(declTag);

            MethodSpecTag methodSpec = new MethodSpecTag(MethodSlotType.Instance, new TypeSpecTag[0], GetSystemObjectType(compiler), declTag);
            methodSpec = compiler.TagRepository.InternMethodSpec(methodSpec);

            MethodHandle methodHandle = compiler.InstantiateMethod(new MethodSpecMethodKey(methodSpec), null);
            m_objectGetTypeHandle = methodHandle;

            return methodHandle;
        }
 public TypeSpecClassTag GetClarityToolsType(Compiler compiler)
 {
     return GetCachedClass(compiler, ref m_clarityToolsType, "Clarity", "Tools");
 }
        private static TypeSpecClassTag GetCachedClass(Compiler compiler, ref TypeSpecClassTag clsTagRef, string typeNamespace, string typeName)
        {
            TypeSpecClassTag clsTag = clsTagRef;
            if (clsTag != null)
                return clsTag;

            TypeNameTag name = new TypeNameTag("mscorlib", typeNamespace, typeName);
            name = compiler.TagRepository.InternTypeName(name);

            clsTag = new TypeSpecClassTag(name, new TypeSpecTag[0]);
            clsTag = (TypeSpecClassTag)compiler.TagRepository.InternTypeSpec(clsTag);

            clsTagRef = clsTag;
            return clsTag;
        }
 internal TypeSpecTag GetSystemDelegateType(Compiler compiler)
 {
     return GetCachedClass(compiler, ref m_systemDelegateType, "System", "Delegate");
 }
Beispiel #25
0
        public RloMethodBody(Compiler compiler, HighMethod method, MethodSpecTag methodSpec, TypeSpecClassTag thisType, bool isStruct, RloInstantiationParameters instParams, MethodInstantiationPath methodInstantiationPath)
        {
            m_instantiationPath = methodInstantiationPath;
            m_methodSpec = methodSpec;

            HighMethodBody methodBody = method.MethodBody;
            TagRepository tagRepo = compiler.TagRepository;

            // Validate locals
            uint numParamArgs = (uint)method.MethodSignature.ParamTypes.Length;

            if (method.IsStatic)
            {
                if (methodBody.InstanceLocal != null)
                    throw new Exception("Instance local in static method");
            }
            else
            {
                HighLocal thisLocal = methodBody.InstanceLocal;
                if (thisLocal == null)
                    throw new Exception("Missing instance local in instance method");

                HighLocal.ETypeOfType expectedTypeOfType = isStruct ? HighLocal.ETypeOfType.ByRef : HighLocal.ETypeOfType.Value;
                if (thisLocal.TypeOfType != expectedTypeOfType || thisLocal.Type.Instantiate(tagRepo, instParams.TypeParams, instParams.MethodParams) != thisType)
                    throw new Exception("Invalid this type for method");
            }

            if (numParamArgs != (uint)methodBody.Args.Length)
                throw new Exception("Mismatched argument count in method body and signature");

            for (uint i = 0; i < numParamArgs; i++)
            {
                HighLocal bodyArg = methodBody.Args[i];
                MethodSignatureParam methodSigParam = method.MethodSignature.ParamTypes[i];
                MethodSignatureParamTypeOfType tot = methodSigParam.TypeOfType;

                HighLocal.ETypeOfType expectedTypeOfType;
                switch (tot.Value)
                {
                    case MethodSignatureParamTypeOfType.Values.ByRef:
                        expectedTypeOfType = HighLocal.ETypeOfType.ByRef;
                        break;
                    case MethodSignatureParamTypeOfType.Values.TypedByRef:
                        expectedTypeOfType = HighLocal.ETypeOfType.TypedByRef;
                        break;
                    case MethodSignatureParamTypeOfType.Values.Value:
                        expectedTypeOfType = HighLocal.ETypeOfType.Value;
                        break;
                    default:
                        throw new ArgumentException();
                }

                if (bodyArg.TypeOfType != expectedTypeOfType)
                    throw new Exception("Method body arg doesn't match signature");
            }

            HighLocal instanceLocal = methodBody.InstanceLocal;

            RloMethodConverter methodConverter = new RloMethodConverter(compiler.TagRepository, instParams, method.MethodSignature.RetType, instanceLocal, methodBody.Args, methodBody.Locals);
            RloRegionConverter regionConverter = new RloRegionConverter(methodConverter, methodBody.MainRegion, true);

            m_locals = methodConverter.Locals2;
            m_args = methodConverter.Args;
            m_instanceLocal = methodConverter.InstanceLocal;
            m_returnType = methodConverter.ReturnType;
            m_entryRegion = new HighRegion(regionConverter.EntryNode);
            m_methodSignature = method.MethodSignature;

            RloFindPredecessorsAndSuccessorsPass psPass = new RloFindPredecessorsAndSuccessorsPass(compiler, this);
            psPass.Run();

            RloCanonicalizeSsaTypesPass cstPass = new RloCanonicalizeSsaTypesPass(compiler, this);
            cstPass.Run();

            RloInitPass initPass = new RloInitPass(compiler, this, psPass);
            initPass.Run();

            RloInitExceptionsPass exceptionInitPass = new RloInitExceptionsPass(compiler, this);
            exceptionInitPass.Run();
        }
 public TypeSpecClassTag GetSystemTypeType(Compiler compiler)
 {
     return GetCachedClass(compiler, ref m_systemTypeType, "System", "Type");
 }
Beispiel #27
0
        public bool Create(Compiler compiler)
        {
            HighTypeDef typeDef = m_typeDef;

            foreach (TypeSpecClassTag ii in typeDef.ParentInterfaces)
            {
                if (!compiler.HaveCliOpenInterface(ii.TypeName))
                    return false;
            }

            Dictionary<TypeSpecClassTag, int> uniqueDeps = new Dictionary<TypeSpecClassTag, int>();
            foreach (TypeSpecClassTag pi in typeDef.ParentInterfaces)
            {
                CliInterface ifc = compiler.GetClosedInterface(pi);
                if (!ifc.IsCreated)
                {
                    ifc = compiler.GetClosedInterface(pi);
                    throw new Exception();
                }

                foreach (TypeSpecClassTag pipi in ifc.InterfaceImpls2)
                    AddUniqueInterface(uniqueDeps, pipi);
                AddUniqueInterface(uniqueDeps, pi);
            }

            m_interfaceImpls = UnrollUniqueInterfaces(uniqueDeps);

            m_parentInterfaces = typeDef.ParentInterfaces;

            m_slots = typeDef.NewSlots;
            m_slotTagToCliSlot = new Dictionary<MethodDeclTag, uint>();
            m_slotTagToRealSlot = new Dictionary<MethodDeclTag, uint>();

            uint numGenericParameters = typeDef.NumGenericParameters;
            TypeSpecTag[] genericParameters = new TypeSpecTag[numGenericParameters];
            for (uint i = 0; i < numGenericParameters; i++)
            {
                TypeSpecGenericParamTypeTag paramType = new TypeSpecGenericParamTypeTag(TypeSpecGenericParamTypeTag.Values.Var);
                TypeSpecTag paramTag = new TypeSpecGenericParamTag(paramType, i);
                paramTag = compiler.TagRepository.InternTypeSpec(paramTag);

                genericParameters[i] = paramTag;
            }

            m_numRealSlots = 0;
            uint cliSlot = 0;
            foreach (HighClassVtableSlot slot in m_slots)
            {
                if (m_slotTagToCliSlot.ContainsKey(slot.SlotTag))
                    throw new Exception("Duplicate interface vtable slot");

                m_slotTagToCliSlot.Add(slot.SlotTag, cliSlot++);
                if (slot.Signature.NumGenericParameters > 0)
                    m_slotTagToRealSlot.Add(slot.SlotTag, m_numRealSlots);
            }

            m_typeSpec = new TypeSpecClassTag(m_typeDef.TypeName, genericParameters);
            m_typeSpec = (TypeSpecClassTag)compiler.TagRepository.InternTypeSpec(m_typeSpec);

            m_isCreated = true;

            return true;
        }
        public uint GetGetHashCodeVTableSlot(Compiler compiler)
        {
            if (m_getHashCodeVTableSlot.HasValue)
                return m_getHashCodeVTableSlot.Value;

            MethodSignatureTag signature = new MethodSignatureTag(0, GetSystemInt32Type(compiler), new MethodSignatureParam[0]);
            signature = compiler.TagRepository.InternMethodSignature(signature);

            MethodDeclTag declTag = new MethodDeclTag("GetHashCode", signature, GetSystemObjectType(compiler).TypeName);
            declTag = compiler.TagRepository.InternMethodDeclTag(declTag);

            CliClass cls = compiler.GetClosedClass(GetSystemObjectType(compiler));
            uint result = cls.DeclTagToVTableSlot[declTag];

            m_getHashCodeVTableSlot = result;

            return result;
        }
Beispiel #29
0
 public override RloMethod GenerateMethod(Compiler compiler, MethodInstantiationPath instantiationPath)
 {
     return new RloMethod(compiler, m_methodSpec, instantiationPath);
 }
Beispiel #30
0
        public CliInterface Instantiate(Compiler compiler, TypeSpecTag[] argTypes)
        {
            if (!m_isCreated)
                throw new RpaCompileException("Attempted to instantiate an uncreated open interface.");

            if (m_typeDef.NumGenericParameters != (uint)argTypes.Length)
                throw new ArgumentException("Interface parameter count doesn't match typedef count");

            if (m_typeDef.NumGenericParameters == 0)
                return this;

            List<HighClassVtableSlot> slots = new List<HighClassVtableSlot>();
            foreach (HighClassVtableSlot slot in m_slots)
            {
                MethodSignatureTag signature = slot.Signature.Instantiate(compiler.TagRepository, argTypes);
                HighClassVtableSlot newSlot = new HighClassVtableSlot(slot.SlotTag, signature, null, true, false);
                slots.Add(newSlot);
            }

            List<TypeSpecClassTag> parentInterfaces = new List<TypeSpecClassTag>();
            foreach (TypeSpecClassTag classTag in m_parentInterfaces)
                parentInterfaces.Add((TypeSpecClassTag)classTag.Instantiate(compiler.TagRepository, argTypes));

            TypeSpecClassTag typeSpec = (TypeSpecClassTag)m_typeSpec.Instantiate(compiler.TagRepository, argTypes);

            Dictionary<TypeSpecClassTag, int> uniqueDeps = new Dictionary<TypeSpecClassTag, int>();
            foreach (TypeSpecClassTag ifc in m_interfaceImpls)
                AddUniqueInterface(uniqueDeps, (TypeSpecClassTag)ifc.Instantiate(compiler.TagRepository, argTypes));
            TypeSpecClassTag[] interfaceImpls = UnrollUniqueInterfaces(uniqueDeps);

            return new CliInterface(m_typeDef, typeSpec, argTypes, parentInterfaces.ToArray(), slots.ToArray(), m_slotTagToCliSlot, m_slotTagToRealSlot, m_numRealSlots, interfaceImpls);
        }