Skip to content

Commit

Permalink
Merge 9526bff into 8b779ee
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Jan 31, 2020
2 parents 8b779ee + 9526bff commit 1144134
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/verilogAST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,17 @@ class BlockComment : public StructuralStatement, public BehavioralStatement {
~BlockComment(){};
};

class PortComment : public AbstractPort {
public:
std::unique_ptr<AbstractPort> port;
std::string value;

PortComment(std::unique_ptr<AbstractPort> port, std::string value)
: port(std::move(port)), value(value){};
std::string toString() override { return port->toString() + "/*" + value + "*/"; };
~PortComment(){};
};

class InlineVerilog : public StructuralStatement {
// Serializes into `value`, so allows the inclusion of arbitrary verilog
// statement(s) in the body of a module definition. The contents of
Expand Down
2 changes: 2 additions & 0 deletions include/verilogAST/transformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Transformer {

virtual std::unique_ptr<Port> visit(std::unique_ptr<Port> node);

virtual std::unique_ptr<PortComment> visit(std::unique_ptr<PortComment> node);

virtual std::unique_ptr<StringPort> visit(std::unique_ptr<StringPort> node);

virtual std::unique_ptr<SingleLineComment> visit(
Expand Down
9 changes: 9 additions & 0 deletions src/transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ std::unique_ptr<Port> Transformer::visit(std::unique_ptr<Port> node) {
return node;
}

std::unique_ptr<PortComment> Transformer::visit(std::unique_ptr<PortComment> node) {
node->port = this->visit(std::move(node->port));
return node;
}

std::unique_ptr<StringPort> Transformer::visit(
std::unique_ptr<StringPort> node) {
return node;
Expand Down Expand Up @@ -305,6 +310,10 @@ std::unique_ptr<AbstractPort> Transformer::visit(
node.release();
return this->visit(std::unique_ptr<Port>(ptr));
}
if (auto ptr = dynamic_cast<PortComment*>(node.get())) {
node.release();
return this->visit(std::unique_ptr<PortComment>(ptr));
}
if (auto ptr = dynamic_cast<StringPort*>(node.get())) {
node.release();
return this->visit(std::unique_ptr<StringPort>(ptr));
Expand Down
4 changes: 4 additions & 0 deletions tests/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ 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");
vAST::PortComment port_comment(
std::make_unique<vAST::Port>(vAST::make_id("i"), vAST::INPUT, vAST::WIRE),
"verilator_public");
EXPECT_EQ(port_comment.toString(), "input i/*verilator_public*/");
}
TEST(BasicTests, InlineVerilog) {
vAST::InlineVerilog inline_verilog(
Expand Down

0 comments on commit 1144134

Please sign in to comment.