예제 #1
0
        public static void EmitIf(IfStatement ifst, List<ILInstuction> il)
        {
            ILDummy end = new ILDummy();
            end.Line = GetLabel();
            foreach (var ic in ifst.Clauses)
            {
                ILBranch branch = new ILBranch();
                ILDummy blockBegin = new ILDummy();
                ILDummy blockEnd = new ILDummy();
                branch.Line = GetLabel();
                blockBegin.Line = GetLabel();
                blockEnd.Line = GetLabel();

                ILGoto gotoEnd = new ILGoto(end.Line);
                gotoEnd.Line = GetLabel();
                branch.SuccessJump = blockBegin.Line;
                branch.FailJump = blockEnd.Line;
                branch.Condition = ConstructILExpression(ic.Condition);
                il.Add(branch);
                il.Add(blockBegin);
                EmitStatementList(ic.Statements, il);
                il.Add(gotoEnd);
                il.Add(blockEnd);
            }
            if (ifst.AlternativeStatements != null)
            {
                EmitStatementList(ifst.AlternativeStatements, il);
            }
            il.Add(end);
        }
예제 #2
0
        public static void _EmitIf(IfStatement ifst,  List<ILInstuction> il)
        {
            ILDummy end = new ILDummy();
            end.Line = GetLabel();
            foreach (var ic in ifst.Clauses)
            {
                ILBranch branch = new ILBranch();
                ILDummy blockBegin = new ILDummy();
                ILDummy blockEnd = new ILDummy();
                branch.Line = GetLabel();
                blockBegin.Line = GetLabel();
                blockEnd.Line = GetLabel();

                ILGoto gotoEnd = new ILGoto(end.Line);
                gotoEnd.Line = GetLabel();
                branch.SuccessJump = blockBegin.Line;
                branch.FailJump = blockEnd.Line;

                var ifConditionVariable = _EmitExpression(ic.Condition, il);

                CurrentFunction.AddLocal(ifConditionVariable, ic.Condition.ResultType);

                branch.Condition = _constructVariableAccess(ifConditionVariable);

                il.Add(branch);
                il.Add(blockBegin);
                _EmitStatementList(ic.Statements, il);
                il.Add(gotoEnd);
                il.Add(blockEnd);
            }
            if (ifst.AlternativeStatements != null)
            {
                _EmitStatementList(ifst.AlternativeStatements, il);
            }
            il.Add(end);
        }