示例#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();
     }
 }
示例#2
0
        public RloMethodConverter(TagRepository tagRepo, RloInstantiationParameters instParams, TypeSpecTag returnType, HighLocal instanceLocal, HighLocal[] args, HighLocal[] locals)
        {
            m_tagRepo = tagRepo;
            m_instParams = instParams;

            m_returnType = InstantiateType(returnType);

            List<HighLocal> mergedLocals = new List<HighLocal>();
            if (instanceLocal != null)
                mergedLocals.Add(instanceLocal);
            mergedLocals.AddRange(args);
            mergedLocals.AddRange(locals);

            foreach (HighLocal local in mergedLocals)
            {
                HighLocal newLocal = new HighLocal(this.InstantiateType(local.Type), local.TypeOfType);
                m_translatedLocals.Add(local, newLocal);
            }

            if (instanceLocal != null)
                m_instanceLocal = m_translatedLocals[instanceLocal];

            List<HighLocal> newArgs = new List<HighLocal>();
            foreach (HighLocal arg in args)
                newArgs.Add(m_translatedLocals[arg]);

            List<HighLocal> newLocals = new List<HighLocal>();
            foreach (HighLocal local in locals)
                newLocals.Add(m_translatedLocals[local]);

            m_args = newArgs.ToArray();
            m_locals = newLocals.ToArray();
        }
示例#3
0
 public RloValueType(Compiler compiler, TypeSpecTag type, RloInstantiationParameters instParams)
 {
     m_typeSpec = type.Instantiate(compiler.TagRepository, instParams.TypeParams, instParams.MethodParams);
 }
示例#4
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();
        }