LoadExpression + more CodeGen

This commit is contained in:
Markus Hauschild
2013-06-01 15:48:28 +02:00
parent c4e0c2f298
commit 96731379b4
9 changed files with 102 additions and 0 deletions

View File

@@ -14,9 +14,42 @@ void CodeGenVisitor::visit(AssignmentExpression* e) {
}
void CodeGenVisitor::visit(BinOpExpression* e) {
e->getLeftExp()->accept(this);
llvm::Value* lhs = value_;
e->getRightExp()->accept(this);
llvm::Value* rhs = value_;
if ((!lhs) || (!rhs)) {
// TODO error
return;
}
// switch (e->getOp()) {
// case "+":
value_ = builder_->CreateAdd(lhs, rhs, "addtmp");
// break;
// case "-":
// value_ = builder_->CreateSub(lhs, rhs, "subtmp");
// break;
// case "*":
// value_ = builder_->CreateMul(lhs, rhs, "multmp");
// break;
// case "/":
// value_ = builder_->CreateSDiv(lhs, rhs, "divtmp");
// break;
// case "==":
// value_ = builder_->CreateICmpEQ(lhs, rhs, "eqtmp");
// break;
// default:
// // TODO error
// break;
// }
value_->dump();
}
void CodeGenVisitor::visit(ConstantExpression* e) {
value_ = llvm::ConstantInt::get(llvm::getGlobalContext(), llvm::APInt(32, e->getValue(), 10));
}
void CodeGenVisitor::visit(ExpressionStatement* e) {
@@ -57,3 +90,13 @@ void CodeGenVisitor::visit(ValueList* e) {
void CodeGenVisitor::visit(VariableDefinition* e) {
}
void CodeGenVisitor::visit(LoadExpression *e) {
}
void CodeGenVisitor::createAnonymousFunction() {
if (value_) {
value_->dump();
}
// TODO implement
}

View File

@@ -0,0 +1,19 @@
#include "AST/LoadExpression.h"
#include "AST/ASTVisitor.h"
LoadExpression::LoadExpression(std::string id): id_(id) {
//
}
LoadExpression::~LoadExpression() {
//
}
void LoadExpression::accept(ASTVisitor *visitor) {
visitor->visit(this);
}
std::string LoadExpression::getId() {
return id_;
}

View File

@@ -194,6 +194,15 @@ void PrintVisitor::visit(VariableDefinition* e) {
level_--;
}
void PrintVisitor::visit(LoadExpression *e) {
println("LoadExpression");
level_++;
std::stringstream ss;
ss << "Name: " << e->getId();
println(ss.str());
level_--;
}
void PrintVisitor::indent() {
for (int i = 0; i < level_; i++) {
std::cout << " ";