public override void Visit(CondElse condElse)
        {
            var expr = new ExpressionSimplifierVisitor().Visit(condElse.Expr);

            if (expr is Bool b)
            {
                Visit(b.Value ? condElse.TBlock : condElse.FBlock);
                return;
            }

            var exprResult = new ExpressionGeneratorVisitor(_state).Visit(expr);

            _state.GoToNextLabel(out var trueLabel);
            string falseLabel = _state.NewLabel, endIfLabel = _state.NewLabel;

            _llvmGenerator.Emit($"br i1 {exprResult.Register}, label %{trueLabel}, label %{falseLabel}");

            _llvmGenerator.Emit($"{trueLabel}:");
            Visit(condElse.TBlock);
            _llvmGenerator.Emit($"br label %{endIfLabel}");

            _state.CurrentLabel = falseLabel;
            _llvmGenerator.Emit($"{falseLabel}:");
            Visit(condElse.FBlock);
            _llvmGenerator.Emit($"br label %{endIfLabel}");

            _state.CurrentLabel = endIfLabel;
            _llvmGenerator.Emit($"{endIfLabel}:");
        }
예제 #2
0
 public virtual void Visit(CondElse condElse)
 {
 }