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); }
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(); }