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 HLLocation ProcessConditionalExpression(IConditional pExpression) { HLLocation locationCondition = ProcessExpression(pExpression.Condition); HLInstructionBlock blockParent = mCurrentBlock; HLLocation locationResult = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); HLInstructionBlock blockTrueStart = CreateBlock(CreateLabel()); mCurrentBlock = blockTrueStart; HLLocation locationTrue = ProcessExpression(pExpression.ResultIfTrue); mCurrentBlock.EmitAssignment(locationResult, locationTrue); HLInstructionBlock blockTrueEnd = mCurrentBlock; HLInstructionBlock blockFalseStart = CreateBlock(CreateLabel()); mCurrentBlock = blockFalseStart; HLLocation locationFalse = ProcessExpression(pExpression.ResultIfFalse); mCurrentBlock.EmitAssignment(locationResult, locationFalse); HLInstructionBlock blockFalseEnd = mCurrentBlock; blockParent.EmitBranch(locationCondition, blockTrueStart.StartLabel, blockFalseStart.StartLabel); mCurrentBlock = CreateBlock(CreateLabel()); blockTrueEnd.Terminate(mCurrentBlock.StartLabel); blockFalseEnd.Terminate(mCurrentBlock.StartLabel); return(locationResult); }
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 HLLocation ProcessCreateDelegateInstanceExpression(ICreateDelegateInstance pExpression) { HLLocation locationInstance = null; if (pExpression.Instance != null) { locationInstance = ProcessExpression(pExpression.Instance); } HLMethod methodCalled = HLDomain.GetOrCreateMethod(pExpression.MethodToCallViaDelegate); HLLocation locationDelegate = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); mCurrentBlock.EmitNewDelegate(locationDelegate.Type, locationDelegate.AddressOf(), locationInstance, methodCalled, pExpression.IsVirtualDelegate); return(locationDelegate); }
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 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); }
private HLLocation ProcessCompileTimeConstantExpression(ICompileTimeConstant pExpression) { if (pExpression.Value == null) { return(HLNullLocation.Create(HLDomain.GetOrCreateType(pExpression.Type))); } if (pExpression.Type.ResolvedType.IsEnum) { return(HLEnumLiteralLocation.Create(HLDomain.GetOrCreateType(pExpression.Type), pExpression.Value.ToString())); } if (pExpression.Value is bool) { return(HLBooleanLiteralLocation.Create((bool)pExpression.Value)); } if (pExpression.Value is sbyte) { return(HLInt8LiteralLocation.Create((sbyte)pExpression.Value)); } if (pExpression.Value is byte) { return(HLUInt8LiteralLocation.Create((byte)pExpression.Value)); } if (pExpression.Value is char) { return(HLCharLiteralLocation.Create((char)pExpression.Value)); } if (pExpression.Value is short) { return(HLInt16LiteralLocation.Create((short)pExpression.Value)); } if (pExpression.Value is ushort) { return(HLUInt16LiteralLocation.Create((ushort)pExpression.Value)); } if (pExpression.Value is float) { return(HLFloat32LiteralLocation.Create((float)pExpression.Value)); } if (pExpression.Value is int) { return(HLInt32LiteralLocation.Create((int)pExpression.Value)); } if (pExpression.Value is uint) { return(HLUInt32LiteralLocation.Create((uint)pExpression.Value)); } if (pExpression.Value is double) { return(HLFloat64LiteralLocation.Create((double)pExpression.Value)); } if (pExpression.Value is long) { return(HLInt64LiteralLocation.Create((long)pExpression.Value)); } if (pExpression.Value is ulong) { return(HLUInt64LiteralLocation.Create((ulong)pExpression.Value)); } if (pExpression.Value is string) { return(HLStringLiteralLocation.Create((string)pExpression.Value)); } throw new NotSupportedException(); }
private HLLocation ProcessExclusiveOrExpression(IExclusiveOr pExpression) { HLLocation locationLeftOperand = ProcessExpression(pExpression.LeftOperand); HLLocation locationRightOperand = ProcessExpression(pExpression.RightOperand); HLLocation locationTemporary = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); mCurrentBlock.EmitBitwiseXor(locationTemporary, locationLeftOperand, locationRightOperand); return(pExpression.ResultIsUnmodifiedLeftOperand ? locationLeftOperand : locationTemporary); }
private HLLocation ProcessLogicalNotExpression(ILogicalNot pExpression) { HLLocation locationOperand = ProcessExpression(pExpression.Operand); HLLocation locationTemporary = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); mCurrentBlock.EmitBitwiseXor(locationTemporary, locationOperand, HLBooleanLiteralLocation.Create(true)); return(locationTemporary); }
private HLLocation ProcessTypeOfExpression(ITypeOf pExpression) { return(HLTypeOfLocation.Create(HLDomain.GetOrCreateType(pExpression.TypeToGet))); }
private HLLocation ProcessDefaultValueExpression(IDefaultValue pExpression) { return(HLDefaultLocation.Create(HLDomain.GetOrCreateType(pExpression.DefaultValueType))); }
private HLLocation ProcessUnaryNegationExpression(IUnaryNegation pExpression) { HLLocation locationOperand = ProcessExpression(pExpression.Operand); HLLocation locationTemporary = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); mCurrentBlock.EmitBitwiseNegate(locationTemporary, locationOperand); return(locationTemporary); }
private HLLocation ProcessConversionExpression(IConversion pExpression) { HLLocation locationSource = ProcessExpression(pExpression.ValueToConvert); HLLocation locationTemporary = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.TypeAfterConversion))); mCurrentBlock.EmitAssignment(locationTemporary, locationSource); return(locationTemporary); }
private HLLocation ProcessSizeOfExpression(ISizeOf pExpression) { return(HLSizeOfLocation.Create(HLDomain.GetOrCreateType(pExpression.TypeToSize))); }
private HLLocation ProcessMultiplicationExpression(IMultiplication pExpression) { HLLocation locationLeftOperand = ProcessExpression(pExpression.LeftOperand); HLLocation locationRightOperand = ProcessExpression(pExpression.RightOperand); HLLocation locationTemporary = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); mCurrentBlock.EmitMultiply(locationTemporary, locationLeftOperand, locationRightOperand); return(pExpression.ResultIsUnmodifiedLeftOperand ? locationLeftOperand : locationTemporary); }
private HLLocation ProcessAddressDereferenceExpression(IAddressDereference pExpression) { HLLocation locationAddress = ProcessExpression(pExpression.Address); return(HLIndirectAddressLocation.Create(locationAddress, HLDomain.GetOrCreateType(pExpression.Type))); }
private HLLocation ProcessNotEqualityExpression(INotEquality pExpression) { HLLocation locationLeftOperand = ProcessExpression(pExpression.LeftOperand); HLLocation locationRightOperand = ProcessExpression(pExpression.RightOperand); HLLocation locationTemporary = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); mCurrentBlock.EmitCompare(HLCompareType.NotEqual, locationTemporary, locationLeftOperand, locationRightOperand); return(pExpression.ResultIsUnmodifiedLeftOperand ? locationLeftOperand : locationTemporary); }
private HLLocation ProcessOnesComplementExpression(IOnesComplement pExpression) { HLLocation locationOperand = ProcessExpression(pExpression.Operand); HLLocation locationTemporary = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); mCurrentBlock.EmitBitwiseNot(locationTemporary, locationOperand); return(locationTemporary); }