Skip to content

Commit

Permalink
Refactor use of std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshanlon committed Sep 25, 2024
1 parent d5d75b2 commit 6921b2c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tools/netlist/include/NetlistVisitorOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
struct NetlistVisitorOptions {

/// If enabled, unroll loops in procedural blocks.
std::optional<bool> unrollForLoops;
bool unrollForLoops{false};
};
2 changes: 1 addition & 1 deletion tools/netlist/include/visitors/ProceduralBlockVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ProceduralBlockVisitor : public ast::ASTVisitor<ProceduralBlockVisitor, tr
void handle(const ast::ForLoopStatement& loop) {

// Conditions that mean this loop cannot be unrolled.
if (!*options.unrollForLoops || loop.loopVars.empty() || !loop.stopExpr ||
if (!options.unrollForLoops || loop.loopVars.empty() || !loop.stopExpr ||
loop.steps.empty() || anyErrors) {
loop.body.visit(*this);
return;
Expand Down
6 changes: 4 additions & 2 deletions tools/netlist/netlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,18 @@ int main(int argc, char** argv) {
driver::Driver driver;
driver.addStandardArgs();

NetlistVisitorOptions options;
std::optional<bool> showHelp;
std::optional<bool> showVersion;
std::optional<bool> quiet;
std::optional<bool> debug;
std::optional<bool> combLoops;
std::optional<bool> unrollForLoops;
driver.cmdLine.add("-h,--help", showHelp, "Display available options");
driver.cmdLine.add("--version", showVersion, "Display version information and exit");
driver.cmdLine.add("-q,--quiet", quiet, "Suppress non-essential output");
driver.cmdLine.add("-d,--debug", debug, "Output debugging information");
driver.cmdLine.add("-c,--comb-loops", combLoops, "Detect combinatorial loops");
driver.cmdLine.add("--unroll-for-loops", options.unrollForLoops, "Unroll procedural for loops");
driver.cmdLine.add("--unroll-for-loops", unrollForLoops, "Unroll procedural for loops");

std::optional<std::string> astJsonFile;
driver.cmdLine.add(
Expand Down Expand Up @@ -286,6 +286,8 @@ int main(int argc, char** argv) {

// Create the netlist by traversing the AST.
Netlist netlist;
NetlistVisitorOptions options;
options.unrollForLoops = unrollForLoops.value_or(false);
NetlistVisitor visitor(*compilation, netlist, options);
compilation->getRoot().visit(visitor);
netlist.split();
Expand Down
1 change: 0 additions & 1 deletion tools/netlist/tests/NetlistTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ using namespace netlist;
inline Netlist createNetlist(ast::Compilation& compilation) {
Netlist netlist;
NetlistVisitorOptions options;
options.unrollForLoops = true;
NetlistVisitor visitor(compilation, netlist, options);
compilation.getRoot().visit(visitor);
netlist.split();
Expand Down

0 comments on commit 6921b2c

Please sign in to comment.