示例#1
0
        protected internal virtual ExprAST VisitIfExprAST(IfExpAST node)
        {
            this.Visit(node.Condition);
            this.Visit(node.Then);
            this.Visit(node.Else);

            return node;
        }
示例#2
0
        protected internal virtual ExprAST VisitIfExprAST(IfExpAST node)
        {
            this.Visit(node.Condition);
            this.Visit(node.Then);
            this.Visit(node.Else);

            return(node);
        }
示例#3
0
        protected override ExprAST VisitIfExprAST(IfExpAST node)
        {
            this.Visit(node.Condition);
            var condv = LLVM.BuildFCmp(this.builder, LLVMRealPredicate.LLVMRealONE, this.valueStack.Pop(), LLVM.ConstReal(LLVM.DoubleType(), 0.0), "ifcond");

            LLVMValueRef func = LLVM.GetBasicBlockParent(LLVM.GetInsertBlock(builder));

            // Create blocks for the then and else cases.  Insert the 'then' block at the
            // end of the function.
            LLVMBasicBlockRef thenBB  = LLVM.AppendBasicBlock(func, "then");
            LLVMBasicBlockRef elseBB  = LLVM.AppendBasicBlock(func, "else");
            LLVMBasicBlockRef mergeBB = LLVM.AppendBasicBlock(func, "ifcont");

            LLVM.BuildCondBr(this.builder, condv, thenBB, elseBB);

            // Emit then value.
            LLVM.PositionBuilderAtEnd(this.builder, thenBB);

            this.Visit(node.Then);
            var thenV = this.valueStack.Pop();

            LLVM.BuildBr(this.builder, mergeBB);

            // Codegen of 'Then' can change the current block, update ThenBB for the PHI.
            thenBB = LLVM.GetInsertBlock(this.builder);

            // Emit else block.

            LLVM.PositionBuilderAtEnd(this.builder, elseBB);

            this.Visit(node.Else);
            var elseV = this.valueStack.Pop();

            LLVM.BuildBr(this.builder, mergeBB);

            // Codegen of 'Else' can change the current block, update ElseBB for the PHI.
            elseBB = LLVM.GetInsertBlock(this.builder);

            // Emit merge block.
            LLVM.PositionBuilderAtEnd(this.builder, mergeBB);
            var phi = LLVM.BuildPhi(this.builder, LLVM.DoubleType(), "iftmp");

            LLVM.AddIncoming(phi, new [] { thenV }, new [] { thenBB }, 1);
            LLVM.AddIncoming(phi, new [] { elseV }, new [] { elseBB }, 1);

            this.valueStack.Push(phi);

            return(node);
        }