Skip to content

Commit

Permalink
hl: Add helpers for generic selection expr.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jezurko committed Sep 9, 2024
1 parent 9d2b242 commit bc8f398
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/vast/Dialect/HighLevel/HighLevelOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,12 @@ def HighLevel_GenericSelectionExpr
}] >
];

let extraClassDeclaration = [{
std::optional< mlir::Region *> getResultRegion();
bool isExprPredicate();
bool isTypePredicate();
}];

let assemblyFormat = [{ attr-dict `match` `:` ($control^)? ($controlType^)? $body `->` type($result)}];
}

Expand Down
21 changes: 21 additions & 0 deletions lib/vast/Dialect/HighLevel/HighLevelOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,27 @@ namespace vast::hl
return std::optional(getCompatibleAttr().getValue());
}

//
// GenericSelectionExpr
//

std::optional< region_t *> GenericSelectionExpr::getResultRegion() {
if (auto selected = getSelected()) {
auto op_it = getBody().op_begin();
std::advance(op_it, selected.value().getZExtValue());
if (auto assoc = mlir::dyn_cast< hl::GenericAssocExpr >(*op_it))
return { &assoc.getBody() };
}
return std::nullopt;
}

bool GenericSelectionExpr::isExprPredicate() {
return !getControl().empty();
}

bool GenericSelectionExpr::isTypePredicate() {
return (*this)->hasAttr("matchType");
}
}

//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit bc8f398

Please sign in to comment.