@@ -97,8 +97,9 @@ auto ASTToObjectVisitor::getFunction(std::string name) -> void {
9797 */
9898auto ASTToObjectVisitor::CreateEntryBlockAlloca (
9999 llvm::Function* fn, llvm::StringRef var_name) -> llvm::AllocaInst* {
100- llvm::IRBuilder<> TmpB (&fn->getEntryBlock (), fn->getEntryBlock ().begin ());
101- return TmpB.CreateAlloca (ArxLLVM::FLOAT_TYPE, nullptr , var_name);
100+ llvm::IRBuilder<> tmp_builder (
101+ &fn->getEntryBlock (), fn->getEntryBlock ().begin ());
102+ return tmp_builder.CreateAlloca (ArxLLVM::FLOAT_TYPE, nullptr , var_name);
102103}
103104
104105/* *
@@ -165,7 +166,7 @@ auto ASTToObjectVisitor::visit(UnaryExprAST& expr) -> void {
165166 *
166167 */
167168auto ASTToObjectVisitor::visit (BinaryExprAST& expr) -> void {
168- // Special case '=' because we don't want to emit the lhs as an
169+ // Special case '=' because we don't want to emit the lhs as an
169170 // expression.*/
170171 if (expr.op == ' =' ) {
171172 // Assignment requires the lhs to be an identifier.
@@ -188,13 +189,13 @@ auto ASTToObjectVisitor::visit(BinaryExprAST& expr) -> void {
188189 };
189190
190191 // Look up the name.//
191- llvm::Value* Variable = ArxLLVM::named_values[var_lhs-> get_name ()];
192- if (!Variable ) {
192+ llvm::Value* variable = ArxLLVM::named_values[LHSE-> getName ()];
193+ if (!variable ) {
193194 this ->result_val = LogErrorV (" Unknown variable name" );
194195 return ;
195196 }
196197
197- ArxLLVM::ir_builder->CreateStore (val, Variable );
198+ ArxLLVM::ir_builder->CreateStore (val, variable );
198199 this ->result_val = val;
199200 }
200201
@@ -520,11 +521,32 @@ auto ASTToObjectVisitor::visit(VarExprAST& expr) -> void {
520521 *
521522 */
522523auto ASTToObjectVisitor::visit (PrototypeAST& expr) -> void {
523- std::vector<llvm::Type*> args_type (expr.args .size (), ArxLLVM::FLOAT_TYPE);
524- llvm::Type* return_type = ArxLLVM::get_data_type (" float" );
524+ // Make the function type: double(double,double) etc.
525+ std::vector<llvm::Type*> args;
526+ llvm::Type* arg_type;
527+
528+ for (auto & arg : expr.args ) {
529+ arg_type = ArxLLVM::get_data_type (arg->type_name );
530+ if (arg_type != nullptr ) {
531+ args.emplace_back (arg_type);
532+ } else {
533+ llvm::errs () << " ARX::GEN-OBJECT[ERROR]: PrototypeAST: "
534+ << " Argument data type " << arg->type_name
535+ << " not implemented yet." ;
536+ }
537+ }
538+
539+ llvm::Type* return_type = ArxLLVM::get_data_type (expr.type_name );
540+
541+ if (return_type == nullptr ) {
542+ llvm::errs () << " ARX::GEN-OBJECT[ERROR]: PrototypeAST: "
543+ << " Argument data type " << expr.type_name
544+ << " not implemented yet." ;
545+ }
525546
526- llvm::FunctionType* fn_type =
527- llvm::FunctionType::get (return_type, args_type, false /* isVarArg */ );
547+ llvm::FunctionType* fn_type = llvm::FunctionType::get (
548+ return_type, args, false /* isVarArg */
549+ );
528550
529551 llvm::Function* fn = llvm::Function::Create (
530552 fn_type,
@@ -794,7 +816,7 @@ auto compile_object(TreeAST& tree_ast) -> int {
794816 std::cout << " ARX[INFO]: " << compiler_cmd << std::endl;
795817 int compile_result = system (compiler_cmd.c_str ());
796818
797- // ArxFile::delete_file(main_cpp_path);
819+ ArxFile::delete_file (main_cpp_path);
798820
799821 if (compile_result != 0 ) {
800822 llvm::errs () << " failed to compile and link object file" ;
0 commit comments