Skip to content

Commit

Permalink
Add unpacked concat logic
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Aug 1, 2020
1 parent 2635197 commit fde8c53
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions include/verilogAST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,13 @@ class Concat : public Expression {

public:
std::vector<std::unique_ptr<Expression>> args;
bool unpacked;

Concat(std::vector<std::unique_ptr<Expression>> args)
: args(std::move(args)){};
Concat(std::vector<std::unique_ptr<Expression>> args, bool unpacked = false)
: args(std::move(args)), unpacked(unpacked){};
Concat(const Concat& rhs) {
for (const auto& arg : rhs.args) args.push_back(arg->clone());
this->unpacked = rhs.unpacked;
};

std::string toString() override;
Expand Down
6 changes: 5 additions & 1 deletion src/verilogAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ std::string Concat::toString() {
for (auto &arg : args) {
arg_strs.push_back(arg->toString());
}
return "{" + join(arg_strs, ",") + "}";
std::string prefix = "";
if (this->unpacked) {
prefix = "'";
}
return prefix + "{" + join(arg_strs, ",") + "}";
}

std::string Replicate::toString() {
Expand Down
6 changes: 6 additions & 0 deletions tests/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ TEST(BasicTests, TestConcat) {
args.push_back(vAST::make_id("y"));
vAST::Concat concat(std::move(args));
EXPECT_EQ(concat.toString(), "{x,y}");

std::vector<std::unique_ptr<vAST::Expression>> args2;
args2.push_back(vAST::make_id("x"));
args2.push_back(vAST::make_id("y"));
vAST::Concat concat2(std::move(args2), true);
EXPECT_EQ(concat2.toString(), "'{x,y}");
}

TEST(BasicTests, TestReplicate) {
Expand Down

0 comments on commit fde8c53

Please sign in to comment.