BuildReturn() public method

public BuildReturn ( ) : Value
return Value
Ejemplo n.º 1
0
        public Function CodeGen(IRBuilder builder)
        {
            CodeGenManager.NamedValues.Clear();
            Function func = this.Proto.CodeGen(builder);
            if(func == null)
                return null;

            // Create a new basic block to start insertion into.
            BasicBlock bb = func.AppendBasicBlock("entry");
            builder.SetInsertPoint(bb);
            Value retVal = Body.CodeGen(builder);

            if(!retVal.IsNull)
            {
                builder.BuildReturn(retVal);

                // Validate the generated code, checking for consistency.
                func.Validate(LLVMVerifierFailureAction.PrintMessageAction);

                return func;
            }

            // Error reading body, remove function.
            func.Delete();
            return null;
        }
Ejemplo n.º 2
0
        public Function CodeGen(IRBuilder builder, PassManager passManager)
        {
            CodeGenManager.NamedValues.Clear();
            Function func = this.Proto.CodeGen(builder);
            if(func == null)
                return null;

            // If this is an operator, install it.
            if(this.Proto.IsBinaryOp)
                CodeGenManager.BinopPrecendence[Proto.OperatorName] = Proto.Precedence;

            // Create a new basic block to start insertion into.
            BasicBlock bb = func.AppendBasicBlock("entry");
            builder.SetInsertPoint(bb);

            Proto.CreateArgAllocas(func, builder);

            Value retVal = Body.CodeGen(builder);

            if(!retVal.IsNull)
            {
                builder.BuildReturn(retVal);

                // Validate the generated code, checking for consistency.
                func.Validate(LLVMVerifierFailureAction.PrintMessageAction);

                // Optimize the function.
                passManager.Run(func);

                return func;
            }

            // Error reading body, remove function.
            func.Delete();
            return null;
        }