This commit is contained in:
Markus Hauschild
2013-06-01 16:12:38 +02:00
parent 96731379b4
commit 59c723fe96
4 changed files with 28 additions and 18 deletions

View File

@@ -3,14 +3,6 @@
#include <string> #include <string>
class Type { enum class Type { BOOL, INT, STRING, VOID };
public:
Type(std::string name);
~Type();
std::string getName();
private:
std::string name_;
};
#endif // TYPE_H #endif // TYPE_H

View File

@@ -59,6 +59,32 @@ void CodeGenVisitor::visit(ForStatement* e) {
} }
void CodeGenVisitor::visit(FunctionCallExpression* 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<llvm::Value*> 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) { void CodeGenVisitor::visit(FunctionDefinition* e) {

View File

@@ -80,7 +80,7 @@ void PrintVisitor::visit(FunctionDefinition* e) {
println(ss.str()); println(ss.str());
ss.str(""); ss.str("");
ss.clear(); ss.clear();
ss << "Type: " << e->getType()->getName(); ss << "Type: " << e->getType();
println(ss.str()); println(ss.str());
ParameterList* params = e->getParams(); ParameterList* params = e->getParams();
if (params) { if (params) {

View File

@@ -1,9 +1 @@
#include "AST/Type.h" #include "AST/Type.h"
Type::Type(std::string name) : name_(name) {
//
}
std::string Type::getName() {
return name_;
}