Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/ubuntu-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ jobs:
strategy:
matrix:
os: [ubuntu-24.04, ubuntu-22.04]
compiler: [clang, gcc]
include:
- compiler: clang
c_compiler: clang
cxx_compiler: clang++
- compiler: gcc
c_compiler: gcc
cxx_compiler: g++

steps:
- uses: actions/checkout@v4
Expand All @@ -30,14 +38,14 @@ jobs:
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -yq libfl-dev ninja-build #clang
#run: sudo apt-get update #&& sudo apt-get install -yq libboost-dev capnproto libcapnp-dev ninja-build clang

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
#xtof: 14/03/2024: deactivate sanitizer for the moment as it is crashing for no reason
#that seems related to naja-verilog in tests
#run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja -DCMAKE_C_COMPILER=clang -DENABLE_SANITIZERS=ON
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja -DCMAKE_C_COMPILER=clang
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja -DCMAKE_C_COMPILER=${{matrix.c_compiler}} -DCMAKE_CXX_COMPILER=${{matrix.cxx_compiler}}

- name: Build
# Build your program with the given configuration
Expand Down
2 changes: 1 addition & 1 deletion src/VerilogParser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ primary
| identifier constant_range_expression.opt {
$$.valid_ = true; $$.value_ = naja::verilog::RangeIdentifier($1, $2); }
| STRING_TK { $$.valid_ = true; $$.value_ = $1.substr(1, $1.size()-2); }
| concatenation { $$.valid_ = true; $$.value_ = naja::verilog::Concatenation($1); }
| concatenation { $$.valid_ = true; $$.value_ = std::make_shared<naja::verilog::Concatenation>($1); }
;

constant_primary
Expand Down
6 changes: 3 additions & 3 deletions src/VerilogTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ size_t Expression::getSize() const {
throw VerilogException("String expressions do not have a size");
case Type::CONCATENATION: {
size_t totalSize = 0;
for (const auto& expr: std::get<Type::CONCATENATION>(value_).expressions_) {
for (const auto& expr: std::get<Type::CONCATENATION>(value_)->expressions_) {
totalSize += expr.getSize();
}
return totalSize;
Expand Down Expand Up @@ -321,7 +321,7 @@ std::string Expression::getString() const {
case Type::STRING:
return std::get<Type::STRING>(value_);
case Type::CONCATENATION:
return std::get<Type::CONCATENATION>(value_).getString();
return std::get<Type::CONCATENATION>(value_)->getString();
}
return std::string();
}
Expand All @@ -339,7 +339,7 @@ std::string Expression::getDescription() const {
stream << std::get<Type::NUMBER>(value_).getDescription();
break;
case Type::CONCATENATION:
stream << std::get<Type::CONCATENATION>(value_).getDescription();
stream << std::get<Type::CONCATENATION>(value_)->getDescription();
break;
}
return stream.str();
Expand Down
33 changes: 19 additions & 14 deletions src/VerilogTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef __VERILOG_TYPES_H_
#define __VERILOG_TYPES_H_

#include <memory>
#include <variant>
#include <vector>
#include <string>
Expand Down Expand Up @@ -209,18 +210,7 @@ struct Number {
Value value_ {};
};

struct Expression;

struct Concatenation {
using Expressions = std::vector<Expression>;
Concatenation() = default;
Concatenation(const Concatenation&) = default;
Concatenation(const Expressions& expressions);
std::string getString() const;
std::string getDescription() const;

Expressions expressions_ {};
};
struct Concatenation;

struct Expression {
Expression() = default;
Expand All @@ -233,8 +223,12 @@ struct Expression {
std::string getString() const;
std::string getDescription() const;

enum Type { RANGEIDENTIFIER=0, NUMBER=1, STRING=2, CONCATENATION=3 };
using Value = std::variant<RangeIdentifier, Number, std::string, Concatenation>;
enum Type { RANGEIDENTIFIER=0, NUMBER=1, STRING=2, CONCATENATION=3 };
// Concatenation is stored via shared_ptr to break the mutual dependency between
// Expression and Concatenation (Concatenation contains std::vector<Expression>).
// unique_ptr would be more semantically correct but std::variant requires all
// alternatives to be copy-constructible, which unique_ptr is not.
using Value = std::variant<RangeIdentifier, Number, std::string, std::shared_ptr<Concatenation>>;

bool valid_ { false };
//If valid_ is true and supported_ is false, then this expression construction
Expand All @@ -243,6 +237,17 @@ struct Expression {
Value value_ {};
};

struct Concatenation {
using Expressions = std::vector<Expression>;
Concatenation() = default;
Concatenation(const Concatenation&) = default;
Concatenation(const Expressions& expressions);
std::string getString() const;
std::string getDescription() const;

Expressions expressions_ {};
};

struct ConstantExpression {
ConstantExpression() = default;
ConstantExpression(const ConstantExpression&) = default;
Expand Down
22 changes: 11 additions & 11 deletions test/NajaVerilogTest3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,34 +196,34 @@ TEST(NajaVerilogTest3, test0) {
inst3->connections_[0].expression_.value_.index());
auto concatenation =
std::get<naja::verilog::Expression::Type::CONCATENATION>(inst3->connections_[0].expression_.value_);
ASSERT_EQ(4, concatenation.expressions_.size());
ASSERT_EQ(4, concatenation->expressions_.size());
EXPECT_EQ(naja::verilog::Expression::Type::RANGEIDENTIFIER,
concatenation.expressions_[0].value_.index());
concatenation->expressions_[0].value_.index());
identifier =
std::get<naja::verilog::Expression::Type::RANGEIDENTIFIER>(concatenation.expressions_[0].value_);
std::get<naja::verilog::Expression::Type::RANGEIDENTIFIER>(concatenation->expressions_[0].value_);
EXPECT_FALSE(identifier.range_.valid_);
EXPECT_EQ("net0", identifier.identifier_.name_);

EXPECT_EQ(naja::verilog::Expression::Type::RANGEIDENTIFIER,
concatenation.expressions_[1].value_.index());
concatenation->expressions_[1].value_.index());
identifier =
std::get<naja::verilog::Expression::Type::RANGEIDENTIFIER>(concatenation.expressions_[1].value_);
std::get<naja::verilog::Expression::Type::RANGEIDENTIFIER>(concatenation->expressions_[1].value_);
EXPECT_FALSE(identifier.range_.valid_);
EXPECT_EQ("net1", identifier.identifier_.name_);


EXPECT_EQ(naja::verilog::Expression::Type::RANGEIDENTIFIER,
concatenation.expressions_[2].value_.index());
concatenation->expressions_[2].value_.index());
identifier =
std::get<naja::verilog::Expression::Type::RANGEIDENTIFIER>(concatenation.expressions_[2].value_);
std::get<naja::verilog::Expression::Type::RANGEIDENTIFIER>(concatenation->expressions_[2].value_);
EXPECT_FALSE(identifier.range_.valid_);
EXPECT_EQ("net2", identifier.identifier_.name_);
EXPECT_FALSE(identifier.identifier_.escaped_);

EXPECT_EQ(naja::verilog::Expression::Type::RANGEIDENTIFIER,
concatenation.expressions_[3].value_.index());
concatenation->expressions_[3].value_.index());
identifier =
std::get<naja::verilog::Expression::Type::RANGEIDENTIFIER>(concatenation.expressions_[3].value_);
std::get<naja::verilog::Expression::Type::RANGEIDENTIFIER>(concatenation->expressions_[3].value_);
EXPECT_TRUE(identifier.range_.valid_);
EXPECT_EQ("net5", identifier.identifier_.name_);
EXPECT_TRUE(identifier.range_.singleValue_);
Expand Down Expand Up @@ -261,7 +261,7 @@ TEST(NajaVerilogTest3, test0) {
expression.value_.index());
concatenation =
std::get<naja::verilog::Expression::Type::CONCATENATION>(expression.value_);
ASSERT_EQ(4, concatenation.expressions_.size());
ASSERT_EQ(4, concatenation->expressions_.size());

auto inst5 = dynamic_cast<VerilogConstructorTest::ModuleInstance*>(test->instances_[5]);
ASSERT_EQ(1, inst5->orderedConnections_.size());
Expand Down
6 changes: 3 additions & 3 deletions test/NajaVerilogTest6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ TEST(NajaVerilogTest6, test) {
EXPECT_TRUE(expression.valid_);
EXPECT_EQ(naja::verilog::Expression::Type::CONCATENATION, expression.value_.index());
auto concatenation = std::get<naja::verilog::Expression::Type::CONCATENATION>(expression.value_);
EXPECT_EQ(3, concatenation.expressions_.size());
EXPECT_TRUE(concatenation.expressions_[2].valid_);
auto constant = concatenation.expressions_[2];
EXPECT_EQ(3, concatenation->expressions_.size());
EXPECT_TRUE(concatenation->expressions_[2].valid_);
auto constant = concatenation->expressions_[2];
EXPECT_EQ(naja::verilog::Expression::NUMBER, constant.value_.index());
auto constantValue = std::get<naja::verilog::Expression::NUMBER>(constant.value_);
EXPECT_TRUE(constantValue.sign_);
Expand Down
2 changes: 1 addition & 1 deletion test/NajaVerilogTestSize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ TEST(NajaVerilogTestSize, testExpressionsSize) {
};
naja::verilog::Concatenation concatenation(expressions);
naja::verilog::Expression expr;
expr.value_ = concatenation;
expr.value_ = std::make_unique<naja::verilog::Concatenation>(concatenation);
expr.valid_ = true;
EXPECT_TRUE(expr.supported_);
EXPECT_EQ(naja::verilog::Expression::Type::CONCATENATION, expr.value_.index());
Expand Down
Loading