Skip to content

Commit

Permalink
use packed array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Jul 31, 2020
1 parent beaaaa0 commit 22ca1d4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
17 changes: 10 additions & 7 deletions include/verilogAST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,20 @@ class Vector : public Node {
};

class NDVector : public Vector {
public:
std::unique_ptr<Identifier> id;
std::unique_ptr<Expression> msb;
std::unique_ptr<Expression> lsb;
std::vector<std::unique_ptr<Expression>> dims;
// we separate outer dim from inner dims to be consistent with vector
// interface
std::vector<
std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression>>>
inner_dims;

public:
NDVector(std::unique_ptr<Identifier> id, std::unique_ptr<Expression> msb,
std::unique_ptr<Expression> lsb,
std::vector<std::unique_ptr<Expression>> dims)
std::vector<std::pair<std::unique_ptr<Expression>,
std::unique_ptr<Expression>>>
inner_dims)
: Vector(std::move(id), std::move(msb), std::move(lsb)),
dims(std::move(dims)){};
inner_dims(std::move(inner_dims)){};
std::string toString() override;
~NDVector(){};
};
Expand Down
10 changes: 5 additions & 5 deletions src/verilogAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ std::string Vector::toString() {
}

std::string NDVector::toString() {
std::string base_str = Vector::toString();
base_str += " ";
for (auto &dim : dims) {
base_str += "[" + dim->toString() + "]";
std::string s =
"[" + this->msb->toString() + ":" + this->lsb->toString() + "]";
for (auto &dim : inner_dims) {
s += "[" + dim.first->toString() + ":" + dim.second->toString() + "]";
}
return base_str;
return s + " " + this->id->toString();
}

std::string BinaryOp::toString() {
Expand Down
12 changes: 7 additions & 5 deletions tests/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ TEST(BasicTests, TestVector) {
}

TEST(BasicTests, TestNDVector) {
std::vector<std::unique_ptr<vAST::Expression>> dims;
dims.push_back(vAST::make_num("8"));
dims.push_back(vAST::make_num("32"));
std::vector<std::pair<std::unique_ptr<vAST::Expression>,
std::unique_ptr<vAST::Expression>>>
inner_dims;
inner_dims.push_back({vAST::make_num("7"), vAST::make_num("0")});
inner_dims.push_back({vAST::make_num("15"), vAST::make_num("0")});
vAST::NDVector slice(vAST::make_id("x"), vAST::make_num("31"),
vAST::make_num("0"), std::move(dims));
EXPECT_EQ(slice.toString(), "[31:0] x [8][32]");
vAST::make_num("0"), std::move(inner_dims));
EXPECT_EQ(slice.toString(), "[31:0][7:0][15:0] x");
}

TEST(BasicTests, TestBinaryOp) {
Expand Down

0 comments on commit 22ca1d4

Please sign in to comment.