Exemplo n.º 1
0
        /// <summary>
        ///     Creates an implemented expression
        /// </summary>
        /// <param name="parser">XLExpressionParser</param>
        /// <param name="currentNode">Current Expression Node</param>
        /// <returns></returns>
        public override HlExpression Create(HlExpressionParser parser, HlExpression currentNode)
        {
            HlTokenType type = parser.CurrentToken.Type;

            parser.Eat(parser.CurrentToken.Type);

            HlExpression token =
                new HlBinaryOp(currentNode, type, parser.ParseExpr(PrecedenceLevel));

            return(token);
        }
        public override ExpressionTarget ParseExpression(
            HlCompilation compilation,
            HlBinaryOp expr)
        {
            ExpressionTarget target = compilation.Parse(expr.Left);

            ExpressionTarget rTarget = compilation.Parse(
                expr.Right
                );

            if (SettingsManager.GetSettings <HlCompilerSettings>().OptimizeReduceExpressions&&
                IsReducable(rTarget))
            {
                uint   amount = GetPowLevel(rTarget.StaticParse());
                string tmp    = compilation.GetTempVarLoad(amount.ToString());

                ExpressionTarget taddr = target.MakeAddress(compilation);
                compilation.EmitterResult.Emit(
                    "SHR",
                    taddr.ResultAddress,
                    tmp
                    );

                compilation.ReleaseTempVar(tmp);
                compilation.ReleaseTempVar(taddr.ResultAddress);

                return(target);
            }

            string rtOrig = rTarget.ResultAddress;

            rTarget = rTarget.MakeAddress(compilation);

            string instrKey =
                target.TypeDefinition.Name == HLBaseTypeNames.s_FloatTypeName ||
                rTarget.TypeDefinition.Name == HLBaseTypeNames.s_FloatTypeName
                    ? InstructionKey + ".F"
                    : InstructionKey;

            compilation.EmitterResult.Emit(
                instrKey,
                target.ResultAddress,
                rTarget.ResultAddress
                );

            compilation.ReleaseTempVar(rTarget.ResultAddress);

            compilation.ReleaseTempVar(rtOrig);

            return(target);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Creates an implemented expression
        /// </summary>
        /// <param name="parser">XLExpressionParser</param>
        /// <param name="currentNode">Current Expression Node</param>
        /// <returns></returns>
        public override HlExpression Create(HlExpressionParser parser, HlExpression currentNode)
        {
            HlTokenType type = parser.CurrentToken.Type;

            parser.Eat(parser.CurrentToken.Type);
            HlExpression node = null;

            if (type == HlTokenType.OpLessThan)
            {
                if (parser.CurrentToken.Type == HlTokenType.OpEquality)
                {
                    parser.Eat(HlTokenType.OpEquality);

                    node = new HlBinaryOp(
                        currentNode,
                        HlTokenType.OpLessOrEqual,
                        parser.ParseExpr(PrecedenceLevel)
                        );
                }
                else
                {
                    node = new HlBinaryOp(currentNode, type, parser.ParseExpr(PrecedenceLevel));
                }
            }
            else if (type == HlTokenType.OpGreaterThan)
            {
                if (parser.CurrentToken.Type == HlTokenType.OpEquality)
                {
                    parser.Eat(HlTokenType.OpEquality);

                    node = new HlBinaryOp(
                        currentNode,
                        HlTokenType.OpGreaterOrEqual,
                        parser.ParseExpr(PrecedenceLevel)
                        );
                }
                else
                {
                    node = new HlBinaryOp(currentNode, type, parser.ParseExpr(PrecedenceLevel));
                }
            }

            return(node);
        }
Exemplo n.º 4
0
        public override ExpressionTarget ParseExpression(
            HlCompilation compilation,
            HlBinaryOp expr,
            ExpressionTarget outputTarget)
        {
            ExpressionTarget targetVal  = compilation.Parse(expr.Left);
            ExpressionTarget rTargetVal = compilation.Parse(expr.Right);

            if (SettingsManager.GetSettings <HlCompilerSettings>().OptimizeConstExpressions&&
                !targetVal.IsAddress &&
                !rTargetVal.IsAddress)
            {
                return(ComputeStatic(compilation, targetVal, rTargetVal));
            }

            if (SettingsManager.GetSettings <HlCompilerSettings>().OptimizeConstExpressions)
            {
                uint             amount   = 0;
                ExpressionTarget baseExpr = default;

                if (IsReducable(targetVal))
                {
                    baseExpr = rTargetVal.MakeAddress(compilation);
                    amount   = GetPowLevel(targetVal.StaticParse());
                }
                else if (IsReducable(rTargetVal))
                {
                    baseExpr = targetVal.MakeAddress(compilation);
                    amount   = GetPowLevel(rTargetVal.StaticParse());
                }

                if (amount != 0)
                {
                    string tmp = compilation.GetTempVarLoad(amount.ToString());

                    compilation.EmitterResult.Emit(
                        "SHL",
                        baseExpr.ResultAddress,
                        tmp,
                        outputTarget.ResultAddress
                        );

                    compilation.ReleaseTempVar(tmp);
                    compilation.ReleaseTempVar(baseExpr.ResultAddress);
                    compilation.ReleaseTempVar(targetVal.ResultAddress);
                    compilation.ReleaseTempVar(rTargetVal.ResultAddress);

                    return(outputTarget);
                }
            }

            ExpressionTarget target  = targetVal.MakeAddress(compilation);
            ExpressionTarget rTarget = rTargetVal.MakeAddress(compilation);

            string instrKey =
                target.TypeDefinition.Name == HLBaseTypeNames.s_FloatTypeName ||
                rTarget.TypeDefinition.Name == HLBaseTypeNames.s_FloatTypeName
                    ? InstructionKey + ".F"
                    : InstructionKey;

            if (target.IsPointer)
            {
                ExpressionTarget et = new ExpressionTarget(
                    compilation.GetTempVarDref(target.ResultAddress),
                    true,
                    target.TypeDefinition
                    );

                compilation.EmitterResult.Emit(
                    instrKey,
                    et.ResultAddress,
                    rTarget.ResultAddress,
                    outputTarget.ResultAddress
                    );

                compilation.ReleaseTempVar(et.ResultAddress);
                compilation.ReleaseTempVar(rTarget.ResultAddress);
                compilation.ReleaseTempVar(target.ResultAddress);
                compilation.ReleaseTempVar(targetVal.ResultAddress);
                compilation.ReleaseTempVar(rTargetVal.ResultAddress);

                return(outputTarget);
            }

            compilation.EmitterResult.Emit(
                instrKey,
                target.ResultAddress,
                rTarget.ResultAddress,
                outputTarget.ResultAddress
                );

            compilation.ReleaseTempVar(rTarget.ResultAddress);
            compilation.ReleaseTempVar(target.ResultAddress);
            compilation.ReleaseTempVar(targetVal.ResultAddress);
            compilation.ReleaseTempVar(rTargetVal.ResultAddress);

            return(outputTarget);
        }