Пример #1
0
        ///// <summary>
        ///// Get the information of the first definition for the l-value with the given name
        ///// </summary>
        ///// <param name="lvalue_name"></param>
        ///// <returns></returns>
        //public HLOLValueDefinitionInfo GetFirstDefinitionInfo(string lvalue_name)
        //{
        //    if (_LValuesDictionary.ContainsKey(lvalue_name))
        //        return _LValuesDictionary[lvalue_name].FirstOrDefault();

        //    return null;
        //}

        /// <summary>
        /// Get the information of the first definition for the given l-value
        /// </summary>
        /// <param name="lvalue"></param>
        /// <returns></returns>
        public HlLValueDefinitionInfo GetFirstDefinitionInfo(SymbolLValue lvalue)
        {
            return
                (_lValuesDictionary.ContainsKey(lvalue.ObjectName)
                ? _lValuesDictionary[lvalue.ObjectName].FirstOrDefault()
                : null);
        }
Пример #2
0
        public BasicUnary ReplaceLValueByExpression(BasicUnary oldExpr, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr)
        {
            ReplaceLValueByExpression(oldExpr.Operator, oldLvalue, newExpr);

            oldExpr.ChangeOperand(ReplaceLValueByExpression(oldExpr.Operand, oldLvalue, newExpr));

            return(oldExpr);
        }
Пример #3
0
        /// <summary>
        /// Create a new ValueComponentAccessBySymbol object and append it to this LanguageValueAccess
        /// </summary>
        /// <param name="accessStepSymbol"></param>
        /// <param name="accessStepType"></param>
        /// <returns></returns>
        public LanguageValueAccess Append(SymbolLValue accessStepSymbol, ILanguageType accessStepType)
        {
            var accessStep = ValueAccessStepByLValue.Create(accessStepType, accessStepSymbol);

            _accessSteps.Add(accessStep);

            return(this);
        }
Пример #4
0
        public OperandsList ReplaceLValueByExpression(OperandsList oldOperands, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr)
        {
            for (var i = 0; i < oldOperands.Operands.Count; i++)
            {
                var newOpExpr = ReplaceLValueByExpression(oldOperands.Operands[i], oldLvalue, newExpr);

                oldOperands.ChangeOperand(i, newOpExpr);
            }

            return(oldOperands);
        }
Пример #5
0
        public OperandsByName ReplaceLValueByExpression(OperandsByName oldOperands, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr)
        {
            var newOperands = new Dictionary <string, ILanguageExpressionAtomic>();

            foreach (var pair in oldOperands.OperandsDictionary)
            {
                var newOpExpr = ReplaceLValueByExpression(pair.Value, oldLvalue, newExpr);

                newOperands.Add(pair.Key, newOpExpr);
            }

            oldOperands.OperandsDictionary.Clear();

            foreach (var pair in newOperands)
            {
                oldOperands.AddOperand(pair.Key, pair.Value);
            }

            return(oldOperands);
        }
Пример #6
0
        public HlLValueDefinitionInfo(int defIndex, SymbolLValue lvalue, HlCommandInfo commandInfo)
        {
            //Output macro parameters are not accepted here
            var parameter = lvalue as SymbolProcedureParameter;

            if (parameter != null && parameter.DirectionOut)
            {
                throw new InvalidOperationException("Cannot generate definition for macro output parameter");
            }

            //A local variable l-value must have a defining assignment command
            if (lvalue is SymbolLocalVariable && ReferenceEquals(commandInfo, null))
            {
                throw new InvalidOperationException("A local variable must have a defining assignment command");
            }

            DefinitionIndex = defIndex;
            LValue          = lvalue;
            DefiningCommand = commandInfo;

            switch (DefinitionIndex)
            {
            case 0:
                //This is the first use of this l-value as the LHS of an assignment command
                CurrentSsaFormName  = LValue.ObjectName;
                PreviousSsaFormName = "";
                break;

            case 1:
                //This is the second use of this l-value as the LHS of an assignment command
                CurrentSsaFormName  = LValue.ObjectName + "SSA" + DefinitionIndex;
                PreviousSsaFormName = LValue.ObjectName;
                break;

            default:
                CurrentSsaFormName  = LValue.ObjectName + "SSA" + DefinitionIndex;
                PreviousSsaFormName = LValue.ObjectName + "SSA" + (DefinitionIndex - 1);
                break;
            }
        }
Пример #7
0
        public BasicPolyadic ReplaceLValueByExpression(BasicPolyadic oldExpr, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr)
        {
            ReplaceLValueByExpression(oldExpr.Operator, oldLvalue, newExpr);

            var t1 = oldExpr.Operands as OperandsByIndex;

            if (t1 != null)
            {
                ReplaceLValueByExpression(t1, oldLvalue, newExpr);
                return(oldExpr);
            }

            var t2 = oldExpr.Operands as OperandsByName;

            if (t2 != null)
            {
                ReplaceLValueByExpression(t2, oldLvalue, newExpr);
                return(oldExpr);
            }

            var t3 = oldExpr.Operands as OperandsList;

            if (t3 != null)
            {
                ReplaceLValueByExpression(t3, oldLvalue, newExpr);
                return(oldExpr);
            }

            var t4 = oldExpr.Operands as OperandsByValueAccess;

            if (t4 == null)
            {
                return(oldExpr);
            }

            ReplaceLValueByExpression(t4, oldLvalue, newExpr);
            return(oldExpr);
        }
Пример #8
0
        public ValueAccessStepByLValue ReplaceComponentSymbol(SymbolLValue componentLvalue)
        {
            AccessLValue = componentLvalue;

            return(this);
        }
Пример #9
0
 public ValueAccessStep Duplicate(SymbolLValue componentLvalue)
 {
     return(new ValueAccessStepByLValue(AccessStepType, componentLvalue));
 }
Пример #10
0
        //private ValueAccessStepBySymbol(ValueAccessStep parent_component, ILanguageType component_type, LanguageSymbol component_symbol)
        //    : base(parent_component, component_type)
        //{
        //    ComponentSymbol = component_symbol;
        //}

        private ValueAccessStepByLValue(ILanguageType componentType, SymbolLValue componentSymbol)
            : base(componentType)
        {
            AccessLValue = componentSymbol;
        }
Пример #11
0
        public virtual ILanguageExpression ReplaceLValueByExpression(ILanguageExpression oldExpr, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr)
        {
            var t1 = oldExpr as LanguageValueAccess;

            if (t1 != null)
            {
                return(ReplaceLValueByExpression(t1, oldLvalue, newExpr));
            }

            var t2 = oldExpr as BasicUnary;

            if (t2 != null)
            {
                return(ReplaceLValueByExpression(t2, oldLvalue, newExpr));
            }

            var t3 = oldExpr as BasicBinary;

            if (t3 != null)
            {
                return(ReplaceLValueByExpression(t3, oldLvalue, newExpr));
            }

            var t4 = oldExpr as BasicPolyadic;

            return
                (t4 == null
                ? oldExpr
                : ReplaceLValueByExpression(t4, oldLvalue, newExpr));
        }
Пример #12
0
        public ILanguageExpressionAtomic ReplaceLValueByExpression(LanguageValueAccess oldValueAccess, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr)
        {
            //If the old value acceess does not depend on the old_lvalue just return the old value access as is
            if (oldValueAccess.HasAccessStepWithSymbol(oldLvalue) == false)
            {
                return(oldValueAccess);
            }

            //If the old value access is a full access just return the new atomic expression
            if (oldValueAccess.IsFullAccess)
            {
                return(newExpr);
            }

            //If the new expression is a language value access
            var valAccess = newExpr as LanguageValueAccess;

            if (valAccess != null)
            {
                oldValueAccess.ReplaceRootSymbol(valAccess);

                foreach (var component in oldValueAccess.PartialAccessStepsByLValue(oldLvalue))
                {
                    if (valAccess.IsFullAccess)
                    {
                        component.ReplaceComponentSymbol(valAccess.RootSymbolAsLValue);
                    }
                    else
                    {
                        throw new InvalidOperationException("Can't replace a symbol with a non-symbol in this access step");
                    }
                }

                return(oldValueAccess);
            }

            if (!(newExpr is ILanguageValue))
            {
                return(oldValueAccess);
            }

            if (oldValueAccess.IsVariableAccess)
            {
                throw new InvalidOperationException("Can't replace a symbol with a non-symbol in this access process");
            }

            return(ReadPartialValue((ILanguageValue)newExpr, oldValueAccess));
        }
 ExpandAndAssignAll(this SymbolLValue symbol, IGMacBinding pattern)
 {
     return(ExpandAndAssignAll(LanguageValueAccess.Create(symbol), pattern));
 }
Пример #14
0
        /// <summary>
        /// Get the information of the first command for the given l-value
        /// </summary>
        /// <param name="lvalue"></param>
        /// <returns></returns>
        public HlCommandInfo GetFirstDefiningCommandInfo(SymbolLValue lvalue)
        {
            var defInfo = GetFirstDefinitionInfo(lvalue);

            return(ReferenceEquals(defInfo, null) ? null : defInfo.DefiningCommand);
        }
Пример #15
0
        public OperandsByValueAccess ReplaceLValueByExpression(OperandsByValueAccess oldOperands, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr)
        {
            foreach (var assignment in oldOperands.AssignmentsList)
            {
                var newOpExpr = ReplaceLValueByExpression(assignment.RhsExpression, oldLvalue, newExpr);

                assignment.ChangeRhsExpression(newOpExpr);
            }

            return(oldOperands);
        }
Пример #16
0
 /// <summary>
 /// Replace the occurances of the given l-value inside the given language operator with the given atomic expression
 /// </summary>
 /// <param name="oldLangOperator"></param>
 /// <param name="oldLvalue"></param>
 /// <param name="newExpr"></param>
 /// <returns></returns>
 public abstract ILanguageOperator ReplaceLValueByExpression(ILanguageOperator oldLangOperator, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr);
Пример #17
0
 /// <summary>
 /// Retrieve the definition information associated with an l-value in the RHS of this command
 /// </summary>
 /// <param name="lvalue"></param>
 /// <returns></returns>
 public HlLValueDefinitionInfo GetRhslValueInfo(SymbolLValue lvalue)
 {
     return(RhsVariablesInfo.FirstOrDefault(lvalueInfo => lvalueInfo.LValue.ObjectId == lvalue.ObjectId));
 }
Пример #18
0
 public static ValueAccessStepByLValue Create(ILanguageType componentType, SymbolLValue componentLvalue)
 {
     return(new ValueAccessStepByLValue(componentType, componentLvalue));
 }
Пример #19
0
        /// <summary>
        /// Create a composite type initialized constructor RHS expression based on the given command with
        /// partial LHS value access and a new temporary local variable as explained in Optimize_ReplaceAllLHSPartialAccess
        /// </summary>
        /// <param name="commandInfo"></param>
        /// <param name="newLvalue"></param>
        /// <returns></returns>
        private BasicPolyadic CreateConstructorExpression(HlCommandInfo commandInfo, SymbolLValue newLvalue)
        {
            var oldValueAccess = commandInfo.AssociatedCommand.LhsValueAccess;

            var oldLvalue = oldValueAccess.RootSymbolAsLValue;

            var firstDefStId = _lValuesTable.GetFirstDefiningCommandInfo(oldLvalue).CommandInfoId;

            var useDefaultSource =
                firstDefStId < 0 || firstDefStId != commandInfo.CommandInfoId;

            var typeStructure = oldValueAccess.RootSymbolAsLValue.SymbolType as GMacStructure;

            if (typeStructure != null)
            {
                var structure = typeStructure;

                var operands = OperandsByValueAccess.Create();

                var dataMemberName = ((ValueAccessStepByKey <string>)oldValueAccess.LastAccessStep).AccessKey;

                var dataMember = structure.GetDataMember(dataMemberName);

                var operandLhsValueAccess = LanguageValueAccess.Create(dataMember);

                var operandRhsExpr = LanguageValueAccess.Create(newLvalue);

                operandLhsValueAccess.Append(oldValueAccess.AccessSteps.Skip(2));

                operands.AddOperand(operandLhsValueAccess, operandRhsExpr);

                if (useDefaultSource)
                {
                    return(structure.CreateConstructorExpression(
                               LanguageValueAccess.Create(oldLvalue),
                               operands
                               ));
                }

                return(structure.CreateConstructorExpression(operands));
            }

            if (!(oldValueAccess.RootSymbolAsLValue.SymbolType is GMacFrameMultivector))
            {
                throw new InvalidOperationException("Unknown composite type to be constructed");
            }

            var mvType = (GMacFrameMultivector)oldValueAccess.RootSymbolAsLValue.SymbolType;

            var operandsByIndex = OperandsByIndex.Create();

            var stepByKey = oldValueAccess.LastAccessStep as ValueAccessStepByKey <int>;

            if (stepByKey != null)
            {
                var id = stepByKey.AccessKey;

                operandsByIndex.AddOperand(id, LanguageValueAccess.Create(newLvalue));
            }
            else
            {
                var stepByKeyList = oldValueAccess.LastAccessStep as ValueAccessStepByKeyList <int>;

                if (stepByKeyList == null)
                {
                    throw new InvalidOperationException("Invalid access step for a multivector");
                }

                var idsList = stepByKeyList.AccessKeyList;

                foreach (var id in idsList)
                {
                    operandsByIndex.AddOperand(id,
                                               LanguageValueAccess.Create(newLvalue).Append(id, ((GMacAst)BaseMacro.RootAst).ScalarType));
                }
            }

            if (useDefaultSource)
            {
                return(mvType.CreateConstructorExpression(
                           LanguageValueAccess.Create(oldLvalue),
                           operandsByIndex
                           ));
            }

            return(mvType.CreateConstructorExpression(operandsByIndex));
        }
Пример #20
0
        public ILanguageExpressionAtomic ReplaceLValueByExpression(ILanguageExpressionAtomic oldExpr, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr)
        {
            var expr = oldExpr as LanguageValueAccess;

            return
                (expr == null ?
                 oldExpr :
                 ReplaceLValueByExpression(expr, oldLvalue, newExpr));
        }
Пример #21
0
        public override ILanguageOperator ReplaceLValueByExpression(ILanguageOperator oldLangOperator, SymbolLValue oldLvalue, ILanguageExpressionAtomic newExpr)
        {
            var structureConstructor = oldLangOperator as GMacStructureConstructor;

            if (structureConstructor != null)
            {
                var structureCons = structureConstructor;

                if (structureCons.HasDefaultValueSource)
                {
                    structureCons.SetDefaultValueSource(
                        ReplaceLValueByExpression(structureCons.DefaultValueSource, oldLvalue, newExpr)
                        );
                }

                return(oldLangOperator);
            }

            var multivectorConstructor = oldLangOperator as GMacFrameMultivectorConstructor;

            if (multivectorConstructor == null)
            {
                return(oldLangOperator);
            }

            var mvTypeCons = multivectorConstructor;

            if (mvTypeCons.HasDefaultValueSource)
            {
                mvTypeCons.SetDefaultValueSource(
                    ReplaceLValueByExpression(mvTypeCons.DefaultValueSource, oldLvalue, newExpr)
                    );
            }

            return(oldLangOperator);
        }
 ExpandAndAssignAll(this SymbolLValue symbol, ILanguageValue value)
 {
     return(ExpandAndAssignAll(LanguageValueAccess.Create(symbol), value));
 }