Esempio n. 1
0
        public RloRegionConverter(RloMethodConverter methodConverter, HighRegion region, bool checkInstructions)
        {
            m_ssaTranslate = TranslateSSA;
            m_localTranslate = TranslateLocal;
            m_cfgNodeTranslate = TranslateCfgNode;
            m_cfgEdgeTranslate = TranslateCfgEdge;
            m_typeSpecTranslate = TranslateTypeSpec;
            m_methodSpecTranslate = TranslateMethodSpec;

            m_methodConverter = methodConverter;
            m_checkInstructions = checkInstructions;

            m_entryNode = GetNode(region.EntryNode.Value);

            while (m_unconvertedNodes.Count > 0)
            {
                KeyValuePair<HighCfgNode, HighCfgNodeHandle> workItem = m_unconvertedNodes.Dequeue();

                ConvertNode(workItem.Key, workItem.Value);
            }
        }
Esempio n. 2
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();
        }