Skip to content

Commit

Permalink
hl: Make enum constants use propes symbol attr names.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Sep 10, 2024
1 parent fa571fe commit 2fea518
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions include/vast/Dialect/HighLevel/HighLevelOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def HighLevel_TypeOfExprOp

def HighLevel_EnumConstantOp
: HighLevel_Op< "enum.const", [Core_EnumConstantSymbol] >
, Arguments<(ins SymbolNameAttr:$name, TypedAttrInterface:$value)>
, Arguments<(ins SymbolNameAttr:$sym_name, TypedAttrInterface:$value)>
{
let summary = "VAST enum constant declaration";
let description = [{
Expand Down Expand Up @@ -194,22 +194,22 @@ def HighLevel_EnumConstantOp
"Type":$type, "llvm::APSInt":$value,
CArg< "maybe_builder_callback_ref", "std::nullopt" >:$init
), [{
$_state.addAttribute("name", $_builder.getStringAttr(name));
$_state.addAttribute("sym_name", $_builder.getStringAttr(name));
$_state.addAttribute("value", core::IntegerAttr::get(type, value));

InsertionGuard guard($_builder);
build_region($_builder, $_state, init);
}]>,
];

let assemblyFormat = [{ $name `=` $value attr-dict (`init` $init^)? }];
let assemblyFormat = [{ $sym_name `=` $value attr-dict (`init` $init^)? }];
}

def HighLevel_EnumRegion : Region< Core_HasOneBlock, "enum constants region" >;

def HighLevel_EnumDeclOp
: HighLevel_Op< "enum", [NoTerminator, Core_TypeSymbol, Core_TypeDefinition] >
, Arguments<(ins SymbolNameAttr:$name, OptionalAttr<TypeAttr>:$type)>
, Arguments<(ins SymbolNameAttr:$sym_name, OptionalAttr<TypeAttr>:$type)>
{
let summary = "VAST enum declaration";
let description = [{
Expand Down
10 changes: 5 additions & 5 deletions lib/vast/Dialect/HighLevel/HighLevelOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,14 @@ namespace vast::hl
Builder &bld, State &st, llvm::StringRef name, Type type,
builder_callback_ref constants
) {
st.addAttribute("name", bld.getStringAttr(name));
st.addAttribute("sym_name", bld.getStringAttr(name));
st.addAttribute("type", mlir::TypeAttr::get(type));
InsertionGuard guard(bld);
build_region(bld, st, constants);
}

void EnumDeclOp::build(Builder &bld, State &st, llvm::StringRef name) {
st.addAttribute("name", bld.getStringAttr(name));
st.addAttribute("sym_name", bld.getStringAttr(name));
build_empty_region(bld, st);
}

Expand All @@ -377,7 +377,7 @@ namespace vast::hl

if (parser.parseSymbolName(nameAttr))
return mlir::failure();
if (nameAttr) result.attributes.append("name", nameAttr);
if (nameAttr) result.attributes.append("sym_name", nameAttr);

parser.getCurrentLocation();
if (parser.parseOptionalAttrDict(result.attributes)) {
Expand Down Expand Up @@ -409,9 +409,9 @@ namespace vast::hl

void EnumDeclOp::print(Printer &odsPrinter) {
odsPrinter << ' ';
odsPrinter.printSymbolName(getNameAttr().getValue());
odsPrinter.printSymbolName(getSymName());
llvm::SmallVector< llvm::StringRef, 2 > elidedAttrs;
elidedAttrs.push_back("name");
elidedAttrs.push_back("sym_name");
elidedAttrs.push_back("type");
odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs);
if (getTypeAttr()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/vast/Dialect/HighLevel/Transforms/LowerEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ namespace vast::hl {
void collect_enum_values(core::module root) {
auto walker = [&](operation op) {
if (auto decl = mlir::dyn_cast< const_decl >(op)) {
VAST_ASSERT(!id_to_value.count(decl.getName()));
id_to_value[decl.getName()] = decl;
VAST_ASSERT(!id_to_value.count(decl.getSymName()));
id_to_value[decl.getSymName()] = decl;
} else if (auto decl = mlir::dyn_cast< enum_decl >(op)) {
name_to_decl[decl.getName()] = decl;
name_to_decl[decl.getSymName()] = decl;
}
};

Expand Down

0 comments on commit 2fea518

Please sign in to comment.