Skip to content

Commit

Permalink
Merge branch 'master' into linebreaks
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Feb 13, 2020
2 parents a22b4cb + afa165a commit 2e9ef03
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
28 changes: 25 additions & 3 deletions include/verilogAST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@

namespace verilogAST {

template <typename T>
class WithComment : public T {
std::string comment;

public:
WithComment(std::unique_ptr<T> node, std::string comment)
: T(std::move(node)), comment(comment){};

std::string toString() override {
return T::toString() + "/*" + this->comment + "*/";
};
~WithComment(){};
};

template <typename T>
std::unique_ptr<WithComment<T>> AddComment(std::unique_ptr<T> node,
std::string comment) {
return std::make_unique<WithComment<T>>(std::move(node), comment);
}

class Node {
public:
virtual std::string toString() = 0;
Expand Down Expand Up @@ -395,9 +415,11 @@ class Port : public AbstractPort {

Port(std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Vector>> value,
Direction direction, PortType data_type)
: value(std::move(value)),
direction(std::move(direction)),
data_type(std::move(data_type)){};
: value(std::move(value)), direction(direction), data_type(data_type){};
Port(std::unique_ptr<Port> port)
: value(std::move(port->value)),
direction(port->direction),
data_type(port->data_type){};
std::string toString();
~Port(){};
};
Expand Down
8 changes: 7 additions & 1 deletion tests/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ TEST(BasicTests, TestSlice) {
EXPECT_EQ(x2->toString(), "x[0][b:c]");
std::unique_ptr<vAST::Slice> x3 = std::make_unique<vAST::Slice>(

std::make_unique<vAST::BinaryOp>(vAST::make_id("x"), vAST::BinOp::ADD, vAST::make_id("y")),
std::make_unique<vAST::BinaryOp>(vAST::make_id("x"), vAST::BinOp::ADD,
vAST::make_id("y")),
std::make_unique<vAST::Identifier>("b"),
std::make_unique<vAST::Identifier>("c"));
EXPECT_EQ(x3->toString(), "(x + y)[b:c]");
Expand Down Expand Up @@ -505,6 +506,11 @@ TEST(BasicTests, Comment) {
vAST::SingleLineComment stmt_with_comment("Test comment",
std::move(cont_assign));
EXPECT_EQ(stmt_with_comment.toString(), "assign a = b; // Test comment");
std::unique_ptr<vAST::WithComment<vAST::Port>> port_with_comment =
vAST::AddComment(std::make_unique<vAST::Port>(vAST::make_id("i"),
vAST::INPUT, vAST::WIRE),
"verilator_public");
EXPECT_EQ(port_with_comment->toString(), "input i/*verilator_public*/");
}
TEST(BasicTests, InlineVerilog) {
vAST::InlineVerilog inline_verilog(
Expand Down

0 comments on commit 2e9ef03

Please sign in to comment.