Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Sep 23, 2023
1 parent f8446d5 commit efc9937
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 142 deletions.
74 changes: 36 additions & 38 deletions tools/netlist/include/Netlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct VariableSelectorBase {

/// A variable selector representing an element selector.
struct VariableElementSelect : public VariableSelectorBase {
const ast::Expression &expr;
const ast::Expression& expr;
ConstantValue index;

VariableElementSelect(ast::Expression const& expr, ConstantValue index) :
Expand All @@ -78,9 +78,7 @@ struct VariableElementSelect : public VariableSelectorBase {
return otherKind == VariableSelectorKind::ElementSelect;
}

bool indexIsConstant() const {
return !index.bad();
}
bool indexIsConstant() const { return !index.bad(); }

int32_t getIndexInt() const {
auto intValue = index.integer().as<int32_t>();
Expand All @@ -89,17 +87,18 @@ struct VariableElementSelect : public VariableSelectorBase {
}

std::string toString() const override {
if (indexIsConstant()) {
return fmt::format("[{}]", index.toString());
} else {
return fmt::format("[{}]", expr.syntax->toString());
}
if (indexIsConstant()) {
return fmt::format("[{}]", index.toString());
}
else {
return fmt::format("[{}]", expr.syntax->toString());
}
}
};

/// A variable selector representing a range selector.
struct VariableRangeSelect : public VariableSelectorBase {
const ast::RangeSelectExpression &expr;
const ast::RangeSelectExpression& expr;
ConstantValue leftIndex, rightIndex;

VariableRangeSelect(ast::RangeSelectExpression const& expr, ConstantValue leftIndex,
Expand All @@ -111,13 +110,9 @@ struct VariableRangeSelect : public VariableSelectorBase {
return otherKind == VariableSelectorKind::RangeSelect;
}

bool leftIndexIsConstant() const {
return !leftIndex.bad();
}
bool leftIndexIsConstant() const { return !leftIndex.bad(); }

bool rightIndexIsConstant() const {
return !rightIndex.bad();
}
bool rightIndexIsConstant() const { return !rightIndex.bad(); }

int32_t getLeftIndexInt() const {
auto intValue = leftIndex.integer().as<int32_t>();
Expand All @@ -134,25 +129,27 @@ struct VariableRangeSelect : public VariableSelectorBase {
std::string toString() const override {
std::string left;
if (leftIndexIsConstant()) {
left = leftIndex.toString();
} else {
left = expr.left().syntax->toString();
left = leftIndex.toString();
}
else {
left = expr.left().syntax->toString();
}
std::string right;
if (rightIndexIsConstant()) {
right = rightIndex.toString();
} else {
right = expr.right().syntax->toString();
right = rightIndex.toString();
}
else {
right = expr.right().syntax->toString();
}
switch (expr.getSelectionKind()) {
case ast::RangeSelectionKind::Simple:
return fmt::format("[{}:{}]", left, right);
case ast::RangeSelectionKind::IndexedUp:
return fmt::format("[{}+:{}]", left, right);
case ast::RangeSelectionKind::IndexedDown:
return fmt::format("[{}-:{}]", left, right);
default:
SLANG_UNREACHABLE;
case ast::RangeSelectionKind::Simple:
return fmt::format("[{}:{}]", left, right);
case ast::RangeSelectionKind::IndexedUp:
return fmt::format("[{}+:{}]", left, right);
case ast::RangeSelectionKind::IndexedDown:
return fmt::format("[{}-:{}]", left, right);
default:
SLANG_UNREACHABLE;
}
}
};
Expand Down Expand Up @@ -271,12 +268,12 @@ class NetlistVariableReference : public NetlistNode {
NetlistNode(NodeKind::VariableReference, symbol),
expression(expr), leftOperand(leftOperand) {}

void addElementSelect(ast::ElementSelectExpression const &expr, const ConstantValue& index) {
void addElementSelect(ast::ElementSelectExpression const& expr, const ConstantValue& index) {
selectors.emplace_back(std::make_unique<VariableElementSelect>(expr.selector(), index));
}

void addRangeSelect(ast::RangeSelectExpression const& expr,
const ConstantValue& leftIndex, const ConstantValue& rightIndex) {
void addRangeSelect(ast::RangeSelectExpression const& expr, const ConstantValue& leftIndex,
const ConstantValue& rightIndex) {
selectors.emplace_back(std::make_unique<VariableRangeSelect>(expr, leftIndex, rightIndex));
}

Expand All @@ -300,11 +297,12 @@ class NetlistVariableReference : public NetlistNode {

/// Return a string representation of this variable reference.
std::string toString() const {
if (selectors.empty()) {
return fmt::format("{}", getName());
} else {
return fmt::format("{}{}", getName(), selectorString());
}
if (selectors.empty()) {
return fmt::format("{}", getName());
}
else {
return fmt::format("{}{}", getName(), selectorString());
}
}

public:
Expand Down
12 changes: 5 additions & 7 deletions tools/netlist/include/NetlistVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ static void connectDeclToVar(Netlist& netlist, NetlistNode& declNode,
const std::string& hierarchicalPath) {
auto* varNode = netlist.lookupVariable(hierarchicalPath);
netlist.addEdge(*varNode, declNode);
DEBUG_PRINT(
fmt::format("Edge decl {} to ref {}\n", varNode->getName(), declNode.getName()));
DEBUG_PRINT(fmt::format("Edge decl {} to ref {}\n", varNode->getName(), declNode.getName()));
}

static void connectVarToDecl(Netlist& netlist, NetlistNode& varNode,
const std::string& hierarchicalPath) {
auto* declNode = netlist.lookupVariable(hierarchicalPath);
netlist.addEdge(varNode, *declNode);
DEBUG_PRINT(
fmt::format("Edge ref {} to decl {}\n", varNode.getName(), declNode->getName()));
DEBUG_PRINT(fmt::format("Edge ref {} to decl {}\n", varNode.getName(), declNode->getName()));
}

static void connectVarToVar(Netlist& netlist, NetlistNode& sourceVarNode,
Expand All @@ -73,9 +71,9 @@ class VariableReferenceVisitor : public ast::ASTVisitor<VariableReferenceVisitor

void handle(const ast::NamedValueExpression& expr) {
if (!expr.eval(evalCtx).bad()) {
// If the symbol reference is to a constant (eg a parameter or enum
// value), then skip it.
return;
// If the symbol reference is to a constant (eg a parameter or enum
// value), then skip it.
return;
}
auto& node = netlist.addVariableReference(expr.symbol, expr, leftOperand);
varList.push_back(&node);
Expand Down
Loading

0 comments on commit efc9937

Please sign in to comment.