Merge branch 'master' of git.tuxzone.org:woc2013
This commit is contained in:
20
src/AST/BinOp.cpp
Normal file
20
src/AST/BinOp.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "AST/BinOp.h"
|
||||
|
||||
std::string binOpToString(BinOp op) {
|
||||
switch (op) {
|
||||
case BinOp::DIV:
|
||||
return "/";
|
||||
case BinOp::EQUALS:
|
||||
return "==";
|
||||
case BinOp::LESS:
|
||||
return "<";
|
||||
case BinOp::MINUS:
|
||||
return "-";
|
||||
case BinOp::PLUS:
|
||||
return "+";
|
||||
case BinOp::TIMES:
|
||||
return "*";
|
||||
default:
|
||||
return "Unknown Op";
|
||||
}
|
||||
}
|
||||
@@ -26,19 +26,19 @@ void CodeGenVisitor::visit(BinOpExpression* e) {
|
||||
}
|
||||
|
||||
switch (e->getOp()) {
|
||||
case OP_PLUS:
|
||||
case BinOp::PLUS:
|
||||
value_ = builder_->CreateAdd(lhs, rhs, "addtmp");
|
||||
break;
|
||||
case OP_MINUS:
|
||||
case BinOp::MINUS:
|
||||
value_ = builder_->CreateSub(lhs, rhs, "subtmp");
|
||||
break;
|
||||
case OP_TIMES:
|
||||
case BinOp::TIMES:
|
||||
value_ = builder_->CreateMul(lhs, rhs, "multmp");
|
||||
break;
|
||||
case OP_DIV:
|
||||
case BinOp::DIV:
|
||||
value_ = builder_->CreateSDiv(lhs, rhs, "divtmp");
|
||||
break;
|
||||
case OP_EQUALS:
|
||||
case BinOp::EQUALS:
|
||||
value_ = builder_->CreateICmpEQ(lhs, rhs, "eqtmp");
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -25,33 +25,7 @@ void PrintVisitor::visit(BinOpExpression* e) {
|
||||
println("BinOpExpression");
|
||||
level_++;
|
||||
std::stringstream ss;
|
||||
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;
|
||||
ss << "Operator: " << binOpToString(e->getOp());
|
||||
println(ss.str());
|
||||
println("LHS:");
|
||||
e->getLeftExp()->accept(this);
|
||||
|
||||
Reference in New Issue
Block a user