BinOp enum

This commit is contained in:
2013-06-01 16:13:23 +02:00
parent 96731379b4
commit 99e44c8e70
5 changed files with 68 additions and 33 deletions

View File

@@ -1,7 +1,7 @@
#include "AST/BinOpExpression.h"
#include "AST/ASTVisitor.h"
BinOpExpression::BinOpExpression(Expression *leftExp, std::string op, Expression *rightExp) :
BinOpExpression::BinOpExpression(Expression *leftExp, BinOp op, Expression *rightExp) :
leftExp_(leftExp), op_(op), rightExp_(rightExp) {
}
@@ -9,7 +9,7 @@ BinOpExpression::~BinOpExpression() {
//
}
std::string BinOpExpression::getOp() {
BinOp BinOpExpression::getOp() {
return op_;
}

View File

@@ -24,26 +24,26 @@ void CodeGenVisitor::visit(BinOpExpression* e) {
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;
// }
switch (e->getOp()) {
case OP_PLUS:
value_ = builder_->CreateAdd(lhs, rhs, "addtmp");
break;
case OP_MINUS:
value_ = builder_->CreateSub(lhs, rhs, "subtmp");
break;
case OP_TIMES:
value_ = builder_->CreateMul(lhs, rhs, "multmp");
break;
case OP_DIV:
value_ = builder_->CreateSDiv(lhs, rhs, "divtmp");
break;
case OP_EQUALS:
value_ = builder_->CreateICmpEQ(lhs, rhs, "eqtmp");
break;
default:
// TODO error
break;
}
value_->dump();
}

View File

@@ -2,6 +2,7 @@
#include <iostream>
#include <sstream>
PrintVisitor::PrintVisitor() : level_(0) {
//
}
@@ -24,7 +25,33 @@ void PrintVisitor::visit(BinOpExpression* e) {
println("BinOpExpression");
level_++;
std::stringstream ss;
ss << "Operator: " << e->getOp();
std::string opStr;
switch (e->getOp()) {
case OP_DIV:
opStr = "/";
break;
case OP_EQUALS:
opStr = "==";
break;
case OP_LESS:
opStr = "<";
break;
case OP_MINUS:
opStr = "-";
break;
case OP_PLUS:
opStr = "+";
break;
case OP_TIMES:
opStr = "*";
break;
default:
opStr = "Unknown Op";
break;
}
ss << "Operator: " << opStr;
println(ss.str());
println("LHS:");
e->getLeftExp()->accept(this);