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 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 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 void ProcessConditionalStatement(IConditionalStatement pStatement) { if (mCurrentBlock.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); } HLLocation locationCondition = ProcessExpression(pStatement.Condition); HLInstructionBlock blockParent = mCurrentBlock; HLInstructionBlock blockTrueStart = CreateBlock(CreateLabel()); mCurrentBlock = blockTrueStart; ProcessStatement(pStatement.TrueBranch); HLInstructionBlock blockTrueEnd = mCurrentBlock; HLInstructionBlock blockFalseStart = CreateBlock(CreateLabel()); mCurrentBlock = blockFalseStart; ProcessStatement(pStatement.FalseBranch); HLInstructionBlock blockFalseEnd = mCurrentBlock; blockParent.EmitBranch(locationCondition, blockTrueStart.StartLabel, blockFalseStart.StartLabel); if (!blockTrueEnd.Terminated || !blockFalseEnd.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); blockTrueEnd.Terminate(mCurrentBlock.StartLabel); blockFalseEnd.Terminate(mCurrentBlock.StartLabel); } }
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 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 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 ProcessAssignmentExpression(IAssignment pExpression) { HLLocation locationSource = ProcessExpression(pExpression.Source); HLLocation locationTarget = ProcessTargetExpression(pExpression.Target); mCurrentBlock.EmitAssignment(locationTarget, locationSource); return(locationTarget); }
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); }
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 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 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 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 void ProcessReturnStatement(IReturnStatement pStatement) { if (mCurrentBlock.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); } HLLocation locationExpression = null; if (pStatement.Expression != null) { locationExpression = ProcessExpression(pStatement.Expression); } mCurrentBlock.EmitReturn(locationExpression); }
private void ProcessSwitchStatement(ISwitchStatement pStatement) { //if (mCurrentBlock.Terminated) mCurrentBlock = CreateBlock(CreateLabel()); HLLocation locationCondition = ProcessExpression(pStatement.Expression); HLInstructionBlock blockParent = mCurrentBlock; List <HLInstructionBlock> blocksStarts = new List <HLInstructionBlock>(); List <HLInstructionBlock> blocksEnds = new List <HLInstructionBlock>(); HLInstructionBlock blockDefaultCase = null; List <Tuple <HLLiteralLocation, HLLabel> > cases = new List <Tuple <HLLiteralLocation, HLLabel> >(); foreach (ISwitchCase switchCase in pStatement.Cases) { HLInstructionBlock blockCase = CreateBlock(CreateLabel()); mCurrentBlock = blockCase; blocksStarts.Add(blockCase); if (switchCase.IsDefault) { blockDefaultCase = blockCase; } else { HLLiteralLocation locationCase = (HLLiteralLocation)ProcessCompileTimeConstantExpression(switchCase.Expression); cases.Add(new Tuple <HLLiteralLocation, HLLabel>(locationCase, blockCase.StartLabel)); } foreach (IStatement statementCase in switchCase.Body) { ProcessStatement(statementCase); } blocksEnds.Add(mCurrentBlock); } if (blockDefaultCase == null) { blockDefaultCase = CreateBlock(CreateLabel()); mCurrentBlock = blockDefaultCase; blocksStarts.Add(blockDefaultCase); blocksEnds.Add(blockDefaultCase); } blockParent.EmitSwitch(locationCondition, blockDefaultCase.StartLabel, cases); if (!blocksEnds.TrueForAll(b => b.Terminated)) { mCurrentBlock = CreateBlock(CreateLabel()); blocksEnds.ForEach(b => b.Terminate(mCurrentBlock.StartLabel)); } }
private void ProcessLocalDeclarationStatement(ILocalDeclarationStatement pStatement) { if (mCurrentBlock.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); } if (pStatement.InitialValue == null) { return; } HLLocation locationLocalVariable = HLLocalLocation.Create(HLDomain.GetLocal(pStatement.LocalVariable)); HLLocation locationInitialValue = ProcessExpression(pStatement.InitialValue); mCurrentBlock.EmitAssignment(locationLocalVariable, locationInitialValue); }
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 ProcessCreateObjectInstanceExpression(ICreateObjectInstance pExpression) { HLMethod methodCalled = HLDomain.GetOrCreateMethod(pExpression.MethodToCall); HLLocation locationThis = HLTemporaryLocation.Create(CreateTemporary(methodCalled.Container)); List <HLLocation> locationsParameters = new List <HLLocation>(); if (methodCalled.Container == HLDomain.SystemString) { locationsParameters.Add(locationThis.AddressOf()); } else { mCurrentBlock.EmitNewObject(methodCalled.Container, locationThis.AddressOf()); locationsParameters.Add(locationThis); } foreach (IExpression argument in pExpression.Arguments) { locationsParameters.Add(ProcessExpression(argument)); } mCurrentBlock.EmitCall(methodCalled, false, null, locationsParameters); return(locationThis); }
public void EmitBitwiseXor(HLLocation pDestination, HLLocation pLeftOperandSource, HLLocation pRightOperandSource) { Emit(HLBitwiseXorInstruction.Create(mMethod, pDestination, pLeftOperandSource, pRightOperandSource)); }
public void EmitBitwiseNot(HLLocation pDestination, HLLocation pSource) { Emit(HLBitwiseNotInstruction.Create(mMethod, pDestination, pSource)); }
public void EmitAssignment(HLLocation pDestination, HLLocation pSource) { Emit(HLAssignmentInstruction.Create(mMethod, pDestination, pSource)); }
public void EmitAdd(HLLocation pDestination, HLLocation pLeftOperandSource, HLLocation pRightOperandSource) { Emit(HLAddInstruction.Create(mMethod, pDestination, pLeftOperandSource, pRightOperandSource)); }
public void EmitSwitch(HLLocation pConditionSource, HLLabel pDefaultLabel, List<Tuple<HLLiteralLocation, HLLabel>> pCases) { Emit(HLSwitchInstruction.Create(mMethod, pConditionSource, pDefaultLabel, pCases)); }
public void EmitReturn(HLLocation pSource) { Emit(HLReturnInstruction.Create(mMethod, pSource)); }
public void EmitSwitch(HLLocation pConditionSource, HLLabel pDefaultLabel, List <Tuple <HLLiteralLocation, HLLabel> > pCases) { Emit(HLSwitchInstruction.Create(mMethod, pConditionSource, pDefaultLabel, pCases)); }
public void EmitNewDelegate(HLType pNewDelegateType, HLLocation pDestinationSource, HLLocation pInstanceSource, HLMethod pMethodCalled, bool pVirtual) { Emit(HLNewDelegateInstruction.Create(mMethod, pNewDelegateType, pDestinationSource, pInstanceSource, pMethodCalled, pVirtual)); }
public void EmitBranch(HLLocation pConditionSource, HLLabel pTrueLabel, HLLabel pFalseLabel) { Emit(HLBranchInstruction.Create(mMethod, pConditionSource, pTrueLabel, pFalseLabel)); }
public void EmitNewArray(HLLocation pDestinationSource, HLLocation pSizeSource, HLType pArrayType, HLType pElementType) { Emit(HLNewArrayInstruction.Create(mMethod, pDestinationSource, pSizeSource, pArrayType, pElementType)); }
public void EmitCompare(HLCompareType pCompareType, HLLocation pDestination, HLLocation pLeftOperandSource, HLLocation pRightOperandSource) { Emit(HLCompareInstruction.Create(mMethod, pCompareType, pDestination, pLeftOperandSource, pRightOperandSource)); }
public void EmitNewObject(HLType pNewObjectType, HLLocation pDestinationSource) { Emit(HLNewObjectInstruction.Create(mMethod, pNewObjectType, pDestinationSource)); }
public void EmitSubtract(HLLocation pDestination, HLLocation pLeftOperandSource, HLLocation pRightOperandSource) { Emit(HLSubtractInstruction.Create(mMethod, pDestination, pLeftOperandSource, pRightOperandSource)); }
public void EmitBitwiseOr(HLLocation pDestination, HLLocation pLeftOperandSource, HLLocation pRightOperandSource) { Emit(HLBitwiseOrInstruction.Create(mMethod, pDestination, pLeftOperandSource, pRightOperandSource)); }
public void EmitCall(HLMethod pCalledMethod, bool pVirtual, HLLocation pReturnDestination, List<HLLocation> pParameterSources) { Emit(HLCallInstruction.Create(mMethod, pCalledMethod, pVirtual, pReturnDestination, pParameterSources)); }