Skip to content

Commit

Permalink
Call coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Dec 16, 2019
1 parent 3d9c112 commit 58db5e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/verilogAST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class CallExpr : public Expression, public Call {
public:
CallExpr(std::string func, std::vector<std::unique_ptr<Expression>> args)
: Call(std::move(func), std::move(args)){};
CallExpr(std::string func) : Call(std::move(func)){};
CallExpr(const CallExpr& rhs) : Call(std::move(rhs.func)) {
for (const auto& arg : rhs.args) {
args.push_back(arg->clone());
Expand Down Expand Up @@ -577,6 +578,7 @@ class CallStmt : public BehavioralStatement, public Call {
public:
CallStmt(std::string func, std::vector<std::unique_ptr<Expression>> args)
: Call(std::move(func), std::move(args)){};
CallStmt(std::string func) : Call(std::move(func)){};
std::string toString() { return Call::toString() + ";"; };
};

Expand Down
26 changes: 26 additions & 0 deletions tests/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ TEST(BasicTests, TestPosEdge) {

EXPECT_EQ(pos_edge.toString(), "posedge clk");
}

TEST(BasicTests, TestCallExpr0) {
std::vector<std::unique_ptr<vAST::Expression>> args;
args.push_back(vAST::make_id("x"));
Expand All @@ -188,6 +189,31 @@ TEST(BasicTests, TestCallExpr1) {
EXPECT_EQ(clog2.toString(), "$clog2(7)");
}

TEST(BasicTests, TestCallExprNoArgs) {
vAST::CallExpr foo("$foo");
EXPECT_EQ(foo.toString(), "$foo()");
}

TEST(BasicTests, TestCallStmt0) {
std::vector<std::unique_ptr<vAST::Expression>> args;
args.push_back(vAST::make_id("x"));
args.push_back(vAST::make_id("y"));
vAST::CallStmt my_func("my_func", std::move(args));
EXPECT_EQ(my_func.toString(), "my_func(x, y);");
}

TEST(BasicTests, TestCallStmt1) {
std::vector<std::unique_ptr<vAST::Expression>> args;
args.push_back(vAST::make_num("7"));
vAST::CallStmt clog2("$clog2", std::move(args));
EXPECT_EQ(clog2.toString(), "$clog2(7);");
}

TEST(BasicTests, TestCallStmtNoArgs) {
vAST::CallStmt foo("$foo");
EXPECT_EQ(foo.toString(), "$foo();");
}

TEST(BasicTests, TestPort) {
vAST::Port i_port(vAST::make_id("i"), vAST::INPUT, vAST::WIRE);

Expand Down

0 comments on commit 58db5e8

Please sign in to comment.