예제 #1
0
        public override string Template()
        {
            var conditionFunc = Healpers.GetFunctionId();
            var endFunc       = Healpers.GetFunctionId();


            var tmp =
                $"# for {Initialise};{Condition};{PostExpression}" +
                $"\n{Initialise.Template()}" +
                $"\n{conditionFunc}:" +
                $"\n# {Condition}" +
                $"\n{Condition.Template()}" +
                "\ncmpq\t$0,%rax\t# compare condition result to 0" +
                $"\nje\t{endFunc}\t# jump to end if condition false" +
                $"\n{Statement.Template()}";

            var end =
                $"\n{PostExpression.Template()}" +
                $"\njmp\t{conditionFunc}\t# loop" +
                $"\n{endFunc}:\n";

            var continuePoint = Scope.UseContinue();
            var breakPoint    = Scope.UseBreakpoint();

            return(tmp + (continuePoint != null ? $"\n{continuePoint}:\t# Continue point" : "") + end + (breakPoint != null ? $"{breakPoint}:\t# Breakpoint\n" : ""));
        }
예제 #2
0
        public override string Template()
        {
            var endFunc   = Healpers.GetFunctionId();
            var falseFunc = Healpers.GetFunctionId();
            var compare   = $"cmpq\t$0, %rax\nje\t{falseFunc}";

            return($"{Expression.Template()}\n{compare}\n{TrueResult.Template()}\njmp\t{endFunc}\n{falseFunc}:\n{FalseResult.Template()}\n{endFunc}:");
        }
예제 #3
0
        public override string Template()
        {
            var whileFunc = Healpers.GetFunctionId();
            var endFunc   = Healpers.GetFunctionId();

            var breakPoint = Scope.UseBreakpoint();
            var tmp        = $"{whileFunc}:\n{Expression.Template()}\ncmpq\t$0,%rax\nje\t{endFunc}\n{Statement.Template()}\njmp\t{whileFunc}\n{endFunc}:";

            return(breakPoint != null ? tmp + $"{breakPoint}:\t# Breakpoint\n" : tmp);
        }
예제 #4
0
        public override string Template()
        {
            var branchName = Healpers.GetFunctionId();
            var endName    = Healpers.GetFunctionId();

            var main =
                $"{LeftExpression.Template()}" +
                "\ncmpq\t$0,%rax" +
                $"\nje\t{branchName}\t# OR ({LeftExpression} || {RightExpression})" +
                "\nmovq\t$1,%rax" +
                $"\njmp\t{endName}";

            var branch =
                $"\n{branchName}:" +
                $"\n{RightExpression.Template()}" +
                "\ncmpq\t$0,%rax" +
                "\nmovq\t$0,%rax" +
                "\nsetne\t%al";

            var end = $"\n{endName}:";

            return(main + branch + end);
        }
예제 #5
0
        public override string Template()
        {
            var endFunc = Healpers.GetFunctionId();

            string compare;

            if (Else != null)
            {
                var elseFunc = Healpers.GetFunctionId();

                compare =
                    "cmpq\t$0, %rax" +
                    $"\nje\t{elseFunc}\t\t\t\t# jump else";

                return
                    ($"{Expression.Template()}" +
                     $"\n{compare}" +
                     $"\n{Statement.Template()}" +
                     $"\njmp\t{endFunc}" +
                     $"\n{elseFunc}:" +
                     $"\n{Else.Template()}" +
                     $"\njmp\t{endFunc}" +
                     $"\n{endFunc}:\t\t\t# end of if\n");
            }

            compare =
                "cmpq\t$0, %rax\t" +
                $"\nje\t{endFunc}\t\t# jump to end if false";

            return
                ($";# if {Expression}" +
                 $"\n{Expression.Template()}" +
                 $"\n{compare}" +
                 $"\n{Statement.Template()}" +
                 $"\n{endFunc}:\t\t\t# end of if\n");
        }
예제 #6
0
        public override string Template()
        {
            var statementFunc = Healpers.GetFunctionId();

            return($"{statementFunc}:\n{Statement.Template()}\n{Expression.Template()}\ncmpq\t$0,%rax\njne\t{statementFunc}\n");
        }