diff --git a/inc/AST/Type.h b/inc/AST/Type.h index b897ee6..19039ca 100644 --- a/inc/AST/Type.h +++ b/inc/AST/Type.h @@ -3,14 +3,6 @@ #include -class Type { -public: - Type(std::string name); - ~Type(); - - std::string getName(); -private: - std::string name_; -}; +enum class Type { BOOL, INT, STRING, VOID }; #endif // TYPE_H diff --git a/src/AST/CodeGenVisitor.cpp b/src/AST/CodeGenVisitor.cpp index 1570e51..f3fa082 100644 --- a/src/AST/CodeGenVisitor.cpp +++ b/src/AST/CodeGenVisitor.cpp @@ -59,6 +59,32 @@ void CodeGenVisitor::visit(ForStatement* e) { } void CodeGenVisitor::visit(FunctionCallExpression* e) { + llvm::Function* cf = module_->getFunction(e->getId()); + if (!cf) { + // TODO error + return; + } + + auto values = e->getValues()->getValues(); + if (cf->arg_size() != values.size()) { + // TODO error + return; + } + + std::vector args; + auto iter = values.begin(); + auto end = values.end(); + for (; iter != end; ++iter) { + Expression *expr = (*iter); + expr->accept(this); + if (!value_) { + // TODO error + } + args.push_back(value_); + } + + value_ = builder_->CreateCall(cf, args, "calltmp"); + value_->dump(); } void CodeGenVisitor::visit(FunctionDefinition* e) { diff --git a/src/AST/PrintVisitor.cpp b/src/AST/PrintVisitor.cpp index 38adeaa..ff8377a 100644 --- a/src/AST/PrintVisitor.cpp +++ b/src/AST/PrintVisitor.cpp @@ -80,7 +80,7 @@ void PrintVisitor::visit(FunctionDefinition* e) { println(ss.str()); ss.str(""); ss.clear(); - ss << "Type: " << e->getType()->getName(); + ss << "Type: " << e->getType(); println(ss.str()); ParameterList* params = e->getParams(); if (params) { diff --git a/src/AST/Type.cpp b/src/AST/Type.cpp index 6c48e28..ea5ff21 100644 --- a/src/AST/Type.cpp +++ b/src/AST/Type.cpp @@ -1,9 +1 @@ #include "AST/Type.h" - -Type::Type(std::string name) : name_(name) { - // -} - -std::string Type::getName() { - return name_; -}