Skip to content

Commit

Permalink
treewide: Add attribute utilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Mar 12, 2024
1 parent 00ea4aa commit cc4f69d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
17 changes: 17 additions & 0 deletions include/vast/Util/Attribute.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2024, Trail of Bits, Inc.

Check notice on line 1 in include/vast/Util/Attribute.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

Run clang-format on include/vast/Util/Attribute.hpp

File include/vast/Util/Attribute.hpp does not conform to Custom style guidelines. (lines 5)

#pragma once

namespace vast::util
{
template< typename attribute_type >
attribute_type get_attr(auto op) {
return op->template getAttrOfType< attribute_type >(attribute_type::getMnemonic());
}

template< typename attribute_type >
bool has_attr(auto op) {
return op->hasAttr(attribute_type::getMnemonic());
}

} // namespace vast::util
5 changes: 3 additions & 2 deletions lib/vast/Conversion/FromHL/ToHLBI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ VAST_UNRELAX_WARNINGS
#include "vast/Conversion/Common/Patterns.hpp"
#include "vast/Conversion/Common/Rewriter.hpp"

#include "vast/Util/Attribute.hpp"
#include "vast/Util/Common.hpp"
#include "vast/Util/DialectConversion.hpp"
#include "vast/Util/TypeList.hpp"
Expand Down Expand Up @@ -62,12 +63,12 @@ namespace vast::conv {
}
auto callee = caller.resolveCallable();

auto attr = callee->template getAttrOfType< hl::BuiltinAttr >("builtin");
auto attr = util::get_attr< hl::BuiltinAttr >(callee);
if (!attr) {
return mlir::failure();
}

auto id = attr.getID();
auto id = mlir::cast< hl::BuiltinAttr >(attr).getID();
VAST_CHECK(id != 0, "Attempting to visit builtin expr that is not builtin (id is 0).");

switch (id) {
Expand Down
4 changes: 3 additions & 1 deletion lib/vast/Dialect/HighLevel/Transforms/UDE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ VAST_UNRELAX_WARNINGS
#include <vast/Interfaces/AggregateTypeDefinitionInterface.hpp>

#include <vast/Conversion/Common/Passes.hpp>

#include <vast/Util/Attribute.hpp>
#include <vast/Util/TypeUtils.hpp>

#include "PassesDetails.hpp"
Expand Down Expand Up @@ -53,7 +55,7 @@ namespace vast::hl {
bool keep(hl::FieldDeclOp op, auto scope) const { return keep(op.getParentAggregate(), scope); }

bool keep(hl::FuncOp op, auto scope) const {
return !op.isDeclaration() && !op->hasAttr( hl::AlwaysInlineAttr::getMnemonic() );
return !op.isDeclaration() && !util::has_attr< hl::AlwaysInlineAttr >(op);
}

bool keep(hl::VarDeclOp op, auto scope) const {
Expand Down

0 comments on commit cc4f69d

Please sign in to comment.