| 835 | } |
| 836 | |
| 837 | llvm::Function* LlvmCodeGen::FnPrototype::GeneratePrototype( |
| 838 | LlvmBuilder* builder, llvm::Value** params) { |
| 839 | vector<llvm::Type*> arguments; |
| 840 | arguments.reserve(args_.size()); |
| 841 | for (int i = 0; i < args_.size(); ++i) { |
| 842 | arguments.push_back(args_[i].type); |
| 843 | } |
| 844 | llvm::FunctionType* prototype = llvm::FunctionType::get(ret_type_, arguments, false); |
| 845 | |
| 846 | llvm::Function* fn = llvm::Function::Create( |
| 847 | prototype, llvm::GlobalValue::ExternalLinkage, name_, codegen_->module_); |
| 848 | DCHECK(fn != NULL); |
| 849 | |
| 850 | // Name the arguments |
| 851 | int idx = 0; |
| 852 | for (llvm::Function::arg_iterator iter = fn->arg_begin(); iter != fn->arg_end(); |
| 853 | ++iter, ++idx) { |
| 854 | iter->setName(args_[idx].name); |
| 855 | if (params != NULL) params[idx] = &*iter; |
| 856 | } |
| 857 | |
| 858 | if (builder != NULL) { |
| 859 | llvm::BasicBlock* entry_block = |
| 860 | llvm::BasicBlock::Create(codegen_->context(), "entry", fn); |
| 861 | // Add it to the llvm module via the builder and to the list of handcrafted functions |
| 862 | // that are a part of the module. |
| 863 | builder->SetInsertPoint(entry_block); |
| 864 | codegen_->handcrafted_functions_.push_back(fn); |
| 865 | } |
| 866 | return fn; |
| 867 | } |
| 868 | |
| 869 | Status LlvmCodeGen::LoadFunction(const TFunction& fn, const string& symbol, |
| 870 | const ColumnType* return_type, const vector<ColumnType>& arg_types, |