Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 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();
 }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
        }