Skip to content

Commit

Permalink
Add comparison ops
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Dec 2, 2019
1 parent e56e7f4 commit fa0b7c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion include/verilogAST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ enum BinOp {
POW,
MOD,
ALSHIFT,
ARSHIFT
ARSHIFT,
LT,
LTE,
GT,
GTE
};
}

Expand Down
12 changes: 12 additions & 0 deletions src/verilogAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ std::string BinaryOp::toString() {
case BinOp::ARSHIFT:
op_str = ">>>";
break;
case BinOp::LT:
op_str = "<";
break;
case BinOp::LTE:
op_str = "<=";
break;
case BinOp::GT:
op_str = ">";
break;
case BinOp::GTE:
op_str = ">=";
break;
}
return left->toString() + ' ' + op_str + ' ' + right->toString();
}
Expand Down
4 changes: 4 additions & 0 deletions tests/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ TEST(BasicTests, TestBinaryOp) {
ops.push_back(std::make_pair(vAST::BinOp::MOD, "%"));
ops.push_back(std::make_pair(vAST::BinOp::ALSHIFT, "<<<"));
ops.push_back(std::make_pair(vAST::BinOp::ARSHIFT, ">>>"));
ops.push_back(std::make_pair(vAST::BinOp::LT, "<"));
ops.push_back(std::make_pair(vAST::BinOp::LTE, "<="));
ops.push_back(std::make_pair(vAST::BinOp::GT, ">"));
ops.push_back(std::make_pair(vAST::BinOp::GTE, ">="));
for (auto it : ops) {
vAST::BinOp::BinOp op = it.first;
std::string op_str = it.second;
Expand Down

0 comments on commit fa0b7c3

Please sign in to comment.