private HLLocation ProcessTargetExpression(ITargetExpression pExpression) { if (pExpression.Definition is ILocalDefinition) { return(HLLocalLocation.Create(HLDomain.GetLocal(pExpression.Definition as ILocalDefinition))); } else if (pExpression.Definition is IParameterDefinition) { HLParameter parameter = HLDomain.GetParameter(pExpression.Definition as IParameterDefinition); parameter.RequiresAddressing = true; return(HLParameterLocation.Create(parameter)); } else if (pExpression.Definition is IFieldDefinition || pExpression.Definition is IFieldReference) { IFieldDefinition definition = pExpression.Definition is IFieldDefinition ? (IFieldDefinition)pExpression.Definition : ((IFieldReference)pExpression.Definition).ResolvedField; HLType typeFieldContainer = HLDomain.GetOrCreateType(definition.Container); HLField field = HLDomain.GetField(definition); if (field.IsStatic) { return(HLStaticFieldLocation.Create(field)); } HLLocation instance = ProcessExpression(pExpression.Instance); return(HLFieldLocation.Create(instance, field)); } else if (pExpression.Definition is IAddressDereference) { IAddressDereference definition = pExpression.Definition as IAddressDereference; HLLocation locationAddress = ProcessExpression(definition.Address); return(HLIndirectAddressLocation.Create(locationAddress, HLDomain.GetOrCreateType(pExpression.Type))); } throw new NotSupportedException(); }
private HLLocation ProcessBoundExpression(IBoundExpression pExpression) { if (pExpression.Definition is ILocalDefinition) { ILocalDefinition definition = pExpression.Definition as ILocalDefinition; HLLocation location = HLLocalLocation.Create(HLDomain.GetLocal(definition)); if (pExpression.Type.ResolvedType.TypeCode == PrimitiveTypeCode.Reference) { location = location.AddressOf(); } return(location); } else if (pExpression.Definition is IParameterDefinition) { return(HLParameterLocation.Create(HLDomain.GetParameter(pExpression.Definition as IParameterDefinition))); } else if (pExpression.Definition is IFieldDefinition || pExpression.Definition is IFieldReference) { IFieldDefinition definition = pExpression.Definition is IFieldDefinition ? (IFieldDefinition)pExpression.Definition : ((IFieldReference)pExpression.Definition).ResolvedField; HLType typeFieldContainer = HLDomain.GetOrCreateType(definition.Container); HLField field = HLDomain.GetField(definition); if (field.IsStatic) { return(HLStaticFieldLocation.Create(field)); } HLLocation instance = ProcessExpression(pExpression.Instance); return(HLFieldLocation.Create(instance, field)); } throw new NotSupportedException(); }
private static HLType CreateType(ITypeDefinition pDefinition) { HLType type = new HLType(); type.Definition = pDefinition; type.Name = pDefinition.ToString(); // TODO: Don't really like this, should use TypeHelper perhaps? type.Signature = HLDomain.GetTypeSignature(pDefinition); sTypes[type.Signature] = type; ITypeReference referenceBase = pDefinition.BaseClasses.FirstOrDefault(); if (referenceBase != null) { type.BaseType = GetOrCreateType(referenceBase); type.BaseType.MemberFields.ForEach(f => type.Fields.Add(f)); } foreach (IFieldDefinition fieldDefinition in pDefinition.Fields.OrderBy(d => d.SequenceNumber)) { CreateField(type, fieldDefinition); } IMethodDefinition definitionStaticConstructor = pDefinition.Methods.FirstOrDefault(d => d.IsStaticConstructor); if (definitionStaticConstructor != null) { type.StaticConstructor = GetOrCreateMethod(definitionStaticConstructor); } return(type); }
public static HLType GetOrCreateType(ITypeDefinition pDefinition) { HLType type = null; if (!sTypes.TryGetValue(GetTypeSignature(pDefinition), out type)) { type = CreateType(pDefinition); } return(type); }
public HLTemporary CreateTemporary(HLType pType) { HLTemporary temporary = new HLTemporary(); temporary.Name = "temp_" + Temporaries.Count; //temporary.Container = this; temporary.Type = pType; Temporaries.Add(temporary); return(temporary); }
public static HLMethod GetOrCreateMethod(IMethodDefinition pDefinition) { HLMethod method = null; if (!sMethods.TryGetValue(GetMethodSignature(pDefinition), out method)) { HLType container = GetOrCreateType(pDefinition.Container); method = CreateMethod(container, pDefinition); } return(method); }
private HLLocation ProcessArrayIndexerExpression(IArrayIndexer pExpression) { if (pExpression.Indices.Count() != 1) { throw new NotSupportedException(); } HLLocation locationInstance = ProcessExpression(pExpression.IndexedObject); HLLocation locationIndex = ProcessExpression(pExpression.Indices.First()); HLType typeElement = HLDomain.GetOrCreateType(pExpression.Type); return(HLArrayElementLocation.Create(locationInstance, locationIndex, typeElement)); }
private static void EnlistRuntimeTypes() { sSystemRuntimeMethodData = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeMethodData")); sSystemRuntimeMethodHandle = GetOrCreateType(PlatformType.SystemRuntimeMethodHandle); sSystemRuntimeType = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeType")); sSystemRuntimeTypeData = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeTypeData")); sSystemRuntimeTypeHandle = GetOrCreateType(PlatformType.SystemRuntimeTypeHandle); sSystemString = GetOrCreateType(PlatformType.SystemString); if (sSystemRuntimeMethodData.Definition.TypeCode == PrimitiveTypeCode.Invalid) { throw new NotImplementedException(); } if (sSystemRuntimeTypeData.Definition.TypeCode == PrimitiveTypeCode.Invalid) { throw new NotImplementedException(); } }
private static HLMethod CreateMethod(HLType pContainer, IMethodDefinition pDefinition) { HLMethod method = new HLMethod(); method.Definition = pDefinition; method.Name = pDefinition.Name.Value; method.Signature = GetMethodSignature(pDefinition); sMethods[method.Signature] = method; method.Container = pContainer; pContainer.Methods.Add(method); method.IsStatic = pDefinition.IsStatic; method.IsExternal = pDefinition.IsExternal; method.IsRuntimeImplemented = pDefinition.IsRuntimeImplemented; method.IsAbstract = pDefinition.IsAbstract; method.IsVirtual = pDefinition.IsVirtual; method.IsConstructor = pDefinition.IsConstructor; method.ReturnType = GetOrCreateType(pDefinition.Type); if (pDefinition != Module.EntryPoint.ResolvedMethod && !pDefinition.HasExplicitThisParameter) { HLType typeImplicitThis = method.Container; if (typeImplicitThis.Definition.IsValueType) { typeImplicitThis = GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pDefinition.Container, Host.InternFactory, pDefinition.Container)); } method.Parameters.Add(new HLParameter() { Name = "this", Type = typeImplicitThis }); } foreach (IParameterDefinition definition in pDefinition.Parameters.OrderBy(d => d.Index)) { method.Parameters.Add(CreateParameter(definition)); } foreach (ILocalDefinition definition in pDefinition.Body.LocalVariables.Where(d => d.Name.Value != string.Empty)) { method.Locals.Add(CreateLocal(definition)); } // TODO: Finish loading from Definition sPendingMethods.Enqueue(method); return(method); }
private HLLocation ProcessAddressableExpression(IAddressableExpression pExpression) { if (pExpression.Definition is ILocalDefinition) { return(HLLocalLocation.Create(HLDomain.GetLocal(pExpression.Definition as ILocalDefinition))); } else if (pExpression.Definition is IParameterDefinition) { return(HLParameterLocation.Create(HLDomain.GetParameter(pExpression.Definition as IParameterDefinition))); } else if (pExpression.Definition is IFieldDefinition || pExpression.Definition is IFieldReference) { IFieldDefinition definition = pExpression.Definition is IFieldDefinition ? (IFieldDefinition)pExpression.Definition : ((IFieldReference)pExpression.Definition).ResolvedField; HLType typeFieldContainer = HLDomain.GetOrCreateType(definition.Container); HLField field = HLDomain.GetField(definition); if (field.IsStatic) { return(HLStaticFieldLocation.Create(field)); } HLLocation instance = ProcessExpression(pExpression.Instance); return(HLFieldLocation.Create(instance, field)); } else if (pExpression.Definition is IArrayIndexer) { IArrayIndexer definition = (IArrayIndexer)pExpression.Definition; if (definition.Indices.Count() != 1) { throw new NotSupportedException(); } HLLocation locationInstance = ProcessExpression(pExpression.Instance); HLLocation locationIndex = ProcessExpression(definition.Indices.First()); HLType typeElement = HLDomain.GetOrCreateType(pExpression.Type); return(HLArrayElementLocation.Create(locationInstance, locationIndex, typeElement)); } else if (pExpression.Definition is IDefaultValue) { HLType typeDefaultValue = HLDomain.GetOrCreateType(((IDefaultValue)pExpression.Definition).DefaultValueType); HLLocation locationDefaultValue = HLTemporaryLocation.Create(CreateTemporary(typeDefaultValue)); mCurrentBlock.EmitAssignment(locationDefaultValue, HLDefaultLocation.Create(typeDefaultValue)); return(locationDefaultValue); } throw new NotSupportedException(); }
private static HLField CreateField(HLType pContainer, IFieldDefinition pDefinition) { HLField field = new HLField(); //field.Definition = pDefinition; field.Name = pDefinition.Name.Value; field.Signature = HLDomain.GetFieldSignature(pDefinition); sFields[field.Signature] = field; field.Container = pContainer; pContainer.Fields.Add(field); field.IsStatic = pDefinition.IsStatic; field.IsCompileTimeConstant = pDefinition.IsCompileTimeConstant; if (field.IsCompileTimeConstant) { field.CompileTimeConstant = pDefinition.Constant.Value; } field.Type = GetOrCreateType(pDefinition.Type); return(field); }
private HLLocation ProcessCreateArrayExpression(ICreateArray pExpression) { if (pExpression.Rank != 1 || pExpression.Sizes.Count() != 1 || pExpression.LowerBounds.Count() > 0) { throw new NotSupportedException(); } HLType typeElement = HLDomain.GetOrCreateType(pExpression.ElementType); HLLocation locationInstance = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); HLLocation locationSize = ProcessExpression(pExpression.Sizes.First()); mCurrentBlock.EmitNewArray(locationInstance.AddressOf(), locationSize, locationInstance.Type, typeElement); IExpression[] initializers = pExpression.Initializers.ToArray(); for (int indexInitializer = 0; indexInitializer < initializers.Length; ++indexInitializer) { HLLocation locationInitializer = ProcessExpression(initializers[indexInitializer]); HLLocation locationArrayElement = HLArrayElementLocation.Create(locationInstance, HLInt32LiteralLocation.Create(indexInitializer), typeElement); mCurrentBlock.EmitAssignment(locationArrayElement, locationInitializer); } return(locationInstance); }
private HLLocation ProcessMethodCallExpression(IMethodCall pExpression) { List <HLLocation> locationsParameters = new List <HLLocation>(); if (pExpression.ThisArgument.Type.TypeCode != PrimitiveTypeCode.Invalid) { locationsParameters.Add(ProcessExpression(pExpression.ThisArgument)); } else if (pExpression.MethodToCall.IsStatic) { HLType typeContainer = null; if (pExpression.MethodToCall.ContainingType.ResolvedType.IsValueType) { typeContainer = HLDomain.GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pExpression.MethodToCall.ContainingType, HLDomain.Host.InternFactory, pExpression.MethodToCall.ContainingType)); } else { typeContainer = HLDomain.GetOrCreateType(pExpression.MethodToCall.ContainingType); } locationsParameters.Add(HLNullLocation.Create(typeContainer)); } foreach (IExpression argument in pExpression.Arguments) { locationsParameters.Add(ProcessExpression(argument)); } HLLocation locationReturn = null; HLMethod methodCalled = HLDomain.GetOrCreateMethod(pExpression.MethodToCall); if (methodCalled.ReturnType.Definition.TypeCode != PrimitiveTypeCode.Void) { locationReturn = HLTemporaryLocation.Create(CreateTemporary(methodCalled.ReturnType)); } mCurrentBlock.EmitCall(methodCalled, pExpression.IsVirtualCall, locationReturn, locationsParameters); return(locationReturn); }
public void EmitNewObject(HLType pNewObjectType, HLLocation pDestinationSource) { Emit(HLNewObjectInstruction.Create(mMethod, pNewObjectType, pDestinationSource)); }
public void EmitNewDelegate(HLType pNewDelegateType, HLLocation pDestinationSource, HLLocation pInstanceSource, HLMethod pMethodCalled, bool pVirtual) { Emit(HLNewDelegateInstruction.Create(mMethod, pNewDelegateType, pDestinationSource, pInstanceSource, pMethodCalled, pVirtual)); }
public void EmitNewArray(HLLocation pDestinationSource, HLLocation pSizeSource, HLType pArrayType, HLType pElementType) { Emit(HLNewArrayInstruction.Create(mMethod, pDestinationSource, pSizeSource, pArrayType, pElementType)); }
protected HLLocation(HLType pType) { mType = pType; }
private static HLField CreateField(HLType pContainer, IFieldDefinition pDefinition) { HLField field = new HLField(); //field.Definition = pDefinition; field.Name = pDefinition.Name.Value; field.Signature = HLDomain.GetFieldSignature(pDefinition); sFields[field.Signature] = field; field.Container = pContainer; pContainer.Fields.Add(field); field.IsStatic = pDefinition.IsStatic; field.IsCompileTimeConstant = pDefinition.IsCompileTimeConstant; if (field.IsCompileTimeConstant) field.CompileTimeConstant = pDefinition.Constant.Value; field.Type = GetOrCreateType(pDefinition.Type); return field; }
protected HLLiteralLocation(HLType pType) : base(pType) { }
private static HLType CreateType(ITypeDefinition pDefinition) { HLType type = new HLType(); type.Definition = pDefinition; type.Name = pDefinition.ToString(); // TODO: Don't really like this, should use TypeHelper perhaps? type.Signature = HLDomain.GetTypeSignature(pDefinition); sTypes[type.Signature] = type; ITypeReference referenceBase = pDefinition.BaseClasses.FirstOrDefault(); if (referenceBase != null) { type.BaseType = GetOrCreateType(referenceBase); type.BaseType.MemberFields.ForEach(f => type.Fields.Add(f)); } foreach (IFieldDefinition fieldDefinition in pDefinition.Fields.OrderBy(d => d.SequenceNumber)) CreateField(type, fieldDefinition); IMethodDefinition definitionStaticConstructor = pDefinition.Methods.FirstOrDefault(d => d.IsStaticConstructor); if (definitionStaticConstructor != null) type.StaticConstructor = GetOrCreateMethod(definitionStaticConstructor); return type; }
private static HLMethod CreateMethod(HLType pContainer, IMethodDefinition pDefinition) { HLMethod method = new HLMethod(); method.Definition = pDefinition; method.Name = pDefinition.Name.Value; method.Signature = GetMethodSignature(pDefinition); sMethods[method.Signature] = method; method.Container = pContainer; pContainer.Methods.Add(method); method.IsStatic = pDefinition.IsStatic; method.IsExternal = pDefinition.IsExternal; method.IsRuntimeImplemented = pDefinition.IsRuntimeImplemented; method.IsAbstract = pDefinition.IsAbstract; method.IsVirtual = pDefinition.IsVirtual; method.IsConstructor = pDefinition.IsConstructor; method.ReturnType = GetOrCreateType(pDefinition.Type); if (pDefinition != Module.EntryPoint.ResolvedMethod && !pDefinition.HasExplicitThisParameter) { HLType typeImplicitThis = method.Container; if (typeImplicitThis.Definition.IsValueType) typeImplicitThis = GetOrCreateType(MutableModelHelper.GetManagedPointerTypeReference(pDefinition.Container, Host.InternFactory, pDefinition.Container)); method.Parameters.Add(new HLParameter() { Name = "this", Type = typeImplicitThis }); } foreach (IParameterDefinition definition in pDefinition.Parameters.OrderBy(d => d.Index)) method.Parameters.Add(CreateParameter(definition)); foreach (ILocalDefinition definition in pDefinition.Body.LocalVariables.Where(d => d.Name.Value != string.Empty)) method.Locals.Add(CreateLocal(definition)); // TODO: Finish loading from Definition sPendingMethods.Enqueue(method); return method; }
private static void EnlistRuntimeTypes() { sSystemRuntimeMethodData = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeMethodData")); sSystemRuntimeMethodHandle = GetOrCreateType(PlatformType.SystemRuntimeMethodHandle); sSystemRuntimeType = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeType")); sSystemRuntimeTypeData = GetOrCreateType(UnitHelper.FindType(Host.NameTable, sRuntimeAssembly, "System.RuntimeTypeData")); sSystemRuntimeTypeHandle = GetOrCreateType(PlatformType.SystemRuntimeTypeHandle); sSystemString = GetOrCreateType(PlatformType.SystemString); if (sSystemRuntimeMethodData.Definition.TypeCode == PrimitiveTypeCode.Invalid) throw new NotImplementedException(); if (sSystemRuntimeTypeData.Definition.TypeCode == PrimitiveTypeCode.Invalid) throw new NotImplementedException(); }
public HLTemporary CreateTemporary(HLType pType) { HLTemporary temporary = new HLTemporary(); temporary.Name = "temp_" + Temporaries.Count; //temporary.Container = this; temporary.Type = pType; Temporaries.Add(temporary); return temporary; }