コード例 #1
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }
コード例 #2
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }
コード例 #3
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }
コード例 #4
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }
コード例 #5
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }
コード例 #6
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }
コード例 #7
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }
コード例 #8
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }
コード例 #9
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }
コード例 #10
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
 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();
 }
コード例 #11
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }
コード例 #12
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }
コード例 #13
0
ファイル: HLMethod.cs プロジェクト: Astaelan/Neutron
        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);
        }